All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1 00/13] support ROHM BD70528 PMIC
@ 2019-01-22  9:41 Matti Vaittinen
  2019-01-22  9:42 ` [RFC PATCH v1 01/13] regmap: regmap-irq: Add main status register support Matti Vaittinen
                   ` (12 more replies)
  0 siblings, 13 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:41 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

Patch series introducing support for ROHM BD70528 PMIC

Please note that patch 2 breaks compilation without patches 3 and 4

ROHM BD70528 is a programmable Power Management IC for battery
powered 'ultra low power' systems like the pre-announced NXP
i.MX7 ULP. This patch series introduces support for the PMIC.

I send this a RFC now as I would like to receive comments from
Lee, Mark and Stephen regarding splitting the existing
include/linux/mfd/bd718x7.h into ROHM generic and chip specific
portions. Benefit is that for example the clk sub-driver does
not need to be aware of chip specific structure(s) (struct
bd718x7 and struct bd70528) as it only needs to derefernce the
generic struct rohm_regmap_dev. Thus same clk subdriver can
support both the bd718x7 and bd70528 as long as MFD driver
data has this generic structure in the beginning of allocated
data. But knowing the bd718x7 driver is already in upstream,
it might be good if this change went through single tree, right?

Another 'RFC' item is 'main register support' for regmap-irq.
This has been initially discussed with Mark in these mail threads

Option 1
https://lore.kernel.org/lkml/20181217185014.GH27909@sirena.org.uk/

Option 2
https://lore.kernel.org/lkml/20181218085803.GD2477@localhost.localdomain/

But I think it is Ok to show it to wider audience with this real
usage example.

RTC block of the bd70528 can support 'wake' irq which wakes PMIC
from standby state. Wake irq's can be armed to wake up system up
to 24 hours from arming. bd70528 can also generate alarm interrupts
which can be armed to occur years after triggering. The RTC driver
does always arm both the waker and alarm irqs and does not utilize
longer period of alarm interrupts. All the RTC timers are limited
to occur within the next 24 hours. Any suggestions on more elegant
timer support are welcome =)

GPIO portion of bd70528 driver adds I/O support for driving GPIO
pins or reading the state. The interrupt functionality is provided
by regmap-irq. Current GPIO driver is not aware of whether the pin(s)
are used for I/O or interrupts and it is up-to driver user to
ensure there is no misconfiguration or "double use".

Currently only MFD core, clk, RTC and regulator portions are
somehow tested. The RFC series also include initial gpio, power-supply
and watchdog patches in order to provide better overview on chip
and to collect initial feedback. Reset and ADC are not supported by
this series.

Patch 1:
	regmap-irq, 'main status register support'. See discussion
	https://lore.kernel.org/lkml/20181217185014.GH27909@sirena.org.uk/
Patch 2:
	split the bd718x7.h to generic and chip specific portions.
	(breaks compilation without patch 3 and 4)
Patch 3:
	adapt bd718x7.h changes to bd718x7 regulator driver
Patch 4:
	adapt bd718x7.h changes to bd718x7 clk driver
Patch 5:
	add MFD core support for bd70528
Patch 6:
	support bd70528 clk using bd718x7 clk driver
Patch 7:
	document DT bindings for BD70528
Patch 8:
	support bd70528 regulators
Patch 9:
	document regulator DT bindings for BD70528
Patch 10:
	support BD70528 GPIO block
Patch 11:
	support BD70528 RTC
Patch 12:
	support BD70528 battery charger
Patch 13:
	support BD70528 watchdog

This patch series is based on Mark's regulator/for-next branch

---

Matti Vaittinen (13):
  regmap: regmap-irq: Add main status register support
  mfd: bd718x7.h split to ROHM common and bd718x7 specific parts
  regulator: bd718x7 use chip specific and generic data structs
  clk: bd718x7: use chip specific and generic data structs
  mfd: bd70528: Support ROHM bd70528 PMIC - core
  clk: bd718x7: Support ROHM BD70528 clk block
  devicetree: bindings: Document first ROHM BD70528 bindings
  regulator: bd70528: Support ROHM BD70528 regulator block
  devicetree: bindings: ROHM bd70528 regulator bindings
  gpio: Initial support for ROHM bd70528 GPIO block
  rtc: bd70528: Initial support for ROHM bd70528 RTC
  power: supply: Initial support for ROHM BD70528 PMIC charger block
  watchdog: bd70528: Initial support for ROHM BD70528 watchdog block

 .../devicetree/bindings/mfd/rohm,bd70528-pmic.txt  | 104 ++++
 .../bindings/regulator/rohm,bd70528-regulator.txt  |  68 +++
 drivers/base/regmap/regmap-irq.c                   |  99 ++-
 drivers/clk/Kconfig                                |   6 +-
 drivers/clk/clk-bd718x7.c                          |  25 +-
 drivers/gpio/Kconfig                               |  11 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-bd70528.c                        | 192 ++++++
 drivers/mfd/Kconfig                                |  17 +
 drivers/mfd/Makefile                               |   1 +
 drivers/mfd/rohm-bd70528.c                         | 409 +++++++++++++
 drivers/mfd/rohm-bd718x7.c                         |  23 +-
 drivers/power/supply/Kconfig                       |   9 +
 drivers/power/supply/Makefile                      |   1 +
 drivers/power/supply/bd70528-charger.c             | 670 +++++++++++++++++++++
 drivers/regulator/Kconfig                          |  11 +
 drivers/regulator/Makefile                         |   1 +
 drivers/regulator/bd70528-regulator.c              | 290 +++++++++
 drivers/regulator/bd718x7-regulator.c              |  22 +-
 drivers/rtc/Kconfig                                |   8 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-bd70528.c                          | 439 ++++++++++++++
 drivers/watchdog/Kconfig                           |  12 +
 drivers/watchdog/Makefile                          |   1 +
 drivers/watchdog/bd70528_wdt.c                     | 161 +++++
 include/linux/mfd/rohm-bd70528.h                   | 392 ++++++++++++
 include/linux/mfd/rohm-bd718x7.h                   |  22 +-
 include/linux/mfd/rohm-generic.h                   |  20 +
 include/linux/regmap.h                             |  31 +
 29 files changed, 2998 insertions(+), 49 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
 create mode 100644 Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt
 create mode 100644 drivers/gpio/gpio-bd70528.c
 create mode 100644 drivers/mfd/rohm-bd70528.c
 create mode 100644 drivers/power/supply/bd70528-charger.c
 create mode 100644 drivers/regulator/bd70528-regulator.c
 create mode 100644 drivers/rtc/rtc-bd70528.c
 create mode 100644 drivers/watchdog/bd70528_wdt.c
 create mode 100644 include/linux/mfd/rohm-bd70528.h
 create mode 100644 include/linux/mfd/rohm-generic.h

-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 01/13] regmap: regmap-irq: Add main status register support
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
@ 2019-01-22  9:42 ` Matti Vaittinen
  2019-01-23 15:55   ` Mark Brown
  2019-01-22  9:42 ` [RFC PATCH v1 02/13] mfd: bd718x7.h split to ROHM common and bd718x7 specific parts Matti Vaittinen
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:42 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

There is bunch of devices with multiple logical blocks which
can generate interrupts. It's not a rare case that the interrupt
reason registers are arranged so that there is own status/ack/mask
register for each logical block. In some devices there is also a
'main interrupt register(s)' which can indicate what sub blocks
have interrupts pending.

When such a device is connected via slow bus like i2c the main
part of interrupt handling latency can be caused by bus accesses.
On systems where it is expected that only one (or few) sub blocks
have active interrupts we can reduce the latency by only reading
the main register and those sub registers which have active
interrupts. Support this with regmap-irq for simple cases where
main register does not require acking or masking.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/base/regmap/regmap-irq.c | 99 ++++++++++++++++++++++++++++++++++++++--
 include/linux/regmap.h           | 31 +++++++++++++
 2 files changed, 126 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 1bd1145ad8b5..22778e9501ff 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -35,6 +35,7 @@ struct regmap_irq_chip_data {
 	int wake_count;
 
 	void *status_reg_buf;
+	unsigned int *main_status_buf;
 	unsigned int *status_buf;
 	unsigned int *mask_buf;
 	unsigned int *mask_buf_def;
@@ -326,6 +327,33 @@ static const struct irq_chip regmap_irq_chip = {
 	.irq_set_wake		= regmap_irq_set_wake,
 };
 
+static inline int read_sub_irq_data(struct regmap_irq_chip_data *data,
+					   unsigned int b)
+{
+	const struct regmap_irq_chip *chip = data->chip;
+	struct regmap *map = data->map;
+	struct regmap_irq_sub_irq_map *subreg;
+	int i, ret = 0;
+
+	if (!chip->sub_reg_offsets) {
+		/* Assume linear mapping */
+		ret = regmap_read(map, chip->status_base +
+				  (b * map->reg_stride * data->irq_reg_stride),
+				   &data->status_buf[b]);
+	} else {
+		subreg = &chip->sub_reg_offsets[b];
+		for (i = 0; i < subreg->num_regs; i++) {
+			unsigned int offset = subreg->offset[i];
+
+			ret = regmap_read(map, chip->status_base + offset,
+					  &data->status_buf[offset]);
+			if (ret)
+				break;
+		}
+	}
+	return ret;
+}
+
 static irqreturn_t regmap_irq_thread(int irq, void *d)
 {
 	struct regmap_irq_chip_data *data = d;
@@ -349,11 +377,65 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 	}
 
 	/*
-	 * Read in the statuses, using a single bulk read if possible
-	 * in order to reduce the I/O overheads.
+	 * Read only registers with active IRQs if the chip has 'main status
+	 * register'. Else read in the statuses, using a single bulk read if
+	 * possible in order to reduce the I/O overheads.
 	 */
-	if (!map->use_single_read && map->reg_stride == 1 &&
-	    data->irq_reg_stride == 1) {
+
+	if (chip->num_main_regs) {
+		unsigned int max_main_bits;
+		unsigned long size;
+
+		size = chip->num_regs * sizeof(unsigned int);
+
+		max_main_bits = (chip->num_main_status_bits) ?
+				 chip->num_main_status_bits : chip->num_regs;
+		/* Clear the status buf as we don't read all status regs */
+		memset(data->status_buf, 0, size);
+
+		/* We could support bulk read for main status registers
+		 * but I don't expect to see devices with really many main
+		 * status registers so let's only support single reads for the
+		 * sake of simplicity. and add bulk reads only if needed
+		 */
+		for (i = 0; i < chip->num_main_regs; i++) {
+			ret = regmap_read(map, chip->main_status +
+				  (i * map->reg_stride
+				   * data->irq_reg_stride),
+				  &data->main_status_buf[i]);
+			if (ret) {
+				dev_err(map->dev,
+					"Failed to read IRQ status %d\n",
+					ret);
+				goto exit;
+			}
+		}
+
+		/* Read sub registers with active IRQs */
+		for (i = 0; i < chip->num_main_regs; i++) {
+			unsigned int b;
+			const unsigned long mreg = data->main_status_buf[i];
+
+			for_each_set_bit(b, &mreg, map->format.val_bytes * 8) {
+				if (i * map->format.val_bytes * 8 + b >
+				    max_main_bits)
+					break;
+				ret = read_sub_irq_data(data, b);
+
+				if (ret != 0) {
+					dev_err(map->dev,
+						"Failed to read IRQ status %d\n",
+						ret);
+					if (chip->runtime_pm)
+						pm_runtime_put(map->dev);
+					goto exit;
+				}
+			}
+
+		}
+	} else if (!map->use_single_read && map->reg_stride == 1 &&
+		   data->irq_reg_stride == 1) {
+
 		u8 *buf8 = data->status_reg_buf;
 		u16 *buf16 = data->status_reg_buf;
 		u32 *buf32 = data->status_reg_buf;
@@ -518,6 +600,15 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
 	if (!d)
 		return -ENOMEM;
 
+	if (chip->num_main_regs) {
+		d->main_status_buf = kcalloc(chip->num_main_regs,
+					     sizeof(unsigned int),
+					     GFP_KERNEL);
+
+		if (!d->main_status_buf)
+			goto err_alloc;
+	}
+
 	d->status_buf = kcalloc(chip->num_regs, sizeof(unsigned int),
 				GFP_KERNEL);
 	if (!d->status_buf)
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 1781b6cb793c..daeec7dbd65c 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1131,11 +1131,37 @@ struct regmap_irq {
 		.reg_offset = (_id) / (_reg_bits),	\
 	}
 
+#define REGMAP_IRQ_MAIN_REG_OFFSET(arr)				\
+	{ .num_regs = ARRAY_SIZE((arr)), .offset = &(arr)[0] }
+
+struct regmap_irq_sub_irq_map {
+	unsigned int num_regs;
+	unsigned int *offset;
+};
+
 /**
  * struct regmap_irq_chip - Description of a generic regmap irq_chip.
  *
  * @name:        Descriptive name for IRQ controller.
  *
+ * @main_status: Base main status register address. For chips which have
+ *		 interrupts arranged in separate sub-irq blocks with own IRQ
+ *		 registers and which have a main IRQ registers indicating
+ *		 sub-irq blocks with unhandled interrupts. For such chips fill
+ *		 sub-irq register information in status_base, mask_base and
+ *		 ack_base.
+ * @num_main_status_bits: Should be given to chips where number of meaningfull
+ *			  main status bits differs from num_regs.
+ * @sub_reg_offsets: arrays of mappings from main register bits to sub irq
+ *		     registers. First item in array describes the registers
+ *		     for first main status bit. Second array for second bit etc.
+ *		     Offset is given as sub register status offset to
+ *		     status_base. Should contain num_regs arrays.
+ *		     Can be provided for chips with more complex mapping than
+ *		     1.st bit to 1.st sub-reg, 2.nd bit to 2.nd sub-reg, ...
+ * @num_main_regs: Number of 'main status' irq registers for chips which have
+ *		   main_status set.
+ *
  * @status_base: Base status register address.
  * @mask_base:   Base mask register address.
  * @mask_writeonly: Base mask register is write only.
@@ -1181,6 +1207,11 @@ struct regmap_irq {
 struct regmap_irq_chip {
 	const char *name;
 
+	unsigned int main_status;
+	unsigned int num_main_status_bits;
+	struct regmap_irq_sub_irq_map *sub_reg_offsets;
+	int num_main_regs;
+
 	unsigned int status_base;
 	unsigned int mask_base;
 	unsigned int unmask_base;
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 02/13] mfd: bd718x7.h split to ROHM common and bd718x7 specific parts
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
  2019-01-22  9:42 ` [RFC PATCH v1 01/13] regmap: regmap-irq: Add main status register support Matti Vaittinen
