]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mmc/host/sdhci-pci.c
sdhci: toggle JMicron PMOS setting
[linux-2.6-omap-h63xx.git] / drivers / mmc / host / sdhci-pci.c
index 51798ec56446fb0526fe478729e34f370e2db71a..ef77ed1bd114b63c584cab8642c738423a3e2198 100644 (file)
 
 #define MAX_SLOTS                      8
 
-static const struct pci_device_id pci_ids[] __devinitdata = {
-       {
-               .vendor         = PCI_VENDOR_ID_RICOH,
-               .device         = PCI_DEVICE_ID_RICOH_R5C822,
-               .subvendor      = PCI_VENDOR_ID_IBM,
-               .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_CLOCK_BEFORE_RESET,
-       },
+struct sdhci_pci_chip;
+
+struct sdhci_pci_fixes {
+       unsigned int            quirks;
+
+       int                     (*probe)(struct sdhci_pci_chip*);
+
+       int                     (*resume)(struct sdhci_pci_chip*);
+};
+
+struct sdhci_pci_slot {
+       struct sdhci_pci_chip   *chip;
+       struct sdhci_host       *host;
+
+       int                     pci_bar;
+};
+
+struct sdhci_pci_chip {
+       struct pci_dev          *pdev;
 
+       unsigned int            quirks;
+       const struct sdhci_pci_fixes *fixes;
+
+       int                     num_slots;      /* Slots on controller */
+       struct sdhci_pci_slot   *slots[MAX_SLOTS]; /* Pointers to host slots */
+};
+
+
+/*****************************************************************************\
+ *                                                                           *
+ * Hardware specific quirk handling                                          *
+ *                                                                           *
+\*****************************************************************************/
+
+static int ricoh_probe(struct sdhci_pci_chip *chip)
+{
+       if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
+               chip->quirks |= SDHCI_QUIRK_CLOCK_BEFORE_RESET;
+
+       if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)
+               chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
+
+       return 0;
+}
+
+static const struct sdhci_pci_fixes sdhci_ricoh = {
+       .probe          = ricoh_probe,
+};
+
+static const struct sdhci_pci_fixes sdhci_ene_712 = {
+       .quirks         = SDHCI_QUIRK_SINGLE_POWER_WRITE |
+                         SDHCI_QUIRK_BROKEN_DMA,
+};
+
+static const struct sdhci_pci_fixes sdhci_ene_714 = {
+       .quirks         = SDHCI_QUIRK_SINGLE_POWER_WRITE |
+                         SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
+                         SDHCI_QUIRK_BROKEN_DMA,
+};
+
+static const struct sdhci_pci_fixes sdhci_cafe = {
+       .quirks         = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
+                         SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
+};
+
+static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
+{
+       u8 scratch;
+       int ret;
+
+       ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
+       if (ret)
+               return ret;
+
+       /*
+        * Turn PMOS on [bit 0], set over current detection to 2.4 V
+        * [bit 1:2] and enable over current debouncing [bit 6].
+        */
+       if (on)
+               scratch |= 0x47;
+       else
+               scratch &= ~0x47;
+
+       ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static int jmicron_probe(struct sdhci_pci_chip *chip)
+{
+       int ret;
+
+       /*
+        * JMicron chips need a bit of a nudge to enable the power
+        * output pins.
+        */
+       ret = jmicron_pmos(chip, 1);
+       if (ret) {
+               dev_err(&chip->pdev->dev, "Failure enabling card power\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int jmicron_resume(struct sdhci_pci_chip *chip)
+{
+       int ret;
+
+       ret = jmicron_pmos(chip, 1);
+       if (ret) {
+               dev_err(&chip->pdev->dev, "Failure enabling card power\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static const struct sdhci_pci_fixes sdhci_jmicron = {
+       .quirks         = SDHCI_QUIRK_32BIT_DMA_ADDR |
+                         SDHCI_QUIRK_32BIT_DMA_SIZE |
+                         SDHCI_QUIRK_RESET_AFTER_REQUEST,
+
+       .probe          = jmicron_probe,
+
+       .resume         = jmicron_resume,
+};
+
+static const struct pci_device_id pci_ids[] __devinitdata = {
        {
                .vendor         = PCI_VENDOR_ID_RICOH,
                .device         = PCI_DEVICE_ID_RICOH_R5C822,
-               .subvendor      = PCI_VENDOR_ID_SAMSUNG,
+               .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_NO_CARD_NO_RESET,
+               .driver_data    = (kernel_ulong_t)&sdhci_ricoh,
        },
 
        {
@@ -60,8 +182,7 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .device         = PCI_DEVICE_ID_ENE_CB712_SD,
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_SINGLE_POWER_WRITE |
-                                 SDHCI_QUIRK_BROKEN_DMA,
+               .driver_data    = (kernel_ulong_t)&sdhci_ene_712,
        },
 
        {
@@ -69,8 +190,7 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .device         = PCI_DEVICE_ID_ENE_CB712_SD_2,
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_SINGLE_POWER_WRITE |
-                                 SDHCI_QUIRK_BROKEN_DMA,
+               .driver_data    = (kernel_ulong_t)&sdhci_ene_712,
        },
 
        {
@@ -78,9 +198,7 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .device         = PCI_DEVICE_ID_ENE_CB714_SD,
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_SINGLE_POWER_WRITE |
-                                 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
-                                 SDHCI_QUIRK_BROKEN_DMA,
+               .driver_data    = (kernel_ulong_t)&sdhci_ene_714,
        },
 
        {
@@ -88,9 +206,7 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .device         = PCI_DEVICE_ID_ENE_CB714_SD_2,
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_SINGLE_POWER_WRITE |
-                                 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
-                                 SDHCI_QUIRK_BROKEN_DMA,
+               .driver_data    = (kernel_ulong_t)&sdhci_ene_714,
        },
 
        {
@@ -98,8 +214,7 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .device         = PCI_DEVICE_ID_MARVELL_CAFE_SD,
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
-                                 SDHCI_QUIRK_INCR_TIMEOUT_CONTROL,
+               .driver_data    = (kernel_ulong_t)&sdhci_cafe,
        },
 
        {
@@ -107,9 +222,7 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
                .device         = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
                .subvendor      = PCI_ANY_ID,
                .subdevice      = PCI_ANY_ID,
-               .driver_data    = SDHCI_QUIRK_32BIT_DMA_ADDR |
-                                 SDHCI_QUIRK_32BIT_DMA_SIZE |
-                                 SDHCI_QUIRK_RESET_AFTER_REQUEST,
+               .driver_data    = (kernel_ulong_t)&sdhci_jmicron,
        },
 
        {       /* Generic SD host controller */
@@ -121,23 +234,6 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
 
 MODULE_DEVICE_TABLE(pci, pci_ids);
 
-struct sdhci_pci_chip;
-
-struct sdhci_pci_slot {
-       struct sdhci_pci_chip   *chip;
-       struct sdhci_host       *host;
-
-       int                     pci_bar;
-};
-
-struct sdhci_pci_chip {
-       struct pci_dev          *pdev;
-       unsigned int             quirks;
-
-       int                     num_slots;      /* Slots on controller */
-       struct sdhci_pci_slot   *slots[MAX_SLOTS]; /* Pointers to host slots */
-};
-
 /*****************************************************************************\
  *                                                                           *
  * SDHCI core callbacks                                                      *
@@ -229,6 +325,12 @@ static int sdhci_pci_resume (struct pci_dev *pdev)
        if (ret)
                return ret;
 
+       if (chip->fixes && chip->fixes->resume) {
+               ret = chip->fixes->resume(chip);
+               if (ret)
+                       return ret;
+       }
+
        for (i = 0;i < chip->num_slots;i++) {
                slot = chip->slots[i];
                if (!slot)
@@ -389,11 +491,19 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
        }
 
        chip->pdev = pdev;
-       chip->quirks = ent->driver_data;
+       chip->fixes = (const struct sdhci_pci_fixes*)ent->driver_data;
+       if (chip->fixes)
+               chip->quirks = chip->fixes->quirks;
        chip->num_slots = slots;
 
        pci_set_drvdata(pdev, chip);
 
+       if (chip->fixes && chip->fixes->probe) {
+               ret = chip->fixes->probe(chip);
+               if (ret)
+                       goto free;
+       }
+
        for (i = 0;i < slots;i++) {
                slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i);
                if (IS_ERR(slot)) {