As Tyler (and the FIXME) suggested, this will bail out if a cx25840 isn't detected at the specified address on the i2c bus. It also makes the device_id output prettier. I also added a line to disable ACFG when doing vbi_reg_setup, since we're overwriting all the fields ACFG would set anyway. Shouldn't make a difference, but it could prevent any surprise changes to the the registers that would mess up VBI.

As a side note: Should we also add a line to cx25850_read that sets buffer[0] = 0 in between the read and the write? Otherwise we'll get the high byte of our address back if the write / read fails. Might also want to check the retval of the write and not read if we get -ETIMEOUT.
Index: driver/cx25840-driver.c
===================================================================
--- driver/cx25840-driver.c     (revision 311)
+++ driver/cx25840-driver.c     (working copy)
@@ -211,6 +211,10 @@
                break;
        }
 
+       // We set 0x470-0x47f manually, prevent
+       // ACFG from trying to autodetect 
+       CX25840_SET_ACFG_DIS(0x01);
+
        if (is_pal) {
                // 8d.
                CX25840_SET_COMB_PHASE_LIMIT(0x11);
@@ -990,6 +994,7 @@
 {
        struct i2c_client *client;
        struct decoder_state *state;
+       u16 device_id;
 
        DEBUG(0, "detecting cx25840 client on address 0x%x", address << 1);
 
@@ -1015,6 +1020,17 @@
        snprintf(client->name, sizeof(client->name) - 1, "cx25840[%u]",
                 (unsigned)sizeof(I2C_NAME(client)));
 
+       device_id = cx25840_read_setting(client, DEVICE_ID);
+       // The high byte of the device ID should be 0x84 if chip is present
+       if ((device_id & 0x8400) != 0x8400) {
+               DEBUG(0, "cx25840 not found");
+               kfree(client);
+               return 0;
+       }
+       DEBUG(1, "cx25%3x-2%x found", 
+               (device_id & 0xfff0) >> 4,
+               (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : 3);
+
        state = kmalloc(sizeof(struct decoder_state), GFP_KERNEL);
        i2c_set_clientdata(client, state);
        if (state == NULL) {
@@ -1049,9 +1065,6 @@
 
        cx25840_initialize(client);
 
-       // FIXME Use this device ID to detect if chip is present...
-       DEBUG(1, "Status: cx25%3X (DEVICE_ID)",
-             cx25840_read_setting(client, DEVICE_ID));
 
        i2c_attach_client(client);
        log_status(client);

Reply via email to