Deleted Added
full compact
avila_gpio.c (277882) avila_gpio.c (277996)
1/*-
2 * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3 * Copyright (c) 2009, Luiz Otavio O Souza.
4 * Copyright (c) 2010, Andrew Thompson <thompsa@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

27 * SUCH DAMAGE.
28 */
29
30/*
31 * GPIO driver for Gateworks Avilia
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3 * Copyright (c) 2009, Luiz Otavio O Souza.
4 * Copyright (c) 2010, Andrew Thompson <thompsa@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

27 * SUCH DAMAGE.
28 */
29
30/*
31 * GPIO driver for Gateworks Avilia
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/avila_gpio.c 277882 2015-01-29 18:08:50Z loos $");
35__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/avila_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#include <arm/xscale/ixp425/ixp425reg.h>
51#include <arm/xscale/ixp425/ixp425var.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#include <arm/xscale/ixp425/ixp425reg.h>
51#include <arm/xscale/ixp425/ixp425var.h>
52#include <dev/gpio/gpiobusvar.h>
52
53#include "gpio_if.h"
54
55#define GPIO_SET_BITS(sc, reg, bits) \
56 GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) | (bits))
57
58#define GPIO_CLEAR_BITS(sc, reg, bits) \
59 GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) & ~(bits))
60
61struct avila_gpio_softc {
62 device_t sc_dev;
53
54#include "gpio_if.h"
55
56#define GPIO_SET_BITS(sc, reg, bits) \
57 GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) | (bits))
58
59#define GPIO_CLEAR_BITS(sc, reg, bits) \
60 GPIO_CONF_WRITE_4(sc, reg, GPIO_CONF_READ_4(sc, (reg)) & ~(bits))
61
62struct avila_gpio_softc {
63 device_t sc_dev;
64 device_t sc_busdev;
63 bus_space_tag_t sc_iot;
64 bus_space_handle_t sc_gpio_ioh;
65 uint32_t sc_valid;
66 struct gpio_pin sc_pins[IXP4XX_GPIO_PINS];
67};
68
69struct avila_gpio_pin {
70 const char *name;

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

111 */
112static int avila_gpio_probe(device_t dev);
113static int avila_gpio_attach(device_t dev);
114static int avila_gpio_detach(device_t dev);
115
116/*
117 * GPIO interface
118 */
65 bus_space_tag_t sc_iot;
66 bus_space_handle_t sc_gpio_ioh;
67 uint32_t sc_valid;
68 struct gpio_pin sc_pins[IXP4XX_GPIO_PINS];
69};
70
71struct avila_gpio_pin {
72 const char *name;

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

113 */
114static int avila_gpio_probe(device_t dev);
115static int avila_gpio_attach(device_t dev);
116static int avila_gpio_detach(device_t dev);
117
118/*
119 * GPIO interface
120 */
121static device_t avila_gpio_get_bus(device_t);
119static int avila_gpio_pin_max(device_t dev, int *maxpin);
120static int avila_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
121static int avila_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
122 *flags);
123static int avila_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
124static int avila_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
125static int avila_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
126static int avila_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);

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

157 else {
158 pin->gp_flags |= GPIO_PIN_INPUT;
159 GPIO_SET_BITS(sc, IXP425_GPIO_GPOER, mask);
160 }
161 IXP4XX_GPIO_UNLOCK();
162 }
163}
164
122static int avila_gpio_pin_max(device_t dev, int *maxpin);
123static int avila_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps);
124static int avila_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t
125 *flags);
126static int avila_gpio_pin_getname(device_t dev, uint32_t pin, char *name);
127static int avila_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags);
128static int avila_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value);
129static int avila_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val);

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

160 else {
161 pin->gp_flags |= GPIO_PIN_INPUT;
162 GPIO_SET_BITS(sc, IXP425_GPIO_GPOER, mask);
163 }
164 IXP4XX_GPIO_UNLOCK();
165 }
166}
167
168static device_t
169avila_gpio_get_bus(device_t dev)
170{
171 struct avila_gpio_softc *sc;
172
173 sc = device_get_softc(dev);
174
175 return (sc->sc_busdev);
176}
177
165static int
166avila_gpio_pin_max(device_t dev, int *maxpin)
167{
168
169 *maxpin = IXP4XX_GPIO_PINS - 1;
170 return (0);
171}
172

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

