Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding
@ 2019-04-28  3:27 Anson Huang
  2019-04-28  3:27 ` [PATCH V2 2/4] arm64: dts: imx8qxp: Move watchdog node into scu node Anson Huang
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Anson Huang @ 2019-04-28  3:27 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wim, linux, shawnguo, s.hauer, kernel,
	festevam, Aisheng Dong, ulf.hansson, Peng Fan, Daniel Baluta,
	devicetree, linux-kernel, linux-watchdog, linux-arm-kernel
  Cc: dl-linux-imx

i.MX system controller watchdog has pretimeout function which
depends on i.MX SCU driver, so watchdog DT node needs to be
subnode of SCU, this patch adds i.MX system controller watchdog
binding to SCU binding doc.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
New patch.
---
 .../devicetree/bindings/arm/freescale/fsl,scu.txt         | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
index 5d7dbab..1b56557 100644
--- a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
+++ b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
@@ -133,6 +133,16 @@ RTC bindings based on SCU Message Protocol
 Required properties:
 - compatible: should be "fsl,imx8qxp-sc-rtc";
 
+Watchdog bindings based on SCU Message Protocol
+------------------------------------------------------------
+
+Required properties:
+- compatible: should be:
+              "fsl,imx8qxp-sc-wdt"
+              followed by "fsl,imx-sc-wdt";
+Optional properties:
+- timeout-sec: contains the watchdog timeout in seconds.
+
 Example (imx8qxp):
 -------------
 aliases {
@@ -185,6 +195,11 @@ firmware {
 		rtc: rtc {
 			compatible = "fsl,imx8qxp-sc-rtc";
 		};
+
+		watchdog {
+			compatible = "fsl,imx8qxp-sc-wdt", "fsl,imx-sc-wdt";
+			timeout-sec = <60>;
+		};
 	};
 };
 
-- 
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 2/4] arm64: dts: imx8qxp: Move watchdog node into scu node
  2019-04-28  3:27 [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Anson Huang
@ 2019-04-28  3:27 ` Anson Huang
  2019-04-28  3:27 ` [PATCH V2 3/4] watchdog: imx_sc: Add pretimeout support Anson Huang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Anson Huang @ 2019-04-28  3:27 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wim, linux, shawnguo, s.hauer, kernel,
	festevam, Aisheng Dong, ulf.hansson, Peng Fan, Daniel Baluta,
	devicetree, linux-kernel, linux-watchdog, linux-arm-kernel
  Cc: dl-linux-imx

i.MX system controller watchdog has pretimeout function which
depends on i.MX SCU driver, so it should be a subnode of SCU.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
New patch.
---
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8qxp.dtsi b/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
index 0683ee2..b17c22e 100644
--- a/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8qxp.dtsi
@@ -149,6 +149,11 @@
 		rtc: rtc {
 			compatible = "fsl,imx8qxp-sc-rtc";
 		};
+
+		watchdog {
+			compatible = "fsl,imx8qxp-sc-wdt", "fsl,imx-sc-wdt";
+			timeout-sec = <60>;
+		};
 	};
 
 	timer {
@@ -517,9 +522,4 @@
 			power-domains = <&pd IMX_SC_R_GPIO_7>;
 		};
 	};
-
-	watchdog {
-		compatible = "fsl,imx8qxp-sc-wdt", "fsl,imx-sc-wdt";
-		timeout-sec = <60>;
-	};
 };
-- 
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 3/4] watchdog: imx_sc: Add pretimeout support
  2019-04-28  3:27 [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Anson Huang
  2019-04-28  3:27 ` [PATCH V2 2/4] arm64: dts: imx8qxp: Move watchdog node into scu node Anson Huang
