Date: Sat, 14 Feb 2015 20:32:25 +0000 (UTC) From: Luiz Otavio O Souza <loos@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r278781 - stable/10/sys/dev/gpio Message-ID: <201502142032.t1EKWPhJ064971@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: loos Date: Sat Feb 14 20:32:24 2015 New Revision: 278781 URL: https://svnweb.freebsd.org/changeset/base/278781 Log: MFC r273566, r273569: Provide a working GPIOBUS_IVAR() macro for FDT systems. Move the duplicated code to a single function. No functional changes. Modified: stable/10/sys/dev/gpio/gpiobus.c stable/10/sys/dev/gpio/gpiobusvar.h stable/10/sys/dev/gpio/ofw_gpiobus.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/gpio/gpiobus.c ============================================================================== --- stable/10/sys/dev/gpio/gpiobus.c Sat Feb 14 20:00:57 2015 (r278780) +++ stable/10/sys/dev/gpio/gpiobus.c Sat Feb 14 20:32:24 2015 (r278781) @@ -99,6 +99,34 @@ gpiobus_print_pins(struct gpiobus_ivar * printf("%d", range_start); } +int +gpiobus_init_softc(device_t dev) +{ + struct gpiobus_softc *sc; + + sc = GPIOBUS_SOFTC(dev); + sc->sc_busdev = dev; + sc->sc_dev = device_get_parent(dev); + + if (GPIO_PIN_MAX(sc->sc_dev, &sc->sc_npins) != 0) + return (ENXIO); + + KASSERT(sc->sc_npins != 0, ("GPIO device with no pins")); + + /* Pins = GPIO_PIN_MAX() + 1 */ + sc->sc_npins++; + + sc->sc_pins_mapped = malloc(sizeof(int) * sc->sc_npins, M_DEVBUF, + M_NOWAIT | M_ZERO); + if (sc->sc_pins_mapped == NULL) + return (ENOMEM); + + /* Initialize the bus lock. */ + GPIOBUS_LOCK_INIT(sc); + + return (0); +} + static int gpiobus_parse_pins(struct gpiobus_softc *sc, device_t child, int mask) { @@ -163,30 +191,11 @@ gpiobus_probe(device_t dev) static int gpiobus_attach(device_t dev) { - struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev); - int res; - - sc->sc_busdev = dev; - sc->sc_dev = device_get_parent(dev); - res = GPIO_PIN_MAX(sc->sc_dev, &sc->sc_npins); - if (res) - return (ENXIO); - - KASSERT(sc->sc_npins != 0, ("GPIO device with no pins")); - - /* - * Increase to get number of pins - */ - sc->sc_npins++; - - sc->sc_pins_mapped = malloc(sizeof(int) * sc->sc_npins, M_DEVBUF, - M_NOWAIT | M_ZERO); - - if (!sc->sc_pins_mapped) - return (ENOMEM); + int err; - /* init bus lock */ - GPIOBUS_LOCK_INIT(sc); + err = gpiobus_init_softc(dev); + if (err != 0) + return (err); /* * Get parent's pins and mark them as unmapped Modified: stable/10/sys/dev/gpio/gpiobusvar.h ============================================================================== --- stable/10/sys/dev/gpio/gpiobusvar.h Sat Feb 14 20:00:57 2015 (r278780) +++ stable/10/sys/dev/gpio/gpiobusvar.h Sat Feb 14 20:32:24 2015 (r278781) @@ -41,7 +41,12 @@ #include "gpio_if.h" +#ifdef FDT +#define GPIOBUS_IVAR(d) (struct gpiobus_ivar *) \ + &((struct ofw_gpiobus_devinfo *)device_get_ivars(d))->opd_dinfo +#else #define GPIOBUS_IVAR(d) (struct gpiobus_ivar *) device_get_ivars(d) +#endif #define GPIOBUS_SOFTC(d) (struct gpiobus_softc *) device_get_softc(d) #define GPIOBUS_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) #define GPIOBUS_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) @@ -84,6 +89,7 @@ gpio_map_gpios(device_t bus, phandle_t d device_t ofw_gpiobus_add_fdt_child(device_t, phandle_t); #endif void gpiobus_print_pins(struct gpiobus_ivar *); +int gpiobus_init_softc(device_t); extern driver_t gpiobus_driver; Modified: stable/10/sys/dev/gpio/ofw_gpiobus.c ============================================================================== --- stable/10/sys/dev/gpio/ofw_gpiobus.c Sat Feb 14 20:00:57 2015 (r278780) +++ stable/10/sys/dev/gpio/ofw_gpiobus.c Sat Feb 14 20:32:24 2015 (r278781) @@ -264,33 +264,13 @@ ofw_gpiobus_probe(device_t dev) static int ofw_gpiobus_attach(device_t dev) { - struct gpiobus_softc *sc; + int err; phandle_t child; - sc = GPIOBUS_SOFTC(dev); - sc->sc_busdev = dev; - sc->sc_dev = device_get_parent(dev); - - /* Read the pin max. value */ - if (GPIO_PIN_MAX(sc->sc_dev, &sc->sc_npins) != 0) - return (ENXIO); - - KASSERT(sc->sc_npins != 0, ("GPIO device with no pins")); - - /* - * Increase to get number of pins. - */ - sc->sc_npins++; - - sc->sc_pins_mapped = malloc(sizeof(int) * sc->sc_npins, M_DEVBUF, - M_NOWAIT | M_ZERO); - - if (!sc->sc_pins_mapped) - return (ENOMEM); - - /* Init the bus lock. */ - GPIOBUS_LOCK_INIT(sc); - + err = gpiobus_init_softc(dev); + if (err != 0) + return (err); + bus_generic_probe(dev); bus_enumerate_hinted_children(dev);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502142032.t1EKWPhJ064971>