1659c9bc1SBen Hutchings /*  linux/drivers/mmc/host/sdhci-pci.c - SDHCI on PCI bus interface
2659c9bc1SBen Hutchings  *
3659c9bc1SBen Hutchings  *  Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
4659c9bc1SBen Hutchings  *
5659c9bc1SBen Hutchings  * This program is free software; you can redistribute it and/or modify
6659c9bc1SBen Hutchings  * it under the terms of the GNU General Public License as published by
7659c9bc1SBen Hutchings  * the Free Software Foundation; either version 2 of the License, or (at
8659c9bc1SBen Hutchings  * your option) any later version.
9659c9bc1SBen Hutchings  *
10659c9bc1SBen Hutchings  * Thanks to the following companies for their support:
11659c9bc1SBen Hutchings  *
12659c9bc1SBen Hutchings  *     - JMicron (hardware and technical support)
13659c9bc1SBen Hutchings  */
14659c9bc1SBen Hutchings 
15659c9bc1SBen Hutchings #include <linux/delay.h>
16659c9bc1SBen Hutchings #include <linux/highmem.h>
17659c9bc1SBen Hutchings #include <linux/module.h>
18659c9bc1SBen Hutchings #include <linux/pci.h>
19659c9bc1SBen Hutchings #include <linux/dma-mapping.h>
20659c9bc1SBen Hutchings #include <linux/slab.h>
21659c9bc1SBen Hutchings #include <linux/device.h>
22659c9bc1SBen Hutchings #include <linux/mmc/host.h>
23659c9bc1SBen Hutchings #include <linux/mmc/mmc.h>
24659c9bc1SBen Hutchings #include <linux/scatterlist.h>
25659c9bc1SBen Hutchings #include <linux/io.h>
26659c9bc1SBen Hutchings #include <linux/gpio.h>
27659c9bc1SBen Hutchings #include <linux/pm_runtime.h>
28659c9bc1SBen Hutchings #include <linux/mmc/slot-gpio.h>
29659c9bc1SBen Hutchings #include <linux/mmc/sdhci-pci-data.h>
30659c9bc1SBen Hutchings 
31659c9bc1SBen Hutchings #include "sdhci.h"
32659c9bc1SBen Hutchings #include "sdhci-pci.h"
33659c9bc1SBen Hutchings #include "sdhci-pci-o2micro.h"
34659c9bc1SBen Hutchings 
35659c9bc1SBen Hutchings /*****************************************************************************\
36659c9bc1SBen Hutchings  *                                                                           *
37659c9bc1SBen Hutchings  * Hardware specific quirk handling                                          *
38659c9bc1SBen Hutchings  *                                                                           *
39659c9bc1SBen Hutchings \*****************************************************************************/
40659c9bc1SBen Hutchings 
41659c9bc1SBen Hutchings static int ricoh_probe(struct sdhci_pci_chip *chip)
42659c9bc1SBen Hutchings {
43659c9bc1SBen Hutchings 	if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
44659c9bc1SBen Hutchings 	    chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
45659c9bc1SBen Hutchings 		chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
46659c9bc1SBen Hutchings 	return 0;
47659c9bc1SBen Hutchings }
48659c9bc1SBen Hutchings 
49659c9bc1SBen Hutchings static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
50659c9bc1SBen Hutchings {
51659c9bc1SBen Hutchings 	slot->host->caps =
52659c9bc1SBen Hutchings 		((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
53659c9bc1SBen Hutchings 			& SDHCI_TIMEOUT_CLK_MASK) |
54659c9bc1SBen Hutchings 
55659c9bc1SBen Hutchings 		((0x21 << SDHCI_CLOCK_BASE_SHIFT)
56659c9bc1SBen Hutchings 			& SDHCI_CLOCK_BASE_MASK) |
57659c9bc1SBen Hutchings 
58659c9bc1SBen Hutchings 		SDHCI_TIMEOUT_CLK_UNIT |
59659c9bc1SBen Hutchings 		SDHCI_CAN_VDD_330 |
60659c9bc1SBen Hutchings 		SDHCI_CAN_DO_HISPD |
61659c9bc1SBen Hutchings 		SDHCI_CAN_DO_SDMA;
62659c9bc1SBen Hutchings 	return 0;
63659c9bc1SBen Hutchings }
64659c9bc1SBen Hutchings 
65659c9bc1SBen Hutchings static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
66659c9bc1SBen Hutchings {
67659c9bc1SBen Hutchings 	/* Apply a delay to allow controller to settle */
68659c9bc1SBen Hutchings 	/* Otherwise it becomes confused if card state changed
69659c9bc1SBen Hutchings 		during suspend */
70659c9bc1SBen Hutchings 	msleep(500);
71659c9bc1SBen Hutchings 	return 0;
72659c9bc1SBen Hutchings }
73659c9bc1SBen Hutchings 
74659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ricoh = {
75659c9bc1SBen Hutchings 	.probe		= ricoh_probe,
76659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_32BIT_DMA_ADDR |
77659c9bc1SBen Hutchings 			  SDHCI_QUIRK_FORCE_DMA |
78659c9bc1SBen Hutchings 			  SDHCI_QUIRK_CLOCK_BEFORE_RESET,
79659c9bc1SBen Hutchings };
80659c9bc1SBen Hutchings 
81659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
82659c9bc1SBen Hutchings 	.probe_slot	= ricoh_mmc_probe_slot,
83659c9bc1SBen Hutchings 	.resume		= ricoh_mmc_resume,
84659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_32BIT_DMA_ADDR |
85659c9bc1SBen Hutchings 			  SDHCI_QUIRK_CLOCK_BEFORE_RESET |
86659c9bc1SBen Hutchings 			  SDHCI_QUIRK_NO_CARD_NO_RESET |
87659c9bc1SBen Hutchings 			  SDHCI_QUIRK_MISSING_CAPS
88659c9bc1SBen Hutchings };
89659c9bc1SBen Hutchings 
90659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ene_712 = {
91659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_SINGLE_POWER_WRITE |
92659c9bc1SBen Hutchings 			  SDHCI_QUIRK_BROKEN_DMA,
93659c9bc1SBen Hutchings };
94659c9bc1SBen Hutchings 
95659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ene_714 = {
96659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_SINGLE_POWER_WRITE |
97659c9bc1SBen Hutchings 			  SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
98659c9bc1SBen Hutchings 			  SDHCI_QUIRK_BROKEN_DMA,
99659c9bc1SBen Hutchings };
100659c9bc1SBen Hutchings 
101659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_cafe = {
102659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
103659c9bc1SBen Hutchings 			  SDHCI_QUIRK_NO_BUSY_IRQ |
104659c9bc1SBen Hutchings 			  SDHCI_QUIRK_BROKEN_CARD_DETECTION |
105659c9bc1SBen Hutchings 			  SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
106659c9bc1SBen Hutchings };
107659c9bc1SBen Hutchings 
108659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_qrk = {
109659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_HISPD_BIT,
110659c9bc1SBen Hutchings };
111659c9bc1SBen Hutchings 
112659c9bc1SBen Hutchings static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
113659c9bc1SBen Hutchings {
114659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
115659c9bc1SBen Hutchings 	return 0;
116659c9bc1SBen Hutchings }
117659c9bc1SBen Hutchings 
118659c9bc1SBen Hutchings /*
119659c9bc1SBen Hutchings  * ADMA operation is disabled for Moorestown platform due to
120659c9bc1SBen Hutchings  * hardware bugs.
121659c9bc1SBen Hutchings  */
122659c9bc1SBen Hutchings static int mrst_hc_probe(struct sdhci_pci_chip *chip)
123659c9bc1SBen Hutchings {
124659c9bc1SBen Hutchings 	/*
125659c9bc1SBen Hutchings 	 * slots number is fixed here for MRST as SDIO3/5 are never used and
126659c9bc1SBen Hutchings 	 * have hardware bugs.
127659c9bc1SBen Hutchings 	 */
128659c9bc1SBen Hutchings 	chip->num_slots = 1;
129659c9bc1SBen Hutchings 	return 0;
130659c9bc1SBen Hutchings }
131659c9bc1SBen Hutchings 
132659c9bc1SBen Hutchings static int pch_hc_probe_slot(struct sdhci_pci_slot *slot)
133659c9bc1SBen Hutchings {
134659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
135659c9bc1SBen Hutchings 	return 0;
136659c9bc1SBen Hutchings }
137659c9bc1SBen Hutchings 
138659c9bc1SBen Hutchings #ifdef CONFIG_PM
139659c9bc1SBen Hutchings 
140659c9bc1SBen Hutchings static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
141659c9bc1SBen Hutchings {
142659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot = dev_id;
143659c9bc1SBen Hutchings 	struct sdhci_host *host = slot->host;
144659c9bc1SBen Hutchings 
145659c9bc1SBen Hutchings 	mmc_detect_change(host->mmc, msecs_to_jiffies(200));
146659c9bc1SBen Hutchings 	return IRQ_HANDLED;
147659c9bc1SBen Hutchings }
148659c9bc1SBen Hutchings 
149659c9bc1SBen Hutchings static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
150659c9bc1SBen Hutchings {
151659c9bc1SBen Hutchings 	int err, irq, gpio = slot->cd_gpio;
152659c9bc1SBen Hutchings 
153659c9bc1SBen Hutchings 	slot->cd_gpio = -EINVAL;
154659c9bc1SBen Hutchings 	slot->cd_irq = -EINVAL;
155659c9bc1SBen Hutchings 
156659c9bc1SBen Hutchings 	if (!gpio_is_valid(gpio))
157659c9bc1SBen Hutchings 		return;
158659c9bc1SBen Hutchings 
159659c9bc1SBen Hutchings 	err = gpio_request(gpio, "sd_cd");
160659c9bc1SBen Hutchings 	if (err < 0)
161659c9bc1SBen Hutchings 		goto out;
162659c9bc1SBen Hutchings 
163659c9bc1SBen Hutchings 	err = gpio_direction_input(gpio);
164659c9bc1SBen Hutchings 	if (err < 0)
165659c9bc1SBen Hutchings 		goto out_free;
166659c9bc1SBen Hutchings 
167659c9bc1SBen Hutchings 	irq = gpio_to_irq(gpio);
168659c9bc1SBen Hutchings 	if (irq < 0)
169659c9bc1SBen Hutchings 		goto out_free;
170659c9bc1SBen Hutchings 
171659c9bc1SBen Hutchings 	err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
172659c9bc1SBen Hutchings 			  IRQF_TRIGGER_FALLING, "sd_cd", slot);
173659c9bc1SBen Hutchings 	if (err)
174659c9bc1SBen Hutchings 		goto out_free;
175659c9bc1SBen Hutchings 
176659c9bc1SBen Hutchings 	slot->cd_gpio = gpio;
177659c9bc1SBen Hutchings 	slot->cd_irq = irq;
178659c9bc1SBen Hutchings 
179659c9bc1SBen Hutchings 	return;
180659c9bc1SBen Hutchings 
181659c9bc1SBen Hutchings out_free:
182659c9bc1SBen Hutchings 	gpio_free(gpio);
183659c9bc1SBen Hutchings out:
184659c9bc1SBen Hutchings 	dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
185659c9bc1SBen Hutchings }
186659c9bc1SBen Hutchings 
187659c9bc1SBen Hutchings static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
188659c9bc1SBen Hutchings {
189659c9bc1SBen Hutchings 	if (slot->cd_irq >= 0)
190659c9bc1SBen Hutchings 		free_irq(slot->cd_irq, slot);
191659c9bc1SBen Hutchings 	if (gpio_is_valid(slot->cd_gpio))
192659c9bc1SBen Hutchings 		gpio_free(slot->cd_gpio);
193659c9bc1SBen Hutchings }
194659c9bc1SBen Hutchings 
195659c9bc1SBen Hutchings #else
196659c9bc1SBen Hutchings 
197659c9bc1SBen Hutchings static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
198659c9bc1SBen Hutchings {
199659c9bc1SBen Hutchings }
200659c9bc1SBen Hutchings 
201659c9bc1SBen Hutchings static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
202659c9bc1SBen Hutchings {
203659c9bc1SBen Hutchings }
204659c9bc1SBen Hutchings 
205659c9bc1SBen Hutchings #endif
206659c9bc1SBen Hutchings 
207659c9bc1SBen Hutchings static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
208659c9bc1SBen Hutchings {
209659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
210659c9bc1SBen Hutchings 	slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
211659c9bc1SBen Hutchings 				  MMC_CAP2_HC_ERASE_SZ;
212659c9bc1SBen Hutchings 	return 0;
213659c9bc1SBen Hutchings }
214659c9bc1SBen Hutchings 
215659c9bc1SBen Hutchings static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
216659c9bc1SBen Hutchings {
217659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
218659c9bc1SBen Hutchings 	return 0;
219659c9bc1SBen Hutchings }
220659c9bc1SBen Hutchings 
221659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
222659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
223659c9bc1SBen Hutchings 	.probe_slot	= mrst_hc_probe_slot,
224659c9bc1SBen Hutchings };
225659c9bc1SBen Hutchings 
226659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
227659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
228659c9bc1SBen Hutchings 	.probe		= mrst_hc_probe,
229659c9bc1SBen Hutchings };
230659c9bc1SBen Hutchings 
231659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
232659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
233659c9bc1SBen Hutchings 	.allow_runtime_pm = true,
234659c9bc1SBen Hutchings 	.own_cd_for_runtime_pm = true,
235659c9bc1SBen Hutchings };
236659c9bc1SBen Hutchings 
237659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
238659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
239659c9bc1SBen Hutchings 	.quirks2	= SDHCI_QUIRK2_HOST_OFF_CARD_ON,
240659c9bc1SBen Hutchings 	.allow_runtime_pm = true,
241659c9bc1SBen Hutchings 	.probe_slot	= mfd_sdio_probe_slot,
242659c9bc1SBen Hutchings };
243659c9bc1SBen Hutchings 
244659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
245659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
246659c9bc1SBen Hutchings 	.allow_runtime_pm = true,
247659c9bc1SBen Hutchings 	.probe_slot	= mfd_emmc_probe_slot,
248659c9bc1SBen Hutchings };
249659c9bc1SBen Hutchings 
250659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = {
251659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_BROKEN_ADMA,
252659c9bc1SBen Hutchings 	.probe_slot	= pch_hc_probe_slot,
253659c9bc1SBen Hutchings };
254659c9bc1SBen Hutchings 
255659c9bc1SBen Hutchings static void sdhci_pci_int_hw_reset(struct sdhci_host *host)
256659c9bc1SBen Hutchings {
257659c9bc1SBen Hutchings 	u8 reg;
258659c9bc1SBen Hutchings 
259659c9bc1SBen Hutchings 	reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
260659c9bc1SBen Hutchings 	reg |= 0x10;
261659c9bc1SBen Hutchings 	sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
262659c9bc1SBen Hutchings 	/* For eMMC, minimum is 1us but give it 9us for good measure */
263659c9bc1SBen Hutchings 	udelay(9);
264659c9bc1SBen Hutchings 	reg &= ~0x10;
265659c9bc1SBen Hutchings 	sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
266659c9bc1SBen Hutchings 	/* For eMMC, minimum is 200us but give it 300us for good measure */
267659c9bc1SBen Hutchings 	usleep_range(300, 1000);
268659c9bc1SBen Hutchings }
269659c9bc1SBen Hutchings 
270659c9bc1SBen Hutchings static int spt_select_drive_strength(struct sdhci_host *host,
271659c9bc1SBen Hutchings 				     struct mmc_card *card,
272659c9bc1SBen Hutchings 				     unsigned int max_dtr,
273659c9bc1SBen Hutchings 				     int host_drv, int card_drv, int *drv_type)
274659c9bc1SBen Hutchings {
275659c9bc1SBen Hutchings 	int drive_strength;
276659c9bc1SBen Hutchings 
277659c9bc1SBen Hutchings 	if (sdhci_pci_spt_drive_strength > 0)
278659c9bc1SBen Hutchings 		drive_strength = sdhci_pci_spt_drive_strength & 0xf;
279659c9bc1SBen Hutchings 	else
2801ca89685SAdrian Hunter 		drive_strength = 0; /* Default 50-ohm */
281659c9bc1SBen Hutchings 
282659c9bc1SBen Hutchings 	if ((mmc_driver_type_mask(drive_strength) & card_drv) == 0)
283659c9bc1SBen Hutchings 		drive_strength = 0; /* Default 50-ohm */
284659c9bc1SBen Hutchings 
285659c9bc1SBen Hutchings 	return drive_strength;
286659c9bc1SBen Hutchings }
287659c9bc1SBen Hutchings 
288659c9bc1SBen Hutchings /* Try to read the drive strength from the card */
289659c9bc1SBen Hutchings static void spt_read_drive_strength(struct sdhci_host *host)
290659c9bc1SBen Hutchings {
291659c9bc1SBen Hutchings 	u32 val, i, t;
292659c9bc1SBen Hutchings 	u16 m;
293659c9bc1SBen Hutchings 
294659c9bc1SBen Hutchings 	if (sdhci_pci_spt_drive_strength)
295659c9bc1SBen Hutchings 		return;
296659c9bc1SBen Hutchings 
297659c9bc1SBen Hutchings 	sdhci_pci_spt_drive_strength = -1;
298659c9bc1SBen Hutchings 
299659c9bc1SBen Hutchings 	m = sdhci_readw(host, SDHCI_HOST_CONTROL2) & 0x7;
300659c9bc1SBen Hutchings 	if (m != 3 && m != 5)
301659c9bc1SBen Hutchings 		return;
302659c9bc1SBen Hutchings 	val = sdhci_readl(host, SDHCI_PRESENT_STATE);
303659c9bc1SBen Hutchings 	if (val & 0x3)
304659c9bc1SBen Hutchings 		return;
305659c9bc1SBen Hutchings 	sdhci_writel(host, 0x007f0023, SDHCI_INT_ENABLE);
306659c9bc1SBen Hutchings 	sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
307659c9bc1SBen Hutchings 	sdhci_writew(host, 0x10, SDHCI_TRANSFER_MODE);
308659c9bc1SBen Hutchings 	sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL);
309659c9bc1SBen Hutchings 	sdhci_writew(host, 512, SDHCI_BLOCK_SIZE);
310659c9bc1SBen Hutchings 	sdhci_writew(host, 1, SDHCI_BLOCK_COUNT);
311659c9bc1SBen Hutchings 	sdhci_writel(host, 0, SDHCI_ARGUMENT);
312659c9bc1SBen Hutchings 	sdhci_writew(host, 0x83b, SDHCI_COMMAND);
313659c9bc1SBen Hutchings 	for (i = 0; i < 1000; i++) {
314659c9bc1SBen Hutchings 		val = sdhci_readl(host, SDHCI_INT_STATUS);
315659c9bc1SBen Hutchings 		if (val & 0xffff8000)
316659c9bc1SBen Hutchings 			return;
317659c9bc1SBen Hutchings 		if (val & 0x20)
318659c9bc1SBen Hutchings 			break;
319659c9bc1SBen Hutchings 		udelay(1);
320659c9bc1SBen Hutchings 	}
321659c9bc1SBen Hutchings 	val = sdhci_readl(host, SDHCI_PRESENT_STATE);
322659c9bc1SBen Hutchings 	if (!(val & 0x800))
323659c9bc1SBen Hutchings 		return;
324659c9bc1SBen Hutchings 	for (i = 0; i < 47; i++)
325659c9bc1SBen Hutchings 		val = sdhci_readl(host, SDHCI_BUFFER);
326659c9bc1SBen Hutchings 	t = val & 0xf00;
327659c9bc1SBen Hutchings 	if (t != 0x200 && t != 0x300)
328659c9bc1SBen Hutchings 		return;
329659c9bc1SBen Hutchings 
330659c9bc1SBen Hutchings 	sdhci_pci_spt_drive_strength = 0x10 | ((val >> 12) & 0xf);
331659c9bc1SBen Hutchings }
332659c9bc1SBen Hutchings 
333163cbe31SAdrian Hunter static int bxt_get_cd(struct mmc_host *mmc)
334163cbe31SAdrian Hunter {
335163cbe31SAdrian Hunter 	int gpio_cd = mmc_gpio_get_cd(mmc);
336163cbe31SAdrian Hunter 	struct sdhci_host *host = mmc_priv(mmc);
337163cbe31SAdrian Hunter 	unsigned long flags;
338163cbe31SAdrian Hunter 	int ret = 0;
339163cbe31SAdrian Hunter 
340163cbe31SAdrian Hunter 	if (!gpio_cd)
341163cbe31SAdrian Hunter 		return 0;
342163cbe31SAdrian Hunter 
343163cbe31SAdrian Hunter 	spin_lock_irqsave(&host->lock, flags);
344163cbe31SAdrian Hunter 
345163cbe31SAdrian Hunter 	if (host->flags & SDHCI_DEVICE_DEAD)
346163cbe31SAdrian Hunter 		goto out;
347163cbe31SAdrian Hunter 
348163cbe31SAdrian Hunter 	ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
349163cbe31SAdrian Hunter out:
350163cbe31SAdrian Hunter 	spin_unlock_irqrestore(&host->lock, flags);
351163cbe31SAdrian Hunter 
352163cbe31SAdrian Hunter 	return ret;
353163cbe31SAdrian Hunter }
354163cbe31SAdrian Hunter 
355659c9bc1SBen Hutchings static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
356659c9bc1SBen Hutchings {
357659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
358659c9bc1SBen Hutchings 				 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
359659c9bc1SBen Hutchings 				 MMC_CAP_WAIT_WHILE_BUSY;
360659c9bc1SBen Hutchings 	slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
361659c9bc1SBen Hutchings 	slot->hw_reset = sdhci_pci_int_hw_reset;
362659c9bc1SBen Hutchings 	if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC)
363659c9bc1SBen Hutchings 		slot->host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
364659c9bc1SBen Hutchings 	if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_SPT_EMMC) {
365659c9bc1SBen Hutchings 		spt_read_drive_strength(slot->host);
366659c9bc1SBen Hutchings 		slot->select_drive_strength = spt_select_drive_strength;
367659c9bc1SBen Hutchings 	}
368659c9bc1SBen Hutchings 	return 0;
369659c9bc1SBen Hutchings }
370659c9bc1SBen Hutchings 
371659c9bc1SBen Hutchings static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
372659c9bc1SBen Hutchings {
373659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE |
374659c9bc1SBen Hutchings 				 MMC_CAP_WAIT_WHILE_BUSY;
375659c9bc1SBen Hutchings 	return 0;
376659c9bc1SBen Hutchings }
377659c9bc1SBen Hutchings 
378659c9bc1SBen Hutchings static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
379659c9bc1SBen Hutchings {
38082296936SAdrian Hunter 	slot->host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
381659c9bc1SBen Hutchings 	slot->cd_con_id = NULL;
382659c9bc1SBen Hutchings 	slot->cd_idx = 0;
383659c9bc1SBen Hutchings 	slot->cd_override_level = true;
384163cbe31SAdrian Hunter 	if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD ||
38501d6b2a4SAdrian Hunter 	    slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD ||
386e8ef5176SAdrian Hunter 	    slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD) {
387163cbe31SAdrian Hunter 		slot->host->mmc_host_ops.get_cd = bxt_get_cd;
388e8ef5176SAdrian Hunter 		slot->host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM;
389e8ef5176SAdrian Hunter 	}
390163cbe31SAdrian Hunter 
391659c9bc1SBen Hutchings 	return 0;
392659c9bc1SBen Hutchings }
393659c9bc1SBen Hutchings 
394659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
395659c9bc1SBen Hutchings 	.allow_runtime_pm = true,
396659c9bc1SBen Hutchings 	.probe_slot	= byt_emmc_probe_slot,
397659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
398659c9bc1SBen Hutchings 	.quirks2	= SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
399659c9bc1SBen Hutchings 			  SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 |
400659c9bc1SBen Hutchings 			  SDHCI_QUIRK2_STOP_WITH_TC,
401659c9bc1SBen Hutchings };
402659c9bc1SBen Hutchings 
403659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
404659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
405659c9bc1SBen Hutchings 	.quirks2	= SDHCI_QUIRK2_HOST_OFF_CARD_ON |
406659c9bc1SBen Hutchings 			SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
407659c9bc1SBen Hutchings 	.allow_runtime_pm = true,
408659c9bc1SBen Hutchings 	.probe_slot	= byt_sdio_probe_slot,
409659c9bc1SBen Hutchings };
410659c9bc1SBen Hutchings 
411659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
412659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
413659c9bc1SBen Hutchings 	.quirks2	= SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
414659c9bc1SBen Hutchings 			  SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
415659c9bc1SBen Hutchings 			  SDHCI_QUIRK2_STOP_WITH_TC,
416659c9bc1SBen Hutchings 	.allow_runtime_pm = true,
417659c9bc1SBen Hutchings 	.own_cd_for_runtime_pm = true,
418659c9bc1SBen Hutchings 	.probe_slot	= byt_sd_probe_slot,
419659c9bc1SBen Hutchings };
420659c9bc1SBen Hutchings 
421659c9bc1SBen Hutchings /* Define Host controllers for Intel Merrifield platform */
4221f64cec2SAndy Shevchenko #define INTEL_MRFLD_EMMC_0	0
4231f64cec2SAndy Shevchenko #define INTEL_MRFLD_EMMC_1	1
424659c9bc1SBen Hutchings 
4251f64cec2SAndy Shevchenko static int intel_mrfld_mmc_probe_slot(struct sdhci_pci_slot *slot)
426659c9bc1SBen Hutchings {
4271f64cec2SAndy Shevchenko 	if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFLD_EMMC_0) &&
4281f64cec2SAndy Shevchenko 	    (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFLD_EMMC_1))
429659c9bc1SBen Hutchings 		/* SD support is not ready yet */
430659c9bc1SBen Hutchings 		return -ENODEV;
431659c9bc1SBen Hutchings 
432659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
433659c9bc1SBen Hutchings 				 MMC_CAP_1_8V_DDR;
434659c9bc1SBen Hutchings 
435659c9bc1SBen Hutchings 	return 0;
436659c9bc1SBen Hutchings }
437659c9bc1SBen Hutchings 
4381f64cec2SAndy Shevchenko static const struct sdhci_pci_fixes sdhci_intel_mrfld_mmc = {
439659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
440659c9bc1SBen Hutchings 	.quirks2	= SDHCI_QUIRK2_BROKEN_HS200 |
441659c9bc1SBen Hutchings 			SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
442659c9bc1SBen Hutchings 	.allow_runtime_pm = true,
4431f64cec2SAndy Shevchenko 	.probe_slot	= intel_mrfld_mmc_probe_slot,
444659c9bc1SBen Hutchings };
445659c9bc1SBen Hutchings 
446659c9bc1SBen Hutchings /* O2Micro extra registers */
447659c9bc1SBen Hutchings #define O2_SD_LOCK_WP		0xD3
448659c9bc1SBen Hutchings #define O2_SD_MULTI_VCC3V	0xEE
449659c9bc1SBen Hutchings #define O2_SD_CLKREQ		0xEC
450659c9bc1SBen Hutchings #define O2_SD_CAPS		0xE0
451659c9bc1SBen Hutchings #define O2_SD_ADMA1		0xE2
452659c9bc1SBen Hutchings #define O2_SD_ADMA2		0xE7
453659c9bc1SBen Hutchings #define O2_SD_INF_MOD		0xF1
454659c9bc1SBen Hutchings 
455659c9bc1SBen Hutchings static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
456659c9bc1SBen Hutchings {
457659c9bc1SBen Hutchings 	u8 scratch;
458659c9bc1SBen Hutchings 	int ret;
459659c9bc1SBen Hutchings 
460659c9bc1SBen Hutchings 	ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
461659c9bc1SBen Hutchings 	if (ret)
462659c9bc1SBen Hutchings 		return ret;
463659c9bc1SBen Hutchings 
464659c9bc1SBen Hutchings 	/*
465659c9bc1SBen Hutchings 	 * Turn PMOS on [bit 0], set over current detection to 2.4 V
466659c9bc1SBen Hutchings 	 * [bit 1:2] and enable over current debouncing [bit 6].
467659c9bc1SBen Hutchings 	 */
468659c9bc1SBen Hutchings 	if (on)
469659c9bc1SBen Hutchings 		scratch |= 0x47;
470659c9bc1SBen Hutchings 	else
471659c9bc1SBen Hutchings 		scratch &= ~0x47;
472659c9bc1SBen Hutchings 
4737582041fSkbuild test robot 	return pci_write_config_byte(chip->pdev, 0xAE, scratch);
474659c9bc1SBen Hutchings }
475659c9bc1SBen Hutchings 
476659c9bc1SBen Hutchings static int jmicron_probe(struct sdhci_pci_chip *chip)
477659c9bc1SBen Hutchings {
478659c9bc1SBen Hutchings 	int ret;
479659c9bc1SBen Hutchings 	u16 mmcdev = 0;
480659c9bc1SBen Hutchings 
481659c9bc1SBen Hutchings 	if (chip->pdev->revision == 0) {
482659c9bc1SBen Hutchings 		chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
483659c9bc1SBen Hutchings 			  SDHCI_QUIRK_32BIT_DMA_SIZE |
484659c9bc1SBen Hutchings 			  SDHCI_QUIRK_32BIT_ADMA_SIZE |
485659c9bc1SBen Hutchings 			  SDHCI_QUIRK_RESET_AFTER_REQUEST |
486659c9bc1SBen Hutchings 			  SDHCI_QUIRK_BROKEN_SMALL_PIO;
487659c9bc1SBen Hutchings 	}
488659c9bc1SBen Hutchings 
489659c9bc1SBen Hutchings 	/*
490659c9bc1SBen Hutchings 	 * JMicron chips can have two interfaces to the same hardware
491659c9bc1SBen Hutchings 	 * in order to work around limitations in Microsoft's driver.
492659c9bc1SBen Hutchings 	 * We need to make sure we only bind to one of them.
493659c9bc1SBen Hutchings 	 *
494659c9bc1SBen Hutchings 	 * This code assumes two things:
495659c9bc1SBen Hutchings 	 *
496659c9bc1SBen Hutchings 	 * 1. The PCI code adds subfunctions in order.
497659c9bc1SBen Hutchings 	 *
498659c9bc1SBen Hutchings 	 * 2. The MMC interface has a lower subfunction number
499659c9bc1SBen Hutchings 	 *    than the SD interface.
500659c9bc1SBen Hutchings 	 */
501659c9bc1SBen Hutchings 	if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
502659c9bc1SBen Hutchings 		mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
503659c9bc1SBen Hutchings 	else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
504659c9bc1SBen Hutchings 		mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
505659c9bc1SBen Hutchings 
506659c9bc1SBen Hutchings 	if (mmcdev) {
507659c9bc1SBen Hutchings 		struct pci_dev *sd_dev;
508659c9bc1SBen Hutchings 
509659c9bc1SBen Hutchings 		sd_dev = NULL;
510659c9bc1SBen Hutchings 		while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
511659c9bc1SBen Hutchings 						mmcdev, sd_dev)) != NULL) {
512659c9bc1SBen Hutchings 			if ((PCI_SLOT(chip->pdev->devfn) ==
513659c9bc1SBen Hutchings 				PCI_SLOT(sd_dev->devfn)) &&
514659c9bc1SBen Hutchings 				(chip->pdev->bus == sd_dev->bus))
515659c9bc1SBen Hutchings 				break;
516659c9bc1SBen Hutchings 		}
517659c9bc1SBen Hutchings 
518659c9bc1SBen Hutchings 		if (sd_dev) {
519659c9bc1SBen Hutchings 			pci_dev_put(sd_dev);
520659c9bc1SBen Hutchings 			dev_info(&chip->pdev->dev, "Refusing to bind to "
521659c9bc1SBen Hutchings 				"secondary interface.\n");
522659c9bc1SBen Hutchings 			return -ENODEV;
523659c9bc1SBen Hutchings 		}
524659c9bc1SBen Hutchings 	}
525659c9bc1SBen Hutchings 
526659c9bc1SBen Hutchings 	/*
527659c9bc1SBen Hutchings 	 * JMicron chips need a bit of a nudge to enable the power
528659c9bc1SBen Hutchings 	 * output pins.
529659c9bc1SBen Hutchings 	 */
530659c9bc1SBen Hutchings 	ret = jmicron_pmos(chip, 1);
531659c9bc1SBen Hutchings 	if (ret) {
532659c9bc1SBen Hutchings 		dev_err(&chip->pdev->dev, "Failure enabling card power\n");
533659c9bc1SBen Hutchings 		return ret;
534659c9bc1SBen Hutchings 	}
535659c9bc1SBen Hutchings 
536659c9bc1SBen Hutchings 	/* quirk for unsable RO-detection on JM388 chips */
537659c9bc1SBen Hutchings 	if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
538659c9bc1SBen Hutchings 	    chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
539659c9bc1SBen Hutchings 		chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
540659c9bc1SBen Hutchings 
541659c9bc1SBen Hutchings 	return 0;
542659c9bc1SBen Hutchings }
543659c9bc1SBen Hutchings 
544659c9bc1SBen Hutchings static void jmicron_enable_mmc(struct sdhci_host *host, int on)
545659c9bc1SBen Hutchings {
546659c9bc1SBen Hutchings 	u8 scratch;
547659c9bc1SBen Hutchings 
548659c9bc1SBen Hutchings 	scratch = readb(host->ioaddr + 0xC0);
549659c9bc1SBen Hutchings 
550659c9bc1SBen Hutchings 	if (on)
551659c9bc1SBen Hutchings 		scratch |= 0x01;
552659c9bc1SBen Hutchings 	else
553659c9bc1SBen Hutchings 		scratch &= ~0x01;
554659c9bc1SBen Hutchings 
555659c9bc1SBen Hutchings 	writeb(scratch, host->ioaddr + 0xC0);
556659c9bc1SBen Hutchings }
557659c9bc1SBen Hutchings 
558659c9bc1SBen Hutchings static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
559659c9bc1SBen Hutchings {
560659c9bc1SBen Hutchings 	if (slot->chip->pdev->revision == 0) {
561659c9bc1SBen Hutchings 		u16 version;
562659c9bc1SBen Hutchings 
563659c9bc1SBen Hutchings 		version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
564659c9bc1SBen Hutchings 		version = (version & SDHCI_VENDOR_VER_MASK) >>
565659c9bc1SBen Hutchings 			SDHCI_VENDOR_VER_SHIFT;
566659c9bc1SBen Hutchings 
567659c9bc1SBen Hutchings 		/*
568659c9bc1SBen Hutchings 		 * Older versions of the chip have lots of nasty glitches
569659c9bc1SBen Hutchings 		 * in the ADMA engine. It's best just to avoid it
570659c9bc1SBen Hutchings 		 * completely.
571659c9bc1SBen Hutchings 		 */
572659c9bc1SBen Hutchings 		if (version < 0xAC)
573659c9bc1SBen Hutchings 			slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
574659c9bc1SBen Hutchings 	}
575659c9bc1SBen Hutchings 
576659c9bc1SBen Hutchings 	/* JM388 MMC doesn't support 1.8V while SD supports it */
577659c9bc1SBen Hutchings 	if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
578659c9bc1SBen Hutchings 		slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
579659c9bc1SBen Hutchings 			MMC_VDD_29_30 | MMC_VDD_30_31 |
580659c9bc1SBen Hutchings 			MMC_VDD_165_195; /* allow 1.8V */
581659c9bc1SBen Hutchings 		slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
582659c9bc1SBen Hutchings 			MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
583659c9bc1SBen Hutchings 	}
584659c9bc1SBen Hutchings 
585659c9bc1SBen Hutchings 	/*
586659c9bc1SBen Hutchings 	 * The secondary interface requires a bit set to get the
587659c9bc1SBen Hutchings 	 * interrupts.
588659c9bc1SBen Hutchings 	 */
589659c9bc1SBen Hutchings 	if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
590659c9bc1SBen Hutchings 	    slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
591659c9bc1SBen Hutchings 		jmicron_enable_mmc(slot->host, 1);
592659c9bc1SBen Hutchings 
593659c9bc1SBen Hutchings 	slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
594659c9bc1SBen Hutchings 
595659c9bc1SBen Hutchings 	return 0;
596659c9bc1SBen Hutchings }
597659c9bc1SBen Hutchings 
598659c9bc1SBen Hutchings static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
599659c9bc1SBen Hutchings {
600659c9bc1SBen Hutchings 	if (dead)
601659c9bc1SBen Hutchings 		return;
602659c9bc1SBen Hutchings 
603659c9bc1SBen Hutchings 	if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
604659c9bc1SBen Hutchings 	    slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
605659c9bc1SBen Hutchings 		jmicron_enable_mmc(slot->host, 0);
606659c9bc1SBen Hutchings }
607659c9bc1SBen Hutchings 
608659c9bc1SBen Hutchings static int jmicron_suspend(struct sdhci_pci_chip *chip)
609659c9bc1SBen Hutchings {
610659c9bc1SBen Hutchings 	int i;
611659c9bc1SBen Hutchings 
612659c9bc1SBen Hutchings 	if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
613659c9bc1SBen Hutchings 	    chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
614659c9bc1SBen Hutchings 		for (i = 0; i < chip->num_slots; i++)
615659c9bc1SBen Hutchings 			jmicron_enable_mmc(chip->slots[i]->host, 0);
616659c9bc1SBen Hutchings 	}
617659c9bc1SBen Hutchings 
618659c9bc1SBen Hutchings 	return 0;
619659c9bc1SBen Hutchings }
620659c9bc1SBen Hutchings 
621659c9bc1SBen Hutchings static int jmicron_resume(struct sdhci_pci_chip *chip)
622659c9bc1SBen Hutchings {
623659c9bc1SBen Hutchings 	int ret, i;
624659c9bc1SBen Hutchings 
625659c9bc1SBen Hutchings 	if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
626659c9bc1SBen Hutchings 	    chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
627659c9bc1SBen Hutchings 		for (i = 0; i < chip->num_slots; i++)
628659c9bc1SBen Hutchings 			jmicron_enable_mmc(chip->slots[i]->host, 1);
629659c9bc1SBen Hutchings 	}
630659c9bc1SBen Hutchings 
631659c9bc1SBen Hutchings 	ret = jmicron_pmos(chip, 1);
632659c9bc1SBen Hutchings 	if (ret) {
633659c9bc1SBen Hutchings 		dev_err(&chip->pdev->dev, "Failure enabling card power\n");
634659c9bc1SBen Hutchings 		return ret;
635659c9bc1SBen Hutchings 	}
636659c9bc1SBen Hutchings 
637659c9bc1SBen Hutchings 	return 0;
638659c9bc1SBen Hutchings }
639659c9bc1SBen Hutchings 
640659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_o2 = {
641659c9bc1SBen Hutchings 	.probe = sdhci_pci_o2_probe,
642659c9bc1SBen Hutchings 	.quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
643659c9bc1SBen Hutchings 	.quirks2 = SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD,
644659c9bc1SBen Hutchings 	.probe_slot = sdhci_pci_o2_probe_slot,
645659c9bc1SBen Hutchings 	.resume = sdhci_pci_o2_resume,
646659c9bc1SBen Hutchings };
647659c9bc1SBen Hutchings 
648659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_jmicron = {
649659c9bc1SBen Hutchings 	.probe		= jmicron_probe,
650659c9bc1SBen Hutchings 
651659c9bc1SBen Hutchings 	.probe_slot	= jmicron_probe_slot,
652659c9bc1SBen Hutchings 	.remove_slot	= jmicron_remove_slot,
653659c9bc1SBen Hutchings 
654659c9bc1SBen Hutchings 	.suspend	= jmicron_suspend,
655659c9bc1SBen Hutchings 	.resume		= jmicron_resume,
656659c9bc1SBen Hutchings };
657659c9bc1SBen Hutchings 
658659c9bc1SBen Hutchings /* SysKonnect CardBus2SDIO extra registers */
659659c9bc1SBen Hutchings #define SYSKT_CTRL		0x200
660659c9bc1SBen Hutchings #define SYSKT_RDFIFO_STAT	0x204
661659c9bc1SBen Hutchings #define SYSKT_WRFIFO_STAT	0x208
662659c9bc1SBen Hutchings #define SYSKT_POWER_DATA	0x20c
663659c9bc1SBen Hutchings #define   SYSKT_POWER_330	0xef
664659c9bc1SBen Hutchings #define   SYSKT_POWER_300	0xf8
665659c9bc1SBen Hutchings #define   SYSKT_POWER_184	0xcc
666659c9bc1SBen Hutchings #define SYSKT_POWER_CMD		0x20d
667659c9bc1SBen Hutchings #define   SYSKT_POWER_START	(1 << 7)
668659c9bc1SBen Hutchings #define SYSKT_POWER_STATUS	0x20e
669659c9bc1SBen Hutchings #define   SYSKT_POWER_STATUS_OK	(1 << 0)
670659c9bc1SBen Hutchings #define SYSKT_BOARD_REV		0x210
671659c9bc1SBen Hutchings #define SYSKT_CHIP_REV		0x211
672659c9bc1SBen Hutchings #define SYSKT_CONF_DATA		0x212
673659c9bc1SBen Hutchings #define   SYSKT_CONF_DATA_1V8	(1 << 2)
674659c9bc1SBen Hutchings #define   SYSKT_CONF_DATA_2V5	(1 << 1)
675659c9bc1SBen Hutchings #define   SYSKT_CONF_DATA_3V3	(1 << 0)
676659c9bc1SBen Hutchings 
677659c9bc1SBen Hutchings static int syskt_probe(struct sdhci_pci_chip *chip)
678659c9bc1SBen Hutchings {
679659c9bc1SBen Hutchings 	if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
680659c9bc1SBen Hutchings 		chip->pdev->class &= ~0x0000FF;
681659c9bc1SBen Hutchings 		chip->pdev->class |= PCI_SDHCI_IFDMA;
682659c9bc1SBen Hutchings 	}
683659c9bc1SBen Hutchings 	return 0;
684659c9bc1SBen Hutchings }
685659c9bc1SBen Hutchings 
686659c9bc1SBen Hutchings static int syskt_probe_slot(struct sdhci_pci_slot *slot)
687659c9bc1SBen Hutchings {
688659c9bc1SBen Hutchings 	int tm, ps;
689659c9bc1SBen Hutchings 
690659c9bc1SBen Hutchings 	u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
691659c9bc1SBen Hutchings 	u8  chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
692659c9bc1SBen Hutchings 	dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
693659c9bc1SBen Hutchings 					 "board rev %d.%d, chip rev %d.%d\n",
694659c9bc1SBen Hutchings 					 board_rev >> 4, board_rev & 0xf,
695659c9bc1SBen Hutchings 					 chip_rev >> 4,  chip_rev & 0xf);
696659c9bc1SBen Hutchings 	if (chip_rev >= 0x20)
697659c9bc1SBen Hutchings 		slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
698659c9bc1SBen Hutchings 
699659c9bc1SBen Hutchings 	writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
700659c9bc1SBen Hutchings 	writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
701659c9bc1SBen Hutchings 	udelay(50);
702659c9bc1SBen Hutchings 	tm = 10;  /* Wait max 1 ms */
703659c9bc1SBen Hutchings 	do {
704659c9bc1SBen Hutchings 		ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
705659c9bc1SBen Hutchings 		if (ps & SYSKT_POWER_STATUS_OK)
706659c9bc1SBen Hutchings 			break;
707659c9bc1SBen Hutchings 		udelay(100);
708659c9bc1SBen Hutchings 	} while (--tm);
709659c9bc1SBen Hutchings 	if (!tm) {
710659c9bc1SBen Hutchings 		dev_err(&slot->chip->pdev->dev,
711659c9bc1SBen Hutchings 			"power regulator never stabilized");
712659c9bc1SBen Hutchings 		writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
713659c9bc1SBen Hutchings 		return -ENODEV;
714659c9bc1SBen Hutchings 	}
715659c9bc1SBen Hutchings 
716659c9bc1SBen Hutchings 	return 0;
717659c9bc1SBen Hutchings }
718659c9bc1SBen Hutchings 
719659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_syskt = {
720659c9bc1SBen Hutchings 	.quirks		= SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
721659c9bc1SBen Hutchings 	.probe		= syskt_probe,
722659c9bc1SBen Hutchings 	.probe_slot	= syskt_probe_slot,
723659c9bc1SBen Hutchings };
724659c9bc1SBen Hutchings 
725659c9bc1SBen Hutchings static int via_probe(struct sdhci_pci_chip *chip)
726659c9bc1SBen Hutchings {
727659c9bc1SBen Hutchings 	if (chip->pdev->revision == 0x10)
728659c9bc1SBen Hutchings 		chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
729659c9bc1SBen Hutchings 
730659c9bc1SBen Hutchings 	return 0;
731659c9bc1SBen Hutchings }
732659c9bc1SBen Hutchings 
733659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_via = {
734659c9bc1SBen Hutchings 	.probe		= via_probe,
735659c9bc1SBen Hutchings };
736659c9bc1SBen Hutchings 
737659c9bc1SBen Hutchings static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
738659c9bc1SBen Hutchings {
739659c9bc1SBen Hutchings 	slot->host->mmc->caps2 |= MMC_CAP2_HS200;
740659c9bc1SBen Hutchings 	return 0;
741659c9bc1SBen Hutchings }
742659c9bc1SBen Hutchings 
743659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_rtsx = {
744659c9bc1SBen Hutchings 	.quirks2	= SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
745659c9bc1SBen Hutchings 			SDHCI_QUIRK2_BROKEN_64_BIT_DMA |
746659c9bc1SBen Hutchings 			SDHCI_QUIRK2_BROKEN_DDR50,
747659c9bc1SBen Hutchings 	.probe_slot	= rtsx_probe_slot,
748659c9bc1SBen Hutchings };
749659c9bc1SBen Hutchings 
750659c9bc1SBen Hutchings /*AMD chipset generation*/
751659c9bc1SBen Hutchings enum amd_chipset_gen {
752659c9bc1SBen Hutchings 	AMD_CHIPSET_BEFORE_ML,
753659c9bc1SBen Hutchings 	AMD_CHIPSET_CZ,
754659c9bc1SBen Hutchings 	AMD_CHIPSET_NL,
755659c9bc1SBen Hutchings 	AMD_CHIPSET_UNKNOWN,
756659c9bc1SBen Hutchings };
757659c9bc1SBen Hutchings 
758659c9bc1SBen Hutchings static int amd_probe(struct sdhci_pci_chip *chip)
759659c9bc1SBen Hutchings {
760659c9bc1SBen Hutchings 	struct pci_dev	*smbus_dev;
761659c9bc1SBen Hutchings 	enum amd_chipset_gen gen;
762659c9bc1SBen Hutchings 
763659c9bc1SBen Hutchings 	smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
764659c9bc1SBen Hutchings 			PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
765659c9bc1SBen Hutchings 	if (smbus_dev) {
766659c9bc1SBen Hutchings 		gen = AMD_CHIPSET_BEFORE_ML;
767659c9bc1SBen Hutchings 	} else {
768659c9bc1SBen Hutchings 		smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
769659c9bc1SBen Hutchings 				PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, NULL);
770659c9bc1SBen Hutchings 		if (smbus_dev) {
771659c9bc1SBen Hutchings 			if (smbus_dev->revision < 0x51)
772659c9bc1SBen Hutchings 				gen = AMD_CHIPSET_CZ;
773659c9bc1SBen Hutchings 			else
774659c9bc1SBen Hutchings 				gen = AMD_CHIPSET_NL;
775659c9bc1SBen Hutchings 		} else {
776659c9bc1SBen Hutchings 			gen = AMD_CHIPSET_UNKNOWN;
777659c9bc1SBen Hutchings 		}
778659c9bc1SBen Hutchings 	}
779659c9bc1SBen Hutchings 
780659c9bc1SBen Hutchings 	if ((gen == AMD_CHIPSET_BEFORE_ML) || (gen == AMD_CHIPSET_CZ)) {
781659c9bc1SBen Hutchings 		chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD;
782659c9bc1SBen Hutchings 		chip->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
783659c9bc1SBen Hutchings 	}
784659c9bc1SBen Hutchings 
785659c9bc1SBen Hutchings 	return 0;
786659c9bc1SBen Hutchings }
787659c9bc1SBen Hutchings 
788659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_amd = {
789659c9bc1SBen Hutchings 	.probe		= amd_probe,
790659c9bc1SBen Hutchings };
791659c9bc1SBen Hutchings 
792659c9bc1SBen Hutchings static const struct pci_device_id pci_ids[] = {
793659c9bc1SBen Hutchings 	{
794659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_RICOH,
795659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_RICOH_R5C822,
796659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
797659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
798659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_ricoh,
799659c9bc1SBen Hutchings 	},
800659c9bc1SBen Hutchings 
801659c9bc1SBen Hutchings 	{
802659c9bc1SBen Hutchings 		.vendor         = PCI_VENDOR_ID_RICOH,
803659c9bc1SBen Hutchings 		.device         = 0x843,
804659c9bc1SBen Hutchings 		.subvendor      = PCI_ANY_ID,
805659c9bc1SBen Hutchings 		.subdevice      = PCI_ANY_ID,
806659c9bc1SBen Hutchings 		.driver_data    = (kernel_ulong_t)&sdhci_ricoh_mmc,
807659c9bc1SBen Hutchings 	},
808659c9bc1SBen Hutchings 
809659c9bc1SBen Hutchings 	{
810659c9bc1SBen Hutchings 		.vendor         = PCI_VENDOR_ID_RICOH,
811659c9bc1SBen Hutchings 		.device         = 0xe822,
812659c9bc1SBen Hutchings 		.subvendor      = PCI_ANY_ID,
813659c9bc1SBen Hutchings 		.subdevice      = PCI_ANY_ID,
814659c9bc1SBen Hutchings 		.driver_data    = (kernel_ulong_t)&sdhci_ricoh_mmc,
815659c9bc1SBen Hutchings 	},
816659c9bc1SBen Hutchings 
817659c9bc1SBen Hutchings 	{
818659c9bc1SBen Hutchings 		.vendor         = PCI_VENDOR_ID_RICOH,
819659c9bc1SBen Hutchings 		.device         = 0xe823,
820659c9bc1SBen Hutchings 		.subvendor      = PCI_ANY_ID,
821659c9bc1SBen Hutchings 		.subdevice      = PCI_ANY_ID,
822659c9bc1SBen Hutchings 		.driver_data    = (kernel_ulong_t)&sdhci_ricoh_mmc,
823659c9bc1SBen Hutchings 	},
824659c9bc1SBen Hutchings 
825659c9bc1SBen Hutchings 	{
826659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_ENE,
827659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_ENE_CB712_SD,
828659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
829659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
830659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_ene_712,
831659c9bc1SBen Hutchings 	},
832659c9bc1SBen Hutchings 
833659c9bc1SBen Hutchings 	{
834659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_ENE,
835659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_ENE_CB712_SD_2,
836659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
837659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
838659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_ene_712,
839659c9bc1SBen Hutchings 	},
840659c9bc1SBen Hutchings 
841659c9bc1SBen Hutchings 	{
842659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_ENE,
843659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_ENE_CB714_SD,
844659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
845659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
846659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_ene_714,
847659c9bc1SBen Hutchings 	},
848659c9bc1SBen Hutchings 
849659c9bc1SBen Hutchings 	{
850659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_ENE,
851659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_ENE_CB714_SD_2,
852659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
853659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
854659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_ene_714,
855659c9bc1SBen Hutchings 	},
856659c9bc1SBen Hutchings 
857659c9bc1SBen Hutchings 	{
858659c9bc1SBen Hutchings 		.vendor         = PCI_VENDOR_ID_MARVELL,
859659c9bc1SBen Hutchings 		.device         = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
860659c9bc1SBen Hutchings 		.subvendor      = PCI_ANY_ID,
861659c9bc1SBen Hutchings 		.subdevice      = PCI_ANY_ID,
862659c9bc1SBen Hutchings 		.driver_data    = (kernel_ulong_t)&sdhci_cafe,
863659c9bc1SBen Hutchings 	},
864659c9bc1SBen Hutchings 
865659c9bc1SBen Hutchings 	{
866659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_JMICRON,
867659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_JMICRON_JMB38X_SD,
868659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
869659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
870659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_jmicron,
871659c9bc1SBen Hutchings 	},
872659c9bc1SBen Hutchings 
873659c9bc1SBen Hutchings 	{
874659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_JMICRON,
875659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
876659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
877659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
878659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_jmicron,
879659c9bc1SBen Hutchings 	},
880659c9bc1SBen Hutchings 
881659c9bc1SBen Hutchings 	{
882659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_JMICRON,
883659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_JMICRON_JMB388_SD,
884659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
885659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
886659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_jmicron,
887659c9bc1SBen Hutchings 	},
888659c9bc1SBen Hutchings 
889659c9bc1SBen Hutchings 	{
890659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_JMICRON,
891659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_JMICRON_JMB388_ESD,
892659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
893659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
894659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_jmicron,
895659c9bc1SBen Hutchings 	},
896659c9bc1SBen Hutchings 
897659c9bc1SBen Hutchings 	{
898659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_SYSKONNECT,
899659c9bc1SBen Hutchings 		.device		= 0x8000,
900659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
901659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
902659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_syskt,
903659c9bc1SBen Hutchings 	},
904659c9bc1SBen Hutchings 
905659c9bc1SBen Hutchings 	{
906659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_VIA,
907659c9bc1SBen Hutchings 		.device		= 0x95d0,
908659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
909659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
910659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_via,
911659c9bc1SBen Hutchings 	},
912659c9bc1SBen Hutchings 
913659c9bc1SBen Hutchings 	{
914659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_REALTEK,
915659c9bc1SBen Hutchings 		.device		= 0x5250,
916659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
917659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
918659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_rtsx,
919659c9bc1SBen Hutchings 	},
920659c9bc1SBen Hutchings 
921659c9bc1SBen Hutchings 	{
922659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
923659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_QRK_SD,
924659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
925659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
926659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_qrk,
927659c9bc1SBen Hutchings 	},
928659c9bc1SBen Hutchings 
929659c9bc1SBen Hutchings 	{
930659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
931659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MRST_SD0,
932659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
933659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
934659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mrst_hc0,
935659c9bc1SBen Hutchings 	},
936659c9bc1SBen Hutchings 
937659c9bc1SBen Hutchings 	{
938659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
939659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MRST_SD1,
940659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
941659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
942659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
943659c9bc1SBen Hutchings 	},
944659c9bc1SBen Hutchings 
945659c9bc1SBen Hutchings 	{
946659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
947659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MRST_SD2,
948659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
949659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
950659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
951659c9bc1SBen Hutchings 	},
952659c9bc1SBen Hutchings 
953659c9bc1SBen Hutchings 	{
954659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
955659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MFD_SD,
956659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
957659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
958659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_sd,
959659c9bc1SBen Hutchings 	},
960659c9bc1SBen Hutchings 
961659c9bc1SBen Hutchings 	{
962659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
963659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MFD_SDIO1,
964659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
965659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
966659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_sdio,
967659c9bc1SBen Hutchings 	},
968659c9bc1SBen Hutchings 
969659c9bc1SBen Hutchings 	{
970659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
971659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MFD_SDIO2,
972659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
973659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
974659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_sdio,
975659c9bc1SBen Hutchings 	},
976659c9bc1SBen Hutchings 
977659c9bc1SBen Hutchings 	{
978659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
979659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MFD_EMMC0,
980659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
981659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
982659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_emmc,
983659c9bc1SBen Hutchings 	},
984659c9bc1SBen Hutchings 
985659c9bc1SBen Hutchings 	{
986659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
987659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_MFD_EMMC1,
988659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
989659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
990659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_emmc,
991659c9bc1SBen Hutchings 	},
992659c9bc1SBen Hutchings 
993659c9bc1SBen Hutchings 	{
994659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
995659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_PCH_SDIO0,
996659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
997659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
998659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_pch_sdio,
999659c9bc1SBen Hutchings 	},
1000659c9bc1SBen Hutchings 
1001659c9bc1SBen Hutchings 	{
1002659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1003659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_PCH_SDIO1,
1004659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1005659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1006659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_pch_sdio,
1007659c9bc1SBen Hutchings 	},
1008659c9bc1SBen Hutchings 
1009659c9bc1SBen Hutchings 	{
1010659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1011659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_BYT_EMMC,
1012659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1013659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1014659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
1015659c9bc1SBen Hutchings 	},
1016659c9bc1SBen Hutchings 
1017659c9bc1SBen Hutchings 	{
1018659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1019659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_BYT_SDIO,
1020659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1021659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1022659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sdio,
1023659c9bc1SBen Hutchings 	},
1024659c9bc1SBen Hutchings 
1025659c9bc1SBen Hutchings 	{
1026659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1027659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_BYT_SD,
1028659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1029659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1030659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sd,
1031659c9bc1SBen Hutchings 	},
1032659c9bc1SBen Hutchings 
1033659c9bc1SBen Hutchings 	{
1034659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1035659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_BYT_EMMC2,
1036659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1037659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1038659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
1039659c9bc1SBen Hutchings 	},
1040659c9bc1SBen Hutchings 
1041659c9bc1SBen Hutchings 	{
1042659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1043659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_BSW_EMMC,
1044659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1045659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1046659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
1047659c9bc1SBen Hutchings 	},
1048659c9bc1SBen Hutchings 
1049659c9bc1SBen Hutchings 	{
1050659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1051659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_BSW_SDIO,
1052659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1053659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1054659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sdio,
1055659c9bc1SBen Hutchings 	},
1056659c9bc1SBen Hutchings 
1057659c9bc1SBen Hutchings 	{
1058659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1059659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_BSW_SD,
1060659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1061659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1062659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sd,
1063659c9bc1SBen Hutchings 	},
1064659c9bc1SBen Hutchings 
1065659c9bc1SBen Hutchings 	{
1066659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1067659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_CLV_SDIO0,
1068659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1069659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1070659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_sd,
1071659c9bc1SBen Hutchings 	},
1072659c9bc1SBen Hutchings 
1073659c9bc1SBen Hutchings 	{
1074659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1075659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_CLV_SDIO1,
1076659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1077659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1078659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_sdio,
1079659c9bc1SBen Hutchings 	},
1080659c9bc1SBen Hutchings 
1081659c9bc1SBen Hutchings 	{
1082659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1083659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_CLV_SDIO2,
1084659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1085659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1086659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_sdio,
1087659c9bc1SBen Hutchings 	},
1088659c9bc1SBen Hutchings 
1089659c9bc1SBen Hutchings 	{
1090659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1091659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_CLV_EMMC0,
1092659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1093659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1094659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1095659c9bc1SBen Hutchings 	},
1096659c9bc1SBen Hutchings 
1097659c9bc1SBen Hutchings 	{
1098659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1099659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_CLV_EMMC1,
1100659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1101659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1102659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mfd_emmc,
1103659c9bc1SBen Hutchings 	},
1104659c9bc1SBen Hutchings 
1105659c9bc1SBen Hutchings 	{
1106659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
11071f64cec2SAndy Shevchenko 		.device		= PCI_DEVICE_ID_INTEL_MRFLD_MMC,
1108659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1109659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
11101f64cec2SAndy Shevchenko 		.driver_data	= (kernel_ulong_t)&sdhci_intel_mrfld_mmc,
1111659c9bc1SBen Hutchings 	},
1112659c9bc1SBen Hutchings 
1113659c9bc1SBen Hutchings 	{
1114659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1115659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_SPT_EMMC,
1116659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1117659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1118659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
1119659c9bc1SBen Hutchings 	},
1120659c9bc1SBen Hutchings 
1121659c9bc1SBen Hutchings 	{
1122659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1123659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_SPT_SDIO,
1124659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1125659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1126659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sdio,
1127659c9bc1SBen Hutchings 	},
1128659c9bc1SBen Hutchings 
1129659c9bc1SBen Hutchings 	{
1130659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_INTEL,
1131659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_INTEL_SPT_SD,
1132659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1133659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1134659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sd,
1135659c9bc1SBen Hutchings 	},
1136659c9bc1SBen Hutchings 
1137659c9bc1SBen Hutchings 	{
113806bf9c56SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
113906bf9c56SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_DNV_EMMC,
114006bf9c56SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
114106bf9c56SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
114206bf9c56SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
114306bf9c56SAdrian Hunter 	},
114406bf9c56SAdrian Hunter 
114506bf9c56SAdrian Hunter 	{
11464fd4c065SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
11474fd4c065SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_BXT_EMMC,
11484fd4c065SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
11494fd4c065SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
11504fd4c065SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
11514fd4c065SAdrian Hunter 	},
11524fd4c065SAdrian Hunter 
11534fd4c065SAdrian Hunter 	{
11544fd4c065SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
11554fd4c065SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_BXT_SDIO,
11564fd4c065SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
11574fd4c065SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
11584fd4c065SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sdio,
11594fd4c065SAdrian Hunter 	},
11604fd4c065SAdrian Hunter 
11614fd4c065SAdrian Hunter 	{
11624fd4c065SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
11634fd4c065SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_BXT_SD,
11644fd4c065SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
11654fd4c065SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
11664fd4c065SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sd,
11674fd4c065SAdrian Hunter 	},
11684fd4c065SAdrian Hunter 
11694fd4c065SAdrian Hunter 	{
11704fd4c065SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
117101d6b2a4SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_BXTM_EMMC,
117201d6b2a4SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
117301d6b2a4SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
117401d6b2a4SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
117501d6b2a4SAdrian Hunter 	},
117601d6b2a4SAdrian Hunter 
117701d6b2a4SAdrian Hunter 	{
117801d6b2a4SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
117901d6b2a4SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_BXTM_SDIO,
118001d6b2a4SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
118101d6b2a4SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
118201d6b2a4SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sdio,
118301d6b2a4SAdrian Hunter 	},
118401d6b2a4SAdrian Hunter 
118501d6b2a4SAdrian Hunter 	{
118601d6b2a4SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
118701d6b2a4SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_BXTM_SD,
118801d6b2a4SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
118901d6b2a4SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
119001d6b2a4SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sd,
119101d6b2a4SAdrian Hunter 	},
119201d6b2a4SAdrian Hunter 
119301d6b2a4SAdrian Hunter 	{
119401d6b2a4SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
11954fd4c065SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_APL_EMMC,
11964fd4c065SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
11974fd4c065SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
11984fd4c065SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_emmc,
11994fd4c065SAdrian Hunter 	},
12004fd4c065SAdrian Hunter 
12014fd4c065SAdrian Hunter 	{
12024fd4c065SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
12034fd4c065SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_APL_SDIO,
12044fd4c065SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
12054fd4c065SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
12064fd4c065SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sdio,
12074fd4c065SAdrian Hunter 	},
12084fd4c065SAdrian Hunter 
12094fd4c065SAdrian Hunter 	{
12104fd4c065SAdrian Hunter 		.vendor		= PCI_VENDOR_ID_INTEL,
12114fd4c065SAdrian Hunter 		.device		= PCI_DEVICE_ID_INTEL_APL_SD,
12124fd4c065SAdrian Hunter 		.subvendor	= PCI_ANY_ID,
12134fd4c065SAdrian Hunter 		.subdevice	= PCI_ANY_ID,
12144fd4c065SAdrian Hunter 		.driver_data	= (kernel_ulong_t)&sdhci_intel_byt_sd,
12154fd4c065SAdrian Hunter 	},
12164fd4c065SAdrian Hunter 
12174fd4c065SAdrian Hunter 	{
1218659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1219659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_8120,
1220659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1221659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1222659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1223659c9bc1SBen Hutchings 	},
1224659c9bc1SBen Hutchings 
1225659c9bc1SBen Hutchings 	{
1226659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1227659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_8220,
1228659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1229659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1230659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1231659c9bc1SBen Hutchings 	},
1232659c9bc1SBen Hutchings 
1233659c9bc1SBen Hutchings 	{
1234659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1235659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_8221,
1236659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1237659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1238659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1239659c9bc1SBen Hutchings 	},
1240659c9bc1SBen Hutchings 
1241659c9bc1SBen Hutchings 	{
1242659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1243659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_8320,
1244659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1245659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1246659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1247659c9bc1SBen Hutchings 	},
1248659c9bc1SBen Hutchings 
1249659c9bc1SBen Hutchings 	{
1250659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1251659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_8321,
1252659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1253659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1254659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1255659c9bc1SBen Hutchings 	},
1256659c9bc1SBen Hutchings 
1257659c9bc1SBen Hutchings 	{
1258659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1259659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_FUJIN2,
1260659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1261659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1262659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1263659c9bc1SBen Hutchings 	},
1264659c9bc1SBen Hutchings 
1265659c9bc1SBen Hutchings 	{
1266659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1267659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_SDS0,
1268659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1269659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1270659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1271659c9bc1SBen Hutchings 	},
1272659c9bc1SBen Hutchings 
1273659c9bc1SBen Hutchings 	{
1274659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1275659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_SDS1,
1276659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1277659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1278659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1279659c9bc1SBen Hutchings 	},
1280659c9bc1SBen Hutchings 
1281659c9bc1SBen Hutchings 	{
1282659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1283659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_SEABIRD0,
1284659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1285659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1286659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1287659c9bc1SBen Hutchings 	},
1288659c9bc1SBen Hutchings 
1289659c9bc1SBen Hutchings 	{
1290659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_O2,
1291659c9bc1SBen Hutchings 		.device		= PCI_DEVICE_ID_O2_SEABIRD1,
1292659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1293659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1294659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_o2,
1295659c9bc1SBen Hutchings 	},
1296659c9bc1SBen Hutchings 	{
1297659c9bc1SBen Hutchings 		.vendor		= PCI_VENDOR_ID_AMD,
1298659c9bc1SBen Hutchings 		.device		= PCI_ANY_ID,
1299659c9bc1SBen Hutchings 		.class		= PCI_CLASS_SYSTEM_SDHCI << 8,
1300659c9bc1SBen Hutchings 		.class_mask	= 0xFFFF00,
1301659c9bc1SBen Hutchings 		.subvendor	= PCI_ANY_ID,
1302659c9bc1SBen Hutchings 		.subdevice	= PCI_ANY_ID,
1303659c9bc1SBen Hutchings 		.driver_data	= (kernel_ulong_t)&sdhci_amd,
1304659c9bc1SBen Hutchings 	},
1305659c9bc1SBen Hutchings 	{	/* Generic SD host controller */
1306659c9bc1SBen Hutchings 		PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
1307659c9bc1SBen Hutchings 	},
1308659c9bc1SBen Hutchings 
1309659c9bc1SBen Hutchings 	{ /* end: all zeroes */ },
1310659c9bc1SBen Hutchings };
1311659c9bc1SBen Hutchings 
1312659c9bc1SBen Hutchings MODULE_DEVICE_TABLE(pci, pci_ids);
1313659c9bc1SBen Hutchings 
1314659c9bc1SBen Hutchings /*****************************************************************************\
1315659c9bc1SBen Hutchings  *                                                                           *
1316659c9bc1SBen Hutchings  * SDHCI core callbacks                                                      *
1317659c9bc1SBen Hutchings  *                                                                           *
1318659c9bc1SBen Hutchings \*****************************************************************************/
1319659c9bc1SBen Hutchings 
1320659c9bc1SBen Hutchings static int sdhci_pci_enable_dma(struct sdhci_host *host)
1321659c9bc1SBen Hutchings {
1322659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot;
1323659c9bc1SBen Hutchings 	struct pci_dev *pdev;
1324659c9bc1SBen Hutchings 
1325659c9bc1SBen Hutchings 	slot = sdhci_priv(host);
1326659c9bc1SBen Hutchings 	pdev = slot->chip->pdev;
1327659c9bc1SBen Hutchings 
1328659c9bc1SBen Hutchings 	if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
1329659c9bc1SBen Hutchings 		((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
1330659c9bc1SBen Hutchings 		(host->flags & SDHCI_USE_SDMA)) {
1331659c9bc1SBen Hutchings 		dev_warn(&pdev->dev, "Will use DMA mode even though HW "
1332659c9bc1SBen Hutchings 			"doesn't fully claim to support it.\n");
1333659c9bc1SBen Hutchings 	}
1334659c9bc1SBen Hutchings 
1335659c9bc1SBen Hutchings 	pci_set_master(pdev);
1336659c9bc1SBen Hutchings 
1337659c9bc1SBen Hutchings 	return 0;
1338659c9bc1SBen Hutchings }
1339659c9bc1SBen Hutchings 
1340659c9bc1SBen Hutchings static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width)
1341659c9bc1SBen Hutchings {
1342659c9bc1SBen Hutchings 	u8 ctrl;
1343659c9bc1SBen Hutchings 
1344659c9bc1SBen Hutchings 	ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1345659c9bc1SBen Hutchings 
1346659c9bc1SBen Hutchings 	switch (width) {
1347659c9bc1SBen Hutchings 	case MMC_BUS_WIDTH_8:
1348659c9bc1SBen Hutchings 		ctrl |= SDHCI_CTRL_8BITBUS;
1349659c9bc1SBen Hutchings 		ctrl &= ~SDHCI_CTRL_4BITBUS;
1350659c9bc1SBen Hutchings 		break;
1351659c9bc1SBen Hutchings 	case MMC_BUS_WIDTH_4:
1352659c9bc1SBen Hutchings 		ctrl |= SDHCI_CTRL_4BITBUS;
1353659c9bc1SBen Hutchings 		ctrl &= ~SDHCI_CTRL_8BITBUS;
1354659c9bc1SBen Hutchings 		break;
1355659c9bc1SBen Hutchings 	default:
1356659c9bc1SBen Hutchings 		ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
1357659c9bc1SBen Hutchings 		break;
1358659c9bc1SBen Hutchings 	}
1359659c9bc1SBen Hutchings 
1360659c9bc1SBen Hutchings 	sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
1361659c9bc1SBen Hutchings }
1362659c9bc1SBen Hutchings 
1363659c9bc1SBen Hutchings static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
1364659c9bc1SBen Hutchings {
1365659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot = sdhci_priv(host);
1366659c9bc1SBen Hutchings 	int rst_n_gpio = slot->rst_n_gpio;
1367659c9bc1SBen Hutchings 
1368659c9bc1SBen Hutchings 	if (!gpio_is_valid(rst_n_gpio))
1369659c9bc1SBen Hutchings 		return;
1370659c9bc1SBen Hutchings 	gpio_set_value_cansleep(rst_n_gpio, 0);
1371659c9bc1SBen Hutchings 	/* For eMMC, minimum is 1us but give it 10us for good measure */
1372659c9bc1SBen Hutchings 	udelay(10);
1373659c9bc1SBen Hutchings 	gpio_set_value_cansleep(rst_n_gpio, 1);
1374659c9bc1SBen Hutchings 	/* For eMMC, minimum is 200us but give it 300us for good measure */
1375659c9bc1SBen Hutchings 	usleep_range(300, 1000);
1376659c9bc1SBen Hutchings }
1377659c9bc1SBen Hutchings 
1378659c9bc1SBen Hutchings static void sdhci_pci_hw_reset(struct sdhci_host *host)
1379659c9bc1SBen Hutchings {
1380659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot = sdhci_priv(host);
1381659c9bc1SBen Hutchings 
1382659c9bc1SBen Hutchings 	if (slot->hw_reset)
1383659c9bc1SBen Hutchings 		slot->hw_reset(host);
1384659c9bc1SBen Hutchings }
1385659c9bc1SBen Hutchings 
1386659c9bc1SBen Hutchings static int sdhci_pci_select_drive_strength(struct sdhci_host *host,
1387659c9bc1SBen Hutchings 					   struct mmc_card *card,
1388659c9bc1SBen Hutchings 					   unsigned int max_dtr, int host_drv,
1389659c9bc1SBen Hutchings 					   int card_drv, int *drv_type)
1390659c9bc1SBen Hutchings {
1391659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot = sdhci_priv(host);
1392659c9bc1SBen Hutchings 
1393659c9bc1SBen Hutchings 	if (!slot->select_drive_strength)
1394659c9bc1SBen Hutchings 		return 0;
1395659c9bc1SBen Hutchings 
1396659c9bc1SBen Hutchings 	return slot->select_drive_strength(host, card, max_dtr, host_drv,
1397659c9bc1SBen Hutchings 					   card_drv, drv_type);
1398659c9bc1SBen Hutchings }
1399659c9bc1SBen Hutchings 
1400659c9bc1SBen Hutchings static const struct sdhci_ops sdhci_pci_ops = {
1401659c9bc1SBen Hutchings 	.set_clock	= sdhci_set_clock,
1402659c9bc1SBen Hutchings 	.enable_dma	= sdhci_pci_enable_dma,
1403659c9bc1SBen Hutchings 	.set_bus_width	= sdhci_pci_set_bus_width,
1404659c9bc1SBen Hutchings 	.reset		= sdhci_reset,
1405659c9bc1SBen Hutchings 	.set_uhs_signaling = sdhci_set_uhs_signaling,
1406659c9bc1SBen Hutchings 	.hw_reset		= sdhci_pci_hw_reset,
1407659c9bc1SBen Hutchings 	.select_drive_strength	= sdhci_pci_select_drive_strength,
1408659c9bc1SBen Hutchings };
1409659c9bc1SBen Hutchings 
1410659c9bc1SBen Hutchings /*****************************************************************************\
1411659c9bc1SBen Hutchings  *                                                                           *
1412659c9bc1SBen Hutchings  * Suspend/resume                                                            *
1413659c9bc1SBen Hutchings  *                                                                           *
1414659c9bc1SBen Hutchings \*****************************************************************************/
1415659c9bc1SBen Hutchings 
1416*f9900f15SUlf Hansson #ifdef CONFIG_PM_SLEEP
1417659c9bc1SBen Hutchings static int sdhci_pci_suspend(struct device *dev)
1418659c9bc1SBen Hutchings {
1419659c9bc1SBen Hutchings 	struct pci_dev *pdev = to_pci_dev(dev);
1420659c9bc1SBen Hutchings 	struct sdhci_pci_chip *chip;
1421659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot;
1422659c9bc1SBen Hutchings 	mmc_pm_flag_t slot_pm_flags;
1423659c9bc1SBen Hutchings 	mmc_pm_flag_t pm_flags = 0;
1424659c9bc1SBen Hutchings 	int i, ret;
1425659c9bc1SBen Hutchings 
1426659c9bc1SBen Hutchings 	chip = pci_get_drvdata(pdev);
1427659c9bc1SBen Hutchings 	if (!chip)
1428659c9bc1SBen Hutchings 		return 0;
1429659c9bc1SBen Hutchings 
1430659c9bc1SBen Hutchings 	for (i = 0; i < chip->num_slots; i++) {
1431659c9bc1SBen Hutchings 		slot = chip->slots[i];
1432659c9bc1SBen Hutchings 		if (!slot)
1433659c9bc1SBen Hutchings 			continue;
1434659c9bc1SBen Hutchings 
1435659c9bc1SBen Hutchings 		ret = sdhci_suspend_host(slot->host);
1436659c9bc1SBen Hutchings 
1437659c9bc1SBen Hutchings 		if (ret)
1438659c9bc1SBen Hutchings 			goto err_pci_suspend;
1439659c9bc1SBen Hutchings 
1440659c9bc1SBen Hutchings 		slot_pm_flags = slot->host->mmc->pm_flags;
1441659c9bc1SBen Hutchings 		if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1442659c9bc1SBen Hutchings 			sdhci_enable_irq_wakeups(slot->host);
1443659c9bc1SBen Hutchings 
1444659c9bc1SBen Hutchings 		pm_flags |= slot_pm_flags;
1445659c9bc1SBen Hutchings 	}
1446659c9bc1SBen Hutchings 
1447659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->suspend) {
1448659c9bc1SBen Hutchings 		ret = chip->fixes->suspend(chip);
1449659c9bc1SBen Hutchings 		if (ret)
1450659c9bc1SBen Hutchings 			goto err_pci_suspend;
1451659c9bc1SBen Hutchings 	}
1452659c9bc1SBen Hutchings 
1453659c9bc1SBen Hutchings 	if (pm_flags & MMC_PM_KEEP_POWER) {
1454659c9bc1SBen Hutchings 		if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
1455659c9bc1SBen Hutchings 			device_init_wakeup(dev, true);
1456659c9bc1SBen Hutchings 		else
1457659c9bc1SBen Hutchings 			device_init_wakeup(dev, false);
1458659c9bc1SBen Hutchings 	} else
1459659c9bc1SBen Hutchings 		device_init_wakeup(dev, false);
1460659c9bc1SBen Hutchings 
1461659c9bc1SBen Hutchings 	return 0;
1462659c9bc1SBen Hutchings 
1463659c9bc1SBen Hutchings err_pci_suspend:
1464659c9bc1SBen Hutchings 	while (--i >= 0)
1465659c9bc1SBen Hutchings 		sdhci_resume_host(chip->slots[i]->host);
1466659c9bc1SBen Hutchings 	return ret;
1467659c9bc1SBen Hutchings }
1468659c9bc1SBen Hutchings 
1469659c9bc1SBen Hutchings static int sdhci_pci_resume(struct device *dev)
1470659c9bc1SBen Hutchings {
1471659c9bc1SBen Hutchings 	struct pci_dev *pdev = to_pci_dev(dev);
1472659c9bc1SBen Hutchings 	struct sdhci_pci_chip *chip;
1473659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot;
1474659c9bc1SBen Hutchings 	int i, ret;
1475659c9bc1SBen Hutchings 
1476659c9bc1SBen Hutchings 	chip = pci_get_drvdata(pdev);
1477659c9bc1SBen Hutchings 	if (!chip)
1478659c9bc1SBen Hutchings 		return 0;
1479659c9bc1SBen Hutchings 
1480659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->resume) {
1481659c9bc1SBen Hutchings 		ret = chip->fixes->resume(chip);
1482659c9bc1SBen Hutchings 		if (ret)
1483659c9bc1SBen Hutchings 			return ret;
1484659c9bc1SBen Hutchings 	}
1485659c9bc1SBen Hutchings 
1486659c9bc1SBen Hutchings 	for (i = 0; i < chip->num_slots; i++) {
1487659c9bc1SBen Hutchings 		slot = chip->slots[i];
1488659c9bc1SBen Hutchings 		if (!slot)
1489659c9bc1SBen Hutchings 			continue;
1490659c9bc1SBen Hutchings 
1491659c9bc1SBen Hutchings 		ret = sdhci_resume_host(slot->host);
1492659c9bc1SBen Hutchings 		if (ret)
1493659c9bc1SBen Hutchings 			return ret;
1494659c9bc1SBen Hutchings 	}
1495659c9bc1SBen Hutchings 
1496659c9bc1SBen Hutchings 	return 0;
1497659c9bc1SBen Hutchings }
1498*f9900f15SUlf Hansson #endif
1499659c9bc1SBen Hutchings 
1500*f9900f15SUlf Hansson #ifdef CONFIG_PM
1501659c9bc1SBen Hutchings static int sdhci_pci_runtime_suspend(struct device *dev)
1502659c9bc1SBen Hutchings {
1503923a231cSGeliang Tang 	struct pci_dev *pdev = to_pci_dev(dev);
1504659c9bc1SBen Hutchings 	struct sdhci_pci_chip *chip;
1505659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot;
1506659c9bc1SBen Hutchings 	int i, ret;
1507659c9bc1SBen Hutchings 
1508659c9bc1SBen Hutchings 	chip = pci_get_drvdata(pdev);
1509659c9bc1SBen Hutchings 	if (!chip)
1510659c9bc1SBen Hutchings 		return 0;
1511659c9bc1SBen Hutchings 
1512659c9bc1SBen Hutchings 	for (i = 0; i < chip->num_slots; i++) {
1513659c9bc1SBen Hutchings 		slot = chip->slots[i];
1514659c9bc1SBen Hutchings 		if (!slot)
1515659c9bc1SBen Hutchings 			continue;
1516659c9bc1SBen Hutchings 
1517659c9bc1SBen Hutchings 		ret = sdhci_runtime_suspend_host(slot->host);
1518659c9bc1SBen Hutchings 
1519659c9bc1SBen Hutchings 		if (ret)
1520659c9bc1SBen Hutchings 			goto err_pci_runtime_suspend;
1521659c9bc1SBen Hutchings 	}
1522659c9bc1SBen Hutchings 
1523659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->suspend) {
1524659c9bc1SBen Hutchings 		ret = chip->fixes->suspend(chip);
1525659c9bc1SBen Hutchings 		if (ret)
1526659c9bc1SBen Hutchings 			goto err_pci_runtime_suspend;
1527659c9bc1SBen Hutchings 	}
1528659c9bc1SBen Hutchings 
1529659c9bc1SBen Hutchings 	return 0;
1530659c9bc1SBen Hutchings 
1531659c9bc1SBen Hutchings err_pci_runtime_suspend:
1532659c9bc1SBen Hutchings 	while (--i >= 0)
1533659c9bc1SBen Hutchings 		sdhci_runtime_resume_host(chip->slots[i]->host);
1534659c9bc1SBen Hutchings 	return ret;
1535659c9bc1SBen Hutchings }
1536659c9bc1SBen Hutchings 
1537659c9bc1SBen Hutchings static int sdhci_pci_runtime_resume(struct device *dev)
1538659c9bc1SBen Hutchings {
1539923a231cSGeliang Tang 	struct pci_dev *pdev = to_pci_dev(dev);
1540659c9bc1SBen Hutchings 	struct sdhci_pci_chip *chip;
1541659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot;
1542659c9bc1SBen Hutchings 	int i, ret;
1543659c9bc1SBen Hutchings 
1544659c9bc1SBen Hutchings 	chip = pci_get_drvdata(pdev);
1545659c9bc1SBen Hutchings 	if (!chip)
1546659c9bc1SBen Hutchings 		return 0;
1547659c9bc1SBen Hutchings 
1548659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->resume) {
1549659c9bc1SBen Hutchings 		ret = chip->fixes->resume(chip);
1550659c9bc1SBen Hutchings 		if (ret)
1551659c9bc1SBen Hutchings 			return ret;
1552659c9bc1SBen Hutchings 	}
1553659c9bc1SBen Hutchings 
1554659c9bc1SBen Hutchings 	for (i = 0; i < chip->num_slots; i++) {
1555659c9bc1SBen Hutchings 		slot = chip->slots[i];
1556659c9bc1SBen Hutchings 		if (!slot)
1557659c9bc1SBen Hutchings 			continue;
1558659c9bc1SBen Hutchings 
1559659c9bc1SBen Hutchings 		ret = sdhci_runtime_resume_host(slot->host);
1560659c9bc1SBen Hutchings 		if (ret)
1561659c9bc1SBen Hutchings 			return ret;
1562659c9bc1SBen Hutchings 	}
1563659c9bc1SBen Hutchings 
1564659c9bc1SBen Hutchings 	return 0;
1565659c9bc1SBen Hutchings }
1566*f9900f15SUlf Hansson #endif
1567659c9bc1SBen Hutchings 
1568659c9bc1SBen Hutchings static const struct dev_pm_ops sdhci_pci_pm_ops = {
1569*f9900f15SUlf Hansson 	SET_SYSTEM_SLEEP_PM_OPS(sdhci_pci_suspend, sdhci_pci_resume)
1570659c9bc1SBen Hutchings 	SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend,
1571659c9bc1SBen Hutchings 			sdhci_pci_runtime_resume, NULL)
1572659c9bc1SBen Hutchings };
1573659c9bc1SBen Hutchings 
1574659c9bc1SBen Hutchings /*****************************************************************************\
1575659c9bc1SBen Hutchings  *                                                                           *
1576659c9bc1SBen Hutchings  * Device probing/removal                                                    *
1577659c9bc1SBen Hutchings  *                                                                           *
1578659c9bc1SBen Hutchings \*****************************************************************************/
1579659c9bc1SBen Hutchings 
1580659c9bc1SBen Hutchings static struct sdhci_pci_slot *sdhci_pci_probe_slot(
1581659c9bc1SBen Hutchings 	struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
1582659c9bc1SBen Hutchings 	int slotno)
1583659c9bc1SBen Hutchings {
1584659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot;
1585659c9bc1SBen Hutchings 	struct sdhci_host *host;
1586659c9bc1SBen Hutchings 	int ret, bar = first_bar + slotno;
1587659c9bc1SBen Hutchings 
1588659c9bc1SBen Hutchings 	if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
1589659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
1590659c9bc1SBen Hutchings 		return ERR_PTR(-ENODEV);
1591659c9bc1SBen Hutchings 	}
1592659c9bc1SBen Hutchings 
1593659c9bc1SBen Hutchings 	if (pci_resource_len(pdev, bar) < 0x100) {
1594659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "Invalid iomem size. You may "
1595659c9bc1SBen Hutchings 			"experience problems.\n");
1596659c9bc1SBen Hutchings 	}
1597659c9bc1SBen Hutchings 
1598659c9bc1SBen Hutchings 	if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
1599659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
1600659c9bc1SBen Hutchings 		return ERR_PTR(-ENODEV);
1601659c9bc1SBen Hutchings 	}
1602659c9bc1SBen Hutchings 
1603659c9bc1SBen Hutchings 	if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
1604659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
1605659c9bc1SBen Hutchings 		return ERR_PTR(-ENODEV);
1606659c9bc1SBen Hutchings 	}
1607659c9bc1SBen Hutchings 
1608659c9bc1SBen Hutchings 	host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
1609659c9bc1SBen Hutchings 	if (IS_ERR(host)) {
1610659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "cannot allocate host\n");
1611659c9bc1SBen Hutchings 		return ERR_CAST(host);
1612659c9bc1SBen Hutchings 	}
1613659c9bc1SBen Hutchings 
1614659c9bc1SBen Hutchings 	slot = sdhci_priv(host);
1615659c9bc1SBen Hutchings 
1616659c9bc1SBen Hutchings 	slot->chip = chip;
1617659c9bc1SBen Hutchings 	slot->host = host;
1618659c9bc1SBen Hutchings 	slot->pci_bar = bar;
1619659c9bc1SBen Hutchings 	slot->rst_n_gpio = -EINVAL;
1620659c9bc1SBen Hutchings 	slot->cd_gpio = -EINVAL;
1621659c9bc1SBen Hutchings 	slot->cd_idx = -1;
1622659c9bc1SBen Hutchings 
1623659c9bc1SBen Hutchings 	/* Retrieve platform data if there is any */
1624659c9bc1SBen Hutchings 	if (*sdhci_pci_get_data)
1625659c9bc1SBen Hutchings 		slot->data = sdhci_pci_get_data(pdev, slotno);
1626659c9bc1SBen Hutchings 
1627659c9bc1SBen Hutchings 	if (slot->data) {
1628659c9bc1SBen Hutchings 		if (slot->data->setup) {
1629659c9bc1SBen Hutchings 			ret = slot->data->setup(slot->data);
1630659c9bc1SBen Hutchings 			if (ret) {
1631659c9bc1SBen Hutchings 				dev_err(&pdev->dev, "platform setup failed\n");
1632659c9bc1SBen Hutchings 				goto free;
1633659c9bc1SBen Hutchings 			}
1634659c9bc1SBen Hutchings 		}
1635659c9bc1SBen Hutchings 		slot->rst_n_gpio = slot->data->rst_n_gpio;
1636659c9bc1SBen Hutchings 		slot->cd_gpio = slot->data->cd_gpio;
1637659c9bc1SBen Hutchings 	}
1638659c9bc1SBen Hutchings 
1639659c9bc1SBen Hutchings 	host->hw_name = "PCI";
1640659c9bc1SBen Hutchings 	host->ops = &sdhci_pci_ops;
1641659c9bc1SBen Hutchings 	host->quirks = chip->quirks;
1642659c9bc1SBen Hutchings 	host->quirks2 = chip->quirks2;
1643659c9bc1SBen Hutchings 
1644659c9bc1SBen Hutchings 	host->irq = pdev->irq;
1645659c9bc1SBen Hutchings 
1646659c9bc1SBen Hutchings 	ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
1647659c9bc1SBen Hutchings 	if (ret) {
1648659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "cannot request region\n");
1649659c9bc1SBen Hutchings 		goto cleanup;
1650659c9bc1SBen Hutchings 	}
1651659c9bc1SBen Hutchings 
1652659c9bc1SBen Hutchings 	host->ioaddr = pci_ioremap_bar(pdev, bar);
1653659c9bc1SBen Hutchings 	if (!host->ioaddr) {
1654659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "failed to remap registers\n");
1655659c9bc1SBen Hutchings 		ret = -ENOMEM;
1656659c9bc1SBen Hutchings 		goto release;
1657659c9bc1SBen Hutchings 	}
1658659c9bc1SBen Hutchings 
1659659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->probe_slot) {
1660659c9bc1SBen Hutchings 		ret = chip->fixes->probe_slot(slot);
1661659c9bc1SBen Hutchings 		if (ret)
1662659c9bc1SBen Hutchings 			goto unmap;
1663659c9bc1SBen Hutchings 	}
1664659c9bc1SBen Hutchings 
1665659c9bc1SBen Hutchings 	if (gpio_is_valid(slot->rst_n_gpio)) {
1666659c9bc1SBen Hutchings 		if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
1667659c9bc1SBen Hutchings 			gpio_direction_output(slot->rst_n_gpio, 1);
1668659c9bc1SBen Hutchings 			slot->host->mmc->caps |= MMC_CAP_HW_RESET;
1669659c9bc1SBen Hutchings 			slot->hw_reset = sdhci_pci_gpio_hw_reset;
1670659c9bc1SBen Hutchings 		} else {
1671659c9bc1SBen Hutchings 			dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
1672659c9bc1SBen Hutchings 			slot->rst_n_gpio = -EINVAL;
1673659c9bc1SBen Hutchings 		}
1674659c9bc1SBen Hutchings 	}
1675659c9bc1SBen Hutchings 
1676659c9bc1SBen Hutchings 	host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
1677659c9bc1SBen Hutchings 	host->mmc->slotno = slotno;
1678659c9bc1SBen Hutchings 	host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
1679659c9bc1SBen Hutchings 
1680659c9bc1SBen Hutchings 	if (slot->cd_idx >= 0 &&
1681659c9bc1SBen Hutchings 	    mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx,
1682659c9bc1SBen Hutchings 				 slot->cd_override_level, 0, NULL)) {
1683659c9bc1SBen Hutchings 		dev_warn(&pdev->dev, "failed to setup card detect gpio\n");
1684659c9bc1SBen Hutchings 		slot->cd_idx = -1;
1685659c9bc1SBen Hutchings 	}
1686659c9bc1SBen Hutchings 
1687659c9bc1SBen Hutchings 	ret = sdhci_add_host(host);
1688659c9bc1SBen Hutchings 	if (ret)
1689659c9bc1SBen Hutchings 		goto remove;
1690659c9bc1SBen Hutchings 
1691659c9bc1SBen Hutchings 	sdhci_pci_add_own_cd(slot);
1692659c9bc1SBen Hutchings 
1693659c9bc1SBen Hutchings 	/*
1694659c9bc1SBen Hutchings 	 * Check if the chip needs a separate GPIO for card detect to wake up
1695659c9bc1SBen Hutchings 	 * from runtime suspend.  If it is not there, don't allow runtime PM.
1696659c9bc1SBen Hutchings 	 * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
1697659c9bc1SBen Hutchings 	 */
1698659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->own_cd_for_runtime_pm &&
1699659c9bc1SBen Hutchings 	    !gpio_is_valid(slot->cd_gpio) && slot->cd_idx < 0)
1700659c9bc1SBen Hutchings 		chip->allow_runtime_pm = false;
1701659c9bc1SBen Hutchings 
1702659c9bc1SBen Hutchings 	return slot;
1703659c9bc1SBen Hutchings 
1704659c9bc1SBen Hutchings remove:
1705659c9bc1SBen Hutchings 	if (gpio_is_valid(slot->rst_n_gpio))
1706659c9bc1SBen Hutchings 		gpio_free(slot->rst_n_gpio);
1707659c9bc1SBen Hutchings 
1708659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->remove_slot)
1709659c9bc1SBen Hutchings 		chip->fixes->remove_slot(slot, 0);
1710659c9bc1SBen Hutchings 
1711659c9bc1SBen Hutchings unmap:
1712659c9bc1SBen Hutchings 	iounmap(host->ioaddr);
1713659c9bc1SBen Hutchings 
1714659c9bc1SBen Hutchings release:
1715659c9bc1SBen Hutchings 	pci_release_region(pdev, bar);
1716659c9bc1SBen Hutchings 
1717659c9bc1SBen Hutchings cleanup:
1718659c9bc1SBen Hutchings 	if (slot->data && slot->data->cleanup)
1719659c9bc1SBen Hutchings 		slot->data->cleanup(slot->data);
1720659c9bc1SBen Hutchings 
1721659c9bc1SBen Hutchings free:
1722659c9bc1SBen Hutchings 	sdhci_free_host(host);
1723659c9bc1SBen Hutchings 
1724659c9bc1SBen Hutchings 	return ERR_PTR(ret);
1725659c9bc1SBen Hutchings }
1726659c9bc1SBen Hutchings 
1727659c9bc1SBen Hutchings static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1728659c9bc1SBen Hutchings {
1729659c9bc1SBen Hutchings 	int dead;
1730659c9bc1SBen Hutchings 	u32 scratch;
1731659c9bc1SBen Hutchings 
1732659c9bc1SBen Hutchings 	sdhci_pci_remove_own_cd(slot);
1733659c9bc1SBen Hutchings 
1734659c9bc1SBen Hutchings 	dead = 0;
1735659c9bc1SBen Hutchings 	scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
1736659c9bc1SBen Hutchings 	if (scratch == (u32)-1)
1737659c9bc1SBen Hutchings 		dead = 1;
1738659c9bc1SBen Hutchings 
1739659c9bc1SBen Hutchings 	sdhci_remove_host(slot->host, dead);
1740659c9bc1SBen Hutchings 
1741659c9bc1SBen Hutchings 	if (gpio_is_valid(slot->rst_n_gpio))
1742659c9bc1SBen Hutchings 		gpio_free(slot->rst_n_gpio);
1743659c9bc1SBen Hutchings 
1744659c9bc1SBen Hutchings 	if (slot->chip->fixes && slot->chip->fixes->remove_slot)
1745659c9bc1SBen Hutchings 		slot->chip->fixes->remove_slot(slot, dead);
1746659c9bc1SBen Hutchings 
1747659c9bc1SBen Hutchings 	if (slot->data && slot->data->cleanup)
1748659c9bc1SBen Hutchings 		slot->data->cleanup(slot->data);
1749659c9bc1SBen Hutchings 
1750659c9bc1SBen Hutchings 	pci_release_region(slot->chip->pdev, slot->pci_bar);
1751659c9bc1SBen Hutchings 
1752659c9bc1SBen Hutchings 	sdhci_free_host(slot->host);
1753659c9bc1SBen Hutchings }
1754659c9bc1SBen Hutchings 
1755659c9bc1SBen Hutchings static void sdhci_pci_runtime_pm_allow(struct device *dev)
1756659c9bc1SBen Hutchings {
175700884b61SAdrian Hunter 	pm_suspend_ignore_children(dev, 1);
1758659c9bc1SBen Hutchings 	pm_runtime_set_autosuspend_delay(dev, 50);
1759659c9bc1SBen Hutchings 	pm_runtime_use_autosuspend(dev);
176000884b61SAdrian Hunter 	pm_runtime_allow(dev);
176100884b61SAdrian Hunter 	/* Stay active until mmc core scans for a card */
176200884b61SAdrian Hunter 	pm_runtime_put_noidle(dev);
1763659c9bc1SBen Hutchings }
1764659c9bc1SBen Hutchings 
1765659c9bc1SBen Hutchings static void sdhci_pci_runtime_pm_forbid(struct device *dev)
1766659c9bc1SBen Hutchings {
1767659c9bc1SBen Hutchings 	pm_runtime_forbid(dev);
1768659c9bc1SBen Hutchings 	pm_runtime_get_noresume(dev);
1769659c9bc1SBen Hutchings }
1770659c9bc1SBen Hutchings 
1771659c9bc1SBen Hutchings static int sdhci_pci_probe(struct pci_dev *pdev,
1772659c9bc1SBen Hutchings 				     const struct pci_device_id *ent)
1773659c9bc1SBen Hutchings {
1774659c9bc1SBen Hutchings 	struct sdhci_pci_chip *chip;
1775659c9bc1SBen Hutchings 	struct sdhci_pci_slot *slot;
1776659c9bc1SBen Hutchings 
1777659c9bc1SBen Hutchings 	u8 slots, first_bar;
1778659c9bc1SBen Hutchings 	int ret, i;
1779659c9bc1SBen Hutchings 
1780659c9bc1SBen Hutchings 	BUG_ON(pdev == NULL);
1781659c9bc1SBen Hutchings 	BUG_ON(ent == NULL);
1782659c9bc1SBen Hutchings 
1783659c9bc1SBen Hutchings 	dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
1784659c9bc1SBen Hutchings 		 (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
1785659c9bc1SBen Hutchings 
1786659c9bc1SBen Hutchings 	ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1787659c9bc1SBen Hutchings 	if (ret)
1788659c9bc1SBen Hutchings 		return ret;
1789659c9bc1SBen Hutchings 
1790659c9bc1SBen Hutchings 	slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1791659c9bc1SBen Hutchings 	dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
1792659c9bc1SBen Hutchings 	if (slots == 0)
1793659c9bc1SBen Hutchings 		return -ENODEV;
1794659c9bc1SBen Hutchings 
1795659c9bc1SBen Hutchings 	BUG_ON(slots > MAX_SLOTS);
1796659c9bc1SBen Hutchings 
1797659c9bc1SBen Hutchings 	ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
1798659c9bc1SBen Hutchings 	if (ret)
1799659c9bc1SBen Hutchings 		return ret;
1800659c9bc1SBen Hutchings 
1801659c9bc1SBen Hutchings 	first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
1802659c9bc1SBen Hutchings 
1803659c9bc1SBen Hutchings 	if (first_bar > 5) {
1804659c9bc1SBen Hutchings 		dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
1805659c9bc1SBen Hutchings 		return -ENODEV;
1806659c9bc1SBen Hutchings 	}
1807659c9bc1SBen Hutchings 
180852ac7acfSAndy Shevchenko 	ret = pcim_enable_device(pdev);
1809659c9bc1SBen Hutchings 	if (ret)
1810659c9bc1SBen Hutchings 		return ret;
1811659c9bc1SBen Hutchings 
181252ac7acfSAndy Shevchenko 	chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
181352ac7acfSAndy Shevchenko 	if (!chip)
181452ac7acfSAndy Shevchenko 		return -ENOMEM;
1815659c9bc1SBen Hutchings 
1816659c9bc1SBen Hutchings 	chip->pdev = pdev;
1817659c9bc1SBen Hutchings 	chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
1818659c9bc1SBen Hutchings 	if (chip->fixes) {
1819659c9bc1SBen Hutchings 		chip->quirks = chip->fixes->quirks;
1820659c9bc1SBen Hutchings 		chip->quirks2 = chip->fixes->quirks2;
1821659c9bc1SBen Hutchings 		chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1822659c9bc1SBen Hutchings 	}
1823659c9bc1SBen Hutchings 	chip->num_slots = slots;
1824659c9bc1SBen Hutchings 
1825659c9bc1SBen Hutchings 	pci_set_drvdata(pdev, chip);
1826659c9bc1SBen Hutchings 
1827659c9bc1SBen Hutchings 	if (chip->fixes && chip->fixes->probe) {
1828659c9bc1SBen Hutchings 		ret = chip->fixes->probe(chip);
1829659c9bc1SBen Hutchings 		if (ret)
183052ac7acfSAndy Shevchenko 			return ret;
1831659c9bc1SBen Hutchings 	}
1832659c9bc1SBen Hutchings 
1833659c9bc1SBen Hutchings 	slots = chip->num_slots;	/* Quirk may have changed this */
1834659c9bc1SBen Hutchings 
1835659c9bc1SBen Hutchings 	for (i = 0; i < slots; i++) {
1836659c9bc1SBen Hutchings 		slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
1837659c9bc1SBen Hutchings 		if (IS_ERR(slot)) {
1838659c9bc1SBen Hutchings 			for (i--; i >= 0; i--)
1839659c9bc1SBen Hutchings 				sdhci_pci_remove_slot(chip->slots[i]);
184052ac7acfSAndy Shevchenko 			return PTR_ERR(slot);
1841659c9bc1SBen Hutchings 		}
1842659c9bc1SBen Hutchings 
1843659c9bc1SBen Hutchings 		chip->slots[i] = slot;
1844659c9bc1SBen Hutchings 	}
1845659c9bc1SBen Hutchings 
1846659c9bc1SBen Hutchings 	if (chip->allow_runtime_pm)
1847659c9bc1SBen Hutchings 		sdhci_pci_runtime_pm_allow(&pdev->dev);
1848659c9bc1SBen Hutchings 
1849659c9bc1SBen Hutchings 	return 0;
1850659c9bc1SBen Hutchings }
1851659c9bc1SBen Hutchings 
1852659c9bc1SBen Hutchings static void sdhci_pci_remove(struct pci_dev *pdev)
1853659c9bc1SBen Hutchings {
1854659c9bc1SBen Hutchings 	int i;
185552ac7acfSAndy Shevchenko 	struct sdhci_pci_chip *chip = pci_get_drvdata(pdev);
1856659c9bc1SBen Hutchings 
1857659c9bc1SBen Hutchings 	if (chip->allow_runtime_pm)
1858659c9bc1SBen Hutchings 		sdhci_pci_runtime_pm_forbid(&pdev->dev);
1859659c9bc1SBen Hutchings 
1860659c9bc1SBen Hutchings 	for (i = 0; i < chip->num_slots; i++)
1861659c9bc1SBen Hutchings 		sdhci_pci_remove_slot(chip->slots[i]);
1862659c9bc1SBen Hutchings }
1863659c9bc1SBen Hutchings 
1864659c9bc1SBen Hutchings static struct pci_driver sdhci_driver = {
1865659c9bc1SBen Hutchings 	.name =		"sdhci-pci",
1866659c9bc1SBen Hutchings 	.id_table =	pci_ids,
1867659c9bc1SBen Hutchings 	.probe =	sdhci_pci_probe,
1868659c9bc1SBen Hutchings 	.remove =	sdhci_pci_remove,
1869659c9bc1SBen Hutchings 	.driver =	{
1870659c9bc1SBen Hutchings 		.pm =   &sdhci_pci_pm_ops
1871659c9bc1SBen Hutchings 	},
1872659c9bc1SBen Hutchings };
1873659c9bc1SBen Hutchings 
1874659c9bc1SBen Hutchings module_pci_driver(sdhci_driver);
1875659c9bc1SBen Hutchings 
1876659c9bc1SBen Hutchings MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
1877659c9bc1SBen Hutchings MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
1878659c9bc1SBen Hutchings MODULE_LICENSE("GPL");
1879