Add a separate internal helper function to get a GPIO value, so that we
will be able to call it with the driver model version and avoid code
duplication.

Also move gpio_get_bank() and check_gpio() down below the helper functions
as these won't be needed with driver model.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 drivers/gpio/omap_gpio.c | 78 ++++++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 36 deletions(-)

diff --git a/drivers/gpio/omap_gpio.c b/drivers/gpio/omap_gpio.c
index 13dcf79..d2d2640 100644
--- a/drivers/gpio/omap_gpio.c
+++ b/drivers/gpio/omap_gpio.c
@@ -26,11 +26,6 @@
 #define OMAP_GPIO_DIR_OUT      0
 #define OMAP_GPIO_DIR_IN       1
 
-static inline const struct gpio_bank *get_gpio_bank(int gpio)
-{
-       return &omap_gpio_bank[gpio >> 5];
-}
-
 static inline int get_gpio_index(int gpio)
 {
        return gpio & 0x1f;
@@ -41,15 +36,6 @@ int gpio_is_valid(int gpio)
        return (gpio >= 0) && (gpio < OMAP_MAX_GPIO);
 }
 
-static int check_gpio(int gpio)
-{
-       if (!gpio_is_valid(gpio)) {
-               printf("ERROR : check_gpio: invalid GPIO %d\n", gpio);
-               return -1;
-       }
-       return 0;
-}
-
 static void _set_gpio_direction(const struct gpio_bank *bank, int gpio,
                                int is_input)
 {
@@ -118,6 +104,46 @@ static void _set_gpio_dataout(const struct gpio_bank 
*bank, int gpio,
        __raw_writel(l, reg);
 }
 
+static int _get_gpio_value(const struct gpio_bank *bank, int gpio)
+{
+       void *reg = bank->base;
+       int input;
+
+       switch (bank->method) {
+       case METHOD_GPIO_24XX:
+               input = _get_gpio_direction(bank, gpio);
+               switch (input) {
+               case OMAP_GPIO_DIR_IN:
+                       reg += OMAP_GPIO_DATAIN;
+                       break;
+               case OMAP_GPIO_DIR_OUT:
+                       reg += OMAP_GPIO_DATAOUT;
+                       break;
+               default:
+                       return -1;
+               }
+               break;
+       default:
+               return -1;
+       }
+
+       return (__raw_readl(reg) & (1 << gpio)) != 0;
+}
+
+static inline const struct gpio_bank *get_gpio_bank(int gpio)
+{
+       return &omap_gpio_bank[gpio >> 5];
+}
+
+static int check_gpio(int gpio)
+{
+       if (!gpio_is_valid(gpio)) {
+               printf("ERROR : check_gpio: invalid GPIO %d\n", gpio);
+               return -1;
+       }
+       return 0;
+}
+
 /**
  * Set value of the specified gpio
  */
@@ -139,32 +165,12 @@ int gpio_set_value(unsigned gpio, int value)
 int gpio_get_value(unsigned gpio)
 {
        const struct gpio_bank *bank;
-       void *reg;
-       int input;
 
        if (check_gpio(gpio) < 0)
                return -1;
        bank = get_gpio_bank(gpio);
-       reg = bank->base;
-       switch (bank->method) {
-       case METHOD_GPIO_24XX:
-               input = _get_gpio_direction(bank, get_gpio_index(gpio));
-               switch (input) {
-               case OMAP_GPIO_DIR_IN:
-                       reg += OMAP_GPIO_DATAIN;
-                       break;
-               case OMAP_GPIO_DIR_OUT:
-                       reg += OMAP_GPIO_DATAOUT;
-                       break;
-               default:
-                       return -1;
-               }
-               break;
-       default:
-               return -1;
-       }
-       return (__raw_readl(reg)
-                       & (1 << get_gpio_index(gpio))) != 0;
+
+       return _get_gpio_value(bank, get_gpio_index(gpio));
 }
 
 /**
-- 
2.1.0.rc2.206.gedb03e5

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to