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