Deleted Added
full compact
bcm2835_gpio.c (277941) bcm2835_gpio.c (277996)
1/*-
2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * Copyright (c) 2012 Luiz Otavio O Souza.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * Copyright (c) 2012 Luiz Otavio O Souza.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c 277941 2015-01-30 18:18:09Z loos $");
29__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c 277996 2015-01-31 19:32:14Z loos $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/bus.h>
34
35#include <sys/kernel.h>
36#include <sys/module.h>
37#include <sys/rman.h>

--- 5 unchanged lines hidden (view full) ---

43#include <machine/bus.h>
44#include <machine/cpu.h>
45#include <machine/cpufunc.h>
46#include <machine/resource.h>
47#include <machine/fdt.h>
48#include <machine/intr.h>
49
50#include <dev/fdt/fdt_common.h>
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/bus.h>
34
35#include <sys/kernel.h>
36#include <sys/module.h>
37#include <sys/rman.h>

--- 5 unchanged lines hidden (view full) ---

43#include <machine/bus.h>
44#include <machine/cpu.h>
45#include <machine/cpufunc.h>
46#include <machine/resource.h>
47#include <machine/fdt.h>
48#include <machine/intr.h>
49
50#include <dev/fdt/fdt_common.h>
51#include <dev/gpio/gpiobusvar.h>
51#include <dev/ofw/ofw_bus.h>
52#include <dev/ofw/ofw_bus_subr.h>
53
54#include <arm/broadcom/bcm2835/bcm2835_gpio.h>
55
56#include "gpio_if.h"
57
58#ifdef DEBUG

--- 19 unchanged lines hidden (view full) ---

78
79struct bcm_gpio_sysctl {
80 struct bcm_gpio_softc *sc;
81 uint32_t pin;
82};
83
84struct bcm_gpio_softc {
85 device_t sc_dev;
52#include <dev/ofw/ofw_bus.h>
53#include <dev/ofw/ofw_bus_subr.h>
54
55#include <arm/broadcom/bcm2835/bcm2835_gpio.h>
56
57#include "gpio_if.h"
58
59#ifdef DEBUG

--- 19 unchanged lines hidden (view full) ---

79
80struct bcm_gpio_sysctl {
81 struct bcm_gpio_softc *sc;
82 uint32_t pin;
83};
84
85struct bcm_gpio_softc {
86 device_t sc_dev;
87 device_t sc_busdev;
86 struct mtx sc_mtx;
87 struct resource * sc_res[BCM_GPIO_IRQS + 1];
88 bus_space_tag_t sc_bst;
89 bus_space_handle_t sc_bsh;
90 void * sc_intrhand;
91 int sc_gpio_npins;
92 int sc_ro_npins;
93 int sc_ro_pins[BCM_GPIO_PINS];

--- 218 unchanged lines hidden (view full) ---

312 bcm_gpio_set_pud(sc, pin->gp_pin, BCM_GPIO_PULLDOWN);
313 }
314 } else
315 bcm_gpio_set_pud(sc, pin->gp_pin, BCM_GPIO_NONE);
316
317 BCM_GPIO_UNLOCK(sc);
318}
319
88 struct mtx sc_mtx;
89 struct resource * sc_res[BCM_GPIO_IRQS + 1];
90 bus_space_tag_t sc_bst;
91 bus_space_handle_t sc_bsh;
92 void * sc_intrhand;
93 int sc_gpio_npins;
94 int sc_ro_npins;
95 int sc_ro_pins[BCM_GPIO_PINS];

--- 218 unchanged lines hidden (view full) ---

314 bcm_gpio_set_pud(sc, pin->gp_pin, BCM_GPIO_PULLDOWN);
315 }
316 } else
317 bcm_gpio_set_pud(sc, pin->gp_pin, BCM_GPIO_NONE);
318
319 BCM_GPIO_UNLOCK(sc);
320}
321
322static device_t
323bcm_gpio_get_bus(device_t dev)
324{
325 struct bcm_gpio_softc *sc;
326
327 sc = device_get_softc(dev);
328
329 return (sc->sc_busdev);
330}
331
320static int
321bcm_gpio_pin_max(device_t dev, int *maxpin)
322{
323
324 *maxpin = BCM_GPIO_PINS - 1;
325 return (0);
326}
327

--- 376 unchanged lines hidden (view full) ---

704 "pin %d", j);
705 func = bcm_gpio_get_function(sc, j);
706 sc->sc_gpio_pins[i].gp_pin = j;
707 sc->sc_gpio_pins[i].gp_caps = BCM_GPIO_DEFAULT_CAPS;
708 sc->sc_gpio_pins[i].gp_flags = bcm_gpio_func_flag(func);
709 i++;
710 }
711 sc->sc_gpio_npins = i;
332static int
333bcm_gpio_pin_max(device_t dev, int *maxpin)
334{
335
336 *maxpin = BCM_GPIO_PINS - 1;
337 return (0);
338}
339

--- 376 unchanged lines hidden (view full) ---

716 "pin %d", j);
717 func = bcm_gpio_get_function(sc, j);
718 sc->sc_gpio_pins[i].gp_pin = j;
719 sc->sc_gpio_pins[i].gp_caps = BCM_GPIO_DEFAULT_CAPS;
720 sc->sc_gpio_pins[i].gp_flags = bcm_gpio_func_flag(func);
721 i++;
722 }
723 sc->sc_gpio_npins = i;
712
713 bcm_gpio_sysctl_init(sc);
724 bcm_gpio_sysctl_init(sc);
725 sc->sc_busdev = gpiobus_attach_bus(dev);
726 if (sc->sc_busdev == NULL)
727 goto fail;
714
728
715 device_add_child(dev, "gpioc", -1);
716 device_add_child(dev, "gpiobus", -1);
729 return (0);
717
730
718 return (bus_generic_attach(dev));
719
720fail:
721 bus_release_resources(dev, bcm_gpio_res_spec, sc->sc_res);
722 mtx_destroy(&sc->sc_mtx);
723
724 return (ENXIO);
725}
726
727static int

--- 13 unchanged lines hidden (view full) ---

741
742static device_method_t bcm_gpio_methods[] = {
743 /* Device interface */
744 DEVMETHOD(device_probe, bcm_gpio_probe),
745 DEVMETHOD(device_attach, bcm_gpio_attach),
746 DEVMETHOD(device_detach, bcm_gpio_detach),
747
748 /* GPIO protocol */
731fail:
732 bus_release_resources(dev, bcm_gpio_res_spec, sc->sc_res);
733 mtx_destroy(&sc->sc_mtx);
734
735 return (ENXIO);
736}
737
738static int

