Commit c36a483d80072f7efdd09e94dd733120dc8ecfb2
Committed by
Wim Van Sebroeck
1 parent
70f3997667
watchdog: Add watchdog timer support for the WinSystems EBC-C384
The WinSystems EBC-C384 has an onboard watchdog timer. The timeout range supported by the watchdog timer is 1 second to 255 minutes. Timeouts under 256 seconds have a 1 second granularity, while the rest have a 1 minute granularity. This driver adds watchdog timer support for this onboard watchdog timer. The timeout may be configured via the timeout module parameter. Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Showing 4 changed files with 204 additions and 0 deletions Side-by-side Diff
MAINTAINERS
... | ... | @@ -11870,6 +11870,12 @@ |
11870 | 11870 | S: Maintained |
11871 | 11871 | F: drivers/media/rc/winbond-cir.c |
11872 | 11872 | |
11873 | +WINSYSTEMS EBC-C384 WATCHDOG DRIVER | |
11874 | +M: William Breathitt Gray <vilhelm.gray@gmail.com> | |
11875 | +L: linux-watchdog@vger.kernel.org | |
11876 | +S: Maintained | |
11877 | +F: drivers/watchdog/ebc-c384_wdt.c | |
11878 | + | |
11873 | 11879 | WIMAX STACK |
11874 | 11880 | M: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> |
11875 | 11881 | M: linux-wimax@intel.com |
drivers/watchdog/Kconfig
... | ... | @@ -715,6 +715,15 @@ |
715 | 715 | |
716 | 716 | Most people will say N. |
717 | 717 | |
718 | +config EBC_C384_WDT | |
719 | + tristate "WinSystems EBC-C384 Watchdog Timer" | |
720 | + depends on X86 | |
721 | + select WATCHDOG_CORE | |
722 | + help | |
723 | + Enables watchdog timer support for the watchdog timer on the | |
724 | + WinSystems EBC-C384 motherboard. The timeout may be configured via | |
725 | + the timeout module parameter. | |
726 | + | |
718 | 727 | config F71808E_WDT |
719 | 728 | tristate "Fintek F71808E, F71862FG, F71869, F71882FG and F71889FG Watchdog" |
720 | 729 | depends on X86 |
drivers/watchdog/Makefile
... | ... | @@ -88,6 +88,7 @@ |
88 | 88 | obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o |
89 | 89 | obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o |
90 | 90 | obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o |
91 | +obj-$(CONFIG_EBC_C384_WDT) += ebc-c384_wdt.o | |
91 | 92 | obj-$(CONFIG_F71808E_WDT) += f71808e_wdt.o |
92 | 93 | obj-$(CONFIG_SP5100_TCO) += sp5100_tco.o |
93 | 94 | obj-$(CONFIG_GEODE_WDT) += geodewdt.o |
drivers/watchdog/ebc-c384_wdt.c
1 | +/* | |
2 | + * Watchdog timer driver for the WinSystems EBC-C384 | |
3 | + * Copyright (C) 2016 William Breathitt Gray | |
4 | + * | |
5 | + * This program is free software; you can redistribute it and/or modify | |
6 | + * it under the terms of the GNU General Public License, version 2, as | |
7 | + * published by the Free Software Foundation. | |
8 | + * | |
9 | + * This program is distributed in the hope that it will be useful, but | |
10 | + * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | + * General Public License for more details. | |
13 | + */ | |
14 | +#include <linux/device.h> | |
15 | +#include <linux/dmi.h> | |
16 | +#include <linux/errno.h> | |
17 | +#include <linux/io.h> | |
18 | +#include <linux/ioport.h> | |
19 | +#include <linux/kernel.h> | |
20 | +#include <linux/module.h> | |
21 | +#include <linux/moduleparam.h> | |
22 | +#include <linux/platform_device.h> | |
23 | +#include <linux/types.h> | |
24 | +#include <linux/watchdog.h> | |
25 | + | |
26 | +#define MODULE_NAME "ebc-c384_wdt" | |
27 | +#define WATCHDOG_TIMEOUT 60 | |
28 | +/* | |
29 | + * The timeout value in minutes must fit in a single byte when sent to the | |
30 | + * watchdog timer; the maximum timeout possible is 15300 (255 * 60) seconds. | |
31 | + */ | |
32 | +#define WATCHDOG_MAX_TIMEOUT 15300 | |
33 | +#define BASE_ADDR 0x564 | |
34 | +#define ADDR_EXTENT 5 | |
35 | +#define CFG_ADDR (BASE_ADDR + 1) | |
36 | +#define PET_ADDR (BASE_ADDR + 2) | |
37 | + | |
38 | +static bool nowayout = WATCHDOG_NOWAYOUT; | |
39 | +module_param(nowayout, bool, 0); | |
40 | +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" | |
41 | + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | |
42 | + | |
43 | +static unsigned timeout; | |
44 | +module_param(timeout, uint, 0); | |
45 | +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" | |
46 | + __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); | |
47 | + | |
48 | +static int ebc_c384_wdt_start(struct watchdog_device *wdev) | |
49 | +{ | |
50 | + unsigned t = wdev->timeout; | |
51 | + | |
52 | + /* resolution is in minutes for timeouts greater than 255 seconds */ | |
53 | + if (t > 255) | |
54 | + t = DIV_ROUND_UP(t, 60); | |
55 | + | |
56 | + outb(t, PET_ADDR); | |
57 | + | |
58 | + return 0; | |
59 | +} | |
60 | + | |
61 | +static int ebc_c384_wdt_stop(struct watchdog_device *wdev) | |
62 | +{ | |
63 | + outb(0x00, PET_ADDR); | |
64 | + | |
65 | + return 0; | |
66 | +} | |
67 | + | |
68 | +static int ebc_c384_wdt_set_timeout(struct watchdog_device *wdev, unsigned t) | |
69 | +{ | |
70 | + /* resolution is in minutes for timeouts greater than 255 seconds */ | |
71 | + if (t > 255) { | |
72 | + /* round second resolution up to minute granularity */ | |
73 | + wdev->timeout = roundup(t, 60); | |
74 | + | |
75 | + /* set watchdog timer for minutes */ | |
76 | + outb(0x00, CFG_ADDR); | |
77 | + } else { | |
78 | + wdev->timeout = t; | |
79 | + | |
80 | + /* set watchdog timer for seconds */ | |
81 | + outb(0x80, CFG_ADDR); | |
82 | + } | |
83 | + | |
84 | + return 0; | |
85 | +} | |
86 | + | |
87 | +static const struct watchdog_ops ebc_c384_wdt_ops = { | |
88 | + .start = ebc_c384_wdt_start, | |
89 | + .stop = ebc_c384_wdt_stop, | |
90 | + .set_timeout = ebc_c384_wdt_set_timeout | |
91 | +}; | |
92 | + | |
93 | +static const struct watchdog_info ebc_c384_wdt_info = { | |
94 | + .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT, | |
95 | + .identity = MODULE_NAME | |
96 | +}; | |
97 | + | |
98 | +static int __init ebc_c384_wdt_probe(struct platform_device *pdev) | |
99 | +{ | |
100 | + struct device *dev = &pdev->dev; | |
101 | + struct watchdog_device *wdd; | |
102 | + | |
103 | + if (!devm_request_region(dev, BASE_ADDR, ADDR_EXTENT, dev_name(dev))) { | |
104 | + dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", | |
105 | + BASE_ADDR, BASE_ADDR + ADDR_EXTENT); | |
106 | + return -EBUSY; | |
107 | + } | |
108 | + | |
109 | + wdd = devm_kzalloc(dev, sizeof(*wdd), GFP_KERNEL); | |
110 | + if (!wdd) | |
111 | + return -ENOMEM; | |
112 | + | |
113 | + wdd->info = &ebc_c384_wdt_info; | |
114 | + wdd->ops = &ebc_c384_wdt_ops; | |
115 | + wdd->timeout = WATCHDOG_TIMEOUT; | |
116 | + wdd->min_timeout = 1; | |
117 | + wdd->max_timeout = WATCHDOG_MAX_TIMEOUT; | |
118 | + | |
119 | + watchdog_set_nowayout(wdd, nowayout); | |
120 | + | |
121 | + if (watchdog_init_timeout(wdd, timeout, dev)) | |
122 | + dev_warn(dev, "Invalid timeout (%u seconds), using default (%u seconds)\n", | |
123 | + timeout, WATCHDOG_TIMEOUT); | |
124 | + | |
125 | + platform_set_drvdata(pdev, wdd); | |
126 | + | |
127 | + return watchdog_register_device(wdd); | |
128 | +} | |
129 | + | |
130 | +static int ebc_c384_wdt_remove(struct platform_device *pdev) | |
131 | +{ | |
132 | + struct watchdog_device *wdd = platform_get_drvdata(pdev); | |
133 | + | |
134 | + watchdog_unregister_device(wdd); | |
135 | + | |
136 | + return 0; | |
137 | +} | |
138 | + | |
139 | +static struct platform_driver ebc_c384_wdt_driver = { | |
140 | + .driver = { | |
141 | + .name = MODULE_NAME | |
142 | + }, | |
143 | + .remove = ebc_c384_wdt_remove | |
144 | +}; | |
145 | + | |
146 | +static struct platform_device *ebc_c384_wdt_device; | |
147 | + | |
148 | +static int __init ebc_c384_wdt_init(void) | |
149 | +{ | |
150 | + int err; | |
151 | + | |
152 | + if (!dmi_match(DMI_BOARD_NAME, "EBC-C384 SBC")) | |
153 | + return -ENODEV; | |
154 | + | |
155 | + ebc_c384_wdt_device = platform_device_alloc(MODULE_NAME, -1); | |
156 | + if (!ebc_c384_wdt_device) | |
157 | + return -ENOMEM; | |
158 | + | |
159 | + err = platform_device_add(ebc_c384_wdt_device); | |
160 | + if (err) | |
161 | + goto err_platform_device; | |
162 | + | |
163 | + err = platform_driver_probe(&ebc_c384_wdt_driver, ebc_c384_wdt_probe); | |
164 | + if (err) | |
165 | + goto err_platform_driver; | |
166 | + | |
167 | + return 0; | |
168 | + | |
169 | +err_platform_driver: | |
170 | + platform_device_del(ebc_c384_wdt_device); | |
171 | +err_platform_device: | |
172 | + platform_device_put(ebc_c384_wdt_device); | |
173 | + return err; | |
174 | +} | |
175 | + | |
176 | +static void __exit ebc_c384_wdt_exit(void) | |
177 | +{ | |
178 | + platform_device_unregister(ebc_c384_wdt_device); | |
179 | + platform_driver_unregister(&ebc_c384_wdt_driver); | |
180 | +} | |
181 | + | |
182 | +module_init(ebc_c384_wdt_init); | |
183 | +module_exit(ebc_c384_wdt_exit); | |
184 | + | |
185 | +MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>"); | |
186 | +MODULE_DESCRIPTION("WinSystems EBC-C384 watchdog timer driver"); | |
187 | +MODULE_LICENSE("GPL v2"); | |
188 | +MODULE_ALIAS("platform:" MODULE_NAME); |