sh-pfc: Simplify the sh_pfc_gpio_is_pin() logic
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Thu, 14 Feb 2013 21:12:11 +0000 (22:12 +0100)
committerLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Fri, 15 Mar 2013 12:33:39 +0000 (13:33 +0100)
The function is guaranteed to be called with a gpio number smaller than
nr_pins. The condition can the be simplified, and the function inlined.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
drivers/pinctrl/sh-pfc/core.c
drivers/pinctrl/sh-pfc/core.h
drivers/pinctrl/sh-pfc/gpio.c

index 3387f824920b51609a9debd32c667de2b7e21061..9b5c0319eb77174eda6ac94d03b22e2a3b2015fb 100644 (file)
@@ -89,12 +89,6 @@ static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r)
        return 1;
 }
 
-static bool sh_pfc_gpio_is_pin(struct sh_pfc *pfc, unsigned int gpio)
-{
-       return (gpio < pfc->info->nr_pins) &&
-              (pfc->info->pins[gpio].enum_id != 0);
-}
-
 static unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg,
                                         unsigned long reg_width)
 {
@@ -226,15 +220,12 @@ static void sh_pfc_write_config_reg(struct sh_pfc *pfc,
        sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data);
 }
 
-static int sh_pfc_setup_data_reg(struct sh_pfc *pfc, unsigned gpio)
+static void sh_pfc_setup_data_reg(struct sh_pfc *pfc, unsigned gpio)
 {
        struct sh_pfc_pin *gpiop = &pfc->info->pins[gpio];
        struct pinmux_data_reg *data_reg;
        int k, n;
 
-       if (!sh_pfc_gpio_is_pin(pfc, gpio))
-               return -1;
-
        k = 0;
        while (1) {
                data_reg = pfc->info->data_regs + k;
@@ -250,15 +241,13 @@ static int sh_pfc_setup_data_reg(struct sh_pfc *pfc, unsigned gpio)
                                gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT);
                                gpiop->flags &= ~PINMUX_FLAG_DBIT;
                                gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT);
-                               return 0;
+                               return;
                        }
                }
                k++;
        }
 
        BUG();
-
-       return -1;
 }
 
 static void sh_pfc_setup_data_regs(struct sh_pfc *pfc)
@@ -266,8 +255,12 @@ static void sh_pfc_setup_data_regs(struct sh_pfc *pfc)
        struct pinmux_data_reg *drp;
        int k;
 
-       for (k = 0; k < pfc->info->nr_pins; k++)
+       for (k = 0; k < pfc->info->nr_pins; k++) {
+               if (pfc->info->pins[k].enum_id == 0)
+                       continue;
+
                sh_pfc_setup_data_reg(pfc, k);
+       }
 
        k = 0;
        while (1) {
@@ -282,20 +275,16 @@ static void sh_pfc_setup_data_regs(struct sh_pfc *pfc)
        }
 }
 
-int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio,
-                       struct pinmux_data_reg **drp, int *bitp)
+void sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio,
+                        struct pinmux_data_reg **drp, int *bitp)
 {
        struct sh_pfc_pin *gpiop = &pfc->info->pins[gpio];
        int k, n;
 
-       if (!sh_pfc_gpio_is_pin(pfc, gpio))
-               return -1;
-
        k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT;
        n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT;
        *drp = pfc->info->data_regs + k;
        *bitp = n;
-       return 0;
 }
 
 static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
index ab816b7fddfbddbb1b2c68011ee49c9ba1443341..a3111b73fb9454b312240831a2a92a054978b906 100644 (file)
@@ -47,8 +47,8 @@ int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc);
 int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos);
 void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos,
                      unsigned long value);
-int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio,
-                       struct pinmux_data_reg **drp, int *bitp);
+void sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio,
+                        struct pinmux_data_reg **drp, int *bitp);
 int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type,
                      int cfg_mode);
 
index 3ad938fd7ecc3e243dd1c9a9b4eac6746134a2aa..db9af4e548a017d6404e62539530c60c8e89ba61 100644 (file)
@@ -42,6 +42,11 @@ static struct sh_pfc *gpio_to_pfc(struct gpio_chip *gc)
 
 static int gpio_pin_request(struct gpio_chip *gc, unsigned offset)
 {
+       struct sh_pfc *pfc = gpio_to_pfc(gc);
+
+       if (pfc->info->pins[offset].enum_id == 0)
+               return -EINVAL;
+
        return pinctrl_request_gpio(offset);
 }
 
@@ -52,12 +57,10 @@ static void gpio_pin_free(struct gpio_chip *gc, unsigned offset)
 
 static void gpio_pin_set_value(struct sh_pfc *pfc, unsigned offset, int value)
 {
-       struct pinmux_data_reg *dr = NULL;
-       int bit = 0;
-
-       if (sh_pfc_get_data_reg(pfc, offset, &dr, &bit) != 0)
-               BUG();
+       struct pinmux_data_reg *dr;
+       int bit;
 
+       sh_pfc_get_data_reg(pfc, offset, &dr, &bit);
        sh_pfc_write_bit(dr, bit, value);
 }
 
@@ -77,12 +80,10 @@ static int gpio_pin_direction_output(struct gpio_chip *gc, unsigned offset,
 static int gpio_pin_get(struct gpio_chip *gc, unsigned offset)
 {
        struct sh_pfc *pfc = gpio_to_pfc(gc);
-       struct pinmux_data_reg *dr = NULL;
-       int bit = 0;
-
-       if (sh_pfc_get_data_reg(pfc, offset, &dr, &bit) != 0)
-               return -EINVAL;
+       struct pinmux_data_reg *dr;
+       int bit;
 
+       sh_pfc_get_data_reg(pfc, offset, &dr, &bit);
        return sh_pfc_read_bit(dr, bit);
 }
 
This page took 0.028381 seconds and 5 git commands to generate.