Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1 | /* linux/drivers/mmc/host/sdhci-pci.c - SDHCI on PCI bus interface |
| 2 | * |
| 3 | * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * Thanks to the following companies for their support: |
| 11 | * |
| 12 | * - JMicron (hardware and technical support) |
| 13 | */ |
| 14 | |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/highmem.h> |
Paul Gortmaker | 88b4767 | 2011-07-03 15:15:51 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 18 | #include <linux/pci.h> |
| 19 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 21 | #include <linux/device.h> |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 22 | #include <linux/mmc/host.h> |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 23 | #include <linux/scatterlist.h> |
| 24 | #include <linux/io.h> |
Adrian Hunter | 0f20165 | 2011-08-29 16:42:13 +0300 | [diff] [blame] | 25 | #include <linux/gpio.h> |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 27 | #include <linux/mmc/sdhci-pci-data.h> |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 28 | |
| 29 | #include "sdhci.h" |
| 30 | |
| 31 | /* |
Alexander Stein | 296e0b0 | 2012-03-14 08:38:58 +0100 | [diff] [blame] | 32 | * PCI device IDs |
| 33 | */ |
| 34 | #define PCI_DEVICE_ID_INTEL_PCH_SDIO0 0x8809 |
| 35 | #define PCI_DEVICE_ID_INTEL_PCH_SDIO1 0x880a |
Adrian Hunter | 728ef3d | 2013-04-26 11:27:23 +0300 | [diff] [blame^] | 36 | #define PCI_DEVICE_ID_INTEL_BYT_EMMC 0x0f14 |
| 37 | #define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15 |
| 38 | #define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16 |
Alexander Stein | 296e0b0 | 2012-03-14 08:38:58 +0100 | [diff] [blame] | 39 | |
| 40 | /* |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 41 | * PCI registers |
| 42 | */ |
| 43 | |
| 44 | #define PCI_SDHCI_IFPIO 0x00 |
| 45 | #define PCI_SDHCI_IFDMA 0x01 |
| 46 | #define PCI_SDHCI_IFVENDOR 0x02 |
| 47 | |
| 48 | #define PCI_SLOT_INFO 0x40 /* 8 bits */ |
| 49 | #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7) |
| 50 | #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07 |
| 51 | |
| 52 | #define MAX_SLOTS 8 |
| 53 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 54 | struct sdhci_pci_chip; |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 55 | struct sdhci_pci_slot; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 56 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 57 | struct sdhci_pci_fixes { |
| 58 | unsigned int quirks; |
Adrian Hunter | f3c55a7 | 2012-02-07 14:48:55 +0200 | [diff] [blame] | 59 | unsigned int quirks2; |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 60 | bool allow_runtime_pm; |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 61 | |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 62 | int (*probe) (struct sdhci_pci_chip *); |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 63 | |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 64 | int (*probe_slot) (struct sdhci_pci_slot *); |
| 65 | void (*remove_slot) (struct sdhci_pci_slot *, int); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 66 | |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 67 | int (*suspend) (struct sdhci_pci_chip *); |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 68 | int (*resume) (struct sdhci_pci_chip *); |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 71 | struct sdhci_pci_slot { |
| 72 | struct sdhci_pci_chip *chip; |
| 73 | struct sdhci_host *host; |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 74 | struct sdhci_pci_data *data; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 75 | |
| 76 | int pci_bar; |
Adrian Hunter | 0f20165 | 2011-08-29 16:42:13 +0300 | [diff] [blame] | 77 | int rst_n_gpio; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 78 | int cd_gpio; |
| 79 | int cd_irq; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | struct sdhci_pci_chip { |
| 83 | struct pci_dev *pdev; |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 84 | |
| 85 | unsigned int quirks; |
Adrian Hunter | f3c55a7 | 2012-02-07 14:48:55 +0200 | [diff] [blame] | 86 | unsigned int quirks2; |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 87 | bool allow_runtime_pm; |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 88 | const struct sdhci_pci_fixes *fixes; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 89 | |
| 90 | int num_slots; /* Slots on controller */ |
| 91 | struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */ |
| 92 | }; |
| 93 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 94 | |
| 95 | /*****************************************************************************\ |
| 96 | * * |
| 97 | * Hardware specific quirk handling * |
| 98 | * * |
| 99 | \*****************************************************************************/ |
| 100 | |
| 101 | static int ricoh_probe(struct sdhci_pci_chip *chip) |
| 102 | { |
Chris Ball | c99436f | 2009-09-22 16:45:22 -0700 | [diff] [blame] | 103 | if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG || |
| 104 | chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY) |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 105 | chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 106 | return 0; |
| 107 | } |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 108 | |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 109 | static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot) |
| 110 | { |
| 111 | slot->host->caps = |
| 112 | ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT) |
| 113 | & SDHCI_TIMEOUT_CLK_MASK) | |
| 114 | |
| 115 | ((0x21 << SDHCI_CLOCK_BASE_SHIFT) |
| 116 | & SDHCI_CLOCK_BASE_MASK) | |
| 117 | |
| 118 | SDHCI_TIMEOUT_CLK_UNIT | |
| 119 | SDHCI_CAN_VDD_330 | |
Madhvapathi Sriram | 1a1f1f0 | 2012-10-15 04:47:30 +0000 | [diff] [blame] | 120 | SDHCI_CAN_DO_HISPD | |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 121 | SDHCI_CAN_DO_SDMA; |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static int ricoh_mmc_resume(struct sdhci_pci_chip *chip) |
| 126 | { |
| 127 | /* Apply a delay to allow controller to settle */ |
| 128 | /* Otherwise it becomes confused if card state changed |
| 129 | during suspend */ |
| 130 | msleep(500); |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static const struct sdhci_pci_fixes sdhci_ricoh = { |
| 135 | .probe = ricoh_probe, |
Vasily Khoruzhick | 8493829 | 2010-03-05 13:43:46 -0800 | [diff] [blame] | 136 | .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | |
| 137 | SDHCI_QUIRK_FORCE_DMA | |
| 138 | SDHCI_QUIRK_CLOCK_BEFORE_RESET, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 141 | static const struct sdhci_pci_fixes sdhci_ricoh_mmc = { |
| 142 | .probe_slot = ricoh_mmc_probe_slot, |
| 143 | .resume = ricoh_mmc_resume, |
| 144 | .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | |
| 145 | SDHCI_QUIRK_CLOCK_BEFORE_RESET | |
| 146 | SDHCI_QUIRK_NO_CARD_NO_RESET | |
| 147 | SDHCI_QUIRK_MISSING_CAPS |
| 148 | }; |
| 149 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 150 | static const struct sdhci_pci_fixes sdhci_ene_712 = { |
| 151 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | |
| 152 | SDHCI_QUIRK_BROKEN_DMA, |
| 153 | }; |
| 154 | |
| 155 | static const struct sdhci_pci_fixes sdhci_ene_714 = { |
| 156 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | |
| 157 | SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS | |
| 158 | SDHCI_QUIRK_BROKEN_DMA, |
| 159 | }; |
| 160 | |
| 161 | static const struct sdhci_pci_fixes sdhci_cafe = { |
| 162 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | |
Andres Salomon | a087489 | 2009-03-02 21:48:20 +0100 | [diff] [blame] | 163 | SDHCI_QUIRK_NO_BUSY_IRQ | |
Daniel Drake | 55fc05b | 2012-07-03 23:13:39 +0100 | [diff] [blame] | 164 | SDHCI_QUIRK_BROKEN_CARD_DETECTION | |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 165 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
Major Lee | 68077b0 | 2011-06-29 14:23:46 +0300 | [diff] [blame] | 168 | static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot) |
| 169 | { |
| 170 | slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA; |
| 171 | return 0; |
| 172 | } |
| 173 | |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 174 | /* |
| 175 | * ADMA operation is disabled for Moorestown platform due to |
| 176 | * hardware bugs. |
| 177 | */ |
Jacob Pan | 35ac6f0 | 2010-11-09 13:57:29 +0000 | [diff] [blame] | 178 | static int mrst_hc_probe(struct sdhci_pci_chip *chip) |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 179 | { |
| 180 | /* |
Jacob Pan | 35ac6f0 | 2010-11-09 13:57:29 +0000 | [diff] [blame] | 181 | * slots number is fixed here for MRST as SDIO3/5 are never used and |
| 182 | * have hardware bugs. |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 183 | */ |
| 184 | chip->num_slots = 1; |
| 185 | return 0; |
| 186 | } |
| 187 | |
Alexander Stein | 296e0b0 | 2012-03-14 08:38:58 +0100 | [diff] [blame] | 188 | static int pch_hc_probe_slot(struct sdhci_pci_slot *slot) |
| 189 | { |
| 190 | slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA; |
| 191 | return 0; |
| 192 | } |
| 193 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 194 | #ifdef CONFIG_PM_RUNTIME |
| 195 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 196 | static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 197 | { |
| 198 | struct sdhci_pci_slot *slot = dev_id; |
| 199 | struct sdhci_host *host = slot->host; |
| 200 | |
| 201 | mmc_detect_change(host->mmc, msecs_to_jiffies(200)); |
| 202 | return IRQ_HANDLED; |
| 203 | } |
| 204 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 205 | static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 206 | { |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 207 | int err, irq, gpio = slot->cd_gpio; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 208 | |
| 209 | slot->cd_gpio = -EINVAL; |
| 210 | slot->cd_irq = -EINVAL; |
| 211 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 212 | if (!gpio_is_valid(gpio)) |
| 213 | return; |
| 214 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 215 | err = gpio_request(gpio, "sd_cd"); |
| 216 | if (err < 0) |
| 217 | goto out; |
| 218 | |
| 219 | err = gpio_direction_input(gpio); |
| 220 | if (err < 0) |
| 221 | goto out_free; |
| 222 | |
| 223 | irq = gpio_to_irq(gpio); |
| 224 | if (irq < 0) |
| 225 | goto out_free; |
| 226 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 227 | err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 228 | IRQF_TRIGGER_FALLING, "sd_cd", slot); |
| 229 | if (err) |
| 230 | goto out_free; |
| 231 | |
| 232 | slot->cd_gpio = gpio; |
| 233 | slot->cd_irq = irq; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 234 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 235 | return; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 236 | |
| 237 | out_free: |
| 238 | gpio_free(gpio); |
| 239 | out: |
| 240 | dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n"); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 241 | } |
| 242 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 243 | static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 244 | { |
| 245 | if (slot->cd_irq >= 0) |
| 246 | free_irq(slot->cd_irq, slot); |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 247 | if (gpio_is_valid(slot->cd_gpio)) |
| 248 | gpio_free(slot->cd_gpio); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | #else |
| 252 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 253 | static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot) |
| 254 | { |
| 255 | } |
| 256 | |
| 257 | static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot) |
| 258 | { |
| 259 | } |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 260 | |
| 261 | #endif |
| 262 | |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 263 | static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot) |
| 264 | { |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 265 | slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE; |
Adrian Hunter | da721cf | 2012-02-07 14:48:53 +0200 | [diff] [blame] | 266 | slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC | |
| 267 | MMC_CAP2_HC_ERASE_SZ; |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 268 | return 0; |
| 269 | } |
| 270 | |
Adrian Hunter | 9393350 | 2011-12-27 15:48:47 +0200 | [diff] [blame] | 271 | static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot) |
| 272 | { |
Adrian Hunter | 012e467 | 2012-01-30 14:27:18 +0200 | [diff] [blame] | 273 | slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE; |
Adrian Hunter | 9393350 | 2011-12-27 15:48:47 +0200 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 277 | static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = { |
| 278 | .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT, |
Major Lee | 68077b0 | 2011-06-29 14:23:46 +0300 | [diff] [blame] | 279 | .probe_slot = mrst_hc_probe_slot, |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 280 | }; |
| 281 | |
Jacob Pan | 35ac6f0 | 2010-11-09 13:57:29 +0000 | [diff] [blame] | 282 | static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = { |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 283 | .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT, |
Jacob Pan | 35ac6f0 | 2010-11-09 13:57:29 +0000 | [diff] [blame] | 284 | .probe = mrst_hc_probe, |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 285 | }; |
| 286 | |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 287 | static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = { |
| 288 | .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 289 | .allow_runtime_pm = true, |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 290 | }; |
| 291 | |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 292 | static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = { |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 293 | .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, |
Adrian Hunter | f3c55a7 | 2012-02-07 14:48:55 +0200 | [diff] [blame] | 294 | .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 295 | .allow_runtime_pm = true, |
Adrian Hunter | 9393350 | 2011-12-27 15:48:47 +0200 | [diff] [blame] | 296 | .probe_slot = mfd_sdio_probe_slot, |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 297 | }; |
| 298 | |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 299 | static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = { |
| 300 | .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 301 | .allow_runtime_pm = true, |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 302 | .probe_slot = mfd_emmc_probe_slot, |
| 303 | }; |
| 304 | |
Alexander Stein | 296e0b0 | 2012-03-14 08:38:58 +0100 | [diff] [blame] | 305 | static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = { |
| 306 | .quirks = SDHCI_QUIRK_BROKEN_ADMA, |
| 307 | .probe_slot = pch_hc_probe_slot, |
| 308 | }; |
| 309 | |
Adrian Hunter | 728ef3d | 2013-04-26 11:27:23 +0300 | [diff] [blame^] | 310 | static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot) |
| 311 | { |
| 312 | slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE; |
| 313 | slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ; |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot) |
| 318 | { |
| 319 | slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE; |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = { |
| 324 | .allow_runtime_pm = true, |
| 325 | .probe_slot = byt_emmc_probe_slot, |
| 326 | }; |
| 327 | |
| 328 | static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { |
| 329 | .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, |
| 330 | .allow_runtime_pm = true, |
| 331 | .probe_slot = byt_sdio_probe_slot, |
| 332 | }; |
| 333 | |
| 334 | static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { |
| 335 | }; |
| 336 | |
Jennifer Li | 26daa1e | 2010-11-17 23:01:59 -0500 | [diff] [blame] | 337 | /* O2Micro extra registers */ |
| 338 | #define O2_SD_LOCK_WP 0xD3 |
| 339 | #define O2_SD_MULTI_VCC3V 0xEE |
| 340 | #define O2_SD_CLKREQ 0xEC |
| 341 | #define O2_SD_CAPS 0xE0 |
| 342 | #define O2_SD_ADMA1 0xE2 |
| 343 | #define O2_SD_ADMA2 0xE7 |
| 344 | #define O2_SD_INF_MOD 0xF1 |
| 345 | |
| 346 | static int o2_probe(struct sdhci_pci_chip *chip) |
| 347 | { |
| 348 | int ret; |
| 349 | u8 scratch; |
| 350 | |
| 351 | switch (chip->pdev->device) { |
| 352 | case PCI_DEVICE_ID_O2_8220: |
| 353 | case PCI_DEVICE_ID_O2_8221: |
| 354 | case PCI_DEVICE_ID_O2_8320: |
| 355 | case PCI_DEVICE_ID_O2_8321: |
| 356 | /* This extra setup is required due to broken ADMA. */ |
| 357 | ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch); |
| 358 | if (ret) |
| 359 | return ret; |
| 360 | scratch &= 0x7f; |
| 361 | pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); |
| 362 | |
| 363 | /* Set Multi 3 to VCC3V# */ |
| 364 | pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08); |
| 365 | |
| 366 | /* Disable CLK_REQ# support after media DET */ |
| 367 | ret = pci_read_config_byte(chip->pdev, O2_SD_CLKREQ, &scratch); |
| 368 | if (ret) |
| 369 | return ret; |
| 370 | scratch |= 0x20; |
| 371 | pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch); |
| 372 | |
| 373 | /* Choose capabilities, enable SDMA. We have to write 0x01 |
| 374 | * to the capabilities register first to unlock it. |
| 375 | */ |
| 376 | ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch); |
| 377 | if (ret) |
| 378 | return ret; |
| 379 | scratch |= 0x01; |
| 380 | pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch); |
| 381 | pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73); |
| 382 | |
| 383 | /* Disable ADMA1/2 */ |
| 384 | pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39); |
| 385 | pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08); |
| 386 | |
| 387 | /* Disable the infinite transfer mode */ |
| 388 | ret = pci_read_config_byte(chip->pdev, O2_SD_INF_MOD, &scratch); |
| 389 | if (ret) |
| 390 | return ret; |
| 391 | scratch |= 0x08; |
| 392 | pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch); |
| 393 | |
| 394 | /* Lock WP */ |
| 395 | ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch); |
| 396 | if (ret) |
| 397 | return ret; |
| 398 | scratch |= 0x80; |
| 399 | pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch); |
| 400 | } |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 405 | static int jmicron_pmos(struct sdhci_pci_chip *chip, int on) |
| 406 | { |
| 407 | u8 scratch; |
| 408 | int ret; |
| 409 | |
| 410 | ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch); |
| 411 | if (ret) |
| 412 | return ret; |
| 413 | |
| 414 | /* |
| 415 | * Turn PMOS on [bit 0], set over current detection to 2.4 V |
| 416 | * [bit 1:2] and enable over current debouncing [bit 6]. |
| 417 | */ |
| 418 | if (on) |
| 419 | scratch |= 0x47; |
| 420 | else |
| 421 | scratch &= ~0x47; |
| 422 | |
| 423 | ret = pci_write_config_byte(chip->pdev, 0xAE, scratch); |
| 424 | if (ret) |
| 425 | return ret; |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int jmicron_probe(struct sdhci_pci_chip *chip) |
| 431 | { |
| 432 | int ret; |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 433 | u16 mmcdev = 0; |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 434 | |
Pierre Ossman | 93fc48c | 2008-06-28 18:21:41 +0200 | [diff] [blame] | 435 | if (chip->pdev->revision == 0) { |
| 436 | chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR | |
| 437 | SDHCI_QUIRK_32BIT_DMA_SIZE | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 438 | SDHCI_QUIRK_32BIT_ADMA_SIZE | |
Pierre Ossman | 4a3cba3 | 2008-07-29 00:11:16 +0200 | [diff] [blame] | 439 | SDHCI_QUIRK_RESET_AFTER_REQUEST | |
Pierre Ossman | 86a6a87 | 2009-02-02 21:13:49 +0100 | [diff] [blame] | 440 | SDHCI_QUIRK_BROKEN_SMALL_PIO; |
Pierre Ossman | 93fc48c | 2008-06-28 18:21:41 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 443 | /* |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 444 | * JMicron chips can have two interfaces to the same hardware |
| 445 | * in order to work around limitations in Microsoft's driver. |
| 446 | * We need to make sure we only bind to one of them. |
| 447 | * |
| 448 | * This code assumes two things: |
| 449 | * |
| 450 | * 1. The PCI code adds subfunctions in order. |
| 451 | * |
| 452 | * 2. The MMC interface has a lower subfunction number |
| 453 | * than the SD interface. |
| 454 | */ |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 455 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) |
| 456 | mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC; |
| 457 | else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD) |
| 458 | mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD; |
| 459 | |
| 460 | if (mmcdev) { |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 461 | struct pci_dev *sd_dev; |
| 462 | |
| 463 | sd_dev = NULL; |
| 464 | while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON, |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 465 | mmcdev, sd_dev)) != NULL) { |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 466 | if ((PCI_SLOT(chip->pdev->devfn) == |
| 467 | PCI_SLOT(sd_dev->devfn)) && |
| 468 | (chip->pdev->bus == sd_dev->bus)) |
| 469 | break; |
| 470 | } |
| 471 | |
| 472 | if (sd_dev) { |
| 473 | pci_dev_put(sd_dev); |
| 474 | dev_info(&chip->pdev->dev, "Refusing to bind to " |
| 475 | "secondary interface.\n"); |
| 476 | return -ENODEV; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | /* |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 481 | * JMicron chips need a bit of a nudge to enable the power |
| 482 | * output pins. |
| 483 | */ |
| 484 | ret = jmicron_pmos(chip, 1); |
| 485 | if (ret) { |
| 486 | dev_err(&chip->pdev->dev, "Failure enabling card power\n"); |
| 487 | return ret; |
| 488 | } |
| 489 | |
Takashi Iwai | 82b0e23 | 2011-04-21 20:26:38 +0200 | [diff] [blame] | 490 | /* quirk for unsable RO-detection on JM388 chips */ |
| 491 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD || |
| 492 | chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) |
| 493 | chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT; |
| 494 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 495 | return 0; |
| 496 | } |
| 497 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 498 | static void jmicron_enable_mmc(struct sdhci_host *host, int on) |
| 499 | { |
| 500 | u8 scratch; |
| 501 | |
| 502 | scratch = readb(host->ioaddr + 0xC0); |
| 503 | |
| 504 | if (on) |
| 505 | scratch |= 0x01; |
| 506 | else |
| 507 | scratch &= ~0x01; |
| 508 | |
| 509 | writeb(scratch, host->ioaddr + 0xC0); |
| 510 | } |
| 511 | |
| 512 | static int jmicron_probe_slot(struct sdhci_pci_slot *slot) |
| 513 | { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 514 | if (slot->chip->pdev->revision == 0) { |
| 515 | u16 version; |
| 516 | |
| 517 | version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION); |
| 518 | version = (version & SDHCI_VENDOR_VER_MASK) >> |
| 519 | SDHCI_VENDOR_VER_SHIFT; |
| 520 | |
| 521 | /* |
| 522 | * Older versions of the chip have lots of nasty glitches |
| 523 | * in the ADMA engine. It's best just to avoid it |
| 524 | * completely. |
| 525 | */ |
| 526 | if (version < 0xAC) |
| 527 | slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; |
| 528 | } |
| 529 | |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 530 | /* JM388 MMC doesn't support 1.8V while SD supports it */ |
| 531 | if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { |
| 532 | slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 | |
| 533 | MMC_VDD_29_30 | MMC_VDD_30_31 | |
| 534 | MMC_VDD_165_195; /* allow 1.8V */ |
| 535 | slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 | |
| 536 | MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */ |
| 537 | } |
| 538 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 539 | /* |
| 540 | * The secondary interface requires a bit set to get the |
| 541 | * interrupts. |
| 542 | */ |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 543 | if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || |
| 544 | slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 545 | jmicron_enable_mmc(slot->host, 1); |
| 546 | |
Takashi Iwai | d75c108 | 2010-12-16 17:54:14 +0100 | [diff] [blame] | 547 | slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST; |
| 548 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 552 | static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 553 | { |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 554 | if (dead) |
| 555 | return; |
| 556 | |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 557 | if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || |
| 558 | slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 559 | jmicron_enable_mmc(slot->host, 0); |
| 560 | } |
| 561 | |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 562 | static int jmicron_suspend(struct sdhci_pci_chip *chip) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 563 | { |
| 564 | int i; |
| 565 | |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 566 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || |
| 567 | chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 568 | for (i = 0; i < chip->num_slots; i++) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 569 | jmicron_enable_mmc(chip->slots[i]->host, 0); |
| 570 | } |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 575 | static int jmicron_resume(struct sdhci_pci_chip *chip) |
| 576 | { |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 577 | int ret, i; |
| 578 | |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 579 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || |
| 580 | chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 581 | for (i = 0; i < chip->num_slots; i++) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 582 | jmicron_enable_mmc(chip->slots[i]->host, 1); |
| 583 | } |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 584 | |
| 585 | ret = jmicron_pmos(chip, 1); |
| 586 | if (ret) { |
| 587 | dev_err(&chip->pdev->dev, "Failure enabling card power\n"); |
| 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
Jennifer Li | 26daa1e | 2010-11-17 23:01:59 -0500 | [diff] [blame] | 594 | static const struct sdhci_pci_fixes sdhci_o2 = { |
| 595 | .probe = o2_probe, |
| 596 | }; |
| 597 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 598 | static const struct sdhci_pci_fixes sdhci_jmicron = { |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 599 | .probe = jmicron_probe, |
| 600 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 601 | .probe_slot = jmicron_probe_slot, |
| 602 | .remove_slot = jmicron_remove_slot, |
| 603 | |
| 604 | .suspend = jmicron_suspend, |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 605 | .resume = jmicron_resume, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 606 | }; |
| 607 | |
Nicolas Pitre | a7a6186 | 2009-12-14 18:01:26 -0800 | [diff] [blame] | 608 | /* SysKonnect CardBus2SDIO extra registers */ |
| 609 | #define SYSKT_CTRL 0x200 |
| 610 | #define SYSKT_RDFIFO_STAT 0x204 |
| 611 | #define SYSKT_WRFIFO_STAT 0x208 |
| 612 | #define SYSKT_POWER_DATA 0x20c |
| 613 | #define SYSKT_POWER_330 0xef |
| 614 | #define SYSKT_POWER_300 0xf8 |
| 615 | #define SYSKT_POWER_184 0xcc |
| 616 | #define SYSKT_POWER_CMD 0x20d |
| 617 | #define SYSKT_POWER_START (1 << 7) |
| 618 | #define SYSKT_POWER_STATUS 0x20e |
| 619 | #define SYSKT_POWER_STATUS_OK (1 << 0) |
| 620 | #define SYSKT_BOARD_REV 0x210 |
| 621 | #define SYSKT_CHIP_REV 0x211 |
| 622 | #define SYSKT_CONF_DATA 0x212 |
| 623 | #define SYSKT_CONF_DATA_1V8 (1 << 2) |
| 624 | #define SYSKT_CONF_DATA_2V5 (1 << 1) |
| 625 | #define SYSKT_CONF_DATA_3V3 (1 << 0) |
| 626 | |
| 627 | static int syskt_probe(struct sdhci_pci_chip *chip) |
| 628 | { |
| 629 | if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { |
| 630 | chip->pdev->class &= ~0x0000FF; |
| 631 | chip->pdev->class |= PCI_SDHCI_IFDMA; |
| 632 | } |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int syskt_probe_slot(struct sdhci_pci_slot *slot) |
| 637 | { |
| 638 | int tm, ps; |
| 639 | |
| 640 | u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV); |
| 641 | u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV); |
| 642 | dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, " |
| 643 | "board rev %d.%d, chip rev %d.%d\n", |
| 644 | board_rev >> 4, board_rev & 0xf, |
| 645 | chip_rev >> 4, chip_rev & 0xf); |
| 646 | if (chip_rev >= 0x20) |
| 647 | slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA; |
| 648 | |
| 649 | writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA); |
| 650 | writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD); |
| 651 | udelay(50); |
| 652 | tm = 10; /* Wait max 1 ms */ |
| 653 | do { |
| 654 | ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS); |
| 655 | if (ps & SYSKT_POWER_STATUS_OK) |
| 656 | break; |
| 657 | udelay(100); |
| 658 | } while (--tm); |
| 659 | if (!tm) { |
| 660 | dev_err(&slot->chip->pdev->dev, |
| 661 | "power regulator never stabilized"); |
| 662 | writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD); |
| 663 | return -ENODEV; |
| 664 | } |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static const struct sdhci_pci_fixes sdhci_syskt = { |
| 670 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER, |
| 671 | .probe = syskt_probe, |
| 672 | .probe_slot = syskt_probe_slot, |
| 673 | }; |
| 674 | |
Harald Welte | 557b069 | 2009-06-18 16:53:38 +0200 | [diff] [blame] | 675 | static int via_probe(struct sdhci_pci_chip *chip) |
| 676 | { |
| 677 | if (chip->pdev->revision == 0x10) |
| 678 | chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER; |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static const struct sdhci_pci_fixes sdhci_via = { |
| 684 | .probe = via_probe, |
| 685 | }; |
| 686 | |
Bill Pemberton | 9647f84 | 2012-11-19 13:25:11 -0500 | [diff] [blame] | 687 | static const struct pci_device_id pci_ids[] = { |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 688 | { |
| 689 | .vendor = PCI_VENDOR_ID_RICOH, |
| 690 | .device = PCI_DEVICE_ID_RICOH_R5C822, |
| 691 | .subvendor = PCI_ANY_ID, |
| 692 | .subdevice = PCI_ANY_ID, |
| 693 | .driver_data = (kernel_ulong_t)&sdhci_ricoh, |
| 694 | }, |
| 695 | |
| 696 | { |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 697 | .vendor = PCI_VENDOR_ID_RICOH, |
| 698 | .device = 0x843, |
| 699 | .subvendor = PCI_ANY_ID, |
| 700 | .subdevice = PCI_ANY_ID, |
| 701 | .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, |
| 702 | }, |
| 703 | |
| 704 | { |
Pablo Castillo | 568133e | 2010-08-10 18:02:01 -0700 | [diff] [blame] | 705 | .vendor = PCI_VENDOR_ID_RICOH, |
| 706 | .device = 0xe822, |
| 707 | .subvendor = PCI_ANY_ID, |
| 708 | .subdevice = PCI_ANY_ID, |
| 709 | .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, |
| 710 | }, |
| 711 | |
| 712 | { |
Manoj Iyer | 5fd11c0 | 2011-02-11 16:25:31 -0600 | [diff] [blame] | 713 | .vendor = PCI_VENDOR_ID_RICOH, |
| 714 | .device = 0xe823, |
| 715 | .subvendor = PCI_ANY_ID, |
| 716 | .subdevice = PCI_ANY_ID, |
| 717 | .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, |
| 718 | }, |
| 719 | |
| 720 | { |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 721 | .vendor = PCI_VENDOR_ID_ENE, |
| 722 | .device = PCI_DEVICE_ID_ENE_CB712_SD, |
| 723 | .subvendor = PCI_ANY_ID, |
| 724 | .subdevice = PCI_ANY_ID, |
| 725 | .driver_data = (kernel_ulong_t)&sdhci_ene_712, |
| 726 | }, |
| 727 | |
| 728 | { |
| 729 | .vendor = PCI_VENDOR_ID_ENE, |
| 730 | .device = PCI_DEVICE_ID_ENE_CB712_SD_2, |
| 731 | .subvendor = PCI_ANY_ID, |
| 732 | .subdevice = PCI_ANY_ID, |
| 733 | .driver_data = (kernel_ulong_t)&sdhci_ene_712, |
| 734 | }, |
| 735 | |
| 736 | { |
| 737 | .vendor = PCI_VENDOR_ID_ENE, |
| 738 | .device = PCI_DEVICE_ID_ENE_CB714_SD, |
| 739 | .subvendor = PCI_ANY_ID, |
| 740 | .subdevice = PCI_ANY_ID, |
| 741 | .driver_data = (kernel_ulong_t)&sdhci_ene_714, |
| 742 | }, |
| 743 | |
| 744 | { |
| 745 | .vendor = PCI_VENDOR_ID_ENE, |
| 746 | .device = PCI_DEVICE_ID_ENE_CB714_SD_2, |
| 747 | .subvendor = PCI_ANY_ID, |
| 748 | .subdevice = PCI_ANY_ID, |
| 749 | .driver_data = (kernel_ulong_t)&sdhci_ene_714, |
| 750 | }, |
| 751 | |
| 752 | { |
| 753 | .vendor = PCI_VENDOR_ID_MARVELL, |
David Woodhouse | 8c5eb88 | 2008-09-03 09:45:57 +0100 | [diff] [blame] | 754 | .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 755 | .subvendor = PCI_ANY_ID, |
| 756 | .subdevice = PCI_ANY_ID, |
| 757 | .driver_data = (kernel_ulong_t)&sdhci_cafe, |
| 758 | }, |
| 759 | |
| 760 | { |
| 761 | .vendor = PCI_VENDOR_ID_JMICRON, |
| 762 | .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD, |
| 763 | .subvendor = PCI_ANY_ID, |
| 764 | .subdevice = PCI_ANY_ID, |
| 765 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, |
| 766 | }, |
| 767 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 768 | { |
| 769 | .vendor = PCI_VENDOR_ID_JMICRON, |
| 770 | .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC, |
| 771 | .subvendor = PCI_ANY_ID, |
| 772 | .subdevice = PCI_ANY_ID, |
| 773 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, |
| 774 | }, |
| 775 | |
Harald Welte | 557b069 | 2009-06-18 16:53:38 +0200 | [diff] [blame] | 776 | { |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 777 | .vendor = PCI_VENDOR_ID_JMICRON, |
| 778 | .device = PCI_DEVICE_ID_JMICRON_JMB388_SD, |
| 779 | .subvendor = PCI_ANY_ID, |
| 780 | .subdevice = PCI_ANY_ID, |
| 781 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, |
| 782 | }, |
| 783 | |
| 784 | { |
| 785 | .vendor = PCI_VENDOR_ID_JMICRON, |
| 786 | .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD, |
| 787 | .subvendor = PCI_ANY_ID, |
| 788 | .subdevice = PCI_ANY_ID, |
| 789 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, |
| 790 | }, |
| 791 | |
| 792 | { |
Nicolas Pitre | a7a6186 | 2009-12-14 18:01:26 -0800 | [diff] [blame] | 793 | .vendor = PCI_VENDOR_ID_SYSKONNECT, |
| 794 | .device = 0x8000, |
| 795 | .subvendor = PCI_ANY_ID, |
| 796 | .subdevice = PCI_ANY_ID, |
| 797 | .driver_data = (kernel_ulong_t)&sdhci_syskt, |
| 798 | }, |
| 799 | |
| 800 | { |
Harald Welte | 557b069 | 2009-06-18 16:53:38 +0200 | [diff] [blame] | 801 | .vendor = PCI_VENDOR_ID_VIA, |
| 802 | .device = 0x95d0, |
| 803 | .subvendor = PCI_ANY_ID, |
| 804 | .subdevice = PCI_ANY_ID, |
| 805 | .driver_data = (kernel_ulong_t)&sdhci_via, |
| 806 | }, |
| 807 | |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 808 | { |
| 809 | .vendor = PCI_VENDOR_ID_INTEL, |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 810 | .device = PCI_DEVICE_ID_INTEL_MRST_SD0, |
| 811 | .subvendor = PCI_ANY_ID, |
| 812 | .subdevice = PCI_ANY_ID, |
| 813 | .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0, |
| 814 | }, |
| 815 | |
| 816 | { |
| 817 | .vendor = PCI_VENDOR_ID_INTEL, |
| 818 | .device = PCI_DEVICE_ID_INTEL_MRST_SD1, |
| 819 | .subvendor = PCI_ANY_ID, |
| 820 | .subdevice = PCI_ANY_ID, |
Jacob Pan | 35ac6f0 | 2010-11-09 13:57:29 +0000 | [diff] [blame] | 821 | .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2, |
| 822 | }, |
| 823 | |
| 824 | { |
| 825 | .vendor = PCI_VENDOR_ID_INTEL, |
| 826 | .device = PCI_DEVICE_ID_INTEL_MRST_SD2, |
| 827 | .subvendor = PCI_ANY_ID, |
| 828 | .subdevice = PCI_ANY_ID, |
| 829 | .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2, |
Alan Cox | f9ee3ea | 2010-10-04 15:25:11 +0100 | [diff] [blame] | 830 | }, |
| 831 | |
| 832 | { |
| 833 | .vendor = PCI_VENDOR_ID_INTEL, |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 834 | .device = PCI_DEVICE_ID_INTEL_MFD_SD, |
| 835 | .subvendor = PCI_ANY_ID, |
| 836 | .subdevice = PCI_ANY_ID, |
| 837 | .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd, |
| 838 | }, |
| 839 | |
| 840 | { |
| 841 | .vendor = PCI_VENDOR_ID_INTEL, |
| 842 | .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1, |
| 843 | .subvendor = PCI_ANY_ID, |
| 844 | .subdevice = PCI_ANY_ID, |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 845 | .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 846 | }, |
| 847 | |
| 848 | { |
| 849 | .vendor = PCI_VENDOR_ID_INTEL, |
| 850 | .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2, |
| 851 | .subvendor = PCI_ANY_ID, |
| 852 | .subdevice = PCI_ANY_ID, |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 853 | .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 854 | }, |
| 855 | |
| 856 | { |
| 857 | .vendor = PCI_VENDOR_ID_INTEL, |
| 858 | .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0, |
| 859 | .subvendor = PCI_ANY_ID, |
| 860 | .subdevice = PCI_ANY_ID, |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 861 | .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 862 | }, |
| 863 | |
| 864 | { |
| 865 | .vendor = PCI_VENDOR_ID_INTEL, |
| 866 | .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1, |
| 867 | .subvendor = PCI_ANY_ID, |
| 868 | .subdevice = PCI_ANY_ID, |
Adrian Hunter | 0d013bc | 2011-06-29 14:23:47 +0300 | [diff] [blame] | 869 | .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, |
Xiaochen Shen | 2922905 | 2010-10-04 15:24:52 +0100 | [diff] [blame] | 870 | }, |
| 871 | |
Jennifer Li | 26daa1e | 2010-11-17 23:01:59 -0500 | [diff] [blame] | 872 | { |
Alexander Stein | 296e0b0 | 2012-03-14 08:38:58 +0100 | [diff] [blame] | 873 | .vendor = PCI_VENDOR_ID_INTEL, |
| 874 | .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0, |
| 875 | .subvendor = PCI_ANY_ID, |
| 876 | .subdevice = PCI_ANY_ID, |
| 877 | .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio, |
| 878 | }, |
| 879 | |
| 880 | { |
| 881 | .vendor = PCI_VENDOR_ID_INTEL, |
| 882 | .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1, |
| 883 | .subvendor = PCI_ANY_ID, |
| 884 | .subdevice = PCI_ANY_ID, |
| 885 | .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio, |
| 886 | }, |
| 887 | |
| 888 | { |
Adrian Hunter | 728ef3d | 2013-04-26 11:27:23 +0300 | [diff] [blame^] | 889 | .vendor = PCI_VENDOR_ID_INTEL, |
| 890 | .device = PCI_DEVICE_ID_INTEL_BYT_EMMC, |
| 891 | .subvendor = PCI_ANY_ID, |
| 892 | .subdevice = PCI_ANY_ID, |
| 893 | .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, |
| 894 | }, |
| 895 | |
| 896 | { |
| 897 | .vendor = PCI_VENDOR_ID_INTEL, |
| 898 | .device = PCI_DEVICE_ID_INTEL_BYT_SDIO, |
| 899 | .subvendor = PCI_ANY_ID, |
| 900 | .subdevice = PCI_ANY_ID, |
| 901 | .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, |
| 902 | }, |
| 903 | |
| 904 | { |
| 905 | .vendor = PCI_VENDOR_ID_INTEL, |
| 906 | .device = PCI_DEVICE_ID_INTEL_BYT_SD, |
| 907 | .subvendor = PCI_ANY_ID, |
| 908 | .subdevice = PCI_ANY_ID, |
| 909 | .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, |
| 910 | }, |
| 911 | |
| 912 | { |
Jennifer Li | 26daa1e | 2010-11-17 23:01:59 -0500 | [diff] [blame] | 913 | .vendor = PCI_VENDOR_ID_O2, |
| 914 | .device = PCI_DEVICE_ID_O2_8120, |
| 915 | .subvendor = PCI_ANY_ID, |
| 916 | .subdevice = PCI_ANY_ID, |
| 917 | .driver_data = (kernel_ulong_t)&sdhci_o2, |
| 918 | }, |
| 919 | |
| 920 | { |
| 921 | .vendor = PCI_VENDOR_ID_O2, |
| 922 | .device = PCI_DEVICE_ID_O2_8220, |
| 923 | .subvendor = PCI_ANY_ID, |
| 924 | .subdevice = PCI_ANY_ID, |
| 925 | .driver_data = (kernel_ulong_t)&sdhci_o2, |
| 926 | }, |
| 927 | |
| 928 | { |
| 929 | .vendor = PCI_VENDOR_ID_O2, |
| 930 | .device = PCI_DEVICE_ID_O2_8221, |
| 931 | .subvendor = PCI_ANY_ID, |
| 932 | .subdevice = PCI_ANY_ID, |
| 933 | .driver_data = (kernel_ulong_t)&sdhci_o2, |
| 934 | }, |
| 935 | |
| 936 | { |
| 937 | .vendor = PCI_VENDOR_ID_O2, |
| 938 | .device = PCI_DEVICE_ID_O2_8320, |
| 939 | .subvendor = PCI_ANY_ID, |
| 940 | .subdevice = PCI_ANY_ID, |
| 941 | .driver_data = (kernel_ulong_t)&sdhci_o2, |
| 942 | }, |
| 943 | |
| 944 | { |
| 945 | .vendor = PCI_VENDOR_ID_O2, |
| 946 | .device = PCI_DEVICE_ID_O2_8321, |
| 947 | .subvendor = PCI_ANY_ID, |
| 948 | .subdevice = PCI_ANY_ID, |
| 949 | .driver_data = (kernel_ulong_t)&sdhci_o2, |
| 950 | }, |
| 951 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 952 | { /* Generic SD host controller */ |
| 953 | PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) |
| 954 | }, |
| 955 | |
| 956 | { /* end: all zeroes */ }, |
| 957 | }; |
| 958 | |
| 959 | MODULE_DEVICE_TABLE(pci, pci_ids); |
| 960 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 961 | /*****************************************************************************\ |
| 962 | * * |
| 963 | * SDHCI core callbacks * |
| 964 | * * |
| 965 | \*****************************************************************************/ |
| 966 | |
| 967 | static int sdhci_pci_enable_dma(struct sdhci_host *host) |
| 968 | { |
| 969 | struct sdhci_pci_slot *slot; |
| 970 | struct pci_dev *pdev; |
| 971 | int ret; |
| 972 | |
| 973 | slot = sdhci_priv(host); |
| 974 | pdev = slot->chip->pdev; |
| 975 | |
| 976 | if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) && |
| 977 | ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) && |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 978 | (host->flags & SDHCI_USE_SDMA)) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 979 | dev_warn(&pdev->dev, "Will use DMA mode even though HW " |
| 980 | "doesn't fully claim to support it.\n"); |
| 981 | } |
| 982 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 983 | ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 984 | if (ret) |
| 985 | return ret; |
| 986 | |
| 987 | pci_set_master(pdev); |
| 988 | |
| 989 | return 0; |
| 990 | } |
| 991 | |
Sascha Hauer | 7bc088d | 2013-01-21 19:02:27 +0800 | [diff] [blame] | 992 | static int sdhci_pci_bus_width(struct sdhci_host *host, int width) |
Major Lee | 68077b0 | 2011-06-29 14:23:46 +0300 | [diff] [blame] | 993 | { |
| 994 | u8 ctrl; |
| 995 | |
| 996 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
| 997 | |
| 998 | switch (width) { |
| 999 | case MMC_BUS_WIDTH_8: |
| 1000 | ctrl |= SDHCI_CTRL_8BITBUS; |
| 1001 | ctrl &= ~SDHCI_CTRL_4BITBUS; |
| 1002 | break; |
| 1003 | case MMC_BUS_WIDTH_4: |
| 1004 | ctrl |= SDHCI_CTRL_4BITBUS; |
| 1005 | ctrl &= ~SDHCI_CTRL_8BITBUS; |
| 1006 | break; |
| 1007 | default: |
| 1008 | ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS); |
| 1009 | break; |
| 1010 | } |
| 1011 | |
| 1012 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
| 1013 | |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
Adrian Hunter | 0f20165 | 2011-08-29 16:42:13 +0300 | [diff] [blame] | 1017 | static void sdhci_pci_hw_reset(struct sdhci_host *host) |
| 1018 | { |
| 1019 | struct sdhci_pci_slot *slot = sdhci_priv(host); |
| 1020 | int rst_n_gpio = slot->rst_n_gpio; |
| 1021 | |
| 1022 | if (!gpio_is_valid(rst_n_gpio)) |
| 1023 | return; |
| 1024 | gpio_set_value_cansleep(rst_n_gpio, 0); |
| 1025 | /* For eMMC, minimum is 1us but give it 10us for good measure */ |
| 1026 | udelay(10); |
| 1027 | gpio_set_value_cansleep(rst_n_gpio, 1); |
| 1028 | /* For eMMC, minimum is 200us but give it 300us for good measure */ |
| 1029 | usleep_range(300, 1000); |
| 1030 | } |
| 1031 | |
Lars-Peter Clausen | c915568 | 2013-03-13 19:26:05 +0100 | [diff] [blame] | 1032 | static const struct sdhci_ops sdhci_pci_ops = { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1033 | .enable_dma = sdhci_pci_enable_dma, |
Sascha Hauer | 7bc088d | 2013-01-21 19:02:27 +0800 | [diff] [blame] | 1034 | .platform_bus_width = sdhci_pci_bus_width, |
Adrian Hunter | 0f20165 | 2011-08-29 16:42:13 +0300 | [diff] [blame] | 1035 | .hw_reset = sdhci_pci_hw_reset, |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1036 | }; |
| 1037 | |
| 1038 | /*****************************************************************************\ |
| 1039 | * * |
| 1040 | * Suspend/resume * |
| 1041 | * * |
| 1042 | \*****************************************************************************/ |
| 1043 | |
| 1044 | #ifdef CONFIG_PM |
| 1045 | |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1046 | static int sdhci_pci_suspend(struct device *dev) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1047 | { |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1048 | struct pci_dev *pdev = to_pci_dev(dev); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1049 | struct sdhci_pci_chip *chip; |
| 1050 | struct sdhci_pci_slot *slot; |
Daniel Drake | 5f61970 | 2010-11-04 22:20:39 +0000 | [diff] [blame] | 1051 | mmc_pm_flag_t slot_pm_flags; |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1052 | mmc_pm_flag_t pm_flags = 0; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1053 | int i, ret; |
| 1054 | |
| 1055 | chip = pci_get_drvdata(pdev); |
| 1056 | if (!chip) |
| 1057 | return 0; |
| 1058 | |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1059 | for (i = 0; i < chip->num_slots; i++) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1060 | slot = chip->slots[i]; |
| 1061 | if (!slot) |
| 1062 | continue; |
| 1063 | |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1064 | ret = sdhci_suspend_host(slot->host); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1065 | |
Axel Lin | b678b91 | 2011-12-03 15:28:05 +0800 | [diff] [blame] | 1066 | if (ret) |
| 1067 | goto err_pci_suspend; |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1068 | |
Daniel Drake | 5f61970 | 2010-11-04 22:20:39 +0000 | [diff] [blame] | 1069 | slot_pm_flags = slot->host->mmc->pm_flags; |
| 1070 | if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ) |
| 1071 | sdhci_enable_irq_wakeups(slot->host); |
| 1072 | |
| 1073 | pm_flags |= slot_pm_flags; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1076 | if (chip->fixes && chip->fixes->suspend) { |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1077 | ret = chip->fixes->suspend(chip); |
Axel Lin | b678b91 | 2011-12-03 15:28:05 +0800 | [diff] [blame] | 1078 | if (ret) |
| 1079 | goto err_pci_suspend; |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1080 | } |
| 1081 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1082 | pci_save_state(pdev); |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1083 | if (pm_flags & MMC_PM_KEEP_POWER) { |
Daniel Drake | 5f61970 | 2010-11-04 22:20:39 +0000 | [diff] [blame] | 1084 | if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) { |
| 1085 | pci_pme_active(pdev, true); |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1086 | pci_enable_wake(pdev, PCI_D3hot, 1); |
Daniel Drake | 5f61970 | 2010-11-04 22:20:39 +0000 | [diff] [blame] | 1087 | } |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1088 | pci_set_power_state(pdev, PCI_D3hot); |
| 1089 | } else { |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1090 | pci_enable_wake(pdev, PCI_D3hot, 0); |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1091 | pci_disable_device(pdev); |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1092 | pci_set_power_state(pdev, PCI_D3hot); |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1093 | } |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1094 | |
| 1095 | return 0; |
Axel Lin | b678b91 | 2011-12-03 15:28:05 +0800 | [diff] [blame] | 1096 | |
| 1097 | err_pci_suspend: |
| 1098 | while (--i >= 0) |
| 1099 | sdhci_resume_host(chip->slots[i]->host); |
| 1100 | return ret; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1103 | static int sdhci_pci_resume(struct device *dev) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1104 | { |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1105 | struct pci_dev *pdev = to_pci_dev(dev); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1106 | struct sdhci_pci_chip *chip; |
| 1107 | struct sdhci_pci_slot *slot; |
| 1108 | int i, ret; |
| 1109 | |
| 1110 | chip = pci_get_drvdata(pdev); |
| 1111 | if (!chip) |
| 1112 | return 0; |
| 1113 | |
| 1114 | pci_set_power_state(pdev, PCI_D0); |
| 1115 | pci_restore_state(pdev); |
| 1116 | ret = pci_enable_device(pdev); |
| 1117 | if (ret) |
| 1118 | return ret; |
| 1119 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 1120 | if (chip->fixes && chip->fixes->resume) { |
| 1121 | ret = chip->fixes->resume(chip); |
| 1122 | if (ret) |
| 1123 | return ret; |
| 1124 | } |
| 1125 | |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1126 | for (i = 0; i < chip->num_slots; i++) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1127 | slot = chip->slots[i]; |
| 1128 | if (!slot) |
| 1129 | continue; |
| 1130 | |
| 1131 | ret = sdhci_resume_host(slot->host); |
| 1132 | if (ret) |
| 1133 | return ret; |
| 1134 | } |
| 1135 | |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | #else /* CONFIG_PM */ |
| 1140 | |
| 1141 | #define sdhci_pci_suspend NULL |
| 1142 | #define sdhci_pci_resume NULL |
| 1143 | |
| 1144 | #endif /* CONFIG_PM */ |
| 1145 | |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1146 | #ifdef CONFIG_PM_RUNTIME |
| 1147 | |
| 1148 | static int sdhci_pci_runtime_suspend(struct device *dev) |
| 1149 | { |
| 1150 | struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); |
| 1151 | struct sdhci_pci_chip *chip; |
| 1152 | struct sdhci_pci_slot *slot; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1153 | int i, ret; |
| 1154 | |
| 1155 | chip = pci_get_drvdata(pdev); |
| 1156 | if (!chip) |
| 1157 | return 0; |
| 1158 | |
| 1159 | for (i = 0; i < chip->num_slots; i++) { |
| 1160 | slot = chip->slots[i]; |
| 1161 | if (!slot) |
| 1162 | continue; |
| 1163 | |
| 1164 | ret = sdhci_runtime_suspend_host(slot->host); |
| 1165 | |
Axel Lin | b678b91 | 2011-12-03 15:28:05 +0800 | [diff] [blame] | 1166 | if (ret) |
| 1167 | goto err_pci_runtime_suspend; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | if (chip->fixes && chip->fixes->suspend) { |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1171 | ret = chip->fixes->suspend(chip); |
Axel Lin | b678b91 | 2011-12-03 15:28:05 +0800 | [diff] [blame] | 1172 | if (ret) |
| 1173 | goto err_pci_runtime_suspend; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | return 0; |
Axel Lin | b678b91 | 2011-12-03 15:28:05 +0800 | [diff] [blame] | 1177 | |
| 1178 | err_pci_runtime_suspend: |
| 1179 | while (--i >= 0) |
| 1180 | sdhci_runtime_resume_host(chip->slots[i]->host); |
| 1181 | return ret; |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static int sdhci_pci_runtime_resume(struct device *dev) |
| 1185 | { |
| 1186 | struct pci_dev *pdev = container_of(dev, struct pci_dev, dev); |
| 1187 | struct sdhci_pci_chip *chip; |
| 1188 | struct sdhci_pci_slot *slot; |
| 1189 | int i, ret; |
| 1190 | |
| 1191 | chip = pci_get_drvdata(pdev); |
| 1192 | if (!chip) |
| 1193 | return 0; |
| 1194 | |
| 1195 | if (chip->fixes && chip->fixes->resume) { |
| 1196 | ret = chip->fixes->resume(chip); |
| 1197 | if (ret) |
| 1198 | return ret; |
| 1199 | } |
| 1200 | |
| 1201 | for (i = 0; i < chip->num_slots; i++) { |
| 1202 | slot = chip->slots[i]; |
| 1203 | if (!slot) |
| 1204 | continue; |
| 1205 | |
| 1206 | ret = sdhci_runtime_resume_host(slot->host); |
| 1207 | if (ret) |
| 1208 | return ret; |
| 1209 | } |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | static int sdhci_pci_runtime_idle(struct device *dev) |
| 1215 | { |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
| 1219 | #else |
| 1220 | |
| 1221 | #define sdhci_pci_runtime_suspend NULL |
| 1222 | #define sdhci_pci_runtime_resume NULL |
| 1223 | #define sdhci_pci_runtime_idle NULL |
| 1224 | |
| 1225 | #endif |
| 1226 | |
| 1227 | static const struct dev_pm_ops sdhci_pci_pm_ops = { |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 1228 | .suspend = sdhci_pci_suspend, |
| 1229 | .resume = sdhci_pci_resume, |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1230 | .runtime_suspend = sdhci_pci_runtime_suspend, |
| 1231 | .runtime_resume = sdhci_pci_runtime_resume, |
| 1232 | .runtime_idle = sdhci_pci_runtime_idle, |
| 1233 | }; |
| 1234 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1235 | /*****************************************************************************\ |
| 1236 | * * |
| 1237 | * Device probing/removal * |
| 1238 | * * |
| 1239 | \*****************************************************************************/ |
| 1240 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 1241 | static struct sdhci_pci_slot *sdhci_pci_probe_slot( |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1242 | struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar, |
| 1243 | int slotno) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1244 | { |
| 1245 | struct sdhci_pci_slot *slot; |
| 1246 | struct sdhci_host *host; |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1247 | int ret, bar = first_bar + slotno; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1248 | |
| 1249 | if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { |
| 1250 | dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar); |
| 1251 | return ERR_PTR(-ENODEV); |
| 1252 | } |
| 1253 | |
Adrian Hunter | 90b3e6c | 2012-10-18 09:54:31 +0300 | [diff] [blame] | 1254 | if (pci_resource_len(pdev, bar) < 0x100) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1255 | dev_err(&pdev->dev, "Invalid iomem size. You may " |
| 1256 | "experience problems.\n"); |
| 1257 | } |
| 1258 | |
| 1259 | if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { |
| 1260 | dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n"); |
| 1261 | return ERR_PTR(-ENODEV); |
| 1262 | } |
| 1263 | |
| 1264 | if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) { |
| 1265 | dev_err(&pdev->dev, "Unknown interface. Aborting.\n"); |
| 1266 | return ERR_PTR(-ENODEV); |
| 1267 | } |
| 1268 | |
| 1269 | host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot)); |
| 1270 | if (IS_ERR(host)) { |
Dan Carpenter | c60a32c | 2009-04-10 23:31:10 +0200 | [diff] [blame] | 1271 | dev_err(&pdev->dev, "cannot allocate host\n"); |
Julia Lawall | dc0fd7b | 2010-05-26 14:42:11 -0700 | [diff] [blame] | 1272 | return ERR_CAST(host); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | slot = sdhci_priv(host); |
| 1276 | |
| 1277 | slot->chip = chip; |
| 1278 | slot->host = host; |
| 1279 | slot->pci_bar = bar; |
Adrian Hunter | 0f20165 | 2011-08-29 16:42:13 +0300 | [diff] [blame] | 1280 | slot->rst_n_gpio = -EINVAL; |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 1281 | slot->cd_gpio = -EINVAL; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1282 | |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1283 | /* Retrieve platform data if there is any */ |
| 1284 | if (*sdhci_pci_get_data) |
| 1285 | slot->data = sdhci_pci_get_data(pdev, slotno); |
| 1286 | |
| 1287 | if (slot->data) { |
| 1288 | if (slot->data->setup) { |
| 1289 | ret = slot->data->setup(slot->data); |
| 1290 | if (ret) { |
| 1291 | dev_err(&pdev->dev, "platform setup failed\n"); |
| 1292 | goto free; |
| 1293 | } |
| 1294 | } |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 1295 | slot->rst_n_gpio = slot->data->rst_n_gpio; |
| 1296 | slot->cd_gpio = slot->data->cd_gpio; |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1297 | } |
| 1298 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1299 | host->hw_name = "PCI"; |
| 1300 | host->ops = &sdhci_pci_ops; |
| 1301 | host->quirks = chip->quirks; |
Adrian Hunter | f3c55a7 | 2012-02-07 14:48:55 +0200 | [diff] [blame] | 1302 | host->quirks2 = chip->quirks2; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1303 | |
| 1304 | host->irq = pdev->irq; |
| 1305 | |
| 1306 | ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc)); |
| 1307 | if (ret) { |
| 1308 | dev_err(&pdev->dev, "cannot request region\n"); |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1309 | goto cleanup; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1310 | } |
| 1311 | |
Arjan van de Ven | 092f82e | 2008-09-28 16:15:56 -0700 | [diff] [blame] | 1312 | host->ioaddr = pci_ioremap_bar(pdev, bar); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1313 | if (!host->ioaddr) { |
| 1314 | dev_err(&pdev->dev, "failed to remap registers\n"); |
Chris Ball | 9fdcdbb | 2011-03-29 00:46:12 -0400 | [diff] [blame] | 1315 | ret = -ENOMEM; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1316 | goto release; |
| 1317 | } |
| 1318 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1319 | if (chip->fixes && chip->fixes->probe_slot) { |
| 1320 | ret = chip->fixes->probe_slot(slot); |
| 1321 | if (ret) |
| 1322 | goto unmap; |
| 1323 | } |
| 1324 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 1325 | if (gpio_is_valid(slot->rst_n_gpio)) { |
| 1326 | if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) { |
| 1327 | gpio_direction_output(slot->rst_n_gpio, 1); |
| 1328 | slot->host->mmc->caps |= MMC_CAP_HW_RESET; |
| 1329 | } else { |
| 1330 | dev_warn(&pdev->dev, "failed to request rst_n_gpio\n"); |
| 1331 | slot->rst_n_gpio = -EINVAL; |
| 1332 | } |
| 1333 | } |
| 1334 | |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1335 | host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ; |
Aaron Lu | eed222a | 2013-03-05 11:24:52 +0800 | [diff] [blame] | 1336 | host->mmc->slotno = slotno; |
Adrian Hunter | a08b17b | 2013-04-15 11:27:25 -0400 | [diff] [blame] | 1337 | host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 1338 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1339 | ret = sdhci_add_host(host); |
| 1340 | if (ret) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1341 | goto remove; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1342 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 1343 | sdhci_pci_add_own_cd(slot); |
| 1344 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1345 | return slot; |
| 1346 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1347 | remove: |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 1348 | if (gpio_is_valid(slot->rst_n_gpio)) |
| 1349 | gpio_free(slot->rst_n_gpio); |
| 1350 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1351 | if (chip->fixes && chip->fixes->remove_slot) |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1352 | chip->fixes->remove_slot(slot, 0); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1353 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1354 | unmap: |
| 1355 | iounmap(host->ioaddr); |
| 1356 | |
| 1357 | release: |
| 1358 | pci_release_region(pdev, bar); |
Dan Carpenter | c60a32c | 2009-04-10 23:31:10 +0200 | [diff] [blame] | 1359 | |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1360 | cleanup: |
| 1361 | if (slot->data && slot->data->cleanup) |
| 1362 | slot->data->cleanup(slot->data); |
| 1363 | |
Dan Carpenter | c60a32c | 2009-04-10 23:31:10 +0200 | [diff] [blame] | 1364 | free: |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1365 | sdhci_free_host(host); |
| 1366 | |
| 1367 | return ERR_PTR(ret); |
| 1368 | } |
| 1369 | |
| 1370 | static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot) |
| 1371 | { |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1372 | int dead; |
| 1373 | u32 scratch; |
| 1374 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 1375 | sdhci_pci_remove_own_cd(slot); |
| 1376 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1377 | dead = 0; |
| 1378 | scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS); |
| 1379 | if (scratch == (u32)-1) |
| 1380 | dead = 1; |
| 1381 | |
| 1382 | sdhci_remove_host(slot->host, dead); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1383 | |
Adrian Hunter | c5e027a | 2011-12-27 15:48:44 +0200 | [diff] [blame] | 1384 | if (gpio_is_valid(slot->rst_n_gpio)) |
| 1385 | gpio_free(slot->rst_n_gpio); |
| 1386 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1387 | if (slot->chip->fixes && slot->chip->fixes->remove_slot) |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 1388 | slot->chip->fixes->remove_slot(slot, dead); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1389 | |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1390 | if (slot->data && slot->data->cleanup) |
| 1391 | slot->data->cleanup(slot->data); |
| 1392 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1393 | pci_release_region(slot->chip->pdev, slot->pci_bar); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 1394 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1395 | sdhci_free_host(slot->host); |
| 1396 | } |
| 1397 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 1398 | static void sdhci_pci_runtime_pm_allow(struct device *dev) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1399 | { |
| 1400 | pm_runtime_put_noidle(dev); |
| 1401 | pm_runtime_allow(dev); |
| 1402 | pm_runtime_set_autosuspend_delay(dev, 50); |
| 1403 | pm_runtime_use_autosuspend(dev); |
| 1404 | pm_suspend_ignore_children(dev, 1); |
| 1405 | } |
| 1406 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 1407 | static void sdhci_pci_runtime_pm_forbid(struct device *dev) |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1408 | { |
| 1409 | pm_runtime_forbid(dev); |
| 1410 | pm_runtime_get_noresume(dev); |
| 1411 | } |
| 1412 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 1413 | static int sdhci_pci_probe(struct pci_dev *pdev, |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1414 | const struct pci_device_id *ent) |
| 1415 | { |
| 1416 | struct sdhci_pci_chip *chip; |
| 1417 | struct sdhci_pci_slot *slot; |
| 1418 | |
Sergei Shtylyov | cf5e23e | 2011-03-17 16:46:17 -0400 | [diff] [blame] | 1419 | u8 slots, first_bar; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1420 | int ret, i; |
| 1421 | |
| 1422 | BUG_ON(pdev == NULL); |
| 1423 | BUG_ON(ent == NULL); |
| 1424 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1425 | dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n", |
Sergei Shtylyov | cf5e23e | 2011-03-17 16:46:17 -0400 | [diff] [blame] | 1426 | (int)pdev->vendor, (int)pdev->device, (int)pdev->revision); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1427 | |
| 1428 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots); |
| 1429 | if (ret) |
| 1430 | return ret; |
| 1431 | |
| 1432 | slots = PCI_SLOT_INFO_SLOTS(slots) + 1; |
| 1433 | dev_dbg(&pdev->dev, "found %d slot(s)\n", slots); |
| 1434 | if (slots == 0) |
| 1435 | return -ENODEV; |
| 1436 | |
| 1437 | BUG_ON(slots > MAX_SLOTS); |
| 1438 | |
| 1439 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar); |
| 1440 | if (ret) |
| 1441 | return ret; |
| 1442 | |
| 1443 | first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK; |
| 1444 | |
| 1445 | if (first_bar > 5) { |
| 1446 | dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n"); |
| 1447 | return -ENODEV; |
| 1448 | } |
| 1449 | |
| 1450 | ret = pci_enable_device(pdev); |
| 1451 | if (ret) |
| 1452 | return ret; |
| 1453 | |
| 1454 | chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL); |
| 1455 | if (!chip) { |
| 1456 | ret = -ENOMEM; |
| 1457 | goto err; |
| 1458 | } |
| 1459 | |
| 1460 | chip->pdev = pdev; |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1461 | chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data; |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 1462 | if (chip->fixes) { |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 1463 | chip->quirks = chip->fixes->quirks; |
Adrian Hunter | f3c55a7 | 2012-02-07 14:48:55 +0200 | [diff] [blame] | 1464 | chip->quirks2 = chip->fixes->quirks2; |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 1465 | chip->allow_runtime_pm = chip->fixes->allow_runtime_pm; |
| 1466 | } |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1467 | chip->num_slots = slots; |
| 1468 | |
| 1469 | pci_set_drvdata(pdev, chip); |
| 1470 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 1471 | if (chip->fixes && chip->fixes->probe) { |
| 1472 | ret = chip->fixes->probe(chip); |
| 1473 | if (ret) |
| 1474 | goto free; |
| 1475 | } |
| 1476 | |
Alan Cox | 225d85f | 2010-10-04 15:24:21 +0100 | [diff] [blame] | 1477 | slots = chip->num_slots; /* Quirk may have changed this */ |
| 1478 | |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1479 | for (i = 0; i < slots; i++) { |
Adrian Hunter | 52c506f | 2011-12-27 15:48:43 +0200 | [diff] [blame] | 1480 | slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1481 | if (IS_ERR(slot)) { |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1482 | for (i--; i >= 0; i--) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1483 | sdhci_pci_remove_slot(chip->slots[i]); |
| 1484 | ret = PTR_ERR(slot); |
| 1485 | goto free; |
| 1486 | } |
| 1487 | |
| 1488 | chip->slots[i] = slot; |
| 1489 | } |
| 1490 | |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 1491 | if (chip->allow_runtime_pm) |
| 1492 | sdhci_pci_runtime_pm_allow(&pdev->dev); |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1493 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1494 | return 0; |
| 1495 | |
| 1496 | free: |
| 1497 | pci_set_drvdata(pdev, NULL); |
| 1498 | kfree(chip); |
| 1499 | |
| 1500 | err: |
| 1501 | pci_disable_device(pdev); |
| 1502 | return ret; |
| 1503 | } |
| 1504 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 1505 | static void sdhci_pci_remove(struct pci_dev *pdev) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1506 | { |
| 1507 | int i; |
| 1508 | struct sdhci_pci_chip *chip; |
| 1509 | |
| 1510 | chip = pci_get_drvdata(pdev); |
| 1511 | |
| 1512 | if (chip) { |
Adrian Hunter | c43fd77 | 2011-10-17 10:52:44 +0300 | [diff] [blame] | 1513 | if (chip->allow_runtime_pm) |
| 1514 | sdhci_pci_runtime_pm_forbid(&pdev->dev); |
| 1515 | |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1516 | for (i = 0; i < chip->num_slots; i++) |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1517 | sdhci_pci_remove_slot(chip->slots[i]); |
| 1518 | |
| 1519 | pci_set_drvdata(pdev, NULL); |
| 1520 | kfree(chip); |
| 1521 | } |
| 1522 | |
| 1523 | pci_disable_device(pdev); |
| 1524 | } |
| 1525 | |
| 1526 | static struct pci_driver sdhci_driver = { |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1527 | .name = "sdhci-pci", |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1528 | .id_table = pci_ids, |
Ameya Palande | b177bc9 | 2011-04-05 21:13:13 +0300 | [diff] [blame] | 1529 | .probe = sdhci_pci_probe, |
Bill Pemberton | 0433c14 | 2012-11-19 13:20:26 -0500 | [diff] [blame] | 1530 | .remove = sdhci_pci_remove, |
Adrian Hunter | 66fd8ad | 2011-10-03 15:33:34 +0300 | [diff] [blame] | 1531 | .driver = { |
| 1532 | .pm = &sdhci_pci_pm_ops |
| 1533 | }, |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1534 | }; |
| 1535 | |
Sachin Kamat | acc6964 | 2012-08-27 11:57:02 +0530 | [diff] [blame] | 1536 | module_pci_driver(sdhci_driver); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1537 | |
Pierre Ossman | 32710e8 | 2009-04-08 20:14:54 +0200 | [diff] [blame] | 1538 | MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>"); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 1539 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver"); |
| 1540 | MODULE_LICENSE("GPL"); |