Skip to content

Commit d46ba2d

Browse files
alcooperstorulf
authored andcommitted
mmc: sdhci-brcmstb: Add support for Command Queuing (CQE)
The latest Arasan controller first used in the 7216 now supports CQE so enable this feature. Signed-off-by: Al Cooper <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent e7b5d63 commit d46ba2d

File tree

2 files changed

+133
-8
lines changed

2 files changed

+133
-8
lines changed

drivers/mmc/host/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ config MMC_SDHCI_BRCMSTB
990990
tristate "Broadcom SDIO/SD/MMC support"
991991
depends on ARCH_BRCMSTB || BMIPS_GENERIC
992992
depends on MMC_SDHCI_PLTFM
993+
select MMC_CQHCI
993994
default y
994995
help
995996
This selects support for the SDIO/SD/MMC Host Controller on

drivers/mmc/host/sdhci-brcmstb.c

Lines changed: 132 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@
1010
#include <linux/module.h>
1111
#include <linux/of.h>
1212
#include <linux/bitops.h>
13+
#include <linux/delay.h>
1314

1415
#include "sdhci-pltfm.h"
16+
#include "cqhci.h"
1517

1618
#define SDHCI_VENDOR 0x78
1719
#define SDHCI_VENDOR_ENHANCED_STRB 0x1
1820

1921
#define BRCMSTB_PRIV_FLAGS_NO_64BIT BIT(0)
2022
#define BRCMSTB_PRIV_FLAGS_BROKEN_TIMEOUT BIT(1)
2123

24+
#define SDHCI_ARASAN_CQE_BASE_ADDR 0x200
25+
2226
struct sdhci_brcmstb_priv {
2327
void __iomem *cfg_regs;
28+
bool has_cqe;
2429
};
2530

2631
struct brcmstb_match_priv {
2732
void (*hs400es)(struct mmc_host *mmc, struct mmc_ios *ios);
33+
struct sdhci_ops *ops;
2834
unsigned int flags;
2935
};
3036

@@ -44,28 +50,74 @@ static void sdhci_brcmstb_hs400es(struct mmc_host *mmc, struct mmc_ios *ios)
4450
writel(reg, host->ioaddr + SDHCI_VENDOR);
4551
}
4652

