aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrina Tirdea <irina.tirdea@intel.com>2015-12-17 18:57:34 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2015-12-17 20:11:52 -0500
commitec6e1b4082d9f5b0858ce33169a1c22a27a982f6 (patch)
treea16efc75f25cac078c60f88e4978599f63c5a070
parenta779fbc6c931007559b74fd74c2dc7b1c25bac33 (diff)
Input: goodix - reset device at init
After power on, it is recommended that the driver resets the device. The reset procedure timing is described in the datasheet and is used at device init (before writing device configuration) and for power management. It is a sequence of setting the interrupt and reset pins high/low at specific timing intervals. This procedure also includes setting the slave address to the one specified in the ACPI/device tree. This is based on Goodix datasheets for GT911 and GT9271 and on Goodix driver gt9xx.c for Android (publicly available in Android kernel trees for various devices). For reset the driver needs to control the interrupt and reset gpio pins (configured through ACPI/device tree). For devices that do not have the gpio pins properly declared, the functionality depending on these pins will not be available, but the device can still be used with basic functionality. For both device tree and ACPI, the interrupt gpio pin configuration is read from the "irq-gpios" property and the reset pin configuration is read from the "reset-gpios" property. For ACPI 5.1, named properties can be specified using the _DSD section. This functionality will not be available for devices that use indexed gpio pins declared in the _CRS section (we need to provide backward compatibility with devices that do not support using the interrupt gpio pin as output). For ACPI, the pins can be specified using ACPI 5.1: Device (STAC) { Name (_HID, "GDIX1001") ... Method (_CRS, 0, Serialized) { Name (RBUF, ResourceTemplate () { I2cSerialBus (0x0014, ControllerInitiated, 0x00061A80, AddressingMode7Bit, "\\I2C0", 0x00, ResourceConsumer, , ) GpioInt (Edge, ActiveHigh, Exclusive, PullNone, 0x0000, "\\I2C0", 0x00, ResourceConsumer, , ) { // Pin list 0 } GpioIo (Exclusive, PullDown, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\I2C0", 0x00, ResourceConsumer, , ) { 1 } }) Return (RBUF) } Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package (2) {"irq-gpios", Package() {^STAC, 0, 0, 0 }}, Package (2) {"reset-gpios", Package() {^STAC, 1, 0, 0 }}, ... } } Signed-off-by: Octavian Purdila <octavian.purdila@intel.com> Signed-off-by: Irina Tirdea <irina.tirdea@intel.com> Acked-by: Rob Herring <robh@kernel.org> Acked-by: Bastien Nocera <hadess@hadess.net> Tested-by: Bastien Nocera <hadess@hadess.net> Tested-by: Aleksei Mamlin <mamlinav@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--Documentation/devicetree/bindings/input/touchscreen/goodix.txt9
-rw-r--r--drivers/input/touchscreen/Kconfig1
-rw-r--r--drivers/input/touchscreen/goodix.c119
3 files changed, 129 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/input/touchscreen/goodix.txt b/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
index 8ba98eec765b..c42d2cebac8e 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/goodix.txt
@@ -13,6 +13,12 @@ Required properties:
13 - interrupt-parent : Interrupt controller to which the chip is connected 13 - interrupt-parent : Interrupt controller to which the chip is connected
14 - interrupts : Interrupt to which the chip is connected 14 - interrupts : Interrupt to which the chip is connected
15 15
16Optional properties:
17
18 - irq-gpios : GPIO pin used for IRQ. The driver uses the
19 interrupt gpio pin as output to reset the device.
20 - reset-gpios : GPIO pin used for reset
21
16Example: 22Example:
17 23
18 i2c@00000000 { 24 i2c@00000000 {
@@ -23,6 +29,9 @@ Example:
23 reg = <0x5d>; 29 reg = <0x5d>;
24 interrupt-parent = <&gpio>; 30 interrupt-parent = <&gpio>;
25 interrupts = <0 0>; 31 interrupts = <0 0>;
32
33 irq-gpios = <&gpio1 0 0>;
34 reset-gpios = <&gpio1 1 0>;
26 }; 35 };
27 36
28 /* ... */ 37 /* ... */
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index ae33da7ab51f..709527cd4c2e 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -324,6 +324,7 @@ config TOUCHSCREEN_FUJITSU
324config TOUCHSCREEN_GOODIX 324config TOUCHSCREEN_GOODIX
325 tristate "Goodix I2C touchscreen" 325 tristate "Goodix I2C touchscreen"
326 depends on I2C 326 depends on I2C
327 depends on GPIOLIB
327 help 328 help
328 Say Y here if you have the Goodix touchscreen (such as one 329 Say Y here if you have the Goodix touchscreen (such as one
329 installed in Onda v975w tablets) connected to your 330 installed in Onda v975w tablets) connected to your
diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index 5479aa17dba8..6ad379aace72 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/dmi.h> 18#include <linux/dmi.h>
19#include <linux/gpio/consumer.h>
19#include <linux/i2c.h> 20#include <linux/i2c.h>
20#include <linux/input.h> 21#include <linux/input.h>
21#include <linux/input/mt.h> 22#include <linux/input/mt.h>
@@ -37,8 +38,13 @@ struct goodix_ts_data {
37 unsigned int int_trigger_type; 38 unsigned int int_trigger_type;
38 bool rotated_screen; 39 bool rotated_screen;
39 int cfg_len; 40 int cfg_len;
41 struct gpio_desc *gpiod_int;
42 struct gpio_desc *gpiod_rst;
40}; 43};
41 44
45#define GOODIX_GPIO_INT_NAME "irq"
46#define GOODIX_GPIO_RST_NAME "reset"
47
42#define GOODIX_MAX_HEIGHT 4096 48#define GOODIX_MAX_HEIGHT 4096
43#define GOODIX_MAX_WIDTH 4096 49#define GOODIX_MAX_WIDTH 4096
44#define GOODIX_INT_TRIGGER 1 50#define GOODIX_INT_TRIGGER 1
@@ -239,6 +245,106 @@ static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
239 return IRQ_HANDLED; 245 return IRQ_HANDLED;
240} 246}
241 247
248static int goodix_int_sync(struct goodix_ts_data *ts)
249{
250 int error;
251
252 error = gpiod_direction_output(ts->gpiod_int, 0);
253 if (error)
254 return error;
255
256 msleep(50); /* T5: 50ms */
257
258 error = gpiod_direction_input(ts->gpiod_int);
259 if (error)
260 return error;
261
262 return 0;
263}
264
265/**
266 * goodix_reset - Reset device during power on
267 *
268 * @ts: goodix_ts_data pointer
269 */
270static int goodix_reset(struct goodix_ts_data *ts)
271{
272 int error;
273
274 /* begin select I2C slave addr */
275 error = gpiod_direction_output(ts->gpiod_rst, 0);
276 if (error)
277 return error;
278
279 msleep(20); /* T2: > 10ms */
280
281 /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */
282 error = gpiod_direction_output(ts->gpiod_int, ts->client->addr == 0x14);
283 if (error)
284 return error;
285
286 usleep_range(100, 2000); /* T3: > 100us */
287
288 error = gpiod_direction_output(ts->gpiod_rst, 1);
289 if (error)
290 return error;
291
292 usleep_range(6000, 10000); /* T4: > 5ms */
293
294 /* end select I2C slave addr */
295 error = gpiod_direction_input(ts->gpiod_rst);
296 if (error)
297 return error;
298
299 error = goodix_int_sync(ts);
300 if (error)
301 return error;
302
303 return 0;
304}
305
306/**
307 * goodix_get_gpio_config - Get GPIO config from ACPI/DT
308 *
309 * @ts: goodix_ts_data pointer
310 */
311static int goodix_get_gpio_config(struct goodix_ts_data *ts)
312{
313 int error;
314 struct device *dev;
315 struct gpio_desc *gpiod;
316
317 if (!ts->client)
318 return -EINVAL;
319 dev = &ts->client->dev;
320
321 /* Get the interrupt GPIO pin number */
322 gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_INT_NAME, GPIOD_IN);
323 if (IS_ERR(gpiod)) {
324 error = PTR_ERR(gpiod);
325 if (error != -EPROBE_DEFER)
326 dev_dbg(dev, "Failed to get %s GPIO: %d\n",
327 GOODIX_GPIO_INT_NAME, error);
328 return error;
329 }
330
331 ts->gpiod_int = gpiod;
332
333 /* Get the reset line GPIO pin number */
334 gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_RST_NAME, GPIOD_IN);
335 if (IS_ERR(gpiod)) {
336 error = PTR_ERR(gpiod);
337 if (error != -EPROBE_DEFER)
338 dev_dbg(dev, "Failed to get %s GPIO: %d\n",
339 GOODIX_GPIO_RST_NAME, error);
340 return error;
341 }
342
343 ts->gpiod_rst = gpiod;
344
345 return 0;
346}
347
242/** 348/**
243 * goodix_read_config - Read the embedded configuration of the panel 349 * goodix_read_config - Read the embedded configuration of the panel
244 * 350 *
@@ -407,6 +513,19 @@ static int goodix_ts_probe(struct i2c_client *client,
407 ts->client = client; 513 ts->client = client;
408 i2c_set_clientdata(client, ts); 514 i2c_set_clientdata(client, ts);
409 515
516 error = goodix_get_gpio_config(ts);
517 if (error)
518 return error;
519
520 if (ts->gpiod_int && ts->gpiod_rst) {
521 /* reset the controller */
522 error = goodix_reset(ts);
523 if (error) {
524 dev_err(&client->dev, "Controller reset failed.\n");
525 return error;
526 }
527 }
528
410 error = goodix_i2c_test(client); 529 error = goodix_i2c_test(client);
411 if (error) { 530 if (error) {
412 dev_err(&client->dev, "I2C communication failure: %d\n", error); 531 dev_err(&client->dev, "I2C communication failure: %d\n", error);