[media] mceusb: fix keybouce issue after parser simplification

Something I failed to notice while testing the mceusb RLE buffer
decoding simplification patches was that we were getting an extra event
from the previously pressed key.

As was pointed out to me on irc by Maxim, this is actually due to using
ir_raw_event_store_with_filter without having set up a timeout value.
The hardware has a timeout value we're now reading and storing, which
properly enables the transition to idle in the raw event storage
process, and makes IR decode behave correctly w/o keybounce.

Also remove no-longer-used ir_raw_event struct from mceusb_dev struct
and add as-yet-unused enable flags for carrier reports and learning
mode, which I'll hopefully start wiring up sooner than later. While
looking into that, found evidence that 0x9f 0x15 responses are only
non-zero when the short-range learning sensor is used, so correct the
debug spew message, and then suppress it when using the standard
long-range sensor.

Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by Jarod Wilson and committed by Mauro Carvalho Chehab 2ee95db2 2d6e588c

+46 -10
+46 -10
drivers/media/IR/mceusb.c
··· 49 49 #define USB_BUFLEN 32 /* USB reception buffer length */ 50 50 #define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */ 51 51 #define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */ 52 + #define MS_TO_NS(msec) ((msec) * 1000) 52 53 53 54 /* MCE constants */ 54 55 #define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */ ··· 93 92 #define MCE_CMD_G_TXMASK 0x13 /* Set TX port bitmask */ 94 93 #define MCE_CMD_S_RXSENSOR 0x14 /* Set RX sensor (std/learning) */ 95 94 #define MCE_CMD_G_RXSENSOR 0x15 /* Get RX sensor (std/learning) */ 95 + #define MCE_RSP_PULSE_COUNT 0x15 /* RX pulse count (only if learning) */ 96 96 #define MCE_CMD_TX_PORTS 0x16 /* Get number of TX ports */ 97 97 #define MCE_CMD_G_WAKESRC 0x17 /* Get wake source */ 98 98 #define MCE_CMD_UNKNOWN7 0x18 /* Unknown */ ··· 316 314 struct mceusb_dev { 317 315 /* ir-core bits */ 318 316 struct ir_dev_props *props; 319 - struct ir_raw_event rawir; 317 + 318 + /* optional features we can enable */ 319 + bool carrier_report_enabled; 320 + bool learning_enabled; 320 321 321 322 /* core device bits */ 322 323 struct device *dev; ··· 334 329 /* buffers and dma */ 335 330 unsigned char *buf_in; 336 331 unsigned int len_in; 332 + dma_addr_t dma_in; 333 + dma_addr_t dma_out; 337 334 338 335 enum { 339 336 CMD_HEADER = 0, ··· 343 336 CMD_DATA, 344 337 PARSE_IRDATA, 345 338 } parser_state; 346 - u8 cmd, rem; /* Remaining IR data bytes in packet */ 347 339 348 - dma_addr_t dma_in; 349 - dma_addr_t dma_out; 340 + u8 cmd, rem; /* Remaining IR data bytes in packet */ 350 341 351 342 struct { 352 343 u32 connected:1; ··· 425 420 case MCE_CMD_UNKNOWN: 426 421 case MCE_CMD_S_CARRIER: 427 422 case MCE_CMD_S_TIMEOUT: 428 - case MCE_CMD_G_RXSENSOR: 423 + case MCE_RSP_PULSE_COUNT: 429 424 datasize = 2; 430 425 break; 431 426 case MCE_CMD_SIG_END: ··· 546 541 inout, data1 == 0x02 ? "short" : "long"); 547 542 break; 548 543 case MCE_CMD_G_RXSENSOR: 549 - if (len == 2) 544 + /* aka MCE_RSP_PULSE_COUNT */ 545 + if (out) 550 546 dev_info(dev, "Get receive sensor\n"); 551 - else 552 - dev_info(dev, "Remaining pulse count is %d\n", 547 + else if (ir->learning_enabled) 548 + dev_info(dev, "RX pulse count: %d\n", 553 549 ((data1 << 8) | data2)); 554 550 break; 555 551 case MCE_RSP_CMD_INVALID: ··· 804 798 return carrier; 805 799 } 806 800 801 + /* 802 + * We don't do anything but print debug spew for many of the command bits 803 + * we receive from the hardware, but some of them are useful information 804 + * we want to store so that we can use them. 805 + */ 806 + static void mceusb_handle_command(struct mceusb_dev *ir, int index) 807 + { 808 + u8 hi = ir->buf_in[index + 1] & 0xff; 809 + u8 lo = ir->buf_in[index + 2] & 0xff; 810 + 811 + switch (ir->buf_in[index]) { 812 + /* 2-byte return value commands */ 813 + case MCE_CMD_S_TIMEOUT: 814 + ir->props->timeout = MS_TO_NS((hi << 8 | lo) / 2); 815 + break; 816 + 817 + /* 1-byte return value commands */ 818 + case MCE_CMD_S_TXMASK: 819 + ir->tx_mask = hi; 820 + break; 821 + case MCE_CMD_S_RXSENSOR: 822 + ir->learning_enabled = (hi == 0x02); 823 + break; 824 + default: 825 + break; 826 + } 827 + } 828 + 807 829 static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len) 808 830 { 809 831 DEFINE_IR_RAW_EVENT(rawir); ··· 851 817 ir->rem = mceusb_cmdsize(ir->cmd, ir->buf_in[i]); 852 818 mceusb_dev_printdata(ir, ir->buf_in, i - 1, 853 819 ir->rem + 2, false); 820 + mceusb_handle_command(ir, i); 854 821 ir->parser_state = CMD_DATA; 855 822 break; 856 823 case PARSE_IRDATA: 857 824 ir->rem--; 858 825 rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0); 859 826 rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK) 860 - * MCE_TIME_UNIT * 1000; 827 + * MS_TO_NS(MCE_TIME_UNIT); 861 828 862 829 dev_dbg(ir->dev, "Storing %s with duration %d\n", 863 830 rawir.pulse ? "pulse" : "space", ··· 880 845 continue; 881 846 } 882 847 ir->rem = (ir->cmd & MCE_PACKET_LENGTH_MASK); 883 - mceusb_dev_printdata(ir, ir->buf_in, i, ir->rem + 1, false); 848 + mceusb_dev_printdata(ir, ir->buf_in, 849 + i, ir->rem + 1, false); 884 850 if (ir->rem) 885 851 ir->parser_state = PARSE_IRDATA; 886 852 break;