提交 fbdbe740 编写于 作者: S Sean Young 提交者: Zheng Zengkai

media: gpio-ir-tx: fix transmit with long spaces on Orange Pi PC

stable inclusion
from stable-v5.10.110
commit cde90e82919005ad581529c5375ff1b1189cd8c0
bugzilla: https://gitee.com/openeuler/kernel/issues/I574AL

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=cde90e82919005ad581529c5375ff1b1189cd8c0

--------------------------------

commit 5ad05eca upstream.

Calling udelay for than 1000us does not always yield the correct
results.

Cc: stable@vger.kernel.org
Reported-by: NМихаил <vrserver1@gmail.com>
Signed-off-by: NSean Young <sean@mess.org>
Signed-off-by: NMauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYu Liao <liaoyu15@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 c46ca5d7
...@@ -48,11 +48,29 @@ static int gpio_ir_tx_set_carrier(struct rc_dev *dev, u32 carrier) ...@@ -48,11 +48,29 @@ static int gpio_ir_tx_set_carrier(struct rc_dev *dev, u32 carrier)
return 0; 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, static void gpio_ir_tx_unmodulated(struct gpio_ir *gpio_ir, uint *txbuf,
uint count) uint count)
{ {
ktime_t edge; ktime_t edge;
s32 delta;
int i; int i;
local_irq_disable(); local_irq_disable();
...@@ -63,9 +81,7 @@ static void gpio_ir_tx_unmodulated(struct gpio_ir *gpio_ir, uint *txbuf, ...@@ -63,9 +81,7 @@ static void gpio_ir_tx_unmodulated(struct gpio_ir *gpio_ir, uint *txbuf,
gpiod_set_value(gpio_ir->gpio, !(i % 2)); gpiod_set_value(gpio_ir->gpio, !(i % 2));
edge = ktime_add_us(edge, txbuf[i]); edge = ktime_add_us(edge, txbuf[i]);
delta = ktime_us_delta(edge, ktime_get()); delay_until(edge);
if (delta > 0)
udelay(delta);
} }
gpiod_set_value(gpio_ir->gpio, 0); gpiod_set_value(gpio_ir->gpio, 0);
...@@ -97,9 +113,7 @@ static void gpio_ir_tx_modulated(struct gpio_ir *gpio_ir, uint *txbuf, ...@@ -97,9 +113,7 @@ static void gpio_ir_tx_modulated(struct gpio_ir *gpio_ir, uint *txbuf,
if (i % 2) { if (i % 2) {
// space // space
edge = ktime_add_us(edge, txbuf[i]); edge = ktime_add_us(edge, txbuf[i]);
delta = ktime_us_delta(edge, ktime_get()); delay_until(edge);
if (delta > 0)
udelay(delta);
} else { } else {
// pulse // pulse
ktime_t last = ktime_add_us(edge, txbuf[i]); ktime_t last = ktime_add_us(edge, txbuf[i]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册