Skip to contentSkip to conversation

dt-bindings: watchdog: move i.MX system controller watchdog binding to SCU

PATCH RESEND Superseded Anson Huang 4 participants 14 messages May 12, 2019 – Jun 8, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND v4 1/3 dt-bindings: watchdog: move i.MX system controller watchdog binding to SCU

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

---
No change, just resend patch with correct encoding.

---
 .../devicetree/bindings/arm/freescale/fsl,scu.txt  | 15 ++++++++++++++
 .../bindings/watchdog/fsl-imx-sc-wdt.txt           | 24 ----------------------
 2 files changed, 15 insertions(+), 24 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt +15 -0
index 5d7dbab..1b56557 100644
@@ -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>;
+		};
 	};
 };
 
Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt deleted +0 -24
deleted file mode 100644
index 02b87e9..0000000
@@ -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>;
-};
Signature · 1 line
2.7.4
#1 lore raw

PATCH RESEND v4 2/3 arm64: dts: imx8qxp: Move watchdog node into scu node

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

---
No change, just resend patch with correct encoding.

---
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +5 -5
index 0683ee2..b17c22e 100644
@@ -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>;
-	};
 };
Signature · 1 line
2.7.4
#2 lore raw

RE: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

Hi, Shawn
The driver and binding doc are already reviewed and waiting for DT patch, will you help review this DT patch?

Thanks,
Anson

Quoted 53 lines

-----Original Message-----
From: Anson Huang
Sent: Sunday, May 12, 2019 6:11 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

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

---
No change, just resend patch with correct encoding.

---
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +5 -6
index 0683ee2..b17c22e 100644
@@ -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

#3 lore raw

Re: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

Quoted 2 lines · Anson Huang

Hi, Shawn
The driver and binding doc are already reviewed and waiting for DT patch, will you help review this DT patch?

I'm fine with it. Should I just pick this patch up, or is there any dependency we need to handle?

Shawn

Quoted 58 lines

Thanks,
Anson

Quoted 53 lines

-----Original Message-----
From: Anson Huang
Sent: Sunday, May 12, 2019 6:11 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

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

---
No change, just resend patch with correct encoding.

---
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +5 -6
index 0683ee2..b17c22e 100644
@@ -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

#4 lore raw

RE: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

Hi, Shawn

Quoted 14 lines

-----Original Message-----
From: Shawn Guo <[email protected]>
Sent: Wednesday, June 5, 2019 2:00 PM
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

Quoted 7 lines
Quoted 2 lines · Anson Huang

Hi, Shawn
The driver and binding doc are already reviewed and waiting for DT

patch, will you help review this DT patch?

I'm fine with it. Should I just pick this patch up, or is there any dependency we need to handle?

No dependency, it just makes more sense to move the node into SCU node as it is NOW depending on SCU driver. Once you pick up this patch (and maybe the dt-binding patch as well?), I will notify the watchdog maintainer to pick up the watchdog patch in this series.

Thanks,
Anson

Quoted 61 lines

Shawn

Quoted 58 lines

Thanks,
Anson

Quoted 53 lines

-----Original Message-----
From: Anson Huang
Sent: Sunday, May 12, 2019 6:11 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

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

---
No change, just resend patch with correct encoding.

---
 arch/arm64/boot/dts/freescale/imx8qxp.dtsi | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/freescale/imx8qxp.dtsi +5 -6
index 0683ee2..b17c22e 100644
@@ -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

#5 lore raw

Re: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

Quoted 19 lines · Anson Huang

Hi, Shawn

Quoted 17 lines

-----Original Message-----
From: Shawn Guo <[email protected]>
Sent: Wednesday, June 5, 2019 2:00 PM
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 2/3] arm64: dts: imx8qxp: Move watchdog node into scu node

Quoted 2 lines · Anson Huang

Hi, Shawn
The driver and binding doc are already reviewed and waiting for DT

Quoted 7 lines
Quoted 4 lines

patch, will you help review this DT patch?

I'm fine with it. Should I just pick this patch up, or is there any dependency we need to handle?

No dependency, it just makes more sense to move the node into SCU node as it is NOW depending on SCU driver. Once you pick up this patch

Just applied.

Quoted 1 line

(and maybe the dt-binding patch as well?),

It makes more sense to have it go through watchdog tree.

Shawn

Quoted 2 lines

I will notify the watchdog
maintainer to pick up the watchdog patch in this series.

#6 lore raw

PATCH RESEND v4 3/3 watchdog: imx_sc: Add pretimeout support

In reply to Anson Huang

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.

---
No change, just resend patch with correct encoding.

---
 drivers/watchdog/Kconfig      |   1 +
 drivers/watchdog/imx_sc_wdt.c | 116 +++++++++++++++++++++++++++++++++++-------
 2 files changed, 98 insertions(+), 19 deletions(-)
drivers/watchdog/Kconfig +1 -0
index 7ea6037..e08238c 100644
@@ -716,6 +716,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
drivers/watchdog/imx_sc_wdt.c +97 -19

180 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#7 lore raw

Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 8 lines · Anson Huang

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.

Other patches waiting for DT review. IMX API feedback below.

Side note: This patch depends on 'firmware: imx: enable imx scu general irq function' which is not yet in mainline.

Quoted 71 lines

---
No change, just resend patch with correct encoding.

---
  drivers/watchdog/Kconfig      |   1 +
  drivers/watchdog/imx_sc_wdt.c | 116 +++++++++++++++++++++++++++++++++++-------
  2 files changed, 98 insertions(+), 19 deletions(-)
drivers/watchdog/Kconfig +1 -0
index 7ea6037..e08238c 100644
@@ -716,6 +716,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
drivers/watchdog/imx_sc_wdt.c +25 -0
index 49848b6..6ecc03f 100644
@@ -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,

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 122

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +10 -0
+			     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);

This should really not be necessary. Event mask and target group (if needed with a wildcard for the group) should be parameters of imx_scu_irq_register_notifier(), and be handled in the imx code.

Also, passing 'group' as pointed seems excessive. Might as well pass it directly.

Guenter

Quoted 127 lines
drivers/watchdog/imx_sc_wdt.c +62 -19
+
+	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,69 @@ 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;
  	}
 
+	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;
+	}
+
+	ret = devm_add_action_or_reset(dev, imx_sc_wdt_action,
+				       &imx_sc_wdd->wdt_notifier);
+	if (!ret)
+		imx_sc_wdt_info.options |= WDIOF_PRETIMEOUT;
+	else
+		dev_warn(dev, "Add action failed, pretimeout NOT supported\n");
+
  	return 0;
  }
 
  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;
  }
#8 lore raw

RE: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 25 lines

-----Original Message-----
From: Guenter Roeck [mailto:[email protected]] On Behalf Of Guenter Roeck
Sent: Sunday, May 12, 2019 9:28 PM
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 7 lines · Anson Huang

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.

Quoted 8 lines
Quoted 1 line

Other patches waiting for DT review. IMX API feedback below.

Side note: This patch depends on 'firmware: imx: enable imx scu general irq function' which is not yet in mainline.

Thanks Guenter.

The ''firmware: imx: enable imx scu general irq function' patch is already in shawn's imx/drivers branch, should be in mainline after next merge window.

Anson.

Quoted 226 lines
Quoted 6 lines

---
No change, just resend patch with correct encoding.

---
  drivers/watchdog/Kconfig      |   1 +
  drivers/watchdog/imx_sc_wdt.c | 116

+++++++++++++++++++++++++++++++++++-------

Quoted 27 lines
  2 files changed, 98 insertions(+), 19 deletions(-)
drivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0 -0

7ea6037..e08238c 100644

drivers/watchdog/Kconfig +1 -0
@@ -716,6 +716,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..6ecc03f 100644

drivers/watchdog/imx_sc_wdt.c +1 -0
@@ -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>

drivers/watchdog/imx_sc_wdt.c line 42

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +3 -0
@@ -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="

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  		 __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,

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +6 -0
  	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,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		      pretimeout * 1000, 0, 0, 0, 0, 0, &res);
