diff mbox series

[v2,8/8] Input: olpc_apsp: allocate the GPIOs used

Message ID 20181010142504.233467-9-lkundrak@v3.sk (mailing list archive)
State New, archived
Headers show
Series OLPC 1.75 Keyboard/Touchpad fixes | expand

Commit Message

Lubomir Rintel Oct. 10, 2018, 2:25 p.m. UTC
Take the GPIO lines are used by the SP. The driver doesn't touch the
lines -- this is done to disallow anything else from fiddling with
them because that would confuse the SP firmware.

Also, the lines are now nicely visible in /sys/kernel/debug/gpio.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 drivers/input/serio/olpc_apsp.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Dmitry Torokhov Oct. 10, 2018, 5:10 p.m. UTC | #1
On Wed, Oct 10, 2018 at 04:25:04PM +0200, Lubomir Rintel wrote:
> Take the GPIO lines are used by the SP. The driver doesn't touch the
> lines -- this is done to disallow anything else from fiddling with
> them because that would confuse the SP firmware.
> 
> Also, the lines are now nicely visible in /sys/kernel/debug/gpio.

Linus, is this something that should be handled by GPIO "hogs"?

> 
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> ---
>  drivers/input/serio/olpc_apsp.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/input/serio/olpc_apsp.c b/drivers/input/serio/olpc_apsp.c
> index fe9e19014e70..287759c5f36d 100644
> --- a/drivers/input/serio/olpc_apsp.c
> +++ b/drivers/input/serio/olpc_apsp.c
> @@ -24,6 +24,7 @@
>  #include <linux/slab.h>
>  #include <linux/delay.h>
>  #include <linux/clk.h>
> +#include <linux/gpio/consumer.h>
>  
>  /*
>   * The OLPC XO-1.75 and XO-4 laptops do not have a hardware PS/2 controller.
> @@ -76,6 +77,8 @@ struct olpc_apsp {
>  	struct serio *padio;
>  	void __iomem *base;
>  	struct clk *clk;
> +	struct gpio_desc *clk_gpio;
> +	struct gpio_desc *data_gpio;
>  	int open_count;
>  	int irq;
>  };
> @@ -211,6 +214,16 @@ static int olpc_apsp_probe(struct platform_device *pdev)
>  	if (IS_ERR(priv->clk))
>  		return PTR_ERR(priv->clk);
>  
> +	priv->clk_gpio = devm_gpiod_get_optional(&pdev->dev, "clk",
> +							GPIOD_ASIS);
> +	if (IS_ERR(priv->clk_gpio))
> +		return PTR_ERR(priv->clk_gpio);
> +
> +	priv->data_gpio = devm_gpiod_get_optional(&pdev->dev, "data",
> +							GPIOD_ASIS);
> +	if (IS_ERR(priv->data_gpio))
> +		return PTR_ERR(priv->data_gpio);
> +
>  	/* KEYBOARD */
>  	kb_serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
>  	if (!kb_serio)
> -- 
> 2.19.0
>
Dmitry Torokhov Oct. 10, 2018, 5:11 p.m. UTC | #2
On Wed, Oct 10, 2018 at 10:10:13AM -0700, Dmitry Torokhov wrote:
> On Wed, Oct 10, 2018 at 04:25:04PM +0200, Lubomir Rintel wrote:
> > Take the GPIO lines are used by the SP. The driver doesn't touch the
> > lines -- this is done to disallow anything else from fiddling with
> > them because that would confuse the SP firmware.
> > 
> > Also, the lines are now nicely visible in /sys/kernel/debug/gpio.
> 
> Linus, is this something that should be handled by GPIO "hogs"?

Argh, meant to add Linus Walleij here.

