All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] media: ir_toy: print firmwware version in correct format
@ 2021-09-14 15:18 Sean Young
  2021-09-14 15:18 ` [PATCH 2/4] media: ir_toy: deal with residual irdata before expected response Sean Young
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sean Young @ 2021-09-14 15:18 UTC (permalink / raw)
  To: linux-media; +Cc: Georgi Bakalski

A value of 25 means firmware version 2.5.

Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/rc/ir_toy.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c
index b0dc19d36ac9..45d39b6e49c0 100644
--- a/drivers/media/rc/ir_toy.c
+++ b/drivers/media/rc/ir_toy.c
@@ -440,8 +440,9 @@ static int irtoy_probe(struct usb_interface *intf,
 	if (err)
 		goto free_rcdev;
 
-	dev_info(irtoy->dev, "version: hardware %u, firmware %u, protocol %u",
-		 irtoy->hw_version, irtoy->sw_version, irtoy->proto_version);
+	dev_info(irtoy->dev, "version: hardware %u, firmware %u.%u, protocol %u",
+		 irtoy->hw_version, irtoy->sw_version / 10,
+		 irtoy->sw_version % 10, irtoy->proto_version);
 
 	if (irtoy->sw_version < MIN_FW_VERSION) {
 		dev_err(irtoy->dev, "need firmware V%02u or higher",
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] media: ir_toy: deal with residual irdata before expected response
  2021-09-14 15:18 [PATCH 1/4] media: ir_toy: print firmwware version in correct format Sean Young
@ 2021-09-14 15:18 ` Sean Young
  2021-09-14 15:18 ` [PATCH 3/4] media: ir_toy: do not resubmit broken urb Sean Young
  2021-09-14 15:18 ` [PATCH 4/4] media: ir_toy: prevent device from hanging during transmit Sean Young
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Young @ 2021-09-14 15:18 UTC (permalink / raw)
  To: linux-media; +Cc: Georgi Bakalski, stable

After sending the start transmit command, the device is supposed to
respond with the length of the buffer which can be sent. There might
be some residual ir data there.

Cc: stable@vger.kernel.org
Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/rc/ir_toy.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c
index 45d39b6e49c0..2b7c8bba4d6a 100644
--- a/drivers/media/rc/ir_toy.c
+++ b/drivers/media/rc/ir_toy.c
@@ -122,6 +122,7 @@ static void irtoy_response(struct irtoy *irtoy, u32 len)
 				len, irtoy->in);
 		}
 		break;
+	case STATE_COMMAND_NO_RESP:
 	case STATE_IRDATA: {
 		struct ir_raw_event rawir = { .pulse = irtoy->pulse };
 		__be16 *in = (__be16 *)irtoy->in;
@@ -167,10 +168,8 @@ static void irtoy_response(struct irtoy *irtoy, u32 len)
 			int err;
 
 			if (len != 1 || space > MAX_PACKET || space == 0) {
-				dev_err(irtoy->dev, "packet length expected: %*phN\n",
+				dev_dbg(irtoy->dev, "packet length expected: %*phN\n",
 					len, irtoy->in);
-				irtoy->state = STATE_IRDATA;
-				complete(&irtoy->command_done);
 				break;
 			}
 
@@ -194,9 +193,6 @@ static void irtoy_response(struct irtoy *irtoy, u32 len)
 			irtoy->tx_len -= buf_len;
 		}
 		break;
-	case STATE_COMMAND_NO_RESP:
-		dev_err(irtoy->dev, "unexpected response to reset: %*phN\n",
-			len, irtoy->in);
 	}
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] media: ir_toy: do not resubmit broken urb
  2021-09-14 15:18 [PATCH 1/4] media: ir_toy: print firmwware version in correct format Sean Young
  2021-09-14 15:18 ` [PATCH 2/4] media: ir_toy: deal with residual irdata before expected response Sean Young
@ 2021-09-14 15:18 ` Sean Young
  2021-09-14 15:18 ` [PATCH 4/4] media: ir_toy: prevent device from hanging during transmit Sean Young
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Young @ 2021-09-14 15:18 UTC (permalink / raw)
  To: linux-media; +Cc: Georgi Bakalski

This causes the same urb to resubmitted continuously, hogging up a cpu.

Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/rc/ir_toy.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c
index 2b7c8bba4d6a..d2d9346eb8f5 100644
--- a/drivers/media/rc/ir_toy.c
+++ b/drivers/media/rc/ir_toy.c
@@ -213,10 +213,20 @@ static void irtoy_in_callback(struct urb *urb)
 	struct irtoy *irtoy = urb->context;
 	int ret;
 
-	if (urb->status == 0)
+	switch (urb->status) {
+	case 0:
 		irtoy_response(irtoy, urb->actual_length);
-	else
+		break;
+	case -ECONNRESET:
+	case -ENOENT:
+	case -ESHUTDOWN:
+	case -EPROTO:
+	case -EPIPE:
+		usb_unlink_urb(urb);
+		return;
+	default:
 		dev_dbg(irtoy->dev, "in urb status: %d\n", urb->status);
+	}
 
 	ret = usb_submit_urb(urb, GFP_ATOMIC);
 	if (ret && ret != -ENODEV)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] media: ir_toy: prevent device from hanging during transmit
  2021-09-14 15:18 [PATCH 1/4] media: ir_toy: print firmwware version in correct format Sean Young
  2021-09-14 15:18 ` [PATCH 2/4] media: ir_toy: deal with residual irdata before expected response Sean Young
  2021-09-14 15:18 ` [PATCH 3/4] media: ir_toy: do not resubmit broken urb Sean Young
@ 2021-09-14 15:18 ` Sean Young
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Young @ 2021-09-14 15:18 UTC (permalink / raw)
  To: linux-media; +Cc: Georgi Bakalski, stable

