xref: /openbmc/u-boot/drivers/power/pmic/max77686.c (revision cbd2fba1)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Copyright (C) 2014-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/regulator.h>
14 #include <power/max77686_pmic.h>
15 
16 static const struct pmic_child_info pmic_children_info[] = {
17 	{ .prefix = "LDO", .driver = MAX77686_LDO_DRIVER },
18 	{ .prefix = "BUCK", .driver = MAX77686_BUCK_DRIVER },
19 	{ },
20 };
21 
22 static int max77686_reg_count(struct udevice *dev)
23 {
24 	return MAX77686_NUM_OF_REGS;
25 }
26 
27 static int max77686_write(struct udevice *dev, uint reg, const uint8_t *buff,
28 			  int len)
29 {
30 	if (dm_i2c_write(dev, reg, buff, len)) {
31 		pr_err("write error to device: %p register: %#x!", dev, reg);
32 		return -EIO;
33 	}
34 
35 	return 0;
36 }
37 
38 static int max77686_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
39 {
40 	if (dm_i2c_read(dev, reg, buff, len)) {
41 		pr_err("read error from device: %p register: %#x!", dev, reg);
42 		return -EIO;
43 	}
44 
45 	return 0;
46 }
47 
48 static int max77686_bind(struct udevice *dev)
49 {
50 	ofnode regulators_node;
51 	int children;
52 
53 	regulators_node = dev_read_subnode(dev, "voltage-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 		debug("%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 max77686_ops = {
71 	.reg_count = max77686_reg_count,
72 	.read = max77686_read,
73 	.write = max77686_write,
74 };
75 
76 static const struct udevice_id max77686_ids[] = {
77 	{ .compatible = "maxim,max77686" },
78 	{ }
79 };
80 
81 U_BOOT_DRIVER(pmic_max77686) = {
82 	.name = "max77686_pmic",
83 	.id = UCLASS_PMIC,
84 	.of_match = max77686_ids,
85 	.bind = max77686_bind,
86 	.ops = &max77686_ops,
87 };
88