linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Young <sean@mess.org>
To: linux-media@vger.kernel.org
Cc: "Marko Mäkelä" <marko.makela@iki.fi>
Subject: [PATCH 2/2] media: rtl28xxu: improve IR receiver
Date: Sat, 12 Feb 2022 16:32:19 +0000	[thread overview]
Message-ID: <704b3d7e5a7a95cbd5e4dfc25a41454e919aed95.1644683294.git.sean@mess.org> (raw)
In-Reply-To: <cover.1644683294.git.sean@mess.org>

This device presents an IR buffer, which can be read and cleared.
Clearing the buffer is racey with receiving IR, so wait until the IR
message is finished before clearing it.

This should minimize the chance of the buffer clear happening while
IR is being received, although we cannot avoid this completely.

Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 27 +++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 60e5153fcb24c..a83b1107fc7fd 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -1720,6 +1720,7 @@ static int rtl2832u_rc_query(struct dvb_usb_device *d)
 		{IR_RX_BUF_CTRL,         0x80, 0xff},
 		{IR_RX_CTRL,             0x80, 0xff},
 	};
+	u32 idle_length;
 
 	/* init remote controller */
 	if (!dev->rc_active) {
@@ -1770,6 +1771,28 @@ static int rtl2832u_rc_query(struct dvb_usb_device *d)
 	if (ret)
 		goto err;
 
+	dev_dbg(&d->intf->dev, "IR_RX_BUF=%*ph\n", len, buf);
+
+	/* if the receiver is not idle yet, do not process */
+	idle_length = 0;
+	if (len > 2) {
+		if (!(buf[len - 1] & 0x80))
+			idle_length += buf[len - 1];
+		if (!(buf[len - 2] & 0x80))
+			idle_length += buf[len - 2];
+	}
+
+	if (idle_length < 0xbf) {
+		/*
+		 * If the IR does not end with a space equal to the idle
+		 * length, then the IR is not complete yet and more is to
+		 * arrive shortly. If we process it and flush the buffer now,
+		 * we end up missing IR.
+		 */
+		dev_dbg(&d->intf->dev, "ignoring idle=%x\n", idle_length);
+		return 0;
+	}
+
 	/* let hw receive new code */
 	for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
 		ret = rtl28xxu_wr_reg_mask(d, refresh_tab[i].reg,
@@ -1807,10 +1830,10 @@ static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
 	rc->allowed_protos = RC_PROTO_BIT_ALL_IR_DECODER;
 	rc->driver_type = RC_DRIVER_IR_RAW;
 	rc->query = rtl2832u_rc_query;
-	rc->interval = 200;
+	rc->interval = 100;
 	/* we program idle len to 0xc0, set timeout to one less */
 	rc->rawir_timeout = 0xbf * 51;
-	rc->keyup_delay = MS_TO_US(210);
+	rc->keyup_delay = MS_TO_US(110);
 
 	return 0;
 }
-- 
2.34.1


  parent reply	other threads:[~2022-02-12 16:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-12 16:32 [PATCH 0/2] Fix rtl28xxu nec/rc5 receiver Sean Young
2022-02-12 16:32 ` [PATCH 1/2] media: rc-core: split IR timeout into rawir timeout and keyup delay Sean Young
2022-02-12 16:32 ` Sean Young [this message]
2022-06-26 12:33   ` [PATCH 2/2] media: rtl28xxu: improve IR receiver Marko Mäkelä
2022-06-27  5:00     ` Marko Mäkelä
2022-07-02  8:17       ` Sean Young
2022-06-27 10:53     ` Sean Young
2022-06-28  6:27       ` Marko Mäkelä
2022-07-02  8:14         ` Sean Young
2022-07-03 17:02           ` Marko Mäkelä
2022-07-04  7:21             ` Sean Young
2022-07-04  9:20               ` Marko Mäkelä
2022-07-04 10:00                 ` Sean Young
2022-07-04 19:04                   ` Marko Mäkelä
2022-07-05  7:25                     ` Sean Young
2022-07-05  8:48                       ` Marko Mäkelä
2022-07-05  9:26                         ` Sean Young

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=704b3d7e5a7a95cbd5e4dfc25a41454e919aed95.1644683294.git.sean@mess.org \
    --to=sean@mess.org \
    --cc=linux-media@vger.kernel.org \
    --cc=marko.makela@iki.fi \
    /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;
as well as URLs for NNTP newsgroup(s).