From owner-svn-src-head@freebsd.org Sat Apr 23 13:59:20 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F1D5BB12C9E; Sat, 23 Apr 2016 13:59:19 +0000 (UTC) (envelope-from jmcneill@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 mx1.freebsd.org (Postfix) with ESMTPS id C8E061FD8; Sat, 23 Apr 2016 13:59:19 +0000 (UTC) (envelope-from jmcneill@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3NDxIto087396; Sat, 23 Apr 2016 13:59:18 GMT (envelope-from jmcneill@FreeBSD.org) Received: (from jmcneill@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3NDxIO5087393; Sat, 23 Apr 2016 13:59:18 GMT (envelope-from jmcneill@FreeBSD.org) Message-Id: <201604231359.u3NDxIO5087393@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jmcneill set sender to jmcneill@FreeBSD.org using -f From: Jared McNeill Date: Sat, 23 Apr 2016 13:59:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r298513 - in head/sys/arm/allwinner: . a31 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.21 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: Sat, 23 Apr 2016 13:59:20 -0000 Author: jmcneill Date: Sat Apr 23 13:59:18 2016 New Revision: 298513 URL: https://svnweb.freebsd.org/changeset/base/298513 Log: Add support for Allwinner A31/A31S R-GPIO (CPUs-PORT) controller. Submitted by: Emmanuel Vadot Reviewed by: jmcneill Differential Revision: https://reviews.freebsd.org/D5930 Added: head/sys/arm/allwinner/a31/a31_r_padconf.c (contents, props changed) Modified: head/sys/arm/allwinner/a10_gpio.c head/sys/arm/allwinner/a31/files.a31 Modified: head/sys/arm/allwinner/a10_gpio.c ============================================================================== --- head/sys/arm/allwinner/a10_gpio.c Sat Apr 23 13:24:45 2016 (r298512) +++ head/sys/arm/allwinner/a10_gpio.c Sat Apr 23 13:59:18 2016 (r298513) @@ -54,49 +54,26 @@ __FBSDID("$FreeBSD$"); #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_INPUT 0 -#define A10_GPIO_OUTPUT 1 +#define A10_GPIO_NONE 0 +#define A10_GPIO_PULLUP 1 +#define A10_GPIO_PULLDOWN 2 -#define AW_GPIO_DRV_MASK 0x3 -#define AW_GPIO_PUD_MASK 0x3 +#define A10_GPIO_INPUT 0 +#define A10_GPIO_OUTPUT 1 -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}, - {NULL, 0} -}; +#define AW_GPIO_DRV_MASK 0x3 +#define AW_GPIO_PUD_MASK 0x3 -struct a10_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; - const struct allwinner_padconf * padconf; -}; +#define AW_PINCTRL 1 +#define AW_R_PINCTRL 2 /* Defined in a10_padconf.c */ #ifdef SOC_ALLWINNER_A10 @@ -118,6 +95,41 @@ extern const struct allwinner_padconf a3 extern const struct allwinner_padconf a31s_padconf; #endif +#if defined(SOC_ALLWINNER_A31) || defined(SOC_ALLWINNER_A31S) +extern const struct allwinner_padconf a31_r_padconf; +#endif + +static struct ofw_compat_data compat_data[] = { +#ifdef SOC_ALLWINNER_A10 + {"allwinner,sun4i-a10-pinctrl", (uintptr_t)&a10_padconf}, +#endif +#ifdef SOC_ALLWINNER_A20 + {"allwinner,sun7i-a20-pinctrl", (uintptr_t)&a20_padconf}, +#endif +#ifdef SOC_ALLWINNER_A31 + {"allwinner,sun6i-a31-pinctrl", (uintptr_t)&a31_padconf}, +#endif +#ifdef SOC_ALLWINNER_A31S + {"allwinner,sun6i-a31s-pinctrl", (uintptr_t)&a31s_padconf}, +#endif +#if defined(SOC_ALLWINNER_A31) || defined(SOC_ALLWINNER_A31S) + {"allwinner,sun6i-a31-r-pinctrl", (uintptr_t)&a31_r_padconf}, +#endif + {NULL, 0} +}; + +struct a10_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; + const struct allwinner_padconf * padconf; +}; + #define A10_GPIO_LOCK(_sc) mtx_lock_spin(&(_sc)->sc_mtx) #define A10_GPIO_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->sc_mtx) #define A10_GPIO_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) @@ -526,9 +538,11 @@ a10_gpio_probe(device_t dev) 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 +575,23 @@ a10_gpio_attach(device_t dev) goto fail; /* Use the right pin data for the current SoC */ - switch (allwinner_soc_type()) { -#ifdef SOC_ALLWINNER_A10 - case ALLWINNERSOC_A10: - sc->padconf = &a10_padconf; - break; -#endif -#ifdef SOC_ALLWINNER_A20 - case ALLWINNERSOC_A20: - sc->padconf = &a20_padconf; - break; -#endif -#ifdef SOC_ALLWINNER_A31 - case ALLWINNERSOC_A31: - sc->padconf = &a31_padconf; - break; -#endif -#ifdef SOC_ALLWINNER_A31S - case ALLWINNERSOC_A31S: - sc->padconf = &a31s_padconf; - break; -#endif - default: - return (ENOENT); + sc->padconf = (struct allwinner_padconf *)ofw_bus_search_compatible(dev, + compat_data)->ocd_data; + + 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); Added: head/sys/arm/allwinner/a31/a31_r_padconf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm/allwinner/a31/a31_r_padconf.c Sat Apr 23 13:59:18 2016 (r298513) @@ -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 Modified: head/sys/arm/allwinner/a31/files.a31 ============================================================================== --- head/sys/arm/allwinner/a31/files.a31 Sat Apr 23 13:24:45 2016 (r298512) +++ head/sys/arm/allwinner/a31/files.a31 Sat Apr 23 13:59:18 2016 (r298513) @@ -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