Merge branch 'master' into upstream
[pandora-kernel.git] / drivers / i2c / busses / i2c-ali1563.c
index e6f6320..6b68074 100644 (file)
@@ -2,7 +2,7 @@
  *     i2c-ali1563.c - i2c driver for the ALi 1563 Southbridge
  *
  *     Copyright (C) 2004 Patrick Mochel
- *                   2005 Rudolf Marek <r.marek@sh.cvut.cz>
+ *                   2005 Rudolf Marek <r.marek@assembler.cz>
  *
  *     The 1563 southbridge is deceptively similar to the 1533, with a
  *     few notable exceptions. One of those happens to be the fact they
@@ -314,35 +314,11 @@ static u32 ali1563_func(struct i2c_adapter * a)
 }
 
 
-static void ali1563_enable(struct pci_dev * dev)
-{
-       u16 ctrl;
-
-       pci_read_config_word(dev,ALI1563_SMBBA,&ctrl);
-       ctrl |= 0x7;
-       pci_write_config_word(dev,ALI1563_SMBBA,ctrl);
-}
-
 static int __devinit ali1563_setup(struct pci_dev * dev)
 {
        u16 ctrl;
 
        pci_read_config_word(dev,ALI1563_SMBBA,&ctrl);
-       printk("ali1563: SMBus control = %04x\n",ctrl);
-
-       /* Check if device is even enabled first */
-       if (!(ctrl & ALI1563_SMB_IOEN)) {
-               dev_warn(&dev->dev,"I/O space not enabled, trying manually\n");
-               ali1563_enable(dev);
-       }
-       if (!(ctrl & ALI1563_SMB_IOEN)) {
-               dev_warn(&dev->dev,"I/O space still not enabled, giving up\n");
-               goto Err;
-       }
-       if (!(ctrl & ALI1563_SMB_HOSTEN)) {
-               dev_warn(&dev->dev,"Host Controller not enabled\n");
-               goto Err;
-       }
 
        /* SMB I/O Base in high 12 bits and must be aligned with the
         * size of the I/O space. */
@@ -351,11 +327,31 @@ static int __devinit ali1563_setup(struct pci_dev * dev)
                dev_warn(&dev->dev,"ali1563_smba Uninitialized\n");
                goto Err;
        }
+
+       /* Check if device is enabled */
+       if (!(ctrl & ALI1563_SMB_HOSTEN)) {
+               dev_warn(&dev->dev, "Host Controller not enabled\n");
+               goto Err;
+       }
+       if (!(ctrl & ALI1563_SMB_IOEN)) {
+               dev_warn(&dev->dev, "I/O space not enabled, trying manually\n");
+               pci_write_config_word(dev, ALI1563_SMBBA,
+                                     ctrl | ALI1563_SMB_IOEN);
+               pci_read_config_word(dev, ALI1563_SMBBA, &ctrl);
+               if (!(ctrl & ALI1563_SMB_IOEN)) {
+                       dev_err(&dev->dev, "I/O space still not enabled, "
+                               "giving up\n");
+                       goto Err;
+               }
+       }
+
        if (!request_region(ali1563_smba, ALI1563_SMB_IOSIZE,
                            ali1563_pci_driver.name)) {
-               dev_warn(&dev->dev,"Could not allocate I/O space");
+               dev_err(&dev->dev, "Could not allocate I/O space at 0x%04x\n",
+                       ali1563_smba);
                goto Err;
        }
+       dev_info(&dev->dev, "Found ALi1563 SMBus at 0x%04x\n", ali1563_smba);
 
        return 0;
 Err:
@@ -367,13 +363,14 @@ static void ali1563_shutdown(struct pci_dev *dev)
        release_region(ali1563_smba,ALI1563_SMB_IOSIZE);
 }
 
-static struct i2c_algorithm ali1563_algorithm = {
+static const struct i2c_algorithm ali1563_algorithm = {
        .smbus_xfer     = ali1563_access,
        .functionality  = ali1563_func,
 };
 
 static struct i2c_adapter ali1563_adapter = {
        .owner  = THIS_MODULE,
+       .id     = I2C_HW_SMBUS_ALI1563,
        .class  = I2C_CLASS_HWMON,
        .algo   = &ali1563_algorithm,
 };
@@ -384,13 +381,18 @@ static int __devinit ali1563_probe(struct pci_dev * dev,
        int error;
 
        if ((error = ali1563_setup(dev)))
-               return error;
+               goto exit;
        ali1563_adapter.dev.parent = &dev->dev;
        sprintf(ali1563_adapter.name,"SMBus ALi 1563 Adapter @ %04x",
                ali1563_smba);
        if ((error = i2c_add_adapter(&ali1563_adapter)))
-               ali1563_shutdown(dev);
-       printk("%s: Returning %d\n",__FUNCTION__,error);
+               goto exit_shutdown;
+       return 0;
+
+exit_shutdown:
+       ali1563_shutdown(dev);
+exit:
+       dev_warn(&dev->dev, "ALi1563 SMBus probe failed (%d)\n", error);
        return error;
 }