Skip to contentSkip to conversation

watchdog: Add support for the WM8350 watchdog

PATCH In review Mark Brown 2 participants 3 messages Oct 27, 2008 – Oct 31, 2008

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 watchdog: Add support for the WM8350 watchdog

This driver implements support for the watchdog functionality provided by the Wolfson Microelectronics WM8350, a multi-function audio and power management subsystem intended for use in embedded systems. It is based on a driver originally written by Graeme Gregory, though it has been extensively modified since then.

Use of a GPIO to kick the watchdog is not yet supported.

---

Changes since last submission (which should address all the feedback):

- Implement GETBOOTSTATUS as an alias for GETSTATUS.
- Use unlocked_ioctl, adding a mutex for hardware access.
- Ping the watchdog when we close it uncleanly.
- Remove debug printk().

 drivers/watchdog/Kconfig      |    7 +
 drivers/watchdog/Makefile     |    1 +
 drivers/watchdog/wm8350_wdt.c |  329 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 337 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/wm8350_wdt.c
drivers/watchdog/Kconfig +7 -0
index 1a22fe7..b93e334 100644
@@ -55,6 +55,13 @@ config SOFT_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called softdog.
 
+config WM8350_WATCHDOG
+	tristate "WM8350 watchdog"
+	depends on MFD_WM8350
+	help
+	  Support for the watchdog in the WM8350 AudioPlus PMIC.  When
+	  the watchdog triggers the system will be reset.
+
 # ALPHA Architecture
 
 # ARM Architecture
drivers/watchdog/Makefile +1 -0
index e352bbb..c3b8db3 100644
@@ -134,3 +134,4 @@ obj-$(CONFIG_WATCHDOG_CP1XXX)		+= cpwd.o
 
 # Architecture Independant
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
+obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
drivers/watchdog/wm8350_wdt.c new file +329 -0

329 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 15 lines · On Mon, 27 Oct 2008 15:31:56 +0000 Mark Brown…

This driver implements support for the watchdog functionality provided by the Wolfson Microelectronics WM8350, a multi-function audio and power management subsystem intended for use in embedded systems. It is based on a driver originally written by Graeme Gregory, though it has been extensively modified since then.

Use of a GPIO to kick the watchdog is not yet supported.

...

drivers/watchdog/wm8350_wdt.c new file +5 -0
+
+static int wm8350_wdt_set_timeout(struct wm8350 *wm8350, u16 value)
+{
+	int ret;
+	u16 reg;

drivers/watchdog/wm8350_wdt.c line 60

Quoted 10 lines
drivers/watchdog/wm8350_wdt.c new file +10 -0
+
+	mutex_lock(&wdt_mutex);
+	wm8350_reg_unlock(wm8350);
+
+	reg = wm8350_reg_read(wm8350, WM8350_SYSTEM_CONTROL_2);
+	reg &= ~WM8350_WDOG_TO_MASK;
+	reg |= value;
+	ret = wm8350_reg_write(wm8350, WM8350_SYSTEM_CONTROL_2, reg);
+
+	wm8350_reg_lock(wm8350);

I was curious about this wm8350_reg_lock/wm8350_reg_unlock thing, so I went to have a look at it. Nothing. Obviously its authors felt there was no benefit in having anyone else understand what it does.

Quoted 6 lines
drivers/watchdog/wm8350_wdt.c new file +4 -0
+	mutex_unlock(&wdt_mutex);
+
+	return ret;
+}
 
...

drivers/watchdog/wm8350_wdt.c line 126

Quoted 10 lines
drivers/watchdog/wm8350_wdt.c new file +9 -0
 
+static int wm8350_wdt_open(struct inode *inode, struct file *file)
+{
+	struct wm8350 *wm8350 = get_wm8350();
+	int ret;
+
+	if (!wm8350)
+		return -ENODEV;
+
+	if (test_and_set_bit(1, &wm8350_wdt_users))

It's odd that the driver uses bit 1 rather than bit 0.

author
#2 lore raw
Quoted 7 lines · Andrew Morton

Review

Quoted 1 line · Mark Brown
(quoted diff) +1 -0
+	wm8350_reg_lock(wm8350);

I was curious about this wm8350_reg_lock/wm8350_reg_unlock thing, so I went to have a look at it. Nothing. Obviously its authors felt there was no benefit in having anyone else understand what it does.

Well, there's really not that much more to it than what the function names say - some of the registers can be locked in hardware, meaning that the lock needs to be unlocked when writing to them. I'll come up with some sort of blurb and send a patch to Samuel but I'm not sure how much it'll actually help.

This is mostly for things particularly likely to cause damage to the system - in this case the hardware supports extremely short timeouts which might be too short to be able to kick the watchdog again if it fires and reboots (the lowest option is 0.125s IIRC). The only way to recover from that is to remove all power from the system.

Quoted 3 lines

drivers/watchdog/wm8350_wdt.c line 126

Quoted 1 line
drivers/watchdog/wm8350_wdt.c new file +1 -0
+	if (test_and_set_bit(1, &wm8350_wdt_users))

It's odd that the driver uses bit 1 rather than bit 0.

Hrm, yeah. No idea why, the driver was like that when I first looked at it and I can't see any history explaining the choice.