Skip to contentSkip to conversation

Add support for Ricoh RN5T618 PMIC

PATCH Superseded Beniamino Galvani 5 participants 20 messages Aug 26, 2014 – Sep 28, 2014

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for Ricoh RN5T618 PMIC

Ricoh RN5T618 is a power management IC which includes 3 step-down DCDC converters, 7 low-dropout regulators, a Li-ion battery charger, fuel gauge, ADC, GPIOs and a watchdog timer.

This series adds a MFD core driver and separate drivers to support the regulator and watchdog functionalities.

The patchset has been tested on a Tronsmart Vega S89 Elite TV box on top of other patches needed to support the Amlogic Meson SoC. The tree with all the changes is available at:

https://github.com/bengal/linux/tree/rn5t618

Beniamino Galvani (4):
mfd: Add Ricoh RN5T618 PMIC core driver
regulator: add driver for Ricoh RN5T618 regulators
watchdog: add driver for Ricoh RN5T618 watchdog
mfd: rn5t618: document device tree bindings

 Documentation/devicetree/bindings/mfd/rn5t618.txt |   36 ++++
 drivers/mfd/Kconfig                               |   11 +
 drivers/mfd/Makefile                              |    1 +
 drivers/mfd/rn5t618.c                             |  129 ++++++++++++
 drivers/regulator/Kconfig                         |    6 +
 drivers/regulator/Makefile                        |    1 +
 drivers/regulator/rn5t618-regulator.c             |  143 +++++++++++++
 drivers/watchdog/Kconfig                          |   11 +
 drivers/watchdog/Makefile                         |    1 +
 drivers/watchdog/rn5t618_wdt.c                    |  196 ++++++++++++++++++
 include/linux/mfd/rn5t618.h                       |  228 +++++++++++++++++++++
 11 files changed, 763 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/rn5t618.txt
 create mode 100644 drivers/mfd/rn5t618.c
 create mode 100644 drivers/regulator/rn5t618-regulator.c
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
 create mode 100644 include/linux/mfd/rn5t618.h
Signature · 6 lines
1.7.10.4

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

PATCH 1/4 mfd: Add Ricoh RN5T618 PMIC core driver

Ricoh RN5T618 is a power management IC which integrates 3 step-down DCDC converters, 7 low-dropout regulators, a Li-ion battery charger, fuel gauge, ADC, GPIOs and a watchdog timer.

This commit adds a MFD core driver to support the I2C communication with the device.

---
 drivers/mfd/Kconfig         |   11 +++
 drivers/mfd/Makefile        |    1 +
 drivers/mfd/rn5t618.c       |  129 ++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h |  210 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 351 insertions(+)
 create mode 100644 drivers/mfd/rn5t618.c
 create mode 100644 include/linux/mfd/rn5t618.h
drivers/mfd/Kconfig +11 -0
index 8d5fad2..fae8c5b 100644
@@ -582,6 +582,17 @@ config MFD_RC5T583
 	  Additional drivers must be enabled in order to use the
 	  different functionality of the device.
 
+config MFD_RN5T618
+	bool "Ricoh RN5T5618 PMIC"
+	depends on I2C=y
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  Say yes here to add support for the Ricoh RN5T618 PMIC. This
+	  driver provides common support for accessing the device,
+	  additional drivers must be enabled in order to use the
+	  functionality of the device.
+
 config MFD_SEC_CORE
 	bool "SAMSUNG Electronics PMIC Series Support"
 	depends on I2C=y
drivers/mfd/Makefile +1 -0
index f001487..b945899 100644
@@ -160,6 +160,7 @@ obj-$(CONFIG_MFD_INTEL_MSIC)	+= intel_msic.o
 obj-$(CONFIG_MFD_PALMAS)	+= palmas.o
 obj-$(CONFIG_MFD_VIPERBOARD)    += viperboard.o
 obj-$(CONFIG_MFD_RC5T583)	+= rc5t583.o rc5t583-irq.o
+obj-$(CONFIG_MFD_RN5T618)	+= rn5t618.o
 obj-$(CONFIG_MFD_SEC_CORE)	+= sec-core.o sec-irq.o
 obj-$(CONFIG_MFD_SYSCON)	+= syscon.o
 obj-$(CONFIG_MFD_LM3533)	+= lm3533-core.o lm3533-ctrlbank.o
drivers/mfd/rn5t618.c new file +129 -0

129 lines not on this page · raw message

include/linux/mfd/rn5t618.h new file +210 -0

210 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 2/4 regulator: add driver for Ricoh RN5T618 regulators

In reply to Beniamino Galvani

This driver supports the 3 DCDC and 7 LDO regulators available on Ricoh RN5T618 PMIC.

---
 drivers/regulator/Kconfig             |    6 ++
 drivers/regulator/Makefile            |    1 +
 drivers/regulator/rn5t618-regulator.c |  143 +++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h           |   14 ++++
 4 files changed, 164 insertions(+)
 create mode 100644 drivers/regulator/rn5t618-regulator.c
drivers/regulator/Kconfig +6 -0
index 2dc8289..9d14e62 100644
@@ -459,6 +459,12 @@ config REGULATOR_RC5T583
 	  through regulator interface. The device supports multiple DCDC/LDO
 	  outputs which can be controlled by i2c communication.
 
+config REGULATOR_RN5T618
+	tristate "Ricoh RN5T618 voltage regulators"
+	depends on MFD_RN5T618
+	help
+	  Say y here to support the regulators found on Ricoh RN5T618 PMIC.
+
 config REGULATOR_S2MPA01
 	tristate "Samsung S2MPA01 voltage regulator"
 	depends on MFD_SEC_CORE
drivers/regulator/Makefile +1 -0
index aa4a6aa..f7c4473 100644
@@ -62,6 +62,7 @@ obj-$(CONFIG_REGULATOR_PBIAS) += pbias-regulator.o
 obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
 obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
 obj-$(CONFIG_REGULATOR_RC5T583)  += rc5t583-regulator.o
+obj-$(CONFIG_REGULATOR_RN5T618)  += rn5t618-regulator.o
 obj-$(CONFIG_REGULATOR_S2MPA01) += s2mpa01.o
 obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
 obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
drivers/regulator/rn5t618-regulator.c new file +143 -0

143 lines not on this page · raw message

include/linux/mfd/rn5t618.h +14 -0
index 87686eb..e3571d1 100644
@@ -203,6 +203,20 @@
 #define RN5T618_REPCNT_REPWRON		BIT(0)
 #define RN5T618_SLPCNT_SWPWROFF		BIT(0)
 
+enum {
+	RN5T618_DCDC1,
+	RN5T618_DCDC2,
+	RN5T618_DCDC3,
+	RN5T618_LDO1,
+	RN5T618_LDO2,
+	RN5T618_LDO3,
+	RN5T618_LDO4,
+	RN5T618_LDO5,
+	RN5T618_LDORTC1,
+	RN5T618_LDORTC2,
+	RN5T618_REG_NUM,
+};
+
 struct rn5t618 {
 	struct regmap *regmap;
 };
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 3/4 watchdog: add driver for Ricoh RN5T618 watchdog