@ 2019-01-22  9:42 ` Matti Vaittinen
  2019-01-22  9:43 ` [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs Matti Vaittinen
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:42 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

Split the bd718x7.h to ROHM common and bd718x7 specific parts
so that we do not need to add same things in every new ROHM
PMIC header. Please note that this change requires changes also
in bd718x7 sub-device drivers for regulators and clk.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/mfd/rohm-bd718x7.c       | 23 ++++++++++++-----------
 include/linux/mfd/rohm-bd718x7.h | 22 ++++++++--------------
 include/linux/mfd/rohm-generic.h | 20 ++++++++++++++++++++
 3 files changed, 40 insertions(+), 25 deletions(-)
 create mode 100644 include/linux/mfd/rohm-generic.h

diff --git a/drivers/mfd/rohm-bd718x7.c b/drivers/mfd/rohm-bd718x7.c
index a29d529a96f4..7beb444a57cb 100644
--- a/drivers/mfd/rohm-bd718x7.c
+++ b/drivers/mfd/rohm-bd718x7.c
@@ -98,18 +98,19 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
 		return -ENOMEM;
 
 	bd718xx->chip_irq = i2c->irq;
-	bd718xx->chip_type = (unsigned int)(uintptr_t)
+	bd718xx->chip.chip_type = (unsigned int)(uintptr_t)
 				of_device_get_match_data(&i2c->dev);
-	bd718xx->dev = &i2c->dev;
+	bd718xx->chip.dev = &i2c->dev;
 	dev_set_drvdata(&i2c->dev, bd718xx);
 
-	bd718xx->regmap = devm_regmap_init_i2c(i2c, &bd718xx_regmap_config);
-	if (IS_ERR(bd718xx->regmap)) {
+	bd718xx->chip.regmap = devm_regmap_init_i2c(i2c,
+						    &bd718xx_regmap_config);
+	if (IS_ERR(bd718xx->chip.regmap)) {
 		dev_err(&i2c->dev, "regmap initialization failed\n");
-		return PTR_ERR(bd718xx->regmap);
+		return PTR_ERR(bd718xx->chip.regmap);
 	}
 
-	ret = devm_regmap_add_irq_chip(&i2c->dev, bd718xx->regmap,
+	ret = devm_regmap_add_irq_chip(&i2c->dev, bd718xx->chip.regmap,
 				       bd718xx->chip_irq, IRQF_ONESHOT, 0,
 				       &bd718xx_irq_chip, &bd718xx->irq_data);
 	if (ret) {
@@ -118,7 +119,7 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
 	}
 
 	/* Configure short press to 10 milliseconds */
-	ret = regmap_update_bits(bd718xx->regmap,
+	ret = regmap_update_bits(bd718xx->chip.regmap,
 				 BD718XX_REG_PWRONCONFIG0,
 				 BD718XX_PWRBTN_PRESS_DURATION_MASK,
 				 BD718XX_PWRBTN_SHORT_PRESS_10MS);
@@ -129,7 +130,7 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
 	}
 
 	/* Configure long press to 10 seconds */
-	ret = regmap_update_bits(bd718xx->regmap,
+	ret = regmap_update_bits(bd718xx->chip.regmap,
 				 BD718XX_REG_PWRONCONFIG1,
 				 BD718XX_PWRBTN_PRESS_DURATION_MASK,
 				 BD718XX_PWRBTN_LONG_PRESS_10S);
@@ -149,7 +150,7 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
 
 	button.irq = ret;
 
-	ret = devm_mfd_add_devices(bd718xx->dev, PLATFORM_DEVID_AUTO,
+	ret = devm_mfd_add_devices(bd718xx->chip.dev, PLATFORM_DEVID_AUTO,
 				   bd718xx_mfd_cells,
 				   ARRAY_SIZE(bd718xx_mfd_cells), NULL, 0,
 				   regmap_irq_get_domain(bd718xx->irq_data));
@@ -162,11 +163,11 @@ static int bd718xx_i2c_probe(struct i2c_client *i2c,
 static const struct of_device_id bd718xx_of_match[] = {
 	{
 		.compatible = "rohm,bd71837",
-		.data = (void *)BD718XX_TYPE_BD71837,
+		.data = (void *)ROHM_CHIP_TYPE_BD71837,
 	},
 	{
 		.compatible = "rohm,bd71847",
-		.data = (void *)BD718XX_TYPE_BD71847,
+		.data = (void *)ROHM_CHIP_TYPE_BD71847,
 	},
 	{ }
 };
diff --git a/include/linux/mfd/rohm-bd718x7.h b/include/linux/mfd/rohm-bd718x7.h
index fd194bfc836f..7f2dbde402a1 100644
--- a/include/linux/mfd/rohm-bd718x7.h
+++ b/include/linux/mfd/rohm-bd718x7.h
@@ -4,14 +4,9 @@
 #ifndef __LINUX_MFD_BD718XX_H__
 #define __LINUX_MFD_BD718XX_H__
 
+#include <linux/mfd/rohm-generic.h>
 #include <linux/regmap.h>
 
-enum {
-	BD718XX_TYPE_BD71837 = 0,
-	BD718XX_TYPE_BD71847,
-	BD718XX_TYPE_AMOUNT
-};
-
 enum {
 	BD718XX_BUCK1 = 0,
 	BD718XX_BUCK2,
@@ -321,18 +316,17 @@ enum {
 	BD718XX_PWRBTN_LONG_PRESS_15S
 };
 
-struct bd718xx_clk;
-
 struct bd718xx {
-	unsigned int chip_type;
-	struct device *dev;
-	struct regmap *regmap;
-	unsigned long int id;
+	/*
+	 * Please keep this as the first member here as some
+	 * drivers (clk) supporting more than one chip may only know this
+	 * generic struct 'struct rohm_regmap_dev' and assume it is
+	 * the first chunk of parent device's private data.
+	 */
+	struct rohm_regmap_dev chip;
 
 	int chip_irq;
 	struct regmap_irq_chip_data *irq_data;
-
-	struct bd718xx_clk *clk;
 };
 
 #endif /* __LINUX_MFD_BD718XX_H__ */
diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
new file mode 100644
index 000000000000..bff15ac26f2c
--- /dev/null
+++ b/include/linux/mfd/rohm-generic.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2018 ROHM Semiconductors */
+
+#ifndef __LINUX_MFD_ROHM_H__
+#define __LINUX_MFD_ROHM_H__
+
+enum {
+	ROHM_CHIP_TYPE_BD71837 = 0,
+	ROHM_CHIP_TYPE_BD71847,
+	ROHM_CHIP_TYPE_BD70528,
+	ROHM_CHIP_TYPE_AMOUNT
+};
+
+struct rohm_regmap_dev {
+	unsigned int chip_type;
+	struct device *dev;
+	struct regmap *regmap;
+};
+
+#endif
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
  2019-01-22  9:42 ` [RFC PATCH v1 01/13] regmap: regmap-irq: Add main status register support Matti Vaittinen
  2019-01-22  9:42 ` [RFC PATCH v1 02/13] mfd: bd718x7.h split to ROHM common and bd718x7 specific parts Matti Vaittinen
@ 2019-01-22  9:43 ` Matti Vaittinen
  2019-01-23 15:51   ` Mark Brown
  2019-01-22  9:44 ` [RFC PATCH v1 04/13] clk: bd718x7: " Matti Vaittinen
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:43 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

Header rohm-bd718x7.h was split to generic and component specific
parts. This changed the struct bd718x7. Adapt the regulator driver to
these changes.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/regulator/bd718x7-regulator.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c
index b8dcdc21dc22..dc56ca06ace2 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -1018,11 +1018,11 @@ static int bd718xx_probe(struct platform_device *pdev)
 	struct bd718xx *mfd;
 	struct regulator_config config = { 0 };
 	struct bd718xx_pmic_inits pmic_regulators[] = {
-		[BD718XX_TYPE_BD71837] = {
+		[ROHM_CHIP_TYPE_BD71837] = {
 			.r_datas = bd71837_regulators,
 			.r_amount = ARRAY_SIZE(bd71837_regulators),
 		},
-		[BD718XX_TYPE_BD71847] = {
+		[ROHM_CHIP_TYPE_BD71847] = {
 			.r_datas = bd71847_regulators,
 			.r_amount = ARRAY_SIZE(bd71847_regulators),
 		},
@@ -1037,15 +1037,15 @@ static int bd718xx_probe(struct platform_device *pdev)
 		goto err;
 	}
 
-	if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
-	    !pmic_regulators[mfd->chip_type].r_datas) {
+	if (mfd->chip.chip_type >= ROHM_CHIP_TYPE_AMOUNT ||
+	    !pmic_regulators[mfd->chip.chip_type].r_datas) {
 		dev_err(&pdev->dev, "Unsupported chip type\n");
 		err = -EINVAL;
 		goto err;
 	}
 
 	/* Register LOCK release */
-	err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
+	err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK,
 				 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
@@ -1065,7 +1065,7 @@ static int bd718xx_probe(struct platform_device *pdev)
 	 * for all reset types because OTP loading at READY will clear SEL
 	 * bit allowing HW defaults for power rails to be used
 	 */
-	err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1,
+	err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_TRANS_COND1,
 				 BD718XX_ON_REQ_POWEROFF_MASK |
 				 BD718XX_SWRESET_POWEROFF_MASK |
 				 BD718XX_WDOG_POWEROFF_MASK |
@@ -1078,17 +1078,17 @@ static int bd718xx_probe(struct platform_device *pdev)
 		dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n");
 	}
 
-	for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
+	for (i = 0; i < pmic_regulators[mfd->chip.chip_type].r_amount; i++) {
 
 		const struct regulator_desc *desc;
 		struct regulator_dev *rdev;
 		const struct bd718xx_regulator_data *r;
 
-		r = &pmic_regulators[mfd->chip_type].r_datas[i];
+		r = &pmic_regulators[mfd->chip.chip_type].r_datas[i];
 		desc = &r->desc;
 
 		config.dev = pdev->dev.parent;
-		config.regmap = mfd->regmap;
+		config.regmap = mfd->chip.regmap;
 
 		rdev = devm_regulator_register(&pdev->dev, desc, &config);
 		if (IS_ERR(rdev)) {
@@ -1104,7 +1104,7 @@ static int bd718xx_probe(struct platform_device *pdev)
 		 * can now switch the control from PMIC state machine to the
 		 * register interface
 		 */
-		err = regmap_update_bits(mfd->regmap, r->init.reg,
+		err = regmap_update_bits(mfd->chip.regmap, r->init.reg,
 					 r->init.mask, r->init.val);
 		if (err) {
 			dev_err(&pdev->dev,
@@ -1113,7 +1113,7 @@ static int bd718xx_probe(struct platform_device *pdev)
 			goto err;
 		}
 		for (j = 0; j < r->additional_init_amnt; j++) {
-			err = regmap_update_bits(mfd->regmap,
+			err = regmap_update_bits(mfd->chip.regmap,
 						 r->additional_inits[j].reg,
 						 r->additional_inits[j].mask,
 						 r->additional_inits[j].val);
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 04/13] clk: bd718x7: use chip specific and generic data structs
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (2 preceding siblings ...)
  2019-01-22  9:43 ` [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs Matti Vaittinen
@ 2019-01-22  9:44 ` Matti Vaittinen
  2019-01-22  9:44 ` [RFC PATCH v1 05/13] mfd: bd70528: Support ROHM bd70528 PMIC - core Matti Vaittinen
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:44 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

Header rohm-bd718x7.h was split to generic and component specific
parts. This changed the struct bd718x7. Adapt the clk driver to
these changes.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/clk/clk-bd718x7.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-bd718x7.c b/drivers/clk/clk-bd718x7.c
index 60422c72d142..461228ebf703 100644
--- a/drivers/clk/clk-bd718x7.c
+++ b/drivers/clk/clk-bd718x7.c
@@ -17,7 +17,7 @@ struct bd718xx_clk {
 	u8 reg;
 	u8 mask;
 	struct platform_device *pdev;
-	struct bd718xx *mfd;
+	struct rohm_regmap_dev *mfd;
 };
 
 static int bd71837_clk_set(struct clk_hw *hw, int status)
@@ -68,7 +68,7 @@ static int bd71837_clk_probe(struct platform_device *pdev)
 	int rval = -ENOMEM;
 	const char *parent_clk;
 	struct device *parent = pdev->dev.parent;
-	struct bd718xx *mfd = dev_get_drvdata(parent);
+	struct rohm_regmap_dev *mfd = dev_get_drvdata(parent);
 	struct clk_init_data init = {
 		.name = "bd718xx-32k-out",
 		.ops = &bd71837_clk_ops,
@@ -119,5 +119,5 @@ static struct platform_driver bd71837_clk = {
 module_platform_driver(bd71837_clk);
 
 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
-MODULE_DESCRIPTION("BD71837 chip clk driver");
+MODULE_DESCRIPTION("BD71837/BD71847 chip clk driver");
 MODULE_LICENSE("GPL");
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 05/13] mfd: bd70528: Support ROHM bd70528 PMIC - core
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (3 preceding siblings ...)
  2019-01-22  9:44 ` [RFC PATCH v1 04/13] clk: bd718x7: " Matti Vaittinen
@ 2019-01-22  9:44 ` Matti Vaittinen
  2019-01-22 14:51   ` Guenter Roeck
  2019-01-22  9:45 ` [RFC PATCH v1 06/13] clk: bd718x7: Support ROHM BD70528 clk block Matti Vaittinen
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:44 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

ROHM BD70528MWV is an ultra-low quiescent current general
purpose single-chip power management IC for battery-powered
portable devices.

Add MFD core which enables chip access for following subdevices:
	- regulators/LED drivers
	- battery-charger
	- gpios
	- 32.768kHz clk
	- RTC
	- watchdog

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/mfd/Kconfig              |  17 ++
 drivers/mfd/Makefile             |   1 +
 drivers/mfd/rohm-bd70528.c       | 409 +++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rohm-bd70528.h | 392 +++++++++++++++++++++++++++++++++++++
 4 files changed, 819 insertions(+)
 create mode 100644 drivers/mfd/rohm-bd70528.c
 create mode 100644 include/linux/mfd/rohm-bd70528.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8c5dfdce4326..d47eca440ece 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1846,6 +1846,23 @@ config MFD_ROHM_BD718XX
 	  NXP i.MX8. It contains 8 BUCK outputs and 7 LDOs, voltage monitoring
 	  and emergency shut down as well as 32,768KHz clock output.
 
+config MFD_ROHM_BD70528
+	tristate "ROHM BD70528 Power Management IC"
+	depends on I2C=y
+	depends on OF
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	select MFD_CORE
+	help
+	  Select this option to get support for the ROHM BD70528 Power
+	  Management IC. BD71837 is general purpose single-chip power
+	  management IC for battery-powered portable devices. It contains
+	  3 ultra-low current consumption buck converters, 3 LDOs and 2 LED
+	  Drivers. Also included are 4 GPIOs, a real-time clock (RTC), a 32kHz
+	  crystal oscillator, high-accuracy VREF for use with an external ADC,
+	  10 bits SAR ADC for battery temperature monitor and 1S battery
+	  charger.
+
 config MFD_STM32_LPTIMER
 	tristate "Support for STM32 Low-Power Timer"
 	depends on (ARCH_STM32 && OF) || COMPILE_TEST
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 12980a4ad460..fc9b1408e39b 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -241,4 +241,5 @@ obj-$(CONFIG_MFD_MXS_LRADC)     += mxs-lradc.o
 obj-$(CONFIG_MFD_SC27XX_PMIC)	+= sprd-sc27xx-spi.o
 obj-$(CONFIG_RAVE_SP_CORE)	+= rave-sp.o
 obj-$(CONFIG_MFD_ROHM_BD718XX)	+= rohm-bd718x7.o
+obj-$(CONFIG_MFD_ROHM_BD70528)	+= rohm-bd70528.o
 
diff --git a/drivers/mfd/rohm-bd70528.c b/drivers/mfd/rohm-bd70528.c
new file mode 100644
index 000000000000..c2bf6c1a7136
--- /dev/null
+++ b/drivers/mfd/rohm-bd70528.c
@@ -0,0 +1,409 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+//
+// Copyright (C) 2018 ROHM Semiconductors
+//
+// ROHM BD70528 PMIC driver
+
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/rohm-bd70528.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/regmap.h>
+#include <linux/types.h>
+
+#define BD70528_INT_RES(_reg, _name)		\
+	{					\
+		.start = (_reg),		\
+		.end = (_reg),			\
+		.name = (_name),		\
+		.flags = IORESOURCE_IRQ,	\
+	}
+
+static DEFINE_MUTEX(rtc_timer_mutex);
+
+static const struct resource rtc_irqs[] = {
+	BD70528_INT_RES(BD70528_INT_RTC_ALARM, "bd70528-rtc-alm"),
+	BD70528_INT_RES(BD70528_INT_ELPS_TIM, "bd70528-elapsed-timer"),
+};
+
+static const struct resource charger_irqs[] = {
+	BD70528_INT_RES(BD70528_INT_BAT_OV_RES, "bd70528-bat-ov-res"),
+	BD70528_INT_RES(BD70528_INT_BAT_OV_DET, "bd70528-bat-ov-det"),
+	BD70528_INT_RES(BD70528_INT_DBAT_DET, "bd70528-bat-dead"),
+	BD70528_INT_RES(BD70528_INT_BATTSD_COLD_RES, "bd70528-bat-warmed"),
+	BD70528_INT_RES(BD70528_INT_BATTSD_COLD_DET, "bd70528-bat-cold"),
+	BD70528_INT_RES(BD70528_INT_BATTSD_HOT_RES, "bd70528-bat-cooled"),
+	BD70528_INT_RES(BD70528_INT_BATTSD_HOT_DET, "bd70528-bat-hot"),
+	BD70528_INT_RES(BD70528_INT_CHG_TSD, "bd70528-chg-tshd"),
+	BD70528_INT_RES(BD70528_INT_BAT_RMV, "bd70528-bat-removed"),
+	BD70528_INT_RES(BD70528_INT_BAT_DET, "bd70528-bat-detected"),
+	BD70528_INT_RES(BD70528_INT_DCIN2_OV_RES, "bd70528-dcin2-ov-res"),
+	BD70528_INT_RES(BD70528_INT_DCIN2_OV_DET, "bd70528-dcin2-ov-det"),
+	BD70528_INT_RES(BD70528_INT_DCIN2_RMV, "bd70528-dcin2-removed"),
+	BD70528_INT_RES(BD70528_INT_DCIN2_DET, "bd70528-dcin2-detected"),
+	BD70528_INT_RES(BD70528_INT_DCIN1_RMV, "bd70528-dcin1-removed"),
+	BD70528_INT_RES(BD70528_INT_DCIN1_DET, "bd70528-dcin1-detected"),
+};
+
+static struct mfd_cell bd70528_mfd_cells[] = {
+	{ .name = "bd70528-pmic", },
+	{ .name = "bd70528-gpio", },
+	/*
+	 * We use BD71837 driver to drive the clk block. Only differences to
+	 * BD70528 clock gate are the register address and mask.
+	 */
+	{ .name = "bd718xx-clk", },
+	{ .name = "bd70528-wdt", },
+	{
+		.name = "bd70528-power",
+		.resources = &charger_irqs[0],
+		.num_resources = ARRAY_SIZE(charger_irqs),
+	},
+	{
+		.name = "bd70528-rtc",
+		.resources = &rtc_irqs[0],
+		.num_resources = ARRAY_SIZE(rtc_irqs),
+	},
+};
+
+static const struct regmap_range volatile_ranges[] = {
+	/* IRQ regs */
+	{
+		.range_min = BD70528_REG_INT_MAIN,
+		.range_max = BD70528_REG_INT_OP_FAIL,
+	},
+	/* RTC regs */
+	{
+		.range_min = BD70528_REG_RTC_COUNT_H,
+		.range_max = BD70528_REG_RTC_ALM_REPEAT,
+	},
+	/*
+	 * WDT control reg is special. Magic values must be
+	 * written to it in order to change the control. Should
+	 * not be cached.
+	 */
+	{
+		.range_min = BD70528_REG_WDT_CTRL,
+		.range_max = BD70528_REG_WDT_CTRL,
+	},
+	/*
+	 * bd70528 contains also few other registers which require
+	 * magic sequence to be written in order to update the value.
+	 * At least SHIPMODE, HWRESET, WARMRESET,and STANDBY
+	 */
+	{
+		.range_min = BD70528_REG_SHIPMODE,
+		.range_max = BD70528_REG_STANDBY,
+	},
+};
+
+static const struct regmap_access_table volatile_regs = {
+	.yes_ranges = &volatile_ranges[0],
+	.n_yes_ranges = ARRAY_SIZE(volatile_ranges),
+};
+
+static struct regmap_config bd70528_regmap = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.volatile_table = &volatile_regs,
+	.max_register = BD70528_MAX_REGISTER,
+	.cache_type = REGCACHE_RBTREE,
+};
+/* bit [0] - Shutdown register */
+unsigned int bit0_offsets[] = {0};
+/* bit [1] - Power failure register */
+unsigned int bit1_offsets[] = {1};
+/* bit [2] - VR FAULT register */
+unsigned int bit2_offsets[] = {2};
+/* bit [3] - PMU register interrupts */
+unsigned int bit3_offsets[] = {3};
+/* bit [4] - Charger 1 and Charger 2 registers */
+unsigned int bit4_offsets[] = {4, 5};
+/* bit [5] - RTC register */
+unsigned int bit5_offsets[] = {6};
+/* bit [6] - GPIO register */
+unsigned int bit6_offsets[] = {7};
+/* bit [7] - Invalid operation register */
+unsigned int bit7_offsets[] = {8};
+
+static struct regmap_irq_sub_irq_map bd70528_sub_irq_offsets[] = {
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit0_offsets),
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit1_offsets),
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit2_offsets),
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit3_offsets),
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit4_offsets),
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit5_offsets),
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit6_offsets),
+	REGMAP_IRQ_MAIN_REG_OFFSET(bit7_offsets),
+};
+
+static struct regmap_irq irqs[] = {
+	REGMAP_IRQ_REG(BD70528_INT_LONGPUSH, 0, BD70528_INT_LONGPUSH_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_WDT, 0, BD70528_INT_WDT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_HWRESET, 0, BD70528_INT_HWRESET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_RSTB_FAULT, 0, BD70528_INT_RSTB_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_VBAT_UVLO, 0, BD70528_INT_VBAT_UVLO_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_TSD, 0, BD70528_INT_TSD_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_RSTIN, 0, BD70528_INT_RSTIN_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK1_FAULT, 1,
+		       BD70528_INT_BUCK1_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK2_FAULT, 1,
+		       BD70528_INT_BUCK2_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK3_FAULT, 1,
+		       BD70528_INT_BUCK3_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LDO1_FAULT, 1, BD70528_INT_LDO1_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LDO2_FAULT, 1, BD70528_INT_LDO2_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LDO3_FAULT, 1, BD70528_INT_LDO3_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LED1_FAULT, 1, BD70528_INT_LED1_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LED2_FAULT, 1, BD70528_INT_LED2_FAULT_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK1_OCP, 2, BD70528_INT_BUCK1_OCP_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK2_OCP, 2, BD70528_INT_BUCK2_OCP_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK3_OCP, 2, BD70528_INT_BUCK3_OCP_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LED1_OCP, 2, BD70528_INT_LED1_OCP_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LED2_OCP, 2, BD70528_INT_LED2_OCP_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK1_FULLON, 2,
+		       BD70528_INT_BUCK1_FULLON_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK2_FULLON, 2,
+		       BD70528_INT_BUCK2_FULLON_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_SHORTPUSH, 3, BD70528_INT_SHORTPUSH_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_AUTO_WAKEUP, 3,
+		       BD70528_INT_AUTO_WAKEUP_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_STATE_CHANGE, 3,
+		       BD70528_INT_STATE_CHANGE_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BAT_OV_RES, 4, BD70528_INT_BAT_OV_RES_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BAT_OV_DET, 4, BD70528_INT_BAT_OV_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_DBAT_DET, 4, BD70528_INT_DBAT_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BATTSD_COLD_RES, 4,
+		       BD70528_INT_BATTSD_COLD_RES_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BATTSD_COLD_DET, 4,
+		       BD70528_INT_BATTSD_COLD_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BATTSD_HOT_RES, 4,
+		       BD70528_INT_BATTSD_HOT_RES_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BATTSD_HOT_DET, 4,
+		       BD70528_INT_BATTSD_HOT_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_CHG_TSD, 4, BD70528_INT_CHG_TSD_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BAT_RMV, 5, BD70528_INT_BAT_RMV_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BAT_DET, 5, BD70528_INT_BAT_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_DCIN2_OV_RES, 5,
+		       BD70528_INT_DCIN2_OV_RES_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_DCIN2_OV_DET, 5,
+		       BD70528_INT_DCIN2_OV_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_DCIN2_RMV, 5, BD70528_INT_DCIN2_RMV_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_DCIN2_DET, 5, BD70528_INT_DCIN2_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_DCIN1_RMV, 5, BD70528_INT_DCIN1_RMV_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_DCIN1_DET, 5, BD70528_INT_DCIN1_DET_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_RTC_ALARM, 6, BD70528_INT_RTC_ALARM_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_ELPS_TIM, 6, BD70528_INT_ELPS_TIM_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_GPIO0, 7, BD70528_INT_GPIO0_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_GPIO1, 7, BD70528_INT_GPIO1_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_GPIO2, 7, BD70528_INT_GPIO2_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_GPIO3, 7, BD70528_INT_GPIO3_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK1_DVS_OPFAIL, 8,
+		       BD70528_INT_BUCK1_DVS_OPFAIL_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK2_DVS_OPFAIL, 8,
+		       BD70528_INT_BUCK2_DVS_OPFAIL_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_BUCK3_DVS_OPFAIL, 8,
+		       BD70528_INT_BUCK3_DVS_OPFAIL_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LED1_VOLT_OPFAIL, 8,
+		       BD70528_INT_LED1_VOLT_OPFAIL_MASK),
+	REGMAP_IRQ_REG(BD70528_INT_LED2_VOLT_OPFAIL, 8,
+		       BD70528_INT_LED2_VOLT_OPFAIL_MASK),
+};
+
+static struct regmap_irq_chip bd70528_irq_chip = {
+	.name = "bd70528_irq",
+	.main_status = BD70528_REG_INT_MAIN,
+	.irqs = &irqs[0],
+	.num_irqs = ARRAY_SIZE(irqs),
+	.status_base = BD70528_REG_INT_SHDN,
+	.mask_base = BD70528_REG_INT_SHDN_MASK,
+	.ack_base = BD70528_REG_INT_SHDN,
+	.type_base = BD70528_REG_GPIO1_IN,
+	.init_ack_masked = true,
+	.num_regs = 9,
+	.num_main_regs = 1,
+	.num_type_reg = 4,
+	.sub_reg_offsets = &bd70528_sub_irq_offsets[0],
+	.num_main_status_bits = 8,
+	.irq_reg_stride = 1,
+};
+
+#define WD_CTRL_MAGIC1 0x55
+#define WD_CTRL_MAGIC2 0xAA
+
+static int bd70528_wdt_set(struct bd70528 *bd70528, int enable, int *old_state)
+{
+	int ret, i;
+	unsigned int tmp;
+	u8 wd_ctrl_arr[3] = { WD_CTRL_MAGIC1, WD_CTRL_MAGIC2, 0 };
+	u8 *wd_ctrl = &wd_ctrl_arr[2];
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_WDT_CTRL, &tmp);
+	if (ret)
+		return ret;
+
+	*wd_ctrl = (u8)tmp;
+
+	if (old_state) {
+		if (*wd_ctrl & BD70528_MASK_WDT_EN)
+			*old_state |= BD70528_WDT_STATE_BIT;
+		else
+			*old_state &= ~BD70528_WDT_STATE_BIT;
+		if ((!enable) == (!(*old_state & BD70528_WDT_STATE_BIT)))
+			return 0;
+	}
+
+	if (enable) {
+		if (*wd_ctrl & BD70528_MASK_WDT_EN)
+			return 0;
+		*wd_ctrl |= BD70528_MASK_WDT_EN;
+	} else {
+		if (*wd_ctrl & BD70528_MASK_WDT_EN)
+			*wd_ctrl &= ~BD70528_MASK_WDT_EN;
+		else
+			return 0;
+	}
+
+	for (i = 0; i < 3; i++) {
+		ret = regmap_write(bd70528->chip.regmap, BD70528_REG_WDT_CTRL,
+				   wd_ctrl_arr[i]);
+		if (ret)
+			return ret;
+	}
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_WDT_CTRL, &tmp);
+	if ((tmp & BD70528_MASK_WDT_EN) != (*wd_ctrl & BD70528_MASK_WDT_EN)) {
+		dev_err(bd70528->chip.dev,
+			"Watchdog ctrl mismatch (hw) 0x%x (set) 0x%x\n",
+			tmp, *wd_ctrl);
+		ret = -EIO;
+	}
+	return ret;
+}
+
+static int bd70528_i2c_probe(struct i2c_client *i2c,
+			    const struct i2c_device_id *id)
+{
+	struct bd70528 *bd70528;
+	struct regmap_irq_chip_data *irq_data;
+	int ret, i;
+
+	if (!i2c->irq) {
+		dev_err(&i2c->dev, "No IRQ configured\n");
+		return -EINVAL;
+	}
+	bd70528 = devm_kzalloc(&i2c->dev, sizeof(*bd70528), GFP_KERNEL);
+
+	if (!bd70528)
+		return -ENOMEM;
+
+	dev_set_drvdata(&i2c->dev, bd70528);
+	bd70528->rtc_timer_lock = &rtc_timer_mutex;
+	bd70528->chip.chip_type = ROHM_CHIP_TYPE_BD70528;
+	bd70528->wdt_set = bd70528_wdt_set;
+	bd70528->chip.regmap = devm_regmap_init_i2c(i2c, &bd70528_regmap);
+	if (IS_ERR(bd70528->chip.regmap)) {
+		dev_err(&i2c->dev, "regmap initialization failed\n");
+		return PTR_ERR(bd70528->chip.regmap);
+	}
+
+	/*
+	 * Disallow type setting for all IRQs by default as
+	 *  most of them do not support setting type.
+	 */
+	for (i = 0; i < ARRAY_SIZE(irqs); i++)
+		irqs[i].type.types_supported = 0;
+
+	irqs[BD70528_INT_GPIO0].type.type_reg_offset = 0;
+	irqs[BD70528_INT_GPIO0].type.type_rising_val = 0x20;
+	irqs[BD70528_INT_GPIO0].type.type_falling_val = 0x10;
+	irqs[BD70528_INT_GPIO0].type.type_level_high_val = 0x40;
+	irqs[BD70528_INT_GPIO0].type.type_level_low_val = 0x50;
+	irqs[BD70528_INT_GPIO0].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
+				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
+	irqs[BD70528_INT_GPIO1].type.type_reg_offset = 2;
+	irqs[BD70528_INT_GPIO1].type.type_rising_val = 0x20;
+	irqs[BD70528_INT_GPIO1].type.type_falling_val = 0x10;
+	irqs[BD70528_INT_GPIO1].type.type_level_high_val = 0x40;
+	irqs[BD70528_INT_GPIO1].type.type_level_low_val = 0x50;
+	irqs[BD70528_INT_GPIO1].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
+				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
+	irqs[BD70528_INT_GPIO2].type.type_reg_offset = 4;
+	irqs[BD70528_INT_GPIO2].type.type_rising_val = 0x20;
+	irqs[BD70528_INT_GPIO2].type.type_falling_val = 0x10;
+	irqs[BD70528_INT_GPIO2].type.type_level_high_val = 0x40;
+	irqs[BD70528_INT_GPIO2].type.type_level_low_val = 0x50;
+	irqs[BD70528_INT_GPIO2].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
+				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
+	irqs[BD70528_INT_GPIO3].type.type_reg_offset = 6;
+	irqs[BD70528_INT_GPIO3].type.type_rising_val = 0x20;
+	irqs[BD70528_INT_GPIO3].type.type_falling_val = 0x10;
+	irqs[BD70528_INT_GPIO3].type.type_level_high_val = 0x40;
+	irqs[BD70528_INT_GPIO3].type.type_level_low_val = 0x50;
+	irqs[BD70528_INT_GPIO3].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
+				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
+
+	ret = devm_regmap_add_irq_chip(&i2c->dev, bd70528->chip.regmap,
+				       i2c->irq, IRQF_ONESHOT, 0,
+				       &bd70528_irq_chip, &irq_data);
+	if (ret) {
+		dev_err(&i2c->dev, "Failed to add irq_chip\n");
+		return ret;
+	}
+	dev_dbg(&i2c->dev, "Registered %d irqs for chip\n",
+			bd70528_irq_chip.num_irqs);
+
+	/*
+	 * BD70528 irq controller is not touching the main mask register.
+	 * So enable the GPIO block interrupts at main level. We can just
+	 * leave them enabled as irq-controller should disable irqs
+	 * from sub-registers when IRQ is disabled or freed.
+	 */
+	ret = regmap_update_bits(bd70528->chip.regmap,
+				 BD70528_REG_INT_MAIN_MASK,
+				 BD70528_INT_GPIO_MASK, 0);
+
+	ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
+				   bd70528_mfd_cells,
+				   ARRAY_SIZE(bd70528_mfd_cells), NULL, 0,
+				   regmap_irq_get_domain(irq_data));
+	if (ret)
+		dev_err(&i2c->dev, "Failed to create subdevices\n");
+
+	return ret;
+}
+
+static const struct of_device_id bd70528_of_match[] = {
+	{
+		.compatible = "rohm,bd70528",
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, bd70528_of_match);
+
+static struct i2c_driver bd70528_drv = {
+	.driver = {
+		.name = "rohm-bd70528",
+		.of_match_table = bd70528_of_match,
+	},
+	.probe = &bd70528_i2c_probe,
+};
+
+static int __init bd70528_init(void)
+{
+	return i2c_add_driver(&bd70528_drv);
+}
+subsys_initcall(bd70528_init);
+
+static void __exit bd70528_exit(void)
+{
+	i2c_del_driver(&bd70528_drv);
+}
+module_exit(bd70528_exit);
+
+MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
+MODULE_DESCRIPTION("ROHM BD70528 Power Management IC driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/rohm-bd70528.h b/include/linux/mfd/rohm-bd70528.h
new file mode 100644
index 000000000000..2ac0701309b8
--- /dev/null
+++ b/include/linux/mfd/rohm-bd70528.h
@@ -0,0 +1,392 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2018 ROHM Semiconductors */
+
+#ifndef __LINUX_MFD_BD70528_H__
+#define __LINUX_MFD_BD70528_H__
+
+#include <linux/device.h>
+#include <linux/mfd/rohm-generic.h>
+#include <linux/regmap.h>
+
+struct bd70528 {
+	/*
+	 * Please keep this as the first member here as some
+	 * drivers (clk) supporting more than one chip may only know this
+	 * generic struct 'struct rohm_regmap_dev' and assume it is
+	 * the first chunk of parent device's private data.
+	 */
+	struct rohm_regmap_dev chip;
+	/* wdt_set must be called rtc_timer_lock held */
+	int (*wdt_set)(struct bd70528 *bd70528, int enable, int *old_state);
+	struct mutex *rtc_timer_lock;
+};
+
+enum {
+	BD70528_BUCK1,
+	BD70528_BUCK2,
+	BD70528_BUCK3,
+	BD70528_LDO1,
+	BD70528_LDO2,
+	BD70528_LDO3,
+	BD70528_LED1,
+	BD70528_LED2,
+};
+
+#define BD70528_BUCK_VOLTS 17
+#define BD70528_BUCK_VOLTS 17
+#define BD70528_BUCK_VOLTS 17
+#define BD70528_LDO_VOLTS 0x20
+
+#define BD70528_REG_BUCK1_EN	0x0F
+#define BD70528_REG_BUCK1_VOLT	0x15
+#define BD70528_REG_BUCK2_EN	0x10
+#define BD70528_REG_BUCK2_VOLT	0x16
+#define BD70528_REG_BUCK3_EN	0x11
+#define BD70528_REG_BUCK3_VOLT	0x17
+#define BD70528_REG_LDO1_EN	0x1b
+#define BD70528_REG_LDO1_VOLT	0x1e
+#define BD70528_REG_LDO2_EN	0x1c
+#define BD70528_REG_LDO2_VOLT	0x1f
+#define BD70528_REG_LDO3_EN	0x1d
+#define BD70528_REG_LDO3_VOLT	0x20
+#define BD70528_REG_LED_CTRL	0x2b
+#define BD70528_REG_LED_VOLT	0x29
+#define BD70528_REG_LED_EN	0x2a
+
+/* main irq registers */
+#define BD70528_REG_INT_MAIN	0x7E
+#define BD70528_REG_INT_MAIN_MASK 0x74
+
+/* 'sub irq' registers */
+#define BD70528_REG_INT_SHDN	0x7F
+#define BD70528_REG_INT_PWR_FLT	0x80
+#define BD70528_REG_INT_VR_FLT	0x81
+#define BD70528_REG_INT_MISC	0x82
+#define BD70528_REG_INT_BAT1	0x83
+#define BD70528_REG_INT_BAT2	0x84
+#define BD70528_REG_INT_RTC	0x85
+#define BD70528_REG_INT_GPIO	0x86
+#define BD70528_REG_INT_OP_FAIL	0x87
+
+#define BD70528_REG_INT_SHDN_MASK	0x75
+#define BD70528_REG_INT_PWR_FLT_MASK	0x76
+#define BD70528_REG_INT_VR_FLT_MASK	0x77
+#define BD70528_REG_INT_MISC_MASK	0x78
+#define BD70528_REG_INT_BAT1_MASK	0x79
+#define BD70528_REG_INT_BAT2_MASK	0x7a
+#define BD70528_REG_INT_RTC_MASK	0x7b
+#define BD70528_REG_INT_GPIO_MASK	0x7c
+#define BD70528_REG_INT_OP_FAIL_MASK	0x7d
+
+/* Reset related 'magic' registers */
+#define BD70528_REG_SHIPMODE	0x03
+#define BD70528_REG_HWRESET	0x04
+#define BD70528_REG_WARMRESET	0x05
+#define BD70528_REG_STANDBY	0x06
+
+/* GPIO registers */
+#define BD70528_REG_GPIO_STATE	0x8F
+
+#define BD70528_REG_GPIO1_IN	0x4d
+#define BD70528_REG_GPIO2_IN	0x4f
+#define BD70528_REG_GPIO3_IN	0x51
+#define BD70528_REG_GPIO4_IN	0x53
+#define BD70528_REG_GPIO1_OUT	0x4e
+#define BD70528_REG_GPIO2_OUT	0x50
+#define BD70528_REG_GPIO3_OUT	0x52
+#define BD70528_REG_GPIO4_OUT	0x54
+
+/* clk control */
+
+#define BD70528_REG_CLK_OUT	0x2c
+
+/* RTC */
+
+#define BD70528_REG_RTC_COUNT_H		0x2d
+#define BD70528_REG_RTC_COUNT_L		0x2e
+#define BD70528_REG_RTC_SEC		0x2f
+#define BD70528_REG_RTC_MINUTE		0x30
+#define BD70528_REG_RTC_HOUR		0x31
+#define BD70528_REG_RTC_WEEK		0x32
+#define BD70528_REG_RTC_DAY		0x33
+#define BD70528_REG_RTC_MONTH		0x34
+#define BD70528_REG_RTC_YEAR		0x35
+
+#define BD70528_REG_RTC_ALM_SEC		0x36
+#define BD70528_REG_RTC_ALM_START	BD70528_REG_RTC_ALM_SEC
+#define BD70528_REG_RTC_ALM_MINUTE	0x37
+#define BD70528_REG_RTC_ALM_HOUR	0x38
+#define BD70528_REG_RTC_ALM_WEEK	0x39
+#define BD70528_REG_RTC_ALM_DAY		0x3a
+#define BD70528_REG_RTC_ALM_MONTH	0x3b
+#define BD70528_REG_RTC_ALM_YEAR	0x3c
+#define BD70528_REG_RTC_ALM_MASK	0x3d
+#define BD70528_REG_RTC_ALM_REPEAT	0x3e
+#define BD70528_REG_RTC_START		BD70528_REG_RTC_SEC
+
+#define BD70528_REG_RTC_WAKE_SEC	0x43
+#define BD70528_REG_RTC_WAKE_START	BD70528_REG_RTC_WAKE_SEC
+#define BD70528_REG_RTC_WAKE_MIN	0x44
+#define BD70528_REG_RTC_WAKE_HOUR	0x45
+#define BD70528_REG_RTC_WAKE_CTRL	0x46
+
+#define BD70528_REG_ELAPSED_TIMER_EN	0x42
+#define BD70528_REG_WAKE_EN		0x46
+
+/* WDT registers */
+#define BD70528_REG_WDT_CTRL		0x4A
+#define BD70528_REG_WDT_HOUR		0x49
+#define BD70528_REG_WDT_MINUTE		0x48
+#define BD70528_REG_WDT_SEC		0x47
+
+/* Charger / Battery */
+#define BD70528_REG_CHG_CURR_STAT	0x59
+#define BD70528_REG_CHG_BAT_STAT	0x57
+#define BD70528_REG_CHG_BAT_TEMP	0x58
+#define BD70528_REG_CHG_IN_STAT		0x56
+#define BD70528_REG_CHG_DCIN_ILIM	0x5d
+#define BD70528_REG_CHG_CHG_CURR_WARM	0x61
+#define BD70528_REG_CHG_CHG_CURR_COLD	0x62
+
+
+/* Masks for main IRQ register bits */
+enum {
+	BD70528_INT_SHDN,
+#define BD70528_INT_SHDN_MASK (1<<BD70528_INT_SHDN)
+	BD70528_INT_PWR_FLT,
+#define BD70528_INT_PWR_FLT_MASK (1<<BD70528_INT_PWR_FLT)
+	BD70528_INT_VR_FLT,
+#define BD70528_INT_VR_FLT_MASK (1<<BD70528_INT_VR_FLT)
+	BD70528_INT_MISC,
+#define BD70528_INT_MISC_MASK (1<<BD70528_INT_MISC)
+	BD70528_INT_BAT1,
+#define BD70528_INT_BAT1_MASK (1<<BD70528_INT_BAT1)
+	BD70528_INT_RTC,
+#define BD70528_INT_RTC_MASK (1<<BD70528_INT_RTC)
+	BD70528_INT_GPIO,
+#define BD70528_INT_GPIO_MASK (1<<BD70528_INT_GPIO)
+	BD70528_INT_OP_FAIL,
+#define BD70528_INT_OP_FAIL_MASK (1<<BD70528_INT_OP_FAIL)
+};
+
+/* IRQs */
+enum {
+	/* Shutdown register IRQs */
+	BD70528_INT_LONGPUSH,
+	BD70528_INT_WDT,
+	BD70528_INT_HWRESET,
+	BD70528_INT_RSTB_FAULT,
+	BD70528_INT_VBAT_UVLO,
+	BD70528_INT_TSD,
+	BD70528_INT_RSTIN,
+	/* Power failure register IRQs */
+	BD70528_INT_BUCK1_FAULT,
+	BD70528_INT_BUCK2_FAULT,
+	BD70528_INT_BUCK3_FAULT,
+	BD70528_INT_LDO1_FAULT,
+	BD70528_INT_LDO2_FAULT,
+	BD70528_INT_LDO3_FAULT,
+	BD70528_INT_LED1_FAULT,
+	BD70528_INT_LED2_FAULT,
+	/* VR FAULT register IRQs */
+	BD70528_INT_BUCK1_OCP,
+	BD70528_INT_BUCK2_OCP,
+	BD70528_INT_BUCK3_OCP,
+	BD70528_INT_LED1_OCP,
+	BD70528_INT_LED2_OCP,
+	BD70528_INT_BUCK1_FULLON,
+	BD70528_INT_BUCK2_FULLON,
+	/* PMU register interrupts */
+	BD70528_INT_SHORTPUSH,
+	BD70528_INT_AUTO_WAKEUP,
+	BD70528_INT_STATE_CHANGE,
+	/* Charger 1 register IRQs */
+	BD70528_INT_BAT_OV_RES,
+	BD70528_INT_BAT_OV_DET,
+	BD70528_INT_DBAT_DET,
+	BD70528_INT_BATTSD_COLD_RES,
+	BD70528_INT_BATTSD_COLD_DET,
+	BD70528_INT_BATTSD_HOT_RES,
+	BD70528_INT_BATTSD_HOT_DET,
+	BD70528_INT_CHG_TSD,
+	/* Charger 2 register IRQs */
+	BD70528_INT_BAT_RMV,
+	BD70528_INT_BAT_DET,
+	BD70528_INT_DCIN2_OV_RES,
+	BD70528_INT_DCIN2_OV_DET,
+	BD70528_INT_DCIN2_RMV,
+	BD70528_INT_DCIN2_DET,
+	BD70528_INT_DCIN1_RMV,
+	BD70528_INT_DCIN1_DET,
+	/* RTC register IRQs */
+	BD70528_INT_RTC_ALARM,
+	BD70528_INT_ELPS_TIM,
+	/* GPIO register IRQs */
+	BD70528_INT_GPIO0,
+	BD70528_INT_GPIO1,
+	BD70528_INT_GPIO2,
+	BD70528_INT_GPIO3,
+	/* Invalid operation register IRQs */
+	BD70528_INT_BUCK1_DVS_OPFAIL,
+	BD70528_INT_BUCK2_DVS_OPFAIL,
+	BD70528_INT_BUCK3_DVS_OPFAIL,
+	BD70528_INT_LED1_VOLT_OPFAIL,
+	BD70528_INT_LED2_VOLT_OPFAIL,
+};
+
+/* Masks */
+#define BD70528_INT_LONGPUSH_MASK 0x1
+#define BD70528_INT_WDT_MASK 0x2
+#define BD70528_INT_HWRESET_MASK 0x4
+#define BD70528_INT_RSTB_FAULT_MASK 0x8
+#define BD70528_INT_VBAT_UVLO_MASK 0x10
+#define BD70528_INT_TSD_MASK 0x20
+#define BD70528_INT_RSTIN_MASK 0x40
+
+#define BD70528_INT_BUCK1_FAULT_MASK 0x1
+#define BD70528_INT_BUCK2_FAULT_MASK 0x2
+#define BD70528_INT_BUCK3_FAULT_MASK 0x4
+#define BD70528_INT_LDO1_FAULT_MASK 0x8
+#define BD70528_INT_LDO2_FAULT_MASK 0x10
+#define BD70528_INT_LDO3_FAULT_MASK 0x20
+#define BD70528_INT_LED1_FAULT_MASK 0x40
+#define BD70528_INT_LED2_FAULT_MASK 0x80
+
+#define BD70528_INT_BUCK1_OCP_MASK 0x1
+#define BD70528_INT_BUCK2_OCP_MASK 0x2
+#define BD70528_INT_BUCK3_OCP_MASK 0x4
+#define BD70528_INT_LED1_OCP_MASK 0x8
+#define BD70528_INT_LED2_OCP_MASK 0x10
+#define BD70528_INT_BUCK1_FULLON_MASK 0x20
+#define BD70528_INT_BUCK2_FULLON_MASK 0x40
+
+#define BD70528_INT_SHORTPUSH_MASK 0x1
+#define BD70528_INT_AUTO_WAKEUP_MASK 0x2
+#define BD70528_INT_STATE_CHANGE_MASK 0x10
+
+#define BD70528_INT_BAT_OV_RES_MASK 0x1
+#define BD70528_INT_BAT_OV_DET_MASK 0x2
+#define BD70528_INT_DBAT_DET_MASK 0x4
+#define BD70528_INT_BATTSD_COLD_RES_MASK 0x8
+#define BD70528_INT_BATTSD_COLD_DET_MASK 0x10
+#define BD70528_INT_BATTSD_HOT_RES_MASK 0x20
+#define BD70528_INT_BATTSD_HOT_DET_MASK 0x40
+#define BD70528_INT_CHG_TSD_MASK 0x80
+
+#define BD70528_INT_BAT_RMV_MASK 0x1
+#define BD70528_INT_BAT_DET_MASK 0x2
+#define BD70528_INT_DCIN2_OV_RES_MASK 0x4
+#define BD70528_INT_DCIN2_OV_DET_MASK 0x8
+#define BD70528_INT_DCIN2_RMV_MASK 0x10
+#define BD70528_INT_DCIN2_DET_MASK 0x20
+#define BD70528_INT_DCIN1_RMV_MASK 0x40
+#define BD70528_INT_DCIN1_DET_MASK 0x80
+
+#define BD70528_INT_RTC_ALARM_MASK 0x1
+#define BD70528_INT_ELPS_TIM_MASK 0x2
+
+#define BD70528_INT_GPIO0_MASK 0x1
+#define BD70528_INT_GPIO1_MASK 0x2
+#define BD70528_INT_GPIO2_MASK 0x4
+#define BD70528_INT_GPIO3_MASK 0x8
+
+#define BD70528_INT_BUCK1_DVS_OPFAIL_MASK 0x1
+#define BD70528_INT_BUCK2_DVS_OPFAIL_MASK 0x2
+#define BD70528_INT_BUCK3_DVS_OPFAIL_MASK 0x4
+#define BD70528_INT_LED1_VOLT_OPFAIL_MASK 0x10
+#define BD70528_INT_LED2_VOLT_OPFAIL_MASK 0x20
+
+#define BD70528_DEBOUNCE_MASK 0x3
+
+#define BD70528_DEBOUNCE_DISABLE 0
+#define BD70528_DEBOUNCE_15MS 1
+#define BD70528_DEBOUNCE_30MS 2
+#define BD70528_DEBOUNCE_50MS 3
+
+#define BD70528_GPIO_DRIVE_MASK 0x2
+#define BD70528_GPIO_PUSH_PULL 0x0
+#define BD70528_GPIO_OPEN_DRAIN 0x2
+
+#define BD70528_GPIO_OUT_EN_MASK 0x80
+#define BD70528_GPIO_OUT_ENABLE 0x80
+#define BD70528_GPIO_OUT_DISABLE 0x0
+
+#define BD70528_GPIO_OUT_HI 0x1
+#define BD70528_GPIO_OUT_LO 0x0
+#define BD70528_GPIO_OUT_MASK 0x1
+
+#define BD70528_GPIO_IN_STATE_BASE 1
+
+#define BD70528_CLK_OUT_EN_MASK 0x1
+
+/* RTC masks to mask out reserved bits */
+
+#define BD70528_MASK_RTC_SEC		0x7f
+#define BD70528_MASK_RTC_MINUTE		0x7f
+#define BD70528_MASK_RTC_HOUR_24H	0x80
+#define BD70528_MASK_RTC_HOUR_PM	0x20
+#define BD70528_MASK_RTC_HOUR		0x1f
+#define BD70528_MASK_RTC_DAY		0x3f
+#define BD70528_MASK_RTC_WEEK		0x07
+#define BD70528_MASK_RTC_MONTH		0x1f
+#define BD70528_MASK_RTC_YEAR		0xff
+#define BD70528_MASK_RTC_COUNT_L	0x7f
+
+#define BD70528_MASK_ELAPSED_TIMER_EN	0x1
+/* Mask second, min and hour fields
+ * HW would support ALM irq for over 24h
+ * (by setting day, month and year too)
+ * but as we wish to keep this same as for
+ * wake-up we limit ALM to 24H and only
+ * unmask sec, min and hour
+ */
+#define BD70528_MASK_ALM_EN		0x7
+#define BD70528_MASK_WAKE_EN		0x1
+
+/* WDT masks */
+#define BD70528_MASK_WDT_EN		0x1
+#define BD70528_MASK_WDT_HOUR		0x1
+#define BD70528_MASK_WDT_MINUTE		0x7f
+#define BD70528_MASK_WDT_SEC		0x7f
+
+#define BD70528_WDT_STATE_BIT		0x1
+#define BD70528_ELAPSED_STATE_BIT	0x2
+#define BD70528_WAKE_STATE_BIT		0x4
+
+/* Charger masks */
+#define BD70528_MASK_CHG_STAT		0x7f
+#define BD70528_MASK_CHG_BAT_TIMER	0x20
+#define BD70528_MASK_CHG_BAT_OVERVOLT	0x10
+#define BD70528_MASK_CHG_BAT_DETECT	0x1
+#define BD70528_MASK_CHG_DCIN1_UVLO	0x1
+#define BD70528_MASK_CHG_DCIN_ILIM	0x3f
+#define BD70528_MASK_CHG_CHG_CURR	0x1f
+#define BD70528_MASK_CHG_TRICKLE_CURR	0x10
+
+/*
+ * Note, external battery register is the lonely rider at
+ * address 0xc5. See how to stuff that in the regmap
+ */
+#define BD70528_MAX_REGISTER 0x94
+
+/* Buck control masks */
+#define BD70528_MASK_RUN_EN	0x4
+#define BD70528_MASK_STBY_EN	0x2
+#define BD70528_MASK_IDLE_EN	0x1
+#define BD70528_MASK_LED1_EN	0x1
+#define BD70528_MASK_LED2_EN	0x10
+
+#define BD70528_MASK_BUCK_VOLT	0xf
+#define BD70528_MASK_LDO_VOLT	0x1f
+#define BD70528_MASK_LED1_VOLT	0x1
+#define BD70528_MASK_LED2_VOLT	0x10
+
+/* Misc irq masks */
+#define BD70528_INT_MASK_SHORT_PUSH	1
+#define BD70528_INT_MASK_AUTO_WAKE	2
+#define BD70528_INT_MASK_POWER_STATE	4
+
+#define BD70528_MASK_BUCK_RAMP 0x10
+#define BD70528_SIFT_BUCK_RAMP 4
+
+#endif /* __LINUX_MFD_BD70528_H__ */
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 06/13] clk: bd718x7: Support ROHM BD70528 clk block
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (4 preceding siblings ...)
  2019-01-22  9:44 ` [RFC PATCH v1 05/13] mfd: bd70528: Support ROHM bd70528 PMIC - core Matti Vaittinen
@ 2019-01-22  9:45 ` Matti Vaittinen
  2019-01-22  9:45 ` [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings Matti Vaittinen
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:45 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

ROHM BD70528 is an ultra low power PMIC with similar 32K clk as
bd718x7. Only difference (from clk perspective) is register address.
Add support for controlling BD70528 clk using bd718x7 driver.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/clk/Kconfig       |  6 +++---
 drivers/clk/clk-bd718x7.c | 21 +++++++++++++++++----
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index e5b2fe80eab4..992cfb86f2ca 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -285,10 +285,10 @@ config COMMON_CLK_STM32H7
 
 config COMMON_CLK_BD718XX
 	tristate "Clock driver for ROHM BD718x7 PMIC"
-	depends on MFD_ROHM_BD718XX
+	depends on MFD_ROHM_BD718XX || MFD_ROHM_BD70528
 	help
-	  This driver supports ROHM BD71837 and ROHM BD71847
-	  PMICs clock gates.
+	  This driver supports ROHM BD71837, ROHM BD71847 and
+	  ROHM BD70528 PMICs clock gates.
 
 source "drivers/clk/actions/Kconfig"
 source "drivers/clk/bcm/Kconfig"
diff --git a/drivers/clk/clk-bd718x7.c b/drivers/clk/clk-bd718x7.c
index 461228ebf703..41c1374f4217 100644
--- a/drivers/clk/clk-bd718x7.c
+++ b/drivers/clk/clk-bd718x7.c
@@ -8,6 +8,7 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/mfd/rohm-bd718x7.h>
+#include <linux/mfd/rohm-bd70528.h>
 #include <linux/clk-provider.h>
 #include <linux/clkdev.h>
 #include <linux/regmap.h>
@@ -86,9 +87,21 @@ static int bd71837_clk_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "No parent clk found\n");
 		return -EINVAL;
 	}
-
-	c->reg = BD718XX_REG_OUT32K;
-	c->mask = BD718XX_OUT32K_EN;
+	switch (mfd->chip_type) {
+	case ROHM_CHIP_TYPE_BD71837:
+	case ROHM_CHIP_TYPE_BD71847:
+
+		c->reg = BD718XX_REG_OUT32K;
+		c->mask = BD718XX_OUT32K_EN;
+		break;
+	case ROHM_CHIP_TYPE_BD70528:
+		c->reg = BD70528_REG_CLK_OUT;
+		c->mask = BD70528_CLK_OUT_EN_MASK;
+		break;
+	default:
+		dev_err(&pdev->dev, "Unknown clk chip\n");
+		return -EINVAL;
+	}
 	c->mfd = mfd;
 	c->pdev = pdev;
 	c->hw.init = &init;
@@ -119,5 +132,5 @@ static struct platform_driver bd71837_clk = {
 module_platform_driver(bd71837_clk);
 
 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
-MODULE_DESCRIPTION("BD71837/BD71847 chip clk driver");
+MODULE_DESCRIPTION("BD71837/BD71847/BD70528 chip clk driver");
 MODULE_LICENSE("GPL");
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (5 preceding siblings ...)
  2019-01-22  9:45 ` [RFC PATCH v1 06/13] clk: bd718x7: Support ROHM BD70528 clk block Matti Vaittinen
@ 2019-01-22  9:45 ` Matti Vaittinen
  2019-02-23  0:30   ` Rob Herring
  2019-01-22  9:46 ` [RFC PATCH v1 08/13] regulator: bd70528: Support ROHM BD70528 regulator block Matti Vaittinen
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:45 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

Document bindings for regulators (3 bucks, 3 LDOs and 2 LED
drivers) and 4 GPIO pins which can be configured for I/O or
as interrupt sources withe configurable trigger levels.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 .../devicetree/bindings/mfd/rohm,bd70528-pmic.txt  | 104 +++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt

diff --git a/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt b/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
new file mode 100644
index 000000000000..21801440a53a
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
@@ -0,0 +1,104 @@
+* ROHM BD70528 Power Management Integrated Circuit bindings
+
+BD70528MWV is an ultra-low Iq general purpose single-chip power management IC
+for battery-powered portable devices. The IC integrates 3 ultra-low current
+consumption buck converters, 3 LDOs and 2 LED Drivers. Also included are 4
+GPIOs, a real-time clock (RTC), a 32kHz clock gate, high-accuracy VREF
+for use with an external ADC, flexible dual-input power path, 10 bits SAR ADC
+for battery temperature monitor and 1S battery charger with scalable charge
+currents.
+
+Required properties:
+ - compatible		: Should be "rohm,bd70528"
+ - reg			: I2C slave address.
+ - interrupt-parent	: Phandle to the parent interrupt controller.
+ - interrupts		: The interrupt line the device is connected to.
+ - interrupt-controller	: To indicate bd70528 acts as an interrupt controller.
+ - #interrupt-cells	: Should be 2. usage is compliant to the 2 cells
+			  variant of ../interrupt-controller/interrupts.txt
+ - gpio-controller	: To indicate bd70528 acts as a gpio controller.
+ - #gpio-cells		: Should be 2. The first cell is the pin number and
+			  the second cell is used to specify flags. See
+			  ../gpio/gpio.txt for more information.
+ - clock-frequency	: Should be 32768
+ - #clock-cells		: Should be 0.
+ - regulators:		: List of child nodes that specify the regulators.
+			  Please see ../regulator/rohm,bd70528-regulator.txt
+
+Optional properties:
+ - clock-output-names	: Should contain name for output clock.
+
+Example:
+/* external oscillator */
+osc: oscillator {
+	compatible = "fixed-clock";
+	#clock-cells = <1>;
+	clock-frequency  = <32768>;
+	clock-output-names = "osc";
+};
+
+pmic: bd70528@4b {
+	compatible = "rohm,bd70528";
+	reg = <0x4b>;
+	interrupt-parent = <&gpio1>;
+	interrupts = <29 GPIO_ACTIVE_LOW>;
+	clocks = <&osc 0>;
+	#clock-cells = <0>;
+	clock-output-names = "bd70528-32k-out";
+	#gpio-cells = <2>;
+	gpio-controller;
+	interrupt-controller;
+	#interrupt-cells = <2>;
+
+	regulators {
+		buck1: BUCK1 {
+			regulator-name = "buck1";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <3400000>;
+			regulator-boot-on;
+			regulator-ramp-delay = <125>;
+		};
+		buck2: BUCK2 {
+			regulator-name = "buck2";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-boot-on;
+			regulator-ramp-delay = <125>;
+		};
+		buck3: BUCK3 {
+			regulator-name = "buck3";
+			regulator-min-microvolt = <800000>;
+			regulator-max-microvolt = <1800000>;
+			regulator-boot-on;
+			regulator-ramp-delay = <250>;
+		};
+		ldo1: LDO1 {
+			regulator-name = "ldo1";
+			regulator-min-microvolt = <1650000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-boot-on;
+		};
+		ldo2: LDO2 {
+			regulator-name = "ldo2";
+			regulator-min-microvolt = <1650000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-boot-on;
+		};
+
+		ldo3: LDO3 {
+			regulator-name = "ldo3";
+			regulator-min-microvolt = <1650000>;
+			regulator-max-microvolt = <3300000>;
+		};
+		led_ldo1: LED_LDO1 {
+			regulator-name = "led_ldo1";
+			regulator-min-microvolt = <200000>;
+			regulator-max-microvolt = <300000>;
+		};
+		led_ldo2: LED_LDO2 {
+			regulator-name = "led_ldo2";
+			regulator-min-microvolt = <200000>;
+			regulator-max-microvolt = <300000>;
+		};
+	};
+};
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 08/13] regulator: bd70528: Support ROHM BD70528 regulator block
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (6 preceding siblings ...)
  2019-01-22  9:45 ` [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings Matti Vaittinen
@ 2019-01-22  9:46 ` Matti Vaittinen
  2019-01-22  9:46 ` [RFC PATCH v1 09/13] devicetree: bindings: ROHM bd70528 regulator bindings Matti Vaittinen
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:46 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

BD70528MWV is an ultra-low Iq general purpose single-chip power
management IC for battery-powered portable devices.

Add support for controlling 3 bucks and 3 LDOs present in
ROHM BD70528.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/regulator/Kconfig             |  11 ++
 drivers/regulator/Makefile            |   1 +
 drivers/regulator/bd70528-regulator.c | 290 ++++++++++++++++++++++++++++++++++
 3 files changed, 302 insertions(+)
 create mode 100644 drivers/regulator/bd70528-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 7fc1f88e27e7..21dc3b59db19 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -180,6 +180,17 @@ config REGULATOR_BCM590XX
 	  BCM590xx PMUs. This will enable support for the software
 	  controllable LDO/Switching regulators.
 
+config REGULATOR_BD70528
+	tristate "ROHM BD70528 Power Regulator"
+	depends on MFD_ROHM_BD70528
+	help
+	  This driver supports voltage regulators on ROHM BD70528 PMIC.
+	  This will enable support for the software controllable buck
+	  and LDO regulators.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called bd70528-regulator.
+
 config REGULATOR_BD718XX
 	tristate "ROHM BD71837 Power Regulator"
 	depends on MFD_ROHM_BD718XX
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index b12e1c9b2118..960406952119 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o
 obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o
 obj-$(CONFIG_REGULATOR_AXP20X) += axp20x-regulator.o
 obj-$(CONFIG_REGULATOR_BCM590XX) += bcm590xx-regulator.o
+obj-$(CONFIG_REGULATOR_BD70528) += bd70528-regulator.o
 obj-$(CONFIG_REGULATOR_BD718XX) += bd718x7-regulator.o
 obj-$(CONFIG_REGULATOR_BD9571MWV) += bd9571mwv-regulator.o
 obj-$(CONFIG_REGULATOR_DA903X)	+= da903x.o
diff --git a/drivers/regulator/bd70528-regulator.c b/drivers/regulator/bd70528-regulator.c
new file mode 100644
index 000000000000..0cf261c469b9
--- /dev/null
+++ b/drivers/regulator/bd70528-regulator.c
@@ -0,0 +1,290 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 ROHM Semiconductors
+// bd70528-regulator.c ROHM BD70528MWV regulator driver
+
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mfd/rohm-bd70528.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/slab.h>
+
+#define BUCK_RAMPRATE_250MV 0
+#define BUCK_RAMPRATE_125MV 1
+#define BUCK_RAMP_MAX 250
+
+static struct regulator_linear_range bd70528_buck1_volts[] = {
+	REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x1, 600000),
+	REGULATOR_LINEAR_RANGE(2750000, 0x2, 0xf, 50000),
+};
+static struct regulator_linear_range bd70528_buck2_volts[] = {
+	REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x1, 300000),
+	REGULATOR_LINEAR_RANGE(1550000, 0x2, 0xd, 50000),
+	REGULATOR_LINEAR_RANGE(3000000, 0xe, 0xf, 300000),
+};
+static struct regulator_linear_range bd70528_buck3_volts[] = {
+	REGULATOR_LINEAR_RANGE(800000, 0x00, 0xd, 50000),
+	REGULATOR_LINEAR_RANGE(1800000, 0xe, 0xf, 0),
+};
+
+/* All LDOs have same voltage ranges */
+static struct regulator_linear_range bd70528_ldo_volts[] = {
+	REGULATOR_LINEAR_RANGE(1650000, 0x0, 0x07, 50000),
+	REGULATOR_LINEAR_RANGE(2100000, 0x8, 0x0f, 100000),
+	REGULATOR_LINEAR_RANGE(2850000, 0x10, 0x19, 50000),
+	REGULATOR_LINEAR_RANGE(3300000, 0x19, 0x1f, 0),
+};
+
+/* Also both LEDs support same voltages */
+static const unsigned int led_volts[] = {
+	20000, 30000
+};
+
+static int bd70528_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
+{
+	if (ramp_delay > 0 && ramp_delay <= BUCK_RAMP_MAX) {
+		unsigned int ramp_value = BUCK_RAMPRATE_250MV;
+
+		if (ramp_delay <= 125)
+			ramp_value = BUCK_RAMPRATE_125MV;
+
+		return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
+				  BD70528_MASK_BUCK_RAMP,
+				  ramp_value << BD70528_SIFT_BUCK_RAMP);
+	}
+	dev_err(&rdev->dev, "%s: ramp_delay: %d not supported\n",
+		rdev->desc->name, ramp_delay);
+	return -EINVAL;
+}
+
+static int bd70528_led_set_voltage_sel(struct regulator_dev *rdev,
+				       unsigned int sel)
+{
+	int ret;
+
+	ret = regulator_is_enabled_regmap(rdev);
+	if (ret < 0)
+		return ret;
+
+	if (ret == 0)
+		return regulator_set_voltage_sel_regmap(rdev, sel);
+
+	dev_err(&rdev->dev,
+		"LED voltage change not allowed when led is enabled\n");
+
+	return -EBUSY;
+}
+
+static struct regulator_ops bd70528_buck_ops = {
+	.enable = regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_linear_range,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_time_sel = regulator_set_voltage_time_sel,
+	.set_ramp_delay = bd70528_set_ramp_delay,
+};
+
+static struct regulator_ops bd70528_ldo_ops = {
+	.enable = regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_linear_range,
+	.set_voltage_sel = regulator_set_voltage_sel_regmap,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_time_sel = regulator_set_voltage_time_sel,
+	.set_ramp_delay = bd70528_set_ramp_delay,
+};
+
+static struct regulator_ops bd70528_led_ops = {
+	.enable = regulator_enable_regmap,
+	.disable = regulator_disable_regmap,
+	.is_enabled = regulator_is_enabled_regmap,
+	.list_voltage = regulator_list_voltage_table,
+	.set_voltage_sel = bd70528_led_set_voltage_sel,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+};
+
+
+static struct regulator_desc bd70528_desc[] = {
+	{
+		.name = "buck1",
+		.of_match = of_match_ptr("BUCK1"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_BUCK1,
+		.ops = &bd70528_buck_ops,
+		.type = REGULATOR_VOLTAGE,
+		.linear_ranges = bd70528_buck1_volts,
+		.n_linear_ranges = ARRAY_SIZE(bd70528_buck1_volts),
+		.n_voltages = BD70528_BUCK_VOLTS,
+		.enable_reg = BD70528_REG_BUCK1_EN,
+		.enable_mask = BD70528_MASK_RUN_EN,
+		.vsel_reg = BD70528_REG_BUCK1_VOLT,
+		.vsel_mask = BD70528_MASK_BUCK_VOLT,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "buck2",
+		.of_match = of_match_ptr("BUCK2"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_BUCK2,
+		.ops = &bd70528_buck_ops,
+		.type = REGULATOR_VOLTAGE,
+		.linear_ranges = bd70528_buck2_volts,
+		.n_linear_ranges = ARRAY_SIZE(bd70528_buck2_volts),
+		.n_voltages = BD70528_BUCK_VOLTS,
+		.enable_reg = BD70528_REG_BUCK2_EN,
+		.enable_mask = BD70528_MASK_RUN_EN,
+		.vsel_reg = BD70528_REG_BUCK2_VOLT,
+		.vsel_mask = BD70528_MASK_BUCK_VOLT,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "buck3",
+		.of_match = of_match_ptr("BUCK3"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_BUCK3,
+		.ops = &bd70528_buck_ops,
+		.type = REGULATOR_VOLTAGE,
+		.linear_ranges = bd70528_buck3_volts,
+		.n_linear_ranges = ARRAY_SIZE(bd70528_buck3_volts),
+		.n_voltages = BD70528_BUCK_VOLTS,
+		.enable_reg = BD70528_REG_BUCK3_EN,
+		.enable_mask = BD70528_MASK_RUN_EN,
+		.vsel_reg = BD70528_REG_BUCK3_VOLT,
+		.vsel_mask = BD70528_MASK_BUCK_VOLT,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "ldo1",
+		.of_match = of_match_ptr("LDO1"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_LDO1,
+		.ops = &bd70528_ldo_ops,
+		.type = REGULATOR_VOLTAGE,
+		.linear_ranges = bd70528_ldo_volts,
+		.n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
+		.n_voltages = BD70528_LDO_VOLTS,
+		.enable_reg = BD70528_REG_LDO1_EN,
+		.enable_mask = BD70528_MASK_RUN_EN,
+		.vsel_reg = BD70528_REG_LDO1_VOLT,
+		.vsel_mask = BD70528_MASK_LDO_VOLT,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "ldo2",
+		.of_match = of_match_ptr("LDO2"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_LDO2,
+		.ops = &bd70528_ldo_ops,
+		.type = REGULATOR_VOLTAGE,
+		.linear_ranges = bd70528_ldo_volts,
+		.n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
+		.n_voltages = BD70528_LDO_VOLTS,
+		.enable_reg = BD70528_REG_LDO2_EN,
+		.enable_mask = BD70528_MASK_RUN_EN,
+		.vsel_reg = BD70528_REG_LDO2_VOLT,
+		.vsel_mask = BD70528_MASK_LDO_VOLT,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "ldo3",
+		.of_match = of_match_ptr("LDO3"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_LDO3,
+		.ops = &bd70528_ldo_ops,
+		.type = REGULATOR_VOLTAGE,
+		.linear_ranges = bd70528_ldo_volts,
+		.n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
+		.n_voltages = BD70528_LDO_VOLTS,
+		.enable_reg = BD70528_REG_LDO3_EN,
+		.enable_mask = BD70528_MASK_RUN_EN,
+		.vsel_reg = BD70528_REG_LDO3_VOLT,
+		.vsel_mask = BD70528_MASK_LDO_VOLT,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "ldo_led1",
+		.of_match = of_match_ptr("LDO_LED1"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_LED1,
+		.ops = &bd70528_led_ops,
+		.type = REGULATOR_VOLTAGE,
+		.volt_table = &led_volts[0],
+		.n_voltages = ARRAY_SIZE(led_volts),
+		.enable_reg = BD70528_REG_LED_EN,
+		.enable_mask = BD70528_MASK_LED1_EN,
+		.vsel_reg = BD70528_REG_LED_VOLT,
+		.vsel_mask = BD70528_MASK_LED1_VOLT,
+		.owner = THIS_MODULE,
+	},
+	{
+		.name = "ldo_led2",
+		.of_match = of_match_ptr("LDO_LED2"),
+		.regulators_node = of_match_ptr("regulators"),
+		.id = BD70528_LED2,
+		.ops = &bd70528_led_ops,
+		.type = REGULATOR_VOLTAGE,
+		.volt_table = &led_volts[0],
+		.n_voltages = ARRAY_SIZE(led_volts),
+		.enable_reg = BD70528_REG_LED_EN,
+		.enable_mask = BD70528_MASK_LED2_EN,
+		.vsel_reg = BD70528_REG_LED_VOLT,
+		.vsel_mask = BD70528_MASK_LED2_VOLT,
+		.owner = THIS_MODULE,
+	},
+
+};
+
+static int bd70528_probe(struct platform_device *pdev)
+{
+	struct bd70528 *bd70528;
+	int i;
+	struct regulator_config config = {
+		.dev = pdev->dev.parent,
+	};
+
+	bd70528 = dev_get_drvdata(pdev->dev.parent);
+	if (!bd70528) {
+		dev_err(&pdev->dev, "No MFD driver data\n");
+		return -EINVAL;
+	}
+
+	config.regmap = bd70528->chip.regmap;
+
+	for (i = 0; i < ARRAY_SIZE(bd70528_desc); i++) {
+		struct regulator_dev *rdev;
+
+		rdev = devm_regulator_register(&pdev->dev, &bd70528_desc[i],
+					       &config);
+		if (IS_ERR(rdev)) {
+			dev_err(&pdev->dev,
+				"failed to register %s regulator\n",
+				bd70528_desc[i].name);
+			return PTR_ERR(rdev);
+		}
+	}
+	return 0;
+}
+
+static struct platform_driver bd70528_regulator = {
+	.driver = {
+		.name = "bd70528-pmic"
+	},
+	.probe = bd70528_probe,
+};
+
+module_platform_driver(bd70528_regulator);
+
+MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
+MODULE_DESCRIPTION("BD70528 voltage regulator driver");
+MODULE_LICENSE("GPL");
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 09/13] devicetree: bindings: ROHM bd70528 regulator bindings
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (7 preceding siblings ...)
  2019-01-22  9:46 ` [RFC PATCH v1 08/13] regulator: bd70528: Support ROHM BD70528 regulator block Matti Vaittinen
@ 2019-01-22  9:46 ` Matti Vaittinen
  2019-01-22  9:47 ` [RFC PATCH v1 10/13] gpio: Initial support for ROHM bd70528 GPIO block Matti Vaittinen
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:46 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

ROHM bd70528 is a ultra low power PMIC which includes
3 bucks, 3 LDOs and 2 LED drivers. Document the bindings
for them.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 .../bindings/regulator/rohm,bd70528-regulator.txt  | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt

diff --git a/Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt b/Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt
new file mode 100644
index 000000000000..698cfc3bc3dd
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt
@@ -0,0 +1,68 @@
+ROHM BD70528 Power Management Integrated Circuit regulator bindings
+
+Required properties:
+ - regulator-name: should be "buck1", "buck2", "buck3", "ldo1", "ldo2", "ldo3",
+		   "led_ldo1", "led_ldo2"
+
+List of regulators provided by this controller. BD70528 regulators node
+should be sub node of the BD70528 MFD node. See BD70528 MFD bindings at
+Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
+
+The valid names for BD70528 regulator nodes are:
+BUCK1, BUCK2, BUCK3, LDO1, LDO2, LDO3, LED_LDO1, LED_LDO2
+
+Optional properties:
+- Any optional property defined in bindings/regulator/regulator.txt
+
+Example:
+regulators {
+	buck1: BUCK1 {
+		regulator-name = "buck1";
+		regulator-min-microvolt = <1200000>;
+		regulator-max-microvolt = <3400000>;
+		regulator-boot-on;
+		regulator-ramp-delay = <125>;
+	};
+	buck2: BUCK2 {
+		regulator-name = "buck2";
+		regulator-min-microvolt = <1200000>;
+		regulator-max-microvolt = <3300000>;
+		regulator-boot-on;
+		regulator-ramp-delay = <125>;
+	};
+	buck3: BUCK3 {
+		regulator-name = "buck3";
+		regulator-min-microvolt = <800000>;
+		regulator-max-microvolt = <1800000>;
+		regulator-boot-on;
+		regulator-ramp-delay = <250>;
+	};
+	ldo1: LDO1 {
+		regulator-name = "ldo1";
+		regulator-min-microvolt = <1650000>;
+		regulator-max-microvolt = <3300000>;
+		regulator-boot-on;
+	};
+	ldo2: LDO2 {
+		regulator-name = "ldo2";
+		regulator-min-microvolt = <1650000>;
+		regulator-max-microvolt = <3300000>;
+		regulator-boot-on;
+	};
+
+	ldo3: LDO3 {
+		regulator-name = "ldo3";
+		regulator-min-microvolt = <1650000>;
+		regulator-max-microvolt = <3300000>;
+	};
+	led_ldo1: LED_LDO1 {
+		regulator-name = "led_ldo1";
+		regulator-min-microvolt = <200000>;
+		regulator-max-microvolt = <300000>;
+	};
+	led_ldo2: LED_LDO2 {
+		regulator-name = "led_ldo2";
+		regulator-min-microvolt = <200000>;
+		regulator-max-microvolt = <300000>;
+	};
+};
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 10/13] gpio: Initial support for ROHM bd70528 GPIO block
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (8 preceding siblings ...)
  2019-01-22  9:46 ` [RFC PATCH v1 09/13] devicetree: bindings: ROHM bd70528 regulator bindings Matti Vaittinen
@ 2019-01-22  9:47 ` Matti Vaittinen
  2019-01-22  9:47 ` [RFC PATCH v1 11/13] rtc: bd70528: Initial support for ROHM bd70528 RTC Matti Vaittinen
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:47 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

ROHM BD70528 PMIC has 4 GPIO pins. Allow them to be
controlled by GPIO framework.

IRQs are handled by regmap-irq and GPIO driver is not
aware of the irq usage.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/gpio/Kconfig        |  11 +++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bd70528.c | 192 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/gpio/gpio-bd70528.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index b5a2845347ec..c82187648630 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -962,6 +962,17 @@ config GPIO_ARIZONA
 	help
 	  Support for GPIOs on Wolfson Arizona class devices.
 
+config GPIO_BD70528
+	tristate "ROHM BD70528 GPIO support"
+	depends on MFD_ROHM_BD70528
+	help
+	  Support for GPIOs on ROHM BD70528 PMIC. There are four GPIOs
+	  available on the ROHM PMIC in total. The GPIOs can also
+	  generate interrupts.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called gpio-bd70528.
+
 config GPIO_BD9571MWV
 	tristate "ROHM BD9571 GPIO support"
 	depends on MFD_BD9571MWV
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 37628f8dbf70..6f12c83598fc 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_GPIO_ATH79)	+= gpio-ath79.o
 obj-$(CONFIG_GPIO_ASPEED)	+= gpio-aspeed.o
 obj-$(CONFIG_GPIO_RASPBERRYPI_EXP)	+= gpio-raspberrypi-exp.o
 obj-$(CONFIG_GPIO_BCM_KONA)	+= gpio-bcm-kona.o
+obj-$(CONFIG_GPIO_BD70528) 	+= gpio-bd70528.o
 obj-$(CONFIG_GPIO_BD9571MWV)	+= gpio-bd9571mwv.o
 obj-$(CONFIG_GPIO_BRCMSTB)	+= gpio-brcmstb.o
 obj-$(CONFIG_GPIO_BT8XX)	+= gpio-bt8xx.o
diff --git a/drivers/gpio/gpio-bd70528.c b/drivers/gpio/gpio-bd70528.c
new file mode 100644
index 000000000000..684d6f744409
--- /dev/null
+++ b/drivers/gpio/gpio-bd70528.c
@@ -0,0 +1,192 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 ROHM Semiconductors
+// gpio-bd70528.c ROHM BD70528MWV gpio driver
+
+#include <linux/gpio/driver.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/rohm-bd70528.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#define GPIO_IN_REG(offset) (BD70528_REG_GPIO1_IN + offset*2)
+#define GPIO_OUT_REG(offset) (BD70528_REG_GPIO1_OUT + offset*2)
+
+struct bd70528_gpio {
+	struct rohm_regmap_dev chip;
+	struct gpio_chip gpio;
+};
+
+static int bd70528_set_debounce(struct bd70528_gpio *bdgpio,
+				unsigned int offset, unsigned int debounce)
+{
+	u8 val;
+
+	switch (debounce) {
+	case 0:
+		val = BD70528_DEBOUNCE_DISABLE;
+		break;
+	case 1 ... 15:
+		val = BD70528_DEBOUNCE_15MS;
+		break;
+	case 16 ... 30:
+		val = BD70528_DEBOUNCE_30MS;
+		break;
+	case 31 ... 50:
+		val = BD70528_DEBOUNCE_50MS;
+		break;
+	default:
+		dev_err(bdgpio->chip.dev,
+			"Invalid debouce value %u\n", debounce);
+		return -EINVAL;
+	}
+	return regmap_update_bits(bdgpio->chip.regmap, GPIO_IN_REG(offset),
+				 BD70528_DEBOUNCE_MASK, val);
+}
+
+static int bd70528_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
+	struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+	int val, ret;
+
+	/* Do we need to do something to IRQs here? */
+	ret = regmap_read(bdgpio->chip.regmap, GPIO_OUT_REG(offset), &val);
+	if (ret) {
+		dev_err(bdgpio->chip.dev, "Could not read gpio direction\n");
+		return ret;
+	}
+
+	return !(val & BD70528_GPIO_OUT_EN_MASK);
+}
+
+static int bd70528_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
+				   unsigned long config)
+{
+	struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_DRIVE_OPEN_DRAIN:
+		return regmap_update_bits(bdgpio->chip.regmap,
+					  GPIO_OUT_REG(offset),
+					  BD70528_GPIO_DRIVE_MASK,
+					  BD70528_GPIO_OPEN_DRAIN);
+		break;
+	case PIN_CONFIG_DRIVE_PUSH_PULL:
+		return regmap_update_bits(bdgpio->chip.regmap,
+					  GPIO_OUT_REG(offset),
+					  BD70528_GPIO_DRIVE_MASK,
+					  BD70528_GPIO_PUSH_PULL);
+		break;
+	case PIN_CONFIG_INPUT_DEBOUNCE:
+		return bd70528_set_debounce(bdgpio, offset,
+					    pinconf_to_config_argument(config));
+		break;
+	default:
+		break;
+	}
+	return -ENOTSUPP;
+}
+
+static int bd70528_direction_input(struct gpio_chip *chip, unsigned int offset)
+{
+	struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+
+	/* Do we need to do something to IRQs here? */
+	return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset),
+				 BD70528_GPIO_OUT_EN_MASK,
+				 BD70528_GPIO_OUT_DISABLE);
+}
+static void bd70528_gpio_set(struct gpio_chip *chip, unsigned int offset,
+			     int value)
+{
+	int ret;
+	struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+	u8 val = (value) ? BD70528_GPIO_OUT_HI : BD70528_GPIO_OUT_LO;
+
+	ret = regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset),
+				  BD70528_GPIO_OUT_MASK, val);
+	if (ret)
+		dev_err(bdgpio->chip.dev, "Could not set gpio to %d\n", value);
+}
+
+static int bd70528_direction_output(struct gpio_chip *chip, unsigned int offset,
+				    int value)
+{
+	struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+
+	bd70528_gpio_set(chip, offset, value);
+	return regmap_update_bits(bdgpio->chip.regmap, GPIO_OUT_REG(offset),
+				 BD70528_GPIO_OUT_EN_MASK,
+				 BD70528_GPIO_OUT_ENABLE);
+}
+
+#define GPIO_STATE_MASK(offset) (BD70528_GPIO_IN_STATE_BASE << offset)
+
+static int bd70528_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+	unsigned int val;
+	int ret = -EINVAL;
+	struct bd70528_gpio *bdgpio = gpiochip_get_data(chip);
+
+	ret = regmap_read(bdgpio->chip.regmap, BD70528_REG_GPIO_STATE, &val);
+
+	if (!ret)
+		ret = !(val & GPIO_STATE_MASK(offset));
+
+	return ret;
+}
+
+static int  bd70528_probe(struct platform_device *pdev)
+{
+	struct bd70528_gpio *bdgpio;
+	struct bd70528 *bd70528;
+	int ret;
+
+	bd70528 = dev_get_drvdata(pdev->dev.parent);
+	if (!bd70528) {
+		dev_err(&pdev->dev, "No MFD driver data\n");
+		return -EINVAL;
+	}
+
+	bdgpio = devm_kzalloc(&pdev->dev, sizeof(*bdgpio),
+				    GFP_KERNEL);
+	if (!bdgpio)
+		return -ENOMEM;
+	bdgpio->chip.dev = &pdev->dev;
+	bdgpio->gpio.parent = pdev->dev.parent;
+	bdgpio->gpio.label = "bd70528-gpio";
+	bdgpio->gpio.owner = THIS_MODULE;
+	bdgpio->gpio.get_direction = &bd70528_get_direction;
+	bdgpio->gpio.direction_input = &bd70528_direction_input;
+	bdgpio->gpio.direction_output = &bd70528_direction_output;
+	bdgpio->gpio.set_config = &bd70528_gpio_set_config;
+	bdgpio->gpio.can_sleep = true;
+	bdgpio->gpio.get = &bd70528_gpio_get;
+	bdgpio->gpio.set = &bd70528_gpio_set;
+	bdgpio->gpio.ngpio = 4;
+	bdgpio->gpio.base = -1;
+#ifdef CONFIG_OF_GPIO
+	bdgpio->gpio.of_node = pdev->dev.parent->of_node;
+#endif
+	bdgpio->chip.regmap = bd70528->chip.regmap;
+
+	ret = devm_gpiochip_add_data(&pdev->dev, &bdgpio->gpio,
+				     bdgpio);
+	if (ret)
+		dev_err(&pdev->dev, "gpio_init: Failed to add bd70528-gpio\n");
+
+	return ret;
+}
+
+static struct platform_driver bd70528_gpio = {
+	.driver = {
+		.name = "bd70528-gpio"
+	},
+	.probe = bd70528_probe,
+};
+
+module_platform_driver(bd70528_gpio);
+
+MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
+MODULE_DESCRIPTION("BD70528 voltage regulator driver");
+MODULE_LICENSE("GPL");
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 11/13] rtc: bd70528: Initial support for ROHM bd70528 RTC
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (9 preceding siblings ...)
  2019-01-22  9:47 ` [RFC PATCH v1 10/13] gpio: Initial support for ROHM bd70528 GPIO block Matti Vaittinen
@ 2019-01-22  9:47 ` Matti Vaittinen
  2019-01-22 14:48   ` Guenter Roeck
  2019-01-22  9:48 ` [RFC PATCH v1 12/13] power: supply: Initial support for ROHM BD70528 PMIC charger block Matti Vaittinen
  2019-01-22  9:48 ` [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block Matti Vaittinen
  12 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:47 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

Support RTC block in ROHM bd70528 power management IC. Support
getting and setting the time and date as well as arming an alarm
which can also be used to wake the PMIC from standby state.

HW supports wake interrupt only for the next 24 hours (sec, minute
and hour information only) so we limit also the alarm interrupt to
this 24 hours for the sake of consistency.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/rtc/Kconfig       |   8 +
 drivers/rtc/Makefile      |   1 +
 drivers/rtc/rtc-bd70528.c | 439 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 448 insertions(+)
 create mode 100644 drivers/rtc/rtc-bd70528.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 225b0b8516f3..df6211cbd83f 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -487,6 +487,14 @@ config RTC_DRV_M41T80_WDT
 	help
 	  If you say Y here you will get support for the
 	  watchdog timer in the ST M41T60 and M41T80 RTC chips series.
+config RTC_DRV_BD70528
+	tristate "ROHM BD70528 PMIC RTC"
+	help
+	  If you say Y here you will get support for the RTC
+	  on ROHM BD70528 Power Management IC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-bd70528.
 
 config RTC_DRV_BQ32K
 	tristate "TI BQ32000"
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index df022d820bee..740b13840913 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_RTC_DRV_ASM9260)	+= rtc-asm9260.o
 obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
 obj-$(CONFIG_RTC_DRV_AT91SAM9)	+= rtc-at91sam9.o
 obj-$(CONFIG_RTC_DRV_AU1XXX)	+= rtc-au1xxx.o
+obj-$(CONFIG_RTC_DRV_BD70528)	+= rtc-bd70528.o
 obj-$(CONFIG_RTC_DRV_BQ32K)	+= rtc-bq32k.o
 obj-$(CONFIG_RTC_DRV_BQ4802)	+= rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_BRCMSTB)	+= rtc-brcmstb-waketimer.o
diff --git a/drivers/rtc/rtc-bd70528.c b/drivers/rtc/rtc-bd70528.c
new file mode 100644
index 000000000000..7c7e1f8769e8
--- /dev/null
+++ b/drivers/rtc/rtc-bd70528.c
@@ -0,0 +1,439 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+//
+// Copyright (C) 2018 ROHM Semiconductors
+//
+// RTC driver for ROHM BD70528 PMIC
+
+#include <linux/bcd.h>
+#include <linux/mfd/rohm-bd70528.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+
+/*
+ * We read regs RTC_SEC => RTC_YEAR
+ * this struct is ordered according to chip registers.
+ * Keep it u8 only to avoid padding issues.
+ */
+struct bd70528_rtc_day {
+	u8 sec;
+	u8 min;
+	u8 hour;
+};
+struct bd70528_rtc_data {
+	struct bd70528_rtc_day time;
+	u8 week;
+	u8 day;
+	u8 month;
+	u8 year;
+};
+struct bd70528_rtc_wake {
+	struct bd70528_rtc_day time;
+	u8 ctrl;
+};
+struct bd70528_rtc_alm {
+	struct bd70528_rtc_data data;
+	u8 alm_mask;
+	u8 alm_repeat;
+};
+
+static int bd70528_set_wake(struct bd70528 *bd70528,
+			    int enable, int *old_state)
+{
+	int ret;
+	unsigned int ctrl_reg;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_WAKE_EN, &ctrl_reg);
+	if (ret)
+		return ret;
+
+	if (old_state) {
+		if (ctrl_reg & BD70528_MASK_WAKE_EN)
+			*old_state |= BD70528_WAKE_STATE_BIT;
+		else
+			*old_state &= ~BD70528_WAKE_STATE_BIT;
+
+		if ((!enable) == (!(*old_state & BD70528_WAKE_STATE_BIT)))
+			return 0;
+	}
+
+	if (enable)
+		ctrl_reg |= BD70528_MASK_WAKE_EN;
+	else
+		ctrl_reg &= ~BD70528_MASK_WAKE_EN;
+
+	return regmap_write(bd70528->chip.regmap, BD70528_REG_WAKE_EN,
+			    ctrl_reg);
+}
+
+static int bd70528_set_elapsed_tmr(struct bd70528 *bd70528,
+				   int enable, int *old_state)
+{
+	int ret;
+	unsigned int ctrl_reg;
+
+	/*
+	 * TBD
+	 * What is the purpose of elapsed timer ?
+	 * Is the timeout registers counting down, or is the disable - re-enable
+	 * going to restart the elapsed-time counting? If counting is restarted
+	 * the timeout should be decreased by the amount of time that has
+	 * elapsed since starting the timer. Maybe we should store the monotonic
+	 * clock value when timer is started so that if RTC is set while timer
+	 * is armed we could do the compensation. This is a hack if RTC/system
+	 * clk are drifting. OTOH, RTC controlled via I2C is in any case
+	 * inaccurate...
+	 */
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_ELAPSED_TIMER_EN,
+			  &ctrl_reg);
+	if (ret)
+		return ret;
+
+	if (old_state) {
+		if (ctrl_reg & BD70528_MASK_ELAPSED_TIMER_EN)
+			*old_state |= BD70528_ELAPSED_STATE_BIT;
+		else
+			*old_state &= ~BD70528_ELAPSED_STATE_BIT;
+
+		if ((!enable) == (!(*old_state & BD70528_ELAPSED_STATE_BIT)))
+			return 0;
+	}
+
+	if (enable)
+		ctrl_reg |= BD70528_MASK_ELAPSED_TIMER_EN;
+	else
+		ctrl_reg &= ~BD70528_MASK_ELAPSED_TIMER_EN;
+
+	return regmap_write(bd70528->chip.regmap, BD70528_REG_ELAPSED_TIMER_EN,
+			    ctrl_reg);
+}
+
+static int bd70528_set_rtc_based_timers(struct bd70528 *bd70528, int new_state,
+							int *old_state)
+{
+	int ret;
+
+	ret = bd70528->wdt_set(bd70528, new_state & BD70528_WDT_STATE_BIT,
+			       old_state);
+	if (ret) {
+		dev_err(bd70528->chip.dev,
+			"Failed to disable WDG for RTC setting (%d)\n", ret);
+		return ret;
+	}
+	ret = bd70528_set_elapsed_tmr(bd70528,
+				      new_state & BD70528_ELAPSED_STATE_BIT,
+				      old_state);
+	if (ret) {
+		dev_err(bd70528->chip.dev,
+			"Failed to disable 'elapsed timer' for RTC setting\n");
+		return ret;
+	}
+	ret = bd70528_set_wake(bd70528, new_state & BD70528_WAKE_STATE_BIT,
+			       old_state);
+	if (ret) {
+		dev_err(bd70528->chip.dev,
+			"Failed to disable 'wake timer' for RTC setting\n");
+		return ret;
+	}
+
+	return ret;
+}
+
+static int bd70528_re_enable_rtc_based_timers(struct bd70528 *bd70528,
+							int old_state)
+{
+	if (bd70528->rtc_timer_lock)
+		mutex_unlock(bd70528->rtc_timer_lock);
+
+	return bd70528_set_rtc_based_timers(bd70528, old_state, NULL);
+}
+
+static int bd70528_disable_rtc_based_timers(struct bd70528 *bd70528,
+							int *old_state)
+{
+	if (bd70528->rtc_timer_lock)
+		mutex_lock(bd70528->rtc_timer_lock);
+
+	return bd70528_set_rtc_based_timers(bd70528, 0, old_state);
+}
+
+static inline void tmday2rtc(struct rtc_time *t, struct bd70528_rtc_day *d)
+{
+	d->sec &= ~BD70528_MASK_RTC_SEC;
+	d->min &= ~BD70528_MASK_RTC_MINUTE;
+	d->hour &= ~BD70528_MASK_RTC_HOUR;
+	d->sec |= bin2bcd(t->tm_sec);
+	d->min |= bin2bcd(t->tm_min);
+	d->hour |= bin2bcd(t->tm_hour);
+}
+
+static inline void tm2rtc(struct rtc_time *t, struct bd70528_rtc_data *r)
+{
+	r->day &= ~BD70528_MASK_RTC_DAY;
+	r->week &= ~BD70528_MASK_RTC_WEEK;
+	r->month &= ~BD70528_MASK_RTC_MONTH;
+	/*
+	 * PM and 24H bits are not used by Wake - thus iwe clear them
+	 * here and not in tmday2rtc() which is also used by wake.
+	 */
+	r->time.hour &= ~(BD70528_MASK_RTC_HOUR_PM | BD70528_MASK_RTC_HOUR_24H);
+
+	tmday2rtc(t, &r->time);
+	/*
+	 * We do always set time in 24H mode.
+	 */
+	r->time.hour |= BD70528_MASK_RTC_HOUR_24H;
+	r->day |= bin2bcd(t->tm_mday);
+	r->week |= bin2bcd(t->tm_wday);
+	r->month |= bin2bcd(t->tm_mon + 1);
+	r->year = bin2bcd(t->tm_year-100);
+}
+
+static inline void rtc2tm(struct bd70528_rtc_data *r, struct rtc_time *t)
+{
+	t->tm_sec = bcd2bin(r->time.sec & BD70528_MASK_RTC_SEC);
+	t->tm_min = bcd2bin(r->time.min & BD70528_MASK_RTC_MINUTE);
+	t->tm_hour = bcd2bin(r->time.hour & BD70528_MASK_RTC_HOUR);
+	/*
+	 * If RTC is in 12H mode, then bit BD70528_MASK_RTC_HOUR_PM
+	 * is not BCD value but tells whether it is AM or PM
+	 */
+	if (!(r->time.hour & BD70528_MASK_RTC_HOUR_24H)) {
+		t->tm_hour %= 12;
+		if (r->time.hour & BD70528_MASK_RTC_HOUR_PM)
+			t->tm_hour += 12;
+	}
+	t->tm_mday = bcd2bin(r->day & BD70528_MASK_RTC_DAY);
+	t->tm_mon = bcd2bin(r->month & BD70528_MASK_RTC_MONTH) - 1;
+	t->tm_year = 100 + bcd2bin(r->year & BD70528_MASK_RTC_YEAR);
+	t->tm_wday = bcd2bin(r->week & BD70528_MASK_RTC_WEEK);
+}
+
+static int bd70528_set_alarm(struct device *dev, struct rtc_wkalrm *a)
+{
+	struct bd70528 *bd70528 = dev_get_drvdata(dev);
+	struct bd70528_rtc_wake wake;
+	struct bd70528_rtc_alm alm;
+	int ret;
+
+	ret = regmap_bulk_read(bd70528->chip.regmap, BD70528_REG_RTC_WAKE_START,
+			       &wake, sizeof(wake));
+	if (ret) {
+		dev_err(dev, "Failed to read wake regs\n");
+		return ret;
+	}
+
+	ret = regmap_bulk_read(bd70528->chip.regmap, BD70528_REG_RTC_ALM_START,
+			       &alm, sizeof(alm));
+	if (ret) {
+		dev_err(dev, "Failed to read alarm regs\n");
+		return ret;
+	}
+
+	tm2rtc(&a->time, &alm.data);
+	tmday2rtc(&a->time, &wake.time);
+
+	if (a->enabled) {
+		alm.alm_mask &= ~BD70528_MASK_ALM_EN;
+		wake.ctrl |= BD70528_MASK_WAKE_EN;
+	} else {
+		alm.alm_mask |= BD70528_MASK_ALM_EN;
+		wake.ctrl &= ~BD70528_MASK_WAKE_EN;
+	}
+
+	ret = regmap_bulk_write(bd70528->chip.regmap,
+				BD70528_REG_RTC_WAKE_START, &wake,
+				sizeof(wake));
+	if (ret) {
+		dev_err(dev, "Failed to set wake time\n");
+		return ret;
+	}
+	ret = regmap_bulk_write(bd70528->chip.regmap, BD70528_REG_RTC_ALM_START,
+				&alm, sizeof(alm));
+	if (ret)
+		dev_err(dev, "Failed to set alarm time\n");
+
+	return ret;
+}
+
+static int bd70528_read_alarm(struct device *dev, struct rtc_wkalrm *a)
+{
+	struct bd70528 *bd70528 = dev_get_drvdata(dev);
+	struct bd70528_rtc_alm alm;
+	int ret;
+
+	ret = regmap_bulk_read(bd70528->chip.regmap, BD70528_REG_RTC_ALM_START,
+			  &alm, sizeof(alm));
+	if (ret) {
+		dev_err(dev, "Failed to read alarm regs\n");
+		return ret;
+	}
+
+	rtc2tm(&alm.data, &a->time);
+	a->time.tm_mday = -1;
+	a->time.tm_mon = -1;
+	a->time.tm_year = -1;
+	if (alm.alm_mask & BD70528_MASK_ALM_EN)
+		a->enabled = 0;
+	else
+		a->enabled = 1;
+
+	a->pending = 0;
+
+	return 0;
+}
+
+static int bd70528_set_time(struct device *dev, struct rtc_time *t)
+{
+	int ret, old_states;
+	struct bd70528_rtc_data rtc_data;
+	struct bd70528 *bd70528 = dev_get_drvdata(dev);
+
+	ret = bd70528_disable_rtc_based_timers(bd70528, &old_states);
+
+	ret = regmap_bulk_read(bd70528->chip.regmap,
+			       BD70528_REG_RTC_START, &rtc_data,
+			       sizeof(rtc_data));
+
+	tm2rtc(t, &rtc_data);
+
+	ret = regmap_bulk_write(bd70528->chip.regmap,
+				BD70528_REG_RTC_START, &rtc_data,
+				sizeof(rtc_data));
+
+	ret = bd70528_re_enable_rtc_based_timers(bd70528, old_states);
+
+	return 0;
+}
+static int bd70528_get_time(struct device *dev, struct rtc_time *t)
+{
+	struct bd70528 *bd70528 = dev_get_drvdata(dev);
+	struct bd70528_rtc_data rtc_data;
+	int ret;
+
+	/* read the RTC date and time registers all at once */
+	ret = regmap_bulk_read(bd70528->chip.regmap,
+			       BD70528_REG_RTC_START, &rtc_data,
+			       sizeof(rtc_data));
+	if (ret) {
+		dev_err(dev, "Failed to read RTC time (err %d)\n", ret);
+		return ret;
+	}
+
+	rtc2tm(&rtc_data, t);
+
+	return 0;
+}
+
+static const struct rtc_class_ops bd70528_rtc_ops = {
+	.read_time	= bd70528_get_time,
+	.set_time	= bd70528_set_time,
+	.read_alarm	= bd70528_read_alarm,
+	.set_alarm	= bd70528_set_alarm,
+};
+
+static irqreturn_t alm_hndlr(int irq, void *data)
+{
+	struct rtc_device *rtc = data;
+
+	rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF | RTC_PF);
+	return IRQ_HANDLED;
+}
+
+static int bd70528_probe(struct platform_device *pdev)
+{
+	struct bd70528 *bd70528;
+	struct bd70528 *tmp;
+	int ret;
+	struct rtc_device *rtc;
+	int irq;
+	unsigned int hr;
+
+	tmp = dev_get_drvdata(pdev->dev.parent);
+	if (!tmp) {
+		dev_err(&pdev->dev, "No MFD driver data\n");
+		return -EINVAL;
+	}
+	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
+	if (!bd70528)
+		return -ENOMEM;
+
+	*bd70528 = *tmp;
+	bd70528->chip.dev = &pdev->dev;
+
+	irq = platform_get_irq_byname(pdev, "bd70528-rtc-alm");
+
+	if (irq < 0) {
+		dev_err(&pdev->dev, "Failed to get irq\n");
+		return irq;
+	}
+
+	platform_set_drvdata(pdev, bd70528);
+
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_RTC_HOUR, &hr);
+
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to reag RTC clock\n");
+		return ret;
+	}
+
+	if (!(hr & BD70528_MASK_RTC_HOUR_24H)) {
+		struct rtc_time t;
+
+		ret = bd70528_get_time(&pdev->dev, &t);
+		if (ret)
+			return ret;
+
+		ret = bd70528_set_time(&pdev->dev, &t);
+		if (ret)
+			return ret;
+	}
+
+	if (ret) {
+		dev_err(&pdev->dev, "Setting 24H clock for RTC failed\n");
+		return ret;
+	}
+
+	device_set_wakeup_capable(&pdev->dev, true);
+	device_wakeup_enable(&pdev->dev);
+	rtc = devm_rtc_device_register(&pdev->dev, "bd70528-rtc",
+				       &bd70528_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc)) {
+		dev_err(&pdev->dev, "Registering RTC failed\n");
+		return PTR_ERR(rtc);
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, &alm_hndlr,
+					IRQF_ONESHOT, "bd70528-rtc", rtc);
+
+	/*
+	 *  BD70528 irq controller is not touching the main mask register.
+	 *  So enable the RTC block interrupts at main level. We can just
+	 *  leave them enabled as irq-controller should disable irqs
+	 *  from sub-registers when IRQ is disabled or freed.
+	 */
+	ret = regmap_update_bits(bd70528->chip.regmap,
+				 BD70528_REG_INT_MAIN,
+				 BD70528_INT_RTC_MASK, 0);
+
+	if (ret)
+		dev_err(&pdev->dev, "Failed to enable RTC interrupts\n");
+
+	return ret;
+}
+
+static struct platform_driver bd70528_rtc = {
+	.driver = {
+		.name = "bd70528-rtc"
+	},
+	.probe = bd70528_probe,
+};
+
+module_platform_driver(bd70528_rtc);
+
+MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
+MODULE_DESCRIPTION("BD70528 RTC driver");
+MODULE_LICENSE("GPL");
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 12/13] power: supply: Initial support for ROHM BD70528 PMIC charger block
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (10 preceding siblings ...)
  2019-01-22  9:47 ` [RFC PATCH v1 11/13] rtc: bd70528: Initial support for ROHM bd70528 RTC Matti Vaittinen
