blob: 3cb9abf67d82283f75d3a103f34773fcbd8deaf6 [file] [log] [blame]
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001/* 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 Gortmaker88b47672011-07-03 15:15:51 -040017#include <linux/module.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010018#include <linux/pci.h>
19#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Maxim Levitskyccc92c22010-08-10 18:01:42 -070021#include <linux/device.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010022#include <linux/mmc/host.h>
Ameya Palandeb177bc92011-04-05 21:13:13 +030023#include <linux/scatterlist.h>
24#include <linux/io.h>
Adrian Hunter0f201652011-08-29 16:42:13 +030025#include <linux/gpio.h>
Adrian Hunter66fd8ad2011-10-03 15:33:34 +030026#include <linux/pm_runtime.h>
Adrian Hunter52c506f2011-12-27 15:48:43 +020027#include <linux/mmc/sdhci-pci-data.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010028
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 Ossmanb8c86fc2008-03-18 17:35:49 +010045struct sdhci_pci_chip;
Pierre Ossman44894282008-04-04 19:36:59 +020046struct sdhci_pci_slot;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010047
Pierre Ossman22606402008-03-23 19:33:23 +010048struct sdhci_pci_fixes {
49 unsigned int quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +020050 unsigned int quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +030051 bool allow_runtime_pm;
Pierre Ossman22606402008-03-23 19:33:23 +010052
Ameya Palandeb177bc92011-04-05 21:13:13 +030053 int (*probe) (struct sdhci_pci_chip *);
Pierre Ossman45211e22008-03-24 13:09:09 +010054
Ameya Palandeb177bc92011-04-05 21:13:13 +030055 int (*probe_slot) (struct sdhci_pci_slot *);
56 void (*remove_slot) (struct sdhci_pci_slot *, int);
Pierre Ossman44894282008-04-04 19:36:59 +020057
Manuel Lauss29495aa2011-11-03 11:09:45 +010058 int (*suspend) (struct sdhci_pci_chip *);
Ameya Palandeb177bc92011-04-05 21:13:13 +030059 int (*resume) (struct sdhci_pci_chip *);
Pierre Ossman22606402008-03-23 19:33:23 +010060};
61
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010062struct sdhci_pci_slot {
63 struct sdhci_pci_chip *chip;
64 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +020065 struct sdhci_pci_data *data;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010066
67 int pci_bar;
Adrian Hunter0f201652011-08-29 16:42:13 +030068 int rst_n_gpio;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +030069 int cd_gpio;
70 int cd_irq;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010071};
72
73struct sdhci_pci_chip {
74 struct pci_dev *pdev;
Pierre Ossman22606402008-03-23 19:33:23 +010075
76 unsigned int quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +020077 unsigned int quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +030078 bool allow_runtime_pm;
Pierre Ossman22606402008-03-23 19:33:23 +010079 const struct sdhci_pci_fixes *fixes;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010080
81 int num_slots; /* Slots on controller */
82 struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
83};
84
Pierre Ossman22606402008-03-23 19:33:23 +010085
86/*****************************************************************************\
87 * *
88 * Hardware specific quirk handling *
89 * *
90\*****************************************************************************/
91
92static int ricoh_probe(struct sdhci_pci_chip *chip)
93{
Chris Ballc99436f2009-09-22 16:45:22 -070094 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
95 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
Pierre Ossman22606402008-03-23 19:33:23 +010096 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
Maxim Levitskyccc92c22010-08-10 18:01:42 -070097 return 0;
98}
Pierre Ossman22606402008-03-23 19:33:23 +010099
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700100static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
101{
102 slot->host->caps =
103 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
104 & SDHCI_TIMEOUT_CLK_MASK) |
105
106 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
107 & SDHCI_CLOCK_BASE_MASK) |
108
109 SDHCI_TIMEOUT_CLK_UNIT |
110 SDHCI_CAN_VDD_330 |
111 SDHCI_CAN_DO_SDMA;
112 return 0;
113}
114
115static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
116{
117 /* Apply a delay to allow controller to settle */
118 /* Otherwise it becomes confused if card state changed
119 during suspend */
120 msleep(500);
Pierre Ossman22606402008-03-23 19:33:23 +0100121 return 0;
122}
123
124static const struct sdhci_pci_fixes sdhci_ricoh = {
125 .probe = ricoh_probe,
Vasily Khoruzhick84938292010-03-05 13:43:46 -0800126 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
127 SDHCI_QUIRK_FORCE_DMA |
128 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
Pierre Ossman22606402008-03-23 19:33:23 +0100129};
130
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700131static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
132 .probe_slot = ricoh_mmc_probe_slot,
133 .resume = ricoh_mmc_resume,
134 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
135 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
136 SDHCI_QUIRK_NO_CARD_NO_RESET |
137 SDHCI_QUIRK_MISSING_CAPS
138};
139
Pierre Ossman22606402008-03-23 19:33:23 +0100140static const struct sdhci_pci_fixes sdhci_ene_712 = {
141 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
142 SDHCI_QUIRK_BROKEN_DMA,
143};
144
145static const struct sdhci_pci_fixes sdhci_ene_714 = {
146 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
147 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
148 SDHCI_QUIRK_BROKEN_DMA,
149};
150
151static const struct sdhci_pci_fixes sdhci_cafe = {
152 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
Andres Salomona0874892009-03-02 21:48:20 +0100153 SDHCI_QUIRK_NO_BUSY_IRQ |
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200154 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
Pierre Ossman22606402008-03-23 19:33:23 +0100155};
156
Major Lee68077b02011-06-29 14:23:46 +0300157static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
158{
159 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
160 return 0;
161}
162
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100163/*
164 * ADMA operation is disabled for Moorestown platform due to
165 * hardware bugs.
166 */
Jacob Pan35ac6f02010-11-09 13:57:29 +0000167static int mrst_hc_probe(struct sdhci_pci_chip *chip)
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100168{
169 /*
Jacob Pan35ac6f02010-11-09 13:57:29 +0000170 * slots number is fixed here for MRST as SDIO3/5 are never used and
171 * have hardware bugs.
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100172 */
173 chip->num_slots = 1;
174 return 0;
175}
176
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300177#ifdef CONFIG_PM_RUNTIME
178
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200179static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300180{
181 struct sdhci_pci_slot *slot = dev_id;
182 struct sdhci_host *host = slot->host;
183
184 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
185 return IRQ_HANDLED;
186}
187
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200188static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300189{
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200190 int err, irq, gpio = slot->cd_gpio;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300191
192 slot->cd_gpio = -EINVAL;
193 slot->cd_irq = -EINVAL;
194
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200195 if (!gpio_is_valid(gpio))
196 return;
197
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300198 err = gpio_request(gpio, "sd_cd");
199 if (err < 0)
200 goto out;
201
202 err = gpio_direction_input(gpio);
203 if (err < 0)
204 goto out_free;
205
206 irq = gpio_to_irq(gpio);
207 if (irq < 0)
208 goto out_free;
209
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200210 err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300211 IRQF_TRIGGER_FALLING, "sd_cd", slot);
212 if (err)
213 goto out_free;
214
215 slot->cd_gpio = gpio;
216 slot->cd_irq = irq;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300217
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200218 return;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300219
220out_free:
221 gpio_free(gpio);
222out:
223 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300224}
225
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200226static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300227{
228 if (slot->cd_irq >= 0)
229 free_irq(slot->cd_irq, slot);
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200230 if (gpio_is_valid(slot->cd_gpio))
231 gpio_free(slot->cd_gpio);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300232}
233
234#else
235
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200236static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
237{
238}
239
240static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
241{
242}
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300243
244#endif
245
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300246static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
247{
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300248 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
Adrian Hunterda721cf2012-02-07 14:48:53 +0200249 slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
250 MMC_CAP2_HC_ERASE_SZ;
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300251 return 0;
252}
253
Adrian Hunter93933502011-12-27 15:48:47 +0200254static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
255{
Adrian Hunter012e4672012-01-30 14:27:18 +0200256 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
Adrian Hunter93933502011-12-27 15:48:47 +0200257 return 0;
258}
259
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100260static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
261 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Major Lee68077b02011-06-29 14:23:46 +0300262 .probe_slot = mrst_hc_probe_slot,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100263};
264
Jacob Pan35ac6f02010-11-09 13:57:29 +0000265static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100266 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000267 .probe = mrst_hc_probe,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100268};
269
Xiaochen Shen29229052010-10-04 15:24:52 +0100270static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
271 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300272 .allow_runtime_pm = true,
Xiaochen Shen29229052010-10-04 15:24:52 +0100273};
274
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300275static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
Xiaochen Shen29229052010-10-04 15:24:52 +0100276 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterf3c55a72012-02-07 14:48:55 +0200277 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300278 .allow_runtime_pm = true,
Adrian Hunter93933502011-12-27 15:48:47 +0200279 .probe_slot = mfd_sdio_probe_slot,
Xiaochen Shen29229052010-10-04 15:24:52 +0100280};
281
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300282static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
283 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300284 .allow_runtime_pm = true,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300285 .probe_slot = mfd_emmc_probe_slot,
286};
287
Jennifer Li26daa1e2010-11-17 23:01:59 -0500288/* O2Micro extra registers */
289#define O2_SD_LOCK_WP 0xD3
290#define O2_SD_MULTI_VCC3V 0xEE
291#define O2_SD_CLKREQ 0xEC
292#define O2_SD_CAPS 0xE0
293#define O2_SD_ADMA1 0xE2
294#define O2_SD_ADMA2 0xE7
295#define O2_SD_INF_MOD 0xF1
296
297static int o2_probe(struct sdhci_pci_chip *chip)
298{
299 int ret;
300 u8 scratch;
301
302 switch (chip->pdev->device) {
303 case PCI_DEVICE_ID_O2_8220:
304 case PCI_DEVICE_ID_O2_8221:
305 case PCI_DEVICE_ID_O2_8320:
306 case PCI_DEVICE_ID_O2_8321:
307 /* This extra setup is required due to broken ADMA. */
308 ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
309 if (ret)
310 return ret;
311 scratch &= 0x7f;
312 pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
313
314 /* Set Multi 3 to VCC3V# */
315 pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08);
316
317 /* Disable CLK_REQ# support after media DET */
318 ret = pci_read_config_byte(chip->pdev, O2_SD_CLKREQ, &scratch);
319 if (ret)
320 return ret;
321 scratch |= 0x20;
322 pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch);
323
324 /* Choose capabilities, enable SDMA. We have to write 0x01
325 * to the capabilities register first to unlock it.
326 */
327 ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch);
328 if (ret)
329 return ret;
330 scratch |= 0x01;
331 pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch);
332 pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73);
333
334 /* Disable ADMA1/2 */
335 pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39);
336 pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08);
337
338 /* Disable the infinite transfer mode */
339 ret = pci_read_config_byte(chip->pdev, O2_SD_INF_MOD, &scratch);
340 if (ret)
341 return ret;
342 scratch |= 0x08;
343 pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch);
344
345 /* Lock WP */
346 ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
347 if (ret)
348 return ret;
349 scratch |= 0x80;
350 pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
351 }
352
353 return 0;
354}
355
Pierre Ossman45211e22008-03-24 13:09:09 +0100356static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
357{
358 u8 scratch;
359 int ret;
360
361 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
362 if (ret)
363 return ret;
364
365 /*
366 * Turn PMOS on [bit 0], set over current detection to 2.4 V
367 * [bit 1:2] and enable over current debouncing [bit 6].
368 */
369 if (on)
370 scratch |= 0x47;
371 else
372 scratch &= ~0x47;
373
374 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
375 if (ret)
376 return ret;
377
378 return 0;
379}
380
381static int jmicron_probe(struct sdhci_pci_chip *chip)
382{
383 int ret;
Takashi Iwai8f230f42010-12-08 10:04:30 +0100384 u16 mmcdev = 0;
Pierre Ossman45211e22008-03-24 13:09:09 +0100385
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200386 if (chip->pdev->revision == 0) {
387 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
388 SDHCI_QUIRK_32BIT_DMA_SIZE |
Pierre Ossman2134a922008-06-28 18:28:51 +0200389 SDHCI_QUIRK_32BIT_ADMA_SIZE |
Pierre Ossman4a3cba32008-07-29 00:11:16 +0200390 SDHCI_QUIRK_RESET_AFTER_REQUEST |
Pierre Ossman86a6a872009-02-02 21:13:49 +0100391 SDHCI_QUIRK_BROKEN_SMALL_PIO;
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200392 }
393
Pierre Ossman45211e22008-03-24 13:09:09 +0100394 /*
Pierre Ossman44894282008-04-04 19:36:59 +0200395 * JMicron chips can have two interfaces to the same hardware
396 * in order to work around limitations in Microsoft's driver.
397 * We need to make sure we only bind to one of them.
398 *
399 * This code assumes two things:
400 *
401 * 1. The PCI code adds subfunctions in order.
402 *
403 * 2. The MMC interface has a lower subfunction number
404 * than the SD interface.
405 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100406 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
407 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
408 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
409 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
410
411 if (mmcdev) {
Pierre Ossman44894282008-04-04 19:36:59 +0200412 struct pci_dev *sd_dev;
413
414 sd_dev = NULL;
415 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
Takashi Iwai8f230f42010-12-08 10:04:30 +0100416 mmcdev, sd_dev)) != NULL) {
Pierre Ossman44894282008-04-04 19:36:59 +0200417 if ((PCI_SLOT(chip->pdev->devfn) ==
418 PCI_SLOT(sd_dev->devfn)) &&
419 (chip->pdev->bus == sd_dev->bus))
420 break;
421 }
422
423 if (sd_dev) {
424 pci_dev_put(sd_dev);
425 dev_info(&chip->pdev->dev, "Refusing to bind to "
426 "secondary interface.\n");
427 return -ENODEV;
428 }
429 }
430
431 /*
Pierre Ossman45211e22008-03-24 13:09:09 +0100432 * JMicron chips need a bit of a nudge to enable the power
433 * output pins.
434 */
435 ret = jmicron_pmos(chip, 1);
436 if (ret) {
437 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
438 return ret;
439 }
440
Takashi Iwai82b0e232011-04-21 20:26:38 +0200441 /* quirk for unsable RO-detection on JM388 chips */
442 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
443 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
444 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
445
Pierre Ossman45211e22008-03-24 13:09:09 +0100446 return 0;
447}
448
Pierre Ossman44894282008-04-04 19:36:59 +0200449static void jmicron_enable_mmc(struct sdhci_host *host, int on)
450{
451 u8 scratch;
452
453 scratch = readb(host->ioaddr + 0xC0);
454
455 if (on)
456 scratch |= 0x01;
457 else
458 scratch &= ~0x01;
459
460 writeb(scratch, host->ioaddr + 0xC0);
461}
462
463static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
464{
Pierre Ossman2134a922008-06-28 18:28:51 +0200465 if (slot->chip->pdev->revision == 0) {
466 u16 version;
467
468 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
469 version = (version & SDHCI_VENDOR_VER_MASK) >>
470 SDHCI_VENDOR_VER_SHIFT;
471
472 /*
473 * Older versions of the chip have lots of nasty glitches
474 * in the ADMA engine. It's best just to avoid it
475 * completely.
476 */
477 if (version < 0xAC)
478 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
479 }
480
Takashi Iwai8f230f42010-12-08 10:04:30 +0100481 /* JM388 MMC doesn't support 1.8V while SD supports it */
482 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
483 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
484 MMC_VDD_29_30 | MMC_VDD_30_31 |
485 MMC_VDD_165_195; /* allow 1.8V */
486 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
487 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
488 }
489
Pierre Ossman44894282008-04-04 19:36:59 +0200490 /*
491 * The secondary interface requires a bit set to get the
492 * interrupts.
493 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100494 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
495 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200496 jmicron_enable_mmc(slot->host, 1);
497
Takashi Iwaid75c1082010-12-16 17:54:14 +0100498 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
499
Pierre Ossman44894282008-04-04 19:36:59 +0200500 return 0;
501}
502
Pierre Ossman1e728592008-04-16 19:13:13 +0200503static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
Pierre Ossman44894282008-04-04 19:36:59 +0200504{
Pierre Ossman1e728592008-04-16 19:13:13 +0200505 if (dead)
506 return;
507
Takashi Iwai8f230f42010-12-08 10:04:30 +0100508 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
509 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200510 jmicron_enable_mmc(slot->host, 0);
511}
512
Manuel Lauss29495aa2011-11-03 11:09:45 +0100513static int jmicron_suspend(struct sdhci_pci_chip *chip)
Pierre Ossman44894282008-04-04 19:36:59 +0200514{
515 int i;
516
Takashi Iwai8f230f42010-12-08 10:04:30 +0100517 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
518 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300519 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200520 jmicron_enable_mmc(chip->slots[i]->host, 0);
521 }
522
523 return 0;
524}
525
Pierre Ossman45211e22008-03-24 13:09:09 +0100526static int jmicron_resume(struct sdhci_pci_chip *chip)
527{
Pierre Ossman44894282008-04-04 19:36:59 +0200528 int ret, i;
529
Takashi Iwai8f230f42010-12-08 10:04:30 +0100530 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
531 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300532 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200533 jmicron_enable_mmc(chip->slots[i]->host, 1);
534 }
Pierre Ossman45211e22008-03-24 13:09:09 +0100535
536 ret = jmicron_pmos(chip, 1);
537 if (ret) {
538 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
539 return ret;
540 }
541
542 return 0;
543}
544
Jennifer Li26daa1e2010-11-17 23:01:59 -0500545static const struct sdhci_pci_fixes sdhci_o2 = {
546 .probe = o2_probe,
547};
548
Pierre Ossman22606402008-03-23 19:33:23 +0100549static const struct sdhci_pci_fixes sdhci_jmicron = {
Pierre Ossman45211e22008-03-24 13:09:09 +0100550 .probe = jmicron_probe,
551
Pierre Ossman44894282008-04-04 19:36:59 +0200552 .probe_slot = jmicron_probe_slot,
553 .remove_slot = jmicron_remove_slot,
554
555 .suspend = jmicron_suspend,
Pierre Ossman45211e22008-03-24 13:09:09 +0100556 .resume = jmicron_resume,
Pierre Ossman22606402008-03-23 19:33:23 +0100557};
558
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800559/* SysKonnect CardBus2SDIO extra registers */
560#define SYSKT_CTRL 0x200
561#define SYSKT_RDFIFO_STAT 0x204
562#define SYSKT_WRFIFO_STAT 0x208
563#define SYSKT_POWER_DATA 0x20c
564#define SYSKT_POWER_330 0xef
565#define SYSKT_POWER_300 0xf8
566#define SYSKT_POWER_184 0xcc
567#define SYSKT_POWER_CMD 0x20d
568#define SYSKT_POWER_START (1 << 7)
569#define SYSKT_POWER_STATUS 0x20e
570#define SYSKT_POWER_STATUS_OK (1 << 0)
571#define SYSKT_BOARD_REV 0x210
572#define SYSKT_CHIP_REV 0x211
573#define SYSKT_CONF_DATA 0x212
574#define SYSKT_CONF_DATA_1V8 (1 << 2)
575#define SYSKT_CONF_DATA_2V5 (1 << 1)
576#define SYSKT_CONF_DATA_3V3 (1 << 0)
577
578static int syskt_probe(struct sdhci_pci_chip *chip)
579{
580 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
581 chip->pdev->class &= ~0x0000FF;
582 chip->pdev->class |= PCI_SDHCI_IFDMA;
583 }
584 return 0;
585}
586
587static int syskt_probe_slot(struct sdhci_pci_slot *slot)
588{
589 int tm, ps;
590
591 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
592 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
593 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
594 "board rev %d.%d, chip rev %d.%d\n",
595 board_rev >> 4, board_rev & 0xf,
596 chip_rev >> 4, chip_rev & 0xf);
597 if (chip_rev >= 0x20)
598 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
599
600 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
601 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
602 udelay(50);
603 tm = 10; /* Wait max 1 ms */
604 do {
605 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
606 if (ps & SYSKT_POWER_STATUS_OK)
607 break;
608 udelay(100);
609 } while (--tm);
610 if (!tm) {
611 dev_err(&slot->chip->pdev->dev,
612 "power regulator never stabilized");
613 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
614 return -ENODEV;
615 }
616
617 return 0;
618}
619
620static const struct sdhci_pci_fixes sdhci_syskt = {
621 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
622 .probe = syskt_probe,
623 .probe_slot = syskt_probe_slot,
624};
625
Harald Welte557b0692009-06-18 16:53:38 +0200626static int via_probe(struct sdhci_pci_chip *chip)
627{
628 if (chip->pdev->revision == 0x10)
629 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
630
631 return 0;
632}
633
634static const struct sdhci_pci_fixes sdhci_via = {
635 .probe = via_probe,
636};
637
Pierre Ossman22606402008-03-23 19:33:23 +0100638static const struct pci_device_id pci_ids[] __devinitdata = {
639 {
640 .vendor = PCI_VENDOR_ID_RICOH,
641 .device = PCI_DEVICE_ID_RICOH_R5C822,
642 .subvendor = PCI_ANY_ID,
643 .subdevice = PCI_ANY_ID,
644 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
645 },
646
647 {
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700648 .vendor = PCI_VENDOR_ID_RICOH,
649 .device = 0x843,
650 .subvendor = PCI_ANY_ID,
651 .subdevice = PCI_ANY_ID,
652 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
653 },
654
655 {
Pablo Castillo568133e2010-08-10 18:02:01 -0700656 .vendor = PCI_VENDOR_ID_RICOH,
657 .device = 0xe822,
658 .subvendor = PCI_ANY_ID,
659 .subdevice = PCI_ANY_ID,
660 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
661 },
662
663 {
Manoj Iyer5fd11c02011-02-11 16:25:31 -0600664 .vendor = PCI_VENDOR_ID_RICOH,
665 .device = 0xe823,
666 .subvendor = PCI_ANY_ID,
667 .subdevice = PCI_ANY_ID,
668 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
669 },
670
671 {
Pierre Ossman22606402008-03-23 19:33:23 +0100672 .vendor = PCI_VENDOR_ID_ENE,
673 .device = PCI_DEVICE_ID_ENE_CB712_SD,
674 .subvendor = PCI_ANY_ID,
675 .subdevice = PCI_ANY_ID,
676 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
677 },
678
679 {
680 .vendor = PCI_VENDOR_ID_ENE,
681 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
682 .subvendor = PCI_ANY_ID,
683 .subdevice = PCI_ANY_ID,
684 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
685 },
686
687 {
688 .vendor = PCI_VENDOR_ID_ENE,
689 .device = PCI_DEVICE_ID_ENE_CB714_SD,
690 .subvendor = PCI_ANY_ID,
691 .subdevice = PCI_ANY_ID,
692 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
693 },
694
695 {
696 .vendor = PCI_VENDOR_ID_ENE,
697 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
698 .subvendor = PCI_ANY_ID,
699 .subdevice = PCI_ANY_ID,
700 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
701 },
702
703 {
704 .vendor = PCI_VENDOR_ID_MARVELL,
David Woodhouse8c5eb882008-09-03 09:45:57 +0100705 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
Pierre Ossman22606402008-03-23 19:33:23 +0100706 .subvendor = PCI_ANY_ID,
707 .subdevice = PCI_ANY_ID,
708 .driver_data = (kernel_ulong_t)&sdhci_cafe,
709 },
710
711 {
712 .vendor = PCI_VENDOR_ID_JMICRON,
713 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
714 .subvendor = PCI_ANY_ID,
715 .subdevice = PCI_ANY_ID,
716 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
717 },
718
Pierre Ossman44894282008-04-04 19:36:59 +0200719 {
720 .vendor = PCI_VENDOR_ID_JMICRON,
721 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
722 .subvendor = PCI_ANY_ID,
723 .subdevice = PCI_ANY_ID,
724 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
725 },
726
Harald Welte557b0692009-06-18 16:53:38 +0200727 {
Takashi Iwai8f230f42010-12-08 10:04:30 +0100728 .vendor = PCI_VENDOR_ID_JMICRON,
729 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
730 .subvendor = PCI_ANY_ID,
731 .subdevice = PCI_ANY_ID,
732 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
733 },
734
735 {
736 .vendor = PCI_VENDOR_ID_JMICRON,
737 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
738 .subvendor = PCI_ANY_ID,
739 .subdevice = PCI_ANY_ID,
740 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
741 },
742
743 {
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800744 .vendor = PCI_VENDOR_ID_SYSKONNECT,
745 .device = 0x8000,
746 .subvendor = PCI_ANY_ID,
747 .subdevice = PCI_ANY_ID,
748 .driver_data = (kernel_ulong_t)&sdhci_syskt,
749 },
750
751 {
Harald Welte557b0692009-06-18 16:53:38 +0200752 .vendor = PCI_VENDOR_ID_VIA,
753 .device = 0x95d0,
754 .subvendor = PCI_ANY_ID,
755 .subdevice = PCI_ANY_ID,
756 .driver_data = (kernel_ulong_t)&sdhci_via,
757 },
758
Xiaochen Shen29229052010-10-04 15:24:52 +0100759 {
760 .vendor = PCI_VENDOR_ID_INTEL,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100761 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
762 .subvendor = PCI_ANY_ID,
763 .subdevice = PCI_ANY_ID,
764 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
765 },
766
767 {
768 .vendor = PCI_VENDOR_ID_INTEL,
769 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
770 .subvendor = PCI_ANY_ID,
771 .subdevice = PCI_ANY_ID,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000772 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
773 },
774
775 {
776 .vendor = PCI_VENDOR_ID_INTEL,
777 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
778 .subvendor = PCI_ANY_ID,
779 .subdevice = PCI_ANY_ID,
780 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100781 },
782
783 {
784 .vendor = PCI_VENDOR_ID_INTEL,
Xiaochen Shen29229052010-10-04 15:24:52 +0100785 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
786 .subvendor = PCI_ANY_ID,
787 .subdevice = PCI_ANY_ID,
788 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
789 },
790
791 {
792 .vendor = PCI_VENDOR_ID_INTEL,
793 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
794 .subvendor = PCI_ANY_ID,
795 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300796 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100797 },
798
799 {
800 .vendor = PCI_VENDOR_ID_INTEL,
801 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
802 .subvendor = PCI_ANY_ID,
803 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300804 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100805 },
806
807 {
808 .vendor = PCI_VENDOR_ID_INTEL,
809 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
810 .subvendor = PCI_ANY_ID,
811 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300812 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100813 },
814
815 {
816 .vendor = PCI_VENDOR_ID_INTEL,
817 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
818 .subvendor = PCI_ANY_ID,
819 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300820 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100821 },
822
Jennifer Li26daa1e2010-11-17 23:01:59 -0500823 {
824 .vendor = PCI_VENDOR_ID_O2,
825 .device = PCI_DEVICE_ID_O2_8120,
826 .subvendor = PCI_ANY_ID,
827 .subdevice = PCI_ANY_ID,
828 .driver_data = (kernel_ulong_t)&sdhci_o2,
829 },
830
831 {
832 .vendor = PCI_VENDOR_ID_O2,
833 .device = PCI_DEVICE_ID_O2_8220,
834 .subvendor = PCI_ANY_ID,
835 .subdevice = PCI_ANY_ID,
836 .driver_data = (kernel_ulong_t)&sdhci_o2,
837 },
838
839 {
840 .vendor = PCI_VENDOR_ID_O2,
841 .device = PCI_DEVICE_ID_O2_8221,
842 .subvendor = PCI_ANY_ID,
843 .subdevice = PCI_ANY_ID,
844 .driver_data = (kernel_ulong_t)&sdhci_o2,
845 },
846
847 {
848 .vendor = PCI_VENDOR_ID_O2,
849 .device = PCI_DEVICE_ID_O2_8320,
850 .subvendor = PCI_ANY_ID,
851 .subdevice = PCI_ANY_ID,
852 .driver_data = (kernel_ulong_t)&sdhci_o2,
853 },
854
855 {
856 .vendor = PCI_VENDOR_ID_O2,
857 .device = PCI_DEVICE_ID_O2_8321,
858 .subvendor = PCI_ANY_ID,
859 .subdevice = PCI_ANY_ID,
860 .driver_data = (kernel_ulong_t)&sdhci_o2,
861 },
862
Pierre Ossman22606402008-03-23 19:33:23 +0100863 { /* Generic SD host controller */
864 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
865 },
866
867 { /* end: all zeroes */ },
868};
869
870MODULE_DEVICE_TABLE(pci, pci_ids);
871
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100872/*****************************************************************************\
873 * *
874 * SDHCI core callbacks *
875 * *
876\*****************************************************************************/
877
878static int sdhci_pci_enable_dma(struct sdhci_host *host)
879{
880 struct sdhci_pci_slot *slot;
881 struct pci_dev *pdev;
882 int ret;
883
884 slot = sdhci_priv(host);
885 pdev = slot->chip->pdev;
886
887 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
888 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
Richard Röjforsa13abc72009-09-22 16:45:30 -0700889 (host->flags & SDHCI_USE_SDMA)) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100890 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
891 "doesn't fully claim to support it.\n");
892 }
893
Yang Hongyang284901a2009-04-06 19:01:15 -0700894 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100895 if (ret)
896 return ret;
897
898 pci_set_master(pdev);
899
900 return 0;
901}
902
Major Lee68077b02011-06-29 14:23:46 +0300903static int sdhci_pci_8bit_width(struct sdhci_host *host, int width)
904{
905 u8 ctrl;
906
907 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
908
909 switch (width) {
910 case MMC_BUS_WIDTH_8:
911 ctrl |= SDHCI_CTRL_8BITBUS;
912 ctrl &= ~SDHCI_CTRL_4BITBUS;
913 break;
914 case MMC_BUS_WIDTH_4:
915 ctrl |= SDHCI_CTRL_4BITBUS;
916 ctrl &= ~SDHCI_CTRL_8BITBUS;
917 break;
918 default:
919 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
920 break;
921 }
922
923 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
924
925 return 0;
926}
927
Adrian Hunter0f201652011-08-29 16:42:13 +0300928static void sdhci_pci_hw_reset(struct sdhci_host *host)
929{
930 struct sdhci_pci_slot *slot = sdhci_priv(host);
931 int rst_n_gpio = slot->rst_n_gpio;
932
933 if (!gpio_is_valid(rst_n_gpio))
934 return;
935 gpio_set_value_cansleep(rst_n_gpio, 0);
936 /* For eMMC, minimum is 1us but give it 10us for good measure */
937 udelay(10);
938 gpio_set_value_cansleep(rst_n_gpio, 1);
939 /* For eMMC, minimum is 200us but give it 300us for good measure */
940 usleep_range(300, 1000);
941}
942
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100943static struct sdhci_ops sdhci_pci_ops = {
944 .enable_dma = sdhci_pci_enable_dma,
Major Lee68077b02011-06-29 14:23:46 +0300945 .platform_8bit_width = sdhci_pci_8bit_width,
Adrian Hunter0f201652011-08-29 16:42:13 +0300946 .hw_reset = sdhci_pci_hw_reset,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100947};
948
949/*****************************************************************************\
950 * *
951 * Suspend/resume *
952 * *
953\*****************************************************************************/
954
955#ifdef CONFIG_PM
956
Manuel Lauss29495aa2011-11-03 11:09:45 +0100957static int sdhci_pci_suspend(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100958{
Manuel Lauss29495aa2011-11-03 11:09:45 +0100959 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100960 struct sdhci_pci_chip *chip;
961 struct sdhci_pci_slot *slot;
Daniel Drake5f619702010-11-04 22:20:39 +0000962 mmc_pm_flag_t slot_pm_flags;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -0800963 mmc_pm_flag_t pm_flags = 0;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100964 int i, ret;
965
966 chip = pci_get_drvdata(pdev);
967 if (!chip)
968 return 0;
969
Ameya Palandeb177bc92011-04-05 21:13:13 +0300970 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100971 slot = chip->slots[i];
972 if (!slot)
973 continue;
974
Manuel Lauss29495aa2011-11-03 11:09:45 +0100975 ret = sdhci_suspend_host(slot->host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100976
Axel Linb678b912011-12-03 15:28:05 +0800977 if (ret)
978 goto err_pci_suspend;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -0800979
Daniel Drake5f619702010-11-04 22:20:39 +0000980 slot_pm_flags = slot->host->mmc->pm_flags;
981 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
982 sdhci_enable_irq_wakeups(slot->host);
983
984 pm_flags |= slot_pm_flags;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100985 }
986
Pierre Ossman44894282008-04-04 19:36:59 +0200987 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +0100988 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +0800989 if (ret)
990 goto err_pci_suspend;
Pierre Ossman44894282008-04-04 19:36:59 +0200991 }
992
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100993 pci_save_state(pdev);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -0800994 if (pm_flags & MMC_PM_KEEP_POWER) {
Daniel Drake5f619702010-11-04 22:20:39 +0000995 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) {
996 pci_pme_active(pdev, true);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -0800997 pci_enable_wake(pdev, PCI_D3hot, 1);
Daniel Drake5f619702010-11-04 22:20:39 +0000998 }
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -0800999 pci_set_power_state(pdev, PCI_D3hot);
1000 } else {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001001 pci_enable_wake(pdev, PCI_D3hot, 0);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001002 pci_disable_device(pdev);
Manuel Lauss29495aa2011-11-03 11:09:45 +01001003 pci_set_power_state(pdev, PCI_D3hot);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001004 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001005
1006 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001007
1008err_pci_suspend:
1009 while (--i >= 0)
1010 sdhci_resume_host(chip->slots[i]->host);
1011 return ret;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001012}
1013
Manuel Lauss29495aa2011-11-03 11:09:45 +01001014static int sdhci_pci_resume(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001015{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001016 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001017 struct sdhci_pci_chip *chip;
1018 struct sdhci_pci_slot *slot;
1019 int i, ret;
1020
1021 chip = pci_get_drvdata(pdev);
1022 if (!chip)
1023 return 0;
1024
1025 pci_set_power_state(pdev, PCI_D0);
1026 pci_restore_state(pdev);
1027 ret = pci_enable_device(pdev);
1028 if (ret)
1029 return ret;
1030
Pierre Ossman45211e22008-03-24 13:09:09 +01001031 if (chip->fixes && chip->fixes->resume) {
1032 ret = chip->fixes->resume(chip);
1033 if (ret)
1034 return ret;
1035 }
1036
Ameya Palandeb177bc92011-04-05 21:13:13 +03001037 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001038 slot = chip->slots[i];
1039 if (!slot)
1040 continue;
1041
1042 ret = sdhci_resume_host(slot->host);
1043 if (ret)
1044 return ret;
1045 }
1046
1047 return 0;
1048}
1049
1050#else /* CONFIG_PM */
1051
1052#define sdhci_pci_suspend NULL
1053#define sdhci_pci_resume NULL
1054
1055#endif /* CONFIG_PM */
1056
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001057#ifdef CONFIG_PM_RUNTIME
1058
1059static int sdhci_pci_runtime_suspend(struct device *dev)
1060{
1061 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1062 struct sdhci_pci_chip *chip;
1063 struct sdhci_pci_slot *slot;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001064 int i, ret;
1065
1066 chip = pci_get_drvdata(pdev);
1067 if (!chip)
1068 return 0;
1069
1070 for (i = 0; i < chip->num_slots; i++) {
1071 slot = chip->slots[i];
1072 if (!slot)
1073 continue;
1074
1075 ret = sdhci_runtime_suspend_host(slot->host);
1076
Axel Linb678b912011-12-03 15:28:05 +08001077 if (ret)
1078 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001079 }
1080
1081 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001082 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001083 if (ret)
1084 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001085 }
1086
1087 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001088
1089err_pci_runtime_suspend:
1090 while (--i >= 0)
1091 sdhci_runtime_resume_host(chip->slots[i]->host);
1092 return ret;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001093}
1094
1095static int sdhci_pci_runtime_resume(struct device *dev)
1096{
1097 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1098 struct sdhci_pci_chip *chip;
1099 struct sdhci_pci_slot *slot;
1100 int i, ret;
1101
1102 chip = pci_get_drvdata(pdev);
1103 if (!chip)
1104 return 0;
1105
1106 if (chip->fixes && chip->fixes->resume) {
1107 ret = chip->fixes->resume(chip);
1108 if (ret)
1109 return ret;
1110 }
1111
1112 for (i = 0; i < chip->num_slots; i++) {
1113 slot = chip->slots[i];
1114 if (!slot)
1115 continue;
1116
1117 ret = sdhci_runtime_resume_host(slot->host);
1118 if (ret)
1119 return ret;
1120 }
1121
1122 return 0;
1123}
1124
1125static int sdhci_pci_runtime_idle(struct device *dev)
1126{
1127 return 0;
1128}
1129
1130#else
1131
1132#define sdhci_pci_runtime_suspend NULL
1133#define sdhci_pci_runtime_resume NULL
1134#define sdhci_pci_runtime_idle NULL
1135
1136#endif
1137
1138static const struct dev_pm_ops sdhci_pci_pm_ops = {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001139 .suspend = sdhci_pci_suspend,
1140 .resume = sdhci_pci_resume,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001141 .runtime_suspend = sdhci_pci_runtime_suspend,
1142 .runtime_resume = sdhci_pci_runtime_resume,
1143 .runtime_idle = sdhci_pci_runtime_idle,
1144};
1145
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001146/*****************************************************************************\
1147 * *
1148 * Device probing/removal *
1149 * *
1150\*****************************************************************************/
1151
1152static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
Adrian Hunter52c506f2011-12-27 15:48:43 +02001153 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1154 int slotno)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001155{
1156 struct sdhci_pci_slot *slot;
1157 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001158 int ret, bar = first_bar + slotno;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001159
1160 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1161 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1162 return ERR_PTR(-ENODEV);
1163 }
1164
1165 if (pci_resource_len(pdev, bar) != 0x100) {
1166 dev_err(&pdev->dev, "Invalid iomem size. You may "
1167 "experience problems.\n");
1168 }
1169
1170 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1171 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1172 return ERR_PTR(-ENODEV);
1173 }
1174
1175 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1176 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1177 return ERR_PTR(-ENODEV);
1178 }
1179
1180 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1181 if (IS_ERR(host)) {
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001182 dev_err(&pdev->dev, "cannot allocate host\n");
Julia Lawalldc0fd7b2010-05-26 14:42:11 -07001183 return ERR_CAST(host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001184 }
1185
1186 slot = sdhci_priv(host);
1187
1188 slot->chip = chip;
1189 slot->host = host;
1190 slot->pci_bar = bar;
Adrian Hunter0f201652011-08-29 16:42:13 +03001191 slot->rst_n_gpio = -EINVAL;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001192 slot->cd_gpio = -EINVAL;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001193
Adrian Hunter52c506f2011-12-27 15:48:43 +02001194 /* Retrieve platform data if there is any */
1195 if (*sdhci_pci_get_data)
1196 slot->data = sdhci_pci_get_data(pdev, slotno);
1197
1198 if (slot->data) {
1199 if (slot->data->setup) {
1200 ret = slot->data->setup(slot->data);
1201 if (ret) {
1202 dev_err(&pdev->dev, "platform setup failed\n");
1203 goto free;
1204 }
1205 }
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001206 slot->rst_n_gpio = slot->data->rst_n_gpio;
1207 slot->cd_gpio = slot->data->cd_gpio;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001208 }
1209
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001210 host->hw_name = "PCI";
1211 host->ops = &sdhci_pci_ops;
1212 host->quirks = chip->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001213 host->quirks2 = chip->quirks2;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001214
1215 host->irq = pdev->irq;
1216
1217 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1218 if (ret) {
1219 dev_err(&pdev->dev, "cannot request region\n");
Adrian Hunter52c506f2011-12-27 15:48:43 +02001220 goto cleanup;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001221 }
1222
Arjan van de Ven092f82e2008-09-28 16:15:56 -07001223 host->ioaddr = pci_ioremap_bar(pdev, bar);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001224 if (!host->ioaddr) {
1225 dev_err(&pdev->dev, "failed to remap registers\n");
Chris Ball9fdcdbb2011-03-29 00:46:12 -04001226 ret = -ENOMEM;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001227 goto release;
1228 }
1229
Pierre Ossman44894282008-04-04 19:36:59 +02001230 if (chip->fixes && chip->fixes->probe_slot) {
1231 ret = chip->fixes->probe_slot(slot);
1232 if (ret)
1233 goto unmap;
1234 }
1235
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001236 if (gpio_is_valid(slot->rst_n_gpio)) {
1237 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1238 gpio_direction_output(slot->rst_n_gpio, 1);
1239 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
1240 } else {
1241 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1242 slot->rst_n_gpio = -EINVAL;
1243 }
1244 }
1245
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001246 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
1247
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001248 ret = sdhci_add_host(host);
1249 if (ret)
Pierre Ossman44894282008-04-04 19:36:59 +02001250 goto remove;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001251
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001252 sdhci_pci_add_own_cd(slot);
1253
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001254 return slot;
1255
Pierre Ossman44894282008-04-04 19:36:59 +02001256remove:
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001257 if (gpio_is_valid(slot->rst_n_gpio))
1258 gpio_free(slot->rst_n_gpio);
1259
Pierre Ossman44894282008-04-04 19:36:59 +02001260 if (chip->fixes && chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001261 chip->fixes->remove_slot(slot, 0);
Pierre Ossman44894282008-04-04 19:36:59 +02001262
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001263unmap:
1264 iounmap(host->ioaddr);
1265
1266release:
1267 pci_release_region(pdev, bar);
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001268
Adrian Hunter52c506f2011-12-27 15:48:43 +02001269cleanup:
1270 if (slot->data && slot->data->cleanup)
1271 slot->data->cleanup(slot->data);
1272
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001273free:
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001274 sdhci_free_host(host);
1275
1276 return ERR_PTR(ret);
1277}
1278
1279static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1280{
Pierre Ossman1e728592008-04-16 19:13:13 +02001281 int dead;
1282 u32 scratch;
1283
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001284 sdhci_pci_remove_own_cd(slot);
1285
Pierre Ossman1e728592008-04-16 19:13:13 +02001286 dead = 0;
1287 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1288 if (scratch == (u32)-1)
1289 dead = 1;
1290
1291 sdhci_remove_host(slot->host, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001292
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001293 if (gpio_is_valid(slot->rst_n_gpio))
1294 gpio_free(slot->rst_n_gpio);
1295
Pierre Ossman44894282008-04-04 19:36:59 +02001296 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001297 slot->chip->fixes->remove_slot(slot, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001298
Adrian Hunter52c506f2011-12-27 15:48:43 +02001299 if (slot->data && slot->data->cleanup)
1300 slot->data->cleanup(slot->data);
1301
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001302 pci_release_region(slot->chip->pdev, slot->pci_bar);
Pierre Ossman44894282008-04-04 19:36:59 +02001303
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001304 sdhci_free_host(slot->host);
1305}
1306
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001307static void __devinit sdhci_pci_runtime_pm_allow(struct device *dev)
1308{
1309 pm_runtime_put_noidle(dev);
1310 pm_runtime_allow(dev);
1311 pm_runtime_set_autosuspend_delay(dev, 50);
1312 pm_runtime_use_autosuspend(dev);
1313 pm_suspend_ignore_children(dev, 1);
1314}
1315
1316static void __devexit sdhci_pci_runtime_pm_forbid(struct device *dev)
1317{
1318 pm_runtime_forbid(dev);
1319 pm_runtime_get_noresume(dev);
1320}
1321
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001322static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1323 const struct pci_device_id *ent)
1324{
1325 struct sdhci_pci_chip *chip;
1326 struct sdhci_pci_slot *slot;
1327
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001328 u8 slots, first_bar;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001329 int ret, i;
1330
1331 BUG_ON(pdev == NULL);
1332 BUG_ON(ent == NULL);
1333
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001334 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001335 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001336
1337 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1338 if (ret)
1339 return ret;
1340
1341 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1342 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1343 if (slots == 0)
1344 return -ENODEV;
1345
1346 BUG_ON(slots > MAX_SLOTS);
1347
1348 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1349 if (ret)
1350 return ret;
1351
1352 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1353
1354 if (first_bar > 5) {
1355 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1356 return -ENODEV;
1357 }
1358
1359 ret = pci_enable_device(pdev);
1360 if (ret)
1361 return ret;
1362
1363 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
1364 if (!chip) {
1365 ret = -ENOMEM;
1366 goto err;
1367 }
1368
1369 chip->pdev = pdev;
Ameya Palandeb177bc92011-04-05 21:13:13 +03001370 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001371 if (chip->fixes) {
Pierre Ossman22606402008-03-23 19:33:23 +01001372 chip->quirks = chip->fixes->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001373 chip->quirks2 = chip->fixes->quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001374 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1375 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001376 chip->num_slots = slots;
1377
1378 pci_set_drvdata(pdev, chip);
1379
Pierre Ossman22606402008-03-23 19:33:23 +01001380 if (chip->fixes && chip->fixes->probe) {
1381 ret = chip->fixes->probe(chip);
1382 if (ret)
1383 goto free;
1384 }
1385
Alan Cox225d85f2010-10-04 15:24:21 +01001386 slots = chip->num_slots; /* Quirk may have changed this */
1387
Ameya Palandeb177bc92011-04-05 21:13:13 +03001388 for (i = 0; i < slots; i++) {
Adrian Hunter52c506f2011-12-27 15:48:43 +02001389 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001390 if (IS_ERR(slot)) {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001391 for (i--; i >= 0; i--)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001392 sdhci_pci_remove_slot(chip->slots[i]);
1393 ret = PTR_ERR(slot);
1394 goto free;
1395 }
1396
1397 chip->slots[i] = slot;
1398 }
1399
Adrian Hunterc43fd772011-10-17 10:52:44 +03001400 if (chip->allow_runtime_pm)
1401 sdhci_pci_runtime_pm_allow(&pdev->dev);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001402
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001403 return 0;
1404
1405free:
1406 pci_set_drvdata(pdev, NULL);
1407 kfree(chip);
1408
1409err:
1410 pci_disable_device(pdev);
1411 return ret;
1412}
1413
1414static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
1415{
1416 int i;
1417 struct sdhci_pci_chip *chip;
1418
1419 chip = pci_get_drvdata(pdev);
1420
1421 if (chip) {
Adrian Hunterc43fd772011-10-17 10:52:44 +03001422 if (chip->allow_runtime_pm)
1423 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1424
Ameya Palandeb177bc92011-04-05 21:13:13 +03001425 for (i = 0; i < chip->num_slots; i++)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001426 sdhci_pci_remove_slot(chip->slots[i]);
1427
1428 pci_set_drvdata(pdev, NULL);
1429 kfree(chip);
1430 }
1431
1432 pci_disable_device(pdev);
1433}
1434
1435static struct pci_driver sdhci_driver = {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001436 .name = "sdhci-pci",
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001437 .id_table = pci_ids,
Ameya Palandeb177bc92011-04-05 21:13:13 +03001438 .probe = sdhci_pci_probe,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001439 .remove = __devexit_p(sdhci_pci_remove),
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001440 .driver = {
1441 .pm = &sdhci_pci_pm_ops
1442 },
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001443};
1444
1445/*****************************************************************************\
1446 * *
1447 * Driver init/exit *
1448 * *
1449\*****************************************************************************/
1450
1451static int __init sdhci_drv_init(void)
1452{
1453 return pci_register_driver(&sdhci_driver);
1454}
1455
1456static void __exit sdhci_drv_exit(void)
1457{
1458 pci_unregister_driver(&sdhci_driver);
1459}
1460
1461module_init(sdhci_drv_init);
1462module_exit(sdhci_drv_exit);
1463
Pierre Ossman32710e82009-04-08 20:14:54 +02001464MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001465MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1466MODULE_LICENSE("GPL");