--- 13 unchanged lines hidden (view full) ---

752
753static device_method_t bcm_gpio_methods[] = {
754 /* Device interface */
755 DEVMETHOD(device_probe, bcm_gpio_probe),
756 DEVMETHOD(device_attach, bcm_gpio_attach),
757 DEVMETHOD(device_detach, bcm_gpio_detach),
758
759 /* GPIO protocol */
760 DEVMETHOD(gpio_get_bus, bcm_gpio_get_bus),
749 DEVMETHOD(gpio_pin_max, bcm_gpio_pin_max),
750 DEVMETHOD(gpio_pin_getname, bcm_gpio_pin_getname),
751 DEVMETHOD(gpio_pin_getflags, bcm_gpio_pin_getflags),
752 DEVMETHOD(gpio_pin_getcaps, bcm_gpio_pin_getcaps),
753 DEVMETHOD(gpio_pin_setflags, bcm_gpio_pin_setflags),
754 DEVMETHOD(gpio_pin_get, bcm_gpio_pin_get),
755 DEVMETHOD(gpio_pin_set, bcm_gpio_pin_set),
756 DEVMETHOD(gpio_pin_toggle, bcm_gpio_pin_toggle),

--- 16 unchanged lines hidden ---
761 DEVMETHOD(gpio_pin_max, bcm_gpio_pin_max),
762 DEVMETHOD(gpio_pin_getname, bcm_gpio_pin_getname),
763 DEVMETHOD(gpio_pin_getflags, bcm_gpio_pin_getflags),
764 DEVMETHOD(gpio_pin_getcaps, bcm_gpio_pin_getcaps),
765 DEVMETHOD(gpio_pin_setflags, bcm_gpio_pin_setflags),
766 DEVMETHOD(gpio_pin_get, bcm_gpio_pin_get),
767 DEVMETHOD(gpio_pin_set, bcm_gpio_pin_set),
768 DEVMETHOD(gpio_pin_toggle, bcm_gpio_pin_toggle),

--- 16 unchanged lines hidden ---