From owner-svn-src-head@freebsd.org Tue Feb 26 13:18:16 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 152ED1519CE1; Tue, 26 Feb 2019 13:18:16 +0000 (UTC) (envelope-from manu@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AF3B985A53; Tue, 26 Feb 2019 13:18:15 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9E6655A95; Tue, 26 Feb 2019 13:18:15 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x1QDIFLM017947; Tue, 26 Feb 2019 13:18:15 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1QDIFvK017946; Tue, 26 Feb 2019 13:18:15 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201902261318.x1QDIFvK017946@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Tue, 26 Feb 2019 13:18:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r344580 - head/sys/arm64/rockchip X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/sys/arm64/rockchip X-SVN-Commit-Revision: 344580 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AF3B985A53 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Feb 2019 13:18:16 -0000 Author: manu Date: Tue Feb 26 13:18:14 2019 New Revision: 344580 URL: https://svnweb.freebsd.org/changeset/base/344580 Log: arm64: rockchip: rk805: Map the regulator No map function was provided before so every regulator lookup resolved the regulator with id 1, as it uses the default mapper, which is wrong. Correctly map the regulators. While here remove some debug printfs and make them disable by default. MFC after: 1 week Modified: head/sys/arm64/rockchip/rk805.c head/sys/arm64/rockchip/rk805reg.h Modified: head/sys/arm64/rockchip/rk805.c ============================================================================== --- head/sys/arm64/rockchip/rk805.c Tue Feb 26 13:17:09 2019 (r344579) +++ head/sys/arm64/rockchip/rk805.c Tue Feb 26 13:18:14 2019 (r344580) @@ -51,6 +51,9 @@ __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...) + enum rk_pmic_type { RK805 = 1, RK808, @@ -258,6 +261,9 @@ rk805_regnode_enable(struct regnode *regnode, bool ena sc = regnode_get_softc(regnode); + dprintf(sc, "%sabling regulator %s\n", + enable ? "En" : "Dis", + sc->def->name); rk805_read(sc->base_dev, sc->def->enable_reg, &val, 1); if (enable) val |= sc->def->enable_mask; @@ -308,25 +314,32 @@ rk805_regnode_set_voltage(struct regnode *regnode, int { struct rk805_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); 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; + rk805_regnode_reg_to_voltage(sc, val, &uvolt); + dprintf(sc, "Regulator %s set to %d uvolt\n", + sc->def->name, + uvolt); + return (0); } @@ -344,6 +357,10 @@ rk805_regnode_get_voltage(struct regnode *regnode, int rk805_read(sc->base_dev, sc->def->voltage_reg, &val, 1); rk805_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); } @@ -377,6 +394,7 @@ rk805_reg_attach(device_t dev, phandle_t node, initdef.std_param.max_uvolt = def->voltage_max; initdef.id = def->id; initdef.ofw_node = node; + regnode = regnode_create(dev, &rk805_regnode_class, &initdef); if (regnode == NULL) { device_printf(dev, "cannot create regulator\n"); @@ -504,11 +522,32 @@ rk805_detach(device_t dev) return (EBUSY); } +static int +rk805_map(device_t dev, phandle_t xref, int ncells, + pcell_t *cells, intptr_t *id) +{ + struct rk805_softc *sc; + int i; + + sc = device_get_softc(dev); + + for (i = 0; i < sc->nregs; i++) { + if (sc->regs[i]->xref == xref) { + *id = sc->regs[i]->def->id; + return (0); + } + } + + return (ERANGE); +} + static device_method_t rk805_methods[] = { DEVMETHOD(device_probe, rk805_probe), DEVMETHOD(device_attach, rk805_attach), DEVMETHOD(device_detach, rk805_detach), + /* regdev interface */ + DEVMETHOD(regdev_map, rk805_map), DEVMETHOD_END }; Modified: head/sys/arm64/rockchip/rk805reg.h ============================================================================== --- head/sys/arm64/rockchip/rk805reg.h Tue Feb 26 13:17:09 2019 (r344579) +++ head/sys/arm64/rockchip/rk805reg.h Tue Feb 26 13:18:14 2019 (r344580) @@ -61,7 +61,7 @@ #define RK805_LDO3_SLEEP_VSEL 0x40 enum rk805_regulator { - RK805_DCDC1, + RK805_DCDC1 = 0, RK805_DCDC2, RK805_DCDC3, RK805_DCDC4, @@ -71,7 +71,7 @@ enum rk805_regulator { }; enum rk808_regulator { - RK808_DCDC1, + RK808_DCDC1 = 0, RK808_DCDC2, RK808_DCDC3, RK808_DCDC4,