@ 2019-01-22  9:48 ` Matti Vaittinen
  2019-01-22  9:48 ` [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block Matti Vaittinen
  12 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:48 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

ROHM BD70528 PMIC includes battery charger block. Support charger
staus queries and doing few basic settings like input current limit
and charging current.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/power/supply/Kconfig           |   9 +
 drivers/power/supply/Makefile          |   1 +
 drivers/power/supply/bd70528-charger.c | 670 +++++++++++++++++++++++++++++++++
 3 files changed, 680 insertions(+)
 create mode 100644 drivers/power/supply/bd70528-charger.c

diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
index e901b9879e7e..903c97a67bf0 100644
--- a/drivers/power/supply/Kconfig
+++ b/drivers/power/supply/Kconfig
@@ -660,4 +660,13 @@ config FUEL_GAUGE_SC27XX
 	 Say Y here to enable support for fuel gauge with SC27XX
 	 PMIC chips.
 
+config CHARGER_BD70528
+	tristate "ROHM bd70528 charger driver"
+	depends on MFD_ROHM_BD70528
+	default n
+	help
+	 Say Y here to enable support for getting battery status
+	 information and altering charger configurations from charger
+	 block of the ROHM BD70528 Power Management IC.
+
 endif # POWER_SUPPLY
diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
index b731c2a9b695..c60387b04bfa 100644
--- a/drivers/power/supply/Makefile
+++ b/drivers/power/supply/Makefile
@@ -87,3 +87,4 @@ obj-$(CONFIG_AXP288_CHARGER)	+= axp288_charger.o
 obj-$(CONFIG_CHARGER_CROS_USBPD)	+= cros_usbpd-charger.o
 obj-$(CONFIG_CHARGER_SC2731)	+= sc2731_charger.o
 obj-$(CONFIG_FUEL_GAUGE_SC27XX)	+= sc27xx_fuel_gauge.o
+obj-$(CONFIG_CHARGER_BD70528)	+= bd70528-charger.o
diff --git a/drivers/power/supply/bd70528-charger.c b/drivers/power/supply/bd70528-charger.c
new file mode 100644
index 000000000000..05d0d6015627
--- /dev/null
+++ b/drivers/power/supply/bd70528-charger.c
@@ -0,0 +1,670 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+//
+// Copyright (C) 2018 ROHM Semiconductors
+//
+// power-supply driver for ROHM BD70528 PMIC
+
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/rohm-bd70528.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+
+#define CHG_STAT_SUSPEND	0x0
+#define CHG_STAT_TRICKLE	0x1
+#define CHG_STAT_FAST		0x3
+#define CHG_STAT_TOPOFF		0xe
+#define CHG_STAT_DONE		0xf
+#define CHG_STAT_OTP_TRICKLE	0x10
+#define CHG_STAT_OTP_FAST	0x11
+#define CHG_STAT_OTP_DONE	0x12
+#define CHG_STAT_TSD_TRICKLE	0x20
+#define CHG_STAT_TSD_FAST	0x21
+#define CHG_STAT_TSD_TOPOFF	0x22
+#define CHG_STAT_BAT_ERR	0x7f
+
+static const char *bd70528_charger_model = "BD70528";
+static const char *bd70528_charger_manufacturer = "ROHM Semiconductors";
+
+#define BD_ERR_IRQ_HND(_name_, _wrn_)					\
+static irqreturn_t bd0528_##_name_##_interrupt(int irq, void *arg)	\
+{									\
+	struct power_supply *psy = (struct power_supply *)arg;		\
+									\
+	power_supply_changed(psy);					\
+	dev_err(&psy->dev, (_wrn_));					\
+									\
+	return IRQ_HANDLED;						\
+}
+
+#define BD_INFO_IRQ_HND(_name_, _wrn_)					\
+static irqreturn_t bd0528_##_name_##_interrupt(int irq, void *arg)	\
+{									\
+	struct power_supply *psy = (struct power_supply *)arg;		\
+									\
+	power_supply_changed(psy);					\
+	dev_dbg(&psy->dev, (_wrn_));					\
+									\
+	return IRQ_HANDLED;						\
+}
+
+#define BD_IRQ_HND(_name_) bd0528_##_name_##_interrupt
+
+BD_ERR_IRQ_HND(BAT_OV_DET, "Battery overvoltage detected\n");
+BD_ERR_IRQ_HND(DBAT_DET, "Dead battery detected\n");
+BD_ERR_IRQ_HND(COLD_DET, "Battery cold\n");
+BD_ERR_IRQ_HND(HOT_DET, "Battery hot\n");
+BD_ERR_IRQ_HND(CHG_TSD, "Charger thermal shutdown\n");
+BD_ERR_IRQ_HND(DCIN2_OV_DET, "DCIN2 overvoltage detected\n");
+
+BD_INFO_IRQ_HND(BAT_OV_RES, "Battery voltage back to normal\n");
+BD_INFO_IRQ_HND(COLD_RES, "Battery temperature back to normal\n");
+BD_INFO_IRQ_HND(HOT_RES, "Battery temperature back to normal\n");
+BD_INFO_IRQ_HND(BAT_RMV, "Battery removed\n");
+BD_INFO_IRQ_HND(BAT_DET, "Battery detected\n");
+BD_INFO_IRQ_HND(DCIN2_OV_RES, "DCIN2 voltage back to normal\n");
+BD_INFO_IRQ_HND(DCIN2_RMV, "DCIN2 removed\n");
+BD_INFO_IRQ_HND(DCIN2_DET, "DCIN2 detected\n");
+BD_INFO_IRQ_HND(DCIN1_RMV, "DCIN1 removed\n");
+BD_INFO_IRQ_HND(DCIN1_DET, "DCIN1 detected\n");
+
+struct irq_name_pair {
+	const char *n;
+	irqreturn_t (*h)(int irq, void *arg);
+};
+
+static int bd70528_get_irqs(struct platform_device *pdev,
+			    struct bd70528 *bd70528)
+{
+	int irq, i, ret;
+	unsigned int mask;
+	struct irq_name_pair bd70528_chg_irqs[] = {
+		{ .n = "bd70528-bat-ov-res", .h = BD_IRQ_HND(BAT_OV_RES) },
+		{ .n = "bd70528-bat-ov-det", .h = BD_IRQ_HND(BAT_OV_DET) },
+		{ .n = "bd70528-bat-dead", .h = BD_IRQ_HND(DBAT_DET) },
+		{ .n = "bd70528-bat-warmed", .h = BD_IRQ_HND(COLD_RES) },
+		{ .n = "bd70528-bat-cold", .h = BD_IRQ_HND(COLD_DET) },
+		{ .n = "bd70528-bat-cooled", .h = BD_IRQ_HND(HOT_RES) },
+		{ .n = "bd70528-bat-hot", .h = BD_IRQ_HND(HOT_DET) },
+		{ .n = "bd70528-chg-tshd", .h = BD_IRQ_HND(CHG_TSD) },
+		{ .n = "bd70528-bat-removed", .h = BD_IRQ_HND(BAT_RMV) },
+		{ .n = "bd70528-bat-detected", .h = BD_IRQ_HND(BAT_DET) },
+		{ .n = "bd70528-dcin2-ov-res", .h = BD_IRQ_HND(DCIN2_OV_RES) },
+		{ .n = "bd70528-dcin2-ov-det", .h = BD_IRQ_HND(DCIN2_OV_DET) },
+		{ .n = "bd70528-dcin2-removed", .h = BD_IRQ_HND(DCIN2_RMV) },
+		{ .n = "bd70528-dcin2-detected", .h = BD_IRQ_HND(DCIN2_DET) },
+		{ .n = "bd70528-dcin1-removed", .h = BD_IRQ_HND(DCIN1_RMV) },
+		{ .n = "bd70528-dcin1-detected", .h = BD_IRQ_HND(DCIN1_DET) },
+	};
+
+	for (i = 0; i < ARRAY_SIZE(bd70528_chg_irqs); i++) {
+		irq = platform_get_irq_byname(pdev, bd70528_chg_irqs[i].n);
+		if (irq < 0) {
+			dev_err(&pdev->dev, "Bad IRQ information for %s (%d)\n",
+				bd70528_chg_irqs[i].n, irq);
+			return irq;
+		}
+		ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+						bd70528_chg_irqs[i].h,
+						IRQF_ONESHOT,
+						bd70528_chg_irqs[i].n, bd70528);
+
+		if (ret)
+			return ret;
+	}
+	/*
+	 * BD70528 irq controller is not touching the main mask register.
+	 * So enable the charger block interrupts at main level. We can just
+	 * leave them enabled as irq-controller should disable irqs
+	 * from sub-registers when IRQ is disabled or freed.
+	 */
+	mask = BD70528_REG_INT_BAT1_MASK | BD70528_REG_INT_BAT2_MASK;
+	ret = regmap_update_bits(bd70528->chip.regmap,
+				 BD70528_REG_INT_MAIN, mask, 0);
+	if (ret)
+		dev_err(&pdev->dev, "Failed to enable charger IRQs\n");
+
+	return ret;
+}
+
+static int bd70528_get_charger_status(struct bd70528 *bd70528, int *val)
+{
+	int ret;
+	unsigned int v;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_CHG_CURR_STAT, &v);
+	if (ret) {
+		dev_err(bd70528->chip.dev, "Charger state read failure %d\n",
+			ret);
+		return ret;
+	}
+
+	switch (v & BD70528_MASK_CHG_STAT) {
+	case CHG_STAT_SUSPEND:
+	/* Maybe we should check the CHG_TTRI_EN? */
+	case CHG_STAT_OTP_TRICKLE:
+	case CHG_STAT_OTP_FAST:
+	case CHG_STAT_OTP_DONE:
+	case CHG_STAT_TSD_TRICKLE:
+	case CHG_STAT_TSD_FAST:
+	case CHG_STAT_TSD_TOPOFF:
+	case CHG_STAT_BAT_ERR:
+		*val = POWER_SUPPLY_STATUS_NOT_CHARGING;
+		break;
+	case CHG_STAT_DONE:
+		*val = POWER_SUPPLY_STATUS_FULL;
+		break;
+	case CHG_STAT_TRICKLE:
+	case CHG_STAT_FAST:
+	case CHG_STAT_TOPOFF:
+		*val = POWER_SUPPLY_STATUS_CHARGING;
+		break;
+	default:
+		*val = POWER_SUPPLY_STATUS_UNKNOWN;
+		break;
+	}
+
+	return 0;
+}
+
+static int bd70528_get_charge_type(struct bd70528 *bd70528, int *val)
+{
+	int ret;
+	unsigned int v;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_CHG_CURR_STAT, &v);
+	if (ret) {
+		dev_err(bd70528->chip.dev, "Charger state read failure %d\n",
+			ret);
+		return ret;
+	}
+
+	switch (v & BD70528_MASK_CHG_STAT) {
+	case CHG_STAT_TRICKLE:
+		*val = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
+		break;
+	case CHG_STAT_FAST:
+	case CHG_STAT_TOPOFF:
+		*val = POWER_SUPPLY_CHARGE_TYPE_FAST;
+		break;
+	case CHG_STAT_DONE:
+	case CHG_STAT_SUSPEND:
+	/* Maybe we should check the CHG_TTRI_EN? */
+	case CHG_STAT_OTP_TRICKLE:
+	case CHG_STAT_OTP_FAST:
+	case CHG_STAT_OTP_DONE:
+	case CHG_STAT_TSD_TRICKLE:
+	case CHG_STAT_TSD_FAST:
+	case CHG_STAT_TSD_TOPOFF:
+	case CHG_STAT_BAT_ERR:
+		*val = POWER_SUPPLY_CHARGE_TYPE_NONE;
+		break;
+	default:
+		*val = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
+		break;
+	}
+
+	return 0;
+}
+
+static int bd70528_get_battery_health(struct bd70528 *bd70528, int *val)
+{
+	int ret;
+	unsigned int v;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_CHG_BAT_STAT, &v);
+	if (ret) {
+		dev_err(bd70528->chip.dev, "Battery state read failure %d\n",
+			ret);
+		return ret;
+	}
+	/* No battery? */
+	if (!(v & BD70528_MASK_CHG_BAT_DETECT))
+		*val = POWER_SUPPLY_HEALTH_DEAD;
+	else if (v & BD70528_MASK_CHG_BAT_OVERVOLT)
+		*val = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
+	else if (v & BD70528_MASK_CHG_BAT_TIMER)
+		*val = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE;
+	else
+		*val = POWER_SUPPLY_HEALTH_GOOD;
+
+	return 0;
+}
+
+static int bd70528_get_online(struct bd70528 *bd70528, int *val)
+{
+	int ret;
+	unsigned int v;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_CHG_IN_STAT, &v);
+	if (ret) {
+		dev_err(bd70528->chip.dev, "DC1 IN state read failure %d\n",
+			ret);
+		return ret;
+	}
+
+	*val = (v & BD70528_MASK_CHG_DCIN1_UVLO) ? 1 : 0;
+
+	return 0;
+}
+
+static int bd70528_get_present(struct bd70528 *bd70528, int *val)
+{
+	int ret;
+	unsigned int v;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_CHG_BAT_STAT, &v);
+	if (ret) {
+		dev_err(bd70528->chip.dev, "Battery state read failure %d\n",
+			ret);
+		return ret;
+	}
+
+	*val = (v & BD70528_MASK_CHG_BAT_DETECT) ? 1 : 0;
+
+	return 0;
+}
+
+struct linear_range {
+	int min;
+	int step;
+	int vals;
+	int low_sel;
+};
+
+struct linear_range current_limit_ranges[] = {
+	{
+		.min = 5,
+		.step = 1,
+		.vals = 36,
+		.low_sel = 0,
+	},
+	{
+		.min = 40,
+		.step = 5,
+		.vals = 5,
+		.low_sel = 0x23,
+	},
+	{
+		.min = 60,
+		.step = 20,
+		.vals = 8,
+		.low_sel = 0x27,
+	},
+	{
+		.min = 200,
+		.step = 50,
+		.vals = 7,
+		.low_sel = 0x2e,
+	}
+};
+
+/*
+ * BD70528 would support setting and getting own charge current/
+ * voltage for low temperatures. The driver currently only reads
+ * the charge current at room temperature. We do set both though.
+ */
+struct linear_range warm_charge_curr[] = {
+	{
+		.min = 10,
+		.step = 10,
+		.vals = 20,
+		.low_sel = 0,
+	},
+	{
+		.min = 200,
+		.step = 25,
+		.vals = 13,
+		.low_sel = 0x13,
+	},
+};
+
+/*
+ * Cold charge current selectors are identical to warm charge current
+ * selectors. The difference is that only smaller currents are available
+ * at cold charge range.
+ */
+#define MAX_COLD_CHG_CURR_SEL 0x15
+#define MAX_WARM_CHG_CURR_SEL 0x1f
+#define MIN_CHG_CURR_SEL 0x0
+
+static int find_value_for_selector_low(struct linear_range *r, int selectors,
+				       unsigned int sel, unsigned int *val)
+{
+	int i;
+
+	for (i = 0; i < selectors; i++) {
+		if (r[i].low_sel <= sel && r[i].low_sel + r[i].vals >= sel) {
+			*val = r[i].min + (sel - r[i].low_sel) * r[i].step;
+			return 0;
+		}
+
+	}
+	return -EINVAL;
+}
+
+/*
+ * For BD70528 voltage/current limits we happily accept any value which
+ * belongs the range. We could check if value matching the selector is
+ * desired by computing the range min + (sel - sel_low) * range step - but
+ * I guess it is enough if we use voltage/current which is closest (below)
+ * the requested?
+ */
+static int find_selector_for_value_low(struct linear_range *r, int selectors,
+				       unsigned int val, unsigned int *sel,
+				       bool *found)
+{
+	int i;
+	int ret = -EINVAL;
+
+	*found = false;
+	for (i = 0; i < selectors; i++) {
+		if (r[i].min <= val) {
+			if (r[i].min + r[i].step * r[i].vals >= val) {
+				*found = true;
+				*sel = r[i].low_sel + (val - r[i].min) /
+				       r[i].step;
+				ret = 0;
+				break;
+			}
+			/*
+			 * If the range max is smaller than requested
+			 * we can set the max supported value from range
+			 */
+			*sel = r[i].low_sel + r[i].vals;
+			ret = 0;
+		}
+	}
+	return ret;
+}
+
+static int get_charge_current(struct bd70528 *bd70528, int *ma)
+{
+	unsigned int sel;
+	int ret;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_CHG_CHG_CURR_WARM,
+			  &sel);
+	if (ret) {
+		dev_err(bd70528->chip.dev,
+			"Charge current reading failed (%d)\n", ret);
+		return ret;
+	}
+
+	sel &= BD70528_MASK_CHG_CHG_CURR;
+
+	ret = find_value_for_selector_low(&warm_charge_curr[0],
+					  ARRAY_SIZE(warm_charge_curr), sel,
+					  ma);
+	if (ret) {
+		dev_err(bd70528->chip.dev,
+			"Unknown charge current value 0x%x\n",
+			sel);
+	}
+
+	return ret;
+}
+
+static int get_current_limit(struct bd70528 *bd70528, int *ma)
+{
+	unsigned int sel;
+	int ret;
+
+	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_CHG_DCIN_ILIM,
+			  &sel);
+
+	if (ret) {
+		dev_err(bd70528->chip.dev,
+			"Input current limit reading failed (%d)\n", ret);
+		return ret;
+	}
+
+	sel &= BD70528_MASK_CHG_DCIN_ILIM;
+
+	ret = find_value_for_selector_low(&current_limit_ranges[0],
+					  ARRAY_SIZE(current_limit_ranges), sel,
+					  ma);
+
+	if (ret) {
+		/* Unspecified values mean 500 mA */
+		*ma = 500;
+	}
+	return 0;
+}
+
+static enum power_supply_property bd70528_charger_props[] = {
+	POWER_SUPPLY_PROP_STATUS,
+	POWER_SUPPLY_PROP_CHARGE_TYPE,
+	POWER_SUPPLY_PROP_HEALTH,
+	POWER_SUPPLY_PROP_PRESENT,
+	POWER_SUPPLY_PROP_ONLINE,
+	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
+	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
+	POWER_SUPPLY_PROP_MODEL_NAME,
+	POWER_SUPPLY_PROP_MANUFACTURER,
+};
+
+static int bd70528_charger_get_property(struct power_supply *psy,
+					enum power_supply_property psp,
+					union power_supply_propval *val)
+{
+	struct bd70528 *bd70528 = power_supply_get_drvdata(psy);
+	int ret = 0;
+
+	switch (psp) {
+	case POWER_SUPPLY_PROP_STATUS:
+		return bd70528_get_charger_status(bd70528, &val->intval);
+	case POWER_SUPPLY_PROP_CHARGE_TYPE:
+		return bd70528_get_charge_type(bd70528, &val->intval);
+	case POWER_SUPPLY_PROP_HEALTH:
+		return bd70528_get_battery_health(bd70528, &val->intval);
+	case POWER_SUPPLY_PROP_PRESENT:
+		return bd70528_get_present(bd70528, &val->intval);
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+		ret = get_current_limit(bd70528, &val->intval);
+		val->intval *= 1000;
+		return ret;
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+		ret = get_charge_current(bd70528, &val->intval);
+		val->intval *= 1000;
+		return ret;
+	case POWER_SUPPLY_PROP_ONLINE:
+		return bd70528_get_online(bd70528, &val->intval);
+	case POWER_SUPPLY_PROP_MODEL_NAME:
+		val->strval = bd70528_charger_model;
+		return 0;
+	case POWER_SUPPLY_PROP_MANUFACTURER:
+		val->strval = bd70528_charger_manufacturer;
+		return 0;
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+
+static int bd70528_prop_is_writable(struct power_supply *psy,
+				    enum power_supply_property psp)
+{
+	switch (psp) {
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+		return 1;
+	default:
+		break;
+	}
+	return 0;
+}
+
+
+
+static int set_charge_current(struct bd70528 *bd70528, int ma)
+{
+	unsigned int reg;
+	int ret = 0, tmpret;
+	bool found;
+
+	if (ma > 500) {
+		dev_warn(bd70528->chip.dev,
+			 "Requested charge current %u exceed maximum (500mA)\n",
+			 ma);
+		reg = MAX_WARM_CHG_CURR_SEL;
+		goto set;
+	}
+	if (ma < 10) {
+		dev_err(bd70528->chip.dev,
+			"Requested charge current %u smaller than min (10mA)\n",
+			 ma);
+		reg = MIN_CHG_CURR_SEL;
+		ret = -EINVAL;
+		goto set;
+	}
+
+	ret = find_selector_for_value_low(&warm_charge_curr[0],
+					  ARRAY_SIZE(warm_charge_curr), ma,
+					  &reg, &found);
+
+	if (!found) {
+		/* There was a gap in supported values and we hit it */
+		dev_warn(bd70528->chip.dev,
+			 "Unsupported charge current %u mA\n", ma);
+	}
+set:
+
+	tmpret = regmap_update_bits(bd70528->chip.regmap,
+				    BD70528_REG_CHG_CHG_CURR_WARM,
+				    BD70528_MASK_CHG_CHG_CURR, reg);
+	if (tmpret)
+		dev_err(bd70528->chip.dev,
+			"Charge current write failure (%d)\n", tmpret);
+
+	if (reg > MAX_COLD_CHG_CURR_SEL)
+		reg = MAX_COLD_CHG_CURR_SEL;
+
+	if (!tmpret)
+		tmpret = regmap_update_bits(bd70528->chip.regmap,
+					    BD70528_REG_CHG_CHG_CURR_COLD,
+					    BD70528_MASK_CHG_CHG_CURR, reg);
+
+	if (!ret)
+		ret = tmpret;
+
+	return ret;
+}
+
+#define MAX_CURR_LIMIT_SEL 0x34
+#define MIN_CURR_LIMIT_SEL 0x0
+
+static int set_current_limit(struct bd70528 *bd70528, int ma)
+{
+	unsigned int reg;
+	int ret = 0, tmpret;
+	bool found;
+
+	if (ma > 500) {
+		dev_warn(bd70528->chip.dev,
+			 "Requested current limit %u exceed maximum (500mA)\n",
+			 ma);
+		reg = MAX_CURR_LIMIT_SEL;
+		goto set;
+	}
+	if (ma < 5) {
+		dev_err(bd70528->chip.dev,
+			"Requested current limit %u smaller than min (5mA)\n",
+			ma);
+		reg = MIN_CURR_LIMIT_SEL;
+		ret = -EINVAL;
+		goto set;
+	}
+
+	ret = find_selector_for_value_low(&current_limit_ranges[0],
+					  ARRAY_SIZE(current_limit_ranges), ma,
+					  &reg, &found);
+	if (!found) {
+		/* There was a gap in supported values and we hit it ?*/
+		dev_warn(bd70528->chip.dev, "Unsupported current limit %umA\n",
+			 ma);
+	}
+
+set:
+	tmpret = regmap_update_bits(bd70528->chip.regmap,
+				    BD70528_REG_CHG_DCIN_ILIM,
+				    BD70528_MASK_CHG_DCIN_ILIM, reg);
+
+	if (!ret)
+		ret = tmpret;
+
+	return ret;
+}
+
+static int bd70528_charger_set_property(struct power_supply *psy,
+					enum power_supply_property psp,
+					const union power_supply_propval *val)
+{
+	struct bd70528 *bd70528 = power_supply_get_drvdata(psy);
+
+	switch (psp) {
+	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+		return set_current_limit(bd70528, val->intval / 1000);
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+		return set_charge_current(bd70528, val->intval / 1000);
+	default:
+		break;
+	}
+	return -EINVAL;
+}
+
+static const struct power_supply_desc bd70528_charger_desc = {
+	.name		= "bd70528-charger",
+	.type		= POWER_SUPPLY_TYPE_BATTERY,
+	.properties	= bd70528_charger_props,
+	.num_properties	= ARRAY_SIZE(bd70528_charger_props),
+	.get_property	= bd70528_charger_get_property,
+	.set_property	= bd70528_charger_set_property,
+	.property_is_writeable	= bd70528_prop_is_writable,
+};
+
+static int bd70528_power_probe(struct platform_device *pdev)
+{
+	struct bd70528 *bd70528, *tmp;
+	struct power_supply *psy;
+	struct power_supply_config cfg = {};
+
+	tmp = dev_get_drvdata(pdev->dev.parent);
+	if (!tmp) {
+		dev_err(&pdev->dev, "No MFD driver data\n");
+		return -EINVAL;
+	}
+	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
+	if (!bd70528)
+		return -ENOMEM;
+	*bd70528 = *tmp;
+	bd70528->chip.dev = &pdev->dev;
+
+	platform_set_drvdata(pdev, bd70528);
+	cfg.drv_data = bd70528;
+	cfg.of_node = pdev->dev.parent->of_node;
+
+	psy = devm_power_supply_register(&pdev->dev, &bd70528_charger_desc,
+					 &cfg);
+	if (IS_ERR(psy)) {
+		dev_err(&pdev->dev, "failed: power supply register\n");
+		return PTR_ERR(psy);
+	}
+
+	return bd70528_get_irqs(pdev, bd70528);
+}
+
+static struct platform_driver bd70528_power = {
+	.driver = {
+		.name = "bd70528-power"
+	},
+	.probe = bd70528_power_probe,
+};
+
+module_platform_driver(bd70528_power);
+
+MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
+MODULE_DESCRIPTION("BD70528 power-supply driver");
+MODULE_LICENSE("GPL");
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
                   ` (11 preceding siblings ...)
  2019-01-22  9:48 ` [RFC PATCH v1 12/13] power: supply: Initial support for ROHM BD70528 PMIC charger block Matti Vaittinen
@ 2019-01-22  9:48 ` Matti Vaittinen
  2019-01-22 15:47   ` Guenter Roeck
  12 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22  9:48 UTC (permalink / raw)
  To: matti.vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, linux, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

Initial support for watchdog block included in ROHM BD70528
power management IC.

Configurations for low power states are still to be checked.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
---
 drivers/watchdog/Kconfig       |  12 +++
 drivers/watchdog/Makefile      |   1 +
 drivers/watchdog/bd70528_wdt.c | 161 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
 create mode 100644 drivers/watchdog/bd70528_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 57f017d74a97..f30e3a3e886e 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -90,6 +90,18 @@ config SOFT_WATCHDOG_PRETIMEOUT
 	  watchdog. Be aware that governors might affect the watchdog because it
 	  is purely software, e.g. the panic governor will stall it!
 
+config BD70528_WATCHDOG
+	tristate "ROHM BD70528 PMIC Watchdog"
+	depends on MFD_ROHM_BD70528
+	select WATCHDOG_CORE
+	help
+	  Support for the watchdog in the ROHM BD70528 PMIC. Watchdog trigger
+	  cause system reset.
+
+	  Say Y here to include support for the ROHM BD70528 watchdog.
+	  Alternatively say M to compile the driver as a module,
+	  which will be called bd70528_wdt.
+
 config DA9052_WATCHDOG
 	tristate "Dialog DA9052 Watchdog"
 	depends on PMIC_DA9052 || COMPILE_TEST
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index a0917ef28e07..1ce87a3b1172 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -204,6 +204,7 @@ obj-$(CONFIG_WATCHDOG_SUN4V)		+= sun4v_wdt.o
 obj-$(CONFIG_XEN_WDT) += xen_wdt.o
 
 # Architecture Independent
+obj-$(CONFIG_BD70528_WATCHDOG) += bd70528_wdt.o
 obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
 obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
 obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
diff --git a/drivers/watchdog/bd70528_wdt.c b/drivers/watchdog/bd70528_wdt.c
new file mode 100644
index 000000000000..e9a32566f595
--- /dev/null
+++ b/drivers/watchdog/bd70528_wdt.c
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 ROHM Semiconductors
+// ROHM BD70528MWV watchdog driver
+
+#include <linux/bcd.h>
+#include <linux/kernel.h>
+#include <linux/mfd/rohm-bd70528.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/watchdog.h>
+
+static int bd70528_wdt_set(struct bd70528 *bd70528, int enable)
+{
+	int ret;
+
+	if (bd70528->rtc_timer_lock)
+		mutex_lock(bd70528->rtc_timer_lock);
+
+	ret = bd70528->wdt_set(bd70528, enable, NULL);
+
+	if (bd70528->rtc_timer_lock)
+		mutex_unlock(bd70528->rtc_timer_lock);
+	return ret;
+}
+
+static int bd70528_wdt_start(struct watchdog_device *wdt)
+{
+	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
+
+	return bd70528_wdt_set(bd70528, 1);
+}
+
+static int bd70528_wdt_stop(struct watchdog_device *wdt)
+{
+	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
+
+	return bd70528_wdt_set(bd70528, 0);
+}
+
+static int bd70528_wdt_set_timeout(struct watchdog_device *wdt,
+				    unsigned int timeout)
+{
+	unsigned int hours;
+	unsigned int minutes;
+	unsigned int seconds;
+	int ret;
+	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
+
+	seconds = timeout;
+	hours = timeout / (60 * 60);
+	/* Maximum timeout is 1h 59m 59s => hours is 1 or 0 */
+	if (hours)
+		seconds -= (60 * 60);
+	minutes = seconds / 60;
+	seconds = seconds % 60;
+
+	if (bd70528->rtc_timer_lock)
+		mutex_lock(bd70528->rtc_timer_lock);
+
+	ret = bd70528->wdt_set(bd70528, 0, NULL);
+	if (ret)
+		goto out_unlock;
+
+	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_HOUR,
+				 BD70528_MASK_WDT_HOUR, hours);
+	if (ret) {
+		dev_err(bd70528->chip.dev, "Failed to set WDT hours\n");
+		goto out_en_unlock;
+	}
+	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_MINUTE,
+				 BD70528_MASK_WDT_MINUTE, bin2bcd(minutes));
+	if (ret) {
+		dev_err(bd70528->chip.dev, "Failed to set WDT minutes\n");
+		goto out_en_unlock;
+	}
+	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_SEC,
+				 BD70528_MASK_WDT_SEC, bin2bcd(seconds));
+	if (ret) {
+		dev_err(bd70528->chip.dev, "Failed to set WDT seconds\n");
+		goto out_en_unlock;
+	}
+
+out_en_unlock:
+	ret = bd70528->wdt_set(bd70528, 1, NULL);
+out_unlock:
+	if (bd70528->rtc_timer_lock)
+		mutex_lock(bd70528->rtc_timer_lock);
+
+	return ret;
+}
+
+static const struct watchdog_info bd70528_wdt_info = {
+	.identity = "bd70528-wdt",
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+};
+
+static const struct watchdog_ops bd70528_wdt_ops = {
+	.start		= bd70528_wdt_start,
+	.stop		= bd70528_wdt_stop,
+	/*
+	 *  bd70528 WDT ping is same as enable. Eg, writing 'enable' to enabled
+	 * WDT will restart the timeout
+	 */
+	.ping		= bd70528_wdt_start,
+	.set_timeout	= bd70528_wdt_set_timeout,
+};
+
+/* Max time we can set is 1 hour, 59 minutes and 59 seconds */
+#define WDT_MAX_MS ((2 * 60 * 60 - 1) * 1000)
+/* Minimum time is 1 second */
+#define WDT_MIN_MS 1000
+static struct watchdog_device bd70528_wd = {
+	.info = &bd70528_wdt_info,
+	.ops =  &bd70528_wdt_ops,
+	.min_hw_heartbeat_ms = WDT_MIN_MS,
+	.max_hw_heartbeat_ms = WDT_MAX_MS,
+};
+
+static int bd70528_wdt_probe(struct platform_device *pdev)
+{
+	struct bd70528 *tmp;
+	struct bd70528 *bd70528;
+	int ret;
+
+	tmp = dev_get_drvdata(pdev->dev.parent);
+	if (!tmp) {
+		dev_err(&pdev->dev, "No MFD driver data\n");
+		return -EINVAL;
+	}
+	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
+	if (!bd70528)
+		return -ENOMEM;
+
+	*bd70528 = *tmp;
+	bd70528->chip.dev = &pdev->dev;
+
+	/*
+	 * TODO: Set the initial state and timeout.
+	 * See whether the low power states require special handling
+	 */
+	watchdog_set_drvdata(&bd70528_wd, bd70528);
+	ret = devm_watchdog_register_device(&pdev->dev, &bd70528_wd);
+	if (ret < 0)
+		dev_err(&pdev->dev, "watchdog registration failed: %d\n", ret);
+
+	return ret;
+}
+static struct platform_driver bd70528_wdt = {
+	.driver = {
+		.name = "bd70528-wdt"
+	},
+	.probe = bd70528_wdt_probe,
+};
+
+module_platform_driver(bd70528_wdt);
+
+MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
+MODULE_DESCRIPTION("BD70528 watchdog driver");
+MODULE_LICENSE("GPL");
-- 
2.14.3


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 11/13] rtc: bd70528: Initial support for ROHM bd70528 RTC
  2019-01-22  9:47 ` [RFC PATCH v1 11/13] rtc: bd70528: Initial support for ROHM bd70528 RTC Matti Vaittinen
@ 2019-01-22 14:48   ` Guenter Roeck
  2019-01-22 16:29     ` Matti Vaittinen
  0 siblings, 1 reply; 33+ messages in thread
From: Guenter Roeck @ 2019-01-22 14:48 UTC (permalink / raw)
  To: Matti Vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

On 1/22/19 1:47 AM, Matti Vaittinen wrote:
> Support RTC block in ROHM bd70528 power management IC. Support
> getting and setting the time and date as well as arming an alarm
> which can also be used to wake the PMIC from standby state.
> 
> HW supports wake interrupt only for the next 24 hours (sec, minute
> and hour information only) so we limit also the alarm interrupt to
> this 24 hours for the sake of consistency.
> 
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
>   drivers/rtc/Kconfig       |   8 +
>   drivers/rtc/Makefile      |   1 +
>   drivers/rtc/rtc-bd70528.c | 439 ++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 448 insertions(+)
>   create mode 100644 drivers/rtc/rtc-bd70528.c
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 225b0b8516f3..df6211cbd83f 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -487,6 +487,14 @@ config RTC_DRV_M41T80_WDT
>   	help
>   	  If you say Y here you will get support for the
>   	  watchdog timer in the ST M41T60 and M41T80 RTC chips series.
> +config RTC_DRV_BD70528
> +	tristate "ROHM BD70528 PMIC RTC"
> +	help
> +	  If you say Y here you will get support for the RTC
> +	  on ROHM BD70528 Power Management IC.
> +
> +	  This driver can also be built as a module. If so, the module
> +	  will be called rtc-bd70528.
>   
>   config RTC_DRV_BQ32K
>   	tristate "TI BQ32000"
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> index df022d820bee..740b13840913 100644
> --- a/drivers/rtc/Makefile
> +++ b/drivers/rtc/Makefile
> @@ -36,6 +36,7 @@ obj-$(CONFIG_RTC_DRV_ASM9260)	+= rtc-asm9260.o
>   obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
>   obj-$(CONFIG_RTC_DRV_AT91SAM9)	+= rtc-at91sam9.o
>   obj-$(CONFIG_RTC_DRV_AU1XXX)	+= rtc-au1xxx.o
> +obj-$(CONFIG_RTC_DRV_BD70528)	+= rtc-bd70528.o
>   obj-$(CONFIG_RTC_DRV_BQ32K)	+= rtc-bq32k.o
>   obj-$(CONFIG_RTC_DRV_BQ4802)	+= rtc-bq4802.o
>   obj-$(CONFIG_RTC_DRV_BRCMSTB)	+= rtc-brcmstb-waketimer.o
> diff --git a/drivers/rtc/rtc-bd70528.c b/drivers/rtc/rtc-bd70528.c
> new file mode 100644
> index 000000000000..7c7e1f8769e8
> --- /dev/null
> +++ b/drivers/rtc/rtc-bd70528.c
> @@ -0,0 +1,439 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +//
> +// Copyright (C) 2018 ROHM Semiconductors
> +//
> +// RTC driver for ROHM BD70528 PMIC
> +
> +#include <linux/bcd.h>
> +#include <linux/mfd/rohm-bd70528.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/rtc.h>
> +
> +/*
> + * We read regs RTC_SEC => RTC_YEAR
> + * this struct is ordered according to chip registers.
> + * Keep it u8 only to avoid padding issues.
> + */
> +struct bd70528_rtc_day {
> +	u8 sec;
> +	u8 min;
> +	u8 hour;
> +};
> +struct bd70528_rtc_data {
> +	struct bd70528_rtc_day time;
> +	u8 week;
> +	u8 day;
> +	u8 month;
> +	u8 year;
> +};
> +struct bd70528_rtc_wake {
> +	struct bd70528_rtc_day time;
> +	u8 ctrl;
> +};
> +struct bd70528_rtc_alm {
> +	struct bd70528_rtc_data data;
> +	u8 alm_mask;
> +	u8 alm_repeat;
> +};
> +
> +static int bd70528_set_wake(struct bd70528 *bd70528,
> +			    int enable, int *old_state)
> +{
> +	int ret;
> +	unsigned int ctrl_reg;
> +
> +	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_WAKE_EN, &ctrl_reg);
> +	if (ret)
> +		return ret;
> +
> +	if (old_state) {
> +		if (ctrl_reg & BD70528_MASK_WAKE_EN)
> +			*old_state |= BD70528_WAKE_STATE_BIT;
> +		else
> +			*old_state &= ~BD70528_WAKE_STATE_BIT;
> +
> +		if ((!enable) == (!(*old_state & BD70528_WAKE_STATE_BIT)))
> +			return 0;
> +	}
> +
> +	if (enable)
> +		ctrl_reg |= BD70528_MASK_WAKE_EN;
> +	else
> +		ctrl_reg &= ~BD70528_MASK_WAKE_EN;
> +
> +	return regmap_write(bd70528->chip.regmap, BD70528_REG_WAKE_EN,
> +			    ctrl_reg);
> +}
> +
> +static int bd70528_set_elapsed_tmr(struct bd70528 *bd70528,
> +				   int enable, int *old_state)
> +{
> +	int ret;
> +	unsigned int ctrl_reg;
> +
> +	/*
> +	 * TBD
> +	 * What is the purpose of elapsed timer ?
> +	 * Is the timeout registers counting down, or is the disable - re-enable
> +	 * going to restart the elapsed-time counting? If counting is restarted
> +	 * the timeout should be decreased by the amount of time that has
> +	 * elapsed since starting the timer. Maybe we should store the monotonic
> +	 * clock value when timer is started so that if RTC is set while timer
> +	 * is armed we could do the compensation. This is a hack if RTC/system
> +	 * clk are drifting. OTOH, RTC controlled via I2C is in any case
> +	 * inaccurate...
> +	 */
> +	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_ELAPSED_TIMER_EN,
> +			  &ctrl_reg);
> +	if (ret)
> +		return ret;
> +
> +	if (old_state) {
> +		if (ctrl_reg & BD70528_MASK_ELAPSED_TIMER_EN)
> +			*old_state |= BD70528_ELAPSED_STATE_BIT;
> +		else
> +			*old_state &= ~BD70528_ELAPSED_STATE_BIT;
> +
> +		if ((!enable) == (!(*old_state & BD70528_ELAPSED_STATE_BIT)))
> +			return 0;
> +	}
> +
> +	if (enable)
> +		ctrl_reg |= BD70528_MASK_ELAPSED_TIMER_EN;
> +	else
> +		ctrl_reg &= ~BD70528_MASK_ELAPSED_TIMER_EN;
> +
> +	return regmap_write(bd70528->chip.regmap, BD70528_REG_ELAPSED_TIMER_EN,
> +			    ctrl_reg);
> +}
> +
> +static int bd70528_set_rtc_based_timers(struct bd70528 *bd70528, int new_state,
> +							int *old_state)

Passed parameter is an int, not int *. I'd be quite surprised if this compiles
without warning.

> +{
> +	int ret;
> +
> +	ret = bd70528->wdt_set(bd70528, new_state & BD70528_WDT_STATE_BIT,
> +			       old_state);
> +	if (ret) {
> +		dev_err(bd70528->chip.dev,
> +			"Failed to disable WDG for RTC setting (%d)\n", ret);
> +		return ret;
> +	}
> +	ret = bd70528_set_elapsed_tmr(bd70528,
> +				      new_state & BD70528_ELAPSED_STATE_BIT,
> +				      old_state);
> +	if (ret) {
> +		dev_err(bd70528->chip.dev,
> +			"Failed to disable 'elapsed timer' for RTC setting\n");
> +		return ret;
> +	}
> +	ret = bd70528_set_wake(bd70528, new_state & BD70528_WAKE_STATE_BIT,
> +			       old_state);
> +	if (ret) {
> +		dev_err(bd70528->chip.dev,
> +			"Failed to disable 'wake timer' for RTC setting\n");
> +		return ret;
> +	}
> +
> +	return ret;
> +}
> +
> +static int bd70528_re_enable_rtc_based_timers(struct bd70528 *bd70528,
> +							int old_state)
> +{
> +	if (bd70528->rtc_timer_lock)
> +		mutex_unlock(bd70528->rtc_timer_lock);
> +
Unlock before calling bd70528_set_rtc_based_timers is odd, especially since it
is called after locking below.

> +	return bd70528_set_rtc_based_timers(bd70528, old_state, NULL);
> +}
> +
> +static int bd70528_disable_rtc_based_timers(struct bd70528 *bd70528,
> +							int *old_state)
> +{
> +	if (bd70528->rtc_timer_lock)
> +		mutex_lock(bd70528->rtc_timer_lock);
> +
> +	return bd70528_set_rtc_based_timers(bd70528, 0, old_state);
> +}
> +
> +static inline void tmday2rtc(struct rtc_time *t, struct bd70528_rtc_day *d)
> +{
> +	d->sec &= ~BD70528_MASK_RTC_SEC;
> +	d->min &= ~BD70528_MASK_RTC_MINUTE;
> +	d->hour &= ~BD70528_MASK_RTC_HOUR;
> +	d->sec |= bin2bcd(t->tm_sec);
> +	d->min |= bin2bcd(t->tm_min);
> +	d->hour |= bin2bcd(t->tm_hour);
> +}
> +
> +static inline void tm2rtc(struct rtc_time *t, struct bd70528_rtc_data *r)
> +{
> +	r->day &= ~BD70528_MASK_RTC_DAY;
> +	r->week &= ~BD70528_MASK_RTC_WEEK;
> +	r->month &= ~BD70528_MASK_RTC_MONTH;
> +	/*
> +	 * PM and 24H bits are not used by Wake - thus iwe clear them
> +	 * here and not in tmday2rtc() which is also used by wake.
> +	 */
> +	r->time.hour &= ~(BD70528_MASK_RTC_HOUR_PM | BD70528_MASK_RTC_HOUR_24H);
> +
> +	tmday2rtc(t, &r->time);
> +	/*
> +	 * We do always set time in 24H mode.
> +	 */
> +	r->time.hour |= BD70528_MASK_RTC_HOUR_24H;
> +	r->day |= bin2bcd(t->tm_mday);
> +	r->week |= bin2bcd(t->tm_wday);
> +	r->month |= bin2bcd(t->tm_mon + 1);
> +	r->year = bin2bcd(t->tm_year-100);
> +}
> +
> +static inline void rtc2tm(struct bd70528_rtc_data *r, struct rtc_time *t)
> +{
> +	t->tm_sec = bcd2bin(r->time.sec & BD70528_MASK_RTC_SEC);
> +	t->tm_min = bcd2bin(r->time.min & BD70528_MASK_RTC_MINUTE);
> +	t->tm_hour = bcd2bin(r->time.hour & BD70528_MASK_RTC_HOUR);
> +	/*
> +	 * If RTC is in 12H mode, then bit BD70528_MASK_RTC_HOUR_PM
> +	 * is not BCD value but tells whether it is AM or PM
> +	 */
> +	if (!(r->time.hour & BD70528_MASK_RTC_HOUR_24H)) {
> +		t->tm_hour %= 12;
> +		if (r->time.hour & BD70528_MASK_RTC_HOUR_PM)
> +			t->tm_hour += 12;
> +	}
> +	t->tm_mday = bcd2bin(r->day & BD70528_MASK_RTC_DAY);
> +	t->tm_mon = bcd2bin(r->month & BD70528_MASK_RTC_MONTH) - 1;
> +	t->tm_year = 100 + bcd2bin(r->year & BD70528_MASK_RTC_YEAR);
> +	t->tm_wday = bcd2bin(r->week & BD70528_MASK_RTC_WEEK);
> +}
> +
> +static int bd70528_set_alarm(struct device *dev, struct rtc_wkalrm *a)
> +{
> +	struct bd70528 *bd70528 = dev_get_drvdata(dev);
> +	struct bd70528_rtc_wake wake;
> +	struct bd70528_rtc_alm alm;
> +	int ret;
> +
> +	ret = regmap_bulk_read(bd70528->chip.regmap, BD70528_REG_RTC_WAKE_START,
> +			       &wake, sizeof(wake));
> +	if (ret) {
> +		dev_err(dev, "Failed to read wake regs\n");
> +		return ret;
> +	}
> +
> +	ret = regmap_bulk_read(bd70528->chip.regmap, BD70528_REG_RTC_ALM_START,
> +			       &alm, sizeof(alm));
> +	if (ret) {
> +		dev_err(dev, "Failed to read alarm regs\n");
> +		return ret;
> +	}
> +
> +	tm2rtc(&a->time, &alm.data);
> +	tmday2rtc(&a->time, &wake.time);
> +
> +	if (a->enabled) {
> +		alm.alm_mask &= ~BD70528_MASK_ALM_EN;
> +		wake.ctrl |= BD70528_MASK_WAKE_EN;
> +	} else {
> +		alm.alm_mask |= BD70528_MASK_ALM_EN;
> +		wake.ctrl &= ~BD70528_MASK_WAKE_EN;
> +	}
> +
> +	ret = regmap_bulk_write(bd70528->chip.regmap,
> +				BD70528_REG_RTC_WAKE_START, &wake,
> +				sizeof(wake));
> +	if (ret) {
> +		dev_err(dev, "Failed to set wake time\n");
> +		return ret;
> +	}
> +	ret = regmap_bulk_write(bd70528->chip.regmap, BD70528_REG_RTC_ALM_START,
> +				&alm, sizeof(alm));
> +	if (ret)
> +		dev_err(dev, "Failed to set alarm time\n");
> +
> +	return ret;
> +}
> +
> +static int bd70528_read_alarm(struct device *dev, struct rtc_wkalrm *a)
> +{
> +	struct bd70528 *bd70528 = dev_get_drvdata(dev);
> +	struct bd70528_rtc_alm alm;
> +	int ret;
> +
> +	ret = regmap_bulk_read(bd70528->chip.regmap, BD70528_REG_RTC_ALM_START,
> +			  &alm, sizeof(alm));
> +	if (ret) {
> +		dev_err(dev, "Failed to read alarm regs\n");
> +		return ret;
> +	}
> +
> +	rtc2tm(&alm.data, &a->time);
> +	a->time.tm_mday = -1;
> +	a->time.tm_mon = -1;
> +	a->time.tm_year = -1;
> +	if (alm.alm_mask & BD70528_MASK_ALM_EN)
> +		a->enabled = 0;
> +	else
> +		a->enabled = 1;
> +
> +	a->pending = 0;
> +
> +	return 0;
> +}
> +
> +static int bd70528_set_time(struct device *dev, struct rtc_time *t)
> +{
> +	int ret, old_states;
> +	struct bd70528_rtc_data rtc_data;
> +	struct bd70528 *bd70528 = dev_get_drvdata(dev);
> +
> +	ret = bd70528_disable_rtc_based_timers(bd70528, &old_states);
> +
> +	ret = regmap_bulk_read(bd70528->chip.regmap,
> +			       BD70528_REG_RTC_START, &rtc_data,
> +			       sizeof(rtc_data));
> +
> +	tm2rtc(t, &rtc_data);
> +
> +	ret = regmap_bulk_write(bd70528->chip.regmap,
> +				BD70528_REG_RTC_START, &rtc_data,
> +				sizeof(rtc_data));
> +
> +	ret = bd70528_re_enable_rtc_based_timers(bd70528, old_states);
> +
> +	return 0;
> +}
> +static int bd70528_get_time(struct device *dev, struct rtc_time *t)
> +{
> +	struct bd70528 *bd70528 = dev_get_drvdata(dev);
> +	struct bd70528_rtc_data rtc_data;
> +	int ret;
> +
> +	/* read the RTC date and time registers all at once */
> +	ret = regmap_bulk_read(bd70528->chip.regmap,
> +			       BD70528_REG_RTC_START, &rtc_data,
> +			       sizeof(rtc_data));
> +	if (ret) {
> +		dev_err(dev, "Failed to read RTC time (err %d)\n", ret);
> +		return ret;
> +	}
> +
> +	rtc2tm(&rtc_data, t);
> +
> +	return 0;
> +}
> +
> +static const struct rtc_class_ops bd70528_rtc_ops = {
> +	.read_time	= bd70528_get_time,
> +	.set_time	= bd70528_set_time,
> +	.read_alarm	= bd70528_read_alarm,
> +	.set_alarm	= bd70528_set_alarm,
> +};
> +
> +static irqreturn_t alm_hndlr(int irq, void *data)
> +{
> +	struct rtc_device *rtc = data;
> +
> +	rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF | RTC_PF);
> +	return IRQ_HANDLED;
> +}
> +
> +static int bd70528_probe(struct platform_device *pdev)
> +{
> +	struct bd70528 *bd70528;
> +	struct bd70528 *tmp;
> +	int ret;
> +	struct rtc_device *rtc;
> +	int irq;
> +	unsigned int hr;
> +
> +	tmp = dev_get_drvdata(pdev->dev.parent);
> +	if (!tmp) {
> +		dev_err(&pdev->dev, "No MFD driver data\n");
> +		return -EINVAL;
> +	}
> +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> +	if (!bd70528)
> +		return -ENOMEM;
> +
> +	*bd70528 = *tmp;
> +	bd70528->chip.dev = &pdev->dev;
> +
> +	irq = platform_get_irq_byname(pdev, "bd70528-rtc-alm");
> +
> +	if (irq < 0) {
> +		dev_err(&pdev->dev, "Failed to get irq\n");
> +		return irq;
> +	}
> +
> +	platform_set_drvdata(pdev, bd70528);
> +
> +
> +	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_RTC_HOUR, &hr);
> +
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to reag RTC clock\n");
> +		return ret;
> +	}
> +
> +	if (!(hr & BD70528_MASK_RTC_HOUR_24H)) {
> +		struct rtc_time t;
> +
> +		ret = bd70528_get_time(&pdev->dev, &t);
> +		if (ret)
> +			return ret;
> +
> +		ret = bd70528_set_time(&pdev->dev, &t);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	if (ret) {
> +		dev_err(&pdev->dev, "Setting 24H clock for RTC failed\n");
> +		return ret;
> +	}
> +
> +	device_set_wakeup_capable(&pdev->dev, true);
> +	device_wakeup_enable(&pdev->dev);
> +	rtc = devm_rtc_device_register(&pdev->dev, "bd70528-rtc",
> +				       &bd70528_rtc_ops, THIS_MODULE);
> +	if (IS_ERR(rtc)) {
> +		dev_err(&pdev->dev, "Registering RTC failed\n");
> +		return PTR_ERR(rtc);
> +	}
> +
> +	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, &alm_hndlr,
> +					IRQF_ONESHOT, "bd70528-rtc", rtc);
> +
> +	/*
> +	 *  BD70528 irq controller is not touching the main mask register.
> +	 *  So enable the RTC block interrupts at main level. We can just
> +	 *  leave them enabled as irq-controller should disable irqs
> +	 *  from sub-registers when IRQ is disabled or freed.
> +	 */
> +	ret = regmap_update_bits(bd70528->chip.regmap,
> +				 BD70528_REG_INT_MAIN,
> +				 BD70528_INT_RTC_MASK, 0);
> +
> +	if (ret)
> +		dev_err(&pdev->dev, "Failed to enable RTC interrupts\n");
> +
> +	return ret;
> +}
> +
> +static struct platform_driver bd70528_rtc = {
> +	.driver = {
> +		.name = "bd70528-rtc"
> +	},
> +	.probe = bd70528_probe,
> +};
> +
> +module_platform_driver(bd70528_rtc);
> +
> +MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
> +MODULE_DESCRIPTION("BD70528 RTC driver");
> +MODULE_LICENSE("GPL");
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 05/13] mfd: bd70528: Support ROHM bd70528 PMIC - core
  2019-01-22  9:44 ` [RFC PATCH v1 05/13] mfd: bd70528: Support ROHM bd70528 PMIC - core Matti Vaittinen
