blob: 52e94e627ba078ea40edd7be7520b0682e2c5a71 [file] [log] [blame]
Mitchel Humpherys0d89e942012-12-13 16:56:46 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Hanumant72aec702012-06-25 11:51:07 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/io.h>
16#include <linux/delay.h>
17#include <linux/workqueue.h>
18#include <linux/slab.h>
19#include <linux/jiffies.h>
Hanumant Singh42ffa442012-08-27 12:26:08 -070020#include <linux/mutex.h>
Hanumant72aec702012-06-25 11:51:07 -070021#include <linux/sched.h>
22#include <linux/interrupt.h>
Hanumant Singh97cf75a2012-08-22 14:07:29 -070023#include <linux/irq.h>
24#include <linux/percpu.h>
Hanumant72aec702012-06-25 11:51:07 -070025#include <linux/of.h>
26#include <linux/cpu.h>
27#include <linux/platform_device.h>
Hanumant Singh15784c82012-08-02 17:37:04 -070028#include <mach/scm.h>
29#include <mach/msm_memory_dump.h>
Hanumant72aec702012-06-25 11:51:07 -070030
31#define MODULE_NAME "msm_watchdog"
32#define WDT0_ACCSCSSNBARK_INT 0
33#define TCSR_WDT_CFG 0x30
34#define WDT0_RST 0x04
35#define WDT0_EN 0x08
36#define WDT0_STS 0x0C
37#define WDT0_BARK_TIME 0x10
38#define WDT0_BITE_TIME 0x14
39
Hanumant Singh15784c82012-08-02 17:37:04 -070040#define MASK_SIZE 32
41#define SCM_SET_REGSAVE_CMD 0x2
Hanumant Singh42ffa442012-08-27 12:26:08 -070042#define SCM_SVC_SEC_WDOG_DIS 0x7
Hanumant72aec702012-06-25 11:51:07 -070043
Mitchel Humpherys0d89e942012-12-13 16:56:46 -080044static struct workqueue_struct *wdog_wq;
45
Hanumant72aec702012-06-25 11:51:07 -070046struct msm_watchdog_data {
47 unsigned int __iomem phys_base;
48 size_t size;
49 void __iomem *base;
50 struct device *dev;
51 unsigned int pet_time;
52 unsigned int bark_time;
53 unsigned int bark_irq;
54 unsigned int bite_irq;
Mitchel Humpherys1be23802012-11-16 15:52:32 -080055 bool do_ipi_ping;
Hanumant72aec702012-06-25 11:51:07 -070056 unsigned long long last_pet;
57 unsigned min_slack_ticks;
58 unsigned long long min_slack_ns;
Hanumant Singh15784c82012-08-02 17:37:04 -070059 void *scm_regsave;
Hanumant72aec702012-06-25 11:51:07 -070060 cpumask_t alive_mask;
Hanumant Singh42ffa442012-08-27 12:26:08 -070061 struct mutex disable_lock;
Hanumant72aec702012-06-25 11:51:07 -070062 struct work_struct init_dogwork_struct;
63 struct delayed_work dogwork_struct;
Hanumant Singh97cf75a2012-08-22 14:07:29 -070064 bool irq_ppi;
65 struct msm_watchdog_data __percpu **wdog_cpu_dd;
Hanumant72aec702012-06-25 11:51:07 -070066 struct notifier_block panic_blk;
67};
68
69/*
70 * On the kernel command line specify
71 * msm_watchdog.enable=1 to enable the watchdog
72 * By default watchdog is turned on
73 */
74static int enable = 1;
75module_param(enable, int, 0);
76
77/*
78 * On the kernel command line specify
79 * msm_watchdog.WDT_HZ=<clock val in HZ> to set Watchdog
80 * ticks. By default it is set to 32765.
81 */
82static long WDT_HZ = 32765;
83module_param(WDT_HZ, long, 0);
84
Hanumant72aec702012-06-25 11:51:07 -070085static void pet_watchdog_work(struct work_struct *work);
86static void init_watchdog_work(struct work_struct *work);
87
88static void dump_cpu_alive_mask(struct msm_watchdog_data *wdog_dd)
89{
90 static char alive_mask_buf[MASK_SIZE];
Hanumant Singha876ba62012-08-17 13:46:42 -070091 cpulist_scnprintf(alive_mask_buf, MASK_SIZE,
Hanumant72aec702012-06-25 11:51:07 -070092 &wdog_dd->alive_mask);
Hanumant Singha876ba62012-08-17 13:46:42 -070093 printk(KERN_INFO "cpu alive mask from last pet %s\n", alive_mask_buf);
Hanumant72aec702012-06-25 11:51:07 -070094}
95
96static int msm_watchdog_suspend(struct device *dev)
97{
98 struct msm_watchdog_data *wdog_dd =
99 (struct msm_watchdog_data *)dev_get_drvdata(dev);
100 if (!enable)
101 return 0;
102 __raw_writel(1, wdog_dd->base + WDT0_RST);
103 __raw_writel(0, wdog_dd->base + WDT0_EN);
104 mb();
105 return 0;
106}
107
108static int msm_watchdog_resume(struct device *dev)
109{
110 struct msm_watchdog_data *wdog_dd =
111 (struct msm_watchdog_data *)dev_get_drvdata(dev);
112 if (!enable)
113 return 0;
114 __raw_writel(1, wdog_dd->base + WDT0_EN);
115 __raw_writel(1, wdog_dd->base + WDT0_RST);
116 mb();
117 return 0;
118}
119
120static int panic_wdog_handler(struct notifier_block *this,
121 unsigned long event, void *ptr)
122{
123 struct msm_watchdog_data *wdog_dd = container_of(this,
124 struct msm_watchdog_data, panic_blk);
125 if (panic_timeout == 0) {
126 __raw_writel(0, wdog_dd->base + WDT0_EN);
127 mb();
128 } else {
129 __raw_writel(WDT_HZ * (panic_timeout + 4),
130 wdog_dd->base + WDT0_BARK_TIME);
131 __raw_writel(WDT_HZ * (panic_timeout + 4),
132 wdog_dd->base + WDT0_BITE_TIME);
133 __raw_writel(1, wdog_dd->base + WDT0_RST);
134 }
135 return NOTIFY_DONE;
136}
Hanumant Singh42ffa442012-08-27 12:26:08 -0700137
138static void wdog_disable(struct msm_watchdog_data *wdog_dd)
Hanumant72aec702012-06-25 11:51:07 -0700139{
Hanumant Singh42ffa442012-08-27 12:26:08 -0700140 __raw_writel(0, wdog_dd->base + WDT0_EN);
141 mb();
142 if (wdog_dd->irq_ppi) {
143 disable_percpu_irq(wdog_dd->bark_irq);
144 free_percpu_irq(wdog_dd->bark_irq, wdog_dd->wdog_cpu_dd);
145 } else
146 devm_free_irq(wdog_dd->dev, wdog_dd->bark_irq, wdog_dd);
147 enable = 0;
148 /*Ensure all cpus see update to enable*/
149 smp_mb();
150 atomic_notifier_chain_unregister(&panic_notifier_list,
151 &wdog_dd->panic_blk);
152 cancel_delayed_work_sync(&wdog_dd->dogwork_struct);
153 /* may be suspended after the first write above */
154 __raw_writel(0, wdog_dd->base + WDT0_EN);
155 mb();
156 pr_info("MSM Apps Watchdog deactivated.\n");
Hanumant72aec702012-06-25 11:51:07 -0700157}
158
Hanumant Singh42ffa442012-08-27 12:26:08 -0700159struct wdog_disable_work_data {
160 struct work_struct work;
161 struct completion complete;
162 struct msm_watchdog_data *wdog_dd;
163};
164
165static void wdog_disable_work(struct work_struct *work)
166{
167 struct wdog_disable_work_data *work_data =
168 container_of(work, struct wdog_disable_work_data, work);
169 wdog_disable(work_data->wdog_dd);
170 complete(&work_data->complete);
171}
172
173static ssize_t wdog_disable_get(struct device *dev,
174 struct device_attribute *attr, char *buf)
175{
176 int ret;
177 struct msm_watchdog_data *wdog_dd = dev_get_drvdata(dev);
178
179 mutex_lock(&wdog_dd->disable_lock);
180 ret = snprintf(buf, PAGE_SIZE, "%d\n", enable == 0 ? 1 : 0);
181 mutex_unlock(&wdog_dd->disable_lock);
182 return ret;
183}
184
185static ssize_t wdog_disable_set(struct device *dev,
186 struct device_attribute *attr,
187 const char *buf, size_t count)
188{
189 int ret;
190 u8 disable;
191 struct wdog_disable_work_data work_data;
192 struct msm_watchdog_data *wdog_dd = dev_get_drvdata(dev);
193
194 ret = kstrtou8(buf, 10, &disable);
195 if (ret) {
196 dev_err(wdog_dd->dev, "invalid user input\n");
197 return ret;
198 }
199 if (disable == 1) {
200 mutex_lock(&wdog_dd->disable_lock);
201 if (enable == 0) {
202 pr_info("MSM Apps Watchdog already disabled\n");
203 mutex_unlock(&wdog_dd->disable_lock);
204 return count;
205 }
206 disable = 1;
207 ret = scm_call(SCM_SVC_BOOT, SCM_SVC_SEC_WDOG_DIS, &disable,
208 sizeof(disable), NULL, 0);
209 if (ret) {
210 dev_err(wdog_dd->dev,
211 "Failed to deactivate secure wdog\n");
212 mutex_unlock(&wdog_dd->disable_lock);
213 return -EIO;
214 }
215 work_data.wdog_dd = wdog_dd;
216 init_completion(&work_data.complete);
217 INIT_WORK_ONSTACK(&work_data.work, wdog_disable_work);
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800218 queue_work_on(0, wdog_wq, &work_data.work);
Hanumant Singh42ffa442012-08-27 12:26:08 -0700219 wait_for_completion(&work_data.complete);
220 mutex_unlock(&wdog_dd->disable_lock);
221 } else {
222 pr_err("invalid operation, only disable = 1 supported\n");
223 return -EINVAL;
224 }
225 return count;
226}
227
228static DEVICE_ATTR(disable, S_IWUSR | S_IRUSR, wdog_disable_get,
229 wdog_disable_set);
Hanumant72aec702012-06-25 11:51:07 -0700230
231static void pet_watchdog(struct msm_watchdog_data *wdog_dd)
232{
Matt Wagantallfc10f282012-10-11 11:39:20 -0700233 int slack, i, count, prev_count = 0;
Hanumant72aec702012-06-25 11:51:07 -0700234 unsigned long long time_ns;
235 unsigned long long slack_ns;
236 unsigned long long bark_time_ns = wdog_dd->bark_time * 1000000ULL;
237
Matt Wagantallfc10f282012-10-11 11:39:20 -0700238 for (i = 0; i < 2; i++) {
239 count = (__raw_readl(wdog_dd->base + WDT0_STS) >> 1) & 0xFFFFF;
240 if (count != prev_count) {
241 prev_count = count;
242 i = 0;
243 }
244 }
245 slack = ((wdog_dd->bark_time * WDT_HZ) / 1000) - count;
Hanumant72aec702012-06-25 11:51:07 -0700246 if (slack < wdog_dd->min_slack_ticks)
247 wdog_dd->min_slack_ticks = slack;
248 __raw_writel(1, wdog_dd->base + WDT0_RST);
249 time_ns = sched_clock();
250 slack_ns = (wdog_dd->last_pet + bark_time_ns) - time_ns;
251 if (slack_ns < wdog_dd->min_slack_ns)
252 wdog_dd->min_slack_ns = slack_ns;
253 wdog_dd->last_pet = time_ns;
254}
255
256static void keep_alive_response(void *info)
257{
258 int cpu = smp_processor_id();
259 struct msm_watchdog_data *wdog_dd = (struct msm_watchdog_data *)info;
260 cpumask_set_cpu(cpu, &wdog_dd->alive_mask);
261 smp_mb();
262}
263
264/*
265 * If this function does not return, it implies one of the
266 * other cpu's is not responsive.
267 */
268static void ping_other_cpus(struct msm_watchdog_data *wdog_dd)
269{
270 int cpu;
271 cpumask_clear(&wdog_dd->alive_mask);
272 smp_mb();
273 for_each_cpu(cpu, cpu_online_mask)
274 smp_call_function_single(cpu, keep_alive_response, wdog_dd, 1);
275}
276
277static void pet_watchdog_work(struct work_struct *work)
278{
279 unsigned long delay_time;
280 struct delayed_work *delayed_work = to_delayed_work(work);
281 struct msm_watchdog_data *wdog_dd = container_of(delayed_work,
282 struct msm_watchdog_data,
283 dogwork_struct);
284 delay_time = msecs_to_jiffies(wdog_dd->pet_time);
Hanumant Singh42ffa442012-08-27 12:26:08 -0700285 if (enable) {
286 if (wdog_dd->do_ipi_ping)
287 ping_other_cpus(wdog_dd);
288 pet_watchdog(wdog_dd);
289 }
290 /* Check again before scheduling *
291 * Could have been changed on other cpu */
Hanumant72aec702012-06-25 11:51:07 -0700292 if (enable)
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800293 queue_delayed_work_on(0, wdog_wq,
294 &wdog_dd->dogwork_struct, delay_time);
Hanumant72aec702012-06-25 11:51:07 -0700295}
296
297static int msm_watchdog_remove(struct platform_device *pdev)
298{
Hanumant Singh42ffa442012-08-27 12:26:08 -0700299 struct wdog_disable_work_data work_data;
Hanumant72aec702012-06-25 11:51:07 -0700300 struct msm_watchdog_data *wdog_dd =
301 (struct msm_watchdog_data *)platform_get_drvdata(pdev);
Hanumant Singh42ffa442012-08-27 12:26:08 -0700302
303 mutex_lock(&wdog_dd->disable_lock);
Hanumant72aec702012-06-25 11:51:07 -0700304 if (enable) {
Hanumant Singh42ffa442012-08-27 12:26:08 -0700305 work_data.wdog_dd = wdog_dd;
306 init_completion(&work_data.complete);
307 INIT_WORK_ONSTACK(&work_data.work, wdog_disable_work);
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800308 queue_work_on(0, wdog_wq, &work_data.work);
Hanumant Singh42ffa442012-08-27 12:26:08 -0700309 wait_for_completion(&work_data.complete);
Hanumant72aec702012-06-25 11:51:07 -0700310 }
Hanumant Singh42ffa442012-08-27 12:26:08 -0700311 mutex_unlock(&wdog_dd->disable_lock);
312 device_remove_file(wdog_dd->dev, &dev_attr_disable);
Hanumant Singh97cf75a2012-08-22 14:07:29 -0700313 if (wdog_dd->irq_ppi)
314 free_percpu(wdog_dd->wdog_cpu_dd);
Hanumant72aec702012-06-25 11:51:07 -0700315 printk(KERN_INFO "MSM Watchdog Exit - Deactivated\n");
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800316 destroy_workqueue(wdog_wq);
Hanumant Singh42ffa442012-08-27 12:26:08 -0700317 kfree(wdog_dd);
Hanumant72aec702012-06-25 11:51:07 -0700318 return 0;
319}
320
321static irqreturn_t wdog_bark_handler(int irq, void *dev_id)
322{
323 struct msm_watchdog_data *wdog_dd = (struct msm_watchdog_data *)dev_id;
324 unsigned long nanosec_rem;
325 unsigned long long t = sched_clock();
326
327 nanosec_rem = do_div(t, 1000000000);
328 printk(KERN_INFO "Watchdog bark! Now = %lu.%06lu\n", (unsigned long) t,
329 nanosec_rem / 1000);
330
331 nanosec_rem = do_div(wdog_dd->last_pet, 1000000000);
332 printk(KERN_INFO "Watchdog last pet at %lu.%06lu\n", (unsigned long)
333 wdog_dd->last_pet, nanosec_rem / 1000);
334 if (wdog_dd->do_ipi_ping)
335 dump_cpu_alive_mask(wdog_dd);
Pushkar Joshie77c0872013-01-17 19:04:37 -0800336 printk(KERN_INFO "Causing a watchdog bite!");
337 __raw_writel(1, wdog_dd->base + WDT0_BITE_TIME);
338 mb();
339 __raw_writel(1, wdog_dd->base + WDT0_RST);
340 mb();
341 /* Delay to make sure bite occurs */
342 mdelay(1);
Pushkar Joshi90760502013-07-12 11:27:09 -0700343 pr_err("Wdog - STS: 0x%x, CTL: 0x%x, BARK TIME: 0x%x, BITE TIME: 0x%x",
344 __raw_readl(wdog_dd->base + WDT0_STS),
345 __raw_readl(wdog_dd->base + WDT0_EN),
346 __raw_readl(wdog_dd->base + WDT0_BARK_TIME),
347 __raw_readl(wdog_dd->base + WDT0_BITE_TIME));
Pushkar Joshie77c0872013-01-17 19:04:37 -0800348 panic("Failed to cause a watchdog bite! - Falling back to kernel panic!");
Hanumant72aec702012-06-25 11:51:07 -0700349 return IRQ_HANDLED;
350}
351
Hanumant Singh97cf75a2012-08-22 14:07:29 -0700352static irqreturn_t wdog_ppi_bark(int irq, void *dev_id)
353{
354 struct msm_watchdog_data *wdog_dd =
355 *(struct msm_watchdog_data **)(dev_id);
356 return wdog_bark_handler(irq, wdog_dd);
357}
358
Hanumant Singh15784c82012-08-02 17:37:04 -0700359static void configure_bark_dump(struct msm_watchdog_data *wdog_dd)
360{
361 int ret;
362 struct msm_client_dump dump_entry;
363 struct {
364 unsigned addr;
365 int len;
366 } cmd_buf;
367
368 wdog_dd->scm_regsave = (void *)__get_free_page(GFP_KERNEL);
369 if (wdog_dd->scm_regsave) {
370 cmd_buf.addr = virt_to_phys(wdog_dd->scm_regsave);
371 cmd_buf.len = PAGE_SIZE;
372 ret = scm_call(SCM_SVC_UTIL, SCM_SET_REGSAVE_CMD,
373 &cmd_buf, sizeof(cmd_buf), NULL, 0);
374 if (ret)
375 pr_err("Setting register save address failed.\n"
376 "Registers won't be dumped on a dog "
377 "bite\n");
378 dump_entry.id = MSM_CPU_CTXT;
379 dump_entry.start_addr = virt_to_phys(wdog_dd->scm_regsave);
380 dump_entry.end_addr = dump_entry.start_addr + PAGE_SIZE;
381 ret = msm_dump_table_register(&dump_entry);
382 if (ret)
383 pr_err("Setting cpu dump region failed\n"
384 "Registers wont be dumped during cpu hang\n");
385 } else {
386 pr_err("Allocating register save space failed\n"
387 "Registers won't be dumped on a dog bite\n");
388 /*
389 * No need to bail if allocation fails. Simply don't
390 * send the command, and the secure side will reset
391 * without saving registers.
392 */
393 }
394}
395
396
Hanumant72aec702012-06-25 11:51:07 -0700397static void init_watchdog_work(struct work_struct *work)
398{
399 struct msm_watchdog_data *wdog_dd = container_of(work,
400 struct msm_watchdog_data,
401 init_dogwork_struct);
402 unsigned long delay_time;
Hanumant Singh42ffa442012-08-27 12:26:08 -0700403 int error;
Hanumant72aec702012-06-25 11:51:07 -0700404 u64 timeout;
Hanumant Singh97cf75a2012-08-22 14:07:29 -0700405 int ret;
406
407 if (wdog_dd->irq_ppi) {
408 wdog_dd->wdog_cpu_dd = alloc_percpu(struct msm_watchdog_data *);
409 if (!wdog_dd->wdog_cpu_dd) {
410 dev_err(wdog_dd->dev, "fail to allocate cpu data\n");
411 return;
412 }
413 *__this_cpu_ptr(wdog_dd->wdog_cpu_dd) = wdog_dd;
414 ret = request_percpu_irq(wdog_dd->bark_irq, wdog_ppi_bark,
415 "apps_wdog_bark",
416 wdog_dd->wdog_cpu_dd);
417 if (ret) {
418 dev_err(wdog_dd->dev, "failed to request bark irq\n");
419 free_percpu(wdog_dd->wdog_cpu_dd);
420 return;
421 }
422 } else {
423 ret = devm_request_irq(wdog_dd->dev, wdog_dd->bark_irq,
424 wdog_bark_handler, IRQF_TRIGGER_RISING,
425 "apps_wdog_bark", wdog_dd);
426 if (ret) {
427 dev_err(wdog_dd->dev, "failed to request bark irq\n");
428 return;
429 }
430 }
Hanumant72aec702012-06-25 11:51:07 -0700431 delay_time = msecs_to_jiffies(wdog_dd->pet_time);
432 wdog_dd->min_slack_ticks = UINT_MAX;
433 wdog_dd->min_slack_ns = ULLONG_MAX;
Hanumant Singh15784c82012-08-02 17:37:04 -0700434 configure_bark_dump(wdog_dd);
Hanumant72aec702012-06-25 11:51:07 -0700435 timeout = (wdog_dd->bark_time * WDT_HZ)/1000;
436 __raw_writel(timeout, wdog_dd->base + WDT0_BARK_TIME);
437 __raw_writel(timeout + 3*WDT_HZ, wdog_dd->base + WDT0_BITE_TIME);
438
439 wdog_dd->panic_blk.notifier_call = panic_wdog_handler;
440 atomic_notifier_chain_register(&panic_notifier_list,
441 &wdog_dd->panic_blk);
Hanumant Singh42ffa442012-08-27 12:26:08 -0700442 mutex_init(&wdog_dd->disable_lock);
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800443 queue_delayed_work_on(0, wdog_wq, &wdog_dd->dogwork_struct,
444 delay_time);
Hanumant72aec702012-06-25 11:51:07 -0700445 __raw_writel(1, wdog_dd->base + WDT0_EN);
446 __raw_writel(1, wdog_dd->base + WDT0_RST);
447 wdog_dd->last_pet = sched_clock();
Hanumant Singh42ffa442012-08-27 12:26:08 -0700448 error = device_create_file(wdog_dd->dev, &dev_attr_disable);
449 if (error)
450 dev_err(wdog_dd->dev, "cannot create sysfs attribute\n");
Hanumant Singh97cf75a2012-08-22 14:07:29 -0700451 if (wdog_dd->irq_ppi)
452 enable_percpu_irq(wdog_dd->bark_irq, 0);
Hanumant Singh42ffa442012-08-27 12:26:08 -0700453 dev_info(wdog_dd->dev, "MSM Watchdog Initialized\n");
Hanumant72aec702012-06-25 11:51:07 -0700454 return;
455}
456
457static struct of_device_id msm_wdog_match_table[] = {
458 { .compatible = "qcom,msm-watchdog" },
459 {}
460};
461
462static void __devinit dump_pdata(struct msm_watchdog_data *pdata)
463{
464 dev_dbg(pdata->dev, "wdog bark_time %d", pdata->bark_time);
465 dev_dbg(pdata->dev, "wdog pet_time %d", pdata->pet_time);
466 dev_dbg(pdata->dev, "wdog perform ipi ping %d", pdata->do_ipi_ping);
467 dev_dbg(pdata->dev, "wdog base address is 0x%x\n", (unsigned int)
468 pdata->base);
469}
470
471static int __devinit msm_wdog_dt_to_pdata(struct platform_device *pdev,
472 struct msm_watchdog_data *pdata)
473{
474 struct device_node *node = pdev->dev.of_node;
475 struct resource *wdog_resource;
476 int ret;
477
478 wdog_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
479 pdata->size = resource_size(wdog_resource);
480 pdata->phys_base = wdog_resource->start;
481 if (unlikely(!(devm_request_region(&pdev->dev, pdata->phys_base,
482 pdata->size, "msm-watchdog")))) {
483 dev_err(&pdev->dev, "%s cannot reserve watchdog region\n",
484 __func__);
485 return -ENXIO;
486 }
487 pdata->base = devm_ioremap(&pdev->dev, pdata->phys_base,
488 pdata->size);
489 if (!pdata->base) {
490 dev_err(&pdev->dev, "%s cannot map wdog register space\n",
491 __func__);
492 return -ENXIO;
493 }
494
495 pdata->bark_irq = platform_get_irq(pdev, 0);
496 pdata->bite_irq = platform_get_irq(pdev, 1);
497 ret = of_property_read_u32(node, "qcom,bark-time", &pdata->bark_time);
498 if (ret) {
499 dev_err(&pdev->dev, "reading bark time failed\n");
500 return -ENXIO;
501 }
502 ret = of_property_read_u32(node, "qcom,pet-time", &pdata->pet_time);
503 if (ret) {
504 dev_err(&pdev->dev, "reading pet time failed\n");
505 return -ENXIO;
506 }
Mitchel Humpherys1be23802012-11-16 15:52:32 -0800507 pdata->do_ipi_ping = of_property_read_bool(node, "qcom,ipi-ping");
Hanumant72aec702012-06-25 11:51:07 -0700508 if (!pdata->bark_time) {
509 dev_err(&pdev->dev, "%s watchdog bark time not setup\n",
510 __func__);
511 return -ENXIO;
512 }
513 if (!pdata->pet_time) {
514 dev_err(&pdev->dev, "%s watchdog pet time not setup\n",
515 __func__);
516 return -ENXIO;
517 }
Hanumant Singh97cf75a2012-08-22 14:07:29 -0700518 pdata->irq_ppi = irq_is_per_cpu(pdata->bark_irq);
Hanumant72aec702012-06-25 11:51:07 -0700519 dump_pdata(pdata);
520 return 0;
521}
522
523static int __devinit msm_watchdog_probe(struct platform_device *pdev)
524{
525 int ret;
526 struct msm_watchdog_data *wdog_dd;
527
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800528 wdog_wq = alloc_workqueue("wdog", WQ_HIGHPRI, 0);
529 if (!wdog_wq) {
530 pr_err("Failed to allocate watchdog workqueue\n");
531 return -EIO;
532 }
533
Hanumant72aec702012-06-25 11:51:07 -0700534 if (!pdev->dev.of_node || !enable)
535 return -ENODEV;
536 wdog_dd = kzalloc(sizeof(struct msm_watchdog_data), GFP_KERNEL);
537 if (!wdog_dd)
538 return -EIO;
539 ret = msm_wdog_dt_to_pdata(pdev, wdog_dd);
540 if (ret)
541 goto err;
542 wdog_dd->dev = &pdev->dev;
543 platform_set_drvdata(pdev, wdog_dd);
Hanumant72aec702012-06-25 11:51:07 -0700544 cpumask_clear(&wdog_dd->alive_mask);
545 INIT_WORK(&wdog_dd->init_dogwork_struct, init_watchdog_work);
546 INIT_DELAYED_WORK(&wdog_dd->dogwork_struct, pet_watchdog_work);
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800547 queue_work_on(0, wdog_wq, &wdog_dd->init_dogwork_struct);
Hanumant72aec702012-06-25 11:51:07 -0700548 return 0;
549err:
Mitchel Humpherys0d89e942012-12-13 16:56:46 -0800550 destroy_workqueue(wdog_wq);
Hanumant72aec702012-06-25 11:51:07 -0700551 kzfree(wdog_dd);
552 return ret;
553}
554
555static const struct dev_pm_ops msm_watchdog_dev_pm_ops = {
556 .suspend_noirq = msm_watchdog_suspend,
557 .resume_noirq = msm_watchdog_resume,
558};
559
560static struct platform_driver msm_watchdog_driver = {
561 .probe = msm_watchdog_probe,
562 .remove = msm_watchdog_remove,
563 .driver = {
564 .name = MODULE_NAME,
565 .owner = THIS_MODULE,
566 .pm = &msm_watchdog_dev_pm_ops,
567 .of_match_table = msm_wdog_match_table,
568 },
569};
570
571static int __devinit init_watchdog(void)
572{
573 return platform_driver_register(&msm_watchdog_driver);
574}
575
Subbaraman Narayanamurthy7a193bc2013-03-26 22:15:50 -0700576pure_initcall(init_watchdog);
Hanumant72aec702012-06-25 11:51:07 -0700577MODULE_DESCRIPTION("MSM Watchdog Driver");
578MODULE_LICENSE("GPL v2");