1 // SPDX-License-Identifier: GPL-2.0+
11 #include <power/pmic.h>
12 #include <power/regulator.h>
13 #include <power/bd71837.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "b", .driver = BD718XX_REGULATOR_DRIVER},
21 { .prefix = "l", .driver = BD718XX_REGULATOR_DRIVER},
25 static int bd71837_reg_count(struct udevice *dev)
27 return BD718XX_MAX_REGISTER - 1;
30 static int bd71837_write(struct udevice *dev, uint reg, const uint8_t *buff,
33 if (dm_i2c_write(dev, reg, buff, len)) {
34 pr_err("write error to device: %p register: %#x!", dev, reg);
41 static int bd71837_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
43 if (dm_i2c_read(dev, reg, buff, len)) {
44 pr_err("read error from device: %p register: %#x!", dev, reg);
51 static int bd71837_bind(struct udevice *dev)
54 ofnode regulators_node;
56 regulators_node = dev_read_subnode(dev, "regulators");
57 if (!ofnode_valid(regulators_node)) {
58 debug("%s: %s regulators subnode not found!\n", __func__,
63 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
65 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
67 debug("%s: %s - no child found\n", __func__, dev->name);
69 /* Always return success for this device */
73 static int bd718x7_probe(struct udevice *dev)
76 uint8_t mask = BD718XX_REGLOCK_PWRSEQ | BD718XX_REGLOCK_VREG;
78 /* Unlock the PMIC regulator control before probing the children */
79 ret = pmic_clrsetbits(dev, BD718XX_REGLOCK, mask, 0);
81 debug("%s: %s Failed to unlock regulator control\n", __func__,
85 debug("%s: '%s' - BD718x7 PMIC registers unlocked\n", __func__,
91 static struct dm_pmic_ops bd71837_ops = {
92 .reg_count = bd71837_reg_count,
94 .write = bd71837_write,
97 static const struct udevice_id bd71837_ids[] = {
98 { .compatible = "rohm,bd71837", .data = ROHM_CHIP_TYPE_BD71837, },
99 { .compatible = "rohm,bd71847", .data = ROHM_CHIP_TYPE_BD71847, },
103 U_BOOT_DRIVER(pmic_bd71837) = {
104 .name = "bd71837 pmic",
106 .of_match = bd71837_ids,
107 .bind = bd71837_bind,
108 .probe = bd718x7_probe,