]>
Commit | Line | Data |
---|---|---|
2a4febfd SG |
1 | /* |
2 | * Copyright (C) 2015 Google, Inc | |
3 | * Written by Simon Glass <[email protected]> | |
4 | * | |
5 | * SPDX-License-Identifier: GPL-2.0+ | |
6 | */ | |
7 | ||
8 | #include <common.h> | |
9 | #include <dm.h> | |
10 | #include <errno.h> | |
11 | #include <fdtdec.h> | |
12 | #include <libfdt.h> | |
453c5a92 | 13 | #include <power/rk8xx_pmic.h> |
2a4febfd SG |
14 | #include <power/pmic.h> |
15 | ||
16 | DECLARE_GLOBAL_DATA_PTR; | |
17 | ||
18 | static const struct pmic_child_info pmic_children_info[] = { | |
453c5a92 JC |
19 | { .prefix = "DCDC_REG", .driver = "rk8xx_buck"}, |
20 | { .prefix = "LDO_REG", .driver = "rk8xx_ldo"}, | |
21 | { .prefix = "SWITCH_REG", .driver = "rk8xx_switch"}, | |
2a4febfd SG |
22 | { }, |
23 | }; | |
24 | ||
453c5a92 | 25 | static int rk8xx_reg_count(struct udevice *dev) |
2a4febfd SG |
26 | { |
27 | return RK808_NUM_OF_REGS; | |
28 | } | |
29 | ||
453c5a92 | 30 | static int rk8xx_write(struct udevice *dev, uint reg, const uint8_t *buff, |
2a4febfd SG |
31 | int len) |
32 | { | |
7d577999 SG |
33 | int ret; |
34 | ||
35 | ret = dm_i2c_write(dev, reg, buff, len); | |
36 | if (ret) { | |
2a4febfd | 37 | debug("write error to device: %p register: %#x!", dev, reg); |
7d577999 | 38 | return ret; |
2a4febfd SG |
39 | } |
40 | ||
41 | return 0; | |
42 | } | |
43 | ||
453c5a92 | 44 | static int rk8xx_read(struct udevice *dev, uint reg, uint8_t *buff, int len) |
2a4febfd | 45 | { |
7d577999 SG |
46 | int ret; |
47 | ||
48 | ret = dm_i2c_read(dev, reg, buff, len); | |
49 | if (ret) { | |
2a4febfd | 50 | debug("read error from device: %p register: %#x!", dev, reg); |
7d577999 | 51 | return ret; |
2a4febfd SG |
52 | } |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | #if CONFIG_IS_ENABLED(PMIC_CHILDREN) | |
453c5a92 | 58 | static int rk8xx_bind(struct udevice *dev) |
2a4febfd | 59 | { |
7a869e6c | 60 | ofnode regulators_node; |
2a4febfd SG |
61 | int children; |
62 | ||
7a869e6c SG |
63 | regulators_node = dev_read_subnode(dev, "regulators"); |
64 | if (!ofnode_valid(regulators_node)) { | |
2a4febfd SG |
65 | debug("%s: %s regulators subnode not found!", __func__, |
66 | dev->name); | |
67 | return -ENXIO; | |
68 | } | |
69 | ||
70 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); | |
71 | ||
72 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); | |
73 | if (!children) | |
74 | debug("%s: %s - no child found\n", __func__, dev->name); | |
75 | ||
76 | /* Always return success for this device */ | |
77 | return 0; | |
78 | } | |
79 | #endif | |
80 | ||
453c5a92 | 81 | static int rk8xx_probe(struct udevice *dev) |
d77af8a8 | 82 | { |
453c5a92 | 83 | struct rk8xx_priv *priv = dev_get_priv(dev); |
d77af8a8 JC |
84 | uint8_t msb, lsb; |
85 | ||
86 | /* read Chip variant */ | |
453c5a92 JC |
87 | rk8xx_read(dev, ID_MSB, &msb, 1); |
88 | rk8xx_read(dev, ID_LSB, &lsb, 1); | |
d77af8a8 JC |
89 | |
90 | priv->variant = ((msb << 8) | lsb) & RK8XX_ID_MSK; | |
91 | ||
92 | return 0; | |
93 | } | |
94 | ||
453c5a92 JC |
95 | static struct dm_pmic_ops rk8xx_ops = { |
96 | .reg_count = rk8xx_reg_count, | |
97 | .read = rk8xx_read, | |
98 | .write = rk8xx_write, | |
2a4febfd SG |
99 | }; |
100 | ||
453c5a92 | 101 | static const struct udevice_id rk8xx_ids[] = { |
2a4febfd | 102 | { .compatible = "rockchip,rk808" }, |
d77af8a8 | 103 | { .compatible = "rockchip,rk818" }, |
2a4febfd SG |
104 | { } |
105 | }; | |
106 | ||
453c5a92 JC |
107 | U_BOOT_DRIVER(pmic_rk8xx) = { |
108 | .name = "rk8xx pmic", | |
2a4febfd | 109 | .id = UCLASS_PMIC, |
453c5a92 | 110 | .of_match = rk8xx_ids, |
2a4febfd | 111 | #if CONFIG_IS_ENABLED(PMIC_CHILDREN) |
453c5a92 | 112 | .bind = rk8xx_bind, |
2a4febfd | 113 | #endif |
453c5a92 JC |
114 | .probe = rk8xx_probe, |
115 | .ops = &rk8xx_ops, | |
2a4febfd | 116 | }; |