mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-08-24 10:58:52 +09:00
![Tom Rini](/assets/img/avatar_default.png)
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
178 lines
3.4 KiB
C
178 lines
3.4 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* 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>
|
|
#include <dm/lists.h>
|
|
#include <power/as3722.h>
|
|
#include <power/pmic.h>
|
|
|
|
#define AS3722_NUM_OF_REGS 0x92
|
|
|
|
static int as3722_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
|
|
{
|
|
int ret;
|
|
|
|
ret = dm_i2c_read(dev, reg, buff, len);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int as3722_write(struct udevice *dev, uint reg, const uint8_t *buff,
|
|
int len)
|
|
{
|
|
int ret;
|
|
|
|
ret = dm_i2c_write(dev, reg, buff, len);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int as3722_read_id(struct udevice *dev, uint *idp, uint *revisionp)
|
|
{
|
|
int ret;
|
|
|
|
ret = pmic_reg_read(dev, AS3722_ASIC_ID1);
|
|
if (ret < 0) {
|
|
pr_err("failed to read ID1 register: %d", ret);
|
|
return ret;
|
|
}
|
|
*idp = ret;
|
|
|
|
ret = pmic_reg_read(dev, AS3722_ASIC_ID2);
|
|
if (ret < 0) {
|
|
pr_err("failed to read ID2 register: %d", ret);
|
|
return ret;
|
|
}
|
|
*revisionp = ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* TODO(treding@nvidia.com): Add proper regulator support to avoid this */
|
|
int as3722_sd_set_voltage(struct udevice *dev, unsigned int sd, u8 value)
|
|
{
|
|
int ret;
|
|
|
|
if (sd > 6)
|
|
return -EINVAL;
|
|
|
|
ret = pmic_reg_write(dev, AS3722_SD_VOLTAGE(sd), value);
|
|
if (ret < 0) {
|
|
pr_err("failed to write SD%u voltage register: %d", sd, ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int as3722_ldo_set_voltage(struct udevice *dev, unsigned int ldo, u8 value)
|
|
{
|
|
int ret;
|
|
|
|
if (ldo > 11)
|
|
return -EINVAL;
|
|
|
|
ret = pmic_reg_write(dev, AS3722_LDO_VOLTAGE(ldo), value);
|
|
if (ret < 0) {
|
|
pr_err("failed to write LDO%u voltage register: %d", ldo,
|
|
ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int as3722_probe(struct udevice *dev)
|
|
{
|
|
uint id, revision;
|
|
int ret;
|
|
|
|
ret = as3722_read_id(dev, &id, &revision);
|
|
if (ret < 0) {
|
|
pr_err("failed to read ID: %d", ret);
|
|
return ret;
|
|
}
|
|
|
|
if (id != AS3722_DEVICE_ID) {
|
|
pr_err("unknown device");
|
|
return -ENOENT;
|
|
}
|
|
|
|
debug("AS3722 revision %#x found on I2C bus %s\n", revision, dev->name);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#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"},
|
|
{ },
|
|
};
|
|
|
|
static int as3722_bind(struct udevice *dev)
|
|
{
|
|
struct udevice *gpio_dev;
|
|
ofnode regulators_node;
|
|
int children;
|
|
int ret;
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
static int as3722_reg_count(struct udevice *dev)
|
|
{
|
|
return AS3722_NUM_OF_REGS;
|
|
}
|
|
|
|
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,
|
|
};
|