[PATCH 6/8] [WATCHDOG] mpc8xxx_wdt: add support for MPC8xx watchdogs

2008-06-02 Thread Anton Vorontsov
The mpc8xxx_wdt driver is using two registers: SWSRR to push magic
numbers, and SWCRR to control the watchdog. Both registers are available
on the MPC8xx, and seem to have the same offsets and semantics as in
MPC83xx/MPC86xx watchdogs. The only difference is prescale value. So this
driver simply works on the MPC8xx CPUs.

One quirk is needed for the MPC8xx, though. It has small prescale value
and slow CPU, so the watchdog resets board prior to the driver has time
to load. To solve this we should split initialization in two steps: start
ping the watchdog early, and register the watchdog userspace interface
later.

MPC823 seem to be the first CPU in MPC8xx line, so we use fsl,mpc823-wdt
compatible matching.

Signed-off-by: Anton Vorontsov [EMAIL PROTECTED]
Tested-by: Jochen Friedrich [EMAIL PROTECTED]
---
 drivers/watchdog/Kconfig   |3 +-
 drivers/watchdog/mpc8xxx_wdt.c |   44 ++--
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 008eaa6..f9e617b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -684,10 +684,11 @@ config 8xx_WDT
 
 config 8xxx_WDT
tristate MPC8xxx Platform Watchdog Timer
-   depends on PPC_83xx || PPC_86xx
+   depends on PPC_8xx || PPC_83xx || PPC_86xx
help
  This driver is for a SoC level watchdog that exists on some
  Freescale PowerPC processors. So far this driver supports:
+ - MPC8xx watchdogs
  - MPC83xx watchdogs
  - MPC86xx watchdogs
 
diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 2f0681f..0f7e165 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -1,5 +1,5 @@
 /*
- * mpc8xxx_wdt.c - MPC83xx/MPC86xx watchdog userspace interface
+ * mpc8xxx_wdt.c - MPC8xx/MPC83xx/MPC86xx watchdog userspace interface
  *
  * Authors: Dave Updegraff [EMAIL PROTECTED]
  * Kumar Gala [EMAIL PROTECTED]
@@ -207,13 +207,6 @@ static int __devinit mpc8xxx_wdt_probe(struct of_device 
*ofdev,
goto err_unmap;
}
 
-   ret = misc_register(mpc8xxx_wdt_miscdev);
-   if (ret) {
-   pr_err(cannot register miscdev on minor=%d (err=%d)\n,
-   WATCHDOG_MINOR, ret);
-   goto err_unmap;
-   }
-
/* Calculate the timeout in seconds */
if (prescale)
timeout_sec = (timeout * wdt_type-prescaler) / freq;
@@ -234,6 +227,7 @@ static int __devinit mpc8xxx_wdt_probe(struct of_device 
*ofdev,
return 0;
 err_unmap:
iounmap(wd_base);
+   wd_base = NULL;
return ret;
 }
 
@@ -261,6 +255,12 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
.hw_enabled = true,
},
},
+   {
+   .compatible = fsl,mpc823-wdt,
+   .data = (struct mpc8xxx_wdt_type) {
+   .prescaler = 0x800,
+   },
+   },
{},
 };
 MODULE_DEVICE_TABLE(of, mpc8xxx_wdt_match);
@@ -275,20 +275,42 @@ static struct of_platform_driver mpc8xxx_wdt_driver = {
},
 };
 
+/*
+ * We do wdt initialization in two steps: arch_initcall probes the wdt
+ * very early to start pinging the watchdog (misc devices are not yet
+ * available), and later module_init() just registers the misc device.
+ */
+static int __init mpc8xxx_wdt_init_late(void)
+{
+   int ret;
+
+   if (!wd_base)
+   return -ENODEV;
+
+   ret = misc_register(mpc8xxx_wdt_miscdev);
+   if (ret) {
+   pr_err(cannot register miscdev on minor=%d (err=%d)\n,
+   WATCHDOG_MINOR, ret);
+   return ret;
+   }
+   return 0;
+}
+module_init(mpc8xxx_wdt_init_late);
+
 static int __init mpc8xxx_wdt_init(void)
 {
return of_register_platform_driver(mpc8xxx_wdt_driver);
 }
+arch_initcall(mpc8xxx_wdt_init);
 
 static void __exit mpc8xxx_wdt_exit(void)
 {
of_unregister_platform_driver(mpc8xxx_wdt_driver);
 }
-
-subsys_initcall(mpc8xxx_wdt_init);
 module_exit(mpc8xxx_wdt_exit);
 
 MODULE_AUTHOR(Dave Updegraff, Kumar Gala);
-MODULE_DESCRIPTION(Driver for watchdog timer in MPC83xx/MPC86xx uProcessors);
+MODULE_DESCRIPTION(Driver for watchdog timer in MPC8xx/MPC83xx/MPC86xx 
+  uProcessors);
 MODULE_LICENSE(GPL);
 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-- 
1.5.5.1

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH 6/8] [WATCHDOG] mpc8xxx_wdt: add support for MPC8xx watchdogs

2008-05-19 Thread Anton Vorontsov
The mpc8xxx_wdt driver is using two registers: SWSRR to push magic
numbers, and SWCRR to control the watchdog. Both registers are available
on the MPC8xx, and seem to have the same offsets and semantics as in
MPC83xx/MPC86xx watchdogs. The only difference is prescale value. So this
driver simply works on the MPC8xx CPUs.

One quirk is needed for the MPC8xx, though. It has small prescale value
and slow CPU, so the watchdog resets board prior to the driver has time
to load. To solve this we should split initialization in two steps: start
ping the watchdog early, and register the watchdog userspace interface
later.

MPC823 seem to be the first CPU in MPC8xx line, so we use fsl,mpc823-wdt
compatible matching.

Signed-off-by: Anton Vorontsov [EMAIL PROTECTED]
Tested-by: Jochen Friedrich [EMAIL PROTECTED]
---
 drivers/watchdog/Kconfig   |3 +-
 drivers/watchdog/mpc8xxx_wdt.c |   44 ++--
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 008eaa6..f9e617b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -684,10 +684,11 @@ config 8xx_WDT
 
 config 8xxx_WDT
tristate MPC8xxx Platform Watchdog Timer
-   depends on PPC_83xx || PPC_86xx
+   depends on PPC_8xx || PPC_83xx || PPC_86xx
help
  This driver is for a SoC level watchdog that exists on some
  Freescale PowerPC processors. So far this driver supports:
+ - MPC8xx watchdogs
  - MPC83xx watchdogs
  - MPC86xx watchdogs
 
diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 2f0681f..0f7e165 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -1,5 +1,5 @@
 /*
- * mpc8xxx_wdt.c - MPC83xx/MPC86xx watchdog userspace interface
+ * mpc8xxx_wdt.c - MPC8xx/MPC83xx/MPC86xx watchdog userspace interface
  *
  * Authors: Dave Updegraff [EMAIL PROTECTED]
  * Kumar Gala [EMAIL PROTECTED]
@@ -207,13 +207,6 @@ static int __devinit mpc8xxx_wdt_probe(struct of_device 
*ofdev,
goto err_unmap;
}
 
-   ret = misc_register(mpc8xxx_wdt_miscdev);
-   if (ret) {
-   pr_err(cannot register miscdev on minor=%d (err=%d)\n,
-   WATCHDOG_MINOR, ret);
-   goto err_unmap;
-   }
-
/* Calculate the timeout in seconds */
if (prescale)
timeout_sec = (timeout * wdt_type-prescaler) / freq;
@@ -234,6 +227,7 @@ static int __devinit mpc8xxx_wdt_probe(struct of_device 
*ofdev,
return 0;
 err_unmap:
iounmap(wd_base);
+   wd_base = NULL;
return ret;
 }
 
@@ -261,6 +255,12 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
.hw_enabled = true,
},
},
+   {
+   .compatible = fsl,mpc823-wdt,
+   .data = (struct mpc8xxx_wdt_type) {
+   .prescaler = 0x800,
+   },
+   },
{},
 };
 MODULE_DEVICE_TABLE(of, mpc8xxx_wdt_match);
@@ -275,20 +275,42 @@ static struct of_platform_driver mpc8xxx_wdt_driver = {
},
 };
 
+/*
+ * We do wdt initialization in two steps: arch_initcall probes the wdt
+ * very early to start pinging the watchdog (misc devices are not yet
+ * available), and later module_init() just registers the misc device.
+ */
+static int __init mpc8xxx_wdt_init_late(void)
+{
+   int ret;
+
+   if (!wd_base)
+   return -ENODEV;
+
+   ret = misc_register(mpc8xxx_wdt_miscdev);
+   if (ret) {
+   pr_err(cannot register miscdev on minor=%d (err=%d)\n,
+   WATCHDOG_MINOR, ret);
+   return ret;
+   }
+   return 0;
+}
+module_init(mpc8xxx_wdt_init_late);
+
 static int __init mpc8xxx_wdt_init(void)
 {
return of_register_platform_driver(mpc8xxx_wdt_driver);
 }
