Deleted Added
full compact
bcm2835_gpio.c (255334) bcm2835_gpio.c (255370)
1/*-
2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * Copyright (c) 2012 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:

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

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * Copyright (c) 2012 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:

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

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c 255334 2013-09-06 23:39:56Z loos $");
29__FBSDID("$FreeBSD: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c 255370 2013-09-07 18:48:15Z loos $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/bus.h>
34
35#include <sys/kernel.h>
36#include <sys/module.h>
37#include <sys/rman.h>

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

47#include <machine/fdt.h>
48#include <machine/frame.h>
49#include <machine/intr.h>
50
51#include <dev/fdt/fdt_common.h>
52#include <dev/ofw/ofw_bus.h>
53#include <dev/ofw/ofw_bus_subr.h>
54
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/bus.h>
34
35#include <sys/kernel.h>
36#include <sys/module.h>
37#include <sys/rman.h>

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

47#include <machine/fdt.h>
48#include <machine/frame.h>
49#include <machine/intr.h>
50
51#include <dev/fdt/fdt_common.h>
52#include <dev/ofw/ofw_bus.h>
53#include <dev/ofw/ofw_bus_subr.h>
54
55#include <arm/broadcom/bcm2835/bcm2835_gpio.h>
56
55#include "gpio_if.h"
56
57#undef DEBUG
58
59#ifdef DEBUG
60#define dprintf(fmt, args...) do { printf("%s(): ", __func__); \
61 printf(fmt,##args); } while (0)
62#else

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

82 void * sc_intrhand;
83 int sc_gpio_npins;
84 int sc_ro_npins;
85 int sc_ro_pins[BCM_GPIO_PINS];
86 struct gpio_pin sc_gpio_pins[BCM_GPIO_PINS];
87 struct bcm_gpio_sysctl sc_sysctl[BCM_GPIO_PINS];
88};
89
57#include "gpio_if.h"
58
59#undef DEBUG
60
61#ifdef DEBUG
62#define dprintf(fmt, args...) do { printf("%s(): ", __func__); \
63 printf(fmt,##args); } while (0)
64#else

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

84 void * sc_intrhand;
85 int sc_gpio_npins;
86 int sc_ro_npins;
87 int sc_ro_pins[BCM_GPIO_PINS];
88 struct gpio_pin sc_gpio_pins[BCM_GPIO_PINS];
89 struct bcm_gpio_sysctl sc_sysctl[BCM_GPIO_PINS];
90};
91
90enum bcm_gpio_fsel {
91 BCM_GPIO_INPUT,
92 BCM_GPIO_OUTPUT,
93 BCM_GPIO_ALT5,
94 BCM_GPIO_ALT4,
95 BCM_GPIO_ALT0,
96 BCM_GPIO_ALT1,
97 BCM_GPIO_ALT2,
98 BCM_GPIO_ALT3,
99};
100
101enum bcm_gpio_pud {
102 BCM_GPIO_NONE,
103 BCM_GPIO_PULLDOWN,
104 BCM_GPIO_PULLUP,
105};
106
107#define BCM_GPIO_LOCK(_sc) mtx_lock(&_sc->sc_mtx)
108#define BCM_GPIO_UNLOCK(_sc) mtx_unlock(&_sc->sc_mtx)

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

252 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), state);
253 DELAY(10);
254 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), (1 << offset));
255 DELAY(10);
256 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), 0);
257 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), 0);
258}
259
92enum bcm_gpio_pud {
93 BCM_GPIO_NONE,
94 BCM_GPIO_PULLDOWN,
95 BCM_GPIO_PULLUP,
96};
97
98#define BCM_GPIO_LOCK(_sc) mtx_lock(&_sc->sc_mtx)
99#define BCM_GPIO_UNLOCK(_sc) mtx_unlock(&_sc->sc_mtx)

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

243 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), state);
244 DELAY(10);
245 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), (1 << offset));
246 DELAY(10);
247 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), 0);
248 BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), 0);
249}
250
251void
252bcm_gpio_set_alternate(device_t dev, uint32_t pin, uint32_t nfunc)
253{
254 struct bcm_gpio_softc *sc;
255 int i;
256
257 sc = device_get_softc(dev);
258 BCM_GPIO_LOCK(sc);
259
260 /* Disable pull-up or pull-down on pin. */
261 bcm_gpio_set_pud(sc, pin, BCM_GPIO_NONE);
262
263 /* And now set the pin function. */
264 bcm_gpio_set_function(sc, pin, nfunc);
265
266 /* Update the pin flags. */
267 for (i = 0; i < sc->sc_gpio_npins; i++) {
268 if (sc->sc_gpio_pins[i].gp_pin == pin)
269 break;
270 }
271 if (i < sc->sc_gpio_npins)
272 sc->sc_gpio_pins[i].gp_flags = bcm_gpio_func_flag(nfunc);
273
274 BCM_GPIO_UNLOCK(sc);
275}
276
260static void
261bcm_gpio_pin_configure(struct bcm_gpio_softc *sc, struct gpio_pin *pin,
262 unsigned int flags)
263{
264
265 BCM_GPIO_LOCK(sc);
266
267 /*

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

530
531static int
532bcm_gpio_func_proc(SYSCTL_HANDLER_ARGS)
533{
534 char buf[16];
535 struct bcm_gpio_softc *sc;
536 struct bcm_gpio_sysctl *sc_sysctl;
537 uint32_t nfunc;
277static void
278bcm_gpio_pin_configure(struct bcm_gpio_softc *sc, struct gpio_pin *pin,
279 unsigned int flags)
280{
281
282 BCM_GPIO_LOCK(sc);
283
284 /*

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

547
548static int
549bcm_gpio_func_proc(SYSCTL_HANDLER_ARGS)
550{
551 char buf[16];
552 struct bcm_gpio_softc *sc;
553 struct bcm_gpio_sysctl *sc_sysctl;
554 uint32_t nfunc;
538 int i, error;
555 int error;
539
540 sc_sysctl = arg1;
541 sc = sc_sysctl->sc;
542
543 /* Get the current pin function. */
544 nfunc = bcm_gpio_get_function(sc, sc_sysctl->pin);
545 bcm_gpio_func_str(nfunc, buf, sizeof(buf));
546
547 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
548 if (error != 0 || req->newptr == NULL)
549 return (error);
550
551 /* Parse the user supplied string and check for a valid pin function. */
552 if (bcm_gpio_str_func(buf, &nfunc) != 0)
553 return (EINVAL);
554
556
557 sc_sysctl = arg1;
558 sc = sc_sysctl->sc;
559
560 /* Get the current pin function. */
561 nfunc = bcm_gpio_get_function(sc, sc_sysctl->pin);
562 bcm_gpio_func_str(nfunc, buf, sizeof(buf));
563
564 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
565 if (error != 0 || req->newptr == NULL)
566 return (error);
567
568 /* Parse the user supplied string and check for a valid pin function. */
569 if (bcm_gpio_str_func(buf, &nfunc) != 0)
570 return (EINVAL);
571
555 BCM_GPIO_LOCK(sc);
572 /* Update the pin alternate function. */
573 bcm_gpio_set_alternate(sc->sc_dev, sc_sysctl->pin, nfunc);
556
574
557 /* Disable pull-up or pull-down on pin. */
558 bcm_gpio_set_pud(sc, sc_sysctl->pin, BCM_GPIO_NONE);
559
560 /* And now set the pin function. */
561 bcm_gpio_set_function(sc, sc_sysctl->pin, nfunc);
562
563 /* Update the pin flags. */
564 for (i = 0; i < sc->sc_gpio_npins; i++) {
565 if (sc->sc_gpio_pins[i].gp_pin == sc_sysctl->pin)
566 break;
567 }
568 if (i < sc->sc_gpio_npins)
569 sc->sc_gpio_pins[i].gp_flags = bcm_gpio_func_flag(nfunc);
570
571 BCM_GPIO_UNLOCK(sc);
572
573 return (0);
574}
575
576static void
577bcm_gpio_sysctl_init(struct bcm_gpio_softc *sc)
578{
579 char pinbuf[3];
580 struct bcm_gpio_sysctl *sc_sysctl;

--- 213 unchanged lines hidden ---
575 return (0);
576}
577
578static void
579bcm_gpio_sysctl_init(struct bcm_gpio_softc *sc)
580{
581 char pinbuf[3];
582 struct bcm_gpio_sysctl *sc_sysctl;

--- 213 unchanged lines hidden ---