diff mbox

[1/6] arm: sa1100: h3100: refactor LCD GPIO handling

Message ID 1385048414-9812-2-git-send-email-dbaryshkov@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dmitry Baryshkov Nov. 21, 2013, 3:40 p.m. UTC
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>
---
 arch/arm/mach-sa1100/h3100.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

Comments

Linus Walleij Nov. 26, 2013, 8:52 a.m. UTC | #1
On Thu, Nov 21, 2013 at 4:40 PM, Dmitry Eremin-Solenikov
<dbaryshkov@gmail.com> wrote:

> +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;
> +}

Hm hm this design pattern is somewhat strange, a run-once
construct, but OK then.
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Dmitry Baryshkov Nov. 26, 2013, 9:07 a.m. UTC | #2
On Tue, Nov 26, 2013 at 12:52 PM, Linus Walleij
<linus.walleij@linaro.org> wrote:
> On Thu, Nov 21, 2013 at 4:40 PM, Dmitry Eremin-Solenikov
> <dbaryshkov@gmail.com> wrote:
>
>> +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;
>> +}
>
> Hm hm this design pattern is somewhat strange, a run-once
> construct, but OK then.
> Acked-by: Linus Walleij <linus.walleij@linaro.org>

Another possibility would be to extend sa11x0-fb driver to also
provide lcd_init and lcd_shutdown callbacks (to request GPIOs).
Would it be better to do so?

It is really unfortunate that lcd_class drivers are not directly controlled
from fbdev drivers. Hopefully CDF can solve that.
Linus Walleij Nov. 26, 2013, 12:31 p.m. UTC | #3
On Tue, Nov 26, 2013 at 10:07 AM, Dmitry Eremin-Solenikov
<dbaryshkov@gmail.com> wrote:
> On Tue, Nov 26, 2013 at 12:52 PM, Linus Walleij
> <linus.walleij@linaro.org> wrote:
>> On Thu, Nov 21, 2013 at 4:40 PM, Dmitry Eremin-Solenikov
>> <dbaryshkov@gmail.com> wrote:
>>
>>> +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;
>>> +}
>>
>> Hm hm this design pattern is somewhat strange, a run-once
>> construct, but OK then.
>> Acked-by: Linus Walleij <linus.walleij@linaro.org>
>
> Another possibility would be to extend sa11x0-fb driver to also
> provide lcd_init and lcd_shutdown callbacks (to request GPIOs).
> Would it be better to do so?
>
> It is really unfortunate that lcd_class drivers are not directly controlled
> from fbdev drivers. Hopefully CDF can solve that.

Hm it looks like there are no good solutions as long as LCDs
are no separate devices. :-(

Nominally you would use the new gpiod* interface and tie the
GPIOs to a struct device * in this case the LCD, and since that
currently has no struct device, this is OK for now...

Yours,
Linus Walleij
diff mbox

Patch

diff --git a/arch/arm/mach-sa1100/h3100.c b/arch/arm/mach-sa1100/h3100.c
index b8f2b15..5b78c9f 100644
--- a/arch/arm/mach-sa1100/h3100.c
+++ b/arch/arm/mach-sa1100/h3100.c
@@ -28,15 +28,35 @@ 
 /*
  * 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)