[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree
zrouter-src-freebsd at zrouter.org
zrouter-src-freebsd at zrouter.org
Wed Aug 15 08:14:46 UTC 2012
details: http://zrouter.org/hg/FreeBSD/head//rev/389b994a8768
changeset: 521:389b994a8768
user: Aleksandr Rybalko <ray at ddteam.net>
date: Fri Aug 10 16:13:53 2012 +0300
description:
Switch back to single GPIO controller driver.
diffstat:
head/sys/mips/atheros/ar71xx_gpio.c | 30 +-
head/sys/mips/atheros/ar71xx_gpiovar.h | 1 -
head/sys/mips/atheros/ar724x_gpio.c | 453 ---------------------------------
head/sys/mips/atheros/files.ar71xx | 3 +-
4 files changed, 22 insertions(+), 465 deletions(-)
diffs (610 lines):
diff -r 2d798fd21d78 -r 389b994a8768 head/sys/mips/atheros/ar71xx_gpio.c
--- a/head/sys/mips/atheros/ar71xx_gpio.c Fri Aug 10 14:19:25 2012 +0300
+++ b/head/sys/mips/atheros/ar71xx_gpio.c Fri Aug 10 16:13:53 2012 +0300
@@ -47,6 +47,7 @@
#include <machine/bus.h>
#include <machine/resource.h>
#include <mips/atheros/ar71xxreg.h>
+#include <mips/atheros/ar724xreg.h>
#include <mips/atheros/ar71xx_setup.h>
#include <mips/atheros/ar71xx_gpiovar.h>
@@ -89,13 +90,17 @@
static void
ar71xx_gpio_function_enable(struct ar71xx_gpio_softc *sc, uint32_t mask)
{
+ GPIO_LOCK(sc);
GPIO_SET_BITS(sc, AR71XX_GPIO_FUNCTION, mask);
+ GPIO_UNLOCK(sc);
}
static void
ar71xx_gpio_function_disable(struct ar71xx_gpio_softc *sc, uint32_t mask)
{
+ GPIO_LOCK(sc);
GPIO_CLEAR_BITS(sc, AR71XX_GPIO_FUNCTION, mask);
+ GPIO_UNLOCK(sc);
}
static void
@@ -105,6 +110,7 @@
uint32_t mask;
mask = 1 << pin->gp_pin;
+ GPIO_LOCK(sc);
/*
* Manage input/output
@@ -120,6 +126,8 @@
GPIO_CLEAR_BITS(sc, AR71XX_GPIO_OE, mask);
}
}
+
+ GPIO_UNLOCK(sc);
}
static int
@@ -246,10 +254,12 @@
if (i >= sc->gpio_npins)
return (EINVAL);
+ GPIO_LOCK(sc);
if (value)
GPIO_WRITE(sc, AR71XX_GPIO_SET, (1 << pin));
else
GPIO_WRITE(sc, AR71XX_GPIO_CLEAR, (1 << pin));
+ GPIO_UNLOCK(sc);
return (0);
}
@@ -268,7 +278,9 @@
if (i >= sc->gpio_npins)
return (EINVAL);
+ GPIO_LOCK(sc);
*val = (GPIO_READ(sc, AR71XX_GPIO_IN) & (1 << pin)) ? 1 : 0;
+ GPIO_UNLOCK(sc);
return (0);
}
@@ -287,11 +299,13 @@
if (i >= sc->gpio_npins)
return (EINVAL);
+ GPIO_LOCK(sc);
res = (GPIO_READ(sc, AR71XX_GPIO_IN) & (1 << pin)) ? 1 : 0;
if (res)
GPIO_WRITE(sc, AR71XX_GPIO_CLEAR, (1 << pin));
else
GPIO_WRITE(sc, AR71XX_GPIO_SET, (1 << pin));
+ GPIO_UNLOCK(sc);
return (0);
}
@@ -328,13 +342,10 @@
{
struct ar71xx_gpio_softc *sc = device_get_softc(dev);
int error = 0;
- int i, j, maxpin;
+ int i, j, npins;
int mask, pinon;
int old = 0;
- KASSERT((device_get_unit(dev) == 0),
- ("ar71xx_gpio: Only one gpio module supported"));
-
mtx_init(&sc->gpio_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
MTX_DEF);
@@ -381,8 +392,7 @@
}
/* Handle previous behaviour */
if (old == 0) {
- ar71xx_gpio_function_enable(sc, GPIO_FUNC_SPI_CS1_EN);
- ar71xx_gpio_function_enable(sc, GPIO_FUNC_SPI_CS2_EN);
+ ar71xx_gpio_function_enable(sc, AR724X_GPIO_FUNC_JTAG_DISABLE);
}
/* Configure all pins as input */
@@ -390,15 +400,17 @@
GPIO_WRITE(sc, AR71XX_GPIO_INT_MASK, 0);
/* Initialise all pins specified in the mask, up to the pin count */
- (void) ar71xx_gpio_pin_max(dev, &maxpin);
+ (void) ar71xx_gpio_pin_max(dev, &npins);
+ /* gpio_pin_max method return max ID, but not count, so increment */
+ npins ++;
if (resource_int_value(device_get_name(dev), device_get_unit(dev),
"pinmask", &mask) != 0)
- mask = 0;
+ mask = ((1 << npins) - 1);
if (resource_int_value(device_get_name(dev), device_get_unit(dev),
"pinon", &pinon) != 0)
pinon = 0;
device_printf(dev, "gpio pinmask=0x%x\n", mask);
- for (i = 0, j = 0; j < maxpin; j++) {
+ for (i = 0, j = 0; j < npins; j++) {
if ((mask & (1 << j)) == 0)
continue;
snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME,
diff -r 2d798fd21d78 -r 389b994a8768 head/sys/mips/atheros/ar71xx_gpiovar.h
--- a/head/sys/mips/atheros/ar71xx_gpiovar.h Fri Aug 10 14:19:25 2012 +0300
+++ b/head/sys/mips/atheros/ar71xx_gpiovar.h Fri Aug 10 16:13:53 2012 +0300
@@ -64,7 +64,6 @@
int gpio_irq_rid;
void *gpio_ih;
int gpio_npins;
-// struct gpio_pin gpio_pins[AR71XX_GPIO_PINS];
struct gpio_pin gpio_pins[AR91XX_GPIO_PINS];
};
diff -r 2d798fd21d78 -r 389b994a8768 head/sys/mips/atheros/ar724x_gpio.c
--- a/head/sys/mips/atheros/ar724x_gpio.c Fri Aug 10 14:19:25 2012 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,453 +0,0 @@
-/*-
- * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo at FreeBSD.org>
- * Copyright (c) 2009, 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 unmodified, 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.
- */
-
-/*
- * GPIO driver for AR724x
- */
-
-#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 <sys/rman.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/gpio.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <mips/atheros/ar71xxreg.h>
-#include <mips/atheros/ar724xreg.h>
-#include <mips/atheros/ar71xx_setup.h>
-#include <mips/atheros/ar724x_gpiovar.h>
-
-#include "gpio_if.h"
-
-#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)
-
-/*
- * Helpers
- */
-#if 0
-static void ar724x_gpio_function_enable(struct ar724x_gpio_softc *sc,
- uint32_t mask);
-static void ar724x_gpio_function_disable(struct ar724x_gpio_softc *sc,
- uint32_t mask);
-#endif
-static void ar724x_gpio_pin_configure(struct ar724x_gpio_softc *sc,
- struct gpio_pin *pin, uint32_t flags);
-
-/*
- * Driver stuff
- */
-static int ar724x_gpio_probe(device_t dev);
-static int ar724x_gpio_attach(device_t dev);
-static int ar724x_gpio_detach(device_t dev);
-static int ar724x_gpio_filter(void *arg);
-static void ar724x_gpio_intr(void *arg);
-
-/*
- * GPIO interface
- */
-static int ar724x_gpio_pin_max(device_t dev, int *maxpin);
-static int ar724x_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
-static int ar724x_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
- *flags);
-static int ar724x_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
-static int ar724x_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
-static int ar724x_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
-static int ar724x_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);
-static int ar724x_gpio_pin_toggle(device_t dev, uint32_t pin);
-
-#if 0
-static void
-ar724x_gpio_function_enable(struct ar724x_gpio_softc *sc, uint32_t mask)
-{
- GPIO_LOCK(sc);
- GPIO_SET_BITS(sc, AR71XX_GPIO_FUNCTION, mask);
- GPIO_UNLOCK(sc);
-}
-
-static void
-ar724x_gpio_function_disable(struct ar724x_gpio_softc *sc, uint32_t mask)
-{
- GPIO_LOCK(sc);
- GPIO_CLEAR_BITS(sc, AR71XX_GPIO_FUNCTION, mask);
- GPIO_UNLOCK(sc);
-}
-#endif
-
-static void
-ar724x_gpio_pin_configure(struct ar724x_gpio_softc *sc, struct gpio_pin *pin,
- unsigned int flags)
-{
- uint32_t mask;
-
- mask = 1 << pin->gp_pin;
- 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;
- GPIO_SET_BITS(sc, AR71XX_GPIO_OE, mask);
- }
- else {
- pin->gp_flags |= GPIO_PIN_INPUT;
- GPIO_CLEAR_BITS(sc, AR71XX_GPIO_OE, mask);
- }
- }
-
- GPIO_UNLOCK(sc);
-}
-
-static int
-ar724x_gpio_pin_max(device_t dev, int *maxpin)
-{
-
- *maxpin = AR724X_GPIO_PINS - 1;
- return (0);
-}
-
-static int
-ar724x_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
-{
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
- int i;
-
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
- return (EINVAL);
-
- GPIO_LOCK(sc);
- *caps = sc->gpio_pins[i].gp_caps;
- GPIO_UNLOCK(sc);
-
- return (0);
-}
-
-static int
-ar724x_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
-{
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
- int i;
-
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
- return (EINVAL);
-
- GPIO_LOCK(sc);
- *flags = sc->gpio_pins[i].gp_flags;
- GPIO_UNLOCK(sc);
-
- return (0);
-}
-
-static int
-ar724x_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
-{
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
- int i;
-
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
- return (EINVAL);
-
- GPIO_LOCK(sc);
- memcpy(name, sc->gpio_pins[i].gp_name, GPIOMAXNAME);
- GPIO_UNLOCK(sc);
-
- return (0);
-}
-
-static int
-ar724x_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
-{
- int i;
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
-
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
- return (EINVAL);
-
- /* Filter out unwanted flags */
- if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
- return (EINVAL);
-
- /* Can't mix input/output together */
- if ((flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) ==
- (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT))
- return (EINVAL);
-
- ar724x_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
- return (0);
-}
-
-static int
-ar724x_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
-{
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
- int i;
-
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
- return (EINVAL);
-
- GPIO_LOCK(sc);
- if (value)
- GPIO_WRITE(sc, AR71XX_GPIO_SET, (1 << pin));
- else
- GPIO_WRITE(sc, AR71XX_GPIO_CLEAR, (1 << pin));
- GPIO_UNLOCK(sc);
-
- return (0);
-}
-
-static int
-ar724x_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
-{
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
- int i;
-
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
- return (EINVAL);
-
- GPIO_LOCK(sc);
- *val = (GPIO_READ(sc, AR71XX_GPIO_IN) & (1 << pin)) ? 1 : 0;
- GPIO_UNLOCK(sc);
-
- return (0);
-}
-
-static int
-ar724x_gpio_pin_toggle(device_t dev, uint32_t pin)
-{
- int res, i;
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
-
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
- return (EINVAL);
-
- GPIO_LOCK(sc);
- res = (GPIO_READ(sc, AR71XX_GPIO_IN) & (1 << pin)) ? 1 : 0;
- if (res)
- GPIO_WRITE(sc, AR71XX_GPIO_CLEAR, (1 << pin));
- else
- GPIO_WRITE(sc, AR71XX_GPIO_SET, (1 << pin));
- GPIO_UNLOCK(sc);
-
- return (0);
-}
-
-static int
-ar724x_gpio_filter(void *arg)
-{
-
- /* TODO: something useful */
- return (FILTER_STRAY);
-}
-
-
-
-static void
-ar724x_gpio_intr(void *arg)
-{
- struct ar724x_gpio_softc *sc = arg;
- GPIO_LOCK(sc);
- /* TODO: something useful */
- GPIO_UNLOCK(sc);
-}
-
-static int
-ar724x_gpio_probe(device_t dev)
-{
-
- switch (ar71xx_soc) {
- case AR71XX_SOC_AR7240:
- case AR71XX_SOC_AR7241:
- case AR71XX_SOC_AR7242:
- device_set_desc(dev, "Atheros AR724X GPIO driver");
- return (0);
- break;
- default:
- break;
- }
- return (ENXIO);
-}
-
-static int
-ar724x_gpio_attach(device_t dev)
-{
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
- int error = 0;
- int i, maxpin;
- uint32_t reg;
-
- KASSERT((device_get_unit(dev) == 0),
- ("ar724x_gpio: Only one gpio module supported"));
-
- mtx_init(&sc->gpio_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
- MTX_DEF);
-
- /* Map control/status registers. */
- sc->gpio_mem_rid = 0;
- sc->gpio_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
- &sc->gpio_mem_rid, RF_ACTIVE);
-
- if (sc->gpio_mem_res == NULL) {
- device_printf(dev, "couldn't map memory\n");
- error = ENXIO;
- ar724x_gpio_detach(dev);
- return(error);
- }
-
- if ((sc->gpio_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
- &sc->gpio_irq_rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
- device_printf(dev, "unable to allocate IRQ resource\n");
- return (ENXIO);
- }
-
- if ((bus_setup_intr(dev, sc->gpio_irq_res, INTR_TYPE_MISC,
- ar724x_gpio_filter, ar724x_gpio_intr, sc, &sc->gpio_ih))) {
- device_printf(dev,
- "WARNING: unable to register interrupt handler\n");
- return (ENXIO);
- }
-
- sc->dev = dev;
-
- /* XXX: use something like hints for it */
- reg = GPIO_READ(sc, AR71XX_GPIO_FUNCTION);
- device_printf(dev, "GPIO Functions reg old value = 0x%08x\n", reg);
-
- /* Disable JTAG on GPIO and enable GE0 MII clock */
- //AR724X_GPIO_FUNC_GE0_MII_CLK_EN |
- reg |= AR724X_GPIO_FUNC_JTAG_DISABLE;
- GPIO_WRITE(sc, AR71XX_GPIO_FUNCTION, reg);
-
- device_printf(dev, "GPIO Functions reg new value = 0x%08x\n",
- GPIO_READ(sc, AR71XX_GPIO_FUNCTION));
-
- /* Configure all pins as input */
- /* disable interrupts for all pins */
- GPIO_WRITE(sc, AR71XX_GPIO_INT_MASK, 0);
- ar724x_gpio_pin_max(dev, &maxpin);
-
- for (i = 0; i <= maxpin; i++) {
- sc->gpio_pins[i].gp_pin = i;
- sc->gpio_pins[i].gp_caps = DEFAULT_CAPS;
- sc->gpio_pins[i].gp_flags = 0;
- }
-
- sc->gpio_npins = i;
-
- device_add_child(dev, "gpiobus", device_get_unit(dev));
- return (bus_generic_attach(dev));
-}
-
-static int
-ar724x_gpio_detach(device_t dev)
-{
- struct ar724x_gpio_softc *sc = device_get_softc(dev);
-
- KASSERT(mtx_initialized(&sc->gpio_mtx), ("gpio mutex not initialized"));
-
- bus_generic_detach(dev);
-
- if (sc->gpio_mem_res)
- bus_release_resource(dev, SYS_RES_MEMORY, sc->gpio_mem_rid,
- sc->gpio_mem_res);
-
- mtx_destroy(&sc->gpio_mtx);
-
- return(0);
-}
-
-static device_method_t ar724x_gpio_methods[] = {
- DEVMETHOD(device_probe, ar724x_gpio_probe),
- DEVMETHOD(device_attach, ar724x_gpio_attach),
- DEVMETHOD(device_detach, ar724x_gpio_detach),
-
- /* GPIO protocol */
- DEVMETHOD(gpio_pin_max, ar724x_gpio_pin_max),
- DEVMETHOD(gpio_pin_getname, ar724x_gpio_pin_getname),
- DEVMETHOD(gpio_pin_getflags, ar724x_gpio_pin_getflags),
- DEVMETHOD(gpio_pin_getcaps, ar724x_gpio_pin_getcaps),
- DEVMETHOD(gpio_pin_setflags, ar724x_gpio_pin_setflags),
- DEVMETHOD(gpio_pin_get, ar724x_gpio_pin_get),
- DEVMETHOD(gpio_pin_set, ar724x_gpio_pin_set),
- DEVMETHOD(gpio_pin_toggle, ar724x_gpio_pin_toggle),
- DEVMETHOD_END
-};
-
-static driver_t ar724x_gpio_driver = {
- "gpio",
- ar724x_gpio_methods,
- sizeof(struct ar724x_gpio_softc),
-};
-static devclass_t ar724x_gpio_devclass;
-
-DRIVER_MODULE(ar724x_gpio, apb, ar724x_gpio_driver, ar724x_gpio_devclass, 0, 0);
diff -r 2d798fd21d78 -r 389b994a8768 head/sys/mips/atheros/files.ar71xx
--- a/head/sys/mips/atheros/files.ar71xx Fri Aug 10 14:19:25 2012 +0300
+++ b/head/sys/mips/atheros/files.ar71xx Fri Aug 10 16:13:53 2012 +0300
@@ -1,8 +1,7 @@
# $FreeBSD: head/sys/mips/atheros/files.ar71xx 234485 2012-04-20 08:26:05Z adrian $
mips/atheros/apb.c standard
-mips/atheros/ar71xx_gpio.c optional ar71xx_gpio gpio
-mips/atheros/ar724x_gpio.c optional gpio
+mips/atheros/ar71xx_gpio.c optional gpio
mips/atheros/ar71xx_machdep.c standard
mips/atheros/ar71xx_ehci.c optional ehci
mips/atheros/ar71xx_ohci.c optional ohci
More information about the Zrouter-src-freebsd
mailing list