[media] mceusb: fix up reporting of trailing space

We were storing a bunch of spaces at the end of each signal, rather than
a single long space. The in-kernel decoders were actually okay with
this, but lirc isn't. As suggested by David Härdeman, switch to storing
samples using ir_raw_event_store_with_filter, which auto-merges the
consecutive space samples for us. This also allows us to bypass having
to store rawir samples in our device struct, further simplifying the
buffer parsing state machine. Both in-kernel decoders and lirc are happy
again with this change.

Also included in this patch is proper parsing of 0x9f 0x01 commands, the
removal of some magic number usage and some printk spew fixups.

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 1cd50f25 b7582815

+13 -32
+13 -32
drivers/media/IR/mceusb.c
··· 74 74 #define MCE_PACKET_LENGTH_MASK 0x1f /* Packet length mask */ 75 75 76 76 /* Sub-commands, which follow MCE_COMMAND_HEADER or MCE_HW_CMD_HEADER */ 77 + #define MCE_CMD_SIG_END 0x01 /* End of signal */ 77 78 #define MCE_CMD_PING 0x03 /* Ping device */ 78 79 #define MCE_CMD_UNKNOWN 0x04 /* Unknown */ 79 80 #define MCE_CMD_UNKNOWN2 0x05 /* Unknown */ ··· 423 422 case MCE_CMD_G_RXSENSOR: 424 423 datasize = 2; 425 424 break; 425 + case MCE_CMD_SIG_END: 426 426 case MCE_CMD_S_TXMASK: 427 427 case MCE_CMD_S_RXSENSOR: 428 428 datasize = 1; ··· 504 502 break; 505 503 case MCE_COMMAND_HEADER: 506 504 switch (subcmd) { 505 + case MCE_CMD_SIG_END: 506 + dev_info(dev, "End of signal\n"); 507 + break; 507 508 case MCE_CMD_PING: 508 509 dev_info(dev, "Ping\n"); 509 510 break; ··· 544 539 if (len == 2) 545 540 dev_info(dev, "Get receive sensor\n"); 546 541 else 547 - dev_info(dev, "Received pulse count is %d\n", 542 + dev_info(dev, "Remaining pulse count is %d\n", 548 543 ((data1 << 8) | data2)); 549 544 break; 550 545 case MCE_RSP_CMD_INVALID: ··· 768 763 769 764 if (carrier == 0) { 770 765 ir->carrier = carrier; 771 - cmdbuf[2] = 0x01; 766 + cmdbuf[2] = MCE_CMD_SIG_END; 772 767 cmdbuf[3] = MCE_IRDATA_TRAILER; 773 768 dev_dbg(ir->dev, "%s: disabling carrier " 774 769 "modulation\n", __func__); ··· 821 816 rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK) 822 817 * MCE_TIME_UNIT * 1000; 823 818 824 - if ((ir->buf_in[i] & MCE_PULSE_MASK) == 0x7f) { 825 - if (ir->rawir.pulse == rawir.pulse) { 826 - ir->rawir.duration += rawir.duration; 827 - } else { 828 - ir->rawir.duration = rawir.duration; 829 - ir->rawir.pulse = rawir.pulse; 830 - } 831 - if (ir->rem) 832 - break; 833 - } 834 - rawir.duration += ir->rawir.duration; 835 - ir->rawir.duration = 0; 836 - ir->rawir.pulse = rawir.pulse; 837 - 838 819 dev_dbg(ir->dev, "Storing %s with duration %d\n", 839 820 rawir.pulse ? "pulse" : "space", 840 821 rawir.duration); 841 822 842 - ir_raw_event_store(ir->idev, &rawir); 823 + ir_raw_event_store_with_filter(ir->idev, &rawir); 843 824 break; 844 825 case CMD_DATA: 845 826 ir->rem--; ··· 842 851 } 843 852 ir->rem = (ir->cmd & MCE_PACKET_LENGTH_MASK); 844 853 mceusb_dev_printdata(ir, ir->buf_in, i, ir->rem + 1, false); 845 - if (ir->rem) { 854 + if (ir->rem) 846 855 ir->parser_state = PARSE_IRDATA; 847 - break; 848 - } 849 - /* 850 - * a package with len=0 (e. g. 0x80) means end of 851 - * data. We could use it to do the call to 852 - * ir_raw_event_handle(). For now, we don't need to 853 - * use it. 854 - */ 855 856 break; 856 857 } 857 858 ··· 1075 1092 bool tx_mask_inverted; 1076 1093 bool is_polaris; 1077 1094 1078 - dev_dbg(&intf->dev, ": %s called\n", __func__); 1095 + dev_dbg(&intf->dev, "%s called\n", __func__); 1079 1096 1080 1097 idesc = intf->cur_altsetting; 1081 1098 ··· 1105 1122 ep_in = ep; 1106 1123 ep_in->bmAttributes = USB_ENDPOINT_XFER_INT; 1107 1124 ep_in->bInterval = 1; 1108 - dev_dbg(&intf->dev, ": acceptable inbound endpoint " 1125 + dev_dbg(&intf->dev, "acceptable inbound endpoint " 1109 1126 "found\n"); 1110 1127 } 1111 1128 ··· 1120 1137 ep_out = ep; 1121 1138 ep_out->bmAttributes = USB_ENDPOINT_XFER_INT; 1122 1139 ep_out->bInterval = 1; 1123 - dev_dbg(&intf->dev, ": acceptable outbound endpoint " 1140 + dev_dbg(&intf->dev, "acceptable outbound endpoint " 1124 1141 "found\n"); 1125 1142 } 1126 1143 } 1127 1144 if (ep_in == NULL) { 1128 - dev_dbg(&intf->dev, ": inbound and/or endpoint not found\n"); 1145 + dev_dbg(&intf->dev, "inbound and/or endpoint not found\n"); 1129 1146 return -ENODEV; 1130 1147 } 1131 1148 ··· 1151 1168 ir->flags.tx_mask_inverted = tx_mask_inverted; 1152 1169 ir->flags.no_tx = mceusb_model[model].no_tx; 1153 1170 ir->model = model; 1154 - 1155 - init_ir_raw_event(&ir->rawir); 1156 1171 1157 1172 /* Saving usb interface data for use by the transmitter routine */ 1158 1173 ir->usb_ep_in = ep_in;