]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
33621d24 K |
2 | /* |
3 | * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com> | |
4 | * Keerthy <j-keerthy@ti.com> | |
33621d24 K |
5 | */ |
6 | ||
7 | #include <common.h> | |
8 | #include <fdtdec.h> | |
9 | #include <errno.h> | |
10 | #include <dm.h> | |
11 | #include <i2c.h> | |
12 | #include <power/pmic.h> | |
13 | #include <power/regulator.h> | |
14 | #include <power/palmas.h> | |
15 | #include <dm/device.h> | |
16 | ||
33621d24 K |
17 | static const struct pmic_child_info pmic_children_info[] = { |
18 | { .prefix = "ldo", .driver = PALMAS_LDO_DRIVER }, | |
19 | { .prefix = "smps", .driver = PALMAS_SMPS_DRIVER }, | |
20 | { }, | |
21 | }; | |
22 | ||
23 | static int palmas_write(struct udevice *dev, uint reg, const uint8_t *buff, | |
24 | int len) | |
25 | { | |
26 | if (dm_i2c_write(dev, reg, buff, len)) { | |
9b643e31 | 27 | pr_err("write error to device: %p register: %#x!", dev, reg); |
33621d24 K |
28 | return -EIO; |
29 | } | |
30 | ||
31 | return 0; | |
32 | } | |
33 | ||
34 | static int palmas_read(struct udevice *dev, uint reg, uint8_t *buff, int len) | |
35 | { | |
36 | if (dm_i2c_read(dev, reg, buff, len)) { | |
9b643e31 | 37 | pr_err("read error from device: %p register: %#x!", dev, reg); |
33621d24 K |
38 | return -EIO; |
39 | } | |
40 | ||
41 | return 0; | |
42 | } | |
43 | ||
44 | static int palmas_bind(struct udevice *dev) | |
45 | { | |
7a869e6c SG |
46 | ofnode pmic_node = ofnode_null(), regulators_node; |
47 | ofnode subnode; | |
33621d24 | 48 | int children; |
33621d24 | 49 | |
7a869e6c | 50 | dev_for_each_subnode(subnode, dev) { |
33621d24 K |
51 | const char *name; |
52 | char *temp; | |
53 | ||
7a869e6c | 54 | name = ofnode_get_name(subnode); |
33621d24 K |
55 | temp = strstr(name, "pmic"); |
56 | if (temp) { | |
57 | pmic_node = subnode; | |
58 | break; | |
59 | } | |
60 | } | |
61 | ||
7a869e6c | 62 | if (!ofnode_valid(pmic_node)) { |
33621d24 K |
63 | debug("%s: %s pmic subnode not found!", __func__, dev->name); |
64 | return -ENXIO; | |
65 | } | |
66 | ||
7a869e6c | 67 | regulators_node = ofnode_find_subnode(pmic_node, "regulators"); |
33621d24 | 68 | |
7a869e6c | 69 | if (!ofnode_valid(regulators_node)) { |
33621d24 K |
70 | debug("%s: %s reg subnode not found!", __func__, dev->name); |
71 | return -ENXIO; | |
72 | } | |
73 | ||
74 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); | |
75 | if (!children) | |
76 | debug("%s: %s - no child found\n", __func__, dev->name); | |
77 | ||
78 | /* Always return success for this device */ | |
79 | return 0; | |
80 | } | |
81 | ||
82 | static struct dm_pmic_ops palmas_ops = { | |
83 | .read = palmas_read, | |
84 | .write = palmas_write, | |
85 | }; | |
86 | ||
87 | static const struct udevice_id palmas_ids[] = { | |
88 | { .compatible = "ti,tps659038", .data = TPS659038 }, | |
89 | { .compatible = "ti,tps65917" , .data = TPS65917 }, | |
90 | { } | |
91 | }; | |
92 | ||
93 | U_BOOT_DRIVER(pmic_palmas) = { | |
94 | .name = "palmas_pmic", | |
95 | .id = UCLASS_PMIC, | |
96 | .of_match = palmas_ids, | |
97 | .bind = palmas_bind, | |
98 | .ops = &palmas_ops, | |
99 | }; |