Author: loos
Date: Sat Feb 14 21:16:19 2015
New Revision: 278786
URL: https://svnweb.freebsd.org/changeset/base/278786

Log:
  MFC r274670, r274671, r276168:
  
  Moves all the duplicate code to a single function.
  
  Verify for invalid modes and unwanted flags before pass the new flags to
  driver.
  
  Make gpio_default_map_gpios() static.  No functional changes.
  
  Improves the GPIO API description a little bit.
  
  gpio_pin_max must return the maximum supported pin number and not the total
  number of pins on the system.

Modified:
  stable/10/sys/arm/allwinner/a10_gpio.c
  stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c
  stable/10/sys/arm/freescale/imx/imx_gpio.c
  stable/10/sys/arm/freescale/vybrid/vf_gpio.c
  stable/10/sys/arm/rockchip/rk30xx_gpio.c
  stable/10/sys/arm/samsung/exynos/exynos5_pad.c
  stable/10/sys/arm/ti/ti_gpio.c
  stable/10/sys/arm/xscale/ixp425/avila_gpio.c
  stable/10/sys/arm/xscale/ixp425/cambria_gpio.c
  stable/10/sys/dev/gpio/gpio_if.m
  stable/10/sys/dev/gpio/gpiobus.c
  stable/10/sys/dev/gpio/gpiobusvar.h
  stable/10/sys/dev/gpio/gpioc.c
  stable/10/sys/mips/atheros/ar71xx_gpio.c
  stable/10/sys/mips/cavium/octeon_gpio.c
  stable/10/sys/mips/rt305x/rt305x_gpio.c
  stable/10/sys/powerpc/wii/wii_gpio.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/arm/allwinner/a10_gpio.c
