xref: /openbmc/u-boot/drivers/power/pmic/pfuze100.c (revision 6b44ae6b)
1 /*
2  * Copyright (C) 2015 Freescale Semiconductor, Inc
3  * Peng Fan <Peng.Fan@freescale.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/pfuze100_pmic.h>
16 
17 DECLARE_GLOBAL_DATA_PTR;
18 
19 static const struct pmic_child_info pmic_children_info[] = {
20 	/* sw[x], swbst */
21 	{ .prefix = "s", .driver = PFUZE100_REGULATOR_DRIVER },
22 	/* vgen[x], vsnvs, vcc, v33, vcc_sd */
23 	{ .prefix = "v", .driver = PFUZE100_REGULATOR_DRIVER },
24 	{ },
25 };
26 
27 static int pfuze100_reg_count(struct udevice *dev)
28 {
29 	return PFUZE100_NUM_OF_REGS;
30 }
31 
32 static int pfuze100_write(struct udevice *dev, uint reg, const uint8_t *buff,
33 			  int len)
34 {
35 	if (dm_i2c_write(dev, reg, buff, len)) {
36 		error("write error to device: %p register: %#x!", dev, reg);
37 		return -EIO;
38 	}
39 
40 	return 0;
41 }
42 
43 static int pfuze100_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
44 {
45 	if (dm_i2c_read(dev, reg, buff, len)) {
46 		error("read error from device: %p register: %#x!", dev, reg);
47 		return -EIO;
48 	}
49 
50 	return 0;
51 }
52 
53 static int pfuze100_bind(struct udevice *dev)
54 {
55 	int children;
56 	int regulators_node;
57 	const void *blob = gd->fdt_blob;
58 
59 	regulators_node = fdt_subnode_offset(blob, dev->of_offset,
60 					     "regulators");
61 	if (regulators_node <= 0) {
62 		debug("%s: %s regulators subnode not found!", __func__,
63 		      dev->name);
64 		return -ENXIO;
65 	}
66 
67 	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
68 
69 	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
70 	if (!children)
71 		debug("%s: %s - no child found\n", __func__, dev->name);
72 
73 	/* Always return success for this device */
74 	return 0;
75 }
76 
77 static struct dm_pmic_ops pfuze100_ops = {
78 	.reg_count = pfuze100_reg_count,
79 	.read = pfuze100_read,
80 	.write = pfuze100_write,
81 };
82 
83 static const struct udevice_id pfuze100_ids[] = {
84 	{ .compatible = "fsl,pfuze100", .data = PFUZE100, },
85 	{ .compatible = "fsl,pfuze200", .data = PFUZE200, },
86 	{ .compatible = "fsl,pfuze3000", .data = PFUZE3000, },
87 	{ }
88 };
89 
90 U_BOOT_DRIVER(pmic_pfuze100) = {
91 	.name = "pfuze100 pmic",
92 	.id = UCLASS_PMIC,
93 	.of_match = pfuze100_ids,
94 	.bind = pfuze100_bind,
95 	.ops = &pfuze100_ops,
96 };
97