aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/booke_wdt.c
diff options
context:
space:
mode:
authorTang Yuantian <yuantian.tang@freescale.com>2014-05-07 22:04:26 -0400
committerWim Van Sebroeck <wim@iguana.be>2014-06-10 15:47:26 -0400
commitd2deebabaeedccf7cee943c1f7f6fdb44afd4e3d (patch)
tree608c9d7e57401f6782f84f3d068b8388cc7374e9 /drivers/watchdog/booke_wdt.c
parentec2e32ca661e7f2fe6c23efe202013f6ab5bf021 (diff)
booke/watchdog: refine and clean up the codes
Basically, this patch does the following: 1. Move the codes of parsing boot parameters from setup-common.c to driver. In this way, code reader can know directly that there are boot parameters that can change the timeout. 2. Make boot parameter 'booke_wdt_period' effective. currently, when driver is loaded, default timeout is always being used in stead of booke_wdt_period. 3. Wrap up the watchdog timeout in device struct and clean up unnecessary codes. Signed-off-by: Tang Yuantian <yuantian.tang@freescale.com> Acked-by: Scott Wood <scottwood@freescale.com> Reviewed-by: Li Yang <leoli@freescale.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog/booke_wdt.c')
-rw-r--r--drivers/watchdog/booke_wdt.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
index a8dbceb32914..08a785398eac 100644
--- a/drivers/watchdog/booke_wdt.c
+++ b/drivers/watchdog/booke_wdt.c
@@ -41,6 +41,28 @@ u32 booke_wdt_period = CONFIG_BOOKE_WDT_DEFAULT_TIMEOUT;
41#define WDTP_MASK (TCR_WP_MASK) 41#define WDTP_MASK (TCR_WP_MASK)
42#endif 42#endif
43 43
44/* Checks wdt=x and wdt_period=xx command-line option */
45notrace int __init early_parse_wdt(char *p)
46{
47 if (p && strncmp(p, "0", 1) != 0)
48 booke_wdt_enabled = 1;
49
50 return 0;
51}
52early_param("wdt", early_parse_wdt);
53
54int __init early_parse_wdt_period(char *p)
55{
56 unsigned long ret;
57 if (p) {
58 if (!kstrtol(p, 0, &ret))
59 booke_wdt_period = ret;
60 }
61
62 return 0;
63}
64early_param("wdt_period", early_parse_wdt_period);
65
44#ifdef CONFIG_PPC_FSL_BOOK3E 66#ifdef CONFIG_PPC_FSL_BOOK3E
45 67
46/* For the specified period, determine the number of seconds 68/* For the specified period, determine the number of seconds
@@ -103,17 +125,18 @@ static unsigned int sec_to_period(unsigned int secs)
103static void __booke_wdt_set(void *data) 125static void __booke_wdt_set(void *data)
104{ 126{
105 u32 val; 127 u32 val;
128 struct watchdog_device *wdog = data;
106 129
107 val = mfspr(SPRN_TCR); 130 val = mfspr(SPRN_TCR);
108 val &= ~WDTP_MASK; 131 val &= ~WDTP_MASK;
109 val |= WDTP(booke_wdt_period); 132 val |= WDTP(sec_to_period(wdog->timeout));
110 133
111 mtspr(SPRN_TCR, val); 134 mtspr(SPRN_TCR, val);
112} 135}
113 136
114static void booke_wdt_set(void) 137static void booke_wdt_set(void *data)
115{ 138{
116 on_each_cpu(__booke_wdt_set, NULL, 0); 139 on_each_cpu(__booke_wdt_set, data, 0);
117} 140}
118 141
119static void __booke_wdt_ping(void *data) 142static void __booke_wdt_ping(void *data)
@@ -131,12 +154,13 @@ static int booke_wdt_ping(struct watchdog_device *wdog)
131static void __booke_wdt_enable(void *data) 154static void __booke_wdt_enable(void *data)
132{ 155{
133 u32 val; 156 u32 val;
157 struct watchdog_device *wdog = data;
134 158
135 /* clear status before enabling watchdog */ 159 /* clear status before enabling watchdog */
136 __booke_wdt_ping(NULL); 160 __booke_wdt_ping(NULL);
137 val = mfspr(SPRN_TCR); 161 val = mfspr(SPRN_TCR);
138 val &= ~WDTP_MASK; 162 val &= ~WDTP_MASK;
139 val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(booke_wdt_period)); 163 val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(sec_to_period(wdog->timeout)));
140 164
141 mtspr(SPRN_TCR, val); 165 mtspr(SPRN_TCR, val);
142} 166}
@@ -162,25 +186,17 @@ static void __booke_wdt_disable(void *data)
162 186
163} 187}
164 188
165static void __booke_wdt_start(struct watchdog_device *wdog) 189static int booke_wdt_start(struct watchdog_device *wdog)
166{ 190{
167 on_each_cpu(__booke_wdt_enable, NULL, 0); 191 on_each_cpu(__booke_wdt_enable, wdog, 0);
168 pr_debug("watchdog enabled (timeout = %u sec)\n", wdog->timeout); 192 pr_debug("watchdog enabled (timeout = %u sec)\n", wdog->timeout);
169}
170 193
171static int booke_wdt_start(struct watchdog_device *wdog)
172{
173 if (booke_wdt_enabled == 0) {
174 booke_wdt_enabled = 1;
175 __booke_wdt_start(wdog);
176 }
177 return 0; 194 return 0;
178} 195}
179 196
180static int booke_wdt_stop(struct watchdog_device *wdog) 197static int booke_wdt_stop(struct watchdog_device *wdog)
181{ 198{
182 on_each_cpu(__booke_wdt_disable, NULL, 0); 199 on_each_cpu(__booke_wdt_disable, NULL, 0);
183 booke_wdt_enabled = 0;
184 pr_debug("watchdog disabled\n"); 200 pr_debug("watchdog disabled\n");
185 201
186 return 0; 202 return 0;
@@ -191,9 +207,8 @@ static int booke_wdt_set_timeout(struct watchdog_device *wdt_dev,
191{ 207{
192 if (timeout > MAX_WDT_TIMEOUT) 208 if (timeout > MAX_WDT_TIMEOUT)
193 return -EINVAL; 209 return -EINVAL;
194 booke_wdt_period = sec_to_period(timeout);
195 wdt_dev->timeout = timeout; 210 wdt_dev->timeout = timeout;
196 booke_wdt_set(); 211 booke_wdt_set(wdt_dev);
197 212
198 return 0; 213 return 0;
199} 214}
@@ -231,10 +246,10 @@ static int __init booke_wdt_init(void)
231 pr_info("powerpc book-e watchdog driver loaded\n"); 246 pr_info("powerpc book-e watchdog driver loaded\n");
232 booke_wdt_info.firmware_version = cur_cpu_spec->pvr_value; 247 booke_wdt_info.firmware_version = cur_cpu_spec->pvr_value;
233 booke_wdt_set_timeout(&booke_wdt_dev, 248 booke_wdt_set_timeout(&booke_wdt_dev,
234 period_to_sec(CONFIG_BOOKE_WDT_DEFAULT_TIMEOUT)); 249 period_to_sec(booke_wdt_period));
235 watchdog_set_nowayout(&booke_wdt_dev, nowayout); 250 watchdog_set_nowayout(&booke_wdt_dev, nowayout);
236 if (booke_wdt_enabled) 251 if (booke_wdt_enabled)
237 __booke_wdt_start(&booke_wdt_dev); 252 booke_wdt_start(&booke_wdt_dev);
238 253
239 ret = watchdog_register_device(&booke_wdt_dev); 254 ret = watchdog_register_device(&booke_wdt_dev);
240 255