blob: 03427755b9029b297393d1d43851b4f678f2bbae [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 Hunterff59c522014-09-24 10:27:31 +030027#include <linux/mmc/slot-gpio.h>
Adrian Hunter52c506f2011-12-27 15:48:43 +020028#include <linux/mmc/sdhci-pci-data.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010029
30#include "sdhci.h"
Adam Lee522624f2013-12-18 22:23:38 +080031#include "sdhci-pci.h"
Adam Lee01acf692013-12-19 00:01:26 +080032#include "sdhci-pci-o2micro.h"
Pierre Ossman22606402008-03-23 19:33:23 +010033
34/*****************************************************************************\
35 * *
36 * Hardware specific quirk handling *
37 * *
38\*****************************************************************************/
39
40static int ricoh_probe(struct sdhci_pci_chip *chip)
41{
Chris Ballc99436f2009-09-22 16:45:22 -070042 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
43 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
Pierre Ossman22606402008-03-23 19:33:23 +010044 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
Maxim Levitskyccc92c22010-08-10 18:01:42 -070045 return 0;
46}
Pierre Ossman22606402008-03-23 19:33:23 +010047
Maxim Levitskyccc92c22010-08-10 18:01:42 -070048static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
49{
50 slot->host->caps =
51 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
52 & SDHCI_TIMEOUT_CLK_MASK) |
53
54 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
55 & SDHCI_CLOCK_BASE_MASK) |
56
57 SDHCI_TIMEOUT_CLK_UNIT |
58 SDHCI_CAN_VDD_330 |
Madhvapathi Sriram1a1f1f02012-10-15 04:47:30 +000059 SDHCI_CAN_DO_HISPD |
Maxim Levitskyccc92c22010-08-10 18:01:42 -070060 SDHCI_CAN_DO_SDMA;
61 return 0;
62}
63
64static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
65{
66 /* Apply a delay to allow controller to settle */
67 /* Otherwise it becomes confused if card state changed
68 during suspend */
69 msleep(500);
Pierre Ossman22606402008-03-23 19:33:23 +010070 return 0;
71}
72
73static const struct sdhci_pci_fixes sdhci_ricoh = {
74 .probe = ricoh_probe,
Vasily Khoruzhick84938292010-03-05 13:43:46 -080075 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
76 SDHCI_QUIRK_FORCE_DMA |
77 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
Pierre Ossman22606402008-03-23 19:33:23 +010078};
79
Maxim Levitskyccc92c22010-08-10 18:01:42 -070080static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
81 .probe_slot = ricoh_mmc_probe_slot,
82 .resume = ricoh_mmc_resume,
83 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
84 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
85 SDHCI_QUIRK_NO_CARD_NO_RESET |
86 SDHCI_QUIRK_MISSING_CAPS
87};
88
Pierre Ossman22606402008-03-23 19:33:23 +010089static const struct sdhci_pci_fixes sdhci_ene_712 = {
90 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
91 SDHCI_QUIRK_BROKEN_DMA,
92};
93
94static const struct sdhci_pci_fixes sdhci_ene_714 = {
95 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
96 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
97 SDHCI_QUIRK_BROKEN_DMA,
98};
99
100static const struct sdhci_pci_fixes sdhci_cafe = {
101 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
Andres Salomona0874892009-03-02 21:48:20 +0100102 SDHCI_QUIRK_NO_BUSY_IRQ |
Daniel Drake55fc05b2012-07-03 23:13:39 +0100103 SDHCI_QUIRK_BROKEN_CARD_DETECTION |
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200104 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
Pierre Ossman22606402008-03-23 19:33:23 +0100105};
106
Derek Browne43e968c2014-06-24 06:56:36 -0700107static const struct sdhci_pci_fixes sdhci_intel_qrk = {
108 .quirks = SDHCI_QUIRK_NO_HISPD_BIT,
109};
110
Major Lee68077b02011-06-29 14:23:46 +0300111static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
112{
113 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
114 return 0;
115}
116
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100117/*
118 * ADMA operation is disabled for Moorestown platform due to
119 * hardware bugs.
120 */
Jacob Pan35ac6f02010-11-09 13:57:29 +0000121static int mrst_hc_probe(struct sdhci_pci_chip *chip)
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100122{
123 /*
Jacob Pan35ac6f02010-11-09 13:57:29 +0000124 * slots number is fixed here for MRST as SDIO3/5 are never used and
125 * have hardware bugs.
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100126 */
127 chip->num_slots = 1;
128 return 0;
129}
130
Alexander Stein296e0b02012-03-14 08:38:58 +0100131static int pch_hc_probe_slot(struct sdhci_pci_slot *slot)
132{
133 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
134 return 0;
135}
136
Rafael J. Wysocki162d6f92014-12-05 03:05:33 +0100137#ifdef CONFIG_PM
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300138
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200139static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300140{
141 struct sdhci_pci_slot *slot = dev_id;
142 struct sdhci_host *host = slot->host;
143
144 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
145 return IRQ_HANDLED;
146}
147
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200148static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300149{
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200150 int err, irq, gpio = slot->cd_gpio;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300151
152 slot->cd_gpio = -EINVAL;
153 slot->cd_irq = -EINVAL;
154
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200155 if (!gpio_is_valid(gpio))
156 return;
157
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300158 err = gpio_request(gpio, "sd_cd");
159 if (err < 0)
160 goto out;
161
162 err = gpio_direction_input(gpio);
163 if (err < 0)
164 goto out_free;
165
166 irq = gpio_to_irq(gpio);
167 if (irq < 0)
168 goto out_free;
169
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200170 err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300171 IRQF_TRIGGER_FALLING, "sd_cd", slot);
172 if (err)
173 goto out_free;
174
175 slot->cd_gpio = gpio;
176 slot->cd_irq = irq;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300177
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200178 return;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300179
180out_free:
181 gpio_free(gpio);
182out:
183 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300184}
185
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200186static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300187{
188 if (slot->cd_irq >= 0)
189 free_irq(slot->cd_irq, slot);
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200190 if (gpio_is_valid(slot->cd_gpio))
191 gpio_free(slot->cd_gpio);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300192}
193
194#else
195
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200196static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
197{
198}
199
200static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
201{
202}
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300203
204#endif
205
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300206static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
207{
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300208 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
Adrian Hunterda721cf2012-02-07 14:48:53 +0200209 slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
210 MMC_CAP2_HC_ERASE_SZ;
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300211 return 0;
212}
213
Adrian Hunter93933502011-12-27 15:48:47 +0200214static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
215{
Adrian Hunter012e4672012-01-30 14:27:18 +0200216 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
Adrian Hunter93933502011-12-27 15:48:47 +0200217 return 0;
218}
219
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100220static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
221 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Major Lee68077b02011-06-29 14:23:46 +0300222 .probe_slot = mrst_hc_probe_slot,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100223};
224
Jacob Pan35ac6f02010-11-09 13:57:29 +0000225static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100226 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000227 .probe = mrst_hc_probe,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100228};
229
Xiaochen Shen29229052010-10-04 15:24:52 +0100230static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
231 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300232 .allow_runtime_pm = true,
Adrian Hunter77a01222014-01-13 09:49:16 +0200233 .own_cd_for_runtime_pm = true,
Xiaochen Shen29229052010-10-04 15:24:52 +0100234};
235
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300236static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
Xiaochen Shen29229052010-10-04 15:24:52 +0100237 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterf3c55a72012-02-07 14:48:55 +0200238 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300239 .allow_runtime_pm = true,
Adrian Hunter93933502011-12-27 15:48:47 +0200240 .probe_slot = mfd_sdio_probe_slot,
Xiaochen Shen29229052010-10-04 15:24:52 +0100241};
242
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300243static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
244 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300245 .allow_runtime_pm = true,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300246 .probe_slot = mfd_emmc_probe_slot,
247};
248
Alexander Stein296e0b02012-03-14 08:38:58 +0100249static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = {
250 .quirks = SDHCI_QUIRK_BROKEN_ADMA,
251 .probe_slot = pch_hc_probe_slot,
252};
253
Adrian Hunterc9faff62013-06-13 11:50:26 +0300254static void sdhci_pci_int_hw_reset(struct sdhci_host *host)
255{
256 u8 reg;
257
258 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
259 reg |= 0x10;
260 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
261 /* For eMMC, minimum is 1us but give it 9us for good measure */
262 udelay(9);
263 reg &= ~0x10;
264 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
265 /* For eMMC, minimum is 200us but give it 300us for good measure */
266 usleep_range(300, 1000);
267}
268
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300269static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
270{
Adrian Hunterc9faff62013-06-13 11:50:26 +0300271 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
Adrian Hunter6aab23a2014-12-01 15:51:18 +0200272 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
273 MMC_CAP_BUS_WIDTH_TEST |
274 MMC_CAP_WAIT_WHILE_BUSY;
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300275 slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
Adrian Hunterc9faff62013-06-13 11:50:26 +0300276 slot->hw_reset = sdhci_pci_int_hw_reset;
Adrian Huntera06586b2014-09-24 10:27:33 +0300277 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC)
278 slot->host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300279 return 0;
280}
281
282static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
283{
Adrian Hunter6aab23a2014-12-01 15:51:18 +0200284 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE |
285 MMC_CAP_BUS_WIDTH_TEST |
286 MMC_CAP_WAIT_WHILE_BUSY;
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300287 return 0;
288}
289
Adrian Hunterff59c522014-09-24 10:27:31 +0300290static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
291{
Adrian Hunter6aab23a2014-12-01 15:51:18 +0200292 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST |
293 MMC_CAP_WAIT_WHILE_BUSY;
Adrian Hunterff59c522014-09-24 10:27:31 +0300294 slot->cd_con_id = NULL;
295 slot->cd_idx = 0;
296 slot->cd_override_level = true;
297 return 0;
298}
299
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300300static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
301 .allow_runtime_pm = true,
302 .probe_slot = byt_emmc_probe_slot,
Adrian Hunterdb6e8cd2014-12-01 15:51:16 +0200303 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Huntere58e4a02014-09-24 10:27:30 +0300304 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
305 SDHCI_QUIRK2_STOP_WITH_TC,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300306};
307
308static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
Adrian Hunterdb6e8cd2014-12-01 15:51:16 +0200309 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Gao, Yunpengb7574ba2014-09-04 15:18:05 +0800310 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON |
311 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300312 .allow_runtime_pm = true,
313 .probe_slot = byt_sdio_probe_slot,
314};
315
316static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
Adrian Hunterdb6e8cd2014-12-01 15:51:16 +0200317 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Gao, Yunpengb7574ba2014-09-04 15:18:05 +0800318 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
Adrian Huntere58e4a02014-09-24 10:27:30 +0300319 SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
320 SDHCI_QUIRK2_STOP_WITH_TC,
Adrian Hunter7396e312013-05-06 12:17:34 +0300321 .allow_runtime_pm = true,
Adrian Hunter77a01222014-01-13 09:49:16 +0200322 .own_cd_for_runtime_pm = true,
Adrian Hunterff59c522014-09-24 10:27:31 +0300323 .probe_slot = byt_sd_probe_slot,
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300324};
325
David Cohen8776a162013-10-01 13:18:15 -0700326/* Define Host controllers for Intel Merrifield platform */
327#define INTEL_MRFL_EMMC_0 0
328#define INTEL_MRFL_EMMC_1 1
329
330static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
331{
332 if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_0) &&
333 (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_1))
334 /* SD support is not ready yet */
335 return -ENODEV;
336
337 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
338 MMC_CAP_1_8V_DDR;
339
340 return 0;
341}
342
343static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
344 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Gao, Yunpengb7574ba2014-09-04 15:18:05 +0800345 .quirks2 = SDHCI_QUIRK2_BROKEN_HS200 |
346 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
Gao, Yunpengf1b55a52014-08-18 15:05:52 +0800347 .allow_runtime_pm = true,
David Cohen8776a162013-10-01 13:18:15 -0700348 .probe_slot = intel_mrfl_mmc_probe_slot,
349};
350
Jennifer Li26daa1e2010-11-17 23:01:59 -0500351/* O2Micro extra registers */
352#define O2_SD_LOCK_WP 0xD3
353#define O2_SD_MULTI_VCC3V 0xEE
354#define O2_SD_CLKREQ 0xEC
355#define O2_SD_CAPS 0xE0
356#define O2_SD_ADMA1 0xE2
357#define O2_SD_ADMA2 0xE7
358#define O2_SD_INF_MOD 0xF1
359
Pierre Ossman45211e22008-03-24 13:09:09 +0100360static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
361{
362 u8 scratch;
363 int ret;
364
365 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
366 if (ret)
367 return ret;
368
369 /*
370 * Turn PMOS on [bit 0], set over current detection to 2.4 V
371 * [bit 1:2] and enable over current debouncing [bit 6].
372 */
373 if (on)
374 scratch |= 0x47;
375 else
376 scratch &= ~0x47;
377
378 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
379 if (ret)
380 return ret;
381
382 return 0;
383}
384
385static int jmicron_probe(struct sdhci_pci_chip *chip)
386{
387 int ret;
Takashi Iwai8f230f42010-12-08 10:04:30 +0100388 u16 mmcdev = 0;
Pierre Ossman45211e22008-03-24 13:09:09 +0100389
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200390 if (chip->pdev->revision == 0) {
391 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
392 SDHCI_QUIRK_32BIT_DMA_SIZE |
Pierre Ossman2134a922008-06-28 18:28:51 +0200393 SDHCI_QUIRK_32BIT_ADMA_SIZE |
Pierre Ossman4a3cba32008-07-29 00:11:16 +0200394 SDHCI_QUIRK_RESET_AFTER_REQUEST |
Pierre Ossman86a6a872009-02-02 21:13:49 +0100395 SDHCI_QUIRK_BROKEN_SMALL_PIO;
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200396 }
397
Pierre Ossman45211e22008-03-24 13:09:09 +0100398 /*
Pierre Ossman44894282008-04-04 19:36:59 +0200399 * JMicron chips can have two interfaces to the same hardware
400 * in order to work around limitations in Microsoft's driver.
401 * We need to make sure we only bind to one of them.
402 *
403 * This code assumes two things:
404 *
405 * 1. The PCI code adds subfunctions in order.
406 *
407 * 2. The MMC interface has a lower subfunction number
408 * than the SD interface.
409 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100410 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
411 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
412 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
413 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
414
415 if (mmcdev) {
Pierre Ossman44894282008-04-04 19:36:59 +0200416 struct pci_dev *sd_dev;
417
418 sd_dev = NULL;
419 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
Takashi Iwai8f230f42010-12-08 10:04:30 +0100420 mmcdev, sd_dev)) != NULL) {
Pierre Ossman44894282008-04-04 19:36:59 +0200421 if ((PCI_SLOT(chip->pdev->devfn) ==
422 PCI_SLOT(sd_dev->devfn)) &&
423 (chip->pdev->bus == sd_dev->bus))
424 break;
425 }
426
427 if (sd_dev) {
428 pci_dev_put(sd_dev);
429 dev_info(&chip->pdev->dev, "Refusing to bind to "
430 "secondary interface.\n");
431 return -ENODEV;
432 }
433 }
434
435 /*
Pierre Ossman45211e22008-03-24 13:09:09 +0100436 * JMicron chips need a bit of a nudge to enable the power
437 * output pins.
438 */
439 ret = jmicron_pmos(chip, 1);
440 if (ret) {
441 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
442 return ret;
443 }
444
Takashi Iwai82b0e232011-04-21 20:26:38 +0200445 /* quirk for unsable RO-detection on JM388 chips */
446 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
447 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
448 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
449
Pierre Ossman45211e22008-03-24 13:09:09 +0100450 return 0;
451}
452
Pierre Ossman44894282008-04-04 19:36:59 +0200453static void jmicron_enable_mmc(struct sdhci_host *host, int on)
454{
455 u8 scratch;
456
457 scratch = readb(host->ioaddr + 0xC0);
458
459 if (on)
460 scratch |= 0x01;
461 else
462 scratch &= ~0x01;
463
464 writeb(scratch, host->ioaddr + 0xC0);
465}
466
467static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
468{
Pierre Ossman2134a922008-06-28 18:28:51 +0200469 if (slot->chip->pdev->revision == 0) {
470 u16 version;
471
472 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
473 version = (version & SDHCI_VENDOR_VER_MASK) >>
474 SDHCI_VENDOR_VER_SHIFT;
475
476 /*
477 * Older versions of the chip have lots of nasty glitches
478 * in the ADMA engine. It's best just to avoid it
479 * completely.
480 */
481 if (version < 0xAC)
482 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
483 }
484
Takashi Iwai8f230f42010-12-08 10:04:30 +0100485 /* JM388 MMC doesn't support 1.8V while SD supports it */
486 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
487 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
488 MMC_VDD_29_30 | MMC_VDD_30_31 |
489 MMC_VDD_165_195; /* allow 1.8V */
490 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
491 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
492 }
493
Pierre Ossman44894282008-04-04 19:36:59 +0200494 /*
495 * The secondary interface requires a bit set to get the
496 * interrupts.
497 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100498 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
499 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200500 jmicron_enable_mmc(slot->host, 1);
501
Takashi Iwaid75c1082010-12-16 17:54:14 +0100502 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
503
Pierre Ossman44894282008-04-04 19:36:59 +0200504 return 0;
505}
506
Pierre Ossman1e728592008-04-16 19:13:13 +0200507static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
Pierre Ossman44894282008-04-04 19:36:59 +0200508{
Pierre Ossman1e728592008-04-16 19:13:13 +0200509 if (dead)
510 return;
511
Takashi Iwai8f230f42010-12-08 10:04:30 +0100512 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
513 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200514 jmicron_enable_mmc(slot->host, 0);
515}
516
Manuel Lauss29495aa2011-11-03 11:09:45 +0100517static int jmicron_suspend(struct sdhci_pci_chip *chip)
Pierre Ossman44894282008-04-04 19:36:59 +0200518{
519 int i;
520
Takashi Iwai8f230f42010-12-08 10:04:30 +0100521 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
522 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300523 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200524 jmicron_enable_mmc(chip->slots[i]->host, 0);
525 }
526
527 return 0;
528}
529
Pierre Ossman45211e22008-03-24 13:09:09 +0100530static int jmicron_resume(struct sdhci_pci_chip *chip)
531{
Pierre Ossman44894282008-04-04 19:36:59 +0200532 int ret, i;
533
Takashi Iwai8f230f42010-12-08 10:04:30 +0100534 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
535 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300536 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200537 jmicron_enable_mmc(chip->slots[i]->host, 1);
538 }
Pierre Ossman45211e22008-03-24 13:09:09 +0100539
540 ret = jmicron_pmos(chip, 1);
541 if (ret) {
542 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
543 return ret;
544 }
545
546 return 0;
547}
548
Jennifer Li26daa1e2010-11-17 23:01:59 -0500549static const struct sdhci_pci_fixes sdhci_o2 = {
Adam Lee01acf692013-12-19 00:01:26 +0800550 .probe = sdhci_pci_o2_probe,
551 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
552 .probe_slot = sdhci_pci_o2_probe_slot,
553 .resume = sdhci_pci_o2_resume,
Jennifer Li26daa1e2010-11-17 23:01:59 -0500554};
555
Pierre Ossman22606402008-03-23 19:33:23 +0100556static const struct sdhci_pci_fixes sdhci_jmicron = {
Pierre Ossman45211e22008-03-24 13:09:09 +0100557 .probe = jmicron_probe,
558
Pierre Ossman44894282008-04-04 19:36:59 +0200559 .probe_slot = jmicron_probe_slot,
560 .remove_slot = jmicron_remove_slot,
561
562 .suspend = jmicron_suspend,
Pierre Ossman45211e22008-03-24 13:09:09 +0100563 .resume = jmicron_resume,
Pierre Ossman22606402008-03-23 19:33:23 +0100564};
565
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800566/* SysKonnect CardBus2SDIO extra registers */
567#define SYSKT_CTRL 0x200
568#define SYSKT_RDFIFO_STAT 0x204
569#define SYSKT_WRFIFO_STAT 0x208
570#define SYSKT_POWER_DATA 0x20c
571#define SYSKT_POWER_330 0xef
572#define SYSKT_POWER_300 0xf8
573#define SYSKT_POWER_184 0xcc
574#define SYSKT_POWER_CMD 0x20d
575#define SYSKT_POWER_START (1 << 7)
576#define SYSKT_POWER_STATUS 0x20e
577#define SYSKT_POWER_STATUS_OK (1 << 0)
578#define SYSKT_BOARD_REV 0x210
579#define SYSKT_CHIP_REV 0x211
580#define SYSKT_CONF_DATA 0x212
581#define SYSKT_CONF_DATA_1V8 (1 << 2)
582#define SYSKT_CONF_DATA_2V5 (1 << 1)
583#define SYSKT_CONF_DATA_3V3 (1 << 0)
584
585static int syskt_probe(struct sdhci_pci_chip *chip)
586{
587 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
588 chip->pdev->class &= ~0x0000FF;
589 chip->pdev->class |= PCI_SDHCI_IFDMA;
590 }
591 return 0;
592}
593
594static int syskt_probe_slot(struct sdhci_pci_slot *slot)
595{
596 int tm, ps;
597
598 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
599 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
600 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
601 "board rev %d.%d, chip rev %d.%d\n",
602 board_rev >> 4, board_rev & 0xf,
603 chip_rev >> 4, chip_rev & 0xf);
604 if (chip_rev >= 0x20)
605 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
606
607 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
608 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
609 udelay(50);
610 tm = 10; /* Wait max 1 ms */
611 do {
612 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
613 if (ps & SYSKT_POWER_STATUS_OK)
614 break;
615 udelay(100);
616 } while (--tm);
617 if (!tm) {
618 dev_err(&slot->chip->pdev->dev,
619 "power regulator never stabilized");
620 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
621 return -ENODEV;
622 }
623
624 return 0;
625}
626
627static const struct sdhci_pci_fixes sdhci_syskt = {
628 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
629 .probe = syskt_probe,
630 .probe_slot = syskt_probe_slot,
631};
632
Harald Welte557b0692009-06-18 16:53:38 +0200633static int via_probe(struct sdhci_pci_chip *chip)
634{
635 if (chip->pdev->revision == 0x10)
636 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
637
638 return 0;
639}
640
641static const struct sdhci_pci_fixes sdhci_via = {
642 .probe = via_probe,
643};
644
Micky Ching9107ebb2014-02-21 18:40:35 +0800645static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
646{
647 slot->host->mmc->caps2 |= MMC_CAP2_HS200;
648 return 0;
649}
650
651static const struct sdhci_pci_fixes sdhci_rtsx = {
652 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
653 SDHCI_QUIRK2_BROKEN_DDR50,
654 .probe_slot = rtsx_probe_slot,
655};
656
Vincent Wand44f88d2014-11-05 14:09:14 +0800657static int amd_probe(struct sdhci_pci_chip *chip)
658{
659 struct pci_dev *smbus_dev;
660
661 smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
662 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
663
Vincent Wane765bfa2014-11-05 14:09:28 +0800664 if (smbus_dev && (smbus_dev->revision < 0x51)) {
Vincent Wand44f88d2014-11-05 14:09:14 +0800665 chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD;
Vincent Wane765bfa2014-11-05 14:09:28 +0800666 chip->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
667 }
Vincent Wand44f88d2014-11-05 14:09:14 +0800668
669 return 0;
670}
671
672static const struct sdhci_pci_fixes sdhci_amd = {
673 .probe = amd_probe,
674};
675
Bill Pemberton9647f842012-11-19 13:25:11 -0500676static const struct pci_device_id pci_ids[] = {
Pierre Ossman22606402008-03-23 19:33:23 +0100677 {
678 .vendor = PCI_VENDOR_ID_RICOH,
679 .device = PCI_DEVICE_ID_RICOH_R5C822,
680 .subvendor = PCI_ANY_ID,
681 .subdevice = PCI_ANY_ID,
682 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
683 },
684
685 {
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700686 .vendor = PCI_VENDOR_ID_RICOH,
687 .device = 0x843,
688 .subvendor = PCI_ANY_ID,
689 .subdevice = PCI_ANY_ID,
690 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
691 },
692
693 {
Pablo Castillo568133e2010-08-10 18:02:01 -0700694 .vendor = PCI_VENDOR_ID_RICOH,
695 .device = 0xe822,
696 .subvendor = PCI_ANY_ID,
697 .subdevice = PCI_ANY_ID,
698 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
699 },
700
701 {
Manoj Iyer5fd11c02011-02-11 16:25:31 -0600702 .vendor = PCI_VENDOR_ID_RICOH,
703 .device = 0xe823,
704 .subvendor = PCI_ANY_ID,
705 .subdevice = PCI_ANY_ID,
706 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
707 },
708
709 {
Pierre Ossman22606402008-03-23 19:33:23 +0100710 .vendor = PCI_VENDOR_ID_ENE,
711 .device = PCI_DEVICE_ID_ENE_CB712_SD,
712 .subvendor = PCI_ANY_ID,
713 .subdevice = PCI_ANY_ID,
714 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
715 },
716
717 {
718 .vendor = PCI_VENDOR_ID_ENE,
719 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
720 .subvendor = PCI_ANY_ID,
721 .subdevice = PCI_ANY_ID,
722 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
723 },
724
725 {
726 .vendor = PCI_VENDOR_ID_ENE,
727 .device = PCI_DEVICE_ID_ENE_CB714_SD,
728 .subvendor = PCI_ANY_ID,
729 .subdevice = PCI_ANY_ID,
730 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
731 },
732
733 {
734 .vendor = PCI_VENDOR_ID_ENE,
735 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
736 .subvendor = PCI_ANY_ID,
737 .subdevice = PCI_ANY_ID,
738 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
739 },
740
741 {
742 .vendor = PCI_VENDOR_ID_MARVELL,
David Woodhouse8c5eb882008-09-03 09:45:57 +0100743 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
Pierre Ossman22606402008-03-23 19:33:23 +0100744 .subvendor = PCI_ANY_ID,
745 .subdevice = PCI_ANY_ID,
746 .driver_data = (kernel_ulong_t)&sdhci_cafe,
747 },
748
749 {
750 .vendor = PCI_VENDOR_ID_JMICRON,
751 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
752 .subvendor = PCI_ANY_ID,
753 .subdevice = PCI_ANY_ID,
754 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
755 },
756
Pierre Ossman44894282008-04-04 19:36:59 +0200757 {
758 .vendor = PCI_VENDOR_ID_JMICRON,
759 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
760 .subvendor = PCI_ANY_ID,
761 .subdevice = PCI_ANY_ID,
762 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
763 },
764
Harald Welte557b0692009-06-18 16:53:38 +0200765 {
Takashi Iwai8f230f42010-12-08 10:04:30 +0100766 .vendor = PCI_VENDOR_ID_JMICRON,
767 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
768 .subvendor = PCI_ANY_ID,
769 .subdevice = PCI_ANY_ID,
770 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
771 },
772
773 {
774 .vendor = PCI_VENDOR_ID_JMICRON,
775 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
776 .subvendor = PCI_ANY_ID,
777 .subdevice = PCI_ANY_ID,
778 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
779 },
780
781 {
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800782 .vendor = PCI_VENDOR_ID_SYSKONNECT,
783 .device = 0x8000,
784 .subvendor = PCI_ANY_ID,
785 .subdevice = PCI_ANY_ID,
786 .driver_data = (kernel_ulong_t)&sdhci_syskt,
787 },
788
789 {
Harald Welte557b0692009-06-18 16:53:38 +0200790 .vendor = PCI_VENDOR_ID_VIA,
791 .device = 0x95d0,
792 .subvendor = PCI_ANY_ID,
793 .subdevice = PCI_ANY_ID,
794 .driver_data = (kernel_ulong_t)&sdhci_via,
795 },
796
Xiaochen Shen29229052010-10-04 15:24:52 +0100797 {
Micky Ching9107ebb2014-02-21 18:40:35 +0800798 .vendor = PCI_VENDOR_ID_REALTEK,
799 .device = 0x5250,
800 .subvendor = PCI_ANY_ID,
801 .subdevice = PCI_ANY_ID,
802 .driver_data = (kernel_ulong_t)&sdhci_rtsx,
803 },
804
805 {
Xiaochen Shen29229052010-10-04 15:24:52 +0100806 .vendor = PCI_VENDOR_ID_INTEL,
Derek Browne43e968c2014-06-24 06:56:36 -0700807 .device = PCI_DEVICE_ID_INTEL_QRK_SD,
808 .subvendor = PCI_ANY_ID,
809 .subdevice = PCI_ANY_ID,
810 .driver_data = (kernel_ulong_t)&sdhci_intel_qrk,
811 },
812
813 {
814 .vendor = PCI_VENDOR_ID_INTEL,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100815 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
816 .subvendor = PCI_ANY_ID,
817 .subdevice = PCI_ANY_ID,
818 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
819 },
820
821 {
822 .vendor = PCI_VENDOR_ID_INTEL,
823 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
824 .subvendor = PCI_ANY_ID,
825 .subdevice = PCI_ANY_ID,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000826 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
827 },
828
829 {
830 .vendor = PCI_VENDOR_ID_INTEL,
831 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
832 .subvendor = PCI_ANY_ID,
833 .subdevice = PCI_ANY_ID,
834 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100835 },
836
837 {
838 .vendor = PCI_VENDOR_ID_INTEL,
Xiaochen Shen29229052010-10-04 15:24:52 +0100839 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
840 .subvendor = PCI_ANY_ID,
841 .subdevice = PCI_ANY_ID,
842 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
843 },
844
845 {
846 .vendor = PCI_VENDOR_ID_INTEL,
847 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
848 .subvendor = PCI_ANY_ID,
849 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300850 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100851 },
852
853 {
854 .vendor = PCI_VENDOR_ID_INTEL,
855 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
856 .subvendor = PCI_ANY_ID,
857 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300858 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100859 },
860
861 {
862 .vendor = PCI_VENDOR_ID_INTEL,
863 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
864 .subvendor = PCI_ANY_ID,
865 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300866 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100867 },
868
869 {
870 .vendor = PCI_VENDOR_ID_INTEL,
871 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
872 .subvendor = PCI_ANY_ID,
873 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300874 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100875 },
876
Jennifer Li26daa1e2010-11-17 23:01:59 -0500877 {
Alexander Stein296e0b02012-03-14 08:38:58 +0100878 .vendor = PCI_VENDOR_ID_INTEL,
879 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
880 .subvendor = PCI_ANY_ID,
881 .subdevice = PCI_ANY_ID,
882 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
883 },
884
885 {
886 .vendor = PCI_VENDOR_ID_INTEL,
887 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
888 .subvendor = PCI_ANY_ID,
889 .subdevice = PCI_ANY_ID,
890 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
891 },
892
893 {
Adrian Hunter728ef3d2013-04-26 11:27:23 +0300894 .vendor = PCI_VENDOR_ID_INTEL,
895 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC,
896 .subvendor = PCI_ANY_ID,
897 .subdevice = PCI_ANY_ID,
898 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
899 },
900
901 {
902 .vendor = PCI_VENDOR_ID_INTEL,
903 .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
904 .subvendor = PCI_ANY_ID,
905 .subdevice = PCI_ANY_ID,
906 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
907 },
908
909 {
910 .vendor = PCI_VENDOR_ID_INTEL,
911 .device = PCI_DEVICE_ID_INTEL_BYT_SD,
912 .subvendor = PCI_ANY_ID,
913 .subdevice = PCI_ANY_ID,
914 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
915 },
916
917 {
Adrian Hunter30d025c2013-06-20 12:57:59 +0300918 .vendor = PCI_VENDOR_ID_INTEL,
919 .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2,
920 .subvendor = PCI_ANY_ID,
921 .subdevice = PCI_ANY_ID,
922 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
923 },
924
Alan Cox066173b2014-08-20 13:27:44 +0300925 {
926 .vendor = PCI_VENDOR_ID_INTEL,
927 .device = PCI_DEVICE_ID_INTEL_BSW_EMMC,
928 .subvendor = PCI_ANY_ID,
929 .subdevice = PCI_ANY_ID,
930 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
931 },
932
933 {
934 .vendor = PCI_VENDOR_ID_INTEL,
935 .device = PCI_DEVICE_ID_INTEL_BSW_SDIO,
936 .subvendor = PCI_ANY_ID,
937 .subdevice = PCI_ANY_ID,
938 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
939 },
940
941 {
942 .vendor = PCI_VENDOR_ID_INTEL,
943 .device = PCI_DEVICE_ID_INTEL_BSW_SD,
944 .subvendor = PCI_ANY_ID,
945 .subdevice = PCI_ANY_ID,
946 .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
947 },
Eric Ernstd0520682013-10-21 09:54:41 -0700948
949 {
950 .vendor = PCI_VENDOR_ID_INTEL,
951 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
952 .subvendor = PCI_ANY_ID,
953 .subdevice = PCI_ANY_ID,
954 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
955 },
956
957 {
958 .vendor = PCI_VENDOR_ID_INTEL,
959 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
960 .subvendor = PCI_ANY_ID,
961 .subdevice = PCI_ANY_ID,
962 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
963 },
964
965 {
966 .vendor = PCI_VENDOR_ID_INTEL,
967 .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
968 .subvendor = PCI_ANY_ID,
969 .subdevice = PCI_ANY_ID,
970 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
971 },
972
973 {
974 .vendor = PCI_VENDOR_ID_INTEL,
975 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
976 .subvendor = PCI_ANY_ID,
977 .subdevice = PCI_ANY_ID,
978 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
979 },
980
981 {
982 .vendor = PCI_VENDOR_ID_INTEL,
983 .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
984 .subvendor = PCI_ANY_ID,
985 .subdevice = PCI_ANY_ID,
986 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
987 },
988
Adrian Hunter30d025c2013-06-20 12:57:59 +0300989 {
David Cohen8776a162013-10-01 13:18:15 -0700990 .vendor = PCI_VENDOR_ID_INTEL,
991 .device = PCI_DEVICE_ID_INTEL_MRFL_MMC,
992 .subvendor = PCI_ANY_ID,
993 .subdevice = PCI_ANY_ID,
994 .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
995 },
996 {
Jennifer Li26daa1e2010-11-17 23:01:59 -0500997 .vendor = PCI_VENDOR_ID_O2,
998 .device = PCI_DEVICE_ID_O2_8120,
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_8220,
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_8221,
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_8320,
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_8321,
1031 .subvendor = PCI_ANY_ID,
1032 .subdevice = PCI_ANY_ID,
1033 .driver_data = (kernel_ulong_t)&sdhci_o2,
1034 },
1035
Adam Lee01acf692013-12-19 00:01:26 +08001036 {
1037 .vendor = PCI_VENDOR_ID_O2,
1038 .device = PCI_DEVICE_ID_O2_FUJIN2,
1039 .subvendor = PCI_ANY_ID,
1040 .subdevice = PCI_ANY_ID,
1041 .driver_data = (kernel_ulong_t)&sdhci_o2,
1042 },
1043
1044 {
1045 .vendor = PCI_VENDOR_ID_O2,
1046 .device = PCI_DEVICE_ID_O2_SDS0,
1047 .subvendor = PCI_ANY_ID,
1048 .subdevice = PCI_ANY_ID,
1049 .driver_data = (kernel_ulong_t)&sdhci_o2,
1050 },
1051
1052 {
1053 .vendor = PCI_VENDOR_ID_O2,
1054 .device = PCI_DEVICE_ID_O2_SDS1,
1055 .subvendor = PCI_ANY_ID,
1056 .subdevice = PCI_ANY_ID,
1057 .driver_data = (kernel_ulong_t)&sdhci_o2,
1058 },
1059
1060 {
1061 .vendor = PCI_VENDOR_ID_O2,
1062 .device = PCI_DEVICE_ID_O2_SEABIRD0,
1063 .subvendor = PCI_ANY_ID,
1064 .subdevice = PCI_ANY_ID,
1065 .driver_data = (kernel_ulong_t)&sdhci_o2,
1066 },
1067
1068 {
1069 .vendor = PCI_VENDOR_ID_O2,
1070 .device = PCI_DEVICE_ID_O2_SEABIRD1,
1071 .subvendor = PCI_ANY_ID,
1072 .subdevice = PCI_ANY_ID,
1073 .driver_data = (kernel_ulong_t)&sdhci_o2,
1074 },
Vincent Wand44f88d2014-11-05 14:09:14 +08001075 {
1076 .vendor = PCI_VENDOR_ID_AMD,
1077 .device = PCI_ANY_ID,
1078 .class = PCI_CLASS_SYSTEM_SDHCI << 8,
1079 .class_mask = 0xFFFF00,
1080 .subvendor = PCI_ANY_ID,
1081 .subdevice = PCI_ANY_ID,
1082 .driver_data = (kernel_ulong_t)&sdhci_amd,
1083 },
Pierre Ossman22606402008-03-23 19:33:23 +01001084 { /* Generic SD host controller */
1085 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
1086 },
1087
1088 { /* end: all zeroes */ },
1089};
1090
1091MODULE_DEVICE_TABLE(pci, pci_ids);
1092
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001093/*****************************************************************************\
1094 * *
1095 * SDHCI core callbacks *
1096 * *
1097\*****************************************************************************/
1098
1099static int sdhci_pci_enable_dma(struct sdhci_host *host)
1100{
1101 struct sdhci_pci_slot *slot;
1102 struct pci_dev *pdev;
Adrian Hunter3828eca2014-11-04 12:42:48 +02001103 int ret = -1;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001104
1105 slot = sdhci_priv(host);
1106 pdev = slot->chip->pdev;
1107
1108 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
1109 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
Richard Röjforsa13abc72009-09-22 16:45:30 -07001110 (host->flags & SDHCI_USE_SDMA)) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001111 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
1112 "doesn't fully claim to support it.\n");
1113 }
1114
Adrian Hunter3828eca2014-11-04 12:42:48 +02001115 if (host->flags & SDHCI_USE_64_BIT_DMA) {
1116 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) {
1117 host->flags &= ~SDHCI_USE_64_BIT_DMA;
1118 } else {
1119 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
1120 if (ret)
1121 dev_warn(&pdev->dev, "Failed to set 64-bit DMA mask\n");
1122 }
1123 }
1124 if (ret)
1125 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001126 if (ret)
1127 return ret;
1128
1129 pci_set_master(pdev);
1130
1131 return 0;
1132}
1133
Russell King2317f562014-04-25 12:57:07 +01001134static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width)
Major Lee68077b02011-06-29 14:23:46 +03001135{
1136 u8 ctrl;
1137
1138 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1139
1140 switch (width) {
1141 case MMC_BUS_WIDTH_8:
1142 ctrl |= SDHCI_CTRL_8BITBUS;
1143 ctrl &= ~SDHCI_CTRL_4BITBUS;
1144 break;
1145 case MMC_BUS_WIDTH_4:
1146 ctrl |= SDHCI_CTRL_4BITBUS;
1147 ctrl &= ~SDHCI_CTRL_8BITBUS;
1148 break;
1149 default:
1150 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
1151 break;
1152 }
1153
1154 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
Major Lee68077b02011-06-29 14:23:46 +03001155}
1156
Adrian Hunterc9faff62013-06-13 11:50:26 +03001157static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
Adrian Hunter0f201652011-08-29 16:42:13 +03001158{
1159 struct sdhci_pci_slot *slot = sdhci_priv(host);
1160 int rst_n_gpio = slot->rst_n_gpio;
1161
1162 if (!gpio_is_valid(rst_n_gpio))
1163 return;
1164 gpio_set_value_cansleep(rst_n_gpio, 0);
1165 /* For eMMC, minimum is 1us but give it 10us for good measure */
1166 udelay(10);
1167 gpio_set_value_cansleep(rst_n_gpio, 1);
1168 /* For eMMC, minimum is 200us but give it 300us for good measure */
1169 usleep_range(300, 1000);
1170}
1171
Adrian Hunterc9faff62013-06-13 11:50:26 +03001172static void sdhci_pci_hw_reset(struct sdhci_host *host)
1173{
1174 struct sdhci_pci_slot *slot = sdhci_priv(host);
1175
1176 if (slot->hw_reset)
1177 slot->hw_reset(host);
1178}
1179
Lars-Peter Clausenc9155682013-03-13 19:26:05 +01001180static const struct sdhci_ops sdhci_pci_ops = {
Russell King17710592014-04-25 12:58:55 +01001181 .set_clock = sdhci_set_clock,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001182 .enable_dma = sdhci_pci_enable_dma,
Russell King2317f562014-04-25 12:57:07 +01001183 .set_bus_width = sdhci_pci_set_bus_width,
Russell King03231f92014-04-25 12:57:12 +01001184 .reset = sdhci_reset,
Russell King96d7b782014-04-25 12:59:26 +01001185 .set_uhs_signaling = sdhci_set_uhs_signaling,
Adrian Hunter0f201652011-08-29 16:42:13 +03001186 .hw_reset = sdhci_pci_hw_reset,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001187};
1188
1189/*****************************************************************************\
1190 * *
1191 * Suspend/resume *
1192 * *
1193\*****************************************************************************/
1194
1195#ifdef CONFIG_PM
1196
Manuel Lauss29495aa2011-11-03 11:09:45 +01001197static int sdhci_pci_suspend(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001198{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001199 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001200 struct sdhci_pci_chip *chip;
1201 struct sdhci_pci_slot *slot;
Daniel Drake5f619702010-11-04 22:20:39 +00001202 mmc_pm_flag_t slot_pm_flags;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001203 mmc_pm_flag_t pm_flags = 0;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001204 int i, ret;
1205
1206 chip = pci_get_drvdata(pdev);
1207 if (!chip)
1208 return 0;
1209
Ameya Palandeb177bc92011-04-05 21:13:13 +03001210 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001211 slot = chip->slots[i];
1212 if (!slot)
1213 continue;
1214
Manuel Lauss29495aa2011-11-03 11:09:45 +01001215 ret = sdhci_suspend_host(slot->host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001216
Axel Linb678b912011-12-03 15:28:05 +08001217 if (ret)
1218 goto err_pci_suspend;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001219
Daniel Drake5f619702010-11-04 22:20:39 +00001220 slot_pm_flags = slot->host->mmc->pm_flags;
1221 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1222 sdhci_enable_irq_wakeups(slot->host);
1223
1224 pm_flags |= slot_pm_flags;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001225 }
1226
Pierre Ossman44894282008-04-04 19:36:59 +02001227 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001228 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001229 if (ret)
1230 goto err_pci_suspend;
Pierre Ossman44894282008-04-04 19:36:59 +02001231 }
1232
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001233 if (pm_flags & MMC_PM_KEEP_POWER) {
Chuanxiao.Dong6b91f2d2014-07-15 17:28:05 +08001234 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1235 device_init_wakeup(dev, true);
1236 else
1237 device_init_wakeup(dev, false);
1238 } else
1239 device_init_wakeup(dev, false);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001240
1241 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001242
1243err_pci_suspend:
1244 while (--i >= 0)
1245 sdhci_resume_host(chip->slots[i]->host);
1246 return ret;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001247}
1248
Manuel Lauss29495aa2011-11-03 11:09:45 +01001249static int sdhci_pci_resume(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001250{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001251 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001252 struct sdhci_pci_chip *chip;
1253 struct sdhci_pci_slot *slot;
1254 int i, ret;
1255
1256 chip = pci_get_drvdata(pdev);
1257 if (!chip)
1258 return 0;
1259
Pierre Ossman45211e22008-03-24 13:09:09 +01001260 if (chip->fixes && chip->fixes->resume) {
1261 ret = chip->fixes->resume(chip);
1262 if (ret)
1263 return ret;
1264 }
1265
Ameya Palandeb177bc92011-04-05 21:13:13 +03001266 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001267 slot = chip->slots[i];
1268 if (!slot)
1269 continue;
1270
1271 ret = sdhci_resume_host(slot->host);
1272 if (ret)
1273 return ret;
1274 }
1275
1276 return 0;
1277}
1278
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001279static int sdhci_pci_runtime_suspend(struct device *dev)
1280{
1281 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1282 struct sdhci_pci_chip *chip;
1283 struct sdhci_pci_slot *slot;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001284 int i, ret;
1285
1286 chip = pci_get_drvdata(pdev);
1287 if (!chip)
1288 return 0;
1289
1290 for (i = 0; i < chip->num_slots; i++) {
1291 slot = chip->slots[i];
1292 if (!slot)
1293 continue;
1294
1295 ret = sdhci_runtime_suspend_host(slot->host);
1296
Axel Linb678b912011-12-03 15:28:05 +08001297 if (ret)
1298 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001299 }
1300
1301 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001302 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001303 if (ret)
1304 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001305 }
1306
1307 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001308
1309err_pci_runtime_suspend:
1310 while (--i >= 0)
1311 sdhci_runtime_resume_host(chip->slots[i]->host);
1312 return ret;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001313}
1314
1315static int sdhci_pci_runtime_resume(struct device *dev)
1316{
1317 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1318 struct sdhci_pci_chip *chip;
1319 struct sdhci_pci_slot *slot;
1320 int i, ret;
1321
1322 chip = pci_get_drvdata(pdev);
1323 if (!chip)
1324 return 0;
1325
1326 if (chip->fixes && chip->fixes->resume) {
1327 ret = chip->fixes->resume(chip);
1328 if (ret)
1329 return ret;
1330 }
1331
1332 for (i = 0; i < chip->num_slots; i++) {
1333 slot = chip->slots[i];
1334 if (!slot)
1335 continue;
1336
1337 ret = sdhci_runtime_resume_host(slot->host);
1338 if (ret)
1339 return ret;
1340 }
1341
1342 return 0;
1343}
1344
1345static int sdhci_pci_runtime_idle(struct device *dev)
1346{
1347 return 0;
1348}
1349
Rafael J. Wysocki162d6f92014-12-05 03:05:33 +01001350#else /* CONFIG_PM */
1351
1352#define sdhci_pci_suspend NULL
1353#define sdhci_pci_resume NULL
1354
1355#endif /* CONFIG_PM */
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001356
1357static const struct dev_pm_ops sdhci_pci_pm_ops = {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001358 .suspend = sdhci_pci_suspend,
1359 .resume = sdhci_pci_resume,
Peter Griffinf3a92b12014-08-12 17:14:28 +01001360 SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend,
1361 sdhci_pci_runtime_resume, sdhci_pci_runtime_idle)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001362};
1363
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001364/*****************************************************************************\
1365 * *
1366 * Device probing/removal *
1367 * *
1368\*****************************************************************************/
1369
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001370static struct sdhci_pci_slot *sdhci_pci_probe_slot(
Adrian Hunter52c506f2011-12-27 15:48:43 +02001371 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1372 int slotno)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001373{
1374 struct sdhci_pci_slot *slot;
1375 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001376 int ret, bar = first_bar + slotno;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001377
1378 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1379 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1380 return ERR_PTR(-ENODEV);
1381 }
1382
Adrian Hunter90b3e6c2012-10-18 09:54:31 +03001383 if (pci_resource_len(pdev, bar) < 0x100) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001384 dev_err(&pdev->dev, "Invalid iomem size. You may "
1385 "experience problems.\n");
1386 }
1387
1388 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1389 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1390 return ERR_PTR(-ENODEV);
1391 }
1392
1393 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1394 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1395 return ERR_PTR(-ENODEV);
1396 }
1397
1398 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1399 if (IS_ERR(host)) {
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001400 dev_err(&pdev->dev, "cannot allocate host\n");
Julia Lawalldc0fd7b2010-05-26 14:42:11 -07001401 return ERR_CAST(host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001402 }
1403
1404 slot = sdhci_priv(host);
1405
1406 slot->chip = chip;
1407 slot->host = host;
1408 slot->pci_bar = bar;
Adrian Hunter0f201652011-08-29 16:42:13 +03001409 slot->rst_n_gpio = -EINVAL;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001410 slot->cd_gpio = -EINVAL;
Adrian Hunterff59c522014-09-24 10:27:31 +03001411 slot->cd_idx = -1;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001412
Adrian Hunter52c506f2011-12-27 15:48:43 +02001413 /* Retrieve platform data if there is any */
1414 if (*sdhci_pci_get_data)
1415 slot->data = sdhci_pci_get_data(pdev, slotno);
1416
1417 if (slot->data) {
1418 if (slot->data->setup) {
1419 ret = slot->data->setup(slot->data);
1420 if (ret) {
1421 dev_err(&pdev->dev, "platform setup failed\n");
1422 goto free;
1423 }
1424 }
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001425 slot->rst_n_gpio = slot->data->rst_n_gpio;
1426 slot->cd_gpio = slot->data->cd_gpio;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001427 }
1428
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001429 host->hw_name = "PCI";
1430 host->ops = &sdhci_pci_ops;
1431 host->quirks = chip->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001432 host->quirks2 = chip->quirks2;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001433
1434 host->irq = pdev->irq;
1435
1436 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1437 if (ret) {
1438 dev_err(&pdev->dev, "cannot request region\n");
Adrian Hunter52c506f2011-12-27 15:48:43 +02001439 goto cleanup;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001440 }
1441
Arjan van de Ven092f82e2008-09-28 16:15:56 -07001442 host->ioaddr = pci_ioremap_bar(pdev, bar);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001443 if (!host->ioaddr) {
1444 dev_err(&pdev->dev, "failed to remap registers\n");
Chris Ball9fdcdbb2011-03-29 00:46:12 -04001445 ret = -ENOMEM;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001446 goto release;
1447 }
1448
Pierre Ossman44894282008-04-04 19:36:59 +02001449 if (chip->fixes && chip->fixes->probe_slot) {
1450 ret = chip->fixes->probe_slot(slot);
1451 if (ret)
1452 goto unmap;
1453 }
1454
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001455 if (gpio_is_valid(slot->rst_n_gpio)) {
1456 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1457 gpio_direction_output(slot->rst_n_gpio, 1);
1458 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
Adrian Hunterc9faff62013-06-13 11:50:26 +03001459 slot->hw_reset = sdhci_pci_gpio_hw_reset;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001460 } else {
1461 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1462 slot->rst_n_gpio = -EINVAL;
1463 }
1464 }
1465
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001466 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
Aaron Lueed222a2013-03-05 11:24:52 +08001467 host->mmc->slotno = slotno;
Adrian Huntera08b17b2013-04-15 11:27:25 -04001468 host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001469
Adrian Hunterff59c522014-09-24 10:27:31 +03001470 if (slot->cd_idx >= 0 &&
1471 mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx,
1472 slot->cd_override_level, 0, NULL)) {
1473 dev_warn(&pdev->dev, "failed to setup card detect gpio\n");
1474 slot->cd_idx = -1;
1475 }
1476
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001477 ret = sdhci_add_host(host);
1478 if (ret)
Pierre Ossman44894282008-04-04 19:36:59 +02001479 goto remove;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001480
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001481 sdhci_pci_add_own_cd(slot);
1482
Adrian Hunter77a01222014-01-13 09:49:16 +02001483 /*
1484 * Check if the chip needs a separate GPIO for card detect to wake up
1485 * from runtime suspend. If it is not there, don't allow runtime PM.
1486 * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
1487 */
Adrian Hunter945be382014-01-21 09:52:39 +02001488 if (chip->fixes && chip->fixes->own_cd_for_runtime_pm &&
Adrian Hunterff59c522014-09-24 10:27:31 +03001489 !gpio_is_valid(slot->cd_gpio) && slot->cd_idx < 0)
Adrian Hunter77a01222014-01-13 09:49:16 +02001490 chip->allow_runtime_pm = false;
1491
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001492 return slot;
1493
Pierre Ossman44894282008-04-04 19:36:59 +02001494remove:
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001495 if (gpio_is_valid(slot->rst_n_gpio))
1496 gpio_free(slot->rst_n_gpio);
1497
Pierre Ossman44894282008-04-04 19:36:59 +02001498 if (chip->fixes && chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001499 chip->fixes->remove_slot(slot, 0);
Pierre Ossman44894282008-04-04 19:36:59 +02001500
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001501unmap:
1502 iounmap(host->ioaddr);
1503
1504release:
1505 pci_release_region(pdev, bar);
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001506
Adrian Hunter52c506f2011-12-27 15:48:43 +02001507cleanup:
1508 if (slot->data && slot->data->cleanup)
1509 slot->data->cleanup(slot->data);
1510
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001511free:
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001512 sdhci_free_host(host);
1513
1514 return ERR_PTR(ret);
1515}
1516
1517static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1518{
Pierre Ossman1e728592008-04-16 19:13:13 +02001519 int dead;
1520 u32 scratch;
1521
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001522 sdhci_pci_remove_own_cd(slot);
1523
Pierre Ossman1e728592008-04-16 19:13:13 +02001524 dead = 0;
1525 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1526 if (scratch == (u32)-1)
1527 dead = 1;
1528
1529 sdhci_remove_host(slot->host, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001530
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001531 if (gpio_is_valid(slot->rst_n_gpio))
1532 gpio_free(slot->rst_n_gpio);
1533
Pierre Ossman44894282008-04-04 19:36:59 +02001534 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001535 slot->chip->fixes->remove_slot(slot, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001536
Adrian Hunter52c506f2011-12-27 15:48:43 +02001537 if (slot->data && slot->data->cleanup)
1538 slot->data->cleanup(slot->data);
1539
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001540 pci_release_region(slot->chip->pdev, slot->pci_bar);
Pierre Ossman44894282008-04-04 19:36:59 +02001541
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001542 sdhci_free_host(slot->host);
1543}
1544
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001545static void sdhci_pci_runtime_pm_allow(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001546{
1547 pm_runtime_put_noidle(dev);
1548 pm_runtime_allow(dev);
1549 pm_runtime_set_autosuspend_delay(dev, 50);
1550 pm_runtime_use_autosuspend(dev);
1551 pm_suspend_ignore_children(dev, 1);
1552}
1553
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001554static void sdhci_pci_runtime_pm_forbid(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001555{
1556 pm_runtime_forbid(dev);
1557 pm_runtime_get_noresume(dev);
1558}
1559
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001560static int sdhci_pci_probe(struct pci_dev *pdev,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001561 const struct pci_device_id *ent)
1562{
1563 struct sdhci_pci_chip *chip;
1564 struct sdhci_pci_slot *slot;
1565
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001566 u8 slots, first_bar;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001567 int ret, i;
1568
1569 BUG_ON(pdev == NULL);
1570 BUG_ON(ent == NULL);
1571
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001572 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001573 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001574
1575 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1576 if (ret)
1577 return ret;
1578
1579 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1580 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1581 if (slots == 0)
1582 return -ENODEV;
1583
1584 BUG_ON(slots > MAX_SLOTS);
1585
1586 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1587 if (ret)
1588 return ret;
1589
1590 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1591
1592 if (first_bar > 5) {
1593 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1594 return -ENODEV;
1595 }
1596
1597 ret = pci_enable_device(pdev);
1598 if (ret)
1599 return ret;
1600
1601 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
1602 if (!chip) {
1603 ret = -ENOMEM;
1604 goto err;
1605 }
1606
1607 chip->pdev = pdev;
Ameya Palandeb177bc92011-04-05 21:13:13 +03001608 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001609 if (chip->fixes) {
Pierre Ossman22606402008-03-23 19:33:23 +01001610 chip->quirks = chip->fixes->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001611 chip->quirks2 = chip->fixes->quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001612 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1613 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001614 chip->num_slots = slots;
1615
1616 pci_set_drvdata(pdev, chip);
1617
Pierre Ossman22606402008-03-23 19:33:23 +01001618 if (chip->fixes && chip->fixes->probe) {
1619 ret = chip->fixes->probe(chip);
1620 if (ret)
1621 goto free;
1622 }
1623
Alan Cox225d85f2010-10-04 15:24:21 +01001624 slots = chip->num_slots; /* Quirk may have changed this */
1625
Ameya Palandeb177bc92011-04-05 21:13:13 +03001626 for (i = 0; i < slots; i++) {
Adrian Hunter52c506f2011-12-27 15:48:43 +02001627 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001628 if (IS_ERR(slot)) {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001629 for (i--; i >= 0; i--)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001630 sdhci_pci_remove_slot(chip->slots[i]);
1631 ret = PTR_ERR(slot);
1632 goto free;
1633 }
1634
1635 chip->slots[i] = slot;
1636 }
1637
Adrian Hunterc43fd772011-10-17 10:52:44 +03001638 if (chip->allow_runtime_pm)
1639 sdhci_pci_runtime_pm_allow(&pdev->dev);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001640
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001641 return 0;
1642
1643free:
1644 pci_set_drvdata(pdev, NULL);
1645 kfree(chip);
1646
1647err:
1648 pci_disable_device(pdev);
1649 return ret;
1650}
1651
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001652static void sdhci_pci_remove(struct pci_dev *pdev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001653{
1654 int i;
1655 struct sdhci_pci_chip *chip;
1656
1657 chip = pci_get_drvdata(pdev);
1658
1659 if (chip) {
Adrian Hunterc43fd772011-10-17 10:52:44 +03001660 if (chip->allow_runtime_pm)
1661 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1662
Ameya Palandeb177bc92011-04-05 21:13:13 +03001663 for (i = 0; i < chip->num_slots; i++)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001664 sdhci_pci_remove_slot(chip->slots[i]);
1665
1666 pci_set_drvdata(pdev, NULL);
1667 kfree(chip);
1668 }
1669
1670 pci_disable_device(pdev);
1671}
1672
1673static struct pci_driver sdhci_driver = {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001674 .name = "sdhci-pci",
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001675 .id_table = pci_ids,
Ameya Palandeb177bc92011-04-05 21:13:13 +03001676 .probe = sdhci_pci_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -05001677 .remove = sdhci_pci_remove,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001678 .driver = {
1679 .pm = &sdhci_pci_pm_ops
1680 },
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001681};
1682
Sachin Kamatacc69642012-08-27 11:57:02 +05301683module_pci_driver(sdhci_driver);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001684
Pierre Ossman32710e82009-04-08 20:14:54 +02001685MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001686MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1687MODULE_LICENSE("GPL");