@ 2019-01-22 14:51   ` Guenter Roeck
  2019-01-22 16:20     ` Matti Vaittinen
  0 siblings, 1 reply; 33+ messages in thread
From: Guenter Roeck @ 2019-01-22 14:51 UTC (permalink / raw)
  To: Matti Vaittinen, mazziesaccount
  Cc: lee.jones, robh+dt, mark.rutland, lgirdwood, broonie, gregkh,
	rafael, mturquette, sboyd, linus.walleij, bgolaszewski, sre,
	a.zummo, alexandre.belloni, wim, devicetree, linux-kernel,
	linux-clk, linux-gpio, linux-pm, linux-rtc, linux-watchdog,
	mikko.mutanen, heikki.haikola

On 1/22/19 1:44 AM, Matti Vaittinen wrote:
> ROHM BD70528MWV is an ultra-low quiescent current general
> purpose single-chip power management IC for battery-powered
> portable devices.
> 
> Add MFD core which enables chip access for following subdevices:
> 	- regulators/LED drivers
> 	- battery-charger
> 	- gpios
> 	- 32.768kHz clk
> 	- RTC
> 	- watchdog
> 
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
>   drivers/mfd/Kconfig              |  17 ++
>   drivers/mfd/Makefile             |   1 +
>   drivers/mfd/rohm-bd70528.c       | 409 +++++++++++++++++++++++++++++++++++++++
>   include/linux/mfd/rohm-bd70528.h | 392 +++++++++++++++++++++++++++++++++++++
>   4 files changed, 819 insertions(+)
>   create mode 100644 drivers/mfd/rohm-bd70528.c
>   create mode 100644 include/linux/mfd/rohm-bd70528.h
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 8c5dfdce4326..d47eca440ece 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1846,6 +1846,23 @@ config MFD_ROHM_BD718XX
>   	  NXP i.MX8. It contains 8 BUCK outputs and 7 LDOs, voltage monitoring
>   	  and emergency shut down as well as 32,768KHz clock output.
>   
> +config MFD_ROHM_BD70528
> +	tristate "ROHM BD70528 Power Management IC"
> +	depends on I2C=y
> +	depends on OF
> +	select REGMAP_I2C
> +	select REGMAP_IRQ
> +	select MFD_CORE
> +	help
> +	  Select this option to get support for the ROHM BD70528 Power
> +	  Management IC. BD71837 is general purpose single-chip power
> +	  management IC for battery-powered portable devices. It contains
> +	  3 ultra-low current consumption buck converters, 3 LDOs and 2 LED
> +	  Drivers. Also included are 4 GPIOs, a real-time clock (RTC), a 32kHz
> +	  crystal oscillator, high-accuracy VREF for use with an external ADC,
> +	  10 bits SAR ADC for battery temperature monitor and 1S battery
> +	  charger.
> +
>   config MFD_STM32_LPTIMER
>   	tristate "Support for STM32 Low-Power Timer"
>   	depends on (ARCH_STM32 && OF) || COMPILE_TEST
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 12980a4ad460..fc9b1408e39b 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -241,4 +241,5 @@ obj-$(CONFIG_MFD_MXS_LRADC)     += mxs-lradc.o
>   obj-$(CONFIG_MFD_SC27XX_PMIC)	+= sprd-sc27xx-spi.o
>   obj-$(CONFIG_RAVE_SP_CORE)	+= rave-sp.o
>   obj-$(CONFIG_MFD_ROHM_BD718XX)	+= rohm-bd718x7.o
> +obj-$(CONFIG_MFD_ROHM_BD70528)	+= rohm-bd70528.o
>   
> diff --git a/drivers/mfd/rohm-bd70528.c b/drivers/mfd/rohm-bd70528.c
> new file mode 100644
> index 000000000000..c2bf6c1a7136
> --- /dev/null
> +++ b/drivers/mfd/rohm-bd70528.c
> @@ -0,0 +1,409 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +//
> +// Copyright (C) 2018 ROHM Semiconductors
> +//
> +// ROHM BD70528 PMIC driver
> +
> +#include <linux/i2c.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/rohm-bd70528.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/regmap.h>
> +#include <linux/types.h>
> +
> +#define BD70528_INT_RES(_reg, _name)		\
> +	{					\
> +		.start = (_reg),		\
> +		.end = (_reg),			\
> +		.name = (_name),		\
> +		.flags = IORESOURCE_IRQ,	\
> +	}
> +
> +static DEFINE_MUTEX(rtc_timer_mutex);
> +
> +static const struct resource rtc_irqs[] = {
> +	BD70528_INT_RES(BD70528_INT_RTC_ALARM, "bd70528-rtc-alm"),
> +	BD70528_INT_RES(BD70528_INT_ELPS_TIM, "bd70528-elapsed-timer"),
> +};
> +
> +static const struct resource charger_irqs[] = {
> +	BD70528_INT_RES(BD70528_INT_BAT_OV_RES, "bd70528-bat-ov-res"),
> +	BD70528_INT_RES(BD70528_INT_BAT_OV_DET, "bd70528-bat-ov-det"),
> +	BD70528_INT_RES(BD70528_INT_DBAT_DET, "bd70528-bat-dead"),
> +	BD70528_INT_RES(BD70528_INT_BATTSD_COLD_RES, "bd70528-bat-warmed"),
> +	BD70528_INT_RES(BD70528_INT_BATTSD_COLD_DET, "bd70528-bat-cold"),
> +	BD70528_INT_RES(BD70528_INT_BATTSD_HOT_RES, "bd70528-bat-cooled"),
> +	BD70528_INT_RES(BD70528_INT_BATTSD_HOT_DET, "bd70528-bat-hot"),
> +	BD70528_INT_RES(BD70528_INT_CHG_TSD, "bd70528-chg-tshd"),
> +	BD70528_INT_RES(BD70528_INT_BAT_RMV, "bd70528-bat-removed"),
> +	BD70528_INT_RES(BD70528_INT_BAT_DET, "bd70528-bat-detected"),
> +	BD70528_INT_RES(BD70528_INT_DCIN2_OV_RES, "bd70528-dcin2-ov-res"),
> +	BD70528_INT_RES(BD70528_INT_DCIN2_OV_DET, "bd70528-dcin2-ov-det"),
> +	BD70528_INT_RES(BD70528_INT_DCIN2_RMV, "bd70528-dcin2-removed"),
> +	BD70528_INT_RES(BD70528_INT_DCIN2_DET, "bd70528-dcin2-detected"),
> +	BD70528_INT_RES(BD70528_INT_DCIN1_RMV, "bd70528-dcin1-removed"),
> +	BD70528_INT_RES(BD70528_INT_DCIN1_DET, "bd70528-dcin1-detected"),
> +};
> +
> +static struct mfd_cell bd70528_mfd_cells[] = {
> +	{ .name = "bd70528-pmic", },
> +	{ .name = "bd70528-gpio", },
> +	/*
> +	 * We use BD71837 driver to drive the clk block. Only differences to
> +	 * BD70528 clock gate are the register address and mask.
> +	 */
> +	{ .name = "bd718xx-clk", },
> +	{ .name = "bd70528-wdt", },
> +	{
> +		.name = "bd70528-power",
> +		.resources = &charger_irqs[0],
> +		.num_resources = ARRAY_SIZE(charger_irqs),
> +	},
> +	{
> +		.name = "bd70528-rtc",
> +		.resources = &rtc_irqs[0],
> +		.num_resources = ARRAY_SIZE(rtc_irqs),
> +	},
> +};
> +
> +static const struct regmap_range volatile_ranges[] = {
> +	/* IRQ regs */
> +	{
> +		.range_min = BD70528_REG_INT_MAIN,
> +		.range_max = BD70528_REG_INT_OP_FAIL,
> +	},
> +	/* RTC regs */
> +	{
> +		.range_min = BD70528_REG_RTC_COUNT_H,
> +		.range_max = BD70528_REG_RTC_ALM_REPEAT,
> +	},
> +	/*
> +	 * WDT control reg is special. Magic values must be
> +	 * written to it in order to change the control. Should
> +	 * not be cached.
> +	 */
> +	{
> +		.range_min = BD70528_REG_WDT_CTRL,
> +		.range_max = BD70528_REG_WDT_CTRL,
> +	},
> +	/*
> +	 * bd70528 contains also few other registers which require
> +	 * magic sequence to be written in order to update the value.
> +	 * At least SHIPMODE, HWRESET, WARMRESET,and STANDBY
> +	 */
> +	{
> +		.range_min = BD70528_REG_SHIPMODE,
> +		.range_max = BD70528_REG_STANDBY,
> +	},
> +};
> +
> +static const struct regmap_access_table volatile_regs = {
> +	.yes_ranges = &volatile_ranges[0],
> +	.n_yes_ranges = ARRAY_SIZE(volatile_ranges),
> +};
> +
> +static struct regmap_config bd70528_regmap = {
> +	.reg_bits = 8,
> +	.val_bits = 8,
> +	.volatile_table = &volatile_regs,
> +	.max_register = BD70528_MAX_REGISTER,
> +	.cache_type = REGCACHE_RBTREE,
> +};
> +/* bit [0] - Shutdown register */
> +unsigned int bit0_offsets[] = {0};
> +/* bit [1] - Power failure register */
> +unsigned int bit1_offsets[] = {1};
> +/* bit [2] - VR FAULT register */
> +unsigned int bit2_offsets[] = {2};
> +/* bit [3] - PMU register interrupts */
> +unsigned int bit3_offsets[] = {3};
> +/* bit [4] - Charger 1 and Charger 2 registers */
> +unsigned int bit4_offsets[] = {4, 5};
> +/* bit [5] - RTC register */
> +unsigned int bit5_offsets[] = {6};
> +/* bit [6] - GPIO register */
> +unsigned int bit6_offsets[] = {7};
> +/* bit [7] - Invalid operation register */
> +unsigned int bit7_offsets[] = {8};
> +
> +static struct regmap_irq_sub_irq_map bd70528_sub_irq_offsets[] = {
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit0_offsets),
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit1_offsets),
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit2_offsets),
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit3_offsets),
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit4_offsets),
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit5_offsets),
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit6_offsets),
> +	REGMAP_IRQ_MAIN_REG_OFFSET(bit7_offsets),
> +};
> +
> +static struct regmap_irq irqs[] = {
> +	REGMAP_IRQ_REG(BD70528_INT_LONGPUSH, 0, BD70528_INT_LONGPUSH_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_WDT, 0, BD70528_INT_WDT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_HWRESET, 0, BD70528_INT_HWRESET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_RSTB_FAULT, 0, BD70528_INT_RSTB_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_VBAT_UVLO, 0, BD70528_INT_VBAT_UVLO_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_TSD, 0, BD70528_INT_TSD_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_RSTIN, 0, BD70528_INT_RSTIN_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK1_FAULT, 1,
> +		       BD70528_INT_BUCK1_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK2_FAULT, 1,
> +		       BD70528_INT_BUCK2_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK3_FAULT, 1,
> +		       BD70528_INT_BUCK3_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LDO1_FAULT, 1, BD70528_INT_LDO1_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LDO2_FAULT, 1, BD70528_INT_LDO2_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LDO3_FAULT, 1, BD70528_INT_LDO3_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LED1_FAULT, 1, BD70528_INT_LED1_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LED2_FAULT, 1, BD70528_INT_LED2_FAULT_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK1_OCP, 2, BD70528_INT_BUCK1_OCP_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK2_OCP, 2, BD70528_INT_BUCK2_OCP_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK3_OCP, 2, BD70528_INT_BUCK3_OCP_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LED1_OCP, 2, BD70528_INT_LED1_OCP_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LED2_OCP, 2, BD70528_INT_LED2_OCP_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK1_FULLON, 2,
> +		       BD70528_INT_BUCK1_FULLON_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK2_FULLON, 2,
> +		       BD70528_INT_BUCK2_FULLON_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_SHORTPUSH, 3, BD70528_INT_SHORTPUSH_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_AUTO_WAKEUP, 3,
> +		       BD70528_INT_AUTO_WAKEUP_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_STATE_CHANGE, 3,
> +		       BD70528_INT_STATE_CHANGE_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BAT_OV_RES, 4, BD70528_INT_BAT_OV_RES_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BAT_OV_DET, 4, BD70528_INT_BAT_OV_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_DBAT_DET, 4, BD70528_INT_DBAT_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BATTSD_COLD_RES, 4,
> +		       BD70528_INT_BATTSD_COLD_RES_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BATTSD_COLD_DET, 4,
> +		       BD70528_INT_BATTSD_COLD_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BATTSD_HOT_RES, 4,
> +		       BD70528_INT_BATTSD_HOT_RES_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BATTSD_HOT_DET, 4,
> +		       BD70528_INT_BATTSD_HOT_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_CHG_TSD, 4, BD70528_INT_CHG_TSD_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BAT_RMV, 5, BD70528_INT_BAT_RMV_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BAT_DET, 5, BD70528_INT_BAT_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_DCIN2_OV_RES, 5,
> +		       BD70528_INT_DCIN2_OV_RES_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_DCIN2_OV_DET, 5,
> +		       BD70528_INT_DCIN2_OV_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_DCIN2_RMV, 5, BD70528_INT_DCIN2_RMV_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_DCIN2_DET, 5, BD70528_INT_DCIN2_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_DCIN1_RMV, 5, BD70528_INT_DCIN1_RMV_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_DCIN1_DET, 5, BD70528_INT_DCIN1_DET_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_RTC_ALARM, 6, BD70528_INT_RTC_ALARM_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_ELPS_TIM, 6, BD70528_INT_ELPS_TIM_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_GPIO0, 7, BD70528_INT_GPIO0_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_GPIO1, 7, BD70528_INT_GPIO1_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_GPIO2, 7, BD70528_INT_GPIO2_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_GPIO3, 7, BD70528_INT_GPIO3_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK1_DVS_OPFAIL, 8,
> +		       BD70528_INT_BUCK1_DVS_OPFAIL_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK2_DVS_OPFAIL, 8,
> +		       BD70528_INT_BUCK2_DVS_OPFAIL_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_BUCK3_DVS_OPFAIL, 8,
> +		       BD70528_INT_BUCK3_DVS_OPFAIL_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LED1_VOLT_OPFAIL, 8,
> +		       BD70528_INT_LED1_VOLT_OPFAIL_MASK),
> +	REGMAP_IRQ_REG(BD70528_INT_LED2_VOLT_OPFAIL, 8,
> +		       BD70528_INT_LED2_VOLT_OPFAIL_MASK),
> +};
> +
> +static struct regmap_irq_chip bd70528_irq_chip = {
> +	.name = "bd70528_irq",
> +	.main_status = BD70528_REG_INT_MAIN,
> +	.irqs = &irqs[0],
> +	.num_irqs = ARRAY_SIZE(irqs),
> +	.status_base = BD70528_REG_INT_SHDN,
> +	.mask_base = BD70528_REG_INT_SHDN_MASK,
> +	.ack_base = BD70528_REG_INT_SHDN,
> +	.type_base = BD70528_REG_GPIO1_IN,
> +	.init_ack_masked = true,
> +	.num_regs = 9,
> +	.num_main_regs = 1,
> +	.num_type_reg = 4,
> +	.sub_reg_offsets = &bd70528_sub_irq_offsets[0],
> +	.num_main_status_bits = 8,
> +	.irq_reg_stride = 1,
> +};
> +
> +#define WD_CTRL_MAGIC1 0x55
> +#define WD_CTRL_MAGIC2 0xAA
> +
> +static int bd70528_wdt_set(struct bd70528 *bd70528, int enable, int *old_state)
> +{
> +	int ret, i;
> +	unsigned int tmp;
> +	u8 wd_ctrl_arr[3] = { WD_CTRL_MAGIC1, WD_CTRL_MAGIC2, 0 };
> +	u8 *wd_ctrl = &wd_ctrl_arr[2];
> +
> +	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_WDT_CTRL, &tmp);
> +	if (ret)
> +		return ret;
> +
> +	*wd_ctrl = (u8)tmp;
> +
> +	if (old_state) {
> +		if (*wd_ctrl & BD70528_MASK_WDT_EN)
> +			*old_state |= BD70528_WDT_STATE_BIT;
> +		else
> +			*old_state &= ~BD70528_WDT_STATE_BIT;
> +		if ((!enable) == (!(*old_state & BD70528_WDT_STATE_BIT)))
> +			return 0;
> +	}
> +
> +	if (enable) {
> +		if (*wd_ctrl & BD70528_MASK_WDT_EN)
> +			return 0;
> +		*wd_ctrl |= BD70528_MASK_WDT_EN;
> +	} else {
> +		if (*wd_ctrl & BD70528_MASK_WDT_EN)
> +			*wd_ctrl &= ~BD70528_MASK_WDT_EN;
> +		else
> +			return 0;
> +	}
> +
> +	for (i = 0; i < 3; i++) {
> +		ret = regmap_write(bd70528->chip.regmap, BD70528_REG_WDT_CTRL,
> +				   wd_ctrl_arr[i]);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	ret = regmap_read(bd70528->chip.regmap, BD70528_REG_WDT_CTRL, &tmp);
> +	if ((tmp & BD70528_MASK_WDT_EN) != (*wd_ctrl & BD70528_MASK_WDT_EN)) {
> +		dev_err(bd70528->chip.dev,
> +			"Watchdog ctrl mismatch (hw) 0x%x (set) 0x%x\n",
> +			tmp, *wd_ctrl);
> +		ret = -EIO;
> +	}
> +	return ret;
> +}
> +
> +static int bd70528_i2c_probe(struct i2c_client *i2c,
> +			    const struct i2c_device_id *id)
> +{
> +	struct bd70528 *bd70528;
> +	struct regmap_irq_chip_data *irq_data;
> +	int ret, i;
> +
> +	if (!i2c->irq) {
> +		dev_err(&i2c->dev, "No IRQ configured\n");
> +		return -EINVAL;
> +	}
> +	bd70528 = devm_kzalloc(&i2c->dev, sizeof(*bd70528), GFP_KERNEL);
> +
> +	if (!bd70528)
> +		return -ENOMEM;
> +
> +	dev_set_drvdata(&i2c->dev, bd70528);
> +	bd70528->rtc_timer_lock = &rtc_timer_mutex;

One global mutex for all instances of this driver is odd.
Why isn't this just part of struct bd70528 ?

> +	bd70528->chip.chip_type = ROHM_CHIP_TYPE_BD70528;
> +	bd70528->wdt_set = bd70528_wdt_set;
> +	bd70528->chip.regmap = devm_regmap_init_i2c(i2c, &bd70528_regmap);
> +	if (IS_ERR(bd70528->chip.regmap)) {
> +		dev_err(&i2c->dev, "regmap initialization failed\n");
> +		return PTR_ERR(bd70528->chip.regmap);
> +	}
> +
> +	/*
> +	 * Disallow type setting for all IRQs by default as
> +	 *  most of them do not support setting type.
> +	 */
> +	for (i = 0; i < ARRAY_SIZE(irqs); i++)
> +		irqs[i].type.types_supported = 0;
> +
> +	irqs[BD70528_INT_GPIO0].type.type_reg_offset = 0;
> +	irqs[BD70528_INT_GPIO0].type.type_rising_val = 0x20;
> +	irqs[BD70528_INT_GPIO0].type.type_falling_val = 0x10;
> +	irqs[BD70528_INT_GPIO0].type.type_level_high_val = 0x40;
> +	irqs[BD70528_INT_GPIO0].type.type_level_low_val = 0x50;
> +	irqs[BD70528_INT_GPIO0].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
> +				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
> +	irqs[BD70528_INT_GPIO1].type.type_reg_offset = 2;
> +	irqs[BD70528_INT_GPIO1].type.type_rising_val = 0x20;
> +	irqs[BD70528_INT_GPIO1].type.type_falling_val = 0x10;
> +	irqs[BD70528_INT_GPIO1].type.type_level_high_val = 0x40;
> +	irqs[BD70528_INT_GPIO1].type.type_level_low_val = 0x50;
> +	irqs[BD70528_INT_GPIO1].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
> +				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
> +	irqs[BD70528_INT_GPIO2].type.type_reg_offset = 4;
> +	irqs[BD70528_INT_GPIO2].type.type_rising_val = 0x20;
> +	irqs[BD70528_INT_GPIO2].type.type_falling_val = 0x10;
> +	irqs[BD70528_INT_GPIO2].type.type_level_high_val = 0x40;
> +	irqs[BD70528_INT_GPIO2].type.type_level_low_val = 0x50;
> +	irqs[BD70528_INT_GPIO2].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
> +				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
> +	irqs[BD70528_INT_GPIO3].type.type_reg_offset = 6;
> +	irqs[BD70528_INT_GPIO3].type.type_rising_val = 0x20;
> +	irqs[BD70528_INT_GPIO3].type.type_falling_val = 0x10;
> +	irqs[BD70528_INT_GPIO3].type.type_level_high_val = 0x40;
> +	irqs[BD70528_INT_GPIO3].type.type_level_low_val = 0x50;
> +	irqs[BD70528_INT_GPIO3].type.types_supported = (IRQ_TYPE_EDGE_BOTH |
> +				IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW);
> +
> +	ret = devm_regmap_add_irq_chip(&i2c->dev, bd70528->chip.regmap,
> +				       i2c->irq, IRQF_ONESHOT, 0,
> +				       &bd70528_irq_chip, &irq_data);
> +	if (ret) {
> +		dev_err(&i2c->dev, "Failed to add irq_chip\n");
> +		return ret;
> +	}
> +	dev_dbg(&i2c->dev, "Registered %d irqs for chip\n",
> +			bd70528_irq_chip.num_irqs);
> +
> +	/*
> +	 * BD70528 irq controller is not touching the main mask register.
> +	 * So enable the GPIO block interrupts at main level. We can just
> +	 * leave them enabled as irq-controller should disable irqs
> +	 * from sub-registers when IRQ is disabled or freed.
> +	 */
> +	ret = regmap_update_bits(bd70528->chip.regmap,
> +				 BD70528_REG_INT_MAIN_MASK,
> +				 BD70528_INT_GPIO_MASK, 0);
> +
> +	ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
> +				   bd70528_mfd_cells,
> +				   ARRAY_SIZE(bd70528_mfd_cells), NULL, 0,
> +				   regmap_irq_get_domain(irq_data));
> +	if (ret)
> +		dev_err(&i2c->dev, "Failed to create subdevices\n");
> +
> +	return ret;
> +}
> +
> +static const struct of_device_id bd70528_of_match[] = {
> +	{
> +		.compatible = "rohm,bd70528",
> +	},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, bd70528_of_match);
> +
> +static struct i2c_driver bd70528_drv = {
> +	.driver = {
> +		.name = "rohm-bd70528",
> +		.of_match_table = bd70528_of_match,
> +	},
> +	.probe = &bd70528_i2c_probe,
> +};
> +
> +static int __init bd70528_init(void)
> +{
> +	return i2c_add_driver(&bd70528_drv);
> +}
> +subsys_initcall(bd70528_init);
> +
> +static void __exit bd70528_exit(void)
> +{
> +	i2c_del_driver(&bd70528_drv);
> +}
> +module_exit(bd70528_exit);
> +
> +MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
> +MODULE_DESCRIPTION("ROHM BD70528 Power Management IC driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/mfd/rohm-bd70528.h b/include/linux/mfd/rohm-bd70528.h
> new file mode 100644
> index 000000000000..2ac0701309b8
> --- /dev/null
> +++ b/include/linux/mfd/rohm-bd70528.h
> @@ -0,0 +1,392 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/* Copyright (C) 2018 ROHM Semiconductors */
> +
> +#ifndef __LINUX_MFD_BD70528_H__
> +#define __LINUX_MFD_BD70528_H__
> +
> +#include <linux/device.h>
> +#include <linux/mfd/rohm-generic.h>
> +#include <linux/regmap.h>
> +
> +struct bd70528 {
> +	/*
> +	 * Please keep this as the first member here as some
> +	 * drivers (clk) supporting more than one chip may only know this
> +	 * generic struct 'struct rohm_regmap_dev' and assume it is
> +	 * the first chunk of parent device's private data.
> +	 */
> +	struct rohm_regmap_dev chip;
> +	/* wdt_set must be called rtc_timer_lock held */
> +	int (*wdt_set)(struct bd70528 *bd70528, int enable, int *old_state);
> +	struct mutex *rtc_timer_lock;
> +};
> +
> +enum {
> +	BD70528_BUCK1,
> +	BD70528_BUCK2,
> +	BD70528_BUCK3,
> +	BD70528_LDO1,
> +	BD70528_LDO2,
> +	BD70528_LDO3,
> +	BD70528_LED1,
> +	BD70528_LED2,
> +};
> +
> +#define BD70528_BUCK_VOLTS 17
> +#define BD70528_BUCK_VOLTS 17
> +#define BD70528_BUCK_VOLTS 17
> +#define BD70528_LDO_VOLTS 0x20
> +
> +#define BD70528_REG_BUCK1_EN	0x0F
> +#define BD70528_REG_BUCK1_VOLT	0x15
> +#define BD70528_REG_BUCK2_EN	0x10
> +#define BD70528_REG_BUCK2_VOLT	0x16
> +#define BD70528_REG_BUCK3_EN	0x11
> +#define BD70528_REG_BUCK3_VOLT	0x17
> +#define BD70528_REG_LDO1_EN	0x1b
> +#define BD70528_REG_LDO1_VOLT	0x1e
> +#define BD70528_REG_LDO2_EN	0x1c
> +#define BD70528_REG_LDO2_VOLT	0x1f
> +#define BD70528_REG_LDO3_EN	0x1d
> +#define BD70528_REG_LDO3_VOLT	0x20
> +#define BD70528_REG_LED_CTRL	0x2b
> +#define BD70528_REG_LED_VOLT	0x29
> +#define BD70528_REG_LED_EN	0x2a
> +
> +/* main irq registers */
> +#define BD70528_REG_INT_MAIN	0x7E
> +#define BD70528_REG_INT_MAIN_MASK 0x74
> +
> +/* 'sub irq' registers */
> +#define BD70528_REG_INT_SHDN	0x7F
> +#define BD70528_REG_INT_PWR_FLT	0x80
> +#define BD70528_REG_INT_VR_FLT	0x81
> +#define BD70528_REG_INT_MISC	0x82
> +#define BD70528_REG_INT_BAT1	0x83
> +#define BD70528_REG_INT_BAT2	0x84
> +#define BD70528_REG_INT_RTC	0x85
> +#define BD70528_REG_INT_GPIO	0x86
> +#define BD70528_REG_INT_OP_FAIL	0x87
> +
> +#define BD70528_REG_INT_SHDN_MASK	0x75
> +#define BD70528_REG_INT_PWR_FLT_MASK	0x76
> +#define BD70528_REG_INT_VR_FLT_MASK	0x77
> +#define BD70528_REG_INT_MISC_MASK	0x78
> +#define BD70528_REG_INT_BAT1_MASK	0x79
> +#define BD70528_REG_INT_BAT2_MASK	0x7a
> +#define BD70528_REG_INT_RTC_MASK	0x7b
> +#define BD70528_REG_INT_GPIO_MASK	0x7c
> +#define BD70528_REG_INT_OP_FAIL_MASK	0x7d
> +
> +/* Reset related 'magic' registers */
> +#define BD70528_REG_SHIPMODE	0x03
> +#define BD70528_REG_HWRESET	0x04
> +#define BD70528_REG_WARMRESET	0x05
> +#define BD70528_REG_STANDBY	0x06
> +
> +/* GPIO registers */
> +#define BD70528_REG_GPIO_STATE	0x8F
> +
> +#define BD70528_REG_GPIO1_IN	0x4d
> +#define BD70528_REG_GPIO2_IN	0x4f
> +#define BD70528_REG_GPIO3_IN	0x51
> +#define BD70528_REG_GPIO4_IN	0x53
> +#define BD70528_REG_GPIO1_OUT	0x4e
> +#define BD70528_REG_GPIO2_OUT	0x50
> +#define BD70528_REG_GPIO3_OUT	0x52
> +#define BD70528_REG_GPIO4_OUT	0x54
> +
> +/* clk control */
> +
> +#define BD70528_REG_CLK_OUT	0x2c
> +
> +/* RTC */
> +
> +#define BD70528_REG_RTC_COUNT_H		0x2d
> +#define BD70528_REG_RTC_COUNT_L		0x2e
> +#define BD70528_REG_RTC_SEC		0x2f
> +#define BD70528_REG_RTC_MINUTE		0x30
> +#define BD70528_REG_RTC_HOUR		0x31
> +#define BD70528_REG_RTC_WEEK		0x32
> +#define BD70528_REG_RTC_DAY		0x33
> +#define BD70528_REG_RTC_MONTH		0x34
> +#define BD70528_REG_RTC_YEAR		0x35
> +
> +#define BD70528_REG_RTC_ALM_SEC		0x36
> +#define BD70528_REG_RTC_ALM_START	BD70528_REG_RTC_ALM_SEC
> +#define BD70528_REG_RTC_ALM_MINUTE	0x37
> +#define BD70528_REG_RTC_ALM_HOUR	0x38
> +#define BD70528_REG_RTC_ALM_WEEK	0x39
> +#define BD70528_REG_RTC_ALM_DAY		0x3a
> +#define BD70528_REG_RTC_ALM_MONTH	0x3b
> +#define BD70528_REG_RTC_ALM_YEAR	0x3c
> +#define BD70528_REG_RTC_ALM_MASK	0x3d
> +#define BD70528_REG_RTC_ALM_REPEAT	0x3e
> +#define BD70528_REG_RTC_START		BD70528_REG_RTC_SEC
> +
> +#define BD70528_REG_RTC_WAKE_SEC	0x43
> +#define BD70528_REG_RTC_WAKE_START	BD70528_REG_RTC_WAKE_SEC
> +#define BD70528_REG_RTC_WAKE_MIN	0x44
> +#define BD70528_REG_RTC_WAKE_HOUR	0x45
> +#define BD70528_REG_RTC_WAKE_CTRL	0x46
> +
> +#define BD70528_REG_ELAPSED_TIMER_EN	0x42
> +#define BD70528_REG_WAKE_EN		0x46
> +
> +/* WDT registers */
> +#define BD70528_REG_WDT_CTRL		0x4A
> +#define BD70528_REG_WDT_HOUR		0x49
> +#define BD70528_REG_WDT_MINUTE		0x48
> +#define BD70528_REG_WDT_SEC		0x47
> +
> +/* Charger / Battery */
> +#define BD70528_REG_CHG_CURR_STAT	0x59
> +#define BD70528_REG_CHG_BAT_STAT	0x57
> +#define BD70528_REG_CHG_BAT_TEMP	0x58
> +#define BD70528_REG_CHG_IN_STAT		0x56
> +#define BD70528_REG_CHG_DCIN_ILIM	0x5d
> +#define BD70528_REG_CHG_CHG_CURR_WARM	0x61
> +#define BD70528_REG_CHG_CHG_CURR_COLD	0x62
> +
> +
> +/* Masks for main IRQ register bits */
> +enum {
> +	BD70528_INT_SHDN,
> +#define BD70528_INT_SHDN_MASK (1<<BD70528_INT_SHDN)
> +	BD70528_INT_PWR_FLT,
> +#define BD70528_INT_PWR_FLT_MASK (1<<BD70528_INT_PWR_FLT)
> +	BD70528_INT_VR_FLT,
> +#define BD70528_INT_VR_FLT_MASK (1<<BD70528_INT_VR_FLT)
> +	BD70528_INT_MISC,
> +#define BD70528_INT_MISC_MASK (1<<BD70528_INT_MISC)
> +	BD70528_INT_BAT1,
> +#define BD70528_INT_BAT1_MASK (1<<BD70528_INT_BAT1)
> +	BD70528_INT_RTC,
> +#define BD70528_INT_RTC_MASK (1<<BD70528_INT_RTC)
> +	BD70528_INT_GPIO,
> +#define BD70528_INT_GPIO_MASK (1<<BD70528_INT_GPIO)
> +	BD70528_INT_OP_FAIL,
> +#define BD70528_INT_OP_FAIL_MASK (1<<BD70528_INT_OP_FAIL)
> +};
> +
> +/* IRQs */
> +enum {
> +	/* Shutdown register IRQs */
> +	BD70528_INT_LONGPUSH,
> +	BD70528_INT_WDT,
> +	BD70528_INT_HWRESET,
> +	BD70528_INT_RSTB_FAULT,
> +	BD70528_INT_VBAT_UVLO,
> +	BD70528_INT_TSD,
> +	BD70528_INT_RSTIN,
> +	/* Power failure register IRQs */
> +	BD70528_INT_BUCK1_FAULT,
> +	BD70528_INT_BUCK2_FAULT,
> +	BD70528_INT_BUCK3_FAULT,
> +	BD70528_INT_LDO1_FAULT,
> +	BD70528_INT_LDO2_FAULT,
> +	BD70528_INT_LDO3_FAULT,
> +	BD70528_INT_LED1_FAULT,
> +	BD70528_INT_LED2_FAULT,
> +	/* VR FAULT register IRQs */
> +	BD70528_INT_BUCK1_OCP,
> +	BD70528_INT_BUCK2_OCP,
> +	BD70528_INT_BUCK3_OCP,
> +	BD70528_INT_LED1_OCP,
> +	BD70528_INT_LED2_OCP,
> +	BD70528_INT_BUCK1_FULLON,
> +	BD70528_INT_BUCK2_FULLON,
> +	/* PMU register interrupts */
> +	BD70528_INT_SHORTPUSH,
> +	BD70528_INT_AUTO_WAKEUP,
> +	BD70528_INT_STATE_CHANGE,
> +	/* Charger 1 register IRQs */
> +	BD70528_INT_BAT_OV_RES,
> +	BD70528_INT_BAT_OV_DET,
> +	BD70528_INT_DBAT_DET,
> +	BD70528_INT_BATTSD_COLD_RES,
> +	BD70528_INT_BATTSD_COLD_DET,
> +	BD70528_INT_BATTSD_HOT_RES,
> +	BD70528_INT_BATTSD_HOT_DET,
> +	BD70528_INT_CHG_TSD,
> +	/* Charger 2 register IRQs */
> +	BD70528_INT_BAT_RMV,
> +	BD70528_INT_BAT_DET,
> +	BD70528_INT_DCIN2_OV_RES,
> +	BD70528_INT_DCIN2_OV_DET,
> +	BD70528_INT_DCIN2_RMV,
> +	BD70528_INT_DCIN2_DET,
> +	BD70528_INT_DCIN1_RMV,
> +	BD70528_INT_DCIN1_DET,
> +	/* RTC register IRQs */
> +	BD70528_INT_RTC_ALARM,
> +	BD70528_INT_ELPS_TIM,
> +	/* GPIO register IRQs */
> +	BD70528_INT_GPIO0,
> +	BD70528_INT_GPIO1,
> +	BD70528_INT_GPIO2,
> +	BD70528_INT_GPIO3,
> +	/* Invalid operation register IRQs */
> +	BD70528_INT_BUCK1_DVS_OPFAIL,
> +	BD70528_INT_BUCK2_DVS_OPFAIL,
> +	BD70528_INT_BUCK3_DVS_OPFAIL,
> +	BD70528_INT_LED1_VOLT_OPFAIL,
> +	BD70528_INT_LED2_VOLT_OPFAIL,
> +};
> +
> +/* Masks */
> +#define BD70528_INT_LONGPUSH_MASK 0x1
> +#define BD70528_INT_WDT_MASK 0x2
> +#define BD70528_INT_HWRESET_MASK 0x4
> +#define BD70528_INT_RSTB_FAULT_MASK 0x8
> +#define BD70528_INT_VBAT_UVLO_MASK 0x10
> +#define BD70528_INT_TSD_MASK 0x20
> +#define BD70528_INT_RSTIN_MASK 0x40
> +
> +#define BD70528_INT_BUCK1_FAULT_MASK 0x1
> +#define BD70528_INT_BUCK2_FAULT_MASK 0x2
> +#define BD70528_INT_BUCK3_FAULT_MASK 0x4
> +#define BD70528_INT_LDO1_FAULT_MASK 0x8
> +#define BD70528_INT_LDO2_FAULT_MASK 0x10
> +#define BD70528_INT_LDO3_FAULT_MASK 0x20
> +#define BD70528_INT_LED1_FAULT_MASK 0x40
> +#define BD70528_INT_LED2_FAULT_MASK 0x80
> +
> +#define BD70528_INT_BUCK1_OCP_MASK 0x1
> +#define BD70528_INT_BUCK2_OCP_MASK 0x2
> +#define BD70528_INT_BUCK3_OCP_MASK 0x4
> +#define BD70528_INT_LED1_OCP_MASK 0x8
> +#define BD70528_INT_LED2_OCP_MASK 0x10
> +#define BD70528_INT_BUCK1_FULLON_MASK 0x20
> +#define BD70528_INT_BUCK2_FULLON_MASK 0x40
> +
> +#define BD70528_INT_SHORTPUSH_MASK 0x1
> +#define BD70528_INT_AUTO_WAKEUP_MASK 0x2
> +#define BD70528_INT_STATE_CHANGE_MASK 0x10
> +
> +#define BD70528_INT_BAT_OV_RES_MASK 0x1
> +#define BD70528_INT_BAT_OV_DET_MASK 0x2
> +#define BD70528_INT_DBAT_DET_MASK 0x4
> +#define BD70528_INT_BATTSD_COLD_RES_MASK 0x8
> +#define BD70528_INT_BATTSD_COLD_DET_MASK 0x10
> +#define BD70528_INT_BATTSD_HOT_RES_MASK 0x20
> +#define BD70528_INT_BATTSD_HOT_DET_MASK 0x40
> +#define BD70528_INT_CHG_TSD_MASK 0x80
> +
> +#define BD70528_INT_BAT_RMV_MASK 0x1
> +#define BD70528_INT_BAT_DET_MASK 0x2
> +#define BD70528_INT_DCIN2_OV_RES_MASK 0x4
> +#define BD70528_INT_DCIN2_OV_DET_MASK 0x8
> +#define BD70528_INT_DCIN2_RMV_MASK 0x10
> +#define BD70528_INT_DCIN2_DET_MASK 0x20
> +#define BD70528_INT_DCIN1_RMV_MASK 0x40
> +#define BD70528_INT_DCIN1_DET_MASK 0x80
> +
> +#define BD70528_INT_RTC_ALARM_MASK 0x1
> +#define BD70528_INT_ELPS_TIM_MASK 0x2
> +
> +#define BD70528_INT_GPIO0_MASK 0x1
> +#define BD70528_INT_GPIO1_MASK 0x2
> +#define BD70528_INT_GPIO2_MASK 0x4
> +#define BD70528_INT_GPIO3_MASK 0x8
> +
> +#define BD70528_INT_BUCK1_DVS_OPFAIL_MASK 0x1
> +#define BD70528_INT_BUCK2_DVS_OPFAIL_MASK 0x2
> +#define BD70528_INT_BUCK3_DVS_OPFAIL_MASK 0x4
> +#define BD70528_INT_LED1_VOLT_OPFAIL_MASK 0x10
> +#define BD70528_INT_LED2_VOLT_OPFAIL_MASK 0x20
> +
> +#define BD70528_DEBOUNCE_MASK 0x3
> +
> +#define BD70528_DEBOUNCE_DISABLE 0
> +#define BD70528_DEBOUNCE_15MS 1
> +#define BD70528_DEBOUNCE_30MS 2
> +#define BD70528_DEBOUNCE_50MS 3
> +
> +#define BD70528_GPIO_DRIVE_MASK 0x2
> +#define BD70528_GPIO_PUSH_PULL 0x0
> +#define BD70528_GPIO_OPEN_DRAIN 0x2
> +
> +#define BD70528_GPIO_OUT_EN_MASK 0x80
> +#define BD70528_GPIO_OUT_ENABLE 0x80
> +#define BD70528_GPIO_OUT_DISABLE 0x0
> +
> +#define BD70528_GPIO_OUT_HI 0x1
> +#define BD70528_GPIO_OUT_LO 0x0
> +#define BD70528_GPIO_OUT_MASK 0x1
> +
> +#define BD70528_GPIO_IN_STATE_BASE 1
> +
> +#define BD70528_CLK_OUT_EN_MASK 0x1
> +
> +/* RTC masks to mask out reserved bits */
> +
> +#define BD70528_MASK_RTC_SEC		0x7f
> +#define BD70528_MASK_RTC_MINUTE		0x7f
> +#define BD70528_MASK_RTC_HOUR_24H	0x80
> +#define BD70528_MASK_RTC_HOUR_PM	0x20
> +#define BD70528_MASK_RTC_HOUR		0x1f
> +#define BD70528_MASK_RTC_DAY		0x3f
> +#define BD70528_MASK_RTC_WEEK		0x07
> +#define BD70528_MASK_RTC_MONTH		0x1f
> +#define BD70528_MASK_RTC_YEAR		0xff
> +#define BD70528_MASK_RTC_COUNT_L	0x7f
> +
> +#define BD70528_MASK_ELAPSED_TIMER_EN	0x1
> +/* Mask second, min and hour fields
> + * HW would support ALM irq for over 24h
> + * (by setting day, month and year too)
> + * but as we wish to keep this same as for
> + * wake-up we limit ALM to 24H and only
> + * unmask sec, min and hour
> + */
> +#define BD70528_MASK_ALM_EN		0x7
> +#define BD70528_MASK_WAKE_EN		0x1
> +
> +/* WDT masks */
> +#define BD70528_MASK_WDT_EN		0x1
> +#define BD70528_MASK_WDT_HOUR		0x1
> +#define BD70528_MASK_WDT_MINUTE		0x7f
> +#define BD70528_MASK_WDT_SEC		0x7f
> +
> +#define BD70528_WDT_STATE_BIT		0x1
> +#define BD70528_ELAPSED_STATE_BIT	0x2
> +#define BD70528_WAKE_STATE_BIT		0x4
> +
> +/* Charger masks */
> +#define BD70528_MASK_CHG_STAT		0x7f
> +#define BD70528_MASK_CHG_BAT_TIMER	0x20
> +#define BD70528_MASK_CHG_BAT_OVERVOLT	0x10
> +#define BD70528_MASK_CHG_BAT_DETECT	0x1
> +#define BD70528_MASK_CHG_DCIN1_UVLO	0x1
> +#define BD70528_MASK_CHG_DCIN_ILIM	0x3f
> +#define BD70528_MASK_CHG_CHG_CURR	0x1f
> +#define BD70528_MASK_CHG_TRICKLE_CURR	0x10
> +
> +/*
> + * Note, external battery register is the lonely rider at
> + * address 0xc5. See how to stuff that in the regmap
> + */
> +#define BD70528_MAX_REGISTER 0x94
> +
> +/* Buck control masks */
> +#define BD70528_MASK_RUN_EN	0x4
> +#define BD70528_MASK_STBY_EN	0x2
> +#define BD70528_MASK_IDLE_EN	0x1
> +#define BD70528_MASK_LED1_EN	0x1
> +#define BD70528_MASK_LED2_EN	0x10
> +
> +#define BD70528_MASK_BUCK_VOLT	0xf
> +#define BD70528_MASK_LDO_VOLT	0x1f
> +#define BD70528_MASK_LED1_VOLT	0x1
> +#define BD70528_MASK_LED2_VOLT	0x10
> +
> +/* Misc irq masks */
> +#define BD70528_INT_MASK_SHORT_PUSH	1
> +#define BD70528_INT_MASK_AUTO_WAKE	2
> +#define BD70528_INT_MASK_POWER_STATE	4
> +
> +#define BD70528_MASK_BUCK_RAMP 0x10
> +#define BD70528_SIFT_BUCK_RAMP 4
> +
> +#endif /* __LINUX_MFD_BD70528_H__ */
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-22  9:48 ` [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block Matti Vaittinen
@ 2019-01-22 15:47   ` Guenter Roeck
  2019-01-22 17:10     ` Matti Vaittinen
  0 siblings, 1 reply; 33+ messages in thread
From: Guenter Roeck @ 2019-01-22 15:47 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	broonie, gregkh, rafael, mturquette, sboyd, linus.walleij,
	bgolaszewski, sre, a.zummo, alexandre.belloni, wim, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

On Tue, Jan 22, 2019 at 11:48:36AM +0200, Matti Vaittinen wrote:
> Initial support for watchdog block included in ROHM BD70528
> power management IC.
> 
> Configurations for low power states are still to be checked.
> 
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
>  drivers/watchdog/Kconfig       |  12 +++
>  drivers/watchdog/Makefile      |   1 +
>  drivers/watchdog/bd70528_wdt.c | 161 +++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 174 insertions(+)
>  create mode 100644 drivers/watchdog/bd70528_wdt.c
> 
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 57f017d74a97..f30e3a3e886e 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -90,6 +90,18 @@ config SOFT_WATCHDOG_PRETIMEOUT
>  	  watchdog. Be aware that governors might affect the watchdog because it
>  	  is purely software, e.g. the panic governor will stall it!
>  
> +config BD70528_WATCHDOG
> +	tristate "ROHM BD70528 PMIC Watchdog"
> +	depends on MFD_ROHM_BD70528
> +	select WATCHDOG_CORE
> +	help
> +	  Support for the watchdog in the ROHM BD70528 PMIC. Watchdog trigger
> +	  cause system reset.
> +
> +	  Say Y here to include support for the ROHM BD70528 watchdog.
> +	  Alternatively say M to compile the driver as a module,
> +	  which will be called bd70528_wdt.
> +
>  config DA9052_WATCHDOG
>  	tristate "Dialog DA9052 Watchdog"
>  	depends on PMIC_DA9052 || COMPILE_TEST
> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> index a0917ef28e07..1ce87a3b1172 100644
> --- a/drivers/watchdog/Makefile
> +++ b/drivers/watchdog/Makefile
> @@ -204,6 +204,7 @@ obj-$(CONFIG_WATCHDOG_SUN4V)		+= sun4v_wdt.o
>  obj-$(CONFIG_XEN_WDT) += xen_wdt.o
>  
>  # Architecture Independent
> +obj-$(CONFIG_BD70528_WATCHDOG) += bd70528_wdt.o
>  obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
>  obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
>  obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
> diff --git a/drivers/watchdog/bd70528_wdt.c b/drivers/watchdog/bd70528_wdt.c
> new file mode 100644
> index 000000000000..e9a32566f595
> --- /dev/null
> +++ b/drivers/watchdog/bd70528_wdt.c
> @@ -0,0 +1,161 @@
> +// SPDX-License-Identifier: GPL-2.0
> +// Copyright (C) 2018 ROHM Semiconductors
> +// ROHM BD70528MWV watchdog driver
> +
> +#include <linux/bcd.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/rohm-bd70528.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/watchdog.h>
> +
> +static int bd70528_wdt_set(struct bd70528 *bd70528, int enable)
> +{
> +	int ret;
> +
> +	if (bd70528->rtc_timer_lock)
> +		mutex_lock(bd70528->rtc_timer_lock);

This looks awkward. I don't think the if() is necessary.

> +
> +	ret = bd70528->wdt_set(bd70528, enable, NULL);
> +
> +	if (bd70528->rtc_timer_lock)
> +		mutex_unlock(bd70528->rtc_timer_lock);
> +	return ret;
> +}
> +
> +static int bd70528_wdt_start(struct watchdog_device *wdt)
> +{
> +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> +
> +	return bd70528_wdt_set(bd70528, 1);
> +}
> +
> +static int bd70528_wdt_stop(struct watchdog_device *wdt)
> +{
> +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> +
> +	return bd70528_wdt_set(bd70528, 0);
> +}
> +
> +static int bd70528_wdt_set_timeout(struct watchdog_device *wdt,
> +				    unsigned int timeout)
> +{
> +	unsigned int hours;
> +	unsigned int minutes;
> +	unsigned int seconds;
> +	int ret;
> +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> +
> +	seconds = timeout;
> +	hours = timeout / (60 * 60);
> +	/* Maximum timeout is 1h 59m 59s => hours is 1 or 0 */
> +	if (hours)
> +		seconds -= (60 * 60);
> +	minutes = seconds / 60;
> +	seconds = seconds % 60;
> +
> +	if (bd70528->rtc_timer_lock)
> +		mutex_lock(bd70528->rtc_timer_lock);
> +
> +	ret = bd70528->wdt_set(bd70528, 0, NULL);
> +	if (ret)
> +		goto out_unlock;
> +
> +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_HOUR,
> +				 BD70528_MASK_WDT_HOUR, hours);
> +	if (ret) {
> +		dev_err(bd70528->chip.dev, "Failed to set WDT hours\n");
> +		goto out_en_unlock;
> +	}
> +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_MINUTE,
> +				 BD70528_MASK_WDT_MINUTE, bin2bcd(minutes));
> +	if (ret) {
> +		dev_err(bd70528->chip.dev, "Failed to set WDT minutes\n");
> +		goto out_en_unlock;
> +	}
> +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_SEC,
> +				 BD70528_MASK_WDT_SEC, bin2bcd(seconds));
> +	if (ret) {
> +		dev_err(bd70528->chip.dev, "Failed to set WDT seconds\n");
> +		goto out_en_unlock;

Unnecessary goto.

> +	}
> +
> +out_en_unlock:
> +	ret = bd70528->wdt_set(bd70528, 1, NULL);
> +out_unlock:
> +	if (bd70528->rtc_timer_lock)
> +		mutex_lock(bd70528->rtc_timer_lock);

I don't think this code was ever tested.

> +
> +	return ret;
> +}
> +
> +static const struct watchdog_info bd70528_wdt_info = {
> +	.identity = "bd70528-wdt",
> +	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
> +};
> +
> +static const struct watchdog_ops bd70528_wdt_ops = {
> +	.start		= bd70528_wdt_start,
> +	.stop		= bd70528_wdt_stop,
> +	/*
> +	 *  bd70528 WDT ping is same as enable. Eg, writing 'enable' to enabled
> +	 * WDT will restart the timeout
> +	 */
Unnecessary comment.

> +	.ping		= bd70528_wdt_start,
> +	.set_timeout	= bd70528_wdt_set_timeout,
> +};
> +
> +/* Max time we can set is 1 hour, 59 minutes and 59 seconds */
> +#define WDT_MAX_MS ((2 * 60 * 60 - 1) * 1000)
> +/* Minimum time is 1 second */
> +#define WDT_MIN_MS 1000
> +static struct watchdog_device bd70528_wd = {
> +	.info = &bd70528_wdt_info,
> +	.ops =  &bd70528_wdt_ops,
> +	.min_hw_heartbeat_ms = WDT_MIN_MS,
> +	.max_hw_heartbeat_ms = WDT_MAX_MS,
> +};
> +
> +static int bd70528_wdt_probe(struct platform_device *pdev)
> +{
> +	struct bd70528 *tmp;
> +	struct bd70528 *bd70528;
> +	int ret;
> +
> +	tmp = dev_get_drvdata(pdev->dev.parent);
> +	if (!tmp) {
> +		dev_err(&pdev->dev, "No MFD driver data\n");
> +		return -EINVAL;
> +	}
> +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> +	if (!bd70528)
> +		return -ENOMEM;
> +
> +	*bd70528 = *tmp;
> +	bd70528->chip.dev = &pdev->dev;

This is wrong.
You should not copy the parent's driver data but have local driver
data as needed which then points to the parent's driver data if
needed. I assume this is why the mutex is a pointer, but that
just shows that the whole approach is wrong.

> +
> +	/*
> +	 * TODO: Set the initial state and timeout.

Confused. Why don't you just do it ?

> +	 * See whether the low power states require special handling
> +	 */
> +	watchdog_set_drvdata(&bd70528_wd, bd70528);

At least in theory there can be more than one of those devices
in the system, since it is an i2c device. With that in mind, bd70528_wd
should be locally allocated.

Also, bd70528_wd should be fully initialized. For example, the parent
device is not set.

> +	ret = devm_watchdog_register_device(&pdev->dev, &bd70528_wd);
> +	if (ret < 0)
> +		dev_err(&pdev->dev, "watchdog registration failed: %d\n", ret);
> +
> +	return ret;
> +}
> +static struct platform_driver bd70528_wdt = {
> +	.driver = {
> +		.name = "bd70528-wdt"
> +	},
> +	.probe = bd70528_wdt_probe,
> +};
> +
> +module_platform_driver(bd70528_wdt);
> +
> +MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
> +MODULE_DESCRIPTION("BD70528 watchdog driver");
> +MODULE_LICENSE("GPL");
> -- 
> 2.14.3
> 
> 
> -- 
> Matti Vaittinen
> ROHM Semiconductors
> 
> ~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 05/13] mfd: bd70528: Support ROHM bd70528 PMIC - core
  2019-01-22 14:51   ` Guenter Roeck
@ 2019-01-22 16:20     ` Matti Vaittinen
  0 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22 16:20 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	broonie, gregkh, rafael, mturquette, sboyd, linus.walleij,
	bgolaszewski, sre, a.zummo, alexandre.belloni, wim, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

Hello Guenter,

Thanks for taking the time and doing review!

On Tue, Jan 22, 2019 at 06:51:26AM -0800, Guenter Roeck wrote:
> On 1/22/19 1:44 AM, Matti Vaittinen wrote:
> > +static DEFINE_MUTEX(rtc_timer_mutex);

// snip

> > +static int bd70528_i2c_probe(struct i2c_client *i2c,
> > +			    const struct i2c_device_id *id)
> > +{
> > +	struct bd70528 *bd70528;
> > +	struct regmap_irq_chip_data *irq_data;
> > +	int ret, i;
> > +
> > +	if (!i2c->irq) {
> > +		dev_err(&i2c->dev, "No IRQ configured\n");
> > +		return -EINVAL;
> > +	}
> > +	bd70528 = devm_kzalloc(&i2c->dev, sizeof(*bd70528), GFP_KERNEL);
> > +
> > +	if (!bd70528)
> > +		return -ENOMEM;
> > +
> > +	dev_set_drvdata(&i2c->dev, bd70528);
> > +	bd70528->rtc_timer_lock = &rtc_timer_mutex;
> 
> One global mutex for all instances of this driver is odd.
> Why isn't this just part of struct bd70528 ?
> 

You are right. This was a brainfart from my side. I don't think there
is many cases where this would har though. I don't expect to see
many instances of PMIC drivers load. But you are correct nevertheless.
I will fix this in future version. Thanks for pointing it out!

Br,
	Matti Vaittinen


-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 11/13] rtc: bd70528: Initial support for ROHM bd70528 RTC
  2019-01-22 14:48   ` Guenter Roeck
@ 2019-01-22 16:29     ` Matti Vaittinen
  0 siblings, 0 replies; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22 16:29 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	broonie, gregkh, rafael, mturquette, sboyd, linus.walleij,
	bgolaszewski, sre, a.zummo, alexandre.belloni, wim, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

On Tue, Jan 22, 2019 at 06:48:21AM -0800, Guenter Roeck wrote:
> On 1/22/19 1:47 AM, Matti Vaittinen wrote:
> > +
> > +static int bd70528_set_rtc_based_timers(struct bd70528 *bd70528, int new_state,
> > +							int *old_state)
> 
> Passed parameter is an int, not int *. I'd be quite surprised if this compiles
> without warning.
> 
> > +static int bd70528_re_enable_rtc_based_timers(struct bd70528 *bd70528,
> > +							int old_state)
// snip
> > +	return bd70528_set_rtc_based_timers(bd70528, old_state, NULL);

and

> > +static int bd70528_disable_rtc_based_timers(struct bd70528 *bd70528,
> > +							int *old_state)
// snip
> > +	return bd70528_set_rtc_based_timers(bd70528, 0, old_state);

I'm not quite sure I understand what you mean by that. Second parameter is int,
third one is is int *.

> > +static int bd70528_re_enable_rtc_based_timers(struct bd70528 *bd70528,
> > +							int old_state)
> > +{
> > +	if (bd70528->rtc_timer_lock)
> > +		mutex_unlock(bd70528->rtc_timer_lock);
> > +
> Unlock before calling bd70528_set_rtc_based_timers is odd, especially since it
> is called after locking below.
> 

Yet another brainfart. Thanks for pointing this out! Will be fixed as
well.

Br,
	Matti Vaittinen

-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-22 15:47   ` Guenter Roeck
@ 2019-01-22 17:10     ` Matti Vaittinen
  2019-01-22 17:40       ` Guenter Roeck
  0 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22 17:10 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	broonie, gregkh, rafael, mturquette, sboyd, linus.walleij,
	bgolaszewski, sre, a.zummo, alexandre.belloni, wim, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

On Tue, Jan 22, 2019 at 07:47:50AM -0800, Guenter Roeck wrote:
> On Tue, Jan 22, 2019 at 11:48:36AM +0200, Matti Vaittinen wrote:
> > Initial support for watchdog block included in ROHM BD70528
> > power management IC.
> > 
> > Configurations for low power states are still to be checked.
> > 
> > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> > ---
> >  drivers/watchdog/Kconfig       |  12 +++
> >  drivers/watchdog/Makefile      |   1 +
> >  drivers/watchdog/bd70528_wdt.c | 161 +++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 174 insertions(+)
> >  create mode 100644 drivers/watchdog/bd70528_wdt.c
> > 
> > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > index 57f017d74a97..f30e3a3e886e 100644
> > --- a/drivers/watchdog/Kconfig
> > +++ b/drivers/watchdog/Kconfig
> > @@ -90,6 +90,18 @@ config SOFT_WATCHDOG_PRETIMEOUT
> >  	  watchdog. Be aware that governors might affect the watchdog because it
> >  	  is purely software, e.g. the panic governor will stall it!
> >  
> > +config BD70528_WATCHDOG
> > +	tristate "ROHM BD70528 PMIC Watchdog"
> > +	depends on MFD_ROHM_BD70528
> > +	select WATCHDOG_CORE
> > +	help
> > +	  Support for the watchdog in the ROHM BD70528 PMIC. Watchdog trigger
> > +	  cause system reset.
> > +
> > +	  Say Y here to include support for the ROHM BD70528 watchdog.
> > +	  Alternatively say M to compile the driver as a module,
> > +	  which will be called bd70528_wdt.
> > +
> >  config DA9052_WATCHDOG
> >  	tristate "Dialog DA9052 Watchdog"
> >  	depends on PMIC_DA9052 || COMPILE_TEST
> > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > index a0917ef28e07..1ce87a3b1172 100644
> > --- a/drivers/watchdog/Makefile
> > +++ b/drivers/watchdog/Makefile
> > @@ -204,6 +204,7 @@ obj-$(CONFIG_WATCHDOG_SUN4V)		+= sun4v_wdt.o
> >  obj-$(CONFIG_XEN_WDT) += xen_wdt.o
> >  
> >  # Architecture Independent
> > +obj-$(CONFIG_BD70528_WATCHDOG) += bd70528_wdt.o
> >  obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
> >  obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
> >  obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
> > diff --git a/drivers/watchdog/bd70528_wdt.c b/drivers/watchdog/bd70528_wdt.c
> > new file mode 100644
> > index 000000000000..e9a32566f595
> > --- /dev/null
> > +++ b/drivers/watchdog/bd70528_wdt.c
> > @@ -0,0 +1,161 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +// Copyright (C) 2018 ROHM Semiconductors
> > +// ROHM BD70528MWV watchdog driver
> > +
> > +#include <linux/bcd.h>
> > +#include <linux/kernel.h>
> > +#include <linux/mfd/rohm-bd70528.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/watchdog.h>
> > +
> > +static int bd70528_wdt_set(struct bd70528 *bd70528, int enable)
> > +{
> > +	int ret;
> > +
> > +	if (bd70528->rtc_timer_lock)
> > +		mutex_lock(bd70528->rtc_timer_lock);
> 
> This looks awkward. I don't think the if() is necessary.

Right. Now when only bd70528 MFD driver uses this WDT this if is not
required.

> > +
> > +	ret = bd70528->wdt_set(bd70528, enable, NULL);
> > +
> > +	if (bd70528->rtc_timer_lock)
> > +		mutex_unlock(bd70528->rtc_timer_lock);
> > +	return ret;
> > +}
> > +
> > +static int bd70528_wdt_start(struct watchdog_device *wdt)
> > +{
> > +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> > +
> > +	return bd70528_wdt_set(bd70528, 1);
> > +}
> > +
> > +static int bd70528_wdt_stop(struct watchdog_device *wdt)
> > +{
> > +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> > +
> > +	return bd70528_wdt_set(bd70528, 0);
> > +}
> > +
> > +static int bd70528_wdt_set_timeout(struct watchdog_device *wdt,
> > +				    unsigned int timeout)
> > +{
> > +	unsigned int hours;
> > +	unsigned int minutes;
> > +	unsigned int seconds;
> > +	int ret;
> > +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> > +
> > +	seconds = timeout;
> > +	hours = timeout / (60 * 60);
> > +	/* Maximum timeout is 1h 59m 59s => hours is 1 or 0 */
> > +	if (hours)
> > +		seconds -= (60 * 60);
> > +	minutes = seconds / 60;
> > +	seconds = seconds % 60;
> > +
> > +	if (bd70528->rtc_timer_lock)
> > +		mutex_lock(bd70528->rtc_timer_lock);
> > +
> > +	ret = bd70528->wdt_set(bd70528, 0, NULL);
> > +	if (ret)
> > +		goto out_unlock;
> > +
> > +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_HOUR,
> > +				 BD70528_MASK_WDT_HOUR, hours);
> > +	if (ret) {
> > +		dev_err(bd70528->chip.dev, "Failed to set WDT hours\n");
> > +		goto out_en_unlock;
> > +	}
> > +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_MINUTE,
> > +				 BD70528_MASK_WDT_MINUTE, bin2bcd(minutes));
> > +	if (ret) {
> > +		dev_err(bd70528->chip.dev, "Failed to set WDT minutes\n");
> > +		goto out_en_unlock;
> > +	}
> > +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_SEC,
> > +				 BD70528_MASK_WDT_SEC, bin2bcd(seconds));
> > +	if (ret) {
> > +		dev_err(bd70528->chip.dev, "Failed to set WDT seconds\n");
> > +		goto out_en_unlock;
> 
> Unnecessary goto.

True. I'll drop this.

> 
> > +	}
> > +
> > +out_en_unlock:
> > +	ret = bd70528->wdt_set(bd70528, 1, NULL);
> > +out_unlock:
> > +	if (bd70528->rtc_timer_lock)
> > +		mutex_lock(bd70528->rtc_timer_lock);
> 
> I don't think this code was ever tested.

