blob: d556b9a5878a0dc7b977321cd2d75a9e5e5eb90b [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>
Simon Glass1e94b462023-09-14 18:21:46 -060013#include <linux/printk.h>
Vasily Khoruzhick5ef1e022019-11-16 11:32:03 -080014#include <power/fan53555.h>
Philipp Tomsichdfb0a702018-11-30 20:00:08 +010015#include <power/pmic.h>
16#include <power/regulator.h>
17
18static int pmic_fan53555_reg_count(struct udevice *dev)
19{
20 return 1;
21};
22
23static int pmic_fan53555_read(struct udevice *dev, uint reg,
24 u8 *buff, int len)
25{
26 if (dm_i2c_read(dev, reg, buff, len)) {
Michal Suchanek0b918622022-09-25 15:43:27 +020027 pr_err("%s: read error for register: %#x!\n", dev->name, reg);
Philipp Tomsichdfb0a702018-11-30 20:00:08 +010028 return -EIO;
29 }
30
31 return 0;
32}
33
34static int pmic_fan53555_write(struct udevice *dev, uint reg,
35 const u8 *buff, int len)
36{
37 if (dm_i2c_write(dev, reg, buff, len)) {
38 pr_err("%s: write error for register: %#x!", dev->name, reg);
39 return -EIO;
40 }
41
42 return 0;
43}
44
45static int pmic_fan53555_bind(struct udevice *dev)
46{
47 /*
48 * The FAN53555 has only a single regulator and therefore doesn't
49 * have a subnode. So we have to rebind a child device (the one
50 * regulator) here.
51 */
52
53 const char *regulator_driver_name = "fan53555_regulator";
54 struct udevice *child;
55 struct driver *drv;
56
57 debug("%s\n", __func__);
58
59 drv = lists_driver_lookup_name(regulator_driver_name);
60 if (!drv) {
61 dev_err(dev, "no driver '%s'\n", regulator_driver_name);
62 return -ENOENT;
63 }
64
Vasily Khoruzhick5ef1e022019-11-16 11:32:03 -080065 return device_bind_with_driver_data(dev, drv, "SW", dev->driver_data,
Philipp Tomsichdfb0a702018-11-30 20:00:08 +010066 dev_ofnode(dev), &child);
67};
68
69static struct dm_pmic_ops pmic_fan53555_ops = {
70 .reg_count = pmic_fan53555_reg_count,
71 .read = pmic_fan53555_read,
72 .write = pmic_fan53555_write,
73};
74
75static const struct udevice_id pmic_fan53555_match[] = {
Vasily Khoruzhick5ef1e022019-11-16 11:32:03 -080076 { .compatible = "fcs,fan53555", .data = FAN53555_VENDOR_FAIRCHILD, },
77 { .compatible = "silergy,syr827", .data = FAN53555_VENDOR_SILERGY, },
78 { .compatible = "silergy,syr828", .data = FAN53555_VENDOR_SILERGY, },
Philipp Tomsichdfb0a702018-11-30 20:00:08 +010079 { },
80};
81
82U_BOOT_DRIVER(pmic_fan53555) = {
83 .name = "pmic_fan53555",
84 .id = UCLASS_PMIC,
85 .of_match = pmic_fan53555_match,
86 .bind = pmic_fan53555_bind,
87 .ops = &pmic_fan53555_ops,
88};