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