ARM: meson: watchdog driver
Subsystems (4)
v2 cover ARM: meson: watchdog driver
This patchset adds support for the watchdog found on Amlogic MesonX SoCs. The watchdog is used also to reboot the device.
DTSI and multi_v7_defconfig are updated and proper documentation is added.
No documentation is provided by Amlogic, the code is reverse-engineered by the code available at http://openlinux.amlogic.com:8000/download/
This patchset depends on:
[1] [PATCH 0/6] ARM: meson: initial support for MesonX SoCs
[2] [PATCH 0/2] ARM: meson: add clocksource support
Changes since v1:
* added restart handler support
[1] http://www.spinics.net/lists/arm-kernel/msg362521.html
[2] http://www.spinics.net/lists/arm-kernel/msg362483.html
Carlo Caione (4):
ARM: docs: add documentation binding for meson watchdog
ARM: meson: add watchdog driver
ARM: DTS: meson: update DTSI to add watchdog node
ARM: defconfig: update multi_v7_defconfig
.../devicetree/bindings/watchdog/meson-wdt.txt | 13 ++ arch/arm/boot/dts/meson.dtsi | 5 + arch/arm/configs/multi_v7_defconfig | 1 + drivers/watchdog/Kconfig | 10 + drivers/watchdog/Makefile | 1 + drivers/watchdog/meson_wdt.c | 237 +++++++++++++++++++++ 6 files changed, 267 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/meson-wdt.txt create mode 100644 drivers/watchdog/meson_wdt.c
Signature · 1 line
1.9.1
PATCH v2 1/4 ARM: docs: add documentation binding for meson watchdog
--- Documentation/devicetree/bindings/watchdog/meson-wdt.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/meson-wdt.txt
Documentation/devicetree/bindings/watchdog/meson-wdt.txt new file +13 -0
@@ -0,0 +1,13 @@ +Meson SoCs Watchdog timer + +Required properties: + +- compatible : should be "amlogic,meson-wdt" +- reg : Specifies base physical address and size of the registers. + +Example: + +wdt: watchdog at c1109900 { + compatible = "amlogic,meson-wdt"; + reg = <0xc1109900 0x8>; +};
Signature · 1 line
1.9.1
PATCH v2 1/4 ARM: docs: add documentation binding for meson watchdog
Quoted 12 lines · Carlo Caione
Signed-off-by Carlo Caione <[email protected]>--- Documentation/devicetree/bindings/watchdog/meson-wdt.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/meson-wdt.txtDocumentation/devicetree/bindings/watchdog/meson-wdt.txt new file +0
-0
Documentation/devicetree/bindings/watchdog/meson-wdt.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/watchdog/meson-wdt.txt new file +5
-0@@ -0,0 +1,13 @@ +Meson SoCs Watchdog timer + +Required properties: + +- compatible : should be "amlogic,meson-wdt"
Hi Carlo,
the compatible property should describe a specific version of the device, so maybe "amlogic,meson6-wdt" would be more appropriate.
Beniamino
Quoted 11 lines
Documentation/devicetree/bindings/watchdog/meson-wdt.txt new file +8
-0+- reg : Specifies base physical address and size of the registers. + +Example: + +wdt: watchdog at c1109900 { + compatible = "amlogic,meson-wdt"; + reg = <0xc1109900 0x8>; +};Signature · 1 line
1.9.1
PATCH v2 1/4 ARM: docs: add documentation binding for meson watchdog
Quoted 21 lines · Beniamino Galvani
Quoted 12 lines · Carlo Caione
Signed-off-by Carlo Caione <[email protected]>--- Documentation/devicetree/bindings/watchdog/meson-wdt.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/meson-wdt.txtDocumentation/devicetree/bindings/watchdog/meson-wdt.txt new file +0
-0Documentation/devicetree/bindings/watchdog/meson-wdt.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/watchdog/meson-wdt.txt new file +5
-0@@ -0,0 +1,13 @@ +Meson SoCs Watchdog timer + +Required properties: + +- compatible : should be "amlogic,meson-wdt"Hi Carlo,
Quoted 2 lines
the compatible property should describe a specific version of the device, so maybe "amlogic,meson6-wdt" would be more appropriate.
Agree. Fix in v3.
Thanks,
Signature · 1 line
Carlo Caione
PATCH v2 2/4 ARM: meson: add watchdog driver
In reply to Carlo CaioneThis patch adds the watchdog driver for the Amlogic Meson SoCs used also to reboot the device.
--- drivers/watchdog/Kconfig | 10 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/meson_wdt.c | 237 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 drivers/watchdog/meson_wdt.c
drivers/watchdog/Kconfig +10 -0
@@ -443,6 +443,16 @@ config TEGRA_WATCHDOG To compile this driver as a module, choose M here: the module will be called tegra_wdt. +config MESON_WATCHDOG + tristate "Amlogic Meson SoCs watchdog support" + depends on ARCH_MESON + select WATCHDOG_CORE + help + Say Y here to include support for the watchdog timer + in Amlogic Meson SoCs. + To compile this driver as a module, choose M here: the + module will be called meson_wdt. + # AVR32 Architecture config AT32AP700X_WDT
drivers/watchdog/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o obj-$(CONFIG_BCM_KONA_WDT) += bcm_kona_wdt.o obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o +obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
drivers/watchdog/meson_wdt.c new file +237 -0
237 lines not on this page · raw message
Signature · 1 line
1.9.1
Guenter Roeck
maintainerPATCH v2 2/4 ARM: meson: add watchdog driver
Quoted 75 lines · Carlo Caione
This patch adds the watchdog driver for the Amlogic Meson SoCs used also to reboot the device.
Signed-off-by Carlo Caione <[email protected]>--- drivers/watchdog/Kconfig | 10 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/meson_wdt.c | 237 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+)create mode 100644
drivers/watchdog/meson_wdt.cdrivers/watchdog/Kconfig +10
-0@@ -443,6 +443,16 @@ config TEGRA_WATCHDOG To compile this driver as a module, choose M here: the module will be called tegra_wdt. +config MESON_WATCHDOG + tristate "Amlogic Meson SoCs watchdog support" + depends on ARCH_MESON + select WATCHDOG_CORE + help + Say Y here to include support for the watchdog timer + in Amlogic Meson SoCs. + To compile this driver as a module, choose M here: the + module will be called meson_wdt. + # AVR32 Architecture config AT32AP700X_WDTdrivers/watchdog/Makefile +1
-0@@ -59,6 +59,7 @@ obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o obj-$(CONFIG_BCM_KONA_WDT) += bcm_kona_wdt.o obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o +obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.odrivers/watchdog/meson_wdt.c new file +25
-0@@ -0,0 +1,237 @@ +/* +* Meson Watchdog Driver +* +* Copyright (c) 2014 Carlo Caione +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/notifier.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/reboot.h> +#include <linux/types.h> +#include <linux/watchdog.h>
drivers/watchdog/meson_wdt.c line 35
Quoted 10 lines
drivers/watchdog/meson_wdt.c new file +10
-0+ +#define DRV_NAME "meson_wdt" + +#define MESON_WDT_TC 0x00 +#define MESON_WDT_TC_EN BIT(22) +#define MESON_WDT_TC_TM_MASK 0x3fffff +#define MESON_WDT_DC_RESET (3 << 24) + +#define MESON_WDT_RESET 0x04 +
Does this all use the same indentation ? Looks a bit odd.
drivers/watchdog/meson_wdt.c line 39
Quoted 4 lines
drivers/watchdog/meson_wdt.c new file +4
-0+#define MESON_WDT_TIMEOUT 40 +#define MESON_WDT_MIN_TIMEOUT 1 +#define MESON_WDT_MAX_TIMEOUT 30 +
Default timeout is 40 seconds, maximum timeout is 30 seconds ? That doesn't really make much sense. What is the real maximum timeout ? If it is 0x3fffff / 100000, as the code suggests, you should set MAX_TIMEOUT to 41 or possibly (0x3fffff / 100000) so people understand what is going on.
drivers/watchdog/meson_wdt.c line 52
Quoted 13 lines
drivers/watchdog/meson_wdt.c new file +13
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +static unsigned int timeout =MESON_WDT_TIMEOUT ; + +struct meson_wdt_dev { +struct watchdog_device wdt_dev; +void __iomem *wdt_base; +struct notifier_block restart_handler; +}; + +static int meson_restart_handle (struct notifier_block *this,unsigned long mode, +void *cmd) +{ +u32 tc_reboot =MESON_WDT_DC_RESET |MESON_WDT_TC_EN |100 ;
What does the magic 100 do ?
drivers/watchdog/meson_wdt.c line 59
Quoted 7 lines
drivers/watchdog/meson_wdt.c new file +7
-0+struct meson_wdt_dev *meson_wdt =container_of (this, + struct meson_wdt_dev, + restart_handler); + +writel (tc_reboot, meson_wdt->wdt_base +MESON_WDT_TC ); +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET ); +
Is this sequence necessary ? Just asking, looks a bit odd.
Quoted 18 lines
drivers/watchdog/meson_wdt.c new file +18
-0+while (1 ) { +mdelay (5 ); +writel (tc_reboot, meson_wdt->wdt_base +MESON_WDT_TC ); + } + +return NOTIFY_DONE ; +} + +static int meson_wdt_ping (struct watchdog_device *wdt_dev) +{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); + +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET ); + +return 0 ; +} + +static int meson_wdt_set_timeout(struct watchdog_device *wdt_dev,
drivers/watchdog/meson_wdt.c line 87
Quoted 10 lines
drivers/watchdog/meson_wdt.c new file +10
-0+ unsigned int timeout) +{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); +u32 reg; + + meson_wdt->wdt_dev.timeout = timeout; + + reg =readl (meson_wdt->wdt_base +MESON_WDT_TC ); + reg &= ~MESON_WDT_TC_TM_MASK ; + reg |= (timeout *100 *1000 );
A define for the clock rate might be helpful.
drivers/watchdog/meson_wdt.c line 100
Quoted 13 lines
drivers/watchdog/meson_wdt.c new file +13
-0+writel (reg, meson_wdt->wdt_base +MESON_WDT_TC ); + +meson_wdt_ping (wdt_dev); + +return 0 ; +} + +static int meson_wdt_stop (struct watchdog_device *wdt_dev) +{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); +u32 reg; + +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET );
Is this final ping really needed here ?
Quoted 5 lines
drivers/watchdog/meson_wdt.c new file +5
-0+ reg =readl (meson_wdt->wdt_base +MESON_WDT_TC ); + reg &= ~MESON_WDT_TC_EN ; +writel (reg, meson_wdt->wdt_base +MESON_WDT_TC ); + +return 0 ;
drivers/watchdog/meson_wdt.c line 115
Quoted 10 lines
drivers/watchdog/meson_wdt.c new file +10
-0+} + +static int meson_wdt_start (struct watchdog_device *wdt_dev) +{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); +u32 reg; +int ret; + + ret =meson_wdt_set_timeout (&meson_wdt->wdt_dev, + meson_wdt->wdt_dev.timeout);
Not really sure if that is such a good idea here, as the set_timeout function does a bit more than just writing the timeout into the register. If you don't want to hard-code it here, I would suggest to write a little helper function which only writes it into the register (which would be called from both here and from meson_wdt_set_timeout).
Quoted 48 lines
drivers/watchdog/meson_wdt.c new file +48
-0+if (ret <0 ) +return ret; + +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET ); + reg =readl (meson_wdt->wdt_base +MESON_WDT_TC ); + reg |=MESON_WDT_TC_EN ; +writel (reg, meson_wdt->wdt_base +MESON_WDT_TC ); + +return 0 ; +} + +static const struct watchdog_info meson_wdt_info = { + .identity =DRV_NAME , + .options =WDIOF_SETTIMEOUT | +WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE , +}; + +static const struct watchdog_ops meson_wdt_ops = { + .owner =THIS_MODULE , + .start = meson_wdt_start, + .stop = meson_wdt_stop, + .ping = meson_wdt_ping, + .set_timeout = meson_wdt_set_timeout, +}; + +static int meson_wdt_probe (struct platform_device *pdev) +{ +struct resource *res; +struct meson_wdt_dev *meson_wdt; +int err; + + meson_wdt =devm_kzalloc (&pdev->dev,sizeof (*meson_wdt),GFP_KERNEL ); +if (!meson_wdt) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + meson_wdt->wdt_base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (meson_wdt->wdt_base)) +return PTR_ERR (meson_wdt->wdt_base); + + meson_wdt->wdt_dev.parent = &pdev->dev; + meson_wdt->wdt_dev.info = &meson_wdt_info; + meson_wdt->wdt_dev.ops = &meson_wdt_ops; + meson_wdt->wdt_dev.timeout =MESON_WDT_TIMEOUT ; + meson_wdt->wdt_dev.max_timeout =MESON_WDT_MAX_TIMEOUT ; + meson_wdt->wdt_dev.min_timeout =MESON_WDT_MIN_TIMEOUT ; +
drivers/watchdog/meson_wdt.c line 173
Quoted 10 lines
drivers/watchdog/meson_wdt.c new file +10
-0+watchdog_set_drvdata (&meson_wdt->wdt_dev, meson_wdt); + +watchdog_init_timeout (&meson_wdt->wdt_dev, timeout, &pdev->dev); +watchdog_set_nowayout (&meson_wdt->wdt_dev, nowayout); + +meson_wdt_stop (&meson_wdt->wdt_dev); + + err =watchdog_register_device (&meson_wdt->wdt_dev); +if (unlikely (err)) +return err;
Please drop the unlikely.
Quoted 14 lines
drivers/watchdog/meson_wdt.c new file +14
-0+ +platform_set_drvdata (pdev, meson_wdt); + + meson_wdt->restart_handler.notifier_call = meson_restart_handle; + meson_wdt->restart_handler.priority =128 ; + err =register_restart_handler (&meson_wdt->restart_handler); +if (err) +dev_err (&pdev->dev, +"cannot register restart handler (err=%d)\n" , err); + +dev_info (&pdev->dev,"Watchdog enabled (timeout=%d sec, nowayout=%d)" , + meson_wdt->wdt_dev.timeout, nowayout); + +return 0 ;
drivers/watchdog/meson_wdt.c line 197
Quoted 10 lines
drivers/watchdog/meson_wdt.c new file +10
-0+} + +static int meson_wdt_remove (struct platform_device *pdev) +{ +struct meson_wdt_dev *meson_wdt =platform_get_drvdata (pdev); + +unregister_restart_handler (&meson_wdt->restart_handler); + +watchdog_unregister_device (&meson_wdt->wdt_dev); +watchdog_set_drvdata (&meson_wdt->wdt_dev,NULL );
Unnecessary.
Quoted 41 lines
drivers/watchdog/meson_wdt.c new file +40
-0+ +return 0 ; +} + +static void meson_wdt_shutdown (struct platform_device *pdev) +{ +struct meson_wdt_dev *meson_wdt =platform_get_drvdata (pdev); + +meson_wdt_stop (&meson_wdt->wdt_dev); +} + +static const struct of_device_id meson_wdt_dt_ids[] = { + { .compatible ="amlogic,meson-wdt" }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, meson_wdt_dt_ids); + +static struct platform_driver meson_wdt_driver = { + .probe = meson_wdt_probe, + .remove = meson_wdt_remove, + .shutdown = meson_wdt_shutdown, + .driver = { + .owner =THIS_MODULE , + .name =DRV_NAME , + .of_match_table = meson_wdt_dt_ids, + }, +}; + +module_platform_driver (meson_wdt_driver); + +module_param (timeout, uint,0 ); +MODULE_PARM_DESC (timeout,"Watchdog heartbeat in seconds" ); + +module_param (nowayout, bool,0 ); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Carlo Caione <[email protected]>" ); +MODULE_DESCRIPTION ("Meson Watchdog Timer Driver" );
PATCH v2 2/4 ARM: meson: add watchdog driver
Quoted 82 lines · Guenter Roeck
Quoted 81 lines · Carlo Caione
This patch adds the watchdog driver for the Amlogic Meson SoCs used also to reboot the device.
Signed-off-by Carlo Caione <[email protected]>--- drivers/watchdog/Kconfig | 10 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/meson_wdt.c | 237 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+)create mode 100644
drivers/watchdog/meson_wdt.cdrivers/watchdog/Kconfig +10
-0@@ -443,6 +443,16 @@ config TEGRA_WATCHDOG To compile this driver as a module, choose M here: the module will be called tegra_wdt. +config MESON_WATCHDOG + tristate "Amlogic Meson SoCs watchdog support" + depends on ARCH_MESON + select WATCHDOG_CORE + help + Say Y here to include support for the watchdog timer + in Amlogic Meson SoCs. + To compile this driver as a module, choose M here: the + module will be called meson_wdt. + # AVR32 Architecture config AT32AP700X_WDTdrivers/watchdog/Makefile +1
-0@@ -59,6 +59,7 @@ obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o obj-$(CONFIG_BCM_KONA_WDT) += bcm_kona_wdt.o obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o +obj-$(CONFIG_MESON_WATCHDOG) += meson_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.odrivers/watchdog/meson_wdt.c new file +29
-0@@ -0,0 +1,237 @@ +/* +* Meson Watchdog Driver +* +* Copyright (c) 2014 Carlo Caione +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/notifier.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/reboot.h> +#include <linux/types.h> +#include <linux/watchdog.h> + +#define DRV_NAME "meson_wdt" + +#define MESON_WDT_TC 0x00
Quoted 8 lines
drivers/watchdog/meson_wdt.c line 35
Quoted 6 lines
drivers/watchdog/meson_wdt.c new file +6
-0+#define MESON_WDT_TC_EN BIT(22) +#define MESON_WDT_TC_TM_MASK 0x3fffff +#define MESON_WDT_DC_RESET (3 << 24) + +#define MESON_WDT_RESET 0x04 +Does this all use the same indentation ? Looks a bit odd.
It does actually.
Quoted 11 lines
drivers/watchdog/meson_wdt.c line 39
Quoted 4 lines
drivers/watchdog/meson_wdt.c new file +4
-0+#define MESON_WDT_TIMEOUT 40 +#define MESON_WDT_MIN_TIMEOUT 1 +#define MESON_WDT_MAX_TIMEOUT 30 +Default timeout is 40 seconds, maximum timeout is 30 seconds ? That doesn't really make much sense. What is the real maximum timeout ? If it is
0x3fffff/ 100000, as the code suggests, you should setMAX_TIMEOUTto 41 or possibly (0x3fffff/ 100000) so people understand what is going on.
I swapped the values, you are right. About the maximum values I wish I had proper documentation to answer your question.
Anyway your guessing is probably right so I'll change it.
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/meson_wdt.c new file +9
-0+static bool nowayout =WATCHDOG_NOWAYOUT ; +static unsigned int timeout =MESON_WDT_TIMEOUT ; + +struct meson_wdt_dev { +struct watchdog_device wdt_dev; +void __iomem *wdt_base; +struct notifier_block restart_handler; +}; +
Quoted 8 lines
drivers/watchdog/meson_wdt.c line 52
Quoted 5 lines
drivers/watchdog/meson_wdt.c new file +1
-0+static int meson_restart_handle(struct notifier_block *this, unsignedlong mode,
drivers/watchdog/meson_wdt.c new file +3
-0+ void *cmd) +{ +u32 tc_reboot =MESON_WDT_DC_RESET |MESON_WDT_TC_EN |100 ;What does the magic 100 do ?
Just setting a really small timeout (I'm still not sure if 100 means actually 1ms timeout or just "the minimum timeout")
Quoted 10 lines
drivers/watchdog/meson_wdt.c line 59
Quoted 8 lines
drivers/watchdog/meson_wdt.c new file +2
-0+struct meson_wdt_dev *meson_wdt =container_of (this, + struct
meson_wdt_dev,drivers/watchdog/meson_wdt.c new file +5
-0+ restart_handler); + +writel (tc_reboot, meson_wdt->wdt_base +MESON_WDT_TC ); +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET ); +Is this sequence necessary ? Just asking, looks a bit odd.
It was like that in the original code. I'll check if it is necessary.
Quoted 24 lines
Quoted 24 lines
drivers/watchdog/meson_wdt.c new file +23
-0+while (1 ) { +mdelay (5 ); +writel (tc_reboot, meson_wdt->wdt_base +MESON_WDT_TC ); + } + +return NOTIFY_DONE ; +} + +static int meson_wdt_ping (struct watchdog_device *wdt_dev) +{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); + +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET ); + +return 0 ; +} + +static int meson_wdt_set_timeout (struct watchdog_device *wdt_dev, +unsigned int timeout) +{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); +u32 reg; +
Quoted 8 lines
drivers/watchdog/meson_wdt.c line 87
Quoted 5 lines
drivers/watchdog/meson_wdt.c new file +5
-0+ meson_wdt->wdt_dev.timeout = timeout; + + reg =readl (meson_wdt->wdt_base +MESON_WDT_TC ); + reg &= ~MESON_WDT_TC_TM_MASK ; + reg |= (timeout *100 *1000 );A define for the clock rate might be helpful.
Agree
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/meson_wdt.c new file +8
-0+writel (reg, meson_wdt->wdt_base +MESON_WDT_TC ); + +meson_wdt_ping (wdt_dev); + +return 0 ; +} + +static int meson_wdt_stop (struct watchdog_device *wdt_dev)
Quoted 8 lines
drivers/watchdog/meson_wdt.c line 100
Quoted 5 lines
drivers/watchdog/meson_wdt.c new file +5
-0+{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); +u32 reg; + +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET );Is this final ping really needed here ?
I'll check it.
Quoted 14 lines
Quoted 14 lines
drivers/watchdog/meson_wdt.c new file +14
-0+ reg =readl (meson_wdt->wdt_base +MESON_WDT_TC ); + reg &= ~MESON_WDT_TC_EN ; +writel (reg, meson_wdt->wdt_base +MESON_WDT_TC ); + +return 0 ; +} + +static int meson_wdt_start (struct watchdog_device *wdt_dev) +{ +struct meson_wdt_dev *meson_wdt =watchdog_get_drvdata (wdt_dev); +u32 reg; +int ret; + + ret = meson_wdt_set_timeout(&meson_wdt->wdt_dev,
Quoted 8 lines
Quoted 1 line
+
meson_wdt->wdt_dev.timeout);Not really sure if that is such a good idea here, as the
set_timeoutfunction does a bit more than just writing the timeout into the register. If you don't want to hard-code it here, I would suggest to write a little helper function which only writes it into the register (which would be called from both here and frommeson_wdt_set_timeout).
Ok. I'll fix it in v3.
Quoted 55 lines
Quoted 55 lines
drivers/watchdog/meson_wdt.c new file +33
-0+if (ret <0 ) +return ret; + +writel (0 , meson_wdt->wdt_base +MESON_WDT_RESET ); + reg =readl (meson_wdt->wdt_base +MESON_WDT_TC ); + reg |=MESON_WDT_TC_EN ; +writel (reg, meson_wdt->wdt_base +MESON_WDT_TC ); + +return 0 ; +} + +static const struct watchdog_info meson_wdt_info = { + .identity =DRV_NAME , + .options =WDIOF_SETTIMEOUT | +WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE , +}; + +static const struct watchdog_ops meson_wdt_ops = { + .owner =THIS_MODULE , + .start = meson_wdt_start, + .stop = meson_wdt_stop, + .ping = meson_wdt_ping, + .set_timeout = meson_wdt_set_timeout, +}; + +static int meson_wdt_probe (struct platform_device *pdev) +{ +struct resource *res; +struct meson_wdt_dev *meson_wdt; +int err; + + meson_wdt = devm_kzalloc(&pdev->dev, sizeof(*meson_wdt),
GFP_KERNEL);drivers/watchdog/meson_wdt.c new file +20
-0+if (!meson_wdt) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + meson_wdt->wdt_base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (meson_wdt->wdt_base)) +return PTR_ERR (meson_wdt->wdt_base); + + meson_wdt->wdt_dev.parent = &pdev->dev; + meson_wdt->wdt_dev.info = &meson_wdt_info; + meson_wdt->wdt_dev.ops = &meson_wdt_ops; + meson_wdt->wdt_dev.timeout =MESON_WDT_TIMEOUT ; + meson_wdt->wdt_dev.max_timeout =MESON_WDT_MAX_TIMEOUT ; + meson_wdt->wdt_dev.min_timeout =MESON_WDT_MIN_TIMEOUT ; + +watchdog_set_drvdata (&meson_wdt->wdt_dev, meson_wdt); + +watchdog_init_timeout (&meson_wdt->wdt_dev, timeout, &pdev->dev); +watchdog_set_nowayout (&meson_wdt->wdt_dev, nowayout); +
Quoted 8 lines
drivers/watchdog/meson_wdt.c line 173
Quoted 5 lines
drivers/watchdog/meson_wdt.c new file +5
-0+meson_wdt_stop (&meson_wdt->wdt_dev); + + err =watchdog_register_device (&meson_wdt->wdt_dev); +if (unlikely (err)) +return err;Please drop the unlikely.
Ok
Quoted 21 lines
Quoted 21 lines
drivers/watchdog/meson_wdt.c new file +9
-0+ +platform_set_drvdata (pdev, meson_wdt); + + meson_wdt->restart_handler.notifier_call = meson_restart_handle; + meson_wdt->restart_handler.priority =128 ; + err =register_restart_handler (&meson_wdt->restart_handler); +if (err) + dev_err(&pdev->dev, + "cannot register restart handler (err=%d)\n",err);
drivers/watchdog/meson_wdt.c new file +2
-0+ + dev_info(&pdev->dev, "Watchdog enabled (timeout=%d sec,nowayout=%d)",
drivers/watchdog/meson_wdt.c new file +8
-0+ meson_wdt->wdt_dev.timeout, nowayout); + +return 0 ; +} + +static int meson_wdt_remove (struct platform_device *pdev) +{ +struct meson_wdt_dev *meson_wdt =platform_get_drvdata (pdev);
Quoted 8 lines
drivers/watchdog/meson_wdt.c line 197
Quoted 5 lines
drivers/watchdog/meson_wdt.c new file +5
-0+ +unregister_restart_handler (&meson_wdt->restart_handler); + +watchdog_unregister_device (&meson_wdt->wdt_dev); +watchdog_set_drvdata (&meson_wdt->wdt_dev,NULL );Unnecessary.
Ok
Quoted 33 lines
Quoted 33 lines
drivers/watchdog/meson_wdt.c new file +32
-0+ +return 0 ; +} + +static void meson_wdt_shutdown (struct platform_device *pdev) +{ +struct meson_wdt_dev *meson_wdt =platform_get_drvdata (pdev); + +meson_wdt_stop (&meson_wdt->wdt_dev); +} + +static const struct of_device_id meson_wdt_dt_ids[] = { + { .compatible ="amlogic,meson-wdt" }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, meson_wdt_dt_ids); + +static struct platform_driver meson_wdt_driver = { + .probe = meson_wdt_probe, + .remove = meson_wdt_remove, + .shutdown = meson_wdt_shutdown, + .driver = { + .owner =THIS_MODULE , + .name =DRV_NAME , + .of_match_table = meson_wdt_dt_ids, + }, +}; + +module_platform_driver (meson_wdt_driver); + +module_param (timeout, uint,0 ); +MODULE_PARM_DESC (timeout,"Watchdog heartbeat in seconds" );
Quoted 8 lines
drivers/watchdog/meson_wdt.c line 237
Quoted 8 lines
drivers/watchdog/meson_wdt.c new file +8
-0+ +module_param (nowayout, bool,0 ); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Carlo Caione <[email protected]>" ); +MODULE_DESCRIPTION ("Meson Watchdog Timer Driver" );
Thank you for the review.
Signature · 1 line
Carlo Caione
PATCH v2 3/4 ARM: DTS: meson: update DTSI to add watchdog node
In reply to Carlo Caione--- arch/arm/boot/dts/meson.dtsi | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/boot/dts/meson.dtsi +5 -0
@@ -70,6 +70,11 @@ #size-cells = <1>; ranges; + wdt: watchdog at c1109900 { + compatible = "amlogic,meson-wdt"; + reg = <0xc1109900 0x8>; + }; + uart_AO: serial at c81004c0 { compatible = "amlogic,meson-uart"; reg = <0xc81004c0 0x14>;
Signature · 1 line
1.9.1
PATCH v2 4/4 ARM: defconfig: update multi_v7_defconfig
In reply to Carlo CaioneUpdate the multi_v7_defconfig enabling the watchdog driver for Meson SoCs.
--- arch/arm/configs/multi_v7_defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm/configs/multi_v7_defconfig +1 -0
@@ -242,6 +242,7 @@ CONFIG_ST_THERMAL_MEMMAP=y CONFIG_WATCHDOG=y CONFIG_ORION_WATCHDOG=y CONFIG_SUNXI_WATCHDOG=y +CONFIG_MESON_WATCHDOG=y CONFIG_MFD_AS3722=y CONFIG_MFD_BCM590XX=y CONFIG_MFD_CROS_EC=y
Signature · 1 line
1.9.1