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