blob: 11304d2146af436d5de47be9071c1e2f52a25b6c [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>
9#include <dm/lists.h>
10#include <i2c.h>
Vasily Khoruzhick43e7b342019-11-16 11:32:03 -080011#include <power/fan53555.h>
Philipp Tomsichb7f57e12018-11-30 20:00:08 +010012#include <power/pmic.h>
13#include <power/regulator.h>
14
15static int pmic_fan53555_reg_count(struct udevice *dev)
16{
17 return 1;
18};
19
20static 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
31static 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
42static 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
Vasily Khoruzhick43e7b342019-11-16 11:32:03 -080062 return device_bind_with_driver_data(dev, drv, "SW", dev->driver_data,
Philipp Tomsichb7f57e12018-11-30 20:00:08 +010063 dev_ofnode(dev), &child);
64};
65
66static 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
72static const struct udevice_id pmic_fan53555_match[] = {
Vasily Khoruzhick43e7b342019-11-16 11:32:03 -080073 { .compatible = "fcs,fan53555", .data = FAN53555_VENDOR_FAIRCHILD, },
74 { .compatible = "silergy,syr827", .data = FAN53555_VENDOR_SILERGY, },
75 { .compatible = "silergy,syr828", .data = FAN53555_VENDOR_SILERGY, },
Philipp Tomsichb7f57e12018-11-30 20:00:08 +010076 { },
77};
78
79U_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};