Skip to content

Commit 8ee82bd

Browse files
ahunter6storulf
authored andcommitted
mmc: sdhci-pci: Add CQHCI support for Intel GLK
Add CQHCI initialization and implement CQHCI operations for Intel GLK. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Tested-by: Linus Walleij <linus.walleij@linaro.org>
1 parent a408022 commit 8ee82bd

File tree

2 files changed

+155
-1
lines changed

2 files changed

+155
-1
lines changed

drivers/mmc/host/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ config MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
8181
config MMC_SDHCI_PCI
8282
tristate "SDHCI support on PCI bus"
8383
depends on MMC_SDHCI && PCI
84+
select MMC_CQHCI
8485
help
8586
This selects the PCI Secure Digital Host Controller Interface.
8687
Most controllers found today are PCI devices.

drivers/mmc/host/sdhci-pci-core.c

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <linux/mmc/sdhci-pci-data.h>
3131
#include <linux/acpi.h>
3232

33+
#include "cqhci.h"
34+
3335
#include "sdhci.h"
3436
#include "sdhci-pci.h"
3537

@@ -116,6 +118,28 @@ int sdhci_pci_resume_host(struct sdhci_pci_chip *chip)
116118

117119
return 0;
118120
}
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+
}
119143
#endif
120144

121145
#ifdef CONFIG_PM
@@ -166,8 +190,48 @@ static int sdhci_pci_runtime_resume_host(struct sdhci_pci_chip *chip)
166190

167191
return 0;
168192
}
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+
}
169215
#endif
170216

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+
171235
/*****************************************************************************\
172236
* *
173237
* Hardware specific quirk handling *
@@ -583,6 +647,18 @@ static const struct sdhci_ops sdhci_intel_byt_ops = {
583647
.voltage_switch = sdhci_intel_voltage_switch,
584648
};
585649

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+
586662
static void byt_read_dsm(struct sdhci_pci_slot *slot)
587663
{
588664
struct intel_host *intel_host = sdhci_pci_priv(slot);
@@ -612,12 +688,80 @@ static int glk_emmc_probe_slot(struct sdhci_pci_slot *slot)
612688
{
613689
int ret = byt_emmc_probe_slot(slot);
614690

691+
slot->host->mmc->caps2 |= MMC_CAP2_CQE;
692+
615693
if (slot->chip->pdev->device != PCI_DEVICE_ID_INTEL_GLK_EMMC) {
616694
slot->host->mmc->caps2 |= MMC_CAP2_HS400_ES,
617695
slot->host->mmc_host_ops.hs400_enhanced_strobe =
618696
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;
619743
}
620744

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);
621765
return ret;
622766
}
623767

@@ -699,11 +843,20 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
699843
static const struct sdhci_pci_fixes sdhci_intel_glk_emmc = {
700844
.allow_runtime_pm = true,
701845
.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
702855
.quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
703856
.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
704857
SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 |
705858
SDHCI_QUIRK2_STOP_WITH_TC,
706-
.ops = &sdhci_intel_byt_ops,
859+
.ops = &sdhci_intel_glk_ops,
707860
.priv_size = sizeof(struct intel_host),
708861
};
709862

0 commit comments

Comments
 (0)