Add i.MX8QXP system controller watchdog support
v3 cover Add i.MX8QXP system controller watchdog support
i.MX8QXP is an ARMv8 Cortex-A35 SoC with a Cortex-M4 system controller inside, the system controller manages overall power, clock, secure RTC and watchdog etc., so Linux kernel running on A35 needs to communicate with system controller for watchdog operation, this system controller watchdog will call SMC to trap to EL3 secure world ARM-Trusted-Firmware and then it will request system controller to do the watchdog operation via IPC.
This V3 patch series addresses all the comments from V2, and change log is inside each patch of this V3 series.
Below are the patch dependency:
The dt-binding and imx8qxp.dtsi patch are based on my thermal patch series as below:
https://patchwork.kernel.org/patch/10827673/
Anson Huang (4):
dt-bindings: fsl: scu: add watchdog binding
watchdog: imx_sc: Add i.MX system controller watchdog support
arm64: defconfig: add support for i.MX system controller watchdog
arm64: dts: freescale: imx8qxp: add watchdog support
.../devicetree/bindings/arm/freescale/fsl,scu.txt | 12 ++ arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 4 + arch/arm64/configs/defconfig | 1 + drivers/watchdog/Kconfig | 13 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 183 +++++++++++++++++++++ 6 files changed, 214 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.c
Signature · 7 lines
2.7.4 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 1/4 dt-bindings: fsl: scu: add watchdog binding
Add i.MX8QXP system controller watchdog binding.
---
Changes since V2:
- add fallback compatible "fsl,imx-sc-wdt" to cover other i.MX platforms with system controller watchdog available.
- this patch depends on my thermal patch series: https://patchwork.kernel.org/patch/10827673/
--- Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt +12 -0
@@ -137,6 +137,14 @@ Required properties: an array of integers to specify each thermal zone's sensor resource ID. +Watchdog bindings based on SCU Message Protocol +------------------------------------------------------------ + +Required properties: +- compatible: Should be : + "fsl,imx8qxp-sc-wdt" + followed by "fsl,imx-sc-wdt"; + Example (imx8qxp): ------------- lsio_mu1: mailbox@5d1c0000 {
@@ -189,6 +197,10 @@ firmware { #thermal-sensor-cells = <0>; imx,sensor-resource-id = <IMX_SC_R_SYSTEM>; }; + + watchdog: watchdog { + compatible = "fsl,imx8qxp-sc-wdt", "fsl,imx-sc-wdt"; + }; }; };
Signature · 1 line
2.7.4
PATCH v3 2/4 watchdog: imx_sc: Add i.MX system controller watchdog support
In reply to Anson Huangi.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and watchdog etc..
This patch adds i.MX system controller watchdog driver support, watchdog operation needs to be done in secure EL3 mode via ARM-Trusted-Firmware, using SMC call, CPU will trap into ARM-Trusted-Firmware and then it will request system controller to do watchdog operation via IPC.
---
Changes since V2:
- improve watchdog_init_timeout() operation and error check, setting it via module parameter "timeout", if it is invalid, roll back to use defaul timeout value DEFAULT_TIMEOUT;
- change compatible string to "fsl,imx-sc-wdt" to make driver more generic for all i.MX platforms with system controller watchdog inside.
--- drivers/watchdog/Kconfig | 13 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 183 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.c
drivers/watchdog/Kconfig +13 -0
@@ -625,6 +625,19 @@ config IMX2_WDT To compile this driver as a module, choose M here: the module will be called imx2_wdt. +config IMX_SC_WDT + tristate "IMX SC Watchdog" + depends on ARCH_MXC || COMPILE_TEST + select WATCHDOG_CORE + help + This is the driver for the system controller watchdog + on the NXP i.MX SoCs with system controller inside. + If you have one of these processors and wish to have + watchdog support enabled, say Y, otherwise say N. + + To compile this driver as a module, choose M here: the + module will be called imx_sc_wdt. + config UX500_WATCHDOG tristate "ST-Ericsson Ux500 watchdog" depends on MFD_DB8500_PRCMU
drivers/watchdog/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o obj-$(CONFIG_TS4800_WATCHDOG) += ts4800_wdt.o obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o +obj-$(CONFIG_IMX_SC_WDT) += imx_sc_wdt.o obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
drivers/watchdog/imx_sc_wdt.c new file +183 -0
183 lines not on this page · raw message
Signature · 1 line
2.7.4
Guenter Roeck
maintainerRe: [PATCH V3 2/4] watchdog: imx_sc: Add i.MX system controller watchdog support
Quoted 30 lines · Anson Huang
i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and watchdog etc..
This patch adds i.MX system controller watchdog driver support, watchdog operation needs to be done in secure EL3 mode via ARM-Trusted-Firmware, using SMC call, CPU will trap into ARM-Trusted-Firmware and then it will request system controller to do watchdog operation via IPC.
Signed-off-by Anson Huang <[email protected]>---
Changes since V2:
- improvewatchdog_init_timeout()operation and error check, setting it via module parameter "timeout", if it is invalid, roll back to use defaul timeout valueDEFAULT_TIMEOUT;
- change compatible string to "fsl,imx-sc-wdt" to make driver more generic for all i.MX platforms with system controller watchdog inside.--- drivers/watchdog/Kconfig | 13 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 183 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig +0
-0
drivers/watchdog/Kconfig config IMX2_WDT · line 630
Quoted 6 lines
drivers/watchdog/Kconfig +3
-0@@ -625,6 +625,19 @@ config IMX2_WDT To compile this driver as a module, choose M here: the module will be called imx2_wdt. +config IMX_SC_WDT + tristate "IMX SC Watchdog" + depends on ARCH_MXC || COMPILE_TEST
Wondering: Did you test on other architectures ? The code calls arm_smccc_smc(), which is unlikely to be available on non-ARM platforms, and I don't see a dummy declaration for those.
Quoted 62 lines
drivers/watchdog/Kconfig +10
-0+ select WATCHDOG_CORE + help + This is the driver for the system controller watchdog + on the NXP i.MX SoCs with system controller inside. + If you have one of these processors and wish to have + watchdog support enabled, say Y, otherwise say N. + + To compile this driver as a module, choose M here: the + module will be called imx_sc_wdt. + config UX500_WATCHDOG tristate "ST-Ericsson Ux500 watchdog" depends on MFD_DB8500_PRCMUdrivers/watchdog/Makefile +1
-0@@ -68,6 +68,7 @@ obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o obj-$(CONFIG_TS4800_WATCHDOG) += ts4800_wdt.o obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o +obj-$(CONFIG_IMX_SC_WDT) += imx_sc_wdt.o obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.odrivers/watchdog/imx_sc_wdt.c new file +31
-0@@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/reboot.h> +#include <linux/watchdog.h> + +#define DEFAULT_TIMEOUT 60 +/* +* Software timer tick implemented in scfw side, support 10ms to 0xffffffff ms +* in theory, but for normal case, 1s~128s is enough, you can change this max +* value in case it's not enough. +*/ +#define MAX_TIMEOUT 128 + +#define IMX_SIP_TIMER 0xC2000002 +#define IMX_SIP_TIMER_START_WDOG 0x01 +#define IMX_SIP_TIMER_STOP_WDOG 0x02 +#define IMX_SIP_TIMER_SET_WDOG_ACT 0x03 +#define IMX_SIP_TIMER_PING_WDOG 0x04 +#define IMX_SIP_TIMER_SET_TIMEOUT_WDOG 0x05 +#define IMX_SIP_TIMER_GET_WDOG_STAT 0x06
drivers/watchdog/imx_sc_wdt.c line 41
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+#define IMX_SIP_TIMER_SET_PRETIME_WDOG 0x07 + +#define SC_TIMER_WDOG_ACTION_PARTITION 0 + +static bool nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, bool,0000 ); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ;
I assume this means that you specifically do _not_ want to support timeout configuration via devicetree (unless the user explicitly sets the timeout to 0 here).
Not that it really matters, since it looks like Rob won't accept a watchdog node anyway.
drivers/watchdog/imx_sc_wdt.c line 53
Quoted 12 lines
drivers/watchdog/imx_sc_wdt.c new file +12
-0+module_param (timeout, uint,0000 ); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static int imx_sc_wdt_ping (struct watchdog_device *wdog) +{ +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_PING_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); + +return res.a0;
I didn't comment on this before, but I am wondering: Does the system controller code return Linux error codes ? Is this documented somewhere ?
Quoted 82 lines
drivers/watchdog/imx_sc_wdt.c new file +82
-0+} + +static int imx_sc_wdt_start (struct watchdog_device *wdog) +{ +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_START_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); +if (res.a0) +return res.a0; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_SET_WDOG_ACT , +SC_TIMER_WDOG_ACTION_PARTITION , +0 ,0 ,0 ,0 ,0 , &res); +return res.a0; +} + +static int imx_sc_wdt_stop (struct watchdog_device *wdog) +{ +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_STOP_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static int imx_sc_wdt_set_timeout (struct watchdog_device *wdog, +unsigned int timeout) +{ +struct arm_smccc_res res; + + wdog->timeout = timeout; +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_SET_TIMEOUT_WDOG , + timeout *1000 ,0 ,0 ,0 ,0 ,0 , &res); + +return res.a0; +} + +static const struct watchdog_ops imx_sc_wdt_ops = { + .owner =THIS_MODULE , + .start = imx_sc_wdt_start, + .stop = imx_sc_wdt_stop, + .ping = imx_sc_wdt_ping, + .set_timeout = imx_sc_wdt_set_timeout, +}; + +static const struct watchdog_info imx_sc_wdt_info = { + .identity ="i.MX SC watchdog timer" , + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE |WDIOF_PRETIMEOUT , +}; + +static int imx_sc_wdt_probe (struct platform_device *pdev) +{ +struct watchdog_device *imx_sc_wdd; +int ret; + + imx_sc_wdd =devm_kzalloc (&pdev->dev,sizeof (*imx_sc_wdd),GFP_KERNEL ); +if (!imx_sc_wdd) +return -ENOMEM ; + +platform_set_drvdata (pdev, imx_sc_wdd); + + imx_sc_wdd->info = &imx_sc_wdt_info; + imx_sc_wdd->ops = &imx_sc_wdt_ops; + imx_sc_wdd->min_timeout =1 ; + imx_sc_wdd->max_timeout =MAX_TIMEOUT ; + imx_sc_wdd->parent = &pdev->dev; + imx_sc_wdd->timeout =DEFAULT_TIMEOUT ; + + ret =watchdog_init_timeout (imx_sc_wdd, timeout, &pdev->dev); +if (ret) +dev_warn (&pdev->dev,"Failed to set timeout value, using default\n" ); + +watchdog_stop_on_reboot (imx_sc_wdd); +watchdog_stop_on_unregister (imx_sc_wdd); + + ret =devm_watchdog_register_device (&pdev->dev, imx_sc_wdd); +if (ret) { +dev_err (&pdev->dev,"Failed to register watchdog device\n" ); +return ret;
drivers/watchdog/imx_sc_wdt.c line 145
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+ } + +return 0 ; +} + +static const struct of_device_id imx_sc_wdt_dt_ids[] = { + { .compatible ="fsl,imx-sc-wdt" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx_sc_wdt_dt_ids);
I assume this will be dropped and replaced with platform code, per feedback from Rob.
Quoted 28 lines
drivers/watchdog/imx_sc_wdt.c new file +28
-0+ +static int __maybe_unused imx_sc_wdt_suspend (struct device *dev) +{ +struct watchdog_device *imx_sc_wdd =dev_get_drvdata (dev); + +if (watchdog_active (imx_sc_wdd)) +imx_sc_wdt_stop (imx_sc_wdd); + +return 0 ; +} + +static int __maybe_unused imx_sc_wdt_resume (struct device *dev) +{ +struct watchdog_device *imx_sc_wdd =dev_get_drvdata (dev); + +if (watchdog_active (imx_sc_wdd)) +imx_sc_wdt_start (imx_sc_wdd); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(imx_sc_wdt_pm_ops, + imx_sc_wdt_suspend, imx_sc_wdt_resume); + +static struct platform_driver imx_sc_wdt_driver = { + .probe = imx_sc_wdt_probe, + .driver = { + .name ="imx-sc-wdt" ,
drivers/watchdog/imx_sc_wdt.c line 183
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+ .of_match_table = imx_sc_wdt_dt_ids, + .pm = &imx_sc_wdt_pm_ops, + }, +}; + +module_platform_driver (imx_sc_wdt_driver); + +MODULE_AUTHOR ("Robin Gong <[email protected]>" ); +MODULE_DESCRIPTION ("NXP i.MX system controller watchdog driver" ); +MODULE_LICENSE ("GPL v2" );
The module license conflicts with the SPDX license which says 2.0+.
RE: [PATCH V3 2/4] watchdog: imx_sc: Add i.MX system controller watchdog support
Hi, Guenter
Best Regards!
Anson Huang
Quoted 57 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年2月27日 6:39
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V3 2/4] watchdog:imx_sc: Add i.MX system controller watchdog supportQuoted 10 lines · Anson Huang
i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and watchdog etc..
This patch adds i.MX system controller watchdog driver support, watchdog operation needs to be done in secure EL3 mode via ARM-Trusted-Firmware, using SMC call, CPU will trap into ARM-Trusted-Firmware and then it will request system controller to do watchdog operation via IPC.
Quoted 4 lines
Signed-off-by Anson Huang <[email protected]>---
Changes since V2:
- improvewatchdog_init_timeout()operation and error check,setting it
Quoted 1 line
via module parameter "timeout", if it is invalid, roll back to use
defaul
Quoted 2 lines
timeout value DEFAULT_TIMEOUT; - change compatible string to "fsl,imx-sc-wdt" to make driver moregeneric
Quoted 17 lines
for all i.MX platforms with system controller watchdog inside.
--- drivers/watchdog/Kconfig | 13 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 183 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0
-065c3c42..5c5b8ba 100644
drivers/watchdog/Kconfig +0
-0@@ -625,6 +625,19 @@ config IMX2_WDT To compile this driver as a module, choose M here: the module will be called imx2_wdt.
Quoted 7 lines
drivers/watchdog/Kconfig config IMX2_WDT · line 630
Quoted 3 lines
drivers/watchdog/Kconfig +3
-0+config IMX_SC_WDT + tristate "IMX SC Watchdog" + depends on ARCH_MXC || COMPILE_TESTWondering: Did you test on other architectures ? The code calls
arm_smccc_smc(), which is unlikely to be available on non-ARM platforms, and I don't see a dummy declaration for those.
Although the ARCH_MXC means for Freescale i.MX SoCs which are all with ARM platforms, but since this driver is targeted for i.MX SoC ARMv8 with system controller inside, so I will add ARM64 dependency here.
+ depends on (ARCH_MXC && ARM64) || COMPILE_TEST
Quoted 82 lines
drivers/watchdog/Makefile obj-$(CONFIG_NUC900_WATCHDOG) +=
Quoted 19 lines
drivers/watchdog/Kconfig +10
-0+ select WATCHDOG_CORE + help + This is the driver for the system controller watchdog + on the NXP i.MX SoCs with system controller inside. + If you have one of these processors and wish to have + watchdog support enabled, say Y, otherwise say N. + + To compile this driver as a module, choose M here: the + module will be called imx_sc_wdt. + config UX500_WATCHDOG tristate "ST-Ericsson Ux500 watchdog" depends on MFD_DB8500_PRCMUdrivers/watchdog/Makefile +0
-0@@ -68,6 +68,7 @@ obj-$(CONFIG_NUC900_WATCHDOG) +=nuc900_wdt.o
Quoted 40 lines
drivers/watchdog/Makefile +1
-0obj-$(CONFIG_TS4800_WATCHDOG) += ts4800_wdt.o obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o +obj-$(CONFIG_IMX_SC_WDT) += imx_sc_wdt.o obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o diff --git
a/drivers/watchdog/imx_sc_wdt.cb/drivers/watchdog/imx_sc_wdt.cnew file mode 100644 index 0000000..7b22575drivers/watchdog/imx_sc_wdt.c new file +28
-0@@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/reboot.h> +#include <linux/watchdog.h> + +#define DEFAULT_TIMEOUT 60 +/* +* Software timer tick implemented in scfw side, support 10ms to +0xffffffff ms +* in theory, but for normal case, 1s~128s is enough, you can change +this max +* value in case it's not enough. +*/ +#define MAX_TIMEOUT 128 + +#define IMX_SIP_TIMER 0xC2000002 +#define IMX_SIP_TIMER_START_WDOG 0x01drivers/watchdog/imx_sc_wdt.c line 38
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+#define IMX_SIP_TIMER_STOP_WDOG 0x02 +#define IMX_SIP_TIMER_SET_WDOG_ACT 0x03 +#define IMX_SIP_TIMER_PING_WDOG 0x04 +#define IMX_SIP_TIMER_SET_TIMEOUT_WDOG 0x05 +#define IMX_SIP_TIMER_GET_WDOG_STAT 0x06 +#define IMX_SIP_TIMER_SET_PRETIME_WDOG 0x07 + +#define SC_TIMER_WDOG_ACTION_PARTITION 0 + +static bool nowayout =WATCHDOG_NOWAYOUT ;module_param(nowayout,
drivers/watchdog/imx_sc_wdt.c line 39
Quoted 1 line
drivers/watchdog/imx_sc_wdt.c new file +1
-0+bool, 0000); MODULE_PARM_DESC(nowayout, "Watchdog cannot bestopped
drivers/watchdog/imx_sc_wdt.c line 41
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ;I assume this means that you specifically do _not_ want to support timeout configuration via devicetree (unless the user explicitly sets the timeout to 0 here).
Quoted 2 lines
Not that it really matters, since it looks like Rob won't accept a watchdog node anyway.
Yes, currently we will NOT get it from devicetree, although user can still pass it via insmod parameter, but if the parameter is NOT specified or is invalid, default value will be used.
Quoted 15 lines
drivers/watchdog/imx_sc_wdt.c line 53
Quoted 12 lines
drivers/watchdog/imx_sc_wdt.c new file +11
-0+module_param (timeout, uint,0000 ); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static int imx_sc_wdt_ping (struct watchdog_device *wdog) { +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_PING_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); + +return res.a0;I didn't comment on this before, but I am wondering: Does the system controller code return Linux error codes ? Is this documented somewhere ?
I checked our system controller firmware, the ONLY possible error code system controller returns is SC_ERR_NOACCESS, so I will make it return -EACCES if error happen, for the ping operation, system controller always returns 0, so I will make it return 0.
Quoted 86 lines
Quoted 23 lines
drivers/watchdog/imx_sc_wdt.c new file +22
-0+} + +static int imx_sc_wdt_start (struct watchdog_device *wdog) { +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_START_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); +if (res.a0) +return res.a0; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_SET_WDOG_ACT , +SC_TIMER_WDOG_ACTION_PARTITION , +0 ,0 ,0 ,0 ,0 , &res); +return res.a0; +} + +static int imx_sc_wdt_stop (struct watchdog_device *wdog) { +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_STOP_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); +drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+return res.a0; +} + +static int imx_sc_wdt_set_timeout (struct watchdog_device *wdog, +unsigned int timeout) +{ +struct arm_smccc_res res; + + wdog->timeout = timeout; + arm_smccc_smc(IMX_SIP_TIMER,
IMX_SIP_TIMER_SET_TIMEOUT_WDOG,Quoted 12 lines
drivers/watchdog/imx_sc_wdt.c new file +12
-0+ timeout * 1000, 0, 0, 0, 0, 0, &res); + +return res.a0; +} + +static const struct watchdog_ops imx_sc_wdt_ops = { + .owner =THIS_MODULE , + .start = imx_sc_wdt_start, + .stop = imx_sc_wdt_stop, + .ping = imx_sc_wdt_ping, + .set_timeout = imx_sc_wdt_set_timeout, }; +drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+static const struct watchdog_info imx_sc_wdt_info = { + .identity ="i.MX SC watchdog timer" , + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE |WDIOF_PRETIMEOUT , }; + +static int imx_sc_wdt_probe (struct platform_device *pdev) { +struct watchdog_device *imx_sc_wdd; +int ret; + + imx_sc_wdd = devm_kzalloc(&pdev->dev, sizeof(*imx_sc_wdd),
GFP_KERNEL);Quoted 29 lines
drivers/watchdog/imx_sc_wdt.c new file +29
-0+if (!imx_sc_wdd) +return -ENOMEM ; + +platform_set_drvdata (pdev, imx_sc_wdd); + + imx_sc_wdd->info = &imx_sc_wdt_info; + imx_sc_wdd->ops = &imx_sc_wdt_ops; + imx_sc_wdd->min_timeout =1 ; + imx_sc_wdd->max_timeout =MAX_TIMEOUT ; + imx_sc_wdd->parent = &pdev->dev; + imx_sc_wdd->timeout =DEFAULT_TIMEOUT ; + + ret =watchdog_init_timeout (imx_sc_wdd, timeout, &pdev->dev); +if (ret) +dev_warn (&pdev->dev,"Failed to set timeout value, using +default\n"); + +watchdog_stop_on_reboot (imx_sc_wdd); +watchdog_stop_on_unregister (imx_sc_wdd); + + ret =devm_watchdog_register_device (&pdev->dev, imx_sc_wdd); +if (ret) { +dev_err (&pdev->dev,"Failed to register watchdog device\n" ); +return ret; + } + +return 0 ; +} +
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 145
Quoted 5 lines
drivers/watchdog/imx_sc_wdt.c new file +5
-0+static const struct of_device_id imx_sc_wdt_dt_ids[] = { + { .compatible ="fsl,imx-sc-wdt" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx_sc_wdt_dt_ids);I assume this will be dropped and replaced with platform code, per feedback from Rob.
Yes, I will remove it in V4, just register platform device in driver directly.
Quoted 31 lines
Quoted 31 lines
drivers/watchdog/imx_sc_wdt.c new file +30
-0+ +static int __maybe_unused imx_sc_wdt_suspend (struct device *dev) { +struct watchdog_device *imx_sc_wdd =dev_get_drvdata (dev); + +if (watchdog_active (imx_sc_wdd)) +imx_sc_wdt_stop (imx_sc_wdd); + +return 0 ; +} + +static int __maybe_unused imx_sc_wdt_resume (struct device *dev) { +struct watchdog_device *imx_sc_wdd =dev_get_drvdata (dev); + +if (watchdog_active (imx_sc_wdd)) +imx_sc_wdt_start (imx_sc_wdd); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(imx_sc_wdt_pm_ops, + imx_sc_wdt_suspend, imx_sc_wdt_resume); + +static struct platform_driver imx_sc_wdt_driver = { + .probe = imx_sc_wdt_probe, + .driver = { + .name ="imx-sc-wdt" , + .of_match_table = imx_sc_wdt_dt_ids, + .pm = &imx_sc_wdt_pm_ops, + }, +};
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 183
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+ +module_platform_driver (imx_sc_wdt_driver); + +MODULE_AUTHOR ("Robin Gong <[email protected]>" ); +MODULE_DESCRIPTION ("NXP i.MX system controller watchdog driver" ); +MODULE_LICENSE ("GPL v2" );The module license conflicts with the SPDX license which says 2.0+.
OK, I will change the SPDX license to 2.0.
Please help review V4 patch series, the dt-binding and dts patch will be removed.
Thanks,
Anson.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Guenter Roeck
maintainerRe: [PATCH V3 2/4] watchdog: imx_sc: Add i.MX system controller watchdog support
Quoted 70 lines · Anson Huang
Hi, Guenter
Best Regards!
Anson HuangQuoted 57 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年2月27日 6:39
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V3 2/4] watchdog:imx_sc: Add i.MX system controller watchdog supportQuoted 10 lines · Anson Huang
i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and watchdog etc..
This patch adds i.MX system controller watchdog driver support, watchdog operation needs to be done in secure EL3 mode via ARM-Trusted-Firmware, using SMC call, CPU will trap into ARM-Trusted-Firmware and then it will request system controller to do watchdog operation via IPC.
Quoted 4 lines
Signed-off-by Anson Huang <[email protected]>---
Changes since V2:
- improvewatchdog_init_timeout()operation and error check,setting it
Quoted 1 line
via module parameter "timeout", if it is invalid, roll back to use
defaul
Quoted 2 lines
timeout value DEFAULT_TIMEOUT; - change compatible string to "fsl,imx-sc-wdt" to make driver moregeneric
Quoted 17 lines
for all i.MX platforms with system controller watchdog inside.
--- drivers/watchdog/Kconfig | 13 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 183 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+)create mode 100644
drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0
-065c3c42..5c5b8ba 100644
drivers/watchdog/Kconfig +0
-0@@ -625,6 +625,19 @@ config IMX2_WDT To compile this driver as a module, choose M here: the module will be called imx2_wdt.Quoted 7 lines
drivers/watchdog/Kconfig config IMX2_WDT · line 630
Quoted 3 lines
drivers/watchdog/Kconfig +3
-0+config IMX_SC_WDT + tristate "IMX SC Watchdog" + depends on ARCH_MXC || COMPILE_TESTWondering: Did you test on other architectures ? The code calls
arm_smccc_smc(), which is unlikely to be available on non-ARM platforms, and I don't see a dummy declaration for those.
Quoted 6 lines
Although the
ARCH_MXCmeans for Freescale i.MX SoCs which are all with ARM platforms, but since this driver is targeted for i.MX SoC ARMv8 with system controller inside, so I will add ARM64 dependency here.+ depends on (
ARCH_MXC&& ARM64) ||COMPILE_TEST
You are missing my point. It will still try to compile with, say, alpha:allmodconfig (or x86_64:allmodconfig). Did you try that ?
Guenter
Quoted 253 lines
Quoted 82 lines
drivers/watchdog/Makefile obj-$(CONFIG_NUC900_WATCHDOG) +=
Quoted 19 lines
drivers/watchdog/Kconfig +10
-0+ select WATCHDOG_CORE + help + This is the driver for the system controller watchdog + on the NXP i.MX SoCs with system controller inside. + If you have one of these processors and wish to have + watchdog support enabled, say Y, otherwise say N. + + To compile this driver as a module, choose M here: the + module will be called imx_sc_wdt. + config UX500_WATCHDOG tristate "ST-Ericsson Ux500 watchdog" depends on MFD_DB8500_PRCMUdrivers/watchdog/Makefile +0
-0@@ -68,6 +68,7 @@ obj-$(CONFIG_NUC900_WATCHDOG) +=nuc900_wdt.o
Quoted 40 lines
drivers/watchdog/Makefile +1
-0obj-$(CONFIG_TS4800_WATCHDOG) += ts4800_wdt.o obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o +obj-$(CONFIG_IMX_SC_WDT) += imx_sc_wdt.o obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o diff --git
a/drivers/watchdog/imx_sc_wdt.cb/drivers/watchdog/imx_sc_wdt.cnew file mode 100644 index 0000000..7b22575drivers/watchdog/imx_sc_wdt.c new file +28
-0@@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/reboot.h> +#include <linux/watchdog.h> + +#define DEFAULT_TIMEOUT 60 +/* +* Software timer tick implemented in scfw side, support 10ms to +0xffffffff ms +* in theory, but for normal case, 1s~128s is enough, you can change +this max +* value in case it's not enough. +*/ +#define MAX_TIMEOUT 128 + +#define IMX_SIP_TIMER 0xC2000002 +#define IMX_SIP_TIMER_START_WDOG 0x01drivers/watchdog/imx_sc_wdt.c line 38
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+#define IMX_SIP_TIMER_STOP_WDOG 0x02 +#define IMX_SIP_TIMER_SET_WDOG_ACT 0x03 +#define IMX_SIP_TIMER_PING_WDOG 0x04 +#define IMX_SIP_TIMER_SET_TIMEOUT_WDOG 0x05 +#define IMX_SIP_TIMER_GET_WDOG_STAT 0x06 +#define IMX_SIP_TIMER_SET_PRETIME_WDOG 0x07 + +#define SC_TIMER_WDOG_ACTION_PARTITION 0 + +static bool nowayout =WATCHDOG_NOWAYOUT ;module_param(nowayout,
drivers/watchdog/imx_sc_wdt.c line 39
Quoted 1 line
drivers/watchdog/imx_sc_wdt.c new file +1
-0+bool, 0000); MODULE_PARM_DESC(nowayout, "Watchdog cannot bestopped
drivers/watchdog/imx_sc_wdt.c line 41
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ;I assume this means that you specifically do _not_ want to support timeout configuration via devicetree (unless the user explicitly sets the timeout to 0 here).
Quoted 2 lines
Not that it really matters, since it looks like Rob won't accept a watchdog node anyway.
Yes, currently we will NOT get it from devicetree, although user can still pass it via insmod parameter, but if the parameter is NOT specified or is invalid, default value will be used.
Quoted 15 lines
drivers/watchdog/imx_sc_wdt.c line 53
Quoted 12 lines
drivers/watchdog/imx_sc_wdt.c new file +11
-0+module_param (timeout, uint,0000 ); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static int imx_sc_wdt_ping (struct watchdog_device *wdog) { +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_PING_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); + +return res.a0;I didn't comment on this before, but I am wondering: Does the system controller code return Linux error codes ? Is this documented somewhere ?
I checked our system controller firmware, the ONLY possible error code system controller returns is
SC_ERR_NOACCESS, so I will make it return-EACCESif error happen, for the ping operation, system controller always returns 0, so I will make it return 0.Quoted 86 lines
Quoted 23 lines
drivers/watchdog/imx_sc_wdt.c new file +22
-0+} + +static int imx_sc_wdt_start (struct watchdog_device *wdog) { +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_START_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); +if (res.a0) +return res.a0; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_SET_WDOG_ACT , +SC_TIMER_WDOG_ACTION_PARTITION , +0 ,0 ,0 ,0 ,0 , &res); +return res.a0; +} + +static int imx_sc_wdt_stop (struct watchdog_device *wdog) { +struct arm_smccc_res res; + +arm_smccc_smc (IMX_SIP_TIMER ,IMX_SIP_TIMER_STOP_WDOG , +0 ,0 ,0 ,0 ,0 ,0 , &res); +drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+return res.a0; +} + +static int imx_sc_wdt_set_timeout (struct watchdog_device *wdog, +unsigned int timeout) +{ +struct arm_smccc_res res; + + wdog->timeout = timeout; + arm_smccc_smc(IMX_SIP_TIMER,
IMX_SIP_TIMER_SET_TIMEOUT_WDOG,Quoted 12 lines
drivers/watchdog/imx_sc_wdt.c new file +12
-0+ timeout * 1000, 0, 0, 0, 0, 0, &res); + +return res.a0; +} + +static const struct watchdog_ops imx_sc_wdt_ops = { + .owner =THIS_MODULE , + .start = imx_sc_wdt_start, + .stop = imx_sc_wdt_stop, + .ping = imx_sc_wdt_ping, + .set_timeout = imx_sc_wdt_set_timeout, }; +drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+static const struct watchdog_info imx_sc_wdt_info = { + .identity ="i.MX SC watchdog timer" , + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING | +WDIOF_MAGICCLOSE |WDIOF_PRETIMEOUT , }; + +static int imx_sc_wdt_probe (struct platform_device *pdev) { +struct watchdog_device *imx_sc_wdd; +int ret; + + imx_sc_wdd = devm_kzalloc(&pdev->dev, sizeof(*imx_sc_wdd),
GFP_KERNEL);Quoted 29 lines
drivers/watchdog/imx_sc_wdt.c new file +29
-0+if (!imx_sc_wdd) +return -ENOMEM ; + +platform_set_drvdata (pdev, imx_sc_wdd); + + imx_sc_wdd->info = &imx_sc_wdt_info; + imx_sc_wdd->ops = &imx_sc_wdt_ops; + imx_sc_wdd->min_timeout =1 ; + imx_sc_wdd->max_timeout =MAX_TIMEOUT ; + imx_sc_wdd->parent = &pdev->dev; + imx_sc_wdd->timeout =DEFAULT_TIMEOUT ; + + ret =watchdog_init_timeout (imx_sc_wdd, timeout, &pdev->dev); +if (ret) +dev_warn (&pdev->dev,"Failed to set timeout value, using +default\n"); + +watchdog_stop_on_reboot (imx_sc_wdd); +watchdog_stop_on_unregister (imx_sc_wdd); + + ret =devm_watchdog_register_device (&pdev->dev, imx_sc_wdd); +if (ret) { +dev_err (&pdev->dev,"Failed to register watchdog device\n" ); +return ret; + } + +return 0 ; +} +Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 145
Quoted 5 lines
drivers/watchdog/imx_sc_wdt.c new file +5
-0+static const struct of_device_id imx_sc_wdt_dt_ids[] = { + { .compatible ="fsl,imx-sc-wdt" , }, + {/* sentinel */ } +}; +MODULE_DEVICE_TABLE (of, imx_sc_wdt_dt_ids);I assume this will be dropped and replaced with platform code, per feedback from Rob.
Yes, I will remove it in V4, just register platform device in driver directly.
Quoted 31 lines
Quoted 31 lines
drivers/watchdog/imx_sc_wdt.c new file +30
-0+ +static int __maybe_unused imx_sc_wdt_suspend (struct device *dev) { +struct watchdog_device *imx_sc_wdd =dev_get_drvdata (dev); + +if (watchdog_active (imx_sc_wdd)) +imx_sc_wdt_stop (imx_sc_wdd); + +return 0 ; +} + +static int __maybe_unused imx_sc_wdt_resume (struct device *dev) { +struct watchdog_device *imx_sc_wdd =dev_get_drvdata (dev); + +if (watchdog_active (imx_sc_wdd)) +imx_sc_wdt_start (imx_sc_wdd); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(imx_sc_wdt_pm_ops, + imx_sc_wdt_suspend, imx_sc_wdt_resume); + +static struct platform_driver imx_sc_wdt_driver = { + .probe = imx_sc_wdt_probe, + .driver = { + .name ="imx-sc-wdt" , + .of_match_table = imx_sc_wdt_dt_ids, + .pm = &imx_sc_wdt_pm_ops, + }, +};Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 183
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+ +module_platform_driver (imx_sc_wdt_driver); + +MODULE_AUTHOR ("Robin Gong <[email protected]>" ); +MODULE_DESCRIPTION ("NXP i.MX system controller watchdog driver" ); +MODULE_LICENSE ("GPL v2" );The module license conflicts with the SPDX license which says 2.0+.
OK, I will change the SPDX license to 2.0.
Please help review V4 patch series, the dt-binding and dts patch will be removed.
Thanks,
Anson.
PATCH v3 3/4 arm64: defconfig: add support for i.MX system controller watchdog
In reply to Anson HuangEnable CONFIG_IMX_SC_WDT as module to support i.MX system controller watchdog.
---
No changes since V2.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -428,6 +428,7 @@ CONFIG_WATCHDOG=y CONFIG_ARM_SP805_WATCHDOG=y CONFIG_S3C2410_WATCHDOG=y CONFIG_IMX2_WDT=y +CONFIG_IMX_SC_WDT=m CONFIG_MESON_GXBB_WATCHDOG=m CONFIG_MESON_WATCHDOG=m CONFIG_RENESAS_WDT=y
Signature · 1 line
2.7.4
PATCH v3 4/4 arm64: dts: freescale: imx8qxp: add watchdog support
In reply to Anson HuangAdd i.MX8QXP system controller watchdog support.
---
Changes since V2:
- add fallback compatilbe "fsl,imx-sc-wdt" for other i.MX platforms with system controller watchdog available;
- this patch depends on my thermal patch series: https://patchwork.kernel.org/patch/10827673/
--- arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +4 -0
@@ -123,6 +123,10 @@ #thermal-sensor-cells = <0>; imx,sensor-resource-id = <IMX_SC_R_SYSTEM>; }; + + watchdog: watchdog { + compatible = "fsl,imx8qxp-sc-wdt", "fsl,imx-sc-wdt"; + }; }; timer {
Signature · 1 line
2.7.4