diff mbox series

[v1,1/2] Input: tsc2007 - convert to GPIO descriptors

Message ID 20210307220549.354263-1-andy.shevchenko@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v1,1/2] Input: tsc2007 - convert to GPIO descriptors | expand

Commit Message

Andy Shevchenko March 7, 2021, 10:05 p.m. UTC
This converts the driver to use GPIO descriptors.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/input/touchscreen/tsc2007.h      |  4 +++-
 drivers/input/touchscreen/tsc2007_core.c | 17 ++++++++---------
 2 files changed, 11 insertions(+), 10 deletions(-)

Comments

Dmitry Torokhov March 7, 2021, 10:57 p.m. UTC | #1
Hi Andy,

On Mon, Mar 08, 2021 at 12:05:48AM +0200, Andy Shevchenko wrote:
> @@ -226,11 +226,12 @@ static int tsc2007_get_pendown_state_gpio(struct device *dev)
>  	struct i2c_client *client = to_i2c_client(dev);
>  	struct tsc2007 *ts = i2c_get_clientdata(client);
>  
> -	return !gpio_get_value(ts->gpio);
> +	return !gpiod_get_value(ts->gpiod);

This is not correct. gpio_get_value() is raw polarity vs
gpiod_get_value() using logical active/inactive, and tsc2007 GPIO lines
are active low. The negation must be dropped after switching to GPIOD
API.

>  }
>  
>  static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts)
>  {
> +	struct device *dev = &client->dev;
>  	struct device_node *np = client->dev.of_node;
>  	u32 val32;
>  	u64 val64;
> @@ -266,13 +267,11 @@ static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts)
>  		return -EINVAL;
>  	}
>  
> -	ts->gpio = of_get_gpio(np, 0);
> -	if (gpio_is_valid(ts->gpio))
> -		ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
> -	else
> -		dev_warn(&client->dev,
> -			 "GPIO not specified in DT (of_get_gpio returned %d)\n",
> -			 ts->gpio);
> +	ts->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);

GPIO is definitely not optional in DT case, at least in the way the
driver written right now.

> +	if (IS_ERR(ts->gpiod))
> +		return PTR_ERR(ts->gpiod);
> +
> +	ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
>  
>  	return 0;
>  }
> -- 
> 2.30.1
> 

Thanks.
Andy Shevchenko March 8, 2021, 9:10 a.m. UTC | #2
On Mon, Mar 8, 2021 at 12:57 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Mon, Mar 08, 2021 at 12:05:48AM +0200, Andy Shevchenko wrote:

...

> > -     return !gpio_get_value(ts->gpio);
> > +     return !gpiod_get_value(ts->gpiod);
>
> This is not correct. gpio_get_value() is raw polarity vs
> gpiod_get_value() using logical active/inactive, and tsc2007 GPIO lines
> are active low. The negation must be dropped after switching to GPIOD
> API.

Ah, indeed, I missed that, thanks!

...

> > -     ts->gpio = of_get_gpio(np, 0);
> > -     if (gpio_is_valid(ts->gpio))
> > -             ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
> > -     else
> > -             dev_warn(&client->dev,
> > -                      "GPIO not specified in DT (of_get_gpio returned %d)\n",
> > -                      ts->gpio);
> > +     ts->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
>
> GPIO is definitely not optional in DT case, at least in the way the
> driver written right now.

Can you elaborate this, please? I don't see from the dev_warn() w/o
any error code returned that it's mandatory.
In the bindings one may read:

  Optional properties:
  - gpios: the interrupt gpio the chip is connected to (trough the penirq pin).
    The penirq pin goes to low when the panel is touched.
    (see GPIO binding[1] for more details).

Nothing suggested it's mandatory. What have I missed?

