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 | 357659c9bc1SBen Hutchings MMC_CAP_WAIT_WHILE_BUSY; 358659c9bc1SBen Hutchings slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ; 359659c9bc1SBen Hutchings slot->hw_reset = sdhci_pci_int_hw_reset; 360659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC) 361659c9bc1SBen Hutchings slot->host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */ 362659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_SPT_EMMC) { 363659c9bc1SBen Hutchings spt_read_drive_strength(slot->host); 364659c9bc1SBen Hutchings slot->select_drive_strength = spt_select_drive_strength; 365659c9bc1SBen Hutchings } 366659c9bc1SBen Hutchings return 0; 367659c9bc1SBen Hutchings } 368659c9bc1SBen Hutchings 369659c9bc1SBen Hutchings static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot) 370659c9bc1SBen Hutchings { 371659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE | 372659c9bc1SBen Hutchings MMC_CAP_WAIT_WHILE_BUSY; 373659c9bc1SBen Hutchings return 0; 374659c9bc1SBen Hutchings } 375659c9bc1SBen Hutchings 376659c9bc1SBen Hutchings static int byt_sd_probe_slot(struct sdhci_pci_slot *slot) 377659c9bc1SBen Hutchings { 37882296936SAdrian Hunter slot->host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; 379659c9bc1SBen Hutchings slot->cd_con_id = NULL; 380659c9bc1SBen Hutchings slot->cd_idx = 0; 381659c9bc1SBen Hutchings slot->cd_override_level = true; 382163cbe31SAdrian Hunter if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD || 38301d6b2a4SAdrian Hunter slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD || 384e8ef5176SAdrian Hunter slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD) { 385163cbe31SAdrian Hunter slot->host->mmc_host_ops.get_cd = bxt_get_cd; 386e8ef5176SAdrian Hunter slot->host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM; 387e8ef5176SAdrian Hunter } 388163cbe31SAdrian Hunter 389659c9bc1SBen Hutchings return 0; 390659c9bc1SBen Hutchings } 391659c9bc1SBen Hutchings 392659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = { 393659c9bc1SBen Hutchings .allow_runtime_pm = true, 394659c9bc1SBen Hutchings .probe_slot = byt_emmc_probe_slot, 395659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 396659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 397659c9bc1SBen Hutchings SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 | 398659c9bc1SBen Hutchings SDHCI_QUIRK2_STOP_WITH_TC, 399659c9bc1SBen Hutchings }; 400659c9bc1SBen Hutchings 401659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { 402659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 403659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON | 404659c9bc1SBen Hutchings SDHCI_QUIRK2_PRESET_VALUE_BROKEN, 405659c9bc1SBen Hutchings .allow_runtime_pm = true, 406659c9bc1SBen Hutchings .probe_slot = byt_sdio_probe_slot, 407659c9bc1SBen Hutchings }; 408659c9bc1SBen Hutchings 409659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { 410659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 411659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | 412659c9bc1SBen Hutchings SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 413659c9bc1SBen Hutchings SDHCI_QUIRK2_STOP_WITH_TC, 414659c9bc1SBen Hutchings .allow_runtime_pm = true, 415659c9bc1SBen Hutchings .own_cd_for_runtime_pm = true, 416659c9bc1SBen Hutchings .probe_slot = byt_sd_probe_slot, 417659c9bc1SBen Hutchings }; 418659c9bc1SBen Hutchings 419659c9bc1SBen Hutchings /* Define Host controllers for Intel Merrifield platform */ 4201f64cec2SAndy Shevchenko #define INTEL_MRFLD_EMMC_0 0 4211f64cec2SAndy Shevchenko #define INTEL_MRFLD_EMMC_1 1 422d5565577SAndy Shevchenko #define INTEL_MRFLD_SDIO 3 423659c9bc1SBen Hutchings 4241f64cec2SAndy Shevchenko static int intel_mrfld_mmc_probe_slot(struct sdhci_pci_slot *slot) 425659c9bc1SBen Hutchings { 4262e57bbe2SAndy Shevchenko unsigned int func = PCI_FUNC(slot->chip->pdev->devfn); 4272e57bbe2SAndy Shevchenko 4282e57bbe2SAndy Shevchenko switch (func) { 4292e57bbe2SAndy Shevchenko case INTEL_MRFLD_EMMC_0: 4302e57bbe2SAndy Shevchenko case INTEL_MRFLD_EMMC_1: 4312e57bbe2SAndy Shevchenko slot->host->mmc->caps |= MMC_CAP_NONREMOVABLE | 4322e57bbe2SAndy Shevchenko MMC_CAP_8_BIT_DATA | 4332e57bbe2SAndy Shevchenko MMC_CAP_1_8V_DDR; 4342e57bbe2SAndy Shevchenko break; 435d5565577SAndy Shevchenko case INTEL_MRFLD_SDIO: 436d5565577SAndy Shevchenko slot->host->mmc->caps |= MMC_CAP_NONREMOVABLE | 437d5565577SAndy Shevchenko MMC_CAP_POWER_OFF_CARD; 438d5565577SAndy Shevchenko break; 4392e57bbe2SAndy Shevchenko default: 440659c9bc1SBen Hutchings /* SD support is not ready yet */ 441659c9bc1SBen Hutchings return -ENODEV; 4422e57bbe2SAndy Shevchenko } 443659c9bc1SBen Hutchings return 0; 444659c9bc1SBen Hutchings } 445659c9bc1SBen Hutchings 4461f64cec2SAndy Shevchenko static const struct sdhci_pci_fixes sdhci_intel_mrfld_mmc = { 447659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 448659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_BROKEN_HS200 | 449659c9bc1SBen Hutchings SDHCI_QUIRK2_PRESET_VALUE_BROKEN, 450659c9bc1SBen Hutchings .allow_runtime_pm = true, 4511f64cec2SAndy Shevchenko .probe_slot = intel_mrfld_mmc_probe_slot, 452659c9bc1SBen Hutchings }; 453659c9bc1SBen Hutchings 454659c9bc1SBen Hutchings /* O2Micro extra registers */ 455659c9bc1SBen Hutchings #define O2_SD_LOCK_WP 0xD3 456659c9bc1SBen Hutchings #define O2_SD_MULTI_VCC3V 0xEE 457659c9bc1SBen Hutchings #define O2_SD_CLKREQ 0xEC 458659c9bc1SBen Hutchings #define O2_SD_CAPS 0xE0 459659c9bc1SBen Hutchings #define O2_SD_ADMA1 0xE2 460659c9bc1SBen Hutchings #define O2_SD_ADMA2 0xE7 461659c9bc1SBen Hutchings #define O2_SD_INF_MOD 0xF1 462659c9bc1SBen Hutchings 463659c9bc1SBen Hutchings static int jmicron_pmos(struct sdhci_pci_chip *chip, int on) 464659c9bc1SBen Hutchings { 465659c9bc1SBen Hutchings u8 scratch; 466659c9bc1SBen Hutchings int ret; 467659c9bc1SBen Hutchings 468659c9bc1SBen Hutchings ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch); 469659c9bc1SBen Hutchings if (ret) 470659c9bc1SBen Hutchings return ret; 471659c9bc1SBen Hutchings 472659c9bc1SBen Hutchings /* 473659c9bc1SBen Hutchings * Turn PMOS on [bit 0], set over current detection to 2.4 V 474659c9bc1SBen Hutchings * [bit 1:2] and enable over current debouncing [bit 6]. 475659c9bc1SBen Hutchings */ 476659c9bc1SBen Hutchings if (on) 477659c9bc1SBen Hutchings scratch |= 0x47; 478659c9bc1SBen Hutchings else 479659c9bc1SBen Hutchings scratch &= ~0x47; 480659c9bc1SBen Hutchings 4817582041fSkbuild test robot return pci_write_config_byte(chip->pdev, 0xAE, scratch); 482659c9bc1SBen Hutchings } 483659c9bc1SBen Hutchings 484659c9bc1SBen Hutchings static int jmicron_probe(struct sdhci_pci_chip *chip) 485659c9bc1SBen Hutchings { 486659c9bc1SBen Hutchings int ret; 487659c9bc1SBen Hutchings u16 mmcdev = 0; 488659c9bc1SBen Hutchings 489659c9bc1SBen Hutchings if (chip->pdev->revision == 0) { 490659c9bc1SBen Hutchings chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR | 491659c9bc1SBen Hutchings SDHCI_QUIRK_32BIT_DMA_SIZE | 492659c9bc1SBen Hutchings SDHCI_QUIRK_32BIT_ADMA_SIZE | 493659c9bc1SBen Hutchings SDHCI_QUIRK_RESET_AFTER_REQUEST | 494659c9bc1SBen Hutchings SDHCI_QUIRK_BROKEN_SMALL_PIO; 495659c9bc1SBen Hutchings } 496659c9bc1SBen Hutchings 497659c9bc1SBen Hutchings /* 498659c9bc1SBen Hutchings * JMicron chips can have two interfaces to the same hardware 499659c9bc1SBen Hutchings * in order to work around limitations in Microsoft's driver. 500659c9bc1SBen Hutchings * We need to make sure we only bind to one of them. 501659c9bc1SBen Hutchings * 502659c9bc1SBen Hutchings * This code assumes two things: 503659c9bc1SBen Hutchings * 504659c9bc1SBen Hutchings * 1. The PCI code adds subfunctions in order. 505659c9bc1SBen Hutchings * 506659c9bc1SBen Hutchings * 2. The MMC interface has a lower subfunction number 507659c9bc1SBen Hutchings * than the SD interface. 508659c9bc1SBen Hutchings */ 509659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) 510659c9bc1SBen Hutchings mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC; 511659c9bc1SBen Hutchings else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD) 512659c9bc1SBen Hutchings mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD; 513659c9bc1SBen Hutchings 514659c9bc1SBen Hutchings if (mmcdev) { 515659c9bc1SBen Hutchings struct pci_dev *sd_dev; 516659c9bc1SBen Hutchings 517659c9bc1SBen Hutchings sd_dev = NULL; 518659c9bc1SBen Hutchings while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON, 519659c9bc1SBen Hutchings mmcdev, sd_dev)) != NULL) { 520659c9bc1SBen Hutchings if ((PCI_SLOT(chip->pdev->devfn) == 521659c9bc1SBen Hutchings PCI_SLOT(sd_dev->devfn)) && 522659c9bc1SBen Hutchings (chip->pdev->bus == sd_dev->bus)) 523659c9bc1SBen Hutchings break; 524659c9bc1SBen Hutchings } 525659c9bc1SBen Hutchings 526659c9bc1SBen Hutchings if (sd_dev) { 527659c9bc1SBen Hutchings pci_dev_put(sd_dev); 528659c9bc1SBen Hutchings dev_info(&chip->pdev->dev, "Refusing to bind to " 529659c9bc1SBen Hutchings "secondary interface.\n"); 530659c9bc1SBen Hutchings return -ENODEV; 531659c9bc1SBen Hutchings } 532659c9bc1SBen Hutchings } 533659c9bc1SBen Hutchings 534659c9bc1SBen Hutchings /* 535659c9bc1SBen Hutchings * JMicron chips need a bit of a nudge to enable the power 536659c9bc1SBen Hutchings * output pins. 537659c9bc1SBen Hutchings */ 538659c9bc1SBen Hutchings ret = jmicron_pmos(chip, 1); 539659c9bc1SBen Hutchings if (ret) { 540659c9bc1SBen Hutchings dev_err(&chip->pdev->dev, "Failure enabling card power\n"); 541659c9bc1SBen Hutchings return ret; 542659c9bc1SBen Hutchings } 543659c9bc1SBen Hutchings 544659c9bc1SBen Hutchings /* quirk for unsable RO-detection on JM388 chips */ 545659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD || 546659c9bc1SBen Hutchings chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) 547659c9bc1SBen Hutchings chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT; 548659c9bc1SBen Hutchings 549659c9bc1SBen Hutchings return 0; 550659c9bc1SBen Hutchings } 551659c9bc1SBen Hutchings 552659c9bc1SBen Hutchings static void jmicron_enable_mmc(struct sdhci_host *host, int on) 553659c9bc1SBen Hutchings { 554659c9bc1SBen Hutchings u8 scratch; 555659c9bc1SBen Hutchings 556659c9bc1SBen Hutchings scratch = readb(host->ioaddr + 0xC0); 557659c9bc1SBen Hutchings 558659c9bc1SBen Hutchings if (on) 559659c9bc1SBen Hutchings scratch |= 0x01; 560659c9bc1SBen Hutchings else 561659c9bc1SBen Hutchings scratch &= ~0x01; 562659c9bc1SBen Hutchings 563659c9bc1SBen Hutchings writeb(scratch, host->ioaddr + 0xC0); 564659c9bc1SBen Hutchings } 565659c9bc1SBen Hutchings 566659c9bc1SBen Hutchings static int jmicron_probe_slot(struct sdhci_pci_slot *slot) 567659c9bc1SBen Hutchings { 568659c9bc1SBen Hutchings if (slot->chip->pdev->revision == 0) { 569659c9bc1SBen Hutchings u16 version; 570659c9bc1SBen Hutchings 571659c9bc1SBen Hutchings version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION); 572659c9bc1SBen Hutchings version = (version & SDHCI_VENDOR_VER_MASK) >> 573659c9bc1SBen Hutchings SDHCI_VENDOR_VER_SHIFT; 574659c9bc1SBen Hutchings 575659c9bc1SBen Hutchings /* 576659c9bc1SBen Hutchings * Older versions of the chip have lots of nasty glitches 577659c9bc1SBen Hutchings * in the ADMA engine. It's best just to avoid it 578659c9bc1SBen Hutchings * completely. 579659c9bc1SBen Hutchings */ 580659c9bc1SBen Hutchings if (version < 0xAC) 581659c9bc1SBen Hutchings slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; 582659c9bc1SBen Hutchings } 583659c9bc1SBen Hutchings 584659c9bc1SBen Hutchings /* JM388 MMC doesn't support 1.8V while SD supports it */ 585659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { 586659c9bc1SBen Hutchings slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 | 587659c9bc1SBen Hutchings MMC_VDD_29_30 | MMC_VDD_30_31 | 588659c9bc1SBen Hutchings MMC_VDD_165_195; /* allow 1.8V */ 589659c9bc1SBen Hutchings slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 | 590659c9bc1SBen Hutchings MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */ 591659c9bc1SBen Hutchings } 592659c9bc1SBen Hutchings 593659c9bc1SBen Hutchings /* 594659c9bc1SBen Hutchings * The secondary interface requires a bit set to get the 595659c9bc1SBen Hutchings * interrupts. 596659c9bc1SBen Hutchings */ 597659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 598659c9bc1SBen Hutchings slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) 599659c9bc1SBen Hutchings jmicron_enable_mmc(slot->host, 1); 600659c9bc1SBen Hutchings 601659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST; 602659c9bc1SBen Hutchings 603659c9bc1SBen Hutchings return 0; 604659c9bc1SBen Hutchings } 605659c9bc1SBen Hutchings 606659c9bc1SBen Hutchings static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead) 607659c9bc1SBen Hutchings { 608659c9bc1SBen Hutchings if (dead) 609659c9bc1SBen Hutchings return; 610659c9bc1SBen Hutchings 611659c9bc1SBen Hutchings if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 612659c9bc1SBen Hutchings slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) 613659c9bc1SBen Hutchings jmicron_enable_mmc(slot->host, 0); 614659c9bc1SBen Hutchings } 615659c9bc1SBen Hutchings 616659c9bc1SBen Hutchings static int jmicron_suspend(struct sdhci_pci_chip *chip) 617659c9bc1SBen Hutchings { 618659c9bc1SBen Hutchings int i; 619659c9bc1SBen Hutchings 620659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 621659c9bc1SBen Hutchings chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { 622659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) 623659c9bc1SBen Hutchings jmicron_enable_mmc(chip->slots[i]->host, 0); 624659c9bc1SBen Hutchings } 625659c9bc1SBen Hutchings 626659c9bc1SBen Hutchings return 0; 627659c9bc1SBen Hutchings } 628659c9bc1SBen Hutchings 629659c9bc1SBen Hutchings static int jmicron_resume(struct sdhci_pci_chip *chip) 630659c9bc1SBen Hutchings { 631659c9bc1SBen Hutchings int ret, i; 632659c9bc1SBen Hutchings 633659c9bc1SBen Hutchings if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC || 634659c9bc1SBen Hutchings chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) { 635659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) 636659c9bc1SBen Hutchings jmicron_enable_mmc(chip->slots[i]->host, 1); 637659c9bc1SBen Hutchings } 638659c9bc1SBen Hutchings 639659c9bc1SBen Hutchings ret = jmicron_pmos(chip, 1); 640659c9bc1SBen Hutchings if (ret) { 641659c9bc1SBen Hutchings dev_err(&chip->pdev->dev, "Failure enabling card power\n"); 642659c9bc1SBen Hutchings return ret; 643659c9bc1SBen Hutchings } 644659c9bc1SBen Hutchings 645659c9bc1SBen Hutchings return 0; 646659c9bc1SBen Hutchings } 647659c9bc1SBen Hutchings 648659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_o2 = { 649659c9bc1SBen Hutchings .probe = sdhci_pci_o2_probe, 650659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 651659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD, 652659c9bc1SBen Hutchings .probe_slot = sdhci_pci_o2_probe_slot, 653659c9bc1SBen Hutchings .resume = sdhci_pci_o2_resume, 654659c9bc1SBen Hutchings }; 655659c9bc1SBen Hutchings 656659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_jmicron = { 657659c9bc1SBen Hutchings .probe = jmicron_probe, 658659c9bc1SBen Hutchings 659659c9bc1SBen Hutchings .probe_slot = jmicron_probe_slot, 660659c9bc1SBen Hutchings .remove_slot = jmicron_remove_slot, 661659c9bc1SBen Hutchings 662659c9bc1SBen Hutchings .suspend = jmicron_suspend, 663659c9bc1SBen Hutchings .resume = jmicron_resume, 664659c9bc1SBen Hutchings }; 665659c9bc1SBen Hutchings 666659c9bc1SBen Hutchings /* SysKonnect CardBus2SDIO extra registers */ 667659c9bc1SBen Hutchings #define SYSKT_CTRL 0x200 668659c9bc1SBen Hutchings #define SYSKT_RDFIFO_STAT 0x204 669659c9bc1SBen Hutchings #define SYSKT_WRFIFO_STAT 0x208 670659c9bc1SBen Hutchings #define SYSKT_POWER_DATA 0x20c 671659c9bc1SBen Hutchings #define SYSKT_POWER_330 0xef 672659c9bc1SBen Hutchings #define SYSKT_POWER_300 0xf8 673659c9bc1SBen Hutchings #define SYSKT_POWER_184 0xcc 674659c9bc1SBen Hutchings #define SYSKT_POWER_CMD 0x20d 675659c9bc1SBen Hutchings #define SYSKT_POWER_START (1 << 7) 676659c9bc1SBen Hutchings #define SYSKT_POWER_STATUS 0x20e 677659c9bc1SBen Hutchings #define SYSKT_POWER_STATUS_OK (1 << 0) 678659c9bc1SBen Hutchings #define SYSKT_BOARD_REV 0x210 679659c9bc1SBen Hutchings #define SYSKT_CHIP_REV 0x211 680659c9bc1SBen Hutchings #define SYSKT_CONF_DATA 0x212 681659c9bc1SBen Hutchings #define SYSKT_CONF_DATA_1V8 (1 << 2) 682659c9bc1SBen Hutchings #define SYSKT_CONF_DATA_2V5 (1 << 1) 683659c9bc1SBen Hutchings #define SYSKT_CONF_DATA_3V3 (1 << 0) 684659c9bc1SBen Hutchings 685659c9bc1SBen Hutchings static int syskt_probe(struct sdhci_pci_chip *chip) 686659c9bc1SBen Hutchings { 687659c9bc1SBen Hutchings if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { 688659c9bc1SBen Hutchings chip->pdev->class &= ~0x0000FF; 689659c9bc1SBen Hutchings chip->pdev->class |= PCI_SDHCI_IFDMA; 690659c9bc1SBen Hutchings } 691659c9bc1SBen Hutchings return 0; 692659c9bc1SBen Hutchings } 693659c9bc1SBen Hutchings 694659c9bc1SBen Hutchings static int syskt_probe_slot(struct sdhci_pci_slot *slot) 695659c9bc1SBen Hutchings { 696659c9bc1SBen Hutchings int tm, ps; 697659c9bc1SBen Hutchings 698659c9bc1SBen Hutchings u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV); 699659c9bc1SBen Hutchings u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV); 700659c9bc1SBen Hutchings dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, " 701659c9bc1SBen Hutchings "board rev %d.%d, chip rev %d.%d\n", 702659c9bc1SBen Hutchings board_rev >> 4, board_rev & 0xf, 703659c9bc1SBen Hutchings chip_rev >> 4, chip_rev & 0xf); 704659c9bc1SBen Hutchings if (chip_rev >= 0x20) 705659c9bc1SBen Hutchings slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA; 706659c9bc1SBen Hutchings 707659c9bc1SBen Hutchings writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA); 708659c9bc1SBen Hutchings writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD); 709659c9bc1SBen Hutchings udelay(50); 710659c9bc1SBen Hutchings tm = 10; /* Wait max 1 ms */ 711659c9bc1SBen Hutchings do { 712659c9bc1SBen Hutchings ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS); 713659c9bc1SBen Hutchings if (ps & SYSKT_POWER_STATUS_OK) 714659c9bc1SBen Hutchings break; 715659c9bc1SBen Hutchings udelay(100); 716659c9bc1SBen Hutchings } while (--tm); 717659c9bc1SBen Hutchings if (!tm) { 718659c9bc1SBen Hutchings dev_err(&slot->chip->pdev->dev, 719659c9bc1SBen Hutchings "power regulator never stabilized"); 720659c9bc1SBen Hutchings writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD); 721659c9bc1SBen Hutchings return -ENODEV; 722659c9bc1SBen Hutchings } 723659c9bc1SBen Hutchings 724659c9bc1SBen Hutchings return 0; 725659c9bc1SBen Hutchings } 726659c9bc1SBen Hutchings 727659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_syskt = { 728659c9bc1SBen Hutchings .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER, 729659c9bc1SBen Hutchings .probe = syskt_probe, 730659c9bc1SBen Hutchings .probe_slot = syskt_probe_slot, 731659c9bc1SBen Hutchings }; 732659c9bc1SBen Hutchings 733659c9bc1SBen Hutchings static int via_probe(struct sdhci_pci_chip *chip) 734659c9bc1SBen Hutchings { 735659c9bc1SBen Hutchings if (chip->pdev->revision == 0x10) 736659c9bc1SBen Hutchings chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER; 737659c9bc1SBen Hutchings 738659c9bc1SBen Hutchings return 0; 739659c9bc1SBen Hutchings } 740659c9bc1SBen Hutchings 741659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_via = { 742659c9bc1SBen Hutchings .probe = via_probe, 743659c9bc1SBen Hutchings }; 744659c9bc1SBen Hutchings 745659c9bc1SBen Hutchings static int rtsx_probe_slot(struct sdhci_pci_slot *slot) 746659c9bc1SBen Hutchings { 747659c9bc1SBen Hutchings slot->host->mmc->caps2 |= MMC_CAP2_HS200; 748659c9bc1SBen Hutchings return 0; 749659c9bc1SBen Hutchings } 750659c9bc1SBen Hutchings 751659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_rtsx = { 752659c9bc1SBen Hutchings .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 753659c9bc1SBen Hutchings SDHCI_QUIRK2_BROKEN_64_BIT_DMA | 754659c9bc1SBen Hutchings SDHCI_QUIRK2_BROKEN_DDR50, 755659c9bc1SBen Hutchings .probe_slot = rtsx_probe_slot, 756659c9bc1SBen Hutchings }; 757659c9bc1SBen Hutchings 758659c9bc1SBen Hutchings /*AMD chipset generation*/ 759659c9bc1SBen Hutchings enum amd_chipset_gen { 760659c9bc1SBen Hutchings AMD_CHIPSET_BEFORE_ML, 761659c9bc1SBen Hutchings AMD_CHIPSET_CZ, 762659c9bc1SBen Hutchings AMD_CHIPSET_NL, 763659c9bc1SBen Hutchings AMD_CHIPSET_UNKNOWN, 764659c9bc1SBen Hutchings }; 765659c9bc1SBen Hutchings 766659c9bc1SBen Hutchings static int amd_probe(struct sdhci_pci_chip *chip) 767659c9bc1SBen Hutchings { 768659c9bc1SBen Hutchings struct pci_dev *smbus_dev; 769659c9bc1SBen Hutchings enum amd_chipset_gen gen; 770659c9bc1SBen Hutchings 771659c9bc1SBen Hutchings smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 772659c9bc1SBen Hutchings PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL); 773659c9bc1SBen Hutchings if (smbus_dev) { 774659c9bc1SBen Hutchings gen = AMD_CHIPSET_BEFORE_ML; 775659c9bc1SBen Hutchings } else { 776659c9bc1SBen Hutchings smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 777659c9bc1SBen Hutchings PCI_DEVICE_ID_AMD_KERNCZ_SMBUS, NULL); 778659c9bc1SBen Hutchings if (smbus_dev) { 779659c9bc1SBen Hutchings if (smbus_dev->revision < 0x51) 780659c9bc1SBen Hutchings gen = AMD_CHIPSET_CZ; 781659c9bc1SBen Hutchings else 782659c9bc1SBen Hutchings gen = AMD_CHIPSET_NL; 783659c9bc1SBen Hutchings } else { 784659c9bc1SBen Hutchings gen = AMD_CHIPSET_UNKNOWN; 785659c9bc1SBen Hutchings } 786659c9bc1SBen Hutchings } 787659c9bc1SBen Hutchings 788659c9bc1SBen Hutchings if ((gen == AMD_CHIPSET_BEFORE_ML) || (gen == AMD_CHIPSET_CZ)) { 789659c9bc1SBen Hutchings chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD; 790659c9bc1SBen Hutchings chip->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200; 791659c9bc1SBen Hutchings } 792659c9bc1SBen Hutchings 793659c9bc1SBen Hutchings return 0; 794659c9bc1SBen Hutchings } 795659c9bc1SBen Hutchings 796659c9bc1SBen Hutchings static const struct sdhci_pci_fixes sdhci_amd = { 797659c9bc1SBen Hutchings .probe = amd_probe, 798659c9bc1SBen Hutchings }; 799659c9bc1SBen Hutchings 800659c9bc1SBen Hutchings static const struct pci_device_id pci_ids[] = { 801659c9bc1SBen Hutchings { 802659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 803659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_RICOH_R5C822, 804659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 805659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 806659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh, 807659c9bc1SBen Hutchings }, 808659c9bc1SBen Hutchings 809659c9bc1SBen Hutchings { 810659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 811659c9bc1SBen Hutchings .device = 0x843, 812659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 813659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 814659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, 815659c9bc1SBen Hutchings }, 816659c9bc1SBen Hutchings 817659c9bc1SBen Hutchings { 818659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 819659c9bc1SBen Hutchings .device = 0xe822, 820659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 821659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 822659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, 823659c9bc1SBen Hutchings }, 824659c9bc1SBen Hutchings 825659c9bc1SBen Hutchings { 826659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_RICOH, 827659c9bc1SBen Hutchings .device = 0xe823, 828659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 829659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 830659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc, 831659c9bc1SBen Hutchings }, 832659c9bc1SBen Hutchings 833659c9bc1SBen Hutchings { 834659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 835659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB712_SD, 836659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 837659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 838659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_712, 839659c9bc1SBen Hutchings }, 840659c9bc1SBen Hutchings 841659c9bc1SBen Hutchings { 842659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 843659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB712_SD_2, 844659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 845659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 846659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_712, 847659c9bc1SBen Hutchings }, 848659c9bc1SBen Hutchings 849659c9bc1SBen Hutchings { 850659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 851659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB714_SD, 852659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 853659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 854659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_714, 855659c9bc1SBen Hutchings }, 856659c9bc1SBen Hutchings 857659c9bc1SBen Hutchings { 858659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_ENE, 859659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_ENE_CB714_SD_2, 860659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 861659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 862659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_ene_714, 863659c9bc1SBen Hutchings }, 864659c9bc1SBen Hutchings 865659c9bc1SBen Hutchings { 866659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_MARVELL, 867659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD, 868659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 869659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 870659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_cafe, 871659c9bc1SBen Hutchings }, 872659c9bc1SBen Hutchings 873659c9bc1SBen Hutchings { 874659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 875659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD, 876659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 877659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 878659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 879659c9bc1SBen Hutchings }, 880659c9bc1SBen Hutchings 881659c9bc1SBen Hutchings { 882659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 883659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC, 884659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 885659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 886659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 887659c9bc1SBen Hutchings }, 888659c9bc1SBen Hutchings 889659c9bc1SBen Hutchings { 890659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 891659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB388_SD, 892659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 893659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 894659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 895659c9bc1SBen Hutchings }, 896659c9bc1SBen Hutchings 897659c9bc1SBen Hutchings { 898659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_JMICRON, 899659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD, 900659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 901659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 902659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_jmicron, 903659c9bc1SBen Hutchings }, 904659c9bc1SBen Hutchings 905659c9bc1SBen Hutchings { 906659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_SYSKONNECT, 907659c9bc1SBen Hutchings .device = 0x8000, 908659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 909659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 910659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_syskt, 911659c9bc1SBen Hutchings }, 912659c9bc1SBen Hutchings 913659c9bc1SBen Hutchings { 914659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_VIA, 915659c9bc1SBen Hutchings .device = 0x95d0, 916659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 917659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 918659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_via, 919659c9bc1SBen Hutchings }, 920659c9bc1SBen Hutchings 921659c9bc1SBen Hutchings { 922659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_REALTEK, 923659c9bc1SBen Hutchings .device = 0x5250, 924659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 925659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 926659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_rtsx, 927659c9bc1SBen Hutchings }, 928659c9bc1SBen Hutchings 929659c9bc1SBen Hutchings { 930659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 931659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_QRK_SD, 932659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 933659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 934659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_qrk, 935659c9bc1SBen Hutchings }, 936659c9bc1SBen Hutchings 937659c9bc1SBen Hutchings { 938659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 939659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MRST_SD0, 940659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 941659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 942659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0, 943659c9bc1SBen Hutchings }, 944659c9bc1SBen Hutchings 945659c9bc1SBen Hutchings { 946659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 947659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MRST_SD1, 948659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 949659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 950659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2, 951659c9bc1SBen Hutchings }, 952659c9bc1SBen Hutchings 953659c9bc1SBen Hutchings { 954659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 955659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MRST_SD2, 956659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 957659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 958659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2, 959659c9bc1SBen Hutchings }, 960659c9bc1SBen Hutchings 961659c9bc1SBen Hutchings { 962659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 963659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_SD, 964659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 965659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 966659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd, 967659c9bc1SBen Hutchings }, 968659c9bc1SBen Hutchings 969659c9bc1SBen Hutchings { 970659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 971659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1, 972659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 973659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 974659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 975659c9bc1SBen Hutchings }, 976659c9bc1SBen Hutchings 977659c9bc1SBen Hutchings { 978659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 979659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2, 980659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 981659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 982659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 983659c9bc1SBen Hutchings }, 984659c9bc1SBen Hutchings 985659c9bc1SBen Hutchings { 986659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 987659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0, 988659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 989659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 990659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 991659c9bc1SBen Hutchings }, 992659c9bc1SBen Hutchings 993659c9bc1SBen Hutchings { 994659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 995659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1, 996659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 997659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 998659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 999659c9bc1SBen Hutchings }, 1000659c9bc1SBen Hutchings 1001659c9bc1SBen Hutchings { 1002659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1003659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0, 1004659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1005659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1006659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio, 1007659c9bc1SBen Hutchings }, 1008659c9bc1SBen Hutchings 1009659c9bc1SBen Hutchings { 1010659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1011659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1, 1012659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1013659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1014659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio, 1015659c9bc1SBen Hutchings }, 1016659c9bc1SBen Hutchings 1017659c9bc1SBen Hutchings { 1018659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1019659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_EMMC, 1020659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1021659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1022659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1023659c9bc1SBen Hutchings }, 1024659c9bc1SBen Hutchings 1025659c9bc1SBen Hutchings { 1026659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1027659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_SDIO, 1028659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1029659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1030659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 1031659c9bc1SBen Hutchings }, 1032659c9bc1SBen Hutchings 1033659c9bc1SBen Hutchings { 1034659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1035659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_SD, 1036659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1037659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1038659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 1039659c9bc1SBen Hutchings }, 1040659c9bc1SBen Hutchings 1041659c9bc1SBen Hutchings { 1042659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1043659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2, 1044659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1045659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1046659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1047659c9bc1SBen Hutchings }, 1048659c9bc1SBen Hutchings 1049659c9bc1SBen Hutchings { 1050659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1051659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BSW_EMMC, 1052659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1053659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1054659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1055659c9bc1SBen Hutchings }, 1056659c9bc1SBen Hutchings 1057659c9bc1SBen Hutchings { 1058659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1059659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BSW_SDIO, 1060659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1061659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1062659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 1063659c9bc1SBen Hutchings }, 1064659c9bc1SBen Hutchings 1065659c9bc1SBen Hutchings { 1066659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1067659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_BSW_SD, 1068659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1069659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1070659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 1071659c9bc1SBen Hutchings }, 1072659c9bc1SBen Hutchings 1073659c9bc1SBen Hutchings { 1074659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1075659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0, 1076659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1077659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1078659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd, 1079659c9bc1SBen Hutchings }, 1080659c9bc1SBen Hutchings 1081659c9bc1SBen Hutchings { 1082659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1083659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1, 1084659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1085659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1086659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 1087659c9bc1SBen Hutchings }, 1088659c9bc1SBen Hutchings 1089659c9bc1SBen Hutchings { 1090659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1091659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2, 1092659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1093659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1094659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio, 1095659c9bc1SBen Hutchings }, 1096659c9bc1SBen Hutchings 1097659c9bc1SBen Hutchings { 1098659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1099659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0, 1100659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1101659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1102659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 1103659c9bc1SBen Hutchings }, 1104659c9bc1SBen Hutchings 1105659c9bc1SBen Hutchings { 1106659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1107659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1, 1108659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1109659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1110659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc, 1111659c9bc1SBen Hutchings }, 1112659c9bc1SBen Hutchings 1113659c9bc1SBen Hutchings { 1114659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 11151f64cec2SAndy Shevchenko .device = PCI_DEVICE_ID_INTEL_MRFLD_MMC, 1116659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1117659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 11181f64cec2SAndy Shevchenko .driver_data = (kernel_ulong_t)&sdhci_intel_mrfld_mmc, 1119659c9bc1SBen Hutchings }, 1120659c9bc1SBen Hutchings 1121659c9bc1SBen Hutchings { 1122659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1123659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_SPT_EMMC, 1124659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1125659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1126659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 1127659c9bc1SBen Hutchings }, 1128659c9bc1SBen Hutchings 1129659c9bc1SBen Hutchings { 1130659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1131659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_SPT_SDIO, 1132659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1133659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1134659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 1135659c9bc1SBen Hutchings }, 1136659c9bc1SBen Hutchings 1137659c9bc1SBen Hutchings { 1138659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_INTEL, 1139659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_INTEL_SPT_SD, 1140659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1141659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1142659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 1143659c9bc1SBen Hutchings }, 1144659c9bc1SBen Hutchings 1145659c9bc1SBen Hutchings { 114606bf9c56SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 114706bf9c56SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_DNV_EMMC, 114806bf9c56SAdrian Hunter .subvendor = PCI_ANY_ID, 114906bf9c56SAdrian Hunter .subdevice = PCI_ANY_ID, 115006bf9c56SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 115106bf9c56SAdrian Hunter }, 115206bf9c56SAdrian Hunter 115306bf9c56SAdrian Hunter { 11544fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 11554fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXT_EMMC, 11564fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 11574fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 11584fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 11594fd4c065SAdrian Hunter }, 11604fd4c065SAdrian Hunter 11614fd4c065SAdrian Hunter { 11624fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 11634fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXT_SDIO, 11644fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 11654fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 11664fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 11674fd4c065SAdrian Hunter }, 11684fd4c065SAdrian Hunter 11694fd4c065SAdrian Hunter { 11704fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 11714fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXT_SD, 11724fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 11734fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 11744fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 11754fd4c065SAdrian Hunter }, 11764fd4c065SAdrian Hunter 11774fd4c065SAdrian Hunter { 11784fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 117901d6b2a4SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXTM_EMMC, 118001d6b2a4SAdrian Hunter .subvendor = PCI_ANY_ID, 118101d6b2a4SAdrian Hunter .subdevice = PCI_ANY_ID, 118201d6b2a4SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 118301d6b2a4SAdrian Hunter }, 118401d6b2a4SAdrian Hunter 118501d6b2a4SAdrian Hunter { 118601d6b2a4SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 118701d6b2a4SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXTM_SDIO, 118801d6b2a4SAdrian Hunter .subvendor = PCI_ANY_ID, 118901d6b2a4SAdrian Hunter .subdevice = PCI_ANY_ID, 119001d6b2a4SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 119101d6b2a4SAdrian Hunter }, 119201d6b2a4SAdrian Hunter 119301d6b2a4SAdrian Hunter { 119401d6b2a4SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 119501d6b2a4SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_BXTM_SD, 119601d6b2a4SAdrian Hunter .subvendor = PCI_ANY_ID, 119701d6b2a4SAdrian Hunter .subdevice = PCI_ANY_ID, 119801d6b2a4SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 119901d6b2a4SAdrian Hunter }, 120001d6b2a4SAdrian Hunter 120101d6b2a4SAdrian Hunter { 120201d6b2a4SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12034fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_APL_EMMC, 12044fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12054fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12064fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 12074fd4c065SAdrian Hunter }, 12084fd4c065SAdrian Hunter 12094fd4c065SAdrian Hunter { 12104fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12114fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_APL_SDIO, 12124fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12134fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12144fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio, 12154fd4c065SAdrian Hunter }, 12164fd4c065SAdrian Hunter 12174fd4c065SAdrian Hunter { 12184fd4c065SAdrian Hunter .vendor = PCI_VENDOR_ID_INTEL, 12194fd4c065SAdrian Hunter .device = PCI_DEVICE_ID_INTEL_APL_SD, 12204fd4c065SAdrian Hunter .subvendor = PCI_ANY_ID, 12214fd4c065SAdrian Hunter .subdevice = PCI_ANY_ID, 12224fd4c065SAdrian Hunter .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd, 12234fd4c065SAdrian Hunter }, 12244fd4c065SAdrian Hunter 12254fd4c065SAdrian Hunter { 1226659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1227659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8120, 1228659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1229659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1230659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1231659c9bc1SBen Hutchings }, 1232659c9bc1SBen Hutchings 1233659c9bc1SBen Hutchings { 1234659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1235659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8220, 1236659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1237659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1238659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1239659c9bc1SBen Hutchings }, 1240659c9bc1SBen Hutchings 1241659c9bc1SBen Hutchings { 1242659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1243659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8221, 1244659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1245659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1246659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1247659c9bc1SBen Hutchings }, 1248659c9bc1SBen Hutchings 1249659c9bc1SBen Hutchings { 1250659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1251659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8320, 1252659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1253659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1254659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1255659c9bc1SBen Hutchings }, 1256659c9bc1SBen Hutchings 1257659c9bc1SBen Hutchings { 1258659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1259659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_8321, 1260659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1261659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1262659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1263659c9bc1SBen Hutchings }, 1264659c9bc1SBen Hutchings 1265659c9bc1SBen Hutchings { 1266659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1267659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_FUJIN2, 1268659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1269659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1270659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1271659c9bc1SBen Hutchings }, 1272659c9bc1SBen Hutchings 1273659c9bc1SBen Hutchings { 1274659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1275659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SDS0, 1276659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1277659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1278659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1279659c9bc1SBen Hutchings }, 1280659c9bc1SBen Hutchings 1281659c9bc1SBen Hutchings { 1282659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1283659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SDS1, 1284659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1285659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1286659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1287659c9bc1SBen Hutchings }, 1288659c9bc1SBen Hutchings 1289659c9bc1SBen Hutchings { 1290659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1291659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SEABIRD0, 1292659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1293659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1294659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1295659c9bc1SBen Hutchings }, 1296659c9bc1SBen Hutchings 1297659c9bc1SBen Hutchings { 1298659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_O2, 1299659c9bc1SBen Hutchings .device = PCI_DEVICE_ID_O2_SEABIRD1, 1300659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1301659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1302659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_o2, 1303659c9bc1SBen Hutchings }, 1304659c9bc1SBen Hutchings { 1305659c9bc1SBen Hutchings .vendor = PCI_VENDOR_ID_AMD, 1306659c9bc1SBen Hutchings .device = PCI_ANY_ID, 1307659c9bc1SBen Hutchings .class = PCI_CLASS_SYSTEM_SDHCI << 8, 1308659c9bc1SBen Hutchings .class_mask = 0xFFFF00, 1309659c9bc1SBen Hutchings .subvendor = PCI_ANY_ID, 1310659c9bc1SBen Hutchings .subdevice = PCI_ANY_ID, 1311659c9bc1SBen Hutchings .driver_data = (kernel_ulong_t)&sdhci_amd, 1312659c9bc1SBen Hutchings }, 1313659c9bc1SBen Hutchings { /* Generic SD host controller */ 1314659c9bc1SBen Hutchings PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) 1315659c9bc1SBen Hutchings }, 1316659c9bc1SBen Hutchings 1317659c9bc1SBen Hutchings { /* end: all zeroes */ }, 1318659c9bc1SBen Hutchings }; 1319659c9bc1SBen Hutchings 1320659c9bc1SBen Hutchings MODULE_DEVICE_TABLE(pci, pci_ids); 1321659c9bc1SBen Hutchings 1322659c9bc1SBen Hutchings /*****************************************************************************\ 1323659c9bc1SBen Hutchings * * 1324659c9bc1SBen Hutchings * SDHCI core callbacks * 1325659c9bc1SBen Hutchings * * 1326659c9bc1SBen Hutchings \*****************************************************************************/ 1327659c9bc1SBen Hutchings 1328659c9bc1SBen Hutchings static int sdhci_pci_enable_dma(struct sdhci_host *host) 1329659c9bc1SBen Hutchings { 1330659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1331659c9bc1SBen Hutchings struct pci_dev *pdev; 1332659c9bc1SBen Hutchings 1333659c9bc1SBen Hutchings slot = sdhci_priv(host); 1334659c9bc1SBen Hutchings pdev = slot->chip->pdev; 1335659c9bc1SBen Hutchings 1336659c9bc1SBen Hutchings if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) && 1337659c9bc1SBen Hutchings ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) && 1338659c9bc1SBen Hutchings (host->flags & SDHCI_USE_SDMA)) { 1339659c9bc1SBen Hutchings dev_warn(&pdev->dev, "Will use DMA mode even though HW " 1340659c9bc1SBen Hutchings "doesn't fully claim to support it.\n"); 1341659c9bc1SBen Hutchings } 1342659c9bc1SBen Hutchings 1343659c9bc1SBen Hutchings pci_set_master(pdev); 1344659c9bc1SBen Hutchings 1345659c9bc1SBen Hutchings return 0; 1346659c9bc1SBen Hutchings } 1347659c9bc1SBen Hutchings 1348659c9bc1SBen Hutchings static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width) 1349659c9bc1SBen Hutchings { 1350659c9bc1SBen Hutchings u8 ctrl; 1351659c9bc1SBen Hutchings 1352659c9bc1SBen Hutchings ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 1353659c9bc1SBen Hutchings 1354659c9bc1SBen Hutchings switch (width) { 1355659c9bc1SBen Hutchings case MMC_BUS_WIDTH_8: 1356659c9bc1SBen Hutchings ctrl |= SDHCI_CTRL_8BITBUS; 1357659c9bc1SBen Hutchings ctrl &= ~SDHCI_CTRL_4BITBUS; 1358659c9bc1SBen Hutchings break; 1359659c9bc1SBen Hutchings case MMC_BUS_WIDTH_4: 1360659c9bc1SBen Hutchings ctrl |= SDHCI_CTRL_4BITBUS; 1361659c9bc1SBen Hutchings ctrl &= ~SDHCI_CTRL_8BITBUS; 1362659c9bc1SBen Hutchings break; 1363659c9bc1SBen Hutchings default: 1364659c9bc1SBen Hutchings ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS); 1365659c9bc1SBen Hutchings break; 1366659c9bc1SBen Hutchings } 1367659c9bc1SBen Hutchings 1368659c9bc1SBen Hutchings sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); 1369659c9bc1SBen Hutchings } 1370659c9bc1SBen Hutchings 1371659c9bc1SBen Hutchings static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host) 1372659c9bc1SBen Hutchings { 1373659c9bc1SBen Hutchings struct sdhci_pci_slot *slot = sdhci_priv(host); 1374659c9bc1SBen Hutchings int rst_n_gpio = slot->rst_n_gpio; 1375659c9bc1SBen Hutchings 1376659c9bc1SBen Hutchings if (!gpio_is_valid(rst_n_gpio)) 1377659c9bc1SBen Hutchings return; 1378659c9bc1SBen Hutchings gpio_set_value_cansleep(rst_n_gpio, 0); 1379659c9bc1SBen Hutchings /* For eMMC, minimum is 1us but give it 10us for good measure */ 1380659c9bc1SBen Hutchings udelay(10); 1381659c9bc1SBen Hutchings gpio_set_value_cansleep(rst_n_gpio, 1); 1382659c9bc1SBen Hutchings /* For eMMC, minimum is 200us but give it 300us for good measure */ 1383659c9bc1SBen Hutchings usleep_range(300, 1000); 1384659c9bc1SBen Hutchings } 1385659c9bc1SBen Hutchings 1386659c9bc1SBen Hutchings static void sdhci_pci_hw_reset(struct sdhci_host *host) 1387659c9bc1SBen Hutchings { 1388659c9bc1SBen Hutchings struct sdhci_pci_slot *slot = sdhci_priv(host); 1389659c9bc1SBen Hutchings 1390659c9bc1SBen Hutchings if (slot->hw_reset) 1391659c9bc1SBen Hutchings slot->hw_reset(host); 1392659c9bc1SBen Hutchings } 1393659c9bc1SBen Hutchings 1394659c9bc1SBen Hutchings static int sdhci_pci_select_drive_strength(struct sdhci_host *host, 1395659c9bc1SBen Hutchings struct mmc_card *card, 1396659c9bc1SBen Hutchings unsigned int max_dtr, int host_drv, 1397659c9bc1SBen Hutchings int card_drv, int *drv_type) 1398659c9bc1SBen Hutchings { 1399659c9bc1SBen Hutchings struct sdhci_pci_slot *slot = sdhci_priv(host); 1400659c9bc1SBen Hutchings 1401659c9bc1SBen Hutchings if (!slot->select_drive_strength) 1402659c9bc1SBen Hutchings return 0; 1403659c9bc1SBen Hutchings 1404659c9bc1SBen Hutchings return slot->select_drive_strength(host, card, max_dtr, host_drv, 1405659c9bc1SBen Hutchings card_drv, drv_type); 1406659c9bc1SBen Hutchings } 1407659c9bc1SBen Hutchings 1408659c9bc1SBen Hutchings static const struct sdhci_ops sdhci_pci_ops = { 1409659c9bc1SBen Hutchings .set_clock = sdhci_set_clock, 1410659c9bc1SBen Hutchings .enable_dma = sdhci_pci_enable_dma, 1411659c9bc1SBen Hutchings .set_bus_width = sdhci_pci_set_bus_width, 1412659c9bc1SBen Hutchings .reset = sdhci_reset, 1413659c9bc1SBen Hutchings .set_uhs_signaling = sdhci_set_uhs_signaling, 1414659c9bc1SBen Hutchings .hw_reset = sdhci_pci_hw_reset, 1415659c9bc1SBen Hutchings .select_drive_strength = sdhci_pci_select_drive_strength, 1416659c9bc1SBen Hutchings }; 1417659c9bc1SBen Hutchings 1418659c9bc1SBen Hutchings /*****************************************************************************\ 1419659c9bc1SBen Hutchings * * 1420659c9bc1SBen Hutchings * Suspend/resume * 1421659c9bc1SBen Hutchings * * 1422659c9bc1SBen Hutchings \*****************************************************************************/ 1423659c9bc1SBen Hutchings 1424f9900f15SUlf Hansson #ifdef CONFIG_PM_SLEEP 1425659c9bc1SBen Hutchings static int sdhci_pci_suspend(struct device *dev) 1426659c9bc1SBen Hutchings { 1427659c9bc1SBen Hutchings struct pci_dev *pdev = to_pci_dev(dev); 1428659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1429659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1430659c9bc1SBen Hutchings mmc_pm_flag_t slot_pm_flags; 1431659c9bc1SBen Hutchings mmc_pm_flag_t pm_flags = 0; 1432659c9bc1SBen Hutchings int i, ret; 1433659c9bc1SBen Hutchings 1434659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1435659c9bc1SBen Hutchings if (!chip) 1436659c9bc1SBen Hutchings return 0; 1437659c9bc1SBen Hutchings 1438659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1439659c9bc1SBen Hutchings slot = chip->slots[i]; 1440659c9bc1SBen Hutchings if (!slot) 1441659c9bc1SBen Hutchings continue; 1442659c9bc1SBen Hutchings 1443659c9bc1SBen Hutchings ret = sdhci_suspend_host(slot->host); 1444659c9bc1SBen Hutchings 1445659c9bc1SBen Hutchings if (ret) 1446659c9bc1SBen Hutchings goto err_pci_suspend; 1447659c9bc1SBen Hutchings 1448659c9bc1SBen Hutchings slot_pm_flags = slot->host->mmc->pm_flags; 1449659c9bc1SBen Hutchings if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ) 1450659c9bc1SBen Hutchings sdhci_enable_irq_wakeups(slot->host); 1451659c9bc1SBen Hutchings 1452659c9bc1SBen Hutchings pm_flags |= slot_pm_flags; 1453659c9bc1SBen Hutchings } 1454659c9bc1SBen Hutchings 1455659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->suspend) { 1456659c9bc1SBen Hutchings ret = chip->fixes->suspend(chip); 1457659c9bc1SBen Hutchings if (ret) 1458659c9bc1SBen Hutchings goto err_pci_suspend; 1459659c9bc1SBen Hutchings } 1460659c9bc1SBen Hutchings 1461659c9bc1SBen Hutchings if (pm_flags & MMC_PM_KEEP_POWER) { 1462659c9bc1SBen Hutchings if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) 1463659c9bc1SBen Hutchings device_init_wakeup(dev, true); 1464659c9bc1SBen Hutchings else 1465659c9bc1SBen Hutchings device_init_wakeup(dev, false); 1466659c9bc1SBen Hutchings } else 1467659c9bc1SBen Hutchings device_init_wakeup(dev, false); 1468659c9bc1SBen Hutchings 1469659c9bc1SBen Hutchings return 0; 1470659c9bc1SBen Hutchings 1471659c9bc1SBen Hutchings err_pci_suspend: 1472659c9bc1SBen Hutchings while (--i >= 0) 1473659c9bc1SBen Hutchings sdhci_resume_host(chip->slots[i]->host); 1474659c9bc1SBen Hutchings return ret; 1475659c9bc1SBen Hutchings } 1476659c9bc1SBen Hutchings 1477659c9bc1SBen Hutchings static int sdhci_pci_resume(struct device *dev) 1478659c9bc1SBen Hutchings { 1479659c9bc1SBen Hutchings struct pci_dev *pdev = to_pci_dev(dev); 1480659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1481659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1482659c9bc1SBen Hutchings int i, ret; 1483659c9bc1SBen Hutchings 1484659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1485659c9bc1SBen Hutchings if (!chip) 1486659c9bc1SBen Hutchings return 0; 1487659c9bc1SBen Hutchings 1488659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->resume) { 1489659c9bc1SBen Hutchings ret = chip->fixes->resume(chip); 1490659c9bc1SBen Hutchings if (ret) 1491659c9bc1SBen Hutchings return ret; 1492659c9bc1SBen Hutchings } 1493659c9bc1SBen Hutchings 1494659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1495659c9bc1SBen Hutchings slot = chip->slots[i]; 1496659c9bc1SBen Hutchings if (!slot) 1497659c9bc1SBen Hutchings continue; 1498659c9bc1SBen Hutchings 1499659c9bc1SBen Hutchings ret = sdhci_resume_host(slot->host); 1500659c9bc1SBen Hutchings if (ret) 1501659c9bc1SBen Hutchings return ret; 1502659c9bc1SBen Hutchings } 1503659c9bc1SBen Hutchings 1504659c9bc1SBen Hutchings return 0; 1505659c9bc1SBen Hutchings } 1506f9900f15SUlf Hansson #endif 1507659c9bc1SBen Hutchings 1508f9900f15SUlf Hansson #ifdef CONFIG_PM 1509659c9bc1SBen Hutchings static int sdhci_pci_runtime_suspend(struct device *dev) 1510659c9bc1SBen Hutchings { 1511923a231cSGeliang Tang struct pci_dev *pdev = to_pci_dev(dev); 1512659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1513659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1514659c9bc1SBen Hutchings int i, ret; 1515659c9bc1SBen Hutchings 1516659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1517659c9bc1SBen Hutchings if (!chip) 1518659c9bc1SBen Hutchings return 0; 1519659c9bc1SBen Hutchings 1520659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1521659c9bc1SBen Hutchings slot = chip->slots[i]; 1522659c9bc1SBen Hutchings if (!slot) 1523659c9bc1SBen Hutchings continue; 1524659c9bc1SBen Hutchings 1525659c9bc1SBen Hutchings ret = sdhci_runtime_suspend_host(slot->host); 1526659c9bc1SBen Hutchings 1527659c9bc1SBen Hutchings if (ret) 1528659c9bc1SBen Hutchings goto err_pci_runtime_suspend; 1529659c9bc1SBen Hutchings } 1530659c9bc1SBen Hutchings 1531659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->suspend) { 1532659c9bc1SBen Hutchings ret = chip->fixes->suspend(chip); 1533659c9bc1SBen Hutchings if (ret) 1534659c9bc1SBen Hutchings goto err_pci_runtime_suspend; 1535659c9bc1SBen Hutchings } 1536659c9bc1SBen Hutchings 1537659c9bc1SBen Hutchings return 0; 1538659c9bc1SBen Hutchings 1539659c9bc1SBen Hutchings err_pci_runtime_suspend: 1540659c9bc1SBen Hutchings while (--i >= 0) 1541659c9bc1SBen Hutchings sdhci_runtime_resume_host(chip->slots[i]->host); 1542659c9bc1SBen Hutchings return ret; 1543659c9bc1SBen Hutchings } 1544659c9bc1SBen Hutchings 1545659c9bc1SBen Hutchings static int sdhci_pci_runtime_resume(struct device *dev) 1546659c9bc1SBen Hutchings { 1547923a231cSGeliang Tang struct pci_dev *pdev = to_pci_dev(dev); 1548659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1549659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1550659c9bc1SBen Hutchings int i, ret; 1551659c9bc1SBen Hutchings 1552659c9bc1SBen Hutchings chip = pci_get_drvdata(pdev); 1553659c9bc1SBen Hutchings if (!chip) 1554659c9bc1SBen Hutchings return 0; 1555659c9bc1SBen Hutchings 1556659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->resume) { 1557659c9bc1SBen Hutchings ret = chip->fixes->resume(chip); 1558659c9bc1SBen Hutchings if (ret) 1559659c9bc1SBen Hutchings return ret; 1560659c9bc1SBen Hutchings } 1561659c9bc1SBen Hutchings 1562659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) { 1563659c9bc1SBen Hutchings slot = chip->slots[i]; 1564659c9bc1SBen Hutchings if (!slot) 1565659c9bc1SBen Hutchings continue; 1566659c9bc1SBen Hutchings 1567659c9bc1SBen Hutchings ret = sdhci_runtime_resume_host(slot->host); 1568659c9bc1SBen Hutchings if (ret) 1569659c9bc1SBen Hutchings return ret; 1570659c9bc1SBen Hutchings } 1571659c9bc1SBen Hutchings 1572659c9bc1SBen Hutchings return 0; 1573659c9bc1SBen Hutchings } 1574f9900f15SUlf Hansson #endif 1575659c9bc1SBen Hutchings 1576659c9bc1SBen Hutchings static const struct dev_pm_ops sdhci_pci_pm_ops = { 1577f9900f15SUlf Hansson SET_SYSTEM_SLEEP_PM_OPS(sdhci_pci_suspend, sdhci_pci_resume) 1578659c9bc1SBen Hutchings SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend, 1579659c9bc1SBen Hutchings sdhci_pci_runtime_resume, NULL) 1580659c9bc1SBen Hutchings }; 1581659c9bc1SBen Hutchings 1582659c9bc1SBen Hutchings /*****************************************************************************\ 1583659c9bc1SBen Hutchings * * 1584659c9bc1SBen Hutchings * Device probing/removal * 1585659c9bc1SBen Hutchings * * 1586659c9bc1SBen Hutchings \*****************************************************************************/ 1587659c9bc1SBen Hutchings 1588659c9bc1SBen Hutchings static struct sdhci_pci_slot *sdhci_pci_probe_slot( 1589659c9bc1SBen Hutchings struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar, 1590659c9bc1SBen Hutchings int slotno) 1591659c9bc1SBen Hutchings { 1592659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1593659c9bc1SBen Hutchings struct sdhci_host *host; 1594659c9bc1SBen Hutchings int ret, bar = first_bar + slotno; 1595659c9bc1SBen Hutchings 1596659c9bc1SBen Hutchings if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { 1597659c9bc1SBen Hutchings dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar); 1598659c9bc1SBen Hutchings return ERR_PTR(-ENODEV); 1599659c9bc1SBen Hutchings } 1600659c9bc1SBen Hutchings 1601659c9bc1SBen Hutchings if (pci_resource_len(pdev, bar) < 0x100) { 1602659c9bc1SBen Hutchings dev_err(&pdev->dev, "Invalid iomem size. You may " 1603659c9bc1SBen Hutchings "experience problems.\n"); 1604659c9bc1SBen Hutchings } 1605659c9bc1SBen Hutchings 1606659c9bc1SBen Hutchings if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { 1607659c9bc1SBen Hutchings dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n"); 1608659c9bc1SBen Hutchings return ERR_PTR(-ENODEV); 1609659c9bc1SBen Hutchings } 1610659c9bc1SBen Hutchings 1611659c9bc1SBen Hutchings if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) { 1612659c9bc1SBen Hutchings dev_err(&pdev->dev, "Unknown interface. Aborting.\n"); 1613659c9bc1SBen Hutchings return ERR_PTR(-ENODEV); 1614659c9bc1SBen Hutchings } 1615659c9bc1SBen Hutchings 1616659c9bc1SBen Hutchings host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot)); 1617659c9bc1SBen Hutchings if (IS_ERR(host)) { 1618659c9bc1SBen Hutchings dev_err(&pdev->dev, "cannot allocate host\n"); 1619659c9bc1SBen Hutchings return ERR_CAST(host); 1620659c9bc1SBen Hutchings } 1621659c9bc1SBen Hutchings 1622659c9bc1SBen Hutchings slot = sdhci_priv(host); 1623659c9bc1SBen Hutchings 1624659c9bc1SBen Hutchings slot->chip = chip; 1625659c9bc1SBen Hutchings slot->host = host; 1626659c9bc1SBen Hutchings slot->rst_n_gpio = -EINVAL; 1627659c9bc1SBen Hutchings slot->cd_gpio = -EINVAL; 1628659c9bc1SBen Hutchings slot->cd_idx = -1; 1629659c9bc1SBen Hutchings 1630659c9bc1SBen Hutchings /* Retrieve platform data if there is any */ 1631659c9bc1SBen Hutchings if (*sdhci_pci_get_data) 1632659c9bc1SBen Hutchings slot->data = sdhci_pci_get_data(pdev, slotno); 1633659c9bc1SBen Hutchings 1634659c9bc1SBen Hutchings if (slot->data) { 1635659c9bc1SBen Hutchings if (slot->data->setup) { 1636659c9bc1SBen Hutchings ret = slot->data->setup(slot->data); 1637659c9bc1SBen Hutchings if (ret) { 1638659c9bc1SBen Hutchings dev_err(&pdev->dev, "platform setup failed\n"); 1639659c9bc1SBen Hutchings goto free; 1640659c9bc1SBen Hutchings } 1641659c9bc1SBen Hutchings } 1642659c9bc1SBen Hutchings slot->rst_n_gpio = slot->data->rst_n_gpio; 1643659c9bc1SBen Hutchings slot->cd_gpio = slot->data->cd_gpio; 1644659c9bc1SBen Hutchings } 1645659c9bc1SBen Hutchings 1646659c9bc1SBen Hutchings host->hw_name = "PCI"; 1647659c9bc1SBen Hutchings host->ops = &sdhci_pci_ops; 1648659c9bc1SBen Hutchings host->quirks = chip->quirks; 1649659c9bc1SBen Hutchings host->quirks2 = chip->quirks2; 1650659c9bc1SBen Hutchings 1651659c9bc1SBen Hutchings host->irq = pdev->irq; 1652659c9bc1SBen Hutchings 1653c10bc372SAndy Shevchenko ret = pcim_iomap_regions(pdev, BIT(bar), mmc_hostname(host->mmc)); 1654659c9bc1SBen Hutchings if (ret) { 1655659c9bc1SBen Hutchings dev_err(&pdev->dev, "cannot request region\n"); 1656659c9bc1SBen Hutchings goto cleanup; 1657659c9bc1SBen Hutchings } 1658659c9bc1SBen Hutchings 1659c10bc372SAndy Shevchenko host->ioaddr = pcim_iomap_table(pdev)[bar]; 1660659c9bc1SBen Hutchings 1661659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->probe_slot) { 1662659c9bc1SBen Hutchings ret = chip->fixes->probe_slot(slot); 1663659c9bc1SBen Hutchings if (ret) 1664c10bc372SAndy Shevchenko goto cleanup; 1665659c9bc1SBen Hutchings } 1666659c9bc1SBen Hutchings 1667659c9bc1SBen Hutchings if (gpio_is_valid(slot->rst_n_gpio)) { 1668c10bc372SAndy Shevchenko if (!devm_gpio_request(&pdev->dev, slot->rst_n_gpio, "eMMC_reset")) { 1669659c9bc1SBen Hutchings gpio_direction_output(slot->rst_n_gpio, 1); 1670659c9bc1SBen Hutchings slot->host->mmc->caps |= MMC_CAP_HW_RESET; 1671659c9bc1SBen Hutchings slot->hw_reset = sdhci_pci_gpio_hw_reset; 1672659c9bc1SBen Hutchings } else { 1673659c9bc1SBen Hutchings dev_warn(&pdev->dev, "failed to request rst_n_gpio\n"); 1674659c9bc1SBen Hutchings slot->rst_n_gpio = -EINVAL; 1675659c9bc1SBen Hutchings } 1676659c9bc1SBen Hutchings } 1677659c9bc1SBen Hutchings 1678659c9bc1SBen Hutchings host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ; 1679659c9bc1SBen Hutchings host->mmc->slotno = slotno; 1680659c9bc1SBen Hutchings host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; 1681659c9bc1SBen Hutchings 1682659c9bc1SBen Hutchings if (slot->cd_idx >= 0 && 1683659c9bc1SBen Hutchings mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx, 1684659c9bc1SBen Hutchings slot->cd_override_level, 0, NULL)) { 1685659c9bc1SBen Hutchings dev_warn(&pdev->dev, "failed to setup card detect gpio\n"); 1686659c9bc1SBen Hutchings slot->cd_idx = -1; 1687659c9bc1SBen Hutchings } 1688659c9bc1SBen Hutchings 1689659c9bc1SBen Hutchings ret = sdhci_add_host(host); 1690659c9bc1SBen Hutchings if (ret) 1691659c9bc1SBen Hutchings goto remove; 1692659c9bc1SBen Hutchings 1693659c9bc1SBen Hutchings sdhci_pci_add_own_cd(slot); 1694659c9bc1SBen Hutchings 1695659c9bc1SBen Hutchings /* 1696659c9bc1SBen Hutchings * Check if the chip needs a separate GPIO for card detect to wake up 1697659c9bc1SBen Hutchings * from runtime suspend. If it is not there, don't allow runtime PM. 1698659c9bc1SBen Hutchings * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure. 1699659c9bc1SBen Hutchings */ 1700659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->own_cd_for_runtime_pm && 1701659c9bc1SBen Hutchings !gpio_is_valid(slot->cd_gpio) && slot->cd_idx < 0) 1702659c9bc1SBen Hutchings chip->allow_runtime_pm = false; 1703659c9bc1SBen Hutchings 1704659c9bc1SBen Hutchings return slot; 1705659c9bc1SBen Hutchings 1706659c9bc1SBen Hutchings remove: 1707659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->remove_slot) 1708659c9bc1SBen Hutchings chip->fixes->remove_slot(slot, 0); 1709659c9bc1SBen Hutchings 1710659c9bc1SBen Hutchings cleanup: 1711659c9bc1SBen Hutchings if (slot->data && slot->data->cleanup) 1712659c9bc1SBen Hutchings slot->data->cleanup(slot->data); 1713659c9bc1SBen Hutchings 1714659c9bc1SBen Hutchings free: 1715659c9bc1SBen Hutchings sdhci_free_host(host); 1716659c9bc1SBen Hutchings 1717659c9bc1SBen Hutchings return ERR_PTR(ret); 1718659c9bc1SBen Hutchings } 1719659c9bc1SBen Hutchings 1720659c9bc1SBen Hutchings static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot) 1721659c9bc1SBen Hutchings { 1722659c9bc1SBen Hutchings int dead; 1723659c9bc1SBen Hutchings u32 scratch; 1724659c9bc1SBen Hutchings 1725659c9bc1SBen Hutchings sdhci_pci_remove_own_cd(slot); 1726659c9bc1SBen Hutchings 1727659c9bc1SBen Hutchings dead = 0; 1728659c9bc1SBen Hutchings scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS); 1729659c9bc1SBen Hutchings if (scratch == (u32)-1) 1730659c9bc1SBen Hutchings dead = 1; 1731659c9bc1SBen Hutchings 1732659c9bc1SBen Hutchings sdhci_remove_host(slot->host, dead); 1733659c9bc1SBen Hutchings 1734659c9bc1SBen Hutchings if (slot->chip->fixes && slot->chip->fixes->remove_slot) 1735659c9bc1SBen Hutchings slot->chip->fixes->remove_slot(slot, dead); 1736659c9bc1SBen Hutchings 1737659c9bc1SBen Hutchings if (slot->data && slot->data->cleanup) 1738659c9bc1SBen Hutchings slot->data->cleanup(slot->data); 1739659c9bc1SBen Hutchings 1740659c9bc1SBen Hutchings sdhci_free_host(slot->host); 1741659c9bc1SBen Hutchings } 1742659c9bc1SBen Hutchings 1743659c9bc1SBen Hutchings static void sdhci_pci_runtime_pm_allow(struct device *dev) 1744659c9bc1SBen Hutchings { 174500884b61SAdrian Hunter pm_suspend_ignore_children(dev, 1); 1746659c9bc1SBen Hutchings pm_runtime_set_autosuspend_delay(dev, 50); 1747659c9bc1SBen Hutchings pm_runtime_use_autosuspend(dev); 174800884b61SAdrian Hunter pm_runtime_allow(dev); 174900884b61SAdrian Hunter /* Stay active until mmc core scans for a card */ 175000884b61SAdrian Hunter pm_runtime_put_noidle(dev); 1751659c9bc1SBen Hutchings } 1752659c9bc1SBen Hutchings 1753659c9bc1SBen Hutchings static void sdhci_pci_runtime_pm_forbid(struct device *dev) 1754659c9bc1SBen Hutchings { 1755659c9bc1SBen Hutchings pm_runtime_forbid(dev); 1756659c9bc1SBen Hutchings pm_runtime_get_noresume(dev); 1757659c9bc1SBen Hutchings } 1758659c9bc1SBen Hutchings 1759659c9bc1SBen Hutchings static int sdhci_pci_probe(struct pci_dev *pdev, 1760659c9bc1SBen Hutchings const struct pci_device_id *ent) 1761659c9bc1SBen Hutchings { 1762659c9bc1SBen Hutchings struct sdhci_pci_chip *chip; 1763659c9bc1SBen Hutchings struct sdhci_pci_slot *slot; 1764659c9bc1SBen Hutchings 1765659c9bc1SBen Hutchings u8 slots, first_bar; 1766659c9bc1SBen Hutchings int ret, i; 1767659c9bc1SBen Hutchings 1768659c9bc1SBen Hutchings BUG_ON(pdev == NULL); 1769659c9bc1SBen Hutchings BUG_ON(ent == NULL); 1770659c9bc1SBen Hutchings 1771659c9bc1SBen Hutchings dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n", 1772659c9bc1SBen Hutchings (int)pdev->vendor, (int)pdev->device, (int)pdev->revision); 1773659c9bc1SBen Hutchings 1774659c9bc1SBen Hutchings ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots); 1775659c9bc1SBen Hutchings if (ret) 1776659c9bc1SBen Hutchings return ret; 1777659c9bc1SBen Hutchings 1778659c9bc1SBen Hutchings slots = PCI_SLOT_INFO_SLOTS(slots) + 1; 1779659c9bc1SBen Hutchings dev_dbg(&pdev->dev, "found %d slot(s)\n", slots); 1780659c9bc1SBen Hutchings if (slots == 0) 1781659c9bc1SBen Hutchings return -ENODEV; 1782659c9bc1SBen Hutchings 1783659c9bc1SBen Hutchings BUG_ON(slots > MAX_SLOTS); 1784659c9bc1SBen Hutchings 1785659c9bc1SBen Hutchings ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar); 1786659c9bc1SBen Hutchings if (ret) 1787659c9bc1SBen Hutchings return ret; 1788659c9bc1SBen Hutchings 1789659c9bc1SBen Hutchings first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK; 1790659c9bc1SBen Hutchings 1791659c9bc1SBen Hutchings if (first_bar > 5) { 1792659c9bc1SBen Hutchings dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n"); 1793659c9bc1SBen Hutchings return -ENODEV; 1794659c9bc1SBen Hutchings } 1795659c9bc1SBen Hutchings 179652ac7acfSAndy Shevchenko ret = pcim_enable_device(pdev); 1797659c9bc1SBen Hutchings if (ret) 1798659c9bc1SBen Hutchings return ret; 1799659c9bc1SBen Hutchings 180052ac7acfSAndy Shevchenko chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 180152ac7acfSAndy Shevchenko if (!chip) 180252ac7acfSAndy Shevchenko return -ENOMEM; 1803659c9bc1SBen Hutchings 1804659c9bc1SBen Hutchings chip->pdev = pdev; 1805659c9bc1SBen Hutchings chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data; 1806659c9bc1SBen Hutchings if (chip->fixes) { 1807659c9bc1SBen Hutchings chip->quirks = chip->fixes->quirks; 1808659c9bc1SBen Hutchings chip->quirks2 = chip->fixes->quirks2; 1809659c9bc1SBen Hutchings chip->allow_runtime_pm = chip->fixes->allow_runtime_pm; 1810659c9bc1SBen Hutchings } 1811659c9bc1SBen Hutchings chip->num_slots = slots; 1812659c9bc1SBen Hutchings 1813659c9bc1SBen Hutchings pci_set_drvdata(pdev, chip); 1814659c9bc1SBen Hutchings 1815659c9bc1SBen Hutchings if (chip->fixes && chip->fixes->probe) { 1816659c9bc1SBen Hutchings ret = chip->fixes->probe(chip); 1817659c9bc1SBen Hutchings if (ret) 181852ac7acfSAndy Shevchenko return ret; 1819659c9bc1SBen Hutchings } 1820659c9bc1SBen Hutchings 1821659c9bc1SBen Hutchings slots = chip->num_slots; /* Quirk may have changed this */ 1822659c9bc1SBen Hutchings 1823659c9bc1SBen Hutchings for (i = 0; i < slots; i++) { 1824659c9bc1SBen Hutchings slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i); 1825659c9bc1SBen Hutchings if (IS_ERR(slot)) { 1826659c9bc1SBen Hutchings for (i--; i >= 0; i--) 1827659c9bc1SBen Hutchings sdhci_pci_remove_slot(chip->slots[i]); 182852ac7acfSAndy Shevchenko return PTR_ERR(slot); 1829659c9bc1SBen Hutchings } 1830659c9bc1SBen Hutchings 1831659c9bc1SBen Hutchings chip->slots[i] = slot; 1832659c9bc1SBen Hutchings } 1833659c9bc1SBen Hutchings 1834659c9bc1SBen Hutchings if (chip->allow_runtime_pm) 1835659c9bc1SBen Hutchings sdhci_pci_runtime_pm_allow(&pdev->dev); 1836659c9bc1SBen Hutchings 1837659c9bc1SBen Hutchings return 0; 1838659c9bc1SBen Hutchings } 1839659c9bc1SBen Hutchings 1840659c9bc1SBen Hutchings static void sdhci_pci_remove(struct pci_dev *pdev) 1841659c9bc1SBen Hutchings { 1842659c9bc1SBen Hutchings int i; 184352ac7acfSAndy Shevchenko struct sdhci_pci_chip *chip = pci_get_drvdata(pdev); 1844659c9bc1SBen Hutchings 1845659c9bc1SBen Hutchings if (chip->allow_runtime_pm) 1846659c9bc1SBen Hutchings sdhci_pci_runtime_pm_forbid(&pdev->dev); 1847659c9bc1SBen Hutchings 1848659c9bc1SBen Hutchings for (i = 0; i < chip->num_slots; i++) 1849659c9bc1SBen Hutchings sdhci_pci_remove_slot(chip->slots[i]); 1850659c9bc1SBen Hutchings } 1851659c9bc1SBen Hutchings 1852659c9bc1SBen Hutchings static struct pci_driver sdhci_driver = { 1853659c9bc1SBen Hutchings .name = "sdhci-pci", 1854659c9bc1SBen Hutchings .id_table = pci_ids, 1855659c9bc1SBen Hutchings .probe = sdhci_pci_probe, 1856659c9bc1SBen Hutchings .remove = sdhci_pci_remove, 1857659c9bc1SBen Hutchings .driver = { 1858659c9bc1SBen Hutchings .pm = &sdhci_pci_pm_ops 1859659c9bc1SBen Hutchings }, 1860659c9bc1SBen Hutchings }; 1861659c9bc1SBen Hutchings 1862659c9bc1SBen Hutchings module_pci_driver(sdhci_driver); 1863659c9bc1SBen Hutchings 1864659c9bc1SBen Hutchings MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>"); 1865659c9bc1SBen Hutchings MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver"); 1866659c9bc1SBen Hutchings MODULE_LICENSE("GPL"); 1867