i2c: i801: Drop useless debug message
[cascardo/linux.git] / drivers / i2c / busses / i2c-i801.c
index 10467a3..48b925a 100644 (file)
@@ -2,7 +2,7 @@
     Copyright (c) 1998 - 2002  Frodo Looijaard <frodol@dds.nl>,
     Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
     <mdsxyz123@yahoo.com>
-    Copyright (C) 2007 - 2012  Jean Delvare <jdelvare@suse.de>
+    Copyright (C) 2007 - 2014  Jean Delvare <jdelvare@suse.de>
     Copyright (C) 2010         Intel Corporation,
                                David Woodhouse <dwmw2@infradead.org>
 
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
 /*
@@ -62,6 +58,7 @@
  * Wildcat Point (PCH)         0x8ca2  32      hard    yes     yes     yes
  * Wildcat Point-LP (PCH)      0x9ca2  32      hard    yes     yes     yes
  * BayTrail (SOC)              0x0f12  32      hard    yes     yes     yes
+ * Sunrise Point-H (PCH)       0xa123  32      hard    yes     yes     yes
  *
  * Features supported by this driver:
  * Software PEC                                no
 
 /* PCI Address Constants */
 #define SMBBAR         4
+#define SMBPCICTL      0x004
 #define SMBPCISTS      0x006
 #define SMBHSTCFG      0x040
 
 /* Host status bits for SMBPCISTS */
 #define SMBPCISTS_INTS         0x08
 
+/* Control bits for SMBPCICTL */
+#define SMBPCICTL_INTDIS       0x0400
+
 /* Host configuration bits for SMBHSTCFG */
 #define SMBHSTCFG_HST_EN       1
 #define SMBHSTCFG_SMB_SMI_EN   2
 #define PCI_DEVICE_ID_INTEL_WELLSBURG_SMBUS_MS2                0x8d7f
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS         0x9c22
 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS      0x9ca2
+#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS       0xa123
 
 struct i801_mux_config {
        char *gpio_chip;
@@ -373,6 +375,7 @@ static int i801_transaction(struct i801_priv *priv, int xact)
 {
        int status;
        int result;
+       const struct i2c_adapter *adap = &priv->adapter;
 
        result = i801_check_pre(priv);
        if (result < 0)
@@ -381,7 +384,14 @@ static int i801_transaction(struct i801_priv *priv, int xact)
        if (priv->features & FEATURE_IRQ) {
                outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
                       SMBHSTCNT(priv));
-               wait_event(priv->waitq, (status = priv->status));
+               result = wait_event_timeout(priv->waitq,
+                                           (status = priv->status),
+                                           adap->timeout);
+               if (!result) {
+                       status = -ETIMEDOUT;
+                       dev_warn(&priv->pci_dev->dev,
+                                "Timeout waiting for interrupt!\n");
+               }
                priv->status = 0;
                return i801_check_post(priv, status);
        }
@@ -495,9 +505,6 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
                return IRQ_NONE;
 
        status = inb_p(SMBHSTSTS(priv));
-       if (status != 0x42)
-               dev_dbg(&priv->pci_dev->dev, "irq: status = %02x\n", status);
-
        if (status & SMBHSTSTS_BYTE_DONE)
                i801_isr_byte_done(priv);
 
@@ -529,6 +536,7 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
        int smbcmd;
        int status;
        int result;
+       const struct i2c_adapter *adap = &priv->adapter;
 
        result = i801_check_pre(priv);
        if (result < 0)
@@ -557,7 +565,14 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
                priv->data = &data->block[1];
 
                outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
-               wait_event(priv->waitq, (status = priv->status));
+               result = wait_event_timeout(priv->waitq,
+                                           (status = priv->status),
+                                           adap->timeout);
+               if (!result) {
+                       status = -ETIMEDOUT;
+                       dev_warn(&priv->pci_dev->dev,
+                                "Timeout waiting for interrupt!\n");
+               }
                priv->status = 0;
                return i801_check_post(priv, status);
        }
@@ -830,6 +845,7 @@ static const struct pci_device_id i801_ids[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_SMBUS) },
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BAYTRAIL_SMBUS) },
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BRASWELL_SMBUS) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_SMBUS) },
        { 0, }
 };
 
@@ -1213,6 +1229,25 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
                outb_p(inb_p(SMBAUXCTL(priv)) &
                       ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
 
+       /* Default timeout in interrupt mode: 200 ms */
+       priv->adapter.timeout = HZ / 5;
+
+       if (priv->features & FEATURE_IRQ) {
+               u16 pcictl, pcists;
+
+               /* Complain if an interrupt is already pending */
+               pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
+               if (pcists & SMBPCISTS_INTS)
+                       dev_warn(&dev->dev, "An interrupt is pending!\n");
+
+               /* Check if interrupts have been disabled */
+               pci_read_config_word(priv->pci_dev, SMBPCICTL, &pcictl);
+               if (pcictl & SMBPCICTL_INTDIS) {
+                       dev_info(&dev->dev, "Interrupts are disabled\n");
+                       priv->features &= ~FEATURE_IRQ;
+               }
+       }
+
        if (priv->features & FEATURE_IRQ) {
                init_waitqueue_head(&priv->waitq);
 
@@ -1221,10 +1256,11 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
                if (err) {
                        dev_err(&dev->dev, "Failed to allocate irq %d: %d\n",
                                dev->irq, err);
-                       goto exit_release;
+                       priv->features &= ~FEATURE_IRQ;
                }
-               dev_info(&dev->dev, "SMBus using PCI Interrupt\n");
        }
+       dev_info(&dev->dev, "SMBus using %s\n",
+                priv->features & FEATURE_IRQ ? "PCI interrupt" : "polling");
 
        /* set up the sysfs linkage to our parent device */
        priv->adapter.dev.parent = &dev->dev;
@@ -1251,7 +1287,6 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 exit_free_irq:
        if (priv->features & FEATURE_IRQ)
                free_irq(dev->irq, priv);
-exit_release:
        pci_release_region(dev, SMBBAR);
 exit:
        kfree(priv);