public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Lawrence Rust <lawrence@softsystem.co.uk>
To: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: [PATCH] Fix cx88 remote control input
Date: Fri, 08 Apr 2011 14:50:45 +0200	[thread overview]
Message-ID: <1302267045.1749.38.camel@gagarin> (raw)

This patch restores remote control input for cx2388x based boards on
Linux kernels >= 2.6.38.

After upgrading from Linux 2.6.37 to 2.6.38 I found that the remote
control input of my Hauppauge Nova-S plus was no longer functioning.  
I posted a question on this newsgroup and Mauro Carvalho Chehab gave
some helpful pointers as to the likely cause.

Turns out that there are 2 problems:

1. In the IR interrupt handler of cx88-input.c there's a 32-bit multiply
overflow which causes IR pulse durations to be incorrectly calculated.

2. The RC5 decoder appends the system code to the scancode and passes
the combination to rc_keydown().  Unfortunately, the combined value is
then forwarded to input_event() which then fails to recognise a valid
scancode and hence no input events are generated.

I note that in commit 2997137be8eba5bf9c07a24d5fda1f4225f9ca7d, which
introduced these changes, David Härdeman changed the IR sample frequency
to a supposed 4kHz.  However, the registers dealing with IR input are
undocumented in the cx2388x datasheets and there's no publicly available
information on them.  I have to ask the question why this change was
made as it is of no apparent benefit and could have unanticipated
consequences.  IMHO that change should also be reverted unless there is
evidence to substantiate it.

Signed off by: Lawrence Rust <lvr at softsystem dot co dot uk>

diff --git a/drivers/media/rc/ir-rc5-decoder.c b/drivers/media/rc/ir-rc5-decoder.c
index ebdba55..c4052da 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -144,10 +144,15 @@ again:
 			system   = (data->bits & 0x007C0) >> 6;
 			toggle   = (data->bits & 0x00800) ? 1 : 0;
 			command += (data->bits & 0x01000) ? 0 : 0x40;
-			scancode = system << 8 | command;
-
-			IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n",
-				   scancode, toggle);
+            /* Notes
+             * 1. Should filter unknown systems e.g Hauppauge use 0x1e or 0x1f
+             * 2. Don't include system in the scancode otherwise input_event()
+             *    doesn't recognise the scancode
+             */
+			scancode = command;
+
+			IR_dprintk(1, "RC5 scancode 0x%02x (system: 0x%02x toggle: %u)\n",
+				   scancode, system, toggle);
 		}
 
 		rc_keydown(dev, scancode, toggle);
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index c820e2f..7281db4 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -524,7 +524,7 @@ void cx88_ir_irq(struct cx88_core *core)
 	for (todo = 32; todo > 0; todo -= bits) {
 		ev.pulse = samples & 0x80000000 ? false : true;
 		bits = min(todo, 32U - fls(ev.pulse ? samples : ~samples));
-		ev.duration = (bits * NSEC_PER_SEC) / (1000 * ir_samplerate);
+		ev.duration = bits * (NSEC_PER_SEC / (1000 * ir_samplerate)); /* NB avoid 32-bit overflow */
 		ir_raw_event_store_with_filter(ir->dev, &ev);
 		samples <<= bits;
 	}



             reply	other threads:[~2011-04-08 12:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-08 12:50 Lawrence Rust [this message]
2011-04-08 14:32 ` [PATCH] Fix cx88 remote control input Jarod Wilson
2011-04-08 14:41 ` Jarod Wilson
2011-04-08 15:22   ` Lawrence Rust
2011-04-08 16:21     ` Jarod Wilson
2011-04-08 16:50       ` Lawrence Rust
2011-04-08 18:18         ` Jarod Wilson
2011-04-08 17:07       ` Devin Heitmueller
2011-04-08 18:00         ` Jarod Wilson
2011-04-08 18:38           ` Devin Heitmueller
2011-04-08 19:27             ` Jarod Wilson
2011-04-08 20:50               ` Andy Walls
2011-04-10  1:39                 ` Jarod Wilson
2011-04-10 23:08                   ` HVR-1250/CX23885 IR Rx (Re: [PATCH] Fix cx88 remote control input) Andy Walls
2011-06-28  0:38                     ` HVR-1250/CX23885 IR Rx Jarod Wilson
2011-06-28 10:30                       ` Andy Walls
2011-06-28 21:39                         ` Jarod Wilson
2011-06-28 22:32                           ` Andy Walls
2011-06-29  2:17                             ` Jarod Wilson
2011-06-29  3:54                               ` Andy Walls
2011-05-02 18:50 ` [PATCH] Fix cx88 remote control input Mauro Carvalho Chehab
2011-05-03  7:25   ` Lawrence Rust
2011-05-03 17:19     ` Jarod Wilson
2011-05-04 20:16       ` Mauro Carvalho Chehab
2011-05-04 20:36         ` Greg KH
2011-05-05  2:25           ` Mauro Carvalho Chehab
2011-05-05 20:35             ` Greg KH
2011-05-05 21:08             ` Patch "[media] cx88: Fix HVR4000 IR keymap" has been added to the 2.6.38-stable tree gregkh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302267045.1749.38.camel@gagarin \
    --to=lawrence@softsystem.co.uk \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox