From c3a39380a39df3750149a2f4699c1c241a0e6ea2 Mon Sep 17 00:00:00 2001 From: Richard Leitner Date: Mon, 28 Jan 2019 14:49:37 -0800 Subject: Input: sx8654 - add reset-gpio support The sx8654 features a NRST input which may be connected to a GPIO. Therefore add support for hard-resetting the sx8654 via this NRST. If the reset-gpio property is provided the sx8654 is resetted via NRST instead of the soft-reset via I2C. Signed-off-by: Richard Leitner Reviewed-by: Rob Herring Signed-off-by: Dmitry Torokhov --- .../bindings/input/touchscreen/sx8654.txt | 4 ++ drivers/input/touchscreen/sx8654.c | 44 +++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/input/touchscreen/sx8654.txt b/Documentation/devicetree/bindings/input/touchscreen/sx8654.txt index 4886c4aa2906..ca521d8f7d65 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/sx8654.txt +++ b/Documentation/devicetree/bindings/input/touchscreen/sx8654.txt @@ -5,6 +5,9 @@ Required properties: - reg: i2c slave address - interrupts: touch controller interrupt +Optional properties: + - reset-gpios: GPIO specification for the NRST input + Example: sx8654@48 { @@ -12,4 +15,5 @@ Example: reg = <0x48>; interrupt-parent = <&gpio6>; interrupts = <3 IRQ_TYPE_EDGE_FALLING>; + reset-gpios = <&gpio4 2 GPIO_ACTIVE_LOW>; }; diff --git a/drivers/input/touchscreen/sx8654.c b/drivers/input/touchscreen/sx8654.c index ed29db3ec731..ab5cbf7e0879 100644 --- a/drivers/input/touchscreen/sx8654.c +++ b/drivers/input/touchscreen/sx8654.c @@ -27,12 +27,14 @@ * published by the Free Software Foundation. */ -#include -#include -#include +#include +#include #include +#include #include #include +#include +#include /* register addresses */ #define I2C_REG_TOUCH0 0x00 @@ -74,6 +76,7 @@ struct sx8654 { struct input_dev *input; struct i2c_client *client; + struct gpio_desc *gpio_reset; }; static irqreturn_t sx8654_irq(int irq, void *handle) @@ -124,6 +127,25 @@ out: return IRQ_HANDLED; } +static int sx8654_reset(struct sx8654 *ts) +{ + int err; + + if (ts->gpio_reset) { + gpiod_set_value_cansleep(ts->gpio_reset, 1); + udelay(2); /* Tpulse > 1µs */ + gpiod_set_value_cansleep(ts->gpio_reset, 0); + } else { + dev_dbg(&ts->client->dev, "NRST unavailable, try softreset\n"); + err = i2c_smbus_write_byte_data(ts->client, I2C_REG_SOFTRESET, + SOFTRESET_VALUE); + if (err) + return err; + } + + return 0; +} + static int sx8654_open(struct input_dev *dev) { struct sx8654 *sx8654 = input_get_drvdata(dev); @@ -186,6 +208,17 @@ static int sx8654_probe(struct i2c_client *client, if (!sx8654) return -ENOMEM; + sx8654->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(sx8654->gpio_reset)) { + error = PTR_ERR(sx8654->gpio_reset); + if (error != -EPROBE_DEFER) + dev_err(&client->dev, "unable to get reset-gpio: %d\n", + error); + return error; + } + dev_dbg(&client->dev, "got GPIO reset pin\n"); + input = devm_input_allocate_device(&client->dev); if (!input) return -ENOMEM; @@ -206,10 +239,9 @@ static int sx8654_probe(struct i2c_client *client, input_set_drvdata(sx8654->input, sx8654); - error = i2c_smbus_write_byte_data(client, I2C_REG_SOFTRESET, - SOFTRESET_VALUE); + error = sx8654_reset(sx8654); if (error) { - dev_err(&client->dev, "writing softreset value failed"); + dev_err(&client->dev, "reset failed"); return error; } -- cgit v1.2.3-59-g8ed1b