From 5fcd039b3f631be2d85ce447ad8dc2899acfc706 Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Thu, 16 Jan 2020 19:59:00 +0000 Subject: [PATCH] axp8xx: Add a regnode_init method This method will set the desired voltaged based on values in the DTS. It will not enable the regulator, this is the job of either a consumer or regnode_set_constraint SYSINIT if the regulator is boot_on or always_on. MFC after: 2 weeks --- sys/arm/allwinner/axp81x.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/sys/arm/allwinner/axp81x.c b/sys/arm/allwinner/axp81x.c index 5a1aad9a3a3..c8b4e30c01a 100644 --- a/sys/arm/allwinner/axp81x.c +++ b/sys/arm/allwinner/axp81x.c @@ -710,6 +710,8 @@ struct axp8xx_softc { #define AXP_LOCK(sc) mtx_lock(&(sc)->mtx) #define AXP_UNLOCK(sc) mtx_unlock(&(sc)->mtx) +static int axp8xx_regnode_set_voltage(struct regnode *regnode, int min_uvolt, + int max_uvolt, int *udelay); static int axp8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size) @@ -753,6 +755,31 @@ axp8xx_write(device_t dev, uint8_t reg, uint8_t val) return (iicbus_transfer(dev, msg, 2)); } +static int +axp8xx_regnode_init(struct regnode *regnode) +{ + struct axp8xx_reg_sc *sc; + struct regnode_std_param *param; + int rv, udelay; + + sc = regnode_get_softc(regnode); + param = regnode_get_stdparam(regnode); + if (param->min_uvolt == 0) + return (0); + + /* + * Set the regulator at the correct voltage + * Do not enable it, this is will be done either by a + * consumer or by regnode_set_constraint if boot_on is true + */ + rv = axp8xx_regnode_set_voltage(regnode, param->min_uvolt, + param->max_uvolt, &udelay); + if (rv != 0) + DELAY(udelay); + + return (rv); +} + static int axp8xx_regnode_enable(struct regnode *regnode, bool enable, int *udelay) { @@ -870,6 +897,7 @@ axp8xx_regnode_get_voltage(struct regnode *regnode, int *uvolt) static regnode_method_t axp8xx_regnode_methods[] = { /* Regulator interface */ + REGNODEMETHOD(regnode_init, axp8xx_regnode_init), REGNODEMETHOD(regnode_enable, axp8xx_regnode_enable), REGNODEMETHOD(regnode_set_voltage, axp8xx_regnode_set_voltage), REGNODEMETHOD(regnode_get_voltage, axp8xx_regnode_get_voltage),