2018-05-07 07:27:01 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
2018-03-12 18:46:12 +09:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018, STMicroelectronics - All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <i2c.h>
|
|
|
|
#include <power/pmic.h>
|
2019-02-04 19:26:16 +09:00
|
|
|
#include <power/stpmic1.h>
|
2018-03-12 18:46:12 +09:00
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
#define STPMIC1_NUM_OF_REGS 0x100
|
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(DM_REGULATOR)
|
|
|
|
static const struct pmic_child_info stpmic1_children_info[] = {
|
|
|
|
{ .prefix = "ldo", .driver = "stpmic1_ldo" },
|
|
|
|
{ .prefix = "buck", .driver = "stpmic1_buck" },
|
|
|
|
{ .prefix = "vref_ddr", .driver = "stpmic1_vref_ddr" },
|
|
|
|
{ .prefix = "pwr_sw", .driver = "stpmic1_pwr_sw" },
|
|
|
|
{ .prefix = "boost", .driver = "stpmic1_boost" },
|
2018-04-27 00:13:10 +09:00
|
|
|
{ },
|
|
|
|
};
|
2019-02-04 19:26:17 +09:00
|
|
|
#endif /* DM_REGULATOR */
|
2018-04-27 00:13:10 +09:00
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
static int stpmic1_reg_count(struct udevice *dev)
|
2018-03-12 18:46:12 +09:00
|
|
|
{
|
2019-02-04 19:26:17 +09:00
|
|
|
return STPMIC1_NUM_OF_REGS;
|
2018-03-12 18:46:12 +09:00
|
|
|
}
|
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
static int stpmic1_write(struct udevice *dev, uint reg, const uint8_t *buff,
|
|
|
|
int len)
|
2018-03-12 18:46:12 +09:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dm_i2c_write(dev, reg, buff, len);
|
|
|
|
if (ret)
|
|
|
|
dev_err(dev, "%s: failed to write register %#x :%d",
|
|
|
|
__func__, reg, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
static int stpmic1_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
|
2018-03-12 18:46:12 +09:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dm_i2c_read(dev, reg, buff, len);
|
|
|
|
if (ret)
|
|
|
|
dev_err(dev, "%s: failed to read register %#x : %d",
|
|
|
|
__func__, reg, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
static int stpmic1_bind(struct udevice *dev)
|
2018-04-27 00:13:10 +09:00
|
|
|
{
|
2019-02-04 19:26:17 +09:00
|
|
|
#if CONFIG_IS_ENABLED(DM_REGULATOR)
|
2018-04-27 00:13:10 +09:00
|
|
|
ofnode regulators_node;
|
|
|
|
int children;
|
|
|
|
|
|
|
|
regulators_node = dev_read_subnode(dev, "regulators");
|
|
|
|
if (!ofnode_valid(regulators_node)) {
|
2019-02-04 19:26:17 +09:00
|
|
|
dev_dbg(dev, "regulators subnode not found!");
|
2018-04-27 00:13:10 +09:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
dev_dbg(dev, "found regulators subnode\n");
|
|
|
|
|
|
|
|
children = pmic_bind_children(dev, regulators_node,
|
2019-02-04 19:26:17 +09:00
|
|
|
stpmic1_children_info);
|
2018-04-27 00:13:10 +09:00
|
|
|
if (!children)
|
|
|
|
dev_dbg(dev, "no child found\n");
|
2019-02-04 19:26:17 +09:00
|
|
|
#endif /* DM_REGULATOR */
|
2018-04-27 00:13:10 +09:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
static struct dm_pmic_ops stpmic1_ops = {
|
|
|
|
.reg_count = stpmic1_reg_count,
|
|
|
|
.read = stpmic1_read,
|
|
|
|
.write = stpmic1_write,
|
2018-03-12 18:46:12 +09:00
|
|
|
};
|
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
static const struct udevice_id stpmic1_ids[] = {
|
|
|
|
{ .compatible = "st,stpmic1" },
|
2018-03-12 18:46:12 +09:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2019-02-04 19:26:17 +09:00
|
|
|
U_BOOT_DRIVER(pmic_stpmic1) = {
|
|
|
|
.name = "stpmic1_pmic",
|
2018-03-12 18:46:12 +09:00
|
|
|
.id = UCLASS_PMIC,
|
2019-02-04 19:26:17 +09:00
|
|
|
.of_match = stpmic1_ids,
|
|
|
|
.bind = stpmic1_bind,
|
|
|
|
.ops = &stpmic1_ops,
|
2018-03-12 18:46:12 +09:00
|
|
|
};
|