ti_gpio.c (d60840138f6292c1ceeb177ebe797eca0b2749da) ti_gpio.c (59c3cb81c1769fdb6c840c971df129b52f4a848d)
1/*-
2 * Copyright (c) 2011 Ben Gray <ben.r.gray@gmail.com>.
3 * Copyright (c) 2014 Luiz Otavio O Souza <loos@FreeBSD.org>.
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:

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

61#include <dev/fdt/fdt_common.h>
62#include <dev/gpio/gpiobusvar.h>
63#include <dev/ofw/openfirm.h>
64#include <dev/ofw/ofw_bus.h>
65#include <dev/ofw/ofw_bus_subr.h>
66
67#include "gpio_if.h"
68#include "ti_gpio_if.h"
1/*-
2 * Copyright (c) 2011 Ben Gray <ben.r.gray@gmail.com>.
3 * Copyright (c) 2014 Luiz Otavio O Souza <loos@FreeBSD.org>.
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:

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

61#include <dev/fdt/fdt_common.h>
62#include <dev/gpio/gpiobusvar.h>
63#include <dev/ofw/openfirm.h>
64#include <dev/ofw/ofw_bus.h>
65#include <dev/ofw/ofw_bus_subr.h>
66
67#include "gpio_if.h"
68#include "ti_gpio_if.h"
69#ifdef ARM_INTRNG
69#ifdef INTRNG
70#include "pic_if.h"
71#endif
72
73#if !defined(SOC_OMAP4) && !defined(SOC_TI_AM335X)
74#error "Unknown SoC"
75#endif
76
77/* Register definitions */

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

116#define AM335X_INTR_PER_BANK 2
117#define AM335X_GPIO_REV 0x50600801
118#define PINS_PER_BANK 32
119#define TI_GPIO_MASK(p) (1U << ((p) % PINS_PER_BANK))
120
121static int ti_gpio_intr(void *arg);
122static int ti_gpio_detach(device_t);
123
70#include "pic_if.h"
71#endif
72
73#if !defined(SOC_OMAP4) && !defined(SOC_TI_AM335X)
74#error "Unknown SoC"
75#endif
76
77/* Register definitions */

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

116#define AM335X_INTR_PER_BANK 2
117#define AM335X_GPIO_REV 0x50600801
118#define PINS_PER_BANK 32
119#define TI_GPIO_MASK(p) (1U << ((p) % PINS_PER_BANK))
120
121static int ti_gpio_intr(void *arg);
122static int ti_gpio_detach(device_t);
123
124#ifdef ARM_INTRNG
124#ifdef INTRNG
125static int ti_gpio_pic_attach(struct ti_gpio_softc *sc);
126static int ti_gpio_pic_detach(struct ti_gpio_softc *sc);
127#endif
128
129static u_int
130ti_first_gpio_bank(void)
131{
132 switch(ti_chip()) {

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

541 else
542 reg = TI_GPIO_SETDATAOUT;
543 ti_gpio_write_4(sc, reg, TI_GPIO_MASK(pin));
544 TI_GPIO_UNLOCK(sc);
545
546 return (0);
547}
548
125static int ti_gpio_pic_attach(struct ti_gpio_softc *sc);
126static int ti_gpio_pic_detach(struct ti_gpio_softc *sc);
127#endif
128
129static u_int
130ti_first_gpio_bank(void)
131{
132 switch(ti_chip()) {

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

541 else
542 reg = TI_GPIO_SETDATAOUT;
543 ti_gpio_write_4(sc, reg, TI_GPIO_MASK(pin));
544 TI_GPIO_UNLOCK(sc);
545
546 return (0);
547}
548
549#ifndef ARM_INTRNG
549#ifndef INTRNG
550/**
551 * ti_gpio_intr - ISR for all GPIO modules
552 * @arg: the soft context pointer
553 *
554 * LOCKING:
555 * Internally locks the context
556 *
557 */

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

650 *
651 * RETURNS:
652 * Always returns 0
653 */
654static int
655ti_gpio_attach(device_t dev)
656{
657 struct ti_gpio_softc *sc;
550/**
551 * ti_gpio_intr - ISR for all GPIO modules
552 * @arg: the soft context pointer
553 *
554 * LOCKING:
555 * Internally locks the context
556 *
557 */

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

650 *
651 * RETURNS:
652 * Always returns 0
653 */
654static int
655ti_gpio_attach(device_t dev)
656{
657 struct ti_gpio_softc *sc;
658#ifndef ARM_INTRNG
658#ifndef INTRNG
659 unsigned int i;
660#endif
661 int err;
662
663 sc = device_get_softc(dev);
664 sc->sc_dev = dev;
665 TI_GPIO_LOCK_INIT(sc);
666 ti_gpio_pin_max(dev, &sc->sc_maxpin);

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

691 INTR_TYPE_MISC | INTR_MPSAFE, ti_gpio_intr, NULL, sc,
692 &sc->sc_irq_hdl) != 0) {
693 device_printf(dev,
694 "WARNING: unable to register interrupt filter\n");
695 ti_gpio_detach(dev);
696 return (ENXIO);
697 }
698
659 unsigned int i;
660#endif
661 int err;
662
663 sc = device_get_softc(dev);
664 sc->sc_dev = dev;
665 TI_GPIO_LOCK_INIT(sc);
666 ti_gpio_pin_max(dev, &sc->sc_maxpin);

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

691 INTR_TYPE_MISC | INTR_MPSAFE, ti_gpio_intr, NULL, sc,
692 &sc->sc_irq_hdl) != 0) {
693 device_printf(dev,
694 "WARNING: unable to register interrupt filter\n");
695 ti_gpio_detach(dev);
696 return (ENXIO);
697 }
698
699#ifdef ARM_INTRNG
699#ifdef INTRNG
700 if (ti_gpio_pic_attach(sc) != 0) {
701 device_printf(dev, "WARNING: unable to attach PIC\n");
702 ti_gpio_detach(dev);
703 return (ENXIO);
704 }
705#else
706 /*
707 * Initialize the interrupt settings. The default is active-low

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

766 struct ti_gpio_softc *sc = device_get_softc(dev);
767
768 KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized"));
769
770 /* Disable all interrupts */
771 if (sc->sc_mem_res != NULL)
772 ti_gpio_intr_clr(sc, 0xffffffff);
773 gpiobus_detach_bus(dev);
700 if (ti_gpio_pic_attach(sc) != 0) {
701 device_printf(dev, "WARNING: unable to attach PIC\n");
702 ti_gpio_detach(dev);
703 return (ENXIO);
704 }
705#else
706 /*
707 * Initialize the interrupt settings. The default is active-low

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

766 struct ti_gpio_softc *sc = device_get_softc(dev);
767
768 KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized"));
769
770 /* Disable all interrupts */
771 if (sc->sc_mem_res != NULL)
772 ti_gpio_intr_clr(sc, 0xffffffff);
773 gpiobus_detach_bus(dev);
774#ifdef ARM_INTRNG
774#ifdef INTRNG
775 if (sc->sc_isrcs != NULL)
776 ti_gpio_pic_detach(sc);
777#else
778 if (sc->sc_events)
779 free(sc->sc_events, M_DEVBUF);
780 if (sc->sc_mask_args)
781 free(sc->sc_mask_args, M_DEVBUF);
782 if (sc->sc_irq_polarity)

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

793 sc->sc_irq_res);
794 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_mem_rid,
795 sc->sc_mem_res);
796 TI_GPIO_LOCK_DESTROY(sc);
797
798 return (0);
799}
800
775 if (sc->sc_isrcs != NULL)
776 ti_gpio_pic_detach(sc);
777#else
778 if (sc->sc_events)
779 free(sc->sc_events, M_DEVBUF);
780 if (sc->sc_mask_args)
781 free(sc->sc_mask_args, M_DEVBUF);
782 if (sc->sc_irq_polarity)

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

