Input: goodix - Refactor IRQ pin GPIO accesses
Subsystems (3)
PATCH RESEND 1/10 Input: goodix - Refactor IRQ pin GPIO accesses
Suspending Goodix touchscreens requires changing the interrupt pin to output before sending them a power-down command. Followed by wiggling the interrupt pin to wake the device up, after which it is put back in input mode.
So far we have only effectively supported this on devices which use devicetree. On X86 ACPI platforms both looking up the pins; and using a pin as both IRQ and GPIO is a bit more complicated. E.g. on some devices we cannot directly access the IRQ pin as GPIO and we need to call ACPI methods to control it instead.
This commit adds a new irq_pin_access_method field to the goodix_chip_data struct and adds goodix_irq_direction_output and goodix_irq_direction_input helpers which together abstract the GPIO accesses to the IRQ pin.
This is a preparation patch for adding support for properly suspending the touchscreen on X86 ACPI platforms.
--- drivers/input/touchscreen/goodix.c | 62 ++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 11 deletions(-)
drivers/input/touchscreen/goodix.c +51 -11
@@ -31,6 +31,11 @@struct goodix_ts_data ; +enum goodix_irq_pin_access_method { + irq_pin_access_none, + irq_pin_access_gpio, +}; +struct goodix_chip_data {u16 config_addr;int config_len;
@@ -53,6 +58,7 @@ struct goodix_ts_data {const char *cfg_name;struct completion firmware_loading_complete;unsigned long irq_flags; +enum goodix_irq_pin_access_method irq_pin_access_method;unsigned int contact_size; };
@@ -502,17 +508,48 @@ static int goodix_send_cfg(struct goodix_ts_data *ts,return 0 ; } +static int goodix_irq_direction_output (struct goodix_ts_data *ts, +int value) +{ +switch (ts->irq_pin_access_method) { +case irq_pin_access_none: +dev_err (&ts->client->dev, +"%s called without an irq_pin_access_method set\n" , + __func__); +return -EINVAL ; +case irq_pin_access_gpio: +return gpiod_direction_output (ts->gpiod_int, value); + } + +return -EINVAL ;/* Never reached */ +} + +static int goodix_irq_direction_input (struct goodix_ts_data *ts) +{ +switch (ts->irq_pin_access_method) { +case irq_pin_access_none: +dev_err (&ts->client->dev, +"%s called without an irq_pin_access_method set\n" , + __func__); +return -EINVAL ; +case irq_pin_access_gpio: +return gpiod_direction_input (ts->gpiod_int); + } + +return -EINVAL ;/* Never reached */ +} +static int goodix_int_sync (struct goodix_ts_data *ts) {int error; - error =gpiod_direction_output (ts->gpiod_int,0 ); + error =goodix_irq_direction_output (ts,0 );if (error)return error;msleep (50 );/* T5: 50ms */ - error =gpiod_direction_input (ts->gpiod_int); + error =goodix_irq_direction_input (ts);if (error)return error;
@@ -536,7 +573,7 @@ static int goodix_reset(struct goodix_ts_data *ts)msleep (20 );/* T2: > 10ms */ /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */ - error =gpiod_direction_output (ts->gpiod_int, ts->client->addr ==0x14 ); + error =goodix_irq_direction_output (ts, ts->client->addr ==0x14 );if (error)return error;
@@ -617,6 +654,9 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod; +if (ts->gpiod_int && ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_gpio; +return 0 ; }
@@ -889,7 +929,7 @@ static int goodix_ts_probe(struct i2c_client *client,if (error)return error; -if (ts->gpiod_int && ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_gpio) {/* reset the controller */ error =goodix_reset (ts);if (error) {
@@ -912,7 +952,7 @@ static int goodix_ts_probe(struct i2c_client *client, ts->chip =goodix_get_chip_data (ts->id); -if (ts->gpiod_int && ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_gpio) {/* update device config */ ts->cfg_name =devm_kasprintf (&client->dev,GFP_KERNEL ,"goodix_%d_cfg.bin" , ts->id);
@@ -943,7 +983,7 @@ static int goodix_ts_remove(struct i2c_client *client) {struct goodix_ts_data *ts =i2c_get_clientdata (client); -if (ts->gpiod_int && ts->gpiod_rst) +if (ts->irq_pin_access_method == irq_pin_access_gpio)wait_for_completion (&ts->firmware_loading_complete);return 0 ;
@@ -956,7 +996,7 @@ static int __maybe_unused goodix_suspend(struct device *dev)int error;/* We need gpio pins to suspend/resume */ -if (!ts->gpiod_int || !ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_none) {disable_irq (client->irq);return 0 ; }
@@ -967,7 +1007,7 @@ static int __maybe_unused goodix_suspend(struct device *dev)goodix_free_irq (ts);/* Output LOW on the INT pin for 5 ms */ - error =gpiod_direction_output (ts->gpiod_int,0 ); + error =goodix_irq_direction_output (ts,0 );if (error) {goodix_request_irq (ts);return error;
@@ -979,7 +1019,7 @@ static int __maybe_unused goodix_suspend(struct device *dev) GOODIX_CMD_SCREEN_OFF);if (error) {dev_err (&ts->client->dev,"Screen off command failed\n" ); -gpiod_direction_input (ts->gpiod_int); +goodix_irq_direction_input (ts);goodix_request_irq (ts);return -EAGAIN ; }
@@ -999,7 +1039,7 @@ static int __maybe_unused goodix_resume(struct device *dev)struct goodix_ts_data *ts =i2c_get_clientdata (client);int error; -if (!ts->gpiod_int || !ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_none) {enable_irq (client->irq);return 0 ; }
@@ -1008,7 +1048,7 @@ static int __maybe_unused goodix_resume(struct device *dev)* Exit sleep mode by outputting HIGH level to INT pin * for 2ms~5ms. */ - error =gpiod_direction_output (ts->gpiod_int,1 ); + error =goodix_irq_direction_output (ts,1 );if (error)return error;
Signature · 1 line
2.25.0
PATCH RESEND 2/10 Input: goodix - Make loading the config from disk independent from the GPIO setup
At least on X86 ACPI platforms it is not necessary to load the touchscreen controller config from disk, if it needs to be loaded this has already been done by the BIOS / UEFI firmware.
Even on other (e.g. devicetree) platforms the config-loading as currently done has the issue that the loaded cfg file is based on the controller model, but the actual cfg is device specific, so the cfg files are not part of linux-firmware and this can only work with a device specific OS image which includes the cfg file.
And we do not need access to the GPIOs at all to load the config, if we do not have access we can still load the config.
So all in all tying the decision to try to load the config from disk to being able to access the GPIOs is not desirable. This commit adds a new load_cfg_from_disk boolean to control the firmware loading instead.
This commits sets the new bool to true when we set irq_pin_access_method to irq_pin_access_gpio, so there are no functional changes.
--- drivers/input/touchscreen/goodix.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/input/touchscreen/goodix.c +8 -4
@@ -56,6 +56,7 @@ struct goodix_ts_data {u16 id;u16 version;const char *cfg_name; +bool load_cfg_from_disk;struct completion firmware_loading_complete;unsigned long irq_flags;enum goodix_irq_pin_access_method irq_pin_access_method;
@@ -654,8 +655,10 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod; -if (ts->gpiod_int && ts->gpiod_rst) +if (ts->gpiod_int && ts->gpiod_rst) { + ts->load_cfg_from_disk = true; ts->irq_pin_access_method = irq_pin_access_gpio; + }return 0 ; }
@@ -952,7 +955,7 @@ static int goodix_ts_probe(struct i2c_client *client, ts->chip =goodix_get_chip_data (ts->id); -if (ts->irq_pin_access_method == irq_pin_access_gpio) { +if (ts->load_cfg_from_disk) {/* update device config */ ts->cfg_name =devm_kasprintf (&client->dev,GFP_KERNEL ,"goodix_%d_cfg.bin" , ts->id);
@@ -983,7 +986,7 @@ static int goodix_ts_remove(struct i2c_client *client) {struct goodix_ts_data *ts =i2c_get_clientdata (client); -if (ts->irq_pin_access_method == irq_pin_access_gpio) +if (ts->load_cfg_from_disk)wait_for_completion (&ts->firmware_loading_complete);return 0 ;
@@ -1001,7 +1004,8 @@ static int __maybe_unused goodix_suspend(struct device *dev)return 0 ; } -wait_for_completion (&ts->firmware_loading_complete); +if (ts->load_cfg_from_disk) +wait_for_completion (&ts->firmware_loading_complete);/* Free IRQ as IRQ pin is used as output in the suspend sequence */ goodix_free_irq (ts);
Signature · 1 line
2.25.0
Re: [PATCH resend 02/10] Input: goodix - Make loading the config from disk independent from the GPIO setup
Quoted 30 lines · Hans de Goede
At least on X86 ACPI platforms it is not necessary to load the touchscreen
controller config from disk, if it needs to be loaded this has already been
done by the BIOS / UEFI firmware.Even on other (e.g. devicetree) platforms the config-loading as currently
done has the issue that the loaded cfg file is based on the controller
model, but the actual cfg is device specific, so the cfg files are not
part of linux-firmware and this can only work with a device specific OS
image which includes the cfg file.And we do not need access to the GPIOs at all to load the config, if we
do not have access we can still load the config.So all in all tying the decision to try to load the config from disk to
being able to access the GPIOs is not desirable. This commit adds a newload_cfg_from_diskboolean to control the firmware loading instead.This commits sets the new bool to true when we set
irq_pin_access_method
toirq_pin_access_gpio, so there are no functional changes.
Quoted 5 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Looks good.
Quoted 63 lines
--- drivers/input/touchscreen/goodix.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/input/touchscreen/goodix.c +4
-1@@ -56,6 +56,7 @@ struct goodix_ts_data {u16 id;u16 version;const char *cfg_name; +bool load_cfg_from_disk;struct completion firmware_loading_complete;unsigned long irq_flags;enum goodix_irq_pin_access_method irq_pin_access_method;@@ -654,8 +655,10 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod; -if (ts->gpiod_int && ts->gpiod_rst) +if (ts->gpiod_int && ts->gpiod_rst) { + ts->load_cfg_from_disk = true; ts->irq_pin_access_method = irq_pin_access_gpio; + }return 0 ;}
drivers/input/touchscreen/goodix.c +1
-1@@ -952,7 +955,7 @@ static int goodix_ts_probe(struct i2c_client *client, ts->chip =goodix_get_chip_data (ts->id); -if (ts->irq_pin_access_method == irq_pin_access_gpio) { +if (ts->load_cfg_from_disk) {/* update device config */ ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL,"goodix_%d_cfg.bin", ts-
Quoted 1 line
id);
drivers/input/touchscreen/goodix.c +1
-1@@ -983,7 +986,7 @@ static int goodix_ts_remove(struct i2c_client *client) {struct goodix_ts_data *ts =i2c_get_clientdata (client); -if (ts->irq_pin_access_method == irq_pin_access_gpio) +if (ts->load_cfg_from_disk)wait_for_completion (&ts->firmware_loading_complete);drivers/input/touchscreen/goodix.c +2
-1return 0 ;@@ -1001,7 +1004,8 @@ static int __maybe_unused goodix_suspend(struct device *dev)return 0 ; } -wait_for_completion (&ts->firmware_loading_complete); +if (ts->load_cfg_from_disk) +wait_for_completion (&ts->firmware_loading_complete);/* Free IRQ as IRQ pin is used as output in the suspend sequence */
goodix_free_irq(ts);
PATCH RESEND 3/10 Input: goodix - Make resetting the controller at probe independent from the GPIO setup
In reply to Hans de GoedeBefore this commit we would always reset the controller at probe when we have access to the GPIOs which are necessary to do a reset.
Doing the reset requires access to the GPIOs, but just because we have access to the GPIOs does not mean that we should always reset the controller at probe. On X86 ACPI platforms the BIOS / UEFI firmware will already have reset the controller and it will have loaded the device specific config into the controller. Doing the reset sometimes causes the controller to loose its configuration, so on X86 ACPI platforms this is not a good idea.
This commit adds a new reset_controller_at_probe boolean to control the reset at probe behavior.
This commits sets the new bool to true when we set irq_pin_access_method to irq_pin_access_gpio, so there are no functional changes.
--- drivers/input/touchscreen/goodix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/input/touchscreen/goodix.c +3 -1
@@ -56,6 +56,7 @@ struct goodix_ts_data {u16 id;u16 version;const char *cfg_name; +bool reset_controller_at_probe;bool load_cfg_from_disk;struct completion firmware_loading_complete;unsigned long irq_flags;
@@ -656,6 +657,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod;if (ts->gpiod_int && ts->gpiod_rst) { + ts->reset_controller_at_probe = true; ts->load_cfg_from_disk = true; ts->irq_pin_access_method = irq_pin_access_gpio; }
@@ -932,7 +934,7 @@ static int goodix_ts_probe(struct i2c_client *client,if (error)return error; -if (ts->irq_pin_access_method == irq_pin_access_gpio) { +if (ts->reset_controller_at_probe) {/* reset the controller */ error =goodix_reset (ts);if (error) {
Signature · 1 line
2.25.0
Re: [PATCH resend 03/10] Input: goodix - Make resetting the controller at probe independent from the GPIO setup
Quoted 4 lines · Hans de Goede
Before this commit we would always reset the controller at probe when we
have access to the GPIOs which are necessary to do a reset.
Quoted 9 lines
Doing the reset requires access to the GPIOs, but just because we have
access to the GPIOs does not mean that we should always reset the controller at probe. On X86 ACPI platforms the BIOS / UEFI firmware will
already have reset the controller and it will have loaded the device specific config into the controller. Doing the reset sometimes causes the
controller to loose its configuration, so on X86 ACPI platforms this
lose.
Quoted 11 lines
is not
a good idea.This commit adds a new
reset_controller_at_probeboolean to control the
reset at probe behavior.This commits sets the new bool to true when we set
irq_pin_access_method
toirq_pin_access_gpio, so there are no functional changes.
Quoted 5 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Looks good apart from the typo in the commit message
Quoted 36 lines
--- drivers/input/touchscreen/goodix.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/input/touchscreen/goodix.c +2
-0@@ -56,6 +56,7 @@ struct goodix_ts_data {u16 id;u16 version;const char *cfg_name; +bool reset_controller_at_probe;bool load_cfg_from_disk;struct completion firmware_loading_complete;unsigned long irq_flags;@@ -656,6 +657,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod;if (ts->gpiod_int && ts->gpiod_rst) { + ts->reset_controller_at_probe = true; ts->load_cfg_from_disk = true; ts->irq_pin_access_method = irq_pin_access_gpio;drivers/input/touchscreen/goodix.c +1
-1}@@ -932,7 +934,7 @@ static int goodix_ts_probe(struct i2c_client *client, if (error)return error; -if (ts->irq_pin_access_method == irq_pin_access_gpio) { +if (ts->reset_controller_at_probe) {/* reset the controller */ error =goodix_reset (ts);if (error) {
PATCH RESEND 4/10 Input: goodix - Add support for getting IRQ + reset GPIOs on Cherry Trail devices
In reply to Hans de GoedeOn most Cherry Trail (x86, UEFI + ACPI) devices the ACPI tables do not have a _DSD with a "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID, adding "irq-gpios" and "reset-gpios" mappings, so we cannot get the GPIOS by name without first manually adding mappings ourselves.
These devices contain 1 GpioInt and 1 GpioIo resource in their _CRS table. There is no fixed order for these 2. This commit adds code to check that there is 1 of each as expected and then registers a mapping matching their order using devm_acpi_dev_add_driver_gpios().
This gives us access to both GPIOs allowing us to properly suspend the controller during suspend, and making it possible to reset the controller if necessary.
--- drivers/input/touchscreen/goodix.c | 113 ++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 4 deletions(-)
drivers/input/touchscreen/goodix.c +109 -4
@@ -34,6 +34,7 @@ struct goodix_ts_data;enum goodix_irq_pin_access_method { irq_pin_access_none, irq_pin_access_gpio, + irq_pin_access_acpi_gpio, };struct goodix_chip_data {
@@ -53,6 +54,8 @@ struct goodix_ts_data {struct regulator *vddio;struct gpio_desc *gpiod_int;struct gpio_desc *gpiod_rst; +int gpio_count; +int gpio_int_idx;u16 id;u16 version;const char *cfg_name;
@@ -521,6 +524,12 @@ static int goodix_irq_direction_output(struct goodix_ts_data *ts,return -EINVAL ;case irq_pin_access_gpio:return gpiod_direction_output (ts->gpiod_int, value); +case irq_pin_access_acpi_gpio: +/* +* The IRQ pin triggers on a falling edge, so its gets marked +* as active-low, use output_raw to avoid the value inversion. +*/ +return gpiod_direction_output_raw (ts->gpiod_int, value); }return -EINVAL ;/* Never reached */
@@ -535,6 +544,7 @@ static int goodix_irq_direction_input(struct goodix_ts_data *ts) __func__);return -EINVAL ;case irq_pin_access_gpio: +case irq_pin_access_acpi_gpio:return gpiod_direction_input (ts->gpiod_int); }
@@ -599,6 +609,87 @@ static int goodix_reset(struct goodix_ts_data *ts)return 0 ; } +#if definedCONFIG_X86 && definedCONFIG_ACPI +static const struct acpi_gpio_params first_gpio = {0 ,0 , false }; +static const struct acpi_gpio_params second_gpio = {1 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_goodix_int_first_gpios[] = { + {GOODIX_GPIO_INT_NAME "-gpios" , &first_gpio,1 }, + {GOODIX_GPIO_RST_NAME "-gpios" , &second_gpio,1 }, + { }, +}; + +static const struct acpi_gpio_mapping acpi_goodix_int_last_gpios[] = { + {GOODIX_GPIO_RST_NAME "-gpios" , &first_gpio,1 }, + {GOODIX_GPIO_INT_NAME "-gpios" , &second_gpio,1 }, + { }, +}; + +static int goodix_resource (struct acpi_resource *ares,void *data) +{ +struct goodix_ts_data *ts = data; +struct device *dev = &ts->client->dev; +struct acpi_resource_gpio *gpio; + +switch (ares->type) { +case ACPI_RESOURCE_TYPE_GPIO : + gpio = &ares->data.gpio; +if (gpio->connection_type ==ACPI_RESOURCE_GPIO_TYPE_INT ) { +if (ts->gpio_int_idx ==-1 ) { + ts->gpio_int_idx = ts->gpio_count; + }else { +dev_err (dev,"More then one GpioInt resource, ignoring ACPI GPIO resources\n" ); + ts->gpio_int_idx =-2 ; + } + } + ts->gpio_count++; +break ; +default : +break ; + } + +return 0 ; +} + +static int goodix_add_acpi_gpio_mappings (struct goodix_ts_data *ts) +{ +const struct acpi_gpio_mapping *gpio_mapping =NULL ; +struct device *dev = &ts->client->dev; +LIST_HEAD (resources); +int ret; + + ts->gpio_count =0 ; + ts->gpio_int_idx =-1 ; + ret =acpi_dev_get_resources (ACPI_COMPANION (dev), &resources, + goodix_resource, ts); +if (ret <0 ) { +dev_err (dev,"Error getting ACPI resources: %d\n" , ret); +return ret; + } + +acpi_dev_free_resource_list (&resources); + +if (ts->gpio_count ==2 && ts->gpio_int_idx ==0 ) { + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_first_gpios; + }else if (ts->gpio_count ==2 && ts->gpio_int_idx ==1 ) { + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_last_gpios; + }else { +dev_warn (dev,"Unexpected ACPI resources: gpio_count %d, gpio_int_idx %d\n" , + ts->gpio_count, ts->gpio_int_idx); +return -EINVAL ; + } + +return devm_acpi_dev_add_driver_gpios (dev, gpio_mapping); +} +#else +static int goodix_add_acpi_gpio_mappings (struct goodix_ts_data *ts) +{ +return -EINVAL ; +} +#endif /* CONFIG_X86 && CONFIG_ACPI */ +/** * goodix_get_gpio_config - Get GPIO config from ACPI/DT *
@@ -609,6 +700,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)int error;struct device *dev;struct gpio_desc *gpiod; +bool added_acpi_mappings = false;if (!ts->client)return -EINVAL ;
@@ -632,6 +724,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)return error; } +retry_get_irq_gpio:/* Get the interrupt GPIO pin number */ gpiod =devm_gpiod_get_optional (dev,GOODIX_GPIO_INT_NAME ,GPIOD_IN );if (IS_ERR (gpiod)) {
@@ -641,6 +734,11 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) GOODIX_GPIO_INT_NAME, error);return error; } +if (!gpiod &&has_acpi_companion (dev) && !added_acpi_mappings) { + added_acpi_mappings = true; +if (goodix_add_acpi_gpio_mappings (ts) ==0 ) + goto retry_get_irq_gpio; + } ts->gpiod_int = gpiod;
@@ -656,10 +754,17 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod; -if (ts->gpiod_int && ts->gpiod_rst) { - ts->reset_controller_at_probe = true; - ts->load_cfg_from_disk = true; - ts->irq_pin_access_method = irq_pin_access_gpio; +switch (ts->irq_pin_access_method) { +case irq_pin_access_acpi_gpio: +if (!ts->gpiod_int || !ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_none; +break ; +default : +if (ts->gpiod_int && ts->gpiod_rst) { + ts->reset_controller_at_probe = true; + ts->load_cfg_from_disk = true; + ts->irq_pin_access_method = irq_pin_access_gpio; + } }return 0 ;
Signature · 1 line
2.25.0
Re: [PATCH resend 04/10] Input: goodix - Add support for getting IRQ + reset GPIOs on Cherry Trail devices
Quoted 15 lines · Hans de Goede
On most Cherry Trail (x86, UEFI + ACPI) devices the ACPI tables do not have
a_DSDwith a "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID, adding "irq-gpios" and "reset-gpios" mappings, so we cannot get the GPIOS by name
without first manually adding mappings ourselves.These devices contain 1 GpioInt and 1 GpioIo resource in their
_CRStable.
There is no fixed order for these 2. This commit adds code to check that
there is 1 of each as expected and then registers a mapping matching their
order usingdevm_acpi_dev_add_driver_gpios().
Quoted 5 lines
This gives us access to both GPIOs allowing us to properly suspend the
controller during suspend, and making it possible to reset the controller
if necessary.
Can you include the DSDT snippet that defines those GPIOs in the commit message?
Quoted 101 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>--- drivers/input/touchscreen/goodix.c | 113 ++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 4 deletions(-)drivers/input/touchscreen/goodix.c +6
-0@@ -34,6 +34,7 @@ struct goodix_ts_data;enum goodix_irq_pin_access_method { irq_pin_access_none, irq_pin_access_gpio, + irq_pin_access_acpi_gpio, };struct goodix_chip_data {@@ -53,6 +54,8 @@ struct goodix_ts_data {struct regulator *vddio;struct gpio_desc *gpiod_int;struct gpio_desc *gpiod_rst; +int gpio_count; +int gpio_int_idx;u16 id;u16 version;const char *cfg_name;@@ -521,6 +524,12 @@ static int goodix_irq_direction_output(struct goodix_ts_data *ts, return -EINVAL ;case irq_pin_access_gpio:return gpiod_direction_output (ts->gpiod_int, value); +case irq_pin_access_acpi_gpio: +/* +* The IRQ pin triggers on a falling edge, so its gets marked
drivers/input/touchscreen/goodix.c +1
-0+* as active-low, use output_raw to avoid the value inversion.
drivers/input/touchscreen/goodix.c +2
-0+*/ + return gpiod_direction_output_raw(ts->gpiod_int,value);
drivers/input/touchscreen/goodix.c +27
-0}return -EINVAL ;/* Never reached */ @@ -535,6 +544,7 @@ static int goodix_irq_direction_input(struct goodix_ts_data *ts) __func__);return -EINVAL ;case irq_pin_access_gpio: +case irq_pin_access_acpi_gpio:return gpiod_direction_input (ts->gpiod_int); }@@ -599,6 +609,87 @@ static int goodix_reset(struct goodix_ts_data *ts)return 0 ; } +#if definedCONFIG_X86 && definedCONFIG_ACPI +static const struct acpi_gpio_params first_gpio = {0 ,0 , false }; +static const struct acpi_gpio_params second_gpio = {1 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_goodix_int_first_gpios[] = { + {GOODIX_GPIO_INT_NAME "-gpios" , &first_gpio,1 }, + {GOODIX_GPIO_RST_NAME "-gpios" , &second_gpio,1 }, + { }, +}; + +static const struct acpi_gpio_mapping acpi_goodix_int_last_gpios[] = { + {GOODIX_GPIO_RST_NAME "-gpios" , &first_gpio,1 }, + {GOODIX_GPIO_INT_NAME "-gpios" , &second_gpio,1 }, + { }, +}; + +static int goodix_resource (struct acpi_resource *ares,void *data) +{ +struct goodix_ts_data *ts = data; +struct device *dev = &ts->client->dev; +struct acpi_resource_gpio *gpio; + +switch (ares->type) { +case ACPI_RESOURCE_TYPE_GPIO : + gpio = &ares->data.gpio; + if (gpio->connection_type ==
ACPI_RESOURCE_GPIO_TYPE_INT) {drivers/input/touchscreen/goodix.c +4
-0+if (ts->gpio_int_idx ==-1 ) { + ts->gpio_int_idx = ts->gpio_count; + }else { + dev_err(dev, "More then one GpioIntresource, ignoring ACPI GPIO resources\n");
drivers/input/touchscreen/goodix.c +3
-0+ ts->gpio_int_idx =-2 ; + } + }
drivers/input/touchscreen/goodix.c static int goodix_reset(struct goodix_ts_data *ts) · line 654
Quoted 10 lines
drivers/input/touchscreen/goodix.c +10
-0+ ts->gpio_count++; +break ; +default : +break ; + } + +return 0 ; +} + +static int goodix_add_acpi_gpio_mappings (struct goodix_ts_data *ts)
Is there no way to implement this in a more generic way? Is goodix the only driver that needs this sort of handling of GPIOs for ACPI?
This portion could do with being split off, if we were ever to get that more generic solution.
Quoted 63 lines
drivers/input/touchscreen/goodix.c +12
-0+{ +const struct acpi_gpio_mapping *gpio_mapping =NULL ; +struct device *dev = &ts->client->dev; +LIST_HEAD (resources); +int ret; + + ts->gpio_count =0 ; + ts->gpio_int_idx =-1 ; + ret =acpi_dev_get_resources (ACPI_COMPANION (dev), &resources, + goodix_resource, ts); +if (ret <0 ) { + dev_err(dev, "Error getting ACPI resources: %d\n",ret);
drivers/input/touchscreen/goodix.c +13
-0+return ret; + } + +acpi_dev_free_resource_list (&resources); + +if (ts->gpio_count ==2 && ts->gpio_int_idx ==0 ) { + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_first_gpios; + }else if (ts->gpio_count ==2 && ts->gpio_int_idx ==1 ) { + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_last_gpios; + }else { + dev_warn(dev, "Unexpected ACPI resources: gpio_count%d,
gpio_int_idx%d\n",drivers/input/touchscreen/goodix.c +14
-0+ ts->gpio_count, ts->gpio_int_idx); + return -EINVAL; + } + +return devm_acpi_dev_add_driver_gpios (dev, gpio_mapping); +} +#else +static int goodix_add_acpi_gpio_mappings (struct goodix_ts_data *ts) +{ +return -EINVAL ; +} +#endif /* CONFIG_X86 && CONFIG_ACPI */ +/** * goodix_get_gpio_config - Get GPIO config from ACPI/DT * @@ -609,6 +700,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)int error;struct device *dev;struct gpio_desc *gpiod; +bool added_acpi_mappings = false;if (!ts->client)drivers/input/touchscreen/goodix.c +1
-0return -EINVAL ;@@ -632,6 +724,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)return error; } +retry_get_irq_gpio:/* Get the interrupt GPIO pin number */ gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_INT_NAME,
GPIOD_IN);drivers/input/touchscreen/goodix.c +0
-0if (IS_ERR (gpiod)) {
drivers/input/touchscreen/goodix.c static int goodix_get_gpio_config(struct · line 740
Quoted 7 lines
drivers/input/touchscreen/goodix.c +2
-0@@ -641,6 +734,11 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) GOODIX_GPIO_INT_NAME, error);return error; } +if (!gpiod &&has_acpi_companion (dev) && !added_acpi_mappings) { + added_acpi_mappings = true;
Does this mean we retry at most once?
Quoted 7 lines
drivers/input/touchscreen/goodix.c +3
-0+if (goodix_add_acpi_gpio_mappings (ts) ==0 ) + goto retry_get_irq_gpio; + }drivers/input/touchscreen/goodix.c +0
-0ts->gpiod_int = gpiod;
drivers/input/touchscreen/goodix.c static int goodix_get_gpio_config(struct · line 758
Quoted 9 lines
drivers/input/touchscreen/goodix.c +1
-4@@ -656,10 +754,17 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod; -if (ts->gpiod_int && ts->gpiod_rst) { - ts->reset_controller_at_probe = true; - ts->load_cfg_from_disk = true; - ts->irq_pin_access_method = irq_pin_access_gpio; +switch (ts->irq_pin_access_method) {
Can't say I like switch statements with only 2 cases...
drivers/input/touchscreen/goodix.c static int goodix_get_gpio_config(struct · line 759
Quoted 1 line
drivers/input/touchscreen/goodix.c +1
-0+case irq_pin_access_acpi_gpio:
Can you add a comment that explains that this is to fallback in case we didn't manage to get the ACPI mappings?
Quoted 14 lines
drivers/input/touchscreen/goodix.c +9
-0+if (!ts->gpiod_int || !ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_none; +break ; +default : +if (ts->gpiod_int && ts->gpiod_rst) { + ts->reset_controller_at_probe = true; + ts->load_cfg_from_disk = true; + ts->irq_pin_access_method = irq_pin_access_gpio; + }drivers/input/touchscreen/goodix.c +0
-0}return 0 ;
Re: [PATCH resend 04/10] Input: goodix - Add support for getting IRQ + reset GPIOs on Cherry Trail devices
Hi,
Quoted 16 lines · Bastien Nocera
Quoted 15 lines · Hans de Goede
On most Cherry Trail (x86, UEFI + ACPI) devices the ACPI tables do not have
a_DSDwith a "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID, adding "irq-gpios" and "reset-gpios" mappings, so we cannot get the GPIOS by name
without first manually adding mappings ourselves.These devices contain 1 GpioInt and 1 GpioIo resource in their
_CRStable.
There is no fixed order for these 2. This commit adds code to check that
there is 1 of each as expected and then registers a mapping matching their
order usingdevm_acpi_dev_add_driver_gpios().
Quoted 8 lines
Quoted 5 lines
This gives us access to both GPIOs allowing us to properly suspend the
controller during suspend, and making it possible to reset the controller
if necessary.Can you include the DSDT snippet that defines those GPIOs in the commit message?
Will do for v2 of this series.
Quoted 105 lines
Quoted 105 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>--- drivers/input/touchscreen/goodix.c | 113 ++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 4 deletions(-)drivers/input/touchscreen/goodix.c +6
-0@@ -34,6 +34,7 @@ struct goodix_ts_data;enum goodix_irq_pin_access_method { irq_pin_access_none, irq_pin_access_gpio, + irq_pin_access_acpi_gpio, };struct goodix_chip_data {@@ -53,6 +54,8 @@ struct goodix_ts_data {struct regulator *vddio;struct gpio_desc *gpiod_int;struct gpio_desc *gpiod_rst; +int gpio_count; +int gpio_int_idx;u16 id;u16 version;const char *cfg_name;@@ -521,6 +524,12 @@ static int goodix_irq_direction_output(struct goodix_ts_data *ts, return -EINVAL ;case irq_pin_access_gpio:return gpiod_direction_output (ts->gpiod_int, value); +case irq_pin_access_acpi_gpio: +/* +* The IRQ pin triggers on a falling edge, so its gets marked
drivers/input/touchscreen/goodix.c +1
-0+* as active-low, use output_raw to avoid the value inversion.
drivers/input/touchscreen/goodix.c +2
-0+*/ + return gpiod_direction_output_raw(ts->gpiod_int,value);
}return
-EINVAL; /* Never reached */drivers/input/touchscreen/goodix.c +27
-0@@ -535,6 +544,7 @@ static int goodix_irq_direction_input(struct goodix_ts_data *ts) __func__);return -EINVAL ;case irq_pin_access_gpio: +case irq_pin_access_acpi_gpio:return gpiod_direction_input (ts->gpiod_int); }@@ -599,6 +609,87 @@ static int goodix_reset(struct goodix_ts_data *ts)return 0 ; } +#if definedCONFIG_X86 && definedCONFIG_ACPI +static const struct acpi_gpio_params first_gpio = {0 ,0 , false }; +static const struct acpi_gpio_params second_gpio = {1 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_goodix_int_first_gpios[] = { + {GOODIX_GPIO_INT_NAME "-gpios" , &first_gpio,1 }, + {GOODIX_GPIO_RST_NAME "-gpios" , &second_gpio,1 }, + { }, +}; + +static const struct acpi_gpio_mapping acpi_goodix_int_last_gpios[] = { + {GOODIX_GPIO_RST_NAME "-gpios" , &first_gpio,1 }, + {GOODIX_GPIO_INT_NAME "-gpios" , &second_gpio,1 }, + { }, +}; + +static int goodix_resource (struct acpi_resource *ares,void *data) +{ +struct goodix_ts_data *ts = data; +struct device *dev = &ts->client->dev; +struct acpi_resource_gpio *gpio; + +switch (ares->type) { +case ACPI_RESOURCE_TYPE_GPIO : + gpio = &ares->data.gpio; + if (gpio->connection_type ==
ACPI_RESOURCE_GPIO_TYPE_INT) {drivers/input/touchscreen/goodix.c +4
-0+if (ts->gpio_int_idx ==-1 ) { + ts->gpio_int_idx = ts->gpio_count; + }else { + dev_err(dev, "More then one GpioIntresource, ignoring ACPI GPIO resources\n");
drivers/input/touchscreen/goodix.c +8
-0+ ts->gpio_int_idx =-2 ; + } + } + ts->gpio_count++; +break ; +default : +break ; + }
Quoted 8 lines
drivers/input/touchscreen/goodix.c static int goodix_reset(struct goodix_ts_data *ts) · line 654
Quoted 5 lines
drivers/input/touchscreen/goodix.c +5
-0+ +return 0 ; +} + +static int goodix_add_acpi_gpio_mappings (struct goodix_ts_data *ts)Is there no way to implement this in a more generic way? Is goodix the only driver that needs this sort of handling of GPIOs for ACPI?
The Linux GPIO subsystem expects drivers to request GPIOs by name, but in most ACPI tables there is only a list of resources, so we have an index, but not a name. ACPI tables can define extra GPIO info using a method with the special ACPI "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID which is reserved for this, but I'm not aware of any devices where the ACPI tables actually use this.
So all x86 drivers which lookup GPIOs from ACPI tables need to manually add a mapping by calling devm_acpi_dev_add_driver_gpios(). Ideally the Windows driver mandates a fixed order in which the GPIOs must be put in the _CRS method and all we need a single acpi_gpio_mapping in the driver.
But in some cases, like this case the order is not fixed and we need some heuristics to figure out the right order and we have multiple acpi_gpio_mapping-s and select one to pass to devm_acpi_dev_add_driver_gpios() based on heuristics. That is what happening here. These heuristics are tyically different per driver, so this is not really something which we can share between drivers. The only other case which I'm aware of which is doing something similar (but not identical) is the bcm bluetooth code in drivers/bluetooth/hci_bcm.c, starting around line 880.
TL;DR: at this point in time I do not see a more generic way to do this.
Quoted 60 lines
This portion could do with being split off, if we were ever to get that more generic solution.
Quoted 57 lines
drivers/input/touchscreen/goodix.c +12
-0+{ +const struct acpi_gpio_mapping *gpio_mapping =NULL ; +struct device *dev = &ts->client->dev; +LIST_HEAD (resources); +int ret; + + ts->gpio_count =0 ; + ts->gpio_int_idx =-1 ; + ret =acpi_dev_get_resources (ACPI_COMPANION (dev), &resources, + goodix_resource, ts); +if (ret <0 ) { + dev_err(dev, "Error getting ACPI resources: %d\n",ret);
drivers/input/touchscreen/goodix.c +13
-0+return ret; + } + +acpi_dev_free_resource_list (&resources); + +if (ts->gpio_count ==2 && ts->gpio_int_idx ==0 ) { + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_first_gpios; + }else if (ts->gpio_count ==2 && ts->gpio_int_idx ==1 ) { + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_last_gpios; + }else { + dev_warn(dev, "Unexpected ACPI resources: gpio_count%d,
gpio_int_idx%d\n",drivers/input/touchscreen/goodix.c +14
-0+ ts->gpio_count, ts->gpio_int_idx); + return -EINVAL; + } + +return devm_acpi_dev_add_driver_gpios (dev, gpio_mapping); +} +#else +static int goodix_add_acpi_gpio_mappings (struct goodix_ts_data *ts) +{ +return -EINVAL ; +} +#endif /* CONFIG_X86 && CONFIG_ACPI */ +/** * goodix_get_gpio_config - Get GPIO config from ACPI/DT * @@ -609,6 +700,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)int error;struct device *dev;struct gpio_desc *gpiod; +bool added_acpi_mappings = false;if (!ts->client)return
-EINVAL;drivers/input/touchscreen/goodix.c +0
-0@@ -632,6 +724,7 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)return error; }
Quoted 15 lines
drivers/input/touchscreen/goodix.c static int goodix_get_gpio_config(struct · line 740
Quoted 13 lines
drivers/input/touchscreen/goodix.c +1
-0+retry_get_irq_gpio:/* Get the interrupt GPIO pin number */ gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_INT_NAME,
GPIOD_IN);
if (IS_ERR(gpiod)) {drivers/input/touchscreen/goodix.c +2
-0@@ -641,6 +734,11 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) GOODIX_GPIO_INT_NAME, error);return error; } +if (!gpiod &&has_acpi_companion (dev) && !added_acpi_mappings) { + added_acpi_mappings = true;Does this mean we retry at most once?
Yes, we are not really "retrying", we are doing a 2 step probe:
1) First try to get the GPIOs without having done our heuristics and without having called devm_acpi_dev_add_driver_gpios(). This is for ACPI platforms extra GPIO info (including names) using the special ACPI "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID method.
2) If this fails then we add our own name to index mappings and get the GPIOs using those.
Quoted 11 lines
Quoted 11 lines
drivers/input/touchscreen/goodix.c +3
-0+if (goodix_add_acpi_gpio_mappings (ts) ==0 ) + goto retry_get_irq_gpio; + }ts->gpiod_int = gpiod;drivers/input/touchscreen/goodix.c +0
-0@@ -656,10 +754,17 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod;
Quoted 7 lines
drivers/input/touchscreen/goodix.c static int goodix_get_gpio_config(struct goodix_ts_data *ts) · line 757
Quoted 5 lines
drivers/input/touchscreen/goodix.c +1
-4-if (ts->gpiod_int && ts->gpiod_rst) { - ts->reset_controller_at_probe = true; - ts->load_cfg_from_disk = true; - ts->irq_pin_access_method = irq_pin_access_gpio; +switch (ts->irq_pin_access_method) {Can't say I like switch statements with only 2 cases...
More cases are added in later patches.
Quoted 5 lines
drivers/input/touchscreen/goodix.c static int goodix_get_gpio_config(struct · line 759
Quoted 2 lines
drivers/input/touchscreen/goodix.c +1
-0+case irq_pin_access_acpi_gpio:Can you add a comment that explains that this is to fallback in case we didn't manage to get the ACPI mappings?
Will do for v2 if this patch series.
Quoted 14 lines
Quoted 14 lines
drivers/input/touchscreen/goodix.c +9
-0+if (!ts->gpiod_int || !ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_none; +break ; +default : +if (ts->gpiod_int && ts->gpiod_rst) { + ts->reset_controller_at_probe = true; + ts->load_cfg_from_disk = true; + ts->irq_pin_access_method = irq_pin_access_gpio; + }}
Quoted 2 lines
Quoted 1 line
return 0;
Regards,
Hans
Re: [PATCH resend 04/10] Input: goodix - Add support for getting IRQ + reset GPIOs on Cherry Trail devices
Quoted 15 lines · Hans de Goede
Quoted 1 line
Does this mean we retry at most once?
Yes, we are not really "retrying", we are doing a 2 step
probe:
1) First try to get the GPIOs without having done our heuristics and
without having called
devm_acpi_dev_add_driver_gpios(). This is forACPI platforms extra GPIO info (including names) using the special
Quoted 7 lines
ACPI "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID method.
2) If this fails then we add our own name to index mappings and
get the GPIOs using those.
Is there a better way to communicate that? Using a separate function for that piece of code, and maybe some comments to clarify what it's doing.
Thanks for the other explanations.
Re: [PATCH resend 04/10] Input: goodix - Add support for getting IRQ + reset GPIOs on Cherry Trail devices
Hi,
Quoted 20 lines · Bastien Nocera
Quoted 19 lines · Hans de Goede
Quoted 1 line
Does this mean we retry at most once?
Yes, we are not really "retrying", we are doing a 2 step
probe:
1) First try to get the GPIOs without having done our heuristics and
without having called
devm_acpi_dev_add_driver_gpios(). This is forACPI platforms extra GPIO info (including names) using the special
ACPI "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID method.
Quoted 6 lines
Quoted 3 lines
2) If this fails then we add our own name to index mappings and
get the GPIOs using those.
Is there a better way to communicate that? Using a separate function for that piece of code,
The code adding our own mappings already is in a separate function, that is what the goodix_add_acpi_gpio_mappings function is for.
Quoted 2 lines
and maybe some comments to clarify what it's
doing.
I will add a comment above the goodix_add_acpi_gpio_mappings function explaining that it is used to add our own mappings if the ACPI tables do not contain GPIO-name to ACPI resource index mappings.
Regards,
Hans
PATCH RESEND 5/10 Input: goodix - Add support for getting IRQ + reset GPIOs on Bay Trail devices
In reply to Hans de GoedeOn most Bay Trail (x86, UEFI + ACPI) devices the ACPI tables do not have a _DSD with a "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID, adding "irq-gpios" and "reset-gpios" mappings, so we cannot get the GPIOS by name without first manually adding mappings ourselves.
These devices contain 2 GpioIo resource in their _CRS table, on all 4 such devices which I have access to, the order of the 2 GPIOs is reset, int.
Note that the GPIO to which the touchscreen controller irq pin is connected is configured in direct-irq mode on these Bay Trail devices, the pinctrl-baytrail.c driver still allows controlling the pin as a GPIO in this case, but this is not necessarily the case on other X86 ACPI platforms, nor do we have a guarantee that the GPIO order is the same elsewhere, so we limit the use of a _CRS table with 2 GpioIo resources to Bay Trail devices only.
--- drivers/input/touchscreen/goodix.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/input/touchscreen/goodix.c +19 -0
@@ -610,6 +610,21 @@ static int goodix_reset(struct goodix_ts_data *ts) }#if definedCONFIG_X86 && definedCONFIG_ACPI +#include <asm/cpu_device_id.h> +#include <asm/intel-family.h> + +static const struct x86_cpu_id baytrail_cpu_ids[] = { + {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT ,X86_FEATURE_ANY , }, + {} +}; + +static inline bool is_byt (void ) +{ +const struct x86_cpu_id *id =x86_match_cpu (baytrail_cpu_ids); + +return !!id; +} +static const struct acpi_gpio_params first_gpio = {0 ,0 , false };static const struct acpi_gpio_params second_gpio = {1 ,0 , false };
@@ -675,6 +690,10 @@ static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts) }else if (ts->gpio_count ==2 && ts->gpio_int_idx ==1 ) { ts->irq_pin_access_method = irq_pin_access_acpi_gpio; gpio_mapping = acpi_goodix_int_last_gpios; + }else if (is_byt () && ts->gpio_count ==2 && ts->gpio_int_idx ==-1 ) { +dev_info (dev,"No ACPI GpioInt resource, assuming that the GPIO order is reset, int\n" ); + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_last_gpios; }else {dev_warn (dev,"Unexpected ACPI resources: gpio_count %d, gpio_int_idx %d\n" , ts->gpio_count, ts->gpio_int_idx);
Signature · 1 line
2.25.0
Re: [PATCH resend 05/10] Input: goodix - Add support for getting IRQ + reset GPIOs on Bay Trail devices
Quoted 23 lines · Hans de Goede
On most Bay Trail (x86, UEFI + ACPI) devices the ACPI tables do not have
a_DSDwith a "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" UUID, adding "irq-gpios" and "reset-gpios" mappings, so we cannot get the GPIOS by name
without first manually adding mappings ourselves.These devices contain 2 GpioIo resource in their
_CRStable, on all 4 such
devices which I have access to, the order of the 2 GPIOs is reset, int.Note that the GPIO to which the touchscreen controller irq pin is connected
is configured in direct-irq mode on these Bay Trail devices, thepinctrl-baytrail.cdriver still allows controlling the pin as a GPIO in
this case, but this is not necessarily the case on other X86 ACPI platforms, nor do we have a guarantee that the GPIO order is the same elsewhere, so we limit the use of a_CRStable with 2 GpioIo resources
to Bay Trail devices only.
Quoted 5 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>
This is gross, but...
Quoted 48 lines
--- drivers/input/touchscreen/goodix.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/input/touchscreen/goodix.c +15
-0@@ -610,6 +610,21 @@ static int goodix_reset(struct goodix_ts_data *ts) }#if definedCONFIG_X86 && definedCONFIG_ACPI +#include <asm/cpu_device_id.h> +#include <asm/intel-family.h> + +static const struct x86_cpu_id baytrail_cpu_ids[] = { + {X86_VENDOR_INTEL ,6 ,INTEL_FAM6_ATOM_SILVERMONT ,X86_FEATURE_ANY , }, + {} +}; + +static inline bool is_byt (void ) +{ +const struct x86_cpu_id *id =x86_match_cpu (baytrail_cpu_ids); + +return !!id; +} +static const struct acpi_gpio_params first_gpio = {0 ,0 , false };static const struct
acpi_gpio_paramssecond_gpio= { 1, 0, false };drivers/input/touchscreen/goodix.c +4
-0@@ -675,6 +690,10 @@ static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts) }else if (ts->gpio_count ==2 && ts->gpio_int_idx ==1 ) { ts->irq_pin_access_method = irq_pin_access_acpi_gpio; gpio_mapping = acpi_goodix_int_last_gpios; + }else if (is_byt () && ts->gpio_count ==2 && ts->gpio_int_idx ==-1 ) { + dev_info(dev, "No ACPI GpioInt resource, assuming that the GPIO order is reset, int\n"); + ts->irq_pin_access_method = irq_pin_access_acpi_gpio; + gpio_mapping = acpi_goodix_int_last_gpios;drivers/input/touchscreen/goodix.c +0
-0}else { dev_warn(dev, "Unexpected ACPI resources: gpio_count%d,
gpio_int_idx%d\n",
ts->gpio_count,ts->gpio_int_idx);
PATCH RESEND 6/10 Input: goodix - Add support for controlling the IRQ pin through ACPI methods
In reply to Hans de GoedeSome Apollo Lake (x86, UEFI + ACPI) devices only list the reset GPIO in their _CRS table and the bit-banging of the IRQ line necessary to wake-up the controller from suspend can be done by calling 2 Goodix custom / specific ACPI methods.
This commit adds support for controlling the IRQ line in this matter, allowing us to properly suspend the touchscreen controller on such devices.
--- drivers/input/touchscreen/goodix.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/input/touchscreen/goodix.c +30 -0
@@ -35,6 +35,7 @@ enum goodix_irq_pin_access_method { irq_pin_access_none, irq_pin_access_gpio, irq_pin_access_acpi_gpio, + irq_pin_access_acpi_method, }; struct goodix_chip_data {
@@ -516,6 +517,9 @@ static int goodix_send_cfg(struct goodix_ts_data *ts,static int goodix_irq_direction_output (struct goodix_ts_data *ts,int value) { +struct device *dev = &ts->client->dev; +acpi_status status; +switch (ts->irq_pin_access_method) {case irq_pin_access_none: dev_err(&ts->client->dev,
@@ -530,6 +534,10 @@ static int goodix_irq_direction_output(struct goodix_ts_data *ts,* as active-low, use output_raw to avoid the value inversion. */ return gpiod_direction_output_raw (ts->gpiod_int, value); +case irq_pin_access_acpi_method: + status =acpi_execute_simple_method (ACPI_HANDLE (dev), +"INTO" , value); +return ACPI_SUCCESS (status) ?0 : -EIO ; }return -EINVAL ;/* Never reached */
@@ -537,6 +545,9 @@ static int goodix_irq_direction_output(struct goodix_ts_data *ts,static int goodix_irq_direction_input (struct goodix_ts_data *ts) { +struct device *dev = &ts->client->dev; +acpi_status status; +switch (ts->irq_pin_access_method) {case irq_pin_access_none: dev_err(&ts->client->dev,
@@ -546,6 +557,10 @@ static int goodix_irq_direction_input(struct goodix_ts_data *ts)case irq_pin_access_gpio:case irq_pin_access_acpi_gpio:return gpiod_direction_input (ts->gpiod_int); +case irq_pin_access_acpi_method: + status =acpi_evaluate_object (ACPI_HANDLE (dev),"INTI" , +NULL ,NULL ); +return ACPI_SUCCESS (status) ?0 : -EIO ; }return -EINVAL ;/* Never reached */
@@ -640,6 +655,11 @@ static const struct acpi_gpio_mapping acpi_goodix_int_last_gpios[] = { { }, }; +static const struct acpi_gpio_mapping acpi_goodix_reset_only_gpios[] = { + {GOODIX_GPIO_RST_NAME "-gpios" , &first_gpio,1 }, + { }, +}; +static int goodix_resource (struct acpi_resource *ares,void *data) {struct goodix_ts_data *ts = data;
@@ -690,6 +710,12 @@ static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts) }else if (ts->gpio_count ==2 && ts->gpio_int_idx ==1 ) { ts->irq_pin_access_method = irq_pin_access_acpi_gpio; gpio_mapping = acpi_goodix_int_last_gpios; + }else if (ts->gpio_count ==1 && ts->gpio_int_idx ==-1 && +acpi_has_method (ACPI_HANDLE (dev),"INTI" ) && +acpi_has_method (ACPI_HANDLE (dev),"INTO" )) { +dev_info (dev,"Using ACPI INTI and INTO methods for IRQ pin access\n" ); + ts->irq_pin_access_method = irq_pin_access_acpi_method; + gpio_mapping = acpi_goodix_reset_only_gpios; }else if (is_byt () && ts->gpio_count ==2 && ts->gpio_int_idx ==-1 ) {dev_info (dev,"No ACPI GpioInt resource, assuming that the GPIO order is reset, int\n" ); ts->irq_pin_access_method = irq_pin_access_acpi_gpio;
@@ -778,6 +804,10 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)if (!ts->gpiod_int || !ts->gpiod_rst) ts->irq_pin_access_method = irq_pin_access_none;break ; +case irq_pin_access_acpi_method: +if (!ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_none; +break ;default :if (ts->gpiod_int && ts->gpiod_rst) { ts->reset_controller_at_probe = true;
Signature · 1 line
2.25.0
Re: [PATCH resend 06/10] Input: goodix - Add support for controlling the IRQ pin through ACPI methods
Quoted 9 lines · Hans de Goede
Some Apollo Lake (x86, UEFI + ACPI) devices only list the reset GPIO in their
_CRStable and the bit-banging of the IRQ line necessary to wake-up the controller from suspend can be done by calling 2 Goodix custom / specific ACPI methods.This commit adds support for controlling the IRQ line in this matter, allowing us to properly suspend the touchscreen controller on such devices.
Quoted 5 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>
What.
Quoted 111 lines
--- drivers/input/touchscreen/goodix.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)drivers/input/touchscreen/goodix.c +4
-0@@ -35,6 +35,7 @@ enum goodix_irq_pin_access_method { irq_pin_access_none, irq_pin_access_gpio, irq_pin_access_acpi_gpio, + irq_pin_access_acpi_method, }; struct goodix_chip_data {@@ -516,6 +517,9 @@ static int goodix_send_cfg(struct goodix_ts_data *ts, static int goodix_irq_direction_output(struct goodix_ts_data *ts,int value) { +struct device *dev = &ts->client->dev; +acpi_status status; +switch (ts->irq_pin_access_method) {case irq_pin_access_none:drivers/input/touchscreen/goodix.c +0
-0dev_err(&ts->client->dev,@@ -530,6 +534,10 @@ static int goodix_irq_direction_output(structgoodix_ts_data *ts, * as active-low, use output_raw to avoid the valueinversion.
drivers/input/touchscreen/goodix.c +0
-0*/ return gpiod_direction_output_raw(ts->gpiod_int,value);
drivers/input/touchscreen/goodix.c +7
-0+case irq_pin_access_acpi_method: + status =acpi_execute_simple_method (ACPI_HANDLE (dev), +"INTO" , value); +return ACPI_SUCCESS (status) ?0 : -EIO ; }return -EINVAL ;/* Never reached */ @@ -537,6 +545,9 @@ static int goodix_irq_direction_output(structgoodix_ts_data *ts, static int goodix_irq_direction_input(struct goodix_ts_data *ts) { + struct device *dev = &ts->client->dev; +acpi_status status; +switch (ts->irq_pin_access_method) {case irq_pin_access_none:drivers/input/touchscreen/goodix.c +4
-0dev_err(&ts->client->dev,@@ -546,6 +557,10 @@ static int goodix_irq_direction_input(struct goodix_ts_data *ts)case irq_pin_access_gpio:case irq_pin_access_acpi_gpio:return gpiod_direction_input (ts->gpiod_int); +case irq_pin_access_acpi_method: + status =acpi_evaluate_object (ACPI_HANDLE (dev),"INTI" , +NULL ,NULL ); +return ACPI_SUCCESS (status) ?0 : -EIO ; }drivers/input/touchscreen/goodix.c +5
-0return -EINVAL ;/* Never reached */ @@ -640,6 +655,11 @@ static const struct acpi_gpio_mapping acpi_goodix_int_last_gpios[] = { { }, }; +static const struct acpi_gpio_mapping acpi_goodix_reset_only_gpios[] = { + {GOODIX_GPIO_RST_NAME "-gpios" , &first_gpio,1 }, + { }, +}; +static int goodix_resource (struct acpi_resource *ares,void *data){
drivers/input/touchscreen/goodix.c +6
-0struct goodix_ts_data *ts = data;@@ -690,6 +710,12 @@ static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts) }else if (ts->gpio_count ==2 && ts->gpio_int_idx ==1 ) { ts->irq_pin_access_method = irq_pin_access_acpi_gpio; gpio_mapping = acpi_goodix_int_last_gpios; + }else if (ts->gpio_count ==1 && ts->gpio_int_idx ==-1 && +acpi_has_method (ACPI_HANDLE (dev),"INTI" ) && +acpi_has_method (ACPI_HANDLE (dev),"INTO" )) { + dev_info(dev, "Using ACPI INTI and INTO methods for IRQ pin access\n"); + ts->irq_pin_access_method = irq_pin_access_acpi_method; + gpio_mapping = acpi_goodix_reset_only_gpios; } else if (is_byt() && ts->gpio_count == 2 && ts->gpio_int_idx== -1) {
dev_info(dev, "No ACPI GpioInt resource, assuming that
the GPIO order is reset, int\n");drivers/input/touchscreen/goodix.c +4
-0ts->irq_pin_access_method = irq_pin_access_acpi_gpio;@@ -778,6 +804,10 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)if (!ts->gpiod_int || !ts->gpiod_rst) ts->irq_pin_access_method = irq_pin_access_none;break ; +case irq_pin_access_acpi_method: +if (!ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_none; +break ;drivers/input/touchscreen/goodix.c +0
-0default :if (ts->gpiod_int && ts->gpiod_rst) { ts->reset_controller_at_probe = true;
PATCH RESEND 7/10 Input: goodix - Move defines to above struct goodix_ts_data declaration
In reply to Hans de GoedeMove the defines to above the struct goodix_ts_data declaration, so that the MAX defines can be used inside the struct goodix_ts_data declaration. No functional changes, just moving a block of code.
--- drivers/input/touchscreen/goodix.c | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-)
drivers/input/touchscreen/goodix.c +30 -30
@@ -29,6 +29,36 @@#include <linux/of.h> #include <asm/unaligned.h> +#define GOODIX_GPIO_INT_NAME "irq" +#define GOODIX_GPIO_RST_NAME "reset" + +#define GOODIX_MAX_HEIGHT 4096 +#define GOODIX_MAX_WIDTH 4096 +#define GOODIX_INT_TRIGGER 1 +#define GOODIX_CONTACT_SIZE 8 +#define GOODIX_MAX_CONTACT_SIZE 9 +#define GOODIX_MAX_CONTACTS 10 + +#define GOODIX_CONFIG_MAX_LENGTH 240 +#define GOODIX_CONFIG_911_LENGTH 186 +#define GOODIX_CONFIG_967_LENGTH 228 + +/* Register defines */ +#define GOODIX_REG_COMMAND 0x8040 +#define GOODIX_CMD_SCREEN_OFF 0x05 + +#define GOODIX_READ_COOR_ADDR 0x814E +#define GOODIX_GT1X_REG_CONFIG_DATA 0x8050 +#define GOODIX_GT9X_REG_CONFIG_DATA 0x8047 +#define GOODIX_REG_ID 0x8140 + +#define GOODIX_BUFFER_STATUS_READY BIT(7) +#define GOODIX_BUFFER_STATUS_TIMEOUT 20 + +#define RESOLUTION_LOC 1 +#define MAX_CONTACTS_LOC 5 +#define TRIGGER_LOC 6 +struct goodix_ts_data ;enum goodix_irq_pin_access_method {
@@ -68,36 +98,6 @@ struct goodix_ts_data {unsigned int contact_size; }; -#define GOODIX_GPIO_INT_NAME "irq" -#define GOODIX_GPIO_RST_NAME "reset" - -#define GOODIX_MAX_HEIGHT 4096 -#define GOODIX_MAX_WIDTH 4096 -#define GOODIX_INT_TRIGGER 1 -#define GOODIX_CONTACT_SIZE 8 -#define GOODIX_MAX_CONTACT_SIZE 9 -#define GOODIX_MAX_CONTACTS 10 - -#define GOODIX_CONFIG_MAX_LENGTH 240 -#define GOODIX_CONFIG_911_LENGTH 186 -#define GOODIX_CONFIG_967_LENGTH 228 - -/* Register defines */ -#define GOODIX_REG_COMMAND 0x8040 -#define GOODIX_CMD_SCREEN_OFF 0x05 - -#define GOODIX_READ_COOR_ADDR 0x814E -#define GOODIX_GT1X_REG_CONFIG_DATA 0x8050 -#define GOODIX_GT9X_REG_CONFIG_DATA 0x8047 -#define GOODIX_REG_ID 0x8140 - -#define GOODIX_BUFFER_STATUS_READY BIT(7) -#define GOODIX_BUFFER_STATUS_TIMEOUT 20 - -#define RESOLUTION_LOC 1 -#define MAX_CONTACTS_LOC 5 -#define TRIGGER_LOC 6 -static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const struct firmware *cfg); static int goodix_check_cfg_16(struct goodix_ts_data *ts,
Signature · 1 line
2.25.0
Re: [PATCH resend 07/10] Input: goodix - Move defines to above struct goodix_ts_data declaration
Quoted 9 lines · Hans de Goede
Move the defines to above the struct
goodix_ts_datadeclaration, so that the MAX defines can be used inside the structgoodix_ts_datadeclaration. No functional changes, just moving a block of code.Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Sure.
Quoted 84 lines
--- drivers/input/touchscreen/goodix.c | 60 +++++++++++++++------------- -- 1 file changed, 30 insertions(+), 30 deletions(-)drivers/input/touchscreen/goodix.c +30
-30@@ -29,6 +29,36 @@#include <linux/of.h> #include <asm/unaligned.h> +#define GOODIX_GPIO_INT_NAME "irq" +#define GOODIX_GPIO_RST_NAME "reset" + +#define GOODIX_MAX_HEIGHT 4096 +#define GOODIX_MAX_WIDTH 4096 +#define GOODIX_INT_TRIGGER 1 +#define GOODIX_CONTACT_SIZE 8 +#define GOODIX_MAX_CONTACT_SIZE 9 +#define GOODIX_MAX_CONTACTS 10 + +#define GOODIX_CONFIG_MAX_LENGTH 240 +#define GOODIX_CONFIG_911_LENGTH 186 +#define GOODIX_CONFIG_967_LENGTH 228 + +/* Register defines */ +#define GOODIX_REG_COMMAND 0x8040 +#define GOODIX_CMD_SCREEN_OFF 0x05 + +#define GOODIX_READ_COOR_ADDR 0x814E +#define GOODIX_GT1X_REG_CONFIG_DATA 0x8050 +#define GOODIX_GT9X_REG_CONFIG_DATA 0x8047 +#define GOODIX_REG_ID 0x8140 + +#define GOODIX_BUFFER_STATUS_READY BIT(7) +#define GOODIX_BUFFER_STATUS_TIMEOUT 20 + +#define RESOLUTION_LOC 1 +#define MAX_CONTACTS_LOC 5 +#define TRIGGER_LOC 6 +struct goodix_ts_data ;enum goodix_irq_pin_access_method {@@ -68,36 +98,6 @@ struct goodix_ts_data {unsigned int contact_size; }; -#define GOODIX_GPIO_INT_NAME "irq" -#define GOODIX_GPIO_RST_NAME "reset" - -#define GOODIX_MAX_HEIGHT 4096 -#define GOODIX_MAX_WIDTH 4096 -#define GOODIX_INT_TRIGGER 1 -#define GOODIX_CONTACT_SIZE 8 -#define GOODIX_MAX_CONTACT_SIZE 9 -#define GOODIX_MAX_CONTACTS 10 - -#define GOODIX_CONFIG_MAX_LENGTH 240 -#define GOODIX_CONFIG_911_LENGTH 186 -#define GOODIX_CONFIG_967_LENGTH 228 - -/* Register defines */ -#define GOODIX_REG_COMMAND 0x8040 -#define GOODIX_CMD_SCREEN_OFF 0x05 - -#define GOODIX_READ_COOR_ADDR 0x814E -#define GOODIX_GT1X_REG_CONFIG_DATA 0x8050 -#define GOODIX_GT9X_REG_CONFIG_DATA 0x8047 -#define GOODIX_REG_ID 0x8140 - -#define GOODIX_BUFFER_STATUS_READY BIT(7) -#define GOODIX_BUFFER_STATUS_TIMEOUT 20 - -#define RESOLUTION_LOC 1 -#define MAX_CONTACTS_LOC 5 -#define TRIGGER_LOC 6 -static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const struct firmware *cfg); static int goodix_check_cfg_16(struct goodix_ts_data *ts,
PATCH RESEND 8/10 Input: goodix - Save a copy of the config from goodix_read_config()
In reply to Hans de GoedeSave a copy of the config in goodix_read_config(), this is a preparation patch for restoring the config if it was lost after a supend/resume cycle.
--- drivers/input/touchscreen/goodix.c | 51 ++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 6 deletions(-)
drivers/input/touchscreen/goodix.c +45 -6
@@ -72,6 +72,7 @@ struct goodix_chip_data {u16 config_addr;int config_len;int (*check_config)(struct goodix_ts_data *,const struct firmware *); +void (*fix_config)(struct goodix_ts_data *ts); };struct goodix_ts_data {
@@ -96,35 +97,42 @@ struct goodix_ts_data {unsigned long irq_flags;enum goodix_irq_pin_access_method irq_pin_access_method;unsigned int contact_size; +u8 config[GOODIX_CONFIG_MAX_LENGTH ]; };static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const struct firmware *cfg);static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const struct firmware *cfg); +static void goodix_fix_cfg_8 (struct goodix_ts_data *ts); +static void goodix_fix_cfg_16 (struct goodix_ts_data *ts);static const struct goodix_chip_data gt1x_chip_data = { .config_addr =GOODIX_GT1X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_MAX_LENGTH , .check_config = goodix_check_cfg_16, + .fix_config = goodix_fix_cfg_16, };static const struct goodix_chip_data gt911_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_911_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const struct goodix_chip_data gt967_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_967_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const struct goodix_chip_data gt9x_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_MAX_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const unsigned long goodix_irq_flags[] = {
@@ -442,6 +450,19 @@ static int goodix_check_cfg_8(struct goodix_ts_data *ts,return 0 ; } +static void goodix_fix_cfg_8 (struct goodix_ts_data *ts) +{ +int i, raw_cfg_len = ts->chip->config_len -2 ; +u8 check_sum =0 ; + +for (i =0 ; i < raw_cfg_len; i++) + check_sum += ts->config[i]; + check_sum = (~check_sum) +1 ; + + ts->config[raw_cfg_len] = check_sum; + ts->config[raw_cfg_len +1 ] =1 ; +} +static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const struct firmware *cfg) {
@@ -466,6 +487,19 @@ static int goodix_check_cfg_16(struct goodix_ts_data *ts,return 0 ; } +static void goodix_fix_cfg_16 (struct goodix_ts_data *ts) +{ +int i, raw_cfg_len = ts->chip->config_len -3 ; +u16 check_sum =0 ; + +for (i =0 ; i < raw_cfg_len; i +=2 ) + check_sum +=get_unaligned_be16 (&ts->config[i]); + check_sum = (~check_sum) +1 ; + +put_unaligned_be16 (check_sum, &ts->config[raw_cfg_len]); + ts->config[raw_cfg_len +2 ] =1 ; +} +/** * goodix_check_cfg - Checks if config fw is valid *
@@ -828,12 +862,11 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)*/ static void goodix_read_config (struct goodix_ts_data *ts) { -u8 config[GOODIX_CONFIG_MAX_LENGTH ];int x_max, y_max;int error; error =goodix_i2c_read (ts->client, ts->chip->config_addr, - config, ts->chip->config_len); + ts->config, ts->chip->config_len);if (error) {dev_warn (&ts->client->dev,"Error reading config: %d\n" , error);
@@ -842,15 +875,21 @@ static void goodix_read_config(struct goodix_ts_data *ts)return ; } - ts->int_trigger_type = config[TRIGGER_LOC ] &0x03 ; - ts->max_touch_num = config[MAX_CONTACTS_LOC ] &0x0f ; + ts->int_trigger_type = ts->config[TRIGGER_LOC ] &0x03 ; + ts->max_touch_num = ts->config[MAX_CONTACTS_LOC ] &0x0f ; - x_max =get_unaligned_le16 (&config[RESOLUTION_LOC ]); - y_max =get_unaligned_le16 (&config[RESOLUTION_LOC +2 ]); + x_max =get_unaligned_le16 (&ts->config[RESOLUTION_LOC ]); + y_max =get_unaligned_le16 (&ts->config[RESOLUTION_LOC +2 ]);if (x_max && y_max) {input_abs_set_max (ts->input_dev,ABS_MT_POSITION_X , x_max -1 );input_abs_set_max (ts->input_dev,ABS_MT_POSITION_Y , y_max -1 ); } + +/* +* Ensure valid checksum and config_fresh bit being set for possible +* re-upload of config after suspend/resume. +*/ + ts->chip->fix_config (ts); }/**
Signature · 1 line
2.25.0
Re: [PATCH resend 08/10] Input: goodix - Save a copy of the config from goodix_read_config()
Quoted 4 lines · Hans de Goede
Save a copy of the config in
goodix_read_config(), this is a preparation
patch for restoring the config if it was lost after a supend/resume cycle.
Is "fix" really the best verb for this "calculate checksum"?
Quoted 6 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Looks fine apart from the nitpicks.
Quoted 68 lines
--- drivers/input/touchscreen/goodix.c | 51 ++++++++++++++++++++++++++ ---- 1 file changed, 45 insertions(+), 6 deletions(-)drivers/input/touchscreen/goodix.c +1
-0@@ -72,6 +72,7 @@ struct goodix_chip_data {u16 config_addr;int config_len;int (*check_config)(struct goodix_ts_data *,const struct firmware *); +void (*fix_config)(struct goodix_ts_data *ts); };struct
goodix_ts_data{drivers/input/touchscreen/goodix.c +8
-0@@ -96,35 +97,42 @@ struct goodix_ts_data {unsigned long irq_flags;enum goodix_irq_pin_access_method irq_pin_access_method;unsigned int contact_size; +u8 config[GOODIX_CONFIG_MAX_LENGTH ]; };static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const struct firmware *cfg);static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const struct firmware *cfg); +static void goodix_fix_cfg_8 (struct goodix_ts_data *ts); +static void goodix_fix_cfg_16 (struct goodix_ts_data *ts);static const struct goodix_chip_data gt1x_chip_data = { .config_addr =GOODIX_GT1X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_MAX_LENGTH , .check_config = goodix_check_cfg_16, + .fix_config = goodix_fix_cfg_16, };static const struct goodix_chip_data gt911_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_911_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const struct goodix_chip_data gt967_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_967_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const struct goodix_chip_data gt9x_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_MAX_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const unsigned long goodix_irq_flags[] = {@@ -442,6 +450,19 @@ static int goodix_check_cfg_8(structgoodix_ts_data *ts, return 0; } +static void goodix_fix_cfg_8 (struct goodix_ts_data *ts)
drivers/input/touchscreen/goodix.c static int goodix_check_cfg_8(struct · line 464
Quoted 10 lines
drivers/input/touchscreen/goodix.c +10
-0+{ +int i, raw_cfg_len = ts->chip->config_len -2 ; +u8 check_sum =0 ; + +for (i =0 ; i < raw_cfg_len; i++) + check_sum += ts->config[i]; + check_sum = (~check_sum) +1 ; + + ts->config[raw_cfg_len] = check_sum; + ts->config[raw_cfg_len +1 ] =1 ;
Would be good to mention that this is the "config_fresh" bit, in this function and others.
Quoted 66 lines
drivers/input/touchscreen/goodix.c +2
-0+} +static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const struct firmware *cfg){
drivers/input/touchscreen/goodix.c +13
-0@@ -466,6 +487,19 @@ static int goodix_check_cfg_16(structgoodix_ts_data *ts, return 0; } +static void goodix_fix_cfg_16 (struct goodix_ts_data *ts) +{ +int i, raw_cfg_len = ts->chip->config_len -3 ; +u16 check_sum =0 ; + +for (i =0 ; i < raw_cfg_len; i +=2 ) + check_sum +=get_unaligned_be16 (&ts->config[i]); + check_sum = (~check_sum) +1 ; + +put_unaligned_be16 (check_sum, &ts->config[raw_cfg_len]); + ts->config[raw_cfg_len +2 ] =1 ; +} +/** * goodix_check_cfg - Checks if config fw is valid *
drivers/input/touchscreen/goodix.c +1
-2@@ -828,12 +862,11 @@ static int goodix_get_gpio_config(structgoodix_ts_data *ts) */ static void goodix_read_config (struct goodix_ts_data *ts) { -u8 config[GOODIX_CONFIG_MAX_LENGTH ];int x_max, y_max;int error; error =goodix_i2c_read (ts->client, ts->chip->config_addr, - config, ts->chip->config_len); + ts->config, ts->chip->config_len);if (error) { dev_warn(&ts->client->dev, "Error reading config:%d\n",
drivers/input/touchscreen/goodix.c +7
-4error);@@ -842,15 +875,21 @@ static void goodix_read_config(struct goodix_ts_data *ts) return; } - ts->int_trigger_type = config[TRIGGER_LOC ] &0x03 ; - ts->max_touch_num = config[MAX_CONTACTS_LOC ] &0x0f ; + ts->int_trigger_type = ts->config[TRIGGER_LOC ] &0x03 ; + ts->max_touch_num = ts->config[MAX_CONTACTS_LOC ] &0x0f ; - x_max =get_unaligned_le16 (&config[RESOLUTION_LOC ]); - y_max =get_unaligned_le16 (&config[RESOLUTION_LOC +2 ]); + x_max =get_unaligned_le16 (&ts->config[RESOLUTION_LOC ]); + y_max =get_unaligned_le16 (&ts->config[RESOLUTION_LOC +2 ]);if (x_max && y_max) {input_abs_set_max (ts->input_dev,ABS_MT_POSITION_X , x_max -1 );input_abs_set_max (ts->input_dev,ABS_MT_POSITION_Y , y_max -1 ); } + +/* +* Ensure valid checksum and config_fresh bit being set for possible
drivers/input/touchscreen/goodix.c static void goodix_read_config(struct goodix_ts_data *ts) · line 891
Quoted 2 lines
drivers/input/touchscreen/goodix.c +2
-0+* re-upload of config after suspend/resume. +*/
I think that the explanation should ultimately be shorter if the vfunc was better named.
Quoted 4 lines
drivers/input/touchscreen/goodix.c +1
-0+ ts->chip->fix_config (ts); }/**
Re: [PATCH resend 08/10] Input: goodix - Save a copy of the config from goodix_read_config()
Hi,
Quoted 7 lines · Bastien Nocera
Quoted 4 lines · Hans de Goede
Save a copy of the config in
goodix_read_config(), this is a preparation
patch for restoring the config if it was lost after a supend/resume cycle.Is "fix" really the best verb for this "calculate checksum"?
Good point, I've renamed fix_config to calc_config_checksum for v2.
Quoted 77 lines
Quoted 5 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>Looks fine apart from the nitpicks.
Reviewed-by Bastien Nocera <[email protected]>Quoted 67 lines
--- drivers/input/touchscreen/goodix.c | 51 ++++++++++++++++++++++++++ ---- 1 file changed, 45 insertions(+), 6 deletions(-)drivers/input/touchscreen/goodix.c +1
-0@@ -72,6 +72,7 @@ struct goodix_chip_data {u16 config_addr;int config_len;int (*check_config)(struct goodix_ts_data *,const struct firmware *); +void (*fix_config)(struct goodix_ts_data *ts); };struct goodix_ts_data {drivers/input/touchscreen/goodix.c +7
-0@@ -96,35 +97,42 @@ struct goodix_ts_data {unsigned long irq_flags;enum goodix_irq_pin_access_method irq_pin_access_method;unsigned int contact_size; +u8 config[GOODIX_CONFIG_MAX_LENGTH ]; };static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const struct firmware *cfg);static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const struct firmware *cfg); +static void goodix_fix_cfg_8 (struct goodix_ts_data *ts); +static void goodix_fix_cfg_16 (struct goodix_ts_data *ts);static const struct goodix_chip_data gt1x_chip_data = { .config_addr =GOODIX_GT1X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_MAX_LENGTH , .check_config = goodix_check_cfg_16, + .fix_config = goodix_fix_cfg_16, };static const struct goodix_chip_data gt911_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_911_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const struct goodix_chip_data gt967_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_967_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const struct goodix_chip_data gt9x_chip_data = { .config_addr =GOODIX_GT9X_REG_CONFIG_DATA , .config_len =GOODIX_CONFIG_MAX_LENGTH , .check_config = goodix_check_cfg_8, + .fix_config = goodix_fix_cfg_8, };static const unsigned long goodix_irq_flags[] = {@@ -442,6 +450,19 @@ static int goodix_check_cfg_8(structgoodix_ts_data *ts, return 0; }
Quoted 14 lines
drivers/input/touchscreen/goodix.c static int goodix_check_cfg_8(struct goodix_ts_data *ts, · line 463
Quoted 11 lines
drivers/input/touchscreen/goodix.c +11
-0+static void goodix_fix_cfg_8 (struct goodix_ts_data *ts) +{ +int i, raw_cfg_len = ts->chip->config_len -2 ; +u8 check_sum =0 ; + +for (i =0 ; i < raw_cfg_len; i++) + check_sum += ts->config[i]; + check_sum = (~check_sum) +1 ; + + ts->config[raw_cfg_len] = check_sum; + ts->config[raw_cfg_len +1 ] =1 ;Would be good to mention that this is the "
config_fresh" bit, in this function and others.
Will fix for v2.
Quoted 73 lines
Quoted 67 lines
drivers/input/touchscreen/goodix.c +2
-0+} +static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const struct firmware *cfg){drivers/input/touchscreen/goodix.c +13
-0@@ -466,6 +487,19 @@ static int goodix_check_cfg_16(structgoodix_ts_data *ts, return 0; } +static void goodix_fix_cfg_16 (struct goodix_ts_data *ts) +{ +int i, raw_cfg_len = ts->chip->config_len -3 ; +u16 check_sum =0 ; + +for (i =0 ; i < raw_cfg_len; i +=2 ) + check_sum +=get_unaligned_be16 (&ts->config[i]); + check_sum = (~check_sum) +1 ; + +put_unaligned_be16 (check_sum, &ts->config[raw_cfg_len]); + ts->config[raw_cfg_len +2 ] =1 ; +} +/** * goodix_check_cfg - Checks if config fw is valid *drivers/input/touchscreen/goodix.c +1
-2@@ -828,12 +862,11 @@ static int goodix_get_gpio_config(structgoodix_ts_data *ts) */ static void goodix_read_config (struct goodix_ts_data *ts) { -u8 config[GOODIX_CONFIG_MAX_LENGTH ];int x_max, y_max;int error; error =goodix_i2c_read (ts->client, ts->chip->config_addr, - config, ts->chip->config_len); + ts->config, ts->chip->config_len);if (error) { dev_warn(&ts->client->dev, "Error reading config:%d\n",
error);drivers/input/touchscreen/goodix.c +7
-4@@ -842,15 +875,21 @@ static void goodix_read_config(struct goodix_ts_data *ts) return; } - ts->int_trigger_type = config[TRIGGER_LOC ] &0x03 ; - ts->max_touch_num = config[MAX_CONTACTS_LOC ] &0x0f ; + ts->int_trigger_type = ts->config[TRIGGER_LOC ] &0x03 ; + ts->max_touch_num = ts->config[MAX_CONTACTS_LOC ] &0x0f ; - x_max =get_unaligned_le16 (&config[RESOLUTION_LOC ]); - y_max =get_unaligned_le16 (&config[RESOLUTION_LOC +2 ]); + x_max =get_unaligned_le16 (&ts->config[RESOLUTION_LOC ]); + y_max =get_unaligned_le16 (&ts->config[RESOLUTION_LOC +2 ]);if (x_max && y_max) {input_abs_set_max (ts->input_dev,ABS_MT_POSITION_X , x_max -1 );input_abs_set_max (ts->input_dev,ABS_MT_POSITION_Y , y_max -1 ); } + +/* +* Ensure valid checksum and config_fresh bit being set for possible
drivers/input/touchscreen/goodix.c static void goodix_read_config(struct goodix_ts_data *ts) · line 891
Quoted 2 lines
drivers/input/touchscreen/goodix.c +2
-0+* re-upload of config after suspend/resume. +*/ I think that the explanation should ultimately be shorter if the vfunc was better named.
Quoted 5 lines
drivers/input/touchscreen/goodix.c static void goodix_read_config(struct goodix_ts_data *ts) · line 895
Quoted 4 lines
drivers/input/touchscreen/goodix.c +1
-0+ ts->chip->fix_config (ts); }/**
Regards,
Hans
PATCH RESEND 9/10 Input: goodix - Make goodix_send_cfg() take a raw buffer as argument
In reply to Hans de GoedeMake goodix_send_cfg() take a raw buffer as argument instead of a struct firmware *cfg, so that it can also be used to restore the config on resume if necessary.
--- drivers/input/touchscreen/goodix.c | 46 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 25 deletions(-)
drivers/input/touchscreen/goodix.c +21 -25
@@ -71,7 +71,7 @@ enum goodix_irq_pin_access_method {struct goodix_chip_data {u16 config_addr;int config_len; -int (*check_config)(struct goodix_ts_data *,const struct firmware *); +int (*check_config)(struct goodix_ts_data *ts,const u8 *cfg,int len);void (*fix_config)(struct goodix_ts_data *ts); };
@@ -101,9 +101,9 @@ struct goodix_ts_data { };static int goodix_check_cfg_8 (struct goodix_ts_data *ts, -const struct firmware *cfg); +const u8 *cfg,int len);static int goodix_check_cfg_16 (struct goodix_ts_data *ts, -const struct firmware *cfg); +const u8 *cfg,int len);static void goodix_fix_cfg_8 (struct goodix_ts_data *ts);static void goodix_fix_cfg_16 (struct goodix_ts_data *ts);
@@ -426,22 +426,21 @@ static int goodix_request_irq(struct goodix_ts_data *ts) ts->irq_flags, ts->client->name, ts); } -static int goodix_check_cfg_8 (struct goodix_ts_data *ts, -const struct firmware *cfg) +static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const u8 *cfg,int len) { -int i, raw_cfg_len = cfg->size -2 ; +int i, raw_cfg_len = len -2 ;u8 check_sum =0 ;for (i =0 ; i < raw_cfg_len; i++) - check_sum += cfg->data[i]; + check_sum += cfg[i]; check_sum = (~check_sum) +1 ; -if (check_sum != cfg->data[raw_cfg_len]) { +if (check_sum != cfg[raw_cfg_len]) {dev_err (&ts->client->dev,"The checksum of the config fw is not correct" );return -EINVAL ; } -if (cfg->data[raw_cfg_len +1 ] !=1 ) { +if (cfg[raw_cfg_len +1 ] !=1 ) {dev_err (&ts->client->dev,"Config fw must have Config_Fresh register set" );return -EINVAL ;
@@ -463,22 +462,22 @@ static void goodix_fix_cfg_8(struct goodix_ts_data *ts) ts->config[raw_cfg_len +1 ] =1 ; } -static int goodix_check_cfg_16 (struct goodix_ts_data *ts, -const struct firmware *cfg) +static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const u8 *cfg, +int len) { -int i, raw_cfg_len = cfg->size -3 ; +int i, raw_cfg_len = len -3 ;u16 check_sum =0 ;for (i =0 ; i < raw_cfg_len; i +=2 ) - check_sum +=get_unaligned_be16 (&cfg->data[i]); + check_sum +=get_unaligned_be16 (&cfg[i]); check_sum = (~check_sum) +1 ; -if (check_sum !=get_unaligned_be16 (&cfg->data[raw_cfg_len])) { +if (check_sum !=get_unaligned_be16 (&cfg[raw_cfg_len])) {dev_err (&ts->client->dev,"The checksum of the config fw is not correct" );return -EINVAL ; } -if (cfg->data[raw_cfg_len +2 ] !=1 ) { +if (cfg[raw_cfg_len +2 ] !=1 ) {dev_err (&ts->client->dev,"Config fw must have Config_Fresh register set" );return -EINVAL ;
@@ -506,16 +505,15 @@ static void goodix_fix_cfg_16(struct goodix_ts_data *ts)* @ts: goodix_ts_data pointer * @cfg: firmware config data */ -static int goodix_check_cfg (struct goodix_ts_data *ts, -const struct firmware *cfg) +static int goodix_check_cfg (struct goodix_ts_data *ts,const u8 *cfg,int len) { -if (cfg->size >GOODIX_CONFIG_MAX_LENGTH ) { +if (len >GOODIX_CONFIG_MAX_LENGTH ) {dev_err (&ts->client->dev,"The length of the config fw is not correct" );return -EINVAL ; } -return ts->chip->check_config (ts, cfg); +return ts->chip->check_config (ts, cfg, len); }/**
@@ -524,17 +522,15 @@ static int goodix_check_cfg(struct goodix_ts_data *ts,* @ts: goodix_ts_data pointer * @cfg: config firmware to write to device */ -static int goodix_send_cfg (struct goodix_ts_data *ts, -const struct firmware *cfg) +static int goodix_send_cfg (struct goodix_ts_data *ts,const u8 *cfg,int len) {int error; - error =goodix_check_cfg (ts, cfg); + error =goodix_check_cfg (ts, cfg, len);if (error)return error; - error =goodix_i2c_write (ts->client, ts->chip->config_addr, cfg->data, - cfg->size); + 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);
@@ -1058,7 +1054,7 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx)if (cfg) {/* send device configuration to the firmware */ - error =goodix_send_cfg (ts, cfg); + error =goodix_send_cfg (ts, cfg->data, cfg->size);if (error) goto err_release_cfg; }
Signature · 1 line
2.25.0
Re: [PATCH resend 09/10] Input: goodix - Make goodix_send_cfg() take a raw buffer as argument
Quoted 21 lines · Hans de Goede
Make
goodix_send_cfg()take a raw buffer as argument instead of a struct firmware *cfg, so that it can also be used to restore the config
on resume if necessary.Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>--- drivers/input/touchscreen/goodix.c | 46 ++++++++++++++------------ ---- 1 file changed, 21 insertions(+), 25 deletions(-)drivers/input/touchscreen/goodix.c +0
-0
drivers/input/touchscreen/goodix.c enum goodix_irq_pin_access_method { · line 76
Quoted 7 lines
drivers/input/touchscreen/goodix.c +1
-1@@ -71,7 +71,7 @@ enum goodix_irq_pin_access_method {struct goodix_chip_data {u16 config_addr;int config_len; -int (*check_config)(struct goodix_ts_data *,const struct firmware *); +int (*check_config)(struct goodix_ts_data *ts,const u8 *cfg,int len);
Any way to make the length a uint instead of an int? That way, we wouldn't need to add < 0 guards, and the "len > MAX_LENGTH" check would be enough.
Looks good otherwise:
Quoted 139 lines
drivers/input/touchscreen/goodix.c +0
-0void (*fix_config)(struct goodix_ts_data *ts);};
drivers/input/touchscreen/goodix.c +7
-8@@ -101,9 +101,9 @@ struct goodix_ts_data { };static int goodix_check_cfg_8 (struct goodix_ts_data *ts, -const struct firmware *cfg); +const u8 *cfg,int len);static int goodix_check_cfg_16 (struct goodix_ts_data *ts, -const struct firmware *cfg); +const u8 *cfg,int len);static void goodix_fix_cfg_8 (struct goodix_ts_data *ts);static void goodix_fix_cfg_16 (struct goodix_ts_data *ts);@@ -426,22 +426,21 @@ static int goodix_request_irq(struct goodix_ts_data *ts) ts->irq_flags, ts->client- >name, ts); } -static int goodix_check_cfg_8 (struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const u8 *cfg,int len) { -int i, raw_cfg_len = cfg->size -2 ; +int i, raw_cfg_len = len -2 ;u8 check_sum =0 ;for (i =0 ; i < raw_cfg_len; i++) - check_sum += cfg->data[i]; + check_sum += cfg[i]; check_sum = (~check_sum) +1 ; -if (check_sum != cfg->data[raw_cfg_len]) { +if (check_sum != cfg[raw_cfg_len]) {dev_err (&ts->client->dev,"The checksum of the config fw is not correct");return -EINVAL ; } -if (cfg->data[raw_cfg_len +1 ] !=1 ) { +if (cfg[raw_cfg_len +1 ] !=1 ) { dev_err(&ts->client->dev, "Config fw must have Config_Fresh registerset");
drivers/input/touchscreen/goodix.c +6
-6return -EINVAL ;@@ -463,22 +462,22 @@ static void goodix_fix_cfg_8(struct goodix_ts_data *ts) ts->config[raw_cfg_len + 1] = 1; } -static int goodix_check_cfg_16 (struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const u8 *cfg, +int len) { -int i, raw_cfg_len = cfg->size -3 ; +int i, raw_cfg_len = len -3 ;u16 check_sum =0 ;for (i =0 ; i < raw_cfg_len; i +=2 ) - check_sum +=get_unaligned_be16 (&cfg->data[i]); + check_sum +=get_unaligned_be16 (&cfg[i]); check_sum = (~check_sum) +1 ; -if (check_sum !=get_unaligned_be16 (&cfg->data[raw_cfg_len])) { +if (check_sum !=get_unaligned_be16 (&cfg[raw_cfg_len])) {dev_err (&ts->client->dev,"The checksum of the config fw is not correct");return -EINVAL ; } -if (cfg->data[raw_cfg_len +2 ] !=1 ) { +if (cfg[raw_cfg_len +2 ] !=1 ) {drivers/input/touchscreen/goodix.c +0
-0dev_err(&ts->client->dev, "Config fw must have Config_Fresh registerset");
drivers/input/touchscreen/goodix.c +3
-4return -EINVAL ;@@ -506,16 +505,15 @@ static void goodix_fix_cfg_16(structgoodix_ts_data *ts) * @ts: goodix_ts_data pointer * @cfg: firmware config data */ -static int goodix_check_cfg (struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_check_cfg (struct goodix_ts_data *ts,const u8 *cfg,int len) { -if (cfg->size >GOODIX_CONFIG_MAX_LENGTH ) { +if (len >GOODIX_CONFIG_MAX_LENGTH ) {dev_err (&ts->client->dev,"The length of the config fw is not correct" );return -EINVAL ; } -return ts->chip->check_config (ts, cfg); +return ts->chip->check_config (ts, cfg, len); }/**
drivers/input/touchscreen/goodix.c +3
-5@@ -524,17 +522,15 @@ static int goodix_check_cfg(structgoodix_ts_data *ts, * @ts: goodix_ts_data pointer * @cfg: config firmware to write to device */ -static int goodix_send_cfg (struct goodix_ts_data *ts, -const struct firmware *cfg) +static int goodix_send_cfg (struct goodix_ts_data *ts,const u8 *cfg,int len) {int error; - error =goodix_check_cfg (ts, cfg); + error =goodix_check_cfg (ts, cfg, len);if (error)return error; - error =goodix_i2c_write (ts->client, ts->chip->config_addr, cfg->data, - cfg->size); + error = goodix_i2c_write(ts->client, ts->chip->config_addr,cfg, len);
drivers/input/touchscreen/goodix.c +0
-0if (error) { dev_err(&ts->client->dev, "Failed to write config data:%d",
drivers/input/touchscreen/goodix.c +1
-1error);@@ -1058,7 +1054,7 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx)if (cfg) {/* send device configuration to the firmware */ - error =goodix_send_cfg (ts, cfg); + error =goodix_send_cfg (ts, cfg->data, cfg->size);if (error) goto err_release_cfg;}
Re: [PATCH resend 09/10] Input: goodix - Make goodix_send_cfg() take a raw buffer as argument
Hi,
Quoted 25 lines · Bastien Nocera
Quoted 24 lines · Hans de Goede
Make
goodix_send_cfg()take a raw buffer as argument instead of a struct firmware *cfg, so that it can also be used to restore the config
on resume if necessary.Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>--- drivers/input/touchscreen/goodix.c | 46 ++++++++++++++------------ ---- 1 file changed, 21 insertions(+), 25 deletions(-)drivers/input/touchscreen/goodix.c +0
-0@@ -71,7 +71,7 @@ enum goodix_irq_pin_access_method {struct goodix_chip_data {u16 config_addr;int config_len;
Quoted 8 lines
drivers/input/touchscreen/goodix.c enum goodix_irq_pin_access_method { · line 76
Quoted 4 lines
drivers/input/touchscreen/goodix.c +1
-1-int (*check_config)(struct goodix_ts_data *,const struct firmware *); +int (*check_config)(struct goodix_ts_data *ts,const u8 *cfg,int len);Any way to make the length a uint instead of an int? That way, we wouldn't need to add < 0 guards, and the "len >
MAX_LENGTH" check would be enough.
Actually the code does things like:
int raw_cfg_len = len - 3;
for (i = 0; i < raw_cfg_len; i += 2)
check_sum += get_unaligned_be16(&ts->config[i]);
check_sum = (~check_sum) + 1;
if (check_sum != get_unaligned_be16(&cfg[raw_cfg_len])) {Which is bad without a minimum check regardless of us using signed or unsigned ints here. unsigned ints will short-circuit / skip the for loop when len < 3, but then we end up with a negative array index when
doing: &cfg[raw_cfg_len]. And when going unsigned then both the loop and the array index will be out of bounds when len < 3. So the proper fix here is to add a minimum check.
I will add an extra patch to the patch-set adding a minimum bounds check.
Regards,
Hans
Quoted 145 lines
Looks good otherwise:
Reviewed-by Bastien Nocera <[email protected]>Quoted 139 lines
drivers/input/touchscreen/goodix.c +0
-0void (*fix_config)(struct goodix_ts_data *ts);};drivers/input/touchscreen/goodix.c +7
-8@@ -101,9 +101,9 @@ struct goodix_ts_data { };static int goodix_check_cfg_8 (struct goodix_ts_data *ts, -const struct firmware *cfg); +const u8 *cfg,int len);static int goodix_check_cfg_16 (struct goodix_ts_data *ts, -const struct firmware *cfg); +const u8 *cfg,int len);static void goodix_fix_cfg_8 (struct goodix_ts_data *ts);static void goodix_fix_cfg_16 (struct goodix_ts_data *ts);@@ -426,22 +426,21 @@ static int goodix_request_irq(struct goodix_ts_data *ts) ts->irq_flags, ts->client- > name, ts); } -static int goodix_check_cfg_8 (struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_check_cfg_8 (struct goodix_ts_data *ts,const u8 *cfg,int len) { -int i, raw_cfg_len = cfg->size -2 ; +int i, raw_cfg_len = len -2 ;u8 check_sum =0 ;for (i =0 ; i < raw_cfg_len; i++) - check_sum += cfg->data[i]; + check_sum += cfg[i]; check_sum = (~check_sum) +1 ; -if (check_sum != cfg->data[raw_cfg_len]) { +if (check_sum != cfg[raw_cfg_len]) {dev_err (&ts->client->dev,"The checksum of the config fw is not correct");return -EINVAL ; } -if (cfg->data[raw_cfg_len +1 ] !=1 ) { +if (cfg[raw_cfg_len +1 ] !=1 ) { dev_err(&ts->client->dev, "Config fw must have Config_Fresh registerset");
return-EINVAL;drivers/input/touchscreen/goodix.c +6
-6@@ -463,22 +462,22 @@ static void goodix_fix_cfg_8(struct goodix_ts_data *ts) ts->config[raw_cfg_len + 1] = 1; } -static int goodix_check_cfg_16 (struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_check_cfg_16 (struct goodix_ts_data *ts,const u8 *cfg, +int len) { -int i, raw_cfg_len = cfg->size -3 ; +int i, raw_cfg_len = len -3 ;u16 check_sum =0 ;for (i =0 ; i < raw_cfg_len; i +=2 ) - check_sum +=get_unaligned_be16 (&cfg->data[i]); + check_sum +=get_unaligned_be16 (&cfg[i]); check_sum = (~check_sum) +1 ; -if (check_sum !=get_unaligned_be16 (&cfg->data[raw_cfg_len])) { +if (check_sum !=get_unaligned_be16 (&cfg[raw_cfg_len])) {dev_err (&ts->client->dev,"The checksum of the config fw is not correct");return -EINVAL ; } -if (cfg->data[raw_cfg_len +2 ] !=1 ) { +if (cfg[raw_cfg_len +2 ] !=1 ) {dev_err(&ts->client->dev,
"Config fw must haveConfig_Freshregister
set");
return-EINVAL;drivers/input/touchscreen/goodix.c +3
-4@@ -506,16 +505,15 @@ static void goodix_fix_cfg_16(structgoodix_ts_data *ts) * @ts: goodix_ts_data pointer * @cfg: firmware config data */ -static int goodix_check_cfg (struct goodix_ts_data *ts, - const struct firmware *cfg) +static int goodix_check_cfg (struct goodix_ts_data *ts,const u8 *cfg,int len) { -if (cfg->size >GOODIX_CONFIG_MAX_LENGTH ) { +if (len >GOODIX_CONFIG_MAX_LENGTH ) {dev_err (&ts->client->dev,"The length of the config fw is not correct" );return -EINVAL ; } -return ts->chip->check_config (ts, cfg); +return ts->chip->check_config (ts, cfg, len); }/**
drivers/input/touchscreen/goodix.c +3
-5@@ -524,17 +522,15 @@ static int goodix_check_cfg(structgoodix_ts_data *ts, * @ts: goodix_ts_data pointer * @cfg: config firmware to write to device */ -static int goodix_send_cfg (struct goodix_ts_data *ts, -const struct firmware *cfg) +static int goodix_send_cfg (struct goodix_ts_data *ts,const u8 *cfg,int len) {int error; - error =goodix_check_cfg (ts, cfg); + error =goodix_check_cfg (ts, cfg, len);if (error)return error; - error =goodix_i2c_write (ts->client, ts->chip->config_addr, cfg->data, - cfg->size); + 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);drivers/input/touchscreen/goodix.c +1
-1@@ -1058,7 +1054,7 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx)if (cfg) {/* send device configuration to the firmware */ - error =goodix_send_cfg (ts, cfg); + error =goodix_send_cfg (ts, cfg->data, cfg->size);if (error) goto err_release_cfg;}
PATCH RESEND 10/10 Input: goodix - Restore config on resume if necessary
In reply to Hans de GoedeSome devices, e.g the Trekstor Primetab S11B, loose there config over a suspend/resume cycle (likely the controller looses power during suspend).
This commit reads back the config version on resume and if matches the expected config version it resets the controller and resends the config we read back and saved at probe time.
--- drivers/input/touchscreen/goodix.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/input/touchscreen/goodix.c +22 -0
@@ -1232,6 +1232,7 @@ static int __maybe_unused goodix_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct goodix_ts_data *ts =i2c_get_clientdata (client); +u8 config_ver;int error;if (ts->irq_pin_access_method == irq_pin_access_none) {
@@ -1253,6 +1254,27 @@ 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 ]) +dev_warn (dev,"Config version mismatch %d != %d, resetting controller\n" , + config_ver, ts->config[0 ]); + +if (error !=0 || config_ver != ts->config[0 ]) { + error =goodix_reset (ts); +if (error) { +dev_err (dev,"Controller reset failed.\n" ); +return error; + } + + error =goodix_send_cfg (ts, ts->config, ts->chip->config_len); +if (error) +return error; + } + error =goodix_request_irq (ts);if (error)return error;
Signature · 1 line
2.25.0
Re: [PATCH resend 10/10] Input: goodix - Restore config on resume if necessary
Quoted 1 line · Hans de Goede
Some devices, e.g the Trekstor Primetab S11B, loose there config over
"lose".
Quoted 1 line
a suspend/resume cycle (likely the controller looses power during
"loses".
Quoted 8 lines
suspend).
This commit reads back the config version on resume and if matches the
expected config version it resets the controller and resends the config
we read back and saved at probe time.
Quoted 5 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Looks fine apart from the nitpicks.
Quoted 23 lines
--- drivers/input/touchscreen/goodix.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)drivers/input/touchscreen/goodix.c +1
-0@@ -1232,6 +1232,7 @@ static int __maybe_unused goodix_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct goodix_ts_data *ts =i2c_get_clientdata (client); +u8 config_ver;int error;drivers/input/touchscreen/goodix.c +0
-0if (ts->irq_pin_access_method == irq_pin_access_none) {@@ -1253,6 +1254,27 @@ static int __maybe_unused goodix_resume(struct device *dev)if (error)return error;
drivers/input/touchscreen/goodix.c static int __maybe_unused goodix_resume(struct · line 1267
Quoted 10 lines
drivers/input/touchscreen/goodix.c +8
-0+ 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 ]) + dev_warn(dev, "Config version mismatch %d != %d, resetting controller\n", + config_ver, ts->config[0 ]);
Should it really be a warning if it happens regularly?
Quoted 17 lines
drivers/input/touchscreen/goodix.c +9
-0+ +if (error !=0 || config_ver != ts->config[0 ]) { + error =goodix_reset (ts); +if (error) { +dev_err (dev,"Controller reset failed.\n" ); +return error; + } + + error = goodix_send_cfg(ts, ts->config, ts->chip-Quoted 1 line
config_len);drivers/input/touchscreen/goodix.c +4
-0+if (error) +return error; + } + error =goodix_request_irq (ts);if (error)return error;
Re: [PATCH resend 10/10] Input: goodix - Restore config on resume if necessary
Hi,
Quoted 50 lines · Bastien Nocera
Quoted 1 line · Hans de Goede
Some devices, e.g the Trekstor Primetab S11B, loose there config over
"lose".
Quoted 1 line
a suspend/resume cycle (likely the controller looses power during
"loses".
Quoted 8 lines
suspend).
This commit reads back the config version on resume and if matches the
expected config version it resets the controller and resends the config
we read back and saved at probe time.Quoted 5 lines
Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>Looks fine apart from the nitpicks.
Reviewed-by Bastien Nocera <[email protected]>Quoted 23 lines
--- drivers/input/touchscreen/goodix.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)drivers/input/touchscreen/goodix.c +1
-0@@ -1232,6 +1232,7 @@ static int __maybe_unused goodix_resume(struct device *dev) {struct i2c_client *client =to_i2c_client (dev);struct goodix_ts_data *ts =i2c_get_clientdata (client); +u8 config_ver;int error;if (ts->irq_pin_access_method == irq_pin_access_none) {drivers/input/touchscreen/goodix.c +0
-0@@ -1253,6 +1254,27 @@ static int __maybe_unused goodix_resume(struct device *dev)if (error)return error;
Quoted 12 lines
drivers/input/touchscreen/goodix.c static int __maybe_unused goodix_resume(struct device *dev) · line 1264
Quoted 10 lines
drivers/input/touchscreen/goodix.c +8
-0+ 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 ]) + dev_warn(dev, "Config version mismatch %d != %d, resetting controller\n", + config_ver, ts->config[0 ]);Should it really be a warning if it happens regularly?
Good point, I've changed this to a dev_info for v2.
Regards,
Hans
Quoted 19 lines
Quoted 18 lines
drivers/input/touchscreen/goodix.c +9
-0+ +if (error !=0 || config_ver != ts->config[0 ]) { + error =goodix_reset (ts); +if (error) { +dev_err (dev,"Controller reset failed.\n" ); +return error; + } + + error = goodix_send_cfg(ts, ts->config, ts->chip-Quoted 1 line
config_len);drivers/input/touchscreen/goodix.c +4
-0+if (error) +return error; + } + error =goodix_request_irq (ts);if (error)return error;
Quoted 40 lines · Hans de Goede
Suspending Goodix touchscreens requires changing the interrupt pin to output before sending them a power-down command. Followed by wiggling the interrupt pin to wake the device up, after which it is put back in input mode.
So far we have only effectively supported this on devices which use devicetree. On X86 ACPI platforms both looking up the pins; and using a
pin as both IRQ and GPIO is a bit more complicated. E.g. on some devices
we cannot directly access the IRQ pin as GPIO and we need to call ACPI
methods to control it instead.This commit adds a new
irq_pin_access_methodfield to thegoodix_chip_data
struct and addsgoodix_irq_direction_outputandgoodix_irq_direction_input
helpers which together abstract the GPIO accesses to the IRQ pin.This is a preparation patch for adding support for properly suspending the
touchscreen on X86 ACPI platforms.Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>--- drivers/input/touchscreen/goodix.c | 62 ++++++++++++++++++++++++-- ---- 1 file changed, 51 insertions(+), 11 deletions(-)drivers/input/touchscreen/goodix.c +0
-0
drivers/input/touchscreen/goodix.c line 36
Quoted 6 lines
drivers/input/touchscreen/goodix.c +3
-0@@ -31,6 +31,11 @@struct goodix_ts_data ; +enum goodix_irq_pin_access_method { + irq_pin_access_none, + irq_pin_access_gpio,
I don't know if that matches the kernel coding style, but I'd rather the enum member names were upper-case, and typedef'ed.
Quoted 20 lines
drivers/input/touchscreen/goodix.c +5
-0+}; +struct goodix_chip_data {u16 config_addr;int config_len;@@ -53,6 +58,7 @@ struct goodix_ts_data {const char *cfg_name;struct completion firmware_loading_complete;unsigned long irq_flags; +enum goodix_irq_pin_access_method irq_pin_access_method;unsigned int contact_size; };@@ -502,17 +508,48 @@ static int goodix_send_cfg(structgoodix_ts_data *ts, return 0; } +static int goodix_irq_direction_output (struct goodix_ts_data *ts, +int value)
drivers/input/touchscreen/goodix.c static int goodix_send_cfg(struct · line 523
Quoted 10 lines
drivers/input/touchscreen/goodix.c +9
-0+{ +switch (ts->irq_pin_access_method) { +case irq_pin_access_none: +dev_err (&ts->client->dev, +"%s called without an irq_pin_access_method set\n", + __func__); +return -EINVAL ; +case irq_pin_access_gpio: +return gpiod_direction_output (ts->gpiod_int, value);
Is that going to complain about default not being handled? If so, an if conditional might be enough.
Quoted 6 lines
drivers/input/touchscreen/goodix.c +6
-0+ } + +return -EINVAL ;/* Never reached */ +} + +static int goodix_irq_direction_input (struct goodix_ts_data *ts)
drivers/input/touchscreen/goodix.c static int goodix_send_cfg(struct goodix_ts_data *ts, · line 536
Quoted 10 lines
drivers/input/touchscreen/goodix.c +9
-0+{ +switch (ts->irq_pin_access_method) { +case irq_pin_access_none: +dev_err (&ts->client->dev, +"%s called without an irq_pin_access_method set\n", + __func__); +return -EINVAL ; +case irq_pin_access_gpio: +return gpiod_direction_input (ts->gpiod_int);
Ditto.
Looks fine otherwise.
Quoted 126 lines
drivers/input/touchscreen/goodix.c +7
-2+ } + +return -EINVAL ;/* Never reached */ +} +static int goodix_int_sync (struct goodix_ts_data *ts) {int error; - error =gpiod_direction_output (ts->gpiod_int,0 ); + error =goodix_irq_direction_output (ts,0 );if (error)return error;msleep (50 );/* T5: 50ms */ - error =gpiod_direction_input (ts->gpiod_int); + error =goodix_irq_direction_input (ts);drivers/input/touchscreen/goodix.c +1
-1if (error)return error;@@ -536,7 +573,7 @@ static int goodix_reset(struct goodix_ts_data *ts)msleep (20 );/* T2: > 10ms */ /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */ - error =gpiod_direction_output (ts->gpiod_int, ts->client->addr == 0x14); + error =goodix_irq_direction_output (ts, ts->client->addr ==0x14 );drivers/input/touchscreen/goodix.c +4
-1if (error)return error;@@ -617,6 +654,9 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod; +if (ts->gpiod_int && ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_gpio; +return 0 ; }@@ -889,7 +929,7 @@ static int goodix_ts_probe(struct i2c_client *client, if (error)return error; -if (ts->gpiod_int && ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_gpio) {/* reset the controller */ error =goodix_reset (ts);drivers/input/touchscreen/goodix.c +1
-1if (error) {@@ -912,7 +952,7 @@ static int goodix_ts_probe(struct i2c_client *client, ts->chip =goodix_get_chip_data (ts->id); -if (ts->gpiod_int && ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_gpio) {/* update device config */ ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL,"goodix_%d_cfg.bin", ts-
Quoted 1 line
id);
drivers/input/touchscreen/goodix.c +1
-1@@ -943,7 +983,7 @@ static int goodix_ts_remove(struct i2c_client *client) {struct goodix_ts_data *ts =i2c_get_clientdata (client); -if (ts->gpiod_int && ts->gpiod_rst) +if (ts->irq_pin_access_method == irq_pin_access_gpio)wait_for_completion (&ts->firmware_loading_complete);drivers/input/touchscreen/goodix.c +1
-1return 0 ;@@ -956,7 +996,7 @@ static int __maybe_unused goodix_suspend(struct device *dev)int error;/* We need gpio pins to suspend/resume */ -if (!ts->gpiod_int || !ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_none) {disable_irq (client->irq);return 0 ;drivers/input/touchscreen/goodix.c +1
-1}@@ -967,7 +1007,7 @@ static int __maybe_unused goodix_suspend(struct device *dev)goodix_free_irq (ts );/* Output LOW on the INT pin for 5 ms */ - error =gpiod_direction_output (ts->gpiod_int,0 ); + error =goodix_irq_direction_output (ts,0 );if (error) {goodix_request_irq (ts);drivers/input/touchscreen/goodix.c +1
-1return error;@@ -979,7 +1019,7 @@ static int __maybe_unused goodix_suspend(struct device *dev) GOODIX_CMD_SCREEN_OFF);if (error) {dev_err (&ts->client->dev,"Screen off command failed\n"); -gpiod_direction_input (ts->gpiod_int); +goodix_irq_direction_input (ts);goodix_request_irq (ts);drivers/input/touchscreen/goodix.c +1
-1return -EAGAIN ; }@@ -999,7 +1039,7 @@ static int __maybe_unused goodix_resume(struct device *dev)struct goodix_ts_data *ts =i2c_get_clientdata (client);int error; -if (!ts->gpiod_int || !ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_none) {enable_irq (client->irq);return 0 ;drivers/input/touchscreen/goodix.c +1
-1}@@ -1008,7 +1048,7 @@ static int __maybe_unused goodix_resume(structdevice *dev) * Exit sleep mode by outputting HIGH level to INT pin * for 2ms~5ms. */ - error =gpiod_direction_output (ts->gpiod_int,1 ); + error =goodix_irq_direction_output (ts,1 );if (error)return error;
Hi,
Quoted 42 lines · Bastien Nocera
Quoted 41 lines · Hans de Goede
Suspending Goodix touchscreens requires changing the interrupt pin to output before sending them a power-down command. Followed by wiggling the interrupt pin to wake the device up, after which it is put back in input mode.
So far we have only effectively supported this on devices which use devicetree. On X86 ACPI platforms both looking up the pins; and using a
pin as both IRQ and GPIO is a bit more complicated. E.g. on some devices
we cannot directly access the IRQ pin as GPIO and we need to call ACPI
methods to control it instead.This commit adds a new
irq_pin_access_methodfield to thegoodix_chip_data
struct and addsgoodix_irq_direction_outputandgoodix_irq_direction_input
helpers which together abstract the GPIO accesses to the IRQ pin.This is a preparation patch for adding support for properly suspending the
touchscreen on X86 ACPI platforms.Cc Dmitry Mastykin <[email protected]>Signed-off-by Hans de Goede <[email protected]>--- drivers/input/touchscreen/goodix.c | 62 ++++++++++++++++++++++++-- ---- 1 file changed, 51 insertions(+), 11 deletions(-)drivers/input/touchscreen/goodix.c +0
-0@@ -31,6 +31,11 @@
Quoted 8 lines
drivers/input/touchscreen/goodix.c line 36
Quoted 5 lines
drivers/input/touchscreen/goodix.c +3
-0struct goodix_ts_data ; +enum goodix_irq_pin_access_method { + irq_pin_access_none, + irq_pin_access_gpio,I don't know if that matches the kernel coding style, but I'd rather the enum member names were upper-case, and typedef'ed.
I checked and most of the kernel also uses upper-case for enum member names, I'll fix this (for the entire series) for v2 of the series.
As for using typedef-s that is typically not done in the kernel for enums / structs so I'm going to keep that as is.
Quoted 19 lines
Quoted 19 lines
drivers/input/touchscreen/goodix.c +3
-0+}; +struct goodix_chip_data {u16 config_addr;int config_len;@@ -53,6 +58,7 @@ struct goodix_ts_data {const char *cfg_name;struct completion firmware_loading_complete;unsigned long irq_flags; +enum goodix_irq_pin_access_method irq_pin_access_method;unsigned int contact_size; };@@ -502,17 +508,48 @@ static int goodix_send_cfg(structgoodix_ts_data *ts, return 0; }
Quoted 15 lines
drivers/input/touchscreen/goodix.c static int goodix_send_cfg(struct goodix_ts_data *ts, · line 521
Quoted 12 lines
drivers/input/touchscreen/goodix.c +11
-0+static int goodix_irq_direction_output (struct goodix_ts_data *ts, +int value) +{ +switch (ts->irq_pin_access_method) { +case irq_pin_access_none: +dev_err (&ts->client->dev, +"%s called without an irq_pin_access_method set\n", + __func__); +return -EINVAL ; +case irq_pin_access_gpio: +return gpiod_direction_output (ts->gpiod_int, value);Is that going to complain about default not being handled? If so, an if conditional might be enough.
All the values in the enum are handled so there is no need for a default label. As for changing this to an if, later patches add more values to the enum and to the switch-case, having this as a switch-case from the start makes the diff in later patches smaller.
Quoted 11 lines
Quoted 11 lines
drivers/input/touchscreen/goodix.c +10
-0+ } + +return -EINVAL ;/* Never reached */ +} + +static int goodix_irq_direction_input (struct goodix_ts_data *ts) +{ +switch (ts->irq_pin_access_method) { +case irq_pin_access_none: + dev_err(&ts->client->dev,
Quoted 8 lines
drivers/input/touchscreen/goodix.c static int goodix_send_cfg(struct goodix_ts_data *ts, · line 536
Quoted 6 lines
drivers/input/touchscreen/goodix.c +5
-0+"%s called without an irq_pin_access_method set\n", + __func__); +return -EINVAL ; +case irq_pin_access_gpio: +return gpiod_direction_input (ts->gpiod_int);Ditto.
Ditto.
Quoted 1 line
Looks fine otherwise.
Thank you for the review.
Regards,
Hans
Quoted 129 lines
Quoted 128 lines
drivers/input/touchscreen/goodix.c +7
-2+ } + +return -EINVAL ;/* Never reached */ +} +static int goodix_int_sync (struct goodix_ts_data *ts) {int error; - error =gpiod_direction_output (ts->gpiod_int,0 ); + error =goodix_irq_direction_output (ts,0 );if (error)return error;msleep (50 );/* T5: 50ms */ - error =gpiod_direction_input (ts->gpiod_int); + error =goodix_irq_direction_input (ts);if (error)
return error;drivers/input/touchscreen/goodix.c +1
-1@@ -536,7 +573,7 @@ static int goodix_reset(struct goodix_ts_data *ts)msleep (20 );/* T2: > 10ms */ /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */ - error =gpiod_direction_output (ts->gpiod_int, ts->client->addr == 0x14); + error =goodix_irq_direction_output (ts, ts->client->addr ==0x14 );if (error)
return error;drivers/input/touchscreen/goodix.c +4
-1@@ -617,6 +654,9 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts) ts->gpiod_rst = gpiod; +if (ts->gpiod_int && ts->gpiod_rst) + ts->irq_pin_access_method = irq_pin_access_gpio; +return 0 ; }@@ -889,7 +929,7 @@ static int goodix_ts_probe(struct i2c_client *client, if (error)return error; -if (ts->gpiod_int && ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_gpio) {/* reset the controller */ error =goodix_reset (ts);if (error) {drivers/input/touchscreen/goodix.c +1
-1@@ -912,7 +952,7 @@ static int goodix_ts_probe(struct i2c_client *client, ts->chip =goodix_get_chip_data (ts->id); -if (ts->gpiod_int && ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_gpio) {/* update device config */ ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL,"goodix_%d_cfg.bin", ts-
Quoted 1 line
id);
drivers/input/touchscreen/goodix.c +1
-1@@ -943,7 +983,7 @@ static int goodix_ts_remove(struct i2c_client *client) {struct goodix_ts_data *ts =i2c_get_clientdata (client); -if (ts->gpiod_int && ts->gpiod_rst) +if (ts->irq_pin_access_method == irq_pin_access_gpio)wait_for_completion (&ts->firmware_loading_complete);return 0;
drivers/input/touchscreen/goodix.c +1
-1@@ -956,7 +996,7 @@ static int __maybe_unused goodix_suspend(struct device *dev)int error;/* We need gpio pins to suspend/resume */ -if (!ts->gpiod_int || !ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_none) {disable_irq (client->irq);return 0 ;}drivers/input/touchscreen/goodix.c +1
-1@@ -967,7 +1007,7 @@ static int __maybe_unused goodix_suspend(struct device *dev)goodix_free_irq (ts );/* Output LOW on the INT pin for 5 ms */ - error =gpiod_direction_output (ts->gpiod_int,0 ); + error =goodix_irq_direction_output (ts,0 );if (error) {goodix_request_irq (ts);return error;
drivers/input/touchscreen/goodix.c +1
-1@@ -979,7 +1019,7 @@ static int __maybe_unused goodix_suspend(struct device *dev) GOODIX_CMD_SCREEN_OFF);if (error) {dev_err (&ts->client->dev,"Screen off command failed\n"); -gpiod_direction_input (ts->gpiod_int); +goodix_irq_direction_input (ts);goodix_request_irq (ts);return -EAGAIN; }drivers/input/touchscreen/goodix.c +1
-1@@ -999,7 +1039,7 @@ static int __maybe_unused goodix_resume(struct device *dev)struct goodix_ts_data *ts =i2c_get_clientdata (client);int error; -if (!ts->gpiod_int || !ts->gpiod_rst) { +if (ts->irq_pin_access_method == irq_pin_access_none) {enable_irq (client->irq);return 0 ;}drivers/input/touchscreen/goodix.c +1
-1@@ -1008,7 +1048,7 @@ static int __maybe_unused goodix_resume(structdevice *dev) * Exit sleep mode by outputting HIGH level to INT pin * for 2ms~5ms. */ - error =gpiod_direction_output (ts->gpiod_int,1 ); + error =goodix_irq_direction_output (ts,1 );if (error)return error;