1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Flowbird
13 #include <linux/printk.h>
14 #include <power/pmic.h>
15 #include <power/regulator.h>
16 #include <power/da9063_pmic.h>
18 static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "ldo", .driver = DA9063_LDO_DRIVER },
20 { .prefix = "b", .driver = DA9063_BUCK_DRIVER },
25 * The register map is non contiguous and attempts to read in the holes fail.
26 * But "pmic dump" tries to dump the full register map.
27 * So define the holes here so we can fix that.
29 struct da9063_reg_hole {
34 static const struct da9063_reg_hole da9063_reg_holes[] = {
38 /* These aren't readable. I can't see why from the datasheet but
39 * attempts to read fail and the kernel marks them unreadable too,
41 {DA9063_REG_OTP_COUNT, DA9063_REG_OTP_DATA},
44 static int da9063_reg_count(struct udevice *dev)
46 return DA9063_NUM_OF_REGS;
49 static bool da9063_reg_valid(uint reg)
53 for (i = 0; i < ARRAY_SIZE(da9063_reg_holes); i++) {
54 const struct da9063_reg_hole *hole = &da9063_reg_holes[i];
56 if (reg >= hole->first && reg <= hole->last)
63 static int da9063_write(struct udevice *dev, uint reg, const uint8_t *buff,
66 if (dm_i2c_write(dev, reg, buff, len)) {
67 pr_err("write error to device: %p register: %#x!", dev, reg);
74 static int da9063_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
76 if (!da9063_reg_valid(reg))
79 if (dm_i2c_read(dev, reg, buff, len)) {
80 pr_err("read error from device: %p register: %#x!", dev, reg);
87 static int da9063_bind(struct udevice *dev)
89 ofnode regulators_node;
92 regulators_node = dev_read_subnode(dev, "regulators");
93 if (!ofnode_valid(regulators_node)) {
94 debug("%s: %s regulators subnode not found!", __func__,
99 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
101 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
103 debug("%s: %s - no child found\n", __func__, dev->name);
105 /* Always return success for this device */
109 static int da9063_probe(struct udevice *dev)
111 return i2c_set_chip_addr_offset_mask(dev, 0x1);
114 static struct dm_pmic_ops da9063_ops = {
115 .reg_count = da9063_reg_count,
117 .write = da9063_write,
120 static const struct udevice_id da9063_ids[] = {
121 { .compatible = "dlg,da9063" },
125 U_BOOT_DRIVER(pmic_da9063) = {
126 .name = "da9063_pmic",
128 .of_match = da9063_ids,
130 .probe = da9063_probe,