Deleted Added
full compact
ar71xx_gpio.c (277968) ar71xx_gpio.c (277996)
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>
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 277968 2015-01-31 12:17:07Z loos $");
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>
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>
55
56#include "gpio_if.h"
57
58#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)
59
60/*
61 * Helpers
62 */

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

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

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

130 }
131 else {
132 pin->gp_flags |= GPIO_PIN_INPUT;
133 GPIO_CLEAR_BITS(sc, AR71XX_GPIO_OE, mask);
134 }
135 }
136}
137
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
138static int
139ar71xx_gpio_pin_max(device_t dev, int *maxpin)
140{
141
142 switch (ar71xx_soc) {
143 case AR71XX_SOC_AR9130:
144 case AR71XX_SOC_AR9132:
145 *maxpin = AR91XX_GPIO_PINS - 1;

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

428 /* Turn on the hinted pins. */
429 for (i = 0; i < sc->gpio_npins; i++) {
430 j = sc->gpio_pins[i].gp_pin;
431 if ((pinon & (1 << j)) != 0) {
432 ar71xx_gpio_pin_setflags(dev, j, GPIO_PIN_OUTPUT);
433 ar71xx_gpio_pin_set(dev, j, 1);
434 }
435 }
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 }
436 device_add_child(dev, "gpioc", -1);
437 device_add_child(dev, "gpiobus", -1);
448 sc->busdev = gpiobus_attach_bus(dev);
449 if (sc->busdev == NULL) {
450 ar71xx_gpio_detach(dev);
451 return (ENXIO);
452 }
438
453
439 return (bus_generic_attach(dev));
454 return (0);
440}
441
442static int
443ar71xx_gpio_detach(device_t dev)
444{
445 struct ar71xx_gpio_softc *sc = device_get_softc(dev);
446
447 KASSERT(mtx_initialized(&sc->gpio_mtx), ("gpio mutex not initialized"));
448
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
449 bus_generic_detach(dev);
464 gpiobus_detach_bus(dev);
450 if (sc->gpio_ih)
451 bus_teardown_intr(dev, sc->gpio_irq_res, sc->gpio_ih);
452 if (sc->gpio_irq_res)
453 bus_release_resource(dev, SYS_RES_IRQ, sc->gpio_irq_rid,
454 sc->gpio_irq_res);
455 if (sc->gpio_mem_res)
456 bus_release_resource(dev, SYS_RES_MEMORY, sc->gpio_mem_rid,
457 sc->gpio_mem_res);

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

463}
464
465static device_method_t ar71xx_gpio_methods[] = {
466 DEVMETHOD(device_probe, ar71xx_gpio_probe),
467 DEVMETHOD(device_attach, ar71xx_gpio_attach),
468 DEVMETHOD(device_detach, ar71xx_gpio_detach),
469
470 /* GPIO protocol */
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),
471 DEVMETHOD(gpio_pin_max, ar71xx_gpio_pin_max),
472 DEVMETHOD(gpio_pin_getname, ar71xx_gpio_pin_getname),
473 DEVMETHOD(gpio_pin_getflags, ar71xx_gpio_pin_getflags),
474 DEVMETHOD(gpio_pin_getcaps, ar71xx_gpio_pin_getcaps),
475 DEVMETHOD(gpio_pin_setflags, ar71xx_gpio_pin_setflags),
476 DEVMETHOD(gpio_pin_get, ar71xx_gpio_pin_get),
477 DEVMETHOD(gpio_pin_set, ar71xx_gpio_pin_set),
478 DEVMETHOD(gpio_pin_toggle, ar71xx_gpio_pin_toggle),
479 {0, 0},
480};
481
482static driver_t ar71xx_gpio_driver = {
483 "gpio",
484 ar71xx_gpio_methods,
485 sizeof(struct ar71xx_gpio_softc),
486};
487static devclass_t ar71xx_gpio_devclass;
488
489DRIVER_MODULE(ar71xx_gpio, apb, ar71xx_gpio_driver, ar71xx_gpio_devclass, 0, 0);
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);