diff mbox series

[4/8] input: touchscreen: ili210x: Add reset GPIO support

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

Commit Message

Marek Vasut Dec. 13, 2018, 3:14 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>
To: linux-input@vger.kernel.org
---
 drivers/input/touchscreen/ili210x.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index 1102ee560bf4d..7579cf16b3663 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
@@ -42,6 +43,7 @@  struct firmware_version {
 struct ili210x {
 	struct i2c_client *client;
 	struct input_dev *input;
+	struct gpio_desc *reset_gpio;
 };
 
 static int ili210x_read_reg(struct i2c_client *client, u8 reg, void *buf,
@@ -158,6 +160,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;
@@ -171,6 +174,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));
@@ -198,6 +212,7 @@  static int ili210x_i2c_probe(struct i2c_client *client,
 
 	priv->client = client;
 	priv->input = input;
+	priv->reset_gpio = reset_gpio;
 
 	/* Setup input device */
 	input->name = "ILI210x Touchscreen";
@@ -256,8 +271,12 @@  static int ili210x_i2c_probe(struct i2c_client *client,
 
 static int ili210x_i2c_remove(struct i2c_client *client)
 {
+	struct ili210x *priv = i2c_get_clientdata(client);
+
 	sysfs_remove_group(&client->dev.kobj, &ili210x_attr_group);
 	input_unregister_device(priv->input);
+	if (priv->reset_gpio)
+		gpiod_set_value_cansleep(priv->reset_gpio, 1);
 
 	return 0;
 }