Commit b145ef94 authored by David Härdeman's avatar David Härdeman Committed by Mauro Carvalho Chehab

[media] media: lirc_dev: make chunk_size and buffer_size mandatory

Make setting chunk_size and buffer_size mandatory for drivers which
expect lirc_dev to allocate the lirc_buffer (i.e. ir-lirc-codec) and
don't set them in lirc-zilog (which creates its own buffer).

Also remove an unnecessary copy of chunk_size in struct irctl (the
same information is already available from struct lirc_buffer).
Signed-off-by: default avatarDavid Härdeman <david@hardeman.nu>
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 615cd3fe
...@@ -41,7 +41,6 @@ struct irctl { ...@@ -41,7 +41,6 @@ struct irctl {
struct mutex irctl_lock; struct mutex irctl_lock;
struct lirc_buffer *buf; struct lirc_buffer *buf;
bool buf_internal; bool buf_internal;
unsigned int chunk_size;
struct device dev; struct device dev;
struct cdev cdev; struct cdev cdev;
...@@ -74,16 +73,8 @@ static void lirc_release(struct device *ld) ...@@ -74,16 +73,8 @@ static void lirc_release(struct device *ld)
static int lirc_allocate_buffer(struct irctl *ir) static int lirc_allocate_buffer(struct irctl *ir)
{ {
int err = 0; int err = 0;
int bytes_in_key;
unsigned int chunk_size;
unsigned int buffer_size;
struct lirc_driver *d = &ir->d; struct lirc_driver *d = &ir->d;
bytes_in_key = BITS_TO_LONGS(d->code_length) +
(d->code_length % 8 ? 1 : 0);
buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key;
chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key;
if (d->rbuf) { if (d->rbuf) {
ir->buf = d->rbuf; ir->buf = d->rbuf;
ir->buf_internal = false; ir->buf_internal = false;
...@@ -94,7 +85,7 @@ static int lirc_allocate_buffer(struct irctl *ir) ...@@ -94,7 +85,7 @@ static int lirc_allocate_buffer(struct irctl *ir)
goto out; goto out;
} }
err = lirc_buffer_init(ir->buf, chunk_size, buffer_size); err = lirc_buffer_init(ir->buf, d->chunk_size, d->buffer_size);
if (err) { if (err) {
kfree(ir->buf); kfree(ir->buf);
ir->buf = NULL; ir->buf = NULL;
...@@ -104,7 +95,6 @@ static int lirc_allocate_buffer(struct irctl *ir) ...@@ -104,7 +95,6 @@ static int lirc_allocate_buffer(struct irctl *ir)
ir->buf_internal = true; ir->buf_internal = true;
d->rbuf = ir->buf; d->rbuf = ir->buf;
} }
ir->chunk_size = ir->buf->chunk_size;
out: out:
return err; return err;
...@@ -131,6 +121,16 @@ int lirc_register_driver(struct lirc_driver *d) ...@@ -131,6 +121,16 @@ int lirc_register_driver(struct lirc_driver *d)
return -EINVAL; return -EINVAL;
} }
if (!d->rbuf && d->chunk_size < 1) {
pr_err("chunk_size must be set!\n");
return -EINVAL;
}
if (!d->rbuf && d->buffer_size < 1) {
pr_err("buffer_size must be set!\n");
return -EINVAL;
}
if (d->code_length < 1 || d->code_length > (BUFLEN * 8)) { if (d->code_length < 1 || d->code_length > (BUFLEN * 8)) {
dev_err(d->dev, "code length must be less than %d bits\n", dev_err(d->dev, "code length must be less than %d bits\n",
BUFLEN * 8); BUFLEN * 8);
...@@ -407,7 +407,7 @@ ssize_t lirc_dev_fop_read(struct file *file, ...@@ -407,7 +407,7 @@ ssize_t lirc_dev_fop_read(struct file *file,
dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor); dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor);
buf = kzalloc(ir->chunk_size, GFP_KERNEL); buf = kzalloc(ir->buf->chunk_size, GFP_KERNEL);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
...@@ -420,7 +420,7 @@ ssize_t lirc_dev_fop_read(struct file *file, ...@@ -420,7 +420,7 @@ ssize_t lirc_dev_fop_read(struct file *file,
goto out_locked; goto out_locked;
} }
if (length % ir->chunk_size) { if (length % ir->buf->chunk_size) {
ret = -EINVAL; ret = -EINVAL;
goto out_locked; goto out_locked;
} }
......
...@@ -1348,8 +1348,6 @@ static const struct file_operations lirc_fops = { ...@@ -1348,8 +1348,6 @@ static const struct file_operations lirc_fops = {
static struct lirc_driver lirc_template = { static struct lirc_driver lirc_template = {
.name = "lirc_zilog", .name = "lirc_zilog",
.code_length = 13, .code_length = 13,
.buffer_size = BUFLEN / 2,
.chunk_size = 2,
.fops = &lirc_fops, .fops = &lirc_fops,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
...@@ -1456,8 +1454,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1456,8 +1454,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
ir->l.dev = &adap->dev; ir->l.dev = &adap->dev;
/* This will be returned by lirc_get_pdata() */ /* This will be returned by lirc_get_pdata() */
ir->l.data = ir; ir->l.data = ir;
ret = lirc_buffer_init(ir->l.rbuf, ret = lirc_buffer_init(ir->l.rbuf, 2, BUFLEN / 2);
ir->l.chunk_size, ir->l.buffer_size);
if (ret) if (ret)
goto out_put_ir; goto out_put_ir;
} }
......
...@@ -121,13 +121,14 @@ static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf, ...@@ -121,13 +121,14 @@ static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
* *
* @code_length: length of the remote control key code expressed in bits. * @code_length: length of the remote control key code expressed in bits.
* *
* @buffer_size: Number of FIFO buffers with @chunk_size size. If zero,
* creates a buffer with BUFLEN size (16 bytes).
*
* @features: lirc compatible hardware features, like LIRC_MODE_RAW, * @features: lirc compatible hardware features, like LIRC_MODE_RAW,
* LIRC_CAN\_\*, as defined at include/media/lirc.h. * LIRC_CAN\_\*, as defined at include/media/lirc.h.
* *
* @buffer_size: Number of FIFO buffers with @chunk_size size.
* Only used if @rbuf is NULL.
*
* @chunk_size: Size of each FIFO buffer. * @chunk_size: Size of each FIFO buffer.
* Only used if @rbuf is NULL.
* *
* @data: it may point to any driver data and this pointer will * @data: it may point to any driver data and this pointer will
* be passed to all callback functions. * be passed to all callback functions.
...@@ -162,9 +163,9 @@ struct lirc_driver { ...@@ -162,9 +163,9 @@ struct lirc_driver {
char name[40]; char name[40];
unsigned int minor; unsigned int minor;
__u32 code_length; __u32 code_length;
unsigned int buffer_size; /* in chunks holding one code each */
__u32 features; __u32 features;
unsigned int buffer_size; /* in chunks holding one code each */
unsigned int chunk_size; unsigned int chunk_size;
void *data; void *data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment