via: Do not attempt I/O on inactive I2C adapters
authorJonathan Corbet <corbet@lwn.net>
Mon, 28 Dec 2009 17:04:02 +0000 (10:04 -0700)
committerJonathan Corbet <corbet@lwn.net>
Fri, 7 May 2010 23:17:37 +0000 (17:17 -0600)
If an adapter has been configured for GPIO (or off), we should not try to
use it as an I2C port.

Cc: ScottFang@viatech.com.cn
Cc: JosephChan@via.com.tw
Cc: Harald Welte <laforge@gnumonks.org>
Acked-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
drivers/video/via/via_i2c.c
drivers/video/via/via_i2c.h

index 3ff60b280d8872a00ddda042c0f8efbb33f1b2f9..c88450ee62baf821a9320207b36ff46955f06251 100644 (file)
@@ -115,6 +115,8 @@ int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata)
        u8 mm1[] = {0x00};
        struct i2c_msg msgs[2];
 
+       if (!via_i2c_par[adap].is_active)
+               return -ENODEV;
        *pdata = 0;
        msgs[0].flags = 0;
        msgs[1].flags = I2C_M_RD;
@@ -130,6 +132,8 @@ int viafb_i2c_writebyte(u8 adap, u8 slave_addr, u8 index, u8 data)
        u8 msg[2] = { index, data };
        struct i2c_msg msgs;
 
+       if (!via_i2c_par[adap].is_active)
+               return -ENODEV;
        msgs.flags = 0;
        msgs.addr = slave_addr / 2;
        msgs.len = 2;
@@ -142,6 +146,8 @@ int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len
        u8 mm1[] = {0x00};
        struct i2c_msg msgs[2];
 
+       if (!via_i2c_par[adap].is_active)
+               return -ENODEV;
        msgs[0].flags = 0;
        msgs[1].flags = I2C_M_RD;
        msgs[0].addr = msgs[1].addr = slave_addr / 2;
@@ -198,18 +204,18 @@ static int viafb_i2c_probe(struct platform_device *platdev)
                struct via_port_cfg *adap_cfg = configs++;
                struct via_i2c_stuff *i2c_stuff = &via_i2c_par[i];
 
+               i2c_stuff->is_active = 0;
                if (adap_cfg->type == 0 || adap_cfg->mode != VIA_MODE_I2C)
                        continue;
-
                ret = create_i2c_bus(&i2c_stuff->adapter,
                                     &i2c_stuff->algo, adap_cfg,
                                NULL); /* FIXME: PCIDEV */
                if (ret < 0) {
                        printk(KERN_ERR "viafb: cannot create i2c bus %u:%d\n",
                                i, ret);
-                       /* FIXME: properly release previous busses */
-                       return ret;
+                       continue;  /* Still try to make the rest */
                }
+               i2c_stuff->is_active = 1;
        }
 
        return 0;
@@ -225,7 +231,7 @@ static int viafb_i2c_remove(struct platform_device *platdev)
                 * Only remove those entries in the array that we've
                 * actually used (and thus initialized algo_data)
                 */
-               if (i2c_stuff->adapter.algo_data == &i2c_stuff->algo)
+               if (i2c_stuff->is_active)
                        i2c_del_adapter(&i2c_stuff->adapter);
        }
        return 0;
index b2332cce9d18b3ae1890c57ed41b98a780ff6448..1d18e7d57b7f7fcdec98f60b30c768377fb3d6a6 100644 (file)
@@ -26,6 +26,7 @@
 
 struct via_i2c_stuff {
        u16 i2c_port;                   /* GPIO or I2C port */
+       u16 is_active;                  /* Being used as I2C? */
        struct i2c_adapter adapter;
        struct i2c_algo_bit_data algo;
 };
This page took 0.028794 seconds and 5 git commands to generate.