==============================================================================
--- stable/10/sys/arm/allwinner/a10_gpio.c      Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/arm/allwinner/a10_gpio.c      Sat Feb 14 21:16:19 2015        
(r278786)
@@ -302,20 +302,6 @@ a10_gpio_pin_setflags(device_t dev, uint
        if (i >= sc->sc_gpio_npins)
                return (EINVAL);
 
-       /* Check for unwanted flags. */
-       if ((flags & sc->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);
-
-       /* Can't mix pull-up/pull-down together. */
-       if ((flags & (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) ==
-           (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN))
-               return (EINVAL);
-
        a10_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags);
 
        return (0);

Modified: stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c
==============================================================================
--- stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c   Sat Feb 14 21:02:33 
2015        (r278785)
+++ stable/10/sys/arm/broadcom/bcm2835/bcm2835_gpio.c   Sat Feb 14 21:16:19 
2015        (r278786)
@@ -399,20 +399,6 @@ bcm_gpio_pin_setflags(device_t dev, uint
        if (bcm_gpio_pin_is_ro(sc, pin))
                return (EINVAL);
 
-       /* Check for unwanted flags. */
-       if ((flags & sc->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);
-
-       /* Can't mix pull-up/pull-down together. */
-       if ((flags & (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) ==
-           (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN))
-               return (EINVAL);
-
        bcm_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags);
 
        return (0);

Modified: stable/10/sys/arm/freescale/imx/imx_gpio.c
==============================================================================
--- stable/10/sys/arm/freescale/imx/imx_gpio.c  Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/arm/freescale/imx/imx_gpio.c  Sat Feb 14 21:16:19 2015        
(r278786)
@@ -268,18 +268,8 @@ imx51_gpio_pin_setflags(device_t dev, ui
        if (i >= sc->gpio_npins)
                return (EINVAL);
 
-       /* Check for 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);
-
        imx51_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
 
-
        return (0);
 }
 

Modified: stable/10/sys/arm/freescale/vybrid/vf_gpio.c
==============================================================================
--- stable/10/sys/arm/freescale/vybrid/vf_gpio.c        Sat Feb 14 21:02:33 
2015        (r278785)
+++ stable/10/sys/arm/freescale/vybrid/vf_gpio.c        Sat Feb 14 21:16:19 
2015        (r278786)
@@ -312,15 +312,6 @@ vf_gpio_pin_setflags(device_t dev, uint3
        if (i >= sc->gpio_npins)
                return (EINVAL);
 
-       /* Check for 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);
-
        vf_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
 
        return (0);

Modified: stable/10/sys/arm/rockchip/rk30xx_gpio.c
==============================================================================
--- stable/10/sys/arm/rockchip/rk30xx_gpio.c    Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/arm/rockchip/rk30xx_gpio.c    Sat Feb 14 21:16:19 2015        
(r278786)
@@ -318,20 +318,6 @@ rk30_gpio_pin_setflags(device_t dev, uin
        if (i >= sc->sc_gpio_npins)
                return (EINVAL);
 
-       /* Check for unwanted flags. */
-       if ((flags & sc->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);
-
-       /* Can't mix pull-up/pull-down together. */
-       if ((flags & (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) ==
-           (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN))
-               return (EINVAL);
-
        rk30_gpio_pin_configure(sc, &sc->sc_gpio_pins[i], flags);
 
        return (0);

Modified: stable/10/sys/arm/samsung/exynos/exynos5_pad.c
==============================================================================
--- stable/10/sys/arm/samsung/exynos/exynos5_pad.c      Sat Feb 14 21:02:33 
2015        (r278785)
+++ stable/10/sys/arm/samsung/exynos/exynos5_pad.c      Sat Feb 14 21:16:19 
2015        (r278786)
@@ -643,15 +643,6 @@ pad_pin_setflags(device_t dev, uint32_t 
        if (i >= sc->gpio_npins)
                return (EINVAL);
 
-       /* Check for 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);
-
        pad_pin_configure(sc, &sc->gpio_pins[i], flags);
 
        return (0);

Modified: stable/10/sys/arm/ti/ti_gpio.c
==============================================================================
--- stable/10/sys/arm/ti/ti_gpio.c      Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/arm/ti/ti_gpio.c      Sat Feb 14 21:16:19 2015        
(r278786)
@@ -456,16 +456,6 @@ ti_gpio_pin_setflags(device_t dev, uint3
        uint32_t mask = (1UL << (pin % PINS_PER_BANK));
        uint32_t reg_val;
 
-       /* Sanity check the flags supplied are valid, i.e. not input and output 
*/
-       if ((flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) == 0x0000)
-               return (EINVAL);
-       if ((flags & (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT)) == 
-           (GPIO_PIN_INPUT|GPIO_PIN_OUTPUT))
-               return (EINVAL);
-       if ((flags & (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) == 
-           (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN))
-               return (EINVAL);
-
        TI_GPIO_LOCK(sc);
 
        /* Sanity check the pin number is valid */

Modified: stable/10/sys/arm/xscale/ixp425/avila_gpio.c
==============================================================================
--- stable/10/sys/arm/xscale/ixp425/avila_gpio.c        Sat Feb 14 21:02:33 
2015        (r278785)
+++ stable/10/sys/arm/xscale/ixp425/avila_gpio.c        Sat Feb 14 21:16:19 
2015        (r278786)
@@ -220,16 +220,8 @@ avila_gpio_pin_setflags(device_t dev, ui
        if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & mask))
                return (EINVAL);
 
-       /* Check for unwanted flags. */
-       if ((flags & sc->sc_pins[pin].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);
-
        avila_gpio_pin_configure(sc, &sc->sc_pins[pin], flags);
+
        return (0);
 }
 

Modified: stable/10/sys/arm/xscale/ixp425/cambria_gpio.c
==============================================================================
--- stable/10/sys/arm/xscale/ixp425/cambria_gpio.c      Sat Feb 14 21:02:33 
2015        (r278785)
+++ stable/10/sys/arm/xscale/ixp425/cambria_gpio.c      Sat Feb 14 21:16:19 
2015        (r278786)
@@ -317,15 +317,6 @@ cambria_gpio_pin_setflags(device_t dev, 
        if (pin >= GPIO_PINS)
                return (EINVAL);
 
-       /* Check for unwanted flags. */
-       if ((flags & sc->sc_pins[pin].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);
-
        GPIO_LOCK(sc);
        sc->sc_pins[pin].gp_flags = flags;
 

Modified: stable/10/sys/dev/gpio/gpio_if.m
==============================================================================
--- stable/10/sys/dev/gpio/gpio_if.m    Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/dev/gpio/gpio_if.m    Sat Feb 14 21:16:19 2015        
(r278786)
@@ -32,9 +32,7 @@
 INTERFACE gpio;
 
 CODE {
-       static gpio_map_gpios_t gpio_default_map_gpios;
-
-       int
+       static int
        gpio_default_map_gpios(device_t bus, phandle_t dev,
            phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin,
            uint32_t *flags)
@@ -58,11 +56,11 @@ HEADER {
 };
 
 #
-# Get total number of pins
+# Get maximum pin number
 #
 METHOD int pin_max {
        device_t dev;
-       int *npins;
+       int *maxpin;
 };
 
 #

Modified: stable/10/sys/dev/gpio/gpiobus.c
==============================================================================
--- stable/10/sys/dev/gpio/gpiobus.c    Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/dev/gpio/gpiobus.c    Sat Feb 14 21:16:19 2015        
(r278786)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/bus.h>
+#include <sys/gpio.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
@@ -70,6 +71,23 @@ static int gpiobus_pin_set(device_t, dev
 static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*);
 static int gpiobus_pin_toggle(device_t, device_t, uint32_t);
 
+int
+gpio_check_flags(uint32_t caps, uint32_t flags)
+{
+
+       /* Check for unwanted flags. */
+       if ((flags & caps) == 0 || (flags & caps) != flags)
+               return (EINVAL);
+       /* Cannot mix input/output together. */
+       if (flags & GPIO_PIN_INPUT && flags & GPIO_PIN_OUTPUT)
+               return (EINVAL);
+       /* Cannot mix pull-up/pull-down together. */
+       if (flags & GPIO_PIN_PULLUP && flags & GPIO_PIN_PULLDOWN)
+               return (EINVAL);
+
+       return (0);
+}
+
 static void
 gpiobus_print_pins(struct gpiobus_ivar *devi, char *buf, size_t buflen)
 {
@@ -490,11 +508,16 @@ gpiobus_pin_setflags(device_t dev, devic
 {
        struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev);
        struct gpiobus_ivar *devi = GPIOBUS_IVAR(child);
+       uint32_t caps;
 
        if (pin >= devi->npins)
                return (EINVAL);
+       if (GPIO_PIN_GETCAPS(sc->sc_dev, devi->pins[pin], &caps) != 0)
+               return (EINVAL);
+       if (gpio_check_flags(caps, flags) != 0)
+               return (EINVAL);
 
-       return GPIO_PIN_SETFLAGS(sc->sc_dev, devi->pins[pin], flags);
+       return (GPIO_PIN_SETFLAGS(sc->sc_dev, devi->pins[pin], flags));
 }
 
 static int

Modified: stable/10/sys/dev/gpio/gpiobusvar.h
==============================================================================
--- stable/10/sys/dev/gpio/gpiobusvar.h Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/dev/gpio/gpiobusvar.h Sat Feb 14 21:16:19 2015        
(r278786)
@@ -94,6 +94,7 @@ gpio_map_gpios(device_t bus, phandle_t d
 
 device_t ofw_gpiobus_add_fdt_child(device_t, phandle_t);
 #endif
+int gpio_check_flags(uint32_t, uint32_t);
 int gpiobus_init_softc(device_t);
 
 extern driver_t gpiobus_driver;

Modified: stable/10/sys/dev/gpio/gpioc.c
==============================================================================
--- stable/10/sys/dev/gpio/gpioc.c      Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/dev/gpio/gpioc.c      Sat Feb 14 21:16:19 2015        
(r278786)
@@ -29,19 +29,16 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/types.h>
-
 #include <sys/bus.h>
 #include <sys/conf.h>
+#include <sys/gpio.h>
 #include <sys/ioccom.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
-#include <sys/queue.h>
-#include <machine/bus.h>
-#include <machine/resource.h>
 
-#include <sys/gpio.h>
+#include <dev/gpio/gpiobusvar.h>
+
 #include "gpio_if.h"
 
 #undef GPIOC_DEBUG
@@ -119,6 +116,7 @@ gpioc_ioctl(struct cdev *cdev, u_long cm
        struct gpioc_softc *sc = cdev->si_drv1;
        struct gpio_pin pin;
        struct gpio_req req;
+       uint32_t caps;
 
        switch (cmd) {
                case GPIOMAXPIN:
@@ -141,8 +139,12 @@ gpioc_ioctl(struct cdev *cdev, u_long cm
                case GPIOSETCONFIG:
                        bcopy(arg, &pin, sizeof(pin));
                        dprintf("set config pin %d\n", pin.gp_pin);
-                       res = GPIO_PIN_SETFLAGS(sc->sc_pdev, pin.gp_pin,
-                           pin.gp_flags);
+                       res = GPIO_PIN_GETCAPS(sc->sc_pdev, pin.gp_pin, &caps);
+                       if (res == 0)
+                               res = gpio_check_flags(caps, pin.gp_flags);
+                       if (res == 0)
+                               res = GPIO_PIN_SETFLAGS(sc->sc_pdev, pin.gp_pin,
+                                   pin.gp_flags);
                        break;
                case GPIOGET:
                        bcopy(arg, &req, sizeof(req));

Modified: stable/10/sys/mips/atheros/ar71xx_gpio.c
==============================================================================
--- stable/10/sys/mips/atheros/ar71xx_gpio.c    Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/mips/atheros/ar71xx_gpio.c    Sat Feb 14 21:16:19 2015        
(r278786)
@@ -241,16 +241,8 @@ ar71xx_gpio_pin_setflags(device_t dev, u
        if (i >= sc->gpio_npins)
                return (EINVAL);
 
-       /* Check for 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);
-
        ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
+
        return (0);
 }
 

Modified: stable/10/sys/mips/cavium/octeon_gpio.c
==============================================================================
--- stable/10/sys/mips/cavium/octeon_gpio.c     Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/mips/cavium/octeon_gpio.c     Sat Feb 14 21:16:19 2015        
(r278786)
@@ -219,16 +219,8 @@ octeon_gpio_pin_setflags(device_t dev, u
        if (i >= sc->gpio_npins)
                return (EINVAL);
 
-       /* Check for 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);
-
        octeon_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
+
        return (0);
 }
 

Modified: stable/10/sys/mips/rt305x/rt305x_gpio.c
==============================================================================
--- stable/10/sys/mips/rt305x/rt305x_gpio.c     Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/mips/rt305x/rt305x_gpio.c     Sat Feb 14 21:16:19 2015        
(r278786)
@@ -242,18 +242,8 @@ rt305x_gpio_pin_setflags(device_t dev, u
        if (i >= sc->gpio_npins)
                return (EINVAL);
 
-       /* Check for 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);
-
        rt305x_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
 
-
        return (0);
 }
 

Modified: stable/10/sys/powerpc/wii/wii_gpio.c
==============================================================================
--- stable/10/sys/powerpc/wii/wii_gpio.c        Sat Feb 14 21:02:33 2015        
(r278785)
+++ stable/10/sys/powerpc/wii/wii_gpio.c        Sat Feb 14 21:16:19 2015        
(r278786)
@@ -295,11 +295,6 @@ wiigpio_pin_setflags(device_t dev, uint3
 
        if (pin >= WIIGPIO_NPINS)
                return (EINVAL);
-       if ((flags & ~(GPIO_PIN_OUTPUT|GPIO_PIN_INPUT)) != 0)
-               return (EINVAL);
-       if ((flags & (GPIO_PIN_OUTPUT|GPIO_PIN_INPUT)) == 
-           (GPIO_PIN_OUTPUT|GPIO_PIN_INPUT))
-               return (EINVAL);
        sc = device_get_softc(dev);
        pinbank = WIIGPIO_PINBANK(pin);
        pinmask = WIIGPIO_PINMASK(pin);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to