Deleted Added
sdiff udiff text old ( 277968 ) new ( 277996 )
full compact
1/*-
2 * Copyright (c) 2012, 2013 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Oleksandr Rybalko under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

27 * SUCH DAMAGE.
28 */
29
30/*
31 * Freescale i.MX515 GPIO driver.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/arm/freescale/imx/imx_gpio.c 277968 2015-01-31 12:17:07Z loos $");
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/bus.h>
40
41#include <sys/kernel.h>
42#include <sys/module.h>
43#include <sys/rman.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/gpio.h>
47
48#include <machine/bus.h>
49#include <machine/resource.h>
50
51#include <dev/fdt/fdt_common.h>
52#include <dev/ofw/openfirm.h>
53#include <dev/ofw/ofw_bus.h>
54#include <dev/ofw/ofw_bus_subr.h>
55
56#include "gpio_if.h"
57
58#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
59#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)

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

87#define IMX_GPIO_ISR_REG 0x018 /* Interrupt Status Register */
88#define IMX_GPIO_EDGE_REG 0x01C /* Edge Detect Register */
89
90#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)
91#define NGPIO 32
92
93struct imx51_gpio_softc {
94 device_t dev;
95 struct mtx sc_mtx;
96 struct resource *sc_res[11]; /* 1 x mem, 2 x IRQ, 8 x IRQ */
97 void *gpio_ih[11]; /* 1 ptr is not a big waste */
98 int sc_l_irq; /* Last irq resource */
99 bus_space_tag_t sc_iot;
100 bus_space_handle_t sc_ioh;
101 int gpio_npins;
102 struct gpio_pin gpio_pins[NGPIO];

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

140static int imx51_gpio_probe(device_t);
141static int imx51_gpio_attach(device_t);
142static int imx51_gpio_detach(device_t);
143static int imx51_gpio_intr(void *);
144
145/*
146 * GPIO interface
147 */
148static int imx51_gpio_pin_max(device_t, int *);
149static int imx51_gpio_pin_getcaps(device_t, uint32_t, uint32_t *);
150static int imx51_gpio_pin_getflags(device_t, uint32_t, uint32_t *);
151static int imx51_gpio_pin_getname(device_t, uint32_t, char *);
152static int imx51_gpio_pin_setflags(device_t, uint32_t, uint32_t);
153static int imx51_gpio_pin_set(device_t, uint32_t, unsigned int);
154static int imx51_gpio_pin_get(device_t, uint32_t, unsigned int *);
155static int imx51_gpio_pin_toggle(device_t, uint32_t pin);

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

174 pin->gp_flags |= GPIO_PIN_INPUT;
175 CLEAR4(sc, IMX_GPIO_OE_REG, (1 << pin->gp_pin));
176 }
177 }
178
179 GPIO_UNLOCK(sc);
180}
181
182static int
183imx51_gpio_pin_max(device_t dev, int *maxpin)
184{
185
186 *maxpin = NGPIO - 1;
187 return (0);
188}
189

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

422 sc->gpio_pins[i].gp_pin = i;
423 sc->gpio_pins[i].gp_caps = DEFAULT_CAPS;
424 sc->gpio_pins[i].gp_flags =
425 (READ4(sc, IMX_GPIO_OE_REG) & (1 << i)) ? GPIO_PIN_OUTPUT:
426 GPIO_PIN_INPUT;
427 snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME,
428 "imx_gpio%d.%d", device_get_unit(dev), i);
429 }
430
431 device_add_child(dev, "gpioc", -1);
432 device_add_child(dev, "gpiobus", -1);
433
434 return (bus_generic_attach(dev));
435}
436
437static int
438imx51_gpio_detach(device_t dev)
439{
440 int irq;
441 struct imx51_gpio_softc *sc;
442
443 sc = device_get_softc(dev);
444
445 KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized"));
446
447 bus_generic_detach(dev);
448 for (irq = 1; irq <= sc->sc_l_irq; irq ++) {
449 if (sc->gpio_ih[irq])
450 bus_teardown_intr(dev, sc->sc_res[irq], sc->gpio_ih[irq]);
451 }
452 bus_release_resources(dev, imx_gpio0irq_spec, &sc->sc_res[3]);
453 bus_release_resources(dev, imx_gpio_spec, sc->sc_res);
454 mtx_destroy(&sc->sc_mtx);
455
456 return(0);
457}
458
459static device_method_t imx51_gpio_methods[] = {
460 DEVMETHOD(device_probe, imx51_gpio_probe),
461 DEVMETHOD(device_attach, imx51_gpio_attach),
462 DEVMETHOD(device_detach, imx51_gpio_detach),
463
464 /* GPIO protocol */
465 DEVMETHOD(gpio_pin_max, imx51_gpio_pin_max),
466 DEVMETHOD(gpio_pin_getname, imx51_gpio_pin_getname),
467 DEVMETHOD(gpio_pin_getflags, imx51_gpio_pin_getflags),
468 DEVMETHOD(gpio_pin_getcaps, imx51_gpio_pin_getcaps),
469 DEVMETHOD(gpio_pin_setflags, imx51_gpio_pin_setflags),
470 DEVMETHOD(gpio_pin_get, imx51_gpio_pin_get),
471 DEVMETHOD(gpio_pin_set, imx51_gpio_pin_set),
472 DEVMETHOD(gpio_pin_toggle, imx51_gpio_pin_toggle),

--- 12 unchanged lines hidden ---