@@ -192,7 +192,8 @@ static int elants_i2c_read(struct i2c_client *client, void *data, size_t size)
192192
193193static int elants_i2c_execute_command (struct i2c_client * client ,
194194 const u8 * cmd , size_t cmd_size ,
195- u8 * resp , size_t resp_size )
195+ u8 * resp , size_t resp_size ,
196+ int retries , const char * cmd_name )
196197{
197198 struct i2c_msg msgs [2 ];
198199 int ret ;
@@ -212,30 +213,55 @@ static int elants_i2c_execute_command(struct i2c_client *client,
212213 break ;
213214
214215 default :
215- dev_err (& client -> dev , "%s : invalid command %*ph\n" ,
216- __func__ , (int )cmd_size , cmd );
216+ dev_err (& client -> dev , "(%s) : invalid command: %*ph\n" ,
217+ cmd_name , (int )cmd_size , cmd );
217218 return - EINVAL ;
218219 }
219220
220- msgs [0 ].addr = client -> addr ;
221- msgs [0 ].flags = client -> flags & I2C_M_TEN ;
222- msgs [0 ].len = cmd_size ;
223- msgs [0 ].buf = (u8 * )cmd ;
221+ for (;;) {
222+ msgs [0 ].addr = client -> addr ;
223+ msgs [0 ].flags = client -> flags & I2C_M_TEN ;
224+ msgs [0 ].len = cmd_size ;
225+ msgs [0 ].buf = (u8 * )cmd ;
226+
227+ msgs [1 ].addr = client -> addr ;
228+ msgs [1 ].flags = (client -> flags & I2C_M_TEN ) | I2C_M_RD ;
229+ msgs [1 ].flags |= I2C_M_RD ;
230+ msgs [1 ].len = resp_size ;
231+ msgs [1 ].buf = resp ;
232+
233+ ret = i2c_transfer (client -> adapter , msgs , ARRAY_SIZE (msgs ));
234+ if (ret < 0 ) {
235+ if (-- retries > 0 ) {
236+ dev_dbg (& client -> dev ,
237+ "(%s) I2C transfer failed: %pe (retrying)\n" ,
238+ cmd_name , ERR_PTR (ret ));
239+ continue ;
240+ }
224241
225- msgs [ 1 ]. addr = client -> addr ;
226- msgs [ 1 ]. flags = client -> flags & I2C_M_TEN ;
227- msgs [ 1 ]. flags |= I2C_M_RD ;
228- msgs [ 1 ]. len = resp_size ;
229- msgs [ 1 ]. buf = resp ;
242+ dev_err ( & client -> dev ,
243+ "(%s) I2C transfer failed: %pe\n" ,
244+ cmd_name , ERR_PTR ( ret )) ;
245+ return ret ;
246+ }
230247
231- ret = i2c_transfer (client -> adapter , msgs , ARRAY_SIZE (msgs ));
232- if (ret < 0 )
233- return ret ;
248+ if (ret != ARRAY_SIZE (msgs ) ||
249+ resp [FW_HDR_TYPE ] != expected_response ) {
250+ if (-- retries > 0 ) {
251+ dev_dbg (& client -> dev ,
252+ "(%s) unexpected response: %*ph (retrying)\n" ,
253+ cmd_name , ret , resp );
254+ continue ;
255+ }
234256
235- if (ret != ARRAY_SIZE (msgs ) || resp [FW_HDR_TYPE ] != expected_response )
236- return - EIO ;
257+ dev_err (& client -> dev ,
258+ "(%s) unexpected response: %*ph\n" ,
259+ cmd_name , ret , resp );
260+ return - EIO ;
261+ }
237262
238- return 0 ;
263+ return 0 ;
264+ }
239265}
240266
241267static int elants_i2c_calibrate (struct elants_data * ts )
@@ -308,27 +334,21 @@ static u16 elants_i2c_parse_version(u8 *buf)
308334static int elants_i2c_query_hw_version (struct elants_data * ts )
309335{
310336 struct i2c_client * client = ts -> client ;
311- int error , retry_cnt ;
337+ int retry_cnt = MAX_RETRIES ;
312338 const u8 cmd [] = { CMD_HEADER_READ , E_ELAN_INFO_FW_ID , 0x00 , 0x01 };
313339 u8 resp [HEADER_SIZE ];
340+ int error ;
314341
315- for (retry_cnt = 0 ; retry_cnt < MAX_RETRIES ; retry_cnt ++ ) {
342+ while (retry_cnt -- ) {
316343 error = elants_i2c_execute_command (client , cmd , sizeof (cmd ),
317- resp , sizeof (resp ));
318- if (!error ) {
319- ts -> hw_version = elants_i2c_parse_version (resp );
320- if (ts -> hw_version != 0xffff )
321- return 0 ;
322- }
323-
324- dev_dbg (& client -> dev , "read fw id error=%d, buf=%*phC\n" ,
325- error , (int )sizeof (resp ), resp );
326- }
344+ resp , sizeof (resp ), 1 ,
345+ "read fw id" );
346+ if (error )
347+ return error ;
327348
328- if (error ) {
329- dev_err (& client -> dev ,
330- "Failed to read fw id: %d\n" , error );
331- return error ;
349+ ts -> hw_version = elants_i2c_parse_version (resp );
350+ if (ts -> hw_version != 0xffff )
351+ return 0 ;
332352 }
333353
334354 dev_err (& client -> dev , "Invalid fw id: %#04x\n" , ts -> hw_version );
@@ -339,57 +359,52 @@ static int elants_i2c_query_hw_version(struct elants_data *ts)
339359static int elants_i2c_query_fw_version (struct elants_data * ts )
340360{
341361 struct i2c_client * client = ts -> client ;
342- int error , retry_cnt ;
362+ int retry_cnt = MAX_RETRIES ;
343363 const u8 cmd [] = { CMD_HEADER_READ , E_ELAN_INFO_FW_VER , 0x00 , 0x01 };
344364 u8 resp [HEADER_SIZE ];
365+ int error ;
345366
346- for (retry_cnt = 0 ; retry_cnt < MAX_RETRIES ; retry_cnt ++ ) {
367+ while (retry_cnt -- ) {
347368 error = elants_i2c_execute_command (client , cmd , sizeof (cmd ),
348- resp , sizeof (resp ));
349- if (!error ) {
350- ts -> fw_version = elants_i2c_parse_version (resp );
351- if (ts -> fw_version != 0x0000 &&
352- ts -> fw_version != 0xffff )
353- return 0 ;
354- }
369+ resp , sizeof (resp ), 1 ,
370+ "read fw version" );
371+ if (error )
372+ return error ;
373+
374+ ts -> fw_version = elants_i2c_parse_version (resp );
375+ if (ts -> fw_version != 0x0000 && ts -> fw_version != 0xffff )
376+ return 0 ;
355377
356- dev_dbg (& client -> dev , "read fw version error=%d, buf= %*phC\n" ,
357- error , (int )sizeof (resp ), resp );
378+ dev_dbg (& client -> dev , "( read fw version) resp %*phC\n" ,
379+ (int )sizeof (resp ), resp );
358380 }
359381
360- dev_err (& client -> dev ,
361- "Failed to read fw version or fw version is invalid\n" );
382+ dev_err (& client -> dev , "Invalid fw ver: %#04x\n" , ts -> fw_version );
362383
363384 return - EINVAL ;
364385}
365386
366387static int elants_i2c_query_test_version (struct elants_data * ts )
367388{
368389 struct i2c_client * client = ts -> client ;
369- int error , retry_cnt ;
390+ int error ;
370391 u16 version ;
371392 const u8 cmd [] = { CMD_HEADER_READ , E_ELAN_INFO_TEST_VER , 0x00 , 0x01 };
372393 u8 resp [HEADER_SIZE ];
373394
374- for (retry_cnt = 0 ; retry_cnt < MAX_RETRIES ; retry_cnt ++ ) {
375- error = elants_i2c_execute_command (client , cmd , sizeof (cmd ),
376- resp , sizeof (resp ));
377- if (!error ) {
378- version = elants_i2c_parse_version (resp );
379- ts -> test_version = version >> 8 ;
380- ts -> solution_version = version & 0xff ;
381-
382- return 0 ;
383- }
384-
385- dev_dbg (& client -> dev ,
386- "read test version error rc=%d, buf=%*phC\n" ,
387- error , (int )sizeof (resp ), resp );
395+ error = elants_i2c_execute_command (client , cmd , sizeof (cmd ),
396+ resp , sizeof (resp ), MAX_RETRIES ,
397+ "read test version" );
398+ if (error ) {
399+ dev_err (& client -> dev , "Failed to read test version\n" );
400+ return error ;
388401 }
389402
390- dev_err (& client -> dev , "Failed to read test version\n" );
403+ version = elants_i2c_parse_version (resp );
404+ ts -> test_version = version >> 8 ;
405+ ts -> solution_version = version & 0xff ;
391406
392- return - EINVAL ;
407+ return 0 ;
393408}
394409
395410static int elants_i2c_query_bc_version (struct elants_data * ts )
@@ -401,13 +416,10 @@ static int elants_i2c_query_bc_version(struct elants_data *ts)
401416 int error ;
402417
403418 error = elants_i2c_execute_command (client , cmd , sizeof (cmd ),
404- resp , sizeof (resp ));
405- if (error ) {
406- dev_err (& client -> dev ,
407- "read BC version error=%d, buf=%*phC\n" ,
408- error , (int )sizeof (resp ), resp );
419+ resp , sizeof (resp ), 1 ,
420+ "read BC version" );
421+ if (error )
409422 return error ;
410- }
411423
412424 version = elants_i2c_parse_version (resp );
413425 ts -> bc_version = version >> 8 ;
@@ -439,49 +451,40 @@ static int elants_i2c_query_ts_info(struct elants_data *ts)
439451 error = elants_i2c_execute_command (client ,
440452 get_resolution_cmd ,
441453 sizeof (get_resolution_cmd ),
442- resp , sizeof (resp ));
443- if (error ) {
444- dev_err (& client -> dev , "get resolution command failed: %d\n" ,
445- error );
454+ resp , sizeof (resp ), 1 ,
455+ "get resolution" );
456+ if (error )
446457 return error ;
447- }
448458
449459 rows = resp [2 ] + resp [6 ] + resp [10 ];
450460 cols = resp [3 ] + resp [7 ] + resp [11 ];
451461
452462 /* Process mm_to_pixel information */
453463 error = elants_i2c_execute_command (client ,
454464 get_osr_cmd , sizeof (get_osr_cmd ),
455- resp , sizeof (resp ));
456- if (error ) {
457- dev_err (& client -> dev , "get osr command failed: %d\n" ,
458- error );
465+ resp , sizeof (resp ), 1 , "get osr" );
466+ if (error )
459467 return error ;
460- }
461468
462469 osr = resp [3 ];
463470
464471 error = elants_i2c_execute_command (client ,
465472 get_physical_scan_cmd ,
466473 sizeof (get_physical_scan_cmd ),
467- resp , sizeof (resp ));
468- if (error ) {
469- dev_err (& client -> dev , "get physical scan command failed: %d\n" ,
470- error );
474+ resp , sizeof (resp ), 1 ,
475+ "get physical scan" );
476+ if (error )
471477 return error ;
472- }
473478
474479 phy_x = get_unaligned_be16 (& resp [2 ]);
475480
476481 error = elants_i2c_execute_command (client ,
477482 get_physical_drive_cmd ,
478483 sizeof (get_physical_drive_cmd ),
479- resp , sizeof (resp ));
480- if (error ) {
481- dev_err (& client -> dev , "get physical drive command failed: %d\n" ,
482- error );
484+ resp , sizeof (resp ), 1 ,
485+ "get physical drive" );
486+ if (error )
483487 return error ;
484- }
485488
486489 phy_y = get_unaligned_be16 (& resp [2 ]);
487490
@@ -636,11 +639,10 @@ static int elants_i2c_validate_remark_id(struct elants_data *ts,
636639
637640 /* Compare TS Remark ID and FW Remark ID */
638641 error = elants_i2c_execute_command (client , cmd , sizeof (cmd ),
639- resp , sizeof (resp ));
640- if ( error ) {
641- dev_err ( & client -> dev , "failed to query Remark ID: %d\n" , error );
642+ resp , sizeof (resp ),
643+ 1 , "read Remark ID" );
644+ if ( error )
642645 return error ;
643- }
644646
645647 ts_remark_id = get_unaligned_be16 (& resp [3 ]);
646648
@@ -1075,16 +1077,12 @@ static ssize_t show_calibration_count(struct device *dev,
10751077 int error ;
10761078
10771079 error = elants_i2c_execute_command (client , cmd , sizeof (cmd ),
1078- resp , sizeof (resp ));
1079- if (error ) {
1080- dev_err (& client -> dev ,
1081- "read ReK status error=%d, buf=%*phC\n" ,
1082- error , (int )sizeof (resp ), resp );
1080+ resp , sizeof (resp ), 1 ,
1081+ "read ReK status" );
1082+ if (error )
10831083 return sprintf (buf , "%d\n" , error );
1084- }
10851084
10861085 rek_count = get_unaligned_be16 (& resp [2 ]);
1087-
10881086 return sprintf (buf , "0x%04x\n" , rek_count );
10891087}
10901088
0 commit comments