Add watchdog driver for Sunplus SP7021 SoC
Xiantao Hu
maintainerv7 cover Add watchdog driver for Sunplus SP7021 SoC
This is a patch series for watchdog driver for Sunplus SP7021 SoC.
Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.
Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html
Xiantao Hu (2):
dt-bindings: watchdog: Add watchdog yaml file for Sunplus SP7021
watchdog: Add watchdog driver for Sunplus SP7021
.../bindings/watchdog/sunplus,sp7021-wdt.yaml | 47 ++++ MAINTAINERS | 7 + drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/sunplus_wdt.c | 220 ++++++++++++++++++ 5 files changed, 286 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml create mode 100644 drivers/watchdog/sunplus_wdt.c
Signature · 1 line
2.33.1
Xiantao Hu
maintainerPATCH v7 1/2 dt-bindings: watchdog: Add watchdog yaml file for Sunplus SP7021
This adds the documentation for the devicetree bindings of the Sunplus SP7021 watchdog driver, found from SP7021 SoCs and newer.
--- .../bindings/watchdog/sunplus,sp7021-wdt.yaml | 47 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +47 -0
@@ -0,0 +1,47 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/watchdog/sunplus,sp7021-wdt.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus SoCs Watchdog Device Tree Bindings + +maintainers: + - XianTao Hu <[email protected]> + +allOf: + - $ref: watchdog.yaml# + +properties: + compatible: + const: sunplus,sp7021-wdt + + reg: + items: + - description: watchdog registers regions + - description: miscellaneous control registers regions + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + +required: + - compatible + - reg + - clocks + - resets + +additionalProperties: false + +examples: + - | + watchdog: watchdog@9c000630 { + compatible = "sunplus,sp7021-wdt"; + reg = <0x9c000630 0x08>, <0x9C000274 0x04>; + clocks = <&clkc 0x24>; + resets = <&rstc 0x14>; + }; +...
MAINTAINERS +6 -0
@@ -18242,6 +18242,12 @@ L: [email protected] S: Maintained F: drivers/net/ethernet/dlink/sundance.c +SUNPLUS WATCHDOG DRIVER +M: Xiantao Hu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml + SUPERH M: Yoshinori Sato <[email protected]> M: Rich Felker <[email protected]>
Signature · 1 line
2.33.1
Re: [PATCH v7 1/2] dt-bindings: watchdog: Add watchdog yaml file for Sunplus SP7021
Quoted 10 lines · Xiantao Hu
This adds the documentation for the devicetree bindings of the Sunplus SP7021 watchdog driver, found from SP7021 SoCs and newer.
Reviewed-by Rob Herring <[email protected]>Signed-off-by Xiantao Hu <[email protected]>--- .../bindings/watchdog/sunplus,sp7021-wdt.yaml | 47 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
Please use scripts/get_maintainer.pl on recent kernel (newest mainline or recent linux-next) to get the list of people to CC.
Quoted 7 lines
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +0
-0
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml line 8
Quoted 8 lines
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +8
-0@@ -0,0 +1,47 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/watchdog/sunplus,sp7021-wdt.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus SoCs Watchdog Device Tree Bindings
s/Device Tree Bindings//
Quoted 25 lines
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +25
-0+ +maintainers: + - XianTao Hu <[email protected]> + +allOf: + - $ref: watchdog.yaml# + +properties: + compatible: + const: sunplus,sp7021-wdt + + reg: + items: + - description: watchdog registers regions + - description: miscellaneous control registers regions + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + +required: + - compatible + - reg
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml line 43
Quoted 10 lines
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +10
-0+ - clocks + - resets + +additionalProperties: false + +examples: + - | + watchdog: watchdog@9c000630 { + compatible = "sunplus,sp7021-wdt"; + reg = <0x9c000630 0x08>, <0x9C000274 0x04>;
lowercase hex (Second reg)
Can be fixed while applying, so in such case:
Best regards,
Krzysztof
xt.hu[胡先韬]
maintainerRE: [PATCH v7 1/2] dt-bindings: watchdog: Add watchdog yaml file for Sunplus SP7021
Dear Krzysztof
Thanks for your review.
Quoted 22 lines
-----Original Message-----
From: Krzysztof Kozlowski [mailto:[email protected]]
Sent: Monday, March 21, 2022 7:10 PM
To: xt.hu[胡先韬] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳騰 <[email protected]>; qinjian[覃健] <[email protected]>; Rob Herring <[email protected]>
Subject: Re: [PATCH v7 1/2] dt-bindings: watchdog: Add watchdog yaml file for Sunplus SP7021Quoted 10 lines · Xiantao Hu
This adds the documentation for the devicetree bindings of the Sunplus SP7021 watchdog driver, found from SP7021 SoCs and newer.
Reviewed-by Rob Herring <[email protected]>Signed-off-by Xiantao Hu <[email protected]>--- .../bindings/watchdog/sunplus,sp7021-wdt.yaml | 47 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml
Quoted 3 lines
Please use
scripts/get_maintainer.plon recent kernel (newest mainline or recent linux-next) to get the list of people to CC.
I will do it in the next patch.
Quoted 19 lines
Review
Quoted 2 lines
(quoted diff) +0
-0
b/Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yamlDocumentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml line 8
Quoted 13 lines
new file mode 100644
index 000000000..9a9bfe150Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +8
-0@@ -0,0 +1,47 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) Sunplus Co., Ltd. 2021 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/watchdog/sunplus,sp7021-wdt.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sunplus SoCs Watchdog Device Tree Bindingss/Device Tree Bindings//
I will drop the string "Device Tree Bindings".
Quoted 29 lines
Quoted 29 lines
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +29
-0+ +maintainers: + - XianTao Hu <[email protected]> + +allOf: + - $ref: watchdog.yaml# + +properties: + compatible: + const: sunplus,sp7021-wdt + + reg: + items: + - description: watchdog registers regions + - description: miscellaneous control registers regions + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + +required: + - compatible + - reg + - clocks + - resets + +additionalProperties: false
Quoted 9 lines
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml line 43
Quoted 6 lines
Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml new file +6
-0+ +examples: + - | + watchdog: watchdog@9c000630 { + compatible = "sunplus,sp7021-wdt"; + reg = <0x9c000630 0x08>, <0x9C000274 0x04>;lowercase hex (Second reg)
I just realized the driver don't use second reg anymore. I will drop it and modify the description of reg.
Quoted 3 lines
Can be fixed while applying, so in such case:
Reviewed-by Krzysztof Kozlowski <[email protected]>
I got it.
Best regards,
Xian-tao
Quoted 2 lines
Best regards,
Krzysztof
Xiantao Hu
maintainerPATCH v7 2/2 watchdog: Add watchdog driver for Sunplus SP7021
In reply to Xiantao HuSunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.
---
Changes in v7:
- Addressed all comments from Mr. Guenter Roeck.
Fix sp_wdt_ping() and add comment to explain the calculation.
MAINTAINERS | 1 + drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sunplus_wdt.c | 220 +++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 drivers/watchdog/sunplus_wdt.c
MAINTAINERS +1 -0
@@ -18247,6 +18247,7 @@ M: Xiantao Hu <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml +F: drivers/watchdog/sunplus_wdt.c SUPERH M: Yoshinori Sato <[email protected]>
drivers/watchdog/Kconfig +11 -0
@@ -976,6 +976,17 @@ config MSC313E_WATCHDOG To compile this driver as a module, choose M here: the module will be called msc313e_wdt. +config SUNPLUS_WATCHDOG + tristate "Sunplus watchdog support" + depends on ARCH_SUNPLUS || COMPILE_TEST + select WATCHDOG_CORE + help + Say Y here to include support for the watchdog timer + in Sunplus SoCs. + + To compile this driver as a module, choose M here: the + module will be called sunplus_wdt. + # X86 (i386 + ia64 + x86_64) Architecture config ACQUIRE_WDT
drivers/watchdog/Makefile +1 -0
@@ -93,6 +93,7 @@ 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 +obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o # X86 (i386 + ia64 + x86_64) Architecture obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
drivers/watchdog/sunplus_wdt.c new file +220 -0
220 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [PATCH v7 2/2] watchdog: Add watchdog driver for Sunplus SP7021
Quoted 4 lines · Xiantao Hu
Sunplus SP7021 requires watchdog timer support.
Add watchdog driver to enable this.Signed-off-by Xiantao Hu <[email protected]>
Quoted 284 lines
---
Changes in v7:
- Addressed all comments from Mr. Guenter Roeck.
Fixsp_wdt_ping()and add comment to explain the calculation.MAINTAINERS | 1 + drivers/watchdog/Kconfig | 11 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sunplus_wdt.c | 220 +++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 drivers/watchdog/sunplus_wdt.cMAINTAINERS +1
-0@@ -18247,6 +18247,7 @@ M: Xiantao Hu <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/watchdog/sunplus,sp7021-wdt.yaml +F: drivers/watchdog/sunplus_wdt.c SUPERH M: Yoshinori Sato <[email protected]>drivers/watchdog/Kconfig +11
-0@@ -976,6 +976,17 @@ config MSC313E_WATCHDOG To compile this driver as a module, choose M here: the module will be called msc313e_wdt. +config SUNPLUS_WATCHDOG + tristate "Sunplus watchdog support" + depends on ARCH_SUNPLUS || COMPILE_TEST + select WATCHDOG_CORE + help + Say Y here to include support for the watchdog timer + in Sunplus SoCs. + + To compile this driver as a module, choose M here: the + module will be called sunplus_wdt. + # X86 (i386 + ia64 + x86_64) Architecture config ACQUIRE_WDTdrivers/watchdog/Makefile +1
-0@@ -93,6 +93,7 @@ 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 +obj-$(CONFIG_SUNPLUS_WATCHDOG) += sunplus_wdt.o # X86 (i386 + ia64 + x86_64) Architecture obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.odrivers/watchdog/sunplus_wdt.c new file +220
-0@@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* sunplus Watchdog Driver +* +* Copyright (C) 2021 Sunplus Technology Co., Ltd. +* +*/ + +#include <linux/clk.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/platform_device.h> +#include <linux/reset.h> +#include <linux/watchdog.h> + +#define WDT_CTRL 0x00 +#define WDT_CNT 0x04 + +#define WDT_STOP 0x3877 +#define WDT_RESUME 0x4A4B +#define WDT_CLRIRQ 0x7482 +#define WDT_UNLOCK 0xAB00 +#define WDT_LOCK 0xAB01 +#define WDT_CONMAX 0xDEAF + +/* TIMEOUT_MAX = ffff0/90kHz =11.65, so longer than 11 seconds will time out. */ +#define SP_WDT_MAX_TIMEOUT 11U +#define SP_WDT_DEFAULT_TIMEOUT 10 + +#define STC_CLK 90000 + +#define DEVICE_NAME "sunplus-wdt" + +static unsigned int timeout; +module_param (timeout, int,0 ); +MODULE_PARM_DESC (timeout,"Watchdog timeout in seconds" ); + +static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,0 ); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +struct sp_wdt_priv { +struct watchdog_device wdev; +void __iomem *base; +struct clk *clk; +struct reset_control *rstc; +}; + +static int sp_wdt_restart (struct watchdog_device *wdev, +unsigned long action,void *data) +{ +struct sp_wdt_priv *priv =watchdog_get_drvdata (wdev); +void __iomem *base = priv->base; + +writel (WDT_STOP , base +WDT_CTRL ); +writel (WDT_UNLOCK , base +WDT_CTRL ); +writel (0x0001 , base +WDT_CNT ); +writel (WDT_LOCK , base +WDT_CTRL ); +writel (WDT_RESUME , base +WDT_CTRL ); + +return 0 ; +} + +static int sp_wdt_ping (struct watchdog_device *wdev) +{ +struct sp_wdt_priv *priv =watchdog_get_drvdata (wdev); +void __iomem *base = priv->base; +u32 count; + +if (wdev->timeout >SP_WDT_MAX_TIMEOUT ) { +/* WDT_CONMAX sets the count to the maximum (down-counting). */ +writel (WDT_CONMAX , base +WDT_CTRL ); + }else { +writel (WDT_UNLOCK , base +WDT_CTRL ); +/* +* Watchdog timer is a 20-bit down-counting based on STC_CLK. +* This register bits[16:0] is from bit[19:4] of the watchdog +* timer counter. +*/ + count = (wdev->timeout *STC_CLK ) >>4 ; +writel (count, base +WDT_CNT ); +writel (WDT_LOCK , base +WDT_CTRL ); + } + +return 0 ; +} + +static int sp_wdt_stop (struct watchdog_device *wdev) +{ +struct sp_wdt_priv *priv =watchdog_get_drvdata (wdev); +void __iomem *base = priv->base; + +writel (WDT_STOP , base +WDT_CTRL ); + +return 0 ; +} + +static int sp_wdt_start (struct watchdog_device *wdev) +{ +struct sp_wdt_priv *priv =watchdog_get_drvdata (wdev); +void __iomem *base = priv->base; + +writel (WDT_RESUME , base +WDT_CTRL ); + +return 0 ; +} + +static unsigned int sp_wdt_get_timeleft (struct watchdog_device *wdev) +{ +struct sp_wdt_priv *priv =watchdog_get_drvdata (wdev); +void __iomem *base = priv->base; +u32 val; + + val =readl (base +WDT_CNT ); + val &=0xffff ; + val = val <<4 ; + +return val; +} + +static const struct watchdog_info sp_wdt_info = { + .identity =DEVICE_NAME , + .options =WDIOF_SETTIMEOUT | +WDIOF_MAGICCLOSE | +WDIOF_KEEPALIVEPING , +}; + +static const struct watchdog_ops sp_wdt_ops = { + .owner =THIS_MODULE , + .start = sp_wdt_start, + .stop = sp_wdt_stop, + .ping = sp_wdt_ping, + .get_timeleft = sp_wdt_get_timeleft, + .restart = sp_wdt_restart, +}; + +static void sp_clk_disable_unprepare (void *data) +{ +clk_disable_unprepare (data); +} + +static void sp_reset_control_assert (void *data) +{ +reset_control_assert (data); +} + +static int sp_wdt_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct sp_wdt_priv *priv; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (priv->clk)) +return dev_err_probe (dev,PTR_ERR (priv->clk),"Failed to get clock\n" ); + + ret =clk_prepare_enable (priv->clk); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable clock\n" ); + + ret =devm_add_action_or_reset (dev, sp_clk_disable_unprepare, priv->clk); +if (ret) +return ret; + +/* The timer and watchdog shared the STC reset */ + priv->rstc =devm_reset_control_get_shared (dev,NULL ); +if (IS_ERR (priv->rstc)) +return dev_err_probe (dev,PTR_ERR (priv->rstc),"Failed to get reset\n" ); + +reset_control_deassert (priv->rstc); + + ret =devm_add_action_or_reset (dev, sp_reset_control_assert, priv->rstc); +if (ret) +return ret; + + priv->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (priv->base)) +return PTR_ERR (priv->base); + + priv->wdev.info = &sp_wdt_info; + priv->wdev.ops = &sp_wdt_ops; + priv->wdev.timeout =SP_WDT_DEFAULT_TIMEOUT ; + priv->wdev.max_hw_heartbeat_ms =SP_WDT_MAX_TIMEOUT *1000 ; + priv->wdev.min_timeout =1 ; + priv->wdev.parent = dev; + +watchdog_set_drvdata (&priv->wdev, priv); +watchdog_init_timeout (&priv->wdev, timeout, dev); +watchdog_set_nowayout (&priv->wdev, nowayout); +watchdog_stop_on_reboot (&priv->wdev); +watchdog_set_restart_priority (&priv->wdev,128 ); + +return devm_watchdog_register_device (dev, &priv->wdev); +} + +static const struct of_device_id sp_wdt_of_match[] = { + {.compatible ="sunplus,sp7021-wdt" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, sp_wdt_of_match); + +static struct platform_driver sp_wdt_driver = { + .probe = sp_wdt_probe, + .driver = { + .name =DEVICE_NAME , + .of_match_table = sp_wdt_of_match, + }, +}; + +module_platform_driver (sp_wdt_driver); + +MODULE_AUTHOR ("Xiantao Hu <[email protected]>" ); +MODULE_DESCRIPTION ("Sunplus Watchdog Timer Driver" ); +MODULE_LICENSE ("GPL" );