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