Skip to content

Commit 1a67448

Browse files
jwrdegoededtor
authored andcommitted
Input: goodix - make goodix_send_cfg() take a raw buffer as argument
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. 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 686e8a2 commit 1a67448

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

drivers/input/touchscreen/goodix.c

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum goodix_irq_pin_access_method {
7373
struct goodix_chip_data {
7474
u16 config_addr;
7575
int config_len;
76-
int (*check_config)(struct goodix_ts_data *, const struct firmware *);
76+
int (*check_config)(struct goodix_ts_data *ts, const u8 *cfg, int len);
7777
void (*calc_config_checksum)(struct goodix_ts_data *ts);
7878
};
7979

@@ -103,9 +103,9 @@ struct goodix_ts_data {
103103
};
104104

105105
static int goodix_check_cfg_8(struct goodix_ts_data *ts,
106-
const struct firmware *cfg);
106+
const u8 *cfg, int len);
107107
static int goodix_check_cfg_16(struct goodix_ts_data *ts,
108-
const struct firmware *cfg);
108+
const u8 *cfg, int len);
109109
static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts);
110110
static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts);
111111

@@ -444,22 +444,21 @@ static int goodix_request_irq(struct goodix_ts_data *ts)
444444
ts->irq_flags, ts->client->name, ts);
445445
}
446446

447-
static int goodix_check_cfg_8(struct goodix_ts_data *ts,
448-
const struct firmware *cfg)
447+
static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 *cfg, int len)
449448
{
450-
int i, raw_cfg_len = cfg->size - 2;
449+
int i, raw_cfg_len = len - 2;
451450
u8 check_sum = 0;
452451

453452
for (i = 0; i < raw_cfg_len; i++)
454-
check_sum += cfg->data[i];
453+
check_sum += cfg[i];
455454
check_sum = (~check_sum) + 1;
456-
if (check_sum != cfg->data[raw_cfg_len]) {
455+
if (check_sum != cfg[raw_cfg_len]) {
457456
dev_err(&ts->client->dev,
458457
"The checksum of the config fw is not correct");
459458
return -EINVAL;
460459
}
461460

462-
if (cfg->data[raw_cfg_len + 1] != 1) {
461+
if (cfg[raw_cfg_len + 1] != 1) {
463462
dev_err(&ts->client->dev,
464463
"Config fw must have Config_Fresh register set");
465464
return -EINVAL;
@@ -481,22 +480,22 @@ static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts)
481480
ts->config[raw_cfg_len + 1] = 1; /* Set "config_fresh" bit */
482481
}
483482

484-
static int goodix_check_cfg_16(struct goodix_ts_data *ts,
485-
const struct firmware *cfg)
483+
static int goodix_check_cfg_16(struct goodix_ts_data *ts, const u8 *cfg,
484+
int len)
486485
{
487-
int i, raw_cfg_len = cfg->size - 3;
486+
int i, raw_cfg_len = len - 3;
488487
u16 check_sum = 0;
489488

490489
for (i = 0; i < raw_cfg_len; i += 2)
491-
check_sum += get_unaligned_be16(&cfg->data[i]);
490+
check_sum += get_unaligned_be16(&cfg[i]);
492491
check_sum = (~check_sum) + 1;
493-
if (check_sum != get_unaligned_be16(&cfg->data[raw_cfg_len])) {
492+
if (check_sum != get_unaligned_be16(&cfg[raw_cfg_len])) {
494493
dev_err(&ts->client->dev,
495494
"The checksum of the config fw is not correct");
496495
return -EINVAL;
497496
}
498497

499-
if (cfg->data[raw_cfg_len + 2] != 1) {
498+
if (cfg[raw_cfg_len + 2] != 1) {
500499
dev_err(&ts->client->dev,
501500
"Config fw must have Config_Fresh register set");
502501
return -EINVAL;
@@ -524,17 +523,16 @@ static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts)
524523
* @ts: goodix_ts_data pointer
525524
* @cfg: firmware config data
526525
*/
527-
static int goodix_check_cfg(struct goodix_ts_data *ts,
528-
const struct firmware *cfg)
526+
static int goodix_check_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len)
529527
{
530-
if (cfg->size < GOODIX_CONFIG_MIN_LENGTH ||
531-
cfg->size > GOODIX_CONFIG_MAX_LENGTH) {
528+
if (len < GOODIX_CONFIG_MIN_LENGTH ||
529+
len > GOODIX_CONFIG_MAX_LENGTH) {
532530
dev_err(&ts->client->dev,
533531
"The length of the config fw is not correct");
534532
return -EINVAL;
535533
}
536534

537-
return ts->chip->check_config(ts, cfg);
535+
return ts->chip->check_config(ts, cfg, len);
538536
}
539537

540538
/**
@@ -543,17 +541,15 @@ static int goodix_check_cfg(struct goodix_ts_data *ts,
543541
* @ts: goodix_ts_data pointer
544542
* @cfg: config firmware to write to device
545543
*/
546-
static int goodix_send_cfg(struct goodix_ts_data *ts,
547-
const struct firmware *cfg)
544+
static int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len)
548545
{
549546
int error;
550547

551-
error = goodix_check_cfg(ts, cfg);
548+
error = goodix_check_cfg(ts, cfg, len);
552549
if (error)
553550
return error;
554551

555-
error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg->data,
556-
cfg->size);
552+
error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg, len);
557553
if (error) {
558554
dev_err(&ts->client->dev, "Failed to write config data: %d",
559555
error);
@@ -1094,7 +1090,7 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx)
10941090

10951091
if (cfg) {
10961092
/* send device configuration to the firmware */
1097-
error = goodix_send_cfg(ts, cfg);
1093+
error = goodix_send_cfg(ts, cfg->data, cfg->size);
10981094
if (error)
10991095
goto err_release_cfg;
11001096
}

0 commit comments

Comments
 (0)