Skip to contentSkip to conversation

tegra30 watchdog support

PATCH In review Andrew Chew 3 participants 13 messages Feb 4, 2014 – Feb 5, 2014

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

v2 cover tegra30 watchdog support

This patch series ultimately adds watchdog support for tegra30 and later chips.

The existing tegra clocksource driver (drivers/clocksource/tegra20_timer.c) sadly does not distinguish between tegra20 and tegra30 (and later), which it should have done since the contents of the timer register base have changed significantly. In particular, tegra30 (and later) has more timers, and also hardware watchdog registers.

The first patch adds nvidia,tegra30-timer to the list of compatibilty strings for the tegra timer device tree node, so that we can distinguish between tegra20 and tegra30 (and later).

The second patch separates out some macros that are interesting to other drivers (in particular, the tegra watchdog driver), and also adds the the missing timers that are present in tegra30 and later.

The third patch adds the actual watchdog driver. This driver configures a single watchdog (watchdog 0), pairs it with timer 5
(defined as TEGRA30_TIMER_WDT_* in the shared header file from the previous patch), and sets it up so that upon timer expiration, will cause the target system to reset.

I've decided to encapsulate all related changes into one patch series, since I did not modify any device tree bindings and therefore don't need to review dt changes separately. This way, everything can be seen within its complete context.

Andrew Chew (3):
clocksource: tegra: Add nvidia,tegra30-timer compat
clocksource: tegra: Define timer bases in header file
watchdog: Add tegra watchdog

 Documentation/watchdog/watchdog-parameters.txt |   5 +
 drivers/clocksource/tegra20_timer.c            |  16 +-
 drivers/watchdog/Kconfig                       |  11 +
 drivers/watchdog/Makefile                      |   1 +
 drivers/watchdog/tegra_wdt.c                   | 372 +++++++++++++++++++++++++
 include/clocksource/tegra_timer.h              |  43 +++
 6 files changed, 439 insertions(+), 9 deletions(-)
 create mode 100644 drivers/watchdog/tegra_wdt.c
 create mode 100644 include/clocksource/tegra_timer.h
Signature · 1 line
1.8.1.5
#1 lore raw

PATCH v2 1/3 clocksource: tegra: Add nvidia,tegra30-timer compat

There are some differences between tegra20's timer registers and tegra30's (and later). For example, tegra30 has more timers. In addition, watchdogs are not present in tegra20.

Add this compatibility string in order to be able to distinguish whether the additional timers and watchdogs are there or not.

---
 drivers/clocksource/tegra20_timer.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/tegra20_timer.c +1 -0
index d1869f0..73cfa56 100644
@@ -218,6 +218,7 @@ static void __init tegra20_init_timer(struct device_node *np)
 					0x1, 0x1fffffff);
 }
 CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer);
+CLOCKSOURCE_OF_DECLARE(tegra30_timer, "nvidia,tegra30-timer", tegra20_init_timer);
 
 static void __init tegra20_init_rtc(struct device_node *np)
 {
Signature · 1 line
1.8.1.5
#2 lore raw

Re: [PATCH v2 1/3] clocksource: tegra: Add nvidia,tegra30-timer compat

drivers/clocksource/tegra20_timer.c static void __init tegra20_init_timer(struct device_node *np) · line 221

Quoted 11 lines · Andrew Chew

There are some differences between tegra20's timer registers and tegra30's (and later). For example, tegra30 has more timers. In addition, watchdogs are not present in tegra20.

Add this compatibility string in order to be able to distinguish whether the additional timers and watchdogs are there or not.

drivers/clocksource/tegra20_timer.c +1 -0
 
 CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer);
+CLOCKSOURCE_OF_DECLARE(tegra30_timer, "nvidia,tegra30-timer", tegra20_init_timer);

Thinking about this more, nothing in this driver actually cares about Tegra20 vs. Tegra30+, since the timer that's used is present in all chips. Hence, this patch isn't needed.

#3 lore raw

RE: [PATCH v2 1/3] clocksource: tegra: Add nvidia,tegra30-timer compat

Quoted 11 lines · Andrew Chew
Quoted 9 lines

There are some differences between tegra20's timer registers and tegra30's (and later). For example, tegra30 has more timers. In addition, watchdogs are not present in tegra20.

