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