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