Lines Matching refs:ps2dev

29 static int ps2_do_sendbyte(struct ps2dev *ps2dev, u8 byte,  in ps2_do_sendbyte()  argument
31 __releases(&ps2dev->serio->lock) __acquires(&ps2dev->serio->lock) in ps2_do_sendbyte()
36 lockdep_assert_held(&ps2dev->serio->lock); in ps2_do_sendbyte()
39 ps2dev->nak = 1; in ps2_do_sendbyte()
40 ps2dev->flags |= PS2_FLAG_ACK; in ps2_do_sendbyte()
42 serio_continue_rx(ps2dev->serio); in ps2_do_sendbyte()
44 error = serio_write(ps2dev->serio, byte); in ps2_do_sendbyte()
46 dev_dbg(&ps2dev->serio->dev, in ps2_do_sendbyte()
49 wait_event_timeout(ps2dev->wait, in ps2_do_sendbyte()
50 !(ps2dev->flags & PS2_FLAG_ACK), in ps2_do_sendbyte()
53 serio_pause_rx(ps2dev->serio); in ps2_do_sendbyte()
54 } while (ps2dev->nak == PS2_RET_NAK && ++attempt < max_attempts); in ps2_do_sendbyte()
56 ps2dev->flags &= ~PS2_FLAG_ACK; in ps2_do_sendbyte()
59 switch (ps2dev->nak) { in ps2_do_sendbyte()
75 dev_dbg(&ps2dev->serio->dev, in ps2_do_sendbyte()
77 byte, error, ps2dev->nak, attempt); in ps2_do_sendbyte()
90 int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) in ps2_sendbyte() argument
94 serio_pause_rx(ps2dev->serio); in ps2_sendbyte()
96 retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); in ps2_sendbyte()
97 dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); in ps2_sendbyte()
99 serio_continue_rx(ps2dev->serio); in ps2_sendbyte()
105 void ps2_begin_command(struct ps2dev *ps2dev) in ps2_begin_command() argument
107 struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex; in ps2_begin_command()
113 void ps2_end_command(struct ps2dev *ps2dev) in ps2_end_command() argument
115 struct mutex *m = ps2dev->serio->ps2_cmd_mutex ?: &ps2dev->cmd_mutex; in ps2_end_command()
126 void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) in ps2_drain() argument
128 if (maxbytes > sizeof(ps2dev->cmdbuf)) { in ps2_drain()
130 maxbytes = sizeof(ps2dev->cmdbuf); in ps2_drain()
133 ps2_begin_command(ps2dev); in ps2_drain()
135 serio_pause_rx(ps2dev->serio); in ps2_drain()
136 ps2dev->flags = PS2_FLAG_CMD; in ps2_drain()
137 ps2dev->cmdcnt = maxbytes; in ps2_drain()
138 serio_continue_rx(ps2dev->serio); in ps2_drain()
140 wait_event_timeout(ps2dev->wait, in ps2_drain()
141 !(ps2dev->flags & PS2_FLAG_CMD), in ps2_drain()
144 ps2_end_command(ps2dev); in ps2_drain()
174 static int ps2_adjust_timeout(struct ps2dev *ps2dev, in ps2_adjust_timeout() argument
197 if (ps2dev->cmdbuf[1] == 0xaa) { in ps2_adjust_timeout()
198 serio_pause_rx(ps2dev->serio); in ps2_adjust_timeout()
199 ps2dev->flags = 0; in ps2_adjust_timeout()
200 serio_continue_rx(ps2dev->serio); in ps2_adjust_timeout()
208 if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { in ps2_adjust_timeout()
209 serio_pause_rx(ps2dev->serio); in ps2_adjust_timeout()
210 ps2dev->flags = ps2dev->cmdcnt = 0; in ps2_adjust_timeout()
211 serio_continue_rx(ps2dev->serio); in ps2_adjust_timeout()
230 int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) in __ps2_command() argument
239 if (receive > sizeof(ps2dev->cmdbuf)) { in __ps2_command()
251 serio_pause_rx(ps2dev->serio); in __ps2_command()
253 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; in __ps2_command()
254 ps2dev->cmdcnt = receive; in __ps2_command()
257 ps2dev->cmdbuf[(receive - 1) - i] = param[i]; in __ps2_command()
260 ps2dev->flags |= PS2_FLAG_ACK_CMD; in __ps2_command()
269 rc = ps2_do_sendbyte(ps2dev, command & 0xff, timeout, 2); in __ps2_command()
274 ps2dev->flags &= ~PS2_FLAG_ACK_CMD; in __ps2_command()
277 rc = ps2_do_sendbyte(ps2dev, param[i], 200, 2); in __ps2_command()
282 serio_continue_rx(ps2dev->serio); in __ps2_command()
289 timeout = wait_event_timeout(ps2dev->wait, in __ps2_command()
290 !(ps2dev->flags & PS2_FLAG_CMD1), timeout); in __ps2_command()
292 if (ps2dev->cmdcnt && !(ps2dev->flags & PS2_FLAG_CMD1)) { in __ps2_command()
294 timeout = ps2_adjust_timeout(ps2dev, command, timeout); in __ps2_command()
295 wait_event_timeout(ps2dev->wait, in __ps2_command()
296 !(ps2dev->flags & PS2_FLAG_CMD), timeout); in __ps2_command()
299 serio_pause_rx(ps2dev->serio); in __ps2_command()
303 param[i] = ps2dev->cmdbuf[(receive - 1) - i]; in __ps2_command()
305 if (ps2dev->cmdcnt && in __ps2_command()
306 (command != PS2_CMD_RESET_BAT || ps2dev->cmdcnt != 1)) { in __ps2_command()
314 ps2dev->flags = 0; in __ps2_command()
315 serio_continue_rx(ps2dev->serio); in __ps2_command()
317 dev_dbg(&ps2dev->serio->dev, in __ps2_command()
320 ps2dev->nak, ps2dev->flags, in __ps2_command()
331 int ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) in ps2_command() argument
335 ps2_begin_command(ps2dev); in ps2_command()
336 rc = __ps2_command(ps2dev, param, command); in ps2_command()
337 ps2_end_command(ps2dev); in ps2_command()
351 int ps2_sliced_command(struct ps2dev *ps2dev, u8 command) in ps2_sliced_command() argument
356 ps2_begin_command(ps2dev); in ps2_sliced_command()
358 retval = __ps2_command(ps2dev, NULL, PS2_CMD_SETSCALE11); in ps2_sliced_command()
364 retval = __ps2_command(ps2dev, &d, PS2_CMD_SETRES); in ps2_sliced_command()
370 dev_dbg(&ps2dev->serio->dev, "%02x - %d\n", command, retval); in ps2_sliced_command()
371 ps2_end_command(ps2dev); in ps2_sliced_command()
380 void ps2_init(struct ps2dev *ps2dev, struct serio *serio) in ps2_init() argument
382 mutex_init(&ps2dev->cmd_mutex); in ps2_init()
383 lockdep_set_subclass(&ps2dev->cmd_mutex, serio->depth); in ps2_init()
384 init_waitqueue_head(&ps2dev->wait); in ps2_init()
385 ps2dev->serio = serio; in ps2_init()
394 bool ps2_handle_ack(struct ps2dev *ps2dev, u8 data) in ps2_handle_ack() argument
398 ps2dev->nak = 0; in ps2_handle_ack()
402 ps2dev->flags |= PS2_FLAG_NAK; in ps2_handle_ack()
403 ps2dev->nak = PS2_RET_NAK; in ps2_handle_ack()
407 if (ps2dev->flags & PS2_FLAG_NAK) { in ps2_handle_ack()
408 ps2dev->flags &= ~PS2_FLAG_NAK; in ps2_handle_ack()
409 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()