Merge tag 'mac80211-for-davem-2015-09-22' of git://git.kernel.org/pub/scm/linux/kerne...
[deliverable/linux.git] / drivers / watchdog / ux500_wdt.c
CommitLineData
f0e5bd41
FB
1/*
2 * Copyright (C) ST-Ericsson SA 2011-2013
3 *
4 * License Terms: GNU General Public License v2
5 *
6 * Author: Mathieu Poirier <mathieu.poirier@linaro.org> for ST-Ericsson
7 * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson
8 */
9
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/moduleparam.h>
f0e5bd41
FB
15#include <linux/err.h>
16#include <linux/uaccess.h>
17#include <linux/watchdog.h>
18#include <linux/platform_device.h>
19#include <linux/platform_data/ux500_wdt.h>
20
21#include <linux/mfd/dbx500-prcmu.h>
22
23#define WATCHDOG_TIMEOUT 600 /* 10 minutes */
24
25#define WATCHDOG_MIN 0
26#define WATCHDOG_MAX28 268435 /* 28 bit resolution in ms == 268435.455 s */
27#define WATCHDOG_MAX32 4294967 /* 32 bit resolution in ms == 4294967.295 s */
28
29static unsigned int timeout = WATCHDOG_TIMEOUT;
30module_param(timeout, uint, 0);
31MODULE_PARM_DESC(timeout,
32 "Watchdog timeout in seconds. default="
33 __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
34
35static bool nowayout = WATCHDOG_NOWAYOUT;
36module_param(nowayout, bool, 0);
37MODULE_PARM_DESC(nowayout,
38 "Watchdog cannot be stopped once started (default="
39 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
40
41static int ux500_wdt_start(struct watchdog_device *wdd)
42{
43 return prcmu_enable_a9wdog(PRCMU_WDOG_ALL);
44}
45
46static int ux500_wdt_stop(struct watchdog_device *wdd)
47{
48 return prcmu_disable_a9wdog(PRCMU_WDOG_ALL);
49}
50
51static int ux500_wdt_keepalive(struct watchdog_device *wdd)
52{
53 return prcmu_kick_a9wdog(PRCMU_WDOG_ALL);
54}
55
56static int ux500_wdt_set_timeout(struct watchdog_device *wdd,
57 unsigned int timeout)
58{
59 ux500_wdt_stop(wdd);
60 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
61 ux500_wdt_start(wdd);
62
63 return 0;
64}
65
66static const struct watchdog_info ux500_wdt_info = {
67 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
68 .identity = "Ux500 WDT",
69 .firmware_version = 1,
70};
71
72static const struct watchdog_ops ux500_wdt_ops = {
73 .owner = THIS_MODULE,
74 .start = ux500_wdt_start,
75 .stop = ux500_wdt_stop,
76 .ping = ux500_wdt_keepalive,
77 .set_timeout = ux500_wdt_set_timeout,
78};
79
80static struct watchdog_device ux500_wdt = {
81 .info = &ux500_wdt_info,
82 .ops = &ux500_wdt_ops,
83 .min_timeout = WATCHDOG_MIN,
84 .max_timeout = WATCHDOG_MAX32,
85};
86
87static int ux500_wdt_probe(struct platform_device *pdev)
88{
89 int ret;
bc8fdfbe 90 struct ux500_wdt_data *pdata = dev_get_platdata(&pdev->dev);
f0e5bd41
FB
91
92 if (pdata) {
93 if (pdata->timeout > 0)
94 timeout = pdata->timeout;
95 if (pdata->has_28_bits_resolution)
96 ux500_wdt.max_timeout = WATCHDOG_MAX28;
97 }
98
99 watchdog_set_nowayout(&ux500_wdt, nowayout);
100
101 /* disable auto off on sleep */
102 prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
103
104 /* set HW initial value */
105 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
106
107 ret = watchdog_register_device(&ux500_wdt);
108 if (ret)
109 return ret;
110
111 dev_info(&pdev->dev, "initialized\n");
112
113 return 0;
114}
115
116static int ux500_wdt_remove(struct platform_device *dev)
117{
118 watchdog_unregister_device(&ux500_wdt);
119
120 return 0;
121}
122
123#ifdef CONFIG_PM
124static int ux500_wdt_suspend(struct platform_device *pdev,
125 pm_message_t state)
126{
127 if (watchdog_active(&ux500_wdt)) {
128 ux500_wdt_stop(&ux500_wdt);
129 prcmu_config_a9wdog(PRCMU_WDOG_CPU1, true);
130
131 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
132 ux500_wdt_start(&ux500_wdt);
133 }
134 return 0;
135}
136
137static int ux500_wdt_resume(struct platform_device *pdev)
138{
139 if (watchdog_active(&ux500_wdt)) {
140 ux500_wdt_stop(&ux500_wdt);
141 prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
142
143 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
144 ux500_wdt_start(&ux500_wdt);
145 }
146 return 0;
147}
148#else
149#define ux500_wdt_suspend NULL
150#define ux500_wdt_resume NULL
151#endif
152
153static struct platform_driver ux500_wdt_driver = {
154 .probe = ux500_wdt_probe,
155 .remove = ux500_wdt_remove,
156 .suspend = ux500_wdt_suspend,
157 .resume = ux500_wdt_resume,
158 .driver = {
f0e5bd41
FB
159 .name = "ux500_wdt",
160 },
161};
162
163module_platform_driver(ux500_wdt_driver);
164
165MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>");
166MODULE_DESCRIPTION("Ux500 Watchdog Driver");
167MODULE_LICENSE("GPL");
f0e5bd41 168MODULE_ALIAS("platform:ux500_wdt");
This page took 0.256524 seconds and 5 git commands to generate.