2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-12-10 05:25:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 NVIDIA Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) "as3722: " fmt
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <i2c.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-07-25 14:30:12 +00:00
|
|
|
#include <dm/lists.h>
|
2014-12-10 05:25:05 +00:00
|
|
|
#include <power/as3722.h>
|
2017-07-25 14:30:12 +00:00
|
|
|
#include <power/pmic.h>
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
#define AS3722_NUM_OF_REGS 0x92
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
static int as3722_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
|
2014-12-10 05:25:05 +00:00
|
|
|
{
|
2017-07-25 14:30:12 +00:00
|
|
|
int ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
ret = dm_i2c_read(dev, reg, buff, len);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
static int as3722_write(struct udevice *dev, uint reg, const uint8_t *buff,
|
|
|
|
int len)
|
2014-12-10 05:25:05 +00:00
|
|
|
{
|
2017-07-25 14:30:12 +00:00
|
|
|
int ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
ret = dm_i2c_write(dev, reg, buff, len);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
static int as3722_read_id(struct udevice *dev, uint *idp, uint *revisionp)
|
2014-12-10 05:25:05 +00:00
|
|
|
{
|
2017-07-25 14:30:12 +00:00
|
|
|
int ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
ret = pmic_reg_read(dev, AS3722_ASIC_ID1);
|
|
|
|
if (ret < 0) {
|
2018-11-18 15:14:28 +00:00
|
|
|
pr_err("failed to read ID1 register: %d\n", ret);
|
2017-07-25 14:30:12 +00:00
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
2017-07-25 14:30:12 +00:00
|
|
|
*idp = ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
ret = pmic_reg_read(dev, AS3722_ASIC_ID2);
|
|
|
|
if (ret < 0) {
|
2018-11-18 15:14:28 +00:00
|
|
|
pr_err("failed to read ID2 register: %d\n", ret);
|
2017-07-25 14:30:12 +00:00
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
2017-07-25 14:30:12 +00:00
|
|
|
*revisionp = ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
/* TODO(treding@nvidia.com): Add proper regulator support to avoid this */
|
|
|
|
int as3722_sd_set_voltage(struct udevice *dev, unsigned int sd, u8 value)
|
2014-12-10 05:25:05 +00:00
|
|
|
{
|
2017-07-25 14:30:12 +00:00
|
|
|
int ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
|
|
|
if (sd > 6)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
ret = pmic_reg_write(dev, AS3722_SD_VOLTAGE(sd), value);
|
|
|
|
if (ret < 0) {
|
2018-11-18 15:14:28 +00:00
|
|
|
pr_err("failed to write SD%u voltage register: %d\n", sd, ret);
|
2017-07-25 14:30:12 +00:00
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
int as3722_ldo_set_voltage(struct udevice *dev, unsigned int ldo, u8 value)
|
2014-12-10 05:25:05 +00:00
|
|
|
{
|
2017-07-25 14:30:12 +00:00
|
|
|
int ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
|
|
|
if (ldo > 11)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
ret = pmic_reg_write(dev, AS3722_LDO_VOLTAGE(ldo), value);
|
|
|
|
if (ret < 0) {
|
2018-11-18 15:14:28 +00:00
|
|
|
pr_err("failed to write LDO%u voltage register: %d\n", ldo,
|
|
|
|
ret);
|
2017-07-25 14:30:12 +00:00
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
static int as3722_probe(struct udevice *dev)
|
2014-12-10 05:25:05 +00:00
|
|
|
{
|
2017-07-25 14:30:12 +00:00
|
|
|
uint id, revision;
|
|
|
|
int ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
ret = as3722_read_id(dev, &id, &revision);
|
|
|
|
if (ret < 0) {
|
2018-11-18 15:14:28 +00:00
|
|
|
pr_err("failed to read ID: %d\n", ret);
|
2017-07-25 14:30:12 +00:00
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
if (id != AS3722_DEVICE_ID) {
|
2018-11-18 15:14:28 +00:00
|
|
|
pr_err("unknown device\n");
|
2017-07-25 14:30:12 +00:00
|
|
|
return -ENOENT;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
debug("AS3722 revision %#x found on I2C bus %s\n", revision, dev->name);
|
2014-12-10 05:25:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
|
|
|
|
static const struct pmic_child_info pmic_children_info[] = {
|
|
|
|
{ .prefix = "sd", .driver = "as3722_stepdown"},
|
|
|
|
{ .prefix = "ldo", .driver = "as3722_ldo"},
|
|
|
|
{ },
|
|
|
|
};
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
static int as3722_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct udevice *gpio_dev;
|
|
|
|
ofnode regulators_node;
|
|
|
|
int children;
|
|
|
|
int ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
regulators_node = dev_read_subnode(dev, "regulators");
|
|
|
|
if (!ofnode_valid(regulators_node)) {
|
|
|
|
debug("%s: %s regulators subnode not found\n", __func__,
|
|
|
|
dev->name);
|
|
|
|
return -ENXIO;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
children = pmic_bind_children(dev, regulators_node, pmic_children_info);
|
|
|
|
if (!children)
|
|
|
|
debug("%s: %s - no child found\n", __func__, dev->name);
|
|
|
|
ret = device_bind_driver(dev, "gpio_as3722", "gpio_as3722", &gpio_dev);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Cannot bind GPIOs (ret=%d)\n", __func__, ret);
|
|
|
|
return ret;
|
2014-12-10 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-25 14:30:12 +00:00
|
|
|
#endif
|
2014-12-10 05:25:05 +00:00
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
static int as3722_reg_count(struct udevice *dev)
|
2015-04-15 03:03:26 +00:00
|
|
|
{
|
2017-07-25 14:30:12 +00:00
|
|
|
return AS3722_NUM_OF_REGS;
|
2015-04-15 03:03:26 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 14:30:12 +00:00
|
|
|
static struct dm_pmic_ops as3722_ops = {
|
|
|
|
.reg_count = as3722_reg_count,
|
|
|
|
.read = as3722_read,
|
|
|
|
.write = as3722_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id as3722_ids[] = {
|
|
|
|
{ .compatible = "ams,as3722" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(pmic_as3722) = {
|
|
|
|
.name = "as3722_pmic",
|
|
|
|
.id = UCLASS_PMIC,
|
|
|
|
.of_match = as3722_ids,
|
|
|
|
#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
|
|
|
|
.bind = as3722_bind,
|
|
|
|
#endif
|
|
|
|
.probe = as3722_probe,
|
|
|
|
.ops = &as3722_ops,
|
|
|
|
};
|