]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/i2c/busses/i2c-sis5595.c
i2c: Let bus drivers add SPD to their class
[linux-2.6-omap-h63xx.git] / drivers / i2c / busses / i2c-sis5595.c
index a6feed449dbe65756ee0016e93fc1be5859dd4f4..f76944b384f57c279d6dd0ae0ac5370778ee612b 100644 (file)
@@ -129,6 +129,7 @@ MODULE_PARM_DESC(force_addr, "Initialize the base address of the i2c controller"
 
 static struct pci_driver sis5595_driver;
 static unsigned short sis5595_base;
+static struct pci_dev *sis5595_pdev;
 
 static u8 sis5595_read(u8 reg)
 {
@@ -235,9 +236,9 @@ static int sis5595_transaction(struct i2c_adapter *adap)
                sis5595_write(SMB_STS_HI, temp >> 8);
                if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) {
                        dev_dbg(&adap->dev, "Failed! (%02x)\n", temp);
-                       return -1;
+                       return -EBUSY;
                } else {
-                       dev_dbg(&adap->dev, "Successfull!\n");
+                       dev_dbg(&adap->dev, "Successful!\n");
                }
        }
 
@@ -253,19 +254,19 @@ static int sis5595_transaction(struct i2c_adapter *adap)
        /* If the SMBus is still busy, we give up */
        if (timeout >= MAX_TIMEOUT) {
                dev_dbg(&adap->dev, "SMBus Timeout!\n");
-               result = -1;
+               result = -ETIMEDOUT;
        }
 
        if (temp & 0x10) {
                dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
-               result = -1;
+               result = -ENXIO;
        }
 
        if (temp & 0x20) {
                dev_err(&adap->dev, "Bus collision! SMBus may be locked until "
                        "next hard reset (or not...)\n");
                /* Clock stops and slave is stuck in mid-transmission */
-               result = -1;
+               result = -EIO;
        }
 
        temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8);
@@ -281,11 +282,13 @@ static int sis5595_transaction(struct i2c_adapter *adap)
        return result;
 }
 
-/* Return -1 on error. */
+/* Return negative errno on error. */
 static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
                          unsigned short flags, char read_write,
                          u8 command, int size, union i2c_smbus_data *data)
 {
+       int status;
+
        switch (size) {
        case I2C_SMBUS_QUICK:
                sis5595_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01));
@@ -315,21 +318,16 @@ static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
                }
                size = (size == I2C_SMBUS_PROC_CALL) ? SIS5595_PROC_CALL : SIS5595_WORD_DATA;
                break;
-/*
-       case I2C_SMBUS_BLOCK_DATA:
-               printk(KERN_WARNING "sis5595.o: Block data not yet implemented!\n");
-               return -1;
-               break;
-*/
        default:
-               printk(KERN_WARNING "sis5595.o: Unsupported transaction %d\n", size);
-               return -1;
+               dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
+               return -EOPNOTSUPP;
        }
 
        sis5595_write(SMB_CTL_LO, ((size & 0x0E)));
 
-       if (sis5595_transaction(adap))
-               return -1;
+       status = sis5595_transaction(adap);
+       if (status)
+               return status;
 
        if ((size != SIS5595_PROC_CALL) &&
            ((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK)))
@@ -337,9 +335,7 @@ static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
 
 
        switch (size) {
-       case SIS5595_BYTE:      /* Where is the result put? I assume here it is in
-                                  SMB_DATA but it might just as well be in the
-                                  SMB_CMD. No clue in the docs */
+       case SIS5595_BYTE:
        case SIS5595_BYTE_DATA:
                data->byte = sis5595_read(SMB_BYTE);
                break;
@@ -366,7 +362,7 @@ static const struct i2c_algorithm smbus_algorithm = {
 static struct i2c_adapter sis5595_adapter = {
        .owner          = THIS_MODULE,
        .id             = I2C_HW_SMBUS_SIS5595,
-       .class          = I2C_CLASS_HWMON,
+       .class          = I2C_CLASS_HWMON | I2C_CLASS_SPD,
        .algo           = &smbus_algorithm,
 };
 
@@ -379,6 +375,8 @@ MODULE_DEVICE_TABLE (pci, sis5595_ids);
 
 static int __devinit sis5595_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
+       int err;
+
        if (sis5595_setup(dev)) {
                dev_err(&dev->dev, "SIS5595 not detected, module not inserted.\n");
                return -ENODEV;
@@ -389,20 +387,24 @@ static int __devinit sis5595_probe(struct pci_dev *dev, const struct pci_device_
 
        sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x",
                sis5595_base + SMB_INDEX);
-       return i2c_add_adapter(&sis5595_adapter);
-}
+       err = i2c_add_adapter(&sis5595_adapter);
+       if (err) {
+               release_region(sis5595_base + SMB_INDEX, 2);
+               return err;
+       }
 
-static void __devexit sis5595_remove(struct pci_dev *dev)
-{
-       i2c_del_adapter(&sis5595_adapter);
-       release_region(sis5595_base + SMB_INDEX, 2);
+       /* Always return failure here.  This is to allow other drivers to bind
+        * to this pci device.  We don't really want to have control over the
+        * pci device, we only wanted to read as few register values from it.
+        */
+       sis5595_pdev =  pci_dev_get(dev);
+       return -ENODEV;
 }
 
 static struct pci_driver sis5595_driver = {
        .name           = "sis5595_smbus",
        .id_table       = sis5595_ids,
        .probe          = sis5595_probe,
-       .remove         = __devexit_p(sis5595_remove),
 };
 
 static int __init i2c_sis5595_init(void)
@@ -413,6 +415,12 @@ static int __init i2c_sis5595_init(void)
 static void __exit i2c_sis5595_exit(void)
 {
        pci_unregister_driver(&sis5595_driver);
+       if (sis5595_pdev) {
+               i2c_del_adapter(&sis5595_adapter);
+               release_region(sis5595_base + SMB_INDEX, 2);
+               pci_dev_put(sis5595_pdev);
+               sis5595_pdev = NULL;
+       }
 }
 
 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");