dm: core: Require users of devres to include the header
[oweals/u-boot.git] / drivers / power / pmic / fan53555.c
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/fan53555.h>
12 #include <power/pmic.h>
13 #include <power/regulator.h>
14
15 static int pmic_fan53555_reg_count(struct udevice *dev)
16 {
17         return 1;
18 };
19
20 static int pmic_fan53555_read(struct udevice *dev, uint reg,
21                               u8 *buff, int len)
22 {
23         if (dm_i2c_read(dev, reg, buff, len)) {
24                 pr_err("%s: read error for register: %#x!", dev->name, reg);
25                 return -EIO;
26         }
27
28         return 0;
29 }
30
31 static int pmic_fan53555_write(struct udevice *dev, uint reg,
32                                const u8 *buff, int len)
33 {
34         if (dm_i2c_write(dev, reg, buff, len)) {
35                 pr_err("%s: write error for register: %#x!", dev->name, reg);
36                 return -EIO;
37         }
38
39         return 0;
40 }
41
42 static int pmic_fan53555_bind(struct udevice *dev)
43 {
44         /*
45          * The FAN53555 has only a single regulator and therefore doesn't
46          * have a subnode.  So we have to rebind a child device (the one
47          * regulator) here.
48          */
49
50         const char *regulator_driver_name = "fan53555_regulator";
51         struct udevice *child;
52         struct driver *drv;
53
54         debug("%s\n", __func__);
55
56         drv = lists_driver_lookup_name(regulator_driver_name);
57         if (!drv) {
58                 dev_err(dev, "no driver '%s'\n", regulator_driver_name);
59                 return -ENOENT;
60         }
61
62         return device_bind_with_driver_data(dev, drv, "SW", dev->driver_data,
63                                             dev_ofnode(dev), &child);
64 };
65
66 static struct dm_pmic_ops pmic_fan53555_ops = {
67         .reg_count = pmic_fan53555_reg_count,
68         .read = pmic_fan53555_read,
69         .write = pmic_fan53555_write,
70 };
71
72 static const struct udevice_id pmic_fan53555_match[] = {
73         { .compatible = "fcs,fan53555", .data = FAN53555_VENDOR_FAIRCHILD, },
74         { .compatible = "silergy,syr827", .data = FAN53555_VENDOR_SILERGY, },
75         { .compatible = "silergy,syr828", .data = FAN53555_VENDOR_SILERGY, },
76         { },
77 };
78
79 U_BOOT_DRIVER(pmic_fan53555) = {
80         .name = "pmic_fan53555",
81         .id = UCLASS_PMIC,
82         .of_match = pmic_fan53555_match,
83         .bind = pmic_fan53555_bind,
84         .ops = &pmic_fan53555_ops,
85 };