xref: /openbmc/u-boot/drivers/power/pmic/tps65090.c (revision f77d4410)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2015 Google, Inc
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <errno.h>
10 #include <fdtdec.h>
11 #include <i2c.h>
12 #include <power/pmic.h>
13 #include <power/tps65090.h>
14 
15 static const struct pmic_child_info pmic_children_info[] = {
16 	{ .prefix = "fet", .driver = TPS65090_FET_DRIVER },
17 	{ },
18 };
19 
20 static int tps65090_reg_count(struct udevice *dev)
21 {
22 	return TPS65090_NUM_REGS;
23 }
24 
25 static int tps65090_write(struct udevice *dev, uint reg, const uint8_t *buff,
26 			  int len)
27 {
28 	if (dm_i2c_write(dev, reg, buff, len)) {
29 		pr_err("write error to device: %p register: %#x!", dev, reg);
30 		return -EIO;
31 	}
32 
33 	return 0;
34 }
35 
36 static int tps65090_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
37 {
38 	int ret;
39 
40 	ret = dm_i2c_read(dev, reg, buff, len);
41 	if (ret) {
42 		pr_err("read error %d from device: %p register: %#x!", ret, dev,
43 		      reg);
44 		return -EIO;
45 	}
46 
47 	return 0;
48 }
49 
50 static int tps65090_bind(struct udevice *dev)
51 {
52 	ofnode regulators_node;
53 	int children;
54 
55 	regulators_node = dev_read_subnode(dev, "regulators");
56 	if (!ofnode_valid(regulators_node)) {
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 		debug("%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 tps65090_ops = {
73 	.reg_count = tps65090_reg_count,
74 	.read = tps65090_read,
75 	.write = tps65090_write,
76 };
77 
78 static const struct udevice_id tps65090_ids[] = {
79 	{ .compatible = "ti,tps65090" },
80 	{ }
81 };
82 
83 U_BOOT_DRIVER(pmic_tps65090) = {
84 	.name = "tps65090 pmic",
85 	.id = UCLASS_PMIC,
86 	.of_match = tps65090_ids,
87 	.bind = tps65090_bind,
88 	.ops = &tps65090_ops,
89 };
90