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