@@ -72,6 +72,7 @@ struct goodix_chip_data {
72
72
u16 config_addr ;
73
73
int config_len ;
74
74
int (* check_config )(struct goodix_ts_data * , const struct firmware * );
75
+ void (* calc_config_checksum )(struct goodix_ts_data * ts );
75
76
};
76
77
77
78
struct goodix_ts_data {
@@ -96,35 +97,42 @@ struct goodix_ts_data {
96
97
unsigned long irq_flags ;
97
98
enum goodix_irq_pin_access_method irq_pin_access_method ;
98
99
unsigned int contact_size ;
100
+ u8 config [GOODIX_CONFIG_MAX_LENGTH ];
99
101
};
100
102
101
103
static int goodix_check_cfg_8 (struct goodix_ts_data * ts ,
102
104
const struct firmware * cfg );
103
105
static int goodix_check_cfg_16 (struct goodix_ts_data * ts ,
104
106
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 );
105
109
106
110
static const struct goodix_chip_data gt1x_chip_data = {
107
111
.config_addr = GOODIX_GT1X_REG_CONFIG_DATA ,
108
112
.config_len = GOODIX_CONFIG_MAX_LENGTH ,
109
113
.check_config = goodix_check_cfg_16 ,
114
+ .calc_config_checksum = goodix_calc_cfg_checksum_16 ,
110
115
};
111
116
112
117
static const struct goodix_chip_data gt911_chip_data = {
113
118
.config_addr = GOODIX_GT9X_REG_CONFIG_DATA ,
114
119
.config_len = GOODIX_CONFIG_911_LENGTH ,
115
120
.check_config = goodix_check_cfg_8 ,
121
+ .calc_config_checksum = goodix_calc_cfg_checksum_8 ,
116
122
};
117
123
118
124
static const struct goodix_chip_data gt967_chip_data = {
119
125
.config_addr = GOODIX_GT9X_REG_CONFIG_DATA ,
120
126
.config_len = GOODIX_CONFIG_967_LENGTH ,
121
127
.check_config = goodix_check_cfg_8 ,
128
+ .calc_config_checksum = goodix_calc_cfg_checksum_8 ,
122
129
};
123
130
124
131
static const struct goodix_chip_data gt9x_chip_data = {
125
132
.config_addr = GOODIX_GT9X_REG_CONFIG_DATA ,
126
133
.config_len = GOODIX_CONFIG_MAX_LENGTH ,
127
134
.check_config = goodix_check_cfg_8 ,
135
+ .calc_config_checksum = goodix_calc_cfg_checksum_8 ,
128
136
};
129
137
130
138
static const unsigned long goodix_irq_flags [] = {
@@ -458,6 +466,19 @@ static int goodix_check_cfg_8(struct goodix_ts_data *ts,
458
466
return 0 ;
459
467
}
460
468
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
+
461
482
static int goodix_check_cfg_16 (struct goodix_ts_data * ts ,
462
483
const struct firmware * cfg )
463
484
{
@@ -482,6 +503,19 @@ static int goodix_check_cfg_16(struct goodix_ts_data *ts,
482
503
return 0 ;
483
504
}
484
505
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
+
485
519
/**
486
520
* goodix_check_cfg - Checks if config fw is valid
487
521
*
@@ -859,12 +893,11 @@ static int goodix_get_gpio_config(struct goodix_ts_data *ts)
859
893
*/
860
894
static void goodix_read_config (struct goodix_ts_data * ts )
861
895
{
862
- u8 config [GOODIX_CONFIG_MAX_LENGTH ];
863
896
int x_max , y_max ;
864
897
int error ;
865
898
866
899
error = goodix_i2c_read (ts -> client , ts -> chip -> config_addr ,
867
- config , ts -> chip -> config_len );
900
+ ts -> config , ts -> chip -> config_len );
868
901
if (error ) {
869
902
dev_warn (& ts -> client -> dev , "Error reading config: %d\n" ,
870
903
error );
@@ -873,15 +906,17 @@ static void goodix_read_config(struct goodix_ts_data *ts)
873
906
return ;
874
907
}
875
908
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 ;
878
911
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 ]);
881
914
if (x_max && y_max ) {
882
915
input_abs_set_max (ts -> input_dev , ABS_MT_POSITION_X , x_max - 1 );
883
916
input_abs_set_max (ts -> input_dev , ABS_MT_POSITION_Y , y_max - 1 );
884
917
}
918
+
919
+ ts -> chip -> calc_config_checksum (ts );
885
920
}
886
921
887
922
/**
0 commit comments