Commit | Line | Data |
---|---|---|
80e45b1e TK |
1 | /* |
2 | * Copyright (C) Nokia Corporation | |
3 | * | |
4 | * Written by Timo Kokkonen <timo.t.kokkonen at nokia.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | */ | |
20 | ||
21 | #include <linux/module.h> | |
22 | #include <linux/types.h> | |
5a0e3ad6 | 23 | #include <linux/slab.h> |
80e45b1e | 24 | #include <linux/kernel.h> |
80e45b1e TK |
25 | #include <linux/watchdog.h> |
26 | #include <linux/platform_device.h> | |
b07682b6 | 27 | #include <linux/i2c/twl.h> |
80e45b1e TK |
28 | |
29 | #define TWL4030_WATCHDOG_CFG_REG_OFFS 0x3 | |
30 | ||
86a1e189 WVS |
31 | static bool nowayout = WATCHDOG_NOWAYOUT; |
32 | module_param(nowayout, bool, 0); | |
80e45b1e TK |
33 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " |
34 | "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | |
35 | ||
36 | static int twl4030_wdt_write(unsigned char val) | |
37 | { | |
2bc3f62f | 38 | return twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, val, |
80e45b1e TK |
39 | TWL4030_WATCHDOG_CFG_REG_OFFS); |
40 | } | |
41 | ||
b2c4e4b2 | 42 | static int twl4030_wdt_start(struct watchdog_device *wdt) |
80e45b1e | 43 | { |
b2c4e4b2 | 44 | return twl4030_wdt_write(wdt->timeout + 1); |
80e45b1e TK |
45 | } |
46 | ||
b2c4e4b2 | 47 | static int twl4030_wdt_stop(struct watchdog_device *wdt) |
80e45b1e TK |
48 | { |
49 | return twl4030_wdt_write(0); | |
50 | } | |
51 | ||
b2c4e4b2 JN |
52 | static int twl4030_wdt_set_timeout(struct watchdog_device *wdt, |
53 | unsigned int timeout) | |
80e45b1e | 54 | { |
b2c4e4b2 | 55 | wdt->timeout = timeout; |
80e45b1e TK |
56 | return 0; |
57 | } | |
58 | ||
b2c4e4b2 | 59 | static const struct watchdog_info twl4030_wdt_info = { |
fb1cbeae | 60 | .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING, |
b2c4e4b2 JN |
61 | .identity = "TWL4030 Watchdog", |
62 | }; | |
80e45b1e | 63 | |
b2c4e4b2 | 64 | static const struct watchdog_ops twl4030_wdt_ops = { |
80e45b1e | 65 | .owner = THIS_MODULE, |
b2c4e4b2 JN |
66 | .start = twl4030_wdt_start, |
67 | .stop = twl4030_wdt_stop, | |
68 | .set_timeout = twl4030_wdt_set_timeout, | |
80e45b1e TK |
69 | }; |
70 | ||
2d991a16 | 71 | static int twl4030_wdt_probe(struct platform_device *pdev) |
80e45b1e TK |
72 | { |
73 | int ret = 0; | |
b2c4e4b2 | 74 | struct watchdog_device *wdt; |
80e45b1e | 75 | |
b2c4e4b2 | 76 | wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); |
80e45b1e TK |
77 | if (!wdt) |
78 | return -ENOMEM; | |
79 | ||
b2c4e4b2 JN |
80 | wdt->info = &twl4030_wdt_info; |
81 | wdt->ops = &twl4030_wdt_ops; | |
82 | wdt->status = 0; | |
83 | wdt->timeout = 30; | |
84 | wdt->min_timeout = 1; | |
85 | wdt->max_timeout = 30; | |
6551881c | 86 | wdt->parent = &pdev->dev; |
80e45b1e | 87 | |
b2c4e4b2 | 88 | watchdog_set_nowayout(wdt, nowayout); |
80e45b1e TK |
89 | platform_set_drvdata(pdev, wdt); |
90 | ||
b2c4e4b2 | 91 | twl4030_wdt_stop(wdt); |
80e45b1e | 92 | |
b2c4e4b2 | 93 | ret = watchdog_register_device(wdt); |
6638f4e5 | 94 | if (ret) |
80e45b1e | 95 | return ret; |
b2c4e4b2 | 96 | |
80e45b1e TK |
97 | return 0; |
98 | } | |
99 | ||
4b12b896 | 100 | static int twl4030_wdt_remove(struct platform_device *pdev) |
80e45b1e | 101 | { |
b2c4e4b2 | 102 | struct watchdog_device *wdt = platform_get_drvdata(pdev); |
80e45b1e | 103 | |
b2c4e4b2 | 104 | watchdog_unregister_device(wdt); |
80e45b1e TK |
105 | |
106 | return 0; | |
107 | } | |
108 | ||
109 | #ifdef CONFIG_PM | |
110 | static int twl4030_wdt_suspend(struct platform_device *pdev, pm_message_t state) | |
111 | { | |
b2c4e4b2 JN |
112 | struct watchdog_device *wdt = platform_get_drvdata(pdev); |
113 | if (watchdog_active(wdt)) | |
114 | return twl4030_wdt_stop(wdt); | |
80e45b1e TK |
115 | |
116 | return 0; | |
117 | } | |
118 | ||
119 | static int twl4030_wdt_resume(struct platform_device *pdev) | |
120 | { | |
b2c4e4b2 JN |
121 | struct watchdog_device *wdt = platform_get_drvdata(pdev); |
122 | if (watchdog_active(wdt)) | |
123 | return twl4030_wdt_start(wdt); | |
80e45b1e TK |
124 | |
125 | return 0; | |
126 | } | |
127 | #else | |
128 | #define twl4030_wdt_suspend NULL | |
129 | #define twl4030_wdt_resume NULL | |
130 | #endif | |
131 | ||
8899b8d9 AK |
132 | static const struct of_device_id twl_wdt_of_match[] = { |
133 | { .compatible = "ti,twl4030-wdt", }, | |
134 | { }, | |
135 | }; | |
136 | MODULE_DEVICE_TABLE(of, twl_wdt_of_match); | |
137 | ||
80e45b1e TK |
138 | static struct platform_driver twl4030_wdt_driver = { |
139 | .probe = twl4030_wdt_probe, | |
82268714 | 140 | .remove = twl4030_wdt_remove, |
80e45b1e TK |
141 | .suspend = twl4030_wdt_suspend, |
142 | .resume = twl4030_wdt_resume, | |
143 | .driver = { | |
8899b8d9 AK |
144 | .name = "twl4030_wdt", |
145 | .of_match_table = twl_wdt_of_match, | |
80e45b1e TK |
146 | }, |
147 | }; | |
148 | ||
b8ec6118 | 149 | module_platform_driver(twl4030_wdt_driver); |
80e45b1e TK |
150 | |
151 | MODULE_AUTHOR("Nokia Corporation"); | |
152 | MODULE_LICENSE("GPL"); | |
80e45b1e TK |
153 | MODULE_ALIAS("platform:twl4030_wdt"); |
154 |