Skip to contentSkip to conversation

watchdog: add support for the Synopsys DesignWare WDT

PATCH Superseded Jamie Iles 4 participants 9 messages Jan 7, 2011 – Jan 9, 2011 Watchdog device drivers

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jamie Iles

author
#0 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

The Synopsys DesignWare watchdog is found in several ARM based systems and provides a choice of 16 timeout periods depending on the clock input. The watchdog cannot be disabled once started.

v3:
- convert pm to dev_pm_ops
- use devres for resource allocation

v2:
- constify fops
- request_mem_region() before ioremap()
- disable clk if misc_register() fails

Cc Wim Van Sebroeck <[email protected]>
---
 drivers/watchdog/Kconfig  |    9 ++
 drivers/watchdog/Makefile |    1 +
 drivers/watchdog/dw_wdt.c |  300 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 310 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/dw_wdt.c
drivers/watchdog/Kconfig +9 -0
index 8a3aa2f..0981aae 100644
@@ -331,6 +331,15 @@ config IMX2_WDT
 	  To compile this driver as a module, choose M here: the
 	  module will be called imx2_wdt.
 
+config DW_WATCHDOG
+	tristate "Synopsys DesignWare watchdog"
+        select WATCHDOG_NOWAYOUT
+	help
+	  Say Y here if to include support for the Synopsys DesignWare
+	  watchdog timer found in many ARM chips.
+	  To compile this driver as a module, choose M here: the
+	  module will be called dw_wdt.
+
 # AVR32 Architecture
 
 config AT32AP700X_WDT
drivers/watchdog/Makefile +1 -0
index 4b0ef38..3b3da4a 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
 obj-$(CONFIG_ADX_WATCHDOG) += adx_wdt.o
 obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o
 obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
+obj-$(CONFIG_DW_WATCHDOG) += dw_wdt.o
 
 # AVR32 Architecture
 obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
drivers/watchdog/dw_wdt.c new file +300 -0

300 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#1 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

On Fri, Jan 7, 2011 at 5:33 PM, Jamie Iles <[email protected]> wrote:

(...)

Quoted 6 lines
drivers/watchdog/dw_wdt.c new file +0 -0
new file mode 100644
index 0000000..e0d0e377
@@ -0,0 +1,300 @@

(...)

drivers/watchdog/dw_wdt.c

Quoted 3 lines
drivers/watchdog/dw_wdt.c new file +3 -0
+static inline int dw_wdt_is_enabled(void)
+{
+#define WDOG_CONTROL_REG_WDT_EN_MASK ? ? ? ? ? 0x01

can be moved to top, with other macros.

Quoted 4 lines

+ ? ? ? return readl(dw_wdt.regs + WDOG_CONTROL_REG_OFFSET) &
+ ? ? ? ? ? ? ? WDOG_CONTROL_REG_WDT_EN_MASK;

drivers/watchdog/dw_wdt.c new file +2 -0
+}
+

(...)

drivers/watchdog/dw_wdt.c

