Skip to contentSkip to conversation

watchdog: add support for Sigma Designs SMP86xx

PATCH RESEND Superseded Mans Rullgard 2 participants 7 messages Nov 13, 2015 Watchdog device drivers

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 watchdog: add support for Sigma Designs SMP86xx

This adds support for the Sigma Designs SMP86xx family built-in watchdog.

---
 drivers/watchdog/Kconfig      |   7 ++
 drivers/watchdog/Makefile     |   1 +
 drivers/watchdog/tangox_wdt.c | 185 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 drivers/watchdog/tangox_wdt.c
drivers/watchdog/Kconfig +7 -0
index 79e1aa1..0ed5ee8 100644
@@ -1337,6 +1337,13 @@ config RALINK_WDT
 	help
 	  Hardware driver for the Ralink SoC Watchdog Timer.
 
+config TANGOX_WDT
+	tristate "SMP86xx watchdog"
+	select WATCHDOG_CORE
+	depends on ARCH_TANGOX
+	help
+	  Watchdog driver for Sigma Designs SMP86xx.
+
 # PARISC Architecture
 
 # POWERPC Architecture
drivers/watchdog/Makefile +1 -0
index 0c616e3..ed00796 100644
@@ -148,6 +148,7 @@ octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
 obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
 obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
 obj-$(CONFIG_IMGPDC_WDT) += imgpdc_wdt.o
+obj-$(CONFIG_TANGOX_WDT) += tangox_wdt.o
 
 # PARISC Architecture
 
drivers/watchdog/tangox_wdt.c new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.6.3
maintainer
#1 lore raw
Quoted 8 lines · Mans Rullgard

This adds support for the Sigma Designs SMP86xx family built-in watchdog.

---
  drivers/watchdog/Kconfig      |   7 ++
  drivers/watchdog/Makefile     |   1 +
  drivers/watchdog/tangox_wdt.c | 185 ++++++++++++++++++++++++++++++++++++++++++

Why tangox_wdt instead of smp86xx_wdt.c ?

tangox also implies that this would (should) work for SMP87xx as well, about which no statement is made. So why not tango3_wdt ?

[ ok, I see all drivers are named tangox, so if the other maintainers
are ok with that, so am I. ]

Is it known if the driver will work for any of the other chips of the series (SMP86XX/SMP87XX) ?

I think it would be helpful to describe in more detail which chips are supported, or at least which chips should work but are untested.

Quoted 8 lines
  3 files changed, 193 insertions(+)

create mode 100644 drivers/watchdog/tangox_wdt.c

drivers/watchdog/Kconfig +0 -0
index 79e1aa1..0ed5ee8 100644

drivers/watchdog/Kconfig config RALINK_WDT · line 1345

Quoted 9 lines
drivers/watchdog/Kconfig +6 -0
@@ -1337,6 +1337,13 @@ config RALINK_WDT
  	help
  	  Hardware driver for the Ralink SoC Watchdog Timer.
 
+config TANGOX_WDT
+	tristate "SMP86xx watchdog"
+	select WATCHDOG_CORE
+	depends on ARCH_TANGOX
+	help
+	  Watchdog driver for Sigma Designs SMP86xx.

Not really; it is for SMP8642, and we don't know if other (later ?) chips will be supported by the same driver. You should be explicit here. More chips can be added later (that would be needed for the devicetree bindings anyway) as they are tested.

Quoted 32 lines
drivers/watchdog/Kconfig +1 -0
+
  # PARISC Architecture
 
  # POWERPC Architecture
drivers/watchdog/Makefile +1 -0
index 0c616e3..ed00796 100644
@@ -148,6 +148,7 @@ octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
  obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
  obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
  obj-$(CONFIG_IMGPDC_WDT) += imgpdc_wdt.o
+obj-$(CONFIG_TANGOX_WDT) += tangox_wdt.o
 
  # PARISC Architecture
 
