[U-Boot] [PATCH v4 1/2] regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot

2019-05-07 Thread Matti Vaittinen
https://source.codeaurora.org/external/imx/uboot-imx

cherry picked, styled and merged commits:
- MLK-18387 pmic: Add pmic driver for BD71837: e9a3bec2e95a
- MLK-18590 pmic: bd71837: Change to use new fdt API: acdc5c297a96

Signed-off-by: Ye Li 
Signed-off-by: Matti Vaittinen 
Reviewed-by: Simon Glass 
---
Changelog v3 => v4:
- No changes

 drivers/power/pmic/Kconfig   |  7 +++
 drivers/power/pmic/Makefile  |  1 +
 drivers/power/pmic/bd71837.c | 89 
 include/power/bd71837.h  | 62 +
 4 files changed, 159 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 include/power/bd71837.h

diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 8cf60ebcf3..e154d0a57b 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -48,6 +48,13 @@ config PMIC_AS3722
  interface and is designs to cover most of the power managementment
  required for a tablets or laptop.
 
+config DM_PMIC_BD71837
+   bool "Enable Driver Model for PMIC BD71837"
+   depends on DM_PMIC
+   help
+ This config enables implementation of driver-model pmic uclass 
features
+ for PMIC BD71837. The driver implements read/write operations.
+
 config DM_PMIC_FAN53555
bool "Enable support for OnSemi FAN53555"
depends on DM_PMIC && DM_REGULATOR && DM_I2C
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 637352ab2b..e605a88196 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_BD71837) += bd71837.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o
 obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
