blob: c1a7f31c66a9c3230919484342716db4ee7f9ed8 [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"
Adam Lee522624f2013-12-18 22:23:38 +080030#include "sdhci-pci.h"
Adam Lee01acf692013-12-19 00:01:26 +080031#include "sdhci-pci-o2micro.h"
Pierre Ossman22606402008-03-23 19:33:23 +010032
33/*****************************************************************************\
34 * *
35 * Hardware specific quirk handling *
36 * *
37\*****************************************************************************/
38
39static int ricoh_probe(struct sdhci_pci_chip *chip)
40{
Chris Ballc99436f2009-09-22 16:45:22 -070041 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
42 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
Pierre Ossman22606402008-03-23 19:33:23 +010043 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
Maxim Levitskyccc92c22010-08-10 18:01:42 -070044 return 0;
45}
Pierre Ossman22606402008-03-23 19:33:23 +010046
Maxim Levitskyccc92c22010-08-10 18:01:42 -070047static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
48{
49 slot->host->caps =
50 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
51 & SDHCI_TIMEOUT_CLK_MASK) |
52
53 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
54 & SDHCI_CLOCK_BASE_MASK) |
55
56 SDHCI_TIMEOUT_CLK_UNIT |
57 SDHCI_CAN_VDD_330 |
Madhvapathi Sriram1a1f1f02012-10-15 04:47:30 +000058 SDHCI_CAN_DO_HISPD |
Maxim Levitskyccc92c22010-08-10 18:01:42 -070059 SDHCI_CAN_DO_SDMA;
60 return 0;
61}
62
63static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
64{
65 /* Apply a delay to allow controller to settle */
66 /* Otherwise it becomes confused if card state changed
67 during suspend */
68 msleep(500);
Pierre Ossman22606402008-03-23 19:33:23 +010069 return 0;
70}
71
72static const struct sdhci_pci_fixes sdhci_ricoh = {
73 .probe = ricoh_probe,
Vasily Khoruzhick84938292010-03-05 13:43:46 -080074 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
75 SDHCI_QUIRK_FORCE_DMA |
76 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
Pierre Ossman22606402008-03-23 19:33:23 +010077};
78
Maxim Levitskyccc92c22010-08-10 18:01:42 -070079static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
80 .probe_slot = ricoh_mmc_probe_slot,
81 .resume = ricoh_mmc_resume,
82 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
83 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
84 SDHCI_QUIRK_NO_CARD_NO_RESET |
85 SDHCI_QUIRK_MISSING_CAPS
86};
87
Pierre Ossman22606402008-03-23 19:33:23 +010088static const struct sdhci_pci_fixes sdhci_ene_712 = {
89 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
90 SDHCI_QUIRK_BROKEN_DMA,
91};
92
93static const struct sdhci_pci_fixes sdhci_ene_714 = {
94 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
95 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
96 SDHCI_QUIRK_BROKEN_DMA,
97};
98
99static const struct sdhci_pci_fixes sdhci_cafe = {
100 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
Andres Salomona0874892009-03-02 21:48:20 +0100101 SDHCI_QUIRK_NO_BUSY_IRQ |
Daniel Drake55fc05b2012-07-03 23:13:39 +0100102 SDHCI_QUIRK_BROKEN_CARD_DETECTION |
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200103 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
Pierre Ossman22606402008-03-23 19:33:23 +0100104};
105
Major Lee68077b02011-06-29 14:23:46 +0300106static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
107{
108 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
109 return 0;
110}
111
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100112/*
113 * ADMA operation is disabled for Moorestown platform due to
114 * hardware bugs.
115 */
Jacob Pan35ac6f02010-11-09 13:57:29 +0000116static int mrst_hc_probe(struct sdhci_pci_chip *chip)
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100117{
118 /*
Jacob Pan35ac6f02010-11-09 13:57:29 +0000119 * slots number is fixed here for MRST as SDIO3/5 are never used and
120 * have hardware bugs.
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100121 */
122 chip->num_slots = 1;
123 return 0;
124}
125
Alexander Stein296e0b02012-03-14 08:38:58 +0100126static int pch_hc_probe_slot(struct sdhci_pci_slot *slot)
127{
128 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
129 return 0;
130}
131
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300132#ifdef CONFIG_PM_RUNTIME
133
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200134static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300135{
136 struct sdhci_pci_slot *slot = dev_id;
137 struct sdhci_host *host = slot->host;
138
139 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
140 return IRQ_HANDLED;
141}
142
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200143static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300144{
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200145 int err, irq, gpio = slot->cd_gpio;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300146
147 slot->cd_gpio = -EINVAL;
148 slot->cd_irq = -EINVAL;
149
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200150 if (!gpio_is_valid(gpio))
151 return;
152
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300153 err = gpio_request(gpio, "sd_cd");
154 if (err < 0)
155 goto out;
156
157 err = gpio_direction_input(gpio);
158 if (err < 0)
159 goto out_free;
160
161 irq = gpio_to_irq(gpio);
162 if (irq < 0)
163 goto out_free;
164
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200165 err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300166 IRQF_TRIGGER_FALLING, "sd_cd", slot);
167 if (err)
168 goto out_free;
169
170 slot->cd_gpio = gpio;
171 slot->cd_irq = irq;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300172
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200173 return;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300174
175out_free:
176 gpio_free(gpio);
177out:
178 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300179}
180
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200181static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300182{
183 if (slot->cd_irq >= 0)
184 free_irq(slot->cd_irq, slot);
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200185 if (gpio_is_valid(slot->cd_gpio))
186 gpio_free(slot->cd_gpio);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300187}
188
189#else
190
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200191static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
192{
193}
194
195static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
196{
197}
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300198
199#endif
200
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300201static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
202{
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300203 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
Adrian Hunterda721cf2012-02-07 14:48:53 +0200204 slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
205 MMC_CAP2_HC_ERASE_SZ;
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300206 return 0;
207}
208
Adrian Hunter93933502011-12-27 15:48:47 +0200209static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
210{
Adrian Hunter012e4672012-01-30 14:27:18 +0200211 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
Adrian Hunter93933502011-12-27 15:48:47 +0200212 return 0;
213}
214
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100215static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
216 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Major Lee68077b02011-06-29 14:23:46 +0300217 .probe_slot = mrst_hc_probe_slot,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100218};
219
Jacob Pan35ac6f02010-11-09 13:57:29 +0000220static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100221 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000222 .probe = mrst_hc_probe,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100223};
224
Xiaochen Shen29229052010-10-04 15:24:52 +0100225static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
226 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300227 .allow_runtime_pm = true,
Xiaochen Shen29229052010-10-04 15:24:52 +0100228};
229
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300230static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
Xiaochen Shen29229052010-10-04 15:24:52 +0100231 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterf3c55a72012-02-07 14:48:55 +0200232 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300233 .allow_runtime_pm = true,
Adrian Hunter93933502011-12-27 15:48:47 +0200234 .probe_slot = mfd_sdio_probe_slot,
Xiaochen Shen29229052010-10-04 15:24:52 +0100235};
236
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300237static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
238 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300239 .allow_runtime_pm = true,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300240 .probe_slot = mfd_emmc_probe_slot,
241};
242
Alexander Stein296e0b02012-03-14 08:38:58 +0100243static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = {
244 .quirks = SDHCI_QUIRK_BROKEN_ADMA,
245 .probe_slot = pch_hc_probe_slot,
246};
247
Adrian Hunterc9faff62013-06-13 11:50:26 +0300248static void sdhci_pci_int_hw_reset(struct sdhci_host *host)
249{
250 u8 reg;
251
252 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
253 reg |= 0x10;
254 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
255 /* For eMMC, minimum is 1us but give it 9us for good measure */
256 udelay(9);
257 reg &= ~0x10;
258 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
259 /* For eMMC, minimum is 200us but give it 300us for good measure */
260 usleep_range(300, 1000);
261}
262
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300263static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
264{
Adrian Hunterc9faff62013-06-13 11:50:26 +0300265 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
266 MMC_CAP_HW_RESET;
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300267 slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
Adrian Hunterc9faff62013-06-13 11:50:26 +0300268 slot->hw_reset = sdhci_pci_int_hw_reset;
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300269 return 0;
270}
271
272static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
273{
274 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
275 return 0;
276}
277
278static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
279 .allow_runtime_pm = true,
280 .probe_slot = byt_emmc_probe_slot,
281};
282
283static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
284 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
285 .allow_runtime_pm = true,
286 .probe_slot = byt_sdio_probe_slot,
287};
288
289static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
Adrian Hunter7396e312013-05-06 12:17:34 +0300290 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON,
291 .allow_runtime_pm = true,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300292};
293
David Cohen8776a162013-10-01 13:18:15 -0700294/* Define Host controllers for Intel Merrifield platform */
295#define INTEL_MRFL_EMMC_0 0
296#define INTEL_MRFL_EMMC_1 1
297
298static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
299{
300 if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_0) &&
301 (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_1))
302 /* SD support is not ready yet */
303 return -ENODEV;
304
305 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
306 MMC_CAP_1_8V_DDR;
307
308 return 0;
309}
310
311static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
312 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
313 .probe_slot = intel_mrfl_mmc_probe_slot,
314};
315
Jennifer Li26daa1e2010-11-17 23:01:59 -0500316/* O2Micro extra registers */
317#define O2_SD_LOCK_WP 0xD3
318#define O2_SD_MULTI_VCC3V 0xEE
319#define O2_SD_CLKREQ 0xEC
320#define O2_SD_CAPS 0xE0
321#define O2_SD_ADMA1 0xE2
322#define O2_SD_ADMA2 0xE7
323#define O2_SD_INF_MOD 0xF1
324
Pierre Ossman45211e22008-03-24 13:09:09 +0100325static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
326{
327 u8 scratch;
328 int ret;
329
330 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
331 if (ret)
332 return ret;
333
334 /*
335 * Turn PMOS on [bit 0], set over current detection to 2.4 V
336 * [bit 1:2] and enable over current debouncing [bit 6].
337 */
338 if (on)
339 scratch |= 0x47;
340 else
341 scratch &= ~0x47;
342
343 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
344 if (ret)
345 return ret;
346
347 return 0;
348}
349
350static int jmicron_probe(struct sdhci_pci_chip *chip)
351{
352 int ret;
Takashi Iwai8f230f42010-12-08 10:04:30 +0100353 u16 mmcdev = 0;
Pierre Ossman45211e22008-03-24 13:09:09 +0100354
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200355 if (chip->pdev->revision == 0) {
356 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
357 SDHCI_QUIRK_32BIT_DMA_SIZE |
Pierre Ossman2134a922008-06-28 18:28:51 +0200358 SDHCI_QUIRK_32BIT_ADMA_SIZE |
Pierre Ossman4a3cba32008-07-29 00:11:16 +0200359 SDHCI_QUIRK_RESET_AFTER_REQUEST |
Pierre Ossman86a6a872009-02-02 21:13:49 +0100360 SDHCI_QUIRK_BROKEN_SMALL_PIO;
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200361 }
362
Pierre Ossman45211e22008-03-24 13:09:09 +0100363 /*
Pierre Ossman44894282008-04-04 19:36:59 +0200364 * JMicron chips can have two interfaces to the same hardware
365 * in order to work around limitations in Microsoft's driver.
366 * We need to make sure we only bind to one of them.
367 *
368 * This code assumes two things:
369 *
370 * 1. The PCI code adds subfunctions in order.
371 *
372 * 2. The MMC interface has a lower subfunction number
373 * than the SD interface.
374 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100375 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
376 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
377 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
378 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
379
380 if (mmcdev) {
Pierre Ossman44894282008-04-04 19:36:59 +0200381 struct pci_dev *sd_dev;
382
383 sd_dev = NULL;
384 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
Takashi Iwai8f230f42010-12-08 10:04:30 +0100385 mmcdev, sd_dev)) != NULL) {
Pierre Ossman44894282008-04-04 19:36:59 +0200386 if ((PCI_SLOT(chip->pdev->devfn) ==
387 PCI_SLOT(sd_dev->devfn)) &&
388 (chip->pdev->bus == sd_dev->bus))
389 break;
390 }
391
392 if (sd_dev) {
393 pci_dev_put(sd_dev);
394 dev_info(&chip->pdev->dev, "Refusing to bind to "
395 "secondary interface.\n");
396 return -ENODEV;
397 }
398 }
399
400 /*
Pierre Ossman45211e22008-03-24 13:09:09 +0100401 * JMicron chips need a bit of a nudge to enable the power
402 * output pins.
403 */
404 ret = jmicron_pmos(chip, 1);
405 if (ret) {
406 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
407 return ret;
408 }
409
Takashi Iwai82b0e232011-04-21 20:26:38 +0200410 /* quirk for unsable RO-detection on JM388 chips */
411 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
412 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
413 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
414
Pierre Ossman45211e22008-03-24 13:09:09 +0100415 return 0;
416}
417
Pierre Ossman44894282008-04-04 19:36:59 +0200418static void jmicron_enable_mmc(struct sdhci_host *host, int on)
419{
420 u8 scratch;
421
422 scratch = readb(host->ioaddr + 0xC0);
423
424 if (on)
425 scratch |= 0x01;
426 else
427 scratch &= ~0x01;
428
429 writeb(scratch, host->ioaddr + 0xC0);
430}
431
432static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
433{
Pierre Ossman2134a922008-06-28 18:28:51 +0200434 if (slot->chip->pdev->revision == 0) {
435 u16 version;
436
437 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
438 version = (version & SDHCI_VENDOR_VER_MASK) >>
439 SDHCI_VENDOR_VER_SHIFT;
440
441 /*
442 * Older versions of the chip have lots of nasty glitches
443 * in the ADMA engine. It's best just to avoid it
444 * completely.
445 */
446 if (version < 0xAC)
447 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
448 }
449
Takashi Iwai8f230f42010-12-08 10:04:30 +0100450 /* JM388 MMC doesn't support 1.8V while SD supports it */
451 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
452 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
453 MMC_VDD_29_30 | MMC_VDD_30_31 |
454 MMC_VDD_165_195; /* allow 1.8V */
455 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
456 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
457 }
458
Pierre Ossman44894282008-04-04 19:36:59 +0200459 /*
460 * The secondary interface requires a bit set to get the
461 * interrupts.
462 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100463 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
464 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200465 jmicron_enable_mmc(slot->host, 1);
466
Takashi Iwaid75c1082010-12-16 17:54:14 +0100467 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
468
Pierre Ossman44894282008-04-04 19:36:59 +0200469 return 0;
470}
471
Pierre Ossman1e728592008-04-16 19:13:13 +0200472static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
Pierre Ossman44894282008-04-04 19:36:59 +0200473{
Pierre Ossman1e728592008-04-16 19:13:13 +0200474 if (dead)
475 return;
476
Takashi Iwai8f230f42010-12-08 10:04:30 +0100477 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
478 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200479 jmicron_enable_mmc(slot->host, 0);
480}
481
Manuel Lauss29495aa2011-11-03 11:09:45 +0100482static int jmicron_suspend(struct sdhci_pci_chip *chip)
Pierre Ossman44894282008-04-04 19:36:59 +0200483{
484 int i;
485
Takashi Iwai8f230f42010-12-08 10:04:30 +0100486 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
487 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300488 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200489 jmicron_enable_mmc(chip->slots[i]->host, 0);
490 }
491
492 return 0;
493}
494
Pierre Ossman45211e22008-03-24 13:09:09 +0100495static int jmicron_resume(struct sdhci_pci_chip *chip)
496{
Pierre Ossman44894282008-04-04 19:36:59 +0200497 int ret, i;
498
Takashi Iwai8f230f42010-12-08 10:04:30 +0100499 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
500 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300501 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200502 jmicron_enable_mmc(chip->slots[i]->host, 1);
503 }
Pierre Ossman45211e22008-03-24 13:09:09 +0100504
505 ret = jmicron_pmos(chip, 1);
506 if (ret) {
507 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
508 return ret;
509 }
510
511 return 0;
512}
513
Jennifer Li26daa1e2010-11-17 23:01:59 -0500514static const struct sdhci_pci_fixes sdhci_o2 = {
Adam Lee01acf692013-12-19 00:01:26 +0800515 .probe = sdhci_pci_o2_probe,
516 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
517 .probe_slot = sdhci_pci_o2_probe_slot,
518 .resume = sdhci_pci_o2_resume,
Jennifer Li26daa1e2010-11-17 23:01:59 -0500519};
520
Pierre Ossman22606402008-03-23 19:33:23 +0100521static const struct sdhci_pci_fixes sdhci_jmicron = {
Pierre Ossman45211e22008-03-24 13:09:09 +0100522 .probe = jmicron_probe,
523
Pierre Ossman44894282008-04-04 19:36:59 +0200524 .probe_slot = jmicron_probe_slot,
525 .remove_slot = jmicron_remove_slot,
526
527 .suspend = jmicron_suspend,
Pierre Ossman45211e22008-03-24 13:09:09 +0100528 .resume = jmicron_resume,
Pierre Ossman22606402008-03-23 19:33:23 +0100529};
530
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800531/* SysKonnect CardBus2SDIO extra registers */
532#define SYSKT_CTRL 0x200
533#define SYSKT_RDFIFO_STAT 0x204
534#define SYSKT_WRFIFO_STAT 0x208
535#define SYSKT_POWER_DATA 0x20c
536#define SYSKT_POWER_330 0xef
537#define SYSKT_POWER_300 0xf8
538#define SYSKT_POWER_184 0xcc
539#define SYSKT_POWER_CMD 0x20d
540#define SYSKT_POWER_START (1 << 7)
541#define SYSKT_POWER_STATUS 0x20e
542#define SYSKT_POWER_STATUS_OK (1 << 0)
543#define SYSKT_BOARD_REV 0x210
544#define SYSKT_CHIP_REV 0x211
545#define SYSKT_CONF_DATA 0x212
546#define SYSKT_CONF_DATA_1V8 (1 << 2)
547#define SYSKT_CONF_DATA_2V5 (1 << 1)
548#define SYSKT_CONF_DATA_3V3 (1 << 0)
549
550static int syskt_probe(struct sdhci_pci_chip *chip)
551{
552 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
553 chip->pdev->class &= ~0x0000FF;
554 chip->pdev->class |= PCI_SDHCI_IFDMA;
555 }
556 return 0;
557}
558
559static int syskt_probe_slot(struct sdhci_pci_slot *slot)
560{
561 int tm, ps;
562
563 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
564 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
565 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
566 "board rev %d.%d, chip rev %d.%d\n",
567 board_rev >> 4, board_rev & 0xf,
568 chip_rev >> 4, chip_rev & 0xf);
569 if (chip_rev >= 0x20)
570 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
571
572 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
573 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
574 udelay(50);
575 tm = 10; /* Wait max 1 ms */
576 do {
577 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
578 if (ps & SYSKT_POWER_STATUS_OK)
579 break;
580 udelay(100);
581 } while (--tm);
582 if (!tm) {
583 dev_err(&slot->chip->pdev->dev,
584 "power regulator never stabilized");
585 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
586 return -ENODEV;
587 }
588
589 return 0;
590}
591
592static const struct sdhci_pci_fixes sdhci_syskt = {
593 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
594 .probe = syskt_probe,
595 .probe_slot = syskt_probe_slot,
596};
597
Harald Welte557b0692009-06-18 16:53:38 +0200598static int via_probe(struct sdhci_pci_chip *chip)
599{
600 if (chip->pdev->revision == 0x10)
601 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
602
603 return 0;
604}
605
606static const struct sdhci_pci_fixes sdhci_via = {
607 .probe = via_probe,
608};
609
Bill Pemberton9647f842012-11-19 13:25:11 -0500610static const struct pci_device_id pci_ids[] = {
Pierre Ossman22606402008-03-23 19:33:23 +0100611 {
612 .vendor = PCI_VENDOR_ID_RICOH,
613 .device = PCI_DEVICE_ID_RICOH_R5C822,
614 .subvendor = PCI_ANY_ID,
615 .subdevice = PCI_ANY_ID,
616 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
617 },
618
619 {
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700620 .vendor = PCI_VENDOR_ID_RICOH,
621 .device = 0x843,
622 .subvendor = PCI_ANY_ID,
623 .subdevice = PCI_ANY_ID,
624 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
625 },
626
627 {
Pablo Castillo568133e2010-08-10 18:02:01 -0700628 .vendor = PCI_VENDOR_ID_RICOH,
629 .device = 0xe822,
630 .subvendor = PCI_ANY_ID,
631 .subdevice = PCI_ANY_ID,
632 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
633 },
634
635 {
Manoj Iyer5fd11c02011-02-11 16:25:31 -0600636 .vendor = PCI_VENDOR_ID_RICOH,
637 .device = 0xe823,
638 .subvendor = PCI_ANY_ID,
639 .subdevice = PCI_ANY_ID,
640 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
641 },
642
643 {
Pierre Ossman22606402008-03-23 19:33:23 +0100644 .vendor = PCI_VENDOR_ID_ENE,
645 .device = PCI_DEVICE_ID_ENE_CB712_SD,
646 .subvendor = PCI_ANY_ID,
647 .subdevice = PCI_ANY_ID,
648 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
649 },
650
651 {
652 .vendor = PCI_VENDOR_ID_ENE,
653 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
654 .subvendor = PCI_ANY_ID,
655 .subdevice = PCI_ANY_ID,
656 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
657 },
658
659 {
660 .vendor = PCI_VENDOR_ID_ENE,
661 .device = PCI_DEVICE_ID_ENE_CB714_SD,
662 .subvendor = PCI_ANY_ID,
663 .subdevice = PCI_ANY_ID,
664 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
665 },
666
667 {
668 .vendor = PCI_VENDOR_ID_ENE,
669 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
670 .subvendor = PCI_ANY_ID,
671 .subdevice = PCI_ANY_ID,
672 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
673 },
674
675 {
676 .vendor = PCI_VENDOR_ID_MARVELL,
David Woodhouse8c5eb882008-09-03 09:45:57 +0100677 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
Pierre Ossman22606402008-03-23 19:33:23 +0100678 .subvendor = PCI_ANY_ID,
679 .subdevice = PCI_ANY_ID,
680 .driver_data = (kernel_ulong_t)&sdhci_cafe,
681 },
682
683 {
684 .vendor = PCI_VENDOR_ID_JMICRON,
685 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
686 .subvendor = PCI_ANY_ID,
687 .subdevice = PCI_ANY_ID,
688 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
689 },
690
Pierre Ossman44894282008-04-04 19:36:59 +0200691 {
692 .vendor = PCI_VENDOR_ID_JMICRON,
693 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
694 .subvendor = PCI_ANY_ID,
695 .subdevice = PCI_ANY_ID,
696 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
697 },
698
Harald Welte557b0692009-06-18 16:53:38 +0200699 {
Takashi Iwai8f230f42010-12-08 10:04:30 +0100700 .vendor = PCI_VENDOR_ID_JMICRON,
701 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
702 .subvendor = PCI_ANY_ID,
703 .subdevice = PCI_ANY_ID,
704 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
705 },
706
707 {
708 .vendor = PCI_VENDOR_ID_JMICRON,
709 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
710 .subvendor = PCI_ANY_ID,
711 .subdevice = PCI_ANY_ID,
712 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
713 },
714
715 {
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800716 .vendor = PCI_VENDOR_ID_SYSKONNECT,
717 .device = 0x8000,
718 .subvendor = PCI_ANY_ID,
719 .subdevice = PCI_ANY_ID,
720 .driver_data = (kernel_ulong_t)&sdhci_syskt,
721 },
722
723 {
Harald Welte557b0692009-06-18 16:53:38 +0200724 .vendor = PCI_VENDOR_ID_VIA,
725 .device = 0x95d0,
726 .subvendor = PCI_ANY_ID,
727 .subdevice = PCI_ANY_ID,
728 .driver_data = (kernel_ulong_t)&sdhci_via,
729 },
730
Xiaochen Shen29229052010-10-04 15:24:52 +0100731 {
732 .vendor = PCI_VENDOR_ID_INTEL,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100733 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
734 .subvendor = PCI_ANY_ID,
735 .subdevice = PCI_ANY_ID,
736 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
737 },
738
739 {
740 .vendor = PCI_VENDOR_ID_INTEL,
741 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
742 .subvendor = PCI_ANY_ID,
743 .subdevice = PCI_ANY_ID,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000744 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
745 },
746
747 {
748 .vendor = PCI_VENDOR_ID_INTEL,
749 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
750 .subvendor = PCI_ANY_ID,
751 .subdevice = PCI_ANY_ID,
752 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100753 },
754
755 {
756 .vendor = PCI_VENDOR_ID_INTEL,
Xiaochen Shen29229052010-10-04 15:24:52 +0100757 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
758 .subvendor = PCI_ANY_ID,
759 .subdevice = PCI_ANY_ID,
760 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
761 },
762
763 {
764 .vendor = PCI_VENDOR_ID_INTEL,
765 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
766 .subvendor = PCI_ANY_ID,
767 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300768 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100769 },
770
771 {
772 .vendor = PCI_VENDOR_ID_INTEL,
773 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
774 .subvendor = PCI_ANY_ID,
775 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300776 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100777 },
778
779 {
780 .vendor = PCI_VENDOR_ID_INTEL,
781 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
782 .subvendor = PCI_ANY_ID,
783 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300784 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100785 },
786
787 {
788 .vendor = PCI_VENDOR_ID_INTEL,
789 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
790 .subvendor = PCI_ANY_ID,
791 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300792 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100793 },
794
Jennifer Li26daa1e2010-11-17 23:01:59 -0500795 {
Alexander Stein296e0b02012-03-14 08:38:58 +0100796 .vendor = PCI_VENDOR_ID_INTEL,
797 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
798 .subvendor = PCI_ANY_ID,
799 .subdevice = PCI_ANY_ID,
800 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
801 },
802
803 {
804 .vendor = PCI_VENDOR_ID_INTEL,
805 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
806 .subvendor = PCI_ANY_ID,
807 .subdevice = PCI_ANY_ID,
808 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
809 },
810
811 {
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300812 .vendor = PCI_VENDOR_ID_INTEL,
813 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC,
814 .subvendor = PCI_ANY_ID,
815 .subdevice = PCI_ANY_ID,
816 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
817 },
818
819 {
820 .vendor = PCI_VENDOR_ID_INTEL,
821 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
822 .subvendor = PCI_ANY_ID,
823 .subdevice = PCI_ANY_ID,
824 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
825 },
826
827 {
828 .vendor = PCI_VENDOR_ID_INTEL,
829 .device = PCI_DEVICE_ID_INTEL_BYT_SD,
830 .subvendor = PCI_ANY_ID,
831 .subdevice = PCI_ANY_ID,
832 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
833 },
834
835 {
Adrian Hunter30d025c2013-06-20 12:57:59 +0300836 .vendor = PCI_VENDOR_ID_INTEL,
837 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2,
838 .subvendor = PCI_ANY_ID,
839 .subdevice = PCI_ANY_ID,
840 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
841 },
842
Eric Ernstd0520682013-10-21 09:54:41 -0700843
844 {
845 .vendor = PCI_VENDOR_ID_INTEL,
846 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
847 .subvendor = PCI_ANY_ID,
848 .subdevice = PCI_ANY_ID,
849 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
850 },
851
852 {
853 .vendor = PCI_VENDOR_ID_INTEL,
854 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
855 .subvendor = PCI_ANY_ID,
856 .subdevice = PCI_ANY_ID,
857 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
858 },
859
860 {
861 .vendor = PCI_VENDOR_ID_INTEL,
862 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
863 .subvendor = PCI_ANY_ID,
864 .subdevice = PCI_ANY_ID,
865 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
866 },
867
868 {
869 .vendor = PCI_VENDOR_ID_INTEL,
870 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
871 .subvendor = PCI_ANY_ID,
872 .subdevice = PCI_ANY_ID,
873 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
874 },
875
876 {
877 .vendor = PCI_VENDOR_ID_INTEL,
878 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
879 .subvendor = PCI_ANY_ID,
880 .subdevice = PCI_ANY_ID,
881 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
882 },
883
Adrian Hunter30d025c2013-06-20 12:57:59 +0300884 {
David Cohen8776a162013-10-01 13:18:15 -0700885 .vendor = PCI_VENDOR_ID_INTEL,
886 .device = PCI_DEVICE_ID_INTEL_MRFL_MMC,
887 .subvendor = PCI_ANY_ID,
888 .subdevice = PCI_ANY_ID,
889 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
890 },
891 {
Jennifer Li26daa1e2010-11-17 23:01:59 -0500892 .vendor = PCI_VENDOR_ID_O2,
893 .device = PCI_DEVICE_ID_O2_8120,
894 .subvendor = PCI_ANY_ID,
895 .subdevice = PCI_ANY_ID,
896 .driver_data = (kernel_ulong_t)&sdhci_o2,
897 },
898
899 {
900 .vendor = PCI_VENDOR_ID_O2,
901 .device = PCI_DEVICE_ID_O2_8220,
902 .subvendor = PCI_ANY_ID,
903 .subdevice = PCI_ANY_ID,
904 .driver_data = (kernel_ulong_t)&sdhci_o2,
905 },
906
907 {
908 .vendor = PCI_VENDOR_ID_O2,
909 .device = PCI_DEVICE_ID_O2_8221,
910 .subvendor = PCI_ANY_ID,
911 .subdevice = PCI_ANY_ID,
912 .driver_data = (kernel_ulong_t)&sdhci_o2,
913 },
914
915 {
916 .vendor = PCI_VENDOR_ID_O2,
917 .device = PCI_DEVICE_ID_O2_8320,
918 .subvendor = PCI_ANY_ID,
919 .subdevice = PCI_ANY_ID,
920 .driver_data = (kernel_ulong_t)&sdhci_o2,
921 },
922
923 {
924 .vendor = PCI_VENDOR_ID_O2,
925 .device = PCI_DEVICE_ID_O2_8321,
926 .subvendor = PCI_ANY_ID,
927 .subdevice = PCI_ANY_ID,
928 .driver_data = (kernel_ulong_t)&sdhci_o2,
929 },
930
Adam Lee01acf692013-12-19 00:01:26 +0800931 {
932 .vendor = PCI_VENDOR_ID_O2,
933 .device = PCI_DEVICE_ID_O2_FUJIN2,
934 .subvendor = PCI_ANY_ID,
935 .subdevice = PCI_ANY_ID,
936 .driver_data = (kernel_ulong_t)&sdhci_o2,
937 },
938
939 {
940 .vendor = PCI_VENDOR_ID_O2,
941 .device = PCI_DEVICE_ID_O2_SDS0,
942 .subvendor = PCI_ANY_ID,
943 .subdevice = PCI_ANY_ID,
944 .driver_data = (kernel_ulong_t)&sdhci_o2,
945 },
946
947 {
948 .vendor = PCI_VENDOR_ID_O2,
949 .device = PCI_DEVICE_ID_O2_SDS1,
950 .subvendor = PCI_ANY_ID,
951 .subdevice = PCI_ANY_ID,
952 .driver_data = (kernel_ulong_t)&sdhci_o2,
953 },
954
955 {
956 .vendor = PCI_VENDOR_ID_O2,
957 .device = PCI_DEVICE_ID_O2_SEABIRD0,
958 .subvendor = PCI_ANY_ID,
959 .subdevice = PCI_ANY_ID,
960 .driver_data = (kernel_ulong_t)&sdhci_o2,
961 },
962
963 {
964 .vendor = PCI_VENDOR_ID_O2,
965 .device = PCI_DEVICE_ID_O2_SEABIRD1,
966 .subvendor = PCI_ANY_ID,
967 .subdevice = PCI_ANY_ID,
968 .driver_data = (kernel_ulong_t)&sdhci_o2,
969 },
970
Pierre Ossman22606402008-03-23 19:33:23 +0100971 { /* Generic SD host controller */
972 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
973 },
974
975 { /* end: all zeroes */ },
976};
977
978MODULE_DEVICE_TABLE(pci, pci_ids);
979
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100980/*****************************************************************************\
981 * *
982 * SDHCI core callbacks *
983 * *
984\*****************************************************************************/
985
986static int sdhci_pci_enable_dma(struct sdhci_host *host)
987{
988 struct sdhci_pci_slot *slot;
989 struct pci_dev *pdev;
990 int ret;
991
992 slot = sdhci_priv(host);
993 pdev = slot->chip->pdev;
994
995 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
996 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
Richard Röjforsa13abc72009-09-22 16:45:30 -0700997 (host->flags & SDHCI_USE_SDMA)) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100998 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
999 "doesn't fully claim to support it.\n");
1000 }
1001
Yang Hongyang284901a2009-04-06 19:01:15 -07001002 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001003 if (ret)
1004 return ret;
1005
1006 pci_set_master(pdev);
1007
1008 return 0;
1009}
1010
Sascha Hauer7bc088d2013-01-21 19:02:27 +08001011static int sdhci_pci_bus_width(struct sdhci_host *host, int width)
Major Lee68077b02011-06-29 14:23:46 +03001012{
1013 u8 ctrl;
1014
1015 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1016
1017 switch (width) {
1018 case MMC_BUS_WIDTH_8:
1019 ctrl |= SDHCI_CTRL_8BITBUS;
1020 ctrl &= ~SDHCI_CTRL_4BITBUS;
1021 break;
1022 case MMC_BUS_WIDTH_4:
1023 ctrl |= SDHCI_CTRL_4BITBUS;
1024 ctrl &= ~SDHCI_CTRL_8BITBUS;
1025 break;
1026 default:
1027 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
1028 break;
1029 }
1030
1031 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
1032
1033 return 0;
1034}
1035
Adrian Hunterc9faff62013-06-13 11:50:26 +03001036static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
Adrian Hunter0f201652011-08-29 16:42:13 +03001037{
1038 struct sdhci_pci_slot *slot = sdhci_priv(host);
1039 int rst_n_gpio = slot->rst_n_gpio;
1040
1041 if (!gpio_is_valid(rst_n_gpio))
1042 return;
1043 gpio_set_value_cansleep(rst_n_gpio, 0);
1044 /* For eMMC, minimum is 1us but give it 10us for good measure */
1045 udelay(10);
1046 gpio_set_value_cansleep(rst_n_gpio, 1);
1047 /* For eMMC, minimum is 200us but give it 300us for good measure */
1048 usleep_range(300, 1000);
1049}
1050
Adrian Hunterc9faff62013-06-13 11:50:26 +03001051static void sdhci_pci_hw_reset(struct sdhci_host *host)
1052{
1053 struct sdhci_pci_slot *slot = sdhci_priv(host);
1054
1055 if (slot->hw_reset)
1056 slot->hw_reset(host);
1057}
1058
Lars-Peter Clausenc9155682013-03-13 19:26:05 +01001059static const struct sdhci_ops sdhci_pci_ops = {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001060 .enable_dma = sdhci_pci_enable_dma,
Sascha Hauer7bc088d2013-01-21 19:02:27 +08001061 .platform_bus_width = sdhci_pci_bus_width,
Adrian Hunter0f201652011-08-29 16:42:13 +03001062 .hw_reset = sdhci_pci_hw_reset,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001063};
1064
1065/*****************************************************************************\
1066 * *
1067 * Suspend/resume *
1068 * *
1069\*****************************************************************************/
1070
1071#ifdef CONFIG_PM
1072
Manuel Lauss29495aa2011-11-03 11:09:45 +01001073static int sdhci_pci_suspend(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001074{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001075 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001076 struct sdhci_pci_chip *chip;
1077 struct sdhci_pci_slot *slot;
Daniel Drake5f619702010-11-04 22:20:39 +00001078 mmc_pm_flag_t slot_pm_flags;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001079 mmc_pm_flag_t pm_flags = 0;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001080 int i, ret;
1081
1082 chip = pci_get_drvdata(pdev);
1083 if (!chip)
1084 return 0;
1085
Ameya Palandeb177bc92011-04-05 21:13:13 +03001086 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001087 slot = chip->slots[i];
1088 if (!slot)
1089 continue;
1090
Manuel Lauss29495aa2011-11-03 11:09:45 +01001091 ret = sdhci_suspend_host(slot->host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001092
Axel Linb678b912011-12-03 15:28:05 +08001093 if (ret)
1094 goto err_pci_suspend;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001095
Daniel Drake5f619702010-11-04 22:20:39 +00001096 slot_pm_flags = slot->host->mmc->pm_flags;
1097 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1098 sdhci_enable_irq_wakeups(slot->host);
1099
1100 pm_flags |= slot_pm_flags;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001101 }
1102
Pierre Ossman44894282008-04-04 19:36:59 +02001103 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001104 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001105 if (ret)
1106 goto err_pci_suspend;
Pierre Ossman44894282008-04-04 19:36:59 +02001107 }
1108
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001109 pci_save_state(pdev);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001110 if (pm_flags & MMC_PM_KEEP_POWER) {
Daniel Drake5f619702010-11-04 22:20:39 +00001111 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) {
1112 pci_pme_active(pdev, true);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001113 pci_enable_wake(pdev, PCI_D3hot, 1);
Daniel Drake5f619702010-11-04 22:20:39 +00001114 }
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001115 pci_set_power_state(pdev, PCI_D3hot);
1116 } else {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001117 pci_enable_wake(pdev, PCI_D3hot, 0);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001118 pci_disable_device(pdev);
Manuel Lauss29495aa2011-11-03 11:09:45 +01001119 pci_set_power_state(pdev, PCI_D3hot);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001120 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001121
1122 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001123
1124err_pci_suspend:
1125 while (--i >= 0)
1126 sdhci_resume_host(chip->slots[i]->host);
1127 return ret;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001128}
1129
Manuel Lauss29495aa2011-11-03 11:09:45 +01001130static int sdhci_pci_resume(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001131{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001132 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001133 struct sdhci_pci_chip *chip;
1134 struct sdhci_pci_slot *slot;
1135 int i, ret;
1136
1137 chip = pci_get_drvdata(pdev);
1138 if (!chip)
1139 return 0;
1140
1141 pci_set_power_state(pdev, PCI_D0);
1142 pci_restore_state(pdev);
1143 ret = pci_enable_device(pdev);
1144 if (ret)
1145 return ret;
1146
Pierre Ossman45211e22008-03-24 13:09:09 +01001147 if (chip->fixes && chip->fixes->resume) {
1148 ret = chip->fixes->resume(chip);
1149 if (ret)
1150 return ret;
1151 }
1152
Ameya Palandeb177bc92011-04-05 21:13:13 +03001153 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001154 slot = chip->slots[i];
1155 if (!slot)
1156 continue;
1157
1158 ret = sdhci_resume_host(slot->host);
1159 if (ret)
1160 return ret;
1161 }
1162
1163 return 0;
1164}
1165
1166#else /* CONFIG_PM */
1167
1168#define sdhci_pci_suspend NULL
1169#define sdhci_pci_resume NULL
1170
1171#endif /* CONFIG_PM */
1172
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001173#ifdef CONFIG_PM_RUNTIME
1174
1175static int sdhci_pci_runtime_suspend(struct device *dev)
1176{
1177 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1178 struct sdhci_pci_chip *chip;
1179 struct sdhci_pci_slot *slot;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001180 int i, ret;
1181
1182 chip = pci_get_drvdata(pdev);
1183 if (!chip)
1184 return 0;
1185
1186 for (i = 0; i < chip->num_slots; i++) {
1187 slot = chip->slots[i];
1188 if (!slot)
1189 continue;
1190
1191 ret = sdhci_runtime_suspend_host(slot->host);
1192
Axel Linb678b912011-12-03 15:28:05 +08001193 if (ret)
1194 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001195 }
1196
1197 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001198 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001199 if (ret)
1200 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001201 }
1202
1203 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001204
1205err_pci_runtime_suspend:
1206 while (--i >= 0)
1207 sdhci_runtime_resume_host(chip->slots[i]->host);
1208 return ret;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001209}
1210
1211static int sdhci_pci_runtime_resume(struct device *dev)
1212{
1213 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1214 struct sdhci_pci_chip *chip;
1215 struct sdhci_pci_slot *slot;
1216 int i, ret;
1217
1218 chip = pci_get_drvdata(pdev);
1219 if (!chip)
1220 return 0;
1221
1222 if (chip->fixes && chip->fixes->resume) {
1223 ret = chip->fixes->resume(chip);
1224 if (ret)
1225 return ret;
1226 }
1227
1228 for (i = 0; i < chip->num_slots; i++) {
1229 slot = chip->slots[i];
1230 if (!slot)
1231 continue;
1232
1233 ret = sdhci_runtime_resume_host(slot->host);
1234 if (ret)
1235 return ret;
1236 }
1237
1238 return 0;
1239}
1240
1241static int sdhci_pci_runtime_idle(struct device *dev)
1242{
1243 return 0;
1244}
1245
1246#else
1247
1248#define sdhci_pci_runtime_suspend NULL
1249#define sdhci_pci_runtime_resume NULL
1250#define sdhci_pci_runtime_idle NULL
1251
1252#endif
1253
1254static const struct dev_pm_ops sdhci_pci_pm_ops = {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001255 .suspend = sdhci_pci_suspend,
1256 .resume = sdhci_pci_resume,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001257 .runtime_suspend = sdhci_pci_runtime_suspend,
1258 .runtime_resume = sdhci_pci_runtime_resume,
1259 .runtime_idle = sdhci_pci_runtime_idle,
1260};
1261
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001262/*****************************************************************************\
1263 * *
1264 * Device probing/removal *
1265 * *
1266\*****************************************************************************/
1267
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001268static struct sdhci_pci_slot *sdhci_pci_probe_slot(
Adrian Hunter52c506f2011-12-27 15:48:43 +02001269 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1270 int slotno)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001271{
1272 struct sdhci_pci_slot *slot;
1273 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001274 int ret, bar = first_bar + slotno;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001275
1276 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1277 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1278 return ERR_PTR(-ENODEV);
1279 }
1280
Adrian Hunter90b3e6c2012-10-18 09:54:31 +03001281 if (pci_resource_len(pdev, bar) < 0x100) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001282 dev_err(&pdev->dev, "Invalid iomem size. You may "
1283 "experience problems.\n");
1284 }
1285
1286 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1287 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1288 return ERR_PTR(-ENODEV);
1289 }
1290
1291 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1292 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1293 return ERR_PTR(-ENODEV);
1294 }
1295
1296 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1297 if (IS_ERR(host)) {
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001298 dev_err(&pdev->dev, "cannot allocate host\n");
Julia Lawalldc0fd7b2010-05-26 14:42:11 -07001299 return ERR_CAST(host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001300 }
1301
1302 slot = sdhci_priv(host);
1303
1304 slot->chip = chip;
1305 slot->host = host;
1306 slot->pci_bar = bar;
Adrian Hunter0f201652011-08-29 16:42:13 +03001307 slot->rst_n_gpio = -EINVAL;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001308 slot->cd_gpio = -EINVAL;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001309
Adrian Hunter52c506f2011-12-27 15:48:43 +02001310 /* Retrieve platform data if there is any */
1311 if (*sdhci_pci_get_data)
1312 slot->data = sdhci_pci_get_data(pdev, slotno);
1313
1314 if (slot->data) {
1315 if (slot->data->setup) {
1316 ret = slot->data->setup(slot->data);
1317 if (ret) {
1318 dev_err(&pdev->dev, "platform setup failed\n");
1319 goto free;
1320 }
1321 }
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001322 slot->rst_n_gpio = slot->data->rst_n_gpio;
1323 slot->cd_gpio = slot->data->cd_gpio;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001324 }
1325
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001326 host->hw_name = "PCI";
1327 host->ops = &sdhci_pci_ops;
1328 host->quirks = chip->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001329 host->quirks2 = chip->quirks2;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001330
1331 host->irq = pdev->irq;
1332
1333 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1334 if (ret) {
1335 dev_err(&pdev->dev, "cannot request region\n");
Adrian Hunter52c506f2011-12-27 15:48:43 +02001336 goto cleanup;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001337 }
1338
Arjan van de Ven092f82e2008-09-28 16:15:56 -07001339 host->ioaddr = pci_ioremap_bar(pdev, bar);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001340 if (!host->ioaddr) {
1341 dev_err(&pdev->dev, "failed to remap registers\n");
Chris Ball9fdcdbb2011-03-29 00:46:12 -04001342 ret = -ENOMEM;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001343 goto release;
1344 }
1345
Pierre Ossman44894282008-04-04 19:36:59 +02001346 if (chip->fixes && chip->fixes->probe_slot) {
1347 ret = chip->fixes->probe_slot(slot);
1348 if (ret)
1349 goto unmap;
1350 }
1351
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001352 if (gpio_is_valid(slot->rst_n_gpio)) {
1353 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1354 gpio_direction_output(slot->rst_n_gpio, 1);
1355 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
Adrian Hunterc9faff62013-06-13 11:50:26 +03001356 slot->hw_reset = sdhci_pci_gpio_hw_reset;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001357 } else {
1358 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1359 slot->rst_n_gpio = -EINVAL;
1360 }
1361 }
1362
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001363 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
Aaron Lueed222a2013-03-05 11:24:52 +08001364 host->mmc->slotno = slotno;
Adrian Huntera08b17b2013-04-15 11:27:25 -04001365 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001366
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001367 ret = sdhci_add_host(host);
1368 if (ret)
Pierre Ossman44894282008-04-04 19:36:59 +02001369 goto remove;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001370
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001371 sdhci_pci_add_own_cd(slot);
1372
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001373 return slot;
1374
Pierre Ossman44894282008-04-04 19:36:59 +02001375remove:
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001376 if (gpio_is_valid(slot->rst_n_gpio))
1377 gpio_free(slot->rst_n_gpio);
1378
Pierre Ossman44894282008-04-04 19:36:59 +02001379 if (chip->fixes && chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001380 chip->fixes->remove_slot(slot, 0);
Pierre Ossman44894282008-04-04 19:36:59 +02001381
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001382unmap:
1383 iounmap(host->ioaddr);
1384
1385release:
1386 pci_release_region(pdev, bar);
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001387
Adrian Hunter52c506f2011-12-27 15:48:43 +02001388cleanup:
1389 if (slot->data && slot->data->cleanup)
1390 slot->data->cleanup(slot->data);
1391
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001392free:
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001393 sdhci_free_host(host);
1394
1395 return ERR_PTR(ret);
1396}
1397
1398static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1399{
Pierre Ossman1e728592008-04-16 19:13:13 +02001400 int dead;
1401 u32 scratch;
1402
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001403 sdhci_pci_remove_own_cd(slot);
1404
Pierre Ossman1e728592008-04-16 19:13:13 +02001405 dead = 0;
1406 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1407 if (scratch == (u32)-1)
1408 dead = 1;
1409
1410 sdhci_remove_host(slot->host, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001411
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001412 if (gpio_is_valid(slot->rst_n_gpio))
1413 gpio_free(slot->rst_n_gpio);
1414
Pierre Ossman44894282008-04-04 19:36:59 +02001415 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001416 slot->chip->fixes->remove_slot(slot, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001417
Adrian Hunter52c506f2011-12-27 15:48:43 +02001418 if (slot->data && slot->data->cleanup)
1419 slot->data->cleanup(slot->data);
1420
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001421 pci_release_region(slot->chip->pdev, slot->pci_bar);
Pierre Ossman44894282008-04-04 19:36:59 +02001422
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001423 sdhci_free_host(slot->host);
1424}
1425
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001426static void sdhci_pci_runtime_pm_allow(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001427{
1428 pm_runtime_put_noidle(dev);
1429 pm_runtime_allow(dev);
1430 pm_runtime_set_autosuspend_delay(dev, 50);
1431 pm_runtime_use_autosuspend(dev);
1432 pm_suspend_ignore_children(dev, 1);
1433}
1434
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001435static void sdhci_pci_runtime_pm_forbid(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001436{
1437 pm_runtime_forbid(dev);
1438 pm_runtime_get_noresume(dev);
1439}
1440
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001441static int sdhci_pci_probe(struct pci_dev *pdev,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001442 const struct pci_device_id *ent)
1443{
1444 struct sdhci_pci_chip *chip;
1445 struct sdhci_pci_slot *slot;
1446
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001447 u8 slots, first_bar;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001448 int ret, i;
1449
1450 BUG_ON(pdev == NULL);
1451 BUG_ON(ent == NULL);
1452
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001453 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001454 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001455
1456 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1457 if (ret)
1458 return ret;
1459
1460 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1461 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1462 if (slots == 0)
1463 return -ENODEV;
1464
1465 BUG_ON(slots > MAX_SLOTS);
1466
1467 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1468 if (ret)
1469 return ret;
1470
1471 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1472
1473 if (first_bar > 5) {
1474 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1475 return -ENODEV;
1476 }
1477
1478 ret = pci_enable_device(pdev);
1479 if (ret)
1480 return ret;
1481
1482 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
1483 if (!chip) {
1484 ret = -ENOMEM;
1485 goto err;
1486 }
1487
1488 chip->pdev = pdev;
Ameya Palandeb177bc92011-04-05 21:13:13 +03001489 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001490 if (chip->fixes) {
Pierre Ossman22606402008-03-23 19:33:23 +01001491 chip->quirks = chip->fixes->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001492 chip->quirks2 = chip->fixes->quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001493 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1494 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001495 chip->num_slots = slots;
1496
1497 pci_set_drvdata(pdev, chip);
1498
Pierre Ossman22606402008-03-23 19:33:23 +01001499 if (chip->fixes && chip->fixes->probe) {
1500 ret = chip->fixes->probe(chip);
1501 if (ret)
1502 goto free;
1503 }
1504
Alan Cox225d85f2010-10-04 15:24:21 +01001505 slots = chip->num_slots; /* Quirk may have changed this */
1506
Ameya Palandeb177bc92011-04-05 21:13:13 +03001507 for (i = 0; i < slots; i++) {
Adrian Hunter52c506f2011-12-27 15:48:43 +02001508 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001509 if (IS_ERR(slot)) {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001510 for (i--; i >= 0; i--)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001511 sdhci_pci_remove_slot(chip->slots[i]);
1512 ret = PTR_ERR(slot);
1513 goto free;
1514 }
1515
1516 chip->slots[i] = slot;
1517 }
1518
Adrian Hunterc43fd772011-10-17 10:52:44 +03001519 if (chip->allow_runtime_pm)
1520 sdhci_pci_runtime_pm_allow(&pdev->dev);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001521
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001522 return 0;
1523
1524free:
1525 pci_set_drvdata(pdev, NULL);
1526 kfree(chip);
1527
1528err:
1529 pci_disable_device(pdev);
1530 return ret;
1531}
1532
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001533static void sdhci_pci_remove(struct pci_dev *pdev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001534{
1535 int i;
1536 struct sdhci_pci_chip *chip;
1537
1538 chip = pci_get_drvdata(pdev);
1539
1540 if (chip) {
Adrian Hunterc43fd772011-10-17 10:52:44 +03001541 if (chip->allow_runtime_pm)
1542 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1543
Ameya Palandeb177bc92011-04-05 21:13:13 +03001544 for (i = 0; i < chip->num_slots; i++)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001545 sdhci_pci_remove_slot(chip->slots[i]);
1546
1547 pci_set_drvdata(pdev, NULL);
1548 kfree(chip);
1549 }
1550
1551 pci_disable_device(pdev);
1552}
1553
1554static struct pci_driver sdhci_driver = {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001555 .name = "sdhci-pci",
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001556 .id_table = pci_ids,
Ameya Palandeb177bc92011-04-05 21:13:13 +03001557 .probe = sdhci_pci_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -05001558 .remove = sdhci_pci_remove,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001559 .driver = {
1560 .pm = &sdhci_pci_pm_ops
1561 },
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001562};
1563
Sachin Kamatacc69642012-08-27 11:57:02 +05301564module_pci_driver(sdhci_driver);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001565
Pierre Ossman32710e82009-04-08 20:14:54 +02001566MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001567MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1568MODULE_LICENSE("GPL");