viafb: Eliminate some global.h references
[deliverable/linux.git] / drivers / video / via / via_i2c.c
index 3ff60b280d8872a00ddda042c0f8efbb33f1b2f9..2291765f2f8efe06929d4799e6b50c7fa8bd3637 100644 (file)
  */
 
 #include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/module.h>
 #include "via-core.h"
 #include "via_i2c.h"
-#include "global.h"
 
 /*
  * There can only be one set of these, so there's no point in having
@@ -52,7 +54,7 @@ static void via_i2c_setscl(void *data, int state)
                val |= 0x80;
                break;
        default:
-               DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
+               printk(KERN_ERR "viafb_i2c: specify wrong i2c type.\n");
        }
        via_write_reg(adap_data->io_port, adap_data->ioport_index, val);
        spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
@@ -104,7 +106,7 @@ static void via_i2c_setsda(void *data, int state)
                val |= 0x40;
                break;
        default:
-               DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
+               printk(KERN_ERR "viafb_i2c: specify wrong i2c type.\n");
        }
        via_write_reg(adap_data->io_port, adap_data->ioport_index, val);
        spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
@@ -115,6 +117,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 +134,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 +148,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;
@@ -151,13 +159,24 @@ int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len
        return i2c_transfer(&via_i2c_par[adap].adapter, msgs, 2);
 }
 
+/*
+ * Allow other viafb subdevices to look up a specific adapter
+ * by port name.
+ */
+struct i2c_adapter *viafb_find_i2c_adapter(enum viafb_i2c_adap which)
+{
+       struct via_i2c_stuff *stuff = &via_i2c_par[which];
+
+       return &stuff->adapter;
+}
+EXPORT_SYMBOL_GPL(viafb_find_i2c_adapter);
+
+
 static int create_i2c_bus(struct i2c_adapter *adapter,
                          struct i2c_algo_bit_data *algo,
                          struct via_port_cfg *adap_cfg,
                          struct pci_dev *pdev)
 {
-       DEBUG_MSG(KERN_DEBUG "viafb: creating bus adap=0x%p, algo_bit_data=0x%p, adap_cfg=0x%p\n", adapter, algo, adap_cfg);
-
        algo->setsda = via_i2c_setsda;
        algo->setscl = via_i2c_setscl;
        algo->getsda = via_i2c_getsda;
@@ -198,18 +217,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 +244,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;
This page took 0.027903 seconds and 5 git commands to generate.