Index: sys/arm/allwinner/a10_gpio.c =================================================================== --- sys/arm/allwinner/a10_gpio.c +++ sys/arm/allwinner/a10_gpio.c @@ -54,35 +54,33 @@ #include #include +#include +#include #include "gpio_if.h" -/* - * A10 have 9 banks of gpio. - * 32 pins per bank: - * PA0 - PA17 | PB0 - PB23 | PC0 - PC24 - * PD0 - PD27 | PE0 - PE31 | PF0 - PF5 - * PG0 - PG9 | PH0 - PH27 | PI0 - PI12 - */ - #define A10_GPIO_DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN) -#define A10_GPIO_NONE 0 -#define A10_GPIO_PULLUP 1 -#define A10_GPIO_PULLDOWN 2 +#define A10_GPIO_NONE 0 +#define A10_GPIO_PULLUP 1 +#define A10_GPIO_PULLDOWN 2 + +#define A10_GPIO_INPUT 0 +#define A10_GPIO_OUTPUT 1 -#define A10_GPIO_INPUT 0 -#define A10_GPIO_OUTPUT 1 +#define AW_GPIO_DRV_MASK 0x3 +#define AW_GPIO_PUD_MASK 0x3 -#define AW_GPIO_DRV_MASK 0x3 -#define AW_GPIO_PUD_MASK 0x3 +#define AW_PINCTRL 1 +#define AW_R_PINCTRL 2 static struct ofw_compat_data compat_data[] = { - {"allwinner,sun4i-a10-pinctrl", 1}, - {"allwinner,sun7i-a20-pinctrl", 1}, - {"allwinner,sun6i-a31-pinctrl", 1}, - {"allwinner,sun6i-a31s-pinctrl", 1}, + {"allwinner,sun4i-a10-pinctrl", AW_PINCTRL}, + {"allwinner,sun7i-a20-pinctrl", AW_PINCTRL}, + {"allwinner,sun6i-a31-pinctrl", AW_PINCTRL}, + {"allwinner,sun6i-a31-r-pinctrl", AW_R_PINCTRL}, + {"allwinner,sun6i-a31s-pinctrl", AW_PINCTRL}, {NULL, 0} }; @@ -111,11 +109,15 @@ /* Defined in a31_padconf.c */ #ifdef SOC_ALLWINNER_A31 extern const struct allwinner_padconf a31_padconf; +extern const struct allwinner_padconf a31_r_padconf; #endif /* Defined in a31s_padconf.c */ #ifdef SOC_ALLWINNER_A31S extern const struct allwinner_padconf a31s_padconf; +#ifndef SOC_ALLWINNER_A31 +extern const struct allwinner_padconf a31_r_padconf; +#endif #endif #define A10_GPIO_LOCK(_sc) mtx_lock_spin(&(_sc)->sc_mtx) @@ -526,9 +528,11 @@ static int a10_gpio_attach(device_t dev) { - int rid; + int rid, error; phandle_t gpio; struct a10_gpio_softc *sc; + clk_t clk; + hwreset_t rst; sc = device_get_softc(dev); sc->sc_dev = dev; @@ -561,29 +565,55 @@ goto fail; /* Use the right pin data for the current SoC */ - switch (allwinner_soc_type()) { + switch (ofw_bus_search_compatible(dev, compat_data)->ocd_data) { + case AW_PINCTRL: + switch (allwinner_soc_type()) { #ifdef SOC_ALLWINNER_A10 - case ALLWINNERSOC_A10: - sc->padconf = &a10_padconf; - break; + case ALLWINNERSOC_A10: + sc->padconf = &a10_padconf; + break; #endif #ifdef SOC_ALLWINNER_A20 - case ALLWINNERSOC_A20: - sc->padconf = &a20_padconf; - break; + case ALLWINNERSOC_A20: + sc->padconf = &a20_padconf; + break; #endif #ifdef SOC_ALLWINNER_A31 - case ALLWINNERSOC_A31: - sc->padconf = &a31_padconf; + case ALLWINNERSOC_A31: + sc->padconf = &a31_padconf; + break; break; #endif #ifdef SOC_ALLWINNER_A31S - case ALLWINNERSOC_A31S: - sc->padconf = &a31s_padconf; + case ALLWINNERSOC_A31S: + sc->padconf = &a31s_padconf; + break; +#endif + default: + return (ENOENT); + } break; + case AW_R_PINCTRL: +#if defined(SOC_ALLWINNER_A31) || defined(SOC_ALLWINNER_A31S) + sc->padconf = &a31_r_padconf; #endif - default: - return (ENOENT); + break; + } + + if (hwreset_get_by_ofw_idx(dev, 0, &rst) == 0) { + error = hwreset_deassert(rst); + if (error != 0) { + device_printf(dev, "cannot de-assert reset\n"); + return (error); + } + } + + if (clk_get_by_ofw_index(dev, 0, &clk) == 0) { + error = clk_enable(clk); + if (error != 0) { + device_printf(dev, "could not enable clock\n"); + return (error); + } } sc->sc_busdev = gpiobus_attach_bus(dev); Index: sys/arm/allwinner/a31/a31_r_padconf.c =================================================================== --- /dev/null +++ sys/arm/allwinner/a31/a31_r_padconf.c @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2016 Emmanuel Vadot + * 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 + +#if defined(SOC_ALLWINNER_A31) || defined(SOC_ALLWINNER_A31S) + +const static struct allwinner_pins a31_r_pins[] = { + {"PL0", 0, 0, {"gpio_in", "gpio_out", "s_twi", "s_p2wi", NULL, NULL, NULL, NULL}}, + {"PL1", 0, 1, {"gpio_in", "gpio_out", "s_twi", "s_p2wi", NULL, NULL, NULL, NULL}}, + {"PL2", 0, 2, {"gpio_in", "gpio_out", "s_uart", NULL, NULL, NULL, NULL, NULL}}, + {"PL3", 0, 3, {"gpio_in", "gpio_out", "s_uart", NULL, NULL, NULL, NULL, NULL}}, + {"PL4", 0, 4, {"gpio_in", "gpio_out", "s_ir", NULL, NULL, NULL, NULL, NULL}}, + {"PL5", 0, 5, {"gpio_in", "gpio_out", "pl_eint0", "s_jtag", NULL, NULL, NULL, NULL}}, + {"PL6", 0, 6, {"gpio_in", "gpio_out", "pl_eint1", "s_jtag", NULL, NULL, NULL, NULL}}, + {"PL7", 0, 7, {"gpio_in", "gpio_out", "pl_eint2", "s_jtag", NULL, NULL, NULL, NULL}}, + {"PL8", 0, 8, {"gpio_in", "gpio_out", "pl_eint3", "s_jtag", NULL, NULL, NULL, NULL}}, + + {"PM0", 1, 0, {"gpio_in", "gpio_out", "pm_eint0", NULL, NULL, NULL, NULL, NULL}}, + {"PM1", 1, 1, {"gpio_in", "gpio_out", "pm_eint1", NULL, NULL, NULL, NULL, NULL}}, + {"PM2", 1, 2, {"gpio_in", "gpio_out", "pm_eint2", "1wire", NULL, NULL, NULL, NULL}}, + {"PM3", 1, 3, {"gpio_in", "gpio_out", "pm_eint3", NULL, NULL, NULL, NULL, NULL}}, + {"PM4", 1, 4, {"gpio_in", "gpio_out", "pm_eint4", NULL, NULL, NULL, NULL, NULL}}, + {"PM5", 1, 5, {"gpio_in", "gpio_out", "pm_eint5", NULL, NULL, NULL, NULL, NULL}}, + {"PM6", 1, 6, {"gpio_in", "gpio_out", "pm_eint6", NULL, NULL, NULL, NULL, NULL}}, + {"PM7", 1, 7, {"gpio_in", "gpio_out", "pm_eint7", "rtc", NULL, NULL, NULL, NULL}}, +}; + +const struct allwinner_padconf a31_r_padconf = { + .npins = nitems(a31_r_pins), + .pins = a31_r_pins, +}; + +#endif Index: sys/arm/allwinner/a31/files.a31 =================================================================== --- sys/arm/allwinner/a31/files.a31 +++ sys/arm/allwinner/a31/files.a31 @@ -1,4 +1,5 @@ # $FreeBSD$ arm/allwinner/a31/a31_padconf.c standard +arm/allwinner/a31/a31_r_padconf.c standard arm/allwinner/a31/a31s_padconf.c standard