+	if (res.a0)
+		return -EACCES;
+
+	wdog->pretimeout = pretimeout;
+
+	return 0;
+}
+

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 122

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +10 -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);

This should really not be necessary. Event mask and target group (if needed with a wildcard for the group) should be parameters of imx_scu_irq_register_notifier(), and be handled in the imx code.

Also, passing 'group' as pointed seems excessive. Might as well pass it directly.

Guenter

Quoted 29 lines
drivers/watchdog/imx_sc_wdt.c +16 -2
+
+	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,
  };

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 159

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +2 -1
 
  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);

@@

Quoted 28 lines

-111,42 +162,69 @@ static int imx_sc_wdt_probe(struct platform_device *pdev)

  	platform_set_drvdata(pdev, imx_sc_wdd);
drivers/watchdog/imx_sc_wdt.c +11 -10
-	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);

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  	if (ret) {
  		dev_err(dev, "Failed to register watchdog device\n");
  		return ret;
  	}
 
+	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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +11 -0
+		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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		return 0;
+	}
+
+	ret = devm_add_action_or_reset(dev, imx_sc_wdt_action,
+				       &imx_sc_wdd->wdt_notifier);
+	if (!ret)
+		imx_sc_wdt_info.options |= WDIOF_PRETIMEOUT;
+	else
+		dev_warn(dev, "Add action failed, pretimeout NOT

supported\n");

Quoted 30 lines
drivers/watchdog/imx_sc_wdt.c +7 -6
+
  	return 0;
  }
 
  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;
  }
#9 lore raw

RE: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

In reply to Guenter Roeck

Hi, Guenter

Quoted 22 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Sunday, May 12, 2019 9:28 PM
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 7 lines · Anson Huang

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.

Quoted 5 lines
Quoted 1 line

Other patches waiting for DT review. IMX API feedback below.

Shaw just picked up the DT patch. Would you please pick up this driver and dt-binding patch to you git repo?

Thanks,
Anson

Quoted 229 lines

Side note: This patch depends on 'firmware: imx: enable imx scu general irq function' which is not yet in mainline.

Quoted 5 lines

---
No change, just resend patch with correct encoding.

---
  drivers/watchdog/Kconfig      |   1 +
  drivers/watchdog/imx_sc_wdt.c | 116

+++++++++++++++++++++++++++++++++++-------

Quoted 27 lines
  2 files changed, 98 insertions(+), 19 deletions(-)
drivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0 -0

7ea6037..e08238c 100644

drivers/watchdog/Kconfig +1 -0
@@ -716,6 +716,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..6ecc03f 100644

drivers/watchdog/imx_sc_wdt.c +1 -0
@@ -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>

drivers/watchdog/imx_sc_wdt.c line 42

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +3 -0
@@ -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="

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  		 __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,

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +6 -0
  	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,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		      pretimeout * 1000, 0, 0, 0, 0, 0, &res);
+	if (res.a0)
+		return -EACCES;
+
+	wdog->pretimeout = pretimeout;
+
+	return 0;
+}
+

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 122

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +10 -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);

This should really not be necessary. Event mask and target group (if needed with a wildcard for the group) should be parameters of imx_scu_irq_register_notifier(), and be handled in the imx code.

Also, passing 'group' as pointed seems excessive. Might as well pass it directly.

Guenter

Quoted 29 lines
drivers/watchdog/imx_sc_wdt.c +16 -2
+
+	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,
  };

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 159

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +2 -1
 
  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);

@@

Quoted 28 lines

-111,42 +162,69 @@ static int imx_sc_wdt_probe(struct platform_device *pdev)

  	platform_set_drvdata(pdev, imx_sc_wdd);
drivers/watchdog/imx_sc_wdt.c +11 -10
-	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);

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  	if (ret) {
  		dev_err(dev, "Failed to register watchdog device\n");
  		return ret;
  	}
 
