20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
30 #include <linux/watchdog.h>
34 #include <linux/slab.h>
40 MODULE_PARM_DESC(nowayout,
"Watchdog cannot be stopped once started (default="
43 #define SIO_SCH56XX_LD_EM 0x0C
44 #define SIO_UNLOCK_KEY 0x55
45 #define SIO_LOCK_KEY 0xAA
47 #define SIO_REG_LDSEL 0x07
48 #define SIO_REG_DEVID 0x20
49 #define SIO_REG_ENABLE 0x30
50 #define SIO_REG_ADDR 0x66
52 #define SIO_SCH5627_ID 0xC6
53 #define SIO_SCH5636_ID 0xC7
55 #define REGION_LENGTH 10
57 #define SCH56XX_CMD_READ 0x02
58 #define SCH56XX_CMD_WRITE 0x03
61 #define SCH56XX_REG_WDOG_PRESET 0x58B
62 #define SCH56XX_REG_WDOG_CONTROL 0x58C
63 #define SCH56XX_WDOG_TIME_BASE_SEC 0x01
64 #define SCH56XX_REG_WDOG_OUTPUT_ENABLE 0x58E
65 #define SCH56XX_WDOG_OUTPUT_ENABLE 0x02
81 static inline int superio_inb(
int base,
int reg)
87 static inline int superio_enter(
int base)
91 pr_err(
"I/O address 0x%04x already in use\n", base);
106 static inline void superio_exit(
int base)
123 const int max_busy_polls = 64;
124 const int max_lazy_polls = 32;
131 outb(0x00, addr + 2);
132 outb(0x80, addr + 3);
136 outb(0x01, addr + 5);
137 outb(0x04, addr + 2);
144 outb(reg & 0xff, addr + 6);
145 outb(reg >> 8, addr + 7);
151 for (i = 0; i < max_busy_polls + max_lazy_polls; i++) {
152 if (i >= max_busy_polls)
163 if (i == max_busy_polls + max_lazy_polls) {
164 pr_err(
"Max retries exceeded reading virtual "
165 "register 0x%04hx (%d)\n", reg, 1);
173 for (i = 0; i < max_busy_polls; i++) {
181 pr_warn(
"EC reports: 0x%02x reading virtual register "
182 "0x%04hx\n", (
unsigned int)val, reg);
184 if (i == max_busy_polls) {
185 pr_err(
"Max retries exceeded reading virtual "
186 "register 0x%04hx (%d)\n", reg, 2);
202 return inb(addr + 4);
232 return lsb | (msb << 8);
251 return (msb << 4) | (lsn >> 4);
253 return (msb << 4) | (lsn & 0x0f);
263 static void watchdog_release_resources(
struct kref *
r)
271 unsigned int timeout)
274 unsigned int resolution;
284 if (timeout < resolution || timeout > (resolution * 255))
402 kref_get(&data->
kref);
409 kref_put(&data->
kref, watchdog_release_resources);
414 .start = watchdog_start,
415 .stop = watchdog_stop,
416 .ping = watchdog_trigger,
417 .set_timeout = watchdog_set_timeout,
419 .unref = watchdog_unref,
438 if (output_enable < 0)
441 pr_warn(
"Watchdog not enabled by BIOS, not registering\n");
451 kref_init(&data->
kref);
454 sizeof(data->
wdinfo.identity));
461 data->
wddev.ops = &watchdog_ops;
462 data->
wddev.parent = parent;
463 data->
wddev.timeout = 60;
464 data->
wddev.min_timeout = 1;
465 data->
wddev.max_timeout = 255 * 60;
468 if (output_enable & SCH56XX_WDOG_OUTPUT_ENABLE)
482 watchdog_set_drvdata(&data->
wddev, data);
485 pr_err(
"Registering watchdog chardev: %d\n", err);
497 kref_put(&data->
kref, watchdog_release_resources);
506 static int __init sch56xx_find(
int sioaddr,
const char **
name)
512 err = superio_enter(sioaddr);
525 pr_debug(
"Unsupported device id: 0x%02x\n",
526 (
unsigned int)devid);
534 pr_warn(
"Device not activated\n");
546 pr_warn(
"Base address not set\n");
553 superio_exit(sioaddr);
557 static int __init sch56xx_device_add(
int address,
const char *name)
573 goto exit_device_put;
577 pr_err(
"Device resource addition failed\n");
578 goto exit_device_put;
583 pr_err(
"Device addition failed\n");
584 goto exit_device_put;
595 static int __init sch56xx_init(
void)
598 const char *name =
NULL;
600 address = sch56xx_find(0x4e, &name);
602 address = sch56xx_find(0x2e, &name);
606 return sch56xx_device_add(address, name);
609 static void __exit sch56xx_exit(
void)