17 #include <linux/module.h>
18 #include <linux/pci.h>
20 #include <linux/slab.h>
21 #include <linux/device.h>
34 #define PCI_DEVICE_ID_INTEL_PCH_SDIO0 0x8809
35 #define PCI_DEVICE_ID_INTEL_PCH_SDIO1 0x880a
41 #define PCI_SDHCI_IFPIO 0x00
42 #define PCI_SDHCI_IFDMA 0x01
43 #define PCI_SDHCI_IFVENDOR 0x02
45 #define PCI_SLOT_INFO 0x40
46 #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
47 #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
131 .probe = ricoh_probe,
138 .probe_slot = ricoh_mmc_probe_slot,
139 .resume = ricoh_mmc_resume,
190 #ifdef CONFIG_PM_RUNTIME
208 if (!gpio_is_valid(gpio))
236 dev_warn(&slot->
chip->pdev->dev,
"failed to setup card detect wake up\n");
243 if (gpio_is_valid(slot->
cd_gpio))
249 static inline void sdhci_pci_add_own_cd(
struct sdhci_pci_slot *slot)
253 static inline void sdhci_pci_remove_own_cd(
struct sdhci_pci_slot *slot)
275 .probe_slot = mrst_hc_probe_slot,
280 .probe = mrst_hc_probe,
285 .allow_runtime_pm =
true,
291 .allow_runtime_pm =
true,
292 .probe_slot = mfd_sdio_probe_slot,
297 .allow_runtime_pm =
true,
298 .probe_slot = mfd_emmc_probe_slot,
303 .probe_slot = pch_hc_probe_slot,
307 #define O2_SD_LOCK_WP 0xD3
308 #define O2_SD_MULTI_VCC3V 0xEE
309 #define O2_SD_CLKREQ 0xEC
310 #define O2_SD_CAPS 0xE0
311 #define O2_SD_ADMA1 0xE2
312 #define O2_SD_ADMA2 0xE7
313 #define O2_SD_INF_MOD 0xF1
320 switch (chip->
pdev->device) {
379 ret = pci_read_config_byte(chip->
pdev, 0xAE, &scratch);
392 ret = pci_write_config_byte(chip->
pdev, 0xAE, scratch);
404 if (chip->
pdev->revision == 0) {
434 mmcdev, sd_dev)) !=
NULL) {
437 (chip->
pdev->bus == sd_dev->
bus))
444 "secondary interface.\n");
453 ret = jmicron_pmos(chip, 1);
455 dev_err(&chip->
pdev->dev,
"Failure enabling card power\n");
467 static void jmicron_enable_mmc(
struct sdhci_host *host,
int on)
483 if (slot->
chip->pdev->revision == 0) {
514 jmicron_enable_mmc(slot->
host, 1);
528 jmicron_enable_mmc(slot->
host, 0);
538 jmicron_enable_mmc(chip->
slots[i]->host, 0);
551 jmicron_enable_mmc(chip->
slots[i]->host, 1);
554 ret = jmicron_pmos(chip, 1);
556 dev_err(&chip->
pdev->dev,
"Failure enabling card power\n");
568 .probe = jmicron_probe,
570 .probe_slot = jmicron_probe_slot,
571 .remove_slot = jmicron_remove_slot,
573 .suspend = jmicron_suspend,
574 .resume = jmicron_resume,
578 #define SYSKT_CTRL 0x200
579 #define SYSKT_RDFIFO_STAT 0x204
580 #define SYSKT_WRFIFO_STAT 0x208
581 #define SYSKT_POWER_DATA 0x20c
582 #define SYSKT_POWER_330 0xef
583 #define SYSKT_POWER_300 0xf8
584 #define SYSKT_POWER_184 0xcc
585 #define SYSKT_POWER_CMD 0x20d
586 #define SYSKT_POWER_START (1 << 7)
587 #define SYSKT_POWER_STATUS 0x20e
588 #define SYSKT_POWER_STATUS_OK (1 << 0)
589 #define SYSKT_BOARD_REV 0x210
590 #define SYSKT_CHIP_REV 0x211
591 #define SYSKT_CONF_DATA 0x212
592 #define SYSKT_CONF_DATA_1V8 (1 << 2)
593 #define SYSKT_CONF_DATA_2V5 (1 << 1)
594 #define SYSKT_CONF_DATA_3V3 (1 << 0)
599 chip->
pdev->class &= ~0x0000FF;
611 dev_info(&slot->
chip->pdev->dev,
"SysKonnect CardBus2SDIO, "
612 "board rev %d.%d, chip rev %d.%d\n",
613 board_rev >> 4, board_rev & 0xf,
614 chip_rev >> 4, chip_rev & 0xf);
615 if (chip_rev >= 0x20)
630 "power regulator never stabilized");
640 .probe = syskt_probe,
641 .probe_slot = syskt_probe_slot,
646 if (chip->
pdev->revision == 0x10)
912 static int sdhci_pci_enable_dma(
struct sdhci_host *host)
918 slot = sdhci_priv(host);
919 pdev = slot->
chip->pdev;
924 dev_warn(&pdev->
dev,
"Will use DMA mode even though HW "
925 "doesn't fully claim to support it.\n");
962 static void sdhci_pci_hw_reset(
struct sdhci_host *host)
967 if (!gpio_is_valid(rst_n_gpio))
977 static struct sdhci_ops sdhci_pci_ops = {
978 .enable_dma = sdhci_pci_enable_dma,
979 .platform_8bit_width = sdhci_pci_8bit_width,
980 .hw_reset = sdhci_pci_hw_reset,
1000 chip = pci_get_drvdata(pdev);
1009 ret = sdhci_suspend_host(slot->
host);
1012 goto err_pci_suspend;
1014 slot_pm_flags = slot->
host->mmc->pm_flags;
1016 sdhci_enable_irq_wakeups(slot->
host);
1018 pm_flags |= slot_pm_flags;
1022 ret = chip->
fixes->suspend(chip);
1024 goto err_pci_suspend;
1044 sdhci_resume_host(chip->
slots[i]->host);
1055 chip = pci_get_drvdata(pdev);
1066 ret = chip->
fixes->resume(chip);
1076 ret = sdhci_resume_host(slot->
host);
1086 #define sdhci_pci_suspend NULL
1087 #define sdhci_pci_resume NULL
1091 #ifdef CONFIG_PM_RUNTIME
1100 chip = pci_get_drvdata(pdev);
1109 ret = sdhci_runtime_suspend_host(slot->
host);
1112 goto err_pci_runtime_suspend;
1116 ret = chip->
fixes->suspend(chip);
1118 goto err_pci_runtime_suspend;
1123 err_pci_runtime_suspend:
1125 sdhci_runtime_resume_host(chip->
slots[i]->host);
1136 chip = pci_get_drvdata(pdev);
1141 ret = chip->
fixes->resume(chip);
1151 ret = sdhci_runtime_resume_host(slot->
host);
1166 #define sdhci_pci_runtime_suspend NULL
1167 #define sdhci_pci_runtime_resume NULL
1168 #define sdhci_pci_runtime_idle NULL
1172 static const struct dev_pm_ops sdhci_pci_pm_ops = {
1192 int ret, bar = first_bar + slotno;
1195 dev_err(&pdev->
dev,
"BAR %d is not iomem. Aborting.\n", bar);
1200 dev_err(&pdev->
dev,
"Invalid iomem size. You may "
1201 "experience problems.\n");
1205 dev_err(&pdev->
dev,
"Vendor specific interface. Aborting.\n");
1210 dev_err(&pdev->
dev,
"Unknown interface. Aborting.\n");
1216 dev_err(&pdev->
dev,
"cannot allocate host\n");
1217 return ERR_CAST(host);
1220 slot = sdhci_priv(host);
1233 if (slot->
data->setup) {
1234 ret = slot->
data->setup(slot->
data);
1236 dev_err(&pdev->
dev,
"platform setup failed\n");
1245 host->
ops = &sdhci_pci_ops;
1253 dev_err(&pdev->
dev,
"cannot request region\n");
1259 dev_err(&pdev->
dev,
"failed to remap registers\n");
1264 if (chip->
fixes && chip->
fixes->probe_slot) {
1265 ret = chip->
fixes->probe_slot(slot);
1275 dev_warn(&pdev->
dev,
"failed to request rst_n_gpio\n");
1286 sdhci_pci_add_own_cd(slot);
1295 chip->
fixes->remove_slot(slot, 0);
1304 if (slot->
data && slot->
data->cleanup)
1310 return ERR_PTR(ret);
1318 sdhci_pci_remove_own_cd(slot);
1322 if (scratch == (
u32)-1)
1330 if (slot->
chip->fixes && slot->
chip->fixes->remove_slot)
1331 slot->
chip->fixes->remove_slot(slot, dead);
1333 if (slot->
data && slot->
data->cleanup)
1343 pm_runtime_put_noidle(dev);
1346 pm_runtime_use_autosuspend(dev);
1347 pm_suspend_ignore_children(dev, 1);
1353 pm_runtime_get_noresume(dev);
1368 dev_info(&pdev->
dev,
"SDHCI controller found [%04x:%04x] (rev %x)\n",
1376 dev_dbg(&pdev->
dev,
"found %d slot(s)\n", slots);
1382 ret = pci_read_config_byte(pdev,
PCI_SLOT_INFO, &first_bar);
1388 if (first_bar > 5) {
1389 dev_err(&pdev->
dev,
"Invalid first BAR. Aborting.\n");
1412 pci_set_drvdata(pdev, chip);
1415 ret = chip->
fixes->probe(chip);
1422 for (i = 0; i <
slots; i++) {
1423 slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
1425 for (i--; i >= 0; i--)
1426 sdhci_pci_remove_slot(chip->
slots[i]);
1427 ret = PTR_ERR(slot);
1435 sdhci_pci_runtime_pm_allow(&pdev->
dev);
1440 pci_set_drvdata(pdev,
NULL);
1453 chip = pci_get_drvdata(pdev);
1457 sdhci_pci_runtime_pm_forbid(&pdev->
dev);
1460 sdhci_pci_remove_slot(chip->
slots[i]);
1462 pci_set_drvdata(pdev,
NULL);
1470 .name =
"sdhci-pci",
1471 .id_table = pci_ids,
1472 .probe = sdhci_pci_probe,
1475 .pm = &sdhci_pci_pm_ops