i2c: i801: Fallback to polling if request_irq() fails
[cascardo/linux.git] / drivers / i2c / busses / i2c-i801.c
index 10467a3..a6f3bc3 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
 #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 +371,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 +380,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);
        }
@@ -529,6 +535,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 +564,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 +844,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 +1228,9 @@ 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) {
                init_waitqueue_head(&priv->waitq);
 
@@ -1221,10 +1239,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 +1270,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);