Skip to content

Commit 9c7e705

Browse files
committed
Merge tag 'mmc-v5.15-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc
Pull MMC fixes from Ulf Hansson: "A couple of MMC host fixes: - meson-gx: Fix read/write access for dram-access-quirk - sdhci-of-at91: Fix calibration sequence" * tag 'mmc-v5.15-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc: mmc: meson-gx: do not use memcpy_to/fromio for dram-access-quirk mmc: sdhci-of-at91: replace while loop with read_poll_timeout mmc: sdhci-of-at91: wait for calibration done before proceed
2 parents 0068dc8 + 8a38a4d commit 9c7e705

File tree

2 files changed

+70
-25
lines changed

2 files changed

+70
-25
lines changed

drivers/mmc/host/meson-gx-mmc.c

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ static void meson_mmc_desc_chain_transfer(struct mmc_host *mmc, u32 cmd_cfg)
746746
writel(start, host->regs + SD_EMMC_START);
747747
}
748748

749-
/* local sg copy to buffer version with _to/fromio usage for dram_access_quirk */
749+
/* local sg copy for dram_access_quirk */
750750
static void meson_mmc_copy_buffer(struct meson_host *host, struct mmc_data *data,
751751
size_t buflen, bool to_buffer)
752752
{
@@ -764,21 +764,27 @@ static void meson_mmc_copy_buffer(struct meson_host *host, struct mmc_data *data
764764
sg_miter_start(&miter, sgl, nents, sg_flags);
765765

766766
while ((offset < buflen) && sg_miter_next(&miter)) {
767-
unsigned int len;
767+
unsigned int buf_offset = 0;
768+
unsigned int len, left;
769+
u32 *buf = miter.addr;
768770

769771
len = min(miter.length, buflen - offset);
772+
left = len;
770773

771-
/* When dram_access_quirk, the bounce buffer is a iomem mapping */
772-
if (host->dram_access_quirk) {
773-
if (to_buffer)
774-
memcpy_toio(host->bounce_iomem_buf + offset, miter.addr, len);
775-
else
776-
memcpy_fromio(miter.addr, host->bounce_iomem_buf + offset, len);
774+
if (to_buffer) {
775+
do {
776+
writel(*buf++, host->bounce_iomem_buf + offset + buf_offset);
777+
778+
buf_offset += 4;
779+
left -= 4;
780+
} while (left);
777781
} else {
778-
if (to_buffer)
779-
memcpy(host->bounce_buf + offset, miter.addr, len);
780-
else
781-
memcpy(miter.addr, host->bounce_buf + offset, len);
782+
do {
783+
*buf++ = readl(host->bounce_iomem_buf + offset + buf_offset);
784+
785+
buf_offset += 4;
786+
left -= 4;
787+
} while (left);
782788
}
783789

784790
offset += len;
@@ -830,7 +836,11 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd)
830836
if (data->flags & MMC_DATA_WRITE) {
831837
cmd_cfg |= CMD_CFG_DATA_WR;
832838
WARN_ON(xfer_bytes > host->bounce_buf_size);
833-
meson_mmc_copy_buffer(host, data, xfer_bytes, true);
839+
if (host->dram_access_quirk)
840+
meson_mmc_copy_buffer(host, data, xfer_bytes, true);
841+
else
842+
sg_copy_to_buffer(data->sg, data->sg_len,
843+
host->bounce_buf, xfer_bytes);
834844
dma_wmb();
835845
}
836846

@@ -849,12 +859,43 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd)
849859
writel(cmd->arg, host->regs + SD_EMMC_CMD_ARG);
850860
}
851861

862+
static int meson_mmc_validate_dram_access(struct mmc_host *mmc, struct mmc_data *data)
863+
{
864+
struct scatterlist *sg;
865+
int i;
866+
867+
/* Reject request if any element offset or size is not 32bit aligned */
868+
for_each_sg(data->sg, sg, data->sg_len, i) {
869+
if (!IS_ALIGNED(sg->offset, sizeof(u32)) ||
870+
!IS_ALIGNED(sg->length, sizeof(u32))) {
871+
dev_err(mmc_dev(mmc), "unaligned sg offset %u len %u\n",
872+
data->sg->offset, data->sg->length);
873+
return -EINVAL;
874+
}
875+
}
876+
877+
return 0;
878+
}
879+
852880
static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
853881
{
854882
struct meson_host *host = mmc_priv(mmc);
855883
bool needs_pre_post_req = mrq->data &&
856884
!(mrq->data->host_cookie & SD_EMMC_PRE_REQ_DONE);
857885

886+
/*
887+
* The memory at the end of the controller used as bounce buffer for
888+
* the dram_access_quirk only accepts 32bit read/write access,
889+
* check the aligment and length of the data before starting the request.
890+
*/
891+
if (host->dram_access_quirk && mrq->data) {
892+
mrq->cmd->error = meson_mmc_validate_dram_access(mmc, mrq->data);
893+
if (mrq->cmd->error) {
894+
mmc_request_done(mmc, mrq);
895+
return;
896+
}
897+
}
898+
858899
if (needs_pre_post_req) {
859900
meson_mmc_get_transfer_mode(mmc, mrq);
860901
if (!meson_mmc_desc_chain_mode(mrq->data))
@@ -999,7 +1040,11 @@ static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id)
9991040
if (meson_mmc_bounce_buf_read(data)) {
10001041
xfer_bytes = data->blksz * data->blocks;
10011042
WARN_ON(xfer_bytes > host->bounce_buf_size);
1002-
meson_mmc_copy_buffer(host, data, xfer_bytes, false);
1043+
if (host->dram_access_quirk)
1044+
meson_mmc_copy_buffer(host, data, xfer_bytes, false);
1045+
else
1046+
sg_copy_from_buffer(data->sg, data->sg_len,
1047+
host->bounce_buf, xfer_bytes);
10031048
}
10041049

10051050
next_cmd = meson_mmc_get_next_command(cmd);

drivers/mmc/host/sdhci-of-at91.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/delay.h>
1212
#include <linux/err.h>
1313
#include <linux/io.h>
14+
#include <linux/iopoll.h>
1415
#include <linux/kernel.h>
1516
#include <linux/mmc/host.h>
1617
#include <linux/mmc/slot-gpio.h>
@@ -61,7 +62,6 @@ static void sdhci_at91_set_force_card_detect(struct sdhci_host *host)
6162
static void sdhci_at91_set_clock(struct sdhci_host *host, unsigned int clock)
6263
{
6364
u16 clk;
64-
unsigned long timeout;
6565

6666
host->mmc->actual_clock = 0;
6767

@@ -86,16 +86,11 @@ static void sdhci_at91_set_clock(struct sdhci_host *host, unsigned int clock)
8686
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
8787

8888
/* Wait max 20 ms */
89-
timeout = 20;
90-
while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
91-
& SDHCI_CLOCK_INT_STABLE)) {
92-
if (timeout == 0) {
93-
pr_err("%s: Internal clock never stabilised.\n",
94-
mmc_hostname(host->mmc));
95-
return;
96-
}
97-
timeout--;
98-
mdelay(1);
89+
if (read_poll_timeout(sdhci_readw, clk, (clk & SDHCI_CLOCK_INT_STABLE),
90+
1000, 20000, false, host, SDHCI_CLOCK_CONTROL)) {
91+
pr_err("%s: Internal clock never stabilised.\n",
92+
mmc_hostname(host->mmc));
93+
return;
9994
}
10095

10196
clk |= SDHCI_CLOCK_CARD_EN;
@@ -114,6 +109,7 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
114109
{
115110
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
116111
struct sdhci_at91_priv *priv = sdhci_pltfm_priv(pltfm_host);
112+
unsigned int tmp;
117113

118114
sdhci_reset(host, mask);
119115

@@ -126,6 +122,10 @@ static void sdhci_at91_reset(struct sdhci_host *host, u8 mask)
126122

127123
sdhci_writel(host, calcr | SDMMC_CALCR_ALWYSON | SDMMC_CALCR_EN,
128124
SDMMC_CALCR);
125+
126+
if (read_poll_timeout(sdhci_readl, tmp, !(tmp & SDMMC_CALCR_EN),
127+
10, 20000, false, host, SDMMC_CALCR))
128+
dev_err(mmc_dev(host->mmc), "Failed to calibrate\n");
129129
}
130130
}
131131

0 commit comments

Comments
 (0)