2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-07-25 14:30:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*
|
|
|
|
* Placeholder regulator driver for as3722.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-07-25 14:30:10 +00:00
|
|
|
#include <power/as3722.h>
|
|
|
|
#include <power/pmic.h>
|
|
|
|
#include <power/regulator.h>
|
|
|
|
|
2018-05-08 15:34:08 +00:00
|
|
|
#define AS3722_LDO_CONTROL0_MAX_INDEX 7
|
|
|
|
|
2017-07-25 14:30:10 +00:00
|
|
|
static int stepdown_get_value(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stepdown_set_value(struct udevice *dev, int uvolt)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stepdown_set_enable(struct udevice *dev, bool enable)
|
|
|
|
{
|
|
|
|
struct udevice *pmic = dev_get_parent(dev);
|
|
|
|
int sd = dev->driver_data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: failed to write SD control register: %d", __func__,
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stepdown_get_enable(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct udevice *pmic = dev_get_parent(dev);
|
|
|
|
int sd = dev->driver_data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pmic_reg_read(pmic, AS3722_SD_CONTROL);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: failed to read SD control register: %d", __func__,
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret & (1 << sd) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldo_get_value(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldo_set_value(struct udevice *dev, int uvolt)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldo_set_enable(struct udevice *dev, bool enable)
|
|
|
|
{
|
|
|
|
struct udevice *pmic = dev_get_parent(dev);
|
2018-05-08 15:34:08 +00:00
|
|
|
u8 ctrl_reg = AS3722_LDO_CONTROL0;
|
2017-07-25 14:30:10 +00:00
|
|
|
int ldo = dev->driver_data;
|
|
|
|
int ret;
|
|
|
|
|
2018-05-08 15:34:08 +00:00
|
|
|
if (ldo > AS3722_LDO_CONTROL0_MAX_INDEX) {
|
|
|
|
ctrl_reg = AS3722_LDO_CONTROL1;
|
|
|
|
ldo -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pmic_clrsetbits(pmic, ctrl_reg, !enable << ldo, enable << ldo);
|
2017-07-25 14:30:10 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: failed to write LDO control register: %d", __func__,
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ldo_get_enable(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct udevice *pmic = dev_get_parent(dev);
|
2018-05-08 15:34:08 +00:00
|
|
|
u8 ctrl_reg = AS3722_LDO_CONTROL0;
|
2017-07-25 14:30:10 +00:00
|
|
|
int ldo = dev->driver_data;
|
|
|
|
int ret;
|
|
|
|
|
2018-05-08 15:34:08 +00:00
|
|
|
if (ldo > AS3722_LDO_CONTROL0_MAX_INDEX) {
|
|
|
|
ctrl_reg = AS3722_LDO_CONTROL1;
|
|
|
|
ldo -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pmic_reg_read(pmic, ctrl_reg);
|
2017-07-25 14:30:10 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
debug("%s: failed to read SD control register: %d", __func__,
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret & (1 << ldo) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int as3722_stepdown_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:18 +00:00
|
|
|
struct dm_regulator_uclass_plat *uc_pdata;
|
2017-07-25 14:30:10 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2017-07-25 14:30:10 +00:00
|
|
|
|
|
|
|
uc_pdata->type = REGULATOR_TYPE_BUCK;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int as3722_ldo_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:18 +00:00
|
|
|
struct dm_regulator_uclass_plat *uc_pdata;
|
2017-07-25 14:30:10 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2017-07-25 14:30:10 +00:00
|
|
|
|
|
|
|
uc_pdata->type = REGULATOR_TYPE_LDO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dm_regulator_ops as3722_stepdown_ops = {
|
|
|
|
.get_value = stepdown_get_value,
|
|
|
|
.set_value = stepdown_set_value,
|
|
|
|
.get_enable = stepdown_get_enable,
|
|
|
|
.set_enable = stepdown_set_enable,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct dm_regulator_ops as3722_ldo_ops = {
|
|
|
|
.get_value = ldo_get_value,
|
|
|
|
.set_value = ldo_set_value,
|
|
|
|
.get_enable = ldo_get_enable,
|
|
|
|
.set_enable = ldo_set_enable,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(as3722_stepdown) = {
|
|
|
|
.name = "as3722_stepdown",
|
|
|
|
.id = UCLASS_REGULATOR,
|
|
|
|
.ops = &as3722_stepdown_ops,
|
|
|
|
.probe = as3722_stepdown_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(as3722_ldo) = {
|
|
|
|
.name = "as3722_ldo",
|
|
|
|
.id = UCLASS_REGULATOR,
|
|
|
|
.ops = &as3722_ldo_ops,
|
|
|
|
.probe = as3722_ldo_probe,
|
|
|
|
};
|