The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/i386/geode.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2003-2004 Poul-Henning Kamp
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/6.2/sys/i386/i386/geode.c 149165 2005-08-16 22:47:14Z phk $");
   29 
   30 #include <sys/param.h>
   31 #include <sys/systm.h>
   32 #include <sys/timetc.h>
   33 #include <sys/bus.h>
   34 #include <sys/kernel.h>
   35 #include <sys/module.h>
   36 #include <sys/watchdog.h>
   37 #include <dev/pci/pcireg.h>
   38 #include <dev/pci/pcivar.h>
   39 #include <dev/led/led.h>
   40 #include <machine/pc/bios.h>
   41 
   42 static struct bios_oem bios_soekris = {
   43         { 0xf0000, 0xf1000 },
   44         {
   45                 { "Soekris", 0, 8 },    /* Soekris Engineering. */
   46                 { "net4", 0, 8 },       /* net45xx */
   47                 { "comBIOS", 0, 54 },   /* comBIOS ver. 1.26a  20040819 ... */
   48                 { NULL, 0, 0 },
   49         }
   50 };
   51 
   52 static struct bios_oem bios_pcengines = {
   53         { 0xf9000, 0xfa000 },
   54         {
   55                 { "PC Engines WRAP", 0, 28 },   /* PC Engines WRAP.1C v1.03 */
   56                 { "tinyBIOS", 0, 28 },          /* tinyBIOS V1.4a (C)1997-2003 */
   57                 { NULL, 0, 0 },
   58         }
   59 };
   60 
   61 static struct bios_oem bios_advantech = {
   62         { 0xfe000, 0xff000 },
   63         {
   64                 { "**** PCM-582", 5, 33 },      /* PCM-5823 BIOS V1.12 ... */
   65                 { "GXm-Cx5530", -11, 35 },      /* 06/07/2002-GXm-Cx5530... */
   66                 { NULL, 0, 0 },
   67         }
   68 };
   69 
   70 static unsigned cba;
   71 static unsigned gpio;
   72 static unsigned geode_counter;
   73 
   74 static struct cdev *led1, *led2, *led3;
   75 static int      led1b, led2b, led3b;
   76 
   77 static void
   78 led_func(void *ptr, int onoff)
   79 {
   80         uint32_t u;
   81         int bit;
   82 
   83         bit = *(int *)ptr;
   84         if (bit < 0) {
   85                 bit = -bit;
   86                 onoff = !onoff;
   87         }
   88 
   89         u = inl(gpio + 4);
   90         if (onoff)
   91                 u |= 1 << bit;
   92         else
   93                 u &= ~(1 << bit);
   94         outl(gpio, u);
   95 }
   96 
   97 
   98 static unsigned
   99 geode_get_timecount(struct timecounter *tc)
  100 {
  101         return (inl(geode_counter));
  102 }
  103 
  104 static struct timecounter geode_timecounter = {
  105         geode_get_timecount,
  106         NULL,
  107         0xffffffff,
  108         27000000,
  109         "Geode",
  110         1000
  111 };
  112 
  113 /*
  114  * The GEODE watchdog runs from a 32kHz frequency.  One period of that is
  115  * 31250 nanoseconds which we round down to 2^14 nanoseconds.  The watchdog
  116  * consists of a power-of-two prescaler and a 16 bit counter, so the math
  117  * is quite simple.  The max timeout is 14 + 16 + 13 = 2^43 nsec ~= 2h26m.
  118  */
  119 static void
  120 geode_watchdog(void *foo __unused, u_int cmd, int *error)
  121 {
  122         u_int u, p, r;
  123 
  124         u = cmd & WD_INTERVAL;
  125         if (cmd && u >= 14 && u <= 43) {
  126                 u -= 14;
  127                 if (u > 16) {
  128                         p = u - 16;
  129                         u -= p;
  130                 } else {
  131                         p = 0;
  132                 }
  133                 if (u == 16)
  134                         u = (1 << u) - 1;
  135                 else
  136                         u = 1 << u;
  137                 r = inw(cba + 2) & 0xff00;
  138                 outw(cba + 2, p | 0xf0 | r);
  139                 outw(cba, u);
  140                 *error = 0;
  141         } else {
  142                 outw(cba, 0);
  143         }
  144 }
  145 
  146 /*
  147  * The Advantech PCM-582x watchdog expects 0x1 at I/O port 0x0443
  148  * every 1.6 secs +/- 30%. Writing 0x0 disables the watchdog
  149  * NB: reading the I/O port enables the timer as well
  150  */
  151 static void
  152 advantech_watchdog(void *foo __unused, u_int cmd, int *error)
  153 {
  154         outb(0x0443, (cmd & WD_INTERVAL) ? 1 : 0);
  155         *error = 0;
  156 }
  157 
  158 static int
  159 geode_probe(device_t self)
  160 {
  161 #define BIOS_OEM_MAXLEN 80
  162         static u_char bios_oem[BIOS_OEM_MAXLEN] = "\0";
  163 
  164         if (pci_get_devid(self) == 0x0515100b) {
  165                 if (geode_counter == 0) {
  166                         /*
  167                          * The address of the CBA is written to this register
  168                          * by the bios, see p161 in data sheet.
  169                          */
  170                         cba = pci_read_config(self, 0x64, 4);
  171                         printf("Geode CBA@ 0x%x\n", cba);
  172                         geode_counter = cba + 0x08;
  173                         outl(cba + 0x0d, 2);
  174                         printf("Geode rev: %02x %02x\n",
  175                                 inb(cba + 0x3c), inb(cba + 0x3d));
  176                         tc_init(&geode_timecounter);
  177                         EVENTHANDLER_REGISTER(watchdog_list, geode_watchdog,
  178                             NULL, 0);
  179                 }
  180         } else if (pci_get_devid(self) == 0x0510100b) {
  181                 gpio = pci_read_config(self, PCIR_BAR(0), 4);
  182                 gpio &= ~0x1f;
  183                 printf("Geode GPIO@ = %x\n", gpio);
  184                 if ( bios_oem_strings(&bios_soekris,
  185                                         bios_oem, BIOS_OEM_MAXLEN) > 0 ) {
  186                         led1b = 20;
  187                         led1 = led_create(led_func, &led1b, "error");
  188                 } else if ( bios_oem_strings(&bios_pcengines,
  189                                         bios_oem, BIOS_OEM_MAXLEN) > 0 ) {
  190                         led1b = -2;
  191                         led2b = -3;
  192                         led3b = -18;
  193                         led1 = led_create(led_func, &led1b, "led1");
  194                         led2 = led_create(led_func, &led2b, "led2");
  195                         led3 = led_create(led_func, &led3b, "led3");
  196                         /*
  197                         * Turn on first LED so we don't make
  198                         * people think their box just died.
  199                         */
  200                         led_func(&led1b, 1);
  201                 }
  202                 if ( strlen(bios_oem) )
  203                         printf("Geode %s\n", bios_oem);
  204         } else if (pci_get_devid(self) == 0x01011078) {
  205                 if ( bios_oem_strings(&bios_advantech,
  206                                 bios_oem, BIOS_OEM_MAXLEN) > 0 ) {
  207                         printf("Geode %s\n", bios_oem);
  208                         EVENTHANDLER_REGISTER(watchdog_list, advantech_watchdog,
  209                             NULL, 0);
  210                 }
  211         }
  212         return (ENXIO);
  213 }
  214 
  215 static int
  216 geode_attach(device_t self)
  217 {
  218 
  219         return(ENODEV);
  220 }
  221 
  222 static device_method_t geode_methods[] = {
  223         /* Device interface */
  224         DEVMETHOD(device_probe,         geode_probe),
  225         DEVMETHOD(device_attach,        geode_attach),
  226         DEVMETHOD(device_suspend,       bus_generic_suspend),
  227         DEVMETHOD(device_resume,        bus_generic_resume),
  228         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  229         {0, 0}
  230 };
  231  
  232 static driver_t geode_driver = {
  233         "geode",
  234         geode_methods,
  235         0,
  236 };
  237 
  238 static devclass_t geode_devclass;
  239 
  240 DRIVER_MODULE(geode, pci, geode_driver, geode_devclass, 0, 0);

Cache object: 9bb11b1d25349dea882369dbf5c1d54a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.