1 // SPDX-License-Identifier: GPL-2.0+
11 #include <asm/global_data.h>
12 #include <power/pmic.h>
13 #include <power/regulator.h>
14 #include <power/bd71837.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 static const struct pmic_child_info pmic_children_info[] = {
20 { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
22 { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
26 static int bd71837_reg_count(struct udevice *dev)
28 return BD718XX_MAX_REGISTER - 1;
31 static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
34 if (dm_i2c_write(dev, reg, buff, len)) {
35 pr_err("write error to device: %p register: %#x!", dev, reg);
42 static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
44 if (dm_i2c_read(dev, reg, buff, len)) {
45 pr_err("read error from device: %p register: %#x!", dev, reg);
52 static int bd71837_bind(struct udevice *dev)
55 ofnode regulators_node;
57 regulators_node = dev_read_subnode(dev, "regulators");
58 if (!ofnode_valid(regulators_node)) {
59 debug("%s: %s regulators subnode not found!\n", __func__,
64 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
66 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
68 debug("%s: %s - no child found\n", __func__, dev->name);
70 /* Always return success for this device */
74 static int bd718x7_probe(struct udevice *dev)
77 uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG;
79 /* Unlock the PMIC regulator control before probing the children */
80 ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0);
82 debug("%s: %s Failed to unlock regulator control\n", __func__,
86 debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__,
92 static struct dm_pmic_ops bd71837_ops = {
93 .reg_count = bd71837_reg_count,
95 .write = bd71837_write,
98 static const struct udevice_id bd71837_ids[] = {
99 { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
100 { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
104 U_BOOT_DRIVER(pmic_bd71837) = {
105 .name = "bd71837 pmic",
107 .of_match = bd71837_ids,
108 .bind = bd71837_bind,
109 .probe = bd718x7_probe,