diff options
author | Philippe De Muyter <phdm@macqel.be> | 2010-11-03 10:07:28 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2011-01-12 08:51:35 -0500 |
commit | 88cce427626070f7d7eb33994e3ff7b4db3292c5 (patch) | |
tree | aa850dddf757ecf9455cbbe4ab77fee54a4e1ef3 | |
parent | f8394f61c66f48b1fe9d6964ddce492d7f9a4cd9 (diff) |
watchdog: Add MCF548x watchdog driver.
Add watchdog driver for MCF548x.
Signed-off-by: Philippe De Muyter <phdm@macqel.be>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
-rw-r--r-- | arch/m68k/include/asm/m548xgpt.h | 2 | ||||
-rw-r--r-- | drivers/watchdog/Kconfig | 7 | ||||
-rw-r--r-- | drivers/watchdog/Makefile | 3 | ||||
-rw-r--r-- | drivers/watchdog/m548x_wdt.c | 227 |
4 files changed, 236 insertions, 3 deletions
diff --git a/arch/m68k/include/asm/m548xgpt.h b/arch/m68k/include/asm/m548xgpt.h index c8ef158a1c4e..33b2eef90f0a 100644 --- a/arch/m68k/include/asm/m548xgpt.h +++ b/arch/m68k/include/asm/m548xgpt.h | |||
@@ -59,11 +59,13 @@ | |||
59 | #define MCF_GPT_GMS_GPIO_INPUT (0x00000000) | 59 | #define MCF_GPT_GMS_GPIO_INPUT (0x00000000) |
60 | #define MCF_GPT_GMS_GPIO_OUTLO (0x00000020) | 60 | #define MCF_GPT_GMS_GPIO_OUTLO (0x00000020) |
61 | #define MCF_GPT_GMS_GPIO_OUTHI (0x00000030) | 61 | #define MCF_GPT_GMS_GPIO_OUTHI (0x00000030) |
62 | #define MCF_GPT_GMS_GPIO_MASK (0x00000030) | ||
62 | #define MCF_GPT_GMS_TMS_DISABLE (0x00000000) | 63 | #define MCF_GPT_GMS_TMS_DISABLE (0x00000000) |
63 | #define MCF_GPT_GMS_TMS_INCAPT (0x00000001) | 64 | #define MCF_GPT_GMS_TMS_INCAPT (0x00000001) |
64 | #define MCF_GPT_GMS_TMS_OUTCAPT (0x00000002) | 65 | #define MCF_GPT_GMS_TMS_OUTCAPT (0x00000002) |
65 | #define MCF_GPT_GMS_TMS_PWM (0x00000003) | 66 | #define MCF_GPT_GMS_TMS_PWM (0x00000003) |
66 | #define MCF_GPT_GMS_TMS_GPIO (0x00000004) | 67 | #define MCF_GPT_GMS_TMS_GPIO (0x00000004) |
68 | #define MCF_GPT_GMS_TMS_MASK (0x00000007) | ||
67 | 69 | ||
68 | /* Bit definitions and macros for MCF_GPT_GCIR */ | 70 | /* Bit definitions and macros for MCF_GPT_GCIR */ |
69 | #define MCF_GPT_GCIR_CNT(x) (((x)&0x0000FFFF)<<0) | 71 | #define MCF_GPT_GCIR_CNT(x) (((x)&0x0000FFFF)<<0) |
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 68a9527f92d0..2e2400e7322e 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig | |||
@@ -862,7 +862,12 @@ config SBC_EPX_C3_WATCHDOG | |||
862 | 862 | ||
863 | # M68K Architecture | 863 | # M68K Architecture |
864 | 864 | ||
865 | # M68KNOMMU Architecture | 865 | config M548x_WATCHDOG |
866 | tristate "MCF548x watchdog support" | ||
867 | depends on M548x | ||
868 | help | ||
869 | To compile this driver as a module, choose M here: the | ||
870 | module will be called m548x_wdt. | ||
866 | 871 | ||
867 | # MIPS Architecture | 872 | # MIPS Architecture |
868 | 873 | ||
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 9b6b33a02072..dd776651917c 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile | |||
@@ -106,8 +106,7 @@ obj-$(CONFIG_SBC_EPX_C3_WATCHDOG) += sbc_epx_c3.o | |||
106 | # M32R Architecture | 106 | # M32R Architecture |
107 | 107 | ||
108 | # M68K Architecture | 108 | # M68K Architecture |
109 | 109 | obj-$(CONFIG_M548x_WATCHDOG) += m548x_wdt.o | |
110 | # M68KNOMMU Architecture | ||
111 | 110 | ||
112 | # MIPS Architecture | 111 | # MIPS Architecture |
113 | obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o | 112 | obj-$(CONFIG_ATH79_WDT) += ath79_wdt.o |
diff --git a/drivers/watchdog/m548x_wdt.c b/drivers/watchdog/m548x_wdt.c new file mode 100644 index 000000000000..cabbcfe1c847 --- /dev/null +++ b/drivers/watchdog/m548x_wdt.c | |||
@@ -0,0 +1,227 @@ | |||
1 | /* | ||
2 | * drivers/watchdog/m548x_wdt.c | ||
3 | * | ||
4 | * Watchdog driver for ColdFire MCF548x processors | ||
5 | * Copyright 2010 (c) Philippe De Muyter <phdm@macqel.be> | ||
6 | * | ||
7 | * Adapted from the IXP4xx watchdog driver, which carries these notices: | ||
8 | * | ||
9 | * Author: Deepak Saxena <dsaxena@plexity.net> | ||
10 | * | ||
11 | * Copyright 2004 (c) MontaVista, Software, Inc. | ||
12 | * Based on sa1100 driver, Copyright (C) 2000 Oleg Drokin <green@crimea.edu> | ||
13 | * | ||
14 | * This file is licensed under the terms of the GNU General Public | ||
15 | * License version 2. This program is licensed "as is" without any | ||
16 | * warranty of any kind, whether express or implied. | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/moduleparam.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/fs.h> | ||
24 | #include <linux/miscdevice.h> | ||
25 | #include <linux/watchdog.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/bitops.h> | ||
28 | #include <linux/ioport.h> | ||
29 | #include <linux/uaccess.h> | ||
30 | |||
31 | #include <asm/coldfire.h> | ||
32 | #include <asm/m548xsim.h> | ||
33 | #include <asm/m548xgpt.h> | ||
34 | |||
35 | static int nowayout = WATCHDOG_NOWAYOUT; | ||
36 | static unsigned int heartbeat = 30; /* (secs) Default is 0.5 minute */ | ||
37 | static unsigned long wdt_status; | ||
38 | |||
39 | #define WDT_IN_USE 0 | ||
40 | #define WDT_OK_TO_CLOSE 1 | ||
41 | |||
42 | static void wdt_enable(void) | ||
43 | { | ||
44 | unsigned int gms0; | ||
45 | |||
46 | /* preserve GPIO usage, if any */ | ||
47 | gms0 = __raw_readl(MCF_MBAR + MCF_GPT_GMS0); | ||
48 | if (gms0 & MCF_GPT_GMS_TMS_GPIO) | ||
49 | gms0 &= (MCF_GPT_GMS_TMS_GPIO | MCF_GPT_GMS_GPIO_MASK | ||
50 | | MCF_GPT_GMS_OD); | ||
51 | else | ||
52 | gms0 = MCF_GPT_GMS_TMS_GPIO | MCF_GPT_GMS_OD; | ||
53 | __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0); | ||
54 | __raw_writel(MCF_GPT_GCIR_PRE(heartbeat*(MCF_BUSCLK/0xffff)) | | ||
55 | MCF_GPT_GCIR_CNT(0xffff), MCF_MBAR + MCF_GPT_GCIR0); | ||
56 | gms0 |= MCF_GPT_GMS_OCPW(0xA5) | MCF_GPT_GMS_WDEN | MCF_GPT_GMS_CE; | ||
57 | __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0); | ||
58 | } | ||
59 | |||
60 | static void wdt_disable(void) | ||
61 | { | ||
62 | unsigned int gms0; | ||
63 | |||
64 | /* disable watchdog */ | ||
65 | gms0 = __raw_readl(MCF_MBAR + MCF_GPT_GMS0); | ||
66 | gms0 &= ~(MCF_GPT_GMS_WDEN | MCF_GPT_GMS_CE); | ||
67 | __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0); | ||
68 | } | ||
69 | |||
70 | static void wdt_keepalive(void) | ||
71 | { | ||
72 | unsigned int gms0; | ||
73 | |||
74 | gms0 = __raw_readl(MCF_MBAR + MCF_GPT_GMS0); | ||
75 | gms0 |= MCF_GPT_GMS_OCPW(0xA5); | ||
76 | __raw_writel(gms0, MCF_MBAR + MCF_GPT_GMS0); | ||
77 | } | ||
78 | |||
79 | static int m548x_wdt_open(struct inode *inode, struct file *file) | ||
80 | { | ||
81 | if (test_and_set_bit(WDT_IN_USE, &wdt_status)) | ||
82 | return -EBUSY; | ||
83 | |||
84 | clear_bit(WDT_OK_TO_CLOSE, &wdt_status); | ||
85 | wdt_enable(); | ||
86 | return nonseekable_open(inode, file); | ||
87 | } | ||
88 | |||
89 | static ssize_t m548x_wdt_write(struct file *file, const char *data, | ||
90 | size_t len, loff_t *ppos) | ||
91 | { | ||
92 | if (len) { | ||
93 | if (!nowayout) { | ||
94 | size_t i; | ||
95 | |||
96 | clear_bit(WDT_OK_TO_CLOSE, &wdt_status); | ||
97 | |||
98 | for (i = 0; i != len; i++) { | ||
99 | char c; | ||
100 | |||
101 | if (get_user(c, data + i)) | ||
102 | return -EFAULT; | ||
103 | if (c == 'V') | ||
104 | set_bit(WDT_OK_TO_CLOSE, &wdt_status); | ||
105 | } | ||
106 | } | ||
107 | wdt_keepalive(); | ||
108 | } | ||
109 | return len; | ||
110 | } | ||
111 | |||
112 | static const struct watchdog_info ident = { | ||
113 | .options = WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT | | ||
114 | WDIOF_KEEPALIVEPING, | ||
115 | .identity = "Coldfire M548x Watchdog", | ||
116 | }; | ||
117 | |||
118 | static long m548x_wdt_ioctl(struct file *file, unsigned int cmd, | ||
119 | unsigned long arg) | ||
120 | { | ||
121 | int ret = -ENOTTY; | ||
122 | int time; | ||
123 | |||
124 | switch (cmd) { | ||
125 | case WDIOC_GETSUPPORT: | ||
126 | ret = copy_to_user((struct watchdog_info *)arg, &ident, | ||
127 | sizeof(ident)) ? -EFAULT : 0; | ||
128 | break; | ||
129 | |||
130 | case WDIOC_GETSTATUS: | ||
131 | ret = put_user(0, (int *)arg); | ||
132 | break; | ||
133 | |||
134 | case WDIOC_GETBOOTSTATUS: | ||
135 | ret = put_user(0, (int *)arg); | ||
136 | break; | ||
137 | |||
138 | case WDIOC_KEEPALIVE: | ||
139 | wdt_keepalive(); | ||
140 | ret = 0; | ||
141 | break; | ||
142 | |||
143 | case WDIOC_SETTIMEOUT: | ||
144 | ret = get_user(time, (int *)arg); | ||
145 | if (ret) | ||
146 | break; | ||
147 | |||
148 | if (time <= 0 || time > 30) { | ||
149 | ret = -EINVAL; | ||
150 | break; | ||
151 | } | ||
152 | |||
153 | heartbeat = time; | ||
154 | wdt_enable(); | ||
155 | /* Fall through */ | ||
156 | |||
157 | case WDIOC_GETTIMEOUT: | ||
158 | ret = put_user(heartbeat, (int *)arg); | ||
159 | break; | ||
160 | } | ||
161 | return ret; | ||
162 | } | ||
163 | |||
164 | static int m548x_wdt_release(struct inode *inode, struct file *file) | ||
165 | { | ||
166 | if (test_bit(WDT_OK_TO_CLOSE, &wdt_status)) | ||
167 | wdt_disable(); | ||
168 | else { | ||
169 | printk(KERN_CRIT "WATCHDOG: Device closed unexpectedly - " | ||
170 | "timer will not stop\n"); | ||
171 | wdt_keepalive(); | ||
172 | } | ||
173 | clear_bit(WDT_IN_USE, &wdt_status); | ||
174 | clear_bit(WDT_OK_TO_CLOSE, &wdt_status); | ||
175 | |||
176 | return 0; | ||
177 | } | ||
178 | |||
179 | |||
180 | static const struct file_operations m548x_wdt_fops = { | ||
181 | .owner = THIS_MODULE, | ||
182 | .llseek = no_llseek, | ||
183 | .write = m548x_wdt_write, | ||
184 | .unlocked_ioctl = m548x_wdt_ioctl, | ||
185 | .open = m548x_wdt_open, | ||
186 | .release = m548x_wdt_release, | ||
187 | }; | ||
188 | |||
189 | static struct miscdevice m548x_wdt_miscdev = { | ||
190 | .minor = WATCHDOG_MINOR, | ||
191 | .name = "watchdog", | ||
192 | .fops = &m548x_wdt_fops, | ||
193 | }; | ||
194 | |||
195 | static int __init m548x_wdt_init(void) | ||
196 | { | ||
197 | if (!request_mem_region(MCF_MBAR + MCF_GPT_GCIR0, 4, | ||
198 | "Coldfire M548x Watchdog")) { | ||
199 | printk(KERN_WARNING | ||
200 | "Coldfire M548x Watchdog : I/O region busy\n"); | ||
201 | return -EBUSY; | ||
202 | } | ||
203 | printk(KERN_INFO "ColdFire watchdog driver is loaded.\n"); | ||
204 | |||
205 | return misc_register(&m548x_wdt_miscdev); | ||
206 | } | ||
207 | |||
208 | static void __exit m548x_wdt_exit(void) | ||
209 | { | ||
210 | misc_deregister(&m548x_wdt_miscdev); | ||
211 | release_mem_region(MCF_MBAR + MCF_GPT_GCIR0, 4); | ||
212 | } | ||
213 | |||
214 | module_init(m548x_wdt_init); | ||
215 | module_exit(m548x_wdt_exit); | ||
216 | |||
217 | MODULE_AUTHOR("Philippe De Muyter <phdm@macqel.be>"); | ||
218 | MODULE_DESCRIPTION("Coldfire M548x Watchdog"); | ||
219 | |||
220 | module_param(heartbeat, int, 0); | ||
221 | MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds (default 30s)"); | ||
222 | |||
223 | module_param(nowayout, int, 0); | ||
224 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"); | ||
225 | |||
226 | MODULE_LICENSE("GPL"); | ||
227 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | ||