Re: [PATCH v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-31 Thread Guenter Roeck
On Fri, May 31, 2013 at 03:05:50PM +0530, anish singh wrote:
> Hi Guenter,
> 
> On Fri, May 31, 2013 at 3:32 AM, Guenter Roeck  wrote:
> > On Thu, May 30, 2013 at 11:59:28PM +0200, Wim Van Sebroeck wrote:
> >> Hi Guenter,
> >>
> >> > On Tue, May 28, 2013 at 10:10:53AM +0200, Johannes Thumshirn wrote:
> >> > > On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
> >> > > [...]
> >> > > > > + watchdog_set_drvdata(&a21_wdt, drv);
> >> > > >
> >> > > > I am missing the initialisation of the watchdog's timeout value 
> >> > > > here...
> >> > >
> >> > > This watchdog only knows two timeout values, 1s and 30s with the 
> >> > > constraint
> >> > > that you can't go back to 30s once your in a 1s timeout without a 
> >> > > reset of the
> >> > > CPLD. I could initially set it to 30s but that would be redundant.
> >> > >
> >> > I wonder - why bother with supporting one-second timeouts ?
> >> >
> >> > Is this realistic, ie can you guarantee that the watchdog will be pinged 
> >> > fast
> >> > enough to keep the system alive under all load conditions ? As far as I 
> >> > know
> >> > you can not even configure the watchdog application for less than 1 
> >> > second
> >> > ping intervals.
> >>
> >> that's why certain drivers use a timer to keep kicking the watchdog at
> >> a rate of 0.5s (do a grep on HZ/2) untill userspace times out.
> >> (example: drivers/watchdog/pika_wdt.c or drivers/watchdog/pcwd.c).
> >>
> > Yes, I have used the same trick in a couple of my drivers. That isn't done 
> > here,
> > though.
> >
> > I even thought about adding this capability to the infrastructure.
> 
> If you don't mind can I give it a try?

I don't mind, but you might want to wait for Wim's feedback.

Thanks,
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-31 Thread anish singh
Hi Guenter,

On Fri, May 31, 2013 at 3:32 AM, Guenter Roeck  wrote:
> On Thu, May 30, 2013 at 11:59:28PM +0200, Wim Van Sebroeck wrote:
>> Hi Guenter,
>>
>> > On Tue, May 28, 2013 at 10:10:53AM +0200, Johannes Thumshirn wrote:
>> > > On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
>> > > [...]
>> > > > > + watchdog_set_drvdata(&a21_wdt, drv);
>> > > >
>> > > > I am missing the initialisation of the watchdog's timeout value here...
>> > >
>> > > This watchdog only knows two timeout values, 1s and 30s with the 
>> > > constraint
>> > > that you can't go back to 30s once your in a 1s timeout without a reset 
>> > > of the
>> > > CPLD. I could initially set it to 30s but that would be redundant.
>> > >
>> > I wonder - why bother with supporting one-second timeouts ?
>> >
>> > Is this realistic, ie can you guarantee that the watchdog will be pinged 
>> > fast
>> > enough to keep the system alive under all load conditions ? As far as I 
>> > know
>> > you can not even configure the watchdog application for less than 1 second
>> > ping intervals.
>>
>> that's why certain drivers use a timer to keep kicking the watchdog at
>> a rate of 0.5s (do a grep on HZ/2) untill userspace times out.
>> (example: drivers/watchdog/pika_wdt.c or drivers/watchdog/pcwd.c).
>>
> Yes, I have used the same trick in a couple of my drivers. That isn't done 
> here,
> though.
>
> I even thought about adding this capability to the infrastructure.

If you don't mind can I give it a try?
>
> Thanks,
> 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/
--
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-31 Thread Johannes Thumshirn
Hi Guenther,

On Thu, May 30, 2013 at 03:02:47PM -0700, Guenter Roeck wrote:
> On Thu, May 30, 2013 at 11:59:28PM +0200, Wim Van Sebroeck wrote:
> > Hi Guenter,
> >
[...]
>
> I even thought about adding this capability to the infrastructure.

Actually this would be pretty nice to have
>
> Thanks,
> Guenter

Johannes
--
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-30 Thread Guenter Roeck
On Thu, May 30, 2013 at 11:59:28PM +0200, Wim Van Sebroeck wrote:
> Hi Guenter,
> 
> > On Tue, May 28, 2013 at 10:10:53AM +0200, Johannes Thumshirn wrote:
> > > On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
> > > [...]
> > > > > + watchdog_set_drvdata(&a21_wdt, drv);
> > > >
> > > > I am missing the initialisation of the watchdog's timeout value here...
> > > 
> > > This watchdog only knows two timeout values, 1s and 30s with the 
> > > constraint
> > > that you can't go back to 30s once your in a 1s timeout without a reset 
> > > of the
> > > CPLD. I could initially set it to 30s but that would be redundant.
> > > 
> > I wonder - why bother with supporting one-second timeouts ?
> > 
> > Is this realistic, ie can you guarantee that the watchdog will be pinged 
> > fast
> > enough to keep the system alive under all load conditions ? As far as I know
> > you can not even configure the watchdog application for less than 1 second
> > ping intervals.
> 
> that's why certain drivers use a timer to keep kicking the watchdog at
> a rate of 0.5s (do a grep on HZ/2) untill userspace times out.
> (example: drivers/watchdog/pika_wdt.c or drivers/watchdog/pcwd.c).
> 
Yes, I have used the same trick in a couple of my drivers. That isn't done here,
though.

I even thought about adding this capability to the infrastructure.

Thanks,
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-30 Thread Wim Van Sebroeck
Hi Guenter,

> On Tue, May 28, 2013 at 10:10:53AM +0200, Johannes Thumshirn wrote:
> > On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
> > [...]
> > > > +   watchdog_set_drvdata(&a21_wdt, drv);
> > >
> > > I am missing the initialisation of the watchdog's timeout value here...
> > 
> > This watchdog only knows two timeout values, 1s and 30s with the constraint
> > that you can't go back to 30s once your in a 1s timeout without a reset of 
> > the
> > CPLD. I could initially set it to 30s but that would be redundant.
> > 
> I wonder - why bother with supporting one-second timeouts ?
> 
> Is this realistic, ie can you guarantee that the watchdog will be pinged fast
> enough to keep the system alive under all load conditions ? As far as I know
> you can not even configure the watchdog application for less than 1 second
> ping intervals.

that's why certain drivers use a timer to keep kicking the watchdog at
a rate of 0.5s (do a grep on HZ/2) untill userspace times out.
(example: drivers/watchdog/pika_wdt.c or drivers/watchdog/pcwd.c).

Kind regards,
Wim.

--
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-30 Thread Wim Van Sebroeck
Hi Johannes,

> On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
> [...]
> > > + watchdog_set_drvdata(&a21_wdt, drv);
> >
> > I am missing the initialisation of the watchdog's timeout value here...
> 
> This watchdog only knows two timeout values, 1s and 30s with the constraint
> that you can't go back to 30s once your in a 1s timeout without a reset of the
> CPLD. I could initially set it to 30s but that would be redundant.

Yes, but if I use a WDIOC_GETTIMEOUT ioctl call then I will get 0 because
you didn't initialize a21_wdt.timeout so you don't know wether or not
it's 30 or 1.

You can also set it default to 1 and use a timer to do the bridge between 
userspace
and an in kernel timer of 0.5msec. (see 
git/linux-watchdog/drivers/watchdog/pika_wdt.c
as an example).

Kind regards,
Wim.

--
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-29 Thread Johannes Thumshirn
On Tue, May 28, 2013 at 09:22:18AM -0700, Guenter Roeck wrote:
> On Tue, May 28, 2013 at 10:10:53AM +0200, Johannes Thumshirn wrote:
> > On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
> > [...]
> > > > +   watchdog_set_drvdata(&a21_wdt, drv);
> > >
> > > I am missing the initialisation of the watchdog's timeout value here...
> >
> > This watchdog only knows two timeout values, 1s and 30s with the constraint
> > that you can't go back to 30s once your in a 1s timeout without a reset of 
> > the
> > CPLD. I could initially set it to 30s but that would be redundant.
> >
> I wonder - why bother with supporting one-second timeouts ?
>
> Is this realistic, ie can you guarantee that the watchdog will be pinged fast
> enough to keep the system alive under all load conditions ? As far as I know
> you can not even configure the watchdog application for less than 1 second
> ping intervals.
>
> Thanks,
> Guenter

Well in my tests it was possible, maybe not under extremely high load. But
considering the application these boards (the VME CPU board the watchdogs chip
is on) are usually used by our customers, I hope they can react within a single
second. Another reason why I want to support the 1s timeout is, the VxWorks BSP
does it too and we don't want a Linux driver have less features than it's
VxWorks counterpart, do we ;-). Just kidding. My opinion is, the hardware
supports it and so should the driver, especially for the (safety critical)
industrial control and automation applications our customers usually do. Just
my point of view though.

Regards,
Johannes
--
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-28 Thread Guenter Roeck
On Tue, May 28, 2013 at 10:10:53AM +0200, Johannes Thumshirn wrote:
> On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
> [...]
> > > + watchdog_set_drvdata(&a21_wdt, drv);
> >
> > I am missing the initialisation of the watchdog's timeout value here...
> 
> This watchdog only knows two timeout values, 1s and 30s with the constraint
> that you can't go back to 30s once your in a 1s timeout without a reset of the
> CPLD. I could initially set it to 30s but that would be redundant.
> 
I wonder - why bother with supporting one-second timeouts ?

Is this realistic, ie can you guarantee that the watchdog will be pinged fast
enough to keep the system alive under all load conditions ? As far as I know
you can not even configure the watchdog application for less than 1 second
ping intervals.

Thanks,
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-28 Thread Johannes Thumshirn
On Mon, May 27, 2013 at 08:25:54PM +0200, Wim Van Sebroeck wrote:
[...]
> > +   watchdog_set_drvdata(&a21_wdt, drv);
>
> I am missing the initialisation of the watchdog's timeout value here...

This watchdog only knows two timeout values, 1s and 30s with the constraint
that you can't go back to 30s once your in a 1s timeout without a reset of the
CPLD. I could initially set it to 30s but that would be redundant.

