From: Petr Hodina <[email protected]>

Add support for an optional "reset-gpios" property. If present, the
driver drives the reset line high at probe time and releases it during
power-on, after the regulators have been enabled.

Signed-off-by: Petr Hodina <[email protected]>
Co-developed-by: David Heidelberg <[email protected]>
Signed-off-by: David Heidelberg <[email protected]>
---
 drivers/input/touchscreen/stmfts.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/input/touchscreen/stmfts.c 
b/drivers/input/touchscreen/stmfts.c
index 9dedccbb183ed..a4d8e81aba275 100644
--- a/drivers/input/touchscreen/stmfts.c
+++ b/drivers/input/touchscreen/stmfts.c
@@ -77,6 +77,7 @@ static const struct regulator_bulk_data stmfts_supplies[] = {
 struct stmfts_data {
        struct i2c_client *client;
        struct input_dev *input;
+       struct gpio_desc *reset_gpio;
        struct led_classdev led_cdev;
        struct mutex mutex;
 
@@ -540,6 +541,15 @@ static int stmfts_read_system_info(struct stmfts_data 
*sdata)
        return 0;
 }
 
+static void stmfts_reset(struct stmfts_data *sdata)
+{
+       gpiod_set_value_cansleep(sdata->reset_gpio, 1);
+       msleep(20);
+
+       gpiod_set_value_cansleep(sdata->reset_gpio, 0);
+       msleep(50);
+}
+
 static int stmfts_power_on(struct stmfts_data *sdata)
 {
        int err;
@@ -549,6 +559,9 @@ static int stmfts_power_on(struct stmfts_data *sdata)
        if (err)
                return err;
 
+       if (sdata->reset_gpio)
+               stmfts_reset(sdata);
+
        /*
         * The datasheet does not specify the power on time, but considering
         * that the reset time is < 10ms, I sleep 20ms to be sure
@@ -607,6 +620,10 @@ static void stmfts_power_off(void *data)
        struct stmfts_data *sdata = data;
 
        disable_irq(sdata->client->irq);
+
+       if (sdata->reset_gpio)
+               gpiod_set_value_cansleep(sdata->reset_gpio, 1);
+
        regulator_bulk_disable(ARRAY_SIZE(stmfts_supplies),
                               sdata->supplies);
 }
@@ -663,6 +680,12 @@ static int stmfts_probe(struct i2c_client *client)
        if (err)
                return err;
 
+       sdata->reset_gpio = devm_gpiod_get_optional(dev, "reset",
+                                                   GPIOD_OUT_HIGH);
+       if (IS_ERR(sdata->reset_gpio))
+               return dev_err_probe(dev, PTR_ERR(sdata->reset_gpio),
+                                    "Failed to get GPIO 'reset'\n");
+
        sdata->input = devm_input_allocate_device(dev);
        if (!sdata->input)
                return -ENOMEM;

-- 
2.51.0



Reply via email to