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 35*fee686b7SAdrian Hunter static int sdhci_pci_enable_dma(struct sdhci_host *host); 36*fee686b7SAdrian Hunter static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width); 37*fee686b7SAdrian Hunter static void sdhci_pci_hw_reset(struct sdhci_host *host); 38*fee686b7SAdrian Hunter static int sdhci_pci_select_drive_strength(struct sdhci_host *host, 39*fee686b7SAdrian Hunter struct mmc_card *card, 40*fee686b7SAdrian Hunter unsigned int max_dtr, int host_drv, 41*fee686b7SAdrian Hunter int card_drv, int *drv_type); 42*fee686b7SAdrian Hunter 43659c9bc1SBen Hutchings /*****************************************************************************\ 44659c9bc1SBen Hutchings * * 45659c9bc1SBen Hutchings * Hardware specific quirk handling * 46659c9bc1SBen Hutchings * * 47659c9bc1SBen Hutchings \*****************************************************************************/ 48659c9bc1SBen Hutchings 49659c9bc1SBen Hutchings static int ricoh_probe(struct sdhci_pci_chip *chip) 50659c9bc1SBen Hutchings { 51659c9bc1SBen Hutchings if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG || 52659c9bc1SBen Hutchings chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY) 53659c9bc1SBen Hutchings chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; 54659c9bc1SBen Hutchings return 0; 55659c9bc1SBen Hutchings } 56659c9bc1SBen Hutchings 57659c9bc1SBen Hutchings static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot) 58659c9bc1SBen Hutchings { 59659c9bc1SBen Hutchings slot->host->caps = 60659c9bc1SBen Hutchings ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT) 61659c9bc1SBen Hutchings & SDHCI_TIMEOUT_CLK_MASK) | 62659c9bc1SBen Hutchings 63659c9bc1SBen Hutchings ((0x21 << SDHCI_CLOCK_BASE_SHIFT) 64659c9bc1SBen Hutchings & SDHCI_CLOCK_BASE_MASK) | 65659c9bc1SBen Hutchings 66659c9bc1SBen Hutchings SDHCI_TIMEOUT_CLK_UNIT | 67659c9bc1SBen Hutchings SDHCI_CAN_VDD_330 | 68659c9bc1SBen Hutchings SDHCI_CAN_DO_HISPD | 69659c9bc1SBen Hutchings SDHCI_CAN_DO_SDMA; 70659c9bc1SBen Hutchings return 0; 71659c9bc1SBen Hutchings } 72659c9bc1SBen Hutchings 73659c9bc1SBen Hutchings static int ricoh_mmc_resume(struct sdhci_pci_chip *chip) 74659c9bc1SBen Hutchings { 75659c9bc1SBen Hutchings /* Apply a delay to allow controller to settle */ 76659c9bc1SBen Hutchings /* Otherwise it becomes confused if card state changed 77659c9bc1SBen Hutchings during suspend */ 78659c9bc1SBen Hutchings msleep(500); 79659c9bc1SBen Hutchings return 0; 80659c9bc1SBen Hutchings } 81659c9bc1SBen Hutchings 82659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ricoh = { 83659c9bc1SBen Hutchings .probe = ricoh_probe, 84659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | 85659c9bc1SBen Hutchings SDHCI_QUIRK_FORCE_DMA | 86659c9bc1SBen Hutchings SDHCI_QUIRK_CLOCK_BEFORE_RESET, 87659c9bc1SBen Hutchings }; 88659c9bc1SBen Hutchings 89659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ricoh_mmc = { 90659c9bc1SBen Hutchings .probe_slot = ricoh_mmc_probe_slot, 91659c9bc1SBen Hutchings .resume = ricoh_mmc_resume, 92659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | 93659c9bc1SBen Hutchings SDHCI_QUIRK_CLOCK_BEFORE_RESET | 94659c9bc1SBen Hutchings SDHCI_QUIRK_NO_CARD_NO_RESET | 95659c9bc1SBen Hutchings SDHCI_QUIRK_MISSING_CAPS 96659c9bc1SBen Hutchings }; 97659c9bc1SBen Hutchings 98659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ene_712 = { 99659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | 100659c9bc1SBen Hutchings SDHCI_QUIRK_BROKEN_DMA, 101659c9bc1SBen Hutchings }; 102659c9bc1SBen Hutchings 103659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_ene_714 = { 104659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | 105659c9bc1SBen Hutchings SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS | 106659c9bc1SBen Hutchings SDHCI_QUIRK_BROKEN_DMA, 107659c9bc1SBen Hutchings }; 108659c9bc1SBen Hutchings 109659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_cafe = { 110659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | 111659c9bc1SBen Hutchings SDHCI_QUIRK_NO_BUSY_IRQ | 112659c9bc1SBen Hutchings SDHCI_QUIRK_BROKEN_CARD_DETECTION | 113659c9bc1SBen Hutchings SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, 114659c9bc1SBen Hutchings }; 115659c9bc1SBen Hutchings 116659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_qrk = { 117659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_HISPD_BIT, 118659c9bc1SBen Hutchings }; 119659c9bc1SBen Hutchings 120659c9bc1SBen Hutchings static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot) 121659c9bc1SBen Hutchings { 122659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA; 123659c9bc1SBen Hutchings return 0; 124659c9bc1SBen Hutchings } 125659c9bc1SBen Hutchings 126659c9bc1SBen Hutchings /* 127659c9bc1SBen Hutchings * ADMA operation is disabled for Moorestown platform due to 128659c9bc1SBen Hutchings * hardware bugs. 129659c9bc1SBen Hutchings */ 130659c9bc1SBen Hutchings static int mrst_hc_probe(struct sdhci_pci_chip *chip) 131659c9bc1SBen Hutchings { 132659c9bc1SBen Hutchings /* 133659c9bc1SBen Hutchings * slots number is fixed here for MRST as SDIO3/5 are never used and 134659c9bc1SBen Hutchings * have hardware bugs. 135659c9bc1SBen Hutchings */ 136659c9bc1SBen Hutchings chip->num_slots = 1; 137659c9bc1SBen Hutchings return 0; 138659c9bc1SBen Hutchings } 139659c9bc1SBen Hutchings 140659c9bc1SBen Hutchings static int pch_hc_probe_slot(struct sdhci_pci_slot *slot) 141659c9bc1SBen Hutchings { 142659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA; 143659c9bc1SBen Hutchings return 0; 144659c9bc1SBen Hutchings } 145659c9bc1SBen Hutchings 146659c9bc1SBen Hutchings #ifdef CONFIG_PM 147659c9bc1SBen Hutchings 148659c9bc1SBen Hutchings static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id) 149659c9bc1SBen Hutchings { 150659c9bc1SBen Hutchings struct sdhci_pci_slot *slot = dev_id; 151659c9bc1SBen Hutchings struct sdhci_host *host = slot->host; 152659c9bc1SBen Hutchings 153659c9bc1SBen Hutchings mmc_detect_change(host->mmc, msecs_to_jiffies(200)); 154659c9bc1SBen Hutchings return IRQ_HANDLED; 155659c9bc1SBen Hutchings } 156659c9bc1SBen Hutchings 157659c9bc1SBen Hutchings static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot) 158659c9bc1SBen Hutchings { 159659c9bc1SBen Hutchings int err, irq, gpio = slot->cd_gpio; 160659c9bc1SBen Hutchings 161659c9bc1SBen Hutchings slot->cd_gpio = -EINVAL; 162659c9bc1SBen Hutchings slot->cd_irq = -EINVAL; 163659c9bc1SBen Hutchings 164659c9bc1SBen Hutchings if (!gpio_is_valid(gpio)) 165659c9bc1SBen Hutchings return; 166659c9bc1SBen Hutchings 167c10bc372SAndy Shevchenko err = devm_gpio_request(&slot->chip->pdev->dev, gpio, "sd_cd"); 168659c9bc1SBen Hutchings if (err < 0) 169659c9bc1SBen Hutchings goto out; 170659c9bc1SBen Hutchings 171659c9bc1SBen Hutchings err = gpio_direction_input(gpio); 172659c9bc1SBen Hutchings if (err < 0) 173659c9bc1SBen Hutchings goto out_free; 174659c9bc1SBen Hutchings 175659c9bc1SBen Hutchings irq = gpio_to_irq(gpio); 176659c9bc1SBen Hutchings if (irq < 0) 177659c9bc1SBen Hutchings goto out_free; 178659c9bc1SBen Hutchings 179659c9bc1SBen Hutchings err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING | 180659c9bc1SBen Hutchings IRQF_TRIGGER_FALLING, "sd_cd", slot); 181659c9bc1SBen Hutchings if (err) 182659c9bc1SBen Hutchings goto out_free; 183659c9bc1SBen Hutchings 184659c9bc1SBen Hutchings slot->cd_gpio = gpio; 185659c9bc1SBen Hutchings slot->cd_irq = irq; 186659c9bc1SBen Hutchings 187659c9bc1SBen Hutchings return; 188659c9bc1SBen Hutchings 189659c9bc1SBen Hutchings out_free: 190c10bc372SAndy Shevchenko devm_gpio_free(&slot->chip->pdev->dev, gpio); 191659c9bc1SBen Hutchings out: 192659c9bc1SBen Hutchings dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n"); 193659c9bc1SBen Hutchings } 194659c9bc1SBen Hutchings 195659c9bc1SBen Hutchings static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot) 196659c9bc1SBen Hutchings { 197659c9bc1SBen Hutchings if (slot->cd_irq >= 0) 198659c9bc1SBen Hutchings free_irq(slot->cd_irq, slot); 199659c9bc1SBen Hutchings } 200659c9bc1SBen Hutchings 201659c9bc1SBen Hutchings #else 202659c9bc1SBen Hutchings 203659c9bc1SBen Hutchings static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot) 204659c9bc1SBen Hutchings { 205659c9bc1SBen Hutchings } 206659c9bc1SBen Hutchings 207659c9bc1SBen Hutchings static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot) 208659c9bc1SBen Hutchings { 209659c9bc1SBen Hutchings } 210659c9bc1SBen Hutchings 211659c9bc1SBen Hutchings #endif 212659c9bc1SBen Hutchings 213659c9bc1SBen Hutchings static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot) 214659c9bc1SBen Hutchings { 215659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE; 216659c9bc1SBen Hutchings slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC | 217659c9bc1SBen Hutchings MMC_CAP2_HC_ERASE_SZ; 218659c9bc1SBen Hutchings return 0; 219659c9bc1SBen Hutchings } 220659c9bc1SBen Hutchings 221659c9bc1SBen Hutchings static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot) 222659c9bc1SBen Hutchings { 223659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE; 224659c9bc1SBen Hutchings return 0; 225659c9bc1SBen Hutchings } 226659c9bc1SBen Hutchings 227659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = { 228659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT, 229659c9bc1SBen Hutchings .probe_slot = mrst_hc_probe_slot, 230659c9bc1SBen Hutchings }; 231659c9bc1SBen Hutchings 232659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = { 233659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT, 234659c9bc1SBen Hutchings .probe = mrst_hc_probe, 235659c9bc1SBen Hutchings }; 236659c9bc1SBen Hutchings 237659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = { 238659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 239659c9bc1SBen Hutchings .allow_runtime_pm = true, 240659c9bc1SBen Hutchings .own_cd_for_runtime_pm = true, 241659c9bc1SBen Hutchings }; 242659c9bc1SBen Hutchings 243659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = { 244659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 245659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, 246659c9bc1SBen Hutchings .allow_runtime_pm = true, 247659c9bc1SBen Hutchings .probe_slot = mfd_sdio_probe_slot, 248659c9bc1SBen Hutchings }; 249659c9bc1SBen Hutchings 250659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = { 251659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 252659c9bc1SBen Hutchings .allow_runtime_pm = true, 253659c9bc1SBen Hutchings .probe_slot = mfd_emmc_probe_slot, 254659c9bc1SBen Hutchings }; 255659c9bc1SBen Hutchings 256659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = { 257659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_BROKEN_ADMA, 258659c9bc1SBen Hutchings .probe_slot = pch_hc_probe_slot, 259659c9bc1SBen Hutchings }; 260659c9bc1SBen Hutchings 261659c9bc1SBen Hutchings static void sdhci_pci_int_hw_reset(struct sdhci_host *host) 262659c9bc1SBen Hutchings { 263659c9bc1SBen Hutchings u8 reg; 264659c9bc1SBen Hutchings 265659c9bc1SBen Hutchings reg = sdhci_readb(host, SDHCI_POWER_CONTROL); 266659c9bc1SBen Hutchings reg |= 0x10; 267659c9bc1SBen Hutchings sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 268659c9bc1SBen Hutchings /* For eMMC, minimum is 1us but give it 9us for good measure */ 269659c9bc1SBen Hutchings udelay(9); 270659c9bc1SBen Hutchings reg &= ~0x10; 271659c9bc1SBen Hutchings sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 272659c9bc1SBen Hutchings /* For eMMC, minimum is 200us but give it 300us for good measure */ 273659c9bc1SBen Hutchings usleep_range(300, 1000); 274659c9bc1SBen Hutchings } 275659c9bc1SBen Hutchings 276659c9bc1SBen Hutchings static int spt_select_drive_strength(struct sdhci_host *host, 277659c9bc1SBen Hutchings struct mmc_card *card, 278659c9bc1SBen Hutchings unsigned int max_dtr, 279659c9bc1SBen Hutchings int host_drv, int card_drv, int *drv_type) 280659c9bc1SBen Hutchings { 281659c9bc1SBen Hutchings int drive_strength; 282659c9bc1SBen Hutchings 283659c9bc1SBen Hutchings if (sdhci_pci_spt_drive_strength > 0) 284659c9bc1SBen Hutchings drive_strength = sdhci_pci_spt_drive_strength & 0xf; 285659c9bc1SBen Hutchings else 2861ca89685SAdrian Hunter drive_strength = 0; /* Default 50-ohm */ 287659c9bc1SBen Hutchings 288659c9bc1SBen Hutchings if ((mmc_driver_type_mask(drive_strength) & card_drv) == 0) 289659c9bc1SBen Hutchings drive_strength = 0; /* Default 50-ohm */ 290659c9bc1SBen Hutchings 291659c9bc1SBen Hutchings return drive_strength; 292659c9bc1SBen Hutchings } 293659c9bc1SBen Hutchings 294659c9bc1SBen Hutchings /* Try to read the drive strength from the card */ 295659c9bc1SBen Hutchings static void spt_read_drive_strength(struct sdhci_host *host) 296659c9bc1SBen Hutchings { 297659c9bc1SBen Hutchings u32 val, i, t; 298659c9bc1SBen Hutchings u16 m; 299659c9bc1SBen Hutchings 300659c9bc1SBen Hutchings if (sdhci_pci_spt_drive_strength) 301659c9bc1SBen Hutchings return; 302659c9bc1SBen Hutchings 303659c9bc1SBen Hutchings sdhci_pci_spt_drive_strength = -1; 304659c9bc1SBen Hutchings 305659c9bc1SBen Hutchings m = sdhci_readw(host, SDHCI_HOST_CONTROL2) & 0x7; 306659c9bc1SBen Hutchings if (m != 3 && m != 5) 307659c9bc1SBen Hutchings return; 308659c9bc1SBen Hutchings val = sdhci_readl(host, SDHCI_PRESENT_STATE); 309659c9bc1SBen Hutchings if (val & 0x3) 310659c9bc1SBen Hutchings return; 311659c9bc1SBen Hutchings sdhci_writel(host, 0x007f0023, SDHCI_INT_ENABLE); 312659c9bc1SBen Hutchings sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); 313659c9bc1SBen Hutchings sdhci_writew(host, 0x10, SDHCI_TRANSFER_MODE); 314659c9bc1SBen Hutchings sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL); 315659c9bc1SBen Hutchings sdhci_writew(host, 512, SDHCI_BLOCK_SIZE); 316659c9bc1SBen Hutchings sdhci_writew(host, 1, SDHCI_BLOCK_COUNT); 317659c9bc1SBen Hutchings sdhci_writel(host, 0, SDHCI_ARGUMENT); 318659c9bc1SBen Hutchings sdhci_writew(host, 0x83b, SDHCI_COMMAND); 319659c9bc1SBen Hutchings for (i = 0; i < 1000; i++) { 320659c9bc1SBen Hutchings val = sdhci_readl(host, SDHCI_INT_STATUS); 321659c9bc1SBen Hutchings if (val & 0xffff8000) 322659c9bc1SBen Hutchings return; 323659c9bc1SBen Hutchings if (val & 0x20) 324659c9bc1SBen Hutchings break; 325659c9bc1SBen Hutchings udelay(1); 326659c9bc1SBen Hutchings } 327659c9bc1SBen Hutchings val = sdhci_readl(host, SDHCI_PRESENT_STATE); 328659c9bc1SBen Hutchings if (!(val & 0x800)) 329659c9bc1SBen Hutchings return; 330659c9bc1SBen Hutchings for (i = 0; i < 47; i++) 331659c9bc1SBen Hutchings val = sdhci_readl(host, SDHCI_BUFFER); 332659c9bc1SBen Hutchings t = val & 0xf00; 333659c9bc1SBen Hutchings if (t != 0x200 && t != 0x300) 334659c9bc1SBen Hutchings return; 335659c9bc1SBen Hutchings 336659c9bc1SBen Hutchings sdhci_pci_spt_drive_strength = 0x10 | ((val >> 12) & 0xf); 337659c9bc1SBen Hutchings } 338659c9bc1SBen Hutchings 339163cbe31SAdrian Hunter static int bxt_get_cd(struct mmc_host *mmc) 340163cbe31SAdrian Hunter { 341163cbe31SAdrian Hunter int gpio_cd = mmc_gpio_get_cd(mmc); 342163cbe31SAdrian Hunter struct sdhci_host *host = mmc_priv(mmc); 343163cbe31SAdrian Hunter unsigned long flags; 344163cbe31SAdrian Hunter int ret = 0; 345163cbe31SAdrian Hunter 346163cbe31SAdrian Hunter if (!gpio_cd) 347163cbe31SAdrian Hunter return 0; 348163cbe31SAdrian Hunter 349163cbe31SAdrian Hunter spin_lock_irqsave(&host->lock, flags); 350163cbe31SAdrian Hunter 351163cbe31SAdrian Hunter if (host->flags & SDHCI_DEVICE_DEAD) 352163cbe31SAdrian Hunter goto out; 353163cbe31SAdrian Hunter 354163cbe31SAdrian Hunter ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); 355163cbe31SAdrian Hunter out: 356163cbe31SAdrian Hunter spin_unlock_irqrestore(&host->lock, flags); 357163cbe31SAdrian Hunter 358163cbe31SAdrian Hunter return ret; 359163cbe31SAdrian Hunter } 360163cbe31SAdrian Hunter 361659c9bc1SBen Hutchings static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot) 362659c9bc1SBen Hutchings { 363659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | 364659c9bc1SBen Hutchings MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR | 36532828857SAdrian Hunter MMC_CAP_CMD_DURING_TFR | 366659c9bc1SBen Hutchings MMC_CAP_WAIT_WHILE_BUSY; 367659c9bc1SBen Hutchings slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ; 368659c9bc1SBen Hutchings slot->hw_reset = sdhci_pci_int_hw_reset; 369659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC) 370659c9bc1SBen Hutchings slot->host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */ 371659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_SPT_EMMC) { 372659c9bc1SBen Hutchings spt_read_drive_strength(slot->host); 373659c9bc1SBen Hutchings slot->select_drive_strength = spt_select_drive_strength; 374659c9bc1SBen Hutchings } 375659c9bc1SBen Hutchings return 0; 376659c9bc1SBen Hutchings } 377659c9bc1SBen Hutchings 378659c9bc1SBen Hutchings static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot) 379659c9bc1SBen Hutchings { 380659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE | 381659c9bc1SBen Hutchings MMC_CAP_WAIT_WHILE_BUSY; 382659c9bc1SBen Hutchings return 0; 383659c9bc1SBen Hutchings } 384659c9bc1SBen Hutchings 385659c9bc1SBen Hutchings static int byt_sd_probe_slot(struct sdhci_pci_slot *slot) 386659c9bc1SBen Hutchings { 38782296936SAdrian Hunter slot->host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; 388659c9bc1SBen Hutchings slot->cd_con_id = NULL; 389659c9bc1SBen Hutchings slot->cd_idx = 0; 390659c9bc1SBen Hutchings slot->cd_override_level = true; 391163cbe31SAdrian Hunter if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD || 39201d6b2a4SAdrian Hunter slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD || 393e8ef5176SAdrian Hunter slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD) { 394163cbe31SAdrian Hunter slot->host->mmc_host_ops.get_cd = bxt_get_cd; 395e8ef5176SAdrian Hunter slot->host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM; 396e8ef5176SAdrian Hunter } 397163cbe31SAdrian Hunter 398659c9bc1SBen Hutchings return 0; 399659c9bc1SBen Hutchings } 400659c9bc1SBen Hutchings 401*fee686b7SAdrian Hunter #define SDHCI_INTEL_PWR_TIMEOUT_CNT 20 402*fee686b7SAdrian Hunter #define SDHCI_INTEL_PWR_TIMEOUT_UDELAY 100 403*fee686b7SAdrian Hunter 404*fee686b7SAdrian Hunter static void sdhci_intel_set_power(struct sdhci_host *host, unsigned char mode, 405*fee686b7SAdrian Hunter unsigned short vdd) 406*fee686b7SAdrian Hunter { 407*fee686b7SAdrian Hunter int cntr; 408*fee686b7SAdrian Hunter u8 reg; 409*fee686b7SAdrian Hunter 410*fee686b7SAdrian Hunter sdhci_set_power(host, mode, vdd); 411*fee686b7SAdrian Hunter 412*fee686b7SAdrian Hunter if (mode == MMC_POWER_OFF) 413*fee686b7SAdrian Hunter return; 414*fee686b7SAdrian Hunter 415*fee686b7SAdrian Hunter /* 416*fee686b7SAdrian Hunter * Bus power might not enable after D3 -> D0 transition due to the 417*fee686b7SAdrian Hunter * present state not yet having propagated. Retry for up to 2ms. 418*fee686b7SAdrian Hunter */ 419*fee686b7SAdrian Hunter for (cntr = 0; cntr < SDHCI_INTEL_PWR_TIMEOUT_CNT; cntr++) { 420*fee686b7SAdrian Hunter reg = sdhci_readb(host, SDHCI_POWER_CONTROL); 421*fee686b7SAdrian Hunter if (reg & SDHCI_POWER_ON) 422*fee686b7SAdrian Hunter break; 423*fee686b7SAdrian Hunter udelay(SDHCI_INTEL_PWR_TIMEOUT_UDELAY); 424*fee686b7SAdrian Hunter reg |= SDHCI_POWER_ON; 425*fee686b7SAdrian Hunter sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 426*fee686b7SAdrian Hunter } 427*fee686b7SAdrian Hunter } 428*fee686b7SAdrian Hunter 429*fee686b7SAdrian Hunter static const struct sdhci_ops sdhci_intel_byt_ops = { 430*fee686b7SAdrian Hunter .set_clock = sdhci_set_clock, 431*fee686b7SAdrian Hunter .set_power = sdhci_intel_set_power, 432*fee686b7SAdrian Hunter .enable_dma = sdhci_pci_enable_dma, 433*fee686b7SAdrian Hunter .set_bus_width = sdhci_pci_set_bus_width, 434*fee686b7SAdrian Hunter .reset = sdhci_reset, 435*fee686b7SAdrian Hunter .set_uhs_signaling = sdhci_set_uhs_signaling, 436*fee686b7SAdrian Hunter .hw_reset = sdhci_pci_hw_reset, 437*fee686b7SAdrian Hunter .select_drive_strength = sdhci_pci_select_drive_strength, 438*fee686b7SAdrian Hunter }; 439*fee686b7SAdrian Hunter 440659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = { 441659c9bc1SBen Hutchings .allow_runtime_pm = true, 442659c9bc1SBen Hutchings .probe_slot = byt_emmc_probe_slot, 443659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 444659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 445659c9bc1SBen Hutchings SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 | 446659c9bc1SBen Hutchings SDHCI_QUIRK2_STOP_WITH_TC, 447*fee686b7SAdrian Hunter .ops = &sdhci_intel_byt_ops, 448659c9bc1SBen Hutchings }; 449659c9bc1SBen Hutchings 450659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { 451659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 452659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON | 453659c9bc1SBen Hutchings SDHCI_QUIRK2_PRESET_VALUE_BROKEN, 454659c9bc1SBen Hutchings .allow_runtime_pm = true, 455659c9bc1SBen Hutchings .probe_slot = byt_sdio_probe_slot, 456*fee686b7SAdrian Hunter .ops = &sdhci_intel_byt_ops, 457659c9bc1SBen Hutchings }; 458659c9bc1SBen Hutchings 459659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { 460659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 461659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | 462659c9bc1SBen Hutchings SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 463659c9bc1SBen Hutchings SDHCI_QUIRK2_STOP_WITH_TC, 464659c9bc1SBen Hutchings .allow_runtime_pm = true, 465659c9bc1SBen Hutchings .own_cd_for_runtime_pm = true, 466659c9bc1SBen Hutchings .probe_slot = byt_sd_probe_slot, 467*fee686b7SAdrian Hunter .ops = &sdhci_intel_byt_ops, 468659c9bc1SBen Hutchings }; 469659c9bc1SBen Hutchings 470659c9bc1SBen Hutchings /* Define Host controllers for Intel Merrifield platform */ 4711f64cec2SAndy Shevchenko #define INTEL_MRFLD_EMMC_0 0 4721f64cec2SAndy Shevchenko #define INTEL_MRFLD_EMMC_1 1 4734674b6c8SAndy Shevchenko #define INTEL_MRFLD_SD 2 474d5565577SAndy Shevchenko #define INTEL_MRFLD_SDIO 3 475659c9bc1SBen Hutchings 4761f64cec2SAndy Shevchenko static int intel_mrfld_mmc_probe_slot(struct sdhci_pci_slot *slot) 477659c9bc1SBen Hutchings { 4782e57bbe2SAndy Shevchenko unsigned int func = PCI_FUNC(slot->chip->pdev->devfn); 4792e57bbe2SAndy Shevchenko 4802e57bbe2SAndy Shevchenko switch (func) { 4812e57bbe2SAndy Shevchenko case INTEL_MRFLD_EMMC_0: 4822e57bbe2SAndy Shevchenko case INTEL_MRFLD_EMMC_1: 4832e57bbe2SAndy Shevchenko slot->host->mmc->caps |= MMC_CAP_NONREMOVABLE | 4842e57bbe2SAndy Shevchenko MMC_CAP_8_BIT_DATA | 4852e57bbe2SAndy Shevchenko MMC_CAP_1_8V_DDR; 4862e57bbe2SAndy Shevchenko break; 4874674b6c8SAndy Shevchenko case INTEL_MRFLD_SD: 4884674b6c8SAndy Shevchenko slot->host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; 4894674b6c8SAndy Shevchenko break; 490d5565577SAndy Shevchenko case INTEL_MRFLD_SDIO: 491d5565577SAndy Shevchenko slot->host->mmc->caps |= MMC_CAP_NONREMOVABLE | 492d5565577SAndy Shevchenko MMC_CAP_POWER_OFF_CARD; 493d5565577SAndy Shevchenko break; 4942e57bbe2SAndy Shevchenko default: 495659c9bc1SBen Hutchings return -ENODEV; 4962e57bbe2SAndy Shevchenko } 497659c9bc1SBen Hutchings return 0; 498659c9bc1SBen Hutchings } 499659c9bc1SBen Hutchings 5001f64cec2SAndy Shevchenko static const struct sdhci_pci_fixes sdhci_intel_mrfld_mmc = { 501659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 502659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_BROKEN_HS200 | 503659c9bc1SBen Hutchings SDHCI_QUIRK2_PRESET_VALUE_BROKEN, 504659c9bc1SBen Hutchings .allow_runtime_pm = true, 5051f64cec2SAndy Shevchenko .probe_slot = intel_mrfld_mmc_probe_slot, 506659c9bc1SBen Hutchings }; 507659c9bc1SBen Hutchings 508659c9bc1SBen Hutchings /* O2Micro extra registers */ 509659c9bc1SBen Hutchings #define O2_SD_LOCK_WP 0xD3 510659c9bc1SBen Hutchings #define O2_SD_MULTI_VCC3V 0xEE 511659c9bc1SBen Hutchings #define O2_SD_CLKREQ 0xEC 512659c9bc1SBen Hutchings #define O2_SD_CAPS 0xE0 513659c9bc1SBen Hutchings #define O2_SD_ADMA1 0xE2 514659c9bc1SBen Hutchings #define O2_SD_ADMA2 0xE7 515659c9bc1SBen Hutchings #define O2_SD_INF_MOD 0xF1 516659c9bc1SBen Hutchings 517659c9bc1SBen Hutchings static int jmicron_pmos(struct sdhci_pci_chip *chip, int on) 518659c9bc1SBen Hutchings { 519659c9bc1SBen Hutchings u8 scratch; 520659c9bc1SBen Hutchings int ret; 521659c9bc1SBen Hutchings 522659c9bc1SBen Hutchings ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch); 523659c9bc1SBen Hutchings if (ret) 524659c9bc1SBen Hutchings return ret; 525659c9bc1SBen Hutchings 526659c9bc1SBen Hutchings /* 527659c9bc1SBen Hutchings * Turn PMOS on [bit 0], set over current detection to 2.4 V 528659c9bc1SBen Hutchings * [bit 1:2] and enable over current debouncing [bit 6]. 529659c9bc1SBen Hutchings */ 530659c9bc1SBen Hutchings if (on) 531659c9bc1SBen Hutchings scratch |= 0x47; 532659c9bc1SBen Hutchings else 533659c9bc1SBen Hutchings scratch &= ~0x47; 534659c9bc1SBen Hutchings 5357582041fSkbuild test robot return pci_write_config_byte(chip->pdev, 0xAE, scratch); 536659c9bc1SBen Hutchings } 537659c9bc1SBen Hutchings 538659c9bc1SBen Hutchings static int jmicron_probe(struct sdhci_pci_chip *chip) 539659c9bc1SBen Hutchings { 540659c9bc1SBen Hutchings int ret; 541659c9bc1SBen Hutchings u16 mmcdev = 0; 542659c9bc1SBen Hutchings 543659c9bc1SBen Hutchings if (chip->pdev->revision == 0) { 544659c9bc1SBen Hutchings chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR | 545659c9bc1SBen Hutchings SDHCI_QUIRK_32BIT_DMA_SIZE | 546659c9bc1SBen Hutchings SDHCI_QUIRK_32BIT_ADMA_SIZE | 547659c9bc1SBen Hutchings SDHCI_QUIRK_RESET_AFTER_REQUEST | 548659c9bc1SBen Hutchings SDHCI_QUIRK_BROKEN_SMALL_PIO; 549659c9bc1SBen Hutchings } 550659c9bc1SBen Hutchings 551659c9bc1SBen Hutchings /* 552659c9bc1SBen Hutchings * JMicron chips can have two interfaces to the same hardware 553659c9bc1SBen Hutchings * in order to work around limitations in Microsoft's driver. 554659c9bc1SBen Hutchings * We need to make sure we only bind to one of them. 555659c9bc1SBen Hutchings * 556659c9bc1SBen Hutchings * This code assumes two things: 557659c9bc1SBen Hutchings * 558659c9bc1SBen Hutchings * 1. The PCI code adds subfunctions in order. 559659c9bc1SBen Hutchings * 560659c9bc1SBen Hutchings * 2. The MMC interface has a lower subfunction number 561659c9bc1SBen Hutchings * than the SD interface. 562659c9bc1SBen Hutchings */ 563659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) 564659c9bc1SBen Hutchings mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC; 565659c9bc1SBen Hutchings else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD) 566659c9bc1SBen Hutchings mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD; 567659c9bc1SBen Hutchings 568659c9bc1SBen Hutchings if (mmcdev) { 569659c9bc1SBen Hutchings struct pci_dev *sd_dev; 570659c9bc1SBen Hutchings 571659c9bc1SBen Hutchings sd_dev = NULL; 572659c9bc1SBen Hutchings while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON, 573659c9bc1SBen Hutchings mmcdev, sd_dev)) != NULL) { 574659c9bc1SBen Hutchings if ((PCI_SLOT(chip->pdev->devfn) == 575659c9bc1SBen Hutchings PCI_SLOT(sd_dev->devfn)) && 576659c9bc1SBen Hutchings (chip->pdev->bus == sd_dev->bus)) 577659c9bc1SBen Hutchings break; 578659c9bc1SBen Hutchings } 579659c9bc1SBen Hutchings 580659c9bc1SBen Hutchings if (sd_dev) { 581659c9bc1SBen Hutchings pci_dev_put(sd_dev); 582659c9bc1SBen Hutchings dev_info(&chip->pdev->dev, "Refusing to bind to " 583659c9bc1SBen Hutchings "secondary interface.\n"); 584659c9bc1SBen Hutchings return -ENODEV; 585659c9bc1SBen Hutchings } 586659c9bc1SBen Hutchings } 587659c9bc1SBen Hutchings 588659c9bc1SBen Hutchings /* 589659c9bc1SBen Hutchings * JMicron chips need a bit of a nudge to enable the power 590659c9bc1SBen Hutchings * output pins. 591659c9bc1SBen Hutchings */ 592659c9bc1SBen Hutchings ret = jmicron_pmos(chip, 1); 593659c9bc1SBen Hutchings if (ret) { 594659c9bc1SBen Hutchings dev_err(&chip->pdev->dev, "Failure enabling card power\n"); 595659c9bc1SBen Hutchings return ret; 596659c9bc1SBen Hutchings } 597659c9bc1SBen Hutchings 598659c9bc1SBen Hutchings /* quirk for unsable RO-detection on JM388 chips */ 599659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD || 600659c9bc1SBen Hutchings chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) 601659c9bc1SBen Hutchings chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT; 602659c9bc1SBen Hutchings 603659c9bc1SBen Hutchings return 0; 604659c9bc1SBen Hutchings } 605659c9bc1SBen Hutchings 606659c9bc1SBen Hutchings static void jmicron_enable_mmc(struct sdhci_host *host, int on) 607659c9bc1SBen Hutchings { 608659c9bc1SBen Hutchings u8 scratch; 609659c9bc1SBen Hutchings 610659c9bc1SBen Hutchings scratch = readb(host->ioaddr + 0xC0); 611659c9bc1SBen Hutchings 612659c9bc1SBen Hutchings if (on) 613659c9bc1SBen Hutchings scratch |= 0x01; 614659c9bc1SBen Hutchings else 615659c9bc1SBen Hutchings scratch &= ~0x01; 616659c9bc1SBen Hutchings 617659c9bc1SBen Hutchings writeb(scratch, host->ioaddr + 0xC0); 618659c9bc1SBen Hutchings } 619659c9bc1SBen Hutchings 620659c9bc1SBen Hutchings static int jmicron_probe_slot(struct sdhci_pci_slot *slot) 621659c9bc1SBen Hutchings { 622659c9bc1SBen Hutchings if (slot->chip->pdev->revision == 0) { 623659c9bc1SBen Hutchings u16 version; 624659c9bc1SBen Hutchings 625659c9bc1SBen Hutchings version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION); 626659c9bc1SBen Hutchings version = (version & SDHCI_VENDOR_VER_MASK) >> 627659c9bc1SBen Hutchings SDHCI_VENDOR_VER_SHIFT; 628659c9bc1SBen Hutchings 629659c9bc1SBen Hutchings /* 630659c9bc1SBen Hutchings * Older versions of the chip have lots of nasty glitches 631659c9bc1SBen Hutchings * in the ADMA engine. It's best just to avoid it 632659c9bc1SBen Hutchings * completely. 633659c9bc1SBen Hutchings */ 634659c9bc1SBen Hutchings if (version < 0xAC) 635659c9bc1SBen Hutchings slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; 636659c9bc1SBen Hutchings } 637659c9bc1SBen Hutchings 638659c9bc1SBen Hutchings /* JM388 MMC doesn't support 1.8V while SD supports it */ 639659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { 640659c9bc1SBen Hutchings slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 | 641659c9bc1SBen Hutchings MMC_VDD_29_30 | MMC_VDD_30_31 | 642659c9bc1SBen Hutchings MMC_VDD_165_195; /* allow 1.8V */ 643659c9bc1SBen Hutchings slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 | 644659c9bc1SBen Hutchings MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */ 645659c9bc1SBen Hutchings } 646659c9bc1SBen Hutchings 647659c9bc1SBen Hutchings /* 648659c9bc1SBen Hutchings * The secondary interface requires a bit set to get the 649659c9bc1SBen Hutchings * interrupts. 650659c9bc1SBen Hutchings */ 651659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 652659c9bc1SBen Hutchings slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) 653659c9bc1SBen Hutchings jmicron_enable_mmc(slot->host, 1); 654659c9bc1SBen Hutchings 655659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST; 656659c9bc1SBen Hutchings 657659c9bc1SBen Hutchings return 0; 658659c9bc1SBen Hutchings } 659659c9bc1SBen Hutchings 660659c9bc1SBen Hutchings static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead) 661659c9bc1SBen Hutchings { 662659c9bc1SBen Hutchings if (dead) 663659c9bc1SBen Hutchings return; 664659c9bc1SBen Hutchings 665659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 666659c9bc1SBen Hutchings slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) 667659c9bc1SBen Hutchings jmicron_enable_mmc(slot->host, 0); 668659c9bc1SBen Hutchings } 669659c9bc1SBen Hutchings 670659c9bc1SBen Hutchings static int jmicron_suspend(struct sdhci_pci_chip *chip) 671659c9bc1SBen Hutchings { 672659c9bc1SBen Hutchings int i; 673659c9bc1SBen Hutchings 674659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 675659c9bc1SBen Hutchings chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { 676659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) 677659c9bc1SBen Hutchings jmicron_enable_mmc(chip->slots[i]->host, 0); 678659c9bc1SBen Hutchings } 679659c9bc1SBen Hutchings 680659c9bc1SBen Hutchings return 0; 681659c9bc1SBen Hutchings } 682659c9bc1SBen Hutchings 683659c9bc1SBen Hutchings static int jmicron_resume(struct sdhci_pci_chip *chip) 684659c9bc1SBen Hutchings { 685659c9bc1SBen Hutchings int ret, i; 686659c9bc1SBen Hutchings 687659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 688659c9bc1SBen Hutchings chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { 689659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) 690659c9bc1SBen Hutchings jmicron_enable_mmc(chip->slots[i]->host, 1); 691659c9bc1SBen Hutchings } 692659c9bc1SBen Hutchings 693659c9bc1SBen Hutchings ret = jmicron_pmos(chip, 1); 694659c9bc1SBen Hutchings if (ret) { 695659c9bc1SBen Hutchings dev_err(&chip->pdev->dev, "Failure enabling card power\n"); 696659c9bc1SBen Hutchings return ret; 697659c9bc1SBen Hutchings } 698659c9bc1SBen Hutchings 699659c9bc1SBen Hutchings return 0; 700659c9bc1SBen Hutchings } 701659c9bc1SBen Hutchings 702659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_o2 = { 703659c9bc1SBen Hutchings .probe = sdhci_pci_o2_probe, 704659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 705659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD, 706659c9bc1SBen Hutchings .probe_slot = sdhci_pci_o2_probe_slot, 707659c9bc1SBen Hutchings .resume = sdhci_pci_o2_resume, 708659c9bc1SBen Hutchings }; 709659c9bc1SBen Hutchings 710659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_jmicron = { 711659c9bc1SBen Hutchings .probe = jmicron_probe, 712659c9bc1SBen Hutchings 713659c9bc1SBen Hutchings .probe_slot = jmicron_probe_slot, 714659c9bc1SBen Hutchings .remove_slot = jmicron_remove_slot, 715659c9bc1SBen Hutchings 716659c9bc1SBen Hutchings .suspend = jmicron_suspend, 717659c9bc1SBen Hutchings .resume = jmicron_resume, 718659c9bc1SBen Hutchings }; 719659c9bc1SBen Hutchings 720659c9bc1SBen Hutchings /* SysKonnect CardBus2SDIO extra registers */ 721659c9bc1SBen Hutchings #define SYSKT_CTRL 0x200 722659c9bc1SBen Hutchings #define SYSKT_RDFIFO_STAT 0x204 723659c9bc1SBen Hutchings #define SYSKT_WRFIFO_STAT 0x208 724659c9bc1SBen Hutchings #define SYSKT_POWER_DATA 0x20c 725659c9bc1SBen Hutchings #define SYSKT_POWER_330 0xef 726659c9bc1SBen Hutchings #define SYSKT_POWER_300 0xf8 727659c9bc1SBen Hutchings #define SYSKT_POWER_184 0xcc 728659c9bc1SBen Hutchings #define SYSKT_POWER_CMD 0x20d 729659c9bc1SBen Hutchings #define SYSKT_POWER_START (1 << 7) 730659c9bc1SBen Hutchings #define SYSKT_POWER_STATUS 0x20e 731659c9bc1SBen Hutchings #define SYSKT_POWER_STATUS_OK (1 << 0) 732659c9bc1SBen Hutchings #define SYSKT_BOARD_REV 0x210 733659c9bc1SBen Hutchings #define SYSKT_CHIP_REV 0x211 734659c9bc1SBen Hutchings #define SYSKT_CONF_DATA 0x212 735659c9bc1SBen Hutchings #define SYSKT_CONF_DATA_1V8 (1 << 2) 736659c9bc1SBen Hutchings #define SYSKT_CONF_DATA_2V5 (1 << 1) 737659c9bc1SBen Hutchings #define SYSKT_CONF_DATA_3V3 (1 << 0) 738659c9bc1SBen Hutchings 739659c9bc1SBen Hutchings static int syskt_probe(struct sdhci_pci_chip *chip) 740659c9bc1SBen Hutchings { 741659c9bc1SBen Hutchings if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { 742659c9bc1SBen Hutchings chip->pdev->class &= ~0x0000FF; 743659c9bc1SBen Hutchings chip->pdev->class |= PCI_SDHCI_IFDMA; 744659c9bc1SBen Hutchings } 745659c9bc1SBen Hutchings return 0; 746659c9bc1SBen Hutchings } 747659c9bc1SBen Hutchings 748659c9bc1SBen Hutchings static int syskt_probe_slot(struct sdhci_pci_slot *slot) 749659c9bc1SBen Hutchings { 750659c9bc1SBen Hutchings int tm, ps; 751659c9bc1SBen Hutchings 752659c9bc1SBen Hutchings u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV); 753659c9bc1SBen Hutchings u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV); 754659c9bc1SBen Hutchings dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, " 755659c9bc1SBen Hutchings "board rev %d.%d, chip rev %d.%d\n", 756659c9bc1SBen Hutchings board_rev >> 4, board_rev & 0xf, 757659c9bc1SBen Hutchings chip_rev >> 4, chip_rev & 0xf); 758659c9bc1SBen Hutchings if (chip_rev >= 0x20) 759659c9bc1SBen Hutchings slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA; 760659c9bc1SBen Hutchings 761659c9bc1SBen Hutchings writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA); 762659c9bc1SBen Hutchings writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD); 763659c9bc1SBen Hutchings udelay(50); 764659c9bc1SBen Hutchings tm = 10; /* Wait max 1 ms */ 765659c9bc1SBen Hutchings do { 766659c9bc1SBen Hutchings ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS); 767659c9bc1SBen Hutchings if (ps & SYSKT_POWER_STATUS_OK) 768659c9bc1SBen Hutchings break; 769659c9bc1SBen Hutchings udelay(100); 770659c9bc1SBen Hutchings } while (--tm); 771659c9bc1SBen Hutchings if (!tm) { 772659c9bc1SBen Hutchings dev_err(&slot->chip->pdev->dev, 773659c9bc1SBen Hutchings "power regulator never stabilized"); 774659c9bc1SBen Hutchings writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD); 775659c9bc1SBen Hutchings return -ENODEV; 776659c9bc1SBen Hutchings } 777659c9bc1SBen Hutchings 778659c9bc1SBen Hutchings return 0; 779659c9bc1SBen Hutchings } 780659c9bc1SBen Hutchings 781659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_syskt = { 782659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER, 783659c9bc1SBen Hutchings .probe = syskt_probe, 784659c9bc1SBen Hutchings .probe_slot = syskt_probe_slot, 785659c9bc1SBen Hutchings }; 786659c9bc1SBen Hutchings 787659c9bc1SBen Hutchings static int via_probe(struct sdhci_pci_chip *chip) 788659c9bc1SBen Hutchings { 789659c9bc1SBen Hutchings if (chip->pdev->revision == 0x10) 790659c9bc1SBen Hutchings chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER; 791659c9bc1SBen Hutchings 792659c9bc1SBen Hutchings return 0; 793659c9bc1SBen Hutchings } 794659c9bc1SBen Hutchings 795659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_via = { 796659c9bc1SBen Hutchings .probe = via_probe, 797659c9bc1SBen Hutchings }; 798659c9bc1SBen Hutchings 799659c9bc1SBen Hutchings static int rtsx_probe_slot(struct sdhci_pci_slot *slot) 800659c9bc1SBen Hutchings { 801659c9bc1SBen Hutchings slot->host->mmc->caps2 |= MMC_CAP2_HS200; 802659c9bc1SBen Hutchings return 0; 803659c9bc1SBen Hutchings } 804659c9bc1SBen Hutchings 805659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_rtsx = { 806659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 807659c9bc1SBen Hutchings SDHCI_QUIRK2_BROKEN_64_BIT_DMA | 808659c9bc1SBen Hutchings SDHCI_QUIRK2_BROKEN_DDR50, 809659c9bc1SBen Hutchings .probe_slot = rtsx_probe_slot, 810659c9bc1SBen Hutchings }; 811659c9bc1SBen Hutchings 812659c9bc1SBen Hutchings /*AMD chipset generation*/ 813659c9bc1SBen Hutchings enum amd_chipset_gen { 814659c9bc1SBen Hutchings AMD_CHIPSET_BEFORE_ML, 815659c9bc1SBen Hutchings AMD_CHIPSET_CZ, 816659c9bc1SBen Hutchings AMD_CHIPSET_NL, 817659c9bc1SBen Hutchings AMD_CHIPSET_UNKNOWN, 818659c9bc1SBen Hutchings }; 819659c9bc1SBen Hutchings 820659c9bc1SBen Hutchings static int amd_probe(struct sdhci_pci_chip *chip) 821659c9bc1SBen Hutchings { 822659c9bc1SBen Hutchings struct pci_dev *smbus_dev; 823659c9bc1SBen Hutchings enum amd_chipset_gen gen; 824659c9bc1SBen Hutchings 825659c9bc1SBen Hutchings smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 826659c9bc1SBen Hutchings PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL); 827659c9bc1SBen Hutchings if (smbus_dev) { 828659c9bc1SBen Hutchings gen = AMD_CHIPSET_BEFORE_ML; 829659c9bc1SBen Hutchings } else { 830659c9bc1SBen Hutchings smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 831659c9bc1SBen Hutchings PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, NULL); 832659c9bc1SBen Hutchings if (smbus_dev) { 833659c9bc1SBen Hutchings if (smbus_dev->revision < 0x51) 834659c9bc1SBen Hutchings gen = AMD_CHIPSET_CZ; 835659c9bc1SBen Hutchings else 836659c9bc1SBen Hutchings gen = AMD_CHIPSET_NL; 837659c9bc1SBen Hutchings } else { 838659c9bc1SBen Hutchings gen = AMD_CHIPSET_UNKNOWN; 839659c9bc1SBen Hutchings } 840659c9bc1SBen Hutchings } 841659c9bc1SBen Hutchings 842659c9bc1SBen Hutchings if ((gen == AMD_CHIPSET_BEFORE_ML) || (gen == AMD_CHIPSET_CZ)) { 843659c9bc1SBen Hutchings chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD; 844659c9bc1SBen Hutchings chip->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200; 845659c9bc1SBen Hutchings } 846659c9bc1SBen Hutchings 847659c9bc1SBen Hutchings return 0; 848659c9bc1SBen Hutchings } 849659c9bc1SBen Hutchings 850659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_amd = { 851659c9bc1SBen Hutchings .probe = amd_probe, 852659c9bc1SBen Hutchings }; 853659c9bc1SBen Hutchings 854659c9bc1SBen Hutchings static const struct pci_device_id pci_ids[] = { 855659c9bc1SBen Hutchings { 856659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 857659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_RICOH_R5C822, 858659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 859659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 860659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh, 861659c9bc1SBen Hutchings }, 862659c9bc1SBen Hutchings 863659c9bc1SBen Hutchings { 864659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 865659c9bc1SBen Hutchings .device = 0x843, 866659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 867659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 868659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, 869659c9bc1SBen Hutchings }, 870659c9bc1SBen Hutchings 871659c9bc1SBen Hutchings { 872659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 873659c9bc1SBen Hutchings .device = 0xe822, 874659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 875659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 876659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, 877659c9bc1SBen Hutchings }, 878659c9bc1SBen Hutchings 879659c9bc1SBen Hutchings { 880659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 881659c9bc1SBen Hutchings .device = 0xe823, 882659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 883659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 884659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, 885659c9bc1SBen Hutchings }, 886659c9bc1SBen Hutchings 887659c9bc1SBen Hutchings { 888659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 889659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB712_SD, 890659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 891659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 892659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_712, 893659c9bc1SBen Hutchings }, 894659c9bc1SBen Hutchings 895659c9bc1SBen Hutchings { 896659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 897659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB712_SD_2, 898659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 899659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 900659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_712, 901659c9bc1SBen Hutchings }, 902659c9bc1SBen Hutchings 903659c9bc1SBen Hutchings { 904659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 905659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB714_SD, 906659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 907659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 908659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_714, 909659c9bc1SBen Hutchings }, 910659c9bc1SBen Hutchings 911659c9bc1SBen Hutchings { 912659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 913659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB714_SD_2, 914659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 915659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 916659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_714, 917659c9bc1SBen Hutchings }, 918659c9bc1SBen Hutchings 919659c9bc1SBen Hutchings { 920659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_MARVELL, 921659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD, 922659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 923659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 924659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_cafe, 925659c9bc1SBen Hutchings }, 926659c9bc1SBen Hutchings 927659c9bc1SBen Hutchings { 928659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 929659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD, 930659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 931659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 932659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 933659c9bc1SBen Hutchings }, 934659c9bc1SBen Hutchings 935659c9bc1SBen Hutchings { 936659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 937659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC, 938659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 939659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 940659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 941659c9bc1SBen Hutchings }, 942659c9bc1SBen Hutchings 943659c9bc1SBen Hutchings { 944659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 945659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB388_SD, 946659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 947659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 948659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 949659c9bc1SBen Hutchings }, 950659c9bc1SBen Hutchings 951659c9bc1SBen Hutchings { 952659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 953659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD, 954659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 955659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 956659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 957659c9bc1SBen Hutchings }, 958659c9bc1SBen Hutchings 959659c9bc1SBen Hutchings { 960659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_SYSKONNECT, 961659c9bc1SBen Hutchings .device = 0x8000, 962659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 963659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 964659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_syskt, 965659c9bc1SBen Hutchings }, 966659c9bc1SBen Hutchings 967659c9bc1SBen Hutchings { 968659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_VIA, 969659c9bc1SBen Hutchings .device = 0x95d0, 970659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 971659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 972659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_via, 973659c9bc1SBen Hutchings }, 974659c9bc1SBen Hutchings 975659c9bc1SBen Hutchings { 976659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_REALTEK, 977659c9bc1SBen Hutchings .device = 0x5250, 978659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 979659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 980659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_rtsx, 981659c9bc1SBen Hutchings }, 982659c9bc1SBen Hutchings 983659c9bc1SBen Hutchings { 984659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 985659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_QRK_SD, 986659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 987659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 988659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_qrk, 989659c9bc1SBen Hutchings }, 990659c9bc1SBen Hutchings 991659c9bc1SBen Hutchings { 992659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 993659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MRST_SD0, 994659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 995659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 996659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0, 997659c9bc1SBen Hutchings }, 998659c9bc1SBen Hutchings 999659c9bc1SBen Hutchings { 1000659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1001659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MRST_SD1, 1002659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1003659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1004659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2, 1005659c9bc1SBen Hutchings }, 1006659c9bc1SBen Hutchings 1007659c9bc1SBen Hutchings { 1008659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1009659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MRST_SD2, 1010659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1011659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1012659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2, 1013659c9bc1SBen Hutchings }, 1014659c9bc1SBen Hutchings 1015659c9bc1SBen Hutchings { 1016659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1017659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_SD, 1018659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1019659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1020659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd, 1021659c9bc1SBen Hutchings }, 1022659c9bc1SBen Hutchings 1023659c9bc1SBen Hutchings { 1024659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1025659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1, 1026659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1027659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1028659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 1029659c9bc1SBen Hutchings }, 1030659c9bc1SBen Hutchings 1031659c9bc1SBen Hutchings { 1032659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1033659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2, 1034659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1035659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1036659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 1037659c9bc1SBen Hutchings }, 1038659c9bc1SBen Hutchings 1039659c9bc1SBen Hutchings { 1040659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1041659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0, 1042659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1043659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1044659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 1045659c9bc1SBen Hutchings }, 1046659c9bc1SBen Hutchings 1047659c9bc1SBen Hutchings { 1048659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1049659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1, 1050659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1051659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1052659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 1053659c9bc1SBen Hutchings }, 1054659c9bc1SBen Hutchings 1055659c9bc1SBen Hutchings { 1056659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1057659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0, 1058659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1059659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1060659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio, 1061659c9bc1SBen Hutchings }, 1062659c9bc1SBen Hutchings 1063659c9bc1SBen Hutchings { 1064659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1065659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1, 1066659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1067659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1068659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio, 1069659c9bc1SBen Hutchings }, 1070659c9bc1SBen Hutchings 1071659c9bc1SBen Hutchings { 1072659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1073659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_EMMC, 1074659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1075659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1076659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1077659c9bc1SBen Hutchings }, 1078659c9bc1SBen Hutchings 1079659c9bc1SBen Hutchings { 1080659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1081659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_SDIO, 1082659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1083659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1084659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 1085659c9bc1SBen Hutchings }, 1086659c9bc1SBen Hutchings 1087659c9bc1SBen Hutchings { 1088659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1089659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_SD, 1090659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1091659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1092659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 1093659c9bc1SBen Hutchings }, 1094659c9bc1SBen Hutchings 1095659c9bc1SBen Hutchings { 1096659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1097659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2, 1098659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1099659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1100659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1101659c9bc1SBen Hutchings }, 1102659c9bc1SBen Hutchings 1103659c9bc1SBen Hutchings { 1104659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1105659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BSW_EMMC, 1106659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1107659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1108659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1109659c9bc1SBen Hutchings }, 1110659c9bc1SBen Hutchings 1111659c9bc1SBen Hutchings { 1112659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1113659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BSW_SDIO, 1114659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1115659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1116659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 1117659c9bc1SBen Hutchings }, 1118659c9bc1SBen Hutchings 1119659c9bc1SBen Hutchings { 1120659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1121659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BSW_SD, 1122659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1123659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1124659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 1125659c9bc1SBen Hutchings }, 1126659c9bc1SBen Hutchings 1127659c9bc1SBen Hutchings { 1128659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1129659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0, 1130659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1131659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1132659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd, 1133659c9bc1SBen Hutchings }, 1134659c9bc1SBen Hutchings 1135659c9bc1SBen Hutchings { 1136659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1137659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1, 1138659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1139659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1140659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 1141659c9bc1SBen Hutchings }, 1142659c9bc1SBen Hutchings 1143659c9bc1SBen Hutchings { 1144659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1145659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2, 1146659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1147659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1148659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 1149659c9bc1SBen Hutchings }, 1150659c9bc1SBen Hutchings 1151659c9bc1SBen Hutchings { 1152659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1153659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0, 1154659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1155659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1156659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 1157659c9bc1SBen Hutchings }, 1158659c9bc1SBen Hutchings 1159659c9bc1SBen Hutchings { 1160659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1161659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1, 1162659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1163659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1164659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 1165659c9bc1SBen Hutchings }, 1166659c9bc1SBen Hutchings 1167659c9bc1SBen Hutchings { 1168659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 11691f64cec2SAndy Shevchenko .device = PCI_DEVICE_ID_INTEL_MRFLD_MMC, 1170659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1171659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 11721f64cec2SAndy Shevchenko .driver_data = (kernel_ulong_t)&sdhci_intel_mrfld_mmc, 1173659c9bc1SBen Hutchings }, 1174659c9bc1SBen Hutchings 1175659c9bc1SBen Hutchings { 1176659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1177659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_SPT_EMMC, 1178659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1179659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1180659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1181659c9bc1SBen Hutchings }, 1182659c9bc1SBen Hutchings 1183659c9bc1SBen Hutchings { 1184659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1185659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_SPT_SDIO, 1186659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1187659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1188659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 1189659c9bc1SBen Hutchings }, 1190659c9bc1SBen Hutchings 1191659c9bc1SBen Hutchings { 1192659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1193659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_SPT_SD, 1194659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1195659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1196659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 1197659c9bc1SBen Hutchings }, 1198659c9bc1SBen Hutchings 1199659c9bc1SBen Hutchings { 120006bf9c56SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 120106bf9c56SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_DNV_EMMC, 120206bf9c56SAdrian Hunter .subvendor = PCI_ANY_ID, 120306bf9c56SAdrian Hunter .subdevice = PCI_ANY_ID, 120406bf9c56SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 120506bf9c56SAdrian Hunter }, 120606bf9c56SAdrian Hunter 120706bf9c56SAdrian Hunter { 12084fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12094fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXT_EMMC, 12104fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12114fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12124fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 12134fd4c065SAdrian Hunter }, 12144fd4c065SAdrian Hunter 12154fd4c065SAdrian Hunter { 12164fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12174fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXT_SDIO, 12184fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12194fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12204fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 12214fd4c065SAdrian Hunter }, 12224fd4c065SAdrian Hunter 12234fd4c065SAdrian Hunter { 12244fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12254fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXT_SD, 12264fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12274fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12284fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 12294fd4c065SAdrian Hunter }, 12304fd4c065SAdrian Hunter 12314fd4c065SAdrian Hunter { 12324fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 123301d6b2a4SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXTM_EMMC, 123401d6b2a4SAdrian Hunter .subvendor = PCI_ANY_ID, 123501d6b2a4SAdrian Hunter .subdevice = PCI_ANY_ID, 123601d6b2a4SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 123701d6b2a4SAdrian Hunter }, 123801d6b2a4SAdrian Hunter 123901d6b2a4SAdrian Hunter { 124001d6b2a4SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 124101d6b2a4SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXTM_SDIO, 124201d6b2a4SAdrian Hunter .subvendor = PCI_ANY_ID, 124301d6b2a4SAdrian Hunter .subdevice = PCI_ANY_ID, 124401d6b2a4SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 124501d6b2a4SAdrian Hunter }, 124601d6b2a4SAdrian Hunter 124701d6b2a4SAdrian Hunter { 124801d6b2a4SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 124901d6b2a4SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXTM_SD, 125001d6b2a4SAdrian Hunter .subvendor = PCI_ANY_ID, 125101d6b2a4SAdrian Hunter .subdevice = PCI_ANY_ID, 125201d6b2a4SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 125301d6b2a4SAdrian Hunter }, 125401d6b2a4SAdrian Hunter 125501d6b2a4SAdrian Hunter { 125601d6b2a4SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12574fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_APL_EMMC, 12584fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12594fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12604fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 12614fd4c065SAdrian Hunter }, 12624fd4c065SAdrian Hunter 12634fd4c065SAdrian Hunter { 12644fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12654fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_APL_SDIO, 12664fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12674fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12684fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 12694fd4c065SAdrian Hunter }, 12704fd4c065SAdrian Hunter 12714fd4c065SAdrian Hunter { 12724fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12734fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_APL_SD, 12744fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12754fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12764fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 12774fd4c065SAdrian Hunter }, 12784fd4c065SAdrian Hunter 12794fd4c065SAdrian Hunter { 1280659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1281659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8120, 1282659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1283659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1284659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1285659c9bc1SBen Hutchings }, 1286659c9bc1SBen Hutchings 1287659c9bc1SBen Hutchings { 1288659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1289659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8220, 1290659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1291659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1292659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1293659c9bc1SBen Hutchings }, 1294659c9bc1SBen Hutchings 1295659c9bc1SBen Hutchings { 1296659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1297659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8221, 1298659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1299659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1300659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1301659c9bc1SBen Hutchings }, 1302659c9bc1SBen Hutchings 1303659c9bc1SBen Hutchings { 1304659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1305659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8320, 1306659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1307659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1308659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1309659c9bc1SBen Hutchings }, 1310659c9bc1SBen Hutchings 1311659c9bc1SBen Hutchings { 1312659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1313659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8321, 1314659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1315659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1316659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1317659c9bc1SBen Hutchings }, 1318659c9bc1SBen Hutchings 1319659c9bc1SBen Hutchings { 1320659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1321659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_FUJIN2, 1322659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1323659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1324659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1325659c9bc1SBen Hutchings }, 1326659c9bc1SBen Hutchings 1327659c9bc1SBen Hutchings { 1328659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1329659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SDS0, 1330659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1331659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1332659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1333659c9bc1SBen Hutchings }, 1334659c9bc1SBen Hutchings 1335659c9bc1SBen Hutchings { 1336659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1337659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SDS1, 1338659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1339659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1340659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1341659c9bc1SBen Hutchings }, 1342659c9bc1SBen Hutchings 1343659c9bc1SBen Hutchings { 1344659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1345659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SEABIRD0, 1346659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1347659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1348659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1349659c9bc1SBen Hutchings }, 1350659c9bc1SBen Hutchings 1351659c9bc1SBen Hutchings { 1352659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1353659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SEABIRD1, 1354659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1355659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1356659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1357659c9bc1SBen Hutchings }, 1358659c9bc1SBen Hutchings { 1359659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_AMD, 1360659c9bc1SBen Hutchings .device = PCI_ANY_ID, 1361659c9bc1SBen Hutchings .class = PCI_CLASS_SYSTEM_SDHCI << 8, 1362659c9bc1SBen Hutchings .class_mask = 0xFFFF00, 1363659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1364659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1365659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_amd, 1366659c9bc1SBen Hutchings }, 1367659c9bc1SBen Hutchings { /* Generic SD host controller */ 1368659c9bc1SBen Hutchings PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) 1369659c9bc1SBen Hutchings }, 1370659c9bc1SBen Hutchings 1371659c9bc1SBen Hutchings { /* end: all zeroes */ }, 1372659c9bc1SBen Hutchings }; 1373659c9bc1SBen Hutchings 1374659c9bc1SBen Hutchings MODULE_DEVICE_TABLE(pci, pci_ids); 1375659c9bc1SBen Hutchings 1376659c9bc1SBen Hutchings /*****************************************************************************\ 1377659c9bc1SBen Hutchings * * 1378659c9bc1SBen Hutchings * SDHCI core callbacks * 1379659c9bc1SBen Hutchings * * 1380659c9bc1SBen Hutchings \*****************************************************************************/ 1381659c9bc1SBen Hutchings 1382659c9bc1SBen Hutchings static int sdhci_pci_enable_dma(struct sdhci_host *host) 1383659c9bc1SBen Hutchings { 1384659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1385659c9bc1SBen Hutchings struct pci_dev *pdev; 1386659c9bc1SBen Hutchings 1387659c9bc1SBen Hutchings slot = sdhci_priv(host); 1388659c9bc1SBen Hutchings pdev = slot->chip->pdev; 1389659c9bc1SBen Hutchings 1390659c9bc1SBen Hutchings if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) && 1391659c9bc1SBen Hutchings ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) && 1392659c9bc1SBen Hutchings (host->flags & SDHCI_USE_SDMA)) { 1393659c9bc1SBen Hutchings dev_warn(&pdev->dev, "Will use DMA mode even though HW " 1394659c9bc1SBen Hutchings "doesn't fully claim to support it.\n"); 1395659c9bc1SBen Hutchings } 1396659c9bc1SBen Hutchings 1397659c9bc1SBen Hutchings pci_set_master(pdev); 1398659c9bc1SBen Hutchings 1399659c9bc1SBen Hutchings return 0; 1400659c9bc1SBen Hutchings } 1401659c9bc1SBen Hutchings 1402659c9bc1SBen Hutchings static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width) 1403659c9bc1SBen Hutchings { 1404659c9bc1SBen Hutchings u8 ctrl; 1405659c9bc1SBen Hutchings 1406659c9bc1SBen Hutchings ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 1407659c9bc1SBen Hutchings 1408659c9bc1SBen Hutchings switch (width) { 1409659c9bc1SBen Hutchings case MMC_BUS_WIDTH_8: 1410659c9bc1SBen Hutchings ctrl |= SDHCI_CTRL_8BITBUS; 1411659c9bc1SBen Hutchings ctrl &= ~SDHCI_CTRL_4BITBUS; 1412659c9bc1SBen Hutchings break; 1413659c9bc1SBen Hutchings case MMC_BUS_WIDTH_4: 1414659c9bc1SBen Hutchings ctrl |= SDHCI_CTRL_4BITBUS; 1415659c9bc1SBen Hutchings ctrl &= ~SDHCI_CTRL_8BITBUS; 1416659c9bc1SBen Hutchings break; 1417659c9bc1SBen Hutchings default: 1418659c9bc1SBen Hutchings ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS); 1419659c9bc1SBen Hutchings break; 1420659c9bc1SBen Hutchings } 1421659c9bc1SBen Hutchings 1422659c9bc1SBen Hutchings sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); 1423659c9bc1SBen Hutchings } 1424659c9bc1SBen Hutchings 1425659c9bc1SBen Hutchings static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host) 1426659c9bc1SBen Hutchings { 1427659c9bc1SBen Hutchings struct sdhci_pci_slot *slot = sdhci_priv(host); 1428659c9bc1SBen Hutchings int rst_n_gpio = slot->rst_n_gpio; 1429659c9bc1SBen Hutchings 1430659c9bc1SBen Hutchings if (!gpio_is_valid(rst_n_gpio)) 1431659c9bc1SBen Hutchings return; 1432659c9bc1SBen Hutchings gpio_set_value_cansleep(rst_n_gpio, 0); 1433659c9bc1SBen Hutchings /* For eMMC, minimum is 1us but give it 10us for good measure */ 1434659c9bc1SBen Hutchings udelay(10); 1435659c9bc1SBen Hutchings gpio_set_value_cansleep(rst_n_gpio, 1); 1436659c9bc1SBen Hutchings /* For eMMC, minimum is 200us but give it 300us for good measure */ 1437659c9bc1SBen Hutchings usleep_range(300, 1000); 1438659c9bc1SBen Hutchings } 1439659c9bc1SBen Hutchings 1440659c9bc1SBen Hutchings static void sdhci_pci_hw_reset(struct sdhci_host *host) 1441659c9bc1SBen Hutchings { 1442659c9bc1SBen Hutchings struct sdhci_pci_slot *slot = sdhci_priv(host); 1443659c9bc1SBen Hutchings 1444659c9bc1SBen Hutchings if (slot->hw_reset) 1445659c9bc1SBen Hutchings slot->hw_reset(host); 1446659c9bc1SBen Hutchings } 1447659c9bc1SBen Hutchings 1448659c9bc1SBen Hutchings static int sdhci_pci_select_drive_strength(struct sdhci_host *host, 1449659c9bc1SBen Hutchings struct mmc_card *card, 1450659c9bc1SBen Hutchings unsigned int max_dtr, int host_drv, 1451659c9bc1SBen Hutchings int card_drv, int *drv_type) 1452659c9bc1SBen Hutchings { 1453659c9bc1SBen Hutchings struct sdhci_pci_slot *slot = sdhci_priv(host); 1454659c9bc1SBen Hutchings 1455659c9bc1SBen Hutchings if (!slot->select_drive_strength) 1456659c9bc1SBen Hutchings return 0; 1457659c9bc1SBen Hutchings 1458659c9bc1SBen Hutchings return slot->select_drive_strength(host, card, max_dtr, host_drv, 1459659c9bc1SBen Hutchings card_drv, drv_type); 1460659c9bc1SBen Hutchings } 1461659c9bc1SBen Hutchings 1462659c9bc1SBen Hutchings static const struct sdhci_ops sdhci_pci_ops = { 1463659c9bc1SBen Hutchings .set_clock = sdhci_set_clock, 1464659c9bc1SBen Hutchings .enable_dma = sdhci_pci_enable_dma, 1465659c9bc1SBen Hutchings .set_bus_width = sdhci_pci_set_bus_width, 1466659c9bc1SBen Hutchings .reset = sdhci_reset, 1467659c9bc1SBen Hutchings .set_uhs_signaling = sdhci_set_uhs_signaling, 1468659c9bc1SBen Hutchings .hw_reset = sdhci_pci_hw_reset, 1469659c9bc1SBen Hutchings .select_drive_strength = sdhci_pci_select_drive_strength, 1470659c9bc1SBen Hutchings }; 1471659c9bc1SBen Hutchings 1472659c9bc1SBen Hutchings /*****************************************************************************\ 1473659c9bc1SBen Hutchings * * 1474659c9bc1SBen Hutchings * Suspend/resume * 1475659c9bc1SBen Hutchings * * 1476659c9bc1SBen Hutchings \*****************************************************************************/ 1477659c9bc1SBen Hutchings 1478f9900f15SUlf Hansson #ifdef CONFIG_PM_SLEEP 1479659c9bc1SBen Hutchings static int sdhci_pci_suspend(struct device *dev) 1480659c9bc1SBen Hutchings { 1481659c9bc1SBen Hutchings struct pci_dev *pdev = to_pci_dev(dev); 1482659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1483659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1484659c9bc1SBen Hutchings mmc_pm_flag_t slot_pm_flags; 1485659c9bc1SBen Hutchings mmc_pm_flag_t pm_flags = 0; 1486659c9bc1SBen Hutchings int i, ret; 1487659c9bc1SBen Hutchings 1488659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1489659c9bc1SBen Hutchings if (!chip) 1490659c9bc1SBen Hutchings return 0; 1491659c9bc1SBen Hutchings 1492659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1493659c9bc1SBen Hutchings slot = chip->slots[i]; 1494659c9bc1SBen Hutchings if (!slot) 1495659c9bc1SBen Hutchings continue; 1496659c9bc1SBen Hutchings 1497659c9bc1SBen Hutchings ret = sdhci_suspend_host(slot->host); 1498659c9bc1SBen Hutchings 1499659c9bc1SBen Hutchings if (ret) 1500659c9bc1SBen Hutchings goto err_pci_suspend; 1501659c9bc1SBen Hutchings 1502659c9bc1SBen Hutchings slot_pm_flags = slot->host->mmc->pm_flags; 1503659c9bc1SBen Hutchings if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ) 1504659c9bc1SBen Hutchings sdhci_enable_irq_wakeups(slot->host); 1505659c9bc1SBen Hutchings 1506659c9bc1SBen Hutchings pm_flags |= slot_pm_flags; 1507659c9bc1SBen Hutchings } 1508659c9bc1SBen Hutchings 1509659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->suspend) { 1510659c9bc1SBen Hutchings ret = chip->fixes->suspend(chip); 1511659c9bc1SBen Hutchings if (ret) 1512659c9bc1SBen Hutchings goto err_pci_suspend; 1513659c9bc1SBen Hutchings } 1514659c9bc1SBen Hutchings 1515659c9bc1SBen Hutchings if (pm_flags & MMC_PM_KEEP_POWER) { 1516659c9bc1SBen Hutchings if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) 1517659c9bc1SBen Hutchings device_init_wakeup(dev, true); 1518659c9bc1SBen Hutchings else 1519659c9bc1SBen Hutchings device_init_wakeup(dev, false); 1520659c9bc1SBen Hutchings } else 1521659c9bc1SBen Hutchings device_init_wakeup(dev, false); 1522659c9bc1SBen Hutchings 1523659c9bc1SBen Hutchings return 0; 1524659c9bc1SBen Hutchings 1525659c9bc1SBen Hutchings err_pci_suspend: 1526659c9bc1SBen Hutchings while (--i >= 0) 1527659c9bc1SBen Hutchings sdhci_resume_host(chip->slots[i]->host); 1528659c9bc1SBen Hutchings return ret; 1529659c9bc1SBen Hutchings } 1530659c9bc1SBen Hutchings 1531659c9bc1SBen Hutchings static int sdhci_pci_resume(struct device *dev) 1532659c9bc1SBen Hutchings { 1533659c9bc1SBen Hutchings struct pci_dev *pdev = to_pci_dev(dev); 1534659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1535659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1536659c9bc1SBen Hutchings int i, ret; 1537659c9bc1SBen Hutchings 1538659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1539659c9bc1SBen Hutchings if (!chip) 1540659c9bc1SBen Hutchings return 0; 1541659c9bc1SBen Hutchings 1542659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->resume) { 1543659c9bc1SBen Hutchings ret = chip->fixes->resume(chip); 1544659c9bc1SBen Hutchings if (ret) 1545659c9bc1SBen Hutchings return ret; 1546659c9bc1SBen Hutchings } 1547659c9bc1SBen Hutchings 1548659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1549659c9bc1SBen Hutchings slot = chip->slots[i]; 1550659c9bc1SBen Hutchings if (!slot) 1551659c9bc1SBen Hutchings continue; 1552659c9bc1SBen Hutchings 1553659c9bc1SBen Hutchings ret = sdhci_resume_host(slot->host); 1554659c9bc1SBen Hutchings if (ret) 1555659c9bc1SBen Hutchings return ret; 1556659c9bc1SBen Hutchings } 1557659c9bc1SBen Hutchings 1558659c9bc1SBen Hutchings return 0; 1559659c9bc1SBen Hutchings } 1560f9900f15SUlf Hansson #endif 1561659c9bc1SBen Hutchings 1562f9900f15SUlf Hansson #ifdef CONFIG_PM 1563659c9bc1SBen Hutchings static int sdhci_pci_runtime_suspend(struct device *dev) 1564659c9bc1SBen Hutchings { 1565923a231cSGeliang Tang struct pci_dev *pdev = to_pci_dev(dev); 1566659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1567659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1568659c9bc1SBen Hutchings int i, ret; 1569659c9bc1SBen Hutchings 1570659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1571659c9bc1SBen Hutchings if (!chip) 1572659c9bc1SBen Hutchings return 0; 1573659c9bc1SBen Hutchings 1574659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1575659c9bc1SBen Hutchings slot = chip->slots[i]; 1576659c9bc1SBen Hutchings if (!slot) 1577659c9bc1SBen Hutchings continue; 1578659c9bc1SBen Hutchings 1579659c9bc1SBen Hutchings ret = sdhci_runtime_suspend_host(slot->host); 1580659c9bc1SBen Hutchings 1581659c9bc1SBen Hutchings if (ret) 1582659c9bc1SBen Hutchings goto err_pci_runtime_suspend; 1583659c9bc1SBen Hutchings } 1584659c9bc1SBen Hutchings 1585659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->suspend) { 1586659c9bc1SBen Hutchings ret = chip->fixes->suspend(chip); 1587659c9bc1SBen Hutchings if (ret) 1588659c9bc1SBen Hutchings goto err_pci_runtime_suspend; 1589659c9bc1SBen Hutchings } 1590659c9bc1SBen Hutchings 1591659c9bc1SBen Hutchings return 0; 1592659c9bc1SBen Hutchings 1593659c9bc1SBen Hutchings err_pci_runtime_suspend: 1594659c9bc1SBen Hutchings while (--i >= 0) 1595659c9bc1SBen Hutchings sdhci_runtime_resume_host(chip->slots[i]->host); 1596659c9bc1SBen Hutchings return ret; 1597659c9bc1SBen Hutchings } 1598659c9bc1SBen Hutchings 1599659c9bc1SBen Hutchings static int sdhci_pci_runtime_resume(struct device *dev) 1600659c9bc1SBen Hutchings { 1601923a231cSGeliang Tang struct pci_dev *pdev = to_pci_dev(dev); 1602659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1603659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1604659c9bc1SBen Hutchings int i, ret; 1605659c9bc1SBen Hutchings 1606659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1607659c9bc1SBen Hutchings if (!chip) 1608659c9bc1SBen Hutchings return 0; 1609659c9bc1SBen Hutchings 1610659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->resume) { 1611659c9bc1SBen Hutchings ret = chip->fixes->resume(chip); 1612659c9bc1SBen Hutchings if (ret) 1613659c9bc1SBen Hutchings return ret; 1614659c9bc1SBen Hutchings } 1615659c9bc1SBen Hutchings 1616659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1617659c9bc1SBen Hutchings slot = chip->slots[i]; 1618659c9bc1SBen Hutchings if (!slot) 1619659c9bc1SBen Hutchings continue; 1620659c9bc1SBen Hutchings 1621659c9bc1SBen Hutchings ret = sdhci_runtime_resume_host(slot->host); 1622659c9bc1SBen Hutchings if (ret) 1623659c9bc1SBen Hutchings return ret; 1624659c9bc1SBen Hutchings } 1625659c9bc1SBen Hutchings 1626659c9bc1SBen Hutchings return 0; 1627659c9bc1SBen Hutchings } 1628f9900f15SUlf Hansson #endif 1629659c9bc1SBen Hutchings 1630659c9bc1SBen Hutchings static const struct dev_pm_ops sdhci_pci_pm_ops = { 1631f9900f15SUlf Hansson SET_SYSTEM_SLEEP_PM_OPS(sdhci_pci_suspend, sdhci_pci_resume) 1632659c9bc1SBen Hutchings SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend, 1633659c9bc1SBen Hutchings sdhci_pci_runtime_resume, NULL) 1634659c9bc1SBen Hutchings }; 1635659c9bc1SBen Hutchings 1636659c9bc1SBen Hutchings /*****************************************************************************\ 1637659c9bc1SBen Hutchings * * 1638659c9bc1SBen Hutchings * Device probing/removal * 1639659c9bc1SBen Hutchings * * 1640659c9bc1SBen Hutchings \*****************************************************************************/ 1641659c9bc1SBen Hutchings 1642659c9bc1SBen Hutchings static struct sdhci_pci_slot *sdhci_pci_probe_slot( 1643659c9bc1SBen Hutchings struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar, 1644659c9bc1SBen Hutchings int slotno) 1645659c9bc1SBen Hutchings { 1646659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1647659c9bc1SBen Hutchings struct sdhci_host *host; 1648659c9bc1SBen Hutchings int ret, bar = first_bar + slotno; 1649659c9bc1SBen Hutchings 1650659c9bc1SBen Hutchings if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { 1651659c9bc1SBen Hutchings dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar); 1652659c9bc1SBen Hutchings return ERR_PTR(-ENODEV); 1653659c9bc1SBen Hutchings } 1654659c9bc1SBen Hutchings 1655659c9bc1SBen Hutchings if (pci_resource_len(pdev, bar) < 0x100) { 1656659c9bc1SBen Hutchings dev_err(&pdev->dev, "Invalid iomem size. You may " 1657659c9bc1SBen Hutchings "experience problems.\n"); 1658659c9bc1SBen Hutchings } 1659659c9bc1SBen Hutchings 1660659c9bc1SBen Hutchings if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { 1661659c9bc1SBen Hutchings dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n"); 1662659c9bc1SBen Hutchings return ERR_PTR(-ENODEV); 1663659c9bc1SBen Hutchings } 1664659c9bc1SBen Hutchings 1665659c9bc1SBen Hutchings if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) { 1666659c9bc1SBen Hutchings dev_err(&pdev->dev, "Unknown interface. Aborting.\n"); 1667659c9bc1SBen Hutchings return ERR_PTR(-ENODEV); 1668659c9bc1SBen Hutchings } 1669659c9bc1SBen Hutchings 1670659c9bc1SBen Hutchings host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot)); 1671659c9bc1SBen Hutchings if (IS_ERR(host)) { 1672659c9bc1SBen Hutchings dev_err(&pdev->dev, "cannot allocate host\n"); 1673659c9bc1SBen Hutchings return ERR_CAST(host); 1674659c9bc1SBen Hutchings } 1675659c9bc1SBen Hutchings 1676659c9bc1SBen Hutchings slot = sdhci_priv(host); 1677659c9bc1SBen Hutchings 1678659c9bc1SBen Hutchings slot->chip = chip; 1679659c9bc1SBen Hutchings slot->host = host; 1680659c9bc1SBen Hutchings slot->rst_n_gpio = -EINVAL; 1681659c9bc1SBen Hutchings slot->cd_gpio = -EINVAL; 1682659c9bc1SBen Hutchings slot->cd_idx = -1; 1683659c9bc1SBen Hutchings 1684659c9bc1SBen Hutchings /* Retrieve platform data if there is any */ 1685659c9bc1SBen Hutchings if (*sdhci_pci_get_data) 1686659c9bc1SBen Hutchings slot->data = sdhci_pci_get_data(pdev, slotno); 1687659c9bc1SBen Hutchings 1688659c9bc1SBen Hutchings if (slot->data) { 1689659c9bc1SBen Hutchings if (slot->data->setup) { 1690659c9bc1SBen Hutchings ret = slot->data->setup(slot->data); 1691659c9bc1SBen Hutchings if (ret) { 1692659c9bc1SBen Hutchings dev_err(&pdev->dev, "platform setup failed\n"); 1693659c9bc1SBen Hutchings goto free; 1694659c9bc1SBen Hutchings } 1695659c9bc1SBen Hutchings } 1696659c9bc1SBen Hutchings slot->rst_n_gpio = slot->data->rst_n_gpio; 1697659c9bc1SBen Hutchings slot->cd_gpio = slot->data->cd_gpio; 1698659c9bc1SBen Hutchings } 1699659c9bc1SBen Hutchings 1700659c9bc1SBen Hutchings host->hw_name = "PCI"; 17016bc09063SAdrian Hunter host->ops = chip->fixes && chip->fixes->ops ? 17026bc09063SAdrian Hunter chip->fixes->ops : 17036bc09063SAdrian Hunter &sdhci_pci_ops; 1704659c9bc1SBen Hutchings host->quirks = chip->quirks; 1705659c9bc1SBen Hutchings host->quirks2 = chip->quirks2; 1706659c9bc1SBen Hutchings 1707659c9bc1SBen Hutchings host->irq = pdev->irq; 1708659c9bc1SBen Hutchings 1709c10bc372SAndy Shevchenko ret = pcim_iomap_regions(pdev, BIT(bar), mmc_hostname(host->mmc)); 1710659c9bc1SBen Hutchings if (ret) { 1711659c9bc1SBen Hutchings dev_err(&pdev->dev, "cannot request region\n"); 1712659c9bc1SBen Hutchings goto cleanup; 1713659c9bc1SBen Hutchings } 1714659c9bc1SBen Hutchings 1715c10bc372SAndy Shevchenko host->ioaddr = pcim_iomap_table(pdev)[bar]; 1716659c9bc1SBen Hutchings 1717659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->probe_slot) { 1718659c9bc1SBen Hutchings ret = chip->fixes->probe_slot(slot); 1719659c9bc1SBen Hutchings if (ret) 1720c10bc372SAndy Shevchenko goto cleanup; 1721659c9bc1SBen Hutchings } 1722659c9bc1SBen Hutchings 1723659c9bc1SBen Hutchings if (gpio_is_valid(slot->rst_n_gpio)) { 1724c10bc372SAndy Shevchenko if (!devm_gpio_request(&pdev->dev, slot->rst_n_gpio, "eMMC_reset")) { 1725659c9bc1SBen Hutchings gpio_direction_output(slot->rst_n_gpio, 1); 1726659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_HW_RESET; 1727659c9bc1SBen Hutchings slot->hw_reset = sdhci_pci_gpio_hw_reset; 1728659c9bc1SBen Hutchings } else { 1729659c9bc1SBen Hutchings dev_warn(&pdev->dev, "failed to request rst_n_gpio\n"); 1730659c9bc1SBen Hutchings slot->rst_n_gpio = -EINVAL; 1731659c9bc1SBen Hutchings } 1732659c9bc1SBen Hutchings } 1733659c9bc1SBen Hutchings 1734659c9bc1SBen Hutchings host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ; 1735659c9bc1SBen Hutchings host->mmc->slotno = slotno; 1736659c9bc1SBen Hutchings host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; 1737659c9bc1SBen Hutchings 1738659c9bc1SBen Hutchings if (slot->cd_idx >= 0 && 1739659c9bc1SBen Hutchings mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx, 1740659c9bc1SBen Hutchings slot->cd_override_level, 0, NULL)) { 1741659c9bc1SBen Hutchings dev_warn(&pdev->dev, "failed to setup card detect gpio\n"); 1742659c9bc1SBen Hutchings slot->cd_idx = -1; 1743659c9bc1SBen Hutchings } 1744659c9bc1SBen Hutchings 1745659c9bc1SBen Hutchings ret = sdhci_add_host(host); 1746659c9bc1SBen Hutchings if (ret) 1747659c9bc1SBen Hutchings goto remove; 1748659c9bc1SBen Hutchings 1749659c9bc1SBen Hutchings sdhci_pci_add_own_cd(slot); 1750659c9bc1SBen Hutchings 1751659c9bc1SBen Hutchings /* 1752659c9bc1SBen Hutchings * Check if the chip needs a separate GPIO for card detect to wake up 1753659c9bc1SBen Hutchings * from runtime suspend. If it is not there, don't allow runtime PM. 1754659c9bc1SBen Hutchings * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure. 1755659c9bc1SBen Hutchings */ 1756659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->own_cd_for_runtime_pm && 1757659c9bc1SBen Hutchings !gpio_is_valid(slot->cd_gpio) && slot->cd_idx < 0) 1758659c9bc1SBen Hutchings chip->allow_runtime_pm = false; 1759659c9bc1SBen Hutchings 1760659c9bc1SBen Hutchings return slot; 1761659c9bc1SBen Hutchings 1762659c9bc1SBen Hutchings remove: 1763659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->remove_slot) 1764659c9bc1SBen Hutchings chip->fixes->remove_slot(slot, 0); 1765659c9bc1SBen Hutchings 1766659c9bc1SBen Hutchings cleanup: 1767659c9bc1SBen Hutchings if (slot->data && slot->data->cleanup) 1768659c9bc1SBen Hutchings slot->data->cleanup(slot->data); 1769659c9bc1SBen Hutchings 1770659c9bc1SBen Hutchings free: 1771659c9bc1SBen Hutchings sdhci_free_host(host); 1772659c9bc1SBen Hutchings 1773659c9bc1SBen Hutchings return ERR_PTR(ret); 1774659c9bc1SBen Hutchings } 1775659c9bc1SBen Hutchings 1776659c9bc1SBen Hutchings static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot) 1777659c9bc1SBen Hutchings { 1778659c9bc1SBen Hutchings int dead; 1779659c9bc1SBen Hutchings u32 scratch; 1780659c9bc1SBen Hutchings 1781659c9bc1SBen Hutchings sdhci_pci_remove_own_cd(slot); 1782659c9bc1SBen Hutchings 1783659c9bc1SBen Hutchings dead = 0; 1784659c9bc1SBen Hutchings scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS); 1785659c9bc1SBen Hutchings if (scratch == (u32)-1) 1786659c9bc1SBen Hutchings dead = 1; 1787659c9bc1SBen Hutchings 1788659c9bc1SBen Hutchings sdhci_remove_host(slot->host, dead); 1789659c9bc1SBen Hutchings 1790659c9bc1SBen Hutchings if (slot->chip->fixes && slot->chip->fixes->remove_slot) 1791659c9bc1SBen Hutchings slot->chip->fixes->remove_slot(slot, dead); 1792659c9bc1SBen Hutchings 1793659c9bc1SBen Hutchings if (slot->data && slot->data->cleanup) 1794659c9bc1SBen Hutchings slot->data->cleanup(slot->data); 1795659c9bc1SBen Hutchings 1796659c9bc1SBen Hutchings sdhci_free_host(slot->host); 1797659c9bc1SBen Hutchings } 1798659c9bc1SBen Hutchings 1799659c9bc1SBen Hutchings static void sdhci_pci_runtime_pm_allow(struct device *dev) 1800659c9bc1SBen Hutchings { 180100884b61SAdrian Hunter pm_suspend_ignore_children(dev, 1); 1802659c9bc1SBen Hutchings pm_runtime_set_autosuspend_delay(dev, 50); 1803659c9bc1SBen Hutchings pm_runtime_use_autosuspend(dev); 180400884b61SAdrian Hunter pm_runtime_allow(dev); 180500884b61SAdrian Hunter /* Stay active until mmc core scans for a card */ 180600884b61SAdrian Hunter pm_runtime_put_noidle(dev); 1807659c9bc1SBen Hutchings } 1808659c9bc1SBen Hutchings 1809659c9bc1SBen Hutchings static void sdhci_pci_runtime_pm_forbid(struct device *dev) 1810659c9bc1SBen Hutchings { 1811659c9bc1SBen Hutchings pm_runtime_forbid(dev); 1812659c9bc1SBen Hutchings pm_runtime_get_noresume(dev); 1813659c9bc1SBen Hutchings } 1814659c9bc1SBen Hutchings 1815659c9bc1SBen Hutchings static int sdhci_pci_probe(struct pci_dev *pdev, 1816659c9bc1SBen Hutchings const struct pci_device_id *ent) 1817659c9bc1SBen Hutchings { 1818659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1819659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1820659c9bc1SBen Hutchings 1821659c9bc1SBen Hutchings u8 slots, first_bar; 1822659c9bc1SBen Hutchings int ret, i; 1823659c9bc1SBen Hutchings 1824659c9bc1SBen Hutchings BUG_ON(pdev == NULL); 1825659c9bc1SBen Hutchings BUG_ON(ent == NULL); 1826659c9bc1SBen Hutchings 1827659c9bc1SBen Hutchings dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n", 1828659c9bc1SBen Hutchings (int)pdev->vendor, (int)pdev->device, (int)pdev->revision); 1829659c9bc1SBen Hutchings 1830659c9bc1SBen Hutchings ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots); 1831659c9bc1SBen Hutchings if (ret) 1832659c9bc1SBen Hutchings return ret; 1833659c9bc1SBen Hutchings 1834659c9bc1SBen Hutchings slots = PCI_SLOT_INFO_SLOTS(slots) + 1; 1835659c9bc1SBen Hutchings dev_dbg(&pdev->dev, "found %d slot(s)\n", slots); 1836659c9bc1SBen Hutchings if (slots == 0) 1837659c9bc1SBen Hutchings return -ENODEV; 1838659c9bc1SBen Hutchings 1839659c9bc1SBen Hutchings BUG_ON(slots > MAX_SLOTS); 1840659c9bc1SBen Hutchings 1841659c9bc1SBen Hutchings ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar); 1842659c9bc1SBen Hutchings if (ret) 1843659c9bc1SBen Hutchings return ret; 1844659c9bc1SBen Hutchings 1845659c9bc1SBen Hutchings first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK; 1846659c9bc1SBen Hutchings 1847659c9bc1SBen Hutchings if (first_bar > 5) { 1848659c9bc1SBen Hutchings dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n"); 1849659c9bc1SBen Hutchings return -ENODEV; 1850659c9bc1SBen Hutchings } 1851659c9bc1SBen Hutchings 185252ac7acfSAndy Shevchenko ret = pcim_enable_device(pdev); 1853659c9bc1SBen Hutchings if (ret) 1854659c9bc1SBen Hutchings return ret; 1855659c9bc1SBen Hutchings 185652ac7acfSAndy Shevchenko chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 185752ac7acfSAndy Shevchenko if (!chip) 185852ac7acfSAndy Shevchenko return -ENOMEM; 1859659c9bc1SBen Hutchings 1860659c9bc1SBen Hutchings chip->pdev = pdev; 1861659c9bc1SBen Hutchings chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data; 1862659c9bc1SBen Hutchings if (chip->fixes) { 1863659c9bc1SBen Hutchings chip->quirks = chip->fixes->quirks; 1864659c9bc1SBen Hutchings chip->quirks2 = chip->fixes->quirks2; 1865659c9bc1SBen Hutchings chip->allow_runtime_pm = chip->fixes->allow_runtime_pm; 1866659c9bc1SBen Hutchings } 1867659c9bc1SBen Hutchings chip->num_slots = slots; 1868659c9bc1SBen Hutchings 1869659c9bc1SBen Hutchings pci_set_drvdata(pdev, chip); 1870659c9bc1SBen Hutchings 1871659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->probe) { 1872659c9bc1SBen Hutchings ret = chip->fixes->probe(chip); 1873659c9bc1SBen Hutchings if (ret) 187452ac7acfSAndy Shevchenko return ret; 1875659c9bc1SBen Hutchings } 1876659c9bc1SBen Hutchings 1877659c9bc1SBen Hutchings slots = chip->num_slots; /* Quirk may have changed this */ 1878659c9bc1SBen Hutchings 1879659c9bc1SBen Hutchings for (i = 0; i < slots; i++) { 1880659c9bc1SBen Hutchings slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i); 1881659c9bc1SBen Hutchings if (IS_ERR(slot)) { 1882659c9bc1SBen Hutchings for (i--; i >= 0; i--) 1883659c9bc1SBen Hutchings sdhci_pci_remove_slot(chip->slots[i]); 188452ac7acfSAndy Shevchenko return PTR_ERR(slot); 1885659c9bc1SBen Hutchings } 1886659c9bc1SBen Hutchings 1887659c9bc1SBen Hutchings chip->slots[i] = slot; 1888659c9bc1SBen Hutchings } 1889659c9bc1SBen Hutchings 1890659c9bc1SBen Hutchings if (chip->allow_runtime_pm) 1891659c9bc1SBen Hutchings sdhci_pci_runtime_pm_allow(&pdev->dev); 1892659c9bc1SBen Hutchings 1893659c9bc1SBen Hutchings return 0; 1894659c9bc1SBen Hutchings } 1895659c9bc1SBen Hutchings 1896659c9bc1SBen Hutchings static void sdhci_pci_remove(struct pci_dev *pdev) 1897659c9bc1SBen Hutchings { 1898659c9bc1SBen Hutchings int i; 189952ac7acfSAndy Shevchenko struct sdhci_pci_chip *chip = pci_get_drvdata(pdev); 1900659c9bc1SBen Hutchings 1901659c9bc1SBen Hutchings if (chip->allow_runtime_pm) 1902659c9bc1SBen Hutchings sdhci_pci_runtime_pm_forbid(&pdev->dev); 1903659c9bc1SBen Hutchings 1904659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) 1905659c9bc1SBen Hutchings sdhci_pci_remove_slot(chip->slots[i]); 1906659c9bc1SBen Hutchings } 1907659c9bc1SBen Hutchings 1908659c9bc1SBen Hutchings static struct pci_driver sdhci_driver = { 1909659c9bc1SBen Hutchings .name = "sdhci-pci", 1910659c9bc1SBen Hutchings .id_table = pci_ids, 1911659c9bc1SBen Hutchings .probe = sdhci_pci_probe, 1912659c9bc1SBen Hutchings .remove = sdhci_pci_remove, 1913659c9bc1SBen Hutchings .driver = { 1914659c9bc1SBen Hutchings .pm = &sdhci_pci_pm_ops 1915659c9bc1SBen Hutchings }, 1916659c9bc1SBen Hutchings }; 1917659c9bc1SBen Hutchings 1918659c9bc1SBen Hutchings module_pci_driver(sdhci_driver); 1919659c9bc1SBen Hutchings 1920659c9bc1SBen Hutchings MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>"); 1921659c9bc1SBen Hutchings MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver"); 1922659c9bc1SBen Hutchings MODULE_LICENSE("GPL"); 1923