V4L/DVB (6463): upd64031a: convert to bus-based I2C API
[pandora-kernel.git] / drivers / media / video / upd64031a.c
index b3b5fd5..b060ce3 100644 (file)
@@ -27,6 +27,8 @@
 #include <linux/i2c.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-chip-ident.h>
+#include <media/v4l2-i2c-drv-legacy.h>
 #include <media/upd64031a.h>
 
 // --------------------- read registers functions define -----------------------
@@ -167,7 +169,7 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
        {
                struct v4l2_register *reg = arg;
 
-               if (reg->i2c_id != I2C_DRIVERID_UPD64031A)
+               if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
@@ -179,6 +181,9 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
        }
 #endif
 
+       case VIDIOC_G_CHIP_IDENT:
+               return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_UPD64031A, 0);
+
        default:
                break;
        }
@@ -189,32 +194,18 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
 
 /* i2c implementation */
 
-static struct i2c_driver i2c_driver;
-
-static int upd64031a_attach(struct i2c_adapter *adapter, int address, int kind)
+static int upd64031a_probe(struct i2c_client *client)
 {
-       struct i2c_client *client;
        struct upd64031a_state *state;
        int i;
 
-       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                return 0;
 
-       client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
-       if (client == NULL) {
-               return -ENOMEM;
-       }
-
-       client->addr = address;
-       client->adapter = adapter;
-       client->driver = &i2c_driver;
-       snprintf(client->name, sizeof(client->name) - 1, "uPD64031A");
-
-       v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
+       v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
 
        state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL);
        if (state == NULL) {
-               kfree(client);
                return -ENOMEM;
        }
        i2c_set_clientdata(client, state);
@@ -225,54 +216,22 @@ static int upd64031a_attach(struct i2c_adapter *adapter, int address, int kind)
        for (i = 0; i < TOT_REGS; i++) {
                upd64031a_write(client, i, state->regs[i]);
        }
-
-       i2c_attach_client(client);
-
-       return 0;
-}
-
-static int upd64031a_probe(struct i2c_adapter *adapter)
-{
-       if (adapter->class & I2C_CLASS_TV_ANALOG)
-               return i2c_probe(adapter, &addr_data, upd64031a_attach);
        return 0;
 }
 
-static int upd64031a_detach(struct i2c_client *client)
+static int upd64031a_remove(struct i2c_client *client)
 {
-       int err;
-
-       err = i2c_detach_client(client);
-       if (err)
-               return err;
-
-       kfree(client);
+       kfree(i2c_get_clientdata(client));
        return 0;
 }
 
 /* ----------------------------------------------------------------------- */
 
-/* i2c implementation */
-static struct i2c_driver i2c_driver = {
-       .driver = {
-               .name = "upd64031a",
-       },
-       .id = I2C_DRIVERID_UPD64031A,
-       .attach_adapter = upd64031a_probe,
-       .detach_client  = upd64031a_detach,
+
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+       .name = "upd64031a",
+       .driverid = I2C_DRIVERID_UPD64031A,
        .command = upd64031a_command,
+       .probe = upd64031a_probe,
+       .remove = upd64031a_remove,
 };
-
-
-static int __init upd64031a_init_module(void)
-{
-       return i2c_add_driver(&i2c_driver);
-}
-
-static void __exit upd64031a_exit_module(void)
-{
-       i2c_del_driver(&i2c_driver);
-}
-
-module_init(upd64031a_init_module);
-module_exit(upd64031a_exit_module);