Skip to content

Commit

Permalink
media: gpio-ir-tx: fix transmit with long spaces on Orange Pi PC
Browse files Browse the repository at this point in the history
commit 5ad05ec upstream.

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

Cc: stable@vger.kernel.org
Reported-by: Михаил <vrserver1@gmail.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Sean Young authored and Greg Kroah-Hartman committed Apr 8, 2022
1 parent 785ffce commit cde90e8
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions drivers/media/rc/gpio-ir-tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,29 @@ static int gpio_ir_tx_set_carrier(struct rc_dev *dev, u32 carrier)
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();
Expand All @@ -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));

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);
Expand Down Expand Up @@ -97,9 +113,7 @@ static void gpio_ir_tx_modulated(struct gpio_ir *gpio_ir, uint *txbuf,
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]);
Expand Down

0 comments on commit cde90e8

Please sign in to comment.