Deleted Added
sdiff udiff text old ( 277968 ) new ( 277996 )
full compact
1/*-
2 * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3 * Copyright (c) 2009, 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:

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

26 * SUCH DAMAGE.
27 */
28
29/*
30 * GPIO driver for AR71xx
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/mips/atheros/ar71xx_gpio.c 277996 2015-01-31 19:32:14Z loos $");
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/bus.h>
39
40#include <sys/kernel.h>
41#include <sys/module.h>
42#include <sys/rman.h>

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

47
48#include <machine/bus.h>
49#include <machine/resource.h>
50#include <mips/atheros/ar71xxreg.h>
51#include <mips/atheros/ar71xx_setup.h>
52#include <mips/atheros/ar71xx_gpiovar.h>
53#include <mips/atheros/ar933xreg.h>
54#include <mips/atheros/ar934xreg.h>
55#include <dev/gpio/gpiobusvar.h>
56
57#include "gpio_if.h"
58
59#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)
60
61/*
62 * Helpers
63 */

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

75static int ar71xx_gpio_attach(device_t dev);
76static int ar71xx_gpio_detach(device_t dev);
77static int ar71xx_gpio_filter(void *arg);
78static void ar71xx_gpio_intr(void *arg);
79
80/*
81 * GPIO interface
82 */
83static device_t ar71xx_gpio_get_bus(device_t);
84static int ar71xx_gpio_pin_max(device_t dev, int *maxpin);
85static int ar71xx_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
86static int ar71xx_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
87 *flags);
88static int ar71xx_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
89static int ar71xx_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
90static int ar71xx_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
91static int ar71xx_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);

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

132 }
133 else {
134 pin->gp_flags |= GPIO_PIN_INPUT;
135 GPIO_CLEAR_BITS(sc, AR71XX_GPIO_OE, mask);
136 }
137 }
138}
139
140static device_t
141ar71xx_gpio_get_bus(device_t dev)
142{
143 struct ar71xx_gpio_softc *sc;
144
145 sc = device_get_softc(dev);
146
147 return (sc->busdev);
148}
149
150static int
151ar71xx_gpio_pin_max(device_t dev, int *maxpin)
152{
153
154 switch (ar71xx_soc) {
155 case AR71XX_SOC_AR9130:
156 case AR71XX_SOC_AR9132:
157 *maxpin = AR91XX_GPIO_PINS - 1;

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

440 /* Turn on the hinted pins. */
441 for (i = 0; i < sc->gpio_npins; i++) {
442 j = sc->gpio_pins[i].gp_pin;
443 if ((pinon & (1 << j)) != 0) {
444 ar71xx_gpio_pin_setflags(dev, j, GPIO_PIN_OUTPUT);
445 ar71xx_gpio_pin_set(dev, j, 1);
446 }
447 }
448 sc->busdev = gpiobus_attach_bus(dev);
449 if (sc->busdev == NULL) {
450 ar71xx_gpio_detach(dev);
451 return (ENXIO);
452 }
453
454 return (0);
455}
456
457static int
458ar71xx_gpio_detach(device_t dev)
459{
460 struct ar71xx_gpio_softc *sc = device_get_softc(dev);
461
462 KASSERT(mtx_initialized(&sc->gpio_mtx), ("gpio mutex not initialized"));
463
464 gpiobus_detach_bus(dev);
465 if (sc->gpio_ih)
466 bus_teardown_intr(dev, sc->gpio_irq_res, sc->gpio_ih);
467 if (sc->gpio_irq_res)
468 bus_release_resource(dev, SYS_RES_IRQ, sc->gpio_irq_rid,
469 sc->gpio_irq_res);
470 if (sc->gpio_mem_res)
471 bus_release_resource(dev, SYS_RES_MEMORY, sc->gpio_mem_rid,
472 sc->gpio_mem_res);

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

478}
479
480static device_method_t ar71xx_gpio_methods[] = {
481 DEVMETHOD(device_probe, ar71xx_gpio_probe),
482 DEVMETHOD(device_attach, ar71xx_gpio_attach),
483 DEVMETHOD(device_detach, ar71xx_gpio_detach),
484
485 /* GPIO protocol */
486 DEVMETHOD(gpio_get_bus, ar71xx_gpio_get_bus),
487 DEVMETHOD(gpio_pin_max, ar71xx_gpio_pin_max),
488 DEVMETHOD(gpio_pin_getname, ar71xx_gpio_pin_getname),
489 DEVMETHOD(gpio_pin_getflags, ar71xx_gpio_pin_getflags),
490 DEVMETHOD(gpio_pin_getcaps, ar71xx_gpio_pin_getcaps),
491 DEVMETHOD(gpio_pin_setflags, ar71xx_gpio_pin_setflags),
492 DEVMETHOD(gpio_pin_get, ar71xx_gpio_pin_get),
493 DEVMETHOD(gpio_pin_set, ar71xx_gpio_pin_set),
494 DEVMETHOD(gpio_pin_toggle, ar71xx_gpio_pin_toggle),
495 {0, 0},
496};
497
498static driver_t ar71xx_gpio_driver = {
499 "gpio",
500 ar71xx_gpio_methods,
501 sizeof(struct ar71xx_gpio_softc),
502};
503static devclass_t ar71xx_gpio_devclass;
504
505DRIVER_MODULE(ar71xx_gpio, apb, ar71xx_gpio_driver, ar71xx_gpio_devclass, 0, 0);