Lines Matching refs:ps2dev
26 static int ps2_do_sendbyte(struct ps2dev *ps2dev, u8 byte, in ps2_do_sendbyte() argument
28 __releases(&ps2dev->serio->lock) __acquires(&ps2dev->serio->lock) in ps2_do_sendbyte()
33 lockdep_assert_held(&ps2dev->serio->lock); in ps2_do_sendbyte()
36 ps2dev->nak = 1; in ps2_do_sendbyte()
37 ps2dev->flags |= PS2_FLAG_ACK; in ps2_do_sendbyte()
39 serio_continue_rx(ps2dev->serio); in ps2_do_sendbyte()
41 error = serio_write(ps2dev->serio, byte); in ps2_do_sendbyte()
43 dev_dbg(&ps2dev->serio->dev, in ps2_do_sendbyte()
46 wait_event_timeout(ps2dev->wait, in ps2_do_sendbyte()
47 !(ps2dev->flags & PS2_FLAG_ACK), in ps2_do_sendbyte()
50 serio_pause_rx(ps2dev->serio); in ps2_do_sendbyte()
51 } while (ps2dev->nak == PS2_RET_NAK && ++attempt < max_attempts); in ps2_do_sendbyte()
53 ps2dev->flags &= ~PS2_FLAG_ACK; in ps2_do_sendbyte()
56 switch (ps2dev->nak) { in ps2_do_sendbyte()
72 dev_dbg(&ps2dev->serio->dev, in ps2_do_sendbyte()
74 byte, error, ps2dev->nak, attempt); in ps2_do_sendbyte()
87 int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) in ps2_sendbyte() argument
91 serio_pause_rx(ps2dev->serio); in ps2_sendbyte()
93 retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); in ps2_sendbyte()
94 dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); in ps2_sendbyte()
96 serio_continue_rx(ps2dev->serio); in ps2_sendbyte()
102 void ps2_begin_command(struct ps2dev *ps2dev) in ps2_begin_command() argument
104 struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex; in ps2_begin_command()
110 void ps2_end_command(struct ps2dev *ps2dev) in ps2_end_command() argument
112 struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex; in ps2_end_command()
123 void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) in ps2_drain() argument
125 if (maxbytes > sizeof(ps2dev->cmdbuf)) { in ps2_drain()
127 maxbytes = sizeof(ps2dev->cmdbuf); in ps2_drain()
130 ps2_begin_command(ps2dev); in ps2_drain()
132 serio_pause_rx(ps2dev->serio); in ps2_drain()
133 ps2dev->flags = PS2_FLAG_CMD; in ps2_drain()
134 ps2dev->cmdcnt = maxbytes; in ps2_drain()
135 serio_continue_rx(ps2dev->serio); in ps2_drain()
137 wait_event_timeout(ps2dev->wait, in ps2_drain()
138 !(ps2dev->flags & PS2_FLAG_CMD), in ps2_drain()
141 ps2_end_command(ps2dev); in ps2_drain()
171 static int ps2_adjust_timeout(struct ps2dev *ps2dev, in ps2_adjust_timeout() argument
194 if (ps2dev->cmdbuf[1] == 0xaa) { in ps2_adjust_timeout()
195 serio_pause_rx(ps2dev->serio); in ps2_adjust_timeout()
196 ps2dev->flags = 0; in ps2_adjust_timeout()
197 serio_continue_rx(ps2dev->serio); in ps2_adjust_timeout()
205 if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { in ps2_adjust_timeout()
206 serio_pause_rx(ps2dev->serio); in ps2_adjust_timeout()
207 ps2dev->flags = ps2dev->cmdcnt = 0; in ps2_adjust_timeout()
208 serio_continue_rx(ps2dev->serio); in ps2_adjust_timeout()
227 int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) in __ps2_command() argument
236 if (receive > sizeof(ps2dev->cmdbuf)) { in __ps2_command()
248 serio_pause_rx(ps2dev->serio); in __ps2_command()
250 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; in __ps2_command()
251 ps2dev->cmdcnt = receive; in __ps2_command()
254 ps2dev->cmdbuf[(receive - 1) - i] = param[i]; in __ps2_command()
257 ps2dev->flags |= PS2_FLAG_ACK_CMD; in __ps2_command()
266 rc = ps2_do_sendbyte(ps2dev, command & 0xff, timeout, 2); in __ps2_command()
271 ps2dev->flags &= ~PS2_FLAG_ACK_CMD; in __ps2_command()
274 rc = ps2_do_sendbyte(ps2dev, param[i], 200, 2); in __ps2_command()
279 serio_continue_rx(ps2dev->serio); in __ps2_command()
286 timeout = wait_event_timeout(ps2dev->wait, in __ps2_command()
287 !(ps2dev->flags & PS2_FLAG_CMD1), timeout); in __ps2_command()
289 if (ps2dev->cmdcnt && !(ps2dev->flags & PS2_FLAG_CMD1)) { in __ps2_command()
291 timeout = ps2_adjust_timeout(ps2dev, command, timeout); in __ps2_command()
292 wait_event_timeout(ps2dev->wait, in __ps2_command()
293 !(ps2dev->flags & PS2_FLAG_CMD), timeout); in __ps2_command()
296 serio_pause_rx(ps2dev->serio); in __ps2_command()
300 param[i] = ps2dev->cmdbuf[(receive - 1) - i]; in __ps2_command()
304 if (ps2dev->cmdcnt && in __ps2_command()
305 (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) { in __ps2_command()
313 ps2dev->flags = 0; in __ps2_command()
314 serio_continue_rx(ps2dev->serio); in __ps2_command()
316 dev_dbg(&ps2dev->serio->dev, in __ps2_command()
319 ps2dev->nak, ps2dev->flags, in __ps2_command()
330 int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) in ps2_command() argument
334 ps2_begin_command(ps2dev); in ps2_command()
335 rc = __ps2_command(ps2dev, param, command); in ps2_command()
336 ps2_end_command(ps2dev); in ps2_command()
350 int ps2_sliced_command(struct ps2dev *ps2dev, u8 command) in ps2_sliced_command() argument
355 ps2_begin_command(ps2dev); in ps2_sliced_command()
357 retval = __ps2_command(ps2dev, NULL, PS2_CMD_SETSCALE11); in ps2_sliced_command()
363 retval = __ps2_command(ps2dev, &d, PS2_CMD_SETRES); in ps2_sliced_command()
369 dev_dbg(&ps2dev->serio->dev, "%02x - %d\n", command, retval); in ps2_sliced_command()
370 ps2_end_command(ps2dev); in ps2_sliced_command()
379 void ps2_init(struct ps2dev *ps2dev, struct serio *serio) in ps2_init() argument
381 mutex_init(&ps2dev->cmd_mutex); in ps2_init()
382 lockdep_set_subclass(&ps2dev->cmd_mutex, serio->depth); in ps2_init()
383 init_waitqueue_head(&ps2dev->wait); in ps2_init()
384 ps2dev->serio = serio; in ps2_init()
393 bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data) in ps2_handle_ack() argument
397 ps2dev->nak = 0; in ps2_handle_ack()
401 ps2dev->flags |= PS2_FLAG_NAK; in ps2_handle_ack()
402 ps2dev->nak = PS2_RET_NAK; in ps2_handle_ack()
406 if (ps2dev->flags & PS2_FLAG_NAK) { in ps2_handle_ack()
407 ps2dev->flags &= ~PS2_FLAG_NAK; in ps2_handle_ack()
408 ps2dev->nak = PS2_RET_ERR; in ps2_handle_ack()
420 if (ps2dev->flags & PS2_FLAG_WAITID) { in ps2_handle_ack()
421 ps2dev->nak = 0; in ps2_handle_ack()
436 dev_dbg(&ps2dev->serio->dev, "unexpected %#02x\n", data); in ps2_handle_ack()
437 ps2dev->flags &= ~PS2_FLAG_WAITID; in ps2_handle_ack()
438 return ps2dev->flags & PS2_FLAG_ACK_CMD; in ps2_handle_ack()
441 if (!ps2dev->nak) { in ps2_handle_ack()
442 ps2dev->flags &= ~PS2_FLAG_NAK; in ps2_handle_ack()
443 if (ps2dev->cmdcnt) in ps2_handle_ack()
444 ps2dev->flags |= PS2_FLAG_CMD | PS2_FLAG_CMD1; in ps2_handle_ack()
447 ps2dev->flags &= ~PS2_FLAG_ACK; in ps2_handle_ack()
448 wake_up(&ps2dev->wait); in ps2_handle_ack()
451 ps2_handle_response(ps2dev, data); in ps2_handle_ack()
463 bool ps2_handle_response(struct ps2dev *ps2dev, u8 data) in ps2_handle_response() argument
465 if (ps2dev->cmdcnt) in ps2_handle_response()
466 ps2dev->cmdbuf[--ps2dev->cmdcnt] = data; in ps2_handle_response()
468 if (ps2dev->flags & PS2_FLAG_CMD1) { in ps2_handle_response()
469 ps2dev->flags &= ~PS2_FLAG_CMD1; in ps2_handle_response()
470 if (ps2dev->cmdcnt) in ps2_handle_response()
471 wake_up(&ps2dev->wait); in ps2_handle_response()
474 if (!ps2dev->cmdcnt) { in ps2_handle_response()
475 ps2dev->flags &= ~PS2_FLAG_CMD; in ps2_handle_response()
476 wake_up(&ps2dev->wait); in ps2_handle_response()
483 void ps2_cmd_aborted(struct ps2dev *ps2dev) in ps2_cmd_aborted() argument
485 if (ps2dev->flags & PS2_FLAG_ACK) in ps2_cmd_aborted()
486 ps2dev->nak = 1; in ps2_cmd_aborted()
488 if (ps2dev->flags & (PS2_FLAG_ACK | PS2_FLAG_CMD)) in ps2_cmd_aborted()
489 wake_up(&ps2dev->wait); in ps2_cmd_aborted()
492 ps2dev->flags &= PS2_FLAG_NAK; in ps2_cmd_aborted()