From nobody Sun Nov 14 12:34:24 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F1FEA183C2CE; Sun, 14 Nov 2021 12:34:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HsWwd1cRXz4cK8; Sun, 14 Nov 2021 12:34:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DD27C266AF; Sun, 14 Nov 2021 12:34:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AECYOCS068496; Sun, 14 Nov 2021 12:34:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AECYOsP068495; Sun, 14 Nov 2021 12:34:24 GMT (envelope-from git) Date: Sun, 14 Nov 2021 12:34:24 GMT Message-Id: <202111141234.1AECYOsP068495@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: ad651f176b57 - main - pmic: rockchip: Split the regulators part in its own file List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ad651f176b579fdc11faf16a199a7b92fa767126 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=ad651f176b579fdc11faf16a199a7b92fa767126 commit ad651f176b579fdc11faf16a199a7b92fa767126 Author: Emmanuel Vadot AuthorDate: 2021-11-14 10:13:12 +0000 Commit: Emmanuel Vadot CommitDate: 2021-11-14 11:31:21 +0000 pmic: rockchip: Split the regulators part in its own file No functional changes intended. --- sys/conf/files.arm64 | 1 + sys/dev/iicbus/pmic/rockchip/rk805.c | 247 -------------------- sys/dev/iicbus/pmic/rockchip/rk8xx.h | 6 + sys/dev/iicbus/pmic/rockchip/rk8xx_regulators.c | 290 ++++++++++++++++++++++++ 4 files changed, 297 insertions(+), 247 deletions(-) diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index a3c325070469..8ad88488fffe 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -541,6 +541,7 @@ arm64/rockchip/rk_dwc3.c optional fdt rk_dwc3 soc_rockchip_rk3399 arm64/rockchip/rk_i2c.c optional fdt rk_i2c soc_rockchip_rk3328 | fdt rk_i2c soc_rockchip_rk3399 arm64/rockchip/rk_i2s.c optional fdt sound soc_rockchip_rk3328 | fdt sound soc_rockchip_rk3399 dev/iicbus/pmic/rockchip/rk805.c optional fdt rk805 soc_rockchip_rk3328 | fdt rk805 soc_rockchip_rk3399 +dev/iicbus/pmic/rockchip/rk8xx_regulators.c optional fdt rk805 soc_rockchip_rk3328 | fdt rk805 soc_rockchip_rk3399 dev/iicbus/pmic/rockchip/rk8xx_rtc.c optional fdt rk805 soc_rockchip_rk3328 | fdt rk805 soc_rockchip_rk3399 arm64/rockchip/rk_grf.c optional fdt soc_rockchip_rk3328 | fdt soc_rockchip_rk3399 arm64/rockchip/rk_pinctrl.c optional fdt rk_pinctrl soc_rockchip_rk3328 | fdt rk_pinctrl soc_rockchip_rk3399 diff --git a/sys/dev/iicbus/pmic/rockchip/rk805.c b/sys/dev/iicbus/pmic/rockchip/rk805.c index ab4006ad63f9..ba5da4e95279 100644 --- a/sys/dev/iicbus/pmic/rockchip/rk805.c +++ b/sys/dev/iicbus/pmic/rockchip/rk805.c @@ -57,20 +57,12 @@ __FBSDID("$FreeBSD$"); MALLOC_DEFINE(M_RK805_REG, "RK805 regulator", "RK805 power regulator"); -/* #define dprintf(sc, format, arg...) device_printf(sc->base_dev, "%s: " format, __func__, arg) */ -#define dprintf(sc, format, arg...) - static struct ofw_compat_data compat_data[] = { {"rockchip,rk805", RK805}, {"rockchip,rk808", RK808}, {NULL, 0} }; -static int rk8xx_regnode_status(struct regnode *regnode, int *status); -static int rk8xx_regnode_set_voltage(struct regnode *regnode, int min_uvolt, - int max_uvolt, int *udelay); -static int rk8xx_regnode_get_voltage(struct regnode *regnode, int *uvolt); - static struct rk8xx_regdef rk805_regdefs[] = { { .id = RK805_BUCK1, @@ -326,226 +318,6 @@ rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size) return (iicdev_writeto(dev, reg, data, size, IIC_INTRWAIT)); } -static int -rk8xx_regnode_init(struct regnode *regnode) -{ - struct rk8xx_reg_sc *sc; - struct regnode_std_param *param; - int rv, udelay, uvolt, status; - - sc = regnode_get_softc(regnode); - dprintf(sc, "Regulator %s init called\n", sc->def->name); - param = regnode_get_stdparam(regnode); - if (param->min_uvolt == 0) - return (0); - - /* Check that the regulator is preset to the correct voltage */ - rv = rk8xx_regnode_get_voltage(regnode, &uvolt); - if (rv != 0) - return(rv); - - if (uvolt >= param->min_uvolt && uvolt <= param->max_uvolt) - return(0); - /* - * Set the regulator at the correct voltage if it is not enabled. - * Do not enable it, this is will be done either by a - * consumer or by regnode_set_constraint if boot_on is true - */ - rv = rk8xx_regnode_status(regnode, &status); - if (rv != 0 || status == REGULATOR_STATUS_ENABLED) - return (rv); - - rv = rk8xx_regnode_set_voltage(regnode, param->min_uvolt, - param->max_uvolt, &udelay); - if (udelay != 0) - DELAY(udelay); - - return (rv); -} - -static int -rk8xx_regnode_enable(struct regnode *regnode, bool enable, int *udelay) -{ - struct rk8xx_reg_sc *sc; - uint8_t val; - - sc = regnode_get_softc(regnode); - - dprintf(sc, "%sabling regulator %s\n", - enable ? "En" : "Dis", - sc->def->name); - rk8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); - if (enable) - val |= sc->def->enable_mask; - else - val &= ~sc->def->enable_mask; - rk8xx_write(sc->base_dev, sc->def->enable_reg, &val, 1); - - *udelay = 0; - - return (0); -} - -static void -rk8xx_regnode_reg_to_voltage(struct rk8xx_reg_sc *sc, uint8_t val, int *uv) -{ - if (val < sc->def->voltage_nstep) - *uv = sc->def->voltage_min + val * sc->def->voltage_step; - else - *uv = sc->def->voltage_min + - (sc->def->voltage_nstep * sc->def->voltage_step); -} - -static int -rk8xx_regnode_voltage_to_reg(struct rk8xx_reg_sc *sc, int min_uvolt, - int max_uvolt, uint8_t *val) -{ - uint8_t nval; - int nstep, uvolt; - - nval = 0; - uvolt = sc->def->voltage_min; - - for (nstep = 0; nstep < sc->def->voltage_nstep && uvolt < min_uvolt; - nstep++) { - ++nval; - uvolt += sc->def->voltage_step; - } - if (uvolt > max_uvolt) - return (EINVAL); - - *val = nval; - return (0); -} - -static int -rk8xx_regnode_status(struct regnode *regnode, int *status) -{ - struct rk8xx_reg_sc *sc; - uint8_t val; - - sc = regnode_get_softc(regnode); - - *status = 0; - rk8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); - if (val & sc->def->enable_mask) - *status = REGULATOR_STATUS_ENABLED; - - return (0); -} - -static int -rk8xx_regnode_set_voltage(struct regnode *regnode, int min_uvolt, - int max_uvolt, int *udelay) -{ - struct rk8xx_reg_sc *sc; - uint8_t val; - int uvolt; - - sc = regnode_get_softc(regnode); - - if (!sc->def->voltage_step) - return (ENXIO); - - dprintf(sc, "Setting %s to %d<->%d uvolts\n", - sc->def->name, - min_uvolt, - max_uvolt); - rk8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); - if (rk8xx_regnode_voltage_to_reg(sc, min_uvolt, max_uvolt, &val) != 0) - return (ERANGE); - - rk8xx_write(sc->base_dev, sc->def->voltage_reg, &val, 1); - - rk8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); - - *udelay = 0; - - rk8xx_regnode_reg_to_voltage(sc, val, &uvolt); - dprintf(sc, "Regulator %s set to %d uvolt\n", - sc->def->name, - uvolt); - - return (0); -} - -static int -rk8xx_regnode_get_voltage(struct regnode *regnode, int *uvolt) -{ - struct rk8xx_reg_sc *sc; - uint8_t val; - - sc = regnode_get_softc(regnode); - - if (sc->def->voltage_min == sc->def->voltage_max) { - *uvolt = sc->def->voltage_min; - return (0); - } - - if (!sc->def->voltage_step) - return (ENXIO); - - rk8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); - rk8xx_regnode_reg_to_voltage(sc, val & sc->def->voltage_mask, uvolt); - - dprintf(sc, "Regulator %s is at %d uvolt\n", - sc->def->name, - *uvolt); - - return (0); -} - -static regnode_method_t rk8xx_regnode_methods[] = { - /* Regulator interface */ - REGNODEMETHOD(regnode_init, rk8xx_regnode_init), - REGNODEMETHOD(regnode_enable, rk8xx_regnode_enable), - REGNODEMETHOD(regnode_status, rk8xx_regnode_status), - REGNODEMETHOD(regnode_set_voltage, rk8xx_regnode_set_voltage), - REGNODEMETHOD(regnode_get_voltage, rk8xx_regnode_get_voltage), - REGNODEMETHOD(regnode_check_voltage, regnode_method_check_voltage), - REGNODEMETHOD_END -}; -DEFINE_CLASS_1(rk8xx_regnode, rk8xx_regnode_class, rk8xx_regnode_methods, - sizeof(struct rk8xx_reg_sc), regnode_class); - -static struct rk8xx_reg_sc * -rk8xx_reg_attach(device_t dev, phandle_t node, - struct rk8xx_regdef *def) -{ - struct rk8xx_reg_sc *reg_sc; - struct regnode_init_def initdef; - struct regnode *regnode; - - memset(&initdef, 0, sizeof(initdef)); - if (regulator_parse_ofw_stdparam(dev, node, &initdef) != 0) { - device_printf(dev, "cannot create regulator\n"); - return (NULL); - } - if (initdef.std_param.min_uvolt == 0) - initdef.std_param.min_uvolt = def->voltage_min; - if (initdef.std_param.max_uvolt == 0) - initdef.std_param.max_uvolt = def->voltage_max; - initdef.id = def->id; - initdef.ofw_node = node; - - regnode = regnode_create(dev, &rk8xx_regnode_class, &initdef); - if (regnode == NULL) { - device_printf(dev, "cannot create regulator\n"); - return (NULL); - } - - reg_sc = regnode_get_softc(regnode); - reg_sc->regnode = regnode; - reg_sc->base_dev = dev; - reg_sc->def = def; - reg_sc->xref = OF_xref_from_node(node); - reg_sc->param = regnode_get_stdparam(regnode); - - regnode_register(regnode); - - return (reg_sc); -} - /* -------------------------------------------------------------------------- */ /* Clock class and method */ @@ -825,25 +597,6 @@ rk8xx_detach(device_t dev) return (EBUSY); } -static int -rk8xx_map(device_t dev, phandle_t xref, int ncells, - pcell_t *cells, intptr_t *id) -{ - struct rk8xx_softc *sc; - struct reg_list *regp; - - sc = device_get_softc(dev); - - TAILQ_FOREACH(regp, &sc->regs, next) { - if (regp->reg->xref == xref) { - *id = regp->reg->def->id; - return (0); - } - } - - return (ERANGE); -} - static device_method_t rk8xx_methods[] = { DEVMETHOD(device_probe, rk8xx_probe), DEVMETHOD(device_attach, rk8xx_attach), diff --git a/sys/dev/iicbus/pmic/rockchip/rk8xx.h b/sys/dev/iicbus/pmic/rockchip/rk8xx.h index 4351f8fe254c..8dc186beb5da 100644 --- a/sys/dev/iicbus/pmic/rockchip/rk8xx.h +++ b/sys/dev/iicbus/pmic/rockchip/rk8xx.h @@ -102,6 +102,12 @@ struct rk8xx_softc { int rk8xx_read(device_t dev, uint8_t reg, uint8_t *data, uint8_t size); int rk8xx_write(device_t dev, uint8_t reg, uint8_t *data, uint8_t size); +/* rk8xx_regulators.c */ +struct rk8xx_reg_sc *rk8xx_reg_attach(device_t dev, phandle_t node, + struct rk8xx_regdef *def); +int rk8xx_map(device_t dev, phandle_t xref, int ncells, + pcell_t *cells, intptr_t *id); + /* rk8xx_rtc.c */ int rk8xx_gettime(device_t dev, struct timespec *ts); int rk8xx_settime(device_t dev, struct timespec *ts); diff --git a/sys/dev/iicbus/pmic/rockchip/rk8xx_regulators.c b/sys/dev/iicbus/pmic/rockchip/rk8xx_regulators.c new file mode 100644 index 000000000000..015fbb1b26b3 --- /dev/null +++ b/sys/dev/iicbus/pmic/rockchip/rk8xx_regulators.c @@ -0,0 +1,290 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2018-2021 Emmanuel Vadot + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include "regdev_if.h" + +static int rk8xx_regnode_status(struct regnode *regnode, int *status); +static int rk8xx_regnode_set_voltage(struct regnode *regnode, int min_uvolt, + int max_uvolt, int *udelay); +static int rk8xx_regnode_get_voltage(struct regnode *regnode, int *uvolt); + +/* #define dprintf(sc, format, arg...) device_printf(sc->base_dev, "%s: " format, __func__, arg) */ +#define dprintf(sc, format, arg...) + +static int +rk8xx_regnode_init(struct regnode *regnode) +{ + struct rk8xx_reg_sc *sc; + struct regnode_std_param *param; + int rv, udelay, uvolt, status; + + sc = regnode_get_softc(regnode); + dprintf(sc, "Regulator %s init called\n", sc->def->name); + param = regnode_get_stdparam(regnode); + if (param->min_uvolt == 0) + return (0); + + /* Check that the regulator is preset to the correct voltage */ + rv = rk8xx_regnode_get_voltage(regnode, &uvolt); + if (rv != 0) + return(rv); + + if (uvolt >= param->min_uvolt && uvolt <= param->max_uvolt) + return(0); + /* + * Set the regulator at the correct voltage if it is not enabled. + * Do not enable it, this is will be done either by a + * consumer or by regnode_set_constraint if boot_on is true + */ + rv = rk8xx_regnode_status(regnode, &status); + if (rv != 0 || status == REGULATOR_STATUS_ENABLED) + return (rv); + + rv = rk8xx_regnode_set_voltage(regnode, param->min_uvolt, + param->max_uvolt, &udelay); + if (udelay != 0) + DELAY(udelay); + + return (rv); +} + +static int +rk8xx_regnode_enable(struct regnode *regnode, bool enable, int *udelay) +{ + struct rk8xx_reg_sc *sc; + uint8_t val; + + sc = regnode_get_softc(regnode); + + dprintf(sc, "%sabling regulator %s\n", + enable ? "En" : "Dis", + sc->def->name); + rk8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); + if (enable) + val |= sc->def->enable_mask; + else + val &= ~sc->def->enable_mask; + rk8xx_write(sc->base_dev, sc->def->enable_reg, &val, 1); + + *udelay = 0; + + return (0); +} + +static void +rk8xx_regnode_reg_to_voltage(struct rk8xx_reg_sc *sc, uint8_t val, int *uv) +{ + if (val < sc->def->voltage_nstep) + *uv = sc->def->voltage_min + val * sc->def->voltage_step; + else + *uv = sc->def->voltage_min + + (sc->def->voltage_nstep * sc->def->voltage_step); +} + +static int +rk8xx_regnode_voltage_to_reg(struct rk8xx_reg_sc *sc, int min_uvolt, + int max_uvolt, uint8_t *val) +{ + uint8_t nval; + int nstep, uvolt; + + nval = 0; + uvolt = sc->def->voltage_min; + + for (nstep = 0; nstep < sc->def->voltage_nstep && uvolt < min_uvolt; + nstep++) { + ++nval; + uvolt += sc->def->voltage_step; + } + if (uvolt > max_uvolt) + return (EINVAL); + + *val = nval; + return (0); +} + +static int +rk8xx_regnode_status(struct regnode *regnode, int *status) +{ + struct rk8xx_reg_sc *sc; + uint8_t val; + + sc = regnode_get_softc(regnode); + + *status = 0; + rk8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); + if (val & sc->def->enable_mask) + *status = REGULATOR_STATUS_ENABLED; + + return (0); +} + +static int +rk8xx_regnode_set_voltage(struct regnode *regnode, int min_uvolt, + int max_uvolt, int *udelay) +{ + struct rk8xx_reg_sc *sc; + uint8_t val; + int uvolt; + + sc = regnode_get_softc(regnode); + + if (!sc->def->voltage_step) + return (ENXIO); + + dprintf(sc, "Setting %s to %d<->%d uvolts\n", + sc->def->name, + min_uvolt, + max_uvolt); + rk8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); + if (rk8xx_regnode_voltage_to_reg(sc, min_uvolt, max_uvolt, &val) != 0) + return (ERANGE); + + rk8xx_write(sc->base_dev, sc->def->voltage_reg, &val, 1); + + rk8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); + + *udelay = 0; + + rk8xx_regnode_reg_to_voltage(sc, val, &uvolt); + dprintf(sc, "Regulator %s set to %d uvolt\n", + sc->def->name, + uvolt); + + return (0); +} + +static int +rk8xx_regnode_get_voltage(struct regnode *regnode, int *uvolt) +{ + struct rk8xx_reg_sc *sc; + uint8_t val; + + sc = regnode_get_softc(regnode); + + if (sc->def->voltage_min == sc->def->voltage_max) { + *uvolt = sc->def->voltage_min; + return (0); + } + + if (!sc->def->voltage_step) + return (ENXIO); + + rk8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); + rk8xx_regnode_reg_to_voltage(sc, val & sc->def->voltage_mask, uvolt); + + dprintf(sc, "Regulator %s is at %d uvolt\n", + sc->def->name, + *uvolt); + + return (0); +} + +static regnode_method_t rk8xx_regnode_methods[] = { + /* Regulator interface */ + REGNODEMETHOD(regnode_init, rk8xx_regnode_init), + REGNODEMETHOD(regnode_enable, rk8xx_regnode_enable), + REGNODEMETHOD(regnode_status, rk8xx_regnode_status), + REGNODEMETHOD(regnode_set_voltage, rk8xx_regnode_set_voltage), + REGNODEMETHOD(regnode_get_voltage, rk8xx_regnode_get_voltage), + REGNODEMETHOD(regnode_check_voltage, regnode_method_check_voltage), + REGNODEMETHOD_END +}; +DEFINE_CLASS_1(rk8xx_regnode, rk8xx_regnode_class, rk8xx_regnode_methods, + sizeof(struct rk8xx_reg_sc), regnode_class); + +struct rk8xx_reg_sc * +rk8xx_reg_attach(device_t dev, phandle_t node, + struct rk8xx_regdef *def) +{ + struct rk8xx_reg_sc *reg_sc; + struct regnode_init_def initdef; + struct regnode *regnode; + + memset(&initdef, 0, sizeof(initdef)); + if (regulator_parse_ofw_stdparam(dev, node, &initdef) != 0) { + device_printf(dev, "cannot create regulator\n"); + return (NULL); + } + if (initdef.std_param.min_uvolt == 0) + initdef.std_param.min_uvolt = def->voltage_min; + if (initdef.std_param.max_uvolt == 0) + initdef.std_param.max_uvolt = def->voltage_max; + initdef.id = def->id; + initdef.ofw_node = node; + + regnode = regnode_create(dev, &rk8xx_regnode_class, &initdef); + if (regnode == NULL) { + device_printf(dev, "cannot create regulator\n"); + return (NULL); + } + + reg_sc = regnode_get_softc(regnode); + reg_sc->regnode = regnode; + reg_sc->base_dev = dev; + reg_sc->def = def; + reg_sc->xref = OF_xref_from_node(node); + reg_sc->param = regnode_get_stdparam(regnode); + + regnode_register(regnode); + + return (reg_sc); +} + +int +rk8xx_map(device_t dev, phandle_t xref, int ncells, + pcell_t *cells, intptr_t *id) +{ + struct rk8xx_softc *sc; + struct reg_list *regp; + + sc = device_get_softc(dev); + + TAILQ_FOREACH(regp, &sc->regs, next) { + if (regp->reg->xref == xref) { + *id = regp->reg->def->id; + return (0); + } + } + + return (ERANGE); +}