Deleted Added
full compact
imx_gpio.c (277968) imx_gpio.c (277996)
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>
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 $");
35__FBSDID("$FreeBSD: head/sys/arm/freescale/imx/imx_gpio.c 277996 2015-01-31 19:32:14Z 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>
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/gpio/gpiobusvar.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;
53#include <dev/ofw/openfirm.h>
54#include <dev/ofw/ofw_bus.h>
55#include <dev/ofw/ofw_bus_subr.h>
56
57#include "gpio_if.h"
58
59#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
60#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)

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

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

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

142static int imx51_gpio_probe(device_t);
143static int imx51_gpio_attach(device_t);
144static int imx51_gpio_detach(device_t);
145static int imx51_gpio_intr(void *);
146
147/*
148 * GPIO interface
149 */
150static device_t imx51_gpio_get_bus(device_t);
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
151static int imx51_gpio_pin_max(device_t, int *);
152static int imx51_gpio_pin_getcaps(device_t, uint32_t, uint32_t *);
153static int imx51_gpio_pin_getflags(device_t, uint32_t, uint32_t *);
154static int imx51_gpio_pin_getname(device_t, uint32_t, char *);
155static int imx51_gpio_pin_setflags(device_t, uint32_t, uint32_t);
156static int imx51_gpio_pin_set(device_t, uint32_t, unsigned int);
157static int imx51_gpio_pin_get(device_t, uint32_t, unsigned int *);
158static int imx51_gpio_pin_toggle(device_t, uint32_t pin);

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

177 pin->gp_flags |= GPIO_PIN_INPUT;
178 CLEAR4(sc, IMX_GPIO_OE_REG, (1 << pin->gp_pin));
179 }
180 }
181
182 GPIO_UNLOCK(sc);
183}
184
185static device_t
186imx51_gpio_get_bus(device_t dev)
187{
188 struct imx51_gpio_softc *sc;
189
190 sc = device_get_softc(dev);
191
192 return (sc->sc_busdev);
193}
194
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 }
195static int
196imx51_gpio_pin_max(device_t dev, int *maxpin)
197{
198
199 *maxpin = NGPIO - 1;
200 return (0);
201}
202

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

435 sc->gpio_pins[i].gp_pin = i;
436 sc->gpio_pins[i].gp_caps = DEFAULT_CAPS;
437 sc->gpio_pins[i].gp_flags =
438 (READ4(sc, IMX_GPIO_OE_REG) & (1 << i)) ? GPIO_PIN_OUTPUT:
439 GPIO_PIN_INPUT;
440 snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME,
441 "imx_gpio%d.%d", device_get_unit(dev), i);
442 }
443 sc->sc_busdev = gpiobus_attach_bus(dev);
444 if (sc->sc_busdev == NULL) {
445 imx51_gpio_detach(dev);
446 return (ENXIO);
447 }
430
448
431 device_add_child(dev, "gpioc", -1);
432 device_add_child(dev, "gpiobus", -1);
433
434 return (bus_generic_attach(dev));
449 return (0);
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
450}
451
452static int
453imx51_gpio_detach(device_t dev)
454{
455 int irq;
456 struct imx51_gpio_softc *sc;
457
458 sc = device_get_softc(dev);
459
460 KASSERT(mtx_initialized(&sc->sc_mtx), ("gpio mutex not initialized"));
461
447 bus_generic_detach(dev);
462 gpiobus_detach_bus(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 */
463 for (irq = 1; irq <= sc->sc_l_irq; irq ++) {
464 if (sc->gpio_ih[irq])
465 bus_teardown_intr(dev, sc->sc_res[irq], sc->gpio_ih[irq]);
466 }
467 bus_release_resources(dev, imx_gpio0irq_spec, &sc->sc_res[3]);
468 bus_release_resources(dev, imx_gpio_spec, sc->sc_res);
469 mtx_destroy(&sc->sc_mtx);
470
471 return(0);
472}
473
474static device_method_t imx51_gpio_methods[] = {
475 DEVMETHOD(device_probe, imx51_gpio_probe),
476 DEVMETHOD(device_attach, imx51_gpio_attach),
477 DEVMETHOD(device_detach, imx51_gpio_detach),
478
479 /* GPIO protocol */
480 DEVMETHOD(gpio_get_bus, imx51_gpio_get_bus),
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 ---
481 DEVMETHOD(gpio_pin_max, imx51_gpio_pin_max),
482 DEVMETHOD(gpio_pin_getname, imx51_gpio_pin_getname),
483 DEVMETHOD(gpio_pin_getflags, imx51_gpio_pin_getflags),
484 DEVMETHOD(gpio_pin_getcaps, imx51_gpio_pin_getcaps),
485 DEVMETHOD(gpio_pin_setflags, imx51_gpio_pin_setflags),
486 DEVMETHOD(gpio_pin_get, imx51_gpio_pin_get),
487 DEVMETHOD(gpio_pin_set, imx51_gpio_pin_set),
488 DEVMETHOD(gpio_pin_toggle, imx51_gpio_pin_toggle),

--- 12 unchanged lines hidden ---