x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / drivers / watchdog / da9055_wdt.c
blob50bdd10221864994a771b868acd98c07fc398528
1 /*
2 * System monitoring driver for DA9055 PMICs.
4 * Copyright(c) 2012 Dialog Semiconductor Ltd.
6 * Author: David Dajun Chen <dchen@diasemi.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
19 #include <linux/platform_device.h>
20 #include <linux/watchdog.h>
21 #include <linux/delay.h>
23 #include <linux/mfd/da9055/core.h>
24 #include <linux/mfd/da9055/reg.h>
26 static bool nowayout = WATCHDOG_NOWAYOUT;
27 module_param(nowayout, bool, 0);
28 MODULE_PARM_DESC(nowayout,
29 "Watchdog cannot be stopped once started (default="
30 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
32 #define DA9055_DEF_TIMEOUT 4
33 #define DA9055_TWDMIN 256
35 struct da9055_wdt_data {
36 struct watchdog_device wdt;
37 struct da9055 *da9055;
40 static const struct {
41 u8 reg_val;
42 int user_time; /* In seconds */
43 } da9055_wdt_maps[] = {
44 { 0, 0 },
45 { 1, 2 },
46 { 2, 4 },
47 { 3, 8 },
48 { 4, 16 },
49 { 5, 32 },
50 { 5, 33 }, /* Actual time 32.768s so included both 32s and 33s */
51 { 6, 65 },
52 { 6, 66 }, /* Actual time 65.536s so include both, 65s and 66s */
53 { 7, 131 },
56 static int da9055_wdt_set_timeout(struct watchdog_device *wdt_dev,
57 unsigned int timeout)
59 struct da9055_wdt_data *driver_data = watchdog_get_drvdata(wdt_dev);
60 struct da9055 *da9055 = driver_data->da9055;
61 int ret, i;
63 for (i = 0; i < ARRAY_SIZE(da9055_wdt_maps); i++)
64 if (da9055_wdt_maps[i].user_time == timeout)
65 break;
67 if (i == ARRAY_SIZE(da9055_wdt_maps))
68 ret = -EINVAL;
69 else
70 ret = da9055_reg_update(da9055, DA9055_REG_CONTROL_B,
71 DA9055_TWDSCALE_MASK,
72 da9055_wdt_maps[i].reg_val <<
73 DA9055_TWDSCALE_SHIFT);
74 if (ret < 0) {
75 dev_err(da9055->dev,
76 "Failed to update timescale bit, %d\n", ret);
77 return ret;
80 wdt_dev->timeout = timeout;
82 return 0;
85 static int da9055_wdt_ping(struct watchdog_device *wdt_dev)
87 struct da9055_wdt_data *driver_data = watchdog_get_drvdata(wdt_dev);
88 struct da9055 *da9055 = driver_data->da9055;
91 * We have a minimum time for watchdog window called TWDMIN. A write
92 * to the watchdog before this elapsed time will cause an error.
94 mdelay(DA9055_TWDMIN);
96 /* Reset the watchdog timer */
97 return da9055_reg_update(da9055, DA9055_REG_CONTROL_E,
98 DA9055_WATCHDOG_MASK, 1);
101 static int da9055_wdt_start(struct watchdog_device *wdt_dev)
103 return da9055_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
106 static int da9055_wdt_stop(struct watchdog_device *wdt_dev)
108 return da9055_wdt_set_timeout(wdt_dev, 0);
111 static const struct watchdog_info da9055_wdt_info = {
112 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
113 .identity = "DA9055 Watchdog",
116 static const struct watchdog_ops da9055_wdt_ops = {
117 .owner = THIS_MODULE,
118 .start = da9055_wdt_start,
119 .stop = da9055_wdt_stop,
120 .ping = da9055_wdt_ping,
121 .set_timeout = da9055_wdt_set_timeout,
124 static int da9055_wdt_probe(struct platform_device *pdev)
126 struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent);
127 struct da9055_wdt_data *driver_data;
128 struct watchdog_device *da9055_wdt;
129 int ret;
131 driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
132 GFP_KERNEL);
133 if (!driver_data)
134 return -ENOMEM;
136 driver_data->da9055 = da9055;
138 da9055_wdt = &driver_data->wdt;
140 da9055_wdt->timeout = DA9055_DEF_TIMEOUT;
141 da9055_wdt->info = &da9055_wdt_info;
142 da9055_wdt->ops = &da9055_wdt_ops;
143 da9055_wdt->parent = &pdev->dev;
144 watchdog_set_nowayout(da9055_wdt, nowayout);
145 watchdog_set_drvdata(da9055_wdt, driver_data);
147 ret = da9055_wdt_stop(da9055_wdt);
148 if (ret < 0) {
149 dev_err(&pdev->dev, "Failed to stop watchdog, %d\n", ret);
150 return ret;
153 ret = devm_watchdog_register_device(&pdev->dev, &driver_data->wdt);
154 if (ret != 0)
155 dev_err(da9055->dev, "watchdog_register_device() failed: %d\n",
156 ret);
158 return ret;
161 static struct platform_driver da9055_wdt_driver = {
162 .probe = da9055_wdt_probe,
163 .driver = {
164 .name = "da9055-watchdog",
168 module_platform_driver(da9055_wdt_driver);
170 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
171 MODULE_DESCRIPTION("DA9055 watchdog");
172 MODULE_LICENSE("GPL");
173 MODULE_ALIAS("platform:da9055-watchdog");