Re: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-12 Thread Guenter Roeck
On Wed, Feb 12, 2014 at 01:43:37PM -0800, Andrew Chew wrote:
> > > +static void tegra_wdt_unref(struct watchdog_device *wdd) {
> > > + struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
> > > +
> > > + kref_put(>kref, tegra_wdt_release_resources); }
> > 
> > I forget why these were needed; they seem to do nothing.
> 
> The reason I did the whole kref thing was by following the guidance
> in Documentation/watchdog/watchdog-kernel-api.txt, which says
> that if the watchdog_device struct is dynamically allocated, then
> one needs this.
> 
I read that too, but I could not follow the logic behind it,
nor the explanation provided with the commit introducing it ;-)

Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-12 Thread Andrew Chew
> > +static void tegra_wdt_unref(struct watchdog_device *wdd) {
> > +   struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
> > +
> > +   kref_put(>kref, tegra_wdt_release_resources); }
> 
> I forget why these were needed; they seem to do nothing.

The reason I did the whole kref thing was by following the guidance
in Documentation/watchdog/watchdog-kernel-api.txt, which says
that if the watchdog_device struct is dynamically allocated, then
one needs this.

> > +MODULE_LICENSE("GPL");
> 
> That should be "GPL v2" according to the license header in the file.

Done.  Thanks!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-12 Thread Stephen Warren
On 02/06/2014 06:54 PM, Andrew Chew wrote:
> 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.

Tested-by: Stephen Warren 

Briefly,
Reviewed-by: Stephen Warren 

Just a couple small comments though.

> diff --git a/drivers/watchdog/tegra_wdt.c b/drivers/watchdog/tegra_wdt.c

> +static void tegra_wdt_ref(struct watchdog_device *wdd)
> +{
> + struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
> +
> + kref_get(>kref);
> +}
> +
> +static void tegra_wdt_unref(struct watchdog_device *wdd)
> +{
> + struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
> +
> + kref_put(>kref, tegra_wdt_release_resources);
> +}

I forget why these were needed; they seem to do nothing.

> +MODULE_LICENSE("GPL");

That should be "GPL v2" according to the license header in the file.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-12 Thread Stephen Warren
On 02/06/2014 06:54 PM, Andrew Chew wrote:
 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.

Tested-by: Stephen Warren swar...@nvidia.com

Briefly,
Reviewed-by: Stephen Warren swar...@nvidia.com

Just a couple small comments though.

 diff --git a/drivers/watchdog/tegra_wdt.c b/drivers/watchdog/tegra_wdt.c

 +static void tegra_wdt_ref(struct watchdog_device *wdd)
 +{
 + struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
 +
 + kref_get(wdt-kref);
 +}
 +
 +static void tegra_wdt_unref(struct watchdog_device *wdd)
 +{
 + struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
 +
 + kref_put(wdt-kref, tegra_wdt_release_resources);
 +}

I forget why these were needed; they seem to do nothing.

 +MODULE_LICENSE(GPL);

That should be GPL v2 according to the license header in the file.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-12 Thread Andrew Chew
  +static void tegra_wdt_unref(struct watchdog_device *wdd) {
  +   struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
  +
  +   kref_put(wdt-kref, tegra_wdt_release_resources); }
 
 I forget why these were needed; they seem to do nothing.

The reason I did the whole kref thing was by following the guidance
in Documentation/watchdog/watchdog-kernel-api.txt, which says
that if the watchdog_device struct is dynamically allocated, then
one needs this.

  +MODULE_LICENSE(GPL);
 
 That should be GPL v2 according to the license header in the file.

Done.  Thanks!
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-12 Thread Guenter Roeck
On Wed, Feb 12, 2014 at 01:43:37PM -0800, Andrew Chew wrote:
   +static void tegra_wdt_unref(struct watchdog_device *wdd) {
   + struct tegra_wdt *wdt = watchdog_get_drvdata(wdd);
   +
   + kref_put(wdt-kref, tegra_wdt_release_resources); }
  
  I forget why these were needed; they seem to do nothing.
 
 The reason I did the whole kref thing was by following the guidance
 in Documentation/watchdog/watchdog-kernel-api.txt, which says
 that if the watchdog_device struct is dynamically allocated, then
 one needs this.
 
I read that too, but I could not follow the logic behind it,
nor the explanation provided with the commit introducing it ;-)

Guenter
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-11 Thread Andrew Chew
> On 02/06/2014 05:54 PM, Andrew Chew wrote:
> > 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.
> >
> > Signed-off-by: Andrew Chew 
> 
> Reviewed-by: Guenter Roeck 

Thanks, Guenter.

Pinging other potential reviewers.  Any other comments for me, guys?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-11 Thread Andrew Chew
 On 02/06/2014 05:54 PM, Andrew Chew wrote:
  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.
 
  Signed-off-by: Andrew Chew ac...@nvidia.com
 
 Reviewed-by: Guenter Roeck li...@roeck-us.net

Thanks, Guenter.

Pinging other potential reviewers.  Any other comments for me, guys?
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-06 Thread Guenter Roeck

On 02/06/2014 05:54 PM, Andrew Chew wrote:

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.

Signed-off-by: Andrew Chew 


Reviewed-by: Guenter Roeck 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-06 Thread 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.

Signed-off-by: Andrew Chew 
---
Changes from v4:

Skip the error check from the platform_get_resources() call, because
devm_ioremap_resource() correctly handles the case when res is NULL.

Changes from v3:

Applied Cuenter Roeck 's comments.  In particular,
since tegra_wdt_start() and tegra_wdt_stop() always return success, skip
error checking for these calls.  Also, removed some unnecessarily verbose
logging around which watchdog and timer ID is being used.  Fixed typo
regarding the ref and unref callback setup.  Removed miscdev stuff.

Cuenter was right in that the watchdog doesn't need to be stopped prior
to changing the timeout.  It is sufficient to just reprogram the watchdog
with the new timeout.

Tested on T124.

To do a simple test, "echo 0 > /dev/watchdog0".  The target will reset when
two minutes (the default heartbeat interval) have expired since the last
write to /dev/watchdog0.

 Documentation/watchdog/watchdog-parameters.txt |   5 +
 drivers/watchdog/Kconfig   |  11 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/tegra_wdt.c   | 327 +
 4 files changed, 344 insertions(+)
 create mode 100644 drivers/watchdog/tegra_wdt.c

diff --git a/Documentation/watchdog/watchdog-parameters.txt 
b/Documentation/watchdog/watchdog-parameters.txt
index f9492fe..b39f355 100644
--- a/Documentation/watchdog/watchdog-parameters.txt
+++ b/Documentation/watchdog/watchdog-parameters.txt
@@ -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
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 4c4c566..3aae2da 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -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 || COMPILE_TEST
+   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
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 985a66c..1b5f3d5 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -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
diff --git a/drivers/watchdog/tegra_wdt.c b/drivers/watchdog/tegra_wdt.c
new file mode 100644
index 000..4c39aad
--- /dev/null
+++ b/drivers/watchdog/tegra_wdt.c
@@ -0,0 +1,327 @@
+/*
+ * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* minimum and maximum watchdog trigger timeout, in seconds */
+#define MIN_WDT_TIMEOUT1
+#define MAX_WDT_TIMEOUT255
+
+/*
+ * Base of the WDT registers, from the timer base address.  There are
+ * actually 5 watchdogs that can be configured (by pairing with an available
+ * timer), at bases 0x100 + (WDT ID) * 0x20, where WDT ID is 0 through 4.
+ * This driver only configures the first watchdog (WDT ID 0).
+ */
+#define WDT_BASE   0x100
+#define WDT_ID 0
+
+/*
+ * Register base of the timer that's selected for pairing with the 

Re: [PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-06 Thread Guenter Roeck

On 02/06/2014 05:54 PM, Andrew Chew wrote:

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.

Signed-off-by: Andrew Chew ac...@nvidia.com


Reviewed-by: Guenter Roeck li...@roeck-us.net

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 1/1] watchdog: Add tegra watchdog

2014-02-06 Thread 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.

Signed-off-by: Andrew Chew ac...@nvidia.com
---
Changes from v4:

Skip the error check from the platform_get_resources() call, because
devm_ioremap_resource() correctly handles the case when res is NULL.

Changes from v3:

Applied Cuenter Roeck li...@roeck-us.net's comments.  In particular,
since tegra_wdt_start() and tegra_wdt_stop() always return success, skip
error checking for these calls.  Also, removed some unnecessarily verbose
logging around which watchdog and timer ID is being used.  Fixed typo
regarding the ref and unref callback setup.  Removed miscdev stuff.

Cuenter was right in that the watchdog doesn't need to be stopped prior
to changing the timeout.  It is sufficient to just reprogram the watchdog
with the new timeout.

Tested on T124.

To do a simple test, echo 0  /dev/watchdog0.  The target will reset when
two minutes (the default heartbeat interval) have expired since the last
write to /dev/watchdog0.

 Documentation/watchdog/watchdog-parameters.txt |   5 +
 drivers/watchdog/Kconfig   |  11 +
 drivers/watchdog/Makefile  |   1 +
 drivers/watchdog/tegra_wdt.c   | 327 +
 4 files changed, 344 insertions(+)
 create mode 100644 drivers/watchdog/tegra_wdt.c

diff --git a/Documentation/watchdog/watchdog-parameters.txt 
b/Documentation/watchdog/watchdog-parameters.txt
index f9492fe..b39f355 100644
--- a/Documentation/watchdog/watchdog-parameters.txt
+++ b/Documentation/watchdog/watchdog-parameters.txt
@@ -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
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 4c4c566..3aae2da 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -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 || COMPILE_TEST
+   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
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 985a66c..1b5f3d5 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -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
diff --git a/drivers/watchdog/tegra_wdt.c b/drivers/watchdog/tegra_wdt.c
new file mode 100644
index 000..4c39aad
--- /dev/null
+++ b/drivers/watchdog/tegra_wdt.c
@@ -0,0 +1,327 @@
+/*
+ * Copyright (c) 2014, NVIDIA CORPORATION.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ */
+
+#include linux/kernel.h
+#include linux/module.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/watchdog.h
+
+/* minimum and maximum watchdog trigger timeout, in seconds */
+#define MIN_WDT_TIMEOUT1
+#define MAX_WDT_TIMEOUT255
+
+/*
+ * Base of the WDT registers, from the timer base address.  There are
+ * actually 5 watchdogs that can be configured (by pairing with an available
+ * timer), at bases 0x100 + (WDT ID) * 0x20, where WDT ID is 0 through 4.
+ * This driver only configures the first watchdog (WDT ID 0).
+ */
+#define WDT_BASE