ARM: 7898/1: sa1100: h3100: refactor LCD GPIO handling
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Tue, 26 Nov 2013 10:09:01 +0000 (11:09 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 12 Dec 2013 23:00:53 +0000 (23:00 +0000)
As GPIOs are going to move to platform device, there is no guarantee
that they will be available at init_machine time.

Request all GPIOs directly in lcd_power callback and not at init_machine
time.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mach-sa1100/h3100.c

index b8f2b151539bd96358824f000fe597f0d0cb894c..5b78c9f9a11defbabee856bca55667e3d9f5feac 100644 (file)
 /*
  * helper for sa1100fb
  */
+static struct gpio h3100_lcd_gpio[] = {
+       { H3100_GPIO_LCD_3V_ON, GPIOF_OUT_INIT_LOW, "LCD 3V" },
+       { H3XXX_EGPIO_LCD_ON, GPIOF_OUT_INIT_LOW, "LCD ON" },
+};
+
+static bool h3100_lcd_request(void)
+{
+       static bool h3100_lcd_ok;
+       int rc;
+
+       if (h3100_lcd_ok)
+               return true;
+
+       rc = gpio_request_array(h3100_lcd_gpio, ARRAY_SIZE(h3100_lcd_gpio));
+       if (rc)
+               pr_err("%s: can't request GPIOs\n", __func__);
+       else
+               h3100_lcd_ok = true;
+
+       return h3100_lcd_ok;
+}
+
 static void h3100_lcd_power(int enable)
 {
-       if (!gpio_request(H3XXX_EGPIO_LCD_ON, "LCD ON")) {
-               gpio_set_value(H3100_GPIO_LCD_3V_ON, enable);
-               gpio_direction_output(H3XXX_EGPIO_LCD_ON, enable);
-               gpio_free(H3XXX_EGPIO_LCD_ON);
-       } else {
-               pr_err("%s: can't request H3XXX_EGPIO_LCD_ON\n", __func__);
-       }
+       if (!h3100_lcd_request())
+               return;
+
+       gpio_set_value(H3100_GPIO_LCD_3V_ON, enable);
+       gpio_set_value(H3XXX_EGPIO_LCD_ON, enable);
 }
 
 static struct sa1100fb_mach_info h3100_lcd_info = {
@@ -91,7 +111,6 @@ static struct gpio_default_state h3100_default_gpio[] = {
        { H3XXX_GPIO_COM_DCD,   GPIO_MODE_IN,   "COM DCD" },
        { H3XXX_GPIO_COM_CTS,   GPIO_MODE_IN,   "COM CTS" },
        { H3XXX_GPIO_COM_RTS,   GPIO_MODE_OUT0, "COM RTS" },
-       { H3100_GPIO_LCD_3V_ON, GPIO_MODE_OUT0, "LCD 3v" },
 };
 
 static void __init h3100_mach_init(void)