diff options
author | loos <loos@FreeBSD.org> | 2015-02-17 20:37:21 +0000 |
---|---|---|
committer | loos <loos@FreeBSD.org> | 2015-02-17 20:37:21 +0000 |
commit | b42715ff599b5c1c22ff6007219090aae17676d8 (patch) | |
tree | 0c6c4f8c087e6ca914412bc4397d369240eedca2 /sys/arm | |
parent | 477e4ca1dbfe93ac7de4b79b9459b1ecf606ff29 (diff) | |
download | FreeBSD-src-b42715ff599b5c1c22ff6007219090aae17676d8.zip FreeBSD-src-b42715ff599b5c1c22ff6007219090aae17676d8.tar.gz |
Make use of the newly introduced macros.
Update the copyright.
Diffstat (limited to 'sys/arm')
-rw-r--r-- | sys/arm/broadcom/bcm2835/bcm2835_gpio.c | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/sys/arm/broadcom/bcm2835/bcm2835_gpio.c b/sys/arm/broadcom/bcm2835/bcm2835_gpio.c index 97256f7..6fff6d8 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_gpio.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_gpio.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> - * Copyright (c) 2012 Luiz Otavio O Souza. + * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@FreeBSD.org> + * Copyright (c) 2012-2015 Luiz Otavio O Souza <loos@FreeBSD.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -251,16 +251,14 @@ bcm_gpio_set_function(struct bcm_gpio_softc *sc, uint32_t pin, uint32_t f) static void bcm_gpio_set_pud(struct bcm_gpio_softc *sc, uint32_t pin, uint32_t state) { - uint32_t bank, offset; + uint32_t bank; /* Must be called with lock held. */ BCM_GPIO_LOCK_ASSERT(sc); - bank = pin / 32; - offset = pin - 32 * bank; - + bank = BCM_GPIO_BANK(pin); BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), state); - BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), (1 << offset)); + BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), BCM_GPIO_MASK(pin)); BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUD(0), 0); BCM_GPIO_WRITE(sc, BCM_GPIO_GPPUDCLK(bank), 0); } @@ -438,29 +436,25 @@ static int bcm_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) { struct bcm_gpio_softc *sc = device_get_softc(dev); - uint32_t bank, offset; + uint32_t bank, reg; int i; for (i = 0; i < sc->sc_gpio_npins; i++) { if (sc->sc_gpio_pins[i].gp_pin == pin) break; } - if (i >= sc->sc_gpio_npins) return (EINVAL); - /* We never write to read-only/reserved pins. */ if (bcm_gpio_pin_is_ro(sc, pin)) return (EINVAL); - - bank = pin / 32; - offset = pin - 32 * bank; - BCM_GPIO_LOCK(sc); + bank = BCM_GPIO_BANK(pin); if (value) - BCM_GPIO_WRITE(sc, BCM_GPIO_GPSET(bank), (1 << offset)); + reg = BCM_GPIO_GPSET(bank); else - BCM_GPIO_WRITE(sc, BCM_GPIO_GPCLR(bank), (1 << offset)); + reg = BCM_GPIO_GPCLR(bank); + BCM_GPIO_WRITE(sc, reg, BCM_GPIO_MASK(pin)); BCM_GPIO_UNLOCK(sc); return (0); @@ -470,24 +464,20 @@ static int bcm_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) { struct bcm_gpio_softc *sc = device_get_softc(dev); - uint32_t bank, offset, reg_data; + uint32_t bank, reg_data; int i; for (i = 0; i < sc->sc_gpio_npins; i++) { if (sc->sc_gpio_pins[i].gp_pin == pin) break; } - if (i >= sc->sc_gpio_npins) return (EINVAL); - - bank = pin / 32; - offset = pin - 32 * bank; - + bank = BCM_GPIO_BANK(pin); BCM_GPIO_LOCK(sc); reg_data = BCM_GPIO_READ(sc, BCM_GPIO_GPLEV(bank)); BCM_GPIO_UNLOCK(sc); - *val = (reg_data & (1 << offset)) ? 1 : 0; + *val = (reg_data & BCM_GPIO_MASK(pin)) ? 1 : 0; return (0); } @@ -496,30 +486,26 @@ static int bcm_gpio_pin_toggle(device_t dev, uint32_t pin) { struct bcm_gpio_softc *sc = device_get_softc(dev); - uint32_t bank, data, offset; + uint32_t bank, data, reg; int i; for (i = 0; i < sc->sc_gpio_npins; i++) { if (sc->sc_gpio_pins[i].gp_pin == pin) break; } - if (i >= sc->sc_gpio_npins) return (EINVAL); - /* We never write to read-only/reserved pins. */ if (bcm_gpio_pin_is_ro(sc, pin)) return (EINVAL); - - bank = pin / 32; - offset = pin - 32 * bank; - BCM_GPIO_LOCK(sc); + bank = BCM_GPIO_BANK(pin); data = BCM_GPIO_READ(sc, BCM_GPIO_GPLEV(bank)); - if (data & (1 << offset)) - BCM_GPIO_WRITE(sc, BCM_GPIO_GPCLR(bank), (1 << offset)); + if (data & BCM_GPIO_MASK(pin)) + reg = BCM_GPIO_GPCLR(bank); else - BCM_GPIO_WRITE(sc, BCM_GPIO_GPSET(bank), (1 << offset)); + reg = BCM_GPIO_GPSET(bank); + BCM_GPIO_WRITE(sc, reg, BCM_GPIO_MASK(pin)); BCM_GPIO_UNLOCK(sc); return (0); |