Add this compatibility string in order to be able to distinguish whether the additional timers and watchdogs are there or not.

drivers/clocksource/tegra20_timer.c +0 -0
Quoted 8 lines

drivers/clocksource/tegra20_timer.c

Quoted 4 lines

CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer",
tegra20_init_timer);

drivers/clocksource/tegra20_timer.c +2 -0
+CLOCKSOURCE_OF_DECLARE(tegra30_timer, "nvidia,tegra30-timer",
+tegra20_init_timer);

Thinking about this more, nothing in this driver actually cares about Tegra20 vs. Tegra30+, since the timer that's used is present in all chips. Hence, this patch isn't needed.

Don't I need to add nvidia,tegra30-timer so that the tegra WDT driver can match against it? It would be weird to have the tegra WDT driver bind against nvidia,tegra20-timer when the tegra WDT driver as it is won't work at all on tegra20.

#4 lore raw

Re: [PATCH v2 1/3] clocksource: tegra: Add nvidia,tegra30-timer compat

Quoted 20 lines · Andrew Chew
Quoted 11 lines · Andrew Chew
Quoted 9 lines

There are some differences between tegra20's timer registers and tegra30's (and later). For example, tegra30 has more timers. In addition, watchdogs are not present in tegra20.

Add this compatibility string in order to be able to distinguish whether the additional timers and watchdogs are there or not.

drivers/clocksource/tegra20_timer.c +0 -0
Quoted 8 lines

drivers/clocksource/tegra20_timer.c

Quoted 4 lines

CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer",
tegra20_init_timer);

drivers/clocksource/tegra20_timer.c +2 -0
+CLOCKSOURCE_OF_DECLARE(tegra30_timer, "nvidia,tegra30-timer",
+tegra20_init_timer);

Thinking about this more, nothing in this driver actually cares about Tegra20 vs. Tegra30+, since the timer that's used is present in all chips. Hence, this patch isn't needed.

Quoted 4 lines

Don't I need to add nvidia,tegra30-timer so that the tegra WDT driver can match against it? It would be weird to have the tegra WDT driver bind against nvidia,tegra20-timer when the tegra WDT driver as it is won't work at all on tegra20.

The DT files need to contain all of:

* The specific SoC (this is already present)
* nvidia,tegra30-timer for SoCs >= Tegra30 (this is missing)
* nvidia,tegra20-timer for all SoCs (this is already present)

However, since all DTs will contain nvidia,tegra20-timer, since all HW is backwards-compatible IIUC, any code that only cares about the parts that have existed since Tegra20 only need match against the Tegra20 compatible value.

#5 lore raw

RE: [PATCH v2 1/3] clocksource: tegra: Add nvidia,tegra30-timer compat

Quoted 28 lines · Andrew Chew
Quoted 20 lines
Quoted 11 lines · Andrew Chew
Quoted 9 lines

There are some differences between tegra20's timer registers and tegra30's (and later). For example, tegra30 has more timers. In addition, watchdogs are not present in tegra20.

Add this compatibility string in order to be able to distinguish whether the additional timers and watchdogs are there or not.

drivers/clocksource/tegra20_timer.c +0 -0
Quoted 8 lines

drivers/clocksource/tegra20_timer.c

Quoted 4 lines

CLOCKSOURCE_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer",
tegra20_init_timer);

drivers/clocksource/tegra20_timer.c +2 -0
+CLOCKSOURCE_OF_DECLARE(tegra30_timer, "nvidia,tegra30-timer",
+tegra20_init_timer);

Thinking about this more, nothing in this driver actually cares about Tegra20 vs. Tegra30+, since the timer that's used is present in all chips. Hence, this patch isn't needed.

Quoted 4 lines

Don't I need to add nvidia,tegra30-timer so that the tegra WDT driver can match against it? It would be weird to have the tegra WDT driver bind against nvidia,tegra20-timer when the tegra WDT driver as it is won't work at all on tegra20.

The DT files need to contain all of:

Quoted 8 lines

* The specific SoC (this is already present)
* nvidia,tegra30-timer for SoCs >= Tegra30 (this is missing)
* nvidia,tegra20-timer for all SoCs (this is already present)

However, since all DTs will contain nvidia,tegra20-timer, since all HW is backwards-compatible IIUC, any code that only cares about the parts that have existed since Tegra20 only need match against the Tegra20 compatible value.

Okay, I think I get what you're saying. So I'll drop this patch. The tegra WDT driver will still match against nvidia,tegra30-timer, and device trees for SoCs that expect to use this WDT driver will have to have nvidia,tegra30-timer.

#6 lore raw

PATCH v2 2/3 clocksource: tegra: Define timer bases in header file

In reply to Andrew Chew

Added timers that are present in tegra30 and later, that are NOT in tegra20.

Also, some of these timer bases are needed in the tegra watchdog driver, so separate them out into a header file that both the clocksource driver and the watchdog driver can share them.

---
 drivers/clocksource/tegra20_timer.c | 15 ++++++-------
 include/clocksource/tegra_timer.h   | 43 +++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 9 deletions(-)
 create mode 100644 include/clocksource/tegra_timer.h
drivers/clocksource/tegra20_timer.c +6 -9
index 73cfa56..2c49643 100644
@@ -28,6 +28,8 @@
 #include <linux/of_irq.h>
 #include <linux/sched_clock.h>
 
+#include <clocksource/tegra_timer.h>
+
 #include <asm/mach/time.h>
 #include <asm/smp_twd.h>
 
@@ -39,11 +41,6 @@
 #define TIMERUS_USEC_CFG 0x14
 #define TIMERUS_CNTR_FREEZE 0x4c
 
-#define TIMER1_BASE 0x0
-#define TIMER2_BASE 0x8
-#define TIMER3_BASE 0x50
-#define TIMER4_BASE 0x58
-
 #define TIMER_PTV 0x0
 #define TIMER_PCR 0x4
 
@@ -64,7 +61,7 @@ static int tegra_timer_set_next_event(unsigned long cycles,
 	u32 reg;
 
 	reg = 0x80000000 | ((cycles > 1) ? (cycles-1) : 0);
-	timer_writel(reg, TIMER3_BASE + TIMER_PTV);
+	timer_writel(reg, TEGRA20_TIMER3_BASE + TIMER_PTV);
 
 	return 0;
 }
@@ -74,12 +71,12 @@ static void tegra_timer_set_mode(enum clock_event_mode mode,
 {
 	u32 reg;
 
-	timer_writel(0, TIMER3_BASE + TIMER_PTV);
+	timer_writel(0, TEGRA20_TIMER3_BASE + TIMER_PTV);
 
 	switch (mode) {
 	case CLOCK_EVT_MODE_PERIODIC:
 		reg = 0xC0000000 | ((1000000/HZ)-1);
-		timer_writel(reg, TIMER3_BASE + TIMER_PTV);
+		timer_writel(reg, TEGRA20_TIMER3_BASE + TIMER_PTV);
 		break;
 	case CLOCK_EVT_MODE_ONESHOT:
 		break;
@@ -142,7 +139,7 @@ static void tegra_read_persistent_clock(struct timespec *ts)
 static irqreturn_t tegra_timer_interrupt(int irq, void *dev_id)
 {
 	struct clock_event_device *evt = (struct clock_event_device *)dev_id;
-	timer_writel(1<<30, TIMER3_BASE + TIMER_PCR);
+	timer_writel(1<<30, TEGRA20_TIMER3_BASE + TIMER_PCR);
 	evt->event_handler(evt);
 	return IRQ_HANDLED;
 }
include/clocksource/tegra_timer.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#7 lore raw

Re: [PATCH v2 2/3] clocksource: tegra: Define timer bases in header file

Quoted 7 lines · Andrew Chew

Added timers that are present in tegra30 and later, that are NOT in tegra20.

Also, some of these timer bases are needed in the tegra watchdog driver, so separate them out into a header file that both the clocksource driver and the watchdog driver can share them.

When reading the patch 3/3, I don't see any define reused from this header except TEGRA30_TIMER_WDT_BASE which is only used for the watchdog. May be I missed something but I don't see any definition shared and thus I don't see the point of creating this header file.

Quoted 70 lines
---
  drivers/clocksource/tegra20_timer.c | 15 ++++++-------
  include/clocksource/tegra_timer.h   | 43 +++++++++++++++++++++++++++++++++++++
  2 files changed, 49 insertions(+), 9 deletions(-)

create mode 100644 include/clocksource/tegra_timer.h

drivers/clocksource/tegra20_timer.c +6 -9
index 73cfa56..2c49643 100644
@@ -28,6 +28,8 @@
  #include <linux/of_irq.h>
  #include <linux/sched_clock.h>
 
+#include <clocksource/tegra_timer.h>
+
  #include <asm/mach/time.h>
  #include <asm/smp_twd.h>
 
@@ -39,11 +41,6 @@
  #define TIMERUS_USEC_CFG 0x14
  #define TIMERUS_CNTR_FREEZE 0x4c
 
-#define TIMER1_BASE 0x0
-#define TIMER2_BASE 0x8
-#define TIMER3_BASE 0x50
-#define TIMER4_BASE 0x58
-
  #define TIMER_PTV 0x0
  #define TIMER_PCR 0x4
 
@@ -64,7 +61,7 @@ static int tegra_timer_set_next_event(unsigned long cycles,
  	u32 reg;
 
  	reg = 0x80000000 | ((cycles > 1) ? (cycles-1) : 0);
-	timer_writel(reg, TIMER3_BASE + TIMER_PTV);
+	timer_writel(reg, TEGRA20_TIMER3_BASE + TIMER_PTV);
 
  	return 0;
  }
@@ -74,12 +71,12 @@ static void tegra_timer_set_mode(enum clock_event_mode mode,
  {
  	u32 reg;
 
-	timer_writel(0, TIMER3_BASE + TIMER_PTV);
+	timer_writel(0, TEGRA20_TIMER3_BASE + TIMER_PTV);
 
  	switch (mode) {
  	case CLOCK_EVT_MODE_PERIODIC:
  		reg = 0xC0000000 | ((1000000/HZ)-1);
-		timer_writel(reg, TIMER3_BASE + TIMER_PTV);
+		timer_writel(reg, TEGRA20_TIMER3_BASE + TIMER_PTV);
  		break;
  	case CLOCK_EVT_MODE_ONESHOT:
  		break;
@@ -142,7 +139,7 @@ static void tegra_read_persistent_clock(struct timespec *ts)
  static irqreturn_t tegra_timer_interrupt(int irq, void *dev_id)
  {
  	struct clock_event_device *evt = (struct clock_event_device *)dev_id;
-	timer_writel(1<<30, TIMER3_BASE + TIMER_PCR);
+	timer_writel(1<<30, TEGRA20_TIMER3_BASE + TIMER_PCR);
  	evt->event_handler(evt);
  	return IRQ_HANDLED;
  }
include/clocksource/tegra_timer.h new file +0 -0
new file mode 100644
index 0000000..ea0bc8b

include/clocksource/tegra_timer.h line 5

Quoted 5 lines
include/clocksource/tegra_timer.h new file +5 -0
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 Google, Inc.
+ *
+ * Author:
+ *	Colin Cross <[email protected]>
         ^^^^^^^^^^^^^^^^^^
Quoted 39 lines
include/clocksource/tegra_timer.h new file +38 -0
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __CLOCKSOURCE_TEGRA_TIMER_H
+#define __CLOCKSOURCE_TEGRA_TIMER_H
+
+/* Tegra 20 timers */
+#define TEGRA20_TIMER1_BASE	0x0
+#define TEGRA20_TIMER2_BASE	0x8
+#define TEGRA20_TIMER3_BASE	0x50
+#define TEGRA20_TIMER4_BASE	0x58
+
+/* Tegra 30 timers */
+#define TEGRA30_TIMER1_BASE	TEGRA20_TIMER1_BASE
+#define TEGRA30_TIMER2_BASE	TEGRA20_TIMER2_BASE
+#define TEGRA30_TIMER3_BASE	TEGRA20_TIMER3_BASE
+#define TEGRA30_TIMER4_BASE	TEGRA20_TIMER4_BASE
+#define TEGRA30_TIMER5_BASE	0x60
+#define TEGRA30_TIMER6_BASE	0x68
+#define TEGRA30_TIMER7_BASE	0x70
+#define TEGRA30_TIMER8_BASE	0x78
+#define TEGRA30_TIMER9_BASE	0x80
+#define TEGRA30_TIMER0_BASE	0x88
+
+/* Used by the tegra watchdog timer */
+#define TEGRA30_TIMER_WDT_BASE	TEGRA30_TIMER5_BASE
+#define TEGRA30_TIMER_WDT_ID	5
+
+#endif /* __CLOCKSOURCE_TEGRA_TIMER_H */
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#8 lore raw

RE: [PATCH v2 2/3] clocksource: tegra: Define timer bases in header file

Quoted 18 lines

From: Daniel Lezcano [mailto:[email protected]]
Sent: Monday, February 03, 2014 11:55 PM
To: Andrew Chew; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v2 2/3] clocksource: tegra: Define timer bases in header file

Quoted 6 lines · Andrew Chew

Added timers that are present in tegra30 and later, that are NOT in tegra20.

Also, some of these timer bases are needed in the tegra watchdog driver, so separate them out into a header file that both the clocksource driver and the watchdog driver can share them.

Quoted 6 lines
Quoted 1 line

When reading the patch 3/3, I don't see any define reused from this header except TEGRA30_TIMER_WDT_BASE which is only used for the watchdog. May be I missed something but I don't see any definition shared and thus I don't see the point of creating this header file.

I guess the point is to make other potential drivers that make use of the timer registers aware that this particular timer (timer 5) is provisioned for the watchdog driver. Right now, you're right, there really isn't much that's shared...the only thing really is the base address of timer 5 (and its associated ID)...the timer bases are kind of all over the place, so it's not straightforward to calculate the ID from the base address.

But I believe the thought at the time (from Stephen Warren's suggestion) is to have a central place where this stuff is defined so that it's more clear what timers are provisioned for what purposes. It just happens that today, the only users of the timers, other than clocksource, is watchdog, as far as I can tell.

Quoted 7 lines

include/clocksource/tegra_timer.h line 5

Quoted 7 lines

+++ b/include/clocksource/tegra_timer.h

include/clocksource/tegra_timer.h new file +5 -0
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 Google, Inc.
+ *
+ * Author:
+ *	Colin Cross <[email protected]>

The contents of this new header file are largely just a cut and paste of the corresponding snippet in tegra20-timer.c, so I thought I'd carry over the license verbatim. I didn't author this really...I just moved it around. What should I do instead?

#9 lore raw

Re: [PATCH v2 2/3] clocksource: tegra: Define timer bases in header file

In reply to Andrew Chew
Quoted 15 lines · Andrew Chew

Added timers that are present in tegra30 and later, that are NOT in tegra20.

Also, some of these timer bases are needed in the tegra watchdog driver, so separate them out into a header file that both the clocksource driver and the watchdog driver can share them.

include/clocksource/tegra_timer.h +7 -0
 
+/* Tegra 20 timers */
+#define TEGRA20_TIMER1_BASE	0x0
+#define TEGRA20_TIMER2_BASE	0x8
+#define TEGRA20_TIMER3_BASE	0x50
+#define TEGRA20_TIMER4_BASE	0x58
+
+/* Tegra 30 timers */

include/clocksource/tegra_timer.h line 37

Quoted 10 lines
include/clocksource/tegra_timer.h +10 -0
+#define TEGRA30_TIMER1_BASE	TEGRA20_TIMER1_BASE
+#define TEGRA30_TIMER2_BASE	TEGRA20_TIMER2_BASE
+#define TEGRA30_TIMER3_BASE	TEGRA20_TIMER3_BASE
+#define TEGRA30_TIMER4_BASE	TEGRA20_TIMER4_BASE
+#define TEGRA30_TIMER5_BASE	0x60
+#define TEGRA30_TIMER6_BASE	0x68
+#define TEGRA30_TIMER7_BASE	0x70
+#define TEGRA30_TIMER8_BASE	0x78
+#define TEGRA30_TIMER9_BASE	0x80
+#define TEGRA30_TIMER0_BASE	0x88

Why put the SoC name in the define names? Why not just have TIMER1_BASE..TIMER10_BASE (that should be 10 not 0 as in your patch, right?) and have the driver know that 1..4 are valid on Tegra20, and 1..10 are valid on later chips.

I guess if the defines are moved into a header file, adding a TEGRA_ prefix does make sense.

But I wonder if it wouldn't be simpler for the Tegra WDT driver to just call a function on the Tegra clocksource driver to find out which timer ID(s) to avoid using? Even simpler would be to just put a comment in the WDT driver saying that timer 5 was chosen arbitrarily, but if it's changed make sure not to conflict with the clocksource driver (and an equivalent change to the clocksource driver).

#10 lore raw

RE: [PATCH v2 2/3] clocksource: tegra: Define timer bases in header file

Quoted 26 lines
Quoted 7 lines
include/clocksource/tegra_timer.h new file +7 -0
+/* Tegra 20 timers */
+#define TEGRA20_TIMER1_BASE	0x0
+#define TEGRA20_TIMER2_BASE	0x8
+#define TEGRA20_TIMER3_BASE	0x50
+#define TEGRA20_TIMER4_BASE	0x58
+
+/* Tegra 30 timers */

include/clocksource/tegra_timer.h line 37

Quoted 10 lines
include/clocksource/tegra_timer.h new file +10 -0
+#define TEGRA30_TIMER1_BASE	TEGRA20_TIMER1_BASE
+#define TEGRA30_TIMER2_BASE	TEGRA20_TIMER2_BASE
+#define TEGRA30_TIMER3_BASE	TEGRA20_TIMER3_BASE
+#define TEGRA30_TIMER4_BASE	TEGRA20_TIMER4_BASE
+#define TEGRA30_TIMER5_BASE	0x60
+#define TEGRA30_TIMER6_BASE	0x68
+#define TEGRA30_TIMER7_BASE	0x70
+#define TEGRA30_TIMER8_BASE	0x78
+#define TEGRA30_TIMER9_BASE	0x80
+#define TEGRA30_TIMER0_BASE	0x88

Why put the SoC name in the define names? Why not just have TIMER1_BASE..TIMER10_BASE (that should be 10 not 0 as in your patch, right?) and have the driver know that 1..4 are valid on Tegra20, and 1..10 are valid on later chips.

I guess if the defines are moved into a header file, adding a TEGRA_ prefix does make sense.

Quoted 6 lines

But I wonder if it wouldn't be simpler for the Tegra WDT driver to just call a function on the Tegra clocksource driver to find out which timer ID(s) to avoid using? Even simpler would be to just put a comment in the WDT driver saying that timer 5 was chosen arbitrarily, but if it's changed make sure not to conflict with the clocksource driver (and an equivalent change to the clocksource driver).

Alright, I think I'll just go with putting a comment in the WDT driver then, so that We don't need to add this new header file.

#11 lore raw

PATCH v2 3/3 watchdog: Add tegra watchdog

In reply to Andrew Chew

Add a driver for the hardware watchdogs in NVIDIA Tegra SoCs (tegra30 and later). This driver will configure one watchdog timer that will reset the system in the case of a watchdog timeout.

This driver binds to the nvidia,tegra30-timer device node and gets its register base from there.

---
 Documentation/watchdog/watchdog-parameters.txt |   5 +
 drivers/watchdog/Kconfig                       |  11 +
 drivers/watchdog/Makefile                      |   1 +
 drivers/watchdog/tegra_wdt.c                   | 372 +++++++++++++++++++++++++
 4 files changed, 389 insertions(+)
 create mode 100644 drivers/watchdog/tegra_wdt.c
Documentation/watchdog/watchdog-parameters.txt +5 -0
index f9492fe..b39f355 100644
@@ -325,6 +325,11 @@ soft_noboot: Softdog action, set to 1 to ignore reboots, 0 to reboot
 stmp3xxx_wdt:
 heartbeat: Watchdog heartbeat period in seconds from 1 to 4194304, default 19
 -------------------------------------------------
+tegra_wdt:
+heartbeat: Watchdog heartbeats in seconds. (default = 120)
+nowayout: Watchdog cannot be stopped once started
+	(default=kernel config parameter)
+-------------------------------------------------
 ts72xx_wdt:
 timeout: Watchdog timeout in seconds. (1 <= timeout <= 8, default=8)
 nowayout: Disable watchdog shutdown on close
drivers/watchdog/Kconfig +11 -0
index 4c4c566..2852447 100644
@@ -420,6 +420,17 @@ config SIRFSOC_WATCHDOG
 	  Support for CSR SiRFprimaII and SiRFatlasVI watchdog. When
 	  the watchdog triggers the system will be reset.
 
+config TEGRA_WATCHDOG
+	tristate "Tegra watchdog"
+	depends on ARCH_TEGRA
+	select WATCHDOG_CORE
+	help
+	  Say Y here to include support for the watchdog timer
+	  embedded in NVIDIA Tegra SoCs.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called tegra_wdt.
+
 # AVR32 Architecture
 
 config AT32AP700X_WDT
drivers/watchdog/Makefile +1 -0
index 985a66c..1b5f3d5 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
 obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
 obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
 obj-$(CONFIG_BCM_KONA_WDT) += bcm_kona_wdt.o
+obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o
 
 # AVR32 Architecture
 obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
drivers/watchdog/tegra_wdt.c new file +372 -0

372 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#12 lore raw

Re: [PATCH v2 3/3] watchdog: Add tegra watchdog

Quoted 1 line · Andrew Chew

Add a driver for the hardware watchdogs in NVIDIA Tegra SoCs (tegra30 and

s/tegra30/Tegra30/

drivers/watchdog/Kconfig config SIRFSOC_WATCHDOG · line 425

Quoted 11 lines

later). This driver will configure one watchdog timer that will reset the system in the case of a watchdog timeout.

This driver binds to the nvidia,tegra30-timer device node and gets its register base from there.

drivers/watchdog/Kconfig +3 -0
 
+config TEGRA_WATCHDOG
+	tristate "Tegra watchdog"
+	depends on ARCH_TEGRA

|| COMPILE_TEST ?

Quoted 7 lines
drivers/watchdog/tegra_wdt.c +4 -0
 
+static int tegra_wdt_probe(struct platform_device *pdev)
 
+	/* This is the timer base. */
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {

...

Quoted 4 lines
drivers/watchdog/tegra_wdt.c +4 -0
+	mem = devm_request_mem_region(&pdev->dev, res->start,
+				      resource_size(res),
+				      pdev->name);
+	if (!mem) {

...

drivers/watchdog/tegra_wdt.c line 233

Quoted 3 lines
drivers/watchdog/tegra_wdt.c +3 -0
+	regs = devm_ioremap(&pdev->dev, mem->start,
+			    resource_size(mem));
+	if (!regs) {

...

I forget exactly which of those, but I think at least one/some of those don't need to be error-checked, since the later functions will detect an error input, and return an appropriate error code, so they can be chained together while only error-checking the final result.

drivers/watchdog/tegra_wdt.c line 306

Quoted 3 lines
drivers/watchdog/tegra_wdt.c +2 -0
+static int tegra_wdt_remove(struct platform_device *pdev)
 
+	platform_set_drvdata(pdev, NULL);

There's no need to do that; the value of drvdata is irrelevant when the device isn't probed, so there's no need for it to be NULL.

drivers/watchdog/tegra_wdt.c line 358

Quoted 7 lines
drivers/watchdog/tegra_wdt.c +7 -0
+static struct platform_driver tegra_wdt_driver = {
+	.probe		= tegra_wdt_probe,
+	.remove		= tegra_wdt_remove,
+#ifdef CONFIG_PM
+	.suspend	= tegra_wdt_suspend,
+	.resume		= tegra_wdt_resume,
+#endif

I think for suspend/resume, you'd usually set it up like:

static const struct dev_pm_ops tegra20_i2s_pm_ops = {
SET_RUNTIME_PM_OPS(tegra20_i2s_runtime_suspend,
tegra20_i2s_runtime_resume, NULL)
};

static struct platform_driver tegra20_i2s_driver = {
        .driver = {
...
               .pm = &tegra20_i2s_pm_ops,
        },

...
};

drivers/watchdog/tegra_wdt.c line 366

Quoted 8 lines
drivers/watchdog/tegra_wdt.c +8 -0
+	.driver		= {
+		.owner	= THIS_MODULE,
+		.name	= "tegra-wdt",
+		.of_match_table = tegra_wdt_of_match,
+	},
+};
+
+module_platform_driver(tegra_wdt_driver);

No need for the blank line before module_platform_driver().

drivers/watchdog/tegra_wdt.c line 372

Quoted 2 lines
drivers/watchdog/tegra_wdt.c +2 -0
+MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
+MODULE_ALIAS("platform:tegra-wdt");

You don't need at least that second alias; everything binds to the MODULE_DEVICE_TABLE() now with DT.