1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Flowbird
4 * Martin Fuzzey <martin.fuzzey@flowbird.group>
12 #include <power/pmic.h>
13 #include <power/regulator.h>
14 #include <power/da9063_pmic.h>
16 static const struct pmic_child_info pmic_children_info[] = {
17 { .prefix = "ldo", .driver = DA9063_LDO_DRIVER },
18 { .prefix = "b", .driver = DA9063_BUCK_DRIVER },
23 * The register map is non contiguous and attempts to read in the holes fail.
24 * But "pmic dump" tries to dump the full register map.
25 * So define the holes here so we can fix that.
27 struct da9063_reg_hole {
32 static const struct da9063_reg_hole da9063_reg_holes[] = {
36 /* These aren't readable. I can't see why from the datasheet but
37 * attempts to read fail and the kernel marks them unreadable too,
39 {DA9063_REG_OTP_COUNT, DA9063_REG_OTP_DATA},
42 static int da9063_reg_count(struct udevice *dev)
44 return DA9063_NUM_OF_REGS;
47 static bool da9063_reg_valid(uint reg)
51 for (i = 0; i < ARRAY_SIZE(da9063_reg_holes); i++) {
52 const struct da9063_reg_hole *hole = &da9063_reg_holes[i];
54 if (reg >= hole->first && reg <= hole->last)
61 static int da9063_write(struct udevice *dev, uint reg, const uint8_t *buff,
64 if (dm_i2c_write(dev, reg, buff, len)) {
65 pr_err("write error to device: %p register: %#x!", dev, reg);
72 static int da9063_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
74 if (!da9063_reg_valid(reg))
77 if (dm_i2c_read(dev, reg, buff, len)) {
78 pr_err("read error from device: %p register: %#x!", dev, reg);
85 static int da9063_bind(struct udevice *dev)
87 ofnode regulators_node;
90 regulators_node = dev_read_subnode(dev, "regulators");
91 if (!ofnode_valid(regulators_node)) {
92 debug("%s: %s regulators subnode not found!", __func__,
97 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
99 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
101 debug("%s: %s - no child found\n", __func__, dev->name);
103 /* Always return success for this device */
107 static int da9063_probe(struct udevice *dev)
109 return i2c_set_chip_addr_offset_mask(dev, 0x1);
112 static struct dm_pmic_ops da9063_ops = {
113 .reg_count = da9063_reg_count,
115 .write = da9063_write,
118 static const struct udevice_id da9063_ids[] = {
119 { .compatible = "dlg,da9063" },
123 U_BOOT_DRIVER(pmic_da9063) = {
124 .name = "da9063_pmic",
126 .of_match = da9063_ids,
128 .probe = da9063_probe,