watchdog: imx_sc: Add i.MX system controller watchdog support
Subsystems (2)
PATCH v5 1/2 watchdog: imx_sc: Add i.MX system controller watchdog support
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.
---
Changes since V4:
- change the module build dependency as depends on IMX_SCU and HAVE_ARM_SMCCC, as this driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call.
--- drivers/watchdog/Kconfig | 14 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.c
drivers/watchdog/Kconfig +14 -0
@@ -625,6 +625,20 @@ 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 IMX_SCU + depends on HAVE_ARM_SMCCC + 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 +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v5 2/2 arm64: defconfig: add support for i.MX system controller watchdog
Enable CONFIG_IMX_SC_WDT as module to support i.MX system controller watchdog.
---
No changes.
--- 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 · 1 line
2.7.4
Guenter Roeck
maintainerQuoted 67 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 V4:
- change the module build dependency as depends onIMX_SCUandHAVE_ARM_SMCCC, as this driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call.--- drivers/watchdog/Kconfig | 14 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig +14
-0@@ -625,6 +625,20 @@ 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 IMX_SCU + depends on HAVE_ARM_SMCCC + 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 +2
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +/*
drivers/watchdog/imx_sc_wdt.c line 12
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-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>
Should no longer be needed.
Quoted 164 lines
drivers/watchdog/imx_sc_wdt.c new file +164
-0+#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 platform_device *imx_sc_wdt_pdev; + +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 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 -EACCES ; + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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; + } + +return 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" , + .pm = &imx_sc_wdt_pm_ops, + }, +}; + +static int __init imx_sc_wdt_init (void ) +{ +int ret;
drivers/watchdog/imx_sc_wdt.c line 186
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+ + ret =platform_driver_register (&imx_sc_wdt_driver); +if (ret) +return ret; + + imx_sc_wdt_pdev =platform_device_register_simple ("imx-sc-wdt" ,-1 ,NULL ,0 ); +if (IS_ERR (imx_sc_wdt_pdev)) { +platform_driver_unregister (&imx_sc_wdt_driver); +return PTR_ERR (imx_sc_wdt_pdev); + }
I just realized what you are doing here. So the watchdog will always be instantiated if/when the module is loaded. I don't think that was the idea, and it seems to be risky. What happens if someone loads the module on a system where the watchdog is not supported ? There maye be lots of "Access Denied" errors, or something undefined may happen.
Is everyone on Cc: ok with this ? Is this how we handle instantiations nowadays ? Or should the driver be instantiated from imx_scu_probe() in drivers/firmware/imx/imx-scu.c ?
Sorry if the answer is obvious, but I am still struggling with "no more instantiations through devicetree".
If the driver is auto-instantiated when the module is loaded, as currently written, there needs to be some check if it is actually supported, possibly in imx_sc_wdt_init() or, if that is not possible, in the probe function. I don't like that, but it would at least prevent the module from being loaded when the hardware is not supported.
Guenter
Quoted 18 lines
drivers/watchdog/imx_sc_wdt.c new file +15
-0+ +return 0 ; +} +module_init (imx_sc_wdt_init); + +static void __exit imx_sc_wdt_exit(void) +{ +platform_driver_unregister (&imx_sc_wdt_driver); +platform_device_unregister (imx_sc_wdt_pdev); +} +module_exit (imx_sc_wdt_exit); + +MODULE_AUTHOR ("Robin Gong <[email protected]>" ); +MODULE_DESCRIPTION ("NXP i.MX system controller watchdog driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
2.7.4
Hi, Guenter
Best Regards!
Anson Huang
Quoted 91 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月2日 2:32
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] 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 V4:
- change the module build dependency as depends onIMX_SCUand
HAVE_ARM_SMCCC, as thisdrivers/watchdog/Makefile obj-$(CONFIG_NUC900_WATCHDOG) +=
Quoted 39 lines
driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call.
--- drivers/watchdog/Kconfig | 14 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0
-065c3c42..a6bfa54 100644
drivers/watchdog/Kconfig +14
-0@@ -625,6 +625,20 @@ 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 IMX_SCU + depends on HAVE_ARM_SMCCC + 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 18 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..50b49b2drivers/watchdog/imx_sc_wdt.c new file +6
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h>
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 12
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> Should no longer be needed.
Correct, I will remove it.
Quoted 171 lines
Quoted 17 lines
drivers/watchdog/imx_sc_wdt.c new file +16
-0+#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 36
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 44
Quoted 5 lines
drivers/watchdog/imx_sc_wdt.c new file +5
-0+once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ;module_param (timeout, +uint, 0000); MODULE_PARM_DESC(timeout, "Watchdog timeout inseconds
Quoted 34 lines
drivers/watchdog/imx_sc_wdt.c new file +34
-0+(default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static struct platform_device *imx_sc_wdt_pdev; + +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 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 -EACCES ; + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 56 lines
drivers/watchdog/imx_sc_wdt.c new file +56
-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 ; +} + +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" , + .pm = &imx_sc_wdt_pm_ops, + },drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+}; + +static int __init imx_sc_wdt_init (void ) { +int ret; + + ret =platform_driver_register (&imx_sc_wdt_driver); +if (ret) +return ret; + + imx_sc_wdt_pdev = platform_device_register_simple("imx-sc-wdt", -1, NULL, 0);
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c line 186
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+if (IS_ERR (imx_sc_wdt_pdev)) { +platform_driver_unregister (&imx_sc_wdt_driver); +return PTR_ERR (imx_sc_wdt_pdev); + }I just realized what you are doing here. So the watchdog will always be instantiated if/when the module is loaded. I don't think that was the idea, and it seems to be risky. What happens if someone loads the module on a system where the watchdog is not supported ? There maye be lots of "Access Denied" errors, or something undefined may happen.
I thought the "depends on IMX_SCU" was already added in Kconfig, that means the module will be ONLY built with IMX_SCU enabled, and watchdog will be always enabled if IMX_SCU is enabled. Is it safe enough?
Quoted 5 lines
Is everyone on Cc: ok with this ? Is this how we handle instantiations nowadays ? Or should the driver be instantiated from
imx_scu_probe()indrivers/firmware/imx/imx-scu.c?
Quoted 8 lines
Sorry if the answer is obvious, but I am still struggling with "no more instantiations through devicetree".
If the driver is auto-instantiated when the module is loaded, as currently written, there needs to be some check if it is actually supported, possibly in
imx_sc_wdt_init()or, if that is not possible, in the probe function. I don't like that, but it would at least prevent the module from being loaded when the hardware is not supported.
Other modules depend on the IMX_SCU IPC will have defer probe there to make sure IMX_SCU driver is ready for IPC handle, since watchdog driver ONLY uses ARM SMC but no IPC call, so I did NOT add the defer probe handle here, so if adding it can answer your question/concern, then I can add it, although I think the dependency in Kconfig should be good here. Without SCU firmware ready, the SoC does NOT boot up A core with ATF/Linux at all.
Thanks,
Anson.
RTC:
68 static int imx_sc_rtc_probe(struct platform_device *pdev) 69 {
70 int ret;
71
72 ret = imx_scu_get_handle(&rtc_ipc_handle);
73 if (ret)
74 return ret;
SCU:
92 int imx_scu_get_handle(struct imx_sc_ipc **ipc) 93 {
94 if (!imx_sc_ipc_handle)
95 return -EPROBE_DEFER;
96
97 *ipc = imx_sc_ipc_handle;
98 return 0;
99 }
100 EXPORT_SYMBOL(imx_scu_get_handle);
Quoted 12 lines
Guenter
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c new file +9
-0+ +return 0 ; +} +module_init (imx_sc_wdt_init); + +static void __exit imx_sc_wdt_exit(void) { +platform_driver_unregister (&imx_sc_wdt_driver); +platform_device_unregister (imx_sc_wdt_pdev); +}
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c new file +5
-1+module_exit (imx_sc_wdt_exit); + +MODULE_AUTHOR ("Robin Gong <[email protected]>" ); +MODULE_DESCRIPTION ("NXP i.MX system controller watchdog driver" ); +MODULE_LICENSE ("GPL v2" ); --2.7.4
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Guenter Roeck
maintainerQuoted 289 lines · Anson Huang
Hi, Guenter
Best Regards!
Anson HuangQuoted 91 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月2日 2:32
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] 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 V4:
- change the module build dependency as depends onIMX_SCUand
HAVE_ARM_SMCCC, as thisdrivers/watchdog/Makefile obj-$(CONFIG_NUC900_WATCHDOG) +=
Quoted 39 lines
driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call.
--- drivers/watchdog/Kconfig | 14 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+)create mode 100644
drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0
-065c3c42..a6bfa54 100644
drivers/watchdog/Kconfig +14
-0@@ -625,6 +625,20 @@ 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 IMX_SCU + depends on HAVE_ARM_SMCCC + 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 18 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..50b49b2drivers/watchdog/imx_sc_wdt.c new file +6
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h> Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 12
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> Should no longer be needed.
Correct, I will remove it.
Quoted 171 lines
Quoted 17 lines
drivers/watchdog/imx_sc_wdt.c new file +16
-0+#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 36
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 44
Quoted 5 lines
drivers/watchdog/imx_sc_wdt.c new file +5
-0+once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ;module_param (timeout, +uint, 0000); MODULE_PARM_DESC(timeout, "Watchdog timeout inseconds
Quoted 34 lines
drivers/watchdog/imx_sc_wdt.c new file +34
-0+(default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static struct platform_device *imx_sc_wdt_pdev; + +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 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 -EACCES ; + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 56 lines
drivers/watchdog/imx_sc_wdt.c new file +56
-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 ; +} + +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" , + .pm = &imx_sc_wdt_pm_ops, + },drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+}; + +static int __init imx_sc_wdt_init (void ) { +int ret; + + ret =platform_driver_register (&imx_sc_wdt_driver); +if (ret) +return ret; + + imx_sc_wdt_pdev = platform_device_register_simple("imx-sc-wdt", -1, NULL, 0);
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c line 186
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+if (IS_ERR (imx_sc_wdt_pdev)) { +platform_driver_unregister (&imx_sc_wdt_driver); +return PTR_ERR (imx_sc_wdt_pdev); + }I just realized what you are doing here. So the watchdog will always be instantiated if/when the module is loaded. I don't think that was the idea, and it seems to be risky. What happens if someone loads the module on a system where the watchdog is not supported ? There maye be lots of "Access Denied" errors, or something undefined may happen.
Quoted 4 lines
I thought the "depends on
IMX_SCU" was already added inKconfig, that means the module will be ONLY built withIMX_SCUenabled, and watchdog will be always enabled ifIMX_SCUis enabled. Is it safe enough?
No. The driver will be built with arm64:defconfig, meaning it will be built for all arm64 systems using defconfig. Any such system will have the driver installed as module, and nothing will prevent the user from running modprobe. But even if it wasn't enabled with defconfig, we must not instantiate the driver on an arbitrary system.
Quoted 14 lines
Quoted 5 lines
Is everyone on Cc: ok with this ? Is this how we handle instantiations nowadays ? Or should the driver be instantiated from
imx_scu_probe()indrivers/firmware/imx/imx-scu.c?Quoted 8 lines
Sorry if the answer is obvious, but I am still struggling with "no more instantiations through devicetree".
If the driver is auto-instantiated when the module is loaded, as currently written, there needs to be some check if it is actually supported, possibly in
imx_sc_wdt_init()or, if that is not possible, in the probe function. I don't like that, but it would at least prevent the module from being loaded when the hardware is not supported.
Quoted 7 lines
Other modules depend on the
IMX_SCUIPC will have defer probe there to make sureIMX_SCUdriver is ready for IPC handle, since watchdog driver ONLY uses ARM SMC but no IPC call, so I did NOT add the defer probe handle here, so if adding it can answer your question/concern, then I can add it, although I think the dependency inKconfigshould be good here. Without SCU firmware ready, the SoC does NOT boot up A core with ATF/Linux at all.
That has nothing to do with deferred probing. My concern is that the driver will be instantiated just by loading it, no matter if the hardware supporting it is present or not.
Having a devicetree node would have prevented that since it instantiates the child drivers with devm_of_platform_populate() in imx_scu_probe(). The equivalent is to register the platform device from imx_scu_probe(). That is the only means to prevent the driver from being instantiated where it shouldn't. As mentioned before, I would have preferred the devicetree method, but having it no longer available doesn't mean that we should add risky code.
Maybe you can check in the init function if the 'fsl,imx-scu' node exists, and instantiate the driver if it does. I don't like that either, but it would be acceptable to me - and maybe better than instantiating it manually from imx_scu_probe().
Guenter
Quoted 43 lines
Thanks,
Anson.RTC:
68 static intimx_sc_rtc_probe(struct platform_device *pdev)69 {
70 int ret;
71
72 ret =imx_scu_get_handle(&rtc_ipc_handle);
73 if (ret)
74 return ret;SCU:
92 intimx_scu_get_handle(struct imx_sc_ipc **ipc)93 {
94 if (!imx_sc_ipc_handle)
95 return -EPROBE_DEFER;
96
97 *ipc =imx_sc_ipc_handle;
98 return 0;
99 }
100EXPORT_SYMBOL(imx_scu_get_handle);Quoted 20 lines
Guenter
Quoted 17 lines
drivers/watchdog/imx_sc_wdt.c new file +14
-1+ +return 0 ; +} +module_init (imx_sc_wdt_init); + +static void __exit imx_sc_wdt_exit(void) { +platform_driver_unregister (&imx_sc_wdt_driver); +platform_device_unregister (imx_sc_wdt_pdev); +} +module_exit (imx_sc_wdt_exit); + +MODULE_AUTHOR ("Robin Gong <[email protected]>" ); +MODULE_DESCRIPTION ("NXP i.MX system controller watchdog driver" ); +MODULE_LICENSE ("GPL v2" ); --2.7.4
Hi, Guenter
Best Regards!
Anson Huang
Quoted 356 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月4日 10:46
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] watchdog:imx_sc: Add i.MX system controller watchdog supportQuoted 14 lines · Anson Huang
Hi, Guenter
Best Regards!
Anson HuangQuoted 9 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月2日 2:32
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected];Quoted 65 lines
Quoted 65 lines
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] 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 V4:
- change the module build dependency as depends onIMX_SCUand
HAVE_ARM_SMCCC, as thisdrivers/watchdog/Makefile obj-$(CONFIG_NUC900_WATCHDOG) +=
Quoted 40 lines
driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call.
--- drivers/watchdog/Kconfig | 14 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+)create mode 100644
drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig +0
-0index
65c3c42..a6bfa54 100644drivers/watchdog/Kconfig +14
-0@@ -625,6 +625,20 @@ 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 IMX_SCU + depends on HAVE_ARM_SMCCC + 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 8 lines
Quoted 8 lines
Quoted 8 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
Quoted 204 lines
Quoted 10 lines
Quoted 10 lines
file mode 100644 index 0000000..50b49b2
drivers/watchdog/imx_sc_wdt.c new file +6
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h> Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 12
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> Should no longer be needed.
Correct, I will remove it.
Quoted 172 lines
Quoted 17 lines
drivers/watchdog/imx_sc_wdt.c new file +16
-0+#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 36
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
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ; +module_param(timeout, uint, 0000); MODULE_PARM_DESC(timeout, +"Watchdog timeout inseconds
Quoted 34 lines
drivers/watchdog/imx_sc_wdt.c new file +34
-0+(default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static struct platform_device *imx_sc_wdt_pdev; + +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 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 -EACCES ; + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 56 lines
drivers/watchdog/imx_sc_wdt.c new file +56
-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 ; +} + +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" , + .pm = &imx_sc_wdt_pm_ops, + },drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+}; + +static int __init imx_sc_wdt_init (void ) { +int ret; + + ret =platform_driver_register (&imx_sc_wdt_driver); +if (ret) +return ret; + + imx_sc_wdt_pdev = platform_device_register_simple("imx-sc-wdt", -1, NULL, 0);
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c line 186
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+if (IS_ERR (imx_sc_wdt_pdev)) { +platform_driver_unregister (&imx_sc_wdt_driver); +return PTR_ERR (imx_sc_wdt_pdev); + }I just realized what you are doing here. So the watchdog will always be instantiated if/when the module is loaded. I don't think that was the idea, and it seems to be risky. What happens if someone loads the module on a system where the watchdog is not supported ? There maye be lots of "Access Denied" errors, or something undefined may happen.
Quoted 4 lines
I thought the "depends on
IMX_SCU" was already added inKconfig, that means the module will be ONLY built withIMX_SCUenabled, and watchdog will be always enabled ifIMX_SCUis enabled. Is it safe enough?No. The driver will be built with arm64:defconfig, meaning it will be built for all arm64 systems using defconfig. Any such system will have the driver installed as module, and nothing will prevent the user from running modprobe. But even if it wasn't enabled with defconfig, we must not instantiate the driver on an arbitrary system.
Quoted 15 lines
Quoted 8 lines
Is everyone on Cc: ok with this ? Is this how we handle instantiations nowadays ? Or should the driver be instantiated from
imx_scu_probe()indrivers/firmware/imx/imx-scu.c?Sorry if the answer is obvious, but I am still struggling with "no more instantiations through devicetree".
Quoted 6 lines
If the driver is auto-instantiated when the module is loaded, as currently written, there needs to be some check if it is actually supported, possibly in
imx_sc_wdt_init()or, if that is not possible, in the probe function. I don't like that, but it would at least prevent the module from being loaded when the hardware is not supported.Quoted 6 lines
Other modules depend on the
IMX_SCUIPC will have defer probe there to make sureIMX_SCUdriver is ready for IPC handle, since watchdog driver ONLY uses ARM SMC but no IPC call, so I did NOT add the defer probe handle here, so if adding it can answer your question/concern, then I can add it, although I think the dependency inKconfigshould be good here. Without SCU firmware ready, the SoC does NOT boot up Acore with ATF/Linux at all.
Quoted 1 line
That has nothing to do with deferred probing. My concern is that the driver will be instantiated just by loading it, no matter if the hardware supporting it is present or not.
Having a devicetree node would have prevented that since it instantiates the child drivers with
devm_of_platform_populate()inimx_scu_probe(). The equivalent is to register the platform device fromimx_scu_probe(). That is the only means to prevent the driver from being instantiated where it shouldn't. As mentioned before, I would have preferred the devicetree method, but having it no longer available doesn't mean that we should add risky code.
Quoted 4 lines
Maybe you can check in the init function if the 'fsl,imx-scu' node exists, and instantiate the driver if it does. I don't like that either, but it would be acceptable to me - and maybe better than instantiating it manually from
imx_scu_probe().
OK, I can add check of "fsl,imx-scu" in init function and ONLY instantiate the driver if it exist, since there is no watchdog node in devicetree and "fsl,imx-scu" should be treated as watchdog node, so adding such check also makes some sense, putting it inside SCU driver is NOT that good I think, do you agree?
Anson.
Quoted 46 lines
Guenter
Quoted 43 lines
Thanks,
Anson.RTC:
68 static intimx_sc_rtc_probe(struct platform_device *pdev)69 {
70 int ret;
71
72 ret =imx_scu_get_handle(&rtc_ipc_handle);
73 if (ret)
74 return ret;SCU:
92 intimx_scu_get_handle(struct imx_sc_ipc **ipc)93 {
94 if (!imx_sc_ipc_handle)
95 return -EPROBE_DEFER;
96
97 *ipc =imx_sc_ipc_handle;
98 return 0;
99 }
100EXPORT_SYMBOL(imx_scu_get_handle);Quoted 20 lines
Guenter
Quoted 17 lines
drivers/watchdog/imx_sc_wdt.c new file +14
-1+ +return 0 ; +} +module_init (imx_sc_wdt_init); + +static void __exit imx_sc_wdt_exit(void) { +platform_driver_unregister (&imx_sc_wdt_driver); +platform_device_unregister (imx_sc_wdt_pdev); +} +module_exit (imx_sc_wdt_exit); + +MODULE_AUTHOR ("Robin Gong <[email protected]>" ); +MODULE_DESCRIPTION ("NXP i.MX system controller watchdog driver" ); +MODULE_LICENSE ("GPL v2" ); --2.7.4
Guenter Roeck
maintainerQuoted 366 lines · Anson Huang
Hi, Guenter
Best Regards!
Anson HuangQuoted 356 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月4日 10:46
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] watchdog:imx_sc: Add i.MX system controller watchdog supportQuoted 14 lines · Anson Huang
Hi, Guenter
Best Regards!
Anson HuangQuoted 9 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月2日 2:32
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected];Quoted 65 lines
Quoted 65 lines
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] 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 V4:
- change the module build dependency as depends onIMX_SCUand
HAVE_ARM_SMCCC, as thisdrivers/watchdog/Makefile obj-$(CONFIG_NUC900_WATCHDOG) +=
Quoted 40 lines
driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call.
--- drivers/watchdog/Kconfig | 14 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+)create mode 100644
drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig +0
-0index
65c3c42..a6bfa54 100644drivers/watchdog/Kconfig +14
-0@@ -625,6 +625,20 @@ 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 IMX_SCU + depends on HAVE_ARM_SMCCC + 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 8 lines
Quoted 8 lines
Quoted 8 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
Quoted 204 lines
Quoted 10 lines
Quoted 10 lines
file mode 100644 index 0000000..50b49b2
drivers/watchdog/imx_sc_wdt.c new file +6
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h> Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 12
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> Should no longer be needed.
Correct, I will remove it.
Quoted 172 lines
Quoted 17 lines
drivers/watchdog/imx_sc_wdt.c new file +16
-0+#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 36
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
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ; +module_param(timeout, uint, 0000); MODULE_PARM_DESC(timeout, +"Watchdog timeout inseconds
Quoted 34 lines
drivers/watchdog/imx_sc_wdt.c new file +34
-0+(default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static struct platform_device *imx_sc_wdt_pdev; + +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 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 -EACCES ; + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 ? -EACCES :0 ; +} + +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 56 lines
drivers/watchdog/imx_sc_wdt.c new file +56
-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 ; +} + +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" , + .pm = &imx_sc_wdt_pm_ops, + },drivers/watchdog/imx_sc_wdt.c
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c new file +10
-0+}; + +static int __init imx_sc_wdt_init (void ) { +int ret; + + ret =platform_driver_register (&imx_sc_wdt_driver); +if (ret) +return ret; + + imx_sc_wdt_pdev = platform_device_register_simple("imx-sc-wdt", -1, NULL, 0);
Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c line 186
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+if (IS_ERR (imx_sc_wdt_pdev)) { +platform_driver_unregister (&imx_sc_wdt_driver); +return PTR_ERR (imx_sc_wdt_pdev); + }I just realized what you are doing here. So the watchdog will always be instantiated if/when the module is loaded. I don't think that was the idea, and it seems to be risky. What happens if someone loads the module on a system where the watchdog is not supported ? There maye be lots of "Access Denied" errors, or something undefined may happen.
Quoted 4 lines
I thought the "depends on
IMX_SCU" was already added inKconfig, that means the module will be ONLY built withIMX_SCUenabled, and watchdog will be always enabled ifIMX_SCUis enabled. Is it safe enough?No. The driver will be built with arm64:defconfig, meaning it will be built for all arm64 systems using defconfig. Any such system will have the driver installed as module, and nothing will prevent the user from running modprobe. But even if it wasn't enabled with defconfig, we must not instantiate the driver on an arbitrary system.
Quoted 15 lines
Quoted 8 lines
Is everyone on Cc: ok with this ? Is this how we handle instantiations nowadays ? Or should the driver be instantiated from
imx_scu_probe()indrivers/firmware/imx/imx-scu.c?Sorry if the answer is obvious, but I am still struggling with "no more instantiations through devicetree".
Quoted 6 lines
If the driver is auto-instantiated when the module is loaded, as currently written, there needs to be some check if it is actually supported, possibly in
imx_sc_wdt_init()or, if that is not possible, in the probe function. I don't like that, but it would at least prevent the module from being loaded when the hardware is not supported.Quoted 6 lines
Other modules depend on the
IMX_SCUIPC will have defer probe there to make sureIMX_SCUdriver is ready for IPC handle, since watchdog driver ONLY uses ARM SMC but no IPC call, so I did NOT add the defer probe handle here, so if adding it can answer your question/concern, then I can add it, although I think the dependency inKconfigshould be good here. Without SCU firmware ready, the SoC does NOT boot up Acore with ATF/Linux at all.
Quoted 1 line
That has nothing to do with deferred probing. My concern is that the driver will be instantiated just by loading it, no matter if the hardware supporting it is present or not.
Having a devicetree node would have prevented that since it instantiates the child drivers with
devm_of_platform_populate()inimx_scu_probe(). The equivalent is to register the platform device fromimx_scu_probe(). That is the only means to prevent the driver from being instantiated where it shouldn't. As mentioned before, I would have preferred the devicetree method, but having it no longer available doesn't mean that we should add risky code.Quoted 4 lines
Maybe you can check in the init function if the 'fsl,imx-scu' node exists, and instantiate the driver if it does. I don't like that either, but it would be acceptable to me - and maybe better than instantiating it manually from
imx_scu_probe().
Quoted 5 lines
OK, I can add check of "fsl,imx-scu" in init function and ONLY instantiate the driver if it exist, since there is no watchdog node in devicetree and "fsl,imx-scu" should be treated as watchdog node, so adding such check also makes some sense, putting it inside SCU driver is NOT that good I think, do you agree?
I dislike both. Putting it into the SCU driver probe function would be more appropriate. Putting it into the watchdog driver is worse since it should really only be instantiated if (and after) the parent driver is instantiated, and the parent driver should be listed as its parent. That will get lost if you put the check into the watchdog driver.
I would suggest to submit the patch for the SCU driver first. If that gets rejected by its maintainer, we'll have to do it in the watchdog driver.
Guenter
Hi, Guenter
Best Regards!
Anson Huang
Quoted 411 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月4日 21:53
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] watchdog:imx_sc: Add i.MX system controller watchdog supportQuoted 14 lines · Anson Huang
Hi, Guenter
Best Regards!
Anson HuangQuoted 9 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: 2019年3月4日 10:46
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected];Quoted 8 lines
Quoted 8 lines
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] watchdog:imx_sc: Add i.MX system controller watchdog supportQuoted 8 lines
Quoted 8 lines · Anson Huang
Quoted 7 lines
Hi, Guenter
Best Regards!
Anson HuangQuoted 2 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf OfGuenter
Quoted 139 lines
Quoted 139 lines
Quoted 7 lines
Quoted 7 lines
Roeck
Sent: 2019年3月2日 2:32
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; wim@linux- watchdog.org; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected];Quoted 65 lines
Quoted 65 lines
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V5 1/2] 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 V4:
- change the module build dependency as depends onIMX_SCUand
HAVE_ARM_SMCCC, as thisdrivers/watchdog/Makefile obj-$(CONFIG_NUC900_WATCHDOG) +=
Quoted 40 lines
driver is ONLY for i.MX SoC with SCU inside and it uses ARM SMC call.
--- drivers/watchdog/Kconfig | 14 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/imx_sc_wdt.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+)create mode 100644
drivers/watchdog/imx_sc_wdt.cdrivers/watchdog/Kconfig +0
-0index
65c3c42..a6bfa54 100644drivers/watchdog/Kconfig +14
-0@@ -625,6 +625,20 @@ 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 IMX_SCU + depends on HAVE_ARM_SMCCC + 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 8 lines
Quoted 8 lines
Quoted 8 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
Quoted 57 lines
Quoted 10 lines
Quoted 10 lines
file mode 100644 index 0000000..50b49b2
drivers/watchdog/imx_sc_wdt.c new file +6
-0@@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018-2019 NXP. +*/ + +#include <linux/arm-smccc.h> Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c line 12
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+#include <linux/io.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/of.h> Should no longer be needed.
Correct, I will remove it.
Quoted 36 lines
Quoted 16 lines
drivers/watchdog/imx_sc_wdt.c new file +15
-0+#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 36
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 38
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
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static unsigned int timeout =DEFAULT_TIMEOUT ; +module_param(timeout, uint, 0000); MODULE_PARM_DESC(timeout, +"Watchdog timeout inseconds
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c new file +9
-0+(default=" + __MODULE_STRING(DEFAULT_TIMEOUT) ")"); + +static struct platform_device *imx_sc_wdt_pdev; + +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,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c new file +9
-0+ 0, 0, 0, 0, 0, 0, &res); + +return 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,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 5 lines
drivers/watchdog/imx_sc_wdt.c new file +5
-0+ 0, 0, 0, 0, 0, 0, &res); +if (res.a0) +return -EACCES ; + + arm_smccc_smc(IMX_SIP_TIMER,
IMX_SIP_TIMER_SET_WDOG_ACT,Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c new file +9
-0+SC_TIMER_WDOG_ACTION_PARTITION , + 0, 0, 0, 0, 0, &res); +return res.a0 ? -EACCES :0 ; +} + +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,Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 12 lines
drivers/watchdog/imx_sc_wdt.c new file +12
-0+ 0, 0, 0, 0, 0, 0, &res); + +return res.a0 ? -EACCES :0 ; +} + +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 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/watchdog/imx_sc_wdt.c new file +7
-0+ timeout * 1000, 0, 0, 0, 0, 0, &res); + +return res.a0 ? -EACCES :0 ; +} + +static const struct watchdog_ops imx_sc_wdt_ops = { + .owner =THIS_MODULE ,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c new file +8
-0+ .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|Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/watchdog/imx_sc_wdt.c line 104
Quoted 1 line
drivers/watchdog/imx_sc_wdt.c new file +1
-0+ WDIOF_MAGICCLOSE |
WDIOF_PRETIMEOUT, };Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+ +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),Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
GFP_KERNEL);drivers/watchdog/imx_sc_wdt.c
Quoted 13 lines
drivers/watchdog/imx_sc_wdt.c new file +13
-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);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/watchdog/imx_sc_wdt.c line 125
Quoted 2 lines
drivers/watchdog/imx_sc_wdt.c new file +2
-0+if (ret) + dev_warn(&pdev->dev, "Failed to set timeout value,using
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 6 lines
drivers/watchdog/imx_sc_wdt.c new file +6
-0+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);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/watchdog/imx_sc_wdt.c line 133
Quoted 2 lines
drivers/watchdog/imx_sc_wdt.c new file +2
-0+if (ret) { + dev_err(&pdev->dev, "Failed to register watchdogdevice\n");
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/watchdog/imx_sc_wdt.c line 143
Quoted 7 lines
drivers/watchdog/imx_sc_wdt.c new file +7
-0+return ret; + } + +return 0 ; +} + +static int __maybe_unused imx_sc_wdt_suspend (struct device *dev){
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/watchdog/imx_sc_wdt.c line 141
Quoted 1 line
drivers/watchdog/imx_sc_wdt.c new file +1
-0+ struct watchdog_device *imx_sc_wdd =
dev_get_drvdata(dev);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c new file +9
-0+ +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);Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/watchdog/imx_sc_wdt.c new file +18
-0+ +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" , + .pm = &imx_sc_wdt_pm_ops, + }, +}; +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c
Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c new file +8
-0+static int __init imx_sc_wdt_init (void ) { +int ret; + + ret =platform_driver_register (&imx_sc_wdt_driver); +if (ret) +return ret; + + imx_sc_wdt_pdev = platform_device_register_simple("imx-sc-wdt",
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/watchdog/imx_sc_wdt.c line 177
Quoted 1 line
drivers/watchdog/imx_sc_wdt.c new file +1
-0+-1, NULL, 0);
drivers/watchdog/imx_sc_wdt.c line 186
Quoted 4 lines
drivers/watchdog/imx_sc_wdt.c new file +4
-0+if (IS_ERR (imx_sc_wdt_pdev)) { +platform_driver_unregister (&imx_sc_wdt_driver); +return PTR_ERR (imx_sc_wdt_pdev); + }I just realized what you are doing here. So the watchdog will always be instantiated if/when the module is loaded. I don't think that was the idea, and it seems to be risky. What happens if someone loads the module on a system where the watchdog is not supported ? There maye be lots of "Access Denied" errors, or
something undefined may happen.
Quoted 35 lines
Quoted 35 lines
Quoted 5 lines
I thought the "depends on
IMX_SCU" was already added inKconfig, that means the module will be ONLY built withIMX_SCUenabled, and watchdog will be always enabled ifIMX_SCUis enabled. Is it safe enough?No. The driver will be built with arm64:defconfig, meaning it will be built for all arm64 systems using defconfig. Any such system will have the driver installed as module, and nothing will prevent the user from running modprobe. But even if it wasn't enabled with defconfig, we must not instantiate the driver on an arbitrary system.
Quoted 16 lines
Quoted 9 lines
Is everyone on Cc: ok with this ? Is this how we handle instantiations nowadays ? Or should the driver be instantiated from
imx_scu_probe()indrivers/firmware/imx/imx-scu.c?Sorry if the answer is obvious, but I am still struggling with "no more instantiations through devicetree".
Quoted 6 lines
If the driver is auto-instantiated when the module is loaded, as currently written, there needs to be some check if it is actually supported, possibly in
imx_sc_wdt_init()or, if that is not possible, in the probe function. I don't like that, but it would at least prevent the module from being loaded when the hardware is not supported.Quoted 6 lines
Other modules depend on the
IMX_SCUIPC will have defer probe there to make sureIMX_SCUdriver is ready for IPC handle, since watchdog driver ONLY uses ARM SMC but no IPC call, so I did NOT add the defer probe handle here, so if adding it can answer your question/concern, then I can add it, although I think the dependency inKconfigshould be good here. Without SCU firmware ready, the SoC does NOT boot up Acore with ATF/Linux at all.
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
That has nothing to do with deferred probing. My concern is that the driver will be instantiated just by loading it, no matter if the hardware supporting it is present or not.
Having a devicetree node would have prevented that since it instantiates the child drivers with
devm_of_platform_populate()inimx_scu_probe(). The equivalent is to register the platform device from
imx_scu_probe().Quoted 10 lines
Quoted 9 lines
That is the only means to prevent the driver from being instantiated where it shouldn't. As mentioned before, I would have preferred the devicetree method, but having it no longer available doesn't mean that we should add risky code.
Maybe you can check in the init function if the 'fsl,imx-scu' node exists, and instantiate the driver if it does. I don't like that either, but it would be acceptable to me - and maybe better than instantiating it manually from
imx_scu_probe().Quoted 4 lines
OK, I can add check of "fsl,imx-scu" in init function and ONLY instantiate the driver if it exist, since there is no watchdog node in devicetree and "fsl,imx-scu" should be treated as watchdog node, so adding such check also makes some sense, putting it inside SCU driver is
NOT that good I think, do you agree?
Quoted 1 line
Quoted 8 lines
I dislike both. Putting it into the SCU driver probe function would be more appropriate. Putting it into the watchdog driver is worse since it should really only be instantiated if (and after) the parent driver is instantiated, and the parent driver should be listed as its parent. That will get lost if you put the check into the watchdog driver.
I would suggest to submit the patch for the SCU driver first. If that gets rejected by its maintainer, we'll have to do it in the watchdog driver.
Thanks Guenter, I resend the V6 patch to move the watchdog platform device register to SCU driver probe, to be child of SCU device, let's wait for SCU maintainer's feedback.
Anson.
Quoted 2 lines
Guenter
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel