diff mbox series

Input: tsc2007 - use GPIO descriptor

Message ID 20190821085503.8062-1-linus.walleij@linaro.org
State New
Headers show
Series Input: tsc2007 - use GPIO descriptor | expand

Commit Message

Linus Walleij Aug. 21, 2019, 8:55 a.m. UTC
This switches the TSC2007 to use a GPIO descriptor to read
the pendown GPIO line.

Cc: H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/input/touchscreen/tsc2007.h      |  4 +++-
 drivers/input/touchscreen/tsc2007_core.c | 14 +++++++-------
 2 files changed, 10 insertions(+), 8 deletions(-)

-- 
2.21.0

Comments

Dmitry Torokhov Aug. 21, 2019, 4:09 p.m. UTC | #1
Hi Linus,

On Wed, Aug 21, 2019 at 10:55:03AM +0200, Linus Walleij wrote:
> This switches the TSC2007 to use a GPIO descriptor to read

> the pendown GPIO line.

> 

> Cc: H. Nikolaus Schaller <hns@goldelico.com>

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

> ---

>  drivers/input/touchscreen/tsc2007.h      |  4 +++-

>  drivers/input/touchscreen/tsc2007_core.c | 14 +++++++-------

>  2 files changed, 10 insertions(+), 8 deletions(-)

> 

> diff --git a/drivers/input/touchscreen/tsc2007.h b/drivers/input/touchscreen/tsc2007.h

> index 91c60bf6dcaf..0306c38b56c7 100644

> --- a/drivers/input/touchscreen/tsc2007.h

> +++ b/drivers/input/touchscreen/tsc2007.h

> @@ -49,6 +49,8 @@

>  #define READ_X		(ADC_ON_12BIT | TSC2007_MEASURE_X)

>  #define PWRDOWN		(TSC2007_12BIT | TSC2007_POWER_OFF_IRQ_EN)

>  

> +struct gpio_desc;

> +

>  struct ts_event {

>  	u16	x;

>  	u16	y;

> @@ -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..5d9c6128622e 100644

> --- a/drivers/input/touchscreen/tsc2007_core.c

> +++ b/drivers/input/touchscreen/tsc2007_core.c

> @@ -23,7 +23,7 @@

>  #include <linux/interrupt.h>

>  #include <linux/i2c.h>

>  #include <linux/of_device.h>

> -#include <linux/of_gpio.h>

> +#include <linux/gpio/consumer.h>

>  #include <linux/platform_data/tsc2007.h>

>  #include "tsc2007.h"

>  

> @@ -226,7 +226,7 @@ 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);


We need to drop the negation here and make sure DTS specifies proper
polarity for GPIOs.

Thanks.

-- 
Dmitry
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/tsc2007.h b/drivers/input/touchscreen/tsc2007.h
index 91c60bf6dcaf..0306c38b56c7 100644
--- a/drivers/input/touchscreen/tsc2007.h
+++ b/drivers/input/touchscreen/tsc2007.h
@@ -49,6 +49,8 @@ 
 #define READ_X		(ADC_ON_12BIT | TSC2007_MEASURE_X)
 #define PWRDOWN		(TSC2007_12BIT | TSC2007_POWER_OFF_IRQ_EN)
 
+struct gpio_desc;
+
 struct ts_event {
 	u16	x;
 	u16	y;
@@ -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..5d9c6128622e 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -23,7 +23,7 @@ 
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/platform_data/tsc2007.h>
 #include "tsc2007.h"
 
@@ -226,7 +226,7 @@  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)
@@ -266,13 +266,13 @@  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->gpiod = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN);
+	if (IS_ERR(ts->gpiod))
+		return PTR_ERR(ts->gpiod);
+	if (ts->gpiod)
 		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);
+		dev_warn(&client->dev, "GPIO not specified in DT\n");
 
 	return 0;
 }