summaryrefslogtreecommitdiffstats
path: root/sys/arm/freescale
diff options
context:
space:
mode:
authorian <ian@FreeBSD.org>2016-04-07 19:17:47 +0000
committerian <ian@FreeBSD.org>2016-04-07 19:17:47 +0000
commitd1312255dfda198688cc3865c5da8b0bf08f5672 (patch)
tree8e6a84a9b0ba53662f6af420faf55be6afbd53a5 /sys/arm/freescale
parentda39bc2a5473a8e43c137ad0ebb83b6a230a8ec8 (diff)
downloadFreeBSD-src-d1312255dfda198688cc3865c5da8b0bf08f5672.zip
FreeBSD-src-d1312255dfda198688cc3865c5da8b0bf08f5672.tar.gz
Code cleanup: stop searching for a pin in the array and just use the pin
number directly as an index. We create the array ourselves and nothing can change the order of items in it, it's a simple 1:1 mapping.
Diffstat (limited to 'sys/arm/freescale')
-rw-r--r--sys/arm/freescale/imx/imx_gpio.c66
1 files changed, 15 insertions, 51 deletions
diff --git a/sys/arm/freescale/imx/imx_gpio.c b/sys/arm/freescale/imx/imx_gpio.c
index e67aa66..96b54fb 100644
--- a/sys/arm/freescale/imx/imx_gpio.c
+++ b/sys/arm/freescale/imx/imx_gpio.c
@@ -497,19 +497,14 @@ static int
imx51_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps)
{
struct imx51_gpio_softc *sc;
- int i;
sc = device_get_softc(dev);
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
- if (i >= sc->gpio_npins)
+ if (pin >= sc->gpio_npins)
return (EINVAL);
mtx_lock_spin(&sc->sc_mtx);
- *caps = sc->gpio_pins[i].gp_caps;
+ *caps = sc->gpio_pins[pin].gp_caps;
mtx_unlock_spin(&sc->sc_mtx);
return (0);
@@ -519,19 +514,14 @@ static int
imx51_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags)
{
struct imx51_gpio_softc *sc;
- int i;
sc = device_get_softc(dev);
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
- if (i >= sc->gpio_npins)
+ if (pin >= sc->gpio_npins)
return (EINVAL);
mtx_lock_spin(&sc->sc_mtx);
- *flags = sc->gpio_pins[i].gp_flags;
+ *flags = sc->gpio_pins[pin].gp_flags;
mtx_unlock_spin(&sc->sc_mtx);
return (0);
@@ -541,19 +531,13 @@ static int
imx51_gpio_pin_getname(device_t dev, uint32_t pin, char *name)
{
struct imx51_gpio_softc *sc;
- int i;
sc = device_get_softc(dev);
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
-
- if (i >= sc->gpio_npins)
+ if (pin >= sc->gpio_npins)
return (EINVAL);
mtx_lock_spin(&sc->sc_mtx);
- memcpy(name, sc->gpio_pins[i].gp_name, GPIOMAXNAME);
+ memcpy(name, sc->gpio_pins[pin].gp_name, GPIOMAXNAME);
mtx_unlock_spin(&sc->sc_mtx);
return (0);
@@ -563,18 +547,13 @@ static int
imx51_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags)
{
struct imx51_gpio_softc *sc;
- int i;
sc = device_get_softc(dev);
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
- if (i >= sc->gpio_npins)
+ if (pin >= sc->gpio_npins)
return (EINVAL);
- imx51_gpio_pin_configure(sc, &sc->gpio_pins[i], flags);
+ imx51_gpio_pin_configure(sc, &sc->gpio_pins[pin], flags);
return (0);
}
@@ -583,22 +562,17 @@ static int
imx51_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value)
{
struct imx51_gpio_softc *sc;
- int i;
sc = device_get_softc(dev);
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
- if (i >= sc->gpio_npins)
+ if (pin >= sc->gpio_npins)
return (EINVAL);
mtx_lock_spin(&sc->sc_mtx);
if (value)
- SET4(sc, IMX_GPIO_DR_REG, (1U << i));
+ SET4(sc, IMX_GPIO_DR_REG, (1U << pin));
else
- CLEAR4(sc, IMX_GPIO_DR_REG, (1U << i));
+ CLEAR4(sc, IMX_GPIO_DR_REG, (1U << pin));
mtx_unlock_spin(&sc->sc_mtx);
return (0);
@@ -608,19 +582,14 @@ static int
imx51_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val)
{
struct imx51_gpio_softc *sc;
- int i;
sc = device_get_softc(dev);
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
- if (i >= sc->gpio_npins)
+ if (pin >= sc->gpio_npins)
return (EINVAL);
mtx_lock_spin(&sc->sc_mtx);
- *val = (READ4(sc, IMX_GPIO_DR_REG) >> i) & 1;
+ *val = (READ4(sc, IMX_GPIO_DR_REG) >> pin) & 1;
mtx_unlock_spin(&sc->sc_mtx);
return (0);
@@ -630,20 +599,15 @@ static int
imx51_gpio_pin_toggle(device_t dev, uint32_t pin)
{
struct imx51_gpio_softc *sc;
- int i;
sc = device_get_softc(dev);
- for (i = 0; i < sc->gpio_npins; i++) {
- if (sc->gpio_pins[i].gp_pin == pin)
- break;
- }
- if (i >= sc->gpio_npins)
+ if (pin >= sc->gpio_npins)
return (EINVAL);
mtx_lock_spin(&sc->sc_mtx);
WRITE4(sc, IMX_GPIO_DR_REG,
- (READ4(sc, IMX_GPIO_DR_REG) ^ (1U << i)));
+ (READ4(sc, IMX_GPIO_DR_REG) ^ (1U << pin)));
mtx_unlock_spin(&sc->sc_mtx);
return (0);
OpenPOWER on IntegriCloud