Skip to content

Commit de956ca

Browse files
jwrdegoededtor
authored andcommitted
Input: goodix - save a copy of the config from goodix_read_config()
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. BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1786317 BugLink: nexus511/gpd-ubuntu-packages#10 BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=199207 Reviewed-by: Bastien Nocera <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent aebfc52 commit de956ca

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

drivers/input/touchscreen/goodix.c

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct goodix_chip_data {
7272
u16 config_addr;
7373
int config_len;
7474
int (*check_config)(struct goodix_ts_data *, const struct firmware *);
75+
void (*calc_config_checksum)(struct goodix_ts_data *ts);
7576
};
7677

7778
struct goodix_ts_data {
@@ -96,35 +97,42 @@ struct goodix_ts_data {
9697
unsigned long irq_flags;
9798
enum goodix_irq_pin_access_method irq_pin_access_method;
9899
unsigned int contact_size;
100+
u8 config[GOODIX_CONFIG_MAX_LENGTH];
99101
};
100102

101103
static int goodix_check_cfg_8(struct goodix_ts_data *ts,
102104
const struct firmware *cfg);
103105
static int goodix_check_cfg_16(struct goodix_ts_data *ts,
104106
const struct firmware *cfg);
107+
static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts);
108+
static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts);
105109

106110
static const struct goodix_chip_data gt1x_chip_data = {
107111
.config_addr = GOODIX_GT1X_REG_CONFIG_DATA,
108112
.config_len = GOODIX_CONFIG_MAX_LENGTH,
109113
.check_config = goodix_check_cfg_16,
114+
.calc_config_checksum = goodix_calc_cfg_checksum_16,
110115
};
111116

112117
static const struct goodix_chip_data gt911_chip_data = {
113118
.config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
114119
.config_len = GOODIX_CONFIG_911_LENGTH,
115120
.check_config = goodix_check_cfg_8,
121+
.calc_config_checksum = goodix_calc_cfg_checksum_8,
116122
};
117123

118124
static const struct goodix_chip_data gt967_chip_data = {
119125
.config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
120126
.config_len = GOODIX_CONFIG_967_LENGTH,
121127
.check_config = goodix_check_cfg_8,
128+
.calc_config_checksum = goodix_calc_cfg_checksum_8,
122129
};
123130

124131
static const struct goodix_chip_data gt9x_chip_data = {
125132
.config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
126133
.config_len = GOODIX_CONFIG_MAX_LENGTH,
127134
.check_config = goodix_check_cfg_8,
135+
.calc_config_checksum = goodix_calc_cfg_checksum_8,
128136
};
129137

130138
static const unsigned long goodix_irq_flags[] = {
@@ -458,6 +466,19 @@ static int goodix_check_cfg_8(struct goodix_ts_data *ts,
458466
return 0;
459467
}
460468

469+
static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts)
470+
{
471+
int i, raw_cfg_len = ts->chip->config_len - 2;
472+
u8 check_sum = 0;
473+
474+
for (i = 0; i < raw_cfg_len; i++)
475+
check_sum += ts->config[i];
476+
check_sum = (~check_sum) + 1;
477+
478+
ts->config[raw_cfg_len] = check_sum;
479+
ts->config[raw_cfg_len + 1] = 1; /* Set "config_fresh" bit */
480+
}
481+
461482
static int goodix_check_cfg_16(struct goodix_ts_data *ts,
462483
const struct firmware *cfg)
463484
{
@@ -482,6 +503,19 @@ static int goodix_check_cfg_16(struct goodix_ts_data *ts,
482503
return 0;
483504
}
484505

506+
static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts)
507+
{
508+
int i, raw_cfg_len = ts->chip->config_len - 3;
509+
u16 check_sum = 0;
510+
511+
for (i = 0; i < raw_cfg_len; i += 2)
512+
check_sum += get_unaligned_be16(&ts->config[i]);
513+
check_sum = (~check_sum) + 1;
514+
515+
put_unaligned_be16(check_sum, &ts->config[raw_cfg_len]);
516+
ts->config[raw_cfg_len + 2] = 1; /* Set "config_fresh" bit */
517+
}
518+
485519
/**
486520
* goodix_check_cfg - Checks if config fw is valid
487521
*
@@ -859,12 +893,11 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)
859893
*/
860894
static void goodix_read_config(struct goodix_ts_data *ts)
861895
{
862-
u8 config[GOODIX_CONFIG_MAX_LENGTH];
863896
int x_max, y_max;
864897
int error;
865898

866899
error = goodix_i2c_read(ts->client, ts->chip->config_addr,
867-
config, ts->chip->config_len);
900+
ts->config, ts->chip->config_len);
868901
if (error) {
869902
dev_warn(&ts->client->dev, "Error reading config: %d\n",
870903
error);
@@ -873,15 +906,17 @@ static void goodix_read_config(struct goodix_ts_data *ts)
873906
return;
874907
}
875908

876-
ts->int_trigger_type = config[TRIGGER_LOC] & 0x03;
877-
ts->max_touch_num = config[MAX_CONTACTS_LOC] & 0x0f;
909+
ts->int_trigger_type = ts->config[TRIGGER_LOC] & 0x03;
910+
ts->max_touch_num = ts->config[MAX_CONTACTS_LOC] & 0x0f;
878911

879-
x_max = get_unaligned_le16(&config[RESOLUTION_LOC]);
880-
y_max = get_unaligned_le16(&config[RESOLUTION_LOC + 2]);
912+
x_max = get_unaligned_le16(&ts->config[RESOLUTION_LOC]);
913+
y_max = get_unaligned_le16(&ts->config[RESOLUTION_LOC + 2]);
881914
if (x_max && y_max) {
882915
input_abs_set_max(ts->input_dev, ABS_MT_POSITION_X, x_max - 1);
883916
input_abs_set_max(ts->input_dev, ABS_MT_POSITION_Y, y_max - 1);
884917
}
918+
919+
ts->chip->calc_config_checksum(ts);
885920
}
886921

887922
/**

0 commit comments

Comments
 (0)