Yep. This should be unlock. What comes to testingI'll quote the
cover-sheet for the patch set:

> Currently only MFD core, clk, RTC and regulator portions are
> somehow tested. The RFC series also include initial gpio, power-supply
> and watchdog patches in order to provide better overview on chip
> and to collect initial feedback. Reset and ADC are not supported by
> this series.

I think having the wdt_set and rtc_timer_lock in MFD would have been
completely mysterious if watchdog draft was not included =)

> > +static const struct watchdog_info bd70528_wdt_info = {
> > +	.identity = "bd70528-wdt",
> > +	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
> > +};
> > +
> > +static const struct watchdog_ops bd70528_wdt_ops = {
> > +	.start		= bd70528_wdt_start,
> > +	.stop		= bd70528_wdt_stop,
> > +	/*
> > +	 *  bd70528 WDT ping is same as enable. Eg, writing 'enable' to enabled
> > +	 * WDT will restart the timeout
> > +	 */
> Unnecessary comment.
> 

Ok. I will remove the comment if this is obvious to others. For me it
was not obvious. I was first writing a separate ping and start functions
untill I realized that it is the same operation. But this was my first
WDT driver so I don't know if this is a normal for all WDTs.

> > +	.ping		= bd70528_wdt_start,
> > +	.set_timeout	= bd70528_wdt_set_timeout,
> > +};
> > +
> > +/* Max time we can set is 1 hour, 59 minutes and 59 seconds */
> > +#define WDT_MAX_MS ((2 * 60 * 60 - 1) * 1000)
> > +/* Minimum time is 1 second */
> > +#define WDT_MIN_MS 1000
> > +static struct watchdog_device bd70528_wd = {
> > +	.info = &bd70528_wdt_info,
> > +	.ops =  &bd70528_wdt_ops,
> > +	.min_hw_heartbeat_ms = WDT_MIN_MS,
> > +	.max_hw_heartbeat_ms = WDT_MAX_MS,
> > +};
> > +
> > +static int bd70528_wdt_probe(struct platform_device *pdev)
> > +{
> > +	struct bd70528 *tmp;
> > +	struct bd70528 *bd70528;
> > +	int ret;
> > +
> > +	tmp = dev_get_drvdata(pdev->dev.parent);
> > +	if (!tmp) {
> > +		dev_err(&pdev->dev, "No MFD driver data\n");
> > +		return -EINVAL;
> > +	}
> > +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> > +	if (!bd70528)
> > +		return -ENOMEM;
> > +
> > +	*bd70528 = *tmp;
> > +	bd70528->chip.dev = &pdev->dev;
> 
> This is wrong.
> You should not copy the parent's driver data but have local driver
> data as needed which then points to the parent's driver data if
> needed. I assume this is why the mutex is a pointer, but that
> just shows that the whole approach is wrong.

Mutex is a pointer because we want to use same mutex from WDT and RTC.
We can sure point to parent data but then we still need our own dev
pointer. So we can have a struct with pointer to parent data and dev
pointer - but I'm not at all sure it is any clearer.
> 
> > +
> > +	/*
> > +	 * TODO: Set the initial state and timeout.
> 
> Confused. Why don't you just do it ?

I will. But it's not ready yet. I still wanted to include the WDT for
this RFC. And I hope I could get the MFD core part included in Lee's
tree at early phase so that the include/linux/mfd/rohm-bd70528.h would
be in other sub trees when they're finalized for upstreaming.

> 
> > +	 * See whether the low power states require special handling
> > +	 */
> > +	watchdog_set_drvdata(&bd70528_wd, bd70528);
> 
> At least in theory there can be more than one of those devices
> in the system, since it is an i2c device. With that in mind, bd70528_wd
> should be locally allocated.

Point taken, thanks.

> Also, bd70528_wd should be fully initialized. For example, the parent
> device is not set.

Thanks for this point too =) I will see what are all the missing
initializations before sending out the final version.

