blob: cfe8a2c85987fd7d5af440d9c6cb7e14b1b86f70 [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
Derek Browne43e968c2014-06-24 06:56:36 -0700106static const struct sdhci_pci_fixes sdhci_intel_qrk = {
107 .quirks = SDHCI_QUIRK_NO_HISPD_BIT,
108};
109
Major Lee68077b02011-06-29 14:23:46 +0300110static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
111{
112 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
113 return 0;
114}
115
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100116/*
117 * ADMA operation is disabled for Moorestown platform due to
118 * hardware bugs.
119 */
Jacob Pan35ac6f02010-11-09 13:57:29 +0000120static int mrst_hc_probe(struct sdhci_pci_chip *chip)
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100121{
122 /*
Jacob Pan35ac6f02010-11-09 13:57:29 +0000123 * slots number is fixed here for MRST as SDIO3/5 are never used and
124 * have hardware bugs.
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100125 */
126 chip->num_slots = 1;
127 return 0;
128}
129
Alexander Stein296e0b02012-03-14 08:38:58 +0100130static int pch_hc_probe_slot(struct sdhci_pci_slot *slot)
131{
132 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
133 return 0;
134}
135
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300136#ifdef CONFIG_PM_RUNTIME
137
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200138static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300139{
140 struct sdhci_pci_slot *slot = dev_id;
141 struct sdhci_host *host = slot->host;
142
143 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
144 return IRQ_HANDLED;
145}
146
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200147static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300148{
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200149 int err, irq, gpio = slot->cd_gpio;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300150
151 slot->cd_gpio = -EINVAL;
152 slot->cd_irq = -EINVAL;
153
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200154 if (!gpio_is_valid(gpio))
155 return;
156
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300157 err = gpio_request(gpio, "sd_cd");
158 if (err < 0)
159 goto out;
160
161 err = gpio_direction_input(gpio);
162 if (err < 0)
163 goto out_free;
164
165 irq = gpio_to_irq(gpio);
166 if (irq < 0)
167 goto out_free;
168
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200169 err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300170 IRQF_TRIGGER_FALLING, "sd_cd", slot);
171 if (err)
172 goto out_free;
173
174 slot->cd_gpio = gpio;
175 slot->cd_irq = irq;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300176
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200177 return;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300178
179out_free:
180 gpio_free(gpio);
181out:
182 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300183}
184
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200185static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300186{
187 if (slot->cd_irq >= 0)
188 free_irq(slot->cd_irq, slot);
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200189 if (gpio_is_valid(slot->cd_gpio))
190 gpio_free(slot->cd_gpio);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300191}
192
193#else
194
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200195static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
196{
197}
198
199static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
200{
201}
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300202
203#endif
204
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300205static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
206{
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300207 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
Adrian Hunterda721cf2012-02-07 14:48:53 +0200208 slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
209 MMC_CAP2_HC_ERASE_SZ;
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300210 return 0;
211}
212
Adrian Hunter93933502011-12-27 15:48:47 +0200213static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
214{
Adrian Hunter012e4672012-01-30 14:27:18 +0200215 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
Adrian Hunter93933502011-12-27 15:48:47 +0200216 return 0;
217}
218
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100219static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
220 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Major Lee68077b02011-06-29 14:23:46 +0300221 .probe_slot = mrst_hc_probe_slot,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100222};
223
Jacob Pan35ac6f02010-11-09 13:57:29 +0000224static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100225 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000226 .probe = mrst_hc_probe,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100227};
228
Xiaochen Shen29229052010-10-04 15:24:52 +0100229static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
230 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300231 .allow_runtime_pm = true,
Adrian Hunter77a01222014-01-13 09:49:16 +0200232 .own_cd_for_runtime_pm = true,
Xiaochen Shen29229052010-10-04 15:24:52 +0100233};
234
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300235static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
Xiaochen Shen29229052010-10-04 15:24:52 +0100236 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterf3c55a72012-02-07 14:48:55 +0200237 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300238 .allow_runtime_pm = true,
Adrian Hunter93933502011-12-27 15:48:47 +0200239 .probe_slot = mfd_sdio_probe_slot,
Xiaochen Shen29229052010-10-04 15:24:52 +0100240};
241
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300242static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
243 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300244 .allow_runtime_pm = true,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300245 .probe_slot = mfd_emmc_probe_slot,
246};
247
Alexander Stein296e0b02012-03-14 08:38:58 +0100248static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = {
249 .quirks = SDHCI_QUIRK_BROKEN_ADMA,
250 .probe_slot = pch_hc_probe_slot,
251};
252
Adrian Hunterc9faff62013-06-13 11:50:26 +0300253static void sdhci_pci_int_hw_reset(struct sdhci_host *host)
254{
255 u8 reg;
256
257 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
258 reg |= 0x10;
259 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
260 /* For eMMC, minimum is 1us but give it 9us for good measure */
261 udelay(9);
262 reg &= ~0x10;
263 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
264 /* For eMMC, minimum is 200us but give it 300us for good measure */
265 usleep_range(300, 1000);
266}
267
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300268static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
269{
Adrian Hunterc9faff62013-06-13 11:50:26 +0300270 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
Maurice Petallof25c3372014-07-08 19:11:01 +0800271 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR;
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300272 slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
Adrian Hunterc9faff62013-06-13 11:50:26 +0300273 slot->hw_reset = sdhci_pci_int_hw_reset;
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300274 return 0;
275}
276
277static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
278{
279 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
280 return 0;
281}
282
283static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
284 .allow_runtime_pm = true,
285 .probe_slot = byt_emmc_probe_slot,
Maurice Petallod61b5942014-07-08 19:11:00 +0800286 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300287};
288
289static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
290 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
291 .allow_runtime_pm = true,
292 .probe_slot = byt_sdio_probe_slot,
293};
294
295static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
Adrian Hunter7396e312013-05-06 12:17:34 +0300296 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON,
297 .allow_runtime_pm = true,
Adrian Hunter77a01222014-01-13 09:49:16 +0200298 .own_cd_for_runtime_pm = true,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300299};
300
David Cohen8776a162013-10-01 13:18:15 -0700301/* Define Host controllers for Intel Merrifield platform */
302#define INTEL_MRFL_EMMC_0 0
303#define INTEL_MRFL_EMMC_1 1
304
305static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
306{
307 if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_0) &&
308 (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_1))
309 /* SD support is not ready yet */
310 return -ENODEV;
311
312 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
313 MMC_CAP_1_8V_DDR;
314
315 return 0;
316}
317
318static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
319 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
David Cohen390145f2013-10-29 10:58:27 -0700320 .quirks2 = SDHCI_QUIRK2_BROKEN_HS200,
David Cohen8776a162013-10-01 13:18:15 -0700321 .probe_slot = intel_mrfl_mmc_probe_slot,
322};
323
Jennifer Li26daa1e2010-11-17 23:01:59 -0500324/* O2Micro extra registers */
325#define O2_SD_LOCK_WP 0xD3
326#define O2_SD_MULTI_VCC3V 0xEE
327#define O2_SD_CLKREQ 0xEC
328#define O2_SD_CAPS 0xE0
329#define O2_SD_ADMA1 0xE2
330#define O2_SD_ADMA2 0xE7
331#define O2_SD_INF_MOD 0xF1
332
Pierre Ossman45211e22008-03-24 13:09:09 +0100333static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
334{
335 u8 scratch;
336 int ret;
337
338 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
339 if (ret)
340 return ret;
341
342 /*
343 * Turn PMOS on [bit 0], set over current detection to 2.4 V
344 * [bit 1:2] and enable over current debouncing [bit 6].
345 */
346 if (on)
347 scratch |= 0x47;
348 else
349 scratch &= ~0x47;
350
351 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
352 if (ret)
353 return ret;
354
355 return 0;
356}
357
358static int jmicron_probe(struct sdhci_pci_chip *chip)
359{
360 int ret;
Takashi Iwai8f230f42010-12-08 10:04:30 +0100361 u16 mmcdev = 0;
Pierre Ossman45211e22008-03-24 13:09:09 +0100362
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200363 if (chip->pdev->revision == 0) {
364 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
365 SDHCI_QUIRK_32BIT_DMA_SIZE |
Pierre Ossman2134a922008-06-28 18:28:51 +0200366 SDHCI_QUIRK_32BIT_ADMA_SIZE |
Pierre Ossman4a3cba32008-07-29 00:11:16 +0200367 SDHCI_QUIRK_RESET_AFTER_REQUEST |
Pierre Ossman86a6a872009-02-02 21:13:49 +0100368 SDHCI_QUIRK_BROKEN_SMALL_PIO;
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200369 }
370
Pierre Ossman45211e22008-03-24 13:09:09 +0100371 /*
Pierre Ossman44894282008-04-04 19:36:59 +0200372 * JMicron chips can have two interfaces to the same hardware
373 * in order to work around limitations in Microsoft's driver.
374 * We need to make sure we only bind to one of them.
375 *
376 * This code assumes two things:
377 *
378 * 1. The PCI code adds subfunctions in order.
379 *
380 * 2. The MMC interface has a lower subfunction number
381 * than the SD interface.
382 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100383 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
384 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
385 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
386 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
387
388 if (mmcdev) {
Pierre Ossman44894282008-04-04 19:36:59 +0200389 struct pci_dev *sd_dev;
390
391 sd_dev = NULL;
392 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
Takashi Iwai8f230f42010-12-08 10:04:30 +0100393 mmcdev, sd_dev)) != NULL) {
Pierre Ossman44894282008-04-04 19:36:59 +0200394 if ((PCI_SLOT(chip->pdev->devfn) ==
395 PCI_SLOT(sd_dev->devfn)) &&
396 (chip->pdev->bus == sd_dev->bus))
397 break;
398 }
399
400 if (sd_dev) {
401 pci_dev_put(sd_dev);
402 dev_info(&chip->pdev->dev, "Refusing to bind to "
403 "secondary interface.\n");
404 return -ENODEV;
405 }
406 }
407
408 /*
Pierre Ossman45211e22008-03-24 13:09:09 +0100409 * JMicron chips need a bit of a nudge to enable the power
410 * output pins.
411 */
412 ret = jmicron_pmos(chip, 1);
413 if (ret) {
414 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
415 return ret;
416 }
417
Takashi Iwai82b0e232011-04-21 20:26:38 +0200418 /* quirk for unsable RO-detection on JM388 chips */
419 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
420 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
421 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
422
Pierre Ossman45211e22008-03-24 13:09:09 +0100423 return 0;
424}
425
Pierre Ossman44894282008-04-04 19:36:59 +0200426static void jmicron_enable_mmc(struct sdhci_host *host, int on)
427{
428 u8 scratch;
429
430 scratch = readb(host->ioaddr + 0xC0);
431
432 if (on)
433 scratch |= 0x01;
434 else
435 scratch &= ~0x01;
436
437 writeb(scratch, host->ioaddr + 0xC0);
438}
439
440static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
441{
Pierre Ossman2134a922008-06-28 18:28:51 +0200442 if (slot->chip->pdev->revision == 0) {
443 u16 version;
444
445 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
446 version = (version & SDHCI_VENDOR_VER_MASK) >>
447 SDHCI_VENDOR_VER_SHIFT;
448
449 /*
450 * Older versions of the chip have lots of nasty glitches
451 * in the ADMA engine. It's best just to avoid it
452 * completely.
453 */
454 if (version < 0xAC)
455 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
456 }
457
Takashi Iwai8f230f42010-12-08 10:04:30 +0100458 /* JM388 MMC doesn't support 1.8V while SD supports it */
459 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
460 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
461 MMC_VDD_29_30 | MMC_VDD_30_31 |
462 MMC_VDD_165_195; /* allow 1.8V */
463 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
464 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
465 }
466
Pierre Ossman44894282008-04-04 19:36:59 +0200467 /*
468 * The secondary interface requires a bit set to get the
469 * interrupts.
470 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100471 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
472 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200473 jmicron_enable_mmc(slot->host, 1);
474
Takashi Iwaid75c1082010-12-16 17:54:14 +0100475 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
476
Pierre Ossman44894282008-04-04 19:36:59 +0200477 return 0;
478}
479
Pierre Ossman1e728592008-04-16 19:13:13 +0200480static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
Pierre Ossman44894282008-04-04 19:36:59 +0200481{
Pierre Ossman1e728592008-04-16 19:13:13 +0200482 if (dead)
483 return;
484
Takashi Iwai8f230f42010-12-08 10:04:30 +0100485 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
486 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200487 jmicron_enable_mmc(slot->host, 0);
488}
489
Manuel Lauss29495aa2011-11-03 11:09:45 +0100490static int jmicron_suspend(struct sdhci_pci_chip *chip)
Pierre Ossman44894282008-04-04 19:36:59 +0200491{
492 int i;
493
Takashi Iwai8f230f42010-12-08 10:04:30 +0100494 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
495 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300496 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200497 jmicron_enable_mmc(chip->slots[i]->host, 0);
498 }
499
500 return 0;
501}
502
Pierre Ossman45211e22008-03-24 13:09:09 +0100503static int jmicron_resume(struct sdhci_pci_chip *chip)
504{
Pierre Ossman44894282008-04-04 19:36:59 +0200505 int ret, i;
506
Takashi Iwai8f230f42010-12-08 10:04:30 +0100507 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
508 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300509 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200510 jmicron_enable_mmc(chip->slots[i]->host, 1);
511 }
Pierre Ossman45211e22008-03-24 13:09:09 +0100512
513 ret = jmicron_pmos(chip, 1);
514 if (ret) {
515 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
516 return ret;
517 }
518
519 return 0;
520}
521
Jennifer Li26daa1e2010-11-17 23:01:59 -0500522static const struct sdhci_pci_fixes sdhci_o2 = {
Adam Lee01acf692013-12-19 00:01:26 +0800523 .probe = sdhci_pci_o2_probe,
524 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
525 .probe_slot = sdhci_pci_o2_probe_slot,
526 .resume = sdhci_pci_o2_resume,
Jennifer Li26daa1e2010-11-17 23:01:59 -0500527};
528
Pierre Ossman22606402008-03-23 19:33:23 +0100529static const struct sdhci_pci_fixes sdhci_jmicron = {
Pierre Ossman45211e22008-03-24 13:09:09 +0100530 .probe = jmicron_probe,
531
Pierre Ossman44894282008-04-04 19:36:59 +0200532 .probe_slot = jmicron_probe_slot,
533 .remove_slot = jmicron_remove_slot,
534
535 .suspend = jmicron_suspend,
Pierre Ossman45211e22008-03-24 13:09:09 +0100536 .resume = jmicron_resume,
Pierre Ossman22606402008-03-23 19:33:23 +0100537};
538
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800539/* SysKonnect CardBus2SDIO extra registers */
540#define SYSKT_CTRL 0x200
541#define SYSKT_RDFIFO_STAT 0x204
542#define SYSKT_WRFIFO_STAT 0x208
543#define SYSKT_POWER_DATA 0x20c
544#define SYSKT_POWER_330 0xef
545#define SYSKT_POWER_300 0xf8
546#define SYSKT_POWER_184 0xcc
547#define SYSKT_POWER_CMD 0x20d
548#define SYSKT_POWER_START (1 << 7)
549#define SYSKT_POWER_STATUS 0x20e
550#define SYSKT_POWER_STATUS_OK (1 << 0)
551#define SYSKT_BOARD_REV 0x210
552#define SYSKT_CHIP_REV 0x211
553#define SYSKT_CONF_DATA 0x212
554#define SYSKT_CONF_DATA_1V8 (1 << 2)
555#define SYSKT_CONF_DATA_2V5 (1 << 1)
556#define SYSKT_CONF_DATA_3V3 (1 << 0)
557
558static int syskt_probe(struct sdhci_pci_chip *chip)
559{
560 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
561 chip->pdev->class &= ~0x0000FF;
562 chip->pdev->class |= PCI_SDHCI_IFDMA;
563 }
564 return 0;
565}
566
567static int syskt_probe_slot(struct sdhci_pci_slot *slot)
568{
569 int tm, ps;
570
571 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
572 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
573 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
574 "board rev %d.%d, chip rev %d.%d\n",
575 board_rev >> 4, board_rev & 0xf,
576 chip_rev >> 4, chip_rev & 0xf);
577 if (chip_rev >= 0x20)
578 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
579
580 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
581 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
582 udelay(50);
583 tm = 10; /* Wait max 1 ms */
584 do {
585 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
586 if (ps & SYSKT_POWER_STATUS_OK)
587 break;
588 udelay(100);
589 } while (--tm);
590 if (!tm) {
591 dev_err(&slot->chip->pdev->dev,
592 "power regulator never stabilized");
593 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
594 return -ENODEV;
595 }
596
597 return 0;
598}
599
600static const struct sdhci_pci_fixes sdhci_syskt = {
601 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
602 .probe = syskt_probe,
603 .probe_slot = syskt_probe_slot,
604};
605
Harald Welte557b0692009-06-18 16:53:38 +0200606static int via_probe(struct sdhci_pci_chip *chip)
607{
608 if (chip->pdev->revision == 0x10)
609 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
610
611 return 0;
612}
613
614static const struct sdhci_pci_fixes sdhci_via = {
615 .probe = via_probe,
616};
617
Micky Ching9107ebb2014-02-21 18:40:35 +0800618static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
619{
620 slot->host->mmc->caps2 |= MMC_CAP2_HS200;
621 return 0;
622}
623
624static const struct sdhci_pci_fixes sdhci_rtsx = {
625 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
626 SDHCI_QUIRK2_BROKEN_DDR50,
627 .probe_slot = rtsx_probe_slot,
628};
629
Bill Pemberton9647f842012-11-19 13:25:11 -0500630static const struct pci_device_id pci_ids[] = {
Pierre Ossman22606402008-03-23 19:33:23 +0100631 {
632 .vendor = PCI_VENDOR_ID_RICOH,
633 .device = PCI_DEVICE_ID_RICOH_R5C822,
634 .subvendor = PCI_ANY_ID,
635 .subdevice = PCI_ANY_ID,
636 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
637 },
638
639 {
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700640 .vendor = PCI_VENDOR_ID_RICOH,
641 .device = 0x843,
642 .subvendor = PCI_ANY_ID,
643 .subdevice = PCI_ANY_ID,
644 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
645 },
646
647 {
Pablo Castillo568133e2010-08-10 18:02:01 -0700648 .vendor = PCI_VENDOR_ID_RICOH,
649 .device = 0xe822,
650 .subvendor = PCI_ANY_ID,
651 .subdevice = PCI_ANY_ID,
652 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
653 },
654
655 {
Manoj Iyer5fd11c02011-02-11 16:25:31 -0600656 .vendor = PCI_VENDOR_ID_RICOH,
657 .device = 0xe823,
658 .subvendor = PCI_ANY_ID,
659 .subdevice = PCI_ANY_ID,
660 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
661 },
662
663 {
Pierre Ossman22606402008-03-23 19:33:23 +0100664 .vendor = PCI_VENDOR_ID_ENE,
665 .device = PCI_DEVICE_ID_ENE_CB712_SD,
666 .subvendor = PCI_ANY_ID,
667 .subdevice = PCI_ANY_ID,
668 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
669 },
670
671 {
672 .vendor = PCI_VENDOR_ID_ENE,
673 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
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_CB714_SD,
682 .subvendor = PCI_ANY_ID,
683 .subdevice = PCI_ANY_ID,
684 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
685 },
686
687 {
688 .vendor = PCI_VENDOR_ID_ENE,
689 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
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_MARVELL,
David Woodhouse8c5eb882008-09-03 09:45:57 +0100697 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
Pierre Ossman22606402008-03-23 19:33:23 +0100698 .subvendor = PCI_ANY_ID,
699 .subdevice = PCI_ANY_ID,
700 .driver_data = (kernel_ulong_t)&sdhci_cafe,
701 },
702
703 {
704 .vendor = PCI_VENDOR_ID_JMICRON,
705 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
706 .subvendor = PCI_ANY_ID,
707 .subdevice = PCI_ANY_ID,
708 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
709 },
710
Pierre Ossman44894282008-04-04 19:36:59 +0200711 {
712 .vendor = PCI_VENDOR_ID_JMICRON,
713 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
714 .subvendor = PCI_ANY_ID,
715 .subdevice = PCI_ANY_ID,
716 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
717 },
718
Harald Welte557b0692009-06-18 16:53:38 +0200719 {
Takashi Iwai8f230f42010-12-08 10:04:30 +0100720 .vendor = PCI_VENDOR_ID_JMICRON,
721 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
722 .subvendor = PCI_ANY_ID,
723 .subdevice = PCI_ANY_ID,
724 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
725 },
726
727 {
728 .vendor = PCI_VENDOR_ID_JMICRON,
729 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
730 .subvendor = PCI_ANY_ID,
731 .subdevice = PCI_ANY_ID,
732 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
733 },
734
735 {
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800736 .vendor = PCI_VENDOR_ID_SYSKONNECT,
737 .device = 0x8000,
738 .subvendor = PCI_ANY_ID,
739 .subdevice = PCI_ANY_ID,
740 .driver_data = (kernel_ulong_t)&sdhci_syskt,
741 },
742
743 {
Harald Welte557b0692009-06-18 16:53:38 +0200744 .vendor = PCI_VENDOR_ID_VIA,
745 .device = 0x95d0,
746 .subvendor = PCI_ANY_ID,
747 .subdevice = PCI_ANY_ID,
748 .driver_data = (kernel_ulong_t)&sdhci_via,
749 },
750
Xiaochen Shen29229052010-10-04 15:24:52 +0100751 {
Micky Ching9107ebb2014-02-21 18:40:35 +0800752 .vendor = PCI_VENDOR_ID_REALTEK,
753 .device = 0x5250,
754 .subvendor = PCI_ANY_ID,
755 .subdevice = PCI_ANY_ID,
756 .driver_data = (kernel_ulong_t)&sdhci_rtsx,
757 },
758
759 {
Xiaochen Shen29229052010-10-04 15:24:52 +0100760 .vendor = PCI_VENDOR_ID_INTEL,
Derek Browne43e968c2014-06-24 06:56:36 -0700761 .device = PCI_DEVICE_ID_INTEL_QRK_SD,
762 .subvendor = PCI_ANY_ID,
763 .subdevice = PCI_ANY_ID,
764 .driver_data = (kernel_ulong_t)&sdhci_intel_qrk,
765 },
766
767 {
768 .vendor = PCI_VENDOR_ID_INTEL,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100769 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
770 .subvendor = PCI_ANY_ID,
771 .subdevice = PCI_ANY_ID,
772 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
773 },
774
775 {
776 .vendor = PCI_VENDOR_ID_INTEL,
777 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
778 .subvendor = PCI_ANY_ID,
779 .subdevice = PCI_ANY_ID,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000780 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
781 },
782
783 {
784 .vendor = PCI_VENDOR_ID_INTEL,
785 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
786 .subvendor = PCI_ANY_ID,
787 .subdevice = PCI_ANY_ID,
788 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100789 },
790
791 {
792 .vendor = PCI_VENDOR_ID_INTEL,
Xiaochen Shen29229052010-10-04 15:24:52 +0100793 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
794 .subvendor = PCI_ANY_ID,
795 .subdevice = PCI_ANY_ID,
796 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
797 },
798
799 {
800 .vendor = PCI_VENDOR_ID_INTEL,
801 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
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_SDIO2,
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_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100813 },
814
815 {
816 .vendor = PCI_VENDOR_ID_INTEL,
817 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
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
823 {
824 .vendor = PCI_VENDOR_ID_INTEL,
825 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
826 .subvendor = PCI_ANY_ID,
827 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300828 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100829 },
830
Jennifer Li26daa1e2010-11-17 23:01:59 -0500831 {
Alexander Stein296e0b02012-03-14 08:38:58 +0100832 .vendor = PCI_VENDOR_ID_INTEL,
833 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
834 .subvendor = PCI_ANY_ID,
835 .subdevice = PCI_ANY_ID,
836 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
837 },
838
839 {
840 .vendor = PCI_VENDOR_ID_INTEL,
841 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
842 .subvendor = PCI_ANY_ID,
843 .subdevice = PCI_ANY_ID,
844 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
845 },
846
847 {
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300848 .vendor = PCI_VENDOR_ID_INTEL,
849 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC,
850 .subvendor = PCI_ANY_ID,
851 .subdevice = PCI_ANY_ID,
852 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
853 },
854
855 {
856 .vendor = PCI_VENDOR_ID_INTEL,
857 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
858 .subvendor = PCI_ANY_ID,
859 .subdevice = PCI_ANY_ID,
860 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
861 },
862
863 {
864 .vendor = PCI_VENDOR_ID_INTEL,
865 .device = PCI_DEVICE_ID_INTEL_BYT_SD,
866 .subvendor = PCI_ANY_ID,
867 .subdevice = PCI_ANY_ID,
868 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
869 },
870
871 {
Adrian Hunter30d025c2013-06-20 12:57:59 +0300872 .vendor = PCI_VENDOR_ID_INTEL,
873 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2,
874 .subvendor = PCI_ANY_ID,
875 .subdevice = PCI_ANY_ID,
876 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
877 },
878
Alan Cox066173b2014-08-20 13:27:44 +0300879 {
880 .vendor = PCI_VENDOR_ID_INTEL,
881 .device = PCI_DEVICE_ID_INTEL_BSW_EMMC,
882 .subvendor = PCI_ANY_ID,
883 .subdevice = PCI_ANY_ID,
884 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
885 },
886
887 {
888 .vendor = PCI_VENDOR_ID_INTEL,
889 .device = PCI_DEVICE_ID_INTEL_BSW_SDIO,
890 .subvendor = PCI_ANY_ID,
891 .subdevice = PCI_ANY_ID,
892 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
893 },
894
895 {
896 .vendor = PCI_VENDOR_ID_INTEL,
897 .device = PCI_DEVICE_ID_INTEL_BSW_SD,
898 .subvendor = PCI_ANY_ID,
899 .subdevice = PCI_ANY_ID,
900 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
901 },
Eric Ernstd0520682013-10-21 09:54:41 -0700902
903 {
904 .vendor = PCI_VENDOR_ID_INTEL,
905 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
906 .subvendor = PCI_ANY_ID,
907 .subdevice = PCI_ANY_ID,
908 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
909 },
910
911 {
912 .vendor = PCI_VENDOR_ID_INTEL,
913 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
914 .subvendor = PCI_ANY_ID,
915 .subdevice = PCI_ANY_ID,
916 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
917 },
918
919 {
920 .vendor = PCI_VENDOR_ID_INTEL,
921 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
922 .subvendor = PCI_ANY_ID,
923 .subdevice = PCI_ANY_ID,
924 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
925 },
926
927 {
928 .vendor = PCI_VENDOR_ID_INTEL,
929 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
930 .subvendor = PCI_ANY_ID,
931 .subdevice = PCI_ANY_ID,
932 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
933 },
934
935 {
936 .vendor = PCI_VENDOR_ID_INTEL,
937 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
938 .subvendor = PCI_ANY_ID,
939 .subdevice = PCI_ANY_ID,
940 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
941 },
942
Adrian Hunter30d025c2013-06-20 12:57:59 +0300943 {
David Cohen8776a162013-10-01 13:18:15 -0700944 .vendor = PCI_VENDOR_ID_INTEL,
945 .device = PCI_DEVICE_ID_INTEL_MRFL_MMC,
946 .subvendor = PCI_ANY_ID,
947 .subdevice = PCI_ANY_ID,
948 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
949 },
950 {
Jennifer Li26daa1e2010-11-17 23:01:59 -0500951 .vendor = PCI_VENDOR_ID_O2,
952 .device = PCI_DEVICE_ID_O2_8120,
953 .subvendor = PCI_ANY_ID,
954 .subdevice = PCI_ANY_ID,
955 .driver_data = (kernel_ulong_t)&sdhci_o2,
956 },
957
958 {
959 .vendor = PCI_VENDOR_ID_O2,
960 .device = PCI_DEVICE_ID_O2_8220,
961 .subvendor = PCI_ANY_ID,
962 .subdevice = PCI_ANY_ID,
963 .driver_data = (kernel_ulong_t)&sdhci_o2,
964 },
965
966 {
967 .vendor = PCI_VENDOR_ID_O2,
968 .device = PCI_DEVICE_ID_O2_8221,
969 .subvendor = PCI_ANY_ID,
970 .subdevice = PCI_ANY_ID,
971 .driver_data = (kernel_ulong_t)&sdhci_o2,
972 },
973
974 {
975 .vendor = PCI_VENDOR_ID_O2,
976 .device = PCI_DEVICE_ID_O2_8320,
977 .subvendor = PCI_ANY_ID,
978 .subdevice = PCI_ANY_ID,
979 .driver_data = (kernel_ulong_t)&sdhci_o2,
980 },
981
982 {
983 .vendor = PCI_VENDOR_ID_O2,
984 .device = PCI_DEVICE_ID_O2_8321,
985 .subvendor = PCI_ANY_ID,
986 .subdevice = PCI_ANY_ID,
987 .driver_data = (kernel_ulong_t)&sdhci_o2,
988 },
989
Adam Lee01acf692013-12-19 00:01:26 +0800990 {
991 .vendor = PCI_VENDOR_ID_O2,
992 .device = PCI_DEVICE_ID_O2_FUJIN2,
993 .subvendor = PCI_ANY_ID,
994 .subdevice = PCI_ANY_ID,
995 .driver_data = (kernel_ulong_t)&sdhci_o2,
996 },
997
998 {
999 .vendor = PCI_VENDOR_ID_O2,
1000 .device = PCI_DEVICE_ID_O2_SDS0,
1001 .subvendor = PCI_ANY_ID,
1002 .subdevice = PCI_ANY_ID,
1003 .driver_data = (kernel_ulong_t)&sdhci_o2,
1004 },
1005
1006 {
1007 .vendor = PCI_VENDOR_ID_O2,
1008 .device = PCI_DEVICE_ID_O2_SDS1,
1009 .subvendor = PCI_ANY_ID,
1010 .subdevice = PCI_ANY_ID,
1011 .driver_data = (kernel_ulong_t)&sdhci_o2,
1012 },
1013
1014 {
1015 .vendor = PCI_VENDOR_ID_O2,
1016 .device = PCI_DEVICE_ID_O2_SEABIRD0,
1017 .subvendor = PCI_ANY_ID,
1018 .subdevice = PCI_ANY_ID,
1019 .driver_data = (kernel_ulong_t)&sdhci_o2,
1020 },
1021
1022 {
1023 .vendor = PCI_VENDOR_ID_O2,
1024 .device = PCI_DEVICE_ID_O2_SEABIRD1,
1025 .subvendor = PCI_ANY_ID,
1026 .subdevice = PCI_ANY_ID,
1027 .driver_data = (kernel_ulong_t)&sdhci_o2,
1028 },
1029
Pierre Ossman22606402008-03-23 19:33:23 +01001030 { /* Generic SD host controller */
1031 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
1032 },
1033
1034 { /* end: all zeroes */ },
1035};
1036
1037MODULE_DEVICE_TABLE(pci, pci_ids);
1038
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001039/*****************************************************************************\
1040 * *
1041 * SDHCI core callbacks *
1042 * *
1043\*****************************************************************************/
1044
1045static int sdhci_pci_enable_dma(struct sdhci_host *host)
1046{
1047 struct sdhci_pci_slot *slot;
1048 struct pci_dev *pdev;
1049 int ret;
1050
1051 slot = sdhci_priv(host);
1052 pdev = slot->chip->pdev;
1053
1054 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
1055 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
Richard Röjforsa13abc72009-09-22 16:45:30 -07001056 (host->flags & SDHCI_USE_SDMA)) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001057 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
1058 "doesn't fully claim to support it.\n");
1059 }
1060
Yang Hongyang284901a2009-04-06 19:01:15 -07001061 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001062 if (ret)
1063 return ret;
1064
1065 pci_set_master(pdev);
1066
1067 return 0;
1068}
1069
Russell King2317f562014-04-25 12:57:07 +01001070static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width)
Major Lee68077b02011-06-29 14:23:46 +03001071{
1072 u8 ctrl;
1073
1074 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1075
1076 switch (width) {
1077 case MMC_BUS_WIDTH_8:
1078 ctrl |= SDHCI_CTRL_8BITBUS;
1079 ctrl &= ~SDHCI_CTRL_4BITBUS;
1080 break;
1081 case MMC_BUS_WIDTH_4:
1082 ctrl |= SDHCI_CTRL_4BITBUS;
1083 ctrl &= ~SDHCI_CTRL_8BITBUS;
1084 break;
1085 default:
1086 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
1087 break;
1088 }
1089
1090 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
Major Lee68077b02011-06-29 14:23:46 +03001091}
1092
Adrian Hunterc9faff62013-06-13 11:50:26 +03001093static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
Adrian Hunter0f201652011-08-29 16:42:13 +03001094{
1095 struct sdhci_pci_slot *slot = sdhci_priv(host);
1096 int rst_n_gpio = slot->rst_n_gpio;
1097
1098 if (!gpio_is_valid(rst_n_gpio))
1099 return;
1100 gpio_set_value_cansleep(rst_n_gpio, 0);
1101 /* For eMMC, minimum is 1us but give it 10us for good measure */
1102 udelay(10);
1103 gpio_set_value_cansleep(rst_n_gpio, 1);
1104 /* For eMMC, minimum is 200us but give it 300us for good measure */
1105 usleep_range(300, 1000);
1106}
1107
Adrian Hunterc9faff62013-06-13 11:50:26 +03001108static void sdhci_pci_hw_reset(struct sdhci_host *host)
1109{
1110 struct sdhci_pci_slot *slot = sdhci_priv(host);
1111
1112 if (slot->hw_reset)
1113 slot->hw_reset(host);
1114}
1115
Lars-Peter Clausenc9155682013-03-13 19:26:05 +01001116static const struct sdhci_ops sdhci_pci_ops = {
Russell King17710592014-04-25 12:58:55 +01001117 .set_clock = sdhci_set_clock,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001118 .enable_dma = sdhci_pci_enable_dma,
Russell King2317f562014-04-25 12:57:07 +01001119 .set_bus_width = sdhci_pci_set_bus_width,
Russell King03231f92014-04-25 12:57:12 +01001120 .reset = sdhci_reset,
Russell King96d7b782014-04-25 12:59:26 +01001121 .set_uhs_signaling = sdhci_set_uhs_signaling,
Adrian Hunter0f201652011-08-29 16:42:13 +03001122 .hw_reset = sdhci_pci_hw_reset,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001123};
1124
1125/*****************************************************************************\
1126 * *
1127 * Suspend/resume *
1128 * *
1129\*****************************************************************************/
1130
1131#ifdef CONFIG_PM
1132
Manuel Lauss29495aa2011-11-03 11:09:45 +01001133static int sdhci_pci_suspend(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001134{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001135 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001136 struct sdhci_pci_chip *chip;
1137 struct sdhci_pci_slot *slot;
Daniel Drake5f619702010-11-04 22:20:39 +00001138 mmc_pm_flag_t slot_pm_flags;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001139 mmc_pm_flag_t pm_flags = 0;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001140 int i, ret;
1141
1142 chip = pci_get_drvdata(pdev);
1143 if (!chip)
1144 return 0;
1145
Ameya Palandeb177bc92011-04-05 21:13:13 +03001146 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001147 slot = chip->slots[i];
1148 if (!slot)
1149 continue;
1150
Manuel Lauss29495aa2011-11-03 11:09:45 +01001151 ret = sdhci_suspend_host(slot->host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001152
Axel Linb678b912011-12-03 15:28:05 +08001153 if (ret)
1154 goto err_pci_suspend;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001155
Daniel Drake5f619702010-11-04 22:20:39 +00001156 slot_pm_flags = slot->host->mmc->pm_flags;
1157 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1158 sdhci_enable_irq_wakeups(slot->host);
1159
1160 pm_flags |= slot_pm_flags;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001161 }
1162
Pierre Ossman44894282008-04-04 19:36:59 +02001163 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001164 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001165 if (ret)
1166 goto err_pci_suspend;
Pierre Ossman44894282008-04-04 19:36:59 +02001167 }
1168
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001169 if (pm_flags & MMC_PM_KEEP_POWER) {
Chuanxiao.Dong6b91f2d2014-07-15 17:28:05 +08001170 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1171 device_init_wakeup(dev, true);
1172 else
1173 device_init_wakeup(dev, false);
1174 } else
1175 device_init_wakeup(dev, false);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001176
1177 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001178
1179err_pci_suspend:
1180 while (--i >= 0)
1181 sdhci_resume_host(chip->slots[i]->host);
1182 return ret;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001183}
1184
Manuel Lauss29495aa2011-11-03 11:09:45 +01001185static int sdhci_pci_resume(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001186{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001187 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001188 struct sdhci_pci_chip *chip;
1189 struct sdhci_pci_slot *slot;
1190 int i, ret;
1191
1192 chip = pci_get_drvdata(pdev);
1193 if (!chip)
1194 return 0;
1195
Pierre Ossman45211e22008-03-24 13:09:09 +01001196 if (chip->fixes && chip->fixes->resume) {
1197 ret = chip->fixes->resume(chip);
1198 if (ret)
1199 return ret;
1200 }
1201
Ameya Palandeb177bc92011-04-05 21:13:13 +03001202 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001203 slot = chip->slots[i];
1204 if (!slot)
1205 continue;
1206
1207 ret = sdhci_resume_host(slot->host);
1208 if (ret)
1209 return ret;
1210 }
1211
1212 return 0;
1213}
1214
1215#else /* CONFIG_PM */
1216
1217#define sdhci_pci_suspend NULL
1218#define sdhci_pci_resume NULL
1219
1220#endif /* CONFIG_PM */
1221
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001222#ifdef CONFIG_PM_RUNTIME
1223
1224static int sdhci_pci_runtime_suspend(struct device *dev)
1225{
1226 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1227 struct sdhci_pci_chip *chip;
1228 struct sdhci_pci_slot *slot;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001229 int i, ret;
1230
1231 chip = pci_get_drvdata(pdev);
1232 if (!chip)
1233 return 0;
1234
1235 for (i = 0; i < chip->num_slots; i++) {
1236 slot = chip->slots[i];
1237 if (!slot)
1238 continue;
1239
1240 ret = sdhci_runtime_suspend_host(slot->host);
1241
Axel Linb678b912011-12-03 15:28:05 +08001242 if (ret)
1243 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001244 }
1245
1246 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001247 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001248 if (ret)
1249 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001250 }
1251
1252 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001253
1254err_pci_runtime_suspend:
1255 while (--i >= 0)
1256 sdhci_runtime_resume_host(chip->slots[i]->host);
1257 return ret;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001258}
1259
1260static int sdhci_pci_runtime_resume(struct device *dev)
1261{
1262 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1263 struct sdhci_pci_chip *chip;
1264 struct sdhci_pci_slot *slot;
1265 int i, ret;
1266
1267 chip = pci_get_drvdata(pdev);
1268 if (!chip)
1269 return 0;
1270
1271 if (chip->fixes && chip->fixes->resume) {
1272 ret = chip->fixes->resume(chip);
1273 if (ret)
1274 return ret;
1275 }
1276
1277 for (i = 0; i < chip->num_slots; i++) {
1278 slot = chip->slots[i];
1279 if (!slot)
1280 continue;
1281
1282 ret = sdhci_runtime_resume_host(slot->host);
1283 if (ret)
1284 return ret;
1285 }
1286
1287 return 0;
1288}
1289
1290static int sdhci_pci_runtime_idle(struct device *dev)
1291{
1292 return 0;
1293}
1294
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001295#endif
1296
1297static const struct dev_pm_ops sdhci_pci_pm_ops = {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001298 .suspend = sdhci_pci_suspend,
1299 .resume = sdhci_pci_resume,
Peter Griffinf3a92b12014-08-12 17:14:28 +01001300 SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend,
1301 sdhci_pci_runtime_resume, sdhci_pci_runtime_idle)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001302};
1303
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001304/*****************************************************************************\
1305 * *
1306 * Device probing/removal *
1307 * *
1308\*****************************************************************************/
1309
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001310static struct sdhci_pci_slot *sdhci_pci_probe_slot(
Adrian Hunter52c506f2011-12-27 15:48:43 +02001311 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1312 int slotno)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001313{
1314 struct sdhci_pci_slot *slot;
1315 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001316 int ret, bar = first_bar + slotno;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001317
1318 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1319 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1320 return ERR_PTR(-ENODEV);
1321 }
1322
Adrian Hunter90b3e6c2012-10-18 09:54:31 +03001323 if (pci_resource_len(pdev, bar) < 0x100) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001324 dev_err(&pdev->dev, "Invalid iomem size. You may "
1325 "experience problems.\n");
1326 }
1327
1328 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1329 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1330 return ERR_PTR(-ENODEV);
1331 }
1332
1333 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1334 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1335 return ERR_PTR(-ENODEV);
1336 }
1337
1338 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1339 if (IS_ERR(host)) {
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001340 dev_err(&pdev->dev, "cannot allocate host\n");
Julia Lawalldc0fd7b2010-05-26 14:42:11 -07001341 return ERR_CAST(host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001342 }
1343
1344 slot = sdhci_priv(host);
1345
1346 slot->chip = chip;
1347 slot->host = host;
1348 slot->pci_bar = bar;
Adrian Hunter0f201652011-08-29 16:42:13 +03001349 slot->rst_n_gpio = -EINVAL;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001350 slot->cd_gpio = -EINVAL;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001351
Adrian Hunter52c506f2011-12-27 15:48:43 +02001352 /* Retrieve platform data if there is any */
1353 if (*sdhci_pci_get_data)
1354 slot->data = sdhci_pci_get_data(pdev, slotno);
1355
1356 if (slot->data) {
1357 if (slot->data->setup) {
1358 ret = slot->data->setup(slot->data);
1359 if (ret) {
1360 dev_err(&pdev->dev, "platform setup failed\n");
1361 goto free;
1362 }
1363 }
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001364 slot->rst_n_gpio = slot->data->rst_n_gpio;
1365 slot->cd_gpio = slot->data->cd_gpio;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001366 }
1367
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001368 host->hw_name = "PCI";
1369 host->ops = &sdhci_pci_ops;
1370 host->quirks = chip->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001371 host->quirks2 = chip->quirks2;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001372
1373 host->irq = pdev->irq;
1374
1375 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1376 if (ret) {
1377 dev_err(&pdev->dev, "cannot request region\n");
Adrian Hunter52c506f2011-12-27 15:48:43 +02001378 goto cleanup;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001379 }
1380
Arjan van de Ven092f82e2008-09-28 16:15:56 -07001381 host->ioaddr = pci_ioremap_bar(pdev, bar);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001382 if (!host->ioaddr) {
1383 dev_err(&pdev->dev, "failed to remap registers\n");
Chris Ball9fdcdbb2011-03-29 00:46:12 -04001384 ret = -ENOMEM;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001385 goto release;
1386 }
1387
Pierre Ossman44894282008-04-04 19:36:59 +02001388 if (chip->fixes && chip->fixes->probe_slot) {
1389 ret = chip->fixes->probe_slot(slot);
1390 if (ret)
1391 goto unmap;
1392 }
1393
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001394 if (gpio_is_valid(slot->rst_n_gpio)) {
1395 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1396 gpio_direction_output(slot->rst_n_gpio, 1);
1397 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
Adrian Hunterc9faff62013-06-13 11:50:26 +03001398 slot->hw_reset = sdhci_pci_gpio_hw_reset;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001399 } else {
1400 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1401 slot->rst_n_gpio = -EINVAL;
1402 }
1403 }
1404
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001405 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
Aaron Lueed222a2013-03-05 11:24:52 +08001406 host->mmc->slotno = slotno;
Adrian Huntera08b17b2013-04-15 11:27:25 -04001407 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001408
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001409 ret = sdhci_add_host(host);
1410 if (ret)
Pierre Ossman44894282008-04-04 19:36:59 +02001411 goto remove;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001412
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001413 sdhci_pci_add_own_cd(slot);
1414
Adrian Hunter77a01222014-01-13 09:49:16 +02001415 /*
1416 * Check if the chip needs a separate GPIO for card detect to wake up
1417 * from runtime suspend. If it is not there, don't allow runtime PM.
1418 * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
1419 */
Adrian Hunter945be382014-01-21 09:52:39 +02001420 if (chip->fixes && chip->fixes->own_cd_for_runtime_pm &&
1421 !gpio_is_valid(slot->cd_gpio))
Adrian Hunter77a01222014-01-13 09:49:16 +02001422 chip->allow_runtime_pm = false;
1423
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001424 return slot;
1425
Pierre Ossman44894282008-04-04 19:36:59 +02001426remove:
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001427 if (gpio_is_valid(slot->rst_n_gpio))
1428 gpio_free(slot->rst_n_gpio);
1429
Pierre Ossman44894282008-04-04 19:36:59 +02001430 if (chip->fixes && chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001431 chip->fixes->remove_slot(slot, 0);
Pierre Ossman44894282008-04-04 19:36:59 +02001432
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001433unmap:
1434 iounmap(host->ioaddr);
1435
1436release:
1437 pci_release_region(pdev, bar);
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001438
Adrian Hunter52c506f2011-12-27 15:48:43 +02001439cleanup:
1440 if (slot->data && slot->data->cleanup)
1441 slot->data->cleanup(slot->data);
1442
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001443free:
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001444 sdhci_free_host(host);
1445
1446 return ERR_PTR(ret);
1447}
1448
1449static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1450{
Pierre Ossman1e728592008-04-16 19:13:13 +02001451 int dead;
1452 u32 scratch;
1453
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001454 sdhci_pci_remove_own_cd(slot);
1455
Pierre Ossman1e728592008-04-16 19:13:13 +02001456 dead = 0;
1457 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1458 if (scratch == (u32)-1)
1459 dead = 1;
1460
1461 sdhci_remove_host(slot->host, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001462
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001463 if (gpio_is_valid(slot->rst_n_gpio))
1464 gpio_free(slot->rst_n_gpio);
1465
Pierre Ossman44894282008-04-04 19:36:59 +02001466 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001467 slot->chip->fixes->remove_slot(slot, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001468
Adrian Hunter52c506f2011-12-27 15:48:43 +02001469 if (slot->data && slot->data->cleanup)
1470 slot->data->cleanup(slot->data);
1471
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001472 pci_release_region(slot->chip->pdev, slot->pci_bar);
Pierre Ossman44894282008-04-04 19:36:59 +02001473
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001474 sdhci_free_host(slot->host);
1475}
1476
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001477static void sdhci_pci_runtime_pm_allow(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001478{
1479 pm_runtime_put_noidle(dev);
1480 pm_runtime_allow(dev);
1481 pm_runtime_set_autosuspend_delay(dev, 50);
1482 pm_runtime_use_autosuspend(dev);
1483 pm_suspend_ignore_children(dev, 1);
1484}
1485
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001486static void sdhci_pci_runtime_pm_forbid(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001487{
1488 pm_runtime_forbid(dev);
1489 pm_runtime_get_noresume(dev);
1490}
1491
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001492static int sdhci_pci_probe(struct pci_dev *pdev,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001493 const struct pci_device_id *ent)
1494{
1495 struct sdhci_pci_chip *chip;
1496 struct sdhci_pci_slot *slot;
1497
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001498 u8 slots, first_bar;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001499 int ret, i;
1500
1501 BUG_ON(pdev == NULL);
1502 BUG_ON(ent == NULL);
1503
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001504 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001505 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001506
1507 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1508 if (ret)
1509 return ret;
1510
1511 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1512 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1513 if (slots == 0)
1514 return -ENODEV;
1515
1516 BUG_ON(slots > MAX_SLOTS);
1517
1518 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1519 if (ret)
1520 return ret;
1521
1522 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1523
1524 if (first_bar > 5) {
1525 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1526 return -ENODEV;
1527 }
1528
1529 ret = pci_enable_device(pdev);
1530 if (ret)
1531 return ret;
1532
1533 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
1534 if (!chip) {
1535 ret = -ENOMEM;
1536 goto err;
1537 }
1538
1539 chip->pdev = pdev;
Ameya Palandeb177bc92011-04-05 21:13:13 +03001540 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001541 if (chip->fixes) {
Pierre Ossman22606402008-03-23 19:33:23 +01001542 chip->quirks = chip->fixes->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001543 chip->quirks2 = chip->fixes->quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001544 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1545 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001546 chip->num_slots = slots;
1547
1548 pci_set_drvdata(pdev, chip);
1549
Pierre Ossman22606402008-03-23 19:33:23 +01001550 if (chip->fixes && chip->fixes->probe) {
1551 ret = chip->fixes->probe(chip);
1552 if (ret)
1553 goto free;
1554 }
1555
Alan Cox225d85f2010-10-04 15:24:21 +01001556 slots = chip->num_slots; /* Quirk may have changed this */
1557
Ameya Palandeb177bc92011-04-05 21:13:13 +03001558 for (i = 0; i < slots; i++) {
Adrian Hunter52c506f2011-12-27 15:48:43 +02001559 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001560 if (IS_ERR(slot)) {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001561 for (i--; i >= 0; i--)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001562 sdhci_pci_remove_slot(chip->slots[i]);
1563 ret = PTR_ERR(slot);
1564 goto free;
1565 }
1566
1567 chip->slots[i] = slot;
1568 }
1569
Adrian Hunterc43fd772011-10-17 10:52:44 +03001570 if (chip->allow_runtime_pm)
1571 sdhci_pci_runtime_pm_allow(&pdev->dev);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001572
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001573 return 0;
1574
1575free:
1576 pci_set_drvdata(pdev, NULL);
1577 kfree(chip);
1578
1579err:
1580 pci_disable_device(pdev);
1581 return ret;
1582}
1583
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001584static void sdhci_pci_remove(struct pci_dev *pdev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001585{
1586 int i;
1587 struct sdhci_pci_chip *chip;
1588
1589 chip = pci_get_drvdata(pdev);
1590
1591 if (chip) {
Adrian Hunterc43fd772011-10-17 10:52:44 +03001592 if (chip->allow_runtime_pm)
1593 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1594
Ameya Palandeb177bc92011-04-05 21:13:13 +03001595 for (i = 0; i < chip->num_slots; i++)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001596 sdhci_pci_remove_slot(chip->slots[i]);
1597
1598 pci_set_drvdata(pdev, NULL);
1599 kfree(chip);
1600 }
1601
1602 pci_disable_device(pdev);
1603}
1604
1605static struct pci_driver sdhci_driver = {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001606 .name = "sdhci-pci",
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001607 .id_table = pci_ids,
Ameya Palandeb177bc92011-04-05 21:13:13 +03001608 .probe = sdhci_pci_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -05001609 .remove = sdhci_pci_remove,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001610 .driver = {
1611 .pm = &sdhci_pci_pm_ops
1612 },
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001613};
1614
Sachin Kamatacc69642012-08-27 11:57:02 +05301615module_pci_driver(sdhci_driver);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001616
Pierre Ossman32710e82009-04-08 20:14:54 +02001617MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001618MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1619MODULE_LICENSE("GPL");