|
30 | 30 | #include <linux/mmc/sdhci-pci-data.h>
|
31 | 31 | #include <linux/acpi.h>
|
32 | 32 |
|
| 33 | +#include "cqhci.h" |
| 34 | + |
33 | 35 | #include "sdhci.h"
|
34 | 36 | #include "sdhci-pci.h"
|
35 | 37 |
|
@@ -116,6 +118,28 @@ int sdhci_pci_resume_host(struct sdhci_pci_chip *chip)
|
116 | 118 |
|
117 | 119 | return 0;
|
118 | 120 | }
|
| 121 | + |
| 122 | +static int sdhci_cqhci_suspend(struct sdhci_pci_chip *chip) |
| 123 | +{ |
| 124 | + int ret; |
| 125 | + |
| 126 | + ret = cqhci_suspend(chip->slots[0]->host->mmc); |
| 127 | + if (ret) |
| 128 | + return ret; |
| 129 | + |
| 130 | + return sdhci_pci_suspend_host(chip); |
| 131 | +} |
| 132 | + |
| 133 | +static int sdhci_cqhci_resume(struct sdhci_pci_chip *chip) |
| 134 | +{ |
| 135 | + int ret; |
| 136 | + |
| 137 | + ret = sdhci_pci_resume_host(chip); |
| 138 | + if (ret) |
| 139 | + return ret; |
| 140 | + |
| 141 | + return cqhci_resume(chip->slots[0]->host->mmc); |
| 142 | +} |
119 | 143 | #endif
|
120 | 144 |
|
121 | 145 | #ifdef CONFIG_PM
|
@@ -166,8 +190,48 @@ static int sdhci_pci_runtime_resume_host(struct sdhci_pci_chip *chip)
|
166 | 190 |
|
167 | 191 | return 0;
|
168 | 192 | }
|
| 193 | + |
| 194 | +static int sdhci_cqhci_runtime_suspend(struct sdhci_pci_chip *chip) |
| 195 | +{ |
| 196 | + int ret; |
| 197 | + |
| 198 | + ret = cqhci_suspend(chip->slots[0]->host->mmc); |
| 199 | + if (ret) |
| 200 | + return ret; |
| 201 | + |
| 202 | + return sdhci_pci_runtime_suspend_host(chip); |
| 203 | +} |
| 204 | + |
| 205 | +static int sdhci_cqhci_runtime_resume(struct sdhci_pci_chip *chip) |
| 206 | +{ |
| 207 | + int ret; |
| 208 | + |
| 209 | + ret = sdhci_pci_runtime_resume_host(chip); |
| 210 | + if (ret) |
| 211 | + return ret; |
| 212 | + |
| 213 | + return cqhci_resume(chip->slots[0]->host->mmc); |
| 214 | +} |
169 | 215 | #endif
|
170 | 216 |
|
| 217 | +static u32 sdhci_cqhci_irq(struct sdhci_host *host, u32 intmask) |
| 218 | +{ |
| 219 | + int cmd_error = 0; |
| 220 | + int data_error = 0; |
| 221 | + |
| 222 | + if (!sdhci_cqe_irq(host, intmask, &cmd_error, &data_error)) |
| 223 | + return intmask; |
| 224 | + |
| 225 | + cqhci_irq(host->mmc, intmask, cmd_error, data_error); |
| 226 | + |
| 227 | + return 0; |
| 228 | +} |
| 229 | + |
| 230 | +static void sdhci_pci_dumpregs(struct mmc_host *mmc) |
| 231 | +{ |
| 232 | + sdhci_dumpregs(mmc_priv(mmc)); |
| 233 | +} |
| 234 | + |
171 | 235 | /*****************************************************************************\
|
172 | 236 | * *
|
173 | 237 | * Hardware specific quirk handling *
|
@@ -583,6 +647,18 @@ static const struct sdhci_ops sdhci_intel_byt_ops = {
|
583 | 647 | .voltage_switch = sdhci_intel_voltage_switch,
|
584 | 648 | };
|
585 | 649 |
|
| 650 | +static const struct sdhci_ops sdhci_intel_glk_ops = { |
| 651 | + .set_clock = sdhci_set_clock, |
| 652 | + .set_power = sdhci_intel_set_power, |
| 653 | + .enable_dma = sdhci_pci_enable_dma, |
| 654 | + .set_bus_width = sdhci_set_bus_width, |
| 655 | + .reset = sdhci_reset, |
| 656 | + .set_uhs_signaling = sdhci_set_uhs_signaling, |
| 657 | + .hw_reset = sdhci_pci_hw_reset, |
| 658 | + .voltage_switch = sdhci_intel_voltage_switch, |
| 659 | + .irq = sdhci_cqhci_irq, |
| 660 | +}; |
| 661 | + |
586 | 662 | static void byt_read_dsm(struct sdhci_pci_slot *slot)
|
587 | 663 | {
|
588 | 664 | struct intel_host *intel_host = sdhci_pci_priv(slot);
|
@@ -612,12 +688,80 @@ static int glk_emmc_probe_slot(struct sdhci_pci_slot *slot)
|
612 | 688 | {
|
613 | 689 | int ret = byt_emmc_probe_slot(slot);
|
614 | 690 |
|
| 691 | + slot->host->mmc->caps2 |= MMC_CAP2_CQE; |
| 692 | + |
615 | 693 | if (slot->chip->pdev->device != PCI_DEVICE_ID_INTEL_GLK_EMMC) {
|
616 | 694 | slot->host->mmc->caps2 |= MMC_CAP2_HS400_ES,
|
617 | 695 | slot->host->mmc_host_ops.hs400_enhanced_strobe =
|
618 | 696 | intel_hs400_enhanced_strobe;
|
| 697 | + slot->host->mmc->caps2 |= MMC_CAP2_CQE_DCMD; |
| 698 | + } |
| 699 | + |
| 700 | + return ret; |
| 701 | +} |
| 702 | + |
| 703 | +static void glk_cqe_enable(struct mmc_host *mmc) |
| 704 | +{ |
| 705 | + struct sdhci_host *host = mmc_priv(mmc); |
| 706 | + u32 reg; |
| 707 | + |
| 708 | + /* |
| 709 | + * CQE gets stuck if it sees Buffer Read Enable bit set, which can be |
| 710 | + * the case after tuning, so ensure the buffer is drained. |
| 711 | + */ |
| 712 | + reg = sdhci_readl(host, SDHCI_PRESENT_STATE); |
| 713 | + while (reg & SDHCI_DATA_AVAILABLE) { |
| 714 | + sdhci_readl(host, SDHCI_BUFFER); |
| 715 | + reg = sdhci_readl(host, SDHCI_PRESENT_STATE); |
| 716 | + } |
| 717 | + |
| 718 | + sdhci_cqe_enable(mmc); |
| 719 | +} |
| 720 | + |
| 721 | +static const struct cqhci_host_ops glk_cqhci_ops = { |
| 722 | + .enable = glk_cqe_enable, |
| 723 | + .disable = sdhci_cqe_disable, |
| 724 | + .dumpregs = sdhci_pci_dumpregs, |
| 725 | +}; |
| 726 | + |
| 727 | +static int glk_emmc_add_host(struct sdhci_pci_slot *slot) |
| 728 | +{ |
| 729 | + struct device *dev = &slot->chip->pdev->dev; |
| 730 | + struct sdhci_host *host = slot->host; |
| 731 | + struct cqhci_host *cq_host; |
| 732 | + bool dma64; |
| 733 | + int ret; |
| 734 | + |
| 735 | + ret = sdhci_setup_host(host); |
| 736 | + if (ret) |
| 737 | + return ret; |
| 738 | + |
| 739 | + cq_host = devm_kzalloc(dev, sizeof(*cq_host), GFP_KERNEL); |
| 740 | + if (!cq_host) { |
| 741 | + ret = -ENOMEM; |
| 742 | + goto cleanup; |
619 | 743 | }
|
620 | 744 |
|
| 745 | + cq_host->mmio = host->ioaddr + 0x200; |
| 746 | + cq_host->quirks |= CQHCI_QUIRK_SHORT_TXFR_DESC_SZ; |
| 747 | + cq_host->ops = &glk_cqhci_ops; |
| 748 | + |
| 749 | + dma64 = host->flags & SDHCI_USE_64_BIT_DMA; |
| 750 | + if (dma64) |
| 751 | + cq_host->caps |= CQHCI_TASK_DESC_SZ_128; |
| 752 | + |
| 753 | + ret = cqhci_init(cq_host, host->mmc, dma64); |
| 754 | + if (ret) |
| 755 | + goto cleanup; |
| 756 | + |
| 757 | + ret = __sdhci_add_host(host); |
| 758 | + if (ret) |
| 759 | + goto cleanup; |
| 760 | + |
| 761 | + return 0; |
| 762 | + |
| 763 | +cleanup: |
| 764 | + sdhci_cleanup_host(host); |
621 | 765 | return ret;
|
622 | 766 | }
|
623 | 767 |
|
@@ -699,11 +843,20 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
|
699 | 843 | static const struct sdhci_pci_fixes sdhci_intel_glk_emmc = {
|
700 | 844 | .allow_runtime_pm = true,
|
701 | 845 | .probe_slot = glk_emmc_probe_slot,
|
| 846 | + .add_host = glk_emmc_add_host, |
| 847 | +#ifdef CONFIG_PM_SLEEP |
| 848 | + .suspend = sdhci_cqhci_suspend, |
| 849 | + .resume = sdhci_cqhci_resume, |
| 850 | +#endif |
| 851 | +#ifdef CONFIG_PM |
| 852 | + .runtime_suspend = sdhci_cqhci_runtime_suspend, |
| 853 | + .runtime_resume = sdhci_cqhci_runtime_resume, |
| 854 | +#endif |
702 | 855 | .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
|
703 | 856 | .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
|
704 | 857 | SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 |
|
705 | 858 | SDHCI_QUIRK2_STOP_WITH_TC,
|
706 |
| - .ops = &sdhci_intel_byt_ops, |
| 859 | + .ops = &sdhci_intel_glk_ops, |
707 | 860 | .priv_size = sizeof(struct intel_host),
|
708 | 861 | };
|
709 | 862 |
|
|
0 commit comments