2 * Copyright (c) 2003-2004 Poul-Henning Kamp
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/timetc.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>
42 static struct bios_oem bios_soekris = {
45 { "Soekris", 0, 8 }, /* Soekris Engineering. */
46 { "net4", 0, 8 }, /* net45xx */
47 { "comBIOS", 0, 54 }, /* comBIOS ver. 1.26a 20040819 ... */
52 static struct bios_oem bios_soekris_55 = {
55 { "Soekris", 0, 8 }, /* Soekris Engineering. */
56 { "net5", 0, 8 }, /* net5xxx */
57 { "comBIOS", 0, 54 }, /* comBIOS ver. 1.26a 20040819 ... */
62 static struct bios_oem bios_pcengines = {
65 { "PC Engines WRAP", 0, 28 }, /* PC Engines WRAP.1C v1.03 */
66 { "tinyBIOS", 0, 28 }, /* tinyBIOS V1.4a (C)1997-2003 */
71 static struct bios_oem bios_pcengines_55 = {
74 { "PC Engines ALIX", 0, 28 }, /* PC Engines ALIX */
75 { "tinyBIOS", 0, 28 }, /* tinyBIOS V1.4a (C)1997-2005 */
80 static struct bios_oem bios_advantech = {
83 { "**** PCM-582", 5, 33 }, /* PCM-5823 BIOS V1.12 ... */
84 { "GXm-Cx5530", -11, 35 }, /* 06/07/2002-GXm-Cx5530... */
91 static unsigned geode_counter;
93 static struct cdev *led1, *led2, *led3;
94 static int led1b, led2b, led3b;
97 led_func(void *ptr, int onoff)
117 cs5536_led_func(void *ptr, int onoff)
128 a = rdmsr(0x5140000c);
137 outl(a, 1 << (bit + 16));
142 geode_get_timecount(struct timecounter *tc)
144 return (inl(geode_counter));
147 static struct timecounter geode_timecounter = {
160 static unsigned last;
161 static uint64_t offset;
163 c = inl(geode_counter);
165 offset += (1LL << 32);
171 * The GEODE watchdog runs from a 32kHz frequency. One period of that is
172 * 31250 nanoseconds which we round down to 2^14 nanoseconds. The watchdog
173 * consists of a power-of-two prescaler and a 16 bit counter, so the math
174 * is quite simple. The max timeout is 14 + 16 + 13 = 2^43 nsec ~= 2h26m.
177 geode_watchdog(void *foo __unused, u_int cmd, int *error)
181 u = cmd & WD_INTERVAL;
182 if (u >= 14 && u <= 43) {
194 r = inw(cba + 2) & 0xff00;
195 outw(cba + 2, p | 0xf0 | r);
204 * We run MFGPT0 off the 32kHz frequency and prescale by 16384 giving a
205 * period of half a second.
206 * Range becomes 2^30 (= 1 sec) to 2^44 (almost 5 hours)
209 cs5536_watchdog(void *foo __unused, u_int cmd, int *error)
215 a = rdmsr(0x5140000d);
216 m = rdmsr(0x51400029);
218 wrmsr(0x51400029, m);
220 u = cmd & WD_INTERVAL;
221 if (u >= 30 && u <= 44) {
224 /* Set up MFGPT0, 32khz, prescaler 16k, C2 event */
226 /* set comparator 2 */
230 /* Arm reset mechanism */
232 wrmsr(0x51400029, m);
241 * The Advantech PCM-582x watchdog expects 0x1 at I/O port 0x0443
242 * every 1.6 secs +/- 30%. Writing 0x0 disables the watchdog
243 * NB: reading the I/O port enables the timer as well
246 advantech_watchdog(void *foo __unused, u_int cmd, int *error)
250 u = cmd & WD_INTERVAL;
251 if (u > 0 && u <= WD_TO_1SEC) {
260 geode_probe(device_t self)
262 #define BIOS_OEM_MAXLEN 80
263 static u_char bios_oem[BIOS_OEM_MAXLEN] = "\0";
265 switch (pci_get_devid(self)) {
267 if (geode_counter == 0) {
269 * The address of the CBA is written to this register
270 * by the bios, see p161 in data sheet.
272 cba = pci_read_config(self, 0x64, 4);
274 printf("Geode CBA@ 0x%x\n", cba);
275 geode_counter = cba + 0x08;
278 printf("Geode rev: %02x %02x\n",
279 inb(cba + 0x3c), inb(cba + 0x3d));
280 tc_init(&geode_timecounter);
281 EVENTHANDLER_REGISTER(watchdog_list, geode_watchdog,
283 set_cputicker(geode_cputicks, 27000000, 0);
287 gpio = pci_read_config(self, PCIR_BAR(0), 4);
290 printf("Geode GPIO@ = %x\n", gpio);
291 if (bios_oem_strings(&bios_soekris,
292 bios_oem, sizeof bios_oem) > 0 ) {
294 led1 = led_create(led_func, &led1b, "error");
295 } else if (bios_oem_strings(&bios_pcengines,
296 bios_oem, sizeof bios_oem) > 0 ) {
300 led1 = led_create(led_func, &led1b, "led1");
301 led2 = led_create(led_func, &led2b, "led2");
302 led3 = led_create(led_func, &led3b, "led3");
304 * Turn on first LED so we don't make
305 * people think their box just died.
310 printf("Geode %s\n", bios_oem);
313 if (bios_oem_strings(&bios_advantech,
314 bios_oem, sizeof bios_oem) > 0 ) {
315 printf("Geode %s\n", bios_oem);
316 EVENTHANDLER_REGISTER(watchdog_list, advantech_watchdog,
321 if (bios_oem_strings(&bios_soekris_55,
322 bios_oem, sizeof bios_oem) > 0 ) {
324 led1 = led_create(cs5536_led_func, &led1b, "error");
325 } else if (bios_oem_strings(&bios_pcengines_55,
326 bios_oem, sizeof bios_oem) > 0 ) {
330 led1 = led_create(cs5536_led_func, &led1b, "led1");
331 led2 = led_create(cs5536_led_func, &led2b, "led2");
332 led3 = led_create(cs5536_led_func, &led3b, "led3");
334 * Turn on first LED so we don't make
335 * people think their box just died.
337 cs5536_led_func(&led1b, 1);
340 printf("Geode LX: %s\n", bios_oem);
342 printf("MFGPT bar: %jx\n", rdmsr(0x5140000d));
343 EVENTHANDLER_REGISTER(watchdog_list, cs5536_watchdog, NULL, 0);
350 geode_attach(device_t self)
356 static device_method_t geode_methods[] = {
357 /* Device interface */
358 DEVMETHOD(device_probe, geode_probe),
359 DEVMETHOD(device_attach, geode_attach),
360 DEVMETHOD(device_suspend, bus_generic_suspend),
361 DEVMETHOD(device_resume, bus_generic_resume),
362 DEVMETHOD(device_shutdown, bus_generic_shutdown),
366 static driver_t geode_driver = {
372 static devclass_t geode_devclass;
374 DRIVER_MODULE(geode, pci, geode_driver, geode_devclass, 0, 0);