47-
static const struct sdhci_ops sdhci_brcmstb_ops = {
53+
static void sdhci_brcmstb_set_clock(struct sdhci_host *host, unsigned int clock)
54+
{
55+
u16 clk;
56+
57+
host->mmc->actual_clock = 0;
58+
59+
clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
60+
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
61+
62+
if (clock == 0)
63+
return;
64+
65+
sdhci_enable_clk(host, clk);
66+
}
67+
68+
static void sdhci_brcmstb_dumpregs(struct mmc_host *mmc)
69+
{
70+
sdhci_dumpregs(mmc_priv(mmc));
71+
}
72+
73+
static void sdhci_brcmstb_cqe_enable(struct mmc_host *mmc)
74+
{
75+
struct sdhci_host *host = mmc_priv(mmc);
76+
u32 reg;
77+
78+
reg = sdhci_readl(host, SDHCI_PRESENT_STATE);
79+
while (reg & SDHCI_DATA_AVAILABLE) {
80+
sdhci_readl(host, SDHCI_BUFFER);
81+
reg = sdhci_readl(host, SDHCI_PRESENT_STATE);
82+
}
83+
84+
sdhci_cqe_enable(mmc);
85+
}
86+
87+
static const struct cqhci_host_ops sdhci_brcmstb_cqhci_ops = {
88+
.enable = sdhci_brcmstb_cqe_enable,
89+
.disable = sdhci_cqe_disable,
90+
.dumpregs = sdhci_brcmstb_dumpregs,
91+
};
92+
93+
static struct sdhci_ops sdhci_brcmstb_ops = {
4894
.set_clock = sdhci_set_clock,
4995
.set_bus_width = sdhci_set_bus_width,
5096
.reset = sdhci_reset,
5197
.set_uhs_signaling = sdhci_set_uhs_signaling,
5298
};
5399

54-
static const struct sdhci_pltfm_data sdhci_brcmstb_pdata = {
55-
.ops = &sdhci_brcmstb_ops,
100+
static struct sdhci_ops sdhci_brcmstb_ops_7216 = {
101+
.set_clock = sdhci_brcmstb_set_clock,
102+
.set_bus_width = sdhci_set_bus_width,
103+
.reset = sdhci_reset,
104+
.set_uhs_signaling = sdhci_set_uhs_signaling,
56105
};
57106

58-
static const struct brcmstb_match_priv match_priv_7425 = {
107+
static struct brcmstb_match_priv match_priv_7425 = {
59108
.flags = BRCMSTB_PRIV_FLAGS_NO_64BIT |
60109
BRCMSTB_PRIV_FLAGS_BROKEN_TIMEOUT,
110+
.ops = &sdhci_brcmstb_ops,
61111
};
62112

63-
static const struct brcmstb_match_priv match_priv_7445 = {
113+
static struct brcmstb_match_priv match_priv_7445 = {
64114
.flags = BRCMSTB_PRIV_FLAGS_BROKEN_TIMEOUT,
115+
.ops = &sdhci_brcmstb_ops,
65116
};
66117

67118
static const struct brcmstb_match_priv match_priv_7216 = {
68119
.hs400es = sdhci_brcmstb_hs400es,
120+
.ops = &sdhci_brcmstb_ops_7216,
69121
};
70122

71123
static const struct of_device_id sdhci_brcm_of_match[] = {
@@ -75,20 +127,85 @@ static const struct of_device_id sdhci_brcm_of_match[] = {
75127
{},
76128
};
77129

130+
static u32 sdhci_brcmstb_cqhci_irq(struct sdhci_host *host, u32 intmask)
131+
{
132+
int cmd_error = 0;
133+
int data_error = 0;
134+
135+
if (!sdhci_cqe_irq(host, intmask, &cmd_error, &data_error))
136+
return intmask;
137+
138+
cqhci_irq(host->mmc, intmask, cmd_error, data_error);
139+
140+
return 0;
141+
}
142+
143+
static int sdhci_brcmstb_add_host(struct sdhci_host *host,
144+
struct sdhci_brcmstb_priv *priv)
145+
{
146+
struct cqhci_host *cq_host;
147+
bool dma64;
148+
int ret;
149+
150+
if (!priv->has_cqe)
151+
return sdhci_add_host(host);
152+
153+
dev_dbg(mmc_dev(host->mmc), "CQE is enabled\n");
154+
host->mmc->caps2 |= MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD;
155+
ret = sdhci_setup_host(host);
156+
if (ret)
157+
return ret;
158+
159+
cq_host = devm_kzalloc(mmc_dev(host->mmc),
160+
sizeof(*cq_host), GFP_KERNEL);
161+
if (!cq_host) {
162+
ret = -ENOMEM;
163+
goto cleanup;
164+
}
165+
166+
cq_host->mmio = host->ioaddr + SDHCI_ARASAN_CQE_BASE_ADDR;
167+
cq_host->ops = &sdhci_brcmstb_cqhci_ops;
168+
169+
dma64 = host->flags & SDHCI_USE_64_BIT_DMA;
170+
if (dma64) {
171+
dev_dbg(mmc_dev(host->mmc), "Using 64 bit DMA\n");
172+
cq_host->caps |= CQHCI_TASK_DESC_SZ_128;
173+
cq_host->quirks |= CQHCI_QUIRK_SHORT_TXFR_DESC_SZ;
174+
}
175+
176+
ret = cqhci_init(cq_host, host->mmc, dma64);
177+
if (ret)
178+
goto cleanup;
179+
180+
ret = __sdhci_add_host(host);
181+
if (ret)
182+
goto cleanup;
183+
184+
return 0;
185+
186+
cleanup:
187+
sdhci_cleanup_host(host);
188+
return ret;
189+
}
190+
78191
static int sdhci_brcmstb_probe(struct platform_device *pdev)
79192
{
80193
const struct brcmstb_match_priv *match_priv;
194+
struct sdhci_pltfm_data brcmstb_pdata;
81195
struct sdhci_pltfm_host *pltfm_host;
82196
const struct of_device_id *match;
83197
struct sdhci_brcmstb_priv *priv;
84198
struct sdhci_host *host;
85199
struct resource *iomem;
200+
bool has_cqe = false;
86201
struct clk *clk;
87202
int res;
88203

89204
match = of_match_node(sdhci_brcm_of_match, pdev->dev.of_node);
90205
match_priv = match->data;
91206

207+
dev_dbg(&pdev->dev, "Probe found match for %s\n", match->compatible);
208+
92209
clk = devm_clk_get(&pdev->dev, NULL);
93210
if (IS_ERR(clk)) {
94211
if (PTR_ERR(clk) == -EPROBE_DEFER)
@@ -100,7 +217,13 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev)
100217
if (res)
101218
return res;
102219

103-
host = sdhci_pltfm_init(pdev, &sdhci_brcmstb_pdata,
220+
memset(&brcmstb_pdata, 0, sizeof(brcmstb_pdata));
221+
if (device_property_read_bool(&pdev->dev, "supports-cqe")) {
222+
has_cqe = true;
223+
match_priv->ops->irq = sdhci_brcmstb_cqhci_irq;
224+
}
225+
brcmstb_pdata.ops = match_priv->ops;
226+
host = sdhci_pltfm_init(pdev, &brcmstb_pdata,
104227
sizeof(struct sdhci_brcmstb_priv));
105228
if (IS_ERR(host)) {
106229
res = PTR_ERR(host);
@@ -109,6 +232,7 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev)
109232

110233
pltfm_host = sdhci_priv(host);
111234
priv = sdhci_pltfm_priv(pltfm_host);
235+
priv->has_cqe = has_cqe;
112236

113237
/* Map in the non-standard CFG registers */
114238
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -141,13 +265,13 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev)
141265
host->caps &= ~SDHCI_CAN_64BIT;
142266
host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
143267
host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
144-
SDHCI_SUPPORT_DDR50);
268+
SDHCI_SUPPORT_DDR50);
145269
host->quirks |= SDHCI_QUIRK_MISSING_CAPS;
146270

147271
if (match_priv->flags & BRCMSTB_PRIV_FLAGS_BROKEN_TIMEOUT)
148272
host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
149273

150-
res = sdhci_add_host(host);
274+
res = sdhci_brcmstb_add_host(host, priv);
151275
if (res)
152276
goto err;
153277

0 commit comments

Comments
 (0)