2018-11-30 19:00:08 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* (C) 2018 Theobroma Systems Design und Consulting GmbH
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-11-30 19:00:08 +00:00
|
|
|
#include <dm/device-internal.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2018-11-30 19:00:08 +00:00
|
|
|
#include <dm/lists.h>
|
|
|
|
#include <i2c.h>
|
2019-11-16 19:32:03 +00:00
|
|
|
#include <power/fan53555.h>
|
2018-11-30 19:00:08 +00:00
|
|
|
#include <power/pmic.h>
|
|
|
|
#include <power/regulator.h>
|
|
|
|
|
|
|
|
static int pmic_fan53555_reg_count(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pmic_fan53555_read(struct udevice *dev, uint reg,
|
|
|
|
u8 *buff, int len)
|
|
|
|
{
|
|
|
|
if (dm_i2c_read(dev, reg, buff, len)) {
|
2022-09-25 13:43:27 +00:00
|
|
|
pr_err("%s: read error for register: %#x!\n", dev->name, reg);
|
2018-11-30 19:00:08 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pmic_fan53555_write(struct udevice *dev, uint reg,
|
|
|
|
const u8 *buff, int len)
|
|
|
|
{
|
|
|
|
if (dm_i2c_write(dev, reg, buff, len)) {
|
|
|
|
pr_err("%s: write error for register: %#x!", dev->name, reg);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pmic_fan53555_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The FAN53555 has only a single regulator and therefore doesn't
|
|
|
|
* have a subnode. So we have to rebind a child device (the one
|
|
|
|
* regulator) here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *regulator_driver_name = "fan53555_regulator";
|
|
|
|
struct udevice *child;
|
|
|
|
struct driver *drv;
|
|
|
|
|
|
|
|
debug("%s\n", __func__);
|
|
|
|
|
|
|
|
drv = lists_driver_lookup_name(regulator_driver_name);
|
|
|
|
if (!drv) {
|
|
|
|
dev_err(dev, "no driver '%s'\n", regulator_driver_name);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2019-11-16 19:32:03 +00:00
|
|
|
return device_bind_with_driver_data(dev, drv, "SW", dev->driver_data,
|
2018-11-30 19:00:08 +00:00
|
|
|
dev_ofnode(dev), &child);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct dm_pmic_ops pmic_fan53555_ops = {
|
|
|
|
.reg_count = pmic_fan53555_reg_count,
|
|
|
|
.read = pmic_fan53555_read,
|
|
|
|
.write = pmic_fan53555_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id pmic_fan53555_match[] = {
|
2019-11-16 19:32:03 +00:00
|
|
|
{ .compatible = "fcs,fan53555", .data = FAN53555_VENDOR_FAIRCHILD, },
|
|
|
|
{ .compatible = "silergy,syr827", .data = FAN53555_VENDOR_SILERGY, },
|
|
|
|
{ .compatible = "silergy,syr828", .data = FAN53555_VENDOR_SILERGY, },
|
2018-11-30 19:00:08 +00:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(pmic_fan53555) = {
|
|
|
|
.name = "pmic_fan53555",
|
|
|
|
.id = UCLASS_PMIC,
|
|
|
|
.of_match = pmic_fan53555_match,
|
|
|
|
.bind = pmic_fan53555_bind,
|
|
|
|
.ops = &pmic_fan53555_ops,
|
|
|
|
};
|