> For the rest this looks OK.
>
> Kind regards,
> wim.
>

This sounds pretty good.
--
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 v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-27 Thread Wim Van Sebroeck
Hi Johannes,

> This patch adds the driver for the watchdog devices found on MEN Mikro
> Elektronik A21 VMEbus CPU Carrier Boards. It has DT-support and uses the
> watchdog framework.
> 
> Revision 2:
> * Removed unneeded open flag in struct a21_wdt_drv
> * Corrected 3bit reason code from gpio
> * Additional sysfs files are now part of watchdog sysfs
> * Changed OFF/ON delay in ping from 400ms to 10ns
> * Reworked timeout setting
> * Removed a21_wdt_ioctl(...)
> 
> Revision 3:
> * Changed pr_{err,info} to dev_{err,info}
> * Removed out of memory error print
> * Transition from "fast" to "slow" mode not allowed by chip
> 
> Revision 4:
> * Remove reboot_notifier and place disable code into platform_device's 
> shutdown function
> * Removed sysfs interface
> 
> Signed-off-by: Johannes Thumshirn 
> ---
>  MAINTAINERS   |6 ++
>  drivers/watchdog/Kconfig  |8 ++
>  drivers/watchdog/Makefile |1 +
>  drivers/watchdog/mena21_wdt.c |  204 
> +
>  4 files changed, 219 insertions(+)
>  create mode 100644 drivers/watchdog/mena21_wdt.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index fd3a495..1ca147a 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -5306,6 +5306,12 @@ F: drivers/mtd/
>  F:   include/linux/mtd/
>  F:   include/uapi/mtd/
>  
> +MEN A21 WATCHDOG DRIVER
> +M:   Johannes Thumshirn 
> +L:   linux-watch...@vger.kernel.org
> +S:   Supported
> +F:   drivers/watchdog/mena21_wdt.c
> +
>  METAG ARCHITECTURE
>  M:   James Hogan 
>  S:   Supported
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index e89fc31..192b84d 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -1172,6 +1172,14 @@ config BOOKE_WDT_DEFAULT_TIMEOUT
>  
> The value can be overridden by the wdt_period command-line parameter.
>  
> +config MEN_A21_WDT
> +   tristate "MEN A21 VME CPU Carrier Board Watchdog Timer"
> +   select WATCHDOG_CORE
> +   help
> +Watchdog driver for MEN A21 VMEbus CPU Carrier Boards.
> +
> + If unsure select N here.
> +
>  # PPC64 Architecture
>  
>  config WATCHDOG_RTAS
> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> index a300b94..bffdcb1 100644
> --- a/drivers/watchdog/Makefile
> +++ b/drivers/watchdog/Makefile
> @@ -143,6 +143,7 @@ obj-$(CONFIG_8xxx_WDT) += mpc8xxx_wdt.o
>  obj-$(CONFIG_MV64X60_WDT) += mv64x60_wdt.o
>  obj-$(CONFIG_PIKA_WDT) += pika_wdt.o
>  obj-$(CONFIG_BOOKE_WDT) += booke_wdt.o
> +obj-$(CONFIG_MEN_A21_WDT) += mena21_wdt.o
>  
>  # PPC64 Architecture
>  obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o
> diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c
> new file mode 100644
> index 000..4fe65ec
> --- /dev/null
> +++ b/drivers/watchdog/mena21_wdt.c
> @@ -0,0 +1,204 @@
> +/*
> + * Watchdog driver for the A21 VME CPU Boards
> + *
> + * Copyright (C) 2013 MEN Mikro Elektronik Nuernberg GmbH
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define GPIO_WD_ENAB 169
> +#define GPIO_WD_FAST 170
> +#define GPIO_WD_TRIG 171
> +
> +#define GPIO_RST_CAUSE_BASE 166
> +
> +struct a21_wdt_drv {
> + struct watchdog_device wdt;
> + struct mutex lock;
> +};
> +
> +static bool nowayout = WATCHDOG_NOWAYOUT;
> +module_param(nowayout, bool, 0);
> +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started 
> (default="
> + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
> +
> +static int a21_wdt_start(struct watchdog_device *wdt)
> +{
> + struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
> +
> + mutex_lock(&drv->lock);
> +
> + gpio_set_value(GPIO_WD_ENAB, 1);
> +
> + mutex_unlock(&drv->lock);
> +
> + return 0;
> +}
> +
> +static int a21_wdt_stop(struct watchdog_device *wdt)
> +{
> + struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
> +
> + /* We don't stop if WDOG_NO_WAY_OUT is set */
> + if (test_bit(WDOG_NO_WAY_OUT, &wdt->status))
> + return -EINVAL;
> +
> + mutex_lock(&drv->lock);
> +
> + gpio_set_value(GPIO_WD_ENAB, 0);
> +
> + mutex_unlock(&drv->lock);
> +
> + return 0;
> +}
> +
> +static int a21_wdt_ping(struct watchdog_device *wdt)
> +{
> + struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
> +
> + mutex_lock(&drv->lock);
> +
> + gpio_set_value(GPIO_WD_TRIG, 0);
> + ndelay(10);
> + gpio_set_value(GPIO_WD_TRIG, 1);
> +
> + mutex_unlock(&drv->lock);
> +
> + return 0;
> +}
> +
> +static int a21_wdt_set_timeout(struct watchdog_device *wdt,
> +unsigned int timeout)
> +{
> + struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
> +
> + if (timeout != 1 && timeout !

[PATCH v4 1/2] watchdog: New watchdog driver for MEN A21 watchdogs

2013-05-27 Thread johannes . thumshirn
From: Johannes Thumshirn 

This patch adds the driver for the watchdog devices found on MEN Mikro
Elektronik A21 VMEbus CPU Carrier Boards. It has DT-support and uses the
watchdog framework.

Revision 2:
* Removed unneeded open flag in struct a21_wdt_drv
* Corrected 3bit reason code from gpio
* Additional sysfs files are now part of watchdog sysfs
* Changed OFF/ON delay in ping from 400ms to 10ns
* Reworked timeout setting
* Removed a21_wdt_ioctl(...)

Revision 3:
* Changed pr_{err,info} to dev_{err,info}
* Removed out of memory error print
* Transition from "fast" to "slow" mode not allowed by chip

Revision 4:
* Remove reboot_notifier and place disable code into platform_device's shutdown 
function
* Removed sysfs interface

Signed-off-by: Johannes Thumshirn 
---
 MAINTAINERS   |6 ++
 drivers/watchdog/Kconfig  |8 ++
 drivers/watchdog/Makefile |1 +
 drivers/watchdog/mena21_wdt.c |  204 +
 4 files changed, 219 insertions(+)
 create mode 100644 drivers/watchdog/mena21_wdt.c

diff --git a/MAINTAINERS b/MAINTAINERS
index fd3a495..1ca147a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5306,6 +5306,12 @@ F:   drivers/mtd/
 F: include/linux/mtd/
 F: include/uapi/mtd/
 
+MEN A21 WATCHDOG DRIVER
+M: Johannes Thumshirn 
+L: linux-watch...@vger.kernel.org
+S: Supported
+F: drivers/watchdog/mena21_wdt.c
+
 METAG ARCHITECTURE
 M: James Hogan 
 S: Supported
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index e89fc31..192b84d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -1172,6 +1172,14 @@ config BOOKE_WDT_DEFAULT_TIMEOUT
 
  The value can be overridden by the wdt_period command-line parameter.
 
+config MEN_A21_WDT
+   tristate "MEN A21 VME CPU Carrier Board Watchdog Timer"
+   select WATCHDOG_CORE
+   help
+Watchdog driver for MEN A21 VMEbus CPU Carrier Boards.
+
+   If unsure select N here.
+
 # PPC64 Architecture
 
 config WATCHDOG_RTAS
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index a300b94..bffdcb1 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -143,6 +143,7 @@ obj-$(CONFIG_8xxx_WDT) += mpc8xxx_wdt.o
 obj-$(CONFIG_MV64X60_WDT) += mv64x60_wdt.o
 obj-$(CONFIG_PIKA_WDT) += pika_wdt.o
 obj-$(CONFIG_BOOKE_WDT) += booke_wdt.o
+obj-$(CONFIG_MEN_A21_WDT) += mena21_wdt.o
 
 # PPC64 Architecture
 obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o
diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c
new file mode 100644
index 000..4fe65ec
--- /dev/null
+++ b/drivers/watchdog/mena21_wdt.c
@@ -0,0 +1,204 @@
+/*
+ * Watchdog driver for the A21 VME CPU Boards
+ *
+ * Copyright (C) 2013 MEN Mikro Elektronik Nuernberg GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define GPIO_WD_ENAB   169
+#define GPIO_WD_FAST   170
+#define GPIO_WD_TRIG   171
+
+#define GPIO_RST_CAUSE_BASE 166
+
+struct a21_wdt_drv {
+   struct watchdog_device wdt;
+   struct mutex lock;
+};
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+   __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static int a21_wdt_start(struct watchdog_device *wdt)
+{
+   struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
+
+   mutex_lock(&drv->lock);
+
+   gpio_set_value(GPIO_WD_ENAB, 1);
+
+   mutex_unlock(&drv->lock);
+
+   return 0;
+}
+
+static int a21_wdt_stop(struct watchdog_device *wdt)
+{
+   struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
+
+   /* We don't stop if WDOG_NO_WAY_OUT is set */
+   if (test_bit(WDOG_NO_WAY_OUT, &wdt->status))
+   return -EINVAL;
+
+   mutex_lock(&drv->lock);
+
+   gpio_set_value(GPIO_WD_ENAB, 0);
+
+   mutex_unlock(&drv->lock);
+
+   return 0;
+}
+
+static int a21_wdt_ping(struct watchdog_device *wdt)
+{
+   struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
+
+   mutex_lock(&drv->lock);
+
+   gpio_set_value(GPIO_WD_TRIG, 0);
+   ndelay(10);
+   gpio_set_value(GPIO_WD_TRIG, 1);
+
+   mutex_unlock(&drv->lock);
+
+   return 0;
+}
+
+static int a21_wdt_set_timeout(struct watchdog_device *wdt,
+  unsigned int timeout)
+{
+   struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
+
+   if (timeout != 1 && timeout != 30) {
+   dev_err(wdt->dev, "Only 1 and 30 allowed as timeout\n");
+   return -EINVAL;
+   }
+
+   if (timeout == 30 && wdt->timeout == 1) {
+   dev_err(wdt->dev,
+   "Transition from fast to s