Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp676502pxb; Tue, 5 Apr 2022 18:20:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFjd2I17bykySMVX+TDM7CH8ouijVn2+Cwg2WqFWDc5/i1PdXw635UXesxg3WgOILN+xRD X-Received: by 2002:a17:907:e8a:b0:6e7:f3cb:61eb with SMTP id ho10-20020a1709070e8a00b006e7f3cb61ebmr6064614ejc.247.1649208021843; Tue, 05 Apr 2022 18:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649208021; cv=none; d=google.com; s=arc-20160816; b=pVxO2CieSc1TX8UmPrx7B704OXp9Xppx1WIs48nXVd9nUntClf4LQl+hrQoeXKlZHY sxSjklc45dBMuTZABubrvhmWqrPbikuWs60ohwlXC73U/n2nqtT8E9+9fmxQbCy1yey8 VEWdmgPCkKb1Wy3OOEhT3pKTq7sPU1Wi60wikTHwQ84ZI0f9mBs1Ertem6l6IPI6BjcF 7Oen++2GOeGGvTVkJMbkKKOOh66JzXHQsRXYNvm+lF0wT4RICS2pquT70bumYgLFo63r srYU7z8LWIaNI17w0jBSkjYsL9M7/8b1kr5wA8Mbrh/H4cNYRNivDBGoA3025/beEFOt WE6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lsK6TCopwdShwjGVUs60IMuTpGR1yp2d4FBXSr6UZAY=; b=uzcPmekgmlOW/tK1vKu8aTjHKIZH3Sc4wEd+033OYjSdrdqUzcxCVU1787nezEsJCD +4wjM7N78ZNoGo7QpQEC1lQi41xTNBE50E0PiLsNAIqvxp3K6PkDh1GRgCORcy9tYcGy 1icWG9cqrJPl6DV+n09N9czU0IUtqReWhZ7LVNpn3tF/82npZCGDMhVKjeHhhzNQuJAI 1WlA4kTvI4roN4thFc78EhlOYN0xhe+yIVT9F4i6NZEX2BLR0zCJIF+apm5Q9/c0R+Eg 0ABTo1m0hGRvx9ySueu/joXmFN4ijEjHyQruGOAKA5eaf9eODyewFLD0K9C/peY+8Kq7 lakA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F+MEWaJa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w24-20020a170906185800b006e02fed97cesi9958802eje.33.2022.04.05.18.19.43; Tue, 05 Apr 2022 18:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F+MEWaJa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235563AbiDEH7v (ORCPT + 99 others); Tue, 5 Apr 2022 03:59:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbiDEHsV (ORCPT ); Tue, 5 Apr 2022 03:48:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5377DBB; Tue, 5 Apr 2022 00:46:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0F286B81B92; Tue, 5 Apr 2022 07:46:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67F5EC340EE; Tue, 5 Apr 2022 07:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144779; bh=68aLZg2k8y7k/NuHYgwWso1X6n6Cr9BCaz8zPh9HeQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F+MEWaJa/15wA4NDxuurDtoqwZKNCid8kz4o7H+ld3pwZP2lyOJaq9TkLMcL7A1T3 YTASzPTFM8avI3Anr/T3s1OVtlDhewxuXjJB6eHgGmZcJ0JAUgDOhMv5Sl6JHzmyB3 ATDQ4rqJpe+wYIK/KadBH7ck9FWr+XiVdTXFXGFA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= , Sean Young , Mauro Carvalho Chehab Subject: [PATCH 5.17 0167/1126] media: gpio-ir-tx: fix transmit with long spaces on Orange Pi PC Date: Tue, 5 Apr 2022 09:15:14 +0200 Message-Id: <20220405070412.500747608@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Young commit 5ad05ecad4326ddaa26a83ba2233a67be24c1aaa upstream. Calling udelay for than 1000us does not always yield the correct results. Cc: stable@vger.kernel.org Reported-by: Михаил Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/rc/gpio-ir-tx.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) --- a/drivers/media/rc/gpio-ir-tx.c +++ b/drivers/media/rc/gpio-ir-tx.c @@ -48,11 +48,29 @@ static int gpio_ir_tx_set_carrier(struct return 0; } +static void delay_until(ktime_t until) +{ + /* + * delta should never exceed 0.5 seconds (IR_MAX_DURATION) and on + * m68k ndelay(s64) does not compile; so use s32 rather than s64. + */ + s32 delta; + + while (true) { + delta = ktime_us_delta(until, ktime_get()); + if (delta <= 0) + return; + + /* udelay more than 1ms may not work */ + delta = min(delta, 1000); + udelay(delta); + } +} + static void gpio_ir_tx_unmodulated(struct gpio_ir *gpio_ir, uint *txbuf, uint count) { ktime_t edge; - s32 delta; int i; local_irq_disable(); @@ -63,9 +81,7 @@ static void gpio_ir_tx_unmodulated(struc 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); + delay_until(edge); } gpiod_set_value(gpio_ir->gpio, 0); @@ -97,9 +113,7 @@ static void gpio_ir_tx_modulated(struct if (i % 2) { // space edge = ktime_add_us(edge, txbuf[i]); - delta = ktime_us_delta(edge, ktime_get()); - if (delta > 0) - udelay(delta); + delay_until(edge); } else { // pulse ktime_t last = ktime_add_us(edge, txbuf[i]);