> 
> > 
> > Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> > ---
> >  drivers/input/serio/olpc_apsp.c | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> > 
> > diff --git a/drivers/input/serio/olpc_apsp.c b/drivers/input/serio/olpc_apsp.c
> > index fe9e19014e70..287759c5f36d 100644
> > --- a/drivers/input/serio/olpc_apsp.c
> > +++ b/drivers/input/serio/olpc_apsp.c
> > @@ -24,6 +24,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/delay.h>
> >  #include <linux/clk.h>
> > +#include <linux/gpio/consumer.h>
> >  
> >  /*
> >   * The OLPC XO-1.75 and XO-4 laptops do not have a hardware PS/2 controller.
> > @@ -76,6 +77,8 @@ struct olpc_apsp {
> >  	struct serio *padio;
> >  	void __iomem *base;
> >  	struct clk *clk;
> > +	struct gpio_desc *clk_gpio;
> > +	struct gpio_desc *data_gpio;
> >  	int open_count;
> >  	int irq;
> >  };
> > @@ -211,6 +214,16 @@ static int olpc_apsp_probe(struct platform_device *pdev)
> >  	if (IS_ERR(priv->clk))
> >  		return PTR_ERR(priv->clk);
> >  
> > +	priv->clk_gpio = devm_gpiod_get_optional(&pdev->dev, "clk",
> > +							GPIOD_ASIS);
> > +	if (IS_ERR(priv->clk_gpio))
> > +		return PTR_ERR(priv->clk_gpio);
> > +
> > +	priv->data_gpio = devm_gpiod_get_optional(&pdev->dev, "data",
> > +							GPIOD_ASIS);
> > +	if (IS_ERR(priv->data_gpio))
> > +		return PTR_ERR(priv->data_gpio);
> > +
> >  	/* KEYBOARD */
> >  	kb_serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
> >  	if (!kb_serio)
> > -- 
> > 2.19.0
> > 
> 
> -- 
> Dmitry
Linus Walleij Oct. 11, 2018, 8:38 a.m. UTC | #3
Hi Lubomir,

thanks for your patch!

On Wed, Oct 10, 2018 at 4:26 PM Lubomir Rintel <lkundrak@v3.sk> wrote:

> Take the GPIO lines are used by the SP. The driver doesn't touch the
> lines -- this is done to disallow anything else from fiddling with
> them because that would confuse the SP firmware.
>
> Also, the lines are now nicely visible in /sys/kernel/debug/gpio.
>
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>

Sadly I do not think this is the right way to do this these days.
In the past I would have agreed.

A few months back, Qualcomm engineers working on ACPI
support ran into similar issues: there were GPIO lines that
could not be touched by the kernel because they were used
by firmware (BIOS).

The solution we devised can be seen in
commit 726cb3ba49692bdae6caff457755e7cdb432efa4
"gpiolib: Support 'gpio-reserved-ranges' property"
which adds a "valid mask" to struct gpio_chip.

It is further refined in the lates working kernel code to make
it easy for users to set up a custom valid_mask.
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git/commit/?h=devel&id=f8ec92a9f63b3b11e399409141b7868bb405e6b5

So what you should do is modify the platform set-up for
the OLPC to mask off these GPIO lines as invalid since
they are used by the firmware and Linux should not touch
them.

Sadly I don't know which GPIO driver the XO1 is using,
but if you tell us I bet me or Andy will be able to help you
out in finding the right spot to patch.

Yours,
Linus Walleij
Pavel Machek Nov. 4, 2018, 11:55 a.m. UTC | #4
On Wed 2018-10-10 16:25:04, Lubomir Rintel wrote:
> Take the GPIO lines are used by the SP. The driver doesn't touch the
> lines -- this is done to disallow anything else from fiddling with
> them because that would confuse the SP firmware.
> 
> Also, the lines are now nicely visible in /sys/kernel/debug/gpio.
> 
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>

Acked-by: Pavel Machek <pavel@ucw.cz>
diff mbox series

Patch

diff --git a/drivers/input/serio/olpc_apsp.c b/drivers/input/serio/olpc_apsp.c
index fe9e19014e70..287759c5f36d 100644
--- a/drivers/input/serio/olpc_apsp.c
+++ b/drivers/input/serio/olpc_apsp.c
@@ -24,6 +24,7 @@ 
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/clk.h>
+#include <linux/gpio/consumer.h>
 
 /*
  * The OLPC XO-1.75 and XO-4 laptops do not have a hardware PS/2 controller.
@@ -76,6 +77,8 @@  struct olpc_apsp {
 	struct serio *padio;
 	void __iomem *base;
 	struct clk *clk;
+	struct gpio_desc *clk_gpio;
+	struct gpio_desc *data_gpio;
 	int open_count;
 	int irq;
 };
@@ -211,6 +214,16 @@  static int olpc_apsp_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->clk))
 		return PTR_ERR(priv->clk);
 
+	priv->clk_gpio = devm_gpiod_get_optional(&pdev->dev, "clk",
+							GPIOD_ASIS);
+	if (IS_ERR(priv->clk_gpio))
+		return PTR_ERR(priv->clk_gpio);
+
+	priv->data_gpio = devm_gpiod_get_optional(&pdev->dev, "data",
+							GPIOD_ASIS);
+	if (IS_ERR(priv->data_gpio))
+		return PTR_ERR(priv->data_gpio);
+
 	/* KEYBOARD */
 	kb_serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
 	if (!kb_serio)