Add watchdog for Mstar SoCs
Romain Perier
maintainerv3 cover Add watchdog for Mstar SoCs
This patches series adds a new driver for the watchdog found in the Mstar MSC313e SoCs and newer. It adds a basic watchdog driver, the corresponding devicetree bindings and its documentation.
This work has been co-developed with Daniel Palmer.
Changes since v2:
- Renamed the dt-bindings documentation to mstar,msc313e-wdt.yaml
- Fixed the subject of the first commit
- Dropped unused dt labels
Changes since v1:
- Dropped "depends OF" from Kconfig (not required)
- Dropped unneeded include files
- Re-ordered include files
- Compute timeout_max dynamically from the probe function to avoid an overflow in _start().
Daniel Palmer (1):
watchdog: Add Mstar MSC313e WDT driver
Romain Perier (2):
dt-bindings: watchdog: Add Mstar MSC313e WDT devicetree bindings
documentation
ARM: dts: mstar: Add watchdog device_node definition
.../bindings/watchdog/mstar,msc313e-wdt.yaml | 40 +++++ MAINTAINERS | 1 + arch/arm/boot/dts/mstar-v7.dtsi | 14 ++ drivers/watchdog/Kconfig | 12 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/msc313e_wdt.c | 166 ++++++++++++++++++ 6 files changed, 234 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/mstar,msc313e-wdt.yaml create mode 100644 drivers/watchdog/msc313e_wdt.c
Signature · 1 line
2.30.2
Romain Perier
maintainerPATCH v3 1/3 dt-bindings: watchdog: Add Mstar MSC313e WDT devicetree bindings documentation
This adds the documentation for the devicetree bindings of the Mstar MSC313e watchdog driver, found from MSC313e SoCs and newer.
--- .../bindings/watchdog/mstar,msc313e-wdt.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/mstar,msc313e-wdt.yaml
Documentation/devicetree/bindings/watchdog/mstar,msc313e-wdt.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/watchdog/mstar,msc313e-wdt.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MStar Watchdog Device Tree Bindings + +maintainers: + - Daniel Palmer <[email protected]> + - Romain Perier <[email protected]> + +allOf: + - $ref: watchdog.yaml# + +properties: + compatible: + enum: + - mstar,msc313e-wdt + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + +required: + - compatible + - clocks + - reg + +unevaluatedProperties: false + +examples: + - | + watchdog@6000 { + compatible = "mstar,msc313e-wdt"; + reg = <0x6000 0x1f>; + clocks = <&xtal_div2>; + };
Signature · 1 line
2.30.2
Romain Perier
maintainerPATCH v3 3/3 ARM: dts: mstar: Add watchdog device_node definition
In reply to Romain PerierThis adds the definition of both an oscillator at 12Mhz required by the the watchdog and the watchdog device_node.
--- arch/arm/boot/dts/mstar-v7.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/arm/boot/dts/mstar-v7.dtsi +14 -0
@@ -62,6 +62,14 @@ rtc_xtal: rtc_xtal { clock-frequency = <32768>; status = "disabled"; }; + + xtal_div2: xtal_div2 { + #clock-cells = <0>; + compatible = "fixed-factor-clock"; + clocks = <&xtal>; + clock-div = <2>; + clock-mult = <1>; + }; }; soc: soc {
@@ -119,6 +127,12 @@ pm_irin_pins: pm_irin { }; }; + watchdog@6000 { + compatible = "mstar,msc313e-wdt"; + reg = <0x6000 0x1f>; + clocks = <&xtal_div2>; + }; + intc_fiq: interrupt-controller@201310 { compatible = "mstar,mst-intc"; reg = <0x201310 0x40>;
Signature · 1 line
2.30.2
Romain Perier
maintainerPATCH v3 2/3 watchdog: Add Mstar MSC313e WDT driver
In reply to Romain PerierFrom: Daniel Palmer <[email protected]>
It adds a driver for the IP block handling the watchdog timer found for Mstar MSC313e SoCs and newer.
--- MAINTAINERS | 1 + drivers/watchdog/Kconfig | 12 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/msc313e_wdt.c | 166 +++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/watchdog/msc313e_wdt.c
MAINTAINERS +1 -0
@@ -2177,6 +2177,7 @@ F: arch/arm/mach-mstar/ F: drivers/clk/mstar/ F: drivers/gpio/gpio-msc313.c F: drivers/pinctrl/pinctrl-msc313.c +F: drivers/watchdog/msc313e_wdt.c F: include/dt-bindings/clock/mstar-* F: include/dt-bindings/gpio/msc313-gpio.h F: include/soc/mstar/
drivers/watchdog/Kconfig +12 -0
@@ -980,6 +980,18 @@ config VISCONTI_WATCHDOG Say Y here to include support for the watchdog timer in Toshiba Visconti SoCs. +config MSC313E_WATCHDOG + tristate "MStar MSC313e watchdog" + depends on ARCH_MSTARV7 || COMPILE_TEST + select WATCHDOG_CORE + help + Say Y here to include support for the Watchdog timer embedded + into MStar MSC313e chips. This will reboot your system when the + timeout is reached. + + To compile this driver as a module, choose M here: the + module will be called msc313e_wdt. + # X86 (i386 + ia64 + x86_64) Architecture config ACQUIRE_WDT
drivers/watchdog/Makefile +1 -0
@@ -92,6 +92,7 @@ obj-$(CONFIG_SPRD_WATCHDOG) += sprd_wdt.o obj-$(CONFIG_PM8916_WATCHDOG) += pm8916_wdt.o obj-$(CONFIG_ARM_SMC_WATCHDOG) += arm_smc_wdt.o obj-$(CONFIG_VISCONTI_WATCHDOG) += visconti_wdt.o +obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o # X86 (i386 + ia64 + x86_64) Architecture obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
drivers/watchdog/msc313e_wdt.c new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v3 2/3] watchdog: Add Mstar MSC313e WDT driver
Quoted 8 lines · Romain Perier
From: Daniel Palmer <[email protected]>
It adds a driver for the IP block handling the watchdog timer found for Mstar MSC313e SoCs and newer.
Signed-off-by Daniel Palmer <[email protected]>Co-developed-by Romain Perier <[email protected]>Signed-off-by Romain Perier <[email protected]>
Quoted 230 lines
--- MAINTAINERS | 1 + drivers/watchdog/Kconfig | 12 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/msc313e_wdt.c | 166 +++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/watchdog/msc313e_wdt.cMAINTAINERS +1
-0@@ -2177,6 +2177,7 @@ F: arch/arm/mach-mstar/ F: drivers/clk/mstar/ F: drivers/gpio/gpio-msc313.c F: drivers/pinctrl/pinctrl-msc313.c +F: drivers/watchdog/msc313e_wdt.c F: include/dt-bindings/clock/mstar-* F: include/dt-bindings/gpio/msc313-gpio.h F: include/soc/mstar/drivers/watchdog/Kconfig +12
-0@@ -980,6 +980,18 @@ config VISCONTI_WATCHDOG Say Y here to include support for the watchdog timer in Toshiba Visconti SoCs. +config MSC313E_WATCHDOG + tristate "MStar MSC313e watchdog" + depends on ARCH_MSTARV7 || COMPILE_TEST + select WATCHDOG_CORE + help + Say Y here to include support for the Watchdog timer embedded + into MStar MSC313e chips. This will reboot your system when the + timeout is reached. + + To compile this driver as a module, choose M here: the + module will be called msc313e_wdt. + # X86 (i386 + ia64 + x86_64) Architecture config ACQUIRE_WDTdrivers/watchdog/Makefile +1
-0@@ -92,6 +92,7 @@ obj-$(CONFIG_SPRD_WATCHDOG) += sprd_wdt.o obj-$(CONFIG_PM8916_WATCHDOG) += pm8916_wdt.o obj-$(CONFIG_ARM_SMC_WATCHDOG) += arm_smc_wdt.o obj-$(CONFIG_VISCONTI_WATCHDOG) += visconti_wdt.o +obj-$(CONFIG_MSC313E_WATCHDOG) += msc313e_wdt.o # X86 (i386 + ia64 + x86_64) Architecture obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.odrivers/watchdog/msc313e_wdt.c new file +166
-0@@ -0,0 +1,166 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* MStar WDT driver +* +* Copyright (C) 2019 - 2021 Daniel Palmer +* Copyright (C) 2021 Romain Perier +* +*/ + +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/watchdog.h> + +#define REG_WDT_CLR 0x0 +#define REG_WDT_MAX_PRD_L 0x10 +#define REG_WDT_MAX_PRD_H 0x14 + +#define MSC313E_WDT_MIN_TIMEOUT 1 +#define MSC313E_WDT_DEFAULT_TIMEOUT 30 + +static unsigned int timeout; + +module_param (timeout, int,0 ); +MODULE_PARM_DESC (timeout,"Watchdog timeout in seconds" ); + +struct msc313e_wdt_priv { +void __iomem *base; +struct watchdog_device wdev; +struct clk *clk; +}; + +static int msc313e_wdt_start (struct watchdog_device *wdev) +{ +struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); +u32 timeout; +int err; + + err =clk_prepare_enable (priv->clk); +if (err) +return err; + + timeout = wdev->timeout *clk_get_rate (priv->clk); +writew (timeout &0xffff , priv->base +REG_WDT_MAX_PRD_L ); +writew ((timeout >>16 ) &0xffff , priv->base +REG_WDT_MAX_PRD_H ); +writew (1 , priv->base +REG_WDT_CLR ); +return 0 ; +} + +static int msc313e_wdt_ping (struct watchdog_device *wdev) +{ +struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); + +writew (1 , priv->base +REG_WDT_CLR ); +return 0 ; +} + +static int msc313e_wdt_stop (struct watchdog_device *wdev) +{ +struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); + +writew (0 , priv->base +REG_WDT_MAX_PRD_L ); +writew (0 , priv->base +REG_WDT_MAX_PRD_H ); +writew (0 , priv->base +REG_WDT_CLR ); +clk_disable_unprepare (priv->clk); +return 0 ; +} + +static int msc313e_wdt_settimeout (struct watchdog_device *wdev,unsigned int new_time) +{ + wdev->timeout = new_time; + +return msc313e_wdt_start (wdev); +} + +static const struct watchdog_info msc313e_wdt_ident = { + .identity ="MSC313e watchdog" , + .options =WDIOF_MAGICCLOSE |WDIOF_KEEPALIVEPING |WDIOF_SETTIMEOUT , +}; + +static const struct watchdog_ops msc313e_wdt_ops = { + .owner =THIS_MODULE , + .start = msc313e_wdt_start, + .stop = msc313e_wdt_stop, + .ping = msc313e_wdt_ping, + .set_timeout = msc313e_wdt_settimeout, +}; + +static const struct of_device_id msc313e_wdt_of_match[] = { + { .compatible ="mstar,msc313e-wdt" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, msc313e_wdt_of_match); + +static int msc313e_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct msc313e_wdt_priv *priv; + + priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base); + + priv->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (priv->clk)) { +dev_err (dev,"No input clock\n" ); +return PTR_ERR (priv->clk); + } + + priv->wdev.info = &msc313e_wdt_ident, + priv->wdev.ops = &msc313e_wdt_ops, + priv->wdev.parent = dev; + priv->wdev.min_timeout =MSC313E_WDT_MIN_TIMEOUT ; + priv->wdev.max_timeout =U32_MAX /clk_get_rate (priv->clk); + priv->wdev.timeout =MSC313E_WDT_DEFAULT_TIMEOUT ; + +watchdog_set_drvdata (&priv->wdev, priv); + +watchdog_init_timeout (&priv->wdev, timeout, dev); +watchdog_stop_on_reboot (&priv->wdev); +watchdog_stop_on_unregister (&priv->wdev); + +return devm_watchdog_register_device (dev, &priv->wdev); +} + +static int __maybe_unused msc313e_wdt_suspend (struct device *dev) +{ +struct msc313e_wdt_priv *priv =dev_get_drvdata (dev); + +if (watchdog_active (&priv->wdev)) +msc313e_wdt_stop (&priv->wdev); + +return 0 ; +} + +static int __maybe_unused msc313e_wdt_resume (struct device *dev) +{ +struct msc313e_wdt_priv *priv =dev_get_drvdata (dev); + +if (watchdog_active (&priv->wdev)) +msc313e_wdt_start (&priv->wdev); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(msc313e_wdt_pm_ops, msc313e_wdt_suspend, msc313e_wdt_resume); + +static struct platform_driver msc313e_wdt_driver = { + .driver = { + .name ="msc313e-wdt" , + .of_match_table = msc313e_wdt_of_match, + .pm = &msc313e_wdt_pm_ops, + }, + .probe = msc313e_wdt_probe, +}; +module_platform_driver (msc313e_wdt_driver); + +MODULE_AUTHOR ("Daniel Palmer <[email protected]>" ); +MODULE_DESCRIPTION ("Watchdog driver for MStar MSC313e" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
2.30.2
Re: [PATCH v3 1/3] dt-bindings: watchdog: Add Mstar MSC313e WDT devicetree bindings documentation
In reply to Romain PerierQuoted 9 lines · Romain Perier
This adds the documentation for the devicetree bindings of the Mstar MSC313e watchdog driver, found from MSC313e SoCs and newer.
Signed-off-by Romain Perier <[email protected]>--- .../bindings/watchdog/mstar,msc313e-wdt.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/mstar,msc313e-wdt.yaml
Guenter Roeck
maintainerRe: [PATCH v3 2/3] watchdog: Add Mstar MSC313e WDT driver
In reply to Romain PerierQuoted 11 lines · Romain Perier
From: Daniel Palmer <[email protected]>
It adds a driver for the IP block handling the watchdog timer found for Mstar MSC313e SoCs and newer.
Signed-off-by Daniel Palmer <[email protected]>Co-developed-by Romain Perier <[email protected]>Signed-off-by Romain Perier <[email protected]>Reviewed-by Guenter Roeck <[email protected]>--- MAINTAINERS | 1 +
I tried to apply this patch to my tree, but it doesn't apply because ...
MAINTAINERS
Quoted 8 lines
drivers/watchdog/Kconfig | 12 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/msc313e_wdt.c | 166 +++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/watchdog/msc313e_wdt.cMAINTAINERS +0
-0
a0f37adb9e64 is not an upstream SHA and there is a conflict. Please resend the series based on some upstream tag.
Guenter
Romain Perier
maintainerRe: [PATCH v3 2/3] watchdog: Add Mstar MSC313e WDT driver
Quoted 22 lines · Guenter Roeck
Quoted 11 lines · Romain Perier
From: Daniel Palmer <[email protected]>
It adds a driver for the IP block handling the watchdog timer found for Mstar MSC313e SoCs and newer.
Signed-off-by Daniel Palmer <[email protected]>Co-developed-by Romain Perier <[email protected]>Signed-off-by Romain Perier <[email protected]>Reviewed-by Guenter Roeck <[email protected]>--- MAINTAINERS | 1 +I tried to apply this patch to my tree, but it doesn't apply because ...
Quoted 6 lines
drivers/watchdog/Kconfig | 12 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/msc313e_wdt.c | 166 +++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/watchdog/msc313e_wdt.c
Quoted 7 lines
MAINTAINERS
Quoted 2 lines
MAINTAINERS +0
-0
a0f37adb9e64is not an upstream SHA and there is a conflict. Please resend the series based on some upstream tag.Guenter
Arf, I will rebase and resend then, my bad. It is okay if I rebase the series onto https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
, branch watchdog-next ?
Romain
Guenter Roeck
maintainerRe: [PATCH v3 2/3] watchdog: Add Mstar MSC313e WDT driver
Quoted 29 lines · Romain Perier
Quoted 28 lines · Guenter Roeck
Quoted 11 lines · Romain Perier
From: Daniel Palmer <[email protected]>
It adds a driver for the IP block handling the watchdog timer found for Mstar MSC313e SoCs and newer.
Signed-off-by Daniel Palmer <[email protected]>Co-developed-by Romain Perier <[email protected]>Signed-off-by Romain Perier <[email protected]>Reviewed-by Guenter Roeck <[email protected]>--- MAINTAINERS | 1 +I tried to apply this patch to my tree, but it doesn't apply because ...
MAINTAINERS
Quoted 8 lines
drivers/watchdog/Kconfig | 12 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/msc313e_wdt.c | 166 +++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/watchdog/msc313e_wdt.cMAINTAINERS +0
-0
a0f37adb9e64is not an upstream SHA and there is a conflict. Please resend the series based on some upstream tag.
Quoted 6 lines
Quoted 1 line
Guenter
Arf, I will rebase and resend then, my bad. It is okay if I rebase the series onto https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git
, branch watchdog-next ?
Please just base it on the latest upstream release tag (currently v5.13-rc5). Git can handle it as long as the base tag is stable.
Thanks,
Guenter