+	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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +11 -0
+		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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		return 0;
+	}
+
+	ret = devm_add_action_or_reset(dev, imx_sc_wdt_action,
+				       &imx_sc_wdd->wdt_notifier);
+	if (!ret)
+		imx_sc_wdt_info.options |= WDIOF_PRETIMEOUT;
+	else
+		dev_warn(dev, "Add action failed, pretimeout NOT

supported\n");

Quoted 30 lines
drivers/watchdog/imx_sc_wdt.c +7 -6
+
  	return 0;
  }
 
  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;
  }
maintainer
#10 lore raw

Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 24 lines · Anson Huang

Hi, Guenter

Quoted 22 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Sunday, May 12, 2019 9:28 PM
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 7 lines · Anson Huang

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.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Other patches waiting for DT review. IMX API feedback below.

Shaw just picked up the DT patch. Would you please pick up this driver and dt-binding patch to you git repo?

I'll pick up patch 3/3, but I can not pick up patches into arch/arm64/boot/; that is the responsibility of arm64 maintainers. I can only do that if I get an explicit Ack and permission to do so from an arm64 maintainer, and I don't recall getting that.

Guenter

Quoted 233 lines

Thanks,
Anson

Quoted 229 lines

Side note: This patch depends on 'firmware: imx: enable imx scu general irq function' which is not yet in mainline.

Quoted 5 lines

---
No change, just resend patch with correct encoding.

---
  drivers/watchdog/Kconfig      |   1 +
  drivers/watchdog/imx_sc_wdt.c | 116

+++++++++++++++++++++++++++++++++++-------

Quoted 27 lines
  2 files changed, 98 insertions(+), 19 deletions(-)
drivers/watchdog/Kconfig index renamed from drivers/watchdog/Kconfig +0 -0

7ea6037..e08238c 100644

drivers/watchdog/Kconfig +1 -0
@@ -716,6 +716,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..6ecc03f 100644

drivers/watchdog/imx_sc_wdt.c +1 -0
@@ -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>

drivers/watchdog/imx_sc_wdt.c line 42

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +3 -0
@@ -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="

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  		 __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,

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +6 -0
  	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,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		      pretimeout * 1000, 0, 0, 0, 0, 0, &res);
+	if (res.a0)
+		return -EACCES;
+
+	wdog->pretimeout = pretimeout;
+
+	return 0;
+}
+

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 122

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +10 -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);

This should really not be necessary. Event mask and target group (if needed with a wildcard for the group) should be parameters of imx_scu_irq_register_notifier(), and be handled in the imx code.

Also, passing 'group' as pointed seems excessive. Might as well pass it directly.

Guenter

Quoted 29 lines
drivers/watchdog/imx_sc_wdt.c +16 -2
+
+	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,
  };

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 159

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +2 -1
 
  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);

@@

Quoted 28 lines

-111,42 +162,69 @@ static int imx_sc_wdt_probe(struct platform_device *pdev)

  	platform_set_drvdata(pdev, imx_sc_wdd);
drivers/watchdog/imx_sc_wdt.c +11 -10
-	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);

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  	if (ret) {
  		dev_err(dev, "Failed to register watchdog device\n");
  		return ret;
  	}
 
+	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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +11 -0
+		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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		return 0;
+	}
+
+	ret = devm_add_action_or_reset(dev, imx_sc_wdt_action,
+				       &imx_sc_wdd->wdt_notifier);
+	if (!ret)
+		imx_sc_wdt_info.options |= WDIOF_PRETIMEOUT;
+	else
+		dev_warn(dev, "Add action failed, pretimeout NOT

supported\n");

Quoted 30 lines
drivers/watchdog/imx_sc_wdt.c +7 -6
+
  	return 0;
  }
 
  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;
  }
#11 lore raw

RE: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Hi, Guenter

Quoted 46 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Saturday, June 8, 2019 1:41 AM
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 7 lines · Anson Huang

Hi, Guenter

Quoted 5 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Sunday, May 12, 2019 9:28 PM
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 23 lines
Quoted 22 lines

