blob: a5f855ce2a3187470c33f727f825d8fee48233f9 [file] [log] [blame]
Philipp Tomsichb7f57e12018-11-30 20:00:08 +01001// 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>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <dm/device_compat.h>
Philipp Tomsichb7f57e12018-11-30 20:00:08 +010010#include <dm/lists.h>
11#include <i2c.h>
Vasily Khoruzhick43e7b342019-11-16 11:32:03 -080012#include <power/fan53555.h>
Philipp Tomsichb7f57e12018-11-30 20:00:08 +010013#include <power/pmic.h>
14#include <power/regulator.h>
15
16static int pmic_fan53555_reg_count(struct udevice *dev)
17{
18 return 1;
19};
20
21static int pmic_fan53555_read(struct udevice *dev, uint reg,
22 u8 *buff, int len)
23{
24 if (dm_i2c_read(dev, reg, buff, len)) {
25 pr_err("%s: read error for register: %#x!", dev->name, reg);
26 return -EIO;
27 }
28
29 return 0;
30}
31
32static int pmic_fan53555_write(struct udevice *dev, uint reg,
33 const u8 *buff, int len)
34{
35 if (dm_i2c_write(dev, reg, buff, len)) {
36 pr_err("%s: write error for register: %#x!", dev->name, reg);
37 return -EIO;
38 }
39
40 return 0;
41}
42
43static int pmic_fan53555_bind(struct udevice *dev)
44{
45 /*
46 * The FAN53555 has only a single regulator and therefore doesn't
47 * have a subnode. So we have to rebind a child device (the one
48 * regulator) here.
49 */
50
51 const char *regulator_driver_name = "fan53555_regulator";
52 struct udevice *child;
53 struct driver *drv;
54
55 debug("%s\n", __func__);
56
57 drv = lists_driver_lookup_name(regulator_driver_name);
58 if (!drv) {
59 dev_err(dev, "no driver '%s'\n", regulator_driver_name);
60 return -ENOENT;
61 }
62
Vasily Khoruzhick43e7b342019-11-16 11:32:03 -080063 return device_bind_with_driver_data(dev, drv, "SW", dev->driver_data,
Philipp Tomsichb7f57e12018-11-30 20:00:08 +010064 dev_ofnode(dev), &child);
65};
66
67static struct dm_pmic_ops pmic_fan53555_ops = {
68 .reg_count = pmic_fan53555_reg_count,
69 .read = pmic_fan53555_read,
70 .write = pmic_fan53555_write,
71};
72
73static const struct udevice_id pmic_fan53555_match[] = {
Vasily Khoruzhick43e7b342019-11-16 11:32:03 -080074 { .compatible = "fcs,fan53555", .data = FAN53555_VENDOR_FAIRCHILD, },
75 { .compatible = "silergy,syr827", .data = FAN53555_VENDOR_SILERGY, },
76 { .compatible = "silergy,syr828", .data = FAN53555_VENDOR_SILERGY, },
Philipp Tomsichb7f57e12018-11-30 20:00:08 +010077 { },
78};
79
80U_BOOT_DRIVER(pmic_fan53555) = {
81 .name = "pmic_fan53555",
82 .id = UCLASS_PMIC,
83 .of_match = pmic_fan53555_match,
84 .bind = pmic_fan53555_bind,
85 .ops = &pmic_fan53555_ops,
86};