Date: Wed, 4 Mar 2020 21:20:15 +0000 (UTC) From: Emmanuel Vadot <manu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r358648 - in stable/12/sys: arm64/conf arm64/rockchip conf modules/rockchip modules/rockchip/rk_spi Message-ID: <202003042120.024LKFXd030527@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: manu Date: Wed Mar 4 21:20:15 2020 New Revision: 358648 URL: https://svnweb.freebsd.org/changeset/base/358648 Log: MFC r356148-r356149, r356277 r356148: arm64: rockchip: rk808: Add remaining regulators The RK808 driver was missing the LDO and switch regulators. Add support for them. Reviewed by: mmel Differential Revision: https://reviews.freebsd.org/D22852 r356149: arm64: rockchip: Add driver for the io domain This driver configure the registers in the GRF according to the value of the regulators for the platform. Some IP can run with either 3.0V or 1.8V, if we don't configure them correctly according to the external voltage used they will not work. It's only done at boot time for now and might be needed at runtime for IP like sdmmc. Reviewed by: mmel Tested On: RockPro64, Firefly-RK3399 (gonzo), AIO-3288 (mmel) Differential Revision: https://reviews.freebsd.org/D22854 r356277: arm64: rockchip: Add a module for rk_spi The spi node doesn't lives under a simple-bus compatible node so we need OFWBUS_PNP_INFO instead of SIMPLEBUS_PNP_INFO. Added: stable/12/sys/arm64/rockchip/rk_iodomain.c - copied unchanged from r356149, head/sys/arm64/rockchip/rk_iodomain.c stable/12/sys/modules/rockchip/rk_spi/ - copied from r356277, head/sys/modules/rockchip/rk_spi/ Modified: stable/12/sys/arm64/conf/GENERIC stable/12/sys/arm64/rockchip/rk805.c stable/12/sys/arm64/rockchip/rk805reg.h stable/12/sys/arm64/rockchip/rk_spi.c stable/12/sys/conf/files.arm64 stable/12/sys/modules/rockchip/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/arm64/conf/GENERIC ============================================================================== --- stable/12/sys/arm64/conf/GENERIC Wed Mar 4 21:12:08 2020 (r358647) +++ stable/12/sys/arm64/conf/GENERIC Wed Mar 4 21:20:15 2020 (r358648) @@ -292,6 +292,9 @@ device regulator device syscon device aw_syscon +# IO Domains +device rk_iodomain + # The `bpf' device enables the Berkeley Packet Filter. # Be aware of the administrative consequences of enabling this! # Note that 'bpf' is required for DHCP. Modified: stable/12/sys/arm64/rockchip/rk805.c ============================================================================== --- stable/12/sys/arm64/rockchip/rk805.c Wed Mar 4 21:12:08 2020 (r358647) +++ stable/12/sys/arm64/rockchip/rk805.c Wed Mar 4 21:20:15 2020 (r358648) @@ -222,6 +222,114 @@ static struct rk805_regdef rk808_regdefs[] = { .voltage_step = 100000, .voltage_nstep = 16, }, + { + .id = RK808_LDO1, + .name = "LDO_REG1", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x1, + .voltage_reg = RK805_LDO1_ON_VSEL, + .voltage_mask = 0x1F, + .voltage_min = 1800000, + .voltage_max = 3400000, + .voltage_step = 100000, + .voltage_nstep = 17, + }, + { + .id = RK808_LDO2, + .name = "LDO_REG2", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x2, + .voltage_reg = RK805_LDO2_ON_VSEL, + .voltage_mask = 0x1F, + .voltage_min = 1800000, + .voltage_max = 3400000, + .voltage_step = 100000, + .voltage_nstep = 17, + }, + { + .id = RK808_LDO3, + .name = "LDO_REG3", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x4, + .voltage_reg = RK805_LDO3_ON_VSEL, + .voltage_mask = 0xF, + .voltage_min = 800000, + .voltage_max = 2500000, + .voltage_step = 100000, + .voltage_nstep = 18, + }, + { + .id = RK808_LDO4, + .name = "LDO_REG4", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x8, + .voltage_reg = RK808_LDO4_ON_VSEL, + .voltage_mask = 0x1F, + .voltage_min = 1800000, + .voltage_max = 3400000, + .voltage_step = 100000, + .voltage_nstep = 17, + }, + { + .id = RK808_LDO5, + .name = "LDO_REG5", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x10, + .voltage_reg = RK808_LDO5_ON_VSEL, + .voltage_mask = 0x1F, + .voltage_min = 1800000, + .voltage_max = 3400000, + .voltage_step = 100000, + .voltage_nstep = 17, + }, + { + .id = RK808_LDO6, + .name = "LDO_REG6", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x20, + .voltage_reg = RK808_LDO6_ON_VSEL, + .voltage_mask = 0x1F, + .voltage_min = 800000, + .voltage_max = 2500000, + .voltage_step = 100000, + .voltage_nstep = 18, + }, + { + .id = RK808_LDO7, + .name = "LDO_REG7", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x40, + .voltage_reg = RK808_LDO7_ON_VSEL, + .voltage_mask = 0x1F, + .voltage_min = 800000, + .voltage_max = 2500000, + .voltage_step = 100000, + .voltage_nstep = 18, + }, + { + .id = RK808_LDO8, + .name = "LDO_REG8", + .enable_reg = RK808_LDO_EN, + .enable_mask = 0x80, + .voltage_reg = RK808_LDO8_ON_VSEL, + .voltage_mask = 0x1F, + .voltage_min = 1800000, + .voltage_max = 3400000, + .voltage_step = 100000, + .voltage_nstep = 17, + }, + { + .id = RK808_SWITCH1, + .name = "SWITCH_REG1", + .enable_reg = RK805_DCDC_EN, + .enable_mask = 0x20, + }, + { + .id = RK808_SWITCH2, + .name = "SWITCH_REG2", + .enable_reg = RK805_DCDC_EN, + .enable_mask = 0x40, + }, }; static int Modified: stable/12/sys/arm64/rockchip/rk805reg.h ============================================================================== --- stable/12/sys/arm64/rockchip/rk805reg.h Wed Mar 4 21:12:08 2020 (r358647) +++ stable/12/sys/arm64/rockchip/rk805reg.h Wed Mar 4 21:20:15 2020 (r358648) @@ -59,6 +59,16 @@ #define RK805_LDO2_SLEEP_VSEL 0x3E #define RK805_LDO3_ON_VSEL 0x3F #define RK805_LDO3_SLEEP_VSEL 0x40 +#define RK808_LDO4_ON_VSEL 0x41 +#define RK808_LDO4_SLEEP_VSEL 0x42 +#define RK808_LDO5_ON_VSEL 0x43 +#define RK808_LDO5_SLEEP_VSEL 0x44 +#define RK808_LDO6_ON_VSEL 0x45 +#define RK808_LDO6_SLEEP_VSEL 0x46 +#define RK808_LDO7_ON_VSEL 0x47 +#define RK808_LDO7_SLEEP_VSEL 0x48 +#define RK808_LDO8_ON_VSEL 0x49 +#define RK808_LDO8_SLEEP_VSEL 0x4A enum rk805_regulator { RK805_DCDC1 = 0, Copied: stable/12/sys/arm64/rockchip/rk_iodomain.c (from r356149, head/sys/arm64/rockchip/rk_iodomain.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/12/sys/arm64/rockchip/rk_iodomain.c Wed Mar 4 21:20:15 2020 (r358648, copy of r356149, head/sys/arm64/rockchip/rk_iodomain.c) @@ -0,0 +1,207 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.org> + * + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/kernel.h> +#include <sys/module.h> + +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include <dev/extres/syscon/syscon.h> +#include <dev/extres/regulator/regulator.h> + +#include "syscon_if.h" + +#define RK3288_GRF_IO_VSEL 0x380 +#define RK3399_GRF_IO_VSEL 0xe640 +#define RK3399_PMUGRF_IO_VSEL 0x180 + +struct rk_iodomain_supply { + char *name; + uint32_t bit; +}; + +struct rk_iodomain_conf { + struct rk_iodomain_supply *supply; + int nsupply; + uint32_t grf_reg; +}; + +struct rk_iodomain_softc { + device_t dev; + struct syscon *grf; + phandle_t node; + struct rk_iodomain_conf *conf; +}; + +static struct rk_iodomain_supply rk3288_supply[] = { + {"lcdc-supply", 0}, + {"dvp-supply", 1}, + {"flash0-supply", 2}, + {"flash1-supply", 3}, + {"wifi-supply", 4}, + {"bb-supply", 5}, + {"audio-supply", 6}, + {"sdcard-supply", 7}, + {"gpio30-supply", 8}, + {"gpio1830-supply", 9}, +}; + +static struct rk_iodomain_conf rk3288_conf = { + .supply = rk3288_supply, + .nsupply = nitems(rk3288_supply), + .grf_reg = RK3288_GRF_IO_VSEL, +}; + +static struct rk_iodomain_supply rk3399_supply[] = { + {"bt656-supply", 0}, + {"audio-supply", 1}, + {"sdmmc-supply", 2}, + {"gpio1830-supply", 3}, +}; + +static struct rk_iodomain_conf rk3399_conf = { + .supply = rk3399_supply, + .nsupply = nitems(rk3399_supply), + .grf_reg = RK3399_GRF_IO_VSEL, +}; + +static struct rk_iodomain_supply rk3399_pmu_supply[] = { + {"pmu1830-supply", 9}, +}; + +static struct rk_iodomain_conf rk3399_pmu_conf = { + .supply = rk3399_pmu_supply, + .nsupply = nitems(rk3399_pmu_supply), + .grf_reg = RK3399_PMUGRF_IO_VSEL, +}; + +static struct ofw_compat_data compat_data[] = { + {"rockchip,rk3288-io-voltage-domain", (uintptr_t)&rk3288_conf}, + {"rockchip,rk3399-io-voltage-domain", (uintptr_t)&rk3399_conf}, + {"rockchip,rk3399-pmu-io-voltage-domain", (uintptr_t)&rk3399_pmu_conf}, + {NULL, 0} +}; + +static void +rk_iodomain_set(struct rk_iodomain_softc *sc) +{ + regulator_t supply; + uint32_t reg = 0; + uint32_t mask = 0; + int uvolt, i; + + for (i = 0; i < sc->conf->nsupply; i++) { + mask |= (1 << sc->conf->supply[i].bit) << 16; + if (regulator_get_by_ofw_property(sc->dev, sc->node, + sc->conf->supply[i].name, &supply) == 0) { + if (regulator_get_voltage(supply, &uvolt) == 0) { + if (uvolt == 1800000) + reg |= (1 << sc->conf->supply[i].bit); + else if (uvolt != 3000000) + device_printf(sc->dev, + "%s regulator is at %duV, ignoring\n", + sc->conf->supply[i].name, uvolt); + } else + device_printf(sc->dev, "Cannot get current " + "voltage for regulator %s\n", + sc->conf->supply[i].name); + } + } + + SYSCON_WRITE_4(sc->grf, sc->conf->grf_reg, reg | mask); +} + +static int +rk_iodomain_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + device_set_desc(dev, "RockChip IO Voltage Domain"); + return (BUS_PROBE_DEFAULT); +} + +static int +rk_iodomain_attach(device_t dev) +{ + struct rk_iodomain_softc *sc; + int rv; + + sc = device_get_softc(dev); + sc->dev = dev; + sc->node = ofw_bus_get_node(dev); + + rv = syscon_get_handle_default(dev, &sc->grf); + if (rv != 0) { + device_printf(dev, "Cannot get grf handle\n"); + return (ENXIO); + } + + sc->conf = (struct rk_iodomain_conf *)ofw_bus_search_compatible(dev, compat_data)->ocd_data; + rk_iodomain_set(sc); + + return (0); +} + +static int +rk_iodomain_detach(device_t dev) +{ + + return (0); +} + +static device_method_t rk_iodomain_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, rk_iodomain_probe), + DEVMETHOD(device_attach, rk_iodomain_attach), + DEVMETHOD(device_detach, rk_iodomain_detach), + + DEVMETHOD_END +}; + +static driver_t rk_iodomain_driver = { + "rk_iodomain", + rk_iodomain_methods, + sizeof(struct rk_iodomain_softc), +}; + +static devclass_t rk_iodomain_devclass; + +EARLY_DRIVER_MODULE(rk_iodomain, simplebus, rk_iodomain_driver, + rk_iodomain_devclass, 0, 0, BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE); Modified: stable/12/sys/arm64/rockchip/rk_spi.c ============================================================================== --- stable/12/sys/arm64/rockchip/rk_spi.c Wed Mar 4 21:12:08 2020 (r358647) +++ stable/12/sys/arm64/rockchip/rk_spi.c Wed Mar 4 21:20:15 2020 (r358648) @@ -480,4 +480,4 @@ static devclass_t rk_spi_devclass; DRIVER_MODULE(rk_spi, simplebus, rk_spi_driver, rk_spi_devclass, 0, 0); DRIVER_MODULE(ofw_spibus, rk_spi, ofw_spibus_driver, ofw_spibus_devclass, 0, 0); MODULE_DEPEND(rk_spi, ofw_spibus, 1, 1, 1); -SIMPLEBUS_PNP_INFO(compat_data); +OFWBUS_PNP_INFO(compat_data); Modified: stable/12/sys/conf/files.arm64 ============================================================================== --- stable/12/sys/conf/files.arm64 Wed Mar 4 21:12:08 2020 (r358647) +++ stable/12/sys/conf/files.arm64 Wed Mar 4 21:20:15 2020 (r358648) @@ -285,6 +285,7 @@ arm64/rockchip/rk805.c optional fdt rk805 soc_rockch 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 arm64/rockchip/rk_gpio.c optional fdt rk_gpio soc_rockchip_rk3328 | fdt rk_gpio soc_rockchip_rk3399 +arm64/rockchip/rk_iodomain.c optional fdt rk_iodomain arm64/rockchip/rk_spi.c optional fdt rk_spi arm64/rockchip/rk_usb2phy.c optional fdt rk_usb2phy soc_rockchip_rk3328 | soc_rockchip_rk3399 arm64/rockchip/rk_typec_phy.c optional fdt rk_typec_phy soc_rockchip_rk3399 Modified: stable/12/sys/modules/rockchip/Makefile ============================================================================== --- stable/12/sys/modules/rockchip/Makefile Wed Mar 4 21:12:08 2020 (r358647) +++ stable/12/sys/modules/rockchip/Makefile Wed Mar 4 21:20:15 2020 (r358648) @@ -3,6 +3,8 @@ SUBDIR = \ rk_i2c \ - rk805 + rk805 \ + rk_dwmmc \ + rk_spi .include <bsd.subdir.mk>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202003042120.024LKFXd030527>