static int __ps2_command(int aux, int command, u8 *param) { int ret2; int receive = (command >> 8) & 0xf; int send = (command >> 12) & 0xf; // Disable interrupts and keyboard/mouse. u8 ps2ctr = GET_EBDA(ps2ctr); u8 newctr = ((ps2ctr | I8042_CTR_AUXDIS | I8042_CTR_KBDDIS) & ~(I8042_CTR_KBDINT|I8042_CTR_AUXINT)); dprintf(6, "i8042 ctr old=%x new=%x\n", ps2ctr, newctr); int ret = i8042_command(I8042_CMD_CTL_WCTR, &newctr); if (ret) return ret; // Flush any interrupts already pending. yield(); // Enable port command is being sent to. if (aux) newctr &= ~I8042_CTR_AUXDIS; else newctr &= ~I8042_CTR_KBDDIS; ret = i8042_command(I8042_CMD_CTL_WCTR, &newctr); if (ret) goto fail; if (command == ATKBD_CMD_RESET_BAT) { // Reset is special wrt timeouts and bytes received. // Send command. ret = ps2_sendbyte(aux, command, 1000); if (ret) goto fail; // Receive parameters. ret = ps2_recvbyte(aux, 0, 4000); if (ret < 0) goto fail; param[0] = ret; ret = ps2_recvbyte(aux, 0, 100); if (ret < 0) // Some devices only respond with one byte on reset. ret = 0; param[1] = ret; } else if (command == ATKBD_CMD_GETID) { // Getid is special wrt bytes received. // Send command. ret = ps2_sendbyte(aux, command, 200); if (ret) goto fail; // Receive parameters. ret = ps2_recvbyte(aux, 0, 500); if (ret < 0) goto fail; param[0] = ret; if (ret == 0xab || ret == 0xac || ret == 0x2b || ret == 0x5d || ret == 0x60 || ret == 0x47) { // These ids (keyboards) return two bytes. ret = ps2_recvbyte(aux, 0, 500); if (ret < 0) goto fail; param[1] = ret; } else { param[1] = 0; } } else { // Send command. ret = ps2_sendbyte(aux, command, 200); if (ret) goto fail; // Send parameters (if any). int i; for (i = 0; i < send; i++) { ret = ps2_sendbyte(aux, param[i], 200); if (ret) goto fail; } // Receive parameters (if any). for (i = 0; i < receive; i++) { ret = ps2_recvbyte(aux, 0, 500); if (ret < 0) goto fail; param[i] = ret; } } ret = 0; fail: // Restore interrupts and keyboard/mouse. ret2 = i8042_command(I8042_CMD_CTL_WCTR, &ps2ctr); if (ret2) return ret2; return ret; }
int __ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command) { int timeout; int send = (command >> 12) & 0xf; int receive = (command >> 8) & 0xf; int rc = -1; int i; if (receive > sizeof(ps2dev->cmdbuf)) { WARN_ON(1); return -1; } if (send && !param) { WARN_ON(1); return -1; } serio_pause_rx(ps2dev->serio); ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; ps2dev->cmdcnt = receive; if (receive && param) for (i = 0; i < receive; i++) ps2dev->cmdbuf[(receive - 1) - i] = param[i]; serio_continue_rx(ps2dev->serio); /* * Some devices (Synaptics) peform the reset before * ACKing the reset command, and so it can take a long * time before the ACK arrrives. */ if (ps2_sendbyte(ps2dev, command & 0xff, command == PS2_CMD_RESET_BAT ? 1000 : 200)) goto out; for (i = 0; i < send; i++) if (ps2_sendbyte(ps2dev, param[i], 200)) goto out; /* * The reset command takes a long time to execute. */ timeout = msecs_to_jiffies(command == PS2_CMD_RESET_BAT ? 4000 : 500); timeout = wait_event_timeout(ps2dev->wait, !(ps2dev->flags & PS2_FLAG_CMD1), timeout); if (ps2dev->cmdcnt && !(ps2dev->flags & PS2_FLAG_CMD1)) { timeout = ps2_adjust_timeout(ps2dev, command, timeout); wait_event_timeout(ps2dev->wait, !(ps2dev->flags & PS2_FLAG_CMD), timeout); } if (param) for (i = 0; i < receive; i++) param[i] = ps2dev->cmdbuf[(receive - 1) - i]; if (ps2dev->cmdcnt && (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) goto out; rc = 0; out: serio_pause_rx(ps2dev->serio); ps2dev->flags = 0; serio_continue_rx(ps2dev->serio); return rc; }
static int ps2_command(int aux, int command, u8 *param) { int ret2; int receive = (command >> 8) & 0xf; int send = (command >> 12) & 0xf; // Disable interrupts and keyboard/mouse. u8 ps2ctr = GET_EBDA(ps2ctr); u8 newctr = ps2ctr; if (aux) newctr |= I8042_CTR_KBDDIS; else newctr |= I8042_CTR_AUXDIS; newctr &= ~(I8042_CTR_KBDINT|I8042_CTR_AUXINT); dprintf(6, "i8042 ctr old=%x new=%x\n", ps2ctr, newctr); int ret = i8042_command(I8042_CMD_CTL_WCTR, &newctr); if (ret) return ret; if (command == ATKBD_CMD_RESET_BAT) { // Reset is special wrt timeouts. // Send command. ret = ps2_sendbyte(aux, command, 1000); if (ret) goto fail; // Receive parameters. ret = ps2_recvbyte(aux, 0, 4000); if (ret < 0) goto fail; param[0] = ret; ret = ps2_recvbyte(aux, 0, 100); if (ret < 0) // Some devices only respond with one byte on reset. ret = 0; param[1] = ret; } else { // Send command. ret = ps2_sendbyte(aux, command, 200); if (ret) goto fail; // Send parameters (if any). int i; for (i = 0; i < send; i++) { ret = ps2_sendbyte(aux, param[i], 200); if (ret) goto fail; } // Receive parameters (if any). for (i = 0; i < receive; i++) { ret = ps2_recvbyte(aux, 0, 500); if (ret < 0) goto fail; param[i] = ret; } } ret = 0; fail: // Restore interrupts and keyboard/mouse. ret2 = i8042_command(I8042_CMD_CTL_WCTR, &ps2ctr); if (ret2) return ret2; return ret; }