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