In reply to Beniamino Galvani

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
drivers/watchdog/Kconfig +11 -0
index f57312f..9eba6af 100644
@@ -309,6 +309,17 @@ config ORION_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called orion_wdt.
 
+config RN5T618_WATCHDOG
+	tristate "Ricoh RN5T618 watchdog"
+	depends on MFD_RN5T618
+	select WATCHDOG_CORE
+	help
+	  If you say yes here you get support for watchdog on the Ricoh
+	  RN5T618 PMIC.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called rn5t618_wdt.
+
 config SUNXI_WATCHDOG
 	tristate "Allwinner SoCs watchdog support"
 	depends on ARCH_SUNXI
drivers/watchdog/Makefile +1 -0
index 468c320..0afa343 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
 obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
 obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
 obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o
+obj-$(CONFIG_RN5T618_WATCHDOG) += rn5t618_wdt.o
 obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
 obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
drivers/watchdog/rn5t618_wdt.c new file +196 -0

196 lines not on this page · raw message

include/linux/mfd/rn5t618.h +4 -0
index e3571d1..c72d534 100644
@@ -202,6 +202,10 @@
 
 #define RN5T618_REPCNT_REPWRON		BIT(0)
 #define RN5T618_SLPCNT_SWPWROFF		BIT(0)
