diff mbox series

[V2,06/10] input: touchscreen: ili210x: Add reset GPIO support

Message ID 20181220204305.28807-7-marex@denx.de (mailing list archive)
State Superseded
Headers show
Series input: touchscreen: ili210x: Add ILI2511 support | expand

Commit Message

Marek Vasut Dec. 20, 2018, 8:43 p.m. UTC
The touchscreen can have a reset GPIO connected to it, add support
for such an arrangement.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Henrik Rydberg <rydberg@bitmath.org>
Cc: Olivier Sobrie <olivier@sobrie.be>
Cc: Philipp Puschmann <pp@emlix.com>
To: linux-input@vger.kernel.org
---
V2: No change
---
 drivers/input/touchscreen/ili210x.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Dmitry Torokhov Dec. 21, 2018, 1:48 a.m. UTC | #1
On Thu, Dec 20, 2018 at 09:43:01PM +0100, Marek Vasut wrote:
> The touchscreen can have a reset GPIO connected to it, add support
> for such an arrangement.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Henrik Rydberg <rydberg@bitmath.org>
> Cc: Olivier Sobrie <olivier@sobrie.be>
> Cc: Philipp Puschmann <pp@emlix.com>
> To: linux-input@vger.kernel.org
> ---
> V2: No change
> ---
>  drivers/input/touchscreen/ili210x.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
> index 04d75d4ecb20..a84ca555829e 100644
> --- a/drivers/input/touchscreen/ili210x.c
> +++ b/drivers/input/touchscreen/ili210x.c
> @@ -5,6 +5,7 @@
>  #include <linux/input.h>
>  #include <linux/input/mt.h>
>  #include <linux/delay.h>
> +#include <linux/gpio/consumer.h>
>  
>  #define MAX_TOUCHES		2
>  #define DEFAULT_POLL_PERIOD	20
> @@ -44,6 +45,7 @@ struct ili210x {
>  	struct input_dev *input;
>  	unsigned int poll_period;
>  	struct delayed_work dwork;
> +	struct gpio_desc *reset_gpio;
>  };
>  
>  static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf,
> @@ -172,6 +174,7 @@ static int ili210x_i2c_probe(struct i2c_client *client,
>  {
>  	struct device *dev = &client->dev;
>  	struct ili210x *priv;
> +	struct gpio_desc *reset_gpio;
>  	struct input_dev *input;
>  	struct panel_info panel;
>  	struct firmware_version firmware;
> @@ -185,6 +188,17 @@ static int ili210x_i2c_probe(struct i2c_client *client,
>  		return -EINVAL;
>  	}
>  
> +	reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
> +	if (IS_ERR(reset_gpio))
> +		return PTR_ERR(reset_gpio);
> +
> +	if (reset_gpio) {
> +		gpiod_set_value_cansleep(reset_gpio, 1);
> +		usleep_range(50, 100);
> +		gpiod_set_value_cansleep(reset_gpio, 0);
> +		mdelay(100);
> +	}
> +
>  	/* Get firmware version */
>  	error = ili210x_read_reg(client, REG_FIRMWARE_VERSION,
>  				 &firmware, sizeof(firmware));
> @@ -214,6 +228,7 @@ static int ili210x_i2c_probe(struct i2c_client *client,
>  	priv->input = input;
>  	priv->poll_period = DEFAULT_POLL_PERIOD;
>  	INIT_DELAYED_WORK(&priv->dwork, ili210x_work);
> +	priv->reset_gpio = reset_gpio;
>  
>  	/* Setup input device */
>  	input->name = "ILI210x Touchscreen";
> @@ -277,6 +292,8 @@ static int ili210x_i2c_remove(struct i2c_client *client)
>  	sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group);
>  	cancel_delayed_work_sync(&priv->dwork);
>  	input_unregister_device(priv->input);
> +	if (priv->reset_gpio)
> +		gpiod_set_value_cansleep(priv->reset_gpio, 1);

Can you install this as devm action (devm_add_action_or_reset())? Then
it will play well with other devm interfaces instead of resetting chip
out of order (for example, devm-managed ISR may fire up and run with
chip in reset).

Thanks.
Marek Vasut Dec. 21, 2018, 2:15 a.m. UTC | #2
On 12/21/2018 02:48 AM, Dmitry Torokhov wrote:
> On Thu, Dec 20, 2018 at 09:43:01PM +0100, Marek Vasut wrote:
>> The touchscreen can have a reset GPIO connected to it, add support
>> for such an arrangement.
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> Cc: Henrik Rydberg <rydberg@bitmath.org>
>> Cc: Olivier Sobrie <olivier@sobrie.be>
>> Cc: Philipp Puschmann <pp@emlix.com>
>> To: linux-input@vger.kernel.org
>> ---
>> V2: No change
>> ---
>>  drivers/input/touchscreen/ili210x.c | 17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>>
>> diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
>> index 04d75d4ecb20..a84ca555829e 100644
>> --- a/drivers/input/touchscreen/ili210x.c
>> +++ b/drivers/input/touchscreen/ili210x.c
>> @@ -5,6 +5,7 @@
>>  #include <linux/input.h>
>>  #include <linux/input/mt.h>
>>  #include <linux/delay.h>
>> +#include <linux/gpio/consumer.h>
>>  
>>  #define MAX_TOUCHES		2
>>  #define DEFAULT_POLL_PERIOD	20
>> @@ -44,6 +45,7 @@ struct ili210x {
>>  	struct input_dev *input;
>>  	unsigned int poll_period;
>>  	struct delayed_work dwork;
>> +	struct gpio_desc *reset_gpio;
>>  };
>>  
>>  static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf,
>> @@ -172,6 +174,7 @@ static int ili210x_i2c_probe(struct i2c_client *client,
>>  {
>>  	struct device *dev = &client->dev;
>>  	struct ili210x *priv;
>> +	struct gpio_desc *reset_gpio;
>>  	struct input_dev *input;
>>  	struct panel_info panel;
>>  	struct firmware_version firmware;
>> @@ -185,6 +188,17 @@ static int ili210x_i2c_probe(struct i2c_client *client,
>>  		return -EINVAL;
>>  	}
>>  
>> +	reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
>> +	if (IS_ERR(reset_gpio))
>> +		return PTR_ERR(reset_gpio);
>> +
>> +	if (reset_gpio) {
>> +		gpiod_set_value_cansleep(reset_gpio, 1);
>> +		usleep_range(50, 100);
>> +		gpiod_set_value_cansleep(reset_gpio, 0);
>> +		mdelay(100);
>> +	}
>> +
>>  	/* Get firmware version */
>>  	error = ili210x_read_reg(client, REG_FIRMWARE_VERSION,
>>  				 &firmware, sizeof(firmware));
>> @@ -214,6 +228,7 @@ static int ili210x_i2c_probe(struct i2c_client *client,
>>  	priv->input = input;
>>  	priv->poll_period = DEFAULT_POLL_PERIOD;
>>  	INIT_DELAYED_WORK(&priv->dwork, ili210x_work);
>> +	priv->reset_gpio = reset_gpio;
>>  
>>  	/* Setup input device */
>>  	input->name = "ILI210x Touchscreen";
>> @@ -277,6 +292,8 @@ static int ili210x_i2c_remove(struct i2c_client *client)
>>  	sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group);
>>  	cancel_delayed_work_sync(&priv->dwork);
>>  	input_unregister_device(priv->input);
>> +	if (priv->reset_gpio)
>> +		gpiod_set_value_cansleep(priv->reset_gpio, 1);
> 
> Can you install this as devm action (devm_add_action_or_reset())? Then
> it will play well with other devm interfaces instead of resetting chip
> out of order (for example, devm-managed ISR may fire up and run with
> chip in reset).

Fixed
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index 04d75d4ecb20..a84ca555829e 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -5,6 +5,7 @@ 
 #include <linux/input.h>
 #include <linux/input/mt.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 
 #define MAX_TOUCHES		2
 #define DEFAULT_POLL_PERIOD	20
@@ -44,6 +45,7 @@  struct ili210x {
 	struct input_dev *input;
 	unsigned int poll_period;
 	struct delayed_work dwork;
+	struct gpio_desc *reset_gpio;
 };
 
 static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf,
@@ -172,6 +174,7 @@  static int ili210x_i2c_probe(struct i2c_client *client,
 {
 	struct device *dev = &client->dev;
 	struct ili210x *priv;
+	struct gpio_desc *reset_gpio;
 	struct input_dev *input;
 	struct panel_info panel;
 	struct firmware_version firmware;
@@ -185,6 +188,17 @@  static int ili210x_i2c_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
+	reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(reset_gpio))
+		return PTR_ERR(reset_gpio);
+
+	if (reset_gpio) {
+		gpiod_set_value_cansleep(reset_gpio, 1);
+		usleep_range(50, 100);
+		gpiod_set_value_cansleep(reset_gpio, 0);
+		mdelay(100);
+	}
+
 	/* Get firmware version */
 	error = ili210x_read_reg(client, REG_FIRMWARE_VERSION,
 				 &firmware, sizeof(firmware));
@@ -214,6 +228,7 @@  static int ili210x_i2c_probe(struct i2c_client *client,
 	priv->input = input;
 	priv->poll_period = DEFAULT_POLL_PERIOD;
 	INIT_DELAYED_WORK(&priv->dwork, ili210x_work);
+	priv->reset_gpio = reset_gpio;
 
 	/* Setup input device */
 	input->name = "ILI210x Touchscreen";
@@ -277,6 +292,8 @@  static int ili210x_i2c_remove(struct i2c_client *client)
 	sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group);
 	cancel_delayed_work_sync(&priv->dwork);
 	input_unregister_device(priv->input);
+	if (priv->reset_gpio)
+		gpiod_set_value_cansleep(priv->reset_gpio, 1);
 
 	return 0;
 }