diff options
Diffstat (limited to 'drivers/power/pmic/lp87565.c')
-rw-r--r-- | drivers/power/pmic/lp87565.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/drivers/power/pmic/lp87565.c b/drivers/power/pmic/lp87565.c new file mode 100644 index 0000000000..a5f29d7760 --- /dev/null +++ b/drivers/power/pmic/lp87565.c | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | * (C) Copyright 2017 Texas Instruments Incorporated, <www.ti.com> | ||
3 | * Keerthy <j-keerthy@ti.com> | ||
4 | * | ||
5 | * SPDX-License-Identifier: GPL-2.0+ | ||
6 | */ | ||
7 | |||
8 | #include <common.h> | ||
9 | #include <fdtdec.h> | ||
10 | #include <errno.h> | ||
11 | #include <dm.h> | ||
12 | #include <i2c.h> | ||
13 | #include <power/pmic.h> | ||
14 | #include <power/regulator.h> | ||
15 | #include <power/lp87565.h> | ||
16 | #include <dm/device.h> | ||
17 | |||
18 | DECLARE_GLOBAL_DATA_PTR; | ||
19 | |||
20 | static const struct pmic_child_info pmic_children_info[] = { | ||
21 | { .prefix = "buck", .driver = LP87565_BUCK_DRIVER }, | ||
22 | { }, | ||
23 | }; | ||
24 | |||
25 | static int lp87565_write(struct udevice *dev, uint reg, const uint8_t *buff, | ||
26 | int len) | ||
27 | { | ||
28 | int ret; | ||
29 | |||
30 | ret = dm_i2c_write(dev, reg, buff, len); | ||
31 | if (ret) | ||
32 | error("write error to device: %p register: %#x!", dev, reg); | ||
33 | |||
34 | return ret; | ||
35 | } | ||
36 | |||
37 | static int lp87565_read(struct udevice *dev, uint reg, uint8_t *buff, int len) | ||
38 | { | ||
39 | int ret; | ||
40 | |||
41 | ret = dm_i2c_read(dev, reg, buff, len); | ||
42 | if (ret) | ||
43 | error("read error from device: %p register: %#x!", dev, reg); | ||
44 | |||
45 | return ret; | ||
46 | } | ||
47 | |||
48 | static int lp87565_bind(struct udevice *dev) | ||
49 | { | ||
50 | int regulators_node; | ||
51 | const void *blob = gd->fdt_blob; | ||
52 | int children; | ||
53 | int node = dev->of_offset; | ||
54 | |||
55 | regulators_node = fdt_subnode_offset(blob, node, "regulators"); | ||
56 | if (regulators_node <= 0) { | ||
57 | debug("%s: %s regulators subnode not found!", __func__, | ||
58 | dev->name); | ||
59 | return -ENXIO; | ||
60 | } | ||
61 | |||
62 | debug("%s: '%s' - found regulators subnode\n", __func__, dev->name); | ||
63 | |||
64 | children = pmic_bind_children(dev, regulators_node, pmic_children_info); | ||
65 | if (!children) | ||
66 | printf("%s: %s - no child found\n", __func__, dev->name); | ||
67 | |||
68 | /* Always return success for this device */ | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static struct dm_pmic_ops lp87565_ops = { | ||
73 | .read = lp87565_read, | ||
74 | .write = lp87565_write, | ||
75 | }; | ||
76 | |||
77 | static const struct udevice_id lp87565_ids[] = { | ||
78 | { .compatible = "ti,lp87565", .data = LP87565 }, | ||
79 | { .compatible = "ti,lp87565-q1", .data = LP87565_Q1 }, | ||
80 | { } | ||
81 | }; | ||
82 | |||
83 | U_BOOT_DRIVER(pmic_lp87565) = { | ||
84 | .name = "lp87565_pmic", | ||
85 | .id = UCLASS_PMIC, | ||
86 | .of_match = lp87565_ids, | ||
87 | .bind = lp87565_bind, | ||
88 | .ops = &lp87565_ops, | ||
89 | }; | ||