i2c: Add support for device alias names
[safe/jmp/linux-2.6] / drivers / media / video / upd64083.c
index 3f0eec0..9ab712a 100644 (file)
@@ -17,7 +17,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
  */
 
 #include <linux/version.h>
 #include <linux/i2c.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-chip-ident.h>
+#include <media/v4l2-i2c-drv.h>
 #include <media/upd64083.h>
 
 MODULE_DESCRIPTION("uPD64083 driver");
 MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil");
 MODULE_LICENSE("GPL");
 
-static int debug = 0;
+static int debug;
 module_param(debug, bool, 0644);
 
 MODULE_PARM_DESC(debug, "Debug level (0-1)");
 
-static unsigned short normal_i2c[] = { 0xb8 >> 1, 0xba >> 1, I2C_CLIENT_END };
-
-
-I2C_CLIENT_INSMOD;
 
 enum {
        R00 = 0, R01, R02, R03, R04,
@@ -87,7 +86,7 @@ static void upd64083_write(struct i2c_client *client, u8 reg, u8 val)
 
        buf[0] = reg;
        buf[1] = val;
-       v4l_dbg(1, debug, client, "writing reg addr: %02x val: %02x\n", reg, val);
+       v4l_dbg(1, debug, client, "write reg: %02x val: %02x\n", reg, val);
        if (i2c_master_send(client, buf, 2) != 2)
                v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val);
 }
@@ -108,7 +107,7 @@ static u8 upd64083_read(struct i2c_client *client, u8 reg)
 
 /* ------------------------------------------------------------------------ */
 
-static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *arg)
+static int upd64083_command(struct i2c_client *client, unsigned cmd, void *arg)
 {
        struct upd64083_state *state = i2c_get_clientdata(client);
        struct v4l2_routing *route = arg;
@@ -140,29 +139,28 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
        case VIDIOC_DBG_G_REGISTER:
-       {
-               struct v4l2_register *reg = arg;
-
-               if (reg->i2c_id != I2C_DRIVERID_UPD64083)
-                       return -EINVAL;
-               reg->val = upd64083_read(client, reg->reg & 0xff);
-               break;
-       }
-
        case VIDIOC_DBG_S_REGISTER:
        {
                struct v4l2_register *reg = arg;
-               u8 addr = reg->reg & 0xff;
-               u8 val = reg->val & 0xff;
 
-               if (reg->i2c_id != I2C_DRIVERID_UPD64083)
+               if (!v4l2_chip_match_i2c_client(client,
+                               reg->match_type, reg->match_chip))
                        return -EINVAL;
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
-               upd64083_write(client, addr, val);
+               if (cmd == VIDIOC_DBG_G_REGISTER) {
+                       reg->val = upd64083_read(client, reg->reg & 0xff);
+                       break;
+               }
+               upd64083_write(client, reg->reg & 0xff, reg->val & 0xff);
                break;
        }
 #endif
+
+       case VIDIOC_G_CHIP_IDENT:
+               return v4l2_chip_ident_i2c_client(client, arg,
+                               V4L2_IDENT_UPD64083, 0);
+
        default:
                break;
        }
@@ -174,89 +172,44 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a
 
 /* i2c implementation */
 
-static struct i2c_driver i2c_driver;
-
-static int upd64083_attach(struct i2c_adapter *adapter, int address, int kind)
+static int upd64083_probe(struct i2c_client *client,
+                         const struct i2c_device_id *id)
 {
-       struct i2c_client *client;
        struct upd64083_state *state;
        int i;
 
-       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-               return 0;
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+               return -EIO;
 
-       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, "uPD64083");
-
-       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 upd64083_state), GFP_KERNEL);
-       if (state == NULL) {
-               kfree(client);
+       if (state == NULL)
                return -ENOMEM;
-       }
        i2c_set_clientdata(client, state);
        /* Initially assume that a ghost reduction chip is present */
        state->mode = 0;  /* YCS mode */
        state->ext_y_adc = (1 << 5);
        memcpy(state->regs, upd64083_init, TOT_REGS);
-       for (i = 0; i < TOT_REGS; i++) {
+       for (i = 0; i < TOT_REGS; i++)
                upd64083_write(client, i, state->regs[i]);
-       }
-       i2c_attach_client(client);
-
        return 0;
 }
 
-static int upd64083_probe(struct i2c_adapter *adapter)
+static int upd64083_remove(struct i2c_client *client)
 {
-       if (adapter->class & I2C_CLASS_TV_ANALOG)
-               return i2c_probe(adapter, &addr_data, upd64083_attach);
-       return 0;
-}
-
-static int upd64083_detach(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 = "upd64083",
-       },
-       .id = I2C_DRIVERID_UPD64083,
-       .attach_adapter = upd64083_probe,
-       .detach_client  = upd64083_detach,
+
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+       .name = "upd64083",
+       .driverid = I2C_DRIVERID_UPD64083,
        .command = upd64083_command,
+       .probe = upd64083_probe,
+       .remove = upd64083_remove,
 };
-
-
-static int __init upd64083_init_module(void)
-{
-       return i2c_add_driver(&i2c_driver);
-}
-
-static void __exit upd64083_exit_module(void)
-{
-       i2c_del_driver(&i2c_driver);
-}
-
-module_init(upd64083_init_module);
-module_exit(upd64083_exit_module);