Commit d2f78268 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Wim Van Sebroeck

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: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent a4f741e3
...@@ -53,7 +53,10 @@ static unsigned timer_margin; ...@@ -53,7 +53,10 @@ static unsigned timer_margin;
module_param(timer_margin, uint, 0); module_param(timer_margin, uint, 0);
MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)"); MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
#define to_omap_wdt_dev(_wdog) container_of(_wdog, struct omap_wdt_dev, wdog)
struct omap_wdt_dev { struct omap_wdt_dev {
struct watchdog_device wdog;
void __iomem *base; /* physical */ void __iomem *base; /* physical */
struct device *dev; struct device *dev;
bool omap_wdt_users; bool omap_wdt_users;
...@@ -123,7 +126,7 @@ static void omap_wdt_set_timer(struct omap_wdt_dev *wdev, ...@@ -123,7 +126,7 @@ static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
static int omap_wdt_start(struct watchdog_device *wdog) static int omap_wdt_start(struct watchdog_device *wdog)
{ {
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
void __iomem *base = wdev->base; void __iomem *base = wdev->base;
mutex_lock(&wdev->lock); mutex_lock(&wdev->lock);
...@@ -151,7 +154,7 @@ static int omap_wdt_start(struct watchdog_device *wdog) ...@@ -151,7 +154,7 @@ static int omap_wdt_start(struct watchdog_device *wdog)
static int omap_wdt_stop(struct watchdog_device *wdog) static int omap_wdt_stop(struct watchdog_device *wdog)
{ {
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
mutex_lock(&wdev->lock); mutex_lock(&wdev->lock);
omap_wdt_disable(wdev); omap_wdt_disable(wdev);
...@@ -163,7 +166,7 @@ static int omap_wdt_stop(struct watchdog_device *wdog) ...@@ -163,7 +166,7 @@ static int omap_wdt_stop(struct watchdog_device *wdog)
static int omap_wdt_ping(struct watchdog_device *wdog) static int omap_wdt_ping(struct watchdog_device *wdog)
{ {
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
mutex_lock(&wdev->lock); mutex_lock(&wdev->lock);
omap_wdt_reload(wdev); omap_wdt_reload(wdev);
...@@ -175,7 +178,7 @@ static int omap_wdt_ping(struct watchdog_device *wdog) ...@@ -175,7 +178,7 @@ static int omap_wdt_ping(struct watchdog_device *wdog)
static int omap_wdt_set_timeout(struct watchdog_device *wdog, static int omap_wdt_set_timeout(struct watchdog_device *wdog,
unsigned int timeout) unsigned int timeout)
{ {
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog); struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
mutex_lock(&wdev->lock); mutex_lock(&wdev->lock);
omap_wdt_disable(wdev); omap_wdt_disable(wdev);
...@@ -204,16 +207,11 @@ static const struct watchdog_ops omap_wdt_ops = { ...@@ -204,16 +207,11 @@ static const struct watchdog_ops omap_wdt_ops = {
static int omap_wdt_probe(struct platform_device *pdev) static int omap_wdt_probe(struct platform_device *pdev)
{ {
struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev); struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
struct watchdog_device *omap_wdt;
struct resource *res; struct resource *res;
struct omap_wdt_dev *wdev; struct omap_wdt_dev *wdev;
u32 rs; u32 rs;
int ret; int ret;
omap_wdt = devm_kzalloc(&pdev->dev, sizeof(*omap_wdt), GFP_KERNEL);
if (!omap_wdt)
return -ENOMEM;
wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL); wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL);
if (!wdev) if (!wdev)
return -ENOMEM; return -ENOMEM;
...@@ -229,18 +227,17 @@ static int omap_wdt_probe(struct platform_device *pdev) ...@@ -229,18 +227,17 @@ static int omap_wdt_probe(struct platform_device *pdev)
if (IS_ERR(wdev->base)) if (IS_ERR(wdev->base))
return PTR_ERR(wdev->base); return PTR_ERR(wdev->base);
omap_wdt->info = &omap_wdt_info; wdev->wdog.info = &omap_wdt_info;
omap_wdt->ops = &omap_wdt_ops; wdev->wdog.ops = &omap_wdt_ops;
omap_wdt->min_timeout = TIMER_MARGIN_MIN; wdev->wdog.min_timeout = TIMER_MARGIN_MIN;
omap_wdt->max_timeout = TIMER_MARGIN_MAX; wdev->wdog.max_timeout = TIMER_MARGIN_MAX;
if (watchdog_init_timeout(omap_wdt, timer_margin, &pdev->dev) < 0) if (watchdog_init_timeout(&wdev->wdog, timer_margin, &pdev->dev) < 0)
omap_wdt->timeout = TIMER_MARGIN_DEFAULT; wdev->wdog.timeout = TIMER_MARGIN_DEFAULT;
watchdog_set_drvdata(omap_wdt, wdev); watchdog_set_nowayout(&wdev->wdog, nowayout);
watchdog_set_nowayout(omap_wdt, nowayout);
platform_set_drvdata(pdev, omap_wdt); platform_set_drvdata(pdev, wdev);
pm_runtime_enable(wdev->dev); pm_runtime_enable(wdev->dev);
pm_runtime_get_sync(wdev->dev); pm_runtime_get_sync(wdev->dev);
...@@ -249,12 +246,12 @@ static int omap_wdt_probe(struct platform_device *pdev) ...@@ -249,12 +246,12 @@ static int omap_wdt_probe(struct platform_device *pdev)
rs = pdata->read_reset_sources(); rs = pdata->read_reset_sources();
else else
rs = 0; rs = 0;
omap_wdt->bootstatus = (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT)) ? wdev->wdog.bootstatus = (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT)) ?
WDIOF_CARDRESET : 0; WDIOF_CARDRESET : 0;
omap_wdt_disable(wdev); omap_wdt_disable(wdev);
ret = watchdog_register_device(omap_wdt); ret = watchdog_register_device(&wdev->wdog);
if (ret) { if (ret) {
pm_runtime_disable(wdev->dev); pm_runtime_disable(wdev->dev);
return ret; return ret;
...@@ -262,7 +259,7 @@ static int omap_wdt_probe(struct platform_device *pdev) ...@@ -262,7 +259,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n", pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF, readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
omap_wdt->timeout); wdev->wdog.timeout);
pm_runtime_put_sync(wdev->dev); pm_runtime_put_sync(wdev->dev);
...@@ -271,8 +268,7 @@ static int omap_wdt_probe(struct platform_device *pdev) ...@@ -271,8 +268,7 @@ static int omap_wdt_probe(struct platform_device *pdev)
static void omap_wdt_shutdown(struct platform_device *pdev) static void omap_wdt_shutdown(struct platform_device *pdev)
{ {
struct watchdog_device *wdog = platform_get_drvdata(pdev); struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
mutex_lock(&wdev->lock); mutex_lock(&wdev->lock);
if (wdev->omap_wdt_users) { if (wdev->omap_wdt_users) {
...@@ -284,11 +280,10 @@ static void omap_wdt_shutdown(struct platform_device *pdev) ...@@ -284,11 +280,10 @@ static void omap_wdt_shutdown(struct platform_device *pdev)
static int omap_wdt_remove(struct platform_device *pdev) static int omap_wdt_remove(struct platform_device *pdev)
{ {
struct watchdog_device *wdog = platform_get_drvdata(pdev); struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
pm_runtime_disable(wdev->dev); pm_runtime_disable(wdev->dev);
watchdog_unregister_device(wdog); watchdog_unregister_device(&wdev->wdog);
return 0; return 0;
} }
...@@ -303,8 +298,7 @@ static int omap_wdt_remove(struct platform_device *pdev) ...@@ -303,8 +298,7 @@ static int omap_wdt_remove(struct platform_device *pdev)
static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state) static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
{ {
struct watchdog_device *wdog = platform_get_drvdata(pdev); struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
mutex_lock(&wdev->lock); mutex_lock(&wdev->lock);
if (wdev->omap_wdt_users) { if (wdev->omap_wdt_users) {
...@@ -318,8 +312,7 @@ static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state) ...@@ -318,8 +312,7 @@ static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
static int omap_wdt_resume(struct platform_device *pdev) static int omap_wdt_resume(struct platform_device *pdev)
{ {
struct watchdog_device *wdog = platform_get_drvdata(pdev); struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
mutex_lock(&wdev->lock); mutex_lock(&wdev->lock);
if (wdev->omap_wdt_users) { if (wdev->omap_wdt_users) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment