[2/3] mceusb: fix up reporting of trailing space

Message ID 20101029030810.GC17238@redhat.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Jarod Wilson Oct. 29, 2010, 3:08 a.m. UTC
  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. Both are happy again with this change, which
starts accumulating data upon seeing an 0x7f space, and then stores it
when we see the next non-space, non-0x7f space, or an 0x80 end of signal
command. To get to that final 0x80 properly, we also need to support
proper parsing of 0x9f 0x01 commands, support for which is also added.

Also remove an obsolete include, some stray colon-space pairs from
prior to conversion to dev_foo printk macros and a magic number.

Signed-off-by: Jarod Wilson <jarod@redhat.com>
---
 drivers/media/IR/mceusb.c |   39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)
  

Comments

David Härdeman Oct. 29, 2010, 7:21 p.m. UTC | #1
On Thu, Oct 28, 2010 at 11:08:10PM -0400, Jarod Wilson wrote:
> 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. Both are happy again with this change, which
> starts accumulating data upon seeing an 0x7f space, and then stores it
> when we see the next non-space, non-0x7f space, or an 0x80 end of signal
> command. To get to that final 0x80 properly, we also need to support
> proper parsing of 0x9f 0x01 commands, support for which is also added.

I think the driver could be further simplified by using 
ir_raw_event_store_with_filter(), right?
  
Jarod Wilson Oct. 29, 2010, 7:36 p.m. UTC | #2
On Fri, Oct 29, 2010 at 09:21:21PM +0200, David Härdeman wrote:
> On Thu, Oct 28, 2010 at 11:08:10PM -0400, Jarod Wilson wrote:
> > 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. Both are happy again with this change, which
> > starts accumulating data upon seeing an 0x7f space, and then stores it
> > when we see the next non-space, non-0x7f space, or an 0x80 end of signal
> > command. To get to that final 0x80 properly, we also need to support
> > proper parsing of 0x9f 0x01 commands, support for which is also added.
> 
> I think the driver could be further simplified by using 
> ir_raw_event_store_with_filter(), right?

Hm, yeah, it probably would. Hadn't even thought to look at that. I'll
give that a closer look...
  
Jarod Wilson Nov. 2, 2010, 9:12 p.m. UTC | #3
On Fri, Oct 29, 2010 at 09:21:21PM +0200, David Härdeman wrote:
> On Thu, Oct 28, 2010 at 11:08:10PM -0400, Jarod Wilson wrote:
> > 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. Both are happy again with this change, which
> > starts accumulating data upon seeing an 0x7f space, and then stores it
> > when we see the next non-space, non-0x7f space, or an 0x80 end of signal
> > command. To get to that final 0x80 properly, we also need to support
> > proper parsing of 0x9f 0x01 commands, support for which is also added.
> 
> I think the driver could be further simplified by using 
> ir_raw_event_store_with_filter(), right?

And in fact, it is. I've got a new series of patches redone atop your
rc-core patch series that includes usage of _with_filter in mceusb.

http://git.kernel.org/?p=linux/kernel/git/jarod/linux-2.6-ir.git;a=shortlog;h=refs/heads/staging

And more specifically, the update of this patch:

http://git.kernel.org/?p=linux/kernel/git/jarod/linux-2.6-ir.git;a=commitdiff;h=bc3d1300cd2d51dc8d877be343382d8932320dfc

Still a bit of testing to do before I send v2 off to the list, plus I'd
like to know where we're at w/your patches first wrt getting them
committed, just in case I need to rework them slightly.
  
David Härdeman Nov. 3, 2010, 12:15 p.m. UTC | #4
On Tue, 2 Nov 2010 17:12:14 -0400, Jarod Wilson <jarod@redhat.com> wrote:
> On Fri, Oct 29, 2010 at 09:21:21PM +0200, David Härdeman wrote:
>> I think the driver could be further simplified by using 
>> ir_raw_event_store_with_filter(), right?
> 
> And in fact, it is. I've got a new series of patches redone atop your
> rc-core patch series that includes usage of _with_filter in mceusb.

From a quick check, I think the entire PARSE_IRDATA block in
mceusb_process_ir_data() could be simplified to:

case PARSE_IRDATA:
    ir->rem--;
    rawir.pulse = !!(ir->buf_in[i] & MCE_PULSE_BIT);
    rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK)
                      * MCE_TIME_UNIT * 1000;
    ir_raw_event_store_with_filter(ir->rc, &rawir);
    break;

And you can then remove "struct ir_raw_event rawir" from struct
mceusb_dev.
  
Jarod Wilson Nov. 3, 2010, 7:48 p.m. UTC | #5
On Wed, Nov 03, 2010 at 01:15:30PM +0100, David Härdeman wrote:
> On Tue, 2 Nov 2010 17:12:14 -0400, Jarod Wilson <jarod@redhat.com> wrote:
> > On Fri, Oct 29, 2010 at 09:21:21PM +0200, David Härdeman wrote:
> >> I think the driver could be further simplified by using 
> >> ir_raw_event_store_with_filter(), right?
> > 
> > And in fact, it is. I've got a new series of patches redone atop your
> > rc-core patch series that includes usage of _with_filter in mceusb.
> 
> From a quick check, I think the entire PARSE_IRDATA block in
> mceusb_process_ir_data() could be simplified to:
> 
> case PARSE_IRDATA:
>     ir->rem--;
>     rawir.pulse = !!(ir->buf_in[i] & MCE_PULSE_BIT);
>     rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK)
>                       * MCE_TIME_UNIT * 1000;
>     ir_raw_event_store_with_filter(ir->rc, &rawir);
>     break;
> 
> And you can then remove "struct ir_raw_event rawir" from struct
> mceusb_dev.

Once again, I think you're correct. :) I'll give this a spin with a few
mceusb devices, but it does certainly look like that'll work, now that
we're using _with_filter.
  

Patch

diff --git a/drivers/media/IR/mceusb.c b/drivers/media/IR/mceusb.c
index e453c6b..a05dec7 100644
--- a/drivers/media/IR/mceusb.c
+++ b/drivers/media/IR/mceusb.c
@@ -38,7 +38,6 @@ 
 #include <linux/usb.h>
 #include <linux/input.h>
 #include <media/ir-core.h>
-#include <media/ir-common.h>
 
 #define DRIVER_VERSION	"1.91"
 #define DRIVER_AUTHOR	"Jarod Wilson <jarod@wilsonet.com>"
@@ -74,6 +73,7 @@ 
 #define MCE_PACKET_LENGTH_MASK	0x1f /* Packet length mask */
 
 /* Sub-commands, which follow MCE_COMMAND_HEADER or MCE_HW_CMD_HEADER */
+#define MCE_CMD_SIG_END		0x01	/* End of signal */
 #define MCE_CMD_PING		0x03	/* Ping device */
 #define MCE_CMD_UNKNOWN		0x04	/* Unknown */
 #define MCE_CMD_UNKNOWN2	0x05	/* Unknown */
@@ -422,6 +422,7 @@  static int mceusb_cmdsize(u8 cmd, u8 subcmd)
 		case MCE_CMD_G_RXSENSOR:
 			datasize = 2;
 			break;
+		case MCE_CMD_SIG_END:
 		case MCE_CMD_S_TXMASK:
 		case MCE_CMD_S_RXSENSOR:
 			datasize = 1;
@@ -502,6 +503,9 @@  static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
 		break;
 	case MCE_COMMAND_HEADER:
 		switch (subcmd) {
+		case MCE_CMD_SIG_END:
+			dev_info(dev, "End of signal\n");
+			break;
 		case MCE_CMD_PING:
 			dev_info(dev, "Ping\n");
 			break;
@@ -539,7 +543,7 @@  static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
 			if (len == 2)
 				dev_info(dev, "Get receive sensor\n");
 			else
-				dev_info(dev, "Received pulse count is %d\n",
+				dev_info(dev, "Remaining pulse count is %d\n",
 					 ((data1 << 8) | data2));
 			break;
 		case MCE_RSP_CMD_INVALID:
@@ -763,7 +767,7 @@  static int mceusb_set_tx_carrier(void *priv, u32 carrier)
 
 		if (carrier == 0) {
 			ir->carrier = carrier;
-			cmdbuf[2] = 0x01;
+			cmdbuf[2] = MCE_CMD_SIG_END;
 			cmdbuf[3] = MCE_IRDATA_TRAILER;
 			dev_dbg(ir->dev, "%s: disabling carrier "
 				"modulation\n", __func__);
@@ -823,8 +827,11 @@  static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
 					ir->rawir.duration = rawir.duration;
 					ir->rawir.pulse = rawir.pulse;
 				}
-				if (ir->rem)
-					break;
+				if (!ir->rem)
+					ir->parser_state = CMD_HEADER;
+				dev_dbg(ir->dev, "Accumulating %d worth of "
+					"space\n", rawir.duration);
+				break;
 			}
 			rawir.duration += ir->rawir.duration;
 			ir->rawir.duration = 0;
@@ -853,14 +860,14 @@  static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
 			mceusb_dev_printdata(ir, ir->buf_in, i, ir->rem + 1, false);
 			if (ir->rem) {
 				ir->parser_state = PARSE_IRDATA;
-				break;
+			} else if (ir->rawir.duration) {
+				/* this means we've encounter an 0x80 pkt,
+				 * which means "end of signal" */
+				dev_dbg(ir->dev, "Storing final space with "
+					"duration %d\n", ir->rawir.duration);
+				ir_raw_event_store(ir->idev, &ir->rawir);
+				ir->rawir.duration = 0;
 			}
-			/*
-			 * a package with len=0 (e. g. 0x80) means end of
-			 * data. We could use it to do the call to
-			 * ir_raw_event_handle(). For now, we don't need to
-			 * use it.
-			 */
 			break;
 		}
 
@@ -1092,7 +1099,7 @@  static int __devinit mceusb_dev_probe(struct usb_interface *intf,
 	bool tx_mask_inverted;
 	bool is_polaris;
 
-	dev_dbg(&intf->dev, ": %s called\n", __func__);
+	dev_dbg(&intf->dev, "%s called\n", __func__);
 
 	idesc  = intf->cur_altsetting;
 
@@ -1122,7 +1129,7 @@  static int __devinit mceusb_dev_probe(struct usb_interface *intf,
 			ep_in = ep;
 			ep_in->bmAttributes = USB_ENDPOINT_XFER_INT;
 			ep_in->bInterval = 1;
-			dev_dbg(&intf->dev, ": acceptable inbound endpoint "
+			dev_dbg(&intf->dev, "acceptable inbound endpoint "
 				"found\n");
 		}
 
@@ -1137,12 +1144,12 @@  static int __devinit mceusb_dev_probe(struct usb_interface *intf,
 			ep_out = ep;
 			ep_out->bmAttributes = USB_ENDPOINT_XFER_INT;
 			ep_out->bInterval = 1;
-			dev_dbg(&intf->dev, ": acceptable outbound endpoint "
+			dev_dbg(&intf->dev, "acceptable outbound endpoint "
 				"found\n");
 		}
 	}
 	if (ep_in == NULL) {
-		dev_dbg(&intf->dev, ": inbound and/or endpoint not found\n");
+		dev_dbg(&intf->dev, "inbound and/or endpoint not found\n");
 		return -ENODEV;
 	}