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 | |
| 22 | #include <linux/mmc/host.h> |
| 23 | |
| 24 | #include <asm/scatterlist.h> |
| 25 | #include <asm/io.h> |
| 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 | |
| 49 | int (*probe)(struct sdhci_pci_chip*); |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 50 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 51 | int (*probe_slot)(struct sdhci_pci_slot*); |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 52 | void (*remove_slot)(struct sdhci_pci_slot*, int); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 53 | |
| 54 | int (*suspend)(struct sdhci_pci_chip*, |
| 55 | pm_message_t); |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [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; |
| 64 | }; |
| 65 | |
| 66 | struct sdhci_pci_chip { |
| 67 | struct pci_dev *pdev; |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 68 | |
| 69 | unsigned int quirks; |
| 70 | const struct sdhci_pci_fixes *fixes; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 71 | |
| 72 | int num_slots; /* Slots on controller */ |
| 73 | struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */ |
| 74 | }; |
| 75 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 76 | |
| 77 | /*****************************************************************************\ |
| 78 | * * |
| 79 | * Hardware specific quirk handling * |
| 80 | * * |
| 81 | \*****************************************************************************/ |
| 82 | |
| 83 | static int ricoh_probe(struct sdhci_pci_chip *chip) |
| 84 | { |
Chris Ball | c99436f | 2009-09-22 16:45:22 -0700 | [diff] [blame] | 85 | if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG || |
| 86 | chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY) |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 87 | chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 90 | |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 91 | static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot) |
| 92 | { |
| 93 | slot->host->caps = |
| 94 | ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT) |
| 95 | & SDHCI_TIMEOUT_CLK_MASK) | |
| 96 | |
| 97 | ((0x21 << SDHCI_CLOCK_BASE_SHIFT) |
| 98 | & SDHCI_CLOCK_BASE_MASK) | |
| 99 | |
| 100 | SDHCI_TIMEOUT_CLK_UNIT | |
| 101 | SDHCI_CAN_VDD_330 | |
| 102 | SDHCI_CAN_DO_SDMA; |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int ricoh_mmc_resume(struct sdhci_pci_chip *chip) |
| 107 | { |
| 108 | /* Apply a delay to allow controller to settle */ |
| 109 | /* Otherwise it becomes confused if card state changed |
| 110 | during suspend */ |
| 111 | msleep(500); |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static const struct sdhci_pci_fixes sdhci_ricoh = { |
| 116 | .probe = ricoh_probe, |
Vasily Khoruzhick | 8493829 | 2010-03-05 13:43:46 -0800 | [diff] [blame] | 117 | .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | |
| 118 | SDHCI_QUIRK_FORCE_DMA | |
| 119 | SDHCI_QUIRK_CLOCK_BEFORE_RESET, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 122 | static const struct sdhci_pci_fixes sdhci_ricoh_mmc = { |
| 123 | .probe_slot = ricoh_mmc_probe_slot, |
| 124 | .resume = ricoh_mmc_resume, |
| 125 | .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | |
| 126 | SDHCI_QUIRK_CLOCK_BEFORE_RESET | |
| 127 | SDHCI_QUIRK_NO_CARD_NO_RESET | |
| 128 | SDHCI_QUIRK_MISSING_CAPS |
| 129 | }; |
| 130 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 131 | static const struct sdhci_pci_fixes sdhci_ene_712 = { |
| 132 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | |
| 133 | SDHCI_QUIRK_BROKEN_DMA, |
| 134 | }; |
| 135 | |
| 136 | static const struct sdhci_pci_fixes sdhci_ene_714 = { |
| 137 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | |
| 138 | SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS | |
| 139 | SDHCI_QUIRK_BROKEN_DMA, |
| 140 | }; |
| 141 | |
| 142 | static const struct sdhci_pci_fixes sdhci_cafe = { |
| 143 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | |
Andres Salomon | a087489 | 2009-03-02 21:48:20 +0100 | [diff] [blame] | 144 | SDHCI_QUIRK_NO_BUSY_IRQ | |
Pierre Ossman | ee53ab5 | 2008-07-05 00:25:15 +0200 | [diff] [blame] | 145 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 148 | static int jmicron_pmos(struct sdhci_pci_chip *chip, int on) |
| 149 | { |
| 150 | u8 scratch; |
| 151 | int ret; |
| 152 | |
| 153 | ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch); |
| 154 | if (ret) |
| 155 | return ret; |
| 156 | |
| 157 | /* |
| 158 | * Turn PMOS on [bit 0], set over current detection to 2.4 V |
| 159 | * [bit 1:2] and enable over current debouncing [bit 6]. |
| 160 | */ |
| 161 | if (on) |
| 162 | scratch |= 0x47; |
| 163 | else |
| 164 | scratch &= ~0x47; |
| 165 | |
| 166 | ret = pci_write_config_byte(chip->pdev, 0xAE, scratch); |
| 167 | if (ret) |
| 168 | return ret; |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static int jmicron_probe(struct sdhci_pci_chip *chip) |
| 174 | { |
| 175 | int ret; |
| 176 | |
Pierre Ossman | 93fc48c | 2008-06-28 18:21:41 +0200 | [diff] [blame] | 177 | if (chip->pdev->revision == 0) { |
| 178 | chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR | |
| 179 | SDHCI_QUIRK_32BIT_DMA_SIZE | |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 180 | SDHCI_QUIRK_32BIT_ADMA_SIZE | |
Pierre Ossman | 4a3cba3 | 2008-07-29 00:11:16 +0200 | [diff] [blame] | 181 | SDHCI_QUIRK_RESET_AFTER_REQUEST | |
Pierre Ossman | 86a6a87 | 2009-02-02 21:13:49 +0100 | [diff] [blame] | 182 | SDHCI_QUIRK_BROKEN_SMALL_PIO; |
Pierre Ossman | 93fc48c | 2008-06-28 18:21:41 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 185 | /* |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 186 | * JMicron chips can have two interfaces to the same hardware |
| 187 | * in order to work around limitations in Microsoft's driver. |
| 188 | * We need to make sure we only bind to one of them. |
| 189 | * |
| 190 | * This code assumes two things: |
| 191 | * |
| 192 | * 1. The PCI code adds subfunctions in order. |
| 193 | * |
| 194 | * 2. The MMC interface has a lower subfunction number |
| 195 | * than the SD interface. |
| 196 | */ |
| 197 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) { |
| 198 | struct pci_dev *sd_dev; |
| 199 | |
| 200 | sd_dev = NULL; |
| 201 | while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON, |
| 202 | PCI_DEVICE_ID_JMICRON_JMB38X_MMC, sd_dev)) != NULL) { |
| 203 | if ((PCI_SLOT(chip->pdev->devfn) == |
| 204 | PCI_SLOT(sd_dev->devfn)) && |
| 205 | (chip->pdev->bus == sd_dev->bus)) |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | if (sd_dev) { |
| 210 | pci_dev_put(sd_dev); |
| 211 | dev_info(&chip->pdev->dev, "Refusing to bind to " |
| 212 | "secondary interface.\n"); |
| 213 | return -ENODEV; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /* |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 218 | * JMicron chips need a bit of a nudge to enable the power |
| 219 | * output pins. |
| 220 | */ |
| 221 | ret = jmicron_pmos(chip, 1); |
| 222 | if (ret) { |
| 223 | dev_err(&chip->pdev->dev, "Failure enabling card power\n"); |
| 224 | return ret; |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 230 | static void jmicron_enable_mmc(struct sdhci_host *host, int on) |
| 231 | { |
| 232 | u8 scratch; |
| 233 | |
| 234 | scratch = readb(host->ioaddr + 0xC0); |
| 235 | |
| 236 | if (on) |
| 237 | scratch |= 0x01; |
| 238 | else |
| 239 | scratch &= ~0x01; |
| 240 | |
| 241 | writeb(scratch, host->ioaddr + 0xC0); |
| 242 | } |
| 243 | |
| 244 | static int jmicron_probe_slot(struct sdhci_pci_slot *slot) |
| 245 | { |
Pierre Ossman | 2134a92 | 2008-06-28 18:28:51 +0200 | [diff] [blame] | 246 | if (slot->chip->pdev->revision == 0) { |
| 247 | u16 version; |
| 248 | |
| 249 | version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION); |
| 250 | version = (version & SDHCI_VENDOR_VER_MASK) >> |
| 251 | SDHCI_VENDOR_VER_SHIFT; |
| 252 | |
| 253 | /* |
| 254 | * Older versions of the chip have lots of nasty glitches |
| 255 | * in the ADMA engine. It's best just to avoid it |
| 256 | * completely. |
| 257 | */ |
| 258 | if (version < 0xAC) |
| 259 | slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; |
| 260 | } |
| 261 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 262 | /* |
| 263 | * The secondary interface requires a bit set to get the |
| 264 | * interrupts. |
| 265 | */ |
| 266 | if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) |
| 267 | jmicron_enable_mmc(slot->host, 1); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 272 | static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 273 | { |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 274 | if (dead) |
| 275 | return; |
| 276 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 277 | if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) |
| 278 | jmicron_enable_mmc(slot->host, 0); |
| 279 | } |
| 280 | |
| 281 | static int jmicron_suspend(struct sdhci_pci_chip *chip, pm_message_t state) |
| 282 | { |
| 283 | int i; |
| 284 | |
| 285 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) { |
| 286 | for (i = 0;i < chip->num_slots;i++) |
| 287 | jmicron_enable_mmc(chip->slots[i]->host, 0); |
| 288 | } |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 293 | static int jmicron_resume(struct sdhci_pci_chip *chip) |
| 294 | { |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 295 | int ret, i; |
| 296 | |
| 297 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) { |
| 298 | for (i = 0;i < chip->num_slots;i++) |
| 299 | jmicron_enable_mmc(chip->slots[i]->host, 1); |
| 300 | } |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 301 | |
| 302 | ret = jmicron_pmos(chip, 1); |
| 303 | if (ret) { |
| 304 | dev_err(&chip->pdev->dev, "Failure enabling card power\n"); |
| 305 | return ret; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 311 | static const struct sdhci_pci_fixes sdhci_jmicron = { |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 312 | .probe = jmicron_probe, |
| 313 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 314 | .probe_slot = jmicron_probe_slot, |
| 315 | .remove_slot = jmicron_remove_slot, |
| 316 | |
| 317 | .suspend = jmicron_suspend, |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 318 | .resume = jmicron_resume, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 319 | }; |
| 320 | |
Nicolas Pitre | a7a6186 | 2009-12-14 18:01:26 -0800 | [diff] [blame] | 321 | /* SysKonnect CardBus2SDIO extra registers */ |
| 322 | #define SYSKT_CTRL 0x200 |
| 323 | #define SYSKT_RDFIFO_STAT 0x204 |
| 324 | #define SYSKT_WRFIFO_STAT 0x208 |
| 325 | #define SYSKT_POWER_DATA 0x20c |
| 326 | #define SYSKT_POWER_330 0xef |
| 327 | #define SYSKT_POWER_300 0xf8 |
| 328 | #define SYSKT_POWER_184 0xcc |
| 329 | #define SYSKT_POWER_CMD 0x20d |
| 330 | #define SYSKT_POWER_START (1 << 7) |
| 331 | #define SYSKT_POWER_STATUS 0x20e |
| 332 | #define SYSKT_POWER_STATUS_OK (1 << 0) |
| 333 | #define SYSKT_BOARD_REV 0x210 |
| 334 | #define SYSKT_CHIP_REV 0x211 |
| 335 | #define SYSKT_CONF_DATA 0x212 |
| 336 | #define SYSKT_CONF_DATA_1V8 (1 << 2) |
| 337 | #define SYSKT_CONF_DATA_2V5 (1 << 1) |
| 338 | #define SYSKT_CONF_DATA_3V3 (1 << 0) |
| 339 | |
| 340 | static int syskt_probe(struct sdhci_pci_chip *chip) |
| 341 | { |
| 342 | if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { |
| 343 | chip->pdev->class &= ~0x0000FF; |
| 344 | chip->pdev->class |= PCI_SDHCI_IFDMA; |
| 345 | } |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static int syskt_probe_slot(struct sdhci_pci_slot *slot) |
| 350 | { |
| 351 | int tm, ps; |
| 352 | |
| 353 | u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV); |
| 354 | u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV); |
| 355 | dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, " |
| 356 | "board rev %d.%d, chip rev %d.%d\n", |
| 357 | board_rev >> 4, board_rev & 0xf, |
| 358 | chip_rev >> 4, chip_rev & 0xf); |
| 359 | if (chip_rev >= 0x20) |
| 360 | slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA; |
| 361 | |
| 362 | writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA); |
| 363 | writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD); |
| 364 | udelay(50); |
| 365 | tm = 10; /* Wait max 1 ms */ |
| 366 | do { |
| 367 | ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS); |
| 368 | if (ps & SYSKT_POWER_STATUS_OK) |
| 369 | break; |
| 370 | udelay(100); |
| 371 | } while (--tm); |
| 372 | if (!tm) { |
| 373 | dev_err(&slot->chip->pdev->dev, |
| 374 | "power regulator never stabilized"); |
| 375 | writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD); |
| 376 | return -ENODEV; |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static const struct sdhci_pci_fixes sdhci_syskt = { |
| 383 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER, |
| 384 | .probe = syskt_probe, |
| 385 | .probe_slot = syskt_probe_slot, |
| 386 | }; |
| 387 | |
Harald Welte | 557b069 | 2009-06-18 16:53:38 +0200 | [diff] [blame] | 388 | static int via_probe(struct sdhci_pci_chip *chip) |
| 389 | { |
| 390 | if (chip->pdev->revision == 0x10) |
| 391 | chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER; |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static const struct sdhci_pci_fixes sdhci_via = { |
| 397 | .probe = via_probe, |
| 398 | }; |
| 399 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 400 | static const struct pci_device_id pci_ids[] __devinitdata = { |
| 401 | { |
| 402 | .vendor = PCI_VENDOR_ID_RICOH, |
| 403 | .device = PCI_DEVICE_ID_RICOH_R5C822, |
| 404 | .subvendor = PCI_ANY_ID, |
| 405 | .subdevice = PCI_ANY_ID, |
| 406 | .driver_data = (kernel_ulong_t)&sdhci_ricoh, |
| 407 | }, |
| 408 | |
| 409 | { |
Maxim Levitsky | ccc92c2 | 2010-08-10 18:01:42 -0700 | [diff] [blame] | 410 | .vendor = PCI_VENDOR_ID_RICOH, |
| 411 | .device = 0x843, |
| 412 | .subvendor = PCI_ANY_ID, |
| 413 | .subdevice = PCI_ANY_ID, |
| 414 | .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, |
| 415 | }, |
| 416 | |
| 417 | { |
Pablo Castillo | 568133e | 2010-08-10 18:02:01 -0700 | [diff] [blame] | 418 | .vendor = PCI_VENDOR_ID_RICOH, |
| 419 | .device = 0xe822, |
| 420 | .subvendor = PCI_ANY_ID, |
| 421 | .subdevice = PCI_ANY_ID, |
| 422 | .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, |
| 423 | }, |
| 424 | |
| 425 | { |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 426 | .vendor = PCI_VENDOR_ID_ENE, |
| 427 | .device = PCI_DEVICE_ID_ENE_CB712_SD, |
| 428 | .subvendor = PCI_ANY_ID, |
| 429 | .subdevice = PCI_ANY_ID, |
| 430 | .driver_data = (kernel_ulong_t)&sdhci_ene_712, |
| 431 | }, |
| 432 | |
| 433 | { |
| 434 | .vendor = PCI_VENDOR_ID_ENE, |
| 435 | .device = PCI_DEVICE_ID_ENE_CB712_SD_2, |
| 436 | .subvendor = PCI_ANY_ID, |
| 437 | .subdevice = PCI_ANY_ID, |
| 438 | .driver_data = (kernel_ulong_t)&sdhci_ene_712, |
| 439 | }, |
| 440 | |
| 441 | { |
| 442 | .vendor = PCI_VENDOR_ID_ENE, |
| 443 | .device = PCI_DEVICE_ID_ENE_CB714_SD, |
| 444 | .subvendor = PCI_ANY_ID, |
| 445 | .subdevice = PCI_ANY_ID, |
| 446 | .driver_data = (kernel_ulong_t)&sdhci_ene_714, |
| 447 | }, |
| 448 | |
| 449 | { |
| 450 | .vendor = PCI_VENDOR_ID_ENE, |
| 451 | .device = PCI_DEVICE_ID_ENE_CB714_SD_2, |
| 452 | .subvendor = PCI_ANY_ID, |
| 453 | .subdevice = PCI_ANY_ID, |
| 454 | .driver_data = (kernel_ulong_t)&sdhci_ene_714, |
| 455 | }, |
| 456 | |
| 457 | { |
| 458 | .vendor = PCI_VENDOR_ID_MARVELL, |
David Woodhouse | 8c5eb88 | 2008-09-03 09:45:57 +0100 | [diff] [blame] | 459 | .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD, |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 460 | .subvendor = PCI_ANY_ID, |
| 461 | .subdevice = PCI_ANY_ID, |
| 462 | .driver_data = (kernel_ulong_t)&sdhci_cafe, |
| 463 | }, |
| 464 | |
| 465 | { |
| 466 | .vendor = PCI_VENDOR_ID_JMICRON, |
| 467 | .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD, |
| 468 | .subvendor = PCI_ANY_ID, |
| 469 | .subdevice = PCI_ANY_ID, |
| 470 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, |
| 471 | }, |
| 472 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 473 | { |
| 474 | .vendor = PCI_VENDOR_ID_JMICRON, |
| 475 | .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC, |
| 476 | .subvendor = PCI_ANY_ID, |
| 477 | .subdevice = PCI_ANY_ID, |
| 478 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, |
| 479 | }, |
| 480 | |
Harald Welte | 557b069 | 2009-06-18 16:53:38 +0200 | [diff] [blame] | 481 | { |
Nicolas Pitre | a7a6186 | 2009-12-14 18:01:26 -0800 | [diff] [blame] | 482 | .vendor = PCI_VENDOR_ID_SYSKONNECT, |
| 483 | .device = 0x8000, |
| 484 | .subvendor = PCI_ANY_ID, |
| 485 | .subdevice = PCI_ANY_ID, |
| 486 | .driver_data = (kernel_ulong_t)&sdhci_syskt, |
| 487 | }, |
| 488 | |
| 489 | { |
Harald Welte | 557b069 | 2009-06-18 16:53:38 +0200 | [diff] [blame] | 490 | .vendor = PCI_VENDOR_ID_VIA, |
| 491 | .device = 0x95d0, |
| 492 | .subvendor = PCI_ANY_ID, |
| 493 | .subdevice = PCI_ANY_ID, |
| 494 | .driver_data = (kernel_ulong_t)&sdhci_via, |
| 495 | }, |
| 496 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 497 | { /* Generic SD host controller */ |
| 498 | PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) |
| 499 | }, |
| 500 | |
| 501 | { /* end: all zeroes */ }, |
| 502 | }; |
| 503 | |
| 504 | MODULE_DEVICE_TABLE(pci, pci_ids); |
| 505 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 506 | /*****************************************************************************\ |
| 507 | * * |
| 508 | * SDHCI core callbacks * |
| 509 | * * |
| 510 | \*****************************************************************************/ |
| 511 | |
| 512 | static int sdhci_pci_enable_dma(struct sdhci_host *host) |
| 513 | { |
| 514 | struct sdhci_pci_slot *slot; |
| 515 | struct pci_dev *pdev; |
| 516 | int ret; |
| 517 | |
| 518 | slot = sdhci_priv(host); |
| 519 | pdev = slot->chip->pdev; |
| 520 | |
| 521 | if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) && |
| 522 | ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) && |
Richard Röjfors | a13abc7 | 2009-09-22 16:45:30 -0700 | [diff] [blame] | 523 | (host->flags & SDHCI_USE_SDMA)) { |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 524 | dev_warn(&pdev->dev, "Will use DMA mode even though HW " |
| 525 | "doesn't fully claim to support it.\n"); |
| 526 | } |
| 527 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 528 | ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 529 | if (ret) |
| 530 | return ret; |
| 531 | |
| 532 | pci_set_master(pdev); |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static struct sdhci_ops sdhci_pci_ops = { |
| 538 | .enable_dma = sdhci_pci_enable_dma, |
| 539 | }; |
| 540 | |
| 541 | /*****************************************************************************\ |
| 542 | * * |
| 543 | * Suspend/resume * |
| 544 | * * |
| 545 | \*****************************************************************************/ |
| 546 | |
| 547 | #ifdef CONFIG_PM |
| 548 | |
| 549 | static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state) |
| 550 | { |
| 551 | struct sdhci_pci_chip *chip; |
| 552 | struct sdhci_pci_slot *slot; |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 553 | mmc_pm_flag_t pm_flags = 0; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 554 | int i, ret; |
| 555 | |
| 556 | chip = pci_get_drvdata(pdev); |
| 557 | if (!chip) |
| 558 | return 0; |
| 559 | |
| 560 | for (i = 0;i < chip->num_slots;i++) { |
| 561 | slot = chip->slots[i]; |
| 562 | if (!slot) |
| 563 | continue; |
| 564 | |
| 565 | ret = sdhci_suspend_host(slot->host, state); |
| 566 | |
| 567 | if (ret) { |
| 568 | for (i--;i >= 0;i--) |
| 569 | sdhci_resume_host(chip->slots[i]->host); |
| 570 | return ret; |
| 571 | } |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 572 | |
| 573 | pm_flags |= slot->host->mmc->pm_flags; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 574 | } |
| 575 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 576 | if (chip->fixes && chip->fixes->suspend) { |
| 577 | ret = chip->fixes->suspend(chip, state); |
| 578 | if (ret) { |
| 579 | for (i = chip->num_slots - 1;i >= 0;i--) |
| 580 | sdhci_resume_host(chip->slots[i]->host); |
| 581 | return ret; |
| 582 | } |
| 583 | } |
| 584 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 585 | pci_save_state(pdev); |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 586 | if (pm_flags & MMC_PM_KEEP_POWER) { |
| 587 | if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) |
| 588 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 589 | pci_set_power_state(pdev, PCI_D3hot); |
| 590 | } else { |
| 591 | pci_enable_wake(pdev, pci_choose_state(pdev, state), 0); |
| 592 | pci_disable_device(pdev); |
| 593 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 594 | } |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | static int sdhci_pci_resume (struct pci_dev *pdev) |
| 600 | { |
| 601 | struct sdhci_pci_chip *chip; |
| 602 | struct sdhci_pci_slot *slot; |
| 603 | int i, ret; |
| 604 | |
| 605 | chip = pci_get_drvdata(pdev); |
| 606 | if (!chip) |
| 607 | return 0; |
| 608 | |
| 609 | pci_set_power_state(pdev, PCI_D0); |
| 610 | pci_restore_state(pdev); |
| 611 | ret = pci_enable_device(pdev); |
| 612 | if (ret) |
| 613 | return ret; |
| 614 | |
Pierre Ossman | 45211e2 | 2008-03-24 13:09:09 +0100 | [diff] [blame] | 615 | if (chip->fixes && chip->fixes->resume) { |
| 616 | ret = chip->fixes->resume(chip); |
| 617 | if (ret) |
| 618 | return ret; |
| 619 | } |
| 620 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 621 | for (i = 0;i < chip->num_slots;i++) { |
| 622 | slot = chip->slots[i]; |
| 623 | if (!slot) |
| 624 | continue; |
| 625 | |
| 626 | ret = sdhci_resume_host(slot->host); |
| 627 | if (ret) |
| 628 | return ret; |
| 629 | } |
| 630 | |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | #else /* CONFIG_PM */ |
| 635 | |
| 636 | #define sdhci_pci_suspend NULL |
| 637 | #define sdhci_pci_resume NULL |
| 638 | |
| 639 | #endif /* CONFIG_PM */ |
| 640 | |
| 641 | /*****************************************************************************\ |
| 642 | * * |
| 643 | * Device probing/removal * |
| 644 | * * |
| 645 | \*****************************************************************************/ |
| 646 | |
| 647 | static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot( |
| 648 | struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar) |
| 649 | { |
| 650 | struct sdhci_pci_slot *slot; |
| 651 | struct sdhci_host *host; |
| 652 | |
| 653 | resource_size_t addr; |
| 654 | |
| 655 | int ret; |
| 656 | |
| 657 | if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { |
| 658 | dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar); |
| 659 | return ERR_PTR(-ENODEV); |
| 660 | } |
| 661 | |
| 662 | if (pci_resource_len(pdev, bar) != 0x100) { |
| 663 | dev_err(&pdev->dev, "Invalid iomem size. You may " |
| 664 | "experience problems.\n"); |
| 665 | } |
| 666 | |
| 667 | if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { |
| 668 | dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n"); |
| 669 | return ERR_PTR(-ENODEV); |
| 670 | } |
| 671 | |
| 672 | if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) { |
| 673 | dev_err(&pdev->dev, "Unknown interface. Aborting.\n"); |
| 674 | return ERR_PTR(-ENODEV); |
| 675 | } |
| 676 | |
| 677 | host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot)); |
| 678 | if (IS_ERR(host)) { |
Dan Carpenter | c60a32c | 2009-04-10 23:31:10 +0200 | [diff] [blame] | 679 | dev_err(&pdev->dev, "cannot allocate host\n"); |
Julia Lawall | dc0fd7b | 2010-05-26 14:42:11 -0700 | [diff] [blame] | 680 | return ERR_CAST(host); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | slot = sdhci_priv(host); |
| 684 | |
| 685 | slot->chip = chip; |
| 686 | slot->host = host; |
| 687 | slot->pci_bar = bar; |
| 688 | |
| 689 | host->hw_name = "PCI"; |
| 690 | host->ops = &sdhci_pci_ops; |
| 691 | host->quirks = chip->quirks; |
| 692 | |
| 693 | host->irq = pdev->irq; |
| 694 | |
| 695 | ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc)); |
| 696 | if (ret) { |
| 697 | dev_err(&pdev->dev, "cannot request region\n"); |
Dan Carpenter | c60a32c | 2009-04-10 23:31:10 +0200 | [diff] [blame] | 698 | goto free; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | addr = pci_resource_start(pdev, bar); |
Arjan van de Ven | 092f82e | 2008-09-28 16:15:56 -0700 | [diff] [blame] | 702 | host->ioaddr = pci_ioremap_bar(pdev, bar); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 703 | if (!host->ioaddr) { |
| 704 | dev_err(&pdev->dev, "failed to remap registers\n"); |
| 705 | goto release; |
| 706 | } |
| 707 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 708 | if (chip->fixes && chip->fixes->probe_slot) { |
| 709 | ret = chip->fixes->probe_slot(slot); |
| 710 | if (ret) |
| 711 | goto unmap; |
| 712 | } |
| 713 | |
Nicolas Pitre | 2f4cbb3 | 2010-03-05 13:43:32 -0800 | [diff] [blame] | 714 | host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ; |
| 715 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 716 | ret = sdhci_add_host(host); |
| 717 | if (ret) |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 718 | goto remove; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 719 | |
| 720 | return slot; |
| 721 | |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 722 | remove: |
| 723 | if (chip->fixes && chip->fixes->remove_slot) |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 724 | chip->fixes->remove_slot(slot, 0); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 725 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 726 | unmap: |
| 727 | iounmap(host->ioaddr); |
| 728 | |
| 729 | release: |
| 730 | pci_release_region(pdev, bar); |
Dan Carpenter | c60a32c | 2009-04-10 23:31:10 +0200 | [diff] [blame] | 731 | |
| 732 | free: |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 733 | sdhci_free_host(host); |
| 734 | |
| 735 | return ERR_PTR(ret); |
| 736 | } |
| 737 | |
| 738 | static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot) |
| 739 | { |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 740 | int dead; |
| 741 | u32 scratch; |
| 742 | |
| 743 | dead = 0; |
| 744 | scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS); |
| 745 | if (scratch == (u32)-1) |
| 746 | dead = 1; |
| 747 | |
| 748 | sdhci_remove_host(slot->host, dead); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 749 | |
| 750 | if (slot->chip->fixes && slot->chip->fixes->remove_slot) |
Pierre Ossman | 1e72859 | 2008-04-16 19:13:13 +0200 | [diff] [blame] | 751 | slot->chip->fixes->remove_slot(slot, dead); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 752 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 753 | pci_release_region(slot->chip->pdev, slot->pci_bar); |
Pierre Ossman | 4489428 | 2008-04-04 19:36:59 +0200 | [diff] [blame] | 754 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 755 | sdhci_free_host(slot->host); |
| 756 | } |
| 757 | |
| 758 | static int __devinit sdhci_pci_probe(struct pci_dev *pdev, |
| 759 | const struct pci_device_id *ent) |
| 760 | { |
| 761 | struct sdhci_pci_chip *chip; |
| 762 | struct sdhci_pci_slot *slot; |
| 763 | |
| 764 | u8 slots, rev, first_bar; |
| 765 | int ret, i; |
| 766 | |
| 767 | BUG_ON(pdev == NULL); |
| 768 | BUG_ON(ent == NULL); |
| 769 | |
| 770 | pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev); |
| 771 | |
| 772 | dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n", |
| 773 | (int)pdev->vendor, (int)pdev->device, (int)rev); |
| 774 | |
| 775 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots); |
| 776 | if (ret) |
| 777 | return ret; |
| 778 | |
| 779 | slots = PCI_SLOT_INFO_SLOTS(slots) + 1; |
| 780 | dev_dbg(&pdev->dev, "found %d slot(s)\n", slots); |
| 781 | if (slots == 0) |
| 782 | return -ENODEV; |
| 783 | |
| 784 | BUG_ON(slots > MAX_SLOTS); |
| 785 | |
| 786 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar); |
| 787 | if (ret) |
| 788 | return ret; |
| 789 | |
| 790 | first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK; |
| 791 | |
| 792 | if (first_bar > 5) { |
| 793 | dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n"); |
| 794 | return -ENODEV; |
| 795 | } |
| 796 | |
| 797 | ret = pci_enable_device(pdev); |
| 798 | if (ret) |
| 799 | return ret; |
| 800 | |
| 801 | chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL); |
| 802 | if (!chip) { |
| 803 | ret = -ENOMEM; |
| 804 | goto err; |
| 805 | } |
| 806 | |
| 807 | chip->pdev = pdev; |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 808 | chip->fixes = (const struct sdhci_pci_fixes*)ent->driver_data; |
| 809 | if (chip->fixes) |
| 810 | chip->quirks = chip->fixes->quirks; |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 811 | chip->num_slots = slots; |
| 812 | |
| 813 | pci_set_drvdata(pdev, chip); |
| 814 | |
Pierre Ossman | 2260640 | 2008-03-23 19:33:23 +0100 | [diff] [blame] | 815 | if (chip->fixes && chip->fixes->probe) { |
| 816 | ret = chip->fixes->probe(chip); |
| 817 | if (ret) |
| 818 | goto free; |
| 819 | } |
| 820 | |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 821 | for (i = 0;i < slots;i++) { |
| 822 | slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i); |
| 823 | if (IS_ERR(slot)) { |
| 824 | for (i--;i >= 0;i--) |
| 825 | sdhci_pci_remove_slot(chip->slots[i]); |
| 826 | ret = PTR_ERR(slot); |
| 827 | goto free; |
| 828 | } |
| 829 | |
| 830 | chip->slots[i] = slot; |
| 831 | } |
| 832 | |
| 833 | return 0; |
| 834 | |
| 835 | free: |
| 836 | pci_set_drvdata(pdev, NULL); |
| 837 | kfree(chip); |
| 838 | |
| 839 | err: |
| 840 | pci_disable_device(pdev); |
| 841 | return ret; |
| 842 | } |
| 843 | |
| 844 | static void __devexit sdhci_pci_remove(struct pci_dev *pdev) |
| 845 | { |
| 846 | int i; |
| 847 | struct sdhci_pci_chip *chip; |
| 848 | |
| 849 | chip = pci_get_drvdata(pdev); |
| 850 | |
| 851 | if (chip) { |
| 852 | for (i = 0;i < chip->num_slots; i++) |
| 853 | sdhci_pci_remove_slot(chip->slots[i]); |
| 854 | |
| 855 | pci_set_drvdata(pdev, NULL); |
| 856 | kfree(chip); |
| 857 | } |
| 858 | |
| 859 | pci_disable_device(pdev); |
| 860 | } |
| 861 | |
| 862 | static struct pci_driver sdhci_driver = { |
| 863 | .name = "sdhci-pci", |
| 864 | .id_table = pci_ids, |
| 865 | .probe = sdhci_pci_probe, |
| 866 | .remove = __devexit_p(sdhci_pci_remove), |
| 867 | .suspend = sdhci_pci_suspend, |
| 868 | .resume = sdhci_pci_resume, |
| 869 | }; |
| 870 | |
| 871 | /*****************************************************************************\ |
| 872 | * * |
| 873 | * Driver init/exit * |
| 874 | * * |
| 875 | \*****************************************************************************/ |
| 876 | |
| 877 | static int __init sdhci_drv_init(void) |
| 878 | { |
| 879 | return pci_register_driver(&sdhci_driver); |
| 880 | } |
| 881 | |
| 882 | static void __exit sdhci_drv_exit(void) |
| 883 | { |
| 884 | pci_unregister_driver(&sdhci_driver); |
| 885 | } |
| 886 | |
| 887 | module_init(sdhci_drv_init); |
| 888 | module_exit(sdhci_drv_exit); |
| 889 | |
Pierre Ossman | 32710e8 | 2009-04-08 20:14:54 +0200 | [diff] [blame] | 890 | MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>"); |
Pierre Ossman | b8c86fc | 2008-03-18 17:35:49 +0100 | [diff] [blame] | 891 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver"); |
| 892 | MODULE_LICENSE("GPL"); |