Add i.MX8QXP system controller watchdog support
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.
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/10800699/
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 | 10 + 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 | 210 +++++++++++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.c
Signature · 1 line
2.7.4
PATCH 1/4 dt-bindings: fsl: scu: add watchdog binding
Add i.MX8QXP system controller watchdog binding.
---
Note: this patch is based on my thermal patch series: https://patchwork.kernel.org/patch/10800699/
--- Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt +10 -0
@@ -140,6 +140,12 @@ Required properties: resource id for thermal driver to get temperature via SCU IPC. +WatchDog bindings based on SCU Message Protocol +------------------------------------------------------------ + +Required properties: +- compatible: should be "fsl,imx8qxp-sc-wdt"; + Example (imx8qxp): ------------- lsio_mu1: mailbox@5d1c0000 {
@@ -194,6 +200,10 @@ firmware { tsens-num = <1>; #thermal-sensor-cells = <1>; }; + + wdog: wdog { + compatible = "fsl,imx8qxp-sc-wdt"; + }; }; };
Signature · 7 lines
2.7.4 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 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.
--- drivers/watchdog/Kconfig | 13 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 210 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 224 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 +210 -0
210 lines not on this page · raw message
Signature · 7 lines
2.7.4 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Guenter Roeck
maintainerRe: [PATCH 2/4] watchdog: imx_sc: Add i.MX system controller watchdog support
Quoted 165 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]>--- drivers/watchdog/Kconfig | 13 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 210 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+)create mode 100644
drivers/watchdog/imx_sc_wdt.cdrivers/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_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 +105
-0@@ -0,0 +1,210 @@ +// 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 +#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 ; +module_param (timeout, uint,0000 ); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static struct watchdog_device imx_sc_wdd; + +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; +} + +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" ,
drivers/watchdog/imx_sc_wdt.c line 115
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+ .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | + WDIOF_MAGICCLOSE | WDIOF_PRETIMEOUT, +}; + +#ifdef CONFIG_PM_SLEEP +static int imx_sc_wdt_suspend (struct device *dev) +{ +if (test_bit (WDOG_ACTIVE , &imx_sc_wdd.status)) +imx_sc_wdt_stop (&imx_sc_wdd); +
What is wrong with watchdog_active() ? It is used below ?
Quoted 17 lines
drivers/watchdog/imx_sc_wdt.c new file +17
-0+return 0 ; +} + +static int imx_sc_wdt_resume (struct device *dev) +{ +if (test_bit (WDOG_ACTIVE , &imx_sc_wdd.status)) +imx_sc_wdt_start (&imx_sc_wdd); + +return 0 ; +} + +static const struct dev_pm_ops imx_sc_wdt_pm_ops = { + .suspend = imx_sc_wdt_suspend, + .resume = imx_sc_wdt_resume, +}; + +#define IMX_SC_WDT_PM_OPS (&imx_sc_wdt_pm_ops)
drivers/watchdog/imx_sc_wdt.c line 142
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+ +#else + +#define IMX_SC_WDT_PM_OPS NULL + +#endif + +static int imx_sc_wdt_probe (struct platform_device *pdev) +{ +struct watchdog_device *wdt = &imx_sc_wdd;
Please use devm_kzalloc() and drop the static variable. You can use dev_get_drvdata() to access it where needed.
drivers/watchdog/imx_sc_wdt.c line 153
Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c new file +11
-0+int err; + +platform_set_drvdata (pdev, wdt); + + wdt->info = &imx_sc_wdt_info; + wdt->ops = &imx_sc_wdt_ops; + wdt->min_timeout =1 ; + wdt->max_timeout =MAX_TIMEOUT ; + wdt->parent = &pdev->dev; +watchdog_set_drvdata (wdt,NULL ); +
This is quite pointless.
Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c new file +11
-0+ err =watchdog_init_timeout (wdt,DEFAULT_TIMEOUT , &pdev->dev); +if (err) { +dev_err (&pdev->dev,"Failed to init the wdog timeout:%d\n" , + err); +return err; + } + + err =watchdog_register_device (wdt); +if (err) { +dev_err (&pdev->dev,"Failed to register watchdog device\n" ); +return err;
drivers/watchdog/imx_sc_wdt.c line 174
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+ } + +return 0 ; +} + +static int imx_sc_wdt_remove (struct platform_device *pdev) +{ +struct watchdog_device *wdt =platform_get_drvdata (pdev); + +imx_sc_wdt_stop (wdt);
Any reason for not using watchdog_stop_on_unregister() ?
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+ +watchdog_unregister_device (wdt); + +return 0 ;
drivers/watchdog/imx_sc_wdt.c line 188
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+} + +static void imx_sc_wdt_shutdown (struct platform_device *pdev) +{ +struct watchdog_device *wdt =platform_get_drvdata (pdev); + +if (watchdog_active (wdt)) +imx_sc_wdt_stop (wdt); +} +
Any reason for not using watchdog_stop_on_reboot() ?
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+static const struct of_device_id imx_sc_wdt_dt_ids[] = { + { .compatible ="fsl,imx8qxp-sc-wdt" , }, + {/*sentinel */ } +};
drivers/watchdog/imx_sc_wdt.c line 202
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+MODULE_DEVICE_TABLE (of, imx_sc_wdt_dt_ids); + +static struct platform_driver imx_sc_wdt_driver = { + .probe = imx_sc_wdt_probe, + .remove = imx_sc_wdt_remove, + .shutdown = imx_sc_wdt_shutdown, + .driver = { + .name ="imx-sc-wdt" , + .of_match_table = imx_sc_wdt_dt_ids, + .pm =IMX_SC_WDT_PM_OPS ,
I prefer the use of SIMPLE_DEV_PM_OPS() together with __maybe_unused for the pm functions instead of #ifdef. This ensures that the unused code compiles even if PM_SLEEP is not enabled.
Thanks,
Guenter
PATCH 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.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -427,6 +427,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 · 7 lines
2.7.4 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 4/4 arm64: dts: freescale: imx8qxp: add watchdog support
In reply to Anson HuangAdd i.MX8QXP system controller watchdog support.
---
Note: this patch is based on my thermal patch series: https://patchwork.kernel.org/patch/10800699/
--- arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +4 -0
@@ -155,6 +155,10 @@ tsens-num = <1>; #thermal-sensor-cells = <1>; }; + + wdog: wdog { + compatible = "fsl,imx8qxp-sc-wdt"; + }; }; timer {
Signature · 1 line
2.7.4
Re: [PATCH 4/4] arm64: dts: freescale: imx8qxp: add watchdog support
Quoted 14 lines · Anson Huang
Add i.MX8QXP system controller watchdog support.
Signed-off-by Anson Huang <[email protected]>---
Note: this patch is based on my thermal patch series: https://patchwork.kernel.org/patch/10800699/--- arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 4 ++++ 1 file changed, 4 insertions(+)arch/arm64/boot/dts/freescale/imx8qxp.dtsi +0
-0
arch/arm64/boot/dts/freescale/imx8qxp.dtsi line 159
Quoted 5 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +2
-0@@ -155,6 +155,10 @@ tsens-num = <1>; #thermal-sensor-cells = <1>; }; + + wdog: wdog {
watchdog for node name.
Shawn
Quoted 8 lines
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +2
-0+ compatible = "fsl,imx8qxp-sc-wdt"; + }; }; timer {Signature · 1 line
2.7.4