Index: head/sys/arm/rockchip/files.rk30xx =================================================================== --- head/sys/arm/rockchip/files.rk30xx +++ head/sys/arm/rockchip/files.rk30xx @@ -1,11 +0,0 @@ -# $FreeBSD$ - -arm/rockchip/rk30xx_machdep.c standard -arm/rockchip/rk30xx_pmu.c standard -arm/rockchip/rk30xx_grf.c standard -arm/rockchip/rk30xx_wdog.c standard -arm/rockchip/rk30xx_gpio.c optional gpio -arm/rockchip/rk30xx_mp.c optional smp - -dev/mmc/host/dwmmc.c optional dwmmc -dev/mmc/host/dwmmc_rockchip.c optional dwmmc Index: head/sys/arm/rockchip/rk30xx_gpio.c =================================================================== --- head/sys/arm/rockchip/rk30xx_gpio.c +++ head/sys/arm/rockchip/rk30xx_gpio.c @@ -1,630 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * Copyright (c) 2012 Oleksandr Tymoshenko - * Copyright (c) 2012 Luiz Otavio O Souza. - * All rights reserved. - * - * 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 - -#include -#include -#include - -#include -#include -#include -#include - -#include "gpio_if.h" - -#include "rk30xx_grf.h" -#include "rk30xx_pmu.h" - -/* - * RK3188 has 4 banks of gpio. - * 32 pins per bank - * PA0 - PA7 | PB0 - PB7 - * PC0 - PC7 | PD0 - PD7 - */ - -#define RK30_GPIO_PINS 32 -#define RK30_GPIO_DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ - GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN) - -#define RK30_GPIO_NONE 0 -#define RK30_GPIO_PULLUP 1 -#define RK30_GPIO_PULLDOWN 2 - -struct rk30_gpio_softc { - device_t sc_dev; - device_t sc_busdev; - struct mtx sc_mtx; - struct resource * sc_mem_res; - struct resource * sc_irq_res; - bus_space_tag_t sc_bst; - bus_space_handle_t sc_bsh; - void * sc_intrhand; - int sc_bank; - int sc_gpio_npins; - struct gpio_pin sc_gpio_pins[RK30_GPIO_PINS]; -}; - -/* We use our base address to find out our bank number. */ -static unsigned long rk30_gpio_base_addr[4] = - { 0x2000a000, 0x2003c000, 0x2003e000, 0x20080000 }; -static struct rk30_gpio_softc *rk30_gpio_sc = NULL; - -typedef int (*gpios_phandler_t)(phandle_t, pcell_t *, int); - -struct gpio_ctrl_entry { - const char *compat; - gpios_phandler_t handler; -}; - -int rk30_gpios_prop_handle(phandle_t ctrl, pcell_t *gpios, int len); -static int rk30_gpio_init(void); - -struct gpio_ctrl_entry gpio_controllers[] = { - { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle }, - { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle }, - { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle }, - { "rockchip,rk30xx-gpio", &rk30_gpios_prop_handle }, - { NULL, NULL } -}; - -#define RK30_GPIO_LOCK(_sc) mtx_lock(&_sc->sc_mtx) -#define RK30_GPIO_UNLOCK(_sc) mtx_unlock(&_sc->sc_mtx) -#define RK30_GPIO_LOCK_ASSERT(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED) - -#define RK30_GPIO_SWPORT_DR 0x00 -#define RK30_GPIO_SWPORT_DDR 0x04 -#define RK30_GPIO_INTEN 0x30 -#define RK30_GPIO_INTMASK 0x34 -#define RK30_GPIO_INTTYPE_LEVEL 0x38 -#define RK30_GPIO_INT_POLARITY 0x3c -#define RK30_GPIO_INT_STATUS 0x40 -#define RK30_GPIO_INT_RAWSTATUS 0x44 -#define RK30_GPIO_DEBOUNCE 0x48 -#define RK30_GPIO_PORT_EOI 0x4c -#define RK30_GPIO_EXT_PORT 0x50 -#define RK30_GPIO_LS_SYNC 0x60 - -#define RK30_GPIO_WRITE(_sc, _off, _val) \ - bus_space_write_4(_sc->sc_bst, _sc->sc_bsh, _off, _val) -#define RK30_GPIO_READ(_sc, _off) \ - bus_space_read_4(_sc->sc_bst, _sc->sc_bsh, _off) - -static uint32_t -rk30_gpio_get_function(struct rk30_gpio_softc *sc, uint32_t pin) -{ - - if (RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DDR) & (1U << pin)) - return (GPIO_PIN_OUTPUT); - else - return (GPIO_PIN_INPUT); -} - -static void -rk30_gpio_set_function(struct rk30_gpio_softc *sc, uint32_t pin, uint32_t func) -{ - uint32_t data; - - /* Must be called with lock held. */ - RK30_GPIO_LOCK_ASSERT(sc); - data = RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DDR); - if (func == GPIO_PIN_OUTPUT) - data |= (1U << pin); - else - data &= ~(1U << pin); - RK30_GPIO_WRITE(sc, RK30_GPIO_SWPORT_DDR, data); -} - -static void -rk30_gpio_set_pud(struct rk30_gpio_softc *sc, uint32_t pin, uint32_t state) -{ - uint32_t pud; - - /* Must be called with lock held. */ - RK30_GPIO_LOCK_ASSERT(sc); - switch (state) { - case GPIO_PIN_PULLUP: - pud = RK30_GPIO_PULLUP; - break; - case GPIO_PIN_PULLDOWN: - pud = RK30_GPIO_PULLDOWN; - break; - default: - pud = RK30_GPIO_NONE; - } - /* - * The pull up/down registers for GPIO0A and half of GPIO0B - * (the first 12 pins on bank 0) are at a different location. - */ - if (sc->sc_bank == 0 && pin < 12) - rk30_pmu_gpio_pud(pin, pud); - else - rk30_grf_gpio_pud(sc->sc_bank, pin, pud); -} - -static void -rk30_gpio_pin_configure(struct rk30_gpio_softc *sc, struct gpio_pin *pin, - unsigned int flags) -{ - - RK30_GPIO_LOCK(sc); - /* - * Manage input/output. - */ - if (flags & (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)) { - pin->gp_flags &= ~(GPIO_PIN_INPUT | GPIO_PIN_OUTPUT); - if (flags & GPIO_PIN_OUTPUT) - pin->gp_flags |= GPIO_PIN_OUTPUT; - else - pin->gp_flags |= GPIO_PIN_INPUT; - rk30_gpio_set_function(sc, pin->gp_pin, pin->gp_flags); - } - /* Manage Pull-up/pull-down. */ - pin->gp_flags &= ~(GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN); - if (flags & (GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN)) { - if (flags & GPIO_PIN_PULLUP) - pin->gp_flags |= GPIO_PIN_PULLUP; - else - pin->gp_flags |= GPIO_PIN_PULLDOWN; - } - rk30_gpio_set_pud(sc, pin->gp_pin, pin->gp_flags); - RK30_GPIO_UNLOCK(sc); -} - -static device_t -rk30_gpio_get_bus(device_t dev) -{ - struct rk30_gpio_softc *sc; - - sc = device_get_softc(dev); - - return (sc->sc_busdev); -} - -static int -rk30_gpio_pin_max(device_t dev, int *maxpin) -{ - - *maxpin = RK30_GPIO_PINS - 1; - return (0); -} - -static int -rk30_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) -{ - struct rk30_gpio_softc *sc = device_get_softc(dev); - int i; - - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - - if (i >= sc->sc_gpio_npins) - return (EINVAL); - - RK30_GPIO_LOCK(sc); - *caps = sc->sc_gpio_pins[i].gp_caps; - RK30_GPIO_UNLOCK(sc); - - return (0); -} - -static int -rk30_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) -{ - struct rk30_gpio_softc *sc = device_get_softc(dev); - int i; - - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - - if (i >= sc->sc_gpio_npins) - return (EINVAL); - - RK30_GPIO_LOCK(sc); - *flags = sc->sc_gpio_pins[i].gp_flags; - RK30_GPIO_UNLOCK(sc); - - return (0); -} - -static int -rk30_gpio_pin_getname(device_t dev, uint32_t pin, char *name) -{ - struct rk30_gpio_softc *sc = device_get_softc(dev); - int i; - - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - - if (i >= sc->sc_gpio_npins) - return (EINVAL); - - RK30_GPIO_LOCK(sc); - memcpy(name, sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME); - RK30_GPIO_UNLOCK(sc); - - return (0); -} - -static int -rk30_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) -{ - struct rk30_gpio_softc *sc = device_get_softc(dev); - int i; - - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - - if (i >= sc->sc_gpio_npins) - return (EINVAL); - - rk30_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags); - - return (0); -} - -static int -rk30_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) -{ - int i; - struct rk30_gpio_softc *sc; - uint32_t data; - - sc = device_get_softc(dev); - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->sc_gpio_npins) - return (EINVAL); - RK30_GPIO_LOCK(sc); - data = RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DR); - if (value) - data |= (1U << pin); - else - data &= ~(1U << pin); - RK30_GPIO_WRITE(sc, RK30_GPIO_SWPORT_DR, data); - RK30_GPIO_UNLOCK(sc); - - return (0); -} - -static int -rk30_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) -{ - int i; - struct rk30_gpio_softc *sc; - uint32_t data; - - sc = device_get_softc(dev); - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->sc_gpio_npins) - return (EINVAL); - RK30_GPIO_LOCK(sc); - data = RK30_GPIO_READ(sc, RK30_GPIO_EXT_PORT); - RK30_GPIO_UNLOCK(sc); - *val = (data & (1U << pin)) ? 1 : 0; - - return (0); -} - -static int -rk30_gpio_pin_toggle(device_t dev, uint32_t pin) -{ - int i; - struct rk30_gpio_softc *sc; - uint32_t data; - - sc = device_get_softc(dev); - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->sc_gpio_npins) - return (EINVAL); - RK30_GPIO_LOCK(sc); - data = RK30_GPIO_READ(sc, RK30_GPIO_SWPORT_DR); - if (data & (1U << pin)) - data &= ~(1U << pin); - else - data |= (1U << pin); - RK30_GPIO_WRITE(sc, RK30_GPIO_SWPORT_DR, data); - RK30_GPIO_UNLOCK(sc); - - return (0); -} - -static int -rk30_gpio_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - - if (!ofw_bus_is_compatible(dev, "rockchip,rk30xx-gpio")) - return (ENXIO); - - device_set_desc(dev, "Rockchip RK30XX GPIO controller"); - return (BUS_PROBE_DEFAULT); -} - -static int -rk30_gpio_attach(device_t dev) -{ - struct rk30_gpio_softc *sc = device_get_softc(dev); - int i, rid; - phandle_t gpio; - unsigned long start; - - if (rk30_gpio_sc) - return (ENXIO); - sc->sc_dev = dev; - mtx_init(&sc->sc_mtx, "rk30 gpio", "gpio", MTX_DEF); - - rid = 0; - sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, - RF_ACTIVE); - if (!sc->sc_mem_res) { - device_printf(dev, "cannot allocate memory window\n"); - goto fail; - } - sc->sc_bst = rman_get_bustag(sc->sc_mem_res); - sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res); - /* Check the unit we are attaching by our base address. */ - sc->sc_bank = -1; - start = rman_get_start(sc->sc_mem_res); - for (i = 0; i < nitems(rk30_gpio_base_addr); i++) { - if (rk30_gpio_base_addr[i] == start) { - sc->sc_bank = i; - break; - } - } - if (sc->sc_bank == -1) { - device_printf(dev, - "unsupported device unit (only GPIO0..3 are supported)\n"); - goto fail; - } - - rid = 0; - sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, - RF_ACTIVE); - if (!sc->sc_irq_res) { - device_printf(dev, "cannot allocate interrupt\n"); - goto fail; - } - - /* Find our node. */ - gpio = ofw_bus_get_node(sc->sc_dev); - - if (!OF_hasprop(gpio, "gpio-controller")) - /* Node is not a GPIO controller. */ - goto fail; - - /* Initialize the software controlled pins. */ - for (i = 0; i < RK30_GPIO_PINS; i++) { - snprintf(sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME, - "pin %d", i); - sc->sc_gpio_pins[i].gp_pin = i; - sc->sc_gpio_pins[i].gp_caps = RK30_GPIO_DEFAULT_CAPS; - sc->sc_gpio_pins[i].gp_flags = rk30_gpio_get_function(sc, i); - } - sc->sc_gpio_npins = i; - rk30_gpio_sc = sc; - rk30_gpio_init(); - sc->sc_busdev = gpiobus_attach_bus(dev); - if (sc->sc_busdev == NULL) - goto fail; - - return (0); - -fail: - if (sc->sc_irq_res) - bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); - if (sc->sc_mem_res) - bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); - mtx_destroy(&sc->sc_mtx); - - return (ENXIO); -} - -static int -rk30_gpio_detach(device_t dev) -{ - - return (EBUSY); -} - -static device_method_t rk30_gpio_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, rk30_gpio_probe), - DEVMETHOD(device_attach, rk30_gpio_attach), - DEVMETHOD(device_detach, rk30_gpio_detach), - - /* GPIO protocol */ - DEVMETHOD(gpio_get_bus, rk30_gpio_get_bus), - DEVMETHOD(gpio_pin_max, rk30_gpio_pin_max), - DEVMETHOD(gpio_pin_getname, rk30_gpio_pin_getname), - DEVMETHOD(gpio_pin_getflags, rk30_gpio_pin_getflags), - DEVMETHOD(gpio_pin_getcaps, rk30_gpio_pin_getcaps), - DEVMETHOD(gpio_pin_setflags, rk30_gpio_pin_setflags), - DEVMETHOD(gpio_pin_get, rk30_gpio_pin_get), - DEVMETHOD(gpio_pin_set, rk30_gpio_pin_set), - DEVMETHOD(gpio_pin_toggle, rk30_gpio_pin_toggle), - - DEVMETHOD_END -}; - -static devclass_t rk30_gpio_devclass; - -static driver_t rk30_gpio_driver = { - "gpio", - rk30_gpio_methods, - sizeof(struct rk30_gpio_softc), -}; - -DRIVER_MODULE(rk30_gpio, simplebus, rk30_gpio_driver, rk30_gpio_devclass, 0, 0); - -int -rk30_gpios_prop_handle(phandle_t ctrl, pcell_t *gpios, int len) -{ - struct rk30_gpio_softc *sc; - pcell_t gpio_cells; - int inc, t, tuples, tuple_size; - int dir, flags, pin, i; - u_long gpio_ctrl, size; - - sc = rk30_gpio_sc; - if (sc == NULL) - return ENXIO; - - if (OF_getencprop(ctrl, "#gpio-cells", &gpio_cells, sizeof(pcell_t)) < 0) - return (ENXIO); - if (gpio_cells != 2) - return (ENXIO); - - tuple_size = gpio_cells * sizeof(pcell_t) + sizeof(phandle_t); - tuples = len / tuple_size; - - if (fdt_regsize(ctrl, &gpio_ctrl, &size)) - return (ENXIO); - - /* - * Skip controller reference, since controller's phandle is given - * explicitly (in a function argument). - */ - inc = sizeof(ihandle_t) / sizeof(pcell_t); - gpios += inc; - for (t = 0; t < tuples; t++) { - pin = gpios[0]; - dir = gpios[1]; - flags = gpios[2]; - - for (i = 0; i < sc->sc_gpio_npins; i++) { - if (sc->sc_gpio_pins[i].gp_pin == pin) - break; - } - if (i >= sc->sc_gpio_npins) - return (EINVAL); - - rk30_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags); - - if (dir == 1) { - /* Input. */ - rk30_gpio_pin_set(sc->sc_dev, pin, GPIO_PIN_INPUT); - } else { - /* Output. */ - rk30_gpio_pin_set(sc->sc_dev, pin, GPIO_PIN_OUTPUT); - } - gpios += gpio_cells + inc; - } - - return (0); -} - -#define MAX_PINS_PER_NODE 5 -#define GPIOS_PROP_CELLS 4 - -static int -rk30_gpio_init(void) -{ - phandle_t child, parent, root, ctrl; - pcell_t gpios[MAX_PINS_PER_NODE * GPIOS_PROP_CELLS]; - struct gpio_ctrl_entry *e; - int len, rv; - - root = OF_finddevice("/"); - len = 0; - parent = root; - - /* Traverse through entire tree to find nodes with 'gpios' prop */ - for (child = OF_child(parent); child != 0; child = OF_peer(child)) { - /* Find a 'leaf'. Start the search from this node. */ - while (OF_child(child)) { - parent = child; - child = OF_child(child); - } - if ((len = OF_getproplen(child, "gpios")) > 0) { - if (len > sizeof(gpios)) - return (ENXIO); - - /* Get 'gpios' property. */ - OF_getencprop(child, "gpios", gpios, len); - - e = (struct gpio_ctrl_entry *)&gpio_controllers; - - /* Find and call a handler. */ - for (; e->compat; e++) { - /* - * First cell of 'gpios' property should - * contain a ref. to a node defining GPIO - * controller. - */ - ctrl = OF_node_from_xref(gpios[0]); - - if (ofw_bus_node_is_compatible(ctrl, e->compat)) - /* Call a handler. */ - if ((rv = e->handler(ctrl, - (pcell_t *)&gpios, len))) - return (rv); - } - } - - if (OF_peer(child) == 0) { - /* No more siblings. */ - child = parent; - parent = OF_parent(child); - } - } - return (0); -} Index: head/sys/arm/rockchip/rk30xx_grf.h =================================================================== --- head/sys/arm/rockchip/rk30xx_grf.h +++ head/sys/arm/rockchip/rk30xx_grf.h @@ -1,143 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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. - * - * $FreeBSD$ - */ - -#ifndef _RK30_GRF_H_ -#define _RK30_GRF_H_ - -#define RK30_GRF_BASE 0xF0008000 - -#define GRF_GPIO0L_DIR 0x0000 -#define GRF_GPIO0H_DIR 0x0004 -#define GRF_GPIO1L_DIR 0x0008 -#define GRF_GPIO1H_DIR 0x000c -#define GRF_GPIO2L_DIR 0x0010 -#define GRF_GPIO2H_DIR 0x0014 -#define GRF_GPIO3L_DIR 0x0018 -#define GRF_GPIO3H_DIR 0x001c -#define GRF_GPIO0L_DO 0x0020 -#define GRF_GPIO0H_DO 0x0024 -#define GRF_GPIO1L_DO 0x0028 -#define GRF_GPIO1H_DO 0x002c -#define GRF_GPIO2L_DO 0x0030 -#define GRF_GPIO2H_DO 0x0034 -#define GRF_GPIO3L_DO 0x0038 -#define GRF_GPIO3H_DO 0x003c -#define GRF_GPIO0L_EN 0x0040 -#define GRF_GPIO0H_EN 0x0044 -#define GRF_GPIO1L_EN 0x0048 -#define GRF_GPIO1H_EN 0x004c -#define GRF_GPIO2L_EN 0x0050 -#define GRF_GPIO2H_EN 0x0054 -#define GRF_GPIO3L_EN 0x0058 -#define GRF_GPIO3H_EN 0x005c - -#define GRF_GPIO0C_IOMUX 0x0068 -#define GRF_GPIO0D_IOMUX 0x006c -#define GRF_GPIO1A_IOMUX 0x0070 -#define GRF_GPIO1B_IOMUX 0x0074 -#define GRF_GPIO1C_IOMUX 0x0078 -#define GRF_GPIO1D_IOMUX 0x007c -#define GRF_GPIO2A_IOMUX 0x0080 -#define GRF_GPIO2B_IOMUX 0x0084 -#define GRF_GPIO2C_IOMUX 0x0088 -#define GRF_GPIO2D_IOMUX 0x008c -#define GRF_GPIO3A_IOMUX 0x0090 -#define GRF_GPIO3B_IOMUX 0x0094 -#define GRF_GPIO3C_IOMUX 0x0098 -#define GRF_GPIO3D_IOMUX 0x009c -#define GRF_SOC_CON0 0x00a0 -#define GRF_SOC_CON1 0x00a4 -#define GRF_SOC_CON2 0x00a8 -#define GRF_SOC_STATUS0 0x00ac -#define GRF_DMAC1_CON0 0x00b0 -#define GRF_DMAC1_CON1 0x00b4 -#define GRF_DMAC1_CON2 0x00b8 -#define GRF_DMAC2_CON0 0x00bc -#define GRF_DMAC2_CON1 0x00c0 -#define GRF_DMAC2_CON2 0x00c4 -#define GRF_DMAC2_CON3 0x00c8 -#define GRF_CPU_CON0 0x00cc -#define GRF_CPU_CON1 0x00d0 -#define GRF_CPU_CON2 0x00d4 -#define GRF_CPU_CON3 0x00d8 -#define GRF_CPU_CON4 0x00dc -#define GRF_CPU_CON5 0x00e0 - -#define GRF_DDRC_CON0 0x00ec -#define GRF_DDRC_STAT 0x00f0 -#define GRF_IO_CON0 0x00f4 -#define GRF_IO_CON1 0x00f8 -#define GRF_IO_CON2 0x00fc -#define GRF_IO_CON3 0x0100 -#define GRF_IO_CON4 0x0104 -#define GRF_SOC_STATUS1 0x0108 -#define GRF_UOC0_CON0 0x010c -#define GRF_UOC0_CON1 0x0110 -#define GRF_UOC0_CON2 0x0114 -#define GRF_UOC0_CON3 0x0118 -#define GRF_UOC1_CON0 0x011c -#define GRF_UOC1_CON1 0x0120 -#define GRF_UOC1_CON2 0x0124 -#define GRF_UOC1_CON3 0x0128 -#define GRF_UOC2_CON0 0x012c -#define GRF_UOC2_CON1 0x0130 - -#define GRF_UOC3_CON0 0x0138 -#define GRF_UOC3_CON1 0x013c -#define GRF_HSIC_STAT 0x0140 -#define GRF_OS_REG0 0x0144 -#define GRF_OS_REG1 0x0148 -#define GRF_OS_REG2 0x014c -#define GRF_OS_REG3 0x0150 -#define GRF_OS_REG4 0x0154 -#define GRF_OS_REG5 0x0158 -#define GRF_OS_REG6 0x015c -#define GRF_OS_REG7 0x0160 -#define GRF_GPIO0B_PULL 0x0164 -#define GRF_GPIO0C_PULL 0x0168 -#define GRF_GPIO0D_PULL 0x016c -#define GRF_GPIO1A_PULL 0x0170 -#define GRF_GPIO1B_PULL 0x0174 -#define GRF_GPIO1C_PULL 0x0178 -#define GRF_GPIO1D_PULL 0x017c -#define GRF_GPIO2A_PULL 0x0180 -#define GRF_GPIO2B_PULL 0x0184 -#define GRF_GPIO2C_PULL 0x0188 -#define GRF_GPIO2D_PULL 0x018c -#define GRF_GPIO3A_PULL 0x0190 -#define GRF_GPIO3B_PULL 0x0194 -#define GRF_GPIO3C_PULL 0x0198 -#define GRF_GPIO3D_PULL 0x019c -#define GRF_FLASH_DATA_PULL 0x01a0 -#define GRF_FLASH_CMD_PULL 0x01a4 - -void rk30_grf_gpio_pud(uint32_t bank, uint32_t pin, uint32_t state); - -#endif /* _RK30_GRF_H_ */ Index: head/sys/arm/rockchip/rk30xx_grf.c =================================================================== --- head/sys/arm/rockchip/rk30xx_grf.c +++ head/sys/arm/rockchip/rk30xx_grf.c @@ -1,131 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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. - */ - -/* General Register File for Rockchip RK30xx */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "rk30xx_grf.h" - -struct rk30_grf_softc { - struct resource *res; - bus_space_tag_t bst; - bus_space_handle_t bsh; -}; - -static struct rk30_grf_softc *rk30_grf_sc = NULL; - -#define grf_read_4(sc, reg) \ - bus_space_read_4((sc)->bst, (sc)->bsh, (reg)) -#define grf_write_4(sc, reg, val) \ - bus_space_write_4((sc)->bst, (sc)->bsh, (reg), (val)) - -static int -rk30_grf_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - - if (ofw_bus_is_compatible(dev, "rockchip,rk30xx-grf")) { - device_set_desc(dev, "RK30XX General Register File"); - return(BUS_PROBE_DEFAULT); - } - - return (ENXIO); -} - -static int -rk30_grf_attach(device_t dev) -{ - struct rk30_grf_softc *sc = device_get_softc(dev); - int rid = 0; - - if (rk30_grf_sc) - return (ENXIO); - - sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (!sc->res) { - device_printf(dev, "could not allocate resource\n"); - return (ENXIO); - } - - sc->bst = rman_get_bustag(sc->res); - sc->bsh = rman_get_bushandle(sc->res); - - rk30_grf_sc = sc; - - return (0); -} - -static device_method_t rk30_grf_methods[] = { - DEVMETHOD(device_probe, rk30_grf_probe), - DEVMETHOD(device_attach, rk30_grf_attach), - { 0, 0 } -}; - -static driver_t rk30_grf_driver = { - "rk30_grf", - rk30_grf_methods, - sizeof(struct rk30_grf_softc), -}; - -static devclass_t rk30_grf_devclass; - -DRIVER_MODULE(rk30_grf, simplebus, rk30_grf_driver, rk30_grf_devclass, 0, 0); - -void -rk30_grf_gpio_pud(uint32_t bank, uint32_t pin, uint32_t state) -{ - uint32_t offset; - - offset = GRF_GPIO0B_PULL - 4 + (bank * 16) + ((pin / 8) * 4); - pin = (7 - (pin % 8)) * 2; - grf_write_4(rk30_grf_sc, offset, (0x3 << (16 + pin)) | (state << pin)); -} Index: head/sys/arm/rockchip/rk30xx_machdep.c =================================================================== --- head/sys/arm/rockchip/rk30xx_machdep.c +++ head/sys/arm/rockchip/rk30xx_machdep.c @@ -1,105 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * All rights reserved. - * - * This code is derived from software written for Brini by Mark Brinicombe - * - * 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. - * - * from: FreeBSD: //depot/projects/arm/src/sys/arm/ti/ti_machdep.c - */ - -#include "opt_ddb.h" -#include "opt_platform.h" - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include "platform_if.h" - -static platform_devmap_init_t rk30xx_devmap_init; -static platform_late_init_t rk30xx_late_init; -static platform_cpu_reset_t rk30xx_cpu_reset; - -static void -rk30xx_late_init(platform_t plat) -{ - - /* Enable cache */ - cpufunc_control(CPU_CONTROL_DC_ENABLE|CPU_CONTROL_IC_ENABLE, - CPU_CONTROL_DC_ENABLE|CPU_CONTROL_IC_ENABLE); -} - -/* - * Set up static device mappings. - */ -static int -rk30xx_devmap_init(platform_t plat) -{ - - devmap_add_entry(0x10000000, 0x00200000); - devmap_add_entry(0x20000000, 0x00100000); - - return (0); -} - -static void -rk30xx_cpu_reset(platform_t plat) -{ - - rk30_wd_watchdog_reset(); - printf("Reset failed!\n"); - while (1); -} - -#if defined(SOC_ROCKCHIP_RK3188) -static platform_method_t rk30xx_methods[] = { - PLATFORMMETHOD(platform_devmap_init, rk30xx_devmap_init), - PLATFORMMETHOD(platform_late_init, rk30xx_late_init), - PLATFORMMETHOD(platform_cpu_reset, rk30xx_cpu_reset), - -#ifdef SMP - PLATFORMMETHOD(platform_mp_start_ap, rk30xx_mp_start_ap), - PLATFORMMETHOD(platform_mp_setmaxid, rk30xx_mp_setmaxid), -#endif - PLATFORMMETHOD_END, -}; -FDT_PLATFORM_DEF(rk30xx, "RK3188", 0, "rockchip,rk3188", 200); -#endif Index: head/sys/arm/rockchip/rk30xx_mp.h =================================================================== --- head/sys/arm/rockchip/rk30xx_mp.h +++ head/sys/arm/rockchip/rk30xx_mp.h @@ -1,38 +0,0 @@ -/*- - * Copyright (C) 2016 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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 - * - * 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. - * - * $FreeBSD$ - */ - -#ifndef _RK30XX_MP_H_ -#define _RK30XX_MP_H_ - -void rk30xx_mp_setmaxid(platform_t plat); -void rk30xx_mp_start_ap(platform_t plat); - -#endif /* _RK30XX_MP_H_ */ Index: head/sys/arm/rockchip/rk30xx_mp.c =================================================================== --- head/sys/arm/rockchip/rk30xx_mp.c +++ head/sys/arm/rockchip/rk30xx_mp.c @@ -1,176 +0,0 @@ -/*- - * Copyright (c) 2014 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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 ``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 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 - -#include -#include -#include -#include -#include -#include - -#include - -#define SCU_PHYSBASE 0x1013c000 -#define SCU_SIZE 0x100 - -#define SCU_CONTROL_REG 0x00 -#define SCU_CONTROL_ENABLE (1 << 0) -#define SCU_STANDBY_EN (1 << 5) -#define SCU_CONFIG_REG 0x04 -#define SCU_CONFIG_REG_NCPU_MASK 0x03 -#define SCU_CPUPOWER_REG 0x08 -#define SCU_INV_TAGS_REG 0x0c - -#define SCU_FILTER_START_REG 0x10 -#define SCU_FILTER_END_REG 0x14 -#define SCU_SECURE_ACCESS_REG 0x18 -#define SCU_NONSECURE_ACCESS_REG 0x1c - -#define IMEM_PHYSBASE 0x10080000 -#define IMEM_SIZE 0x20 - -#define PMU_PHYSBASE 0x20004000 -#define PMU_SIZE 0x100 -#define PMU_PWRDN_CON 0x08 -#define PMU_PWRDN_SCU (1 << 4) - -extern char *mpentry_addr; -static void rk30xx_boot2(void); - -static void -rk30xx_boot2(void) -{ - - __asm __volatile( - "ldr pc, 1f\n" - ".globl mpentry_addr\n" - "mpentry_addr:\n" - "1: .space 4\n"); -} - -void -rk30xx_mp_setmaxid(platform_t plat) -{ - bus_space_handle_t scu; - int ncpu; - uint32_t val; - - if (mp_ncpus != 0) - return; - - if (bus_space_map(fdtbus_bs_tag, SCU_PHYSBASE, SCU_SIZE, 0, &scu) != 0) - panic("Could not map the SCU"); - - val = bus_space_read_4(fdtbus_bs_tag, scu, SCU_CONFIG_REG); - ncpu = (val & SCU_CONFIG_REG_NCPU_MASK) + 1; - bus_space_unmap(fdtbus_bs_tag, scu, SCU_SIZE); - - mp_ncpus = ncpu; - mp_maxid = ncpu - 1; -} - -void -rk30xx_mp_start_ap(platform_t plat) -{ - bus_space_handle_t scu; - bus_space_handle_t imem; - bus_space_handle_t pmu; - uint32_t val; - int i; - - if (bus_space_map(fdtbus_bs_tag, SCU_PHYSBASE, SCU_SIZE, 0, &scu) != 0) - panic("Could not map the SCU"); - if (bus_space_map(fdtbus_bs_tag, IMEM_PHYSBASE, - IMEM_SIZE, 0, &imem) != 0) - panic("Could not map the IMEM"); - if (bus_space_map(fdtbus_bs_tag, PMU_PHYSBASE, PMU_SIZE, 0, &pmu) != 0) - panic("Could not map the PMU"); - - /* - * Invalidate SCU cache tags. The 0x0000ffff constant invalidates all - * ways on all cores 0-3. Per the ARM docs, it's harmless to write to - * the bits for cores that are not present. - */ - bus_space_write_4(fdtbus_bs_tag, scu, SCU_INV_TAGS_REG, 0x0000ffff); - - /* Make sure all cores except the first are off */ - val = bus_space_read_4(fdtbus_bs_tag, pmu, PMU_PWRDN_CON); - for (i = 1; i < mp_ncpus; i++) - val |= 1 << i; - bus_space_write_4(fdtbus_bs_tag, pmu, PMU_PWRDN_CON, val); - - /* Enable SCU power domain */ - val = bus_space_read_4(fdtbus_bs_tag, pmu, PMU_PWRDN_CON); - val &= ~PMU_PWRDN_SCU; - bus_space_write_4(fdtbus_bs_tag, pmu, PMU_PWRDN_CON, val); - - /* Enable SCU */ - val = bus_space_read_4(fdtbus_bs_tag, scu, SCU_CONTROL_REG); - bus_space_write_4(fdtbus_bs_tag, scu, SCU_CONTROL_REG, - val | SCU_CONTROL_ENABLE); - - /* - * Cores will execute the code which resides at the start of - * the on-chip bootram/sram after power-on. This sram region - * should be reserved and the trampoline code that directs - * the core to the real startup code in ram should be copied - * into this sram region. - * - * First set boot function for the sram code. - */ - mpentry_addr = (char *)pmap_kextract((vm_offset_t)mpentry); - - /* Copy trampoline to sram, that runs during startup of the core */ - bus_space_write_region_4(fdtbus_bs_tag, imem, 0, - (uint32_t *)&rk30xx_boot2, 8); - - dcache_wbinv_poc_all(); - - /* Start all cores */ - val = bus_space_read_4(fdtbus_bs_tag, pmu, PMU_PWRDN_CON); - for (i = 1; i < mp_ncpus; i++) - val &= ~(1 << i); - bus_space_write_4(fdtbus_bs_tag, pmu, PMU_PWRDN_CON, val); - - dsb(); - sev(); - - bus_space_unmap(fdtbus_bs_tag, scu, SCU_SIZE); - bus_space_unmap(fdtbus_bs_tag, imem, IMEM_SIZE); - bus_space_unmap(fdtbus_bs_tag, pmu, PMU_SIZE); -} Index: head/sys/arm/rockchip/rk30xx_pmu.h =================================================================== --- head/sys/arm/rockchip/rk30xx_pmu.h +++ head/sys/arm/rockchip/rk30xx_pmu.h @@ -1,62 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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. - * - * $FreeBSD$ - */ - -#ifndef _RK30_PMU_H_ -#define _RK30_PMU_H_ - -#define RK30_PMU_BASE 0xF0004000 - -#define PMU_WAKEUP_CFG0 0x00 -#define PMU_WAKEUP_CFG1 0x04 -#define PMU_PWRDN_CON 0x08 -#define PMU_PWRDN_ST 0x0c -#define PMU_INT_CON 0x10 -#define PMU_INT_ST 0x14 -#define PMU_MISC_CON 0x18 -#define PMU_OSC_CNT 0x1c -#define PMU_PLL_CNT 0x20 -#define PMU_PMU_CNT 0x24 -#define PMU_DDRIO_PWRON_CNT 0x28 -#define PMU_WAKEUP_RST_CLR_CNT 0x2c -#define PMU_SCU_PWRDWN_CNT 0x30 -#define PMU_SCU_PWRUP_CNT 0x34 -#define PMU_MISC_CON1 0x38 -#define PMU_GPIO0_CON 0x3c -#define PMU_SYS_REG0 0x40 -#define PMU_SYS_REG1 0x44 -#define PMU_SYS_REG2 0x48 -#define PMU_SYS_REG3 0x4c -#define PMU_STOP_INT_DLY 0x60 -#define PMU_GPIO0A_PULL 0x64 -#define PMU_GPIO0B_PULL 0x68 - -void rk30_pmu_gpio_pud(uint32_t pin, uint32_t state); - -#endif /* _RK30_PMU_H_ */ Index: head/sys/arm/rockchip/rk30xx_pmu.c =================================================================== --- head/sys/arm/rockchip/rk30xx_pmu.c +++ head/sys/arm/rockchip/rk30xx_pmu.c @@ -1,131 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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. - */ - -/* PMU for Rockchip RK30xx */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "rk30xx_pmu.h" - -struct rk30_pmu_softc { - struct resource *res; - bus_space_tag_t bst; - bus_space_handle_t bsh; -}; - -static struct rk30_pmu_softc *rk30_pmu_sc = NULL; - -#define pmu_read_4(sc, reg) \ - bus_space_read_4((sc)->bst, (sc)->bsh, (reg)) -#define pmu_write_4(sc, reg, val) \ - bus_space_write_4((sc)->bst, (sc)->bsh, (reg), (val)) - -static int -rk30_pmu_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - - if (ofw_bus_is_compatible(dev, "rockchip,rk30xx-pmu")) { - device_set_desc(dev, "RK30XX PMU"); - return(BUS_PROBE_DEFAULT); - } - - return (ENXIO); -} - -static int -rk30_pmu_attach(device_t dev) -{ - struct rk30_pmu_softc *sc = device_get_softc(dev); - int rid = 0; - - if (rk30_pmu_sc) - return (ENXIO); - - sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (!sc->res) { - device_printf(dev, "could not allocate resource\n"); - return (ENXIO); - } - - sc->bst = rman_get_bustag(sc->res); - sc->bsh = rman_get_bushandle(sc->res); - - rk30_pmu_sc = sc; - - return (0); -} - -static device_method_t rk30_pmu_methods[] = { - DEVMETHOD(device_probe, rk30_pmu_probe), - DEVMETHOD(device_attach, rk30_pmu_attach), - { 0, 0 } -}; - -static driver_t rk30_pmu_driver = { - "rk30_pmu", - rk30_pmu_methods, - sizeof(struct rk30_pmu_softc), -}; - -static devclass_t rk30_pmu_devclass; - -DRIVER_MODULE(rk30_pmu, simplebus, rk30_pmu_driver, rk30_pmu_devclass, 0, 0); - -void -rk30_pmu_gpio_pud(uint32_t pin, uint32_t state) -{ - uint32_t offset; - - offset = PMU_GPIO0A_PULL + ((pin / 8) * 4); - pin = (pin % 8) * 2; - pmu_write_4(rk30_pmu_sc, offset, (0x3 << (16 + pin)) | (state << pin)); -} Index: head/sys/arm/rockchip/rk30xx_wdog.h =================================================================== --- head/sys/arm/rockchip/rk30xx_wdog.h +++ head/sys/arm/rockchip/rk30xx_wdog.h @@ -1,36 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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. - * - * $FreeBSD$ - * - */ -#ifndef __RK30XX_WDOG_H__ -#define __RK30XX_WDOG_H__ - -void rk30_wd_watchdog_reset(void); - -#endif /*__RK30XX_WDOG_H__*/ Index: head/sys/arm/rockchip/rk30xx_wdog.c =================================================================== --- head/sys/arm/rockchip/rk30xx_wdog.c +++ head/sys/arm/rockchip/rk30xx_wdog.c @@ -1,202 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2013 Ganbold Tsagaankhuu - * All rights reserved. - * - * 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 -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#ifndef RK30_WDT_BASE -#define RK30_WDT_BASE 0x2004c000 -#define RK30_WDT_PSIZE 0x100 -#endif - -#define RK30_WDT_READ(_sc, _r) bus_read_4((_sc)->res, (_r)) -#define RK30_WDT_WRITE(_sc, _r, _v) bus_write_4((_sc)->res, (_r), (_v)) - -#define WDOG_CTRL 0x00 -#define WDOG_CTRL_EN (1 << 0) -#define WDOG_CTRL_RSP_MODE (1 << 1) -#define WDOG_CTRL_RST_PULSE (4 << 2) -#define WDOG_CTRL_RST 0xa -#define WDOG_TORR 0x04 -#define WDOG_TORR_INTVL_SHIFT 0 -#define WDOG_CCVR 0x08 -#define WDOG_CRR 0x0c -#define WDOG_CRR_PWD 0x76 -#define WDOG_STAT 0x10 -#define WDOG_EOI 0x14 - -static struct rk30_wd_softc *rk30_wd_sc = NULL; - -struct rk30_wd_softc { - device_t dev; - struct resource *res; - struct mtx mtx; - int freq; -}; - -static void rk30_wd_watchdog_fn(void *private, u_int cmd, int *error); - -static int -rk30_wd_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - - if (ofw_bus_is_compatible(dev, "rockchip,rk30xx-wdt")) { - device_set_desc(dev, "Rockchip RK30XX Watchdog"); - return (BUS_PROBE_DEFAULT); - } - - return (ENXIO); -} - -static int -rk30_wd_attach(device_t dev) -{ - struct rk30_wd_softc *sc; - int rid; - phandle_t node; - pcell_t cell; - - if (rk30_wd_sc != NULL) - return (ENXIO); - - sc = device_get_softc(dev); - sc->dev = dev; - - node = ofw_bus_get_node(sc->dev); - if (OF_getencprop(node, "clock-frequency", &cell, sizeof(cell)) > 0) - sc->freq = cell / 1000000; - else - return (ENXIO); - - rid = 0; - sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); - if (sc->res == NULL) { - device_printf(dev, "could not allocate memory resource\n"); - return (ENXIO); - } - - rk30_wd_sc = sc; - mtx_init(&sc->mtx, "RK30XX Watchdog", "rk30_wd", MTX_DEF); - EVENTHANDLER_REGISTER(watchdog_list, rk30_wd_watchdog_fn, sc, 0); - - return (0); -} - -static void -rk30_wd_watchdog_fn(void *private, u_int cmd, int *error) -{ - struct rk30_wd_softc *sc; - uint64_t ms, m, max; - int i; - - sc = private; - mtx_lock(&sc->mtx); - - cmd &= WD_INTERVAL; - - if (cmd > 0) { - ms = ((uint64_t)1 << (cmd & WD_INTERVAL)) / 1000000; - m = 0xffff / sc->freq; - max = 0x7fffffff / sc->freq + 1; - i = 0; - while (m < max && m < ms) { - m <<= 1; - i++; - } - if (m < max) { - RK30_WDT_WRITE(sc, WDOG_TORR, - i << WDOG_TORR_INTVL_SHIFT); - RK30_WDT_WRITE(sc, WDOG_CTRL, - WDOG_CTRL_EN | WDOG_CTRL_RSP_MODE | - WDOG_CTRL_RST_PULSE); - RK30_WDT_WRITE(sc, WDOG_CRR, WDOG_CRR_PWD); - *error = 0; - } else { - device_printf(sc->dev, "Can not be disabled\n"); - mtx_unlock(&sc->mtx); - RK30_WDT_WRITE(sc, WDOG_CTRL, WDOG_CTRL_RST); - return; - } - } - else - RK30_WDT_WRITE(sc, WDOG_CTRL, WDOG_CTRL_RST); - - mtx_unlock(&sc->mtx); -} - -void -rk30_wd_watchdog_reset(void) -{ - bus_space_handle_t bsh; - - bus_space_map(fdtbus_bs_tag, RK30_WDT_BASE, RK30_WDT_PSIZE, 0, &bsh); - bus_space_write_4(fdtbus_bs_tag, bsh, WDOG_TORR, 0); - bus_space_write_4(fdtbus_bs_tag, bsh, WDOG_CTRL, - WDOG_CTRL_EN | WDOG_CTRL_RSP_MODE | WDOG_CTRL_RST_PULSE); - - while (1); -} - -static device_method_t rk30_wd_methods[] = { - DEVMETHOD(device_probe, rk30_wd_probe), - DEVMETHOD(device_attach, rk30_wd_attach), - - DEVMETHOD_END -}; - -static driver_t rk30_wd_driver = { - "rk30_wd", - rk30_wd_methods, - sizeof(struct rk30_wd_softc), -}; -static devclass_t rk30_wd_devclass; - -DRIVER_MODULE(rk30_wd, simplebus, rk30_wd_driver, rk30_wd_devclass, 0, 0); Index: head/sys/arm/rockchip/std.rk30xx =================================================================== --- head/sys/arm/rockchip/std.rk30xx +++ head/sys/arm/rockchip/std.rk30xx @@ -1,8 +0,0 @@ -# Rockchip rk30xx common options -#$FreeBSD$ - -cpu CPU_CORTEXA -machine arm armv7 -makeoptions CONF_CFLAGS="-march=armv7a" - -files "../rockchip/files.rk30xx"