blob: 3dee22d098e904c51566671346d4e9a5cae4fad5 [file] [log] [blame]
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001/* linux/drivers/mmc/host/sdhci-pci.c - SDHCI on PCI bus interface
2 *
3 * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * Thanks to the following companies for their support:
11 *
12 * - JMicron (hardware and technical support)
13 */
14
15#include <linux/delay.h>
16#include <linux/highmem.h>
Paul Gortmaker88b47672011-07-03 15:15:51 -040017#include <linux/module.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010018#include <linux/pci.h>
19#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Maxim Levitskyccc92c22010-08-10 18:01:42 -070021#include <linux/device.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010022#include <linux/mmc/host.h>
Ameya Palandeb177bc92011-04-05 21:13:13 +030023#include <linux/scatterlist.h>
24#include <linux/io.h>
Adrian Hunter0f201652011-08-29 16:42:13 +030025#include <linux/gpio.h>
Adrian Hunter66fd8ad2011-10-03 15:33:34 +030026#include <linux/pm_runtime.h>
Adrian Hunter52c506f2011-12-27 15:48:43 +020027#include <linux/mmc/sdhci-pci-data.h>
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010028
29#include "sdhci.h"
30
31/*
Alexander Stein296e0b02012-03-14 08:38:58 +010032 * PCI device IDs
33 */
34#define PCI_DEVICE_ID_INTEL_PCH_SDIO0 0x8809
35#define PCI_DEVICE_ID_INTEL_PCH_SDIO1 0x880a
36
37/*
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010038 * PCI registers
39 */
40
41#define PCI_SDHCI_IFPIO 0x00
42#define PCI_SDHCI_IFDMA 0x01
43#define PCI_SDHCI_IFVENDOR 0x02
44
45#define PCI_SLOT_INFO 0x40 /* 8 bits */
46#define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
47#define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
48
49#define MAX_SLOTS 8
50
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010051struct sdhci_pci_chip;
Pierre Ossman44894282008-04-04 19:36:59 +020052struct sdhci_pci_slot;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010053
Pierre Ossman22606402008-03-23 19:33:23 +010054struct sdhci_pci_fixes {
55 unsigned int quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +020056 unsigned int quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +030057 bool allow_runtime_pm;
Pierre Ossman22606402008-03-23 19:33:23 +010058
Ameya Palandeb177bc92011-04-05 21:13:13 +030059 int (*probe) (struct sdhci_pci_chip *);
Pierre Ossman45211e22008-03-24 13:09:09 +010060
Ameya Palandeb177bc92011-04-05 21:13:13 +030061 int (*probe_slot) (struct sdhci_pci_slot *);
62 void (*remove_slot) (struct sdhci_pci_slot *, int);
Pierre Ossman44894282008-04-04 19:36:59 +020063
Manuel Lauss29495aa2011-11-03 11:09:45 +010064 int (*suspend) (struct sdhci_pci_chip *);
Ameya Palandeb177bc92011-04-05 21:13:13 +030065 int (*resume) (struct sdhci_pci_chip *);
Pierre Ossman22606402008-03-23 19:33:23 +010066};
67
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010068struct sdhci_pci_slot {
69 struct sdhci_pci_chip *chip;
70 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +020071 struct sdhci_pci_data *data;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010072
73 int pci_bar;
Adrian Hunter0f201652011-08-29 16:42:13 +030074 int rst_n_gpio;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +030075 int cd_gpio;
76 int cd_irq;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010077};
78
79struct sdhci_pci_chip {
80 struct pci_dev *pdev;
Pierre Ossman22606402008-03-23 19:33:23 +010081
82 unsigned int quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +020083 unsigned int quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +030084 bool allow_runtime_pm;
Pierre Ossman22606402008-03-23 19:33:23 +010085 const struct sdhci_pci_fixes *fixes;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +010086
87 int num_slots; /* Slots on controller */
88 struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
89};
90
Pierre Ossman22606402008-03-23 19:33:23 +010091
92/*****************************************************************************\
93 * *
94 * Hardware specific quirk handling *
95 * *
96\*****************************************************************************/
97
98static int ricoh_probe(struct sdhci_pci_chip *chip)
99{
Chris Ballc99436f2009-09-22 16:45:22 -0700100 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
101 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
Pierre Ossman22606402008-03-23 19:33:23 +0100102 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700103 return 0;
104}
Pierre Ossman22606402008-03-23 19:33:23 +0100105
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700106static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
107{
108 slot->host->caps =
109 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
110 & SDHCI_TIMEOUT_CLK_MASK) |
111
112 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
113 & SDHCI_CLOCK_BASE_MASK) |
114
115 SDHCI_TIMEOUT_CLK_UNIT |
116 SDHCI_CAN_VDD_330 |
Madhvapathi Sriram1a1f1f02012-10-15 04:47:30 +0000117 SDHCI_CAN_DO_HISPD |
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700118 SDHCI_CAN_DO_SDMA;
119 return 0;
120}
121
122static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
123{
124 /* Apply a delay to allow controller to settle */
125 /* Otherwise it becomes confused if card state changed
126 during suspend */
127 msleep(500);
Pierre Ossman22606402008-03-23 19:33:23 +0100128 return 0;
129}
130
131static const struct sdhci_pci_fixes sdhci_ricoh = {
132 .probe = ricoh_probe,
Vasily Khoruzhick84938292010-03-05 13:43:46 -0800133 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
134 SDHCI_QUIRK_FORCE_DMA |
135 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
Pierre Ossman22606402008-03-23 19:33:23 +0100136};
137
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700138static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
139 .probe_slot = ricoh_mmc_probe_slot,
140 .resume = ricoh_mmc_resume,
141 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
142 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
143 SDHCI_QUIRK_NO_CARD_NO_RESET |
144 SDHCI_QUIRK_MISSING_CAPS
145};
146
Pierre Ossman22606402008-03-23 19:33:23 +0100147static const struct sdhci_pci_fixes sdhci_ene_712 = {
148 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
149 SDHCI_QUIRK_BROKEN_DMA,
150};
151
152static const struct sdhci_pci_fixes sdhci_ene_714 = {
153 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
154 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
155 SDHCI_QUIRK_BROKEN_DMA,
156};
157
158static const struct sdhci_pci_fixes sdhci_cafe = {
159 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
Andres Salomona0874892009-03-02 21:48:20 +0100160 SDHCI_QUIRK_NO_BUSY_IRQ |
Daniel Drake55fc05b2012-07-03 23:13:39 +0100161 SDHCI_QUIRK_BROKEN_CARD_DETECTION |
Pierre Ossmanee53ab52008-07-05 00:25:15 +0200162 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
Pierre Ossman22606402008-03-23 19:33:23 +0100163};
164
Major Lee68077b02011-06-29 14:23:46 +0300165static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
166{
167 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
168 return 0;
169}
170
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100171/*
172 * ADMA operation is disabled for Moorestown platform due to
173 * hardware bugs.
174 */
Jacob Pan35ac6f02010-11-09 13:57:29 +0000175static int mrst_hc_probe(struct sdhci_pci_chip *chip)
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100176{
177 /*
Jacob Pan35ac6f02010-11-09 13:57:29 +0000178 * slots number is fixed here for MRST as SDIO3/5 are never used and
179 * have hardware bugs.
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100180 */
181 chip->num_slots = 1;
182 return 0;
183}
184
Alexander Stein296e0b02012-03-14 08:38:58 +0100185static int pch_hc_probe_slot(struct sdhci_pci_slot *slot)
186{
187 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
188 return 0;
189}
190
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300191#ifdef CONFIG_PM_RUNTIME
192
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200193static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300194{
195 struct sdhci_pci_slot *slot = dev_id;
196 struct sdhci_host *host = slot->host;
197
198 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
199 return IRQ_HANDLED;
200}
201
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200202static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300203{
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200204 int err, irq, gpio = slot->cd_gpio;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300205
206 slot->cd_gpio = -EINVAL;
207 slot->cd_irq = -EINVAL;
208
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200209 if (!gpio_is_valid(gpio))
210 return;
211
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300212 err = gpio_request(gpio, "sd_cd");
213 if (err < 0)
214 goto out;
215
216 err = gpio_direction_input(gpio);
217 if (err < 0)
218 goto out_free;
219
220 irq = gpio_to_irq(gpio);
221 if (irq < 0)
222 goto out_free;
223
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200224 err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300225 IRQF_TRIGGER_FALLING, "sd_cd", slot);
226 if (err)
227 goto out_free;
228
229 slot->cd_gpio = gpio;
230 slot->cd_irq = irq;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300231
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200232 return;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300233
234out_free:
235 gpio_free(gpio);
236out:
237 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300238}
239
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200240static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300241{
242 if (slot->cd_irq >= 0)
243 free_irq(slot->cd_irq, slot);
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200244 if (gpio_is_valid(slot->cd_gpio))
245 gpio_free(slot->cd_gpio);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300246}
247
248#else
249
Adrian Hunterc5e027a2011-12-27 15:48:44 +0200250static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
251{
252}
253
254static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
255{
256}
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300257
258#endif
259
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300260static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
261{
Adrian Hunter66fd8ad2011-10-03 15:33:34 +0300262 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
Adrian Hunterda721cf2012-02-07 14:48:53 +0200263 slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
264 MMC_CAP2_HC_ERASE_SZ;
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300265 return 0;
266}
267
Adrian Hunter93933502011-12-27 15:48:47 +0200268static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
269{
Adrian Hunter012e4672012-01-30 14:27:18 +0200270 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
Adrian Hunter93933502011-12-27 15:48:47 +0200271 return 0;
272}
273
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100274static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
275 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Major Lee68077b02011-06-29 14:23:46 +0300276 .probe_slot = mrst_hc_probe_slot,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100277};
278
Jacob Pan35ac6f02010-11-09 13:57:29 +0000279static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100280 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000281 .probe = mrst_hc_probe,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100282};
283
Xiaochen Shen29229052010-10-04 15:24:52 +0100284static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
285 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300286 .allow_runtime_pm = true,
Xiaochen Shen29229052010-10-04 15:24:52 +0100287};
288
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300289static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
Xiaochen Shen29229052010-10-04 15:24:52 +0100290 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterf3c55a72012-02-07 14:48:55 +0200291 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300292 .allow_runtime_pm = true,
Adrian Hunter93933502011-12-27 15:48:47 +0200293 .probe_slot = mfd_sdio_probe_slot,
Xiaochen Shen29229052010-10-04 15:24:52 +0100294};
295
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300296static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
297 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
Adrian Hunterc43fd772011-10-17 10:52:44 +0300298 .allow_runtime_pm = true,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300299 .probe_slot = mfd_emmc_probe_slot,
300};
301
Alexander Stein296e0b02012-03-14 08:38:58 +0100302static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = {
303 .quirks = SDHCI_QUIRK_BROKEN_ADMA,
304 .probe_slot = pch_hc_probe_slot,
305};
306
Jennifer Li26daa1e2010-11-17 23:01:59 -0500307/* O2Micro extra registers */
308#define O2_SD_LOCK_WP 0xD3
309#define O2_SD_MULTI_VCC3V 0xEE
310#define O2_SD_CLKREQ 0xEC
311#define O2_SD_CAPS 0xE0
312#define O2_SD_ADMA1 0xE2
313#define O2_SD_ADMA2 0xE7
314#define O2_SD_INF_MOD 0xF1
315
316static int o2_probe(struct sdhci_pci_chip *chip)
317{
318 int ret;
319 u8 scratch;
320
321 switch (chip->pdev->device) {
322 case PCI_DEVICE_ID_O2_8220:
323 case PCI_DEVICE_ID_O2_8221:
324 case PCI_DEVICE_ID_O2_8320:
325 case PCI_DEVICE_ID_O2_8321:
326 /* This extra setup is required due to broken ADMA. */
327 ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
328 if (ret)
329 return ret;
330 scratch &= 0x7f;
331 pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
332
333 /* Set Multi 3 to VCC3V# */
334 pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08);
335
336 /* Disable CLK_REQ# support after media DET */
337 ret = pci_read_config_byte(chip->pdev, O2_SD_CLKREQ, &scratch);
338 if (ret)
339 return ret;
340 scratch |= 0x20;
341 pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch);
342
343 /* Choose capabilities, enable SDMA. We have to write 0x01
344 * to the capabilities register first to unlock it.
345 */
346 ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch);
347 if (ret)
348 return ret;
349 scratch |= 0x01;
350 pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch);
351 pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73);
352
353 /* Disable ADMA1/2 */
354 pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39);
355 pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08);
356
357 /* Disable the infinite transfer mode */
358 ret = pci_read_config_byte(chip->pdev, O2_SD_INF_MOD, &scratch);
359 if (ret)
360 return ret;
361 scratch |= 0x08;
362 pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch);
363
364 /* Lock WP */
365 ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
366 if (ret)
367 return ret;
368 scratch |= 0x80;
369 pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
370 }
371
372 return 0;
373}
374
Pierre Ossman45211e22008-03-24 13:09:09 +0100375static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
376{
377 u8 scratch;
378 int ret;
379
380 ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
381 if (ret)
382 return ret;
383
384 /*
385 * Turn PMOS on [bit 0], set over current detection to 2.4 V
386 * [bit 1:2] and enable over current debouncing [bit 6].
387 */
388 if (on)
389 scratch |= 0x47;
390 else
391 scratch &= ~0x47;
392
393 ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
394 if (ret)
395 return ret;
396
397 return 0;
398}
399
400static int jmicron_probe(struct sdhci_pci_chip *chip)
401{
402 int ret;
Takashi Iwai8f230f42010-12-08 10:04:30 +0100403 u16 mmcdev = 0;
Pierre Ossman45211e22008-03-24 13:09:09 +0100404
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200405 if (chip->pdev->revision == 0) {
406 chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
407 SDHCI_QUIRK_32BIT_DMA_SIZE |
Pierre Ossman2134a922008-06-28 18:28:51 +0200408 SDHCI_QUIRK_32BIT_ADMA_SIZE |
Pierre Ossman4a3cba32008-07-29 00:11:16 +0200409 SDHCI_QUIRK_RESET_AFTER_REQUEST |
Pierre Ossman86a6a872009-02-02 21:13:49 +0100410 SDHCI_QUIRK_BROKEN_SMALL_PIO;
Pierre Ossman93fc48c2008-06-28 18:21:41 +0200411 }
412
Pierre Ossman45211e22008-03-24 13:09:09 +0100413 /*
Pierre Ossman44894282008-04-04 19:36:59 +0200414 * JMicron chips can have two interfaces to the same hardware
415 * in order to work around limitations in Microsoft's driver.
416 * We need to make sure we only bind to one of them.
417 *
418 * This code assumes two things:
419 *
420 * 1. The PCI code adds subfunctions in order.
421 *
422 * 2. The MMC interface has a lower subfunction number
423 * than the SD interface.
424 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100425 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
426 mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
427 else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
428 mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
429
430 if (mmcdev) {
Pierre Ossman44894282008-04-04 19:36:59 +0200431 struct pci_dev *sd_dev;
432
433 sd_dev = NULL;
434 while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
Takashi Iwai8f230f42010-12-08 10:04:30 +0100435 mmcdev, sd_dev)) != NULL) {
Pierre Ossman44894282008-04-04 19:36:59 +0200436 if ((PCI_SLOT(chip->pdev->devfn) ==
437 PCI_SLOT(sd_dev->devfn)) &&
438 (chip->pdev->bus == sd_dev->bus))
439 break;
440 }
441
442 if (sd_dev) {
443 pci_dev_put(sd_dev);
444 dev_info(&chip->pdev->dev, "Refusing to bind to "
445 "secondary interface.\n");
446 return -ENODEV;
447 }
448 }
449
450 /*
Pierre Ossman45211e22008-03-24 13:09:09 +0100451 * JMicron chips need a bit of a nudge to enable the power
452 * output pins.
453 */
454 ret = jmicron_pmos(chip, 1);
455 if (ret) {
456 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
457 return ret;
458 }
459
Takashi Iwai82b0e232011-04-21 20:26:38 +0200460 /* quirk for unsable RO-detection on JM388 chips */
461 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
462 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
463 chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
464
Pierre Ossman45211e22008-03-24 13:09:09 +0100465 return 0;
466}
467
Pierre Ossman44894282008-04-04 19:36:59 +0200468static void jmicron_enable_mmc(struct sdhci_host *host, int on)
469{
470 u8 scratch;
471
472 scratch = readb(host->ioaddr + 0xC0);
473
474 if (on)
475 scratch |= 0x01;
476 else
477 scratch &= ~0x01;
478
479 writeb(scratch, host->ioaddr + 0xC0);
480}
481
482static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
483{
Pierre Ossman2134a922008-06-28 18:28:51 +0200484 if (slot->chip->pdev->revision == 0) {
485 u16 version;
486
487 version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
488 version = (version & SDHCI_VENDOR_VER_MASK) >>
489 SDHCI_VENDOR_VER_SHIFT;
490
491 /*
492 * Older versions of the chip have lots of nasty glitches
493 * in the ADMA engine. It's best just to avoid it
494 * completely.
495 */
496 if (version < 0xAC)
497 slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
498 }
499
Takashi Iwai8f230f42010-12-08 10:04:30 +0100500 /* JM388 MMC doesn't support 1.8V while SD supports it */
501 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
502 slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
503 MMC_VDD_29_30 | MMC_VDD_30_31 |
504 MMC_VDD_165_195; /* allow 1.8V */
505 slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
506 MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
507 }
508
Pierre Ossman44894282008-04-04 19:36:59 +0200509 /*
510 * The secondary interface requires a bit set to get the
511 * interrupts.
512 */
Takashi Iwai8f230f42010-12-08 10:04:30 +0100513 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
514 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200515 jmicron_enable_mmc(slot->host, 1);
516
Takashi Iwaid75c1082010-12-16 17:54:14 +0100517 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
518
Pierre Ossman44894282008-04-04 19:36:59 +0200519 return 0;
520}
521
Pierre Ossman1e728592008-04-16 19:13:13 +0200522static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
Pierre Ossman44894282008-04-04 19:36:59 +0200523{
Pierre Ossman1e728592008-04-16 19:13:13 +0200524 if (dead)
525 return;
526
Takashi Iwai8f230f42010-12-08 10:04:30 +0100527 if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
528 slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
Pierre Ossman44894282008-04-04 19:36:59 +0200529 jmicron_enable_mmc(slot->host, 0);
530}
531
Manuel Lauss29495aa2011-11-03 11:09:45 +0100532static int jmicron_suspend(struct sdhci_pci_chip *chip)
Pierre Ossman44894282008-04-04 19:36:59 +0200533{
534 int i;
535
Takashi Iwai8f230f42010-12-08 10:04:30 +0100536 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
537 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300538 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200539 jmicron_enable_mmc(chip->slots[i]->host, 0);
540 }
541
542 return 0;
543}
544
Pierre Ossman45211e22008-03-24 13:09:09 +0100545static int jmicron_resume(struct sdhci_pci_chip *chip)
546{
Pierre Ossman44894282008-04-04 19:36:59 +0200547 int ret, i;
548
Takashi Iwai8f230f42010-12-08 10:04:30 +0100549 if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
550 chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
Ameya Palandeb177bc92011-04-05 21:13:13 +0300551 for (i = 0; i < chip->num_slots; i++)
Pierre Ossman44894282008-04-04 19:36:59 +0200552 jmicron_enable_mmc(chip->slots[i]->host, 1);
553 }
Pierre Ossman45211e22008-03-24 13:09:09 +0100554
555 ret = jmicron_pmos(chip, 1);
556 if (ret) {
557 dev_err(&chip->pdev->dev, "Failure enabling card power\n");
558 return ret;
559 }
560
561 return 0;
562}
563
Jennifer Li26daa1e2010-11-17 23:01:59 -0500564static const struct sdhci_pci_fixes sdhci_o2 = {
565 .probe = o2_probe,
566};
567
Pierre Ossman22606402008-03-23 19:33:23 +0100568static const struct sdhci_pci_fixes sdhci_jmicron = {
Pierre Ossman45211e22008-03-24 13:09:09 +0100569 .probe = jmicron_probe,
570
Pierre Ossman44894282008-04-04 19:36:59 +0200571 .probe_slot = jmicron_probe_slot,
572 .remove_slot = jmicron_remove_slot,
573
574 .suspend = jmicron_suspend,
Pierre Ossman45211e22008-03-24 13:09:09 +0100575 .resume = jmicron_resume,
Pierre Ossman22606402008-03-23 19:33:23 +0100576};
577
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800578/* SysKonnect CardBus2SDIO extra registers */
579#define SYSKT_CTRL 0x200
580#define SYSKT_RDFIFO_STAT 0x204
581#define SYSKT_WRFIFO_STAT 0x208
582#define SYSKT_POWER_DATA 0x20c
583#define SYSKT_POWER_330 0xef
584#define SYSKT_POWER_300 0xf8
585#define SYSKT_POWER_184 0xcc
586#define SYSKT_POWER_CMD 0x20d
587#define SYSKT_POWER_START (1 << 7)
588#define SYSKT_POWER_STATUS 0x20e
589#define SYSKT_POWER_STATUS_OK (1 << 0)
590#define SYSKT_BOARD_REV 0x210
591#define SYSKT_CHIP_REV 0x211
592#define SYSKT_CONF_DATA 0x212
593#define SYSKT_CONF_DATA_1V8 (1 << 2)
594#define SYSKT_CONF_DATA_2V5 (1 << 1)
595#define SYSKT_CONF_DATA_3V3 (1 << 0)
596
597static int syskt_probe(struct sdhci_pci_chip *chip)
598{
599 if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
600 chip->pdev->class &= ~0x0000FF;
601 chip->pdev->class |= PCI_SDHCI_IFDMA;
602 }
603 return 0;
604}
605
606static int syskt_probe_slot(struct sdhci_pci_slot *slot)
607{
608 int tm, ps;
609
610 u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
611 u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
612 dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
613 "board rev %d.%d, chip rev %d.%d\n",
614 board_rev >> 4, board_rev & 0xf,
615 chip_rev >> 4, chip_rev & 0xf);
616 if (chip_rev >= 0x20)
617 slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
618
619 writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
620 writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
621 udelay(50);
622 tm = 10; /* Wait max 1 ms */
623 do {
624 ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
625 if (ps & SYSKT_POWER_STATUS_OK)
626 break;
627 udelay(100);
628 } while (--tm);
629 if (!tm) {
630 dev_err(&slot->chip->pdev->dev,
631 "power regulator never stabilized");
632 writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
633 return -ENODEV;
634 }
635
636 return 0;
637}
638
639static const struct sdhci_pci_fixes sdhci_syskt = {
640 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
641 .probe = syskt_probe,
642 .probe_slot = syskt_probe_slot,
643};
644
Harald Welte557b0692009-06-18 16:53:38 +0200645static int via_probe(struct sdhci_pci_chip *chip)
646{
647 if (chip->pdev->revision == 0x10)
648 chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
649
650 return 0;
651}
652
653static const struct sdhci_pci_fixes sdhci_via = {
654 .probe = via_probe,
655};
656
Bill Pemberton9647f842012-11-19 13:25:11 -0500657static const struct pci_device_id pci_ids[] = {
Pierre Ossman22606402008-03-23 19:33:23 +0100658 {
659 .vendor = PCI_VENDOR_ID_RICOH,
660 .device = PCI_DEVICE_ID_RICOH_R5C822,
661 .subvendor = PCI_ANY_ID,
662 .subdevice = PCI_ANY_ID,
663 .driver_data = (kernel_ulong_t)&sdhci_ricoh,
664 },
665
666 {
Maxim Levitskyccc92c22010-08-10 18:01:42 -0700667 .vendor = PCI_VENDOR_ID_RICOH,
668 .device = 0x843,
669 .subvendor = PCI_ANY_ID,
670 .subdevice = PCI_ANY_ID,
671 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
672 },
673
674 {
Pablo Castillo568133e2010-08-10 18:02:01 -0700675 .vendor = PCI_VENDOR_ID_RICOH,
676 .device = 0xe822,
677 .subvendor = PCI_ANY_ID,
678 .subdevice = PCI_ANY_ID,
679 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
680 },
681
682 {
Manoj Iyer5fd11c02011-02-11 16:25:31 -0600683 .vendor = PCI_VENDOR_ID_RICOH,
684 .device = 0xe823,
685 .subvendor = PCI_ANY_ID,
686 .subdevice = PCI_ANY_ID,
687 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
688 },
689
690 {
Pierre Ossman22606402008-03-23 19:33:23 +0100691 .vendor = PCI_VENDOR_ID_ENE,
692 .device = PCI_DEVICE_ID_ENE_CB712_SD,
693 .subvendor = PCI_ANY_ID,
694 .subdevice = PCI_ANY_ID,
695 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
696 },
697
698 {
699 .vendor = PCI_VENDOR_ID_ENE,
700 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
701 .subvendor = PCI_ANY_ID,
702 .subdevice = PCI_ANY_ID,
703 .driver_data = (kernel_ulong_t)&sdhci_ene_712,
704 },
705
706 {
707 .vendor = PCI_VENDOR_ID_ENE,
708 .device = PCI_DEVICE_ID_ENE_CB714_SD,
709 .subvendor = PCI_ANY_ID,
710 .subdevice = PCI_ANY_ID,
711 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
712 },
713
714 {
715 .vendor = PCI_VENDOR_ID_ENE,
716 .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
717 .subvendor = PCI_ANY_ID,
718 .subdevice = PCI_ANY_ID,
719 .driver_data = (kernel_ulong_t)&sdhci_ene_714,
720 },
721
722 {
723 .vendor = PCI_VENDOR_ID_MARVELL,
David Woodhouse8c5eb882008-09-03 09:45:57 +0100724 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
Pierre Ossman22606402008-03-23 19:33:23 +0100725 .subvendor = PCI_ANY_ID,
726 .subdevice = PCI_ANY_ID,
727 .driver_data = (kernel_ulong_t)&sdhci_cafe,
728 },
729
730 {
731 .vendor = PCI_VENDOR_ID_JMICRON,
732 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
733 .subvendor = PCI_ANY_ID,
734 .subdevice = PCI_ANY_ID,
735 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
736 },
737
Pierre Ossman44894282008-04-04 19:36:59 +0200738 {
739 .vendor = PCI_VENDOR_ID_JMICRON,
740 .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
741 .subvendor = PCI_ANY_ID,
742 .subdevice = PCI_ANY_ID,
743 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
744 },
745
Harald Welte557b0692009-06-18 16:53:38 +0200746 {
Takashi Iwai8f230f42010-12-08 10:04:30 +0100747 .vendor = PCI_VENDOR_ID_JMICRON,
748 .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
749 .subvendor = PCI_ANY_ID,
750 .subdevice = PCI_ANY_ID,
751 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
752 },
753
754 {
755 .vendor = PCI_VENDOR_ID_JMICRON,
756 .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
757 .subvendor = PCI_ANY_ID,
758 .subdevice = PCI_ANY_ID,
759 .driver_data = (kernel_ulong_t)&sdhci_jmicron,
760 },
761
762 {
Nicolas Pitrea7a61862009-12-14 18:01:26 -0800763 .vendor = PCI_VENDOR_ID_SYSKONNECT,
764 .device = 0x8000,
765 .subvendor = PCI_ANY_ID,
766 .subdevice = PCI_ANY_ID,
767 .driver_data = (kernel_ulong_t)&sdhci_syskt,
768 },
769
770 {
Harald Welte557b0692009-06-18 16:53:38 +0200771 .vendor = PCI_VENDOR_ID_VIA,
772 .device = 0x95d0,
773 .subvendor = PCI_ANY_ID,
774 .subdevice = PCI_ANY_ID,
775 .driver_data = (kernel_ulong_t)&sdhci_via,
776 },
777
Xiaochen Shen29229052010-10-04 15:24:52 +0100778 {
779 .vendor = PCI_VENDOR_ID_INTEL,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100780 .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
781 .subvendor = PCI_ANY_ID,
782 .subdevice = PCI_ANY_ID,
783 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
784 },
785
786 {
787 .vendor = PCI_VENDOR_ID_INTEL,
788 .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
789 .subvendor = PCI_ANY_ID,
790 .subdevice = PCI_ANY_ID,
Jacob Pan35ac6f02010-11-09 13:57:29 +0000791 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
792 },
793
794 {
795 .vendor = PCI_VENDOR_ID_INTEL,
796 .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
797 .subvendor = PCI_ANY_ID,
798 .subdevice = PCI_ANY_ID,
799 .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
Alan Coxf9ee3ea2010-10-04 15:25:11 +0100800 },
801
802 {
803 .vendor = PCI_VENDOR_ID_INTEL,
Xiaochen Shen29229052010-10-04 15:24:52 +0100804 .device = PCI_DEVICE_ID_INTEL_MFD_SD,
805 .subvendor = PCI_ANY_ID,
806 .subdevice = PCI_ANY_ID,
807 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
808 },
809
810 {
811 .vendor = PCI_VENDOR_ID_INTEL,
812 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
813 .subvendor = PCI_ANY_ID,
814 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300815 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100816 },
817
818 {
819 .vendor = PCI_VENDOR_ID_INTEL,
820 .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
821 .subvendor = PCI_ANY_ID,
822 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300823 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
Xiaochen Shen29229052010-10-04 15:24:52 +0100824 },
825
826 {
827 .vendor = PCI_VENDOR_ID_INTEL,
828 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
829 .subvendor = PCI_ANY_ID,
830 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300831 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100832 },
833
834 {
835 .vendor = PCI_VENDOR_ID_INTEL,
836 .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
837 .subvendor = PCI_ANY_ID,
838 .subdevice = PCI_ANY_ID,
Adrian Hunter0d013bc2011-06-29 14:23:47 +0300839 .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
Xiaochen Shen29229052010-10-04 15:24:52 +0100840 },
841
Jennifer Li26daa1e2010-11-17 23:01:59 -0500842 {
Alexander Stein296e0b02012-03-14 08:38:58 +0100843 .vendor = PCI_VENDOR_ID_INTEL,
844 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
845 .subvendor = PCI_ANY_ID,
846 .subdevice = PCI_ANY_ID,
847 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
848 },
849
850 {
851 .vendor = PCI_VENDOR_ID_INTEL,
852 .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
853 .subvendor = PCI_ANY_ID,
854 .subdevice = PCI_ANY_ID,
855 .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
856 },
857
858 {
Jennifer Li26daa1e2010-11-17 23:01:59 -0500859 .vendor = PCI_VENDOR_ID_O2,
860 .device = PCI_DEVICE_ID_O2_8120,
861 .subvendor = PCI_ANY_ID,
862 .subdevice = PCI_ANY_ID,
863 .driver_data = (kernel_ulong_t)&sdhci_o2,
864 },
865
866 {
867 .vendor = PCI_VENDOR_ID_O2,
868 .device = PCI_DEVICE_ID_O2_8220,
869 .subvendor = PCI_ANY_ID,
870 .subdevice = PCI_ANY_ID,
871 .driver_data = (kernel_ulong_t)&sdhci_o2,
872 },
873
874 {
875 .vendor = PCI_VENDOR_ID_O2,
876 .device = PCI_DEVICE_ID_O2_8221,
877 .subvendor = PCI_ANY_ID,
878 .subdevice = PCI_ANY_ID,
879 .driver_data = (kernel_ulong_t)&sdhci_o2,
880 },
881
882 {
883 .vendor = PCI_VENDOR_ID_O2,
884 .device = PCI_DEVICE_ID_O2_8320,
885 .subvendor = PCI_ANY_ID,
886 .subdevice = PCI_ANY_ID,
887 .driver_data = (kernel_ulong_t)&sdhci_o2,
888 },
889
890 {
891 .vendor = PCI_VENDOR_ID_O2,
892 .device = PCI_DEVICE_ID_O2_8321,
893 .subvendor = PCI_ANY_ID,
894 .subdevice = PCI_ANY_ID,
895 .driver_data = (kernel_ulong_t)&sdhci_o2,
896 },
897
Pierre Ossman22606402008-03-23 19:33:23 +0100898 { /* Generic SD host controller */
899 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
900 },
901
902 { /* end: all zeroes */ },
903};
904
905MODULE_DEVICE_TABLE(pci, pci_ids);
906
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100907/*****************************************************************************\
908 * *
909 * SDHCI core callbacks *
910 * *
911\*****************************************************************************/
912
913static int sdhci_pci_enable_dma(struct sdhci_host *host)
914{
915 struct sdhci_pci_slot *slot;
916 struct pci_dev *pdev;
917 int ret;
918
919 slot = sdhci_priv(host);
920 pdev = slot->chip->pdev;
921
922 if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
923 ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
Richard Röjforsa13abc72009-09-22 16:45:30 -0700924 (host->flags & SDHCI_USE_SDMA)) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100925 dev_warn(&pdev->dev, "Will use DMA mode even though HW "
926 "doesn't fully claim to support it.\n");
927 }
928
Yang Hongyang284901a2009-04-06 19:01:15 -0700929 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100930 if (ret)
931 return ret;
932
933 pci_set_master(pdev);
934
935 return 0;
936}
937
Sascha Hauer7bc088d2013-01-21 19:02:27 +0800938static int sdhci_pci_bus_width(struct sdhci_host *host, int width)
Major Lee68077b02011-06-29 14:23:46 +0300939{
940 u8 ctrl;
941
942 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
943
944 switch (width) {
945 case MMC_BUS_WIDTH_8:
946 ctrl |= SDHCI_CTRL_8BITBUS;
947 ctrl &= ~SDHCI_CTRL_4BITBUS;
948 break;
949 case MMC_BUS_WIDTH_4:
950 ctrl |= SDHCI_CTRL_4BITBUS;
951 ctrl &= ~SDHCI_CTRL_8BITBUS;
952 break;
953 default:
954 ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
955 break;
956 }
957
958 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
959
960 return 0;
961}
962
Adrian Hunter0f201652011-08-29 16:42:13 +0300963static void sdhci_pci_hw_reset(struct sdhci_host *host)
964{
965 struct sdhci_pci_slot *slot = sdhci_priv(host);
966 int rst_n_gpio = slot->rst_n_gpio;
967
968 if (!gpio_is_valid(rst_n_gpio))
969 return;
970 gpio_set_value_cansleep(rst_n_gpio, 0);
971 /* For eMMC, minimum is 1us but give it 10us for good measure */
972 udelay(10);
973 gpio_set_value_cansleep(rst_n_gpio, 1);
974 /* For eMMC, minimum is 200us but give it 300us for good measure */
975 usleep_range(300, 1000);
976}
977
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100978static struct sdhci_ops sdhci_pci_ops = {
979 .enable_dma = sdhci_pci_enable_dma,
Sascha Hauer7bc088d2013-01-21 19:02:27 +0800980 .platform_bus_width = sdhci_pci_bus_width,
Adrian Hunter0f201652011-08-29 16:42:13 +0300981 .hw_reset = sdhci_pci_hw_reset,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100982};
983
984/*****************************************************************************\
985 * *
986 * Suspend/resume *
987 * *
988\*****************************************************************************/
989
990#ifdef CONFIG_PM
991
Manuel Lauss29495aa2011-11-03 11:09:45 +0100992static int sdhci_pci_suspend(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100993{
Manuel Lauss29495aa2011-11-03 11:09:45 +0100994 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100995 struct sdhci_pci_chip *chip;
996 struct sdhci_pci_slot *slot;
Daniel Drake5f619702010-11-04 22:20:39 +0000997 mmc_pm_flag_t slot_pm_flags;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -0800998 mmc_pm_flag_t pm_flags = 0;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +0100999 int i, ret;
1000
1001 chip = pci_get_drvdata(pdev);
1002 if (!chip)
1003 return 0;
1004
Ameya Palandeb177bc92011-04-05 21:13:13 +03001005 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001006 slot = chip->slots[i];
1007 if (!slot)
1008 continue;
1009
Manuel Lauss29495aa2011-11-03 11:09:45 +01001010 ret = sdhci_suspend_host(slot->host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001011
Axel Linb678b912011-12-03 15:28:05 +08001012 if (ret)
1013 goto err_pci_suspend;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001014
Daniel Drake5f619702010-11-04 22:20:39 +00001015 slot_pm_flags = slot->host->mmc->pm_flags;
1016 if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1017 sdhci_enable_irq_wakeups(slot->host);
1018
1019 pm_flags |= slot_pm_flags;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001020 }
1021
Pierre Ossman44894282008-04-04 19:36:59 +02001022 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001023 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001024 if (ret)
1025 goto err_pci_suspend;
Pierre Ossman44894282008-04-04 19:36:59 +02001026 }
1027
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001028 pci_save_state(pdev);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001029 if (pm_flags & MMC_PM_KEEP_POWER) {
Daniel Drake5f619702010-11-04 22:20:39 +00001030 if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) {
1031 pci_pme_active(pdev, true);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001032 pci_enable_wake(pdev, PCI_D3hot, 1);
Daniel Drake5f619702010-11-04 22:20:39 +00001033 }
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001034 pci_set_power_state(pdev, PCI_D3hot);
1035 } else {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001036 pci_enable_wake(pdev, PCI_D3hot, 0);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001037 pci_disable_device(pdev);
Manuel Lauss29495aa2011-11-03 11:09:45 +01001038 pci_set_power_state(pdev, PCI_D3hot);
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001039 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001040
1041 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001042
1043err_pci_suspend:
1044 while (--i >= 0)
1045 sdhci_resume_host(chip->slots[i]->host);
1046 return ret;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001047}
1048
Manuel Lauss29495aa2011-11-03 11:09:45 +01001049static int sdhci_pci_resume(struct device *dev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001050{
Manuel Lauss29495aa2011-11-03 11:09:45 +01001051 struct pci_dev *pdev = to_pci_dev(dev);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001052 struct sdhci_pci_chip *chip;
1053 struct sdhci_pci_slot *slot;
1054 int i, ret;
1055
1056 chip = pci_get_drvdata(pdev);
1057 if (!chip)
1058 return 0;
1059
1060 pci_set_power_state(pdev, PCI_D0);
1061 pci_restore_state(pdev);
1062 ret = pci_enable_device(pdev);
1063 if (ret)
1064 return ret;
1065
Pierre Ossman45211e22008-03-24 13:09:09 +01001066 if (chip->fixes && chip->fixes->resume) {
1067 ret = chip->fixes->resume(chip);
1068 if (ret)
1069 return ret;
1070 }
1071
Ameya Palandeb177bc92011-04-05 21:13:13 +03001072 for (i = 0; i < chip->num_slots; i++) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001073 slot = chip->slots[i];
1074 if (!slot)
1075 continue;
1076
1077 ret = sdhci_resume_host(slot->host);
1078 if (ret)
1079 return ret;
1080 }
1081
1082 return 0;
1083}
1084
1085#else /* CONFIG_PM */
1086
1087#define sdhci_pci_suspend NULL
1088#define sdhci_pci_resume NULL
1089
1090#endif /* CONFIG_PM */
1091
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001092#ifdef CONFIG_PM_RUNTIME
1093
1094static int sdhci_pci_runtime_suspend(struct device *dev)
1095{
1096 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1097 struct sdhci_pci_chip *chip;
1098 struct sdhci_pci_slot *slot;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001099 int i, ret;
1100
1101 chip = pci_get_drvdata(pdev);
1102 if (!chip)
1103 return 0;
1104
1105 for (i = 0; i < chip->num_slots; i++) {
1106 slot = chip->slots[i];
1107 if (!slot)
1108 continue;
1109
1110 ret = sdhci_runtime_suspend_host(slot->host);
1111
Axel Linb678b912011-12-03 15:28:05 +08001112 if (ret)
1113 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001114 }
1115
1116 if (chip->fixes && chip->fixes->suspend) {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001117 ret = chip->fixes->suspend(chip);
Axel Linb678b912011-12-03 15:28:05 +08001118 if (ret)
1119 goto err_pci_runtime_suspend;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001120 }
1121
1122 return 0;
Axel Linb678b912011-12-03 15:28:05 +08001123
1124err_pci_runtime_suspend:
1125 while (--i >= 0)
1126 sdhci_runtime_resume_host(chip->slots[i]->host);
1127 return ret;
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001128}
1129
1130static int sdhci_pci_runtime_resume(struct device *dev)
1131{
1132 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1133 struct sdhci_pci_chip *chip;
1134 struct sdhci_pci_slot *slot;
1135 int i, ret;
1136
1137 chip = pci_get_drvdata(pdev);
1138 if (!chip)
1139 return 0;
1140
1141 if (chip->fixes && chip->fixes->resume) {
1142 ret = chip->fixes->resume(chip);
1143 if (ret)
1144 return ret;
1145 }
1146
1147 for (i = 0; i < chip->num_slots; i++) {
1148 slot = chip->slots[i];
1149 if (!slot)
1150 continue;
1151
1152 ret = sdhci_runtime_resume_host(slot->host);
1153 if (ret)
1154 return ret;
1155 }
1156
1157 return 0;
1158}
1159
1160static int sdhci_pci_runtime_idle(struct device *dev)
1161{
1162 return 0;
1163}
1164
1165#else
1166
1167#define sdhci_pci_runtime_suspend NULL
1168#define sdhci_pci_runtime_resume NULL
1169#define sdhci_pci_runtime_idle NULL
1170
1171#endif
1172
1173static const struct dev_pm_ops sdhci_pci_pm_ops = {
Manuel Lauss29495aa2011-11-03 11:09:45 +01001174 .suspend = sdhci_pci_suspend,
1175 .resume = sdhci_pci_resume,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001176 .runtime_suspend = sdhci_pci_runtime_suspend,
1177 .runtime_resume = sdhci_pci_runtime_resume,
1178 .runtime_idle = sdhci_pci_runtime_idle,
1179};
1180
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001181/*****************************************************************************\
1182 * *
1183 * Device probing/removal *
1184 * *
1185\*****************************************************************************/
1186
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001187static struct sdhci_pci_slot *sdhci_pci_probe_slot(
Adrian Hunter52c506f2011-12-27 15:48:43 +02001188 struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1189 int slotno)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001190{
1191 struct sdhci_pci_slot *slot;
1192 struct sdhci_host *host;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001193 int ret, bar = first_bar + slotno;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001194
1195 if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1196 dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1197 return ERR_PTR(-ENODEV);
1198 }
1199
Adrian Hunter90b3e6c2012-10-18 09:54:31 +03001200 if (pci_resource_len(pdev, bar) < 0x100) {
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001201 dev_err(&pdev->dev, "Invalid iomem size. You may "
1202 "experience problems.\n");
1203 }
1204
1205 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1206 dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1207 return ERR_PTR(-ENODEV);
1208 }
1209
1210 if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1211 dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1212 return ERR_PTR(-ENODEV);
1213 }
1214
1215 host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1216 if (IS_ERR(host)) {
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001217 dev_err(&pdev->dev, "cannot allocate host\n");
Julia Lawalldc0fd7b2010-05-26 14:42:11 -07001218 return ERR_CAST(host);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001219 }
1220
1221 slot = sdhci_priv(host);
1222
1223 slot->chip = chip;
1224 slot->host = host;
1225 slot->pci_bar = bar;
Adrian Hunter0f201652011-08-29 16:42:13 +03001226 slot->rst_n_gpio = -EINVAL;
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001227 slot->cd_gpio = -EINVAL;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001228
Adrian Hunter52c506f2011-12-27 15:48:43 +02001229 /* Retrieve platform data if there is any */
1230 if (*sdhci_pci_get_data)
1231 slot->data = sdhci_pci_get_data(pdev, slotno);
1232
1233 if (slot->data) {
1234 if (slot->data->setup) {
1235 ret = slot->data->setup(slot->data);
1236 if (ret) {
1237 dev_err(&pdev->dev, "platform setup failed\n");
1238 goto free;
1239 }
1240 }
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001241 slot->rst_n_gpio = slot->data->rst_n_gpio;
1242 slot->cd_gpio = slot->data->cd_gpio;
Adrian Hunter52c506f2011-12-27 15:48:43 +02001243 }
1244
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001245 host->hw_name = "PCI";
1246 host->ops = &sdhci_pci_ops;
1247 host->quirks = chip->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001248 host->quirks2 = chip->quirks2;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001249
1250 host->irq = pdev->irq;
1251
1252 ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1253 if (ret) {
1254 dev_err(&pdev->dev, "cannot request region\n");
Adrian Hunter52c506f2011-12-27 15:48:43 +02001255 goto cleanup;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001256 }
1257
Arjan van de Ven092f82e2008-09-28 16:15:56 -07001258 host->ioaddr = pci_ioremap_bar(pdev, bar);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001259 if (!host->ioaddr) {
1260 dev_err(&pdev->dev, "failed to remap registers\n");
Chris Ball9fdcdbb2011-03-29 00:46:12 -04001261 ret = -ENOMEM;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001262 goto release;
1263 }
1264
Pierre Ossman44894282008-04-04 19:36:59 +02001265 if (chip->fixes && chip->fixes->probe_slot) {
1266 ret = chip->fixes->probe_slot(slot);
1267 if (ret)
1268 goto unmap;
1269 }
1270
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001271 if (gpio_is_valid(slot->rst_n_gpio)) {
1272 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1273 gpio_direction_output(slot->rst_n_gpio, 1);
1274 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
1275 } else {
1276 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1277 slot->rst_n_gpio = -EINVAL;
1278 }
1279 }
1280
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001281 host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
Aaron Lueed222a2013-03-05 11:24:52 +08001282 host->mmc->slotno = slotno;
Nicolas Pitre2f4cbb32010-03-05 13:43:32 -08001283
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001284 ret = sdhci_add_host(host);
1285 if (ret)
Pierre Ossman44894282008-04-04 19:36:59 +02001286 goto remove;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001287
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001288 sdhci_pci_add_own_cd(slot);
1289
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001290 return slot;
1291
Pierre Ossman44894282008-04-04 19:36:59 +02001292remove:
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001293 if (gpio_is_valid(slot->rst_n_gpio))
1294 gpio_free(slot->rst_n_gpio);
1295
Pierre Ossman44894282008-04-04 19:36:59 +02001296 if (chip->fixes && chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001297 chip->fixes->remove_slot(slot, 0);
Pierre Ossman44894282008-04-04 19:36:59 +02001298
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001299unmap:
1300 iounmap(host->ioaddr);
1301
1302release:
1303 pci_release_region(pdev, bar);
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001304
Adrian Hunter52c506f2011-12-27 15:48:43 +02001305cleanup:
1306 if (slot->data && slot->data->cleanup)
1307 slot->data->cleanup(slot->data);
1308
Dan Carpenterc60a32c2009-04-10 23:31:10 +02001309free:
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001310 sdhci_free_host(host);
1311
1312 return ERR_PTR(ret);
1313}
1314
1315static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1316{
Pierre Ossman1e728592008-04-16 19:13:13 +02001317 int dead;
1318 u32 scratch;
1319
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001320 sdhci_pci_remove_own_cd(slot);
1321
Pierre Ossman1e728592008-04-16 19:13:13 +02001322 dead = 0;
1323 scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1324 if (scratch == (u32)-1)
1325 dead = 1;
1326
1327 sdhci_remove_host(slot->host, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001328
Adrian Hunterc5e027a2011-12-27 15:48:44 +02001329 if (gpio_is_valid(slot->rst_n_gpio))
1330 gpio_free(slot->rst_n_gpio);
1331
Pierre Ossman44894282008-04-04 19:36:59 +02001332 if (slot->chip->fixes && slot->chip->fixes->remove_slot)
Pierre Ossman1e728592008-04-16 19:13:13 +02001333 slot->chip->fixes->remove_slot(slot, dead);
Pierre Ossman44894282008-04-04 19:36:59 +02001334
Adrian Hunter52c506f2011-12-27 15:48:43 +02001335 if (slot->data && slot->data->cleanup)
1336 slot->data->cleanup(slot->data);
1337
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001338 pci_release_region(slot->chip->pdev, slot->pci_bar);
Pierre Ossman44894282008-04-04 19:36:59 +02001339
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001340 sdhci_free_host(slot->host);
1341}
1342
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001343static void sdhci_pci_runtime_pm_allow(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001344{
1345 pm_runtime_put_noidle(dev);
1346 pm_runtime_allow(dev);
1347 pm_runtime_set_autosuspend_delay(dev, 50);
1348 pm_runtime_use_autosuspend(dev);
1349 pm_suspend_ignore_children(dev, 1);
1350}
1351
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001352static void sdhci_pci_runtime_pm_forbid(struct device *dev)
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001353{
1354 pm_runtime_forbid(dev);
1355 pm_runtime_get_noresume(dev);
1356}
1357
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001358static int sdhci_pci_probe(struct pci_dev *pdev,
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001359 const struct pci_device_id *ent)
1360{
1361 struct sdhci_pci_chip *chip;
1362 struct sdhci_pci_slot *slot;
1363
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001364 u8 slots, first_bar;
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001365 int ret, i;
1366
1367 BUG_ON(pdev == NULL);
1368 BUG_ON(ent == NULL);
1369
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001370 dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
Sergei Shtylyovcf5e23e2011-03-17 16:46:17 -04001371 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001372
1373 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1374 if (ret)
1375 return ret;
1376
1377 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1378 dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1379 if (slots == 0)
1380 return -ENODEV;
1381
1382 BUG_ON(slots > MAX_SLOTS);
1383
1384 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1385 if (ret)
1386 return ret;
1387
1388 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1389
1390 if (first_bar > 5) {
1391 dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1392 return -ENODEV;
1393 }
1394
1395 ret = pci_enable_device(pdev);
1396 if (ret)
1397 return ret;
1398
1399 chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
1400 if (!chip) {
1401 ret = -ENOMEM;
1402 goto err;
1403 }
1404
1405 chip->pdev = pdev;
Ameya Palandeb177bc92011-04-05 21:13:13 +03001406 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001407 if (chip->fixes) {
Pierre Ossman22606402008-03-23 19:33:23 +01001408 chip->quirks = chip->fixes->quirks;
Adrian Hunterf3c55a72012-02-07 14:48:55 +02001409 chip->quirks2 = chip->fixes->quirks2;
Adrian Hunterc43fd772011-10-17 10:52:44 +03001410 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1411 }
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001412 chip->num_slots = slots;
1413
1414 pci_set_drvdata(pdev, chip);
1415
Pierre Ossman22606402008-03-23 19:33:23 +01001416 if (chip->fixes && chip->fixes->probe) {
1417 ret = chip->fixes->probe(chip);
1418 if (ret)
1419 goto free;
1420 }
1421
Alan Cox225d85f2010-10-04 15:24:21 +01001422 slots = chip->num_slots; /* Quirk may have changed this */
1423
Ameya Palandeb177bc92011-04-05 21:13:13 +03001424 for (i = 0; i < slots; i++) {
Adrian Hunter52c506f2011-12-27 15:48:43 +02001425 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001426 if (IS_ERR(slot)) {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001427 for (i--; i >= 0; i--)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001428 sdhci_pci_remove_slot(chip->slots[i]);
1429 ret = PTR_ERR(slot);
1430 goto free;
1431 }
1432
1433 chip->slots[i] = slot;
1434 }
1435
Adrian Hunterc43fd772011-10-17 10:52:44 +03001436 if (chip->allow_runtime_pm)
1437 sdhci_pci_runtime_pm_allow(&pdev->dev);
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001438
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001439 return 0;
1440
1441free:
1442 pci_set_drvdata(pdev, NULL);
1443 kfree(chip);
1444
1445err:
1446 pci_disable_device(pdev);
1447 return ret;
1448}
1449
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001450static void sdhci_pci_remove(struct pci_dev *pdev)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001451{
1452 int i;
1453 struct sdhci_pci_chip *chip;
1454
1455 chip = pci_get_drvdata(pdev);
1456
1457 if (chip) {
Adrian Hunterc43fd772011-10-17 10:52:44 +03001458 if (chip->allow_runtime_pm)
1459 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1460
Ameya Palandeb177bc92011-04-05 21:13:13 +03001461 for (i = 0; i < chip->num_slots; i++)
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001462 sdhci_pci_remove_slot(chip->slots[i]);
1463
1464 pci_set_drvdata(pdev, NULL);
1465 kfree(chip);
1466 }
1467
1468 pci_disable_device(pdev);
1469}
1470
1471static struct pci_driver sdhci_driver = {
Ameya Palandeb177bc92011-04-05 21:13:13 +03001472 .name = "sdhci-pci",
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001473 .id_table = pci_ids,
Ameya Palandeb177bc92011-04-05 21:13:13 +03001474 .probe = sdhci_pci_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -05001475 .remove = sdhci_pci_remove,
Adrian Hunter66fd8ad2011-10-03 15:33:34 +03001476 .driver = {
1477 .pm = &sdhci_pci_pm_ops
1478 },
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001479};
1480
Sachin Kamatacc69642012-08-27 11:57:02 +05301481module_pci_driver(sdhci_driver);
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001482
Pierre Ossman32710e82009-04-08 20:14:54 +02001483MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
Pierre Ossmanb8c86fc2008-03-18 17:35:49 +01001484MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1485MODULE_LICENSE("GPL");