Lines Matching +full:rc +full:- +full:rc6 +full:- +full:mce
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ir-mce_kbd-decoder.c - A decoder for the RC6-ish keyboard/mouse IR protocol
5 * as "an internal protocol called MCIR-2".
11 #include "rc-core-priv.h"
15 * - MCIR-2 29-bit IR signals used for mouse movement and buttons
16 * - MCIR-2 32-bit IR signals used for standard keyboard keys
18 * The media keys on the keyboard send RC-6 signals that are indistinguishable
19 * from the keys of the same name on the stock MCE remote, and will be handled
20 * by the standard RC-6 decoder, and be made available to the system via the
117 dev_dbg(&raw->dev->dev, "timer callback clearing all keys\n"); in mce_kbd_rx_timeout()
119 spin_lock_irqsave(&raw->mce_kbd.keylock, flags); in mce_kbd_rx_timeout()
121 if (time_is_before_eq_jiffies(raw->mce_kbd.rx_timeout.expires)) { in mce_kbd_rx_timeout()
124 input_report_key(raw->dev->input_dev, maskcode, 0); in mce_kbd_rx_timeout()
128 input_report_key(raw->dev->input_dev, kbd_keycodes[i], in mce_kbd_rx_timeout()
131 input_sync(raw->dev->input_dev); in mce_kbd_rx_timeout()
133 spin_unlock_irqrestore(&raw->mce_kbd.keylock, flags); in mce_kbd_rx_timeout()
138 switch (data->header & MCIR2_MODE_MASK) { in mce_kbd_mode()
156 dev_dbg(&dev->dev, "keyboard: keydata2 = 0x%02x, keydata1 = 0x%02x, shiftmask = 0x%02x\n", in ir_mce_kbd_process_keyboard_data()
165 input_report_key(dev->input_dev, maskcode, keystate); in ir_mce_kbd_process_keyboard_data()
169 input_report_key(dev->input_dev, kbd_keycodes[keydata1], 1); in ir_mce_kbd_process_keyboard_data()
171 input_report_key(dev->input_dev, kbd_keycodes[keydata2], 1); in ir_mce_kbd_process_keyboard_data()
175 input_report_key(dev->input_dev, kbd_keycodes[i], 0); in ir_mce_kbd_process_keyboard_data()
190 x = -((~xdata & 0x7f) + 1); in ir_mce_kbd_process_mouse_data()
195 y = -((~ydata & 0x7f) + 1); in ir_mce_kbd_process_mouse_data()
199 dev_dbg(&dev->dev, "mouse: x = %d, y = %d, btns = %s%s\n", in ir_mce_kbd_process_mouse_data()
202 input_report_rel(dev->input_dev, REL_X, x); in ir_mce_kbd_process_mouse_data()
203 input_report_rel(dev->input_dev, REL_Y, y); in ir_mce_kbd_process_mouse_data()
205 input_report_key(dev->input_dev, BTN_LEFT, left); in ir_mce_kbd_process_mouse_data()
206 input_report_key(dev->input_dev, BTN_RIGHT, right); in ir_mce_kbd_process_mouse_data()
210 * ir_mce_kbd_decode() - Decode one mce_kbd pulse or space
214 * This function returns -EINVAL if the pulse violates the state machine
218 struct mce_kbd_dec *data = &dev->raw->mce_kbd; in ir_mce_kbd_decode()
225 data->state = STATE_INACTIVE; in ir_mce_kbd_decode()
233 dev_dbg(&dev->dev, "started at state %i (%uus %s)\n", in ir_mce_kbd_decode()
234 data->state, ev.duration, TO_STR(ev.pulse)); in ir_mce_kbd_decode()
239 switch (data->state) { in ir_mce_kbd_decode()
251 data->state = STATE_HEADER_BIT_START; in ir_mce_kbd_decode()
252 data->count = 0; in ir_mce_kbd_decode()
253 data->header = 0; in ir_mce_kbd_decode()
260 data->header <<= 1; in ir_mce_kbd_decode()
262 data->header |= 1; in ir_mce_kbd_decode()
263 data->count++; in ir_mce_kbd_decode()
264 data->state = STATE_HEADER_BIT_END; in ir_mce_kbd_decode()
270 if (data->count != MCIR2_HEADER_NBITS) { in ir_mce_kbd_decode()
271 data->state = STATE_HEADER_BIT_START; in ir_mce_kbd_decode()
277 data->wanted_bits = MCIR2_KEYBOARD_NBITS; in ir_mce_kbd_decode()
280 data->wanted_bits = MCIR2_MOUSE_NBITS; in ir_mce_kbd_decode()
283 dev_dbg(&dev->dev, "not keyboard or mouse data\n"); in ir_mce_kbd_decode()
287 data->count = 0; in ir_mce_kbd_decode()
288 data->body = 0; in ir_mce_kbd_decode()
289 data->state = STATE_BODY_BIT_START; in ir_mce_kbd_decode()
296 data->body <<= 1; in ir_mce_kbd_decode()
298 data->body |= 1; in ir_mce_kbd_decode()
299 data->count++; in ir_mce_kbd_decode()
300 data->state = STATE_BODY_BIT_END; in ir_mce_kbd_decode()
304 if (data->count == data->wanted_bits) in ir_mce_kbd_decode()
305 data->state = STATE_FINISHED; in ir_mce_kbd_decode()
307 data->state = STATE_BODY_BIT_START; in ir_mce_kbd_decode()
316 switch (data->wanted_bits) { in ir_mce_kbd_decode()
318 scancode = data->body & 0xffffff; in ir_mce_kbd_decode()
319 dev_dbg(&dev->dev, "keyboard data 0x%08x\n", in ir_mce_kbd_decode()
320 data->body); in ir_mce_kbd_decode()
321 spin_lock(&data->keylock); in ir_mce_kbd_decode()
323 delay = usecs_to_jiffies(dev->timeout) + in ir_mce_kbd_decode()
325 mod_timer(&data->rx_timeout, jiffies + delay); in ir_mce_kbd_decode()
327 del_timer(&data->rx_timeout); in ir_mce_kbd_decode()
331 spin_unlock(&data->keylock); in ir_mce_kbd_decode()
335 scancode = data->body & 0x1fffff; in ir_mce_kbd_decode()
336 dev_dbg(&dev->dev, "mouse data 0x%06x\n", scancode); in ir_mce_kbd_decode()
342 dev_dbg(&dev->dev, "not keyboard or mouse data\n"); in ir_mce_kbd_decode()
348 data->state = STATE_INACTIVE; in ir_mce_kbd_decode()
349 input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode); in ir_mce_kbd_decode()
350 input_sync(dev->input_dev); in ir_mce_kbd_decode()
355 dev_dbg(&dev->dev, "failed at state %i (%uus %s)\n", in ir_mce_kbd_decode()
356 data->state, ev.duration, TO_STR(ev.pulse)); in ir_mce_kbd_decode()
357 data->state = STATE_INACTIVE; in ir_mce_kbd_decode()
358 return -EINVAL; in ir_mce_kbd_decode()
363 struct mce_kbd_dec *mce_kbd = &dev->raw->mce_kbd; in ir_mce_kbd_register()
365 timer_setup(&mce_kbd->rx_timeout, mce_kbd_rx_timeout, 0); in ir_mce_kbd_register()
366 spin_lock_init(&mce_kbd->keylock); in ir_mce_kbd_register()
373 struct mce_kbd_dec *mce_kbd = &dev->raw->mce_kbd; in ir_mce_kbd_unregister()
375 del_timer_sync(&mce_kbd->rx_timeout); in ir_mce_kbd_unregister()
388 * ir_mce_kbd_encode() - Encode a scancode as a stream of raw events
396 * -ENOBUFS if there isn't enough space in the array to fit the
420 return e - events; in ir_mce_kbd_encode()
437 printk(KERN_INFO "IR MCE Keyboard/mouse protocol handler initialized\n"); in ir_mce_kbd_decode_init()
451 MODULE_DESCRIPTION("MCE Keyboard/mouse IR protocol decoder");