If the IR Toy is receiving IR while a transmit is done, it may end up
hanging. We can prevent this from happening by re-entering sample mode
just before issuing the transmit command.

Link: https://github.com/bengtmartensson/HarcHardware/discussions/25
Cc: stable@vger.kernel.org
Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/rc/ir_toy.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c
index d2d9346eb8f5..71aced52248f 100644
--- a/drivers/media/rc/ir_toy.c
+++ b/drivers/media/rc/ir_toy.c
@@ -26,6 +26,7 @@ static const u8 COMMAND_VERSION[] = { 'v' };
 // End transmit and repeat reset command so we exit sump mode
 static const u8 COMMAND_RESET[] = { 0xff, 0xff, 0, 0, 0, 0, 0 };
 static const u8 COMMAND_SMODE_ENTER[] = { 's' };
+static const u8 COMMAND_SMODE_EXIT[] = { 0 };
 static const u8 COMMAND_TXSTART[] = { 0x26, 0x24, 0x25, 0x03 };
 
 #define REPLY_XMITCOUNT 't'
@@ -317,12 +318,30 @@ static int irtoy_tx(struct rc_dev *rc, uint *txbuf, uint count)
 		buf[i] = cpu_to_be16(v);
 	}
 
-	buf[count] = cpu_to_be16(0xffff);
+	buf[count] = 0xffff;
 
 	irtoy->tx_buf = buf;
 	irtoy->tx_len = size;
 	irtoy->emitted = 0;
 
+	// There is an issue where if the unit is receiving IR while the
+	// first TXSTART command is sent, the device might end up hanging
+	// with its led on. It does not respond to any command when this
+	// happens. To work around this, re-enter sample mode.
+	err = irtoy_command(irtoy, COMMAND_SMODE_EXIT,
+			    sizeof(COMMAND_SMODE_EXIT), STATE_COMMAND_NO_RESP);
+	if (err) {
+		dev_err(irtoy->dev, "exit sample mode: %d\n", err);
+		return err;
+	}
+
+	err = irtoy_command(irtoy, COMMAND_SMODE_ENTER,
+			    sizeof(COMMAND_SMODE_ENTER), STATE_COMMAND);
+	if (err) {
+		dev_err(irtoy->dev, "enter sample mode: %d\n", err);
+		return err;
+	}
+
 	err = irtoy_command(irtoy, COMMAND_TXSTART, sizeof(COMMAND_TXSTART),
 			    STATE_TX);
 	kfree(buf);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-14 15:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 15:18 [PATCH 1/4] media: ir_toy: print firmwware version in correct format Sean Young
2021-09-14 15:18 ` [PATCH 2/4] media: ir_toy: deal with residual irdata before expected response Sean Young
2021-09-14 15:18 ` [PATCH 3/4] media: ir_toy: do not resubmit broken urb Sean Young
2021-09-14 15:18 ` [PATCH 4/4] media: ir_toy: prevent device from hanging during transmit Sean Young

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.