> > +     if (IS_ERR(ts->gpiod))
> > +             return PTR_ERR(ts->gpiod);
Dmitry Torokhov March 8, 2021, 7:29 p.m. UTC | #3
On Mon, Mar 08, 2021 at 11:10:38AM +0200, Andy Shevchenko wrote:
> On Mon, Mar 8, 2021 at 12:57 AM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> > On Mon, Mar 08, 2021 at 12:05:48AM +0200, Andy Shevchenko wrote:
> 
> ...
> 
> > > -     return !gpio_get_value(ts->gpio);
> > > +     return !gpiod_get_value(ts->gpiod);
> >
> > This is not correct. gpio_get_value() is raw polarity vs
> > gpiod_get_value() using logical active/inactive, and tsc2007 GPIO lines
> > are active low. The negation must be dropped after switching to GPIOD
> > API.
> 
> Ah, indeed, I missed that, thanks!
> 
> ...
> 
> > > -     ts->gpio = of_get_gpio(np, 0);
> > > -     if (gpio_is_valid(ts->gpio))
> > > -             ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
> > > -     else
> > > -             dev_warn(&client->dev,
> > > -                      "GPIO not specified in DT (of_get_gpio returned %d)\n",
> > > -                      ts->gpio);
> > > +     ts->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
> >
> > GPIO is definitely not optional in DT case, at least in the way the
> > driver written right now.
> 
> Can you elaborate this, please? I don't see from the dev_warn() w/o
> any error code returned that it's mandatory.
> In the bindings one may read:
> 
>   Optional properties:
>   - gpios: the interrupt gpio the chip is connected to (trough the penirq pin).
>     The penirq pin goes to low when the panel is touched.
>     (see GPIO binding[1] for more details).
> 
> Nothing suggested it's mandatory. What have I missed?

Ah, indeed, I misread the code and thought we'd abort if there is no
pendown GPIO. I wonder if we should remove the warning since we seem to
support operations without it.

Thanks.
Andy Shevchenko March 8, 2021, 9:04 p.m. UTC | #4
On Mon, Mar 8, 2021 at 9:29 PM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> On Mon, Mar 08, 2021 at 11:10:38AM +0200, Andy Shevchenko wrote:
> > On Mon, Mar 8, 2021 at 12:57 AM Dmitry Torokhov
> > <dmitry.torokhov@gmail.com> wrote:
> > > On Mon, Mar 08, 2021 at 12:05:48AM +0200, Andy Shevchenko wrote:
> >
> > ...
> >
> > > > -     return !gpio_get_value(ts->gpio);
> > > > +     return !gpiod_get_value(ts->gpiod);
> > >
> > > This is not correct. gpio_get_value() is raw polarity vs
> > > gpiod_get_value() using logical active/inactive, and tsc2007 GPIO lines
> > > are active low. The negation must be dropped after switching to GPIOD
> > > API.
> >
> > Ah, indeed, I missed that, thanks!
> >
> > ...
> >
> > > > -     ts->gpio = of_get_gpio(np, 0);
> > > > -     if (gpio_is_valid(ts->gpio))
> > > > -             ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
> > > > -     else
> > > > -             dev_warn(&client->dev,
> > > > -                      "GPIO not specified in DT (of_get_gpio returned %d)\n",
> > > > -                      ts->gpio);
> > > > +     ts->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
> > >
> > > GPIO is definitely not optional in DT case, at least in the way the
> > > driver written right now.
> >
> > Can you elaborate this, please? I don't see from the dev_warn() w/o
> > any error code returned that it's mandatory.
> > In the bindings one may read:
> >
> >   Optional properties:
> >   - gpios: the interrupt gpio the chip is connected to (trough the penirq pin).
> >     The penirq pin goes to low when the panel is touched.
> >     (see GPIO binding[1] for more details).
> >
> > Nothing suggested it's mandatory. What have I missed?
>
> Ah, indeed, I misread the code and thought we'd abort if there is no
> pendown GPIO. I wonder if we should remove the warning since we seem to
> support operations without it.

But that's what I have done, i.e. removed the warning as well.

So, if there are no other concerns than inverted value, I'll send v2.
Dmitry Torokhov March 8, 2021, 9:12 p.m. UTC | #5
On Mon, Mar 08, 2021 at 11:04:59PM +0200, Andy Shevchenko wrote:
> On Mon, Mar 8, 2021 at 9:29 PM Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> >
> > On Mon, Mar 08, 2021 at 11:10:38AM +0200, Andy Shevchenko wrote:
> > > On Mon, Mar 8, 2021 at 12:57 AM Dmitry Torokhov
> > > <dmitry.torokhov@gmail.com> wrote:
> > > > On Mon, Mar 08, 2021 at 12:05:48AM +0200, Andy Shevchenko wrote:
> > >
> > > ...
> > >
> > > > > -     return !gpio_get_value(ts->gpio);
> > > > > +     return !gpiod_get_value(ts->gpiod);
> > > >
> > > > This is not correct. gpio_get_value() is raw polarity vs
> > > > gpiod_get_value() using logical active/inactive, and tsc2007 GPIO lines
> > > > are active low. The negation must be dropped after switching to GPIOD
> > > > API.
> > >
> > > Ah, indeed, I missed that, thanks!
> > >
> > > ...
> > >
> > > > > -     ts->gpio = of_get_gpio(np, 0);
> > > > > -     if (gpio_is_valid(ts->gpio))
> > > > > -             ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
> > > > > -     else
> > > > > -             dev_warn(&client->dev,
> > > > > -                      "GPIO not specified in DT (of_get_gpio returned %d)\n",
> > > > > -                      ts->gpio);
> > > > > +     ts->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
> > > >
> > > > GPIO is definitely not optional in DT case, at least in the way the
> > > > driver written right now.
> > >
> > > Can you elaborate this, please? I don't see from the dev_warn() w/o
> > > any error code returned that it's mandatory.
> > > In the bindings one may read:
> > >
> > >   Optional properties:
> > >   - gpios: the interrupt gpio the chip is connected to (trough the penirq pin).
> > >     The penirq pin goes to low when the panel is touched.
> > >     (see GPIO binding[1] for more details).
> > >
> > > Nothing suggested it's mandatory. What have I missed?
> >
> > Ah, indeed, I misread the code and thought we'd abort if there is no
> > pendown GPIO. I wonder if we should remove the warning since we seem to
> > support operations without it.
> 
> But that's what I have done, i.e. removed the warning as well.

Well, what can I say, -ENOCOFFEE.
> 
> So, if there are no other concerns than inverted value, I'll send v2.

Yes, please.
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/tsc2007.h b/drivers/input/touchscreen/tsc2007.h
index 91c60bf6dcaf..69b08dd6c8df 100644
--- a/drivers/input/touchscreen/tsc2007.h
+++ b/drivers/input/touchscreen/tsc2007.h
@@ -19,6 +19,8 @@ 
 #ifndef _TSC2007_H
 #define _TSC2007_H
 
+struct gpio_desc;
+
 #define TSC2007_MEASURE_TEMP0		(0x0 << 4)
 #define TSC2007_MEASURE_AUX		(0x2 << 4)
 #define TSC2007_MEASURE_TEMP1		(0x4 << 4)
@@ -69,7 +71,7 @@  struct tsc2007 {
 	int			fuzzy;
 	int			fuzzz;
 
-	unsigned int		gpio;
+	struct gpio_desc	*gpiod;
 	int			irq;
 
 	wait_queue_head_t	wait;
diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index 3b80abfc1eca..9b747c7d11f1 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -19,11 +19,11 @@ 
 
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/gpio/consumer.h>
 #include <linux/input.h>
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_data/tsc2007.h>
 #include "tsc2007.h"
 
@@ -226,11 +226,12 @@  static int tsc2007_get_pendown_state_gpio(struct device *dev)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct tsc2007 *ts = i2c_get_clientdata(client);
 
-	return !gpio_get_value(ts->gpio);
+	return !gpiod_get_value(ts->gpiod);
 }
 
 static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts)
 {
+	struct device *dev = &client->dev;
 	struct device_node *np = client->dev.of_node;
 	u32 val32;
 	u64 val64;
@@ -266,13 +267,11 @@  static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts)
 		return -EINVAL;
 	}
 
-	ts->gpio = of_get_gpio(np, 0);
-	if (gpio_is_valid(ts->gpio))
-		ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
-	else
-		dev_warn(&client->dev,
-			 "GPIO not specified in DT (of_get_gpio returned %d)\n",
-			 ts->gpio);
+	ts->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
+	if (IS_ERR(ts->gpiod))
+		return PTR_ERR(ts->gpiod);
+
+	ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
 
 	return 0;
 }