new file mode 100644
index 00..24d9f7fab7
--- /dev/null
+++ b/drivers/power/pmic/bd71837.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier:  GPL-2.0+
+/*
+ * Copyright 2018 NXP
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const struct pmic_child_info pmic_children_info[] = {
+   /* buck */
+   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   /* ldo */
+   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { },
+};
+
+static int bd71837_reg_count(struct udevice *dev)
+{
+   return BD71837_REG_NUM;
+}
+
+static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
+int len)
+{
+   if (dm_i2c_write(dev, reg, buff, len)) {
+   pr_err("write error to device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
+{
+   if (dm_i2c_read(dev, reg, buff, len)) {
+   pr_err("read error from device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_bind(struct udevice *dev)
+{
+   int children;
+   ofnode regulators_node;
+
+   regulators_node = dev_read_subnode(dev, "regulators");
+   if (!ofnode_valid(regulators_node)) {
+   debug("%s: %s regulators subnode not found!", __func__,
+ dev->name);
+   return -ENXIO;
+   }
+
+   debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
+
+   children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+   if (!children)
+   debug("%s: %s - no child found\n", __func__, dev->name);
+
+   /* Always return success for this device */
+   return 0;
+}
+
+static struct dm_pmic_ops bd71837_ops = {
+   .reg_count = bd71837_reg_count,
+   .read = bd71837_read,
+   .write = bd71837_write,
+};
+
+static const struct udevice_id bd71837_ids[] = {
+   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { }
+};
+
+U_BOOT_DRIVER(pmic_bd71837) = {
+   .name = "bd71837 pmic",
+   .id = UCLASS_PMIC,
+   .of_match = bd71837_ids,
+   .bind = bd71837_bind,
+   .ops = _ops,
+};
diff --git a/include/power/bd71837.h b/include/power/bd71837.h
new file mode 100644
index 00..38c69b2b90
--- /dev/null
+++ b/include/power/bd71837.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2018 ROHM Semiconductors */
+
+#ifndef BD71837_H_
+#define BD71837_H_
+
+#define BD71837_REGULATOR_DRIVER "bd71837_regulator"
+
+enum {
+   BD71837_REV   

[U-Boot] [PATCH v4 0/2] support for ROHM BD71837 and BD71847 PMICs

2019-05-07 Thread Matti Vaittinen
Patch series to support for ROHM BD71837 and BD71847 PMICs.

ROHM BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847 is used
for example on NXP imx8mm EVK.

Series adds PMIC driver with register read and write support, and
regulator driver with enable/disable and voltage changing support
with certain limitations:
- Enable/Disable state control is by default only allowed for BD71837
  bucks 3 and 4. This is due to a HW feature which leaves SW
  controlled power rails unpowered after reset which leads to SNVS
  state.
- Voltage control for enabled regulator is only allowed for "DVS"
  regulators (bucks 1-4 on BD71837, bucks 1 and 2 on BD71847). This
  is done because changing voltage on other regulators may cause
  under-/over shoot when regulator is enabled.

Drivers expect to see PMIC node with proper regulator sub-nodes given
from device tree but.

Driver is tested using BD71837 and BD71847 break-out board connected
to Beagle Bone Black and device-tree entry which was created as
desctibed in dt-binding document for BD718x7 shipped with Linux.

This patch series does not support DT properties which allow changing
the reset target between SNVS and READY or identifying boot-critical
regulators and disabling SW control based on reset target as the
Linux driver does.

Changelog v4:
- prefer u8 over uint8_t
- prefer types with natural alignment over u8 on function arguments
- remove inclusion of errno.h

Changelog v3:
- improve Kconfig description
- use pmic_clrsetbits() also in pmic/bd71837.c
- remove unnecessary header includes
- minor readability/styling fixes

Changelog v2: (fix issues pointed by Simon Glass)
- Fix typo in patch series name (BD71827 => BD71837)
- Drop drivers/power/pmic/pmic_bd71837.c (the old PMIC interface)
- Fix characters in hex numbers to lowercase
- use pmic_clrsetbits() instead of using separate reads and writes
- fix styling issues

Changelog v1:
- This version is created based on the RFC v1.
  https://lists.denx.de/pipermail/u-boot/2019-March/363076.html
  https://lists.denx.de/pipermail/u-boot/2019-March/363077.html
- Support BD71847.
- Unlock the PMIC protection register

Patch 1:
- Cherry picks the initial PMIC driver for BD71837 from NXP's i.MX
  repository at: https://source.codeaurora.org/external/imx/uboot-imx
  (commits e9a3bec2e95a and acdc5c297a96). Fixes checkpatch issues.

Patch 2:
- Support BD71847 PMIC.
- Add support for BD71837 and BD71847 regulators.

---


Matti Vaittinen (2):
  regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot
  regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

 drivers/power/pmic/Kconfig|   7 +
 drivers/power/pmic/Makefile   |   1 +
 drivers/power/pmic/bd71837.c  | 111 +++
 drivers/power/regulator/Kconfig   |  17 ++
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 468 ++
 include/power/bd71837.h   | 103 +++
 7 files changed, 708 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 drivers/power/regulator/bd71837.c
 create mode 100644 include/power/bd71837.h

-- 
2.17.2


-- 
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 ~~~
Simon says - in Latin please.
"non cogito me" dixit Rene Descarte, deinde evanescavit

Thanks to Simon Glass for the translation =]
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 2/2] regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

2019-05-07 Thread Matti Vaittinen
BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847
is used for example on NXP imx8mm EVK.

Add regulator driver for ROHM BD71837 and BD71847 PMICs.
BD71837 contains 8 bucks and 7 LDOS. BD71847 is reduced
version containing 6 bucks and 6 LDOs. Voltages for DVS
bucks (1-4 on BD71837, 1 and 2 on BD71847) can be adjusted
when regulators are enabled. For other bucks and LDOs we may
have over- or undershooting if voltage is adjusted when
regulator is enabled. Thus this is prevented by default.

BD718x7 has a quirk which may leave power output disabled
after reset if enable/disable state was controlled by SW.
Thus the SW control is only allowed for BD71837  bucks
3 and 4 by default. The impact of this limitation must be
evaluated board-by board and restrictions may need to be
modified. (Linux driver get's these limitations from DT and we
may want to implement same on u-Boot driver).

Signed-off-by: Matti Vaittinen 
---
Changelog v3 => v4:
- prefer u8 over uint8_t
- prefer types with natural alignment over u8 on function arguments
- remove inclusion of errno.h from drivers/power/regulator/bd71837.c

 drivers/power/pmic/bd71837.c  |  32 +-
 drivers/power/regulator/Kconfig   |  17 ++
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 468 ++
 include/power/bd71837.h   | 147 ++
 5 files changed, 607 insertions(+), 58 deletions(-)
 create mode 100644 drivers/power/regulator/bd71837.c

diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
index 24d9f7fab7..e292d42a8c 100644
--- a/drivers/power/pmic/bd71837.c
+++ b/drivers/power/pmic/bd71837.c
@@ -3,6 +3,8 @@
  * Copyright 2018 NXP
  */
 
+#define DEBUG
+
 #include 
 #include 
 #include 
@@ -15,15 +17,15 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static const struct pmic_child_info pmic_children_info[] = {
/* buck */
-   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
/* ldo */
-   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
{ },
 };
 
 static int bd71837_reg_count(struct udevice *dev)
 {
-   return BD71837_REG_NUM;
+   return BD718XX_MAX_REGISTER - 1;
 }
 
 static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
@@ -54,7 +56,7 @@ static int bd71837_bind(struct udevice *dev)
 
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
-   debug("%s: %s regulators subnode not found!", __func__,
+   debug("%s: %s regulators subnode not found!\n", __func__,
  dev->name);
return -ENXIO;
}
@@ -69,6 +71,24 @@ static int bd71837_bind(struct udevice *dev)
return 0;
 }
 
+static int bd718x7_probe(struct udevice *dev)
+{
+   int ret;
+   uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG;
+
+   /* Unlock the PMIC regulator control before probing the children */
+   ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0);
+   if (ret) {
+   debug("%s: %s Failed to unlock regulator control\n", __func__,
+ dev->name);
+   return ret;
+   }
+   debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__,
+ dev->name);
+
+   return 0;
+}
+
 static struct dm_pmic_ops bd71837_ops = {
.reg_count = bd71837_reg_count,
.read = bd71837_read,
@@ -76,7 +96,8 @@ static struct dm_pmic_ops bd71837_ops = {
 };
 
 static const struct udevice_id bd71837_ids[] = {
-   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
+   { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
{ }
 };
 
@@ -85,5 +106,6 @@ U_BOOT_DRIVER(pmic_bd71837) = {
.id = UCLASS_PMIC,
.of_match = bd71837_ids,
.bind = bd71837_bind,
+   .probe = bd718x7_probe,
.ops = _ops,
 };
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 3ed0dd2264..4687bee09c 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -43,6 +43,23 @@ config REGULATOR_AS3722
  but does not yet support change voltages. Currently this must be
  done using direct register writes to the PMIC.
 
+config DM_REGULATOR_BD71837
+   bool "Enable Driver Model for ROHM BD71837/BD71847 regulators"
+   depends on DM_REGULATOR && DM_PMIC_BD71837
+   help
+   This config enables implementation of driver-model regulator uclass
+   features for regulators on ROHM BD71837 and BD71847 PMICs.
+   BD71837 contain

[U-Boot] [PATCH v3 2/2] regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

2019-04-25 Thread Matti Vaittinen
BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847
is used for example on NXP imx8mm EVK.

Add regulator driver for ROHM BD71837 and BD71847 PMICs.
BD71837 contains 8 bucks and 7 LDOS. BD71847 is reduced
version containing 6 bucks and 6 LDOs. Voltages for DVS
bucks (1-4 on BD71837, 1 and 2 on BD71847) can be adjusted
when regulators are enabled. For other bucks and LDOs we may
have over- or undershooting if voltage is adjusted when
regulator is enabled. Thus this is prevented by default.

BD718x7 has a quirk which may leave power output disabled
after reset if enable/disable state was controlled by SW.
Thus the SW control is only allowed for BD71837  bucks
3 and 4 by default. The impact of this limitation must be
evaluated board-by board and restrictions may need to be
modified. (Linux driver get's these limitations from DT and we
may want to implement same on u-Boot driver).

Signed-off-by: Matti Vaittinen 
---

Changelog v2 => v3:
- remove unnecessary include
- use uint8_t instead of u8
- improve Kconfig documentation
- improve readability by inverting handling of 'not_found' variable
  to 'found'

 drivers/power/pmic/bd71837.c  |  32 +-
 drivers/power/regulator/Kconfig   |  17 ++
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 468 ++
 include/power/bd71837.h   | 147 ++
 5 files changed, 607 insertions(+), 58 deletions(-)
 create mode 100644 drivers/power/regulator/bd71837.c

diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
index 24d9f7fab7..e292d42a8c 100644
--- a/drivers/power/pmic/bd71837.c
+++ b/drivers/power/pmic/bd71837.c
@@ -3,6 +3,8 @@
  * Copyright 2018 NXP
  */
 
+#define DEBUG
+
 #include 
 #include 
 #include 
@@ -15,15 +17,15 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static const struct pmic_child_info pmic_children_info[] = {
/* buck */
-   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
/* ldo */
-   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
{ },
 };
 
 static int bd71837_reg_count(struct udevice *dev)
 {
-   return BD71837_REG_NUM;
+   return BD718XX_MAX_REGISTER - 1;
 }
 
 static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
@@ -54,7 +56,7 @@ static int bd71837_bind(struct udevice *dev)
 
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
-   debug("%s: %s regulators subnode not found!", __func__,
+   debug("%s: %s regulators subnode not found!\n", __func__,
  dev->name);
return -ENXIO;
}
@@ -69,6 +71,24 @@ static int bd71837_bind(struct udevice *dev)
return 0;
 }
 
+static int bd718x7_probe(struct udevice *dev)
+{
+   int ret;
+   uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG;
+
+   /* Unlock the PMIC regulator control before probing the children */
+   ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0);
+   if (ret) {
+   debug("%s: %s Failed to unlock regulator control\n", __func__,
+ dev->name);
+   return ret;
+   }
+   debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__,
+ dev->name);
+
+   return 0;
+}
+
 static struct dm_pmic_ops bd71837_ops = {
.reg_count = bd71837_reg_count,
.read = bd71837_read,
@@ -76,7 +96,8 @@ static struct dm_pmic_ops bd71837_ops = {
 };
 
 static const struct udevice_id bd71837_ids[] = {
-   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
+   { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
{ }
 };
 
@@ -85,5 +106,6 @@ U_BOOT_DRIVER(pmic_bd71837) = {
.id = UCLASS_PMIC,
.of_match = bd71837_ids,
.bind = bd71837_bind,
+   .probe = bd718x7_probe,
.ops = _ops,
 };
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 3ed0dd2264..4687bee09c 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -43,6 +43,23 @@ config REGULATOR_AS3722
  but does not yet support change voltages. Currently this must be
  done using direct register writes to the PMIC.
 
+config DM_REGULATOR_BD71837
+   bool "Enable Driver Model for ROHM BD71837/BD71847 regulators"
+   depends on DM_REGULATOR && DM_PMIC_BD71837
+   help
+   This config enables implementation of driver-model regulator uclass
+   features for regulators on ROHM BD71837 and BD71847 PMICs.
+   BD71

[U-Boot] [PATCH v3 1/2] regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot

2019-04-25 Thread Matti Vaittinen
https://source.codeaurora.org/external/imx/uboot-imx

cherry picked, styled and merged commits:
- MLK-18387 pmic: Add pmic driver for BD71837: e9a3bec2e95a
- MLK-18590 pmic: bd71837: Change to use new fdt API: acdc5c297a96

Signed-off-by: Ye Li 
Signed-off-by: Matti Vaittinen 
---
Changelog v2 => v3
- use pmic_clrsetbits() instead of reg_read and reg_write
- remove unnecessary include

 drivers/power/pmic/Kconfig   |  7 +++
 drivers/power/pmic/Makefile  |  1 +
 drivers/power/pmic/bd71837.c | 89 
 include/power/bd71837.h  | 62 +
 4 files changed, 159 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 include/power/bd71837.h

diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 8cf60ebcf3..e154d0a57b 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -48,6 +48,13 @@ config PMIC_AS3722
  interface and is designs to cover most of the power managementment
  required for a tablets or laptop.
 
+config DM_PMIC_BD71837
+   bool "Enable Driver Model for PMIC BD71837"
+   depends on DM_PMIC
+   help
+ This config enables implementation of driver-model pmic uclass 
features
+ for PMIC BD71837. The driver implements read/write operations.
+
 config DM_PMIC_FAN53555
bool "Enable support for OnSemi FAN53555"
depends on DM_PMIC && DM_REGULATOR && DM_I2C
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 637352ab2b..e605a88196 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_BD71837) += bd71837.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o
 obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
new file mode 100644
index 00..24d9f7fab7
--- /dev/null
+++ b/drivers/power/pmic/bd71837.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier:  GPL-2.0+
+/*
+ * Copyright 2018 NXP
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const struct pmic_child_info pmic_children_info[] = {
+   /* buck */
+   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   /* ldo */
+   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { },
+};
+
+static int bd71837_reg_count(struct udevice *dev)
+{
+   return BD71837_REG_NUM;
+}
+
+static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
+int len)
+{
+   if (dm_i2c_write(dev, reg, buff, len)) {
+   pr_err("write error to device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
+{
+   if (dm_i2c_read(dev, reg, buff, len)) {
+   pr_err("read error from device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_bind(struct udevice *dev)
+{
+   int children;
+   ofnode regulators_node;
+
+   regulators_node = dev_read_subnode(dev, "regulators");
+   if (!ofnode_valid(regulators_node)) {
+   debug("%s: %s regulators subnode not found!", __func__,
+ dev->name);
+   return -ENXIO;
+   }
+
+   debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
+
+   children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+   if (!children)
+   debug("%s: %s - no child found\n", __func__, dev->name);
+
+   /* Always return success for this device */
+   return 0;
+}
+
+static struct dm_pmic_ops bd71837_ops = {
+   .reg_count = bd71837_reg_count,
+   .read = bd71837_read,
+   .write = bd71837_write,
+};
+
+static const struct udevice_id bd71837_ids[] = {
+   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { }
+};
+
+U_BOOT_DRIVER(pmic_bd71837) = {
+   .name = "bd71837 pmic",
+   .id = UCLASS_PMIC,
+   .of_match = bd71837_ids,
+   .bind = bd71837_bind,
+   .ops = _ops,
+};
diff --git a/include/power/bd71837.h b/include/power/bd71837.h
new file mode 100644
index 00..38c69b2b90
--- /dev/null
+++ b/include/power/bd71837.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2018 ROHM Semiconductors */
+
+#ifndef BD71837_H_
+#define BD71837_H_
+
+#define BD71837_REGULATOR_DRIVER "bd71837_regulator&qu

[U-Boot] [PATCH v3 0/2] support for ROHM BD71837 and BD71847 PMICs

2019-04-25 Thread Matti Vaittinen
Patch series to support for ROHM BD71837 and BD71847 PMICs.

ROHM BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847 is used
for example on NXP imx8mm EVK.

Series adds PMIC driver with register read and write support, and
regulator driver with enable/disable and voltage changing support
with certain limitations:
- Enable/Disable state control is by default only allowed for BD71837
  bucks 3 and 4. This is due to a HW feature which leaves SW
  controlled power rails unpowered after reset which leads to SNVS
  state.
- Voltage control for enabled regulator is only allowed for "DVS"
  regulators (bucks 1-4 on BD71837, bucks 1 and 2 on BD71847). This
  is done because changing voltage on other regulators may cause
  under-/over shoot when regulator is enabled.

Drivers expect to see PMIC node with proper regulator sub-nodes given
from device tree but.

Driver is tested using BD71837 and BD71847 break-out board connected
to Beagle Bone Black and device-tree entry which was created as
desctibed in dt-binding document for BD718x7 shipped with Linux.

This patch series does not support DT properties which allow changing
the reset target between SNVS and READY or identifying boot-critical
regulators and disabling SW control based on reset target as the
Linux driver does.

Changelog v3:
- improve Kconfig description
- use pmic_clrsetbits() also in pmic/bd71837.c
- remove unnecessary header includes
- minor readability/styling fixes

Changelog v2: (fix issues pointed by Simon Glass)
- Fix typo in patch series name (BD71827 => BD71837)
- Drop drivers/power/pmic/pmic_bd71837.c (the old PMIC interface)
- Fix characters in hex numbers to lowercase
- use pmic_clrsetbits() instead of using separate reads and writes
- fix styling issues

Changelog v1:
- This version is created based on the RFC v1.
  https://lists.denx.de/pipermail/u-boot/2019-March/363076.html
  https://lists.denx.de/pipermail/u-boot/2019-March/363077.html
- Support BD71847.
- Unlock the PMIC protection register

Patch 1:
- Cherry picks the initial PMIC driver for BD71837 from NXP's i.MX
  repository at: https://source.codeaurora.org/external/imx/uboot-imx
  (commits e9a3bec2e95a and acdc5c297a96). Fixes checkpatch issues.

Patch 2:
- Support BD71847 PMIC.
- Add support for BD71837 and BD71847 regulators.

---

Matti Vaittinen (2):
  regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot
  regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

 drivers/power/pmic/Kconfig|   7 +
 drivers/power/pmic/Makefile   |   1 +
 drivers/power/pmic/bd71837.c  | 111 +++
 drivers/power/regulator/Kconfig   |  17 ++
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 468 ++
 include/power/bd71837.h   | 103 +++
 7 files changed, 708 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 drivers/power/regulator/bd71837.c
 create mode 100644 include/power/bd71837.h

-- 
2.17.2


-- 
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 ~~~
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 2/2] regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

2019-04-24 Thread Matti Vaittinen
BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847
is used for example on NXP imx8mm EVK.

Add regulator driver for ROHM BD71837 and BD71847 PMICs.
BD71837 contains 8 bucks and 7 LDOS. BD71847 is reduced
version containing 6 bucks and 6 LDOs. Voltages for DVS
bucks (1-4 on BD71837, 1 and 2 on BD71847) can be adjusted
when regulators are enabled. For other bucks and LDOs we may
have over- or undershooting if voltage is adjusted when
regulator is enabled. Thus this is prevented by default.

BD718x7 has a quirk which may leave power output disabled
after reset if enable/disable state was controlled by SW.
Thus the SW control is only allowed for BD71837  bucks
3 and 4 by default. The impact of this limitation must be
evaluated board-by board and restrictions may need to be
modified. (Linux driver get's these limitations from DT and we
may want to implement same on u-Boot driver).

Signed-off-by: Matti Vaittinen 
---

Changelog v1 => v2:
- document structs containing the platdata
- use pmic_clrsetbits() instead of using separate reads and writes
- fix styling issues

 drivers/power/pmic/bd71837.c  |  42 ++-
 drivers/power/regulator/Kconfig   |  15 +
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 469 ++
 include/power/bd71837.h   | 147 ++
 5 files changed, 616 insertions(+), 58 deletions(-)
 create mode 100644 drivers/power/regulator/bd71837.c

diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
index b749f9430a..12c2e15a19 100644
--- a/drivers/power/pmic/bd71837.c
+++ b/drivers/power/pmic/bd71837.c
@@ -3,6 +3,8 @@
  * Copyright 2018 NXP
  */
 
+#define DEBUG
+
 #include 
 #include 
 #include 
@@ -16,15 +18,15 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static const struct pmic_child_info pmic_children_info[] = {
/* buck */
-   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
/* ldo */
-   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
{ },
 };
 
 static int bd71837_reg_count(struct udevice *dev)
 {
-   return BD71837_REG_NUM;
+   return BD718XX_MAX_REGISTER - 1;
 }
 
 static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
@@ -55,7 +57,7 @@ static int bd71837_bind(struct udevice *dev)
 
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
-   debug("%s: %s regulators subnode not found!", __func__,
+   debug("%s: %s regulators subnode not found!\n", __func__,
  dev->name);
return -ENXIO;
}
@@ -70,6 +72,34 @@ static int bd71837_bind(struct udevice *dev)
return 0;
 }
 
+static int bd718x7_probe(struct udevice *dev)
+{
+   int ret;
+   u8 unlock;
+
+   /* Unlock the PMIC regulator control before probing the children */
+   ret = pmic_reg_read(dev, BD718XX_REGLOCK);
+   if (ret < 0) {
+   debug("%s: %s Failed to read lock register, error %d\n",
+ __func__, dev->name, ret);
+   return ret;
+   }
+
+   unlock = ret;
+   unlock &= ~(BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG);
+
+   ret = pmic_reg_write(dev, BD718XX_REGLOCK, unlock);
+   if (ret) {
+   debug("%s: %s Failed to unlock regulator control\n", __func__,
+ dev->name);
+   return ret;
+   }
+   debug("%s: '%s' - BD718x7 PMIC register unlocked\n", __func__,
+ dev->name);
+
+   return 0;
+}
+
 static struct dm_pmic_ops bd71837_ops = {
.reg_count = bd71837_reg_count,
.read = bd71837_read,
@@ -77,7 +107,8 @@ static struct dm_pmic_ops bd71837_ops = {
 };
 
 static const struct udevice_id bd71837_ids[] = {
-   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
+   { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
{ }
 };
 
@@ -86,5 +117,6 @@ U_BOOT_DRIVER(pmic_bd71837) = {
.id = UCLASS_PMIC,
.of_match = bd71837_ids,
.bind = bd71837_bind,
+   .probe = bd718x7_probe,
.ops = _ops,
 };
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 3ed0dd2264..323516587c 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -43,6 +43,21 @@ config REGULATOR_AS3722
  but does not yet support change voltages. Currently this must be
  done using direct register writes to the PMIC.
 
+config DM_REGULATOR_BD71837
+   bool "Enable Driver Model for R

[U-Boot] [PATCH v2 1/2] regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot

2019-04-24 Thread Matti Vaittinen
https://source.codeaurora.org/external/imx/uboot-imx

cherry picked, styled and merged commits:
- MLK-18387 pmic: Add pmic driver for BD71837: e9a3bec2e95a
- MLK-18590 pmic: bd71837: Change to use new fdt API: acdc5c297a96

Signed-off-by: Ye Li 
Signed-off-by: Matti Vaittinen 
---

Changelog v1 => v2:
- Drop drivers/power/pmic/pmic_bd71837.c (the old PMIC interface)
- Fix characters in hex numbers to lowercase

 drivers/power/pmic/Kconfig   |  7 +++
 drivers/power/pmic/Makefile  |  1 +
 drivers/power/pmic/bd71837.c | 90 
 include/power/bd71837.h  | 62 +
 4 files changed, 160 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 include/power/bd71837.h

diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 8cf60ebcf3..e154d0a57b 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -48,6 +48,13 @@ config PMIC_AS3722
  interface and is designs to cover most of the power managementment
  required for a tablets or laptop.
 
+config DM_PMIC_BD71837
+   bool "Enable Driver Model for PMIC BD71837"
+   depends on DM_PMIC
+   help
+ This config enables implementation of driver-model pmic uclass 
features
+ for PMIC BD71837. The driver implements read/write operations.
+
 config DM_PMIC_FAN53555
bool "Enable support for OnSemi FAN53555"
depends on DM_PMIC && DM_REGULATOR && DM_I2C
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 637352ab2b..e605a88196 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_BD71837) += bd71837.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o
 obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
new file mode 100644
index 00..b749f9430a
--- /dev/null
+++ b/drivers/power/pmic/bd71837.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier:  GPL-2.0+
+/*
+ * Copyright 2018 NXP
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const struct pmic_child_info pmic_children_info[] = {
+   /* buck */
+   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   /* ldo */
+   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { },
+};
+
+static int bd71837_reg_count(struct udevice *dev)
+{
+   return BD71837_REG_NUM;
+}
+
+static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
+int len)
+{
+   if (dm_i2c_write(dev, reg, buff, len)) {
+   pr_err("write error to device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
+{
+   if (dm_i2c_read(dev, reg, buff, len)) {
+   pr_err("read error from device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_bind(struct udevice *dev)
+{
+   int children;
+   ofnode regulators_node;
+
+   regulators_node = dev_read_subnode(dev, "regulators");
+   if (!ofnode_valid(regulators_node)) {
+   debug("%s: %s regulators subnode not found!", __func__,
+ dev->name);
+   return -ENXIO;
+   }
+
+   debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
+
+   children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+   if (!children)
+   debug("%s: %s - no child found\n", __func__, dev->name);
+
+   /* Always return success for this device */
+   return 0;
+}
+
+static struct dm_pmic_ops bd71837_ops = {
+   .reg_count = bd71837_reg_count,
+   .read = bd71837_read,
+   .write = bd71837_write,
+};
+
+static const struct udevice_id bd71837_ids[] = {
+   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { }
+};
+
+U_BOOT_DRIVER(pmic_bd71837) = {
+   .name = "bd71837 pmic",
+   .id = UCLASS_PMIC,
+   .of_match = bd71837_ids,
+   .bind = bd71837_bind,
+   .ops = _ops,
+};
diff --git a/include/power/bd71837.h b/include/power/bd71837.h
new file mode 100644
index 00..38c69b2b90
--- /dev/null
+++ b/include/power/bd71837.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2018 ROHM Semiconductors */
+
+#ifndef BD71837_H_
+#define BD71837_H_
+
+#define BD71837_RE

[U-Boot] [PATCH v2 0/2] support for ROHM BD71837 and BD71847 PMICs

2019-04-24 Thread Matti Vaittinen
Patch series to support for ROHM BD71837 and BD71847 PMICs.

ROHM BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847 is used
for example on NXP imx8mm EVK.

Series adds PMIC driver with register read and write support, and
regulator driver with enable/disable and voltage changing support
with certain limitations:
- Enable/Disable state control is by default only allowed for BD71837
  bucks 3 and 4. This is due to a HW feature which leaves SW
  controlled power rails unpowered after reset which leads to SNVS
  state.
- Voltage control for enabled regulator is only allowed for "DVS"
  regulators (bucks 1-4 on BD71837, bucks 1 and 2 on BD71847). This
  is done because changing voltage on other regulators may cause
  under-/over shoot when regulator is enabled.

Drivers expect to see PMIC node with proper regulator sub-nodes given
from device tree but.

Driver is tested using BD71837 and BD71847 break-out board connected
to Beagle Bone Black and device-tree entry which was created as
desctibed in dt-binding document for BD718x7 shipped with Linux.

This patch series does not support DT properties which allow changing
the reset target between SNVS and READY or identifying boot-critical
regulators and disabling SW control based on reset target as the
Linux driver does.

Changelog v2: (fix issues pointed by Simon Glass)
- Fix typo in patch series name (BD71827 => BD71837)
- Drop drivers/power/pmic/pmic_bd71837.c (the old PMIC interface)
- Fix characters in hex numbers to lowercase
- use pmic_clrsetbits() instead of using separate reads and writes
- fix styling issues

Changelog v1:
- This version is created based on the RFC v1.
  https://lists.denx.de/pipermail/u-boot/2019-March/363076.html
  https://lists.denx.de/pipermail/u-boot/2019-March/363077.html
- Support BD71847.
- Unlock the PMIC protection register

Patch 1:
- Cherry picks the initial PMIC driver for BD71837 from NXP's i.MX
  repository at: https://source.codeaurora.org/external/imx/uboot-imx
  (commits e9a3bec2e95a and acdc5c297a96). Fixes checkpatch issues.

Patch 2:
- Support BD71847 PMIC.
- Add support for BD71837 and BD71847 regulators.

---

Matti Vaittinen (2):
  regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot
  regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

 drivers/power/pmic/Kconfig|   7 +
 drivers/power/pmic/Makefile   |   1 +
 drivers/power/pmic/bd71837.c  | 122 
 drivers/power/regulator/Kconfig   |  15 +
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 469 ++
 include/power/bd71837.h   | 103 +++
 7 files changed, 718 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 drivers/power/regulator/bd71837.c
 create mode 100644 include/power/bd71837.h

-- 
2.17.2


-- 
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 ~~~
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v1 2/2] regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

2019-04-08 Thread Matti Vaittinen
BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847
is used for example on NXP imx8mm EVK.

Add regulator driver for ROHM BD71837 and BD71847 PMICs.
BD71837 contains 8 bucks and 7 LDOS. BD71847 is reduced
version containing 6 bucks and 6 LDOs. Voltages for DVS
bucks (1-4 on BD71837, 1 and 2 on BD71847) can be adjusted
when regulators are enabled. For other bucks and LDOs we may
have over- or undershooting if voltage is adjusted when
regulator is enabled. Thus this is prevented by default.

BD718x7 has a quirk which may leave power output disabled
after reset if enable/disable state was controlled by SW.
Thus the SW control is only allowed for BD71837  bucks
3 and 4 by default. The impact of this limitation must be
evaluated board-by board and restrictions may need to be
modified. (Linux driver get's these limitations from DT and we
may want to implement same on u-Boot driver).

Signed-off-by: Matti Vaittinen 

---

Changelog v1:
  This version is created based on the RFC v1.
  https://lists.denx.de/pipermail/u-boot/2019-March/363077.html
  Additionally
- Support BD71847.
- Unlock the PMIC protection register

 drivers/power/pmic/bd71837.c  |  42 ++-
 drivers/power/regulator/Kconfig   |  15 +
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 457 ++
 include/power/bd71837.h   | 147 ++
 5 files changed, 604 insertions(+), 58 deletions(-)
 create mode 100644 drivers/power/regulator/bd71837.c

diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
index eadf373a18..babddcba60 100644
--- a/drivers/power/pmic/bd71837.c
+++ b/drivers/power/pmic/bd71837.c
@@ -2,6 +2,8 @@
 //
 // Copyright 2018 NXP  *
 
+#define DEBUG
+
 #include 
 #include 
 #include 
@@ -15,15 +17,15 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static const struct pmic_child_info pmic_children_info[] = {
/* buck */
-   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
/* ldo */
-   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
{ },
 };
 
 static int bd71837_reg_count(struct udevice *dev)
 {
-   return BD71837_REG_NUM;
+   return BD718XX_MAX_REGISTER - 1;
 }
 
 static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
@@ -54,7 +56,7 @@ static int bd71837_bind(struct udevice *dev)
 
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
-   debug("%s: %s regulators subnode not found!", __func__,
+   debug("%s: %s regulators subnode not found!\n", __func__,
  dev->name);
return -ENXIO;
}
@@ -69,6 +71,34 @@ static int bd71837_bind(struct udevice *dev)
return 0;
 }
 
+static int bd718x7_probe(struct udevice *dev)
+{
+   int ret;
+   u8 unlock;
+
+   /* Unlock the PMIC regulator control before probing the children */
+   ret = pmic_reg_read(dev, BD718XX_REGLOCK);
+   if (ret < 0) {
+   debug("%s: %s Failed to read lock register, error %d\n",
+ __func__, dev->name, ret);
+   return ret;
+   }
+
+   unlock = ret;
+   unlock &= ~(BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG);
+
+   ret = pmic_reg_write(dev, BD718XX_REGLOCK, unlock);
+   if (ret) {
+   debug("%s: %s Failed to unlock regulator control\n", __func__,
+ dev->name);
+   return ret;
+   }
+   debug("%s: '%s' - BD718x7 PMIC register unlocked\n", __func__,
+ dev->name);
+
+   return 0;
+}
+
 static struct dm_pmic_ops bd71837_ops = {
.reg_count = bd71837_reg_count,
.read = bd71837_read,
@@ -76,7 +106,8 @@ static struct dm_pmic_ops bd71837_ops = {
 };
 
 static const struct udevice_id bd71837_ids[] = {
-   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
+   { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
{ }
 };
 
@@ -85,5 +116,6 @@ U_BOOT_DRIVER(pmic_bd71837) = {
.id = UCLASS_PMIC,
.of_match = bd71837_ids,
.bind = bd71837_bind,
+   .probe = bd718x7_probe,
.ops = _ops,
 };
diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 3ed0dd2264..323516587c 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -43,6 +43,21 @@ config REGULATOR_AS3722
  but does not yet support change voltages. Currently this must be
  done using direct register writes to the PMIC.
 
+config DM_REGULATOR_BD71837

[U-Boot] [PATCH v1 1/2] regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot

2019-04-08 Thread Matti Vaittinen
https://source.codeaurora.org/external/imx/uboot-imx

cherry picked, styled and merged commits:
- MLK-18387 pmic: Add pmic driver for BD71837: e9a3bec2e95a
- MLK-18590 pmic: bd71837: Change to use new fdt API: acdc5c297a96

Signed-off-by: Ye Li 
Signed-off-by: Matti Vaittinen 
---

Based on RFC:
https://lists.denx.de/pipermail/u-boot/2019-March/363076.html

 drivers/power/pmic/Kconfig|  7 +++
 drivers/power/pmic/Makefile   |  2 +
 drivers/power/pmic/bd71837.c  | 89 +++
 drivers/power/pmic/pmic_bd71837.c | 31 +++
 include/power/bd71837.h   | 64 ++
 5 files changed, 193 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 drivers/power/pmic/pmic_bd71837.c
 create mode 100644 include/power/bd71837.h

diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 8cf60ebcf3..e154d0a57b 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -48,6 +48,13 @@ config PMIC_AS3722
  interface and is designs to cover most of the power managementment
  required for a tablets or laptop.
 
+config DM_PMIC_BD71837
+   bool "Enable Driver Model for PMIC BD71837"
+   depends on DM_PMIC
+   help
+ This config enables implementation of driver-model pmic uclass 
features
+ for PMIC BD71837. The driver implements read/write operations.
+
 config DM_PMIC_FAN53555
bool "Enable support for OnSemi FAN53555"
depends on DM_PMIC && DM_REGULATOR && DM_I2C
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 637352ab2b..e74c6190a8 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_BD71837) += bd71837.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o
 obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
@@ -30,6 +31,7 @@ obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
 obj-$(CONFIG_POWER_MAX8998) += pmic_max8998.o
 obj-$(CONFIG_POWER_MAX8997) += pmic_max8997.o
 obj-$(CONFIG_POWER_MUIC_MAX8997) += muic_max8997.o
+obj-$(CONFIG_POWER_BD71837) += pmic_bd71837.o
 obj-$(CONFIG_POWER_PFUZE100) += pmic_pfuze100.o
 obj-$(CONFIG_POWER_PFUZE3000) += pmic_pfuze3000.o
 obj-$(CONFIG_POWER_TPS65217) += pmic_tps65217.o
diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
new file mode 100644
index 00..eadf373a18
--- /dev/null
+++ b/drivers/power/pmic/bd71837.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier:  GPL-2.0+
+//
+// Copyright 2018 NXP  *
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const struct pmic_child_info pmic_children_info[] = {
+   /* buck */
+   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   /* ldo */
+   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { },
+};
+
+static int bd71837_reg_count(struct udevice *dev)
+{
+   return BD71837_REG_NUM;
+}
+
+static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
+int len)
+{
+   if (dm_i2c_write(dev, reg, buff, len)) {
+   pr_err("write error to device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
+{
+   if (dm_i2c_read(dev, reg, buff, len)) {
+   pr_err("read error from device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_bind(struct udevice *dev)
+{
+   int children;
+   ofnode regulators_node;
+
+   regulators_node = dev_read_subnode(dev, "regulators");
+   if (!ofnode_valid(regulators_node)) {
+   debug("%s: %s regulators subnode not found!", __func__,
+ dev->name);
+   return -ENXIO;
+   }
+
+   debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
+
+   children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+   if (!children)
+   debug("%s: %s - no child found\n", __func__, dev->name);
+
+   /* Always return success for this device */
+   return 0;
+}
+
+static struct dm_pmic_ops bd71837_ops = {
+   .reg_count = bd71837_reg_count,
+   .read = bd71837_read,
+   .write = bd71837_write,
+};
+
+static const struct udevice_id bd71837_ids[] = {
+   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { }
+};
+
+U_BOOT_DRIVER(pmic_bd71837) = {
+   .name = "

[U-Boot] [PATCH v1 0/2] support for ROHM BD71827 and BD71847 PMICs

2019-04-08 Thread Matti Vaittinen
Patch series to support for ROHM BD71827 and BD71847 PMICs.

ROHM BD71837 and BD71847 is PMIC intended for powering single-core,
dual-core, and quad-core SoC’s such as NXP-i.MX 8M. BD71847 is used
for example on NXP imx8mm EVK.

Series adds PMIC driver with register read and write support, and
regulator driver with enable/disable and voltage changing support
with certain limitations:
- Enable/Disable state control is by default only allowed for BD71837
  bucks 3 and 4. This is due to a HW feature which leaves SW
  controlled power rails unpowered after reset which leads to SNVS
  state.
- Voltage control for enabled regulator is only allowed for "DVS"
  regulators (bucks 1-4 on BD71837, bucks 1 and 2 on BD71847). This
  is done because changing voltage on other regulators may cause
  under-/over shoot when regulator is enabled.

Drivers expect to see PMIC node with proper regulator sub-nodes given
from device tree but.

Driver is tested using BD71837 and BD71847 break-out board connected
to Beagle Bone Black and device-tree entry which was created as
desctibed in dt-binding document for BD718x7 shipped with Linux.

This patch series does not support DT properties which allow changing
the reset target between SNVS and READY or identifying boot-critical
regulators and disabling SW control based on reset target as the
Linux driver does.

Changelog v1:
- This version is created based on the RFC v1.
  https://lists.denx.de/pipermail/u-boot/2019-March/363076.html
  https://lists.denx.de/pipermail/u-boot/2019-March/363077.html
- Support BD71847.
- Unlock the PMIC protection register

Patch 1:
- Cherry picks the initial PMIC driver for BD71837 from NXP's i.MX
  repository at: https://source.codeaurora.org/external/imx/uboot-imx
  (commits e9a3bec2e95a and acdc5c297a96). Fixes checkpatch issues.

Patch 2:
- Support BD71847 PMIC.
- Add support for BD71837 and BD71847 regulators.

---

Matti Vaittinen (2):
  regulator: bd71837: copy the bd71837 pmic driver from NXP imx u-boot
  regulator: bd718x7: support ROHM BD71837 and BD71847 PMICs

 drivers/power/pmic/Kconfig|   7 +
 drivers/power/pmic/Makefile   |   2 +
 drivers/power/pmic/bd71837.c  | 121 
 drivers/power/pmic/pmic_bd71837.c |  31 ++
 drivers/power/regulator/Kconfig   |  15 +
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 457 ++
 include/power/bd71837.h   | 105 +++
 8 files changed, 739 insertions(+)
 create mode 100644 drivers/power/pmic/bd71837.c
 create mode 100644 drivers/power/pmic/pmic_bd71837.c
 create mode 100644 drivers/power/regulator/bd71837.c
 create mode 100644 include/power/bd71837.h

-- 
2.17.2


-- 
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 ~~~
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [RFC PATCH v1 2/2] power: regulator: support ROHM BD71837 PMIC

2019-04-04 Thread Matti Vaittinen
Hi de Ho Peeps,

On Wed, Mar 27, 2019 at 02:40:47PM +0200, Matti Vaittinen wrote:
> Add regulator driver for ROHM BD71837 PMIC. BD71837 contains
> 8 bucks and 7 LDOS. Voltages for bucks 1-4 can be adjusted
> when regulators are enabled. For other bucks and LDOs we may
> have over- or undershooting if voltage is adjusted when
> regulator is enabled. Thus this is prevented by default.
> 
> BD71837 has a quirk which may leave power output disabled
> after reset if enable/disable state was controlled by SW.
> Thus the SW control is only allowed for bucks3 and 4 by
> default.
> 
> Signed-off-by: Matti Vaittinen 
> ---
>  drivers/power/regulator/Kconfig   |  15 ++
>  drivers/power/regulator/Makefile  |   1 +
>  drivers/power/regulator/bd71837.c | 373 ++
>  include/power/bd71837.h   |  20 ++
>  4 files changed, 409 insertions(+)
>

This Patch:

This was my first patch to U-boot so I wonder if there is something to
improve. Is this Ok like this or should I have formatted it somehow
differently?

Also, is this type of submissions welcome? Any place to check if
submissions are rejected, being reviewed or forgotten?


Next Steps:

Finally, the BD71837 is mainly targeted for powering the i.MX8M. There's
another ROHM PMIC BD71847 - which is mainly used for powering the
i.MX8MM. The Linux driver I wrote does support both of these PMICs and I
was thinking that maybe I should add support for BD71847 in this u-Boot
driver too. But before investing on that work I would like to get some
feedback regarding the BD71837 u-boot driver. At least a sign that this
kind of submissions are welcome or information if I am doing something
completely wrong =)


About RFC tag:

I used RFC tag here mainly because I am unsure if the driver design fits
what the u-boot is heading on or if this is kind of driver u-Boot should
include. Is this correct use of RFC, and what are the consequences of
using RFC-tag? My assumption was that the patch with RFC is reviewed as
ither patches, but it is also a sign that the patch might have something
that makes it unsuitable for applying to u-Boot. Is this correct?

Finally, I guess I need to (re)submit the driver(s) without the RFC tag
at some point, any suggestions when?


Best Regards
Matti Vaittinen
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [RFC PATCH v1 2/2] power: regulator: support ROHM BD71837 PMIC

2019-03-27 Thread Matti Vaittinen
Add regulator driver for ROHM BD71837 PMIC. BD71837 contains
8 bucks and 7 LDOS. Voltages for bucks 1-4 can be adjusted
when regulators are enabled. For other bucks and LDOs we may
have over- or undershooting if voltage is adjusted when
regulator is enabled. Thus this is prevented by default.

BD71837 has a quirk which may leave power output disabled
after reset if enable/disable state was controlled by SW.
Thus the SW control is only allowed for bucks3 and 4 by
default.

Signed-off-by: Matti Vaittinen 
---
 drivers/power/regulator/Kconfig   |  15 ++
 drivers/power/regulator/Makefile  |   1 +
 drivers/power/regulator/bd71837.c | 373 ++
 include/power/bd71837.h   |  20 ++
 4 files changed, 409 insertions(+)

diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 3ed0dd2264..323516587c 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -43,6 +43,21 @@ config REGULATOR_AS3722
  but does not yet support change voltages. Currently this must be
  done using direct register writes to the PMIC.
 
+config DM_REGULATOR_BD71837
+   bool "Enable Driver Model for REGULATOR BD71837"
+   depends on DM_REGULATOR && DM_PMIC_BD71837
+   help
+   This config enables implementation of driver-model regulator uclass
+   features for REGULATOR BD71837. The driver implements get/set api for:
+   value and enable.
+
+config SPL_DM_REGULATOR_BD71837
+   bool "Enable Driver Model for REGULATOR BD71837 in SPL"
+   depends on DM_REGULATOR_BD71837
+   help
+   This config enables implementation of driver-model regulator uclass
+   features for REGULATOR BD71837 in SPL.
+
 config DM_REGULATOR_PFUZE100
bool "Enable Driver Model for REGULATOR PFUZE100"
depends on DM_REGULATOR && DM_PMIC_PFUZE100
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile
index f617ce723a..898ed5f084 100644
--- a/drivers/power/regulator/Makefile
+++ b/drivers/power/regulator/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o
 obj-$(CONFIG_REGULATOR_AS3722) += as3722_regulator.o
 obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
+obj-$(CONFIG_$(SPL_)DM_REGULATOR_BD71837) += bd71837.o
 obj-$(CONFIG_$(SPL_)REGULATOR_PWM) += pwm_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_FAN53555) += fan53555.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_FIXED) += fixed.o
diff --git a/drivers/power/regulator/bd71837.c 
b/drivers/power/regulator/bd71837.c
new file mode 100644
index 00..5b32425ba9
--- /dev/null
+++ b/drivers/power/regulator/bd71837.c
@@ -0,0 +1,373 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+//
+// Copyright (C) 2019 ROHM Semiconductors
+//
+// ROHM BD71837 regulator driver
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define HW_STATE_CONTROL 0
+
+struct bd71837_vrange {
+   unsigned intmin_volt;
+   unsigned intstep;
+   u8  min_sel;
+   u8  max_sel;
+   u8  rangeval;
+};
+
+struct bd71837_data {
+   const char  *name;
+   u8  enable_reg;
+   u8  enablemask;
+   u8  volt_reg;
+   u8  volt_mask;
+   struct bd71837_vrange   *ranges;
+   unsigned intnumranges;
+   u8  rangemask;
+   u8  sel_mask;
+   booldvs;
+};
+
+#define BD_RANGE(_min, _vstep, _sel_low, _sel_hi, _range_sel) \
+{ \
+   .min_volt = (_min), .step = (_vstep), .min_sel = (_sel_low), \
+   .max_sel = (_sel_hi), .rangeval = (_range_sel) \
+}
+
+#define BD_DATA(_name, enreg, enmask, vreg, vmask, _range, rmask, _dvs, sel) \
+{ \
+   .name = (_name), .enable_reg = (enreg), .enablemask = (enmask), \
+   .volt_reg = (vreg), .volt_mask = (vmask), .ranges = (_range), \
+   .numranges = ARRAY_SIZE(_range), .rangemask = (rmask), .dvs = (_dvs), \
+   .sel_mask = (sel) \
+}
+
+static struct bd71837_vrange buck1to4_vranges[] = {
+   BD_RANGE(70, 1, 0, 0x3C, 0),
+   BD_RANGE(130, 0, 0x3D, 0x3F, 0),
+};
+
+static struct bd71837_vrange buck5_vranges[] = {
+   BD_RANGE(70, 10, 0, 0x3, 0),
+   BD_RANGE(105, 5, 0x04, 0x05, 0),
+   BD_RANGE(120, 15, 0x06, 0x07, 0),
+   BD_RANGE(675000, 10, 0x0, 0x3, 0x80),
+   BD_RANGE(1025000, 5, 0x04, 0x05, 0x80),
+   BD_RANGE(1175000, 15, 0x06, 0x07, 0x80),
+};
+
+static struct bd71837_vrange buck6_vranges[] = {
+   BD_RANGE(300, 10, 0x00, 0x03, 0),
+};
+
+static struct bd71837_vrange buck7_vranges[] = {
+   BD_RANGE(1605000, 9, 0, 1, 0),
+   BD_RANGE(1755000, 45000, 2, 4, 0),
+   BD_RANGE(1905000, 45000, 5, 7, 0),
+};

[U-Boot] [RFC PATCH v1 1/2] copy the bd71837 pmic driver from NXP imx u-boot

2019-03-27 Thread Matti Vaittinen
Add initial support for ROHM BD71837 PMIC

https://source.codeaurora.org/external/imx/uboot-imx

cherry picked, styled and merged commits:
- MLK-18387 pmic: Add pmic driver for BD71837: e9a3bec2e95a
- MLK-18590 pmic: bd71837: Change to use new fdt API: acdc5c297a96

Signed-off-by: Ye Li 
Signed-off-by: Matti Vaittinen 
---
 drivers/power/pmic/Kconfig|  7 +++
 drivers/power/pmic/Makefile   |  2 +
 drivers/power/pmic/bd71837.c  | 89 +++
 drivers/power/pmic/pmic_bd71837.c | 31 +++
 include/power/bd71837.h   | 64 ++
 5 files changed, 193 insertions(+)

diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 8cf60ebcf3..e154d0a57b 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -48,6 +48,13 @@ config PMIC_AS3722
  interface and is designs to cover most of the power managementment
  required for a tablets or laptop.
 
+config DM_PMIC_BD71837
+   bool "Enable Driver Model for PMIC BD71837"
+   depends on DM_PMIC
+   help
+ This config enables implementation of driver-model pmic uclass 
features
+ for PMIC BD71837. The driver implements read/write operations.
+
 config DM_PMIC_FAN53555
bool "Enable support for OnSemi FAN53555"
depends on DM_PMIC && DM_REGULATOR && DM_I2C
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 637352ab2b..e74c6190a8 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_BD71837) += bd71837.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o
 obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
@@ -30,6 +31,7 @@ obj-$(CONFIG_POWER_MAX77696) += pmic_max77696.o
 obj-$(CONFIG_POWER_MAX8998) += pmic_max8998.o
 obj-$(CONFIG_POWER_MAX8997) += pmic_max8997.o
 obj-$(CONFIG_POWER_MUIC_MAX8997) += muic_max8997.o
+obj-$(CONFIG_POWER_BD71837) += pmic_bd71837.o
 obj-$(CONFIG_POWER_PFUZE100) += pmic_pfuze100.o
 obj-$(CONFIG_POWER_PFUZE3000) += pmic_pfuze3000.o
 obj-$(CONFIG_POWER_TPS65217) += pmic_tps65217.o
diff --git a/drivers/power/pmic/bd71837.c b/drivers/power/pmic/bd71837.c
new file mode 100644
index 00..eadf373a18
--- /dev/null
+++ b/drivers/power/pmic/bd71837.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier:  GPL-2.0+
+//
+// Copyright 2018 NXP  *
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const struct pmic_child_info pmic_children_info[] = {
+   /* buck */
+   { .prefix = "b", .driver = BD71837_REGULATOR_DRIVER},
+   /* ldo */
+   { .prefix = "l", .driver = BD71837_REGULATOR_DRIVER},
+   { },
+};
+
+static int bd71837_reg_count(struct udevice *dev)
+{
+   return BD71837_REG_NUM;
+}
+
+static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
+int len)
+{
+   if (dm_i2c_write(dev, reg, buff, len)) {
+   pr_err("write error to device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
+{
+   if (dm_i2c_read(dev, reg, buff, len)) {
+   pr_err("read error from device: %p register: %#x!", dev, reg);
+   return -EIO;
+   }
+
+   return 0;
+}
+
+static int bd71837_bind(struct udevice *dev)
+{
+   int children;
+   ofnode regulators_node;
+
+   regulators_node = dev_read_subnode(dev, "regulators");
+   if (!ofnode_valid(regulators_node)) {
+   debug("%s: %s regulators subnode not found!", __func__,
+ dev->name);
+   return -ENXIO;
+   }
+
+   debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
+
+   children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+   if (!children)
+   debug("%s: %s - no child found\n", __func__, dev->name);
+
+   /* Always return success for this device */
+   return 0;
+}
+
+static struct dm_pmic_ops bd71837_ops = {
+   .reg_count = bd71837_reg_count,
+   .read = bd71837_read,
+   .write = bd71837_write,
+};
+
+static const struct udevice_id bd71837_ids[] = {
+   { .compatible = "rohm,bd71837", .data = 0x4b, },
+   { }
+};
+
+U_BOOT_DRIVER(pmic_bd71837) = {
+   .name = "bd71837 pmic",
+   .id = UCLASS_PMIC,
+   .of_match = bd71837_ids,
+   .bind = bd71837_bind,
+   .ops = _ops,
+};
diff --git a/drivers/power/pmic/pmic_bd71837.c 
b/