From efb7c378b6c916b25aaeaa1a38d6307eb8407282 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 11 Feb 2009 23:14:09 +0100 Subject: saa6588: convert to v4l2-i2c-drv-legacy.h From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- linux/drivers/media/video/saa6588.c | 86 +++++++++++++------------------------ 1 file changed, 31 insertions(+), 55 deletions(-) diff --git a/linux/drivers/media/video/saa6588.c b/linux/drivers/media/video/saa6588.c index ab41d9526..57a40e62f 100644 --- a/linux/drivers/media/video/saa6588.c +++ b/linux/drivers/media/video/saa6588.c @@ -32,6 +32,8 @@ #include #include +#include +#include #include "compat.h" /* Addresses to scan */ @@ -73,7 +75,7 @@ MODULE_LICENSE("GPL"); #define dprintk if (debug) printk struct saa6588 { - struct i2c_client client; + struct i2c_client *client; struct work_struct work; struct timer_list timer; spinlock_t lock; @@ -87,9 +89,6 @@ struct saa6588 { int data_available_for_read; }; -static struct i2c_driver driver; -static struct i2c_client client_template; - /* ---------------------------------------------------------------------- */ /* @@ -266,7 +265,7 @@ static void saa6588_i2c_poll(struct saa6588 *s) /* Although we only need 3 bytes, we have to read at least 6. SAA6588 returns garbage otherwise */ - if (6 != i2c_master_recv(&s->client, &tmpbuf[0], 6)) { + if (6 != i2c_master_recv(s->client, &tmpbuf[0], 6)) { if (debug > 1) dprintk(PREFIX "read error!\n"); return; @@ -389,7 +388,8 @@ static int saa6588_configure(struct saa6588 *s) dprintk(PREFIX "writing: 0w=0x%02x 1w=0x%02x 2w=0x%02x\n", buf[0], buf[1], buf[2]); - if (3 != (rc = i2c_master_send(&s->client, buf, 3))) + rc = i2c_master_send(s->client, buf, 3); + if (rc != 3) printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc); return 0; @@ -397,33 +397,34 @@ static int saa6588_configure(struct saa6588 *s) /* ---------------------------------------------------------------------- */ -static int saa6588_attach(struct i2c_adapter *adap, int addr, int kind) +static int saa6588_probe(struct i2c_client *client, + const struct i2c_device_id *id) { struct saa6588 *s; - client_template.adapter = adap; - client_template.addr = addr; - printk(PREFIX "chip found @ 0x%x\n", addr << 1); + v4l_info(client, "saa6588 found @ 0x%x (%s)\n", + client->addr << 1, client->adapter->name); - if (NULL == (s = kmalloc(sizeof(*s), GFP_KERNEL))) + s = kzalloc(sizeof(*s), GFP_KERNEL); + if (s == NULL) return -ENOMEM; + s->client = client; s->buf_size = bufblocks * 3; - if (NULL == (s->buffer = kmalloc(s->buf_size, GFP_KERNEL))) { + s->buffer = kmalloc(s->buf_size, GFP_KERNEL); + if (s->buffer == NULL) { kfree(s); return -ENOMEM; } spin_lock_init(&s->lock); - s->client = client_template; s->block_count = 0; s->wr_index = 0; s->rd_index = 0; s->last_blocknum = 0xff; init_waitqueue_head(&s->read_queue); s->data_available_for_read = 0; - i2c_set_clientdata(&s->client, s); - i2c_attach_client(&s->client); + i2c_set_clientdata(client, s); saa6588_configure(s); @@ -440,21 +441,13 @@ static int saa6588_attach(struct i2c_adapter *adap, int addr, int kind) return 0; } -static int saa6588_probe(struct i2c_adapter *adap) -{ - if (adap->class & I2C_CLASS_TV_ANALOG) - return i2c_probe(adap, &addr_data, saa6588_attach); - return 0; -} - -static int saa6588_detach(struct i2c_client *client) +static int saa6588_remove(struct i2c_client *client) { struct saa6588 *s = i2c_get_clientdata(client); del_timer_sync(&s->timer); flush_scheduled_work(); - i2c_detach_client(client); kfree(s->buffer); kfree(s); return 0; @@ -499,38 +492,21 @@ static int saa6588_command(struct i2c_client *client, unsigned int cmd, /* ----------------------------------------------------------------------- */ -static struct i2c_driver driver = { - .driver = { - .name = "saa6588", - }, - .id = -1, /* FIXME */ - .attach_adapter = saa6588_probe, - .detach_client = saa6588_detach, - .command = saa6588_command, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) +static const struct i2c_device_id saa6588_id[] = { + { "saa6588", 0 }, + { } }; +MODULE_DEVICE_TABLE(i2c, saa6588_id); -static struct i2c_client client_template = { +#endif +static struct v4l2_i2c_driver_data v4l2_i2c_data = { .name = "saa6588", - .driver = &driver, + .command = saa6588_command, + .probe = saa6588_probe, + .remove = saa6588_remove, + .legacy_class = I2C_CLASS_TV_ANALOG, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) + .id_table = saa6588_id, +#endif }; - -static int __init saa6588_init_module(void) -{ - return i2c_add_driver(&driver); -} - -static void __exit saa6588_cleanup_module(void) -{ - i2c_del_driver(&driver); -} - -module_init(saa6588_init_module); -module_exit(saa6588_cleanup_module); - -/* - * Overrides for Emacs so that we follow Linus's tabbing style. - * --------------------------------------------------------------------------- - * Local variables: - * c-basic-offset: 8 - * End: - */ -- cgit v1.2.3 From ed3c315b6213d5787151999cac89a343634a4814 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 11 Feb 2009 23:23:57 +0100 Subject: saa6588: convert to v4l2_subdev. From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- linux/drivers/media/video/saa6588.c | 117 ++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 45 deletions(-) diff --git a/linux/drivers/media/video/saa6588.c b/linux/drivers/media/video/saa6588.c index 57a40e62f..53c74f2ba 100644 --- a/linux/drivers/media/video/saa6588.c +++ b/linux/drivers/media/video/saa6588.c @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include "compat.h" @@ -75,7 +75,7 @@ MODULE_LICENSE("GPL"); #define dprintk if (debug) printk struct saa6588 { - struct i2c_client *client; + struct v4l2_subdev sd; struct work_struct work; struct timer_list timer; spinlock_t lock; @@ -89,6 +89,11 @@ struct saa6588 { int data_available_for_read; }; +static inline struct saa6588 *to_saa6588(struct v4l2_subdev *sd) +{ + return container_of(sd, struct saa6588, sd); +} + /* ---------------------------------------------------------------------- */ /* @@ -258,6 +263,7 @@ static void block_to_buf(struct saa6588 *s, unsigned char *blockbuf) static void saa6588_i2c_poll(struct saa6588 *s) { + struct i2c_client *client = v4l2_get_subdevdata(&s->sd); unsigned long flags; unsigned char tmpbuf[6]; unsigned char blocknum; @@ -265,7 +271,7 @@ static void saa6588_i2c_poll(struct saa6588 *s) /* Although we only need 3 bytes, we have to read at least 6. SAA6588 returns garbage otherwise */ - if (6 != i2c_master_recv(s->client, &tmpbuf[0], 6)) { + if (6 != i2c_master_recv(client, &tmpbuf[0], 6)) { if (debug > 1) dprintk(PREFIX "read error!\n"); return; @@ -341,6 +347,7 @@ static void saa6588_work(struct work_struct *work) static int saa6588_configure(struct saa6588 *s) { + struct i2c_client *client = v4l2_get_subdevdata(&s->sd); unsigned char buf[3]; int rc; @@ -388,7 +395,7 @@ static int saa6588_configure(struct saa6588 *s) dprintk(PREFIX "writing: 0w=0x%02x 1w=0x%02x 2w=0x%02x\n", buf[0], buf[1], buf[2]); - rc = i2c_master_send(s->client, buf, 3); + rc = i2c_master_send(client, buf, 3); if (rc != 3) printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc); @@ -397,10 +404,64 @@ static int saa6588_configure(struct saa6588 *s) /* ---------------------------------------------------------------------- */ +static long saa6588_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) +{ + struct saa6588 *s = to_saa6588(sd); + struct rds_command *a = arg; + + switch (cmd) { + /* --- open() for /dev/radio --- */ + case RDS_CMD_OPEN: + a->result = 0; /* return error if chip doesn't work ??? */ + break; + /* --- close() for /dev/radio --- */ + case RDS_CMD_CLOSE: + s->data_available_for_read = 1; + wake_up_interruptible(&s->read_queue); + a->result = 0; + break; + /* --- read() for /dev/radio --- */ + case RDS_CMD_READ: + read_from_buf(s, a); + break; + /* --- poll() for /dev/radio --- */ + case RDS_CMD_POLL: + a->result = 0; + if (s->data_available_for_read) { + a->result |= POLLIN | POLLRDNORM; + } + poll_wait(a->instance, &s->read_queue, a->event_list); + break; + + default: + /* nothing */ + return -ENOIOCTLCMD; + } + return 0; +} + +static int saa6588_command(struct i2c_client *client, unsigned cmd, void *arg) +{ + return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); +} + +/* ----------------------------------------------------------------------- */ + +static const struct v4l2_subdev_core_ops saa6588_core_ops = { + .ioctl = saa6588_ioctl, +}; + +static const struct v4l2_subdev_ops saa6588_ops = { + .core = &saa6588_core_ops, +}; + +/* ---------------------------------------------------------------------- */ + static int saa6588_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct saa6588 *s; + struct v4l2_subdev *sd; v4l_info(client, "saa6588 found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); @@ -409,7 +470,6 @@ static int saa6588_probe(struct i2c_client *client, if (s == NULL) return -ENOMEM; - s->client = client; s->buf_size = bufblocks * 3; s->buffer = kmalloc(s->buf_size, GFP_KERNEL); @@ -417,6 +477,8 @@ static int saa6588_probe(struct i2c_client *client, kfree(s); return -ENOMEM; } + sd = &s->sd; + v4l2_i2c_subdev_init(sd, client, &saa6588_ops); spin_lock_init(&s->lock); s->block_count = 0; s->wr_index = 0; @@ -424,12 +486,11 @@ static int saa6588_probe(struct i2c_client *client, s->last_blocknum = 0xff; init_waitqueue_head(&s->read_queue); s->data_available_for_read = 0; - i2c_set_clientdata(client, s); saa6588_configure(s); /* start polling via eventd */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) INIT_WORK(&s->work, saa6588_work, s); #else INIT_WORK(&s->work, saa6588_work); @@ -443,7 +504,10 @@ static int saa6588_probe(struct i2c_client *client, static int saa6588_remove(struct i2c_client *client) { - struct saa6588 *s = i2c_get_clientdata(client); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct saa6588 *s = to_saa6588(sd); + + v4l2_device_unregister_subdev(sd); del_timer_sync(&s->timer); flush_scheduled_work(); @@ -453,43 +517,6 @@ static int saa6588_remove(struct i2c_client *client) return 0; } -static int saa6588_command(struct i2c_client *client, unsigned int cmd, - void *arg) -{ - struct saa6588 *s = i2c_get_clientdata(client); - struct rds_command *a = (struct rds_command *)arg; - - switch (cmd) { - /* --- open() for /dev/radio --- */ - case RDS_CMD_OPEN: - a->result = 0; /* return error if chip doesn't work ??? */ - break; - /* --- close() for /dev/radio --- */ - case RDS_CMD_CLOSE: - s->data_available_for_read = 1; - wake_up_interruptible(&s->read_queue); - a->result = 0; - break; - /* --- read() for /dev/radio --- */ - case RDS_CMD_READ: - read_from_buf(s, a); - break; - /* --- poll() for /dev/radio --- */ - case RDS_CMD_POLL: - a->result = 0; - if (s->data_available_for_read) { - a->result |= POLLIN | POLLRDNORM; - } - poll_wait(a->instance, &s->read_queue, a->event_list); - break; - - default: - /* nothing */ - break; - } - return 0; -} - /* ----------------------------------------------------------------------- */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) -- cgit v1.2.3 From d096d77d6e81756f65115cc8c10a2df07c64d466 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 11 Feb 2009 23:28:30 +0100 Subject: saa6588: add g_chip_ident support. From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- linux/drivers/media/video/saa6588.c | 9 +++++++++ linux/include/media/v4l2-chip-ident.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/linux/drivers/media/video/saa6588.c b/linux/drivers/media/video/saa6588.c index 53c74f2ba..4f60df943 100644 --- a/linux/drivers/media/video/saa6588.c +++ b/linux/drivers/media/video/saa6588.c @@ -33,6 +33,7 @@ #include #include +#include #include #include "compat.h" @@ -440,6 +441,13 @@ static long saa6588_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return 0; } +static int saa6588_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + + return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA6588, 0); +} + static int saa6588_command(struct i2c_client *client, unsigned cmd, void *arg) { return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); @@ -448,6 +456,7 @@ static int saa6588_command(struct i2c_client *client, unsigned cmd, void *arg) /* ----------------------------------------------------------------------- */ static const struct v4l2_subdev_core_ops saa6588_core_ops = { + .g_chip_ident = saa6588_g_chip_ident, .ioctl = saa6588_ioctl, }; diff --git a/linux/include/media/v4l2-chip-ident.h b/linux/include/media/v4l2-chip-ident.h index 4e2182e52..bbe2bb6a5 100644 --- a/linux/include/media/v4l2-chip-ident.h +++ b/linux/include/media/v4l2-chip-ident.h @@ -92,6 +92,9 @@ enum { /* module tea6420: just ident 6420 */ V4L2_IDENT_TEA6420 = 6420, + /* module saa6588: just ident 6588 */ + V4L2_IDENT_SAA6588 = 6588, + /* module saa6752hs: reserved range 6750-6759 */ V4L2_IDENT_SAA6752HS = 6752, V4L2_IDENT_SAA6752HS_AC3 = 6753, -- cgit v1.2.3 From 4162a001c7f1ef358a70ce97fa1867e3d102cb32 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 13 Feb 2009 09:08:27 +0100 Subject: saa6588: remove legacy_class, not needed for saa6588 From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- linux/drivers/media/video/saa6588.c | 1 - 1 file changed, 1 deletion(-) diff --git a/linux/drivers/media/video/saa6588.c b/linux/drivers/media/video/saa6588.c index 4f60df943..77c3b59e8 100644 --- a/linux/drivers/media/video/saa6588.c +++ b/linux/drivers/media/video/saa6588.c @@ -541,7 +541,6 @@ static struct v4l2_i2c_driver_data v4l2_i2c_data = { .command = saa6588_command, .probe = saa6588_probe, .remove = saa6588_remove, - .legacy_class = I2C_CLASS_TV_ANALOG, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) .id_table = saa6588_id, #endif -- cgit v1.2.3 From 52a672f1e1c02901afbfcc810f5ab962759a05e0 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 13 Feb 2009 09:12:02 +0100 Subject: cx2341x: fixed bug causing several audio controls to be no longer listed From: Hans Verkuil The cx2341x_mpeg_ctrls array must be ordered by control ID. I know that this is bad design, but for now I will just fix this bug and revisit it when all drivers have moved to v4l2_device/v4l2_subdev, since that will allow me to do greatly improve control handling. Priority: normal Signed-off-by: Hans Verkuil --- linux/drivers/media/video/cx2341x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/drivers/media/video/cx2341x.c b/linux/drivers/media/video/cx2341x.c index c92b98135..ebee97bc2 100644 --- a/linux/drivers/media/video/cx2341x.c +++ b/linux/drivers/media/video/cx2341x.c @@ -46,12 +46,12 @@ const u32 cx2341x_mpeg_ctrls[] = { V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ, V4L2_CID_MPEG_AUDIO_ENCODING, V4L2_CID_MPEG_AUDIO_L2_BITRATE, - V4L2_CID_MPEG_AUDIO_AC3_BITRATE, V4L2_CID_MPEG_AUDIO_MODE, V4L2_CID_MPEG_AUDIO_MODE_EXTENSION, V4L2_CID_MPEG_AUDIO_EMPHASIS, V4L2_CID_MPEG_AUDIO_CRC, V4L2_CID_MPEG_AUDIO_MUTE, + V4L2_CID_MPEG_AUDIO_AC3_BITRATE, V4L2_CID_MPEG_VIDEO_ENCODING, V4L2_CID_MPEG_VIDEO_ASPECT, V4L2_CID_MPEG_VIDEO_B_FRAMES, -- cgit v1.2.3