From owner-svn-src-head@FreeBSD.ORG Mon Dec 22 16:12:56 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3CE0A17F; Mon, 22 Dec 2014 16:12:56 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 289E33F59; Mon, 22 Dec 2014 16:12:56 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBMGCuR8015959; Mon, 22 Dec 2014 16:12:56 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBMGCuvf015958; Mon, 22 Dec 2014 16:12:56 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201412221612.sBMGCuvf015958@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Mon, 22 Dec 2014 16:12:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r276059 - head/sys/arm/ti 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.18-1 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: Mon, 22 Dec 2014 16:12:56 -0000 Author: loos Date: Mon Dec 22 16:12:55 2014 New Revision: 276059 URL: https://svnweb.freebsd.org/changeset/base/276059 Log: Simplify the use of locks where possible, remove the locking when it is not required. Simplify the code a little bit. Reviewed by: andrew (previous version) Modified: head/sys/arm/ti/ti_gpio.c Modified: head/sys/arm/ti/ti_gpio.c ============================================================================== --- head/sys/arm/ti/ti_gpio.c Mon Dec 22 15:39:24 2014 (r276058) +++ head/sys/arm/ti/ti_gpio.c Mon Dec 22 16:12:55 2014 (r276059) @@ -290,7 +290,7 @@ ti_gpio_intr_clr(struct ti_gpio_softc *s * * * LOCKING: - * Internally locks the context + * No locking required, returns static data. * * RETURNS: * Returns 0 on success otherwise an error code @@ -302,8 +302,6 @@ ti_gpio_pin_max(device_t dev, int *maxpi unsigned int i; unsigned int banks = 0; - TI_GPIO_LOCK(sc); - /* Calculate how many valid banks we have and then multiply that by 32 to * give use the total number of pins. */ @@ -314,8 +312,6 @@ ti_gpio_pin_max(device_t dev, int *maxpi *maxpin = (banks * PINS_PER_BANK) - 1; - TI_GPIO_UNLOCK(sc); - return (0); } @@ -332,7 +328,7 @@ ti_gpio_pin_max(device_t dev, int *maxpi * - GPIO_PIN_PULLDOWN * * LOCKING: - * Internally locks the context + * No locking required, returns static data. * * RETURNS: * Returns 0 on success otherwise an error code @@ -343,19 +339,13 @@ ti_gpio_pin_getcaps(device_t dev, uint32 struct ti_gpio_softc *sc = device_get_softc(dev); uint32_t bank = (pin / PINS_PER_BANK); - TI_GPIO_LOCK(sc); - /* Sanity check the pin number is valid */ - if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) { - TI_GPIO_UNLOCK(sc); + if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) return (EINVAL); - } - *caps = (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT |GPIO_PIN_PULLUP | + *caps = (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN); - TI_GPIO_UNLOCK(sc); - return (0); } @@ -381,17 +371,13 @@ ti_gpio_pin_getflags(device_t dev, uint3 struct ti_gpio_softc *sc = device_get_softc(dev); uint32_t bank = (pin / PINS_PER_BANK); - TI_GPIO_LOCK(sc); - /* Sanity check the pin number is valid */ - if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) { - TI_GPIO_UNLOCK(sc); + if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) return (EINVAL); - } /* Get the current pin state */ + TI_GPIO_LOCK(sc); TI_GPIO_GET_FLAGS(dev, pin, flags); - TI_GPIO_UNLOCK(sc); return (0); @@ -407,7 +393,7 @@ ti_gpio_pin_getflags(device_t dev, uint3 * of the pin. * * LOCKING: - * Internally locks the context + * No locking required, returns static data. * * RETURNS: * Returns 0 on success otherwise an error code @@ -418,20 +404,14 @@ ti_gpio_pin_getname(device_t dev, uint32 struct ti_gpio_softc *sc = device_get_softc(dev); uint32_t bank = (pin / PINS_PER_BANK); - TI_GPIO_LOCK(sc); - /* Sanity check the pin number is valid */ - if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) { - TI_GPIO_UNLOCK(sc); + if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) return (EINVAL); - } /* Set a very simple name */ snprintf(name, GPIOMAXNAME, "gpio_%u", pin); name[GPIOMAXNAME - 1] = '\0'; - TI_GPIO_UNLOCK(sc); - return (0); } @@ -460,30 +440,26 @@ ti_gpio_pin_setflags(device_t dev, uint3 struct ti_gpio_softc *sc = device_get_softc(dev); uint32_t bank = (pin / PINS_PER_BANK); uint32_t mask = (1UL << (pin % PINS_PER_BANK)); - uint32_t reg_val; - - TI_GPIO_LOCK(sc); + uint32_t oe; /* Sanity check the pin number is valid */ - if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) { - TI_GPIO_UNLOCK(sc); + if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) return (EINVAL); - } /* Set the GPIO mode and state */ + TI_GPIO_LOCK(sc); if (TI_GPIO_SET_FLAGS(dev, pin, flags) != 0) { TI_GPIO_UNLOCK(sc); return (EINVAL); } /* If configuring as an output set the "output enable" bit */ - reg_val = ti_gpio_read_4(sc, bank, TI_GPIO_OE); + oe = ti_gpio_read_4(sc, bank, TI_GPIO_OE); if (flags & GPIO_PIN_INPUT) - reg_val |= mask; + oe |= mask; else - reg_val &= ~mask; - ti_gpio_write_4(sc, bank, TI_GPIO_OE, reg_val); - + oe &= ~mask; + ti_gpio_write_4(sc, bank, TI_GPIO_OE, oe); TI_GPIO_UNLOCK(sc); return (0); @@ -509,18 +485,18 @@ ti_gpio_pin_set(device_t dev, uint32_t p struct ti_gpio_softc *sc = device_get_softc(dev); uint32_t bank = (pin / PINS_PER_BANK); uint32_t mask = (1UL << (pin % PINS_PER_BANK)); - - TI_GPIO_LOCK(sc); + uint32_t reg; /* Sanity check the pin number is valid */ - if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) { - TI_GPIO_UNLOCK(sc); + if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) return (EINVAL); - } - - ti_gpio_write_4(sc, bank, (value == GPIO_PIN_LOW) ? TI_GPIO_CLEARDATAOUT - : TI_GPIO_SETDATAOUT, mask); + TI_GPIO_LOCK(sc); + if (value == GPIO_PIN_LOW) + reg = TI_GPIO_CLEARDATAOUT; + else + reg = TI_GPIO_SETDATAOUT; + ti_gpio_write_4(sc, bank, reg, mask); TI_GPIO_UNLOCK(sc); return (0); @@ -547,25 +523,23 @@ ti_gpio_pin_get(device_t dev, uint32_t p struct ti_gpio_softc *sc = device_get_softc(dev); uint32_t bank = (pin / PINS_PER_BANK); uint32_t mask = (1UL << (pin % PINS_PER_BANK)); - uint32_t val = 0; - - TI_GPIO_LOCK(sc); + uint32_t oe, reg; /* Sanity check the pin number is valid */ - if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) { - TI_GPIO_UNLOCK(sc); + if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) return (EINVAL); - } - - /* Sanity check the pin is not configured as an output */ - val = ti_gpio_read_4(sc, bank, TI_GPIO_OE); - /* Read the value on the pin */ - if (val & mask) - *value = (ti_gpio_read_4(sc, bank, TI_GPIO_DATAIN) & mask) ? 1 : 0; + /* + * Return data from output latch when set as output and from the + * input register otherwise. + */ + TI_GPIO_LOCK(sc); + oe = ti_gpio_read_4(sc, bank, TI_GPIO_OE); + if (oe & mask) + reg = TI_GPIO_DATAIN; else - *value = (ti_gpio_read_4(sc, bank, TI_GPIO_DATAOUT) & mask) ? 1 : 0; - + reg = TI_GPIO_DATAOUT; + *value = (ti_gpio_read_4(sc, bank, reg) & mask) ? 1 : 0; TI_GPIO_UNLOCK(sc); return (0); @@ -589,23 +563,20 @@ ti_gpio_pin_toggle(device_t dev, uint32_ struct ti_gpio_softc *sc = device_get_softc(dev); uint32_t bank = (pin / PINS_PER_BANK); uint32_t mask = (1UL << (pin % PINS_PER_BANK)); - uint32_t val; - - TI_GPIO_LOCK(sc); + uint32_t reg, val; /* Sanity check the pin number is valid */ - if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) { - TI_GPIO_UNLOCK(sc); + if ((bank >= ti_max_gpio_banks()) || (sc->sc_mem_res[bank] == NULL)) return (EINVAL); - } /* Toggle the pin */ + TI_GPIO_LOCK(sc); val = ti_gpio_read_4(sc, bank, TI_GPIO_DATAOUT); if (val & mask) - ti_gpio_write_4(sc, bank, TI_GPIO_CLEARDATAOUT, mask); + reg = TI_GPIO_CLEARDATAOUT; else - ti_gpio_write_4(sc, bank, TI_GPIO_SETDATAOUT, mask); - + reg = TI_GPIO_SETDATAOUT; + ti_gpio_write_4(sc, bank, reg, mask); TI_GPIO_UNLOCK(sc); return (0);