From patchwork Wed May 6 14:01:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Young X-Patchwork-Id: 11531257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6EA6C92A for ; Wed, 6 May 2020 14:01:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5EC042073A for ; Wed, 6 May 2020 14:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728854AbgEFOBq (ORCPT ); Wed, 6 May 2020 10:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727084AbgEFOBq (ORCPT ); Wed, 6 May 2020 10:01:46 -0400 Received: from gofer.mess.org (gofer.mess.org [IPv6:2a02:8011:d000:212::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 828B4C061A0F for ; Wed, 6 May 2020 07:01:46 -0700 (PDT) Received: by gofer.mess.org (Postfix, from userid 1000) id CBA40C6372; Wed, 6 May 2020 15:01:44 +0100 (BST) From: Sean Young To: linux-media@vger.kernel.org Subject: [PATCH v2 1/2] media: gpio-ir-tx: improve precision of transmitted signal due to scheduling Date: Wed, 6 May 2020 15:01:43 +0100 Message-Id: <20200506140144.19778-1-sean@mess.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org usleep_range() may take longer than the max argument due to scheduling, especially under load. This is causing random errors in the transmitted IR. Remove the usleep_range() in favour of busy-looping with udelay(). Signed-off-by: Sean Young --- drivers/media/rc/gpio-ir-tx.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/media/rc/gpio-ir-tx.c b/drivers/media/rc/gpio-ir-tx.c index 18ca12d78314c..66703989ae185 100644 --- a/drivers/media/rc/gpio-ir-tx.c +++ b/drivers/media/rc/gpio-ir-tx.c @@ -79,13 +79,8 @@ static int gpio_ir_tx(struct rc_dev *dev, unsigned int *txbuf, // space edge = ktime_add_us(edge, txbuf[i]); delta = ktime_us_delta(edge, ktime_get()); - if (delta > 10) { - spin_unlock_irqrestore(&gpio_ir->lock, flags); - usleep_range(delta, delta + 10); - spin_lock_irqsave(&gpio_ir->lock, flags); - } else if (delta > 0) { + if (delta > 0) udelay(delta); - } } else { // pulse ktime_t last = ktime_add_us(edge, txbuf[i]); From patchwork Wed May 6 14:01:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Young X-Patchwork-Id: 11531259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9901914B4 for ; Wed, 6 May 2020 14:01:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 809F820746 for ; Wed, 6 May 2020 14:01:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728858AbgEFOBq (ORCPT ); Wed, 6 May 2020 10:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728667AbgEFOBq (ORCPT ); Wed, 6 May 2020 10:01:46 -0400 Received: from gofer.mess.org (gofer.mess.org [IPv6:2a02:8011:d000:212::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E473C061A10 for ; Wed, 6 May 2020 07:01:46 -0700 (PDT) Received: by gofer.mess.org (Postfix, from userid 1000) id DA2DFC63F1; Wed, 6 May 2020 15:01:44 +0100 (BST) From: Sean Young To: linux-media@vger.kernel.org Subject: [PATCH v2 2/2] media: gpio-ir-tx: allow transmission without carrier Date: Wed, 6 May 2020 15:01:44 +0100 Message-Id: <20200506140144.19778-2-sean@mess.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506140144.19778-1-sean@mess.org> References: <20200506140144.19778-1-sean@mess.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Some IR protocols do not use a carrier. Signed-off-by: Sean Young --- drivers/media/rc/gpio-ir-tx.c | 45 ++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/drivers/media/rc/gpio-ir-tx.c b/drivers/media/rc/gpio-ir-tx.c index 66703989ae185..156abebcce152 100644 --- a/drivers/media/rc/gpio-ir-tx.c +++ b/drivers/media/rc/gpio-ir-tx.c @@ -42,18 +42,40 @@ static int gpio_ir_tx_set_carrier(struct rc_dev *dev, u32 carrier) { struct gpio_ir *gpio_ir = dev->priv; - if (!carrier) - return -EINVAL; - gpio_ir->carrier = carrier; return 0; } -static int gpio_ir_tx(struct rc_dev *dev, unsigned int *txbuf, - unsigned int count) +static void gpio_ir_tx_unmodulated(struct gpio_ir *gpio_ir, uint *txbuf, + uint count) +{ + unsigned long flags; + ktime_t edge; + s32 delta; + int i; + + spin_lock_irqsave(&gpio_ir->lock, flags); + + edge = ktime_get(); + + for (i = 0; i < count; i++) { + gpiod_set_value(gpio_ir->gpio, !(i % 2)); + + edge = ktime_add_us(edge, txbuf[i]); + delta = ktime_us_delta(edge, ktime_get()); + if (delta > 0) + udelay(delta); + } + + gpiod_set_value(gpio_ir->gpio, 0); + + spin_unlock_irqrestore(&gpio_ir->lock, flags); +} + +static void gpio_ir_tx_modulated(struct gpio_ir *gpio_ir, uint *txbuf, + uint count) { - struct gpio_ir *gpio_ir = dev->priv; unsigned long flags; ktime_t edge; /* @@ -105,6 +127,17 @@ static int gpio_ir_tx(struct rc_dev *dev, unsigned int *txbuf, } spin_unlock_irqrestore(&gpio_ir->lock, flags); +} + +static int gpio_ir_tx(struct rc_dev *dev, unsigned int *txbuf, + unsigned int count) +{ + struct gpio_ir *gpio_ir = dev->priv; + + if (gpio_ir->carrier) + gpio_ir_tx_modulated(gpio_ir, txbuf, count); + else + gpio_ir_tx_unmodulated(gpio_ir, txbuf, count); return count; }