Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Apr 2016 13:59:18 +0000 (UTC)
From:      Jared McNeill <jmcneill@FreeBSD.org>
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
Message-ID:  <201604231359.u3NDxIO5087393@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <manu@bidouilliste.com>
  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 <arm/allwinner/allwinner_machdep.h>
 #include <arm/allwinner/allwinner_pinctrl.h>
+#include <dev/extres/clk/clk.h>
+#include <dev/extres/hwreset/hwreset.h>
 
 #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 <manu@bidouilliste.com>
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/types.h>
+
+#include <arm/allwinner/allwinner_pinctrl.h>
+
+#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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201604231359.u3NDxIO5087393>