Skip to contentSkip to conversation

Add reaction control in rti

PATCH In review Judith Mendez 2 participants 5 messages Feb 6 – Feb 9

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

v5 cover Add reaction control in rti

This adds reaction control to the RTI watchdog driver. Since AM62L SoC [0] does not have WWD reset output routed to an ESM module like all other K3 SoCs and has the reset output signal routed to the reset HW block, add a new compatible for AM62L [1] and configure reset reaction for AM62L SoC instead of NMI.

Changes since v4 RESEND:
- Fix commit message grammar and capitalization issues
- Store only needed bool nmi field instead of pointer to match data structure
- Add NULL check for device_get_match_data() with proper error handling
- Rename data structures with SoC-specific rti_wdt prefix and add const
- Update struct documentation and clarify WDT expiration comment

v4 (RESEND): https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1 (RESEND): https://lore.kernel.org/all/[email protected]/

[0] https://www.ti.com/product/AM62L
[1] https://www.ti.com/tool/TMDS62LEVM

Judith Mendez (2):
dt-bindings: watchdog: ti,rti-wdt: Add ti,am62l-rti-wdt compatible
watchdog: rti_wdt: Add reaction control

 .../bindings/watchdog/ti,rti-wdt.yaml         |  1 +
 drivers/watchdog/rti_wdt.c                    | 39 +++++++++++++++++--
 2 files changed, 36 insertions(+), 4 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH v5 1/2 dt-bindings: watchdog: ti,rti-wdt: Add ti,am62l-rti-wdt compatible

Add a new compatible ti,am62l-rti-wdt for AM62L SoC [0].

[0] https://www.ti.com/product/AM62L

---
Changes since v4 RESEND:
- Fix commit message capitalization issues

---
 Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml +1 -0
index 62ddc284a524c..2966e5bfb6c09 100644
@@ -23,6 +23,7 @@ allOf:
 properties:
   compatible:
     enum:
+      - ti,am62l-rti-wdt
       - ti,j7-rti-wdt
 
   reg:
Signature · 1 line
2.52.0
maintainer Reviewed-by on v5 1/2
#2 lore raw

Re: [PATCH v5 1/2] dt-bindings: watchdog: ti,rti-wdt: Add ti,am62l-rti-wdt compatible

Quoted 5 lines · Judith Mendez

Add a new compatible ti,am62l-rti-wdt for AM62L SoC [0].

[0] https://www.ti.com/product/AM62L

Quoted 19 lines

---
Changes since v4 RESEND:
- Fix commit message capitalization issues

---
  Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml | 1 +
  1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml +1 -0
index 62ddc284a524c..2966e5bfb6c09 100644
@@ -23,6 +23,7 @@ allOf:
  properties:
    compatible:
      enum:
+      - ti,am62l-rti-wdt
        - ti,j7-rti-wdt
 
    reg:
#3 lore raw

PATCH v5 2/2 watchdog: rti_wdt: Add reaction control

In reply to Judith Mendez

This configures the reaction between NMI and reset for WWD.

On K3 SoCs other than AM62L SoC [0], watchdog reset output is routed to the ESM module which can subsequently route the signal to safety master or SoC reset. On AM62L, the watchdog reset output is routed to the SoC HW reset block. So, add a new compatible for AM62L to add SoC data and configure reaction to reset instead of NMI.

[0] https://www.ti.com/product/AM62L

---
Changes since v4 RESEND:
- Fix commit message grammar and capitalization issues
- Store only needed bool nmi field instead of pointer to match data structure
- Add NULL check for device_get_match_data() with proper error handling
- Rename data structures with SoC-specific rti_wdt prefix and add const
- Update struct documentation and clarify WDT expiration comment

---
 drivers/watchdog/rti_wdt.c | 39 ++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)
drivers/watchdog/rti_wdt.c +35 -4
index be7d7db475911..c3c7715140ea8 100644
@@ -35,7 +35,8 @@
 #define RTIWWDRXCTRL	0xa4
 #define RTIWWDSIZECTRL	0xa8
 
-#define RTIWWDRX_NMI	0xa
+#define RTIWWDRXN_RST	0x5
+#define RTIWWDRXN_NMI	0xa
 
 #define RTIWWDSIZE_50P		0x50
 #define RTIWWDSIZE_25P		0x500
