1 From e72f42ebc9a236c023f8027a37c9351d58e28b05 Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Wed, 8 Jan 2025 16:02:27 +0000
4 Subject: [PATCH] mmc: use downstream DT property to modify CQE and/or SD CQ
7 Implement a tristate-style option for "supports-cqe". If the property is
8 absent or zero, disable CQ completely. For 1, enable CQ unconditionally
9 for eMMC cards, and known-good SD cards. For 2, enable for eMMC cards,
10 and all SD cards that are not known-bad.
12 The sdhci-brcmstb driver needs to know about the tristate as its probe
13 sequence would otherwise override a disable in mmc_of_parse().
15 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
17 drivers/mmc/core/host.c | 11 ++++++++++-
18 drivers/mmc/core/sd.c | 4 ++--
19 drivers/mmc/host/sdhci-brcmstb.c | 6 ++++--
20 include/linux/mmc/host.h | 1 +
21 4 files changed, 17 insertions(+), 5 deletions(-)
23 --- a/drivers/mmc/core/host.c
24 +++ b/drivers/mmc/core/host.c
25 @@ -275,7 +275,7 @@ EXPORT_SYMBOL(mmc_of_parse_clk_phase);
26 int mmc_of_parse(struct mmc_host *host)
28 struct device *dev = host->parent;
29 - u32 bus_width, drv_type, cd_debounce_delay_ms;
30 + u32 bus_width, drv_type, cd_debounce_delay_ms, cq_allow;
33 if (!dev || !dev_fwnode(dev))
34 @@ -410,6 +410,15 @@ int mmc_of_parse(struct mmc_host *host)
35 host->caps2 &= ~(MMC_CAP2_HS400_1_8V | MMC_CAP2_HS400_1_2V |
40 + * Downstream property - if a u32 and 2 instead of a bool,
41 + * trust most A2 SD cards claiming CQ support.
43 + device_property_read_u32(dev, "supports-cqe", &cq_allow);
45 + host->caps2 |= MMC_CAP2_SD_CQE_PERMISSIVE;
47 /* Must be after "non-removable" check */
48 if (device_property_read_u32(dev, "fixed-emmc-driver-type", &drv_type) == 0) {
49 if (host->caps & MMC_CAP_NONREMOVABLE)
50 --- a/drivers/mmc/core/sd.c
51 +++ b/drivers/mmc/core/sd.c
52 @@ -1506,8 +1506,8 @@ cont:
56 - /* Disallow command queueing on unvetted cards */
57 - if (!mmc_card_working_sd_cq(card))
58 + /* Disallow command queueing on unvetted cards unless overridden */
59 + if (!(host->caps2 & MMC_CAP2_SD_CQE_PERMISSIVE) && !mmc_card_working_sd_cq(card))
60 card->ext_csd.cmdq_support = false;
62 /* Enable command queueing if supported */
63 --- a/drivers/mmc/host/sdhci-brcmstb.c
64 +++ b/drivers/mmc/host/sdhci-brcmstb.c
65 @@ -511,7 +511,7 @@ static int sdhci_brcmstb_probe(struct pl
66 struct sdhci_pltfm_host *pltfm_host;
67 const struct of_device_id *match;
68 struct sdhci_brcmstb_priv *priv;
69 - u32 actual_clock_mhz;
70 + u32 actual_clock_mhz, cqe;
71 struct sdhci_host *host;
72 struct resource *iomem;
73 bool no_pinctrl = false;
74 @@ -540,7 +540,9 @@ static int sdhci_brcmstb_probe(struct pl
75 pltfm_host->clk = clk;
77 priv = sdhci_pltfm_priv(pltfm_host);
78 - if (device_property_read_bool(&pdev->dev, "supports-cqe")) {
80 + device_property_read_u32(&pdev->dev, "supports-cqe", &cqe);
82 priv->flags |= BRCMSTB_PRIV_FLAGS_HAS_CQE;
83 match_priv->ops->irq = sdhci_brcmstb_cqhci_irq;
85 --- a/include/linux/mmc/host.h
86 +++ b/include/linux/mmc/host.h
87 @@ -427,6 +427,7 @@ struct mmc_host {
88 #define MMC_CAP2_CRYPTO 0
90 #define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT entry at a non-standard location */
91 +#define MMC_CAP2_SD_CQE_PERMISSIVE (1 << 31) /* Ignore allow-list for CQ capable SD card detection */
93 int fixed_drv_type; /* fixed driver type for non-removable media */