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 <log.h>
13 #include <power/pmic.h>
14 #include <power/regulator.h>
15 #include <power/tps65941.h>
16 #include <dm/device.h>
17
18 static const struct pmic_child_info pmic_children_info[] = {
19 { .prefix = "ldo", .driver = TPS65941_LDO_DRIVER },
20 { .prefix = "buck", .driver = TPS65941_BUCK_DRIVER },
21 { },
22 };
23
tps65941_write(struct udevice * dev,uint reg,const uint8_t * buff,int len)24 static int tps65941_write(struct udevice *dev, uint reg, const uint8_t *buff,
25 int len)
26 {
27 if (dm_i2c_write(dev, reg, buff, len)) {
28 pr_err("write error to device: %p register: %#x!\n", dev, reg);
29 return -EIO;
30 }
31
32 return 0;
33 }
34
tps65941_read(struct udevice * dev,uint reg,uint8_t * buff,int len)35 static int tps65941_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
36 {
37 if (dm_i2c_read(dev, reg, buff, len)) {
38 pr_err("read error from device: %p register: %#x!\n", dev, reg);
39 return -EIO;
40 }
41
42 return 0;
43 }
44
tps65941_bind(struct udevice * dev)45 static int tps65941_bind(struct udevice *dev)
46 {
47 ofnode regulators_node;
48 int children;
49
50 regulators_node = dev_read_subnode(dev, "regulators");
51 if (!ofnode_valid(regulators_node)) {
52 debug("%s: %s regulators subnode not found!\n", __func__,
53 dev->name);
54 return -ENXIO;
55 }
56
57 debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
58
59 children = pmic_bind_children(dev, regulators_node, pmic_children_info);
60 if (!children)
61 printf("%s: %s - no child found\n", __func__, dev->name);
62
63 /* Probe all the child devices */
64 return dm_scan_fdt_dev(dev);
65 }
66
67 static struct dm_pmic_ops tps65941_ops = {
68 .read = tps65941_read,
69 .write = tps65941_write,
70 };
71
72 static const struct udevice_id tps65941_ids[] = {
73 { .compatible = "ti,tps659411", .data = TPS659411 },
74 { .compatible = "ti,tps659413", .data = TPS659413 },
75 { }
76 };
77
78 U_BOOT_DRIVER(pmic_tps65941) = {
79 .name = "tps65941_pmic",
80 .id = UCLASS_PMIC,
81 .of_match = tps65941_ids,
82 .bind = tps65941_bind,
83 .ops = &tps65941_ops,
84 };
85