Input: goodix - Add support for controllers without flash
Subsystems (3)
v2 cover Input: goodix - Add support for controllers without flash
Hi All,
Here is v2 of my patch-set to add support for Goodix controllers without flash-memory.
Changes in v2:
- Decide if a controller does not have flash / needs firmware to be uploaded based on the presence of the "firmware-name" device-property, the autodetection code in v1 was causing false-positives on some devices
Original cover-letter:
A while ago I bought a Glavey TM800A550L tablet. This is a Bay Trail (x86) tablet which comes with Android from the factory.
It is mostly just another Bay Trail tablet, but the way the Goodix touchscreen on it works is interesting. The controller needs to have firmware uploaded to it before it will work. After that it pretty much works 100% the same as any other Goodix touchscreen controller.
I've described this patch-set in the Subject as "Add support for controllers without flash", but I suspect that the Goodix controllers used on Bay Trail devices which ship with Windows pre-installed may also lack flash; and that the Windows version of the BIOS-es on these devices does the upload for us. Anyways just something which I'm wondering about, these patches are necessary to make things work regardless.
These patches should also be useful for supporting the Goodix controllers on some ARM based devices, as some of those need the OS to upload the firmware too AFAIK.
Regards,
Hans
Hans de Goede (6):
Input: goodix - Change goodix_i2c_write() len parameter type to int
Input: goodix - Add a goodix.h header file
Input: goodix - Refactor reset handling
Input: goodix - Push error logging up into i2c_read and i2c_write
helpers
Input: goodix - Allow specifying the config filename through a
"goodix,config-name" device-property
Input: goodix - Add support for controllers without flash
MAINTAINERS | 3 +- drivers/input/touchscreen/Makefile | 3 +- drivers/input/touchscreen/goodix.c | 240 +++++------- drivers/input/touchscreen/goodix.h | 117 ++++++ drivers/input/touchscreen/goodix_fwupload.c | 413 ++++++++++++++++++++ 5 files changed, 639 insertions(+), 137 deletions(-) create mode 100644 drivers/input/touchscreen/goodix.h create mode 100644 drivers/input/touchscreen/goodix_fwupload.c
Signature · 1 line
2.31.1
PATCH v2 1/6 Input: goodix - Change goodix_i2c_write() len parameter type to int
Change the type of the goodix_i2c_write() len parameter to from 'unsigned' to 'int' to avoid bare use of 'unsigned', changing it to 'int' makes goodix_i2c_write()' prototype consistent with goodix_i2c_read().
--- drivers/input/touchscreen/goodix.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/touchscreen/goodix.c +1 -2
@@ -244,8 +244,7 @@ static int goodix_i2c_read(struct i2c_client *client,* @buf: raw data buffer to write. * @len: length of the buffer to write */ -static int goodix_i2c_write (struct i2c_client *client,u16 reg,const u8 *buf, -unsigned len) +static int goodix_i2c_write (struct i2c_client *client,u16 reg,const u8 *buf,int len) {u8 *addr_buf;struct i2c_msg msg;
Signature · 1 line
2.31.1
PATCH v2 2/6 Input: goodix - Add a goodix.h header file
In reply to Hans de GoedeAdd a goodix.h header file, and move the register definitions, and struct declarations there and add prototypes for various helper functions.
This is a preparation patch for adding support for controllers without flash, which need to have their firmware uploaded and need some other special handling too.
Since MAINTAINERS needs updating because of this change anyways, also add myself as co-maintainer.
--- MAINTAINERS | 3 +- drivers/input/touchscreen/goodix.c | 73 +++--------------------------- drivers/input/touchscreen/goodix.h | 73 ++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 68 deletions(-) create mode 100644 drivers/input/touchscreen/goodix.h
MAINTAINERS +2 -1
@@ -7936,9 +7936,10 @@ F: drivers/media/usb/go7007/ GOODIX TOUCHSCREEN M: Bastien Nocera <[email protected]> +M: Hans de Goede <[email protected]> L: [email protected] S: Maintained -F: drivers/input/touchscreen/goodix.c +F: drivers/input/touchscreen/goodix* GOOGLE ETHERNET DRIVERS M: Jeroen de Borst <[email protected]>
drivers/input/touchscreen/goodix.c +6 -67
139 lines not on this page · raw message
drivers/input/touchscreen/goodix.h new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v2 3/6 Input: goodix - Refactor reset handling
In reply to Hans de GoedeRefactor reset handling a bit, change the main reset handler into a new goodix_reset_no_int_sync() helper and add a goodix_reset() wrapper which calls goodix_int_sync() separately.
Also push the dev_err() call on reset failure into the goodix_reset_no_int_sync() and goodix_int_sync() functions, so that we don't need to have separate dev_err() calls in all their callers.
This is a preparation patch for adding support for controllers without flash, which need to have their firmware uploaded and need some other special handling too.
--- drivers/input/touchscreen/goodix.c | 46 +++++++++++++++++++----------- drivers/input/touchscreen/goodix.h | 1 + 2 files changed, 31 insertions(+), 16 deletions(-)
drivers/input/touchscreen/goodix.c +30 -16
@@ -595,56 +595,74 @@ int goodix_int_sync(struct goodix_ts_data *ts) error =goodix_irq_direction_output (ts,0 );if (error) -return error; + goto error;msleep (50 );/* T5: 50ms */ error =goodix_irq_direction_input (ts);if (error) -return error; + goto error;return 0 ; +error: +dev_err (&ts->client->dev,"Controller irq sync failed.\n" ); +return error; }/** -* goodix_reset - Reset device during power on +* goodix_reset_no_int_sync - Reset device, leaving interrupt line in output mode * * @ts: goodix_ts_data pointer */ -static int goodix_reset (struct goodix_ts_data *ts) +int goodix_reset_no_int_sync (struct goodix_ts_data *ts) {int error;/* begin select I2C slave addr */ error =gpiod_direction_output (ts->gpiod_rst,0 );if (error) -return error; + goto error;msleep (20 );/* T2: > 10ms */ /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */ error =goodix_irq_direction_output (ts, ts->client->addr ==0x14 );if (error) -return error; + goto error;usleep_range (100 ,2000 );/* T3: > 100us */ error =gpiod_direction_output (ts->gpiod_rst,1 );if (error) -return error; + goto error;usleep_range (6000 ,10000 );/* T4: > 5ms */ /* end select I2C slave addr */ error =gpiod_direction_input (ts->gpiod_rst);if (error) -return error; + goto error; - error =goodix_int_sync (ts); +return 0 ; +error: +dev_err (&ts->client->dev,"Controller reset failed.\n" ); +return error; +} + +/** +* goodix_reset - Reset device during power on +* +* @ts: goodix_ts_data pointer +*/ +static int goodix_reset (struct goodix_ts_data *ts) +{ +int error; + + error =goodix_reset_no_int_sync (ts);if (error)return error; -return 0 ; +return goodix_int_sync (ts); }#ifdef ACPI_GPIO_SUPPORT
@@ -1143,10 +1161,8 @@ static int goodix_ts_probe(struct i2c_client *client,if (ts->reset_controller_at_probe) {/* reset the controller */ error =goodix_reset (ts); -if (error) { -dev_err (&client->dev,"Controller reset failed.\n" ); +if (error)return error; - } } error =goodix_i2c_test (client);
@@ -1288,10 +1304,8 @@ static int __maybe_unused goodix_resume(struct device *dev)if (error !=0 || config_ver != ts->config[0 ]) { error =goodix_reset (ts); -if (error) { -dev_err (dev,"Controller reset failed.\n" ); +if (error)return error; - } error =goodix_send_cfg (ts, ts->config, ts->chip->config_len);if (error)
drivers/input/touchscreen/goodix.h +1 -0
@@ -69,5 +69,6 @@ int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len)int goodix_i2c_write_u8 (struct i2c_client *client,u16 reg,u8 value);int goodix_send_cfg (struct goodix_ts_data *ts,const u8 *cfg,int len);int goodix_int_sync (struct goodix_ts_data *ts); +int goodix_reset_no_int_sync (struct goodix_ts_data *ts);#endif
Signature · 1 line
2.31.1
PATCH v2 4/6 Input: goodix - Push error logging up into i2c_read and i2c_write helpers
In reply to Hans de GoedeMake the goodix_i2c_read() and goodix_i2c_write*() helpers log errors themselves. This allows removing all the error logging from their callers.
This already results in a nice cleanup with the current code and it also helps to make the upcoming support for controllers without flash cleaner.
--- drivers/input/touchscreen/goodix.c | 68 ++++++++++++------------------ 1 file changed, 28 insertions(+), 40 deletions(-)
drivers/input/touchscreen/goodix.c +28 -40
@@ -172,7 +172,13 @@ int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len) msgs[1 ].buf = buf; ret =i2c_transfer (client->adapter, msgs,2 ); -return ret <0 ? ret : (ret !=ARRAY_SIZE (msgs) ? -EIO :0 ); +if (ret >=0 ) + ret = (ret ==ARRAY_SIZE (msgs) ?0 : -EIO ); + +if (ret) +dev_err (&client->dev,"Error reading %d bytes from 0x%04x: %d\n" , + len, reg, ret); +return ret; }/**
@@ -203,8 +209,15 @@ int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len) msg.len = len +2 ; ret =i2c_transfer (client->adapter, &msg,1 ); +if (ret >=0 ) + ret = (ret ==1 ?0 : -EIO ); +kfree (addr_buf); -return ret <0 ? ret : (ret !=1 ? -EIO :0 ); + +if (ret) +dev_err (&client->dev,"Error writing %d bytes to 0x%04x: %d\n" , + len, reg, ret); +return ret; }int goodix_i2c_write_u8 (struct i2c_client *client,u16 reg,u8 value)
@@ -244,13 +257,9 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)*/ max_timeout = jiffies +msecs_to_jiffies (GOODIX_BUFFER_STATUS_TIMEOUT ); do { - error = goodix_i2c_read(ts->client, addr, data, - header_contact_keycode_size); - if (error) { - dev_err(&ts->client->dev, "I2C transfer error: %d\n", - error); + error = goodix_i2c_read(ts->client, addr, data, header_contact_keycode_size); + if (error) return error; - } if (data[0] & GOODIX_BUFFER_STATUS_READY) { touch_num = data[0] & 0x0f;
@@ -260,10 +269,8 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)if (touch_num >1 ) { addr += header_contact_keycode_size; data += header_contact_keycode_size; - error =goodix_i2c_read (ts->client, - addr, data, - ts->contact_size * - (touch_num -1 )); + error =goodix_i2c_read (ts->client, addr, data, + ts->contact_size * (touch_num -1 ));if (error)return error; }
@@ -373,9 +380,7 @@ static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)struct goodix_ts_data *ts = dev_id;goodix_process_events (ts); - -if (goodix_i2c_write_u8 (ts->client,GOODIX_READ_COOR_ADDR ,0 ) <0 ) -dev_err (&ts->client->dev,"I2C write end_cmd error\n" ); +goodix_i2c_write_u8 (ts->client,GOODIX_READ_COOR_ADDR ,0 );return IRQ_HANDLED ; }
@@ -500,11 +505,9 @@ int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len)return error; error =goodix_i2c_write (ts->client, ts->chip->config_addr, cfg, len); -if (error) { -dev_err (&ts->client->dev,"Failed to write config data: %d" , - error); +if (error)return error; - } +dev_dbg (&ts->client->dev,"Config sent successfully." );/* Let the firmware reconfigure itself, so sleep for 10ms */
@@ -890,8 +893,6 @@ static void goodix_read_config(struct goodix_ts_data *ts) error =goodix_i2c_read (ts->client, ts->chip->config_addr, ts->config, ts->chip->config_len);if (error) { -dev_warn (&ts->client->dev,"Error reading config: %d\n" , - error); ts->int_trigger_type =GOODIX_INT_TRIGGER ; ts->max_touch_num =GOODIX_MAX_CONTACTS ;return ;
@@ -922,10 +923,8 @@ static int goodix_read_version(struct goodix_ts_data *ts)char id_str[GOODIX_ID_MAX_LEN +1 ]; error =goodix_i2c_read (ts->client,GOODIX_REG_ID , buf,sizeof (buf)); -if (error) { -dev_err (&ts->client->dev,"read version failed: %d\n" , error); +if (error)return error; - }memcpy (id_str, buf,GOODIX_ID_MAX_LEN ); id_str[GOODIX_ID_MAX_LEN ] =0 ;
@@ -951,13 +950,10 @@ static int goodix_i2c_test(struct i2c_client *client)u8 test;while (retry++ <2 ) { - error =goodix_i2c_read (client,GOODIX_REG_ID , - &test,1 ); + error =goodix_i2c_read (client,GOODIX_REG_ID , &test,1 );if (!error)return 0 ; -dev_err (&client->dev,"i2c test failed attempt %d: %d\n" , - retry, error);msleep (20 ); }
@@ -1178,10 +1174,8 @@ static int goodix_ts_probe(struct i2c_client *client, } error =goodix_read_version (ts); -if (error) { -dev_err (&client->dev,"Read version failed.\n" ); +if (error)return error; - } ts->chip =goodix_get_chip_data (ts->id);
@@ -1249,10 +1243,8 @@ static int __maybe_unused goodix_suspend(struct device *dev)usleep_range (5000 ,6000 ); - error =goodix_i2c_write_u8 (ts->client,GOODIX_REG_COMMAND , -GOODIX_CMD_SCREEN_OFF ); + error =goodix_i2c_write_u8 (ts->client,GOODIX_REG_COMMAND ,GOODIX_CMD_SCREEN_OFF );if (error) { -dev_err (&ts->client->dev,"Screen off command failed\n" );goodix_irq_direction_input (ts);goodix_request_irq (ts);return -EAGAIN ;
@@ -1293,12 +1285,8 @@ static int __maybe_unused goodix_resume(struct device *dev)if (error)return error; - error =goodix_i2c_read (ts->client, ts->chip->config_addr, - &config_ver,1 ); -if (error) -dev_warn (dev,"Error reading config version: %d, resetting controller\n" , - error); -else if (config_ver != ts->config[0 ]) + error =goodix_i2c_read (ts->client, ts->chip->config_addr, &config_ver,1 ); +if (!error && config_ver != ts->config[0 ])dev_info (dev,"Config version mismatch %d != %d, resetting controller\n" , config_ver, ts->config[0 ]);
Signature · 1 line
2.31.1
PATCH v2 5/6 Input: goodix - Allow specifying the config filename through a "goodix,config-name" device-property
In reply to Hans de GoedeThe config which needs to be send to the controller on some device-models is model-specific. Allow specifying a model-specific filename through a device-property, rather then always using a fixed filename.
Note the "goodix,config-name" device-property used by this is *not* documented in the Documentation/devicetree/bindings/input/touchscreen/goodix.yaml device-tree bindings for now.
Not documenting these is intentional. This is done because this code has only been tested on x86/ACPI so far, where devicetree is not used. Instead these properties are set through a software-fwnode attached to the device by the drivers/platform/x86/touchscreen_dmi.c code. This means that the use of this property for now is purely a kernel-internal thing and the name/working of the property may still be changed for now.
--- drivers/input/touchscreen/goodix.c | 10 ++++++---- drivers/input/touchscreen/goodix.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/input/touchscreen/goodix.c +6 -4
@@ -1108,6 +1108,7 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) {struct goodix_ts_data *ts; +const char *cfg_name;int error;dev_dbg (&client->dev,"I2C Address: 0x%02x\n" , client->addr);
@@ -1181,10 +1182,11 @@ static int goodix_ts_probe(struct i2c_client *client,if (ts->load_cfg_from_disk) {/* update device config */ - ts->cfg_name =devm_kasprintf (&client->dev,GFP_KERNEL , -"goodix_%s_cfg.bin" , ts->id); -if (!ts->cfg_name) -return -ENOMEM ; + error =device_property_read_string (&client->dev,"goodix,config-name" , &cfg_name); +if (!error) +snprintf (ts->cfg_name,sizeof (ts->cfg_name),"goodix/%s" , cfg_name); +else +snprintf (ts->cfg_name,sizeof (ts->cfg_name),"goodix_%s_cfg.bin" , ts->id); error = request_firmware_nowait(THIS_MODULE, true, ts->cfg_name, &client->dev, GFP_KERNEL, ts,
drivers/input/touchscreen/goodix.h +1 -1
@@ -52,8 +52,8 @@ struct goodix_ts_data {int gpio_count;int gpio_int_idx;char id[GOODIX_ID_MAX_LEN +1 ]; +char cfg_name[64 ];u16 version; -const char *cfg_name;bool reset_controller_at_probe;bool load_cfg_from_disk;struct completion firmware_loading_complete;
Signature · 1 line
2.31.1
PATCH v2 6/6 Input: goodix - Add support for controllers without flash
In reply to Hans de GoedeSome Goodix touchscreen controllers, such as for example the GT912, don't have flash-storage for their firmware.
These models require the OS to load the firmware at runtime, as well as some other special handling. Add support for this to the goodix driver.
This patch was developed and tested on a Glavey TM800A550L tablet.
Note the "goodix,main-clk" and "firmware-name" device-properties used by the new code are *not* documented in the Documentation/devicetree/bindings/input/touchscreen/goodix.yaml device-tree bindings for now.
Not documenting these is intentional. This is done because this code has only been tested on x86/ACPI so far, where devicetree is not used. Instead these properties are set through a software-fwnode attached to the device by the drivers/platform/x86/touchscreen_dmi.c code. This means that the use of this properties for now is purely a kernel-internal thing and the name/working of the properties may still be changed for now.
---
Changes in v2:
- Decide if a controller does not have flash / needs firmware to be uploaded based on the presence of the "firmware-name" device-property, the autodetection code in v1 was causing false-positives on some devices
--- drivers/input/touchscreen/Makefile | 3 +- drivers/input/touchscreen/goodix.c | 42 +- drivers/input/touchscreen/goodix.h | 43 ++ drivers/input/touchscreen/goodix_fwupload.c | 413 ++++++++++++++++++++ 4 files changed, 493 insertions(+), 8 deletions(-) create mode 100644 drivers/input/touchscreen/goodix_fwupload.c
drivers/input/touchscreen/Makefile +2 -1
@@ -6,6 +6,7 @@ # Each configuration option enables a list of files. wm97xx-ts-y := wm97xx-core.o +goodix_ts-y := goodix.o goodix_fwupload.o obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o
@@ -44,7 +45,7 @@ obj-$(CONFIG_TOUCHSCREEN_EGALAX) += egalax_ts.o obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL) += egalax_ts_serial.o obj-$(CONFIG_TOUCHSCREEN_EXC3000) += exc3000.o obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o -obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix.o +obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix_ts.o obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o obj-$(CONFIG_TOUCHSCREEN_ILITEK) += ilitek_ts_i2c.o
drivers/input/touchscreen/goodix.c +35 -7
72 lines not on this page · raw message
drivers/input/touchscreen/goodix.h +43 -0
72 lines not on this page · raw message
drivers/input/touchscreen/goodix_fwupload.c new file +413 -0
413 lines not on this page · raw message
Signature · 1 line
2.31.1