[PATCH] fix missing includes
[linux-drm-fsl-dcu.git] / drivers / pci / pci.c
index 65ea7d25f6911d7396e19afbf4bb2738906376f7..e74d75843047c24cf299cf53daad16635355d640 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/pci.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
+#include <linux/string.h>
 #include <asm/dma.h>   /* isa_dma_bridge_buggy */
 #include "pci.h"
 
@@ -252,6 +253,8 @@ pci_restore_bars(struct pci_dev *dev)
                pci_update_resource(dev, &dev->resource[i], i);
 }
 
+int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
+
 /**
  * pci_set_power_state - Set the power state of a PCI device
  * @dev: PCI device to be suspended
@@ -266,7 +269,6 @@ pci_restore_bars(struct pci_dev *dev)
  * -EIO if device does not support PCI PM.
  * 0 if we can successfully change the power state.
  */
-int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
 int
 pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
@@ -294,7 +296,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
                return -EIO; 
 
        pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
-       if ((pmc & PCI_PM_CAP_VER_MASK) > 2) {
+       if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
                printk(KERN_DEBUG
                       "PCI: %s has unsupported PM cap regs version (%u)\n",
                       pci_name(dev), pmc & PCI_PM_CAP_VER_MASK);
@@ -302,26 +304,32 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
        }
 
        /* check if this device supports the desired state */
-       if (state == PCI_D1 || state == PCI_D2) {
-               if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1))
-                       return -EIO;
-               else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2))
-                       return -EIO;
-       }
+       if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1))
+               return -EIO;
+       else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2))
+               return -EIO;
 
        pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
 
-       /* If we're in D3, force entire word to 0.
+       /* If we're (effectively) in D3, force entire word to 0.
         * This doesn't affect PME_Status, disables PME_En, and
         * sets PowerState to 0.
         */
-       if (dev->current_state >= PCI_D3hot) {
-               if (!(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
-                       need_restore = 1;
-               pmcsr = 0;
-       } else {
+       switch (dev->current_state) {
+       case PCI_D0:
+       case PCI_D1:
+       case PCI_D2:
                pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
                pmcsr |= state;
+               break;
+       case PCI_UNKNOWN: /* Boot-up */
+               if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
+                && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
+                       need_restore = 1;
+               /* Fall-through: force to D0 */
+       default:
+               pmcsr = 0;
+               break;
        }
 
        /* enter specified state */
@@ -383,13 +391,17 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
        if (platform_pci_choose_state) {
                ret = platform_pci_choose_state(dev, state);
                if (ret >= 0)
-                       state = ret;
+                       state.event = ret;
        }
-       switch (state) {
-       case 0: return PCI_D0;
-       case 3: return PCI_D3hot;
+
+       switch (state.event) {
+       case PM_EVENT_ON:
+               return PCI_D0;
+       case PM_EVENT_FREEZE:
+       case PM_EVENT_SUSPEND:
+               return PCI_D3hot;
        default:
-               printk("They asked me for state %d\n", state);
+               printk("They asked me for state %d\n", state.event);
                BUG();
        }
        return PCI_D0;
@@ -440,8 +452,11 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
 {
        int err;
 
-       pci_set_power_state(dev, PCI_D0);
-       if ((err = pcibios_enable_device(dev, bars)) < 0)
+       err = pci_set_power_state(dev, PCI_D0);
+       if (err < 0 && err != -EIO)
+               return err;
+       err = pcibios_enable_device(dev, bars);
+       if (err < 0)
                return err;
        return 0;
 }
@@ -793,6 +808,31 @@ pci_clear_mwi(struct pci_dev *dev)
        }
 }
 
+/**
+ * pci_intx - enables/disables PCI INTx for device dev
+ * @pdev: the PCI device to operate on
+ * @enable: boolean: whether to enable or disable PCI INTx
+ *
+ * Enables/disables PCI INTx for device dev
+ */
+void
+pci_intx(struct pci_dev *pdev, int enable)
+{
+       u16 pci_command, new;
+
+       pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
+
+       if (enable) {
+               new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
+       } else {
+               new = pci_command | PCI_COMMAND_INTX_DISABLE;
+       }
+
+       if (new != pci_command) {
+               pci_write_config_word(pdev, PCI_COMMAND, new);
+       }
+}
+
 #ifndef HAVE_ARCH_PCI_SET_DMA_MASK
 /*
  * These can be overridden by arch-specific implementations
@@ -870,6 +910,7 @@ EXPORT_SYMBOL(pci_request_region);
 EXPORT_SYMBOL(pci_set_master);
 EXPORT_SYMBOL(pci_set_mwi);
 EXPORT_SYMBOL(pci_clear_mwi);
+EXPORT_SYMBOL_GPL(pci_intx);
 EXPORT_SYMBOL(pci_set_dma_mask);
 EXPORT_SYMBOL(pci_set_consistent_dma_mask);
 EXPORT_SYMBOL(pci_assign_resource);