From babb7dc7776dd6ded4e1e6cb7acc34c25c0eb521 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 13 Feb 2009 07:31:05 -0300 Subject: [PATCH] V4L/DVB (10860): saa7191: convert to v4l2-i2c-drv-legacy.h Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/saa7191.c | 157 ++++++++++++++-------------------- 1 file changed, 63 insertions(+), 94 deletions(-) diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c index b4018cce3285..9943e5c35e15 100644 --- a/drivers/media/video/saa7191.c +++ b/drivers/media/video/saa7191.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "saa7191.h" @@ -32,6 +34,10 @@ MODULE_VERSION(SAA7191_MODULE_VERSION); MODULE_AUTHOR("Mikael Nousiainen "); MODULE_LICENSE("GPL"); +static unsigned short normal_i2c[] = { 0x8a >> 1, 0x8e >> 1, I2C_CLIENT_END }; + +I2C_CLIENT_INSMOD; + // #define SAA7191_DEBUG #ifdef SAA7191_DEBUG @@ -54,8 +60,6 @@ struct saa7191 { int norm; }; -static struct i2c_driver i2c_driver_saa7191; - static const u8 initseq[] = { 0, /* Subaddress */ @@ -561,83 +565,6 @@ static int saa7191_set_control(struct i2c_client *client, /* I2C-interface */ -static int saa7191_attach(struct i2c_adapter *adap, int addr, int kind) -{ - int err = 0; - struct saa7191 *decoder; - struct i2c_client *client; - - printk(KERN_INFO "Philips SAA7191 driver version %s\n", - SAA7191_MODULE_VERSION); - - client = kzalloc(sizeof(*client), GFP_KERNEL); - if (!client) - return -ENOMEM; - decoder = kzalloc(sizeof(*decoder), GFP_KERNEL); - if (!decoder) { - err = -ENOMEM; - goto out_free_client; - } - - client->addr = addr; - client->adapter = adap; - client->driver = &i2c_driver_saa7191; - client->flags = 0; - strcpy(client->name, "saa7191 client"); - i2c_set_clientdata(client, decoder); - - decoder->client = client; - - err = i2c_attach_client(client); - if (err) - goto out_free_decoder; - - err = saa7191_write_block(client, sizeof(initseq), initseq); - if (err) { - printk(KERN_ERR "SAA7191 initialization failed\n"); - goto out_detach_client; - } - - printk(KERN_INFO "SAA7191 initialized\n"); - - decoder->input = SAA7191_INPUT_COMPOSITE; - decoder->norm = SAA7191_NORM_PAL; - - err = saa7191_autodetect_norm(client); - if (err && (err != -EBUSY)) { - printk(KERN_ERR "SAA7191: Signal auto-detection failed\n"); - } - - return 0; - -out_detach_client: - i2c_detach_client(client); -out_free_decoder: - kfree(decoder); -out_free_client: - kfree(client); - return err; -} - -static int saa7191_probe(struct i2c_adapter *adap) -{ - /* Always connected to VINO */ - if (adap->id == I2C_HW_SGI_VINO) - return saa7191_attach(adap, SAA7191_ADDR, 0); - /* Feel free to add probe here :-) */ - return -ENODEV; -} - -static int saa7191_detach(struct i2c_client *client) -{ - struct saa7191 *decoder = i2c_get_clientdata(client); - - i2c_detach_client(client); - kfree(decoder); - kfree(client); - return 0; -} - static int saa7191_command(struct i2c_client *client, unsigned int cmd, void *arg) { @@ -783,25 +710,67 @@ static int saa7191_command(struct i2c_client *client, unsigned int cmd, return 0; } -static struct i2c_driver i2c_driver_saa7191 = { - .driver = { - .name = "saa7191", - }, - .id = I2C_DRIVERID_SAA7191, - .attach_adapter = saa7191_probe, - .detach_client = saa7191_detach, - .command = saa7191_command -}; +static int saa7191_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int err = 0; + struct saa7191 *decoder; -static int saa7191_init(void) + v4l_info(client, "chip found @ 0x%x (%s)\n", + client->addr << 1, client->adapter->name); + + decoder = kzalloc(sizeof(*decoder), GFP_KERNEL); + if (!decoder) + return -ENOMEM; + + i2c_set_clientdata(client, decoder); + + decoder->client = client; + + err = saa7191_write_block(client, sizeof(initseq), initseq); + if (err) { + printk(KERN_ERR "SAA7191 initialization failed\n"); + kfree(decoder); + return err; + } + + printk(KERN_INFO "SAA7191 initialized\n"); + + decoder->input = SAA7191_INPUT_COMPOSITE; + decoder->norm = SAA7191_NORM_PAL; + + err = saa7191_autodetect_norm(client); + if (err && (err != -EBUSY)) + printk(KERN_ERR "SAA7191: Signal auto-detection failed\n"); + + return 0; +} + +static int saa7191_remove(struct i2c_client *client) { - return i2c_add_driver(&i2c_driver_saa7191); + struct saa7191 *decoder = i2c_get_clientdata(client); + + kfree(decoder); + return 0; } -static void saa7191_exit(void) +static int saa7191_legacy_probe(struct i2c_adapter *adapter) { - i2c_del_driver(&i2c_driver_saa7191); + return adapter->id == I2C_HW_SGI_VINO; } -module_init(saa7191_init); -module_exit(saa7191_exit); +static const struct i2c_device_id saa7191_id[] = { + { "saa7191", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, saa7191_id); + +static struct v4l2_i2c_driver_data v4l2_i2c_data = { + .name = "saa7191", + .driverid = I2C_DRIVERID_SAA7191, + .command = saa7191_command, + .probe = saa7191_probe, + .remove = saa7191_remove, + .legacy_probe = saa7191_legacy_probe, + .id_table = saa7191_id, +}; -- 2.30.2