+#define RN5T618_WATCHDOG_WDOGEN		BIT(2)
+#define RN5T618_WATCHDOG_WDOGTIM_M	(BIT(0) | BIT(1))
+#define RN5T618_WATCHDOG_WDOGTIM_S	0
+#define RN5T618_PWRIRQ_IR_WDOG		BIT(6)
 
 enum {
 	RN5T618_DCDC1,
Signature · 1 line
1.7.10.4
#18 lore raw

PATCH 4/4 mfd: rn5t618: document device tree bindings

In reply to Beniamino Galvani

This adds the device tree bindings documentation for Ricoh RN5T618.

---
 Documentation/devicetree/bindings/mfd/rn5t618.txt |   36 +++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/rn5t618.txt
Documentation/devicetree/bindings/mfd/rn5t618.txt new file +36 -0
new file mode 100644
index 0000000..937785a
@@ -0,0 +1,36 @@
+* Ricoh RN5T618 PMIC
+
+Ricoh RN5T618 is a power management IC which integrates 3 step-down
+DCDC converters, 7 low-dropout regulators, a Li-ion battery charger,
+fuel gauge, ADC, GPIOs and a watchdog timer. It can be controlled
+through a I2C interface.
+
+Required properties:
+ - compatible: should be "ricoh,rn5t618"
+ - reg: the I2C slave address of the device
+
+Sub-nodes:
+ - regulators: the node is required if the regulator functionality is
+   needed. The valid regulator names are: DCDC1, DCDC2, DCDC3, LDO1,
+   LDO2, LDO3, LDO4, LDO5, LDORTC1 and LDORTC2.
+   The common bindings for each individual regulator can be found in:
+   Documentation/devicetree/bindings/regulator/regulator.txt
+
+Example:
+
+	pmic@32 {
+		compatible = "ricoh,rn5t618";
+		reg = <0x32>;
+
+		regulators {
+			DCDC1 {
+				regulator-min-microvolt = <1050000>;
+				regulator-max-microvolt = <1050000>;
+			};
+
+			DCDC2 {
+				regulator-min-microvolt = <1175000>;
+				regulator-max-microvolt = <1175000>;
+			};
+		};
+	};
Signature · 1 line
1.7.10.4
maintainer
#19 lore raw

Re: [PATCH 4/4] mfd: rn5t618: document device tree bindings

Quoted 1 line · Beniamino Galvani

This adds the device tree bindings documentation for Ricoh RN5T618.

maintainer
#5 lore raw

Re: [PATCH 2/4] regulator: add driver for Ricoh RN5T618 regulators

In reply to Beniamino Galvani
Quoted 5 lines · Beniamino Galvani

This driver supports the 3 DCDC and 7 LDO regulators available on Ricoh RN5T618 PMIC.

 drivers/regulator/rn5t618-regulator.c |  143 +++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h           |   14 ++++

This is fine but I can't apply it since you're patching the MFD header which you added in the first patch. It'd be better to include those changes in the first patch, making the second patch independant.

#2 lore raw

Re: [PATCH 1/4] mfd: Add Ricoh RN5T618 PMIC core driver

In reply to Beniamino Galvani
Quoted 8 lines · Beniamino Galvani

Ricoh RN5T618 is a power management IC which integrates 3 step-down DCDC converters, 7 low-dropout regulators, a Li-ion battery charger, fuel gauge, ADC, GPIOs and a watchdog timer.

This commit adds a MFD core driver to support the I2C communication with the device.

Quoted 8 lines
---
 drivers/mfd/Kconfig         |   11 +++
 drivers/mfd/Makefile        |    1 +
 drivers/mfd/rn5t618.c       |  129 ++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h |  210 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 351 insertions(+)
 create mode 100644 drivers/mfd/rn5t618.c
 create mode 100644 include/linux/mfd/rn5t618.h

Really nicely done. We don't normally get many first submissions at this quality level.

One question and a _really_ small nit though.

drivers/mfd/Kconfig config MFD_RC5T583 · line 586

Quoted 10 lines
drivers/mfd/Kconfig +2 -0
index 8d5fad2..fae8c5b 100644
@@ -582,6 +582,17 @@ config MFD_RC5T583
 	  Additional drivers must be enabled in order to use the
 	  different functionality of the device.
 
+config MFD_RN5T618
+	bool "Ricoh RN5T5618 PMIC"

Shouldn't this be tristate?

drivers/mfd/Kconfig config MFD_RC5T583 · line 587

Quoted 1 line
drivers/mfd/Kconfig +1 -0
+	depends on I2C=y

If so, this should be:

depends on I2C

Quoted 7 lines
drivers/mfd/Kconfig +7 -0
+	select MFD_CORE
+	select REGMAP_I2C
+	help
+	  Say yes here to add support for the Ricoh RN5T618 PMIC. This
+	  driver provides common support for accessing the device,
+	  additional drivers must be enabled in order to use the
+	  functionality of the device.

[...]

Quoted 2 lines

+++ b/drivers/mfd/rn5t618.c

drivers/mfd/Kconfig +0 -0
@@ -0,0 +1,129 @@

[...]

Quoted 3 lines
drivers/mfd/Kconfig +3 -0
+static int rn5t618_i2c_probe(struct i2c_client *i2c,
+			     const struct i2c_device_id *id)
+{

[...]

drivers/mfd/Kconfig

Quoted 1 line
drivers/mfd/Kconfig +1 -0
+	dev_info(&i2c->dev, "RN5T618 MFD driver loaded");

Can you remove this line? We normally only print things when information is gathered from a chip i.e. version information and the like.

Quoted 2 lines
drivers/mfd/Kconfig +2 -0
+	return 0;
+}

[...]

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
maintainer
#7 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

In reply to Beniamino Galvani
Quoted 66 lines · Beniamino Galvani

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
drivers/watchdog/Kconfig +11 -0
index f57312f..9eba6af 100644
@@ -309,6 +309,17 @@ config ORION_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called orion_wdt.
 
+config RN5T618_WATCHDOG
+	tristate "Ricoh RN5T618 watchdog"
+	depends on MFD_RN5T618
+	select WATCHDOG_CORE
+	help
+	  If you say yes here you get support for watchdog on the Ricoh
+	  RN5T618 PMIC.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called rn5t618_wdt.
+
 config SUNXI_WATCHDOG
 	tristate "Allwinner SoCs watchdog support"
 	depends on ARCH_SUNXI
drivers/watchdog/Makefile +1 -0
index 468c320..0afa343 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
 obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
 obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
 obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o
+obj-$(CONFIG_RN5T618_WATCHDOG) += rn5t618_wdt.o
 obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
 obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
drivers/watchdog/rn5t618_wdt.c new file +13 -0
new file mode 100644
index 0000000..3a76ad7
@@ -0,0 +1,196 @@
+/*
+ * Watchdog driver for Ricoh RN5T618 PMIC
+ *
+ * Copyright (C) 2014 Beniamino Galvani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+

drivers/watchdog/rn5t618_wdt.c line 23

Quoted 10 lines
drivers/watchdog/rn5t618_wdt.c new file +10 -0
+#include <linux/device.h>
+#include <linux/mfd/rn5t618.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
+#define DRIVER_NAME "rn5t618-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+static unsigned int heartbeat = -1;

I'd be surprised if this doesn't cause a compiler warning. Why not just initialize the variable with 0 ?

Quoted 32 lines
drivers/watchdog/rn5t618_wdt.c new file +32 -0
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
+
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct rn5t618_wdt {
+	struct watchdog_device wdt_dev;
+	struct rn5t618 *rn5t618;
+};
+
+/*
+ * This array encodes the values of WDOGTIM field for the supported
+ * watchdog expiration times. If the watchdog is not accessed before
+ * the timer expiration, the PMU generates an interrupt and if the CPU
+ * doesn't clear it within one second the system is restarted.
+ */
+static const struct {
+	u8 reg_val;
+	int time;
+} rn5t618_wdt_map[] = {
+	{ 0, 1 },
+	{ 1, 8 },
+	{ 2, 32 },
+	{ 3, 128 },
+};
+
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{

drivers/watchdog/rn5t618_wdt.c line 65

Quoted 10 lines
drivers/watchdog/rn5t618_wdt.c new file +10 -0
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;

Can you simplify this a bit ? If you use

	if (i == ARRAY_SIZE(rn5t618_wdt_map))
		return -EINVAL;

drivers/watchdog/rn5t618_wdt.c line 66

Quoted 1 line
drivers/watchdog/rn5t618_wdt.c new file +1 -0
+	else

You can drop this else statement.

Thanks,
Guenter

Quoted 153 lines
drivers/watchdog/rn5t618_wdt.c new file +130 -0
+		ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+					 RN5T618_WATCHDOG_WDOGTIM_M,
+					 rn5t618_wdt_map[i].reg_val);
+	if (!ret)
+		wdt_dev->timeout = rn5t618_wdt_map[i].time;
+
+	return ret;
+}
+
+static int rn5t618_wdt_start(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret;
+
+	ret = rn5t618_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
+	if (ret)
+		return ret;
+
+	/* enable repower-on */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_REPCNT,
+				 RN5T618_REPCNT_REPWRON,
+				 RN5T618_REPCNT_REPWRON);
+	if (ret)
+		return ret;
+
+	/* enable watchdog */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				 RN5T618_WATCHDOG_WDOGEN,
+				 RN5T618_WATCHDOG_WDOGEN);
+	if (ret)
+		return ret;
+
+	/* enable watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIREN,
+				  RN5T618_PWRIRQ_IR_WDOG,
+				  RN5T618_PWRIRQ_IR_WDOG);
+}
+
+static int rn5t618_wdt_stop(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				  RN5T618_WATCHDOG_WDOGEN, 0);
+}
+
+static int rn5t618_wdt_ping(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned int val;
+	int ret;
+
+	/* The counter is restarted after a R/W access to watchdog register */
+	ret = regmap_read(wdt->rn5t618->regmap, RN5T618_WATCHDOG, &val);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(wdt->rn5t618->regmap, RN5T618_WATCHDOG, val);
+	if (ret)
+		return ret;
+
+	/* Clear pending watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIRQ,
+				  RN5T618_PWRIRQ_IR_WDOG, 0);
+}
+
+static struct watchdog_info rn5t618_wdt_info = {
+	.options	= WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE |
+			  WDIOF_KEEPALIVEPING,
+	.identity	= DRIVER_NAME,
+};
+
+static struct watchdog_ops rn5t618_wdt_ops = {
+	.owner          = THIS_MODULE,
+	.start          = rn5t618_wdt_start,
+	.stop           = rn5t618_wdt_stop,
+	.ping           = rn5t618_wdt_ping,
+	.set_timeout    = rn5t618_wdt_set_timeout,
+};
+
+static int rn5t618_wdt_probe(struct platform_device *pdev)
+{
+	struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
+	struct rn5t618_wdt *wdt;
+	int min_timeout, max_timeout;
+
+	wdt = devm_kzalloc(&pdev->dev, sizeof(struct rn5t618_wdt), GFP_KERNEL);
+	if (!wdt)
+		return -ENOMEM;
+
+	min_timeout = rn5t618_wdt_map[0].time;
+	max_timeout = rn5t618_wdt_map[ARRAY_SIZE(rn5t618_wdt_map) - 1].time;
+
+	wdt->rn5t618 = rn5t618;
+	wdt->wdt_dev.info = &rn5t618_wdt_info;
+	wdt->wdt_dev.ops = &rn5t618_wdt_ops;
+	wdt->wdt_dev.min_timeout = min_timeout;
+	wdt->wdt_dev.max_timeout = max_timeout;
+	wdt->wdt_dev.timeout = max_timeout;
+	wdt->wdt_dev.parent = &pdev->dev;
+
+	watchdog_set_drvdata(&wdt->wdt_dev, wdt);
+	watchdog_init_timeout(&wdt->wdt_dev, heartbeat, &pdev->dev);
+	watchdog_set_nowayout(&wdt->wdt_dev, nowayout);
+
+	return watchdog_register_device(&wdt->wdt_dev);
+}
+
+static int rn5t618_wdt_remove(struct platform_device *pdev)
+{
+	struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
+
+	watchdog_unregister_device(wdt_dev);
+
+	return 0;
+}
+
+static struct platform_driver rn5t618_wdt_driver = {
+	.probe = rn5t618_wdt_probe,
+	.remove = rn5t618_wdt_remove,
+	.driver = {
+		.name	= DRIVER_NAME,
+	},
+};
+
+module_platform_driver(rn5t618_wdt_driver);
+
+MODULE_AUTHOR("Beniamino Galvani <[email protected]>");
+MODULE_DESCRIPTION("RN5T618 watchdog driver");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/rn5t618.h +4 -0
index e3571d1..c72d534 100644
@@ -202,6 +202,10 @@
 
 #define RN5T618_REPCNT_REPWRON		BIT(0)
 #define RN5T618_SLPCNT_SWPWROFF		BIT(0)
+#define RN5T618_WATCHDOG_WDOGEN		BIT(2)
+#define RN5T618_WATCHDOG_WDOGTIM_M	(BIT(0) | BIT(1))
+#define RN5T618_WATCHDOG_WDOGTIM_S	0
+#define RN5T618_PWRIRQ_IR_WDOG		BIT(6)
 
 enum {
 	RN5T618_DCDC1,
Signature · 6 lines
1.7.10.4

--
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

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

#3 lore raw

Re: [PATCH 1/4] mfd: Add Ricoh RN5T618 PMIC core driver

In reply to Lee Jones

On Wed, Aug 27, 2014 at 08:56:14AM +0100, Lee Jones wrote:
[...]

Quoted 8 lines
Quoted 8 lines
drivers/mfd/Kconfig +0 -0
index 8d5fad2..fae8c5b 100644
@@ -582,6 +582,17 @@ config MFD_RC5T583
 	  Additional drivers must be enabled in order to use the
 	  different functionality of the device.
 
Quoted 4 lines

drivers/mfd/Kconfig config MFD_RC5T583 · line 586

Quoted 2 lines
drivers/mfd/Kconfig +2 -0
+config MFD_RN5T618
+	bool "Ricoh RN5T5618 PMIC"

Shouldn't this be tristate?

Yes, I suppose the driver would work also as a module, I only have to uninstall the pm_power_off hook on module removal.

Quoted 11 lines
Quoted 2 lines
drivers/mfd/Kconfig +1 -0
+++ b/drivers/mfd/rn5t618.c
@@ -0,0 +1,129 @@

[...]

Quoted 3 lines
drivers/mfd/Kconfig +3 -0
+static int rn5t618_i2c_probe(struct i2c_client *i2c,
+			     const struct i2c_device_id *id)
+{

[...]

Quoted 5 lines

drivers/mfd/Kconfig

Quoted 1 line
drivers/mfd/Kconfig +1 -0
+	dev_info(&i2c->dev, "RN5T618 MFD driver loaded");

Can you remove this line? We normally only print things when information is gathered from a chip i.e. version information and the like.

I will remove it, thanks.

Beniamino

#8 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

In reply to Guenter Roeck

On Wed, Aug 27, 2014 at 12:01:35PM -0700, Guenter Roeck wrote:
[...]

Quoted 5 lines
Quoted 5 lines
drivers/watchdog/rn5t618_wdt.c new file +5 -0
+#include <linux/device.h>
+#include <linux/mfd/rn5t618.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
Quoted 8 lines

drivers/watchdog/rn5t618_wdt.c line 23

Quoted 5 lines
drivers/watchdog/rn5t618_wdt.c new file +5 -0
+
+#define DRIVER_NAME "rn5t618-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+static unsigned int heartbeat = -1;

I'd be surprised if this doesn't cause a compiler warning. Why not just initialize the variable with 0 ?

The idea was to initialize the variable with an invalid value that has no effect when watchdog_init_timeout() is called during probe, thus leaving the watchdog timeout to the maximum value.

You are right, the same effect can be achieved in a cleaner way leaving the variable to zero (by the way, the above assignment doesn't seem to generate warnings).

Quoted 13 lines
Quoted 13 lines
drivers/watchdog/rn5t618_wdt.c new file +12 -0
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
+
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct rn5t618_wdt {
+	struct watchdog_device wdt_dev;
+	struct rn5t618 *rn5t618;
+};

[..]

Quoted 16 lines

drivers/watchdog/rn5t618_wdt.c line 65

Quoted 13 lines
drivers/watchdog/rn5t618_wdt.c new file +13 -0
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;

Can you simplify this a bit ? If you use

Quoted 6 lines
	if (i == ARRAY_SIZE(rn5t618_wdt_map))
		return -EINVAL;

drivers/watchdog/rn5t618_wdt.c line 66

Quoted 1 line
drivers/watchdog/rn5t618_wdt.c new file +1 -0
+	else

You can drop this else statement.

Will do, thanks.

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

#9 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

In reply to Guenter Roeck
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Beniamino Galvani

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c

[...]

Quoted 2 lines
Quoted 2 lines

+++ b/drivers/watchdog/rn5t618_wdt.c

(quoted diff) +0 -0
@@ -0,0 +1,196 @@

[...]

Quoted 16 lines

drivers/watchdog/rn5t618_wdt.c line 65

Quoted 13 lines
drivers/watchdog/rn5t618_wdt.c new file +13 -0
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;

Can you simplify this a bit ? If you use

Quoted 2 lines
	if (i == ARRAY_SIZE(rn5t618_wdt_map))
		return -EINVAL;

This changes the semantics.

Quoted 9 lines

drivers/watchdog/rn5t618_wdt.c line 66

Quoted 1 line
drivers/watchdog/rn5t618_wdt.c new file +1 -0
+	else

You can drop this else statement.

drivers/watchdog/rn5t618_wdt.c line 71

Quoted 5 lines
drivers/watchdog/rn5t618_wdt.c new file +5 -0
+		ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+					 RN5T618_WATCHDOG_WDOGTIM_M,
+					 rn5t618_wdt_map[i].reg_val);
+	if (!ret)
+		wdt_dev->timeout = rn5t618_wdt_map[i].time;

... Isn't this important?

Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+	return ret;
+}
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#10 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

Quoted 38 lines · Lee Jones
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Beniamino Galvani

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
  drivers/watchdog/Kconfig       |   11 +++
  drivers/watchdog/Makefile      |    1 +
  drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
  include/linux/mfd/rn5t618.h    |    4 +
  4 files changed, 212 insertions(+)

create mode 100644 drivers/watchdog/rn5t618_wdt.c

[...]

Quoted 2 lines
Quoted 2 lines

+++ b/drivers/watchdog/rn5t618_wdt.c

(quoted diff) +0 -0
@@ -0,0 +1,196 @@

[...]

Quoted 16 lines

drivers/watchdog/rn5t618_wdt.c line 65

Quoted 13 lines
drivers/watchdog/rn5t618_wdt.c new file +13 -0
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;

Can you simplify this a bit ? If you use

Quoted 5 lines
Quoted 2 lines
	if (i == ARRAY_SIZE(rn5t618_wdt_map))
		return -EINVAL;

This changes the semantics.

How so ? If ret is set to -EINVAL, the rest of the function won't do anything but eventually return -EINVAL. I don't see why returning -EINVAL immediately would change that.

Guenter

Quoted 12 lines
Quoted 9 lines

drivers/watchdog/rn5t618_wdt.c line 66

Quoted 1 line
drivers/watchdog/rn5t618_wdt.c new file +1 -0
+	else

You can drop this else statement.

drivers/watchdog/rn5t618_wdt.c line 71

Quoted 5 lines
drivers/watchdog/rn5t618_wdt.c new file +5 -0
+		ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+					 RN5T618_WATCHDOG_WDOGTIM_M,
+					 rn5t618_wdt_map[i].reg_val);
+	if (!ret)
+		wdt_dev->timeout = rn5t618_wdt_map[i].time;

... Isn't this important?

Quoted 3 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return ret;
+}

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

#11 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

Quoted 39 lines · Guenter Roeck
Quoted 38 lines · Lee Jones
Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Beniamino Galvani

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c

[...]

Quoted 2 lines
Quoted 2 lines

+++ b/drivers/watchdog/rn5t618_wdt.c

(quoted diff) +0 -0
@@ -0,0 +1,196 @@

[...]

Quoted 16 lines

drivers/watchdog/rn5t618_wdt.c line 65

Quoted 13 lines
drivers/watchdog/rn5t618_wdt.c new file +13 -0
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;

Can you simplify this a bit ? If you use

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
	if (i == ARRAY_SIZE(rn5t618_wdt_map))
		return -EINVAL;

This changes the semantics.

How so ? If ret is set to -EINVAL, the rest of the function won't do anything but eventually return -EINVAL. I don't see why returning -EINVAL immediately would change that.

Ah, you're right.

I read:

  if (!ret)
    wdt_dev->timeout = rn5t618_wdt_map[i].time;

As:

  if (ret)
    wdt_dev->timeout = rn5t618_wdt_map[i].time;

My bad - withdrawn.

Quoted 16 lines
Quoted 15 lines
Quoted 9 lines

drivers/watchdog/rn5t618_wdt.c line 66

Quoted 1 line
drivers/watchdog/rn5t618_wdt.c new file +1 -0
+	else

You can drop this else statement.

drivers/watchdog/rn5t618_wdt.c line 71

Quoted 5 lines
drivers/watchdog/rn5t618_wdt.c new file +5 -0
+		ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+					 RN5T618_WATCHDOG_WDOGTIM_M,
+					 rn5t618_wdt_map[i].reg_val);
+	if (!ret)
+		wdt_dev->timeout = rn5t618_wdt_map[i].time;

... Isn't this important?

Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+	return ret;
+}
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

In reply to Beniamino Galvani

Wim,

Still waiting on a Watchdog Ack, so I can take this set in.

Quoted 264 lines

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
drivers/watchdog/Kconfig +11 -0
index f57312f..9eba6af 100644
@@ -309,6 +309,17 @@ config ORION_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called orion_wdt.
 
+config RN5T618_WATCHDOG
+	tristate "Ricoh RN5T618 watchdog"
+	depends on MFD_RN5T618
+	select WATCHDOG_CORE
+	help
+	  If you say yes here you get support for watchdog on the Ricoh
+	  RN5T618 PMIC.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called rn5t618_wdt.
+
 config SUNXI_WATCHDOG
 	tristate "Allwinner SoCs watchdog support"
 	depends on ARCH_SUNXI
drivers/watchdog/Makefile +1 -0
index 468c320..0afa343 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
 obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
 obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
 obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o
+obj-$(CONFIG_RN5T618_WATCHDOG) += rn5t618_wdt.o
 obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
 obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
drivers/watchdog/rn5t618_wdt.c new file +196 -0
new file mode 100644
index 0000000..3a76ad7
@@ -0,0 +1,196 @@
+/*
+ * Watchdog driver for Ricoh RN5T618 PMIC
+ *
+ * Copyright (C) 2014 Beniamino Galvani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/mfd/rn5t618.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
+#define DRIVER_NAME "rn5t618-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+static unsigned int heartbeat = -1;
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
+
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct rn5t618_wdt {
+	struct watchdog_device wdt_dev;
+	struct rn5t618 *rn5t618;
+};
+
+/*
+ * This array encodes the values of WDOGTIM field for the supported
+ * watchdog expiration times. If the watchdog is not accessed before
+ * the timer expiration, the PMU generates an interrupt and if the CPU
+ * doesn't clear it within one second the system is restarted.
+ */
+static const struct {
+	u8 reg_val;
+	int time;
+} rn5t618_wdt_map[] = {
+	{ 0, 1 },
+	{ 1, 8 },
+	{ 2, 32 },
+	{ 3, 128 },
+};
+
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;
+	else
+		ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+					 RN5T618_WATCHDOG_WDOGTIM_M,
+					 rn5t618_wdt_map[i].reg_val);
+	if (!ret)
+		wdt_dev->timeout = rn5t618_wdt_map[i].time;
+
+	return ret;
+}
+
+static int rn5t618_wdt_start(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret;
+
+	ret = rn5t618_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
+	if (ret)
+		return ret;
+
+	/* enable repower-on */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_REPCNT,
+				 RN5T618_REPCNT_REPWRON,
+				 RN5T618_REPCNT_REPWRON);
+	if (ret)
+		return ret;
+
+	/* enable watchdog */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				 RN5T618_WATCHDOG_WDOGEN,
+				 RN5T618_WATCHDOG_WDOGEN);
+	if (ret)
+		return ret;
+
+	/* enable watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIREN,
+				  RN5T618_PWRIRQ_IR_WDOG,
+				  RN5T618_PWRIRQ_IR_WDOG);
+}
+
+static int rn5t618_wdt_stop(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				  RN5T618_WATCHDOG_WDOGEN, 0);
+}
+
+static int rn5t618_wdt_ping(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned int val;
+	int ret;
+
+	/* The counter is restarted after a R/W access to watchdog register */
+	ret = regmap_read(wdt->rn5t618->regmap, RN5T618_WATCHDOG, &val);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(wdt->rn5t618->regmap, RN5T618_WATCHDOG, val);
+	if (ret)
+		return ret;
+
+	/* Clear pending watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIRQ,
+				  RN5T618_PWRIRQ_IR_WDOG, 0);
+}
+
+static struct watchdog_info rn5t618_wdt_info = {
+	.options	= WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE |
+			  WDIOF_KEEPALIVEPING,
+	.identity	= DRIVER_NAME,
+};
+
+static struct watchdog_ops rn5t618_wdt_ops = {
+	.owner          = THIS_MODULE,
+	.start          = rn5t618_wdt_start,
+	.stop           = rn5t618_wdt_stop,
+	.ping           = rn5t618_wdt_ping,
+	.set_timeout    = rn5t618_wdt_set_timeout,
+};
+
+static int rn5t618_wdt_probe(struct platform_device *pdev)
+{
+	struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
+	struct rn5t618_wdt *wdt;
+	int min_timeout, max_timeout;
+
+	wdt = devm_kzalloc(&pdev->dev, sizeof(struct rn5t618_wdt), GFP_KERNEL);
+	if (!wdt)
+		return -ENOMEM;
+
+	min_timeout = rn5t618_wdt_map[0].time;
+	max_timeout = rn5t618_wdt_map[ARRAY_SIZE(rn5t618_wdt_map) - 1].time;
+
+	wdt->rn5t618 = rn5t618;
+	wdt->wdt_dev.info = &rn5t618_wdt_info;
+	wdt->wdt_dev.ops = &rn5t618_wdt_ops;
+	wdt->wdt_dev.min_timeout = min_timeout;
+	wdt->wdt_dev.max_timeout = max_timeout;
+	wdt->wdt_dev.timeout = max_timeout;
+	wdt->wdt_dev.parent = &pdev->dev;
+
+	watchdog_set_drvdata(&wdt->wdt_dev, wdt);
+	watchdog_init_timeout(&wdt->wdt_dev, heartbeat, &pdev->dev);
+	watchdog_set_nowayout(&wdt->wdt_dev, nowayout);
+
+	return watchdog_register_device(&wdt->wdt_dev);
+}
+
+static int rn5t618_wdt_remove(struct platform_device *pdev)
+{
+	struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
+
+	watchdog_unregister_device(wdt_dev);
+
+	return 0;
+}
+
+static struct platform_driver rn5t618_wdt_driver = {
+	.probe = rn5t618_wdt_probe,
+	.remove = rn5t618_wdt_remove,
+	.driver = {
+		.name	= DRIVER_NAME,
+	},
+};
+
+module_platform_driver(rn5t618_wdt_driver);
+
+MODULE_AUTHOR("Beniamino Galvani <[email protected]>");
+MODULE_DESCRIPTION("RN5T618 watchdog driver");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/rn5t618.h +4 -0
index e3571d1..c72d534 100644
@@ -202,6 +202,10 @@
 
 #define RN5T618_REPCNT_REPWRON		BIT(0)
 #define RN5T618_SLPCNT_SWPWROFF		BIT(0)
+#define RN5T618_WATCHDOG_WDOGEN		BIT(2)
+#define RN5T618_WATCHDOG_WDOGTIM_M	(BIT(0) | BIT(1))
+#define RN5T618_WATCHDOG_WDOGTIM_S	0
+#define RN5T618_PWRIRQ_IR_WDOG		BIT(6)
 
 enum {
 	RN5T618_DCDC1,
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
maintainer
#13 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

Quoted 4 lines · Lee Jones

Wim,

Still waiting on a Watchdog Ack, so I can take this set in.

Wasn't there a more recent version of this patch ?

Thanks,
Guenter

Quoted 262 lines
Quoted 262 lines

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
drivers/watchdog/Kconfig +11 -0
index f57312f..9eba6af 100644
@@ -309,6 +309,17 @@ config ORION_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called orion_wdt.
 
+config RN5T618_WATCHDOG
+	tristate "Ricoh RN5T618 watchdog"
+	depends on MFD_RN5T618
+	select WATCHDOG_CORE
+	help
+	  If you say yes here you get support for watchdog on the Ricoh
+	  RN5T618 PMIC.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called rn5t618_wdt.
+
 config SUNXI_WATCHDOG
 	tristate "Allwinner SoCs watchdog support"
 	depends on ARCH_SUNXI
drivers/watchdog/Makefile +1 -0
index 468c320..0afa343 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
 obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
 obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
 obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o
+obj-$(CONFIG_RN5T618_WATCHDOG) += rn5t618_wdt.o
 obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
 obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
drivers/watchdog/rn5t618_wdt.c new file +196 -0
new file mode 100644
index 0000000..3a76ad7
@@ -0,0 +1,196 @@
+/*
+ * Watchdog driver for Ricoh RN5T618 PMIC
+ *
+ * Copyright (C) 2014 Beniamino Galvani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/mfd/rn5t618.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
+#define DRIVER_NAME "rn5t618-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+static unsigned int heartbeat = -1;
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
+
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct rn5t618_wdt {
+	struct watchdog_device wdt_dev;
+	struct rn5t618 *rn5t618;
+};
+
+/*
+ * This array encodes the values of WDOGTIM field for the supported
+ * watchdog expiration times. If the watchdog is not accessed before
+ * the timer expiration, the PMU generates an interrupt and if the CPU
+ * doesn't clear it within one second the system is restarted.
+ */
+static const struct {
+	u8 reg_val;
+	int time;
+} rn5t618_wdt_map[] = {
+	{ 0, 1 },
+	{ 1, 8 },
+	{ 2, 32 },
+	{ 3, 128 },
+};
+
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;
+	else
+		ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+					 RN5T618_WATCHDOG_WDOGTIM_M,
+					 rn5t618_wdt_map[i].reg_val);
+	if (!ret)
+		wdt_dev->timeout = rn5t618_wdt_map[i].time;
+
+	return ret;
+}
+
+static int rn5t618_wdt_start(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret;
+
+	ret = rn5t618_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
+	if (ret)
+		return ret;
+
+	/* enable repower-on */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_REPCNT,
+				 RN5T618_REPCNT_REPWRON,
+				 RN5T618_REPCNT_REPWRON);
+	if (ret)
+		return ret;
+
+	/* enable watchdog */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				 RN5T618_WATCHDOG_WDOGEN,
+				 RN5T618_WATCHDOG_WDOGEN);
+	if (ret)
+		return ret;
+
+	/* enable watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIREN,
+				  RN5T618_PWRIRQ_IR_WDOG,
+				  RN5T618_PWRIRQ_IR_WDOG);
+}
+
+static int rn5t618_wdt_stop(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				  RN5T618_WATCHDOG_WDOGEN, 0);
+}
+
+static int rn5t618_wdt_ping(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned int val;
+	int ret;
+
+	/* The counter is restarted after a R/W access to watchdog register */
+	ret = regmap_read(wdt->rn5t618->regmap, RN5T618_WATCHDOG, &val);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(wdt->rn5t618->regmap, RN5T618_WATCHDOG, val);
+	if (ret)
+		return ret;
+
+	/* Clear pending watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIRQ,
+				  RN5T618_PWRIRQ_IR_WDOG, 0);
+}
+
+static struct watchdog_info rn5t618_wdt_info = {
+	.options	= WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE |
+			  WDIOF_KEEPALIVEPING,
+	.identity	= DRIVER_NAME,
+};
+
+static struct watchdog_ops rn5t618_wdt_ops = {
+	.owner          = THIS_MODULE,
+	.start          = rn5t618_wdt_start,
+	.stop           = rn5t618_wdt_stop,
+	.ping           = rn5t618_wdt_ping,
+	.set_timeout    = rn5t618_wdt_set_timeout,
+};
+
+static int rn5t618_wdt_probe(struct platform_device *pdev)
+{
+	struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
+	struct rn5t618_wdt *wdt;
+	int min_timeout, max_timeout;
+
+	wdt = devm_kzalloc(&pdev->dev, sizeof(struct rn5t618_wdt), GFP_KERNEL);
+	if (!wdt)
+		return -ENOMEM;
+
+	min_timeout = rn5t618_wdt_map[0].time;
+	max_timeout = rn5t618_wdt_map[ARRAY_SIZE(rn5t618_wdt_map) - 1].time;
+
+	wdt->rn5t618 = rn5t618;
+	wdt->wdt_dev.info = &rn5t618_wdt_info;
+	wdt->wdt_dev.ops = &rn5t618_wdt_ops;
+	wdt->wdt_dev.min_timeout = min_timeout;
+	wdt->wdt_dev.max_timeout = max_timeout;
+	wdt->wdt_dev.timeout = max_timeout;
+	wdt->wdt_dev.parent = &pdev->dev;
+
+	watchdog_set_drvdata(&wdt->wdt_dev, wdt);
+	watchdog_init_timeout(&wdt->wdt_dev, heartbeat, &pdev->dev);
+	watchdog_set_nowayout(&wdt->wdt_dev, nowayout);
+
+	return watchdog_register_device(&wdt->wdt_dev);
+}
+
+static int rn5t618_wdt_remove(struct platform_device *pdev)
+{
+	struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
+
+	watchdog_unregister_device(wdt_dev);
+
+	return 0;
+}
+
+static struct platform_driver rn5t618_wdt_driver = {
+	.probe = rn5t618_wdt_probe,
+	.remove = rn5t618_wdt_remove,
+	.driver = {
+		.name	= DRIVER_NAME,
+	},
+};
+
+module_platform_driver(rn5t618_wdt_driver);
+
+MODULE_AUTHOR("Beniamino Galvani <[email protected]>");
+MODULE_DESCRIPTION("RN5T618 watchdog driver");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/rn5t618.h +4 -0
index e3571d1..c72d534 100644
@@ -202,6 +202,10 @@
 
 #define RN5T618_REPCNT_REPWRON		BIT(0)
 #define RN5T618_SLPCNT_SWPWROFF		BIT(0)
+#define RN5T618_WATCHDOG_WDOGEN		BIT(2)
+#define RN5T618_WATCHDOG_WDOGTIM_M	(BIT(0) | BIT(1))
+#define RN5T618_WATCHDOG_WDOGTIM_S	0
+#define RN5T618_PWRIRQ_IR_WDOG		BIT(6)
 
Quoted 12 lines
Quoted 2 lines
include/linux/mfd/rn5t618.h +0 -0
 enum {
 	RN5T618_DCDC1,
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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

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

#14 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

Quoted 6 lines · Guenter Roeck
Quoted 4 lines · Lee Jones

Wim,

Still waiting on a Watchdog Ack, so I can take this set in.

Wasn't there a more recent version of this patch ?

Yes, this is superseded by v2.

Beniamino

#17 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

In reply to Beniamino Galvani

Hi Beniamino,

Quoted 69 lines

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
drivers/watchdog/Kconfig +11 -0
index f57312f..9eba6af 100644
@@ -309,6 +309,17 @@ config ORION_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called orion_wdt.
 
+config RN5T618_WATCHDOG
+	tristate "Ricoh RN5T618 watchdog"
+	depends on MFD_RN5T618
+	select WATCHDOG_CORE
+	help
+	  If you say yes here you get support for watchdog on the Ricoh
+	  RN5T618 PMIC.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called rn5t618_wdt.
+
 config SUNXI_WATCHDOG
 	tristate "Allwinner SoCs watchdog support"
 	depends on ARCH_SUNXI
drivers/watchdog/Makefile +1 -0
index 468c320..0afa343 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
 obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
 obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
 obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o
+obj-$(CONFIG_RN5T618_WATCHDOG) += rn5t618_wdt.o
 obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
 obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
drivers/watchdog/rn5t618_wdt.c new file +16 -0
new file mode 100644
index 0000000..3a76ad7
@@ -0,0 +1,196 @@
+/*
+ * Watchdog driver for Ricoh RN5T618 PMIC
+ *
+ * Copyright (C) 2014 Beniamino Galvani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/mfd/rn5t618.h>
+#include <linux/module.h>

drivers/watchdog/rn5t618_wdt.c line 26

Quoted 10 lines
drivers/watchdog/rn5t618_wdt.c new file +10 -0
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
+#define DRIVER_NAME "rn5t618-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+static unsigned int heartbeat = -1;
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");

1) this is actually a timeout value and not the same as the heartbeat of the watchdog device. So I prefer this also to be called as timeout and not heartbeat.
2) this actually is an unsigned int.

For the rest OK by me.

Kind regards,
Wim.

Quoted 188 lines
drivers/watchdog/rn5t618_wdt.c new file +170 -0
+
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+struct rn5t618_wdt {
+	struct watchdog_device wdt_dev;
+	struct rn5t618 *rn5t618;
+};
+
+/*
+ * This array encodes the values of WDOGTIM field for the supported
+ * watchdog expiration times. If the watchdog is not accessed before
+ * the timer expiration, the PMU generates an interrupt and if the CPU
+ * doesn't clear it within one second the system is restarted.
+ */
+static const struct {
+	u8 reg_val;
+	int time;
+} rn5t618_wdt_map[] = {
+	{ 0, 1 },
+	{ 1, 8 },
+	{ 2, 32 },
+	{ 3, 128 },
+};
+
+static int rn5t618_wdt_set_timeout(struct watchdog_device *wdt_dev,
+				   unsigned int timeout)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(rn5t618_wdt_map); i++) {
+		if (rn5t618_wdt_map[i].time + 1 >= timeout)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(rn5t618_wdt_map))
+		ret = -EINVAL;
+	else
+		ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+					 RN5T618_WATCHDOG_WDOGTIM_M,
+					 rn5t618_wdt_map[i].reg_val);
+	if (!ret)
+		wdt_dev->timeout = rn5t618_wdt_map[i].time;
+
+	return ret;
+}
+
+static int rn5t618_wdt_start(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	int ret;
+
+	ret = rn5t618_wdt_set_timeout(wdt_dev, wdt_dev->timeout);
+	if (ret)
+		return ret;
+
+	/* enable repower-on */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_REPCNT,
+				 RN5T618_REPCNT_REPWRON,
+				 RN5T618_REPCNT_REPWRON);
+	if (ret)
+		return ret;
+
+	/* enable watchdog */
+	ret = regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				 RN5T618_WATCHDOG_WDOGEN,
+				 RN5T618_WATCHDOG_WDOGEN);
+	if (ret)
+		return ret;
+
+	/* enable watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIREN,
+				  RN5T618_PWRIRQ_IR_WDOG,
+				  RN5T618_PWRIRQ_IR_WDOG);
+}
+
+static int rn5t618_wdt_stop(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_WATCHDOG,
+				  RN5T618_WATCHDOG_WDOGEN, 0);
+}
+
+static int rn5t618_wdt_ping(struct watchdog_device *wdt_dev)
+{
+	struct rn5t618_wdt *wdt = watchdog_get_drvdata(wdt_dev);
+	unsigned int val;
+	int ret;
+
+	/* The counter is restarted after a R/W access to watchdog register */
+	ret = regmap_read(wdt->rn5t618->regmap, RN5T618_WATCHDOG, &val);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(wdt->rn5t618->regmap, RN5T618_WATCHDOG, val);
+	if (ret)
+		return ret;
+
+	/* Clear pending watchdog interrupt */
+	return regmap_update_bits(wdt->rn5t618->regmap, RN5T618_PWRIRQ,
+				  RN5T618_PWRIRQ_IR_WDOG, 0);
+}
+
+static struct watchdog_info rn5t618_wdt_info = {
+	.options	= WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE |
+			  WDIOF_KEEPALIVEPING,
+	.identity	= DRIVER_NAME,
+};
+
+static struct watchdog_ops rn5t618_wdt_ops = {
+	.owner          = THIS_MODULE,
+	.start          = rn5t618_wdt_start,
+	.stop           = rn5t618_wdt_stop,
+	.ping           = rn5t618_wdt_ping,
+	.set_timeout    = rn5t618_wdt_set_timeout,
+};
+
+static int rn5t618_wdt_probe(struct platform_device *pdev)
+{
+	struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
+	struct rn5t618_wdt *wdt;
+	int min_timeout, max_timeout;
+
+	wdt = devm_kzalloc(&pdev->dev, sizeof(struct rn5t618_wdt), GFP_KERNEL);
+	if (!wdt)
+		return -ENOMEM;
+
+	min_timeout = rn5t618_wdt_map[0].time;
+	max_timeout = rn5t618_wdt_map[ARRAY_SIZE(rn5t618_wdt_map) - 1].time;
+
+	wdt->rn5t618 = rn5t618;
+	wdt->wdt_dev.info = &rn5t618_wdt_info;
+	wdt->wdt_dev.ops = &rn5t618_wdt_ops;
+	wdt->wdt_dev.min_timeout = min_timeout;
+	wdt->wdt_dev.max_timeout = max_timeout;
+	wdt->wdt_dev.timeout = max_timeout;
+	wdt->wdt_dev.parent = &pdev->dev;
+
+	watchdog_set_drvdata(&wdt->wdt_dev, wdt);
+	watchdog_init_timeout(&wdt->wdt_dev, heartbeat, &pdev->dev);
+	watchdog_set_nowayout(&wdt->wdt_dev, nowayout);
+
+	return watchdog_register_device(&wdt->wdt_dev);
+}
+
+static int rn5t618_wdt_remove(struct platform_device *pdev)
+{
+	struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
+
+	watchdog_unregister_device(wdt_dev);
+
+	return 0;
+}
+
+static struct platform_driver rn5t618_wdt_driver = {
+	.probe = rn5t618_wdt_probe,
+	.remove = rn5t618_wdt_remove,
+	.driver = {
+		.name	= DRIVER_NAME,
+	},
+};
+
+module_platform_driver(rn5t618_wdt_driver);
+
+MODULE_AUTHOR("Beniamino Galvani <[email protected]>");
+MODULE_DESCRIPTION("RN5T618 watchdog driver");
+MODULE_LICENSE("GPL v2");
include/linux/mfd/rn5t618.h +4 -0
index e3571d1..c72d534 100644
@@ -202,6 +202,10 @@
 
 #define RN5T618_REPCNT_REPWRON		BIT(0)
 #define RN5T618_SLPCNT_SWPWROFF		BIT(0)