drivers/watchdog/tangox_wdt.c new file +10 -0
new file mode 100644
index 0000000..305759f
@@ -0,0 +1,185 @@
+/*
+ *  Copyright (C) 2014, Mans Rullgard <[email protected]>
+ *  SMP86xx Watchdog driver
+ *
+ *  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;  either version 2 of the License, or (at your
+ *  option) any later version.
+ */
+

drivers/watchdog/tangox_wdt.c line 20

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/notifier.h>
+#include <linux/delay.h>
+#include <linux/reboot.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+#include <linux/clk.h>
+#include <linux/io.h>

Please list include files in alphabetic order.

drivers/watchdog/tangox_wdt.c line 24

Quoted 4 lines
drivers/watchdog/tangox_wdt.c new file +4 -0
+
+#define DEFAULT_TIMEOUT	30
+#define MAX_TIMEOUT	120
+

This looks like an arbitrary value. You should calculate the real maximum by dividing the maximum register value by the clock rate.

Quoted 27 lines
drivers/watchdog/tangox_wdt.c new file +27 -0
+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 unsigned int timeout = DEFAULT_TIMEOUT;
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(watchdog_timeout, "Watchdog timeout");
+
+#define WD_COUNTER	0
+#define WD_CONFIG	4
+
+struct tangox_wdt_device {
+	struct watchdog_device wdt;
+	void __iomem *base;
+	unsigned int timeout;
+	struct clk *clk;
+	struct notifier_block restart;
+};
+
+static int tangox_wdt_ping(struct watchdog_device *wdt)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	writel(dev->timeout, dev->base + WD_COUNTER);
+

drivers/watchdog/tangox_wdt.c line 61

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+	return 0;
+}
+
+static int tangox_wdt_set_timeout(struct watchdog_device *wdt,
+				  unsigned int new_timeout)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	wdt->timeout = new_timeout;
+	dev->timeout = 1 + new_timeout * clk_get_rate(dev->clk);

Why "1 +" ?

drivers/watchdog/tangox_wdt.c line 64

Quoted 3 lines
drivers/watchdog/tangox_wdt.c new file +3 -0
+
+	tangox_wdt_ping(wdt);
+

The infrastructure does that already.

drivers/watchdog/tangox_wdt.c line 70

Quoted 6 lines
drivers/watchdog/tangox_wdt.c new file +6 -0
+	return 0;
+}
+
+static int tangox_wdt_start(struct watchdog_device *wdt)
+{
+	return tangox_wdt_set_timeout(wdt, wdt->timeout);

This is an odd way of setting dev->timeout.
You should set it in the probe function instead.
Unless I am missing something, the ping and start functions will then be the same and you'll only need one of them.

Quoted 21 lines
drivers/watchdog/tangox_wdt.c new file +21 -0
+}
+
+static int tangox_wdt_stop(struct watchdog_device *wdt)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	writel(0, dev->base + WD_COUNTER);
+
+	return 0;
+}
+
+static const struct watchdog_info tangox_wdt_info = {
+	.options  = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "tangox watchdog",
+};
+
+static const struct watchdog_ops tangox_wdt_ops = {
+	.start		= tangox_wdt_start,
+	.stop		= tangox_wdt_stop,
+	.ping		= tangox_wdt_ping,
+	.set_timeout	= tangox_wdt_set_timeout,

drivers/watchdog/tangox_wdt.c line 101

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+};
+
+static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action,
+			      void *data)
+{
+	struct tangox_wdt_device *dev =
+		container_of(nb, struct tangox_wdt_device, restart);
+
+	writel(1, dev->base + WD_COUNTER);
+

A comment might be useful here, explaining what this does (reset after minimum timeout ?). Also, the code should wait a bit to ensure that the reset 'catches'
before the function returns.

Quoted 7 lines
drivers/watchdog/tangox_wdt.c new file +7 -0
+	return NOTIFY_DONE;
+}
+
+static int tangox_wdt_probe(struct platform_device *pdev)
+{
+	struct tangox_wdt_device *dev;
+	struct resource *res;

drivers/watchdog/tangox_wdt.c line 118

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+	int err;
+
+	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	dev->wdt.parent = &pdev->dev;
+	dev->wdt.info = &tangox_wdt_info;
+	dev->wdt.ops = &tangox_wdt_ops;
+	dev->wdt.timeout = timeout;

It might make more sense to use watchdog_init_timeout(), especially since the driver supports devicetree and the timeout can be set in devicetree data.

drivers/watchdog/tangox_wdt.c line 126

Quoted 8 lines
drivers/watchdog/tangox_wdt.c new file +8 -0
+	dev->wdt.min_timeout = 1;
+	dev->wdt.max_timeout = MAX_TIMEOUT;
+	watchdog_set_nowayout(&dev->wdt, nowayout);
+	watchdog_set_drvdata(&dev->wdt, dev);
+
+	dev->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(dev->clk))
+		return PTR_ERR(dev->clk);

