aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2015-04-27 05:23:00 -0400
committerWim Van Sebroeck <wim@iguana.be>2015-06-22 09:54:05 -0400
commitd2f78268ba583f75d5a67d44b8ef4b1560d6f597 (patch)
tree1fafadaa8ccc2b4909da788f263fc539e82a9480
parenta4f741e3e157c3a5c8aea5f2ea62b692fbf17338 (diff)
watchdog: omap: put struct watchdog_device into driver data
This way only a single allocation is needed (per device). Also this simplifies the data structure used by the driver because there is no need anymore to link from one struct to the other (by means of watchdog_{set,get}_drvdata). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
-rw-r--r--drivers/watchdog/omap_wdt.c55
1 files changed, 24 insertions, 31 deletions
diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c
index 88ca2ea88695..9494c4b25477 100644
--- a/drivers/watchdog/omap_wdt.c
+++ b/drivers/watchdog/omap_wdt.c
@@ -53,7 +53,10 @@ static unsigned timer_margin;
53module_param(timer_margin, uint, 0); 53module_param(timer_margin, uint, 0);
54MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)"); 54MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
55 55
56#define to_omap_wdt_dev(_wdog) container_of(_wdog, struct omap_wdt_dev, wdog)
57
56struct omap_wdt_dev { 58struct omap_wdt_dev {
59 struct watchdog_device wdog;
57 void __iomem *base; /* physical */ 60 void __iomem *base; /* physical */
58 struct device *dev; 61 struct device *dev;
59 bool omap_wdt_users; 62 bool omap_wdt_users;
@@ -123,7 +126,7 @@ static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
123 126
124static int omap_wdt_start(struct watchdog_device *wdog) 127static int omap_wdt_start(struct watchdog_device *wdog)
125{ 128{
126 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); 129 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
127 void __iomem *base = wdev->base; 130 void __iomem *base = wdev->base;
128 131
129 mutex_lock(&wdev->lock); 132 mutex_lock(&wdev->lock);
@@ -151,7 +154,7 @@ static int omap_wdt_start(struct watchdog_device *wdog)
151 154
152static int omap_wdt_stop(struct watchdog_device *wdog) 155static int omap_wdt_stop(struct watchdog_device *wdog)
153{ 156{
154 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); 157 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
155 158
156 mutex_lock(&wdev->lock); 159 mutex_lock(&wdev->lock);
157 omap_wdt_disable(wdev); 160 omap_wdt_disable(wdev);
@@ -163,7 +166,7 @@ static int omap_wdt_stop(struct watchdog_device *wdog)
163 166
164static int omap_wdt_ping(struct watchdog_device *wdog) 167static int omap_wdt_ping(struct watchdog_device *wdog)
165{ 168{
166 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); 169 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
167 170
168 mutex_lock(&wdev->lock); 171 mutex_lock(&wdev->lock);
169 omap_wdt_reload(wdev); 172 omap_wdt_reload(wdev);
@@ -175,7 +178,7 @@ static int omap_wdt_ping(struct watchdog_device *wdog)
175static int omap_wdt_set_timeout(struct watchdog_device *wdog, 178static int omap_wdt_set_timeout(struct watchdog_device *wdog,
176 unsigned int timeout) 179 unsigned int timeout)
177{ 180{
178 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); 181 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
179 182
180 mutex_lock(&wdev->lock); 183 mutex_lock(&wdev->lock);
181 omap_wdt_disable(wdev); 184 omap_wdt_disable(wdev);
@@ -204,16 +207,11 @@ static const struct watchdog_ops omap_wdt_ops = {
204static int omap_wdt_probe(struct platform_device *pdev) 207static int omap_wdt_probe(struct platform_device *pdev)
205{ 208{
206 struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev); 209 struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
207 struct watchdog_device *omap_wdt;
208 struct resource *res; 210 struct resource *res;
209 struct omap_wdt_dev *wdev; 211 struct omap_wdt_dev *wdev;
210 u32 rs; 212 u32 rs;
211 int ret; 213 int ret;
212 214
213 omap_wdt = devm_kzalloc(&pdev->dev, sizeof(*omap_wdt), GFP_KERNEL);
214 if (!omap_wdt)
215 return -ENOMEM;
216
217 wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL); 215 wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL);
218 if (!wdev) 216 if (!wdev)
219 return -ENOMEM; 217 return -ENOMEM;
@@ -229,18 +227,17 @@ static int omap_wdt_probe(struct platform_device *pdev)
229 if (IS_ERR(wdev->base)) 227 if (IS_ERR(wdev->base))
230 return PTR_ERR(wdev->base); 228 return PTR_ERR(wdev->base);
231 229
232 omap_wdt->info = &omap_wdt_info; 230 wdev->wdog.info = &omap_wdt_info;
233 omap_wdt->ops = &omap_wdt_ops; 231 wdev->wdog.ops = &omap_wdt_ops;
234 omap_wdt->min_timeout = TIMER_MARGIN_MIN; 232 wdev->wdog.min_timeout = TIMER_MARGIN_MIN;
235 omap_wdt->max_timeout = TIMER_MARGIN_MAX; 233 wdev->wdog.max_timeout = TIMER_MARGIN_MAX;
236 234
237 if (watchdog_init_timeout(omap_wdt, timer_margin, &pdev->dev) < 0) 235 if (watchdog_init_timeout(&wdev->wdog, timer_margin, &pdev->dev) < 0)
238 omap_wdt->timeout = TIMER_MARGIN_DEFAULT; 236 wdev->wdog.timeout = TIMER_MARGIN_DEFAULT;
239 237
240 watchdog_set_drvdata(omap_wdt, wdev); 238 watchdog_set_nowayout(&wdev->wdog, nowayout);
241 watchdog_set_nowayout(omap_wdt, nowayout);
242 239
243 platform_set_drvdata(pdev, omap_wdt); 240 platform_set_drvdata(pdev, wdev);
244 241
245 pm_runtime_enable(wdev->dev); 242 pm_runtime_enable(wdev->dev);
246 pm_runtime_get_sync(wdev->dev); 243 pm_runtime_get_sync(wdev->dev);
@@ -249,12 +246,12 @@ static int omap_wdt_probe(struct platform_device *pdev)
249 rs = pdata->read_reset_sources(); 246 rs = pdata->read_reset_sources();
250 else 247 else
251 rs = 0; 248 rs = 0;
252 omap_wdt->bootstatus = (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT)) ? 249 wdev->wdog.bootstatus = (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT)) ?
253 WDIOF_CARDRESET : 0; 250 WDIOF_CARDRESET : 0;
254 251
255 omap_wdt_disable(wdev); 252 omap_wdt_disable(wdev);
256 253
257 ret = watchdog_register_device(omap_wdt); 254 ret = watchdog_register_device(&wdev->wdog);
258 if (ret) { 255 if (ret) {
259 pm_runtime_disable(wdev->dev); 256 pm_runtime_disable(wdev->dev);
260 return ret; 257 return ret;
@@ -262,7 +259,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
262 259
263 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n", 260 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
264 readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF, 261 readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
265 omap_wdt->timeout); 262 wdev->wdog.timeout);
266 263
267 pm_runtime_put_sync(wdev->dev); 264 pm_runtime_put_sync(wdev->dev);
268 265
@@ -271,8 +268,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
271 268
272static void omap_wdt_shutdown(struct platform_device *pdev) 269static void omap_wdt_shutdown(struct platform_device *pdev)
273{ 270{
274 struct watchdog_device *wdog = platform_get_drvdata(pdev); 271 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
275 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
276 272
277 mutex_lock(&wdev->lock); 273 mutex_lock(&wdev->lock);
278 if (wdev->omap_wdt_users) { 274 if (wdev->omap_wdt_users) {
@@ -284,11 +280,10 @@ static void omap_wdt_shutdown(struct platform_device *pdev)
284 280
285static int omap_wdt_remove(struct platform_device *pdev) 281static int omap_wdt_remove(struct platform_device *pdev)
286{ 282{
287 struct watchdog_device *wdog = platform_get_drvdata(pdev); 283 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
288 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
289 284
290 pm_runtime_disable(wdev->dev); 285 pm_runtime_disable(wdev->dev);
291 watchdog_unregister_device(wdog); 286 watchdog_unregister_device(&wdev->wdog);
292 287
293 return 0; 288 return 0;
294} 289}
@@ -303,8 +298,7 @@ static int omap_wdt_remove(struct platform_device *pdev)
303 298
304static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state) 299static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
305{ 300{
306 struct watchdog_device *wdog = platform_get_drvdata(pdev); 301 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
307 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
308 302
309 mutex_lock(&wdev->lock); 303 mutex_lock(&wdev->lock);
310 if (wdev->omap_wdt_users) { 304 if (wdev->omap_wdt_users) {
@@ -318,8 +312,7 @@ static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
318 312
319static int omap_wdt_resume(struct platform_device *pdev) 313static int omap_wdt_resume(struct platform_device *pdev)
320{ 314{
321 struct watchdog_device *wdog = platform_get_drvdata(pdev); 315 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
322 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
323 316
324 mutex_lock(&wdev->lock); 317 mutex_lock(&wdev->lock);
325 if (wdev->omap_wdt_users) { 318 if (wdev->omap_wdt_users) {