diff options
Diffstat (limited to 'drivers/media/rc/ir-lirc-codec.c')
-rw-r--r-- | drivers/media/rc/ir-lirc-codec.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c index 5faba2a2fdd3..569124b03de3 100644 --- a/drivers/media/rc/ir-lirc-codec.c +++ b/drivers/media/rc/ir-lirc-codec.c @@ -105,8 +105,14 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, struct lirc_codec *lirc; struct rc_dev *dev; unsigned int *txbuf; /* buffer with values to transmit */ - ssize_t ret = 0; + ssize_t ret = -EINVAL; size_t count; + ktime_t start; + s64 towait; + unsigned int duration = 0; /* signal duration in us */ + int i; + + start = ktime_get(); lirc = lirc_get_pdata(file); if (!lirc) @@ -129,11 +135,30 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, goto out; } - if (dev->tx_ir) - ret = dev->tx_ir(dev, txbuf, count); + if (!dev->tx_ir) { + ret = -ENOSYS; + goto out; + } + + ret = dev->tx_ir(dev, txbuf, count); + if (ret < 0) + goto out; + + for (i = 0; i < ret; i++) + duration += txbuf[i]; - if (ret > 0) - ret *= sizeof(unsigned); + ret *= sizeof(unsigned int); + + /* + * The lircd gap calculation expects the write function to + * wait for the actual IR signal to be transmitted before + * returning. + */ + towait = ktime_us_delta(ktime_add_us(start, duration), ktime_get()); + if (towait > 0) { + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(usecs_to_jiffies(towait)); + } out: kfree(txbuf); |