+arch_initcall(mpc8xxx_wdt_init);
 
 static void __exit mpc8xxx_wdt_exit(void)
 {
of_unregister_platform_driver(mpc8xxx_wdt_driver);
 }
-
-subsys_initcall(mpc8xxx_wdt_init);
 module_exit(mpc8xxx_wdt_exit);
 
 MODULE_AUTHOR(Dave Updegraff, Kumar Gala);
-MODULE_DESCRIPTION(Driver for watchdog timer in MPC83xx/MPC86xx uProcessors);
+MODULE_DESCRIPTION(Driver for watchdog timer in MPC8xx/MPC83xx/MPC86xx 
+  uProcessors);
 MODULE_LICENSE(GPL);
 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-- 
1.5.5.1

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH 6/8] [WATCHDOG] mpc8xxx_wdt: add support for MPC8xx watchdogs

2008-05-16 Thread Jochen Friedrich
Hi Anton,

 The mpc8xxx_wdt driver is using two registers: SWSRR to push magic
 numbers, and SWCRR to control the watchdog. Both registers are available
 on the MPC8xx, and seem to have the same offsets and semantics as in
 MPC83xx/MPC86xx watchdogs. The only difference is prescale value. So this
 driver should simply work on the MPC8xx CPUs.
 
 MPC823 seem to be the first CPU in MPC8xx line, so we use fsl,mpc823-wdt
 compatible matching.
 
 Though, this patch was only build-tested and okay to drop from this
 series until tested or corrected to work on the actual hardware.
 
 Signed-off-by: Anton Vorontsov [EMAIL PROTECTED]

Tested-by: Jochen Friedrich [EMAIL PROTECTED]

The driver works OK on MPC823.

One nit however ist the late initialisation of the wdt timer. I had to add
two hardcoded wdt resets in the board setup, one in setup_arch and one in
arch_initcall, to prevent a reset until mpc8xxx_wdt kicks in. However, IMHO
this is acceptable as it only hits the 8xx series with the small prescale.

Some time ago in 
http://patchwork.ozlabs.org/linuxppc/patch?person=1023id=16189,
i tried a different aproach to the problem (mainly a port of the old ARC=ppc
stuff), but the code became very ugly and the wdt maintainers didn't like it
very much.

So the only thing left for full 8xx support is a refactoring / cleanup of
http://patchwork.ozlabs.org/linuxppc/patch?person=1023id=16262.

Thanks,
Jochen
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH 6/8] [WATCHDOG] mpc8xxx_wdt: add support for MPC8xx watchdogs

2008-05-16 Thread Anton Vorontsov
On Fri, May 16, 2008 at 11:17:29AM +0200, Jochen Friedrich wrote:
 Hi Anton,
 
  The mpc8xxx_wdt driver is using two registers: SWSRR to push magic
  numbers, and SWCRR to control the watchdog. Both registers are available
  on the MPC8xx, and seem to have the same offsets and semantics as in
  MPC83xx/MPC86xx watchdogs. The only difference is prescale value. So this
  driver should simply work on the MPC8xx CPUs.
  
  MPC823 seem to be the first CPU in MPC8xx line, so we use fsl,mpc823-wdt
  compatible matching.
  
  Though, this patch was only build-tested and okay to drop from this
  series until tested or corrected to work on the actual hardware.
  
  Signed-off-by: Anton Vorontsov [EMAIL PROTECTED]
 
 Tested-by: Jochen Friedrich [EMAIL PROTECTED]

Thanks!

 The driver works OK on MPC823.
 
 One nit however ist the late initialisation of the wdt timer. I had to add
 two hardcoded wdt resets in the board setup, one in setup_arch and one in
 arch_initcall, to prevent a reset until mpc8xxx_wdt kicks in. However, IMHO
 this is acceptable as it only hits the 8xx series with the small prescale.

Hm... This is strange because subsys initcalls should be called quite
early... what type of initcall you're using in the board file to probe the
OF bus? I guess this was machine_device_initcall, can you try the
machine_subsys_initcall(), i.e. the same as we use in the driver?

If this still doesn't not work... You can try the patch attached here,
and try using machine_arch_initcall to do of_platform_bus_probe().
This way wdt should be called even earlier...

Also, if u-boot enables the watchdog, it should support the keepalive
too, because it might spend precious time not pinging the wdt...

diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index c7e28f0..0f7e165 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -207,13 +207,6 @@ static int __devinit mpc8xxx_wdt_probe(struct of_device 
*ofdev,
goto err_unmap;
}
 
