summaryrefslogtreecommitdiff
path: root/drivers/media/rc/lirc_dev.c
diff options
context:
space:
mode:
authorSean Young <sean@mess.org>2017-09-23 21:44:18 +0300
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2017-12-14 18:35:18 +0300
commit71695aff9fe036857596965635e2607cf561a230 (patch)
treed92dd7d09aedee87d6ad93f47b6f56dd29364514 /drivers/media/rc/lirc_dev.c
parent95bc71e199e50487054adfd8222c5105deddbbd9 (diff)
downloadlinux-71695aff9fe036857596965635e2607cf561a230.tar.xz
media: lirc: use kfifo rather than lirc_buffer for raw IR
Since the only mode lirc devices can handle is raw IR, handle this in a plain kfifo. Remove lirc_buffer since this is no longer needed. Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/rc/lirc_dev.c')
-rw-r--r--drivers/media/rc/lirc_dev.c199
1 files changed, 16 insertions, 183 deletions
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 95058ea01e62..9a0ad8d9a0cb 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -44,40 +44,14 @@ static struct class *lirc_class;
static void lirc_release_device(struct device *ld)
{
struct lirc_dev *d = container_of(ld, struct lirc_dev, dev);
+ struct rc_dev *rcdev = d->rdev;
- put_device(d->dev.parent);
+ if (rcdev->driver_type == RC_DRIVER_IR_RAW)
+ kfifo_free(&rcdev->rawir);
- if (d->buf_internal) {
- lirc_buffer_free(d->buf);
- kfree(d->buf);
- d->buf = NULL;
- }
kfree(d);
module_put(THIS_MODULE);
-}
-
-static int lirc_allocate_buffer(struct lirc_dev *d)
-{
- int err;
-
- if (d->buf) {
- d->buf_internal = false;
- return 0;
- }
-
- d->buf = kmalloc(sizeof(*d->buf), GFP_KERNEL);
- if (!d->buf)
- return -ENOMEM;
-
- err = lirc_buffer_init(d->buf, d->chunk_size, d->buffer_size);
- if (err) {
- kfree(d->buf);
- d->buf = NULL;
- return err;
- }
-
- d->buf_internal = true;
- return 0;
+ put_device(d->dev.parent);
}
struct lirc_dev *
@@ -128,31 +102,16 @@ int lirc_register_device(struct lirc_dev *d)
return -EINVAL;
}
- if (!d->buf && d->chunk_size < 1) {
- pr_err("chunk_size must be set!\n");
- return -EINVAL;
- }
-
- if (!d->buf && d->buffer_size < 1) {
- pr_err("buffer_size must be set!\n");
- return -EINVAL;
- }
-
- if (!d->buf && !(d->fops && d->fops->read &&
- d->fops->poll && d->fops->unlocked_ioctl)) {
- dev_err(&d->dev, "undefined read, poll, ioctl\n");
- return -EBADRQC;
- }
-
/* some safety check 8-) */
d->name[sizeof(d->name) - 1] = '\0';
if (rcdev->driver_type == RC_DRIVER_IR_RAW) {
- err = lirc_allocate_buffer(d);
- if (err)
- return err;
+ if (kfifo_alloc(&rcdev->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL))
+ return -ENOMEM;
}
+ init_waitqueue_head(&rcdev->wait_poll);
+
minor = ida_simple_get(&lirc_ida, 0, LIRC_MAX_DEVICES, GFP_KERNEL);
if (minor < 0)
return minor;
@@ -182,9 +141,13 @@ EXPORT_SYMBOL(lirc_register_device);
void lirc_unregister_device(struct lirc_dev *d)
{
+ struct rc_dev *rcdev;
+
if (!d)
return;
+ rcdev = d->rdev;
+
dev_dbg(&d->dev, "lirc_dev: driver %s unregistered from minor = %d\n",
d->name, d->minor);
@@ -194,7 +157,7 @@ void lirc_unregister_device(struct lirc_dev *d)
if (d->open) {
dev_dbg(&d->dev, LOGHEAD "releasing opened driver\n",
d->name, d->minor);
- wake_up_interruptible(&d->buf->wait_poll);
+ wake_up_poll(&rcdev->wait_poll, POLLHUP);
}
mutex_unlock(&d->mutex);
@@ -208,6 +171,7 @@ EXPORT_SYMBOL(lirc_unregister_device);
int lirc_dev_fop_open(struct inode *inode, struct file *file)
{
struct lirc_dev *d = container_of(inode->i_cdev, struct lirc_dev, cdev);
+ struct rc_dev *rcdev = d->rdev;
int retval;
dev_dbg(&d->dev, LOGHEAD "open called\n", d->name, d->minor);
@@ -232,8 +196,8 @@ int lirc_dev_fop_open(struct inode *inode, struct file *file)
goto out;
}
- if (d->buf)
- lirc_buffer_clear(d->buf);
+ if (rcdev->driver_type == RC_DRIVER_IR_RAW)
+ kfifo_reset_out(&rcdev->rawir);
d->open++;
@@ -265,137 +229,6 @@ int lirc_dev_fop_close(struct inode *inode, struct file *file)
}
EXPORT_SYMBOL(lirc_dev_fop_close);
-unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait)
-{
- struct rc_dev *rcdev = file->private_data;
- struct lirc_dev *d = rcdev->lirc_dev;
- unsigned int ret;
-
- if (!d->attached)
- return POLLHUP | POLLERR;
-
- if (d->buf) {
- poll_wait(file, &d->buf->wait_poll, wait);
-
- if (lirc_buffer_empty(d->buf))
- ret = 0;
- else
- ret = POLLIN | POLLRDNORM;
- } else {
- ret = POLLERR;
- }
-
- dev_dbg(&d->dev, LOGHEAD "poll result = %d\n", d->name, d->minor, ret);
-
- return ret;
-}
-EXPORT_SYMBOL(lirc_dev_fop_poll);
-
-ssize_t lirc_dev_fop_read(struct file *file,
- char __user *buffer,
- size_t length,
- loff_t *ppos)
-{
- struct rc_dev *rcdev = file->private_data;
- struct lirc_dev *d = rcdev->lirc_dev;
- unsigned char *buf;
- int ret, written = 0;
- DECLARE_WAITQUEUE(wait, current);
-
- buf = kzalloc(d->buf->chunk_size, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- dev_dbg(&d->dev, LOGHEAD "read called\n", d->name, d->minor);
-
- ret = mutex_lock_interruptible(&d->mutex);
- if (ret) {
- kfree(buf);
- return ret;
- }
-
- if (!d->attached) {
- ret = -ENODEV;
- goto out_locked;
- }
-
- if (rcdev->driver_type != RC_DRIVER_IR_RAW) {
- ret = -EINVAL;
- goto out_locked;
- }
-
- if (length % d->buf->chunk_size) {
- ret = -EINVAL;
- goto out_locked;
- }
-
- /*
- * we add ourselves to the task queue before buffer check
- * to avoid losing scan code (in case when queue is awaken somewhere
- * between while condition checking and scheduling)
- */
- add_wait_queue(&d->buf->wait_poll, &wait);
-
- /*
- * while we didn't provide 'length' bytes, device is opened in blocking
- * mode and 'copy_to_user' is happy, wait for data.
- */
- while (written < length && ret == 0) {
- if (lirc_buffer_empty(d->buf)) {
- /* According to the read(2) man page, 'written' can be
- * returned as less than 'length', instead of blocking
- * again, returning -EWOULDBLOCK, or returning
- * -ERESTARTSYS
- */
- if (written)
- break;
- if (file->f_flags & O_NONBLOCK) {
- ret = -EWOULDBLOCK;
- break;
- }
- if (signal_pending(current)) {
- ret = -ERESTARTSYS;
- break;
- }
-
- mutex_unlock(&d->mutex);
- set_current_state(TASK_INTERRUPTIBLE);
- schedule();
- set_current_state(TASK_RUNNING);
-
- ret = mutex_lock_interruptible(&d->mutex);
- if (ret) {
- remove_wait_queue(&d->buf->wait_poll, &wait);
- goto out_unlocked;
- }
-
- if (!d->attached) {
- ret = -ENODEV;
- goto out_locked;
- }
- } else {
- lirc_buffer_read(d->buf, buf);
- ret = copy_to_user((void __user *)buffer+written, buf,
- d->buf->chunk_size);
- if (!ret)
- written += d->buf->chunk_size;
- else
- ret = -EFAULT;
- }
- }
-
- remove_wait_queue(&d->buf->wait_poll, &wait);
-
-out_locked:
- mutex_unlock(&d->mutex);
-
-out_unlocked:
- kfree(buf);
-
- return ret ? ret : written;
-}
-EXPORT_SYMBOL(lirc_dev_fop_read);
-
int __init lirc_dev_init(void)
{
int retval;