793 sc->sc_irq_res);
794 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_mem_rid,
795 sc->sc_mem_res);
796 TI_GPIO_LOCK_DESTROY(sc);
797
798 return (0);
799}
800
801#ifdef ARM_INTRNG
801#ifdef INTRNG
802static inline void
803ti_gpio_rwreg_set(struct ti_gpio_softc *sc, uint32_t reg, uint32_t mask)
804{
805
806 ti_gpio_write_4(sc, reg, ti_gpio_read_4(sc, reg) | mask);
807}
808
809static inline void

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

1295 DEVMETHOD(gpio_pin_getname, ti_gpio_pin_getname),
1296 DEVMETHOD(gpio_pin_getflags, ti_gpio_pin_getflags),
1297 DEVMETHOD(gpio_pin_getcaps, ti_gpio_pin_getcaps),
1298 DEVMETHOD(gpio_pin_setflags, ti_gpio_pin_setflags),
1299 DEVMETHOD(gpio_pin_get, ti_gpio_pin_get),
1300 DEVMETHOD(gpio_pin_set, ti_gpio_pin_set),
1301 DEVMETHOD(gpio_pin_toggle, ti_gpio_pin_toggle),
1302
802static inline void
803ti_gpio_rwreg_set(struct ti_gpio_softc *sc, uint32_t reg, uint32_t mask)
804{
805
806 ti_gpio_write_4(sc, reg, ti_gpio_read_4(sc, reg) | mask);
807}
808
809static inline void

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

1295 DEVMETHOD(gpio_pin_getname, ti_gpio_pin_getname),
1296 DEVMETHOD(gpio_pin_getflags, ti_gpio_pin_getflags),
1297 DEVMETHOD(gpio_pin_getcaps, ti_gpio_pin_getcaps),
1298 DEVMETHOD(gpio_pin_setflags, ti_gpio_pin_setflags),
1299 DEVMETHOD(gpio_pin_get, ti_gpio_pin_get),
1300 DEVMETHOD(gpio_pin_set, ti_gpio_pin_set),
1301 DEVMETHOD(gpio_pin_toggle, ti_gpio_pin_toggle),
1302
1303#ifdef ARM_INTRNG
1303#ifdef INTRNG
1304 /* Interrupt controller interface */
1305 DEVMETHOD(pic_disable_intr, ti_gpio_pic_disable_intr),
1306 DEVMETHOD(pic_enable_intr, ti_gpio_pic_enable_intr),
1307 DEVMETHOD(pic_map_intr, ti_gpio_pic_map_intr),
1308 DEVMETHOD(pic_setup_intr, ti_gpio_pic_setup_intr),
1309 DEVMETHOD(pic_teardown_intr, ti_gpio_pic_teardown_intr),
1310 DEVMETHOD(pic_post_filter, ti_gpio_pic_post_filter),
1311 DEVMETHOD(pic_post_ithread, ti_gpio_pic_post_ithread),

--- 21 unchanged lines hidden ---
1304 /* Interrupt controller interface */
1305 DEVMETHOD(pic_disable_intr, ti_gpio_pic_disable_intr),
1306 DEVMETHOD(pic_enable_intr, ti_gpio_pic_enable_intr),
1307 DEVMETHOD(pic_map_intr, ti_gpio_pic_map_intr),
1308 DEVMETHOD(pic_setup_intr, ti_gpio_pic_setup_intr),
1309 DEVMETHOD(pic_teardown_intr, ti_gpio_pic_teardown_intr),
1310 DEVMETHOD(pic_post_filter, ti_gpio_pic_post_filter),
1311 DEVMETHOD(pic_post_ithread, ti_gpio_pic_post_ithread),

--- 21 unchanged lines hidden ---