Normally one calls clk_prepare_enable() after clk_get() (and clk_disable_unprepare when exiting).

Also, it might make sense to read the clock rate once and store it in a variable.

drivers/watchdog/tangox_wdt.c line 136

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
+	dev->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(dev->base))
+		return PTR_ERR(dev->base);
+
+	writel(0, dev->base + WD_COUNTER);

This always stops the watchdog even if already running. Is this on purpose ?

drivers/watchdog/tangox_wdt.c line 137

Quoted 1 line
drivers/watchdog/tangox_wdt.c new file +1 -0
+	writel(1, dev->base + WD_CONFIG);

A define or a comment might help here to explain what this write does.

drivers/watchdog/tangox_wdt.c line 149

Quoted 12 lines
drivers/watchdog/tangox_wdt.c new file +12 -0
+
+	err = watchdog_register_device(&dev->wdt);
+	if (err)
+		return err;
+
+	platform_set_drvdata(pdev, dev);
+
+	dev->restart.notifier_call = tangox_wdt_restart;
+	dev->restart.priority = 128;
+	err = register_restart_handler(&dev->restart);
+	if (err)
+		dev_err(&pdev->dev, "failed to register restart handler\n");

dev_warn

Quoted 9 lines
drivers/watchdog/tangox_wdt.c new file +9 -0
+
+	dev_info(dev->wdt.dev, "SMP86xx watchdog registered\n");
+
+	return 0;
+}
+
+static int tangox_wdt_remove(struct platform_device *pdev)
+{
+	struct tangox_wdt_device *dev = platform_get_drvdata(pdev);

drivers/watchdog/tangox_wdt.c line 168

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+
+	tangox_wdt_stop(&dev->wdt);
+	unregister_restart_handler(&dev->restart);
+	watchdog_unregister_device(&dev->wdt);
+
+	return 0;
+}
+
+static const struct of_device_id tangox_wdt_dt_ids[] = {
+	{ .compatible = "sigma,smp8642-wdt" },

So this is really for smp8642 only, not for any other chips in the series ?

drivers/watchdog/tangox_wdt.c line 169

Quoted 1 line
drivers/watchdog/tangox_wdt.c new file +1 -0
+	{ }

Do you have a devicetree bindings file ? You should have, and it should describe all necessary and optional bindings including clocks.

Quoted 7 lines
drivers/watchdog/tangox_wdt.c new file +6 -0
+};
+
+static struct platform_driver tangox_wdt_driver = {
+	.probe	= tangox_wdt_probe,
+	.remove	= tangox_wdt_remove,
+	.driver	= {

drivers/watchdog/tangox_wdt.c line 185

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+		.name		= "tangox-wdt",
+		.of_match_table	= tangox_wdt_dt_ids,
+	},
+};
+
+module_platform_driver(tangox_wdt_driver);
+
+MODULE_AUTHOR("Mans Rullgard <[email protected]>");
+MODULE_DESCRIPTION("SMP86xx Watchdog driver");
+MODULE_LICENSE("GPL");

MODULE_ALIAS ?

#2 lore raw
Quoted 12 lines · Guenter Roeck
Quoted 8 lines · Mans Rullgard

This adds support for the Sigma Designs SMP86xx family built-in watchdog.

---
  drivers/watchdog/Kconfig      |   7 ++
  drivers/watchdog/Makefile     |   1 +
  drivers/watchdog/tangox_wdt.c | 185 ++++++++++++++++++++++++++++++++++++++++++

Why tangox_wdt instead of smp86xx_wdt.c ?

Quoted 8 lines

tangox also implies that this would (should) work for SMP87xx as well, about which no statement is made. So why not tango3_wdt ?

[ ok, I see all drivers are named tangox, so if the other maintainers
are ok with that, so am I. ]

Is it known if the driver will work for any of the other chips of the series (SMP86XX/SMP87XX) ?

It does work on SMP87xx (tango4) as well. I wrote the driver before I had any such hardware, then forgot to update the help text and commit message.

Quoted 14 lines

I think it would be helpful to describe in more detail which chips are supported, or at least which chips should work but are untested.

Quoted 11 lines
  3 files changed, 193 insertions(+)

create mode 100644 drivers/watchdog/tangox_wdt.c

drivers/watchdog/Kconfig +0 -0
index 79e1aa1..0ed5ee8 100644
@@ -1337,6 +1337,13 @@ config RALINK_WDT
  	help
  	  Hardware driver for the Ralink SoC Watchdog Timer.
 
Quoted 11 lines

drivers/watchdog/Kconfig config RALINK_WDT · line 1345

Quoted 6 lines
drivers/watchdog/Kconfig +6 -0
+config TANGOX_WDT
+	tristate "SMP86xx watchdog"
+	select WATCHDOG_CORE
+	depends on ARCH_TANGOX
+	help
+	  Watchdog driver for Sigma Designs SMP86xx.

Not really; it is for SMP8642, and we don't know if other (later ?) chips will be supported by the same driver. You should be explicit here. More chips can be added later (that would be needed for the devicetree bindings anyway) as they are tested.

I have tested it on SMP8642 and SMP8759. The documentation for SMP8654 agrees.

Quoted 9 lines

drivers/watchdog/Kconfig config RALINK_WDT

Quoted 7 lines
drivers/watchdog/Kconfig +7 -0
+static int tangox_wdt_set_timeout(struct watchdog_device *wdt,
+				  unsigned int new_timeout)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	wdt->timeout = new_timeout;
+	dev->timeout = 1 + new_timeout * clk_get_rate(dev->clk);

Why "1 +" ?

The counter counts down from the loaded value and asserts the reset pin when it reaches 1. Setting it to zero disables the watchdog.

