xref: /openbmc/u-boot/drivers/power/pmic/lp87565.c (revision a22bbfda)
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 	ofnode regulators_node;
51 	int children;
52 
53 	regulators_node = dev_read_subnode(dev, "regulators");
54 	if (!ofnode_valid(regulators_node)) {
55 		debug("%s: %s regulators subnode not found!", __func__,
56 		      dev->name);
57 		return -ENXIO;
58 	}
59 
60 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
61 
62 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
63 	if (!children)
64 		printf("%s: %s - no child found\n", __func__, dev->name);
65 
66 	/* Always return success for this device */
67 	return 0;
68 }
69 
70 static struct dm_pmic_ops lp87565_ops = {
71 	.read = lp87565_read,
72 	.write = lp87565_write,
73 };
74 
75 static const struct udevice_id lp87565_ids[] = {
76 	{ .compatible = "ti,lp87565", .data = LP87565 },
77 	{ .compatible = "ti,lp87565-q1", .data = LP87565_Q1 },
78 	{ }
79 };
80 
81 U_BOOT_DRIVER(pmic_lp87565) = {
82 	.name = "lp87565_pmic",
83 	.id = UCLASS_PMIC,
84 	.of_match = lp87565_ids,
85 	.bind = lp87565_bind,
86 	.ops = &lp87565_ops,
87 };
88