Lines Matching +full:inverted +full:- +full:out
1 /*-
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 #define GPIO_LOCK(_sc) mtx_lock(&(_sc)->mtx)
58 #define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx)
59 #define GPIO_LOCK_INIT(_sc) mtx_init(&_sc->mtx, \
60 device_get_nameunit(_sc->dev), "mvebu_gpio", MTX_DEF)
61 #define GPIO_LOCK_DESTROY(_sc) mtx_destroy(&_sc->mtx);
62 #define GPIO_ASSERT_LOCKED(_sc) mtx_assert(&_sc->mtx, MA_OWNED);
63 #define GPIO_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->mtx, MA_NOTOWNED);
112 {"marvell,armada-8k-gpio", 1},
116 /* --------------------------------------------------------------------------
127 bit = GPIO_BIT(pin->gp_pin); in gpio_write()
128 SYSCON_WRITE_4(sc->syscon, sc->offset + GPIO_REGNUM(pin->gp_pin) + reg, in gpio_write()
138 bit = GPIO_BIT(pin->gp_pin); in gpio_read()
139 val = SYSCON_READ_4(sc->syscon, in gpio_read()
140 sc->offset + GPIO_REGNUM(pin->gp_pin) + reg); in gpio_read()
151 bit = GPIO_BIT(pin->gp_pin); in gpio_modify()
152 SYSCON_MODIFY_4(sc->syscon, sc->offset + GPIO_REGNUM(pin->gp_pin) + reg, in gpio_modify()
165 pin->gp_flags &= ~(GPIO_PIN_INPUT | GPIO_PIN_OUTPUT); in mvebu_gpio_pin_configure()
167 pin->gp_flags |= GPIO_PIN_OUTPUT; in mvebu_gpio_pin_configure()
170 pin->gp_flags |= GPIO_PIN_INPUT; in mvebu_gpio_pin_configure()
181 return (sc->busdev); in mvebu_gpio_get_bus()
190 *maxpin = sc->gpio_npins - 1; in mvebu_gpio_pin_max()
200 if (pin >= sc->gpio_npins) in mvebu_gpio_pin_getcaps()
203 *caps = sc->gpio_pins[pin].gp_caps; in mvebu_gpio_pin_getcaps()
214 if (pin >= sc->gpio_npins) in mvebu_gpio_pin_getflags()
217 *flags = sc->gpio_pins[pin].gp_flags; in mvebu_gpio_pin_getflags()
228 if (pin >= sc->gpio_npins) in mvebu_gpio_pin_getname()
231 memcpy(name, sc->gpio_pins[pin].gp_name, GPIOMAXNAME); in mvebu_gpio_pin_getname()
242 if (pin >= sc->gpio_npins) in mvebu_gpio_pin_setflags()
245 mvebu_gpio_pin_configure(sc, &sc->gpio_pins[pin], flags); in mvebu_gpio_pin_setflags()
256 if (pin >= sc->gpio_npins) in mvebu_gpio_pin_set()
260 gpio_write(sc, GPIO_DATA_SET, &sc->gpio_pins[pin], 1); in mvebu_gpio_pin_set()
262 gpio_write(sc, GPIO_DATA_CLR, &sc->gpio_pins[pin], 1); in mvebu_gpio_pin_set()
273 if (pin >= sc->gpio_npins) in mvebu_gpio_pin_get()
277 *val = gpio_read(sc, GPIO_DATA_IN, &sc->gpio_pins[pin]); in mvebu_gpio_pin_get()
278 *val ^= gpio_read(sc, GPIO_DATA_IN_POL, &sc->gpio_pins[pin]); in mvebu_gpio_pin_get()
291 if (pin >= sc->gpio_npins) in mvebu_gpio_pin_toggle()
295 mvebu_gpio_pin_get(sc->dev, pin, &val); in mvebu_gpio_pin_toggle()
297 gpio_write(sc, GPIO_DATA_CLR, &sc->gpio_pins[pin], 1); in mvebu_gpio_pin_toggle()
299 gpio_write(sc, GPIO_DATA_SET, &sc->gpio_pins[pin], 1); in mvebu_gpio_pin_toggle()
305 /* --------------------------------------------------------------------------
316 bit = GPIO_BIT(mgi->irq); in intr_modify()
317 SYSCON_MODIFY_4(sc->syscon, in intr_modify()
318 sc->offset + GPIO_REGNUM(mgi->irq) + reg, 1 << bit, in intr_modify()
327 if (mgi->is_level) in mvebu_gpio_isrc_mask()
339 if (!mgi->is_level) { in mvebu_gpio_isrc_eoi()
340 bit = GPIO_BIT(mgi->irq); in mvebu_gpio_isrc_eoi()
341 SYSCON_WRITE_4(sc->syscon, in mvebu_gpio_isrc_eoi()
342 sc->offset + GPIO_REGNUM(mgi->irq) + GPIO_INT_CAUSE, in mvebu_gpio_isrc_eoi()
354 sc->isrcs = malloc(sizeof(*sc->isrcs) * sc->gpio_npins, M_DEVBUF, in mvebu_gpio_pic_attach()
357 name = device_get_nameunit(sc->dev); in mvebu_gpio_pic_attach()
358 for (irq = 0; irq < sc->gpio_npins; irq++) { in mvebu_gpio_pic_attach()
359 sc->isrcs[irq].irq = irq; in mvebu_gpio_pic_attach()
360 sc->isrcs[irq].is_level = false; in mvebu_gpio_pic_attach()
361 sc->isrcs[irq].is_inverted = false; in mvebu_gpio_pic_attach()
362 rv = intr_isrc_register(&sc->isrcs[irq].isrc, in mvebu_gpio_pic_attach()
363 sc->dev, 0, "%s,%u", name, irq); in mvebu_gpio_pic_attach()
367 if (intr_pic_register(sc->dev, in mvebu_gpio_pic_attach()
368 OF_xref_from_node(ofw_bus_get_node(sc->dev))) == NULL) in mvebu_gpio_pic_attach()
382 device_printf(sc->dev, "%s: not implemented yet\n", __func__); in mvebu_gpio_pic_detach()
412 bool inverted, level; in mvebu_gpio_pic_map_fdt() local
418 * 1 = low-to-high edge triggered. in mvebu_gpio_pic_map_fdt()
419 * 2 = high-to-low edge triggered. in mvebu_gpio_pic_map_fdt()
420 * 4 = active high level-sensitive. in mvebu_gpio_pic_map_fdt()
421 * 8 = active low level-sensitive. in mvebu_gpio_pic_map_fdt()
423 if (ncells != 2 || cells[0] >= sc->gpio_npins) in mvebu_gpio_pic_map_fdt()
428 inverted = false; in mvebu_gpio_pic_map_fdt()
432 inverted = true; in mvebu_gpio_pic_map_fdt()
436 inverted = false; in mvebu_gpio_pic_map_fdt()
440 inverted = true; in mvebu_gpio_pic_map_fdt()
448 *invertedp = inverted; in mvebu_gpio_pic_map_fdt()
459 bool inverted, level; in mvebu_gpio_pic_map_gpio() local
461 if (gpio_pin_num >= sc->gpio_npins) in mvebu_gpio_pic_map_gpio()
466 inverted = true; in mvebu_gpio_pic_map_gpio()
470 inverted = false; in mvebu_gpio_pic_map_gpio()
475 inverted = false; in mvebu_gpio_pic_map_gpio()
479 inverted = true; in mvebu_gpio_pic_map_gpio()
487 *invertedp = inverted; in mvebu_gpio_pic_map_gpio()
503 if (data->type == INTR_MAP_DATA_FDT) { in mvebu_gpio_pic_map_intr()
507 rv = mvebu_gpio_pic_map_fdt(sc, daf->ncells, daf->cells, &irq, in mvebu_gpio_pic_map_intr()
509 } else if (data->type == INTR_MAP_DATA_GPIO) { in mvebu_gpio_pic_map_intr()
513 rv = mvebu_gpio_pic_map_gpio(sc, dag->gpio_pin_num, in mvebu_gpio_pic_map_intr()
514 dag->gpio_pin_flags, dag->gpio_intr_mode, &irq, NULL, NULL); in mvebu_gpio_pic_map_intr()
519 *isrcp = &sc->isrcs[irq].isrc; in mvebu_gpio_pic_map_intr()
531 if (mgi->is_level) in mvebu_gpio_pic_post_filter()
556 if (mgi->is_level) in mvebu_gpio_pic_pre_ithread()
565 bool inverted, level; in mvebu_gpio_pic_setup_intr() local
577 if (data->type == INTR_MAP_DATA_FDT) { in mvebu_gpio_pic_setup_intr()
581 rv = mvebu_gpio_pic_map_fdt(sc, daf->ncells, daf->cells, &irq, in mvebu_gpio_pic_setup_intr()
582 &inverted, &level); in mvebu_gpio_pic_setup_intr()
583 } else if (data->type == INTR_MAP_DATA_GPIO) { in mvebu_gpio_pic_setup_intr()
587 rv = mvebu_gpio_pic_map_gpio(sc, dag->gpio_pin_num, in mvebu_gpio_pic_setup_intr()
588 dag->gpio_pin_flags, dag->gpio_intr_mode, &irq, in mvebu_gpio_pic_setup_intr()
589 &inverted, &level); in mvebu_gpio_pic_setup_intr()
600 if (isrc->isrc_handlers != 0) in mvebu_gpio_pic_setup_intr()
602 mgi->is_level == level && mgi->is_inverted == inverted ? in mvebu_gpio_pic_setup_intr()
605 mgi->is_level = level; in mvebu_gpio_pic_setup_intr()
606 mgi->is_inverted = inverted; in mvebu_gpio_pic_setup_intr()
609 intr_modify(sc, GPIO_DATA_IN_POL, mgi, inverted ? 1 : 0); in mvebu_gpio_pic_setup_intr()
626 if (isrc->isrc_handlers == 0) in mvebu_gpio_pic_teardown_intr()
631 /* --------------------------------------------------------------------------
647 sc = cookie->sc; in mvebu_gpio_intr()
648 tf = curthread->td_intr_frame; in mvebu_gpio_intr()
650 for (i = 0; i < sc->gpio_npins; i++) { in mvebu_gpio_intr()
651 lvl = gpio_read(sc, GPIO_DATA_IN, &sc->gpio_pins[i]); in mvebu_gpio_intr()
652 lvl &= gpio_read(sc, GPIO_INT_LEVEL_MASK, &sc->gpio_pins[i]); in mvebu_gpio_intr()
653 edge = gpio_read(sc, GPIO_DATA_IN, &sc->gpio_pins[i]); in mvebu_gpio_intr()
654 edge &= gpio_read(sc, GPIO_INT_LEVEL_MASK, &sc->gpio_pins[i]); in mvebu_gpio_intr()
658 mgi = &sc->isrcs[i]; in mvebu_gpio_intr()
659 if (!mgi->is_level) in mvebu_gpio_intr()
662 if (intr_isrc_dispatch(&mgi->isrc, tf) != 0) { in mvebu_gpio_intr()
664 if (mgi->is_level) in mvebu_gpio_intr()
666 device_printf(sc->dev, in mvebu_gpio_intr()
667 "Stray irq %u disabled\n", mgi->irq); in mvebu_gpio_intr()
679 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) in mvebu_gpio_probe()
694 KASSERT(mtx_initialized(&sc->mtx), ("gpio mutex not initialized")); in mvebu_gpio_detach()
697 if (sc->irq_ih[i] != NULL) in mvebu_gpio_detach()
698 bus_teardown_intr(dev, sc->irq_res[i], sc->irq_ih[i]); in mvebu_gpio_detach()
701 if (sc->isrcs != NULL) in mvebu_gpio_detach()
707 if (sc->irq_res[i] != NULL) in mvebu_gpio_detach()
709 sc->irq_res[i]); in mvebu_gpio_detach()
726 sc->dev = dev; in mvebu_gpio_attach()
735 "ERROR: no pin-count or ngpios entry found!\n"); in mvebu_gpio_attach()
739 sc->gpio_npins = MIN(pincnt, MV_GPIO_MAX_NPINS); in mvebu_gpio_attach()
742 "%d pins available\n", sc->gpio_npins); in mvebu_gpio_attach()
744 rv = OF_getencprop(node, "offset", &sc->offset, sizeof(sc->offset)); in mvebu_gpio_attach()
745 if (rv == -1) { in mvebu_gpio_attach()
750 if (SYSCON_GET_HANDLE(sc->dev, &sc->syscon) != 0 || in mvebu_gpio_attach()
751 sc->syscon == NULL) { in mvebu_gpio_attach()
758 sc->irq_cookies[i].sc = sc; in mvebu_gpio_attach()
759 sc->irq_cookies[i].bank_num = i; in mvebu_gpio_attach()
761 sc->irq_res[i] = bus_alloc_resource_any(dev, SYS_RES_IRQ, in mvebu_gpio_attach()
763 if (sc->irq_res[i] == NULL) in mvebu_gpio_attach()
765 if ((bus_setup_intr(dev, sc->irq_res[i], in mvebu_gpio_attach()
767 &sc->irq_cookies[i], &sc->irq_ih[i]))) { in mvebu_gpio_attach()
776 for (i = 0; i < sc->gpio_npins; i++) { in mvebu_gpio_attach()
777 pin = sc->gpio_pins + i; in mvebu_gpio_attach()
778 pin->gp_pin = i; in mvebu_gpio_attach()
779 if (sc->irq_res[0] != NULL) in mvebu_gpio_attach()
780 pin->gp_caps = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | in mvebu_gpio_attach()
784 pin->gp_caps = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT; in mvebu_gpio_attach()
785 pin->gp_flags = in mvebu_gpio_attach()
786 gpio_read(sc, GPIO_CONTROL, &sc->gpio_pins[i]) == 0 ? in mvebu_gpio_attach()
788 snprintf(pin->gp_name, GPIOMAXNAME, "gpio%d", i); in mvebu_gpio_attach()
798 if (sc->irq_res[0] != NULL) { in mvebu_gpio_attach()
807 sc->busdev = gpiobus_attach_bus(dev); in mvebu_gpio_attach()
808 if (sc->busdev == NULL) { in mvebu_gpio_attach()