I do really appreciate that you see the trouble of doing the review and
giving me the push to right direction!

Br,
	Matti Vaittinen

-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-22 17:10     ` Matti Vaittinen
@ 2019-01-22 17:40       ` Guenter Roeck
  2019-01-22 18:03         ` Matti Vaittinen
  0 siblings, 1 reply; 33+ messages in thread
From: Guenter Roeck @ 2019-01-22 17:40 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	broonie, gregkh, rafael, mturquette, sboyd, linus.walleij,
	bgolaszewski, sre, a.zummo, alexandre.belloni, wim, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

On Tue, Jan 22, 2019 at 07:10:23PM +0200, Matti Vaittinen wrote:
> On Tue, Jan 22, 2019 at 07:47:50AM -0800, Guenter Roeck wrote:
> > On Tue, Jan 22, 2019 at 11:48:36AM +0200, Matti Vaittinen wrote:
> > > Initial support for watchdog block included in ROHM BD70528
> > > power management IC.
> > > 
> > > Configurations for low power states are still to be checked.
> > > 
> > > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> > > ---
> > >  drivers/watchdog/Kconfig       |  12 +++
> > >  drivers/watchdog/Makefile      |   1 +
> > >  drivers/watchdog/bd70528_wdt.c | 161 +++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 174 insertions(+)
> > >  create mode 100644 drivers/watchdog/bd70528_wdt.c
> > > 
> > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > > index 57f017d74a97..f30e3a3e886e 100644
> > > --- a/drivers/watchdog/Kconfig
> > > +++ b/drivers/watchdog/Kconfig
> > > @@ -90,6 +90,18 @@ config SOFT_WATCHDOG_PRETIMEOUT
> > >  	  watchdog. Be aware that governors might affect the watchdog because it
> > >  	  is purely software, e.g. the panic governor will stall it!
> > >  
> > > +config BD70528_WATCHDOG
> > > +	tristate "ROHM BD70528 PMIC Watchdog"
> > > +	depends on MFD_ROHM_BD70528
> > > +	select WATCHDOG_CORE
> > > +	help
> > > +	  Support for the watchdog in the ROHM BD70528 PMIC. Watchdog trigger
> > > +	  cause system reset.
> > > +
> > > +	  Say Y here to include support for the ROHM BD70528 watchdog.
> > > +	  Alternatively say M to compile the driver as a module,
> > > +	  which will be called bd70528_wdt.
> > > +
> > >  config DA9052_WATCHDOG
> > >  	tristate "Dialog DA9052 Watchdog"
> > >  	depends on PMIC_DA9052 || COMPILE_TEST
> > > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > > index a0917ef28e07..1ce87a3b1172 100644
> > > --- a/drivers/watchdog/Makefile
> > > +++ b/drivers/watchdog/Makefile
> > > @@ -204,6 +204,7 @@ obj-$(CONFIG_WATCHDOG_SUN4V)		+= sun4v_wdt.o
> > >  obj-$(CONFIG_XEN_WDT) += xen_wdt.o
> > >  
> > >  # Architecture Independent
> > > +obj-$(CONFIG_BD70528_WATCHDOG) += bd70528_wdt.o
> > >  obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
> > >  obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
> > >  obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
> > > diff --git a/drivers/watchdog/bd70528_wdt.c b/drivers/watchdog/bd70528_wdt.c
> > > new file mode 100644
> > > index 000000000000..e9a32566f595
> > > --- /dev/null
> > > +++ b/drivers/watchdog/bd70528_wdt.c
> > > @@ -0,0 +1,161 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +// Copyright (C) 2018 ROHM Semiconductors
> > > +// ROHM BD70528MWV watchdog driver
> > > +
> > > +#include <linux/bcd.h>
> > > +#include <linux/kernel.h>
> > > +#include <linux/mfd/rohm-bd70528.h>
> > > +#include <linux/module.h>
> > > +#include <linux/of.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/regmap.h>
> > > +#include <linux/watchdog.h>
> > > +
> > > +static int bd70528_wdt_set(struct bd70528 *bd70528, int enable)
> > > +{
> > > +	int ret;
> > > +
> > > +	if (bd70528->rtc_timer_lock)
> > > +		mutex_lock(bd70528->rtc_timer_lock);
> > 
> > This looks awkward. I don't think the if() is necessary.
> 
> Right. Now when only bd70528 MFD driver uses this WDT this if is not
> required.
> 
That doesn't warrant the conditional. It just bloats the code.
If there is only one user, the mutex will always be acquired.

> > > +
> > > +	ret = bd70528->wdt_set(bd70528, enable, NULL);
> > > +
> > > +	if (bd70528->rtc_timer_lock)
> > > +		mutex_unlock(bd70528->rtc_timer_lock);
> > > +	return ret;
> > > +}
> > > +
> > > +static int bd70528_wdt_start(struct watchdog_device *wdt)
> > > +{
> > > +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> > > +
> > > +	return bd70528_wdt_set(bd70528, 1);
> > > +}
> > > +
> > > +static int bd70528_wdt_stop(struct watchdog_device *wdt)
> > > +{
> > > +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> > > +
> > > +	return bd70528_wdt_set(bd70528, 0);
> > > +}
> > > +
> > > +static int bd70528_wdt_set_timeout(struct watchdog_device *wdt,
> > > +				    unsigned int timeout)
> > > +{
> > > +	unsigned int hours;
> > > +	unsigned int minutes;
> > > +	unsigned int seconds;
> > > +	int ret;
> > > +	struct bd70528 *bd70528 = watchdog_get_drvdata(wdt);
> > > +
> > > +	seconds = timeout;
> > > +	hours = timeout / (60 * 60);
> > > +	/* Maximum timeout is 1h 59m 59s => hours is 1 or 0 */
> > > +	if (hours)
> > > +		seconds -= (60 * 60);
> > > +	minutes = seconds / 60;
> > > +	seconds = seconds % 60;
> > > +
> > > +	if (bd70528->rtc_timer_lock)
> > > +		mutex_lock(bd70528->rtc_timer_lock);
> > > +
> > > +	ret = bd70528->wdt_set(bd70528, 0, NULL);
> > > +	if (ret)
> > > +		goto out_unlock;
> > > +
> > > +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_HOUR,
> > > +				 BD70528_MASK_WDT_HOUR, hours);
> > > +	if (ret) {
> > > +		dev_err(bd70528->chip.dev, "Failed to set WDT hours\n");
> > > +		goto out_en_unlock;
> > > +	}
> > > +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_MINUTE,
> > > +				 BD70528_MASK_WDT_MINUTE, bin2bcd(minutes));
> > > +	if (ret) {
> > > +		dev_err(bd70528->chip.dev, "Failed to set WDT minutes\n");
> > > +		goto out_en_unlock;
> > > +	}
> > > +	ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_SEC,
> > > +				 BD70528_MASK_WDT_SEC, bin2bcd(seconds));
> > > +	if (ret) {
> > > +		dev_err(bd70528->chip.dev, "Failed to set WDT seconds\n");
> > > +		goto out_en_unlock;
> > 
> > Unnecessary goto.
> 
> True. I'll drop this.
> 
> > 
> > > +	}
> > > +
> > > +out_en_unlock:
> > > +	ret = bd70528->wdt_set(bd70528, 1, NULL);
> > > +out_unlock:
> > > +	if (bd70528->rtc_timer_lock)
> > > +		mutex_lock(bd70528->rtc_timer_lock);
> > 
> > I don't think this code was ever tested.
> 
> Yep. This should be unlock. What comes to testingI'll quote the
> cover-sheet for the patch set:
> 
> > Currently only MFD core, clk, RTC and regulator portions are
> > somehow tested. The RFC series also include initial gpio, power-supply
> > and watchdog patches in order to provide better overview on chip
> > and to collect initial feedback. Reset and ADC are not supported by
> > this series.
> 
> I think having the wdt_set and rtc_timer_lock in MFD would have been
> completely mysterious if watchdog draft was not included =)
> 
> > > +static const struct watchdog_info bd70528_wdt_info = {
> > > +	.identity = "bd70528-wdt",
> > > +	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
> > > +};
> > > +
> > > +static const struct watchdog_ops bd70528_wdt_ops = {
> > > +	.start		= bd70528_wdt_start,
> > > +	.stop		= bd70528_wdt_stop,
> > > +	/*
> > > +	 *  bd70528 WDT ping is same as enable. Eg, writing 'enable' to enabled
> > > +	 * WDT will restart the timeout
> > > +	 */
> > Unnecessary comment.
> > 
> 
> Ok. I will remove the comment if this is obvious to others. For me it
> was not obvious. I was first writing a separate ping and start functions
> untill I realized that it is the same operation. But this was my first
> WDT driver so I don't know if this is a normal for all WDTs.
> 
It is documented as part of the API.

"Most hardware that does not support this as a separate function uses the
start function to restart the watchdog timer hardware"

Repeating the API for each driver doesn't really add value.

> > > +	.ping		= bd70528_wdt_start,
> > > +	.set_timeout	= bd70528_wdt_set_timeout,
> > > +};
> > > +
> > > +/* Max time we can set is 1 hour, 59 minutes and 59 seconds */
> > > +#define WDT_MAX_MS ((2 * 60 * 60 - 1) * 1000)
> > > +/* Minimum time is 1 second */
> > > +#define WDT_MIN_MS 1000
> > > +static struct watchdog_device bd70528_wd = {
> > > +	.info = &bd70528_wdt_info,
> > > +	.ops =  &bd70528_wdt_ops,
> > > +	.min_hw_heartbeat_ms = WDT_MIN_MS,
> > > +	.max_hw_heartbeat_ms = WDT_MAX_MS,
> > > +};
> > > +
> > > +static int bd70528_wdt_probe(struct platform_device *pdev)
> > > +{
> > > +	struct bd70528 *tmp;
> > > +	struct bd70528 *bd70528;
> > > +	int ret;
> > > +
> > > +	tmp = dev_get_drvdata(pdev->dev.parent);
> > > +	if (!tmp) {
> > > +		dev_err(&pdev->dev, "No MFD driver data\n");
> > > +		return -EINVAL;
> > > +	}
> > > +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> > > +	if (!bd70528)
> > > +		return -ENOMEM;
> > > +
> > > +	*bd70528 = *tmp;
> > > +	bd70528->chip.dev = &pdev->dev;
> > 
> > This is wrong.
> > You should not copy the parent's driver data but have local driver
> > data as needed which then points to the parent's driver data if
> > needed. I assume this is why the mutex is a pointer, but that
> > just shows that the whole approach is wrong.
> 
> Mutex is a pointer because we want to use same mutex from WDT and RTC.
> We can sure point to parent data but then we still need our own dev
> pointer. So we can have a struct with pointer to parent data and dev
> pointer - but I'm not at all sure it is any clearer.

As I said, that is wrong. To say it in plaintext, I won't accept
the driver if it copies the parent's driver data. The driver should
have and use its own driver data, and only maintain a pointer to
its parent's driver data. And most definitely you don't want to
copy and use any device data structure from the parent.

> > 
> > > +
> > > +	/*
> > > +	 * TODO: Set the initial state and timeout.
> > 
> > Confused. Why don't you just do it ?
> 
> I will. But it's not ready yet. I still wanted to include the WDT for
> this RFC. And I hope I could get the MFD core part included in Lee's
> tree at early phase so that the include/linux/mfd/rohm-bd70528.h would
> be in other sub trees when they're finalized for upstreaming.
> 
> > 
> > > +	 * See whether the low power states require special handling
> > > +	 */
> > > +	watchdog_set_drvdata(&bd70528_wd, bd70528);
> > 
> > At least in theory there can be more than one of those devices
> > in the system, since it is an i2c device. With that in mind, bd70528_wd
> > should be locally allocated.
> 
> Point taken, thanks.
> 
> > Also, bd70528_wd should be fully initialized. For example, the parent
> > device is not set.
> 
> Thanks for this point too =) I will see what are all the missing
> initializations before sending out the final version.
> 
> I do really appreciate that you see the trouble of doing the review and
> giving me the push to right direction!
> 
> Br,
> 	Matti Vaittinen
> 
> -- 
> Matti Vaittinen
> ROHM Semiconductors
> 
> ~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-22 17:40       ` Guenter Roeck
@ 2019-01-22 18:03         ` Matti Vaittinen
  2019-01-23 17:47           ` Sebastian Reichel
  0 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-22 18:03 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	broonie, gregkh, rafael, mturquette, sboyd, linus.walleij,
	bgolaszewski, sre, a.zummo, alexandre.belloni, wim, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

