Skip to content

Commit a57604f

Browse files
author
Josh Tsai
committed
Fixed touchpad cannot work due to i2c bus error
Signed-off-by: Josh Tsai <josh_tsai@compal.com>
1 parent 885f8e0 commit a57604f

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

board/hx30/ps2mouse.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ static int inreport_retries;
326326
void read_touchpad_in_report(void)
327327
{
328328
int rv = EC_SUCCESS;
329+
int need_reset = 0;
329330
uint8_t data[128];
330331
int xfer_len = 0;
331332
int16_t x, y;
@@ -339,6 +340,8 @@ void read_touchpad_in_report(void)
339340

340341
/*dont trigger disable state during our own transactions*/
341342
gpio_disable_interrupt(GPIO_EC_I2C_3_SDA);
343+
/* need to disable SOC_TP_INT_L if we need to setup touchpad */
344+
gpio_disable_interrupt(GPIO_SOC_TP_INT_L);
342345
i2c_set_timeout(I2C_PORT_TOUCHPAD, 25*MSEC);
343346
i2c_lock(I2C_PORT_TOUCHPAD, 1);
344347
rv = i2c_xfer_unlocked(I2C_PORT_TOUCHPAD,
@@ -348,16 +351,19 @@ void read_touchpad_in_report(void)
348351
goto read_failed;
349352
xfer_len = (data[1]<<8) + data[0];
350353
if (xfer_len == 0) {
351-
/* touchpad has reset per i2c-hid-protocol 7.3 */
352-
CPRINTS("PS2M Touchpad Reset");
353-
goto read_failed;
354+
/**
355+
* touchpad has reset per i2c-hid-protocol 7.3
356+
* We need to complete the read protocol to make sure i2c state machine
357+
* is correct.
358+
*/
359+
CPRINTS("PS2M Touchpad need to reset");
360+
xfer_len = 6;
361+
need_reset = 1;
354362
}
355363
xfer_len = MIN(126, xfer_len-2);
356364
rv = i2c_xfer_unlocked(I2C_PORT_TOUCHPAD,
357365
TOUCHPAD_I2C_HID_EP | I2C_FLAG_ADDR16_LITTLE_ENDIAN,
358366
NULL, 0, data+2, xfer_len, I2C_XFER_STOP);
359-
if (rv != EC_SUCCESS)
360-
goto read_failed;
361367
read_failed:
362368
if (rv != EC_SUCCESS) {
363369
/* sometimes we get a read failed for unknown reason to try again in a while
@@ -384,6 +390,7 @@ void read_touchpad_in_report(void)
384390
}
385391
i2c_lock(I2C_PORT_TOUCHPAD, 0);
386392
gpio_enable_interrupt(GPIO_EC_I2C_3_SDA);
393+
gpio_enable_interrupt(GPIO_SOC_TP_INT_L);
387394

388395
if (mouse_state == PS2MSTATE_RESET) {
389396
return;
@@ -415,13 +422,13 @@ void read_touchpad_in_report(void)
415422
current_pos[1] = x;
416423
current_pos[2] = y;
417424
send_movement_packet();
418-
} else {
419-
if (rv == EC_SUCCESS) {
420-
CPRINTS("PS2M Unexpected Report ID %d reconfiguring", data[2]);
421-
setup_touchpad();
422-
}
423425
}
424426

427+
if (need_reset) {
428+
CPRINTS("PS2M Unexpected Report ID %d reconfiguring", data[2]);
429+
setup_touchpad();
430+
need_reset = 0;
431+
}
425432
}
426433
/*
427434
* Looking at timing it takes the SOC about 2ms to grab a tp packet from start of

0 commit comments

Comments
 (0)