@@ -46,7 +46,7 @@ void send_data_byte(uint8_t data) {
46
46
int timeout = 0 ;
47
47
48
48
/* sometimes the host will get behind */
49
- while (aux_buffer_available () < 1 && timeout ++ < 25 )
49
+ while (aux_buffer_available () < 1 && timeout ++ < AUX_BUFFER_FULL_RETRIES )
50
50
usleep (10 * MSEC );
51
51
send_aux_data_to_host_interrupt (data );
52
52
}
@@ -59,12 +59,13 @@ void send_movement_packet(void)
59
59
if (five_button_mode )
60
60
max = 4 ;
61
61
/* sometimes the host will get behind */
62
- while (aux_buffer_available () < max && timeout ++ < 25 &&
62
+ while (aux_buffer_available () < max && timeout ++ < AUX_BUFFER_FULL_RETRIES &&
63
63
(* task_get_event_bitmap (emumouse_task_id ) & PS2MOUSE_EVT_AUX_DATA ) == 0 ) {
64
64
usleep (10 * MSEC );
65
65
}
66
66
67
- if (timeout == 25 || (* task_get_event_bitmap (emumouse_task_id ) & PS2MOUSE_EVT_AUX_DATA )) {
67
+ if (timeout == AUX_BUFFER_FULL_RETRIES ||
68
+ (* task_get_event_bitmap (emumouse_task_id ) & PS2MOUSE_EVT_AUX_DATA )) {
68
69
CPRINTS ("PS2M Dropping" );
69
70
/*drop mouse packet - host is too far behind */
70
71
return ;
@@ -332,8 +333,14 @@ void read_touchpad_in_report(void)
332
333
333
334
/* Make sure report id is set to an invalid value */
334
335
data [2 ] = 0 ;
336
+
337
+ if (power_get_state () == POWER_S5 ) {
338
+ return ;
339
+ }
340
+
335
341
/*dont trigger disable state during our own transactions*/
336
342
gpio_disable_interrupt (GPIO_EC_I2C_3_SDA );
343
+ i2c_set_timeout (I2C_PORT_TOUCHPAD , 25 * MSEC );
337
344
i2c_lock (I2C_PORT_TOUCHPAD , 1 );
338
345
rv = i2c_xfer_unlocked (I2C_PORT_TOUCHPAD ,
339
346
TOUCHPAD_I2C_HID_EP | I2C_FLAG_ADDR16_LITTLE_ENDIAN ,
@@ -362,11 +369,13 @@ void read_touchpad_in_report(void)
362
369
/* try again some other time later if the TP keeps interrupting us */
363
370
detected_host_packet = true;
364
371
inreport_retries = 0 ;
372
+ usleep (10 * MSEC );
373
+ /*The EC SMB controller sometimes gets in a bad state, so try to recover */
365
374
MCHP_I2C_CTRL (MCHP_I2C_CTRL4 ) = BIT (7 ) |
366
375
BIT (6 ) |
367
376
BIT (3 ) |
368
377
BIT (0 );
369
- CPRINTS ("PS2M Too many retries" );
378
+ CPRINTS ("PS2M %d Too many retries" , rv );
370
379
} else {
371
380
hook_call_deferred (& retry_tp_read_evt_deferred_data , 25 * MSEC );
372
381
}
@@ -413,6 +422,7 @@ void read_touchpad_in_report(void)
413
422
setup_touchpad ();
414
423
}
415
424
}
425
+
416
426
}
417
427
/*
418
428
* Looking at timing it takes the SOC about 2ms to grab a tp packet from start of
@@ -423,6 +433,7 @@ void mouse_interrupt_handler_task(void *p)
423
433
{
424
434
int power_state = 0 ;
425
435
int evt ;
436
+ int i ;
426
437
427
438
emumouse_task_id = task_get_current ();
428
439
while (1 ) {
@@ -445,14 +456,18 @@ void mouse_interrupt_handler_task(void *p)
445
456
if (evt & PS2MOUSE_EVT_AUX_DATA ) {
446
457
process_request (aux_data );
447
458
} else if (evt & PS2MOUSE_EVT_INTERRUPT ) {
448
- usleep (4 * MSEC );
449
459
/* at the expensive of a slight additional latency
450
460
* check to see if the soc has grabbed this out from under us
451
461
*/
452
- if (gpio_get_level (GPIO_SOC_TP_INT_L ) == 1 ) {
453
- CPRINTS ("PS2M Detected host packet during interrupt handling" );
454
- detected_host_packet = true;
455
- } else {
462
+ for (i = 0 ; i < 4 ; i ++ ) {
463
+ usleep (MSEC );
464
+ if (gpio_get_level (GPIO_SOC_TP_INT_L ) == 1 ) {
465
+ CPRINTS ("PS2M Detected host packet during interrupt handling" );
466
+ detected_host_packet = true;
467
+ break ;
468
+ }
469
+ }
470
+ if (detected_host_packet != true) {
456
471
read_touchpad_in_report ();
457
472
}
458
473
}
@@ -479,7 +494,7 @@ void mouse_interrupt_handler_task(void *p)
479
494
if ((power_state == POWER_S3S0 ) && gpio_get_level (GPIO_SOC_TP_INT_L ) == 0 ) {
480
495
read_touchpad_in_report ();
481
496
}
482
- if (power_state == POWER_S0S3 ) {
497
+ if (power_state == POWER_S0S3 || power_state == POWER_S5 ) {
483
498
/* Power Down */
484
499
gpio_disable_interrupt (GPIO_SOC_TP_INT_L );
485
500
gpio_disable_interrupt (GPIO_EC_I2C_3_SDA );
0 commit comments