1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2019 Texas Instruments Incorporated, <www.ti.com>
4 * Keerthy <j-keerthy@ti.com>
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/tps65941.h>
15 #include <dm/device.h>
16
17 static const struct pmic_child_info pmic_children_info[] = {
18 { .prefix = "ldo", .driver = TPS65941_LDO_DRIVER },
19 { .prefix = "buck", .driver = TPS65941_BUCK_DRIVER },
20 { },
21 };
22
tps65941_write(struct udevice * dev,uint reg,const uint8_t * buff,int len)23 static int tps65941_write(struct udevice *dev, uint reg, const uint8_t *buff,
24 int len)
25 {
26 if (dm_i2c_write(dev, reg, buff, len)) {
27 pr_err("write error to device: %p register: %#x!\n", dev, reg);
28 return -EIO;
29 }
30
31 return 0;
32 }
33
tps65941_read(struct udevice * dev,uint reg,uint8_t * buff,int len)34 static int tps65941_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
35 {
36 if (dm_i2c_read(dev, reg, buff, len)) {
37 pr_err("read error from device: %p register: %#x!\n", dev, reg);
38 return -EIO;
39 }
40
41 return 0;
42 }
43
tps65941_bind(struct udevice * dev)44 static int tps65941_bind(struct udevice *dev)
45 {
46 ofnode regulators_node;
47 int children;
48
49 regulators_node = dev_read_subnode(dev, "regulators");
50 if (!ofnode_valid(regulators_node)) {
51 debug("%s: %s regulators subnode not found!\n", __func__,
52 dev->name);
53 return -ENXIO;
54 }
55
56 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
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 tps65941_ops = {
67 .read = tps65941_read,
68 .write = tps65941_write,
69 };
70
71 static const struct udevice_id tps65941_ids[] = {
72 { .compatible = "ti,tps659411", .data = TPS659411 },
73 { .compatible = "ti,tps659413", .data = TPS659413 },
74 { }
75 };
76
77 U_BOOT_DRIVER(pmic_tps65941) = {
78 .name = "tps65941_pmic",
79 .id = UCLASS_PMIC,
80 .of_match = tps65941_ids,
81 .bind = tps65941_bind,
82 .ops = &tps65941_ops,
83 };
84