Quoted 3 lines
drivers/watchdog/dw_wdt.c new file +3 -0
+static void dw_wdt_keepalive(void)
+{
+#define WDOG_COUNTER_RESTART_KICK_VALUE ? ? ? ? ? ?0x76

ditto...

Quoted 6 lines

+ ? ? ? writel(WDOG_COUNTER_RESTART_KICK_VALUE, dw_wdt.regs +
+ ? ? ? ? ? ? ?WDOG_COUNTER_RESTART_REG_OFFSET);

drivers/watchdog/dw_wdt.c new file +4 -0
+}
+
+static int dw_wdt_open(struct inode *inode, struct file *filp)
+{

drivers/watchdog/dw_wdt.c

Quoted 10 lines
drivers/watchdog/dw_wdt.c new file +10 -0
+ ? ? ? /* Make sure we don't get unloaded. */
+ ? ? ? __module_get(THIS_MODULE);
+
+ ? ? ? spin_lock(&dw_wdt.lock);
+ ? ? ? if (!dw_wdt_is_enabled()) {
+ ? ? ? ? ? ? ? /*
+ ? ? ? ? ? ? ? ?* The watchdog is not currently enabled. Set the timeout to
+ ? ? ? ? ? ? ? ?* the maximum and then start it.
+ ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? dw_wdt_set_top(DW_WDT_MAX_TOP);

shouldn't we check return value here??

Quoted 8 lines

+ ? ? ? ? ? ? ? writel(WDOG_CONTROL_REG_WDT_EN_MASK,
+ ? ? ? ? ? ? ? ? ? ? ?dw_wdt.regs + WDOG_CONTROL_REG_OFFSET);
+ ? ? ? }
+ ? ? ? spin_unlock(&dw_wdt.lock);

drivers/watchdog/dw_wdt.c new file +4 -0
+
+ ? ? ? return nonseekable_open(inode, filp);
+}
+

(...)

drivers/watchdog/dw_wdt.c line 211

Quoted 9 lines
drivers/watchdog/dw_wdt.c new file +9 -0
+static const struct dev_pm_ops dw_wdt_pm_ops = {
+ ? ? ? .suspend ? ? ? ?= dw_wdt_suspend,
+ ? ? ? .resume ? ? ? ? = dw_wdt_resume,
+};
+
+#define DW_WDT_PM_OPS ?(&dw_wdt_pm_ops)
+#else /* CONFIG_PM */
+#define DW_WDT_PM_OPS ?NULL
+#endif /* CONFIG_PM */

This can be rewritten as:
static struct platform_driver dw_wdt_driver = {
...
+#ifdef CONFIG_PM
? ? ? ? ? ? ? .pm ? ? = dw_wdt_pm_ops,
#endif
}

Quoted 6 lines
drivers/watchdog/dw_wdt.c new file +6 -0
+static int __devinit dw_wdt_drv_probe(struct platform_device *pdev)
+{
+ ? ? ? int ret;
+ ? ? ? struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+ ? ? ? if (!mem)

drivers/watchdog/dw_wdt.c

Quoted 10 lines
drivers/watchdog/dw_wdt.c new file +10 -0
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? if (!devm_request_mem_region(&pdev->dev, mem->start, resource_size(mem),
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"iomem"))
+ ? ? ? ? ? ? ? return -ENOMEM;
+
+ ? ? ? dw_wdt.regs = devm_ioremap(&pdev->dev, mem->start,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resource_size(mem));
+ ? ? ? if (!dw_wdt.regs)
+ ? ? ? ? ? ? ? return -ENOMEM;

should release mem_region in case of error.

Quoted 4 lines

+
+ ? ? ? dw_wdt.clk = clk_get(&pdev->dev, NULL);
+ ? ? ? if (IS_ERR_OR_NULL(dw_wdt.clk))
+ ? ? ? ? ? ? ? return -ENODEV;

should release mem_region and free ioremaped space.
Also, may be we can continue here in case of error too. Some platforms might nor support clock framework. You can enable and disable clk's
if dw_wdt.clk is !NULL

drivers/watchdog/dw_wdt.c

Quoted 11 lines

+ ? ? ? clk_enable(dw_wdt.clk);

drivers/watchdog/dw_wdt.c new file +10 -0
+
+ ? ? ? ret = misc_register(&dw_wdt_miscdev);
+ ? ? ? if (ret)
+ ? ? ? ? ? ? ? goto register_failed;
+
+ ? ? ? return 0;
+
+register_failed:
+ ? ? ? clk_disable(dw_wdt.clk);
+ ? ? ? clk_put(dw_wdt.clk);

also iounmap and release_mem_region...

drivers/watchdog/dw_wdt.c

Quoted 10 lines
drivers/watchdog/dw_wdt.c new file +10 -0
+
+ ? ? ? return ret;
+}
+
+static int __devexit dw_wdt_drv_remove(struct platform_device *pdev)
+{
+ ? ? ? clk_disable(dw_wdt.clk);
+ ? ? ? clk_put(dw_wdt.clk);
+
+ ? ? ? misc_deregister(&dw_wdt_miscdev);

also iounmap and release_mem_region...

Quoted 7 lines
drivers/watchdog/dw_wdt.c new file +7 -0
+
+ ? ? ? return 0;
+}
+
+static struct platform_driver dw_wdt_driver = {
+ ? ? ? .probe ? ? ? ? ?= dw_wdt_drv_probe,
+ ? ? ? .remove ? ? ? ? = __devexit_p(dw_wdt_drv_remove),

drivers/watchdog/dw_wdt.c

Quoted 10 lines
drivers/watchdog/dw_wdt.c new file +10 -0
+ ? ? ? .driver ? ? ? ? = {
+ ? ? ? ? ? ? ? .name ? = "dw_wdt",
+ ? ? ? ? ? ? ? .owner ?= THIS_MODULE,
+ ? ? ? ? ? ? ? .pm ? ? = DW_WDT_PM_OPS,
+ ? ? ? },
+};
+
+static int __init dw_wdt_watchdog_init(void)
+{
+ ? ? ? spin_lock_init(&dw_wdt.lock);

This can be moved to probe. spin_lock_init should be only called when we have some device for this driver.

drivers/watchdog/dw_wdt.c line 296

Quoted 11 lines
drivers/watchdog/dw_wdt.c new file +11 -0
+
+ ? ? ? return platform_driver_register(&dw_wdt_driver);
+}
+
+static void __exit dw_wdt_watchdog_exit(void)
+{
+ ? ? ? platform_driver_unregister(&dw_wdt_driver);
+}
+
+module_init(dw_wdt_watchdog_init);
+module_exit(dw_wdt_watchdog_exit);

should be moved after init & exit routines without any blank lines.

--
viresh
ST Microelectronics

#2 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

Quoted 10 lines · viresh kumar
Quoted 4 lines

+
+ ? ? ? dw_wdt.clk = clk_get(&pdev->dev, NULL);
+ ? ? ? if (IS_ERR_OR_NULL(dw_wdt.clk))
+ ? ? ? ? ? ? ? return -ENODEV;

should release mem_region and free ioremaped space.
Also, may be we can continue here in case of error too. Some platforms might nor support clock framework. You can enable and disable clk's
if dw_wdt.clk is !NULL

And some platforms have been known to return NULL for clk_get() as they don't support more than one clock.

arch/arm/mach-aaec2000/core.c:struct clk *clk_get(struct device *dev, const char *id) arch/arm/mach-aaec2000/core.c-{
arch/arm/mach-aaec2000/core.c- return dev && strcmp(dev_name(dev), "mb:16") == 0 ? NULL : ERR_PTR(-ENOENT);
--
arch/arm/mach-at91/at91x40.c:struct clk *clk_get(struct device *dev, const char *id)
arch/arm/mach-at91/at91x40.c-{
arch/arm/mach-at91/at91x40.c- return NULL;
--
arch/arm/mach-netx/fb.c:struct clk *clk_get(struct device *dev, const char *id) arch/arm/mach-netx/fb.c-{
arch/arm/mach-netx/fb.c- return dev && strcmp(dev_name(dev), "fb") == 0 ? NULL : ERR_PTR(-ENOENT);

Please stick to the conventions of the API in the driver. IS_ERR() values mean we failed. Anything else must be considered success. Don't assume NULL means we failed.

author
#3 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

Quoted 29 lines · Russell King - ARM Linux
Quoted 10 lines · viresh kumar
Quoted 4 lines

+
+ ? ? ? dw_wdt.clk = clk_get(&pdev->dev, NULL);
+ ? ? ? if (IS_ERR_OR_NULL(dw_wdt.clk))
+ ? ? ? ? ? ? ? return -ENODEV;

should release mem_region and free ioremaped space.
Also, may be we can continue here in case of error too. Some platforms might nor support clock framework. You can enable and disable clk's
if dw_wdt.clk is !NULL

And some platforms have been known to return NULL for clk_get() as they don't support more than one clock.

arch/arm/mach-aaec2000/core.c:struct clk *clk_get(struct device *dev, const char *id) arch/arm/mach-aaec2000/core.c-{
arch/arm/mach-aaec2000/core.c- return dev && strcmp(dev_name(dev), "mb:16") == 0 ? NULL : ERR_PTR(-ENOENT);
--
arch/arm/mach-at91/at91x40.c:struct clk *clk_get(struct device *dev, const char *id)
arch/arm/mach-at91/at91x40.c-{
arch/arm/mach-at91/at91x40.c- return NULL;
--
arch/arm/mach-netx/fb.c:struct clk *clk_get(struct device *dev, const char *id) arch/arm/mach-netx/fb.c-{
arch/arm/mach-netx/fb.c- return dev && strcmp(dev_name(dev), "fb") == 0 ? NULL : ERR_PTR(-ENOENT);

Quoted 3 lines

Please stick to the conventions of the API in the driver. IS_ERR() values mean we failed. Anything else must be considered success. Don't assume NULL means we failed.

Ok, so I'll change the driver to get the clock rate of the watchdog through platform data for those that don't provide a struct clk and clk_get_rate() returns 0.

Looking at mach-aaec2000 and mach-netx they don't provide a clk_get_rate() which from linux/clk.h doesn't look like it's optional. Should these platforms have some kind of stub clk_get_rate()?

Jamie

#4 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

Quoted 34 lines · Jamie Iles
Quoted 29 lines · Russell King - ARM Linux
Quoted 10 lines · viresh kumar
Quoted 4 lines

+
+ ? ? ? dw_wdt.clk = clk_get(&pdev->dev, NULL);
+ ? ? ? if (IS_ERR_OR_NULL(dw_wdt.clk))
+ ? ? ? ? ? ? ? return -ENODEV;

should release mem_region and free ioremaped space.
Also, may be we can continue here in case of error too. Some platforms might nor support clock framework. You can enable and disable clk's
if dw_wdt.clk is !NULL

And some platforms have been known to return NULL for clk_get() as they don't support more than one clock.

arch/arm/mach-aaec2000/core.c:struct clk *clk_get(struct device *dev, const char *id) arch/arm/mach-aaec2000/core.c-{
arch/arm/mach-aaec2000/core.c- return dev && strcmp(dev_name(dev), "mb:16") == 0 ? NULL : ERR_PTR(-ENOENT);
--
arch/arm/mach-at91/at91x40.c:struct clk *clk_get(struct device *dev, const char *id)
arch/arm/mach-at91/at91x40.c-{
arch/arm/mach-at91/at91x40.c- return NULL;
--
arch/arm/mach-netx/fb.c:struct clk *clk_get(struct device *dev, const char *id) arch/arm/mach-netx/fb.c-{
arch/arm/mach-netx/fb.c- return dev && strcmp(dev_name(dev), "fb") == 0 ? NULL : ERR_PTR(-ENOENT);

Quoted 3 lines

Please stick to the conventions of the API in the driver. IS_ERR() values mean we failed. Anything else must be considered success. Don't assume NULL means we failed.

Quoted 7 lines

Ok, so I'll change the driver to get the clock rate of the watchdog through platform data for those that don't provide a struct clk and clk_get_rate() returns 0.

Looking at mach-aaec2000 and mach-netx they don't provide a clk_get_rate() which from linux/clk.h doesn't look like it's optional. Should these platforms have some kind of stub clk_get_rate()?

Probably, though I don't think aaec2000 is maintained anymore (I think it was a dump-and-run thing) so should probably be deleted from the kernel tree.

netx - since December 2008, it's only received updates when other stuff has changed (eg, on my clocksource sweep, or when I've noticed it no longer building.) So I think that's also a candidate for deletion unless someone speaks up.

Wonder if anyone wants to volunteer to delete them... ;)

author
#5 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

Quoted 10 lines · Russell King - ARM Linux

Probably, though I don't think aaec2000 is maintained anymore (I think it was a dump-and-run thing) so should probably be deleted from the kernel tree.

netx - since December 2008, it's only received updates when other stuff has changed (eg, on my clocksource sweep, or when I've noticed it no longer building.) So I think that's also a candidate for deletion unless someone speaks up.

Wonder if anyone wants to volunteer to delete them... ;)

I'm happy to do that for aaec2000, patch to follow. I'm willing to do the same for netx too or would you like to give people chance to shout first?

Jamie

author
#6 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

In reply to viresh kumar

Hi Viresh,

Thanks for the feedback, comments inline.

Jamie

Quoted 26 lines · viresh kumar

On Fri, Jan 7, 2011 at 5:33 PM, Jamie Iles <[email protected]> wrote:

(...)

Quoted 6 lines
drivers/watchdog/dw_wdt.c new file +0 -0
new file mode 100644
index 0000000..e0d0e377
@@ -0,0 +1,300 @@

(...)

drivers/watchdog/dw_wdt.c

Quoted 3 lines
drivers/watchdog/dw_wdt.c new file +3 -0
+static inline int dw_wdt_is_enabled(void)
+{
+#define WDOG_CONTROL_REG_WDT_EN_MASK ? ? ? ? ? 0x01

can be moved to top, with other macros.

Quoted 4 lines

+ ? ? ? return readl(dw_wdt.regs + WDOG_CONTROL_REG_OFFSET) &
+ ? ? ? ? ? ? ? WDOG_CONTROL_REG_WDT_EN_MASK;

drivers/watchdog/dw_wdt.c new file +2 -0
+}
+

(...)

Quoted 5 lines

drivers/watchdog/dw_wdt.c

Quoted 3 lines
drivers/watchdog/dw_wdt.c new file +3 -0
+static void dw_wdt_keepalive(void)
+{
+#define WDOG_COUNTER_RESTART_KICK_VALUE ? ? ? ? ? ?0x76

ditto...

Ok, agreed.

Quoted 10 lines
Quoted 10 lines

+ ? ? ? writel(WDOG_COUNTER_RESTART_KICK_VALUE, dw_wdt.regs +
+ ? ? ? ? ? ? ?WDOG_COUNTER_RESTART_REG_OFFSET);

drivers/watchdog/dw_wdt.c new file +8 -0
+}
+
+static int dw_wdt_open(struct inode *inode, struct file *filp)
+{
+ ? ? ? /* Make sure we don't get unloaded. */
+ ? ? ? __module_get(THIS_MODULE);
+
+ ? ? ? spin_lock(&dw_wdt.lock);
Quoted 8 lines
Quoted 6 lines

+ ? ? ? if (!dw_wdt_is_enabled()) {
+ ? ? ? ? ? ? ? /*
+ ? ? ? ? ? ? ? ?* The watchdog is not currently enabled. Set the timeout to
+ ? ? ? ? ? ? ? ?* the maximum and then start it.
+ ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? dw_wdt_set_top(DW_WDT_MAX_TOP);

shouldn't we check return value here??

No, dw_wdt_set_top() can't fail, it just returns the timeout period that it set in seconds. We use this when the user changes the timeout period as we may not be able to select the exact timeout period they chose, but here we just select the maximum timeout.

Quoted 21 lines
Quoted 8 lines

+ ? ? ? ? ? ? ? writel(WDOG_CONTROL_REG_WDT_EN_MASK,
+ ? ? ? ? ? ? ? ? ? ? ?dw_wdt.regs + WDOG_CONTROL_REG_OFFSET);
+ ? ? ? }
+ ? ? ? spin_unlock(&dw_wdt.lock);

drivers/watchdog/dw_wdt.c new file +4 -0
+
+ ? ? ? return nonseekable_open(inode, filp);
+}
+

(...)

drivers/watchdog/dw_wdt.c line 211

Quoted 9 lines
drivers/watchdog/dw_wdt.c new file +9 -0
+static const struct dev_pm_ops dw_wdt_pm_ops = {
+ ? ? ? .suspend ? ? ? ?= dw_wdt_suspend,
+ ? ? ? .resume ? ? ? ? = dw_wdt_resume,
+};
+
+#define DW_WDT_PM_OPS ?(&dw_wdt_pm_ops)
+#else /* CONFIG_PM */
+#define DW_WDT_PM_OPS ?NULL
+#endif /* CONFIG_PM */
Quoted 7 lines

This can be rewritten as:
static struct platform_driver dw_wdt_driver = {
...
+#ifdef CONFIG_PM
? ? ? ? ? ? ? .pm ? ? = dw_wdt_pm_ops,
#endif
}

Ok, that's clearer.

Quoted 19 lines
Quoted 6 lines
drivers/watchdog/dw_wdt.c new file +6 -0
+static int __devinit dw_wdt_drv_probe(struct platform_device *pdev)
+{
+ ? ? ? int ret;
+ ? ? ? struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+ ? ? ? if (!mem)

drivers/watchdog/dw_wdt.c

Quoted 10 lines
drivers/watchdog/dw_wdt.c new file +10 -0
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? if (!devm_request_mem_region(&pdev->dev, mem->start, resource_size(mem),
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"iomem"))
+ ? ? ? ? ? ? ? return -ENOMEM;
+
+ ? ? ? dw_wdt.regs = devm_ioremap(&pdev->dev, mem->start,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resource_size(mem));
+ ? ? ? if (!dw_wdt.regs)
+ ? ? ? ? ? ? ? return -ENOMEM;

should release mem_region in case of error.

Quoted 6 lines
Quoted 4 lines

+
+ ? ? ? dw_wdt.clk = clk_get(&pdev->dev, NULL);
+ ? ? ? if (IS_ERR_OR_NULL(dw_wdt.clk))
+ ? ? ? ? ? ? ? return -ENODEV;

should release mem_region and free ioremaped space.

We're using devres for the ioremap and region request so that takes care of the cleanup for us. This also means we don't need to iounmap and release in the release method.

Quoted 3 lines

Also, may be we can continue here in case of error too. Some platforms might nor support clock framework. You can enable and disable clk's if dw_wdt.clk is !NULL

The DesignWare watchdog has 16 timeout periods and these are derived from the clock frequency input to the WDT. If we don't have a clk then we don't know how long the timeout periods. The only alternative would be to have a 'struct dw_wdt_platform_data' that includes the input clock frequency which we use if we can't get a clk and get the rate.

Quoted 39 lines

drivers/watchdog/dw_wdt.c

Quoted 11 lines

+ ? ? ? clk_enable(dw_wdt.clk);

drivers/watchdog/dw_wdt.c new file +10 -0
+
+ ? ? ? ret = misc_register(&dw_wdt_miscdev);
+ ? ? ? if (ret)
+ ? ? ? ? ? ? ? goto register_failed;
+
+ ? ? ? return 0;
+
+register_failed:
+ ? ? ? clk_disable(dw_wdt.clk);
+ ? ? ? clk_put(dw_wdt.clk);

also iounmap and release_mem_region...

drivers/watchdog/dw_wdt.c

Quoted 10 lines
drivers/watchdog/dw_wdt.c new file +10 -0
+
+ ? ? ? return ret;
+}
+
+static int __devexit dw_wdt_drv_remove(struct platform_device *pdev)
+{
+ ? ? ? clk_disable(dw_wdt.clk);
+ ? ? ? clk_put(dw_wdt.clk);
+
+ ? ? ? misc_deregister(&dw_wdt_miscdev);

also iounmap and release_mem_region...

Quoted 12 lines
drivers/watchdog/dw_wdt.c new file +12 -0
+
+ ? ? ? return 0;
+}
+
+static struct platform_driver dw_wdt_driver = {
+ ? ? ? .probe ? ? ? ? ?= dw_wdt_drv_probe,
+ ? ? ? .remove ? ? ? ? = __devexit_p(dw_wdt_drv_remove),
+ ? ? ? .driver ? ? ? ? = {
+ ? ? ? ? ? ? ? .name ? = "dw_wdt",
+ ? ? ? ? ? ? ? .owner ?= THIS_MODULE,
+ ? ? ? ? ? ? ? .pm ? ? = DW_WDT_PM_OPS,
+ ? ? ? },
Quoted 8 lines

drivers/watchdog/dw_wdt.c

Quoted 5 lines
drivers/watchdog/dw_wdt.c new file +5 -0
+};
+
+static int __init dw_wdt_watchdog_init(void)
+{
+ ? ? ? spin_lock_init(&dw_wdt.lock);

This can be moved to probe. spin_lock_init should be only called when we have some device for this driver.

Agreed.

Quoted 5 lines
Quoted 5 lines
drivers/watchdog/dw_wdt.c new file +5 -0
+
+ ? ? ? return platform_driver_register(&dw_wdt_driver);
+}
+
+static void __exit dw_wdt_watchdog_exit(void)
Quoted 8 lines

drivers/watchdog/dw_wdt.c line 296

Quoted 6 lines
drivers/watchdog/dw_wdt.c new file +6 -0
+{
+ ? ? ? platform_driver_unregister(&dw_wdt_driver);
+}
+
+module_init(dw_wdt_watchdog_init);
+module_exit(dw_wdt_watchdog_exit);

should be moved after init & exit routines without any blank lines.

Ok, thanks.

#7 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

Quoted 15 lines · Jamie Iles
Quoted 6 lines
Quoted 6 lines
drivers/watchdog/dw_wdt.c new file +6 -0
+static int dw_wdt_open(struct inode *inode, struct file *filp)
+{
+ ? ? ? /* Make sure we don't get unloaded. */
+ ? ? ? __module_get(THIS_MODULE);
+
+ ? ? ? spin_lock(&dw_wdt.lock);
Quoted 8 lines
Quoted 6 lines

+ ? ? ? if (!dw_wdt_is_enabled()) {
+ ? ? ? ? ? ? ? /*
+ ? ? ? ? ? ? ? ?* The watchdog is not currently enabled. Set the timeout to
+ ? ? ? ? ? ? ? ?* the maximum and then start it.
+ ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? dw_wdt_set_top(DW_WDT_MAX_TOP);

shouldn't we check return value here??

Quoted 4 lines

No, dw_wdt_set_top() can't fail, it just returns the timeout period that it set in seconds. ?We use this when the user changes the timeout period as we may not be able to select the exact timeout period they chose, but here we just select the maximum timeout.

Sorry, I missed that.

Quoted 24 lines
Quoted 24 lines
Quoted 6 lines
(quoted diff) +6 -0
+static int __devinit dw_wdt_drv_probe(struct platform_device *pdev)
+{
+ ? ? ? int ret;
+ ? ? ? struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+ ? ? ? if (!mem)

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? if (!devm_request_mem_region(&pdev->dev, mem->start, resource_size(mem),
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"iomem"))
+ ? ? ? ? ? ? ? return -ENOMEM;
+
+ ? ? ? dw_wdt.regs = devm_ioremap(&pdev->dev, mem->start,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?resource_size(mem));
+ ? ? ? if (!dw_wdt.regs)
+ ? ? ? ? ? ? ? return -ENOMEM;

should release mem_region in case of error.

Quoted 4 lines

+
+ ? ? ? dw_wdt.clk = clk_get(&pdev->dev, NULL);
+ ? ? ? if (IS_ERR_OR_NULL(dw_wdt.clk))
+ ? ? ? ? ? ? ? return -ENODEV;

Quoted 5 lines
Quoted 1 line

should release mem_region and free ioremaped space.

We're using devres for the ioremap and region request so that takes care of the cleanup for us. ?This also means we don't need to iounmap and release in the release method.

ok

Quoted 10 lines
Quoted 4 lines

Also, may be we can continue here in case of error too. Some platforms might nor support clock framework. You can enable and disable clk's if dw_wdt.clk is !NULL

The DesignWare watchdog has 16 timeout periods and these are derived from the clock frequency input to the WDT. ?If we don't have a clk then we don't know how long the timeout periods. ?The only alternative would be to have a 'struct dw_wdt_platform_data' that includes the input clock frequency which we use if we can't get a clk and get the rate.

That will be fine.

--
viresh

#8 lore raw

PATCH v3 1/1 watchdog: add support for the Synopsys DesignWare WDT

In reply to Jamie Iles

Hi Jamie,

On top of other comments from Viresh:

Quoted 9 lines
drivers/watchdog/dw_wdt.c new file +9 -0
+static int dw_wdt_open(struct inode *inode, struct file *filp)
+{
+	/* Make sure we don't get unloaded. */
+	__module_get(THIS_MODULE);
+
+	spin_lock(&dw_wdt.lock);
+	if (!dw_wdt_is_enabled()) {
+		/*
+		 * The watchdog is not currently enabled. Set the timeout to

drivers/watchdog/dw_wdt.c line 119

Quoted 10 lines
drivers/watchdog/dw_wdt.c new file +10 -0
+		 * the maximum and then start it.
+		 */
+		dw_wdt_set_top(DW_WDT_MAX_TOP);
+		writel(WDOG_CONTROL_REG_WDT_EN_MASK,
+		       dw_wdt.regs + WDOG_CONTROL_REG_OFFSET);
+	}
+	spin_unlock(&dw_wdt.lock);
+
+	return nonseekable_open(inode, filp);
+}

Would be nice to have the open /dev/watchdog once protection here also.

drivers/watchdog/dw_wdt.c line 271

Quoted 9 lines
drivers/watchdog/dw_wdt.c new file +9 -0
+static int __devexit dw_wdt_drv_remove(struct platform_device *pdev)
+{
+	clk_disable(dw_wdt.clk);
+	clk_put(dw_wdt.clk);
+
+	misc_deregister(&dw_wdt_miscdev);
+
+	return 0;
+}

misc_deregister (=link to user-space) should be called before the clk_disabel calls.

Kind regards,
Wim.