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