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