+#define RN5T618_WATCHDOG_WDOGEN		BIT(2)
+#define RN5T618_WATCHDOG_WDOGTIM_M	(BIT(0) | BIT(1))
+#define RN5T618_WATCHDOG_WDOGTIM_S	0
+#define RN5T618_PWRIRQ_IR_WDOG		BIT(6)
 
 enum {
 	RN5T618_DCDC1,
Signature · 1 line
1.7.10.4
#15 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

In reply to Lee Jones

Hi Lee,

Quoted 74 lines

Still waiting on a Watchdog Ack, so I can take this set in.

Quoted 72 lines

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
drivers/watchdog/Kconfig +11 -0
index f57312f..9eba6af 100644
@@ -309,6 +309,17 @@ config ORION_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called orion_wdt.
 
+config RN5T618_WATCHDOG
+	tristate "Ricoh RN5T618 watchdog"
+	depends on MFD_RN5T618
+	select WATCHDOG_CORE
+	help
+	  If you say yes here you get support for watchdog on the Ricoh
+	  RN5T618 PMIC.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called rn5t618_wdt.
+
 config SUNXI_WATCHDOG
 	tristate "Allwinner SoCs watchdog support"
 	depends on ARCH_SUNXI
drivers/watchdog/Makefile +1 -0
index 468c320..0afa343 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
 obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
 obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
 obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o
+obj-$(CONFIG_RN5T618_WATCHDOG) += rn5t618_wdt.o
 obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
 obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
drivers/watchdog/rn5t618_wdt.c new file +19 -0
new file mode 100644
index 0000000..3a76ad7
@@ -0,0 +1,196 @@
+/*
+ * Watchdog driver for Ricoh RN5T618 PMIC
+ *
+ * Copyright (C) 2014 Beniamino Galvani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/mfd/rn5t618.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
Quoted 8 lines

drivers/watchdog/rn5t618_wdt.c line 27

Quoted 8 lines
drivers/watchdog/rn5t618_wdt.c new file +8 -0
+#define DRIVER_NAME "rn5t618-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+static unsigned int heartbeat = -1;
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
+

These are the comments I just mailed:
1) this is actually a timeout value and not the same as the heartbeat of the watchdog device. So I prefer this also to be called as timeout and not heartbeat.
2) this actually is an unsigned int.

For the rest OK by me.

Kind regards,
Wim.

#16 lore raw

Re: [PATCH 3/4] watchdog: add driver for Ricoh RN5T618 watchdog

Quoted 90 lines · Wim Van Sebroeck

Hi Lee,

Quoted 74 lines

Still waiting on a Watchdog Ack, so I can take this set in.

Quoted 72 lines

This adds a driver for the watchdog timer available in Ricoh RN5T618 PMIC. The device supports a programmable expiration time of 1, 8, 32 or 128 seconds.

---
 drivers/watchdog/Kconfig       |   11 +++
 drivers/watchdog/Makefile      |    1 +
 drivers/watchdog/rn5t618_wdt.c |  196 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rn5t618.h    |    4 +
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/watchdog/rn5t618_wdt.c
drivers/watchdog/Kconfig +11 -0
index f57312f..9eba6af 100644
@@ -309,6 +309,17 @@ config ORION_WATCHDOG
 	  To compile this driver as a module, choose M here: the
 	  module will be called orion_wdt.
 
+config RN5T618_WATCHDOG
+	tristate "Ricoh RN5T618 watchdog"
+	depends on MFD_RN5T618
+	select WATCHDOG_CORE
+	help
+	  If you say yes here you get support for watchdog on the Ricoh
+	  RN5T618 PMIC.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called rn5t618_wdt.
+
 config SUNXI_WATCHDOG
 	tristate "Allwinner SoCs watchdog support"
 	depends on ARCH_SUNXI
drivers/watchdog/Makefile +1 -0
index 468c320..0afa343 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o
 obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o
 obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o
 obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o
+obj-$(CONFIG_RN5T618_WATCHDOG) += rn5t618_wdt.o
 obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o
 obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
drivers/watchdog/rn5t618_wdt.c new file +19 -0
new file mode 100644
index 0000000..3a76ad7
@@ -0,0 +1,196 @@
+/*
+ * Watchdog driver for Ricoh RN5T618 PMIC
+ *
+ * Copyright (C) 2014 Beniamino Galvani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/mfd/rn5t618.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+
Quoted 8 lines

drivers/watchdog/rn5t618_wdt.c line 27

Quoted 8 lines
drivers/watchdog/rn5t618_wdt.c new file +8 -0
+#define DRIVER_NAME "rn5t618-wdt"
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+static unsigned int heartbeat = -1;
+
+module_param(heartbeat, int, 0);
+MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
+

These are the comments I just mailed:
1) this is actually a timeout value and not the same as the heartbeat of the watchdog device. So I prefer this also to be called as timeout and not heartbeat.
2) this actually is an unsigned int.

Quoted 1 line

For the rest OK by me.

Hi Wim,

there was a more recent version of the patch [1] , but your comments were still valid. I addressed your suggestions in v3 of the patch [2].

Beniamino

[1] http://lwn.net/Articles/610000/
[2] https://lkml.org/lkml/2014/9/28/173