305
306 strncpy(sc->sc_pins[p->pin].gp_name, p->name, GPIOMAXNAME);
307 sc->sc_pins[p->pin].gp_pin = p->pin;
308 sc->sc_pins[p->pin].gp_caps = p->caps;
309 sc->sc_pins[p->pin].gp_flags = avila_gpio_pin_flags(sc, p->pin);
310 sc->sc_valid |= 1 << p->pin;
311 }
312
178static int
179avila_gpio_pin_max(device_t dev, int *maxpin)
180{
181
182 *maxpin = IXP4XX_GPIO_PINS - 1;
183 return (0);
184}
185

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

318
319 strncpy(sc->sc_pins[p->pin].gp_name, p->name, GPIOMAXNAME);
320 sc->sc_pins[p->pin].gp_pin = p->pin;
321 sc->sc_pins[p->pin].gp_caps = p->caps;
322 sc->sc_pins[p->pin].gp_flags = avila_gpio_pin_flags(sc, p->pin);
323 sc->sc_valid |= 1 << p->pin;
324 }
325
313 device_add_child(dev, "gpioc", -1);
314 device_add_child(dev, "gpiobus", -1);
326 sc->sc_busdev = gpiobus_attach_bus(dev);
327 if (sc->sc_busdev == NULL)
328 return (ENXIO);
315
329
316 return (bus_generic_attach(dev));
330 return (0);
317#undef N
318}
319
320static int
321avila_gpio_detach(device_t dev)
322{
323
331#undef N
332}
333
334static int
335avila_gpio_detach(device_t dev)
336{
337
324 bus_generic_detach(dev);
338 gpiobus_detach_bus(dev);
325
326 return(0);
327}
328
329static device_method_t gpio_avila_methods[] = {
330 DEVMETHOD(device_probe, avila_gpio_probe),
331 DEVMETHOD(device_attach, avila_gpio_attach),
332 DEVMETHOD(device_detach, avila_gpio_detach),
333
334 /* GPIO protocol */
339
340 return(0);
341}
342
343static device_method_t gpio_avila_methods[] = {
344 DEVMETHOD(device_probe, avila_gpio_probe),
345 DEVMETHOD(device_attach, avila_gpio_attach),
346 DEVMETHOD(device_detach, avila_gpio_detach),
347
348 /* GPIO protocol */
349 DEVMETHOD(gpio_get_bus, avila_gpio_get_bus),
335 DEVMETHOD(gpio_pin_max, avila_gpio_pin_max),
336 DEVMETHOD(gpio_pin_getname, avila_gpio_pin_getname),
337 DEVMETHOD(gpio_pin_getflags, avila_gpio_pin_getflags),
338 DEVMETHOD(gpio_pin_getcaps, avila_gpio_pin_getcaps),
339 DEVMETHOD(gpio_pin_setflags, avila_gpio_pin_setflags),
340 DEVMETHOD(gpio_pin_get, avila_gpio_pin_get),
341 DEVMETHOD(gpio_pin_set, avila_gpio_pin_set),
342 DEVMETHOD(gpio_pin_toggle, avila_gpio_pin_toggle),

--- 12 unchanged lines hidden ---
350 DEVMETHOD(gpio_pin_max, avila_gpio_pin_max),
351 DEVMETHOD(gpio_pin_getname, avila_gpio_pin_getname),
352 DEVMETHOD(gpio_pin_getflags, avila_gpio_pin_getflags),
353 DEVMETHOD(gpio_pin_getcaps, avila_gpio_pin_getcaps),
354 DEVMETHOD(gpio_pin_setflags, avila_gpio_pin_setflags),
355 DEVMETHOD(gpio_pin_get, avila_gpio_pin_get),
356 DEVMETHOD(gpio_pin_set, avila_gpio_pin_set),
357 DEVMETHOD(gpio_pin_toggle, avila_gpio_pin_toggle),

--- 12 unchanged lines hidden ---