Quoted 4 lines
Quoted 4 lines
drivers/watchdog/Kconfig +4 -0
+static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action,
+			      void *data)
+{
+	struct tangox_wdt_device *dev =
Quoted 8 lines

drivers/watchdog/Kconfig

Quoted 4 lines
drivers/watchdog/Kconfig +4 -0
+		container_of(nb, struct tangox_wdt_device, restart);
+
+	writel(1, dev->base + WD_COUNTER);
+

A comment might be useful here, explaining what this does (reset after minimum timeout ?). Also, the code should wait a bit to ensure that the reset 'catches'
before the function returns.

Writing 1 to the counter asserts the reset immediately.

Quoted 4 lines

drivers/watchdog/Kconfig

Quoted 2 lines
drivers/watchdog/Kconfig +2 -0
+static const struct of_device_id tangox_wdt_dt_ids[] = {
+	{ .compatible = "sigma,smp8642-wdt" },

So this is really for smp8642 only, not for any other chips in the series ?

It's for about a dozen SMP86xx, SMP87xx, and SMP89xx chips. Should I list them all? I don't even know where to find a comprehensive list of device numbers.

Signature · 2 lines
Måns Rullgård
[email protected]
maintainer
#3 lore raw
Quoted 53 lines · Måns Rullgård
Quoted 12 lines · Guenter Roeck
Quoted 8 lines · Mans Rullgard

This adds support for the Sigma Designs SMP86xx family built-in watchdog.

---
   drivers/watchdog/Kconfig      |   7 ++
   drivers/watchdog/Makefile     |   1 +
   drivers/watchdog/tangox_wdt.c | 185 ++++++++++++++++++++++++++++++++++++++++++

Why tangox_wdt instead of smp86xx_wdt.c ?

Quoted 8 lines

tangox also implies that this would (should) work for SMP87xx as well, about which no statement is made. So why not tango3_wdt ?

[ ok, I see all drivers are named tangox, so if the other maintainers
are ok with that, so am I. ]

Is it known if the driver will work for any of the other chips of the series (SMP86XX/SMP87XX) ?

It does work on SMP87xx (tango4) as well. I wrote the driver before I had any such hardware, then forgot to update the help text and commit message.

Quoted 14 lines

I think it would be helpful to describe in more detail which chips are supported, or at least which chips should work but are untested.

Quoted 11 lines
   3 files changed, 193 insertions(+)

create mode 100644 drivers/watchdog/tangox_wdt.c

drivers/watchdog/Kconfig +0 -0
index 79e1aa1..0ed5ee8 100644
@@ -1337,6 +1337,13 @@ config RALINK_WDT
   	help
   	  Hardware driver for the Ralink SoC Watchdog Timer.
 
Quoted 11 lines

drivers/watchdog/Kconfig config RALINK_WDT · line 1345

Quoted 6 lines
drivers/watchdog/Kconfig +6 -0
+config TANGOX_WDT
+	tristate "SMP86xx watchdog"
+	select WATCHDOG_CORE
+	depends on ARCH_TANGOX
+	help
+	  Watchdog driver for Sigma Designs SMP86xx.

Not really; it is for SMP8642, and we don't know if other (later ?) chips will be supported by the same driver. You should be explicit here. More chips can be added later (that would be needed for the devicetree bindings anyway) as they are tested.

Quoted 3 lines

I have tested it on SMP8642 and SMP8759. The documentation for SMP8654 agrees.

We should have that information somewhere - maybe in the driver header. It is very useful to know which hardware this was tested with and which hardware is supposed to work.

Quoted 10 lines
Quoted 9 lines

drivers/watchdog/Kconfig config RALINK_WDT

Quoted 7 lines
drivers/watchdog/Kconfig +7 -0
+static int tangox_wdt_set_timeout(struct watchdog_device *wdt,
+				  unsigned int new_timeout)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	wdt->timeout = new_timeout;
+	dev->timeout = 1 + new_timeout * clk_get_rate(dev->clk);

Why "1 +" ?

Quoted 3 lines

The counter counts down from the loaded value and asserts the reset pin when it reaches 1. Setting it to zero disables the watchdog.

You might want to explain that somewhere. Maybe use a define, explain it there, and use the define here and below.

Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
drivers/watchdog/Kconfig +4 -0
+static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action,
+			      void *data)
+{
+	struct tangox_wdt_device *dev =
Quoted 8 lines

drivers/watchdog/Kconfig

Quoted 4 lines
drivers/watchdog/Kconfig +4 -0
+		container_of(nb, struct tangox_wdt_device, restart);
+
+	writel(1, dev->base + WD_COUNTER);
+

A comment might be useful here, explaining what this does (reset after minimum timeout ?). Also, the code should wait a bit to ensure that the reset 'catches'
before the function returns.

Writing 1 to the counter asserts the reset immediately.

Quoted 9 lines
Quoted 4 lines

drivers/watchdog/Kconfig

Quoted 2 lines
drivers/watchdog/Kconfig +2 -0
+static const struct of_device_id tangox_wdt_dt_ids[] = {
+	{ .compatible = "sigma,smp8642-wdt" },

So this is really for smp8642 only, not for any other chips in the series ?

It's for about a dozen SMP86xx, SMP87xx, and SMP89xx chips. Should I list them all? I don't even know where to find a comprehensive list of device numbers.

I thought so, but I am not a devicetree expert, and I see some "xx" in existing devicetree bindings. Something to ask when you submit the bindings to the devicetree mailing list. Either case, I think it would be either something like "sigma,smp86xx-wdt" or a list of all of them, but not "sigma,smp8642-wdt" to be used for all chips.

As for which chips to list, the easy answer would be to only list the IDs for chips known to work.

Thanks,
Guenter

#4 lore raw
Quoted 12 lines · Guenter Roeck
Quoted 12 lines
Quoted 11 lines

drivers/watchdog/Kconfig config RALINK_WDT · line 1345

Quoted 6 lines
drivers/watchdog/Kconfig +6 -0
+config TANGOX_WDT
+	tristate "SMP86xx watchdog"
+	select WATCHDOG_CORE
+	depends on ARCH_TANGOX
+	help
+	  Watchdog driver for Sigma Designs SMP86xx.

Not really; it is for SMP8642, and we don't know if other (later ?) chips will be supported by the same driver. You should be explicit here. More chips can be added later (that would be needed for the devicetree bindings anyway) as they are tested.

Quoted 7 lines
Quoted 3 lines

I have tested it on SMP8642 and SMP8759. The documentation for SMP8654 agrees.

We should have that information somewhere - maybe in the driver header. It is very useful to know which hardware this was tested with and which hardware is supposed to work.

OK, I'll add that info somewhere.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

drivers/watchdog/tangox_wdt.c line 61

Quoted 7 lines
drivers/watchdog/tangox_wdt.c new file +7 -0
+static int tangox_wdt_set_timeout(struct watchdog_device *wdt,
+				  unsigned int new_timeout)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	wdt->timeout = new_timeout;
+	dev->timeout = 1 + new_timeout * clk_get_rate(dev->clk);

Why "1 +" ?

Quoted 5 lines
Quoted 2 lines

The counter counts down from the loaded value and asserts the reset pin when it reaches 1. Setting it to zero disables the watchdog.

You might want to explain that somewhere. Maybe use a define, explain it there, and use the define here and below.

Will do.

Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

drivers/watchdog/tangox_wdt.c line 168

Quoted 2 lines
drivers/watchdog/tangox_wdt.c new file +2 -0
+static const struct of_device_id tangox_wdt_dt_ids[] = {
+	{ .compatible = "sigma,smp8642-wdt" },

So this is really for smp8642 only, not for any other chips in the series ?

It's for about a dozen SMP86xx, SMP87xx, and SMP89xx chips. Should I list them all? I don't even know where to find a comprehensive list of device numbers.

Quoted 5 lines

I thought so, but I am not a devicetree expert, and I see some "xx" in existing devicetree bindings. Something to ask when you submit the bindings to the devicetree mailing list. Either case, I think it would be either something like "sigma,smp86xx-wdt" or a list of all of them, but not "sigma,smp8642-wdt" to be used for all chips.

The general advice is to not use wildcards in DT bindings since the next chip matching the pattern might not be compatible at all. New chips known to be compatible with an old one can specify both the exact chip and the older one such that existing drivers will work automatically. If at some point they are found not to be compatible after all (hardware bugs, perhaps) a fixed driver will work with existing device trees.

Thanks for the review.

Signature · 2 lines
Måns Rullgård
[email protected]
maintainer
#5 lore raw
Quoted 15 lines · Måns Rullgård
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

drivers/watchdog/tangox_wdt.c line 168

Quoted 2 lines
drivers/watchdog/tangox_wdt.c new file +2 -0
+static const struct of_device_id tangox_wdt_dt_ids[] = {
+	{ .compatible = "sigma,smp8642-wdt" },

So this is really for smp8642 only, not for any other chips in the series ?

It's for about a dozen SMP86xx, SMP87xx, and SMP89xx chips. Should I list them all? I don't even know where to find a comprehensive list of device numbers.

Quoted 5 lines

I thought so, but I am not a devicetree expert, and I see some "xx" in existing devicetree bindings. Something to ask when you submit the bindings to the devicetree mailing list. Either case, I think it would be either something like "sigma,smp86xx-wdt" or a list of all of them, but not "sigma,smp8642-wdt" to be used for all chips.

Quoted 7 lines

The general advice is to not use wildcards in DT bindings since the next chip matching the pattern might not be compatible at all. New chips known to be compatible with an old one can specify both the exact chip and the older one such that existing drivers will work automatically. If at some point they are found not to be compatible after all (hardware bugs, perhaps) a fixed driver will work with existing device trees.

So I think the best approach here would be to list the chips known to work.

Thanks,
Guenter

--
To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#6 lore raw
In reply to Mans Rullgard
Quoted 16 lines · Mans Rullgard

This adds support for the Sigma Designs SMP86xx family built-in watchdog.

---
  drivers/watchdog/Kconfig      |   7 ++
  drivers/watchdog/Makefile     |   1 +
  drivers/watchdog/tangox_wdt.c | 185 ++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 193 insertions(+)

create mode 100644 drivers/watchdog/tangox_wdt.c

drivers/watchdog/Kconfig +0 -0
index 79e1aa1..0ed5ee8 100644

drivers/watchdog/Kconfig config RALINK_WDT · line 1343

Quoted 7 lines
drivers/watchdog/Kconfig +4 -0
@@ -1337,6 +1337,13 @@ config RALINK_WDT
  	help
  	  Hardware driver for the Ralink SoC Watchdog Timer.
 
+config TANGOX_WDT
+	tristate "SMP86xx watchdog"
+	select WATCHDOG_CORE
+	depends on ARCH_TANGOX

Please make this "depends on ARCH_TANGOX | COMPILE_TEST" so the driver can be compile-tested without ARCH_TANGOX.

One more comment below.

Thanks,
Guenter

Quoted 145 lines
drivers/watchdog/Kconfig +3 -0
+	help
+	  Watchdog driver for Sigma Designs SMP86xx.
+
  # PARISC Architecture
 
  # POWERPC Architecture
drivers/watchdog/Makefile +1 -0
index 0c616e3..ed00796 100644
@@ -148,6 +148,7 @@ octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
  obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
  obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
  obj-$(CONFIG_IMGPDC_WDT) += imgpdc_wdt.o
+obj-$(CONFIG_TANGOX_WDT) += tangox_wdt.o
 
  # PARISC Architecture
 
drivers/watchdog/tangox_wdt.c new file +121 -0
new file mode 100644
index 0000000..305759f
@@ -0,0 +1,185 @@
+/*
+ *  Copyright (C) 2014, Mans Rullgard <[email protected]>
+ *  SMP86xx Watchdog driver
+ *
+ *  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;  either version 2 of the License, or (at your
+ *  option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/notifier.h>
+#include <linux/delay.h>
+#include <linux/reboot.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#define DEFAULT_TIMEOUT	30
+#define MAX_TIMEOUT	120
+
+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 unsigned int timeout = DEFAULT_TIMEOUT;
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(watchdog_timeout, "Watchdog timeout");
+
+#define WD_COUNTER	0
+#define WD_CONFIG	4
+
+struct tangox_wdt_device {
+	struct watchdog_device wdt;
+	void __iomem *base;
+	unsigned int timeout;
+	struct clk *clk;
+	struct notifier_block restart;
+};
+
+static int tangox_wdt_ping(struct watchdog_device *wdt)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	writel(dev->timeout, dev->base + WD_COUNTER);
+
+	return 0;
+}
+
+static int tangox_wdt_set_timeout(struct watchdog_device *wdt,
+				  unsigned int new_timeout)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	wdt->timeout = new_timeout;
+	dev->timeout = 1 + new_timeout * clk_get_rate(dev->clk);
+
+	tangox_wdt_ping(wdt);
+
+	return 0;
+}
+
+static int tangox_wdt_start(struct watchdog_device *wdt)
+{
+	return tangox_wdt_set_timeout(wdt, wdt->timeout);
+}
+
+static int tangox_wdt_stop(struct watchdog_device *wdt)
+{
+	struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+	writel(0, dev->base + WD_COUNTER);
+
+	return 0;
+}
+
+static const struct watchdog_info tangox_wdt_info = {
+	.options  = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "tangox watchdog",
+};
+
+static const struct watchdog_ops tangox_wdt_ops = {
+	.start		= tangox_wdt_start,
+	.stop		= tangox_wdt_stop,
+	.ping		= tangox_wdt_ping,
+	.set_timeout	= tangox_wdt_set_timeout,
+};
+
+static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action,
+			      void *data)
+{
+	struct tangox_wdt_device *dev =
+		container_of(nb, struct tangox_wdt_device, restart);
+
+	writel(1, dev->base + WD_COUNTER);
+
+	return NOTIFY_DONE;
+}
+
+static int tangox_wdt_probe(struct platform_device *pdev)
+{
+	struct tangox_wdt_device *dev;
+	struct resource *res;
+	int err;
+
+	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	dev->wdt.parent = &pdev->dev;
+	dev->wdt.info = &tangox_wdt_info;
+	dev->wdt.ops = &tangox_wdt_ops;
+	dev->wdt.timeout = timeout;
+	dev->wdt.min_timeout = 1;
+	dev->wdt.max_timeout = MAX_TIMEOUT;
+	watchdog_set_nowayout(&dev->wdt, nowayout);

drivers/watchdog/tangox_wdt.c line 131

Quoted 10 lines
drivers/watchdog/tangox_wdt.c new file +10 -0
+	watchdog_set_drvdata(&dev->wdt, dev);
+
+	dev->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(dev->clk))
+		return PTR_ERR(dev->clk);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+

Unnecessary error check; devm_ioremap_resource() generates an error if res is NULL.

Quoted 55 lines
drivers/watchdog/tangox_wdt.c new file +54 -0
+	dev->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(dev->base))
+		return PTR_ERR(dev->base);
+
+	writel(0, dev->base + WD_COUNTER);
+	writel(1, dev->base + WD_CONFIG);
+
+	err = watchdog_register_device(&dev->wdt);
+	if (err)
+		return err;
+
+	platform_set_drvdata(pdev, dev);
+
+	dev->restart.notifier_call = tangox_wdt_restart;
+	dev->restart.priority = 128;
+	err = register_restart_handler(&dev->restart);
+	if (err)
+		dev_err(&pdev->dev, "failed to register restart handler\n");
+
+	dev_info(dev->wdt.dev, "SMP86xx watchdog registered\n");
+
+	return 0;
+}
+
+static int tangox_wdt_remove(struct platform_device *pdev)
+{
+	struct tangox_wdt_device *dev = platform_get_drvdata(pdev);
+
+	tangox_wdt_stop(&dev->wdt);
+	unregister_restart_handler(&dev->restart);
+	watchdog_unregister_device(&dev->wdt);
+
+	return 0;
+}
+
+static const struct of_device_id tangox_wdt_dt_ids[] = {
+	{ .compatible = "sigma,smp8642-wdt" },
+	{ }
+};
+
+static struct platform_driver tangox_wdt_driver = {
+	.probe	= tangox_wdt_probe,
+	.remove	= tangox_wdt_remove,
+	.driver	= {
+		.name		= "tangox-wdt",
+		.of_match_table	= tangox_wdt_dt_ids,
+	},
+};
+
+module_platform_driver(tangox_wdt_driver);
+
+MODULE_AUTHOR("Mans Rullgard <[email protected]>");
+MODULE_DESCRIPTION("SMP86xx Watchdog driver");
+MODULE_LICENSE("GPL");