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