[email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 8 lines · Anson Huang

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.

Other patches waiting for DT review. IMX API feedback below.

Quoted 7 lines
Quoted 3 lines

Shaw just picked up the DT patch. Would you please pick up this driver and dt-binding patch to you git repo?

I'll pick up patch 3/3, but I can not pick up patches into arch/arm64/boot/; that is the responsibility of arm64 maintainers. I can only do that if I get an explicit Ack and permission to do so from an arm64 maintainer, and I don't recall getting that.

Will you also pick up 1/3, the DT binding patch, as DT binding normally go with driver, if NOT, please advise who should pick up this patch.

Thanks,
Anson.

Quoted 236 lines

Guenter

Quoted 233 lines

Thanks,
Anson

Quoted 229 lines

Side note: This patch depends on 'firmware: imx: enable imx scu general irq function' which is not yet in mainline.

Quoted 5 lines

---
No change, just resend patch with correct encoding.

---
  drivers/watchdog/Kconfig      |   1 +
  drivers/watchdog/imx_sc_wdt.c | 116

+++++++++++++++++++++++++++++++++++-------

Quoted 27 lines
  2 files changed, 98 insertions(+), 19 deletions(-)
drivers/watchdog/Kconfig +1 -1
index 7ea6037..e08238c 100644
@@ -716,6 +716,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..6ecc03f 100644

drivers/watchdog/imx_sc_wdt.c +1 -0
@@ -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>

drivers/watchdog/imx_sc_wdt.c line 42

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +3 -0
@@ -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="

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +4 -0
  		 __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,

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog,

Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  	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,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		      pretimeout * 1000, 0, 0, 0, 0, 0, &res);
+	if (res.a0)
+		return -EACCES;
+
+	wdog->pretimeout = pretimeout;
+
+	return 0;
+}
+

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 122

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +10 -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);

This should really not be necessary. Event mask and target group (if needed with a wildcard for the group) should be parameters of imx_scu_irq_register_notifier(), and be handled in the imx code.

Also, passing 'group' as pointed seems excessive. Might as well pass it directly.

Guenter

Quoted 39 lines
drivers/watchdog/imx_sc_wdt.c +18 -3
+
+	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),
Quoted 1 line

GFP_KERNEL);

@@

Quoted 29 lines

-111,42 +162,69 @@ static int imx_sc_wdt_probe(struct platform_device
*pdev)

  	platform_set_drvdata(pdev, imx_sc_wdd);
drivers/watchdog/imx_sc_wdt.c +11 -10
-	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);

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
  	if (ret) {
  		dev_err(dev, "Failed to register watchdog device\n");
  		return ret;
  	}
 
+	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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +11 -0
+		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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		return 0;
+	}
+
+	ret = devm_add_action_or_reset(dev, imx_sc_wdt_action,
+				       &imx_sc_wdd->wdt_notifier);
+	if (!ret)
+		imx_sc_wdt_info.options |= WDIOF_PRETIMEOUT;
+	else
+		dev_warn(dev, "Add action failed, pretimeout NOT

supported\n");

Quoted 30 lines
drivers/watchdog/imx_sc_wdt.c +7 -6
+
  	return 0;
  }
 
  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;
  }
maintainer
#12 lore raw

Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 51 lines · Anson Huang

Hi, Guenter

Quoted 49 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Saturday, June 8, 2019 1:41 AM
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 7 lines · Anson Huang

Hi, Guenter

Quoted 5 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Sunday, May 12, 2019 9:28 PM
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 26 lines
Quoted 17 lines

[email protected]; [email protected]; [email protected]; Aisheng Dong <[email protected]>; [email protected]; Daniel Baluta <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: Re: [PATCH RESEND V4 3/3] watchdog: imx_sc: Add pretimeout support

Quoted 7 lines · Anson Huang

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.

Quoted 5 lines
Quoted 1 line

Other patches waiting for DT review. IMX API feedback below.

Shaw just picked up the DT patch. Would you please pick up this driver and dt-binding patch to you git repo?

Quoted 8 lines
Quoted 4 lines

