Re: [PATCH v5 1/4] mfd: bd71837: mfd driver for ROHM BD71837 PMIC

2018-06-05 Thread Matti Vaittinen
On Mon, Jun 04, 2018 at 04:18:07PM +0300, Matti Vaittinen wrote:
> +static struct regmap_irq_chip bd71837_irq_chip = {
> + .name = "bd71837-irq",
> + .irqs = bd71837_irqs,
> + .num_irqs = ARRAY_SIZE(bd71837_irqs),
> + .num_regs = 1,
> + .irq_reg_stride = 1,
> + .status_base = BD71837_REG_IRQ,
> + .mask_base = BD71837_REG_MIRQ,
> + .init_ack_masked = true,
> + .mask_invert = false,
> +};

.ack_base = BD71837_REG_IRQ, is missing. I'll send yet another version
with this fixed - unless Rob tells me to drop the whole irq handling
from the patch series.

Br,
Matti Vaittinen



Re: [PATCH v5 1/4] mfd: bd71837: mfd driver for ROHM BD71837 PMIC

2018-06-05 Thread Matti Vaittinen
On Mon, Jun 04, 2018 at 04:18:07PM +0300, Matti Vaittinen wrote:
> +static struct regmap_irq_chip bd71837_irq_chip = {
> + .name = "bd71837-irq",
> + .irqs = bd71837_irqs,
> + .num_irqs = ARRAY_SIZE(bd71837_irqs),
> + .num_regs = 1,
> + .irq_reg_stride = 1,
> + .status_base = BD71837_REG_IRQ,
> + .mask_base = BD71837_REG_MIRQ,
> + .init_ack_masked = true,
> + .mask_invert = false,
> +};

.ack_base = BD71837_REG_IRQ, is missing. I'll send yet another version
with this fixed - unless Rob tells me to drop the whole irq handling
from the patch series.

Br,
Matti Vaittinen



[PATCH v5 1/4] mfd: bd71837: mfd driver for ROHM BD71837 PMIC

2018-06-04 Thread Matti Vaittinen
ROHM BD71837 PMIC MFD driver providing interrupts and support
for two subsystems:
- clk
- Regulators

Signed-off-by: Matti Vaittinen 
---
 drivers/mfd/Kconfig |  13 ++
 drivers/mfd/Makefile|   1 +
 drivers/mfd/bd71837.c   | 223 ++
 include/linux/mfd/bd71837.h | 288 
 4 files changed, 525 insertions(+)
 create mode 100644 drivers/mfd/bd71837.c
 create mode 100644 include/linux/mfd/bd71837.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b860eb5aa194..7aa05fc9ed8e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1787,6 +1787,19 @@ config MFD_STW481X
  in various ST Microelectronics and ST-Ericsson embedded
  Nomadik series.
 
+config MFD_BD71837
+   bool "BD71837 Power Management chip"
+   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 BD71837
+ Power Management chips. BD71837 is designed to power processors like
+ 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_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 e9fd20dba18d..09dc9eb3782c 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -227,4 +227,5 @@ obj-$(CONFIG_MFD_STM32_TIMERS)  += stm32-timers.o
 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_BD71837)  += bd71837.o
 
