xref: /openbmc/u-boot/drivers/power/pmic/fan53555.c (revision 224f7452)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) 2018 Theobroma Systems Design und Consulting GmbH
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <dm/device-internal.h>
9 #include <dm/lists.h>
10 #include <i2c.h>
11 #include <power/pmic.h>
12 #include <power/regulator.h>
13 
14 static int pmic_fan53555_reg_count(struct udevice *dev)
15 {
16 	return 1;
17 };
18 
19 static int pmic_fan53555_read(struct udevice *dev, uint reg,
20 			      u8 *buff, int len)
21 {
22 	if (dm_i2c_read(dev, reg, buff, len)) {
23 		pr_err("%s: read error for register: %#x!", dev->name, reg);
24 		return -EIO;
25 	}
26 
27 	return 0;
28 }
29 
30 static int pmic_fan53555_write(struct udevice *dev, uint reg,
31 			       const u8 *buff, int len)
32 {
33 	if (dm_i2c_write(dev, reg, buff, len)) {
34 		pr_err("%s: write error for register: %#x!", dev->name, reg);
35 		return -EIO;
36 	}
37 
38 	return 0;
39 }
40 
41 static int pmic_fan53555_bind(struct udevice *dev)
42 {
43 	/*
44 	 * The FAN53555 has only a single regulator and therefore doesn't
45 	 * have a subnode.  So we have to rebind a child device (the one
46 	 * regulator) here.
47 	 */
48 
49 	const char *regulator_driver_name = "fan53555_regulator";
50 	struct udevice *child;
51 	struct driver *drv;
52 
53 	debug("%s\n", __func__);
54 
55 	drv = lists_driver_lookup_name(regulator_driver_name);
56 	if (!drv) {
57 		dev_err(dev, "no driver '%s'\n", regulator_driver_name);
58 		return -ENOENT;
59 	}
60 
61 	return device_bind_with_driver_data(dev, drv, "SW", 0,
62 					    dev_ofnode(dev), &child);
63 };
64 
65 static struct dm_pmic_ops pmic_fan53555_ops = {
66 	.reg_count = pmic_fan53555_reg_count,
67 	.read = pmic_fan53555_read,
68 	.write = pmic_fan53555_write,
69 };
70 
71 static const struct udevice_id pmic_fan53555_match[] = {
72 	{ .compatible = "fcs,fan53555" },
73 	{ },
74 };
75 
76 U_BOOT_DRIVER(pmic_fan53555) = {
77 	.name = "pmic_fan53555",
78 	.id = UCLASS_PMIC,
79 	.of_match = pmic_fan53555_match,
80 	.bind = pmic_fan53555_bind,
81 	.ops = &pmic_fan53555_ops,
82 };
83