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