On Tue, Jan 22, 2019 at 09:40:56AM -0800, Guenter Roeck wrote:
> On Tue, Jan 22, 2019 at 07:10:23PM +0200, Matti Vaittinen wrote:
> > On Tue, Jan 22, 2019 at 07:47:50AM -0800, Guenter Roeck wrote:
> > > On Tue, Jan 22, 2019 at 11:48:36AM +0200, Matti Vaittinen wrote:
> > > > Initial support for watchdog block included in ROHM BD70528
> > > > power management IC.
> > > > 
> > > > Configurations for low power states are still to be checked.
> > > > 
> > > > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> > > > ---
> > > >  drivers/watchdog/Kconfig       |  12 +++
> > > >  drivers/watchdog/Makefile      |   1 +
> > > >  drivers/watchdog/bd70528_wdt.c | 161 +++++++++++++++++++++++++++++++++++++++++
> > > >  3 files changed, 174 insertions(+)
> > > >  create mode 100644 drivers/watchdog/bd70528_wdt.c
> > > > 
> > > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > > > index 57f017d74a97..f30e3a3e886e 100644
> > > > --- a/drivers/watchdog/Kconfig
> > > > +++ b/drivers/watchdog/Kconfig
> > > > @@ -90,6 +90,18 @@ config SOFT_WATCHDOG_PRETIMEOUT
> > > >  	  watchdog. Be aware that governors might affect the watchdog because it
> > > >  	  is purely software, e.g. the panic governor will stall it!
> > > >  
> > > > +config BD70528_WATCHDOG
> > > > +	tristate "ROHM BD70528 PMIC Watchdog"
> > > > +	depends on MFD_ROHM_BD70528
> > > > +	select WATCHDOG_CORE
> > > > +	help
> > > > +	  Support for the watchdog in the ROHM BD70528 PMIC. Watchdog trigger
> > > > +	  cause system reset.
> > > > +
> > > > +	  Say Y here to include support for the ROHM BD70528 watchdog.
> > > > +	  Alternatively say M to compile the driver as a module,
> > > > +	  which will be called bd70528_wdt.
> > > > +
> > > >  config DA9052_WATCHDOG
> > > >  	tristate "Dialog DA9052 Watchdog"
> > > >  	depends on PMIC_DA9052 || COMPILE_TEST
> > > > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > > > index a0917ef28e07..1ce87a3b1172 100644
> > > > --- a/drivers/watchdog/Makefile
> > > > +++ b/drivers/watchdog/Makefile
> > > > @@ -204,6 +204,7 @@ obj-$(CONFIG_WATCHDOG_SUN4V)		+= sun4v_wdt.o
> > > >  obj-$(CONFIG_XEN_WDT) += xen_wdt.o
> > > >  
> > > >  # Architecture Independent
> > > > +obj-$(CONFIG_BD70528_WATCHDOG) += bd70528_wdt.o
> > > >  obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
> > > >  obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
> > > >  obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
> > > > diff --git a/drivers/watchdog/bd70528_wdt.c b/drivers/watchdog/bd70528_wdt.c
> > > > new file mode 100644
> > > > index 000000000000..e9a32566f595
> > > > --- /dev/null
> > > > +++ b/drivers/watchdog/bd70528_wdt.c
> > > > @@ -0,0 +1,161 @@
> > > > +// SPDX-License-Identifier: GPL-2.0
> > > > +// Copyright (C) 2018 ROHM Semiconductors
> > > > +// ROHM BD70528MWV watchdog driver
> > > > +
> > > > +#include <linux/bcd.h>
> > > > +#include <linux/kernel.h>
> > > > +#include <linux/mfd/rohm-bd70528.h>
> > > > +#include <linux/module.h>
> > > > +#include <linux/of.h>
> > > > +#include <linux/platform_device.h>
> > > > +#include <linux/regmap.h>
> > > > +#include <linux/watchdog.h>
> > > > +
> > > > +static int bd70528_wdt_set(struct bd70528 *bd70528, int enable)
> > > > +{
> > > > +	int ret;
> > > > +
> > > > +	if (bd70528->rtc_timer_lock)
> > > > +		mutex_lock(bd70528->rtc_timer_lock);
> > > 
> > > This looks awkward. I don't think the if() is necessary.
> > 
> > Right. Now when only bd70528 MFD driver uses this WDT this if is not
> > required.
> > 
> That doesn't warrant the conditional. It just bloats the code.
> If there is only one user, the mutex will always be acquired.

Yep. What I meant was that the only possible parent is bd70528 MFD
driver which always initializes the mutex pointer. So pointer should be
always set. I can imagine some other ROHM PMIC having almost identical
watchdog block - in which case we might want to re-use this WDT driver
with this PMIC. And if this PMIC has no RTC, then we may not need this
mutex. But this is all speculation and I will remove check - or see how
this changes when I see what to do with the driver's private data.

> > > > +static const struct watchdog_info bd70528_wdt_info = {
> > > > +	.identity = "bd70528-wdt",
> > > > +	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
> > > > +};
> > > > +
> > > > +static const struct watchdog_ops bd70528_wdt_ops = {
> > > > +	.start		= bd70528_wdt_start,
> > > > +	.stop		= bd70528_wdt_stop,
> > > > +	/*
> > > > +	 *  bd70528 WDT ping is same as enable. Eg, writing 'enable' to enabled
> > > > +	 * WDT will restart the timeout
> > > > +	 */
> > > Unnecessary comment.
> > > 
> > 
> > Ok. I will remove the comment if this is obvious to others. For me it
> > was not obvious. I was first writing a separate ping and start functions
> > untill I realized that it is the same operation. But this was my first
> > WDT driver so I don't know if this is a normal for all WDTs.
> > 
> It is documented as part of the API.
I'd better read the documentation then. Thanks for pointing this out.
I'll remove the comment.

> > > > +static int bd70528_wdt_probe(struct platform_device *pdev)
> > > > +{
> > > > +	struct bd70528 *tmp;
> > > > +	struct bd70528 *bd70528;
> > > > +	int ret;
> > > > +
> > > > +	tmp = dev_get_drvdata(pdev->dev.parent);
> > > > +	if (!tmp) {
> > > > +		dev_err(&pdev->dev, "No MFD driver data\n");
> > > > +		return -EINVAL;
> > > > +	}
> > > > +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> > > > +	if (!bd70528)
> > > > +		return -ENOMEM;
> > > > +
> > > > +	*bd70528 = *tmp;
> > > > +	bd70528->chip.dev = &pdev->dev;
> > > 
> > > This is wrong.
> > > You should not copy the parent's driver data but have local driver
> > > data as needed which then points to the parent's driver data if
> > > needed. I assume this is why the mutex is a pointer, but that
> > > just shows that the whole approach is wrong.
> > 
> > Mutex is a pointer because we want to use same mutex from WDT and RTC.
> > We can sure point to parent data but then we still need our own dev
> > pointer. So we can have a struct with pointer to parent data and dev
> > pointer - but I'm not at all sure it is any clearer.
> 
> As I said, that is wrong. To say it in plaintext, I won't accept
> the driver if it copies the parent's driver data. The driver should
> have and use its own driver data, and only maintain a pointer to
> its parent's driver data. And most definitely you don't want to
> copy and use any device data structure from the parent.

Allright. At the moment the WDT driver only needs regmap pointer from
parent. I'm not sure if it will later need DT or "chip type" - but I
will change this.

Br,
	Matti Vaittinen

-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs
  2019-01-22  9:43 ` [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs Matti Vaittinen
@ 2019-01-23 15:51   ` Mark Brown
  2019-01-24  7:16     ` Matti Vaittinen
  0 siblings, 1 reply; 33+ messages in thread
From: Mark Brown @ 2019-01-23 15:51 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	gregkh, rafael, mturquette, sboyd, linus.walleij, bgolaszewski,
	sre, a.zummo, alexandre.belloni, wim, linux, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

On Tue, Jan 22, 2019 at 11:43:28AM +0200, Matti Vaittinen wrote:
> Header rohm-bd718x7.h was split to generic and component specific
> parts. This changed the struct bd718x7. Adapt the regulator driver to
> these changes.

Acked-by: Mark Brown <broonie@kernel.org>

Does this need to be squashed into the earlier commit for bisection?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 01/13] regmap: regmap-irq: Add main status register support
  2019-01-22  9:42 ` [RFC PATCH v1 01/13] regmap: regmap-irq: Add main status register support Matti Vaittinen
@ 2019-01-23 15:55   ` Mark Brown
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Brown @ 2019-01-23 15:55 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	gregkh, rafael, mturquette, sboyd, linus.walleij, bgolaszewski,
	sre, a.zummo, alexandre.belloni, wim, linux, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]

On Tue, Jan 22, 2019 at 11:42:24AM +0200, Matti Vaittinen wrote:

> There is bunch of devices with multiple logical blocks which
> can generate interrupts. It's not a rare case that the interrupt
> reason registers are arranged so that there is own status/ack/mask
> register for each logical block. In some devices there is also a
> 'main interrupt register(s)' which can indicate what sub blocks
> have interrupts pending.

The following changes since commit bfeffd155283772bbe78c6a05dec7c0128ee500c:

  Linux 5.0-rc1 (2019-01-06 17:08:20 -0800)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git tags/regmap-irq-main-status

for you to fetch changes up to a2d21848d9211dad5e786aa7368709ca8938834e:

  regmap: regmap-irq: Add main status register support (2019-01-23 15:52:15 +0000)

----------------------------------------------------------------
regmap: Main status register support

Add support for a main status register, used by chips on slower buses
with many interrupt sources to improve performance in interrupt
handling.

----------------------------------------------------------------
Matti Vaittinen (1):
      regmap: regmap-irq: Add main status register support

 drivers/base/regmap/regmap-irq.c | 99 ++++++++++++++++++++++++++++++++++++++--
 include/linux/regmap.h           | 31 +++++++++++++
 2 files changed, 126 insertions(+), 4 deletions(-)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-22 18:03         ` Matti Vaittinen
@ 2019-01-23 17:47           ` Sebastian Reichel
  2019-01-24 10:44             ` Matti Vaittinen
  0 siblings, 1 reply; 33+ messages in thread
From: Sebastian Reichel @ 2019-01-23 17:47 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Guenter Roeck, mazziesaccount, lee.jones, robh+dt, mark.rutland,
	lgirdwood, broonie, gregkh, rafael, mturquette, sboyd,
	linus.walleij, bgolaszewski, a.zummo, alexandre.belloni, wim,
	devicetree, linux-kernel, linux-clk, linux-gpio, linux-pm,
	linux-rtc, linux-watchdog, mikko.mutanen, heikki.haikola

[-- Attachment #1: Type: text/plain, Size: 7351 bytes --]

Hi,

On Tue, Jan 22, 2019 at 08:03:09PM +0200, Matti Vaittinen wrote:
> On Tue, Jan 22, 2019 at 09:40:56AM -0800, Guenter Roeck wrote:
> > On Tue, Jan 22, 2019 at 07:10:23PM +0200, Matti Vaittinen wrote:
> > > On Tue, Jan 22, 2019 at 07:47:50AM -0800, Guenter Roeck wrote:
> > > > On Tue, Jan 22, 2019 at 11:48:36AM +0200, Matti Vaittinen wrote:
> > > > > Initial support for watchdog block included in ROHM BD70528
> > > > > power management IC.
> > > > > 
> > > > > Configurations for low power states are still to be checked.
> > > > > 
> > > > > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> > > > > ---
> > > > >  drivers/watchdog/Kconfig       |  12 +++
> > > > >  drivers/watchdog/Makefile      |   1 +
> > > > >  drivers/watchdog/bd70528_wdt.c | 161 +++++++++++++++++++++++++++++++++++++++++
> > > > >  3 files changed, 174 insertions(+)
> > > > >  create mode 100644 drivers/watchdog/bd70528_wdt.c
> > > > > 
> > > > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > > > > index 57f017d74a97..f30e3a3e886e 100644
> > > > > --- a/drivers/watchdog/Kconfig
> > > > > +++ b/drivers/watchdog/Kconfig
> > > > > @@ -90,6 +90,18 @@ config SOFT_WATCHDOG_PRETIMEOUT
> > > > >  	  watchdog. Be aware that governors might affect the watchdog because it
> > > > >  	  is purely software, e.g. the panic governor will stall it!
> > > > >  
> > > > > +config BD70528_WATCHDOG
> > > > > +	tristate "ROHM BD70528 PMIC Watchdog"
> > > > > +	depends on MFD_ROHM_BD70528
> > > > > +	select WATCHDOG_CORE
> > > > > +	help
> > > > > +	  Support for the watchdog in the ROHM BD70528 PMIC. Watchdog trigger
> > > > > +	  cause system reset.
> > > > > +
> > > > > +	  Say Y here to include support for the ROHM BD70528 watchdog.
> > > > > +	  Alternatively say M to compile the driver as a module,
> > > > > +	  which will be called bd70528_wdt.
> > > > > +
> > > > >  config DA9052_WATCHDOG
> > > > >  	tristate "Dialog DA9052 Watchdog"
> > > > >  	depends on PMIC_DA9052 || COMPILE_TEST
> > > > > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > > > > index a0917ef28e07..1ce87a3b1172 100644
> > > > > --- a/drivers/watchdog/Makefile
> > > > > +++ b/drivers/watchdog/Makefile
> > > > > @@ -204,6 +204,7 @@ obj-$(CONFIG_WATCHDOG_SUN4V)		+= sun4v_wdt.o
> > > > >  obj-$(CONFIG_XEN_WDT) += xen_wdt.o
> > > > >  
> > > > >  # Architecture Independent
> > > > > +obj-$(CONFIG_BD70528_WATCHDOG) += bd70528_wdt.o
> > > > >  obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o
> > > > >  obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
> > > > >  obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
> > > > > diff --git a/drivers/watchdog/bd70528_wdt.c b/drivers/watchdog/bd70528_wdt.c
> > > > > new file mode 100644
> > > > > index 000000000000..e9a32566f595
> > > > > --- /dev/null
> > > > > +++ b/drivers/watchdog/bd70528_wdt.c
> > > > > @@ -0,0 +1,161 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0
> > > > > +// Copyright (C) 2018 ROHM Semiconductors
> > > > > +// ROHM BD70528MWV watchdog driver
> > > > > +
> > > > > +#include <linux/bcd.h>
> > > > > +#include <linux/kernel.h>
> > > > > +#include <linux/mfd/rohm-bd70528.h>
> > > > > +#include <linux/module.h>
> > > > > +#include <linux/of.h>
> > > > > +#include <linux/platform_device.h>
> > > > > +#include <linux/regmap.h>
> > > > > +#include <linux/watchdog.h>
> > > > > +
> > > > > +static int bd70528_wdt_set(struct bd70528 *bd70528, int enable)
> > > > > +{
> > > > > +	int ret;
> > > > > +
> > > > > +	if (bd70528->rtc_timer_lock)
> > > > > +		mutex_lock(bd70528->rtc_timer_lock);
> > > > 
> > > > This looks awkward. I don't think the if() is necessary.
> > > 
> > > Right. Now when only bd70528 MFD driver uses this WDT this if is not
> > > required.
> > > 
> > That doesn't warrant the conditional. It just bloats the code.
> > If there is only one user, the mutex will always be acquired.
> 
> Yep. What I meant was that the only possible parent is bd70528 MFD
> driver which always initializes the mutex pointer. So pointer should be
> always set. I can imagine some other ROHM PMIC having almost identical
> watchdog block - in which case we might want to re-use this WDT driver
> with this PMIC. And if this PMIC has no RTC, then we may not need this
> mutex. But this is all speculation and I will remove check - or see how
> this changes when I see what to do with the driver's private data.
> 
> > > > > +static const struct watchdog_info bd70528_wdt_info = {
> > > > > +	.identity = "bd70528-wdt",
> > > > > +	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
> > > > > +};
> > > > > +
> > > > > +static const struct watchdog_ops bd70528_wdt_ops = {
> > > > > +	.start		= bd70528_wdt_start,
> > > > > +	.stop		= bd70528_wdt_stop,
> > > > > +	/*
> > > > > +	 *  bd70528 WDT ping is same as enable. Eg, writing 'enable' to enabled
> > > > > +	 * WDT will restart the timeout
> > > > > +	 */
> > > > Unnecessary comment.
> > > > 
> > > 
> > > Ok. I will remove the comment if this is obvious to others. For me it
> > > was not obvious. I was first writing a separate ping and start functions
> > > untill I realized that it is the same operation. But this was my first
> > > WDT driver so I don't know if this is a normal for all WDTs.
> > > 
> > It is documented as part of the API.
> I'd better read the documentation then. Thanks for pointing this out.
> I'll remove the comment.
> 
> > > > > +static int bd70528_wdt_probe(struct platform_device *pdev)
> > > > > +{
> > > > > +	struct bd70528 *tmp;
> > > > > +	struct bd70528 *bd70528;
> > > > > +	int ret;
> > > > > +
> > > > > +	tmp = dev_get_drvdata(pdev->dev.parent);
> > > > > +	if (!tmp) {
> > > > > +		dev_err(&pdev->dev, "No MFD driver data\n");
> > > > > +		return -EINVAL;
> > > > > +	}
> > > > > +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> > > > > +	if (!bd70528)
> > > > > +		return -ENOMEM;
> > > > > +
> > > > > +	*bd70528 = *tmp;
> > > > > +	bd70528->chip.dev = &pdev->dev;
> > > > 
> > > > This is wrong.
> > > > You should not copy the parent's driver data but have local driver
> > > > data as needed which then points to the parent's driver data if
> > > > needed. I assume this is why the mutex is a pointer, but that
> > > > just shows that the whole approach is wrong.
> > > 
> > > Mutex is a pointer because we want to use same mutex from WDT and RTC.
> > > We can sure point to parent data but then we still need our own dev
> > > pointer. So we can have a struct with pointer to parent data and dev
> > > pointer - but I'm not at all sure it is any clearer.
> > 
> > As I said, that is wrong. To say it in plaintext, I won't accept
> > the driver if it copies the parent's driver data. The driver should
> > have and use its own driver data, and only maintain a pointer to
> > its parent's driver data. And most definitely you don't want to
> > copy and use any device data structure from the parent.
> 
> Allright. At the moment the WDT driver only needs regmap pointer from
> parent. I'm not sure if it will later need DT or "chip type" - but I
> will change this.

You probably want to use this:

dev_get_regmap(pdev->dev.parent, NULL);

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs
  2019-01-23 15:51   ` Mark Brown
@ 2019-01-24  7:16     ` Matti Vaittinen
  2019-01-24 10:24       ` Mark Brown
  0 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-24  7:16 UTC (permalink / raw)
  To: Mark Brown
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	gregkh, rafael, mturquette, sboyd, linus.walleij, bgolaszewski,
	sre, a.zummo, alexandre.belloni, wim, linux, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

Hello Mark,

Thanks again for looking through my changes =)

On Wed, Jan 23, 2019 at 03:51:21PM +0000, Mark Brown wrote:
> On Tue, Jan 22, 2019 at 11:43:28AM +0200, Matti Vaittinen wrote:
> > Header rohm-bd718x7.h was split to generic and component specific
> > parts. This changed the struct bd718x7. Adapt the regulator driver to
> > these changes.
> 
> Acked-by: Mark Brown <broonie@kernel.org>
> 
> Does this need to be squashed into the earlier commit for bisection?

Yes. If we don't want to break the compilation between commits then
the patches 2, 3 and 4 should be squashed into one. I sent them as
separare changes for easier review. I can squash them and send them
squashed if they are Ok to Lee and Stephen. Please just let me know
whose tree I should use as the basis so I can do rebasing if needed.
(Or is there some better way to do changes like this?)

Br,
	Matti Vaittinen 

-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs
  2019-01-24  7:16     ` Matti Vaittinen
@ 2019-01-24 10:24       ` Mark Brown
  0 siblings, 0 replies; 33+ messages in thread
From: Mark Brown @ 2019-01-24 10:24 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: mazziesaccount, lee.jones, robh+dt, mark.rutland, lgirdwood,
	gregkh, rafael, mturquette, sboyd, linus.walleij, bgolaszewski,
	sre, a.zummo, alexandre.belloni, wim, linux, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

[-- Attachment #1: Type: text/plain, Size: 522 bytes --]

On Thu, Jan 24, 2019 at 09:16:35AM +0200, Matti Vaittinen wrote:

> Yes. If we don't want to break the compilation between commits then
> the patches 2, 3 and 4 should be squashed into one. I sent them as
> separare changes for easier review. I can squash them and send them
> squashed if they are Ok to Lee and Stephen. Please just let me know
> whose tree I should use as the basis so I can do rebasing if needed.
> (Or is there some better way to do changes like this?)

I'd guess Lee's but check with him and Stephen.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-23 17:47           ` Sebastian Reichel
@ 2019-01-24 10:44             ` Matti Vaittinen
  2019-01-24 14:37               ` Guenter Roeck
  0 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-01-24 10:44 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Guenter Roeck, mazziesaccount, lee.jones, robh+dt, mark.rutland,
	lgirdwood, broonie, gregkh, rafael, mturquette, sboyd,
	linus.walleij, bgolaszewski, a.zummo, alexandre.belloni, wim,
	devicetree, linux-kernel, linux-clk, linux-gpio, linux-pm,
	linux-rtc, linux-watchdog, mikko.mutanen, heikki.haikola

On Wed, Jan 23, 2019 at 06:47:28PM +0100, Sebastian Reichel wrote:
> Hi,
> 
> On Tue, Jan 22, 2019 at 08:03:09PM +0200, Matti Vaittinen wrote:
> > On Tue, Jan 22, 2019 at 09:40:56AM -0800, Guenter Roeck wrote:
> > > On Tue, Jan 22, 2019 at 07:10:23PM +0200, Matti Vaittinen wrote:
> > > > On Tue, Jan 22, 2019 at 07:47:50AM -0800, Guenter Roeck wrote:
> > > > > On Tue, Jan 22, 2019 at 11:48:36AM +0200, Matti Vaittinen wrote:
> > > > > > +static int bd70528_wdt_probe(struct platform_device *pdev)
> > > > > > +{
> > > > > > +	struct bd70528 *tmp;
> > > > > > +	struct bd70528 *bd70528;
> > > > > > +	int ret;
> > > > > > +
> > > > > > +	tmp = dev_get_drvdata(pdev->dev.parent);
> > > > > > +	if (!tmp) {
> > > > > > +		dev_err(&pdev->dev, "No MFD driver data\n");
> > > > > > +		return -EINVAL;
> > > > > > +	}
> > > > > > +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> > > > > > +	if (!bd70528)
> > > > > > +		return -ENOMEM;
> > > > > > +
> > > > > > +	*bd70528 = *tmp;
> > > > > > +	bd70528->chip.dev = &pdev->dev;
> > > > > 
> > > > > This is wrong.
> > > > > You should not copy the parent's driver data but have local driver
> > > > > data as needed which then points to the parent's driver data if
> > > > > needed. I assume this is why the mutex is a pointer, but that
> > > > > just shows that the whole approach is wrong.
> > > > 
> > > > Mutex is a pointer because we want to use same mutex from WDT and RTC.
> > > > We can sure point to parent data but then we still need our own dev
> > > > pointer. So we can have a struct with pointer to parent data and dev
> > > > pointer - but I'm not at all sure it is any clearer.
> > > 
> > > As I said, that is wrong. To say it in plaintext, I won't accept
> > > the driver if it copies the parent's driver data. The driver should
> > > have and use its own driver data, and only maintain a pointer to
> > > its parent's driver data. And most definitely you don't want to
> > > copy and use any device data structure from the parent.
> > 
> > Allright. At the moment the WDT driver only needs regmap pointer from
> > parent. I'm not sure if it will later need DT or "chip type" - but I
> > will change this.
> 
> You probably want to use this:
> 
> dev_get_regmap(pdev->dev.parent, NULL);

Thanks a bunch Sebastian. All help is highly appreciated!! =)

Unfortunately I forgot to mention the key thing - the RTC mutex. We also
need that because RTC needs to stop WDT when RTC is adjusted as the WDT
uses RTC as counter - and jumping the RTC WDT enabled might trigger WDT
or have other consequences.

Se even if we used dev_get_regmap (which is slightly heavier than
accessing direct pointer) - we would still need at least the mutex from
parent data, possibly also the chip type and if we want to avoid code
dublication - then also the WDT start/stop function.

Thus I guess we can as well keep the regmap in parent data because we
need the parent data anyways, right?

Br
	Matti Vaittinen

-- 
Matti Vaittinen
ROHM Semiconductors

~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block
  2019-01-24 10:44             ` Matti Vaittinen
@ 2019-01-24 14:37               ` Guenter Roeck
  0 siblings, 0 replies; 33+ messages in thread
From: Guenter Roeck @ 2019-01-24 14:37 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Sebastian Reichel, mazziesaccount, lee.jones, robh+dt,
	mark.rutland, lgirdwood, broonie, gregkh, rafael, mturquette,
	sboyd, linus.walleij, bgolaszewski, a.zummo, alexandre.belloni,
	wim, devicetree, linux-kernel, linux-clk, linux-gpio, linux-pm,
	linux-rtc, linux-watchdog, mikko.mutanen, heikki.haikola

On Thu, Jan 24, 2019 at 12:44:35PM +0200, Matti Vaittinen wrote:
> On Wed, Jan 23, 2019 at 06:47:28PM +0100, Sebastian Reichel wrote:
> > Hi,
> > 
> > On Tue, Jan 22, 2019 at 08:03:09PM +0200, Matti Vaittinen wrote:
> > > On Tue, Jan 22, 2019 at 09:40:56AM -0800, Guenter Roeck wrote:
> > > > On Tue, Jan 22, 2019 at 07:10:23PM +0200, Matti Vaittinen wrote:
> > > > > On Tue, Jan 22, 2019 at 07:47:50AM -0800, Guenter Roeck wrote:
> > > > > > On Tue, Jan 22, 2019 at 11:48:36AM +0200, Matti Vaittinen wrote:
> > > > > > > +static int bd70528_wdt_probe(struct platform_device *pdev)
> > > > > > > +{
> > > > > > > +	struct bd70528 *tmp;
> > > > > > > +	struct bd70528 *bd70528;
> > > > > > > +	int ret;
> > > > > > > +
> > > > > > > +	tmp = dev_get_drvdata(pdev->dev.parent);
> > > > > > > +	if (!tmp) {
> > > > > > > +		dev_err(&pdev->dev, "No MFD driver data\n");
> > > > > > > +		return -EINVAL;
> > > > > > > +	}
> > > > > > > +	bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL);
> > > > > > > +	if (!bd70528)
> > > > > > > +		return -ENOMEM;
> > > > > > > +
> > > > > > > +	*bd70528 = *tmp;
> > > > > > > +	bd70528->chip.dev = &pdev->dev;
> > > > > > 
> > > > > > This is wrong.
> > > > > > You should not copy the parent's driver data but have local driver
> > > > > > data as needed which then points to the parent's driver data if
> > > > > > needed. I assume this is why the mutex is a pointer, but that
> > > > > > just shows that the whole approach is wrong.
> > > > > 
> > > > > Mutex is a pointer because we want to use same mutex from WDT and RTC.
> > > > > We can sure point to parent data but then we still need our own dev
> > > > > pointer. So we can have a struct with pointer to parent data and dev
> > > > > pointer - but I'm not at all sure it is any clearer.
> > > > 
> > > > As I said, that is wrong. To say it in plaintext, I won't accept
> > > > the driver if it copies the parent's driver data. The driver should
> > > > have and use its own driver data, and only maintain a pointer to
> > > > its parent's driver data. And most definitely you don't want to
> > > > copy and use any device data structure from the parent.
> > > 
> > > Allright. At the moment the WDT driver only needs regmap pointer from
> > > parent. I'm not sure if it will later need DT or "chip type" - but I
> > > will change this.
> > 
> > You probably want to use this:
> > 
> > dev_get_regmap(pdev->dev.parent, NULL);
> 
> Thanks a bunch Sebastian. All help is highly appreciated!! =)
> 
> Unfortunately I forgot to mention the key thing - the RTC mutex. We also
> need that because RTC needs to stop WDT when RTC is adjusted as the WDT
> uses RTC as counter - and jumping the RTC WDT enabled might trigger WDT
> or have other consequences.
> 
> Se even if we used dev_get_regmap (which is slightly heavier than
> accessing direct pointer) - we would still need at least the mutex from
> parent data, possibly also the chip type and if we want to avoid code
> dublication - then also the WDT start/stop function.
> 
> Thus I guess we can as well keep the regmap in parent data because we
> need the parent data anyways, right?
> 

You are free to _use_ the parent data. Just not copy it.

Another possibility would be for the parent to provide platform
data for the rtc driver to use, and that platform data would
include pointers to the regmap and to the rtc mutex.

However, again, the one thing you can _not_ do is to copy the parent's
driver data.

Guenter

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings
  2019-01-22  9:45 ` [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings Matti Vaittinen
@ 2019-02-23  0:30   ` Rob Herring
  2019-02-28  6:49     ` Matti Vaittinen
  0 siblings, 1 reply; 33+ messages in thread
From: Rob Herring @ 2019-02-23  0:30 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: mazziesaccount, lee.jones, mark.rutland, lgirdwood, broonie,
	gregkh, rafael, mturquette, sboyd, linus.walleij, bgolaszewski,
	sre, a.zummo, alexandre.belloni, wim, linux, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

On Tue, Jan 22, 2019 at 11:45:38AM +0200, Matti Vaittinen wrote:
> Document bindings for regulators (3 bucks, 3 LDOs and 2 LED
> drivers) and 4 GPIO pins which can be configured for I/O or
> as interrupt sources withe configurable trigger levels.

'dt-bindings: mfd: ...' for the subject.

> 
> Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> ---
>  .../devicetree/bindings/mfd/rohm,bd70528-pmic.txt  | 104 +++++++++++++++++++++
>  1 file changed, 104 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
> 
> diff --git a/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt b/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
> new file mode 100644
> index 000000000000..21801440a53a
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
> @@ -0,0 +1,104 @@
> +* ROHM BD70528 Power Management Integrated Circuit bindings
> +
> +BD70528MWV is an ultra-low Iq general purpose single-chip power management IC
> +for battery-powered portable devices. The IC integrates 3 ultra-low current
> +consumption buck converters, 3 LDOs and 2 LED Drivers. Also included are 4
> +GPIOs, a real-time clock (RTC), a 32kHz clock gate, high-accuracy VREF
> +for use with an external ADC, flexible dual-input power path, 10 bits SAR ADC
> +for battery temperature monitor and 1S battery charger with scalable charge
> +currents.
> +
> +Required properties:
> + - compatible		: Should be "rohm,bd70528"
> + - reg			: I2C slave address.
> + - interrupt-parent	: Phandle to the parent interrupt controller.

Don't need to document this. It is implied and could be in the parent.

> + - interrupts		: The interrupt line the device is connected to.
> + - interrupt-controller	: To indicate bd70528 acts as an interrupt controller.
> + - #interrupt-cells	: Should be 2. usage is compliant to the 2 cells
> +			  variant of ../interrupt-controller/interrupts.txt
> + - gpio-controller	: To indicate bd70528 acts as a gpio controller.
> + - #gpio-cells		: Should be 2. The first cell is the pin number and
> +			  the second cell is used to specify flags. See
> +			  ../gpio/gpio.txt for more information.
> + - clock-frequency	: Should be 32768
> + - #clock-cells		: Should be 0.
> + - regulators:		: List of child nodes that specify the regulators.
> +			  Please see ../regulator/rohm,bd70528-regulator.txt
> +
> +Optional properties:
> + - clock-output-names	: Should contain name for output clock.
> +
> +Example:
> +/* external oscillator */
> +osc: oscillator {
> +	compatible = "fixed-clock";
> +	#clock-cells = <1>;
> +	clock-frequency  = <32768>;
> +	clock-output-names = "osc";
> +};
> +
> +pmic: bd70528@4b {

pmic@4b

> +	compatible = "rohm,bd70528";
> +	reg = <0x4b>;
> +	interrupt-parent = <&gpio1>;
> +	interrupts = <29 GPIO_ACTIVE_LOW>;
> +	clocks = <&osc 0>;
> +	#clock-cells = <0>;
> +	clock-output-names = "bd70528-32k-out";
> +	#gpio-cells = <2>;
> +	gpio-controller;
> +	interrupt-controller;
> +	#interrupt-cells = <2>;
> +
> +	regulators {
> +		buck1: BUCK1 {
> +			regulator-name = "buck1";
> +			regulator-min-microvolt = <1200000>;
> +			regulator-max-microvolt = <3400000>;
> +			regulator-boot-on;
> +			regulator-ramp-delay = <125>;
> +		};
> +		buck2: BUCK2 {
> +			regulator-name = "buck2";
> +			regulator-min-microvolt = <1200000>;
> +			regulator-max-microvolt = <3300000>;
> +			regulator-boot-on;
> +			regulator-ramp-delay = <125>;
> +		};
> +		buck3: BUCK3 {
> +			regulator-name = "buck3";
> +			regulator-min-microvolt = <800000>;
> +			regulator-max-microvolt = <1800000>;
> +			regulator-boot-on;
> +			regulator-ramp-delay = <250>;
> +		};
> +		ldo1: LDO1 {
> +			regulator-name = "ldo1";
> +			regulator-min-microvolt = <1650000>;
> +			regulator-max-microvolt = <3300000>;
> +			regulator-boot-on;
> +		};
> +		ldo2: LDO2 {
> +			regulator-name = "ldo2";
> +			regulator-min-microvolt = <1650000>;
> +			regulator-max-microvolt = <3300000>;
> +			regulator-boot-on;
> +		};
> +
> +		ldo3: LDO3 {
> +			regulator-name = "ldo3";
> +			regulator-min-microvolt = <1650000>;
> +			regulator-max-microvolt = <3300000>;
> +		};
> +		led_ldo1: LED_LDO1 {
> +			regulator-name = "led_ldo1";
> +			regulator-min-microvolt = <200000>;
> +			regulator-max-microvolt = <300000>;
> +		};
> +		led_ldo2: LED_LDO2 {
> +			regulator-name = "led_ldo2";
> +			regulator-min-microvolt = <200000>;
> +			regulator-max-microvolt = <300000>;
> +		};
> +	};
> +};
> -- 
> 2.14.3
> 
> 
> -- 
> Matti Vaittinen
> ROHM Semiconductors
> 
> ~~~ "I don't think so," said Rene Descartes.  Just then, he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings
  2019-02-23  0:30   ` Rob Herring
@ 2019-02-28  6:49     ` Matti Vaittinen
  2019-02-28 15:37         ` Rob Herring
  0 siblings, 1 reply; 33+ messages in thread
From: Matti Vaittinen @ 2019-02-28  6:49 UTC (permalink / raw)
  To: Rob Herring
  Cc: mazziesaccount, lee.jones, mark.rutland, lgirdwood, broonie,
	gregkh, rafael, mturquette, sboyd, linus.walleij, bgolaszewski,
	sre, a.zummo, alexandre.belloni, wim, linux, devicetree,
	linux-kernel, linux-clk, linux-gpio, linux-pm, linux-rtc,
	linux-watchdog, mikko.mutanen, heikki.haikola

Hello Rob, All

Sorry for long delay - I was ill for a few days. Back at the business
now =)

Rob, maybe dropping the RFC tag has messed your book keeping? This
is the latest version:
https://lore.kernel.org/lkml/90c3b820baf072a7cc3a21aa50c661774a045158.1550148989.git.matti.vaittinen@fi.rohmeurope.com/
and I thought it already had the Reviewed-by tag from you :)

On Fri, Feb 22, 2019 at 06:30:41PM -0600, Rob Herring wrote:
> On Tue, Jan 22, 2019 at 11:45:38AM +0200, Matti Vaittinen wrote:
> > Document bindings for regulators (3 bucks, 3 LDOs and 2 LED
> > drivers) and 4 GPIO pins which can be configured for I/O or
> > as interrupt sources withe configurable trigger levels.
> 
> 'dt-bindings: mfd: ...' for the subject.

I see at least the patch subject comment is still valid though. Do you
want me to change it and resubmit the series?

> 
> > 
> > Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
> > ---
> >  .../devicetree/bindings/mfd/rohm,bd70528-pmic.txt  | 104 +++++++++++++++++++++
> >  1 file changed, 104 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt b/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
> > new file mode 100644
> > index 000000000000..21801440a53a
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
> > @@ -0,0 +1,104 @@
> > +* ROHM BD70528 Power Management Integrated Circuit bindings
> > +
> > +BD70528MWV is an ultra-low Iq general purpose single-chip power management IC
> > +for battery-powered portable devices. The IC integrates 3 ultra-low current
> > +consumption buck converters, 3 LDOs and 2 LED Drivers. Also included are 4
> > +GPIOs, a real-time clock (RTC), a 32kHz clock gate, high-accuracy VREF
> > +for use with an external ADC, flexible dual-input power path, 10 bits SAR ADC
> > +for battery temperature monitor and 1S battery charger with scalable charge
> > +currents.

Br,
	Matti Vaittinen


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings
  2019-02-28  6:49     ` Matti Vaittinen
@ 2019-02-28 15:37         ` Rob Herring
  0 siblings, 0 replies; 33+ messages in thread
From: Rob Herring @ 2019-02-28 15:37 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Matti Vaittinen, Lee Jones, Mark Rutland, Liam Girdwood,
	Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
	Michael Turquette, Stephen Boyd, Linus Walleij,
	Bartosz Golaszewski, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, Wim Van Sebroeck, Guenter Roeck, devicetree,
	linux-kernel, linux-clk

On Thu, Feb 28, 2019 at 12:49 AM Matti Vaittinen
<matti.vaittinen@fi.rohmeurope.com> wrote:
>
> Hello Rob, All
>
> Sorry for long delay - I was ill for a few days. Back at the business
> now =)
>
> Rob, maybe dropping the RFC tag has messed your book keeping? This
> is the latest version:
> https://lore.kernel.org/lkml/90c3b820baf072a7cc3a21aa50c661774a045158.1550148989.git.matti.vaittinen@fi.rohmeurope.com/
> and I thought it already had the Reviewed-by tag from you :)

I thought I ignored RFC tag, but could be that. My script (and memory)
aren't perfect.

> On Fri, Feb 22, 2019 at 06:30:41PM -0600, Rob Herring wrote:
> > On Tue, Jan 22, 2019 at 11:45:38AM +0200, Matti Vaittinen wrote:
> > > Document bindings for regulators (3 bucks, 3 LDOs and 2 LED
> > > drivers) and 4 GPIO pins which can be configured for I/O or
> > > as interrupt sources withe configurable trigger levels.
> >
> > 'dt-bindings: mfd: ...' for the subject.
>
> I see at least the patch subject comment is still valid though. Do you
> want me to change it and resubmit the series?

No, if that's the only thing, it's not important.

Rob

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings
@ 2019-02-28 15:37         ` Rob Herring
  0 siblings, 0 replies; 33+ messages in thread
From: Rob Herring @ 2019-02-28 15:37 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Matti Vaittinen, Lee Jones, Mark Rutland, Liam Girdwood,
	Mark Brown, Greg Kroah-Hartman, Rafael J. Wysocki,
	Michael Turquette, Stephen Boyd, Linus Walleij,
	Bartosz Golaszewski, Sebastian Reichel, Alessandro Zummo,
	Alexandre Belloni, Wim Van Sebroeck, Guenter Roeck, devicetree,
	linux-kernel, linux-clk, open list:GPIO SUBSYSTEM,
	open list:THERMAL, open list:REAL TIME CLOCK (RTC) SUBSYSTEM,
	LINUX-WATCHDOG, mikko.mutanen, heikki.haikola

On Thu, Feb 28, 2019 at 12:49 AM Matti Vaittinen
<matti.vaittinen@fi.rohmeurope.com> wrote:
>
> Hello Rob, All
>
> Sorry for long delay - I was ill for a few days. Back at the business
> now =)
>
> Rob, maybe dropping the RFC tag has messed your book keeping? This
> is the latest version:
> https://lore.kernel.org/lkml/90c3b820baf072a7cc3a21aa50c661774a045158.1550148989.git.matti.vaittinen@fi.rohmeurope.com/
> and I thought it already had the Reviewed-by tag from you :)

I thought I ignored RFC tag, but could be that. My script (and memory)
aren't perfect.

> On Fri, Feb 22, 2019 at 06:30:41PM -0600, Rob Herring wrote:
> > On Tue, Jan 22, 2019 at 11:45:38AM +0200, Matti Vaittinen wrote:
> > > Document bindings for regulators (3 bucks, 3 LDOs and 2 LED
> > > drivers) and 4 GPIO pins which can be configured for I/O or
> > > as interrupt sources withe configurable trigger levels.
> >
> > 'dt-bindings: mfd: ...' for the subject.
>
> I see at least the patch subject comment is still valid though. Do you
> want me to change it and resubmit the series?

No, if that's the only thing, it's not important.

Rob

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2019-02-28 15:37 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-22  9:41 [RFC PATCH v1 00/13] support ROHM BD70528 PMIC Matti Vaittinen
2019-01-22  9:42 ` [RFC PATCH v1 01/13] regmap: regmap-irq: Add main status register support Matti Vaittinen
2019-01-23 15:55   ` Mark Brown
2019-01-22  9:42 ` [RFC PATCH v1 02/13] mfd: bd718x7.h split to ROHM common and bd718x7 specific parts Matti Vaittinen
2019-01-22  9:43 ` [RFC PATCH v1 03/13] regulator: bd718x7 use chip specific and generic data structs Matti Vaittinen
2019-01-23 15:51   ` Mark Brown
2019-01-24  7:16     ` Matti Vaittinen
2019-01-24 10:24       ` Mark Brown
2019-01-22  9:44 ` [RFC PATCH v1 04/13] clk: bd718x7: " Matti Vaittinen
2019-01-22  9:44 ` [RFC PATCH v1 05/13] mfd: bd70528: Support ROHM bd70528 PMIC - core Matti Vaittinen
2019-01-22 14:51   ` Guenter Roeck
2019-01-22 16:20     ` Matti Vaittinen
2019-01-22  9:45 ` [RFC PATCH v1 06/13] clk: bd718x7: Support ROHM BD70528 clk block Matti Vaittinen
2019-01-22  9:45 ` [RFC PATCH v1 07/13] devicetree: bindings: Document first ROHM BD70528 bindings Matti Vaittinen
2019-02-23  0:30   ` Rob Herring
2019-02-28  6:49     ` Matti Vaittinen
2019-02-28 15:37       ` Rob Herring
2019-02-28 15:37         ` Rob Herring
2019-01-22  9:46 ` [RFC PATCH v1 08/13] regulator: bd70528: Support ROHM BD70528 regulator block Matti Vaittinen
2019-01-22  9:46 ` [RFC PATCH v1 09/13] devicetree: bindings: ROHM bd70528 regulator bindings Matti Vaittinen
2019-01-22  9:47 ` [RFC PATCH v1 10/13] gpio: Initial support for ROHM bd70528 GPIO block Matti Vaittinen
2019-01-22  9:47 ` [RFC PATCH v1 11/13] rtc: bd70528: Initial support for ROHM bd70528 RTC Matti Vaittinen
2019-01-22 14:48   ` Guenter Roeck
2019-01-22 16:29     ` Matti Vaittinen
2019-01-22  9:48 ` [RFC PATCH v1 12/13] power: supply: Initial support for ROHM BD70528 PMIC charger block Matti Vaittinen
2019-01-22  9:48 ` [RFC PATCH v1 13/13] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block Matti Vaittinen
2019-01-22 15:47   ` Guenter Roeck
2019-01-22 17:10     ` Matti Vaittinen
2019-01-22 17:40       ` Guenter Roeck
2019-01-22 18:03         ` Matti Vaittinen
2019-01-23 17:47           ` Sebastian Reichel
2019-01-24 10:44             ` Matti Vaittinen
2019-01-24 14:37               ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.