I'll pick up patch 3/3, but I can not pick up patches into arch/arm64/boot/; that is the responsibility of arm64 maintainers. I can only do that if I get an explicit Ack and permission to do so from an arm64 maintainer, and I don't recall getting that.

Will you also pick up 1/3, the DT binding patch, as DT binding normally go with driver, if NOT, please advise who should pick up this patch.

Makes sense. Will do.

Guenter

Quoted 239 lines

Thanks,
Anson.

Quoted 236 lines

Guenter

Quoted 233 lines

Thanks,
Anson

Quoted 229 lines

Side note: This patch depends on 'firmware: imx: enable imx scu general irq function' which is not yet in mainline.

Quoted 5 lines

---
No change, just resend patch with correct encoding.

---
   drivers/watchdog/Kconfig      |   1 +
   drivers/watchdog/imx_sc_wdt.c | 116

+++++++++++++++++++++++++++++++++++-------

Quoted 27 lines
   2 files changed, 98 insertions(+), 19 deletions(-)
drivers/watchdog/Kconfig +1 -1
index 7ea6037..e08238c 100644
@@ -716,6 +716,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..6ecc03f 100644

drivers/watchdog/imx_sc_wdt.c +1 -0
@@ -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>

drivers/watchdog/imx_sc_wdt.c line 42

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +3 -0
@@ -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="

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +4 -0
   		 __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,

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog,

Quoted 8 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
   	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,

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		      pretimeout * 1000, 0, 0, 0, 0, 0, &res);
+	if (res.a0)
+		return -EACCES;
+
+	wdog->pretimeout = pretimeout;
+
+	return 0;
+}
+

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_set_timeout(struct watchdog_device *wdog, · line 122

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +10 -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);

This should really not be necessary. Event mask and target group (if needed with a wildcard for the group) should be parameters of imx_scu_irq_register_notifier(), and be handled in the imx code.

Also, passing 'group' as pointed seems excessive. Might as well pass it directly.

Guenter

Quoted 39 lines
drivers/watchdog/imx_sc_wdt.c +18 -3
+
+	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),
Quoted 1 line

GFP_KERNEL);

@@

Quoted 29 lines

-111,42 +162,69 @@ static int imx_sc_wdt_probe(struct platform_device
*pdev)

   	platform_set_drvdata(pdev, imx_sc_wdd);
drivers/watchdog/imx_sc_wdt.c +11 -10
-	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);

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/watchdog/imx_sc_wdt.c +5 -0
   	if (ret) {
   		dev_err(dev, "Failed to register watchdog device\n");
   		return ret;
   	}
 
+	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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 11 lines
drivers/watchdog/imx_sc_wdt.c +11 -0
+		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");

drivers/watchdog/imx_sc_wdt.c static int imx_sc_wdt_probe(struct platform_device *pdev)

Quoted 9 lines
drivers/watchdog/imx_sc_wdt.c +9 -0
+		return 0;
+	}
+
+	ret = devm_add_action_or_reset(dev, imx_sc_wdt_action,
+				       &imx_sc_wdd->wdt_notifier);
+	if (!ret)
+		imx_sc_wdt_info.options |= WDIOF_PRETIMEOUT;
+	else
+		dev_warn(dev, "Add action failed, pretimeout NOT

supported\n");

Quoted 30 lines
drivers/watchdog/imx_sc_wdt.c +7 -6
+
   	return 0;
   }
 
   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;
   }
maintainer Reviewed-by on v4 1/3
#13 lore raw
In reply to Anson Huang
Quoted 7 lines · Anson Huang

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

---
No change, just resend patch with correct encoding.

Quoted-printable isn't really correct either. It should be 7-bit or 8-bit if UTF-8.

Quoted 5 lines
---
 .../devicetree/bindings/arm/freescale/fsl,scu.txt  | 15 ++++++++++++++
 .../bindings/watchdog/fsl-imx-sc-wdt.txt           | 24 ----------------------
 2 files changed, 15 insertions(+), 24 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/watchdog/fsl-imx-sc-wdt.txt