@ 2019-04-28  3:27 ` Anson Huang
  2019-04-28  3:27 ` [PATCH V2 4/4] dt-bindings: watchdog: remove i.MX system controller watchdog Anson Huang
  2019-05-01 20:10 ` [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Rob Herring
  3 siblings, 0 replies; 6+ messages in thread
From: Anson Huang @ 2019-04-28  3:27 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wim, linux, shawnguo, s.hauer, kernel,
	festevam, Aisheng Dong, ulf.hansson, Peng Fan, Daniel Baluta,
	devicetree, linux-kernel, linux-watchdog, linux-arm-kernel
  Cc: dl-linux-imx

i.MX system controller watchdog can support pretimeout IRQ
via general SCU MU IRQ, it depends on IMX_SCU and driver MUST
be probed after SCU IPC ready, then enable corresponding SCU
IRQ group and register SCU IRQ notifier, when watchdog pretimeout
IRQ fires, SCU MU IRQ will be handled and watchdog pretimeout
notifier will be called to handle the event.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
Changes since V1:
        - improve imx_sc_wdt_set_pretimeout() return value and assignment sequence;
        - improve coding and logic of imx_sc_wdt_notify() function;
        - use devm_add_action() instead of .remove;
        - add local data structure to include notifier block;
        - remove the defer probe check since the watchdog node is now moved into SCU node;
        - ONLY enable pretimeout function after everything about IRQ are successfully.
---
 drivers/watchdog/Kconfig      |   1 +
 drivers/watchdog/imx_sc_wdt.c | 114 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 95 insertions(+), 20 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 44a3158..f2c2c1a 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -644,6 +644,7 @@ config IMX2_WDT
 config IMX_SC_WDT
 	tristate "IMX SC Watchdog"
 	depends on HAVE_ARM_SMCCC
+	depends on IMX_SCU
 	select WATCHDOG_CORE
 	help
 	  This is the driver for the system controller watchdog
diff --git a/drivers/watchdog/imx_sc_wdt.c b/drivers/watchdog/imx_sc_wdt.c
index 49848b6..d8493a3 100644
--- a/drivers/watchdog/imx_sc_wdt.c
+++ b/drivers/watchdog/imx_sc_wdt.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/arm-smccc.h>
+#include <linux/firmware/imx/sci.h>
 #include <linux/io.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -33,11 +34,19 @@
 
 #define SC_TIMER_WDOG_ACTION_PARTITION	0
 
+#define SC_IRQ_WDOG			1
+#define SC_IRQ_GROUP_WDOG		1
+
 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) ")");
 
+struct imx_sc_wdt_device {
+	struct watchdog_device wdd;
+	struct notifier_block wdt_notifier;
+};
+
 static int imx_sc_wdt_ping(struct watchdog_device *wdog)
 {
 	struct arm_smccc_res res;
@@ -85,24 +94,66 @@ static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog,
 	return res.a0 ? -EACCES : 0;
 }
 
+static int imx_sc_wdt_set_pretimeout(struct watchdog_device *wdog,
+				     unsigned int pretimeout)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(IMX_SIP_TIMER, IMX_SIP_TIMER_SET_PRETIME_WDOG,
+		      pretimeout * 1000, 0, 0, 0, 0, 0, &res);
+	if (res.a0)
+		return -EACCES;
+
+	wdog->pretimeout = pretimeout;
+
+	return 0;
+}
+
+static int imx_sc_wdt_notify(struct notifier_block *nb,
+			     unsigned long event, void *group)
+{
+	struct imx_sc_wdt_device *imx_sc_wdd =
+				 container_of(nb,
+					      struct imx_sc_wdt_device,
+					      wdt_notifier);
+
+	if (event & SC_IRQ_WDOG &&
+	    *(u8 *)group == SC_IRQ_GROUP_WDOG)
+		watchdog_notify_pretimeout(&imx_sc_wdd->wdd);
+
+	return 0;
+}
+
+static void imx_sc_wdt_action(void *data)
+{
+	struct notifier_block *wdt_notifier = data;
+
+	imx_scu_irq_unregister_notifier(wdt_notifier);
+	imx_scu_irq_group_enable(SC_IRQ_GROUP_WDOG,
+				 SC_IRQ_WDOG,
+				 false);
+}
+
 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,
+	.set_pretimeout = imx_sc_wdt_set_pretimeout,
 };
 
-static const struct watchdog_info imx_sc_wdt_info = {
+static struct watchdog_info imx_sc_wdt_info = {
 	.identity	= "i.MX SC watchdog timer",
 	.options	= WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
-			  WDIOF_MAGICCLOSE | WDIOF_PRETIMEOUT,
+			  WDIOF_MAGICCLOSE,
 };
 
 static int imx_sc_wdt_probe(struct platform_device *pdev)
 {
+	struct imx_sc_wdt_device *imx_sc_wdd;
+	struct watchdog_device *wdog;
 	struct device *dev = &pdev->dev;
-	struct watchdog_device *imx_sc_wdd;
 	int ret;
 
 	imx_sc_wdd = devm_kzalloc(dev, sizeof(*imx_sc_wdd), GFP_KERNEL);
@@ -111,42 +162,65 @@ static int imx_sc_wdt_probe(struct platform_device *pdev)
 
 	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 = dev;
-	imx_sc_wdd->timeout = DEFAULT_TIMEOUT;
+	wdog = &imx_sc_wdd->wdd;
+	wdog->info = &imx_sc_wdt_info;
+	wdog->ops = &imx_sc_wdt_ops;
+	wdog->min_timeout = 1;
+	wdog->max_timeout = MAX_TIMEOUT;
+	wdog->parent = dev;
+	wdog->timeout = DEFAULT_TIMEOUT;
 
-	watchdog_init_timeout(imx_sc_wdd, 0, dev);
-	watchdog_stop_on_reboot(imx_sc_wdd);
-	watchdog_stop_on_unregister(imx_sc_wdd);
+	watchdog_init_timeout(wdog, 0, dev);
+	watchdog_stop_on_reboot(wdog);
+	watchdog_stop_on_unregister(wdog);
 
-	ret = devm_watchdog_register_device(dev, imx_sc_wdd);
+	ret = devm_watchdog_register_device(dev, wdog);
 	if (ret) {
 		dev_err(dev, "Failed to register watchdog device\n");
 		return ret;
 	}
 
-	return 0;
+	ret = imx_scu_irq_group_enable(SC_IRQ_GROUP_WDOG,
+				       SC_IRQ_WDOG,
+				       true);
+	if (ret) {
+		dev_warn(dev, "Enable irq failed, pretimeout NOT supported\n");
+		return 0;
+	}
+
+	imx_sc_wdd->wdt_notifier.notifier_call = imx_sc_wdt_notify;
+	ret = imx_scu_irq_register_notifier(&imx_sc_wdd->wdt_notifier);
+	if (ret) {
+		imx_scu_irq_group_enable(SC_IRQ_GROUP_WDOG,
+					 SC_IRQ_WDOG,
+					 false);
+		dev_warn(dev,
+			 "Register irq notifier failed, pretimeout NOT supported\n");
+		return 0;
+	}
+
+	imx_sc_wdt_info.options |= WDIOF_PRETIMEOUT;
+	ret = devm_add_action(dev, imx_sc_wdt_action,
+			      &imx_sc_wdd->wdt_notifier);
+	return ret;
 }
 
 static int __maybe_unused imx_sc_wdt_suspend(struct device *dev)
 {
-	struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev);
+	struct imx_sc_wdt_device *imx_sc_wdd = dev_get_drvdata(dev);
 
-	if (watchdog_active(imx_sc_wdd))
-		imx_sc_wdt_stop(imx_sc_wdd);
+	if (watchdog_active(&imx_sc_wdd->wdd))
+		imx_sc_wdt_stop(&imx_sc_wdd->wdd);
 
 	return 0;
 }
 
 static int __maybe_unused imx_sc_wdt_resume(struct device *dev)
 {
-	struct watchdog_device *imx_sc_wdd = dev_get_drvdata(dev);
+	struct imx_sc_wdt_device *imx_sc_wdd = dev_get_drvdata(dev);
 
-	if (watchdog_active(imx_sc_wdd))
-		imx_sc_wdt_start(imx_sc_wdd);
+	if (watchdog_active(&imx_sc_wdd->wdd))
+		imx_sc_wdt_start(&imx_sc_wdd->wdd);
 
 	return 0;
 }
-- 
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V2 4/4] dt-bindings: watchdog: remove i.MX system controller watchdog
  2019-04-28  3:27 [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Anson Huang
  2019-04-28  3:27 ` [PATCH V2 2/4] arm64: dts: imx8qxp: Move watchdog node into scu node Anson Huang
  2019-04-28  3:27 ` [PATCH V2 3/4] watchdog: imx_sc: Add pretimeout support Anson Huang
@ 2019-04-28  3:27 ` Anson Huang
  2019-05-01 20:13   ` Rob Herring
  2019-05-01 20:10 ` [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Rob Herring
  3 siblings, 1 reply; 6+ messages in thread
From: Anson Huang @ 2019-04-28  3:27 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wim, linux, shawnguo, s.hauer, kernel,
	festevam, Aisheng Dong, ulf.hansson, Peng Fan, Daniel Baluta,
	devicetree, linux-kernel, linux-watchdog, linux-arm-kernel
  Cc: dl-linux-imx

i.MX system controller watchdog now depends on SCU driver, so it
needs to be subnode of SCU node in DT, binding doc is moved to
fsl,scu.txt as well.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
New patch.
---
 .../bindings/watchdog/fsl-imx-sc-wdt.txt           | 24 ----------------------
 1 file changed, 24 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt

diff --git a/Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt b/Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt
deleted file mode 100644
index 02b87e9..0000000
--- a/Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-* Freescale i.MX System Controller Watchdog
-
-i.MX system controller watchdog is for i.MX SoCs with system controller inside,
-the watchdog is managed by system controller, users can ONLY communicate with
-system controller from secure mode for watchdog operations, so Linux i.MX system
-controller watchdog driver will call ARM SMC API and trap into ARM-Trusted-Firmware
-for watchdog operations, ARM-Trusted-Firmware is running at secure EL3 mode and
-it will request system controller to execute the watchdog operation passed from
-Linux kernel.
-
-Required properties:
-- compatible:	Should be :
-		"fsl,imx8qxp-sc-wdt"
-		followed by "fsl,imx-sc-wdt";
-
-Optional properties:
-- timeout-sec : Contains the watchdog timeout in seconds.
-
-Examples:
-
-watchdog {
-	compatible = "fsl,imx8qxp-sc-wdt", "fsl,imx-sc-wdt";
-	timeout-sec = <60>;
-};
-- 
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding
  2019-04-28  3:27 [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Anson Huang
                   ` (2 preceding siblings ...)
  2019-04-28  3:27 ` [PATCH V2 4/4] dt-bindings: watchdog: remove i.MX system controller watchdog Anson Huang
@ 2019-05-01 20:10 ` Rob Herring
  3 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2019-05-01 20:10 UTC (permalink / raw)
  To: Anson Huang
  Cc: mark.rutland, wim, linux, shawnguo, s.hauer, kernel, festevam,
	Aisheng Dong, ulf.hansson, Peng Fan, Daniel Baluta, devicetree,
	linux-kernel, linux-watchdog, linux-arm-kernel, dl-linux-imx

On Sun, Apr 28, 2019 at 03:27:00AM +0000, Anson Huang wrote:
> i.MX system controller watchdog has pretimeout function which
> depends on i.MX SCU driver, so watchdog DT node needs to be
> subnode of SCU, this patch adds i.MX system controller watchdog
> binding to SCU binding doc.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> ---
> New patch.
> ---
>  .../devicetree/bindings/arm/freescale/fsl,scu.txt         | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
> index 5d7dbab..1b56557 100644
> --- a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
> +++ b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
> @@ -133,6 +133,16 @@ RTC bindings based on SCU Message Protocol
>  Required properties:
>  - compatible: should be "fsl,imx8qxp-sc-rtc";
>  
> +Watchdog bindings based on SCU Message Protocol
> +------------------------------------------------------------
> +
> +Required properties:
> +- compatible: should be:
> +              "fsl,imx8qxp-sc-wdt"
> +              followed by "fsl,imx-sc-wdt";
> +Optional properties:
> +- timeout-sec: contains the watchdog timeout in seconds.

This should be the time to reset the system, but the subject talks about 
the pre-timeout which I guess is just an interrupt. If it is pre-timeout 
you want add a new property and don't abuse the existing one.

Rob

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V2 4/4] dt-bindings: watchdog: remove i.MX system controller watchdog
  2019-04-28  3:27 ` [PATCH V2 4/4] dt-bindings: watchdog: remove i.MX system controller watchdog Anson Huang
@ 2019-05-01 20:13   ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2019-05-01 20:13 UTC (permalink / raw)
  To: Anson Huang
  Cc: mark.rutland, wim, linux, shawnguo, s.hauer, kernel, festevam,
	Aisheng Dong, ulf.hansson, Peng Fan, Daniel Baluta, devicetree,
	linux-kernel, linux-watchdog, linux-arm-kernel, dl-linux-imx

On Sun, Apr 28, 2019 at 03:27:17AM +0000, Anson Huang wrote:
> i.MX system controller watchdog now depends on SCU driver, so it
> needs to be subnode of SCU node in DT, binding doc is moved to
> fsl,scu.txt as well.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> ---
> New patch.
> ---
>  .../bindings/watchdog/fsl-imx-sc-wdt.txt           | 24 ----------------------
>  1 file changed, 24 deletions(-)
>  delete mode 100644 Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt

This should probably just be part of patch 1 to be clear you are moving 
things.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-28  3:27 [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Anson Huang
2019-04-28  3:27 ` [PATCH V2 2/4] arm64: dts: imx8qxp: Move watchdog node into scu node Anson Huang
2019-04-28  3:27 ` [PATCH V2 3/4] watchdog: imx_sc: Add pretimeout support Anson Huang
2019-04-28  3:27 ` [PATCH V2 4/4] dt-bindings: watchdog: remove i.MX system controller watchdog Anson Huang
2019-05-01 20:13   ` Rob Herring
2019-05-01 20:10 ` [PATCH V2 1/4] dt-bindings: fsl: scu: add watchdog binding Rob Herring

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org linux-watchdog@archiver.kernel.org
	public-inbox-index linux-watchdog


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/ public-inbox