From patchwork Tue Nov 10 09:15:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Young X-Patchwork-Id: 11893627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B866C388F7 for ; Tue, 10 Nov 2020 09:18:00 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1569A20780 for ; Tue, 10 Nov 2020 09:18:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="zwP1rseo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mess.org header.i=@mess.org header.b="JtLQfxd7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1569A20780 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mess.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=pCFlQx6KhFAITZ74jDpEOoPsKUrx3GbKslpjHA7wiWI=; b=zwP1rseo0fzBBQeT04LxFuyDFi 7Z2YYsV9riRjR4QMmBfXBUTQvVNERrV2dgL/Cmk/XfBzbVOreCJ8ErPMzsvV1JDXI3XsjaMFE4vi0 NULYvh3Y+Pmax2bcRhAmcYubBxffTk3rHaxZOODHzgaSKOqsh/uXXeZYXkyYAkKMumXshULk7x55a kCFuY5D3Y4y2MhiLApAl2XeSFGtIDc+4Qr20UT3HMCSJoYXE/tKOcOBF2qv7DIPLEI5gbJfe+oNKl ArQAnYBJKh9m1RoFFpwlJSMu3+Xj/Z1XU7zOMoDn1HH0/BKvGPm0k5UPdDyNtwhQeErq2fznehqjr lnhQmQqw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcPl5-0001v6-4D; Tue, 10 Nov 2020 09:16:11 +0000 Received: from gofer.mess.org ([88.97.38.141]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcPky-0001tx-RZ for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 09:16:09 +0000 Received: by gofer.mess.org (Postfix, from userid 1000) id CEF41C6398; Tue, 10 Nov 2020 09:15:57 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mess.org; s=2020; t=1604999757; bh=oo1sXhCURed1LSMO71Y9DGDuLwiNpyS266VJLDVsDQE=; h=From:To:Cc:Subject:Date:From; b=JtLQfxd7ZM7m8KsFeoZm4pVWx6Lvu2SVx4zhfBgWbfMdkv7bWHkj6mzGL8MikR/FB 4D9/ilCpepHZ7HAcQzZ7o4GlS5p3bFar1N51hqdqjptcSxHS3rTj3+1flBb9IzPXKC XeqyRDRJ3472pWBdjkmlBJZ0M0rsj4Ly+dpv5/b+GginUpn3kbabCl3+vtm/4HeV0Z 9xt3Jeijt54MYPQcqy0H3VVOE9nDeV9Yf0yKhZCk6/skfhKuHB2TlT39SC17mgqDD9 +2+G9g1f6gx7TrGVyuD8moTv7NthnTyp6I6fWGaDkInQEf92RhJpdSBWFU02/twAT0 izEbkleRUzUiA== From: Sean Young To: linux-media@vger.kernel.org, Chen-Yu Tsai , Maxime Ripard , linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] media: sunxi-cir: ensure IR is handled when it is continuous Date: Tue, 10 Nov 2020 09:15:56 +0000 Message-Id: <20201110091557.25680-1-sean@mess.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_041605_033894_3E171FE9 X-CRM114-Status: GOOD ( 12.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Verkuil , stable@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If a user holds a button down on a remote, then no ir idle interrupt will be generated until the user releases the button, depending on how quickly the remote repeats. No IR is processed until that point, which means that holding down a button may not do anything. This also resolves an issue on a Cubieboard 1 where the IR receiver is picking up ambient infrared as IR and spews out endless "rc rc0: IR event FIFO is full!" messages unless you choose to live in the dark. Cc: stable@vger.kernel.org Reported-by: Hans Verkuil Signed-off-by: Sean Young Tested-by: Hans Verkuil --- drivers/media/rc/sunxi-cir.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c index ddee6ee37bab1..4afc5895bee74 100644 --- a/drivers/media/rc/sunxi-cir.c +++ b/drivers/media/rc/sunxi-cir.c @@ -137,6 +137,8 @@ static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id) } else if (status & REG_RXSTA_RPE) { ir_raw_event_set_idle(ir->rc, true); ir_raw_event_handle(ir->rc); + } else { + ir_raw_event_handle(ir->rc); } spin_unlock(&ir->ir_lock); From patchwork Tue Nov 10 09:15:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Young X-Patchwork-Id: 11893625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1609EC388F7 for ; Tue, 10 Nov 2020 09:16:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E8E52065E for ; Tue, 10 Nov 2020 09:16:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Xc+7tNIp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mess.org header.i=@mess.org header.b="KQVWnnw5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E8E52065E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=mess.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fLO5qYP/8MIw+53/DNHC93AwwnRkan7+8uaEmLIcE6s=; b=Xc+7tNIpcZM1TOJT+bRMrdGY31 Cd9rRlyvGMnhJNBabZL9Hp7Jx8jVxUvYZ6zSmEfUhryGEYE3Vr4qZ9OBXeq6zRCT0LksdYDrt1mrw I4je9oJgRh1d/asUMM6F3ZNMNUEopn/2v5cs13ToKDcBGbVxWSCJBTCcYpg2Fgw5J+6RQZyfvVnBq 7tLtNs4JACparRaAFL4MdA7nG5yH9TRAE6FhiXNuCof8T4g1iMFu+L1lB36SOPzylBLwm7tCejRUU 5iogDvgQGH7/BTSkLamdjsY9mWuzVQNyc7Opptl4JtEq8ucHrw38376Alh2wDpuUJbJYym9Hoyg7J uVzoDkQQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcPl6-0001vN-O7; Tue, 10 Nov 2020 09:16:12 +0000 Received: from gofer.mess.org ([88.97.38.141]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcPky-0001tw-Pg for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 09:16:09 +0000 Received: by gofer.mess.org (Postfix, from userid 1000) id EB923C6389; Tue, 10 Nov 2020 09:15:57 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mess.org; s=2020; t=1604999757; bh=tDnE0GizgWhHBHXSTNsrdayXMk2UGr+MnzFQqwiAo9A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KQVWnnw5+R8DQxEGKXFG96hqFSPAWiXpIJ6znsCMa9a9x8avvRQFlbLxeB4al5Ndn F+q4dPskc/rsoYknhE6efwG0O97nGyZAaTz0T3hqO5yTF/wrWDxMK0T+ePY/AX3Uqf 94SrqeKaBqxIlaMub3Ef1gMdSjbgjYHH1N3riEox+UkPq7mthU4+Z+L4dpwFqo5Q3Q gYw090XfJZRic4w5G0ajdHDsLsLTzUdGi0hVzmIFA95/kfIIBP5AC5A0YdubUdlLf2 df9FAX7rbLVU5mIsUfu92qEew0INB+FWR0NcyQ6l3CZFzAxTYEbEq8Q06gjYFh0dj9 FI9UuLZw859Zw== From: Sean Young To: linux-media@vger.kernel.org, Chen-Yu Tsai , Maxime Ripard , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] media: sunxi-cir: allow timeout to be set at runtime Date: Tue, 10 Nov 2020 09:15:57 +0000 Message-Id: <20201110091557.25680-2-sean@mess.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110091557.25680-1-sean@mess.org> References: <20201110091557.25680-1-sean@mess.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_041604_946105_0F66F88A X-CRM114-Status: GOOD ( 14.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This allows the timeout to be set with the LIRC_SET_REC_TIMEOUT ioctl. The timeout was hardcoded at just over 20ms, but returned 120ms when queried with the LIRC_GET_REC_TIMEOUT ioctl. This also ensures the idle threshold is set correctly with a base clock other than 8000000Mhz. Signed-off-by: Sean Young Acked-by: Maxime Ripard --- drivers/media/rc/sunxi-cir.c | 46 +++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c index 4afc5895bee74..3c25db25e55c6 100644 --- a/drivers/media/rc/sunxi-cir.c +++ b/drivers/media/rc/sunxi-cir.c @@ -73,10 +73,6 @@ #define SUNXI_IR_BASE_CLK 8000000 /* Noise threshold in samples */ #define SUNXI_IR_RXNOISE 1 -/* Idle Threshold in samples */ -#define SUNXI_IR_RXIDLE 20 -/* Time after which device stops sending data in ms */ -#define SUNXI_IR_TIMEOUT 120 /** * struct sunxi_ir_quirks - Differences between SoC variants. @@ -146,6 +142,39 @@ static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id) return IRQ_HANDLED; } +/* Convert idle threshold to usec */ +static unsigned int sunxi_ithr_to_usec(unsigned int base_clk, unsigned int ithr) +{ + return (USEC_PER_SEC * (ithr + 1)) / (base_clk / (128 * 64)); +} + +/* Convert usec to idle threshold */ +static unsigned int sunxi_usec_to_ithr(unsigned int base_clk, unsigned int usec) +{ + return ((base_clk / (128 * 64)) * usec) / USEC_PER_SEC; +} + +static int sunxi_ir_set_timeout(struct rc_dev *rc_dev, unsigned int timeout) +{ + struct sunxi_ir *ir = rc_dev->priv; + unsigned int base_clk = clk_get_rate(ir->clk); + unsigned long flags; + + unsigned int ithr = sunxi_usec_to_ithr(base_clk, timeout); + + dev_dbg(rc_dev->dev.parent, "setting idle threshold to %u\n", ithr); + + spin_lock_irqsave(&ir->ir_lock, flags); + /* Set noise threshold and idle threshold */ + writel(REG_CIR_NTHR(SUNXI_IR_RXNOISE) | REG_CIR_ITHR(ithr), + ir->base + SUNXI_IR_CIR_REG); + spin_unlock_irqrestore(&ir->ir_lock, flags); + + rc_dev->timeout = sunxi_ithr_to_usec(base_clk, ithr); + + return 0; +} + static int sunxi_ir_probe(struct platform_device *pdev) { int ret = 0; @@ -242,9 +271,11 @@ static int sunxi_ir_probe(struct platform_device *pdev) ir->rc->map_name = ir->map_name ?: RC_MAP_EMPTY; ir->rc->dev.parent = dev; ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; - /* Frequency after IR internal divider with sample period in ns */ + /* Frequency after IR internal divider with sample period in us */ ir->rc->rx_resolution = (USEC_PER_SEC / (b_clk_freq / 64)); - ir->rc->timeout = MS_TO_US(SUNXI_IR_TIMEOUT); + ir->rc->min_timeout = sunxi_ithr_to_usec(b_clk_freq, 0); + ir->rc->max_timeout = sunxi_ithr_to_usec(b_clk_freq, 255); + ir->rc->s_timeout = sunxi_ir_set_timeout; ir->rc->driver_name = SUNXI_IR_DEV; ret = rc_register_device(ir->rc); @@ -272,8 +303,7 @@ static int sunxi_ir_probe(struct platform_device *pdev) writel(REG_CTL_MD, ir->base+SUNXI_IR_CTL_REG); /* Set noise threshold and idle threshold */ - writel(REG_CIR_NTHR(SUNXI_IR_RXNOISE)|REG_CIR_ITHR(SUNXI_IR_RXIDLE), - ir->base + SUNXI_IR_CIR_REG); + sunxi_ir_set_timeout(ir->rc, IR_DEFAULT_TIMEOUT); /* Invert Input Signal */ writel(REG_RXCTL_RPPI, ir->base + SUNXI_IR_RXCTL_REG);