blob: 31181d8dc5616a9c82a7e94610604438b79c1f7b [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,
Adrian Huntere58e4a02014-09-24 10:27:30 +0300286 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
287 SDHCI_QUIRK2_STOP_WITH_TC,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300288};
289
290static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
Gao, Yunpengb7574ba2014-09-04 15:18:05 +0800291 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON |
292 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300293 .allow_runtime_pm = true,
294 .probe_slot = byt_sdio_probe_slot,
295};
296
297static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
Gao, Yunpengb7574ba2014-09-04 15:18:05 +0800298 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
Adrian Huntere58e4a02014-09-24 10:27:30 +0300299 SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
300 SDHCI_QUIRK2_STOP_WITH_TC,
Adrian Hunter7396e312013-05-06 12:17:34 +0300301 .allow_runtime_pm = true,
Adrian Hunter77a01222014-01-13 09:49:16 +0200302 .own_cd_for_runtime_pm = true,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300303};
304
David Cohen8776a162013-10-01 13:18:15 -0700305/* Define Host controllers for Intel Merrifield platform */
306#define INTEL_MRFL_EMMC_0 0
307#define INTEL_MRFL_EMMC_1 1
308
309static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
310{
311 if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_0) &&
312 (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_1))
313 /* SD support is not ready yet */
314 return -ENODEV;
315
316 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
317 MMC_CAP_1_8V_DDR;
318
319 return 0;
320}
321
322static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
323 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Gao, Yunpengb7574ba2014-09-04 15:18:05 +0800324 .quirks2 = SDHCI_QUIRK2_BROKEN_HS200 |
325 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
Gao, Yunpengf1b55a52014-08-18 15:05:52 +0800326 .allow_runtime_pm = true,
David Cohen8776a162013-10-01 13:18:15 -0700327 .probe_slot = intel_mrfl_mmc_probe_slot,
328};
329
Jennifer Li26daa1e2010-11-17 23:01:59 -0500330/* O2Micro extra registers */
331#define O2_SD_LOCK_WP 0xD3
332#define O2_SD_MULTI_VCC3V 0xEE
333#define O2_SD_CLKREQ 0xEC
334#define O2_SD_CAPS 0xE0
335#define O2_SD_ADMA1 0xE2
336#define O2_SD_ADMA2 0xE7
337#define O2_SD_INF_MOD 0xF1
338
Pierre Ossman45211e22008-03-24 13:09:09 +0100339static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
340{
341 u8 scratch;
342 int ret;
343
344 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
345 if (ret)
346 return ret;
347
348 /*
349 * Turn PMOS on [bit 0], set over current detection to 2.4 V
350 * [bit 1:2] and enable over current debouncing [bit 6].
351 */
352 if (on)
353 scratch |= 0x47;
354 else
355 scratch &= ~0x47;
356
357 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
358 if (ret)
359 return ret;
360
361 return 0;
362}
363
364static int jmicron_probe(struct sdhci_pci_chip *chip)
365{
366 int ret;
Takashi Iwai8f230f42010-12-08 10:04:30 +0100367 u16 mmcdev = 0;
Pierre Ossman45211e22008-03-24 13:09:09 +0100368
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200369 if (chip->pdev->revision == 0) {
370 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
371 SDHCI_QUIRK_32BIT_DMA_SIZE |
Pierre Ossman2134a922008-06-28 18:28:51 +0200372 SDHCI_QUIRK_32BIT_ADMA_SIZE |
Pierre Ossman4a3cba32008-07-29 00:11:16 +0200373 SDHCI_QUIRK_RESET_AFTER_REQUEST |
Pierre Ossman86a6a872009-02-02 21:13:49 +0100374 SDHCI_QUIRK_BROKEN_SMALL_PIO;
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200375 }
376
Pierre Ossman45211e22008-03-24 13:09:09 +0100377 /*
Pierre Ossman44894282008-04-04 19:36:59 +0200378 * JMicron chips can have two interfaces to the same hardware
379 * in order to work around limitations in Microsoft's driver.
380 * We need to make sure we only bind to one of them.
381 *
382 * This code assumes two things:
383 *
384 * 1. The PCI code adds subfunctions in order.
385 *
386 * 2. The MMC interface has a lower subfunction number
387 * than the SD interface.
388 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100389 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
390 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
391 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
392 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
393
394 if (mmcdev) {
Pierre Ossman44894282008-04-04 19:36:59 +0200395 struct pci_dev *sd_dev;
396
397 sd_dev = NULL;
398 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
Takashi Iwai8f230f42010-12-08 10:04:30 +0100399 mmcdev, sd_dev)) != NULL) {
Pierre Ossman44894282008-04-04 19:36:59 +0200400 if ((PCI_SLOT(chip->pdev->devfn) ==
401 PCI_SLOT(sd_dev->devfn)) &&
402 (chip->pdev->bus == sd_dev->bus))
403 break;
404 }
405
406 if (sd_dev) {
407 pci_dev_put(sd_dev);
408 dev_info(&chip->pdev->dev, "Refusing to bind to "
409 "secondary interface.\n");
410 return -ENODEV;
411 }
412 }
413
414 /*
Pierre Ossman45211e22008-03-24 13:09:09 +0100415 * JMicron chips need a bit of a nudge to enable the power
416 * output pins.
417 */
418 ret = jmicron_pmos(chip, 1);
419 if (ret) {
420 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
421 return ret;
422 }
423
Takashi Iwai82b0e232011-04-21 20:26:38 +0200424 /* quirk for unsable RO-detection on JM388 chips */
425 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
426 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
427 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
428
Pierre Ossman45211e22008-03-24 13:09:09 +0100429 return 0;
430}
431
Pierre Ossman44894282008-04-04 19:36:59 +0200432static void jmicron_enable_mmc(struct sdhci_host *host, int on)
433{
434 u8 scratch;
435
436 scratch = readb(host->ioaddr + 0xC0);
437
438 if (on)
439 scratch |= 0x01;
440 else
441 scratch &= ~0x01;
442
443 writeb(scratch, host->ioaddr + 0xC0);
444}
445
446static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
447{
Pierre Ossman2134a922008-06-28 18:28:51 +0200448 if (slot->chip->pdev->revision == 0) {
449 u16 version;
450
451 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
452 version = (version & SDHCI_VENDOR_VER_MASK) >>
453 SDHCI_VENDOR_VER_SHIFT;
454
455 /*
456 * Older versions of the chip have lots of nasty glitches
457 * in the ADMA engine. It's best just to avoid it
458 * completely.
459 */
460 if (version < 0xAC)
461 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
462 }
463
Takashi Iwai8f230f42010-12-08 10:04:30 +0100464 /* JM388 MMC doesn't support 1.8V while SD supports it */
465 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
466 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
467 MMC_VDD_29_30 | MMC_VDD_30_31 |
468 MMC_VDD_165_195; /* allow 1.8V */
469 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
470 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
471 }
472
Pierre Ossman44894282008-04-04 19:36:59 +0200473 /*
474 * The secondary interface requires a bit set to get the
475 * interrupts.
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, 1);
480
Takashi Iwaid75c1082010-12-16 17:54:14 +0100481 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
482
Pierre Ossman44894282008-04-04 19:36:59 +0200483 return 0;
484}
485
Pierre Ossman1e728592008-04-16 19:13:13 +0200486static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
Pierre Ossman44894282008-04-04 19:36:59 +0200487{
Pierre Ossman1e728592008-04-16 19:13:13 +0200488 if (dead)
489 return;
490
Takashi Iwai8f230f42010-12-08 10:04:30 +0100491 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
492 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200493 jmicron_enable_mmc(slot->host, 0);
494}
495
Manuel Lauss29495aa2011-11-03 11:09:45 +0100496static int jmicron_suspend(struct sdhci_pci_chip *chip)
Pierre Ossman44894282008-04-04 19:36:59 +0200497{
498 int i;
499
Takashi Iwai8f230f42010-12-08 10:04:30 +0100500 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
501 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300502 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200503 jmicron_enable_mmc(chip->slots[i]->host, 0);
504 }
505
506 return 0;
507}
508
Pierre Ossman45211e22008-03-24 13:09:09 +0100509static int jmicron_resume(struct sdhci_pci_chip *chip)
510{
Pierre Ossman44894282008-04-04 19:36:59 +0200511 int ret, i;
512
Takashi Iwai8f230f42010-12-08 10:04:30 +0100513 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
514 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300515 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200516 jmicron_enable_mmc(chip->slots[i]->host, 1);
517 }
Pierre Ossman45211e22008-03-24 13:09:09 +0100518
519 ret = jmicron_pmos(chip, 1);
520 if (ret) {
521 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
522 return ret;
523 }
524
525 return 0;
526}
527
Jennifer Li26daa1e2010-11-17 23:01:59 -0500528static const struct sdhci_pci_fixes sdhci_o2 = {
Adam Lee01acf692013-12-19 00:01:26 +0800529 .probe = sdhci_pci_o2_probe,
530 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
531 .probe_slot = sdhci_pci_o2_probe_slot,
532 .resume = sdhci_pci_o2_resume,
Jennifer Li26daa1e2010-11-17 23:01:59 -0500533};
534
Pierre Ossman22606402008-03-23 19:33:23 +0100535static const struct sdhci_pci_fixes sdhci_jmicron = {
Pierre Ossman45211e22008-03-24 13:09:09 +0100536 .probe = jmicron_probe,
537
Pierre Ossman44894282008-04-04 19:36:59 +0200538 .probe_slot = jmicron_probe_slot,
539 .remove_slot = jmicron_remove_slot,
540
541 .suspend = jmicron_suspend,
Pierre Ossman45211e22008-03-24 13:09:09 +0100542 .resume = jmicron_resume,
Pierre Ossman22606402008-03-23 19:33:23 +0100543};
544
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800545/* SysKonnect CardBus2SDIO extra registers */
546#define SYSKT_CTRL 0x200
547#define SYSKT_RDFIFO_STAT 0x204
548#define SYSKT_WRFIFO_STAT 0x208
549#define SYSKT_POWER_DATA 0x20c
550#define SYSKT_POWER_330 0xef
551#define SYSKT_POWER_300 0xf8
552#define SYSKT_POWER_184 0xcc
553#define SYSKT_POWER_CMD 0x20d
554#define SYSKT_POWER_START (1 << 7)
555#define SYSKT_POWER_STATUS 0x20e
556#define SYSKT_POWER_STATUS_OK (1 << 0)
557#define SYSKT_BOARD_REV 0x210
558#define SYSKT_CHIP_REV 0x211
559#define SYSKT_CONF_DATA 0x212
560#define SYSKT_CONF_DATA_1V8 (1 << 2)
561#define SYSKT_CONF_DATA_2V5 (1 << 1)
562#define SYSKT_CONF_DATA_3V3 (1 << 0)
563
564static int syskt_probe(struct sdhci_pci_chip *chip)
565{
566 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
567 chip->pdev->class &= ~0x0000FF;
568 chip->pdev->class |= PCI_SDHCI_IFDMA;
569 }
570 return 0;
571}
572
573static int syskt_probe_slot(struct sdhci_pci_slot *slot)
574{
575 int tm, ps;
576
577 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
578 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
579 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
580 "board rev %d.%d, chip rev %d.%d\n",
581 board_rev >> 4, board_rev & 0xf,
582 chip_rev >> 4, chip_rev & 0xf);
583 if (chip_rev >= 0x20)
584 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
585
586 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
587 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
588 udelay(50);
589 tm = 10; /* Wait max 1 ms */
590 do {
591 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
592 if (ps & SYSKT_POWER_STATUS_OK)
593 break;
594 udelay(100);
595 } while (--tm);
596 if (!tm) {
597 dev_err(&slot->chip->pdev->dev,
598 "power regulator never stabilized");
599 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
600 return -ENODEV;
601 }
602
603 return 0;
604}
605
606static const struct sdhci_pci_fixes sdhci_syskt = {
607 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
608 .probe = syskt_probe,
609 .probe_slot = syskt_probe_slot,
610};
611
Harald Welte557b0692009-06-18 16:53:38 +0200612static int via_probe(struct sdhci_pci_chip *chip)
613{
614 if (chip->pdev->revision == 0x10)
615 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
616
617 return 0;
618}
619
620static const struct sdhci_pci_fixes sdhci_via = {
621 .probe = via_probe,
622};
623
Micky Ching9107ebb2014-02-21 18:40:35 +0800624static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
625{
626 slot->host->mmc->caps2 |= MMC_CAP2_HS200;
627 return 0;
628}
629
630static const struct sdhci_pci_fixes sdhci_rtsx = {
631 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
632 SDHCI_QUIRK2_BROKEN_DDR50,
633 .probe_slot = rtsx_probe_slot,
634};
635
Bill Pemberton9647f842012-11-19 13:25:11 -0500636static const struct pci_device_id pci_ids[] = {
Pierre Ossman22606402008-03-23 19:33:23 +0100637 {
638 .vendor = PCI_VENDOR_ID_RICOH,
639 .device = PCI_DEVICE_ID_RICOH_R5C822,
640 .subvendor = PCI_ANY_ID,
641 .subdevice = PCI_ANY_ID,
642 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
643 },
644
645 {
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700646 .vendor = PCI_VENDOR_ID_RICOH,
647 .device = 0x843,
648 .subvendor = PCI_ANY_ID,
649 .subdevice = PCI_ANY_ID,
650 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
651 },
652
653 {
Pablo Castillo568133e2010-08-10 18:02:01 -0700654 .vendor = PCI_VENDOR_ID_RICOH,
655 .device = 0xe822,
656 .subvendor = PCI_ANY_ID,
657 .subdevice = PCI_ANY_ID,
658 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
659 },
660
661 {
Manoj Iyer5fd11c02011-02-11 16:25:31 -0600662 .vendor = PCI_VENDOR_ID_RICOH,
663 .device = 0xe823,
664 .subvendor = PCI_ANY_ID,
665 .subdevice = PCI_ANY_ID,
666 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
667 },
668
669 {
Pierre Ossman22606402008-03-23 19:33:23 +0100670 .vendor = PCI_VENDOR_ID_ENE,
671 .device = PCI_DEVICE_ID_ENE_CB712_SD,
672 .subvendor = PCI_ANY_ID,
673 .subdevice = PCI_ANY_ID,
674 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
675 },
676
677 {
678 .vendor = PCI_VENDOR_ID_ENE,
679 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
680 .subvendor = PCI_ANY_ID,
681 .subdevice = PCI_ANY_ID,
682 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
683 },
684
685 {
686 .vendor = PCI_VENDOR_ID_ENE,
687 .device = PCI_DEVICE_ID_ENE_CB714_SD,
688 .subvendor = PCI_ANY_ID,
689 .subdevice = PCI_ANY_ID,
690 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
691 },
692
693 {
694 .vendor = PCI_VENDOR_ID_ENE,
695 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
696 .subvendor = PCI_ANY_ID,
697 .subdevice = PCI_ANY_ID,
698 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
699 },
700
701 {
702 .vendor = PCI_VENDOR_ID_MARVELL,
David Woodhouse8c5eb882008-09-03 09:45:57 +0100703 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
Pierre Ossman22606402008-03-23 19:33:23 +0100704 .subvendor = PCI_ANY_ID,
705 .subdevice = PCI_ANY_ID,
706 .driver_data = (kernel_ulong_t)&sdhci_cafe,
707 },
708
709 {
710 .vendor = PCI_VENDOR_ID_JMICRON,
711 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
712 .subvendor = PCI_ANY_ID,
713 .subdevice = PCI_ANY_ID,
714 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
715 },
716
Pierre Ossman44894282008-04-04 19:36:59 +0200717 {
718 .vendor = PCI_VENDOR_ID_JMICRON,
719 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
720 .subvendor = PCI_ANY_ID,
721 .subdevice = PCI_ANY_ID,
722 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
723 },
724
Harald Welte557b0692009-06-18 16:53:38 +0200725 {
Takashi Iwai8f230f42010-12-08 10:04:30 +0100726 .vendor = PCI_VENDOR_ID_JMICRON,
727 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
728 .subvendor = PCI_ANY_ID,
729 .subdevice = PCI_ANY_ID,
730 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
731 },
732
733 {
734 .vendor = PCI_VENDOR_ID_JMICRON,
735 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
736 .subvendor = PCI_ANY_ID,
737 .subdevice = PCI_ANY_ID,
738 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
739 },
740
741 {
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800742 .vendor = PCI_VENDOR_ID_SYSKONNECT,
743 .device = 0x8000,
744 .subvendor = PCI_ANY_ID,
745 .subdevice = PCI_ANY_ID,
746 .driver_data = (kernel_ulong_t)&sdhci_syskt,
747 },
748
749 {
Harald Welte557b0692009-06-18 16:53:38 +0200750 .vendor = PCI_VENDOR_ID_VIA,
751 .device = 0x95d0,
752 .subvendor = PCI_ANY_ID,
753 .subdevice = PCI_ANY_ID,
754 .driver_data = (kernel_ulong_t)&sdhci_via,
755 },
756
Xiaochen Shen29229052010-10-04 15:24:52 +0100757 {
Micky Ching9107ebb2014-02-21 18:40:35 +0800758 .vendor = PCI_VENDOR_ID_REALTEK,
759 .device = 0x5250,
760 .subvendor = PCI_ANY_ID,
761 .subdevice = PCI_ANY_ID,
762 .driver_data = (kernel_ulong_t)&sdhci_rtsx,
763 },
764
765 {
Xiaochen Shen29229052010-10-04 15:24:52 +0100766 .vendor = PCI_VENDOR_ID_INTEL,
Derek Browne43e968c2014-06-24 06:56:36 -0700767 .device = PCI_DEVICE_ID_INTEL_QRK_SD,
768 .subvendor = PCI_ANY_ID,
769 .subdevice = PCI_ANY_ID,
770 .driver_data = (kernel_ulong_t)&sdhci_intel_qrk,
771 },
772
773 {
774 .vendor = PCI_VENDOR_ID_INTEL,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100775 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
776 .subvendor = PCI_ANY_ID,
777 .subdevice = PCI_ANY_ID,
778 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
779 },
780
781 {
782 .vendor = PCI_VENDOR_ID_INTEL,
783 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
784 .subvendor = PCI_ANY_ID,
785 .subdevice = PCI_ANY_ID,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000786 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
787 },
788
789 {
790 .vendor = PCI_VENDOR_ID_INTEL,
791 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
792 .subvendor = PCI_ANY_ID,
793 .subdevice = PCI_ANY_ID,
794 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100795 },
796
797 {
798 .vendor = PCI_VENDOR_ID_INTEL,
Xiaochen Shen29229052010-10-04 15:24:52 +0100799 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
800 .subvendor = PCI_ANY_ID,
801 .subdevice = PCI_ANY_ID,
802 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
803 },
804
805 {
806 .vendor = PCI_VENDOR_ID_INTEL,
807 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
808 .subvendor = PCI_ANY_ID,
809 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300810 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100811 },
812
813 {
814 .vendor = PCI_VENDOR_ID_INTEL,
815 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
816 .subvendor = PCI_ANY_ID,
817 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300818 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100819 },
820
821 {
822 .vendor = PCI_VENDOR_ID_INTEL,
823 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
824 .subvendor = PCI_ANY_ID,
825 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300826 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100827 },
828
829 {
830 .vendor = PCI_VENDOR_ID_INTEL,
831 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
832 .subvendor = PCI_ANY_ID,
833 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300834 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100835 },
836
Jennifer Li26daa1e2010-11-17 23:01:59 -0500837 {
Alexander Stein296e0b02012-03-14 08:38:58 +0100838 .vendor = PCI_VENDOR_ID_INTEL,
839 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
840 .subvendor = PCI_ANY_ID,
841 .subdevice = PCI_ANY_ID,
842 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
843 },
844
845 {
846 .vendor = PCI_VENDOR_ID_INTEL,
847 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
848 .subvendor = PCI_ANY_ID,
849 .subdevice = PCI_ANY_ID,
850 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
851 },
852
853 {
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300854 .vendor = PCI_VENDOR_ID_INTEL,
855 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC,
856 .subvendor = PCI_ANY_ID,
857 .subdevice = PCI_ANY_ID,
858 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
859 },
860
861 {
862 .vendor = PCI_VENDOR_ID_INTEL,
863 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
864 .subvendor = PCI_ANY_ID,
865 .subdevice = PCI_ANY_ID,
866 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
867 },
868
869 {
870 .vendor = PCI_VENDOR_ID_INTEL,
871 .device = PCI_DEVICE_ID_INTEL_BYT_SD,
872 .subvendor = PCI_ANY_ID,
873 .subdevice = PCI_ANY_ID,
874 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
875 },
876
877 {
Adrian Hunter30d025c2013-06-20 12:57:59 +0300878 .vendor = PCI_VENDOR_ID_INTEL,
879 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2,
880 .subvendor = PCI_ANY_ID,
881 .subdevice = PCI_ANY_ID,
882 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
883 },
884
Alan Cox066173b2014-08-20 13:27:44 +0300885 {
886 .vendor = PCI_VENDOR_ID_INTEL,
887 .device = PCI_DEVICE_ID_INTEL_BSW_EMMC,
888 .subvendor = PCI_ANY_ID,
889 .subdevice = PCI_ANY_ID,
890 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
891 },
892
893 {
894 .vendor = PCI_VENDOR_ID_INTEL,
895 .device = PCI_DEVICE_ID_INTEL_BSW_SDIO,
896 .subvendor = PCI_ANY_ID,
897 .subdevice = PCI_ANY_ID,
898 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
899 },
900
901 {
902 .vendor = PCI_VENDOR_ID_INTEL,
903 .device = PCI_DEVICE_ID_INTEL_BSW_SD,
904 .subvendor = PCI_ANY_ID,
905 .subdevice = PCI_ANY_ID,
906 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
907 },
Eric Ernstd0520682013-10-21 09:54:41 -0700908
909 {
910 .vendor = PCI_VENDOR_ID_INTEL,
911 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
912 .subvendor = PCI_ANY_ID,
913 .subdevice = PCI_ANY_ID,
914 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
915 },
916
917 {
918 .vendor = PCI_VENDOR_ID_INTEL,
919 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
920 .subvendor = PCI_ANY_ID,
921 .subdevice = PCI_ANY_ID,
922 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
923 },
924
925 {
926 .vendor = PCI_VENDOR_ID_INTEL,
927 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
928 .subvendor = PCI_ANY_ID,
929 .subdevice = PCI_ANY_ID,
930 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
931 },
932
933 {
934 .vendor = PCI_VENDOR_ID_INTEL,
935 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
936 .subvendor = PCI_ANY_ID,
937 .subdevice = PCI_ANY_ID,
938 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
939 },
940
941 {
942 .vendor = PCI_VENDOR_ID_INTEL,
943 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
944 .subvendor = PCI_ANY_ID,
945 .subdevice = PCI_ANY_ID,
946 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
947 },
948
Adrian Hunter30d025c2013-06-20 12:57:59 +0300949 {
David Cohen8776a162013-10-01 13:18:15 -0700950 .vendor = PCI_VENDOR_ID_INTEL,
951 .device = PCI_DEVICE_ID_INTEL_MRFL_MMC,
952 .subvendor = PCI_ANY_ID,
953 .subdevice = PCI_ANY_ID,
954 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
955 },
956 {
Jennifer Li26daa1e2010-11-17 23:01:59 -0500957 .vendor = PCI_VENDOR_ID_O2,
958 .device = PCI_DEVICE_ID_O2_8120,
959 .subvendor = PCI_ANY_ID,
960 .subdevice = PCI_ANY_ID,
961 .driver_data = (kernel_ulong_t)&sdhci_o2,
962 },
963
964 {
965 .vendor = PCI_VENDOR_ID_O2,
966 .device = PCI_DEVICE_ID_O2_8220,
967 .subvendor = PCI_ANY_ID,
968 .subdevice = PCI_ANY_ID,
969 .driver_data = (kernel_ulong_t)&sdhci_o2,
970 },
971
972 {
973 .vendor = PCI_VENDOR_ID_O2,
974 .device = PCI_DEVICE_ID_O2_8221,
975 .subvendor = PCI_ANY_ID,
976 .subdevice = PCI_ANY_ID,
977 .driver_data = (kernel_ulong_t)&sdhci_o2,
978 },
979
980 {
981 .vendor = PCI_VENDOR_ID_O2,
982 .device = PCI_DEVICE_ID_O2_8320,
983 .subvendor = PCI_ANY_ID,
984 .subdevice = PCI_ANY_ID,
985 .driver_data = (kernel_ulong_t)&sdhci_o2,
986 },
987
988 {
989 .vendor = PCI_VENDOR_ID_O2,
990 .device = PCI_DEVICE_ID_O2_8321,
991 .subvendor = PCI_ANY_ID,
992 .subdevice = PCI_ANY_ID,
993 .driver_data = (kernel_ulong_t)&sdhci_o2,
994 },
995
Adam Lee01acf692013-12-19 00:01:26 +0800996 {
997 .vendor = PCI_VENDOR_ID_O2,
998 .device = PCI_DEVICE_ID_O2_FUJIN2,
999 .subvendor = PCI_ANY_ID,
1000 .subdevice = PCI_ANY_ID,
1001 .driver_data = (kernel_ulong_t)&sdhci_o2,
1002 },
1003
1004 {
1005 .vendor = PCI_VENDOR_ID_O2,
1006 .device = PCI_DEVICE_ID_O2_SDS0,
1007 .subvendor = PCI_ANY_ID,
1008 .subdevice = PCI_ANY_ID,
1009 .driver_data = (kernel_ulong_t)&sdhci_o2,
1010 },
1011
1012 {
1013 .vendor = PCI_VENDOR_ID_O2,
1014 .device = PCI_DEVICE_ID_O2_SDS1,
1015 .subvendor = PCI_ANY_ID,
1016 .subdevice = PCI_ANY_ID,
1017 .driver_data = (kernel_ulong_t)&sdhci_o2,
1018 },
1019
1020 {
1021 .vendor = PCI_VENDOR_ID_O2,
1022 .device = PCI_DEVICE_ID_O2_SEABIRD0,
1023 .subvendor = PCI_ANY_ID,
1024 .subdevice = PCI_ANY_ID,
1025 .driver_data = (kernel_ulong_t)&sdhci_o2,
1026 },
1027
1028 {
1029 .vendor = PCI_VENDOR_ID_O2,
1030 .device = PCI_DEVICE_ID_O2_SEABIRD1,
1031 .subvendor = PCI_ANY_ID,
1032 .subdevice = PCI_ANY_ID,
1033 .driver_data = (kernel_ulong_t)&sdhci_o2,
1034 },
1035
Pierre Ossman22606402008-03-23 19:33:23 +01001036 { /* Generic SD host controller */
1037 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
1038 },
1039
1040 { /* end: all zeroes */ },
1041};
1042
1043MODULE_DEVICE_TABLE(pci, pci_ids);
1044
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001045/*****************************************************************************\
1046 * *
1047 * SDHCI core callbacks *
1048 * *
1049\*****************************************************************************/
1050
1051static int sdhci_pci_enable_dma(struct sdhci_host *host)
1052{
1053 struct sdhci_pci_slot *slot;
1054 struct pci_dev *pdev;
1055 int ret;
1056
1057 slot = sdhci_priv(host);
1058 pdev = slot->chip->pdev;
1059
1060 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
1061 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
Richard Röjforsa13abc72009-09-22 16:45:30 -07001062 (host->flags & SDHCI_USE_SDMA)) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001063 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
1064 "doesn't fully claim to support it.\n");
1065 }
1066
Yang Hongyang284901a2009-04-06 19:01:15 -07001067 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001068 if (ret)
1069 return ret;
1070
1071 pci_set_master(pdev);
1072
1073 return 0;
1074}
1075
Russell King2317f562014-04-25 12:57:07 +01001076static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width)
Major Lee68077b02011-06-29 14:23:46 +03001077{
1078 u8 ctrl;
1079
1080 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1081
1082 switch (width) {
1083 case MMC_BUS_WIDTH_8:
1084 ctrl |= SDHCI_CTRL_8BITBUS;
1085 ctrl &= ~SDHCI_CTRL_4BITBUS;
1086 break;
1087 case MMC_BUS_WIDTH_4:
1088 ctrl |= SDHCI_CTRL_4BITBUS;
1089 ctrl &= ~SDHCI_CTRL_8BITBUS;
1090 break;
1091 default:
1092 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
1093 break;
1094 }
1095
1096 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
Major Lee68077b02011-06-29 14:23:46 +03001097}
1098
Adrian Hunterc9faff62013-06-13 11:50:26 +03001099static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
Adrian Hunter0f201652011-08-29 16:42:13 +03001100{
1101 struct sdhci_pci_slot *slot = sdhci_priv(host);
1102 int rst_n_gpio = slot->rst_n_gpio;
1103
1104 if (!gpio_is_valid(rst_n_gpio))
1105 return;
1106 gpio_set_value_cansleep(rst_n_gpio, 0);
1107 /* For eMMC, minimum is 1us but give it 10us for good measure */
1108 udelay(10);
1109 gpio_set_value_cansleep(rst_n_gpio, 1);
1110 /* For eMMC, minimum is 200us but give it 300us for good measure */
1111 usleep_range(300, 1000);
1112}
1113
Adrian Hunterc9faff62013-06-13 11:50:26 +03001114static void sdhci_pci_hw_reset(struct sdhci_host *host)
1115{
1116 struct sdhci_pci_slot *slot = sdhci_priv(host);
1117
1118 if (slot->hw_reset)
1119 slot->hw_reset(host);
1120}
1121
Lars-Peter Clausenc9155682013-03-13 19:26:05 +01001122static const struct sdhci_ops sdhci_pci_ops = {
Russell King17710592014-04-25 12:58:55 +01001123 .set_clock = sdhci_set_clock,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001124 .enable_dma = sdhci_pci_enable_dma,
Russell King2317f562014-04-25 12:57:07 +01001125 .set_bus_width = sdhci_pci_set_bus_width,
Russell King03231f92014-04-25 12:57:12 +01001126 .reset = sdhci_reset,
Russell King96d7b782014-04-25 12:59:26 +01001127 .set_uhs_signaling = sdhci_set_uhs_signaling,
Adrian Hunter0f201652011-08-29 16:42:13 +03001128 .hw_reset = sdhci_pci_hw_reset,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001129};
1130
1131/*****************************************************************************\
1132 * *
1133 * Suspend/resume *
1134 * *
1135\*****************************************************************************/
1136
1137#ifdef CONFIG_PM
1138
Manuel Lauss29495aa2011-11-03 11:09:45 +01001139static int sdhci_pci_suspend(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001140{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001141 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001142 struct sdhci_pci_chip *chip;
1143 struct sdhci_pci_slot *slot;
Daniel Drake5f619702010-11-04 22:20:39 +00001144 mmc_pm_flag_t slot_pm_flags;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001145 mmc_pm_flag_t pm_flags = 0;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001146 int i, ret;
1147
1148 chip = pci_get_drvdata(pdev);
1149 if (!chip)
1150 return 0;
1151
Ameya Palandeb177bc92011-04-05 21:13:13 +03001152 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001153 slot = chip->slots[i];
1154 if (!slot)
1155 continue;
1156
Manuel Lauss29495aa2011-11-03 11:09:45 +01001157 ret = sdhci_suspend_host(slot->host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001158
Axel Linb678b912011-12-03 15:28:05 +08001159 if (ret)
1160 goto err_pci_suspend;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001161
Daniel Drake5f619702010-11-04 22:20:39 +00001162 slot_pm_flags = slot->host->mmc->pm_flags;
1163 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1164 sdhci_enable_irq_wakeups(slot->host);
1165
1166 pm_flags |= slot_pm_flags;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001167 }
1168
Pierre Ossman44894282008-04-04 19:36:59 +02001169 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001170 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001171 if (ret)
1172 goto err_pci_suspend;
Pierre Ossman44894282008-04-04 19:36:59 +02001173 }
1174
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001175 if (pm_flags & MMC_PM_KEEP_POWER) {
Chuanxiao.Dong6b91f2d2014-07-15 17:28:05 +08001176 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1177 device_init_wakeup(dev, true);
1178 else
1179 device_init_wakeup(dev, false);
1180 } else
1181 device_init_wakeup(dev, false);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001182
1183 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001184
1185err_pci_suspend:
1186 while (--i >= 0)
1187 sdhci_resume_host(chip->slots[i]->host);
1188 return ret;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001189}
1190
Manuel Lauss29495aa2011-11-03 11:09:45 +01001191static int sdhci_pci_resume(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001192{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001193 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001194 struct sdhci_pci_chip *chip;
1195 struct sdhci_pci_slot *slot;
1196 int i, ret;
1197
1198 chip = pci_get_drvdata(pdev);
1199 if (!chip)
1200 return 0;
1201
Pierre Ossman45211e22008-03-24 13:09:09 +01001202 if (chip->fixes && chip->fixes->resume) {
1203 ret = chip->fixes->resume(chip);
1204 if (ret)
1205 return ret;
1206 }
1207
Ameya Palandeb177bc92011-04-05 21:13:13 +03001208 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001209 slot = chip->slots[i];
1210 if (!slot)
1211 continue;
1212
1213 ret = sdhci_resume_host(slot->host);
1214 if (ret)
1215 return ret;
1216 }
1217
1218 return 0;
1219}
1220
1221#else /* CONFIG_PM */
1222
1223#define sdhci_pci_suspend NULL
1224#define sdhci_pci_resume NULL
1225
1226#endif /* CONFIG_PM */
1227
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001228#ifdef CONFIG_PM_RUNTIME
1229
1230static int sdhci_pci_runtime_suspend(struct device *dev)
1231{
1232 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1233 struct sdhci_pci_chip *chip;
1234 struct sdhci_pci_slot *slot;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001235 int i, ret;
1236
1237 chip = pci_get_drvdata(pdev);
1238 if (!chip)
1239 return 0;
1240
1241 for (i = 0; i < chip->num_slots; i++) {
1242 slot = chip->slots[i];
1243 if (!slot)
1244 continue;
1245
1246 ret = sdhci_runtime_suspend_host(slot->host);
1247
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 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001253 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001254 if (ret)
1255 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001256 }
1257
1258 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001259
1260err_pci_runtime_suspend:
1261 while (--i >= 0)
1262 sdhci_runtime_resume_host(chip->slots[i]->host);
1263 return ret;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001264}
1265
1266static int sdhci_pci_runtime_resume(struct device *dev)
1267{
1268 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1269 struct sdhci_pci_chip *chip;
1270 struct sdhci_pci_slot *slot;
1271 int i, ret;
1272
1273 chip = pci_get_drvdata(pdev);
1274 if (!chip)
1275 return 0;
1276
1277 if (chip->fixes && chip->fixes->resume) {
1278 ret = chip->fixes->resume(chip);
1279 if (ret)
1280 return ret;
1281 }
1282
1283 for (i = 0; i < chip->num_slots; i++) {
1284 slot = chip->slots[i];
1285 if (!slot)
1286 continue;
1287
1288 ret = sdhci_runtime_resume_host(slot->host);
1289 if (ret)
1290 return ret;
1291 }
1292
1293 return 0;
1294}
1295
1296static int sdhci_pci_runtime_idle(struct device *dev)
1297{
1298 return 0;
1299}
1300
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001301#endif
1302
1303static const struct dev_pm_ops sdhci_pci_pm_ops = {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001304 .suspend = sdhci_pci_suspend,
1305 .resume = sdhci_pci_resume,
Peter Griffinf3a92b12014-08-12 17:14:28 +01001306 SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend,
1307 sdhci_pci_runtime_resume, sdhci_pci_runtime_idle)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001308};
1309
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001310/*****************************************************************************\
1311 * *
1312 * Device probing/removal *
1313 * *
1314\*****************************************************************************/
1315
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001316static struct sdhci_pci_slot *sdhci_pci_probe_slot(
Adrian Hunter52c506f2011-12-27 15:48:43 +02001317 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1318 int slotno)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001319{
1320 struct sdhci_pci_slot *slot;
1321 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001322 int ret, bar = first_bar + slotno;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001323
1324 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1325 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1326 return ERR_PTR(-ENODEV);
1327 }
1328
Adrian Hunter90b3e6c2012-10-18 09:54:31 +03001329 if (pci_resource_len(pdev, bar) < 0x100) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001330 dev_err(&pdev->dev, "Invalid iomem size. You may "
1331 "experience problems.\n");
1332 }
1333
1334 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1335 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1336 return ERR_PTR(-ENODEV);
1337 }
1338
1339 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1340 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1341 return ERR_PTR(-ENODEV);
1342 }
1343
1344 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1345 if (IS_ERR(host)) {
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001346 dev_err(&pdev->dev, "cannot allocate host\n");
Julia Lawalldc0fd7b2010-05-26 14:42:11 -07001347 return ERR_CAST(host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001348 }
1349
1350 slot = sdhci_priv(host);
1351
1352 slot->chip = chip;
1353 slot->host = host;
1354 slot->pci_bar = bar;
Adrian Hunter0f201652011-08-29 16:42:13 +03001355 slot->rst_n_gpio = -EINVAL;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001356 slot->cd_gpio = -EINVAL;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001357
Adrian Hunter52c506f2011-12-27 15:48:43 +02001358 /* Retrieve platform data if there is any */
1359 if (*sdhci_pci_get_data)
1360 slot->data = sdhci_pci_get_data(pdev, slotno);
1361
1362 if (slot->data) {
1363 if (slot->data->setup) {
1364 ret = slot->data->setup(slot->data);
1365 if (ret) {
1366 dev_err(&pdev->dev, "platform setup failed\n");
1367 goto free;
1368 }
1369 }
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001370 slot->rst_n_gpio = slot->data->rst_n_gpio;
1371 slot->cd_gpio = slot->data->cd_gpio;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001372 }
1373
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001374 host->hw_name = "PCI";
1375 host->ops = &sdhci_pci_ops;
1376 host->quirks = chip->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001377 host->quirks2 = chip->quirks2;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001378
1379 host->irq = pdev->irq;
1380
1381 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1382 if (ret) {
1383 dev_err(&pdev->dev, "cannot request region\n");
Adrian Hunter52c506f2011-12-27 15:48:43 +02001384 goto cleanup;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001385 }
1386
Arjan van de Ven092f82e2008-09-28 16:15:56 -07001387 host->ioaddr = pci_ioremap_bar(pdev, bar);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001388 if (!host->ioaddr) {
1389 dev_err(&pdev->dev, "failed to remap registers\n");
Chris Ball9fdcdbb2011-03-29 00:46:12 -04001390 ret = -ENOMEM;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001391 goto release;
1392 }
1393
Pierre Ossman44894282008-04-04 19:36:59 +02001394 if (chip->fixes && chip->fixes->probe_slot) {
1395 ret = chip->fixes->probe_slot(slot);
1396 if (ret)
1397 goto unmap;
1398 }
1399
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001400 if (gpio_is_valid(slot->rst_n_gpio)) {
1401 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1402 gpio_direction_output(slot->rst_n_gpio, 1);
1403 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
Adrian Hunterc9faff62013-06-13 11:50:26 +03001404 slot->hw_reset = sdhci_pci_gpio_hw_reset;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001405 } else {
1406 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1407 slot->rst_n_gpio = -EINVAL;
1408 }
1409 }
1410
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001411 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
Aaron Lueed222a2013-03-05 11:24:52 +08001412 host->mmc->slotno = slotno;
Adrian Huntera08b17b2013-04-15 11:27:25 -04001413 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001414
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001415 ret = sdhci_add_host(host);
1416 if (ret)
Pierre Ossman44894282008-04-04 19:36:59 +02001417 goto remove;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001418
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001419 sdhci_pci_add_own_cd(slot);
1420
Adrian Hunter77a01222014-01-13 09:49:16 +02001421 /*
1422 * Check if the chip needs a separate GPIO for card detect to wake up
1423 * from runtime suspend. If it is not there, don't allow runtime PM.
1424 * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
1425 */
Adrian Hunter945be382014-01-21 09:52:39 +02001426 if (chip->fixes && chip->fixes->own_cd_for_runtime_pm &&
1427 !gpio_is_valid(slot->cd_gpio))
Adrian Hunter77a01222014-01-13 09:49:16 +02001428 chip->allow_runtime_pm = false;
1429
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001430 return slot;
1431
Pierre Ossman44894282008-04-04 19:36:59 +02001432remove:
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001433 if (gpio_is_valid(slot->rst_n_gpio))
1434 gpio_free(slot->rst_n_gpio);
1435
Pierre Ossman44894282008-04-04 19:36:59 +02001436 if (chip->fixes && chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001437 chip->fixes->remove_slot(slot, 0);
Pierre Ossman44894282008-04-04 19:36:59 +02001438
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001439unmap:
1440 iounmap(host->ioaddr);
1441
1442release:
1443 pci_release_region(pdev, bar);
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001444
Adrian Hunter52c506f2011-12-27 15:48:43 +02001445cleanup:
1446 if (slot->data && slot->data->cleanup)
1447 slot->data->cleanup(slot->data);
1448
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001449free:
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001450 sdhci_free_host(host);
1451
1452 return ERR_PTR(ret);
1453}
1454
1455static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1456{
Pierre Ossman1e728592008-04-16 19:13:13 +02001457 int dead;
1458 u32 scratch;
1459
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001460 sdhci_pci_remove_own_cd(slot);
1461
Pierre Ossman1e728592008-04-16 19:13:13 +02001462 dead = 0;
1463 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1464 if (scratch == (u32)-1)
1465 dead = 1;
1466
1467 sdhci_remove_host(slot->host, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001468
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001469 if (gpio_is_valid(slot->rst_n_gpio))
1470 gpio_free(slot->rst_n_gpio);
1471
Pierre Ossman44894282008-04-04 19:36:59 +02001472 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001473 slot->chip->fixes->remove_slot(slot, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001474
Adrian Hunter52c506f2011-12-27 15:48:43 +02001475 if (slot->data && slot->data->cleanup)
1476 slot->data->cleanup(slot->data);
1477
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001478 pci_release_region(slot->chip->pdev, slot->pci_bar);
Pierre Ossman44894282008-04-04 19:36:59 +02001479
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001480 sdhci_free_host(slot->host);
1481}
1482
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001483static void sdhci_pci_runtime_pm_allow(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001484{
1485 pm_runtime_put_noidle(dev);
1486 pm_runtime_allow(dev);
1487 pm_runtime_set_autosuspend_delay(dev, 50);
1488 pm_runtime_use_autosuspend(dev);
1489 pm_suspend_ignore_children(dev, 1);
1490}
1491
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001492static void sdhci_pci_runtime_pm_forbid(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001493{
1494 pm_runtime_forbid(dev);
1495 pm_runtime_get_noresume(dev);
1496}
1497
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001498static int sdhci_pci_probe(struct pci_dev *pdev,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001499 const struct pci_device_id *ent)
1500{
1501 struct sdhci_pci_chip *chip;
1502 struct sdhci_pci_slot *slot;
1503
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001504 u8 slots, first_bar;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001505 int ret, i;
1506
1507 BUG_ON(pdev == NULL);
1508 BUG_ON(ent == NULL);
1509
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001510 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001511 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001512
1513 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1514 if (ret)
1515 return ret;
1516
1517 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1518 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1519 if (slots == 0)
1520 return -ENODEV;
1521
1522 BUG_ON(slots > MAX_SLOTS);
1523
1524 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1525 if (ret)
1526 return ret;
1527
1528 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1529
1530 if (first_bar > 5) {
1531 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1532 return -ENODEV;
1533 }
1534
1535 ret = pci_enable_device(pdev);
1536 if (ret)
1537 return ret;
1538
1539 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
1540 if (!chip) {
1541 ret = -ENOMEM;
1542 goto err;
1543 }
1544
1545 chip->pdev = pdev;
Ameya Palandeb177bc92011-04-05 21:13:13 +03001546 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001547 if (chip->fixes) {
Pierre Ossman22606402008-03-23 19:33:23 +01001548 chip->quirks = chip->fixes->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001549 chip->quirks2 = chip->fixes->quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001550 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1551 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001552 chip->num_slots = slots;
1553
1554 pci_set_drvdata(pdev, chip);
1555
Pierre Ossman22606402008-03-23 19:33:23 +01001556 if (chip->fixes && chip->fixes->probe) {
1557 ret = chip->fixes->probe(chip);
1558 if (ret)
1559 goto free;
1560 }
1561
Alan Cox225d85f2010-10-04 15:24:21 +01001562 slots = chip->num_slots; /* Quirk may have changed this */
1563
Ameya Palandeb177bc92011-04-05 21:13:13 +03001564 for (i = 0; i < slots; i++) {
Adrian Hunter52c506f2011-12-27 15:48:43 +02001565 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001566 if (IS_ERR(slot)) {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001567 for (i--; i >= 0; i--)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001568 sdhci_pci_remove_slot(chip->slots[i]);
1569 ret = PTR_ERR(slot);
1570 goto free;
1571 }
1572
1573 chip->slots[i] = slot;
1574 }
1575
Adrian Hunterc43fd772011-10-17 10:52:44 +03001576 if (chip->allow_runtime_pm)
1577 sdhci_pci_runtime_pm_allow(&pdev->dev);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001578
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001579 return 0;
1580
1581free:
1582 pci_set_drvdata(pdev, NULL);
1583 kfree(chip);
1584
1585err:
1586 pci_disable_device(pdev);
1587 return ret;
1588}
1589
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001590static void sdhci_pci_remove(struct pci_dev *pdev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001591{
1592 int i;
1593 struct sdhci_pci_chip *chip;
1594
1595 chip = pci_get_drvdata(pdev);
1596
1597 if (chip) {
Adrian Hunterc43fd772011-10-17 10:52:44 +03001598 if (chip->allow_runtime_pm)
1599 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1600
Ameya Palandeb177bc92011-04-05 21:13:13 +03001601 for (i = 0; i < chip->num_slots; i++)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001602 sdhci_pci_remove_slot(chip->slots[i]);
1603
1604 pci_set_drvdata(pdev, NULL);
1605 kfree(chip);
1606 }
1607
1608 pci_disable_device(pdev);
1609}
1610
1611static struct pci_driver sdhci_driver = {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001612 .name = "sdhci-pci",
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001613 .id_table = pci_ids,
Ameya Palandeb177bc92011-04-05 21:13:13 +03001614 .probe = sdhci_pci_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -05001615 .remove = sdhci_pci_remove,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001616 .driver = {
1617 .pm = &sdhci_pci_pm_ops
1618 },
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001619};
1620
Sachin Kamatacc69642012-08-27 11:57:02 +05301621module_pci_driver(sdhci_driver);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001622
Pierre Ossman32710e82009-04-08 20:14:54 +02001623MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001624MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1625MODULE_LICENSE("GPL");