xref: /openbmc/u-boot/drivers/power/pmic/s2mps11.c (revision 9d466f2f)
1 /*
2  *  Copyright (C) 2015 Samsung Electronics
3  *  Przemyslaw Marczak  <p.marczak@samsung.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/s2mps11.h>
15 
16 DECLARE_GLOBAL_DATA_PTR;
17 
18 static const struct pmic_child_info pmic_children_info[] = {
19 	{ .prefix = S2MPS11_OF_LDO_PREFIX, .driver = S2MPS11_LDO_DRIVER },
20 	{ .prefix = S2MPS11_OF_BUCK_PREFIX, .driver = S2MPS11_BUCK_DRIVER },
21 	{ },
22 };
23 
24 static int s2mps11_reg_count(struct udevice *dev)
25 {
26 	return S2MPS11_REG_COUNT;
27 }
28 
29 static int s2mps11_write(struct udevice *dev, uint reg, const uint8_t *buff,
30 			 int len)
31 {
32 	int ret;
33 
34 	ret = dm_i2c_write(dev, reg, buff, len);
35 	if (ret)
36 		pr_err("write error to device: %p register: %#x!", dev, reg);
37 
38 	return ret;
39 }
40 
41 static int s2mps11_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
42 {
43 	int ret;
44 
45 	ret = dm_i2c_read(dev, reg, buff, len);
46 	if (ret)
47 		pr_err("read error from device: %p register: %#x!", dev, reg);
48 
49 	return ret;
50 }
51 
52 static int s2mps11_probe(struct udevice *dev)
53 {
54 	ofnode regulators_node;
55 	int children;
56 
57 	regulators_node = dev_read_subnode(dev, "voltage-regulators");
58 	if (!ofnode_valid(regulators_node)) {
59 		debug("%s: %s regulators subnode not found!", __func__,
60 							     dev->name);
61 		return -ENXIO;
62 	}
63 
64 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
65 
66 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
67 	if (!children)
68 		debug("%s: %s - no child found\n", __func__, dev->name);
69 
70 	return 0;
71 }
72 
73 static struct dm_pmic_ops s2mps11_ops = {
74 	.reg_count = s2mps11_reg_count,
75 	.read = s2mps11_read,
76 	.write = s2mps11_write,
77 };
78 
79 static const struct udevice_id s2mps11_ids[] = {
80 	{ .compatible = "samsung,s2mps11-pmic" },
81 	{ }
82 };
83 
84 U_BOOT_DRIVER(pmic_s2mps11) = {
85 	.name = "s2mps11_pmic",
86 	.id = UCLASS_PMIC,
87 	.of_match = s2mps11_ids,
88 	.ops = &s2mps11_ops,
89 	.probe = s2mps11_probe,
90 };
91