Skip to content

Commit d93bae6

Browse files
itirdeahadess
authored andcommitted
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 <[email protected]> Signed-off-by: Irina Tirdea <[email protected]> Acked-by: Rob Herring <[email protected]> Acked-by: Bastien Nocera <[email protected]> Tested-by: Bastien Nocera <[email protected]> Tested-by: Aleksei Mamlin <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 70041fb commit d93bae6

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

goodix.c

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <linux/kernel.h>
1818
#include <linux/dmi.h>
19+
#include <linux/gpio/consumer.h>
1920
#include <linux/i2c.h>
2021
#include <linux/input.h>
2122
#include <linux/input/mt.h>
@@ -37,8 +38,13 @@ struct goodix_ts_data {
3738
unsigned int int_trigger_type;
3839
bool rotated_screen;
3940
int cfg_len;
41+
struct gpio_desc *gpiod_int;
42+
struct gpio_desc *gpiod_rst;
4043
};
4144

45+
#define GOODIX_GPIO_INT_NAME "irq"
46+
#define GOODIX_GPIO_RST_NAME "reset"
47+
4248
#define GOODIX_MAX_HEIGHT 4096
4349
#define GOODIX_MAX_WIDTH 4096
4450
#define GOODIX_INT_TRIGGER 1
@@ -239,6 +245,106 @@ static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
239245
return IRQ_HANDLED;
240246
}
241247

248+
static 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+
*/
270+
static 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+
*/
311+
static 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+
242348
/**
243349
* goodix_read_config - Read the embedded configuration of the panel
244350
*
@@ -407,6 +513,19 @@ static int goodix_ts_probe(struct i2c_client *client,
407513
ts->client = client;
408514
i2c_set_clientdata(client, ts);
409515

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+
410529
error = goodix_i2c_test(client);
411530
if (error) {
412531
dev_err(&client->dev, "I2C communication failure: %d\n", error);

0 commit comments

Comments
 (0)