1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
10 #include <power/rk8xx_pmic.h>
11 #include <power/pmic.h>
13 static const struct pmic_child_info pmic_children_info[] = {
14 { .prefix = "DCDC_REG", .driver = "rk8xx_buck"},
15 { .prefix = "LDO_REG", .driver = "rk8xx_ldo"},
16 { .prefix = "SWITCH_REG", .driver = "rk8xx_switch"},
20 static int rk8xx_reg_count(struct udevice *dev)
22 return RK808_NUM_OF_REGS;
25 static int rk8xx_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 ret = dm_i2c_write(dev, reg, buff, len);
32 debug("write error to device: %p register: %#x!\n", dev, reg);
39 static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
43 ret = dm_i2c_read(dev, reg, buff, len);
45 debug("read error from device: %p register: %#x!\n", dev, reg);
52 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
53 static int rk8xx_bind(struct udevice *dev)
55 ofnode regulators_node;
58 regulators_node = dev_read_subnode(dev, "regulators");
59 if (!ofnode_valid(regulators_node)) {
60 debug("%s: %s regulators subnode not found!\n", __func__,
65 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
67 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
69 debug("%s: %s - no child found\n", __func__, dev->name);
71 /* Always return success for this device */
76 static int rk8xx_probe(struct udevice *dev)
78 struct rk8xx_priv *priv = dev_get_priv(dev);
81 /* read Chip variant */
82 rk8xx_read(dev, ID_MSB, &msb, 1);
83 rk8xx_read(dev, ID_LSB, &lsb, 1);
85 priv->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK;
90 static struct dm_pmic_ops rk8xx_ops = {
91 .reg_count = rk8xx_reg_count,
96 static const struct udevice_id rk8xx_ids[] = {
97 { .compatible = "rockchip,rk808" },
98 { .compatible = "rockchip,rk816" },
99 { .compatible = "rockchip,rk818" },
103 U_BOOT_DRIVER(pmic_rk8xx) = {
104 .name = "rk8xx pmic",
106 .of_match = rk8xx_ids,
107 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
110 .priv_auto_alloc_size = sizeof(struct rk8xx_priv),
111 .probe = rk8xx_probe,