diff --git a/src/board/system76/galp3-c/main.c b/src/board/system76/galp3-c/main.c index b2f12e5..3f56123 100644 --- a/src/board/system76/galp3-c/main.c +++ b/src/board/system76/galp3-c/main.c @@ -396,7 +396,7 @@ void touchpad_event(struct Ps2 * ps2) { if (kbc_second) { *(ps2->control) = 0x07; } else { - *(ps2->control) = 0x01; + ps2_reset(ps2); } uint8_t status = *(ps2->status); diff --git a/src/board/system76/galp3-c/ps2.c b/src/board/system76/galp3-c/ps2.c index 502568e..237e061 100644 --- a/src/board/system76/galp3-c/ps2.c +++ b/src/board/system76/galp3-c/ps2.c @@ -1,12 +1,7 @@ #include void ps2_init(void) { - *(PS2_1.control) = 0x11; - *(PS2_1.interrupt) = 0x04; - - *(PS2_2.control) = 0x41; - *(PS2_2.interrupt) = 0x04; - - *(PS2_3.control) = 0x41; - *(PS2_3.interrupt) = 0x04; + ps2_reset(&PS2_1); + ps2_reset(&PS2_2); + ps2_reset(&PS2_3); } diff --git a/src/ec/it8587e/include/ec/ps2.h b/src/ec/it8587e/include/ec/ps2.h index f253a92..cb75460 100644 --- a/src/ec/it8587e/include/ec/ps2.h +++ b/src/ec/it8587e/include/ec/ps2.h @@ -14,7 +14,8 @@ extern struct Ps2 __code PS2_1; extern struct Ps2 __code PS2_2; extern struct Ps2 __code PS2_3; -int ps2_read(struct Ps2 * ps2, uint8_t * data, int length); +void ps2_reset(struct Ps2 * ps2); +int ps2_read(struct Ps2 * ps2, uint8_t * data, int length); int ps2_write(struct Ps2 * ps2, uint8_t * data, int length); volatile uint8_t __xdata __at(0x1700) PSCTL1; diff --git a/src/ec/it8587e/ps2.c b/src/ec/it8587e/ps2.c index 5fce7cc..797d60b 100644 --- a/src/ec/it8587e/ps2.c +++ b/src/ec/it8587e/ps2.c @@ -22,6 +22,13 @@ struct Ps2 __code PS2_1 = PS2(1); struct Ps2 __code PS2_2 = PS2(2); struct Ps2 __code PS2_3 = PS2(3); +void ps2_reset(struct Ps2 * ps2) { + // Reset interface to defaults + *(ps2->control) = 1; + // Clear status + *(ps2->status) = *(ps2->status); +} + static int ps2_transaction(struct Ps2 * ps2, uint8_t * data, int length, bool read) { int i; for (i = 0; i < length; i++) { @@ -43,7 +50,7 @@ static int ps2_transaction(struct Ps2 * ps2, uint8_t * data, int length, bool re uint8_t status = *(ps2->status); // If an error happened, clear status and return the error if (status & PSSTS_ALL_ERR) { - *(ps2->status) = status; + ps2_reset(ps2); return -(int)status; } // If transaction is done, break @@ -53,11 +60,14 @@ static int ps2_transaction(struct Ps2 * ps2, uint8_t * data, int length, bool re } // If a timeout happened, return the error if (timeout == 0) { - return -1; + ps2_reset(ps2); + return -0x1000; } if (read) { data[i] = *(ps2->data); } + // Set interface to defaults + ps2_reset(ps2); } return i;