linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors
@ 2021-03-08 21:55 Andy Shevchenko
  2021-03-08 21:55 ` [PATCH v2 2/2] Input: tsc2007 - make use of device properties Andy Shevchenko
  2021-03-08 22:27 ` [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors Dmitry Torokhov
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-03-08 21:55 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input; +Cc: Andy Shevchenko

This converts the driver to use GPIO descriptors.

Note that it now uses logical polarity and thus nagation has been dropped.

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

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..eecd10effb56 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;
 }
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] Input: tsc2007 - make use of device properties
  2021-03-08 21:55 [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors Andy Shevchenko
@ 2021-03-08 21:55 ` Andy Shevchenko
  2021-03-08 22:27 ` [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors Dmitry Torokhov
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-03-08 21:55 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input; +Cc: Andy Shevchenko

Device property API allows to gather device resources from different sources,
such as ACPI. Convert the drivers to unleash the power of device property API.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
v2: no changes
 drivers/input/touchscreen/tsc2007_core.c | 35 +++++++-----------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/drivers/input/touchscreen/tsc2007_core.c b/drivers/input/touchscreen/tsc2007_core.c
index eecd10effb56..f57644af5d8f 100644
--- a/drivers/input/touchscreen/tsc2007_core.c
+++ b/drivers/input/touchscreen/tsc2007_core.c
@@ -23,7 +23,8 @@
 #include <linux/input.h>
 #include <linux/interrupt.h>
 #include <linux/i2c.h>
-#include <linux/of_device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/property.h>
 #include <linux/platform_data/tsc2007.h>
 #include "tsc2007.h"
 
@@ -220,7 +221,6 @@ static void tsc2007_close(struct input_dev *input_dev)
 	tsc2007_stop(ts);
 }
 
-#ifdef CONFIG_OF
 static int tsc2007_get_pendown_state_gpio(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
@@ -232,38 +232,32 @@ static int tsc2007_get_pendown_state_gpio(struct device *dev)
 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;
 
-	if (!np) {
-		dev_err(&client->dev, "missing device tree data\n");
-		return -EINVAL;
-	}
-
-	if (!of_property_read_u32(np, "ti,max-rt", &val32))
+	if (!device_property_read_u32(dev, "ti,max-rt", &val32))
 		ts->max_rt = val32;
 	else
 		ts->max_rt = MAX_12BIT;
 
-	if (!of_property_read_u32(np, "ti,fuzzx", &val32))
+	if (!device_property_read_u32(dev, "ti,fuzzx", &val32))
 		ts->fuzzx = val32;
 
-	if (!of_property_read_u32(np, "ti,fuzzy", &val32))
+	if (!device_property_read_u32(dev, "ti,fuzzy", &val32))
 		ts->fuzzy = val32;
 
-	if (!of_property_read_u32(np, "ti,fuzzz", &val32))
+	if (!device_property_read_u32(dev, "ti,fuzzz", &val32))
 		ts->fuzzz = val32;
 
-	if (!of_property_read_u64(np, "ti,poll-period", &val64))
+	if (!device_property_read_u64(dev, "ti,poll-period", &val64))
 		ts->poll_period = msecs_to_jiffies(val64);
 	else
 		ts->poll_period = msecs_to_jiffies(1);
 
-	if (!of_property_read_u32(np, "ti,x-plate-ohms", &val32)) {
+	if (!device_property_read_u32(dev, "ti,x-plate-ohms", &val32)) {
 		ts->x_plate_ohms = val32;
 	} else {
-		dev_err(&client->dev, "missing ti,x-plate-ohms devicetree property.");
+		dev_err(dev, "missing ti,x-plate-ohms devicetree property.");
 		return -EINVAL;
 	}
 
@@ -275,13 +269,6 @@ static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts)
 
 	return 0;
 }
-#else
-static int tsc2007_probe_dt(struct i2c_client *client, struct tsc2007 *ts)
-{
-	dev_err(&client->dev, "platform data is required!\n");
-	return -EINVAL;
-}
-#endif
 
 static int tsc2007_probe_pdev(struct i2c_client *client, struct tsc2007 *ts,
 			      const struct tsc2007_platform_data *pdata,
@@ -430,18 +417,16 @@ static const struct i2c_device_id tsc2007_idtable[] = {
 
 MODULE_DEVICE_TABLE(i2c, tsc2007_idtable);
 
-#ifdef CONFIG_OF
 static const struct of_device_id tsc2007_of_match[] = {
 	{ .compatible = "ti,tsc2007" },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, tsc2007_of_match);
-#endif
 
 static struct i2c_driver tsc2007_driver = {
 	.driver = {
 		.name	= "tsc2007",
-		.of_match_table = of_match_ptr(tsc2007_of_match),
+		.of_match_table = tsc2007_of_match,
 	},
 	.id_table	= tsc2007_idtable,
 	.probe		= tsc2007_probe,
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors
  2021-03-08 21:55 [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors Andy Shevchenko
  2021-03-08 21:55 ` [PATCH v2 2/2] Input: tsc2007 - make use of device properties Andy Shevchenko
@ 2021-03-08 22:27 ` Dmitry Torokhov
  2021-03-14 21:11   ` Andy Shevchenko
  1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2021-03-08 22:27 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-input

On Mon, Mar 08, 2021 at 11:55:07PM +0200, Andy Shevchenko wrote:
> This converts the driver to use GPIO descriptors.
> 
> Note that it now uses logical polarity and thus nagation has been dropped.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
> v2: dropped negation (Dmitry)
>  drivers/input/touchscreen/tsc2007.h      |  4 +++-
>  drivers/input/touchscreen/tsc2007_core.c | 17 ++++++++---------
>  2 files changed, 11 insertions(+), 10 deletions(-)
> 
> 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..eecd10effb56 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;

OK, I know what my concern was here. You are now assigning
ts->get_pendown_state unconditionally, and with ts->gpiod being NULL it
will always return false, whereas the old code would skip setting
ts->get_pendown_state when GPIO is not available, and the driver would
assume that on interrupt the pen is actually down.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors
  2021-03-08 22:27 ` [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors Dmitry Torokhov
@ 2021-03-14 21:11   ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-03-14 21:11 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input

On Tue, Mar 9, 2021 at 12:27 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> On Mon, Mar 08, 2021 at 11:55:07PM +0200, Andy Shevchenko wrote:

...

> > +     ts->get_pendown_state = tsc2007_get_pendown_state_gpio;
>
> OK, I know what my concern was here. You are now assigning
> ts->get_pendown_state unconditionally, and with ts->gpiod being NULL it
> will always return false, whereas the old code would skip setting
> ts->get_pendown_state when GPIO is not available, and the driver would
> assume that on interrupt the pen is actually down.

Good catch!
I fixed this in v3 (left original conditional, if we want to drop the
warning, then we may do it in a separate change).

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-14 21:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 21:55 [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors Andy Shevchenko
2021-03-08 21:55 ` [PATCH v2 2/2] Input: tsc2007 - make use of device properties Andy Shevchenko
2021-03-08 22:27 ` [PATCH v2 1/2] Input: tsc2007 - convert to GPIO descriptors Dmitry Torokhov
2021-03-14 21:11   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).