Skip to contentSkip to conversation

GPIO-Watchdog in devicetree

RFC In review Wolfram Sang 4 participants 7 messages Sep 22, 2008 – Sep 26, 2008

lore
Share & tools
lore
#0 lore raw

RFC 1/1 GPIO-Watchdog in devicetree

Hello all,

I understood that the device-tree is for describing hardware and should not contain driver specific information. I have problems drawing this line right now. I made a driver for watchdogs which are pinged by toggling a gpio. Currently the device-tree entry looks like this:

	watchdog@gpio {
		compatible = "gpio-watchdog";
		gpios =	<&gpio_simple 19 0>;
	};

Then, there are two module parameters. One to define the initial state of the gpio (0 or 1), one to define the length of the pulse when serving the watchdog (default 1 us). Now my question is:

Is it plausible to say that the module parameters would also fit to the device-tree as properties? Recently, I tend to say so as otherwise the description of the watchdog is incomplete. Then again, one might argue to develop a specific watchdog driver instead of a generic one, and use something like compatible = "<myvendor>, <mywatchdog>" which would result in lots of duplicated code per watchdog. So, which way to go? I am really undecided and would be happy to hear opinions.

For completeness, I'll append the current version of my driver.

All the best,

Wolfram

===

From; Wolfram Sang <[email protected]> Subject; of-driver for external gpio-triggered watchdogs

Still needs tests and review before it can go mainline.

---
 drivers/watchdog/Kconfig       |    8 +
 drivers/watchdog/Makefile      |    1 
 drivers/watchdog/of_gpio_wdt.c |  188 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 197 insertions(+)
watchdog/Kconfig renamed from watchdog/Kconfig.orig +8 -0
Index: drivers/watchdog/Kconfig
===================================================================
@@ -55,6 +55,14 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called softdog.
 
+config OF_GPIO_WDT
+	tristate "OF GPIO watchdog"
+	help
+	  This driver handles external watchdogs which are triggered by a gpio.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called of_gpio_wdt.
+
 # ALPHA Architecture
 
 # ARM Architecture
watchdog/Makefile renamed from watchdog/Makefile.orig +1 -0
Index: drivers/watchdog/Makefile
===================================================================
@@ -124,4 +124,5 @@
 # XTENSA Architecture
 
 # Architecture Independant
+obj-$(CONFIG_OF_GPIO_WDT) += of_gpio_wdt.o
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
watchdog/of_gpio_wdt.c new file +188 -0

188 lines not on this page · raw message

Signature · 2 lines
  Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
#1 lore raw
Quoted 16 lines · Wolfram Sang

Hello all,

I understood that the device-tree is for describing hardware and should not contain driver specific information. I have problems drawing this line right now. I made a driver for watchdogs which are pinged by toggling a gpio. Currently the device-tree entry looks like this:

	watchdog@gpio {
		compatible = "gpio-watchdog";
		gpios =	<&gpio_simple 19 0>;
	};

Then, there are two module parameters. One to define the initial state of the gpio (0 or 1), one to define the length of the pulse when serving the watchdog (default 1 us). Now my question is:

Quoted 7 lines

Is it plausible to say that the module parameters would also fit to the device-tree as properties? Recently, I tend to say so as otherwise the description of the watchdog is incomplete. Then again, one might argue to develop a specific watchdog driver instead of a generic one, and use something like compatible = "<myvendor>, <mywatchdog>" which would result in lots of duplicated code per watchdog. So, which way to go? I am really undecided and would be happy to hear opinions.

Since this is *very* board specific and there are a lot of parameters that come into play that affect how the GPIO should be twiddled, I'd consider leaving it out of the device tree entirely and coding it in the platform code for your board (arch/powerpc/platforms/*/*). Or, if you still want to describe the gpio pin used the device tree, then add a property to the base of the device tree that only your board platform code looks at.

For example:

/ {
	model = "pengutronix,super-sexy-board";
	#address-cells = <1>;
	#size-cells = <1>;
	super-sexy-board,watchdog-gpio = <&gpio_simple 19 0>;
	...
}

Decoding a GPIO from the tree is quite simple so this should not result in great swaths of duplicated code.

g.

#2 lore raw
Quoted 8 lines · Grant Likely

For example:

/ {
	model = "pengutronix,super-sexy-board";
	#address-cells = <1>;
	#size-cells = <1>;
	super-sexy-board,watchdog-gpio = <&gpio_simple 19 0>;
	...
}

Why as a property of the root node, and not as a node with a very specific compatible property?

-Scott

#3 lore raw
Quoted 11 lines · Scott Wood
Quoted 8 lines · Grant Likely

For example:

/ {
      model = "pengutronix,super-sexy-board";
      #address-cells = <1>;
      #size-cells = <1>;
      super-sexy-board,watchdog-gpio = <&gpio_simple 19 0>;
      ...
}
Quoted 2 lines

Why as a property of the root node, and not as a node with a very specific compatible property?

Because the root node is the only logical board-level node we have right now. However, I'm not deeply committed to this approach. The only question I have about putting it in another node is choosing the parent node. I don't think it fits to make it a child of the SoC node or any other bus node.

g.

--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#4 lore raw
Quoted 10 lines · Grant Likely
Quoted 9 lines · Scott Wood
Quoted 8 lines · Grant Likely

For example:

/ {
      model = "pengutronix,super-sexy-board";
      #address-cells = <1>;
      #size-cells = <1>;
      super-sexy-board,watchdog-gpio = <&gpio_simple 19 0>;
      ...
}
Quoted 8 lines
Quoted 2 lines

Why as a property of the root node, and not as a node with a very specific compatible property?

Because the root node is the only logical board-level node we have right now. However, I'm not deeply committed to this approach. The only question I have about putting it in another node is choosing the parent node. I don't think it fits to make it a child of the SoC node or any other bus node.

A child of the gpio controller node seems most logical, though a child of the root node would be OK. It was the freefloating property that struck me as a little odd.

-Scott

#5 lore raw
Quoted 20 lines · Scott Wood
Quoted 10 lines · Grant Likely
Quoted 9 lines · Scott Wood
Quoted 8 lines · Grant Likely

For example:

/ {
      model = "pengutronix,super-sexy-board";
      #address-cells = <1>;
      #size-cells = <1>;
      super-sexy-board,watchdog-gpio = <&gpio_simple 19 0>;
      ...
}
Quoted 8 lines
Quoted 2 lines

Why as a property of the root node, and not as a node with a very specific compatible property?

Because the root node is the only logical board-level node we have right now. However, I'm not deeply committed to this approach. The only question I have about putting it in another node is choosing the parent node. I don't think it fits to make it a child of the SoC node or any other bus node.

Quoted 3 lines

A child of the gpio controller node seems most logical, though a child of the root node would be OK. It was the freefloating property that struck me as a little odd.

I concur.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#6 lore raw
In reply to Wolfram Sang
Quoted 11 lines · Wolfram Sang

Hello all,

I understood that the device-tree is for describing hardware and should not contain driver specific information. I have problems drawing this line right now. I made a driver for watchdogs which are pinged by toggling a gpio. Currently the device-tree entry looks like this:

	watchdog@gpio {
		compatible = "gpio-watchdog";
		gpios =	<&gpio_simple 19 0>;
	};

This certainly isn't right. The unit address should be based on the 'reg' property. If there's no 'reg' property, there should be no unit address.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson