Lines Matching refs:ps2dev
25 static int ps2_do_sendbyte(struct ps2dev *ps2dev, u8 byte, in ps2_do_sendbyte() argument
27 __releases(&ps2dev->serio->lock) __acquires(&ps2dev->serio->lock) in ps2_do_sendbyte()
32 lockdep_assert_held(&ps2dev->serio->lock); in ps2_do_sendbyte()
35 ps2dev->nak = 1; in ps2_do_sendbyte()
36 ps2dev->flags |= PS2_FLAG_ACK; in ps2_do_sendbyte()
38 serio_continue_rx(ps2dev->serio); in ps2_do_sendbyte()
40 error = serio_write(ps2dev->serio, byte); in ps2_do_sendbyte()
42 dev_dbg(&ps2dev->serio->dev, in ps2_do_sendbyte()
45 wait_event_timeout(ps2dev->wait, in ps2_do_sendbyte()
46 !(ps2dev->flags & PS2_FLAG_ACK), in ps2_do_sendbyte()
49 serio_pause_rx(ps2dev->serio); in ps2_do_sendbyte()
50 } while (ps2dev->nak == PS2_RET_NAK && ++attempt < max_attempts); in ps2_do_sendbyte()
52 ps2dev->flags &= ~PS2_FLAG_ACK; in ps2_do_sendbyte()
55 switch (ps2dev->nak) { in ps2_do_sendbyte()
71 dev_dbg(&ps2dev->serio->dev, in ps2_do_sendbyte()
73 byte, error, ps2dev->nak, attempt); in ps2_do_sendbyte()
86 int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) in ps2_sendbyte() argument
90 serio_pause_rx(ps2dev->serio); in ps2_sendbyte()
92 retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); in ps2_sendbyte()
93 dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); in ps2_sendbyte()
95 serio_continue_rx(ps2dev->serio); in ps2_sendbyte()
101 void ps2_begin_command(struct ps2dev *ps2dev) in ps2_begin_command() argument
103 struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex; in ps2_begin_command()
109 void ps2_end_command(struct ps2dev *ps2dev) in ps2_end_command() argument
111 struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex; in ps2_end_command()
122 void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) in ps2_drain() argument
124 if (maxbytes > sizeof(ps2dev->cmdbuf)) { in ps2_drain()
126 maxbytes = sizeof(ps2dev->cmdbuf); in ps2_drain()
129 ps2_begin_command(ps2dev); in ps2_drain()
131 serio_pause_rx(ps2dev->serio); in ps2_drain()
132 ps2dev->flags = PS2_FLAG_CMD; in ps2_drain()
133 ps2dev->cmdcnt = maxbytes; in ps2_drain()
134 serio_continue_rx(ps2dev->serio); in ps2_drain()
136 wait_event_timeout(ps2dev->wait, in ps2_drain()
137 !(ps2dev->flags & PS2_FLAG_CMD), in ps2_drain()
140 ps2_end_command(ps2dev); in ps2_drain()
170 static int ps2_adjust_timeout(struct ps2dev *ps2dev, in ps2_adjust_timeout() argument
193 if (ps2dev->cmdbuf[1] == 0xaa) { in ps2_adjust_timeout()
194 serio_pause_rx(ps2dev->serio); in ps2_adjust_timeout()
195 ps2dev->flags = 0; in ps2_adjust_timeout()
196 serio_continue_rx(ps2dev->serio); in ps2_adjust_timeout()
204 if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { in ps2_adjust_timeout()
205 serio_pause_rx(ps2dev->serio); in ps2_adjust_timeout()
206 ps2dev->flags = ps2dev->cmdcnt = 0; in ps2_adjust_timeout()
207 serio_continue_rx(ps2dev->serio); in ps2_adjust_timeout()
226 int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) in __ps2_command() argument
235 if (receive > sizeof(ps2dev->cmdbuf)) { in __ps2_command()
247 serio_pause_rx(ps2dev->serio); in __ps2_command()
249 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; in __ps2_command()
250 ps2dev->cmdcnt = receive; in __ps2_command()
253 ps2dev->cmdbuf[(receive - 1) - i] = param[i]; in __ps2_command()
256 ps2dev->flags |= PS2_FLAG_ACK_CMD; in __ps2_command()
265 rc = ps2_do_sendbyte(ps2dev, command & 0xff, timeout, 2); in __ps2_command()
270 ps2dev->flags &= ~PS2_FLAG_ACK_CMD; in __ps2_command()
273 rc = ps2_do_sendbyte(ps2dev, param[i], 200, 2); in __ps2_command()
278 serio_continue_rx(ps2dev->serio); in __ps2_command()
285 timeout = wait_event_timeout(ps2dev->wait, in __ps2_command()
286 !(ps2dev->flags & PS2_FLAG_CMD1), timeout); in __ps2_command()
288 if (ps2dev->cmdcnt && !(ps2dev->flags & PS2_FLAG_CMD1)) { in __ps2_command()
290 timeout = ps2_adjust_timeout(ps2dev, command, timeout); in __ps2_command()
291 wait_event_timeout(ps2dev->wait, in __ps2_command()
292 !(ps2dev->flags & PS2_FLAG_CMD), timeout); in __ps2_command()
295 serio_pause_rx(ps2dev->serio); in __ps2_command()
299 param[i] = ps2dev->cmdbuf[(receive - 1) - i]; in __ps2_command()
301 if (ps2dev->cmdcnt && in __ps2_command()
302 (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) { in __ps2_command()
310 ps2dev->flags = 0; in __ps2_command()
311 serio_continue_rx(ps2dev->serio); in __ps2_command()
313 dev_dbg(&ps2dev->serio->dev, in __ps2_command()
316 ps2dev->nak, ps2dev->flags, in __ps2_command()
327 int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) in ps2_command() argument
331 ps2_begin_command(ps2dev); in ps2_command()
332 rc = __ps2_command(ps2dev, param, command); in ps2_command()
333 ps2_end_command(ps2dev); in ps2_command()
347 int ps2_sliced_command(struct ps2dev *ps2dev, u8 command) in ps2_sliced_command() argument
352 ps2_begin_command(ps2dev); in ps2_sliced_command()
354 retval = __ps2_command(ps2dev, NULL, PS2_CMD_SETSCALE11); in ps2_sliced_command()
360 retval = __ps2_command(ps2dev, &d, PS2_CMD_SETRES); in ps2_sliced_command()
366 dev_dbg(&ps2dev->serio->dev, "%02x - %d\n", command, retval); in ps2_sliced_command()
367 ps2_end_command(ps2dev); in ps2_sliced_command()
376 void ps2_init(struct ps2dev *ps2dev, struct serio *serio) in ps2_init() argument
378 mutex_init(&ps2dev->cmd_mutex); in ps2_init()
379 lockdep_set_subclass(&ps2dev->cmd_mutex, serio->depth); in ps2_init()
380 init_waitqueue_head(&ps2dev->wait); in ps2_init()
381 ps2dev->serio = serio; in ps2_init()
390 bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data) in ps2_handle_ack() argument
394 ps2dev->nak = 0; in ps2_handle_ack()
398 ps2dev->flags |= PS2_FLAG_NAK; in ps2_handle_ack()
399 ps2dev->nak = PS2_RET_NAK; in ps2_handle_ack()
403 if (ps2dev->flags & PS2_FLAG_NAK) { in ps2_handle_ack()
404 ps2dev->flags &= ~PS2_FLAG_NAK; in ps2_handle_ack()
405 ps2dev->nak = PS2_RET_ERR; in ps2_handle_ack()
417 if (ps2dev->flags & PS2_FLAG_WAITID) { in ps2_handle_ack()
418 ps2dev->nak = 0; in ps2_handle_ack()
433 dev_dbg(&ps2dev->serio->dev, "unexpected %#02x\n", data); in ps2_handle_ack()
434 ps2dev->flags &= ~PS2_FLAG_WAITID; in ps2_handle_ack()
435 return ps2dev->flags & PS2_FLAG_ACK_CMD; in ps2_handle_ack()
438 if (!ps2dev->nak) { in ps2_handle_ack()
439 ps2dev->flags &= ~PS2_FLAG_NAK; in ps2_handle_ack()
440 if (ps2dev->cmdcnt) in ps2_handle_ack()
441 ps2dev->flags |= PS2_FLAG_CMD | PS2_FLAG_CMD1; in ps2_handle_ack()
444 ps2dev->flags &= ~PS2_FLAG_ACK; in ps2_handle_ack()
445 wake_up(&ps2dev->wait); in ps2_handle_ack()
448 ps2_handle_response(ps2dev, data); in ps2_handle_ack()
460 bool ps2_handle_response(struct ps2dev *ps2dev, u8 data) in ps2_handle_response() argument
462 if (ps2dev->cmdcnt) in ps2_handle_response()
463 ps2dev->cmdbuf[--ps2dev->cmdcnt] = data; in ps2_handle_response()
465 if (ps2dev->flags & PS2_FLAG_CMD1) { in ps2_handle_response()
466 ps2dev->flags &= ~PS2_FLAG_CMD1; in ps2_handle_response()
467 if (ps2dev->cmdcnt) in ps2_handle_response()
468 wake_up(&ps2dev->wait); in ps2_handle_response()
471 if (!ps2dev->cmdcnt) { in ps2_handle_response()
472 ps2dev->flags &= ~PS2_FLAG_CMD; in ps2_handle_response()
473 wake_up(&ps2dev->wait); in ps2_handle_response()
480 void ps2_cmd_aborted(struct ps2dev *ps2dev) in ps2_cmd_aborted() argument
482 if (ps2dev->flags & PS2_FLAG_ACK) in ps2_cmd_aborted()
483 ps2dev->nak = 1; in ps2_cmd_aborted()
485 if (ps2dev->flags & (PS2_FLAG_ACK | PS2_FLAG_CMD)) in ps2_cmd_aborted()
486 wake_up(&ps2dev->wait); in ps2_cmd_aborted()
489 ps2dev->flags &= PS2_FLAG_NAK; in ps2_cmd_aborted()