1 // SPDX-License-Identifier: GPL-2.0
3 * Watchdog timer driver for the WinSystems EBC-C384
4 * Copyright (C) 2016 William Breathitt Gray
6 #include <linux/device.h>
8 #include <linux/errno.h>
10 #include <linux/ioport.h>
11 #include <linux/isa.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/types.h>
16 #include <linux/watchdog.h>
18 #define MODULE_NAME "ebc-c384_wdt"
19 #define WATCHDOG_TIMEOUT 60
21 * The timeout value in minutes must fit in a single byte when sent to the
22 * watchdog timer; the maximum timeout possible is 15300 (255 * 60) seconds.
24 #define WATCHDOG_MAX_TIMEOUT 15300
25 #define BASE_ADDR 0x564
27 #define CFG_ADDR (BASE_ADDR + 1)
28 #define PET_ADDR (BASE_ADDR + 2)
30 static bool nowayout
= WATCHDOG_NOWAYOUT
;
31 module_param(nowayout
, bool, 0);
32 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started (default="
33 __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
35 static unsigned timeout
;
36 module_param(timeout
, uint
, 0);
37 MODULE_PARM_DESC(timeout
, "Watchdog timeout in seconds (default="
38 __MODULE_STRING(WATCHDOG_TIMEOUT
) ")");
40 static int ebc_c384_wdt_start(struct watchdog_device
*wdev
)
42 unsigned t
= wdev
->timeout
;
44 /* resolution is in minutes for timeouts greater than 255 seconds */
46 t
= DIV_ROUND_UP(t
, 60);
53 static int ebc_c384_wdt_stop(struct watchdog_device
*wdev
)
60 static int ebc_c384_wdt_set_timeout(struct watchdog_device
*wdev
, unsigned t
)
62 /* resolution is in minutes for timeouts greater than 255 seconds */
64 /* round second resolution up to minute granularity */
65 wdev
->timeout
= roundup(t
, 60);
67 /* set watchdog timer for minutes */
72 /* set watchdog timer for seconds */
79 static const struct watchdog_ops ebc_c384_wdt_ops
= {
80 .start
= ebc_c384_wdt_start
,
81 .stop
= ebc_c384_wdt_stop
,
82 .set_timeout
= ebc_c384_wdt_set_timeout
85 static const struct watchdog_info ebc_c384_wdt_info
= {
86 .options
= WDIOF_KEEPALIVEPING
| WDIOF_MAGICCLOSE
| WDIOF_SETTIMEOUT
,
87 .identity
= MODULE_NAME
90 static int ebc_c384_wdt_probe(struct device
*dev
, unsigned int id
)
92 struct watchdog_device
*wdd
;
94 if (!devm_request_region(dev
, BASE_ADDR
, ADDR_EXTENT
, dev_name(dev
))) {
95 dev_err(dev
, "Unable to lock port addresses (0x%X-0x%X)\n",
96 BASE_ADDR
, BASE_ADDR
+ ADDR_EXTENT
);
100 wdd
= devm_kzalloc(dev
, sizeof(*wdd
), GFP_KERNEL
);
104 wdd
->info
= &ebc_c384_wdt_info
;
105 wdd
->ops
= &ebc_c384_wdt_ops
;
106 wdd
->timeout
= WATCHDOG_TIMEOUT
;
107 wdd
->min_timeout
= 1;
108 wdd
->max_timeout
= WATCHDOG_MAX_TIMEOUT
;
110 watchdog_set_nowayout(wdd
, nowayout
);
111 watchdog_init_timeout(wdd
, timeout
, dev
);
113 return devm_watchdog_register_device(dev
, wdd
);
116 static struct isa_driver ebc_c384_wdt_driver
= {
117 .probe
= ebc_c384_wdt_probe
,
123 static int __init
ebc_c384_wdt_init(void)
125 if (!dmi_match(DMI_BOARD_NAME
, "EBC-C384 SBC"))
128 return isa_register_driver(&ebc_c384_wdt_driver
, 1);
131 static void __exit
ebc_c384_wdt_exit(void)
133 isa_unregister_driver(&ebc_c384_wdt_driver
);
136 module_init(ebc_c384_wdt_init
);
137 module_exit(ebc_c384_wdt_exit
);
139 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
140 MODULE_DESCRIPTION("WinSystems EBC-C384 watchdog timer driver");
141 MODULE_LICENSE("GPL v2");
142 MODULE_ALIAS("isa:" MODULE_NAME
);