2011-01-18 13:33:08 +08:00
|
|
|
/* ir-lirc-codec.c - rc-core to classic lirc interface bridge
|
2010-07-03 12:07:53 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 by Jarod Wilson <jarod@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
2011-07-04 02:03:12 +08:00
|
|
|
#include <linux/module.h>
|
2010-07-03 12:07:53 +08:00
|
|
|
#include <media/lirc.h>
|
2010-07-17 01:25:33 +08:00
|
|
|
#include <media/lirc_dev.h>
|
2010-11-18 00:28:38 +08:00
|
|
|
#include <media/rc-core.h>
|
2010-11-10 10:09:57 +08:00
|
|
|
#include "rc-core-priv.h"
|
2010-07-03 12:07:53 +08:00
|
|
|
|
|
|
|
#define LIRCBUF_SIZE 256
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the
|
|
|
|
* lircd userspace daemon for decoding.
|
2010-10-30 03:08:23 +08:00
|
|
|
* @input_dev: the struct rc_dev descriptor of the device
|
2010-07-03 12:07:53 +08:00
|
|
|
* @duration: the struct ir_raw_event descriptor of the pulse/space
|
|
|
|
*
|
|
|
|
* This function returns -EINVAL if the lirc interfaces aren't wired up.
|
|
|
|
*/
|
2010-10-30 03:08:23 +08:00
|
|
|
static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
|
2010-07-03 12:07:53 +08:00
|
|
|
{
|
2010-10-30 03:08:23 +08:00
|
|
|
struct lirc_codec *lirc = &dev->raw->lirc;
|
2010-07-31 22:59:15 +08:00
|
|
|
int sample;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2017-09-22 03:13:34 +08:00
|
|
|
if (!dev->raw->lirc.ldev || !dev->raw->lirc.ldev->rbuf)
|
2010-07-03 12:07:53 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-17 06:56:28 +08:00
|
|
|
/* Packet start */
|
2014-07-24 18:40:20 +08:00
|
|
|
if (ev.reset) {
|
|
|
|
/* Userspace expects a long space event before the start of
|
|
|
|
* the signal to use as a sync. This may be done with repeat
|
|
|
|
* packets and normal samples. But if a reset has been sent
|
|
|
|
* then we assume that a long time has passed, so we send a
|
|
|
|
* space with the maximum time value. */
|
|
|
|
sample = LIRC_SPACE(LIRC_VALUE_MASK);
|
|
|
|
IR_dprintk(2, "delivering reset sync space to lirc_dev\n");
|
2010-07-31 22:59:15 +08:00
|
|
|
|
2010-10-17 06:56:28 +08:00
|
|
|
/* Carrier reports */
|
2014-07-24 18:40:20 +08:00
|
|
|
} else if (ev.carrier_report) {
|
2010-10-17 06:56:28 +08:00
|
|
|
sample = LIRC_FREQUENCY(ev.carrier);
|
2011-01-18 13:33:08 +08:00
|
|
|
IR_dprintk(2, "carrier report (freq: %d)\n", sample);
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2010-10-17 06:56:28 +08:00
|
|
|
/* Packet end */
|
|
|
|
} else if (ev.timeout) {
|
|
|
|
|
|
|
|
if (lirc->gap)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
lirc->gap_start = ktime_get();
|
|
|
|
lirc->gap = true;
|
|
|
|
lirc->gap_duration = ev.duration;
|
|
|
|
|
|
|
|
if (!lirc->send_timeout_reports)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sample = LIRC_TIMEOUT(ev.duration / 1000);
|
2011-01-18 13:33:08 +08:00
|
|
|
IR_dprintk(2, "timeout report (duration: %d)\n", sample);
|
2010-10-17 06:56:28 +08:00
|
|
|
|
|
|
|
/* Normal sample */
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (lirc->gap) {
|
|
|
|
int gap_sample;
|
|
|
|
|
|
|
|
lirc->gap_duration += ktime_to_ns(ktime_sub(ktime_get(),
|
|
|
|
lirc->gap_start));
|
|
|
|
|
|
|
|
/* Convert to ms and cap by LIRC_VALUE_MASK */
|
|
|
|
do_div(lirc->gap_duration, 1000);
|
|
|
|
lirc->gap_duration = min(lirc->gap_duration,
|
|
|
|
(u64)LIRC_VALUE_MASK);
|
|
|
|
|
|
|
|
gap_sample = LIRC_SPACE(lirc->gap_duration);
|
2017-09-22 03:13:34 +08:00
|
|
|
lirc_buffer_write(dev->raw->lirc.ldev->rbuf,
|
|
|
|
(unsigned char *)&gap_sample);
|
2010-10-17 06:56:28 +08:00
|
|
|
lirc->gap = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample = ev.pulse ? LIRC_PULSE(ev.duration / 1000) :
|
|
|
|
LIRC_SPACE(ev.duration / 1000);
|
2011-01-18 13:33:08 +08:00
|
|
|
IR_dprintk(2, "delivering %uus %s to lirc_dev\n",
|
|
|
|
TO_US(ev.duration), TO_STR(ev.pulse));
|
2010-10-17 06:56:28 +08:00
|
|
|
}
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2017-09-22 03:13:34 +08:00
|
|
|
lirc_buffer_write(dev->raw->lirc.ldev->rbuf,
|
2010-07-31 22:59:15 +08:00
|
|
|
(unsigned char *) &sample);
|
2017-09-22 03:13:34 +08:00
|
|
|
wake_up(&dev->raw->lirc.ldev->rbuf->wait_poll);
|
2010-07-03 12:07:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-06 13:41:06 +08:00
|
|
|
static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
|
2010-07-03 12:07:53 +08:00
|
|
|
size_t n, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct lirc_codec *lirc;
|
2010-10-30 03:08:23 +08:00
|
|
|
struct rc_dev *dev;
|
2011-04-28 23:13:58 +08:00
|
|
|
unsigned int *txbuf; /* buffer with values to transmit */
|
2012-08-13 19:59:49 +08:00
|
|
|
ssize_t ret = -EINVAL;
|
2010-11-27 01:06:35 +08:00
|
|
|
size_t count;
|
2011-04-28 22:14:03 +08:00
|
|
|
ktime_t start;
|
|
|
|
s64 towait;
|
|
|
|
unsigned int duration = 0; /* signal duration in us */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
start = ktime_get();
|
2010-07-03 12:07:53 +08:00
|
|
|
|
|
|
|
lirc = lirc_get_pdata(file);
|
|
|
|
if (!lirc)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2011-04-28 23:13:58 +08:00
|
|
|
if (n < sizeof(unsigned) || n % sizeof(unsigned))
|
2010-07-03 12:07:53 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-04-28 23:13:58 +08:00
|
|
|
count = n / sizeof(unsigned);
|
|
|
|
if (count > LIRCBUF_SIZE || count % 2 == 0)
|
2010-07-03 12:07:53 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-07-17 05:29:54 +08:00
|
|
|
txbuf = memdup_user(buf, n);
|
|
|
|
if (IS_ERR(txbuf))
|
|
|
|
return PTR_ERR(txbuf);
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
dev = lirc->dev;
|
|
|
|
if (!dev) {
|
2010-07-03 12:07:53 +08:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-04-28 22:14:03 +08:00
|
|
|
if (!dev->tx_ir) {
|
2017-01-27 01:19:33 +08:00
|
|
|
ret = -EINVAL;
|
2011-04-28 22:14:03 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-07-09 04:33:11 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (txbuf[i] > IR_MAX_DURATION / 1000 - duration || !txbuf[i]) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
duration += txbuf[i];
|
|
|
|
}
|
|
|
|
|
2012-08-24 04:18:25 +08:00
|
|
|
ret = dev->tx_ir(dev, txbuf, count);
|
2011-04-28 22:14:03 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2013-07-09 04:33:11 +08:00
|
|
|
for (duration = i = 0; i < ret; i++)
|
2011-04-28 22:14:03 +08:00
|
|
|
duration += txbuf[i];
|
2011-04-28 23:13:58 +08:00
|
|
|
|
2011-04-28 22:14:03 +08:00
|
|
|
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));
|
|
|
|
}
|
2010-07-03 12:07:53 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(txbuf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-07-31 22:59:23 +08:00
|
|
|
static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
|
2011-10-06 13:41:06 +08:00
|
|
|
unsigned long arg)
|
2010-07-03 12:07:53 +08:00
|
|
|
{
|
|
|
|
struct lirc_codec *lirc;
|
2010-10-30 03:08:23 +08:00
|
|
|
struct rc_dev *dev;
|
2011-10-06 13:41:06 +08:00
|
|
|
u32 __user *argp = (u32 __user *)(arg);
|
2010-07-03 12:07:53 +08:00
|
|
|
int ret = 0;
|
2010-10-17 06:56:28 +08:00
|
|
|
__u32 val = 0, tmp;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
|
|
|
lirc = lirc_get_pdata(filep);
|
|
|
|
if (!lirc)
|
|
|
|
return -EFAULT;
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
dev = lirc->dev;
|
|
|
|
if (!dev)
|
2010-07-03 12:07:53 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
2010-07-31 22:59:23 +08:00
|
|
|
if (_IOC_DIR(cmd) & _IOC_WRITE) {
|
2011-10-06 13:41:06 +08:00
|
|
|
ret = get_user(val, argp);
|
2010-07-03 12:07:53 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-07-31 22:59:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
/* legacy support */
|
|
|
|
case LIRC_GET_SEND_MODE:
|
2016-12-03 01:16:09 +08:00
|
|
|
if (!dev->tx_ir)
|
|
|
|
return -ENOTTY;
|
|
|
|
|
|
|
|
val = LIRC_MODE_PULSE;
|
2010-07-31 22:59:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIRC_SET_SEND_MODE:
|
2016-12-03 01:16:09 +08:00
|
|
|
if (!dev->tx_ir)
|
|
|
|
return -ENOTTY;
|
|
|
|
|
|
|
|
if (val != LIRC_MODE_PULSE)
|
2010-07-31 22:59:23 +08:00
|
|
|
return -EINVAL;
|
2010-10-17 06:56:28 +08:00
|
|
|
return 0;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2010-07-31 22:59:23 +08:00
|
|
|
/* TX settings */
|
|
|
|
case LIRC_SET_TRANSMITTER_MASK:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->s_tx_mask)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-10-17 06:56:28 +08:00
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
return dev->s_tx_mask(dev, val);
|
2010-07-03 12:07:53 +08:00
|
|
|
|
|
|
|
case LIRC_SET_SEND_CARRIER:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->s_tx_carrier)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-10-17 06:56:28 +08:00
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
return dev->s_tx_carrier(dev, val);
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2010-07-31 22:59:23 +08:00
|
|
|
case LIRC_SET_SEND_DUTY_CYCLE:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->s_tx_duty_cycle)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-07-31 22:59:23 +08:00
|
|
|
|
|
|
|
if (val <= 0 || val >= 100)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
return dev->s_tx_duty_cycle(dev, val);
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2010-07-31 22:59:23 +08:00
|
|
|
/* RX settings */
|
|
|
|
case LIRC_SET_REC_CARRIER:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->s_rx_carrier_range)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2010-10-17 06:56:28 +08:00
|
|
|
if (val <= 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
return dev->s_rx_carrier_range(dev,
|
|
|
|
dev->raw->lirc.carrier_low,
|
|
|
|
val);
|
2010-07-31 22:59:23 +08:00
|
|
|
|
|
|
|
case LIRC_SET_REC_CARRIER_RANGE:
|
2017-02-09 06:44:38 +08:00
|
|
|
if (!dev->s_rx_carrier_range)
|
|
|
|
return -ENOTTY;
|
|
|
|
|
2010-10-17 06:56:28 +08:00
|
|
|
if (val <= 0)
|
|
|
|
return -EINVAL;
|
2010-07-31 22:59:23 +08:00
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
dev->raw->lirc.carrier_low = val;
|
2010-10-17 06:56:28 +08:00
|
|
|
return 0;
|
2010-07-31 22:59:23 +08:00
|
|
|
|
|
|
|
case LIRC_GET_REC_RESOLUTION:
|
2017-02-09 06:48:17 +08:00
|
|
|
if (!dev->rx_resolution)
|
|
|
|
return -ENOTTY;
|
|
|
|
|
2017-07-08 05:49:18 +08:00
|
|
|
val = dev->rx_resolution / 1000;
|
2010-07-31 22:59:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIRC_SET_WIDEBAND_RECEIVER:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->s_learning_mode)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-07-31 22:59:23 +08:00
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
return dev->s_learning_mode(dev, !!val);
|
2010-10-17 06:56:28 +08:00
|
|
|
|
|
|
|
case LIRC_SET_MEASURE_CARRIER_MODE:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->s_carrier_report)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-10-17 06:56:28 +08:00
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
return dev->s_carrier_report(dev, !!val);
|
2010-10-17 06:56:28 +08:00
|
|
|
|
2010-07-31 22:59:23 +08:00
|
|
|
/* Generic timeout support */
|
|
|
|
case LIRC_GET_MIN_TIMEOUT:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->max_timeout)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2017-01-20 05:44:00 +08:00
|
|
|
val = DIV_ROUND_UP(dev->min_timeout, 1000);
|
2010-07-31 22:59:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIRC_GET_MAX_TIMEOUT:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->max_timeout)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-10-30 03:08:23 +08:00
|
|
|
val = dev->max_timeout / 1000;
|
2010-07-31 22:59:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIRC_SET_REC_TIMEOUT:
|
2010-10-30 03:08:23 +08:00
|
|
|
if (!dev->max_timeout)
|
2017-01-27 01:19:33 +08:00
|
|
|
return -ENOTTY;
|
2010-10-17 06:56:28 +08:00
|
|
|
|
|
|
|
tmp = val * 1000;
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
if (tmp < dev->min_timeout ||
|
|
|
|
tmp > dev->max_timeout)
|
2010-10-17 06:56:28 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-07-11 00:34:38 +08:00
|
|
|
if (dev->s_timeout)
|
|
|
|
ret = dev->s_timeout(dev, tmp);
|
|
|
|
if (!ret)
|
|
|
|
dev->timeout = tmp;
|
2010-10-17 06:56:28 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LIRC_SET_REC_TIMEOUT_REPORTS:
|
2017-02-09 06:44:38 +08:00
|
|
|
if (!dev->timeout)
|
|
|
|
return -ENOTTY;
|
|
|
|
|
2010-10-17 06:56:28 +08:00
|
|
|
lirc->send_timeout_reports = !!val;
|
2010-07-03 12:07:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-08-03 02:43:35 +08:00
|
|
|
return lirc_dev_fop_ioctl(filep, cmd, arg);
|
2010-07-03 12:07:53 +08:00
|
|
|
}
|
|
|
|
|
2010-07-31 22:59:23 +08:00
|
|
|
if (_IOC_DIR(cmd) & _IOC_READ)
|
2011-10-06 13:41:06 +08:00
|
|
|
ret = put_user(val, argp);
|
2010-07-31 22:59:23 +08:00
|
|
|
|
2010-07-03 12:07:53 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-05 07:09:41 +08:00
|
|
|
static const struct file_operations lirc_fops = {
|
2010-07-03 12:07:53 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write = ir_lirc_transmit_ir,
|
2010-08-03 02:43:35 +08:00
|
|
|
.unlocked_ioctl = ir_lirc_ioctl,
|
2010-10-10 02:07:06 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = ir_lirc_ioctl,
|
|
|
|
#endif
|
2010-07-03 12:07:53 +08:00
|
|
|
.read = lirc_dev_fop_read,
|
|
|
|
.poll = lirc_dev_fop_poll,
|
|
|
|
.open = lirc_dev_fop_open,
|
|
|
|
.release = lirc_dev_fop_close,
|
2010-08-16 00:51:56 +08:00
|
|
|
.llseek = no_llseek,
|
2010-07-03 12:07:53 +08:00
|
|
|
};
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
static int ir_lirc_register(struct rc_dev *dev)
|
2010-07-03 12:07:53 +08:00
|
|
|
{
|
2017-09-22 03:13:34 +08:00
|
|
|
struct lirc_dev *ldev;
|
2010-07-03 12:07:53 +08:00
|
|
|
int rc = -ENOMEM;
|
2017-01-20 05:27:17 +08:00
|
|
|
unsigned long features = 0;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2017-06-25 20:32:15 +08:00
|
|
|
ldev = lirc_allocate_device();
|
2017-09-22 03:13:34 +08:00
|
|
|
if (!ldev)
|
2010-07-03 12:07:53 +08:00
|
|
|
return rc;
|
|
|
|
|
2017-02-09 06:48:17 +08:00
|
|
|
if (dev->driver_type != RC_DRIVER_IR_RAW_TX) {
|
2017-01-20 05:27:17 +08:00
|
|
|
features |= LIRC_CAN_REC_MODE2;
|
2017-02-09 06:48:17 +08:00
|
|
|
if (dev->rx_resolution)
|
|
|
|
features |= LIRC_CAN_GET_REC_RESOLUTION;
|
|
|
|
}
|
2017-05-01 21:32:34 +08:00
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->tx_ir) {
|
2010-07-03 12:07:53 +08:00
|
|
|
features |= LIRC_CAN_SEND_PULSE;
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->s_tx_mask)
|
2010-07-03 12:07:53 +08:00
|
|
|
features |= LIRC_CAN_SET_TRANSMITTER_MASK;
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->s_tx_carrier)
|
2010-07-03 12:07:53 +08:00
|
|
|
features |= LIRC_CAN_SET_SEND_CARRIER;
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->s_tx_duty_cycle)
|
2010-09-07 05:26:08 +08:00
|
|
|
features |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
|
2010-07-03 12:07:53 +08:00
|
|
|
}
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->s_rx_carrier_range)
|
2010-07-31 22:59:23 +08:00
|
|
|
features |= LIRC_CAN_SET_REC_CARRIER |
|
|
|
|
LIRC_CAN_SET_REC_CARRIER_RANGE;
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->s_learning_mode)
|
2010-07-31 22:59:23 +08:00
|
|
|
features |= LIRC_CAN_USE_WIDEBAND_RECEIVER;
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->s_carrier_report)
|
2010-10-17 06:56:28 +08:00
|
|
|
features |= LIRC_CAN_MEASURE_CARRIER;
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
if (dev->max_timeout)
|
2010-07-31 22:59:23 +08:00
|
|
|
features |= LIRC_CAN_SET_REC_TIMEOUT;
|
|
|
|
|
2017-09-22 03:13:34 +08:00
|
|
|
snprintf(ldev->name, sizeof(ldev->name), "ir-lirc-codec (%s)",
|
2010-10-30 03:08:23 +08:00
|
|
|
dev->driver_name);
|
2017-09-22 03:13:34 +08:00
|
|
|
ldev->features = features;
|
|
|
|
ldev->data = &dev->raw->lirc;
|
|
|
|
ldev->rbuf = NULL;
|
|
|
|
ldev->code_length = sizeof(struct ir_raw_event) * 8;
|
|
|
|
ldev->chunk_size = sizeof(int);
|
|
|
|
ldev->buffer_size = LIRCBUF_SIZE;
|
|
|
|
ldev->fops = &lirc_fops;
|
|
|
|
ldev->dev = &dev->dev;
|
|
|
|
ldev->rdev = dev;
|
|
|
|
ldev->owner = THIS_MODULE;
|
|
|
|
|
|
|
|
rc = lirc_register_device(ldev);
|
2017-06-25 20:31:24 +08:00
|
|
|
if (rc < 0)
|
2017-05-01 21:32:34 +08:00
|
|
|
goto out;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2017-09-22 03:13:34 +08:00
|
|
|
dev->raw->lirc.ldev = ldev;
|
2010-10-30 03:08:23 +08:00
|
|
|
dev->raw->lirc.dev = dev;
|
2010-07-03 12:07:53 +08:00
|
|
|
return 0;
|
|
|
|
|
2017-05-01 21:32:34 +08:00
|
|
|
out:
|
2017-09-22 03:13:34 +08:00
|
|
|
kfree(ldev);
|
2010-07-03 12:07:53 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-10-30 03:08:23 +08:00
|
|
|
static int ir_lirc_unregister(struct rc_dev *dev)
|
2010-07-03 12:07:53 +08:00
|
|
|
{
|
2010-10-30 03:08:23 +08:00
|
|
|
struct lirc_codec *lirc = &dev->raw->lirc;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
2017-09-22 03:13:34 +08:00
|
|
|
lirc_unregister_device(lirc->ldev);
|
|
|
|
kfree(lirc->ldev);
|
|
|
|
lirc->ldev = NULL;
|
2010-07-03 12:07:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ir_raw_handler lirc_handler = {
|
2015-05-20 06:03:22 +08:00
|
|
|
.protocols = 0,
|
2010-07-03 12:07:53 +08:00
|
|
|
.decode = ir_lirc_decode,
|
|
|
|
.raw_register = ir_lirc_register,
|
|
|
|
.raw_unregister = ir_lirc_unregister,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ir_lirc_codec_init(void)
|
|
|
|
{
|
|
|
|
ir_raw_handler_register(&lirc_handler);
|
|
|
|
|
|
|
|
printk(KERN_INFO "IR LIRC bridge handler initialized\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ir_lirc_codec_exit(void)
|
|
|
|
{
|
|
|
|
ir_raw_handler_unregister(&lirc_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ir_lirc_codec_init);
|
|
|
|
module_exit(ir_lirc_codec_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
|
|
|
|
MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
|
|
|
|
MODULE_DESCRIPTION("LIRC IR handler bridge");
|