arm64: rockchip: rk805: Add basic support for RK808 PMIC
RK808 PMIC is the companion chip for RK3399 SoC. Add basic regulator support in RK805 since they are similar. MFC after: 1 month
This commit is contained in:
parent
002812972a
commit
cdbfc50a64
@ -51,8 +51,14 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
MALLOC_DEFINE(M_RK805_REG, "RK805 regulator", "RK805 power regulator");
|
||||
|
||||
enum rk_pmic_type {
|
||||
RK805 = 1,
|
||||
RK808,
|
||||
};
|
||||
|
||||
static struct ofw_compat_data compat_data[] = {
|
||||
{"rockchip,rk805", 1},
|
||||
{"rockchip,rk805", RK805},
|
||||
{"rockchip,rk808", RK808},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
@ -83,6 +89,7 @@ struct rk805_softc {
|
||||
struct resource * res[1];
|
||||
void * intrcookie;
|
||||
struct intr_config_hook intr_hook;
|
||||
enum rk_pmic_type type;
|
||||
|
||||
struct rk805_reg_sc **regs;
|
||||
int nregs;
|
||||
@ -133,6 +140,51 @@ static struct rk805_regdef rk805_regdefs[] = {
|
||||
},
|
||||
};
|
||||
|
||||
static struct rk805_regdef rk808_regdefs[] = {
|
||||
{
|
||||
.id = RK805_DCDC1,
|
||||
.name = "DCDC_REG1",
|
||||
.enable_reg = RK805_DCDC_EN,
|
||||
.enable_mask = 0x1,
|
||||
.voltage_reg = RK805_DCDC1_ON_VSEL,
|
||||
.voltage_mask = 0x3F,
|
||||
.voltage_min = 712500,
|
||||
.voltage_max = 1500000,
|
||||
.voltage_step = 12500,
|
||||
.voltage_nstep = 64,
|
||||
},
|
||||
{
|
||||
.id = RK805_DCDC2,
|
||||
.name = "DCDC_REG2",
|
||||
.enable_reg = RK805_DCDC_EN,
|
||||
.enable_mask = 0x2,
|
||||
.voltage_reg = RK805_DCDC2_ON_VSEL,
|
||||
.voltage_mask = 0x3F,
|
||||
.voltage_min = 712500,
|
||||
.voltage_max = 1500000,
|
||||
.voltage_step = 12500,
|
||||
.voltage_nstep = 64,
|
||||
},
|
||||
{
|
||||
.id = RK805_DCDC3,
|
||||
.name = "DCDC_REG3",
|
||||
.enable_reg = RK805_DCDC_EN,
|
||||
.enable_mask = 0x4,
|
||||
},
|
||||
{
|
||||
.id = RK805_DCDC4,
|
||||
.name = "DCDC_REG4",
|
||||
.enable_reg = RK805_DCDC_EN,
|
||||
.enable_mask = 0x8,
|
||||
.voltage_reg = RK805_DCDC4_ON_VSEL,
|
||||
.voltage_mask = 0xF,
|
||||
.voltage_min = 1800000,
|
||||
.voltage_max = 3300000,
|
||||
.voltage_step = 100000,
|
||||
.voltage_nstep = 16,
|
||||
},
|
||||
};
|
||||
|
||||
static int
|
||||
rk805_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size)
|
||||
{
|
||||
@ -226,11 +278,17 @@ rk805_regnode_set_voltage(struct regnode *regnode, int min_uvolt,
|
||||
if (!sc->def->voltage_step)
|
||||
return (ENXIO);
|
||||
|
||||
rk805_read(sc->base_dev, sc->def->voltage_reg, &val, 1);
|
||||
printf("rk805_set_voltage: Current value for %x: %x\n", sc->def->voltage_reg, val);
|
||||
if (rk805_regnode_voltage_to_reg(sc, min_uvolt, max_uvolt, &val) != 0)
|
||||
return (ERANGE);
|
||||
|
||||
printf("rk805_set_voltage: Setting %x to %x\n", sc->def->voltage_reg, val);
|
||||
rk805_write(sc->base_dev, sc->def->voltage_reg, val);
|
||||
|
||||
rk805_read(sc->base_dev, sc->def->voltage_reg, &val, 1);
|
||||
printf("rk805_set_voltage: Set value for %x: %x\n", sc->def->voltage_reg, val);
|
||||
|
||||
*udelay = 0;
|
||||
|
||||
return (0);
|
||||
@ -326,13 +384,14 @@ rk805_start(void *pdev)
|
||||
sc = device_get_softc(dev);
|
||||
sc->dev = dev;
|
||||
|
||||
if (bootverbose) {
|
||||
err = rk805_read(dev, 0x17, data, 1);
|
||||
/* No version register in RK808 */
|
||||
if (bootverbose && sc->type == RK805) {
|
||||
err = rk805_read(dev, RK805_CHIP_NAME, data, 1);
|
||||
if (err != 0) {
|
||||
device_printf(dev, "Cannot read chip name reg\n");
|
||||
return;
|
||||
}
|
||||
err = rk805_read(dev, 0x18, data + 1, 1);
|
||||
err = rk805_read(dev, RK805_CHIP_VER, data + 1, 1);
|
||||
if (err != 0) {
|
||||
device_printf(dev, "Cannot read chip version reg\n");
|
||||
return;
|
||||
@ -365,8 +424,17 @@ rk805_attach(device_t dev)
|
||||
sc->regs = malloc(sizeof(struct rk805_reg_sc *) * sc->nregs,
|
||||
M_RK805_REG, M_WAITOK | M_ZERO);
|
||||
|
||||
regdefs = rk805_regdefs;
|
||||
sc->nregs = nitems(rk805_regdefs);
|
||||
sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data;
|
||||
switch (sc->type) {
|
||||
case RK805:
|
||||
regdefs = rk805_regdefs;
|
||||
sc->nregs = nitems(rk805_regdefs);
|
||||
break;
|
||||
case RK808:
|
||||
regdefs = rk808_regdefs;
|
||||
sc->nregs = nitems(rk808_regdefs);
|
||||
break;
|
||||
}
|
||||
|
||||
rnode = ofw_bus_find_child(ofw_bus_get_node(dev), "regulators");
|
||||
if (rnode > 0) {
|
||||
|
@ -37,6 +37,7 @@
|
||||
#define RK805_OTP_VER 0x19
|
||||
|
||||
#define RK805_DCDC_EN 0x23
|
||||
#define RK808_LDO_EN 0x24
|
||||
#define RK805_SLEEP_DCDC_EN 0x25
|
||||
#define RK805_SLEEP_LDO_EN 0x26
|
||||
#define RK805_LDO_EN 0x27
|
||||
@ -69,4 +70,21 @@ enum rk805_regulator {
|
||||
RK805_LDO3,
|
||||
};
|
||||
|
||||
enum rk808_regulator {
|
||||
RK808_DCDC1,
|
||||
RK808_DCDC2,
|
||||
RK808_DCDC3,
|
||||
RK808_DCDC4,
|
||||
RK808_LDO1,
|
||||
RK808_LDO2,
|
||||
RK808_LDO3,
|
||||
RK808_LDO4,
|
||||
RK808_LDO5,
|
||||
RK808_LDO6,
|
||||
RK808_LDO7,
|
||||
RK808_LDO8,
|
||||
RK808_SWITCH1,
|
||||
RK808_SWITCH2,
|
||||
};
|
||||
|
||||
#endif /* _RK805REG_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user