xref: /openbmc/u-boot/drivers/power/pmic/tps65090.c (revision 3c03f492)
1 /*
2  * Copyright (c) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <dm.h>
10 #include <errno.h>
11 #include <fdtdec.h>
12 #include <i2c.h>
13 #include <power/pmic.h>
14 #include <power/tps65090.h>
15 
16 DECLARE_GLOBAL_DATA_PTR;
17 
18 static const struct pmic_child_info pmic_children_info[] = {
19 	{ .prefix = "fet", .driver = TPS65090_FET_DRIVER },
20 	{ },
21 };
22 
23 static int tps65090_reg_count(struct udevice *dev)
24 {
25 	return TPS65090_NUM_REGS;
26 }
27 
28 static int tps65090_write(struct udevice *dev, uint reg, const uint8_t *buff,
29 			  int len)
30 {
31 	if (dm_i2c_write(dev, reg, buff, len)) {
32 		error("write error to device: %p register: %#x!", dev, reg);
33 		return -EIO;
34 	}
35 
36 	return 0;
37 }
38 
39 static int tps65090_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
40 {
41 	int ret;
42 
43 	ret = dm_i2c_read(dev, reg, buff, len);
44 	if (ret) {
45 		error("read error %d from device: %p register: %#x!", ret, dev,
46 		      reg);
47 		return -EIO;
48 	}
49 
50 	return 0;
51 }
52 
53 static int tps65090_bind(struct udevice *dev)
54 {
55 	int regulators_node;
56 	const void *blob = gd->fdt_blob;
57 	int children;
58 
59 	regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
60 					     "regulators");
61 	if (regulators_node <= 0) {
62 		debug("%s: %s regulators subnode not found!", __func__,
63 		      dev->name);
64 		return -ENXIO;
65 	}
66 
67 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
68 
69 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
70 	if (!children)
71 		debug("%s: %s - no child found\n", __func__, dev->name);
72 
73 	/* Always return success for this device */
74 	return 0;
75 }
76 
77 static struct dm_pmic_ops tps65090_ops = {
78 	.reg_count = tps65090_reg_count,
79 	.read = tps65090_read,
80 	.write = tps65090_write,
81 };
82 
83 static const struct udevice_id tps65090_ids[] = {
84 	{ .compatible = "ti,tps65090" },
85 	{ }
86 };
87 
88 U_BOOT_DRIVER(pmic_tps65090) = {
89 	.name = "tps65090 pmic",
90 	.id = UCLASS_PMIC,
91 	.of_match = tps65090_ids,
92 	.bind = tps65090_bind,
93 	.ops = &tps65090_ops,
94 };
95