@@ -63,22 +64,29 @@
 
 static int heartbeat;
 
+struct rti_wdt_data {
+	bool nmi;
+};
+
 /*
  * struct to hold data for each WDT device
  * @base - base io address of WD device
  * @freq - source clock frequency of WDT
  * @wdd  - hold watchdog device as is in WDT core
+ * @nmi - Set if this WDT instance supports generating NMI
  */
 struct rti_wdt_device {
 	void __iomem		*base;
 	unsigned long		freq;
 	struct watchdog_device	wdd;
+	bool			nmi;
 };
 
 static int rti_wdt_start(struct watchdog_device *wdd)
 {
 	u32 timer_margin;
 	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
+	u8 reaction;
 	int ret;
 
 	ret = pm_runtime_resume_and_get(wdd->parent);
@@ -101,8 +109,13 @@ static int rti_wdt_start(struct watchdog_device *wdd)
 	 */
 	wdd->min_hw_heartbeat_ms = 520 * wdd->timeout + MAX_HW_ERROR;
 
-	/* Generate NMI when wdt expires */
-	writel_relaxed(RTIWWDRX_NMI, wdt->base + RTIWWDRXCTRL);
+	/* When WDT expires, generate NMI or reset if NMI not supported */
+	if (wdt->nmi)
+		reaction = RTIWWDRXN_NMI;
+	else
+		reaction = RTIWWDRXN_RST;
+
+	writel_relaxed(reaction, wdt->base + RTIWWDRXCTRL);
 
 	/* Open window size 50%; this is the largest window size available */
 	writel_relaxed(RTIWWDSIZE_50P, wdt->base + RTIWWDSIZECTRL);
@@ -210,6 +223,7 @@ static int rti_wdt_probe(struct platform_device *pdev)
 {
 	int ret = 0;
 	struct device *dev = &pdev->dev;
+	const struct rti_wdt_data *data;
 	struct watchdog_device *wdd;
 	struct rti_wdt_device *wdt;
 	struct clk *clk;
@@ -254,6 +268,14 @@ static int rti_wdt_probe(struct platform_device *pdev)
 	wdd->timeout = DEFAULT_HEARTBEAT;
 	wdd->parent = dev;
 
+	data = device_get_match_data(dev);
+	if (!data) {
+		ret = -ENODEV;
+		goto err_iomap;
+	}
+
+	wdt->nmi = data->nmi;
+
 	watchdog_set_drvdata(wdd, wdt);
 	watchdog_set_nowayout(wdd, 1);
 	watchdog_set_restart_priority(wdd, 128);
@@ -361,8 +383,17 @@ static void rti_wdt_remove(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 }
 
+static const struct rti_wdt_data rti_wdt_j7_data = {
+	.nmi = true,
+};
+
+static const struct rti_wdt_data rti_wdt_am62l_data = {
+	.nmi = false,
+};
+
 static const struct of_device_id rti_wdt_of_match[] = {
-	{ .compatible = "ti,j7-rti-wdt", },
+	{ .compatible = "ti,j7-rti-wdt", .data = &rti_wdt_j7_data },
+	{ .compatible = "ti,am62l-rti-wdt", .data = &rti_wdt_am62l_data },
 	{},
 };
 MODULE_DEVICE_TABLE(of, rti_wdt_of_match);
Signature · 1 line
2.52.0
maintainer Reviewed-by on v5 2/2
#4 lore raw

Re: [PATCH v5 2/2] watchdog: rti_wdt: Add reaction control

Quoted 10 lines · Judith Mendez

This configures the reaction between NMI and reset for WWD.

On K3 SoCs other than AM62L SoC [0], watchdog reset output is routed to the ESM module which can subsequently route the signal to safety master or SoC reset. On AM62L, the watchdog reset output is routed to the SoC HW reset block. So, add a new compatible for AM62L to add SoC data and configure reaction to reset instead of NMI.

[0] https://www.ti.com/product/AM62L

Quoted 113 lines

---
Changes since v4 RESEND:
- Fix commit message grammar and capitalization issues
- Store only needed bool nmi field instead of pointer to match data structure
- Add NULL check for device_get_match_data() with proper error handling
- Rename data structures with SoC-specific rti_wdt prefix and add const
- Update struct documentation and clarify WDT expiration comment

---
  drivers/watchdog/rti_wdt.c | 39 ++++++++++++++++++++++++++++++++++----
  1 file changed, 35 insertions(+), 4 deletions(-)
drivers/watchdog/rti_wdt.c +35 -4
index be7d7db475911..c3c7715140ea8 100644
@@ -35,7 +35,8 @@
  #define RTIWWDRXCTRL	0xa4
  #define RTIWWDSIZECTRL	0xa8
 
-#define RTIWWDRX_NMI	0xa
+#define RTIWWDRXN_RST	0x5
+#define RTIWWDRXN_NMI	0xa
 
  #define RTIWWDSIZE_50P		0x50
  #define RTIWWDSIZE_25P		0x500
@@ -63,22 +64,29 @@
 
  static int heartbeat;
 
+struct rti_wdt_data {
+	bool nmi;
+};
+
  /*
   * struct to hold data for each WDT device
   * @base - base io address of WD device
   * @freq - source clock frequency of WDT
   * @wdd  - hold watchdog device as is in WDT core
+ * @nmi - Set if this WDT instance supports generating NMI
   */
  struct rti_wdt_device {
  	void __iomem		*base;
  	unsigned long		freq;
  	struct watchdog_device	wdd;
+	bool			nmi;
  };
 
  static int rti_wdt_start(struct watchdog_device *wdd)
  {
  	u32 timer_margin;
  	struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
+	u8 reaction;
  	int ret;
 
  	ret = pm_runtime_resume_and_get(wdd->parent);
@@ -101,8 +109,13 @@ static int rti_wdt_start(struct watchdog_device *wdd)
  	 */
  	wdd->min_hw_heartbeat_ms = 520 * wdd->timeout + MAX_HW_ERROR;
 
-	/* Generate NMI when wdt expires */
-	writel_relaxed(RTIWWDRX_NMI, wdt->base + RTIWWDRXCTRL);
+	/* When WDT expires, generate NMI or reset if NMI not supported */
+	if (wdt->nmi)
+		reaction = RTIWWDRXN_NMI;
+	else
+		reaction = RTIWWDRXN_RST;
+
+	writel_relaxed(reaction, wdt->base + RTIWWDRXCTRL);
 
  	/* Open window size 50%; this is the largest window size available */
  	writel_relaxed(RTIWWDSIZE_50P, wdt->base + RTIWWDSIZECTRL);
@@ -210,6 +223,7 @@ static int rti_wdt_probe(struct platform_device *pdev)
  {
  	int ret = 0;
  	struct device *dev = &pdev->dev;
+	const struct rti_wdt_data *data;
  	struct watchdog_device *wdd;
  	struct rti_wdt_device *wdt;
  	struct clk *clk;
@@ -254,6 +268,14 @@ static int rti_wdt_probe(struct platform_device *pdev)
  	wdd->timeout = DEFAULT_HEARTBEAT;
  	wdd->parent = dev;
 
+	data = device_get_match_data(dev);
+	if (!data) {
+		ret = -ENODEV;
+		goto err_iomap;
+	}
+
+	wdt->nmi = data->nmi;
+
  	watchdog_set_drvdata(wdd, wdt);
  	watchdog_set_nowayout(wdd, 1);
  	watchdog_set_restart_priority(wdd, 128);
@@ -361,8 +383,17 @@ static void rti_wdt_remove(struct platform_device *pdev)
  	pm_runtime_disable(&pdev->dev);
  }
 
+static const struct rti_wdt_data rti_wdt_j7_data = {
+	.nmi = true,
+};
+
+static const struct rti_wdt_data rti_wdt_am62l_data = {
+	.nmi = false,
+};
+
  static const struct of_device_id rti_wdt_of_match[] = {
-	{ .compatible = "ti,j7-rti-wdt", },
+	{ .compatible = "ti,j7-rti-wdt", .data = &rti_wdt_j7_data },
+	{ .compatible = "ti,am62l-rti-wdt", .data = &rti_wdt_am62l_data },
  	{},
  };
  MODULE_DEVICE_TABLE(of, rti_wdt_of_match);