diff --git a/drivers/mfd/bd71837.c b/drivers/mfd/bd71837.c
new file mode 100644
index ..93930f1f2893
--- /dev/null
+++ b/drivers/mfd/bd71837.c
@@ -0,0 +1,223 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 ROHM Semiconductors
+// bd71837.c -- ROHM BD71837MWV mfd driver
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* bd71837 multi function cells */
+static struct mfd_cell bd71837_mfd_cells[] = {
+   {
+   .name = "bd71837-clk",
+   .of_compatible = "rohm,bd71837-clk",
+   }, {
+   .name = "bd71837-pmic",
+   },
+};
+
+static const struct regmap_irq bd71837_irqs[] = {
+   REGMAP_IRQ_REG(BD71837_INT_SWRST, 0, BD71837_INT_SWRST_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_PWRBTN_S, 0, BD71837_INT_PWRBTN_S_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_PWRBTN_L, 0, BD71837_INT_PWRBTN_L_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_PWRBTN, 0, BD71837_INT_PWRBTN_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_WDOG, 0, BD71837_INT_WDOG_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_ON_REQ, 0, BD71837_INT_ON_REQ_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_STBY_REQ, 0, BD71837_INT_STBY_REQ_MASK),
+};
+
+static struct regmap_irq_chip bd71837_irq_chip = {
+   .name = "bd71837-irq",
+   .irqs = bd71837_irqs,
+   .num_irqs = ARRAY_SIZE(bd71837_irqs),
+   .num_regs = 1,
+   .irq_reg_stride = 1,
+   .status_base = BD71837_REG_IRQ,
+   .mask_base = BD71837_REG_MIRQ,
+   .init_ack_masked = true,
+   .mask_invert = false,
+};
+
+static int bd71837_irq_exit(struct bd71837 *bd71837)
+{
+   if (bd71837->chip_irq > 0)
+   regmap_del_irq_chip(bd71837->chip_irq, bd71837->irq_data);
+   return 0;
+}
+
+static const struct regmap_range pmic_status_range = {
+   .range_min = BD71837_REG_IRQ,
+   .range_max = BD71837_REG_POW_STATE,
+};
+
+static const struct regmap_access_table volatile_regs = {
+   .yes_ranges = _status_range,
+   .n_yes_ranges = 1,
+};
+
+static const struct regmap_config bd71837_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .volatile_table = _regs,
+   .max_register = BD71837_MAX_REGISTER - 1,
+   .cache_type = REGCACHE_RBTREE,
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id bd71837_of_match[] = {
+   { .compatible = "rohm,bd71837", .data = (void *)0},
+   { },
+};
+MODULE_DEVICE_TABLE(of, bd71837_of_match);
+
+static int bd71837_parse_dt(struct i2c_client *client, struct bd71837_board 
**b)
+{
+   struct device_node *np = client->dev.of_node;
+   struct bd71837_board *board_info;
+   unsigned int prop;
+   int r;
+   int rv = -ENOMEM;
+
+   board_info = devm_kzalloc(>dev, sizeof(*board_info),
+   GFP_KERNEL);
+   if (!board_info)
+   goto err_out;
+
+   if (client->irq) {
+   dev_dbg(>dev, "Got irq %d\n", client->irq);
+   board_info->gpio_intr = client->irq;
+   } else {
+   dev_err(>dev, "no pmic intr pin available\n");
+   rv 

[PATCH v5 1/4] mfd: bd71837: mfd driver for ROHM BD71837 PMIC

2018-06-04 Thread Matti Vaittinen
ROHM BD71837 PMIC MFD driver providing interrupts and support
for two subsystems:
- clk
- Regulators

Signed-off-by: Matti Vaittinen 
---
 drivers/mfd/Kconfig |  13 ++
 drivers/mfd/Makefile|   1 +
 drivers/mfd/bd71837.c   | 223 ++
 include/linux/mfd/bd71837.h | 288 
 4 files changed, 525 insertions(+)
 create mode 100644 drivers/mfd/bd71837.c
 create mode 100644 include/linux/mfd/bd71837.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b860eb5aa194..7aa05fc9ed8e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1787,6 +1787,19 @@ config MFD_STW481X
  in various ST Microelectronics and ST-Ericsson embedded
  Nomadik series.
 
+config MFD_BD71837
+   bool "BD71837 Power Management chip"
+   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 BD71837
+ Power Management chips. BD71837 is designed to power processors like
+ 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_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 e9fd20dba18d..09dc9eb3782c 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -227,4 +227,5 @@ obj-$(CONFIG_MFD_STM32_TIMERS)  += stm32-timers.o
 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_BD71837)  += bd71837.o
 
diff --git a/drivers/mfd/bd71837.c b/drivers/mfd/bd71837.c
new file mode 100644
index ..93930f1f2893
--- /dev/null
+++ b/drivers/mfd/bd71837.c
@@ -0,0 +1,223 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 ROHM Semiconductors
+// bd71837.c -- ROHM BD71837MWV mfd driver
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* bd71837 multi function cells */
+static struct mfd_cell bd71837_mfd_cells[] = {
+   {
+   .name = "bd71837-clk",
+   .of_compatible = "rohm,bd71837-clk",
+   }, {
+   .name = "bd71837-pmic",
+   },
+};
+
+static const struct regmap_irq bd71837_irqs[] = {
+   REGMAP_IRQ_REG(BD71837_INT_SWRST, 0, BD71837_INT_SWRST_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_PWRBTN_S, 0, BD71837_INT_PWRBTN_S_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_PWRBTN_L, 0, BD71837_INT_PWRBTN_L_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_PWRBTN, 0, BD71837_INT_PWRBTN_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_WDOG, 0, BD71837_INT_WDOG_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_ON_REQ, 0, BD71837_INT_ON_REQ_MASK),
+   REGMAP_IRQ_REG(BD71837_INT_STBY_REQ, 0, BD71837_INT_STBY_REQ_MASK),
+};
+
+static struct regmap_irq_chip bd71837_irq_chip = {
+   .name = "bd71837-irq",
+   .irqs = bd71837_irqs,
+   .num_irqs = ARRAY_SIZE(bd71837_irqs),
+   .num_regs = 1,
+   .irq_reg_stride = 1,
+   .status_base = BD71837_REG_IRQ,
+   .mask_base = BD71837_REG_MIRQ,
+   .init_ack_masked = true,
+   .mask_invert = false,
+};
+
+static int bd71837_irq_exit(struct bd71837 *bd71837)
+{
+   if (bd71837->chip_irq > 0)
+   regmap_del_irq_chip(bd71837->chip_irq, bd71837->irq_data);
+   return 0;
+}
+
+static const struct regmap_range pmic_status_range = {
+   .range_min = BD71837_REG_IRQ,
+   .range_max = BD71837_REG_POW_STATE,
+};
+
+static const struct regmap_access_table volatile_regs = {
+   .yes_ranges = _status_range,
+   .n_yes_ranges = 1,
+};
+
+static const struct regmap_config bd71837_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+   .volatile_table = _regs,
+   .max_register = BD71837_MAX_REGISTER - 1,
+   .cache_type = REGCACHE_RBTREE,
+};
+
+#ifdef CONFIG_OF
+static const struct of_device_id bd71837_of_match[] = {
+   { .compatible = "rohm,bd71837", .data = (void *)0},
+   { },
+};
+MODULE_DEVICE_TABLE(of, bd71837_of_match);
+
+static int bd71837_parse_dt(struct i2c_client *client, struct bd71837_board 
**b)
+{
+   struct device_node *np = client->dev.of_node;
+   struct bd71837_board *board_info;
+   unsigned int prop;
+   int r;
+   int rv = -ENOMEM;
+
+   board_info = devm_kzalloc(>dev, sizeof(*board_info),
+   GFP_KERNEL);
+   if (!board_info)
+   goto err_out;
+
+   if (client->irq) {
+   dev_dbg(>dev, "Got irq %d\n", client->irq);
+   board_info->gpio_intr = client->irq;
+   } else {
+   dev_err(>dev, "no pmic intr pin available\n");
+   rv