Merge branch 'i2c-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
[powerpc.git] / drivers / i2c / busses / i2c-viapro.c
index a89a212..03c5fc8 100644 (file)
@@ -4,7 +4,7 @@
     Copyright (c) 1998 - 2002  Frodo Looijaard <frodol@dds.nl>,
     Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>,
     Mark D. Studebaker <mdsxyz123@yahoo.com>
-    Copyright (C) 2005  Jean Delvare <khali@linux-fr.org>
+    Copyright (C) 2005 - 2007  Jean Delvare <khali@linux-fr.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -34,6 +34,9 @@
    VT8233A            0x3147             yes?
    VT8235             0x3177             yes
    VT8237R            0x3227             yes
+   VT8237A            0x3337             yes
+   VT8251             0x3287             yes
+   CX700              0x8324             yes
 
    Note: we assume there can only be one device, with one SMBus interface.
 */
@@ -104,6 +107,32 @@ static struct i2c_adapter vt596_adapter;
 #define FEATURE_I2CBLOCK       (1<<0)
 static unsigned int vt596_features;
 
+#ifdef DEBUG
+static void vt596_dump_regs(const char *msg, u8 size)
+{
+       dev_dbg(&vt596_adapter.dev, "%s: STS=%02x CNT=%02x CMD=%02x ADD=%02x "
+               "DAT=%02x,%02x\n", msg, inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),
+               inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
+               inb_p(SMBHSTDAT1));
+
+       if (size == VT596_BLOCK_DATA
+        || size == VT596_I2C_BLOCK_DATA) {
+               int i;
+
+               dev_dbg(&vt596_adapter.dev, "BLK=");
+               for (i = 0; i < I2C_SMBUS_BLOCK_MAX / 2; i++)
+                       printk("%02x,", inb_p(SMBBLKDAT));
+               printk("\n");
+               dev_dbg(&vt596_adapter.dev, "    ");
+               for (; i < I2C_SMBUS_BLOCK_MAX - 1; i++)
+                       printk("%02x,", inb_p(SMBBLKDAT));
+               printk("%02x\n", inb_p(SMBBLKDAT));
+       }
+}
+#else
+static inline void vt596_dump_regs(const char *msg, u8 size) { }
+#endif
+
 /* Return -1 on error, 0 on success */
 static int vt596_transaction(u8 size)
 {
@@ -111,27 +140,23 @@ static int vt596_transaction(u8 size)
        int result = 0;
        int timeout = 0;
 
-       dev_dbg(&vt596_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
-               "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
-               inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
-               inb_p(SMBHSTDAT1));
+       vt596_dump_regs("Transaction (pre)", size);
 
        /* Make sure the SMBus host is ready to start transmitting */
        if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
                dev_dbg(&vt596_adapter.dev, "SMBus busy (0x%02x). "
-                       "Resetting... ", temp);
+                       "Resetting...\n", temp);
 
                outb_p(temp, SMBHSTSTS);
                if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
-                       printk("Failed! (0x%02x)\n", temp);
+                       dev_err(&vt596_adapter.dev, "SMBus reset failed! "
+                               "(0x%02x)\n", temp);
                        return -1;
-               } else {
-                       printk("Successful!\n");
                }
        }
 
        /* Start the transaction by setting bit 6 */
-       outb_p(0x40 | (size & 0x3C), SMBHSTCNT);
+       outb_p(0x40 | size, SMBHSTCNT);
 
        /* We will always wait for a fraction of a second */
        do {
@@ -148,7 +173,7 @@ static int vt596_transaction(u8 size)
        if (temp & 0x10) {
                result = -1;
                dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n",
-                       inb_p(SMBHSTCNT) & 0x3C);
+                       size);
        }
 
        if (temp & 0x08) {
@@ -157,11 +182,13 @@ static int vt596_transaction(u8 size)
        }
 
        if (temp & 0x04) {
+               int read = inb_p(SMBHSTADD) & 0x01;
                result = -1;
-               /* Quick commands are used to probe for chips, so
-                  errors are expected, and we don't want to frighten the
-                  user. */
-               if ((inb_p(SMBHSTCNT) & 0x3C) != VT596_QUICK)
+               /* The quick and receive byte commands are used to probe
+                  for chips, so errors are expected, and we don't want
+                  to frighten the user. */
+               if (!((size == VT596_QUICK && !read) ||
+                     (size == VT596_BYTE && read)))
                        dev_err(&vt596_adapter.dev, "Transaction error!\n");
        }
 
@@ -169,10 +196,7 @@ static int vt596_transaction(u8 size)
        if (temp & 0x1F)
                outb_p(temp, SMBHSTSTS);
 
-       dev_dbg(&vt596_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, "
-               "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
-               inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
-               inb_p(SMBHSTDAT1));
+       vt596_dump_regs("Transaction (post)", size);
 
        return result;
 }
@@ -276,13 +300,14 @@ static u32 vt596_func(struct i2c_adapter *adapter)
        return func;
 }
 
-static struct i2c_algorithm smbus_algorithm = {
+static const struct i2c_algorithm smbus_algorithm = {
        .smbus_xfer     = vt596_access,
        .functionality  = vt596_func,
 };
 
 static struct i2c_adapter vt596_adapter = {
        .owner          = THIS_MODULE,
+       .id             = I2C_HW_SMBUS_VIA2,
        .class          = I2C_CLASS_HWMON,
        .algo           = &smbus_algorithm,
 };
@@ -360,7 +385,10 @@ found:
        dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba);
 
        switch (pdev->device) {
+       case PCI_DEVICE_ID_VIA_CX700:
+       case PCI_DEVICE_ID_VIA_8251:
        case PCI_DEVICE_ID_VIA_8237:
+       case PCI_DEVICE_ID_VIA_8237A:
        case PCI_DEVICE_ID_VIA_8235:
        case PCI_DEVICE_ID_VIA_8233A:
        case PCI_DEVICE_ID_VIA_8233_0:
@@ -411,8 +439,14 @@ static struct pci_device_id vt596_ids[] = {
          .driver_data = SMBBA3 },
        { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237),
          .driver_data = SMBBA3 },
+       { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A),
+         .driver_data = SMBBA3 },
        { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4),
          .driver_data = SMBBA1 },
+       { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8251),
+         .driver_data = SMBBA3 },
+       { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700),
+         .driver_data = SMBBA3 },
        { 0, }
 };
 
@@ -441,9 +475,9 @@ static void __exit i2c_vt596_exit(void)
        }
 }
 
-MODULE_AUTHOR(
-    "Frodo Looijaard <frodol@dds.nl> and "
-    "Philip Edelbrock <phil@netroedge.com>");
+MODULE_AUTHOR("Kyosti Malkki <kmalkki@cc.hut.fi>, "
+             "Mark D. Studebaker <mdsxyz123@yahoo.com> and "
+             "Jean Delvare <khali@linux-fr.org>");
 MODULE_DESCRIPTION("vt82c596 SMBus driver");
 MODULE_LICENSE("GPL");