-   ret = misc_register(mpc8xxx_wdt_miscdev);
-   if (ret) {
-   pr_err(cannot register miscdev on minor=%d (err=%d)\n,
-   WATCHDOG_MINOR, ret);
-   goto err_unmap;
-   }
-
/* Calculate the timeout in seconds */
if (prescale)
timeout_sec = (timeout * wdt_type-prescaler) / freq;
@@ -234,6 +227,7 @@ static int __devinit mpc8xxx_wdt_probe(struct of_device 
*ofdev,
return 0;
 err_unmap:
iounmap(wd_base);
+   wd_base = NULL;
return ret;
 }
 
@@ -281,17 +275,38 @@ static struct of_platform_driver mpc8xxx_wdt_driver = {
},
 };
 
+/*
+ * We do wdt initialization in two steps: arch_initcall probes the wdt
+ * very early to start pinging the watchdog (misc devices are not yet
+ * available), and later module_init() just registers the misc device.
+ */
+static int __init mpc8xxx_wdt_init_late(void)
+{
+   int ret;
+
+   if (!wd_base)
+   return -ENODEV;
+
+   ret = misc_register(mpc8xxx_wdt_miscdev);
+   if (ret) {
+   pr_err(cannot register miscdev on minor=%d (err=%d)\n,
+   WATCHDOG_MINOR, ret);
+   return ret;
+   }
+   return 0;
+}
+module_init(mpc8xxx_wdt_init_late);
+
 static int __init mpc8xxx_wdt_init(void)
 {
return of_register_platform_driver(mpc8xxx_wdt_driver);
 }
+arch_initcall(mpc8xxx_wdt_init);
 
 static void __exit mpc8xxx_wdt_exit(void)
 {
of_unregister_platform_driver(mpc8xxx_wdt_driver);
 }
-
-subsys_initcall(mpc8xxx_wdt_init);
 module_exit(mpc8xxx_wdt_exit);
 
 MODULE_AUTHOR(Dave Updegraff, Kumar Gala);
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH 6/8] [WATCHDOG] mpc8xxx_wdt: add support for MPC8xx watchdogs

2008-05-15 Thread Anton Vorontsov
The mpc8xxx_wdt driver is using two registers: SWSRR to push magic
numbers, and SWCRR to control the watchdog. Both registers are available
on the MPC8xx, and seem to have the same offsets and semantics as in
MPC83xx/MPC86xx watchdogs. The only difference is prescale value. So this
driver should simply work on the MPC8xx CPUs.

MPC823 seem to be the first CPU in MPC8xx line, so we use fsl,mpc823-wdt
compatible matching.

Though, this patch was only build-tested and okay to drop from this
series until tested or corrected to work on the actual hardware.

Signed-off-by: Anton Vorontsov [EMAIL PROTECTED]
---
 drivers/watchdog/Kconfig   |3 ++-
 drivers/watchdog/mpc8xxx_wdt.c |   11 +--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 008eaa6..f9e617b 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -684,10 +684,11 @@ config 8xx_WDT
 
 config 8xxx_WDT
tristate MPC8xxx Platform Watchdog Timer
-   depends on PPC_83xx || PPC_86xx
+   depends on PPC_8xx || PPC_83xx || PPC_86xx
help
  This driver is for a SoC level watchdog that exists on some
  Freescale PowerPC processors. So far this driver supports:
+ - MPC8xx watchdogs
  - MPC83xx watchdogs
  - MPC86xx watchdogs
 
diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 2f0681f..c7e28f0 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -1,5 +1,5 @@
 /*
- * mpc8xxx_wdt.c - MPC83xx/MPC86xx watchdog userspace interface
+ * mpc8xxx_wdt.c - MPC8xx/MPC83xx/MPC86xx watchdog userspace interface
  *
  * Authors: Dave Updegraff [EMAIL PROTECTED]
  * Kumar Gala [EMAIL PROTECTED]
@@ -261,6 +261,12 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
.hw_enabled = true,
},
},
+   {
+   .compatible = fsl,mpc823-wdt,
+   .data = (struct mpc8xxx_wdt_type) {
+   .prescaler = 0x800,
+   },
+   },
{},
 };
 MODULE_DEVICE_TABLE(of, mpc8xxx_wdt_match);
@@ -289,6 +295,7 @@ subsys_initcall(mpc8xxx_wdt_init);
 module_exit(mpc8xxx_wdt_exit);
 
 MODULE_AUTHOR(Dave Updegraff, Kumar Gala);
-MODULE_DESCRIPTION(Driver for watchdog timer in MPC83xx/MPC86xx uProcessors);
+MODULE_DESCRIPTION(Driver for watchdog timer in MPC8xx/MPC83xx/MPC86xx 
+  uProcessors);
 MODULE_LICENSE(GPL);
 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
-- 
1.5.5.1

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev