]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
ca1de0b5 K |
2 | /* |
3 | * (C) Copyright 2016 Texas Instruments Incorporated, <www.ti.com> | |
4 | * Keerthy <j-keerthy@ti.com> | |
ca1de0b5 K |
5 | */ |
6 | ||
d678a59d | 7 | #include <common.h> |
ca1de0b5 K |
8 | #include <fdtdec.h> |
9 | #include <errno.h> | |
10 | #include <dm.h> | |
11 | #include <i2c.h> | |
f7ae49fc | 12 | #include <log.h> |
1e94b46f | 13 | #include <linux/printk.h> |
ca1de0b5 K |
14 | #include <power/pmic.h> |
15 | #include <power/regulator.h> | |
16 | #include <power/lp873x.h> | |
17 | #include <dm/device.h> | |
18 | ||
ca1de0b5 K |
19 | static const struct pmic_child_info pmic_children_info[] = { |
20 | { .prefix = "ldo", .driver = LP873X_LDO_DRIVER }, | |
21 | { .prefix = "buck", .driver = LP873X_BUCK_DRIVER }, | |
22 | { }, | |
23 | }; | |
24 | ||
25 | static int lp873x_write(struct udevice *dev, uint reg, const uint8_t *buff, | |
26 | int len) | |
27 | { | |
28 | if (dm_i2c_write(dev, reg, buff, len)) { | |
c83c436d | 29 | pr_err("write error to device: %p register: %#x!\n", dev, reg); |
ca1de0b5 K |
30 | return -EIO; |
31 | } | |
32 | ||
33 | return 0; | |
34 | } | |
35 | ||
36 | static int lp873x_read(struct udevice *dev, uint reg, uint8_t *buff, int len) | |
37 | { | |
38 | if (dm_i2c_read(dev, reg, buff, len)) { | |
c83c436d | 39 | pr_err("read error from device: %p register: %#x!\n", dev, reg); |
ca1de0b5 K |
40 | return -EIO; |
41 | } | |
42 | ||
43 | return 0; | |
44 | } | |
45 | ||
46 | static int lp873x_bind(struct udevice *dev) | |
47 | { | |
7a869e6c | 48 | ofnode regulators_node; |
ca1de0b5 | 49 | int children; |
ca1de0b5 | 50 | |
7a869e6c SG |
51 | regulators_node = dev_read_subnode(dev, "regulators"); |
52 | if (!ofnode_valid(regulators_node)) { | |
c83c436d | 53 | debug("%s: %s regulators subnode not found!\n", __func__, |
7a869e6c | 54 | dev->name); |
ca1de0b5 K |
55 | return -ENXIO; |
56 | } | |
57 | ||
58 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); | |
59 | if (!children) | |
60 | printf("%s: %s - no child found\n", __func__, dev->name); | |
61 | ||
62 | /* Always return success for this device */ | |
63 | return 0; | |
64 | } | |
65 | ||
66 | static struct dm_pmic_ops lp873x_ops = { | |
67 | .read = lp873x_read, | |
68 | .write = lp873x_write, | |
69 | }; | |
70 | ||
71 | static const struct udevice_id lp873x_ids[] = { | |
72 | { .compatible = "ti,lp8732", .data = LP8732 }, | |
73 | { .compatible = "ti,lp8733" , .data = LP8733 }, | |
74 | { } | |
75 | }; | |
76 | ||
77 | U_BOOT_DRIVER(pmic_lp873x) = { | |
78 | .name = "lp873x_pmic", | |
79 | .id = UCLASS_PMIC, | |
80 | .of_match = lp873x_ids, | |
81 | .bind = lp873x_bind, | |
82 | .ops = &lp873x_ops, | |
83 | }; |