From: Inochi Amaoto <inochiama@gmail.com>
To: Ulf Hansson <ulfh@kernel.org>,
Karol Gugala <kgugala@antmicro.com>,
Mateusz Holenko <mholenko@antmicro.com>,
Gabriel Somlo <gsomlo@gmail.com>, Joel Stanley <joel@jms.id.au>
Cc: Inochi Amaoto <inochiama@gmail.com>,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
Yixun Lan <dlan@gentoo.org>, Longbin Li <looong.bin@gmail.com>
Subject: [PATCH 1/2] mmc: litex_mmc: Set width from linux request
Date: Mon, 29 Jun 2026 15:25:07 +0800 [thread overview]
Message-ID: <20260629072510.1451480-2-inochiama@gmail.com> (raw)
In-Reply-To: <20260629072510.1451480-1-inochiama@gmail.com>
Previously, the litex_mmc driver force the 4 bits bus width.
This means that the gateware with 1 bit bus width is not fit.
However, litesdcard does support setting bus width, which
make the 1 bit bus width gateware possible to be used.
Add logic for setting bus width in the set_ios() function.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
drivers/mmc/host/litex_mmc.c | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/drivers/mmc/host/litex_mmc.c b/drivers/mmc/host/litex_mmc.c
index 3655542ca998..affdff8621bf 100644
--- a/drivers/mmc/host/litex_mmc.c
+++ b/drivers/mmc/host/litex_mmc.c
@@ -29,6 +29,7 @@
#define LITEX_PHY_CLOCKERDIV 0x04
#define LITEX_PHY_INITIALIZE 0x08
#define LITEX_PHY_WRITESTATUS 0x0C
+#define LITEX_PHY_SETTINGS 0x18
#define LITEX_CORE_CMDARG 0x00
#define LITEX_CORE_CMDCMD 0x04
#define LITEX_CORE_CMDSND 0x08
@@ -72,6 +73,10 @@
#define SD_INIT_DELAY_US 1000
#define SD_INIT_CLK_HZ 400000
+#define SD_PHY_SPEED_1X 0
+#define SD_PHY_SPEED_4X 1
+#define SD_PHY_SPEED_8X 2
+
#define SDIRQ_CARD_DETECT 1
#define SDIRQ_SD_TO_MEM_DONE 2
#define SDIRQ_MEM_TO_SD_DONE 4
@@ -96,6 +101,8 @@ struct litex_mmc_host {
unsigned int ref_clk;
unsigned int sd_clk;
+ u8 width;
+
u32 resp[4];
u16 rca;
@@ -451,6 +458,24 @@ static void litex_mmc_setclk(struct litex_mmc_host *host, unsigned int freq)
static void litex_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
{
struct litex_mmc_host *host = mmc_priv(mmc);
+ unsigned int bus_width = SD_PHY_SPEED_1X;
+
+ switch (ios->bus_width) {
+ case MMC_BUS_WIDTH_1:
+ bus_width = SD_PHY_SPEED_1X;
+ break;
+ case MMC_BUS_WIDTH_4:
+ bus_width = SD_PHY_SPEED_4X;
+ break;
+ case MMC_BUS_WIDTH_8:
+ bus_width = SD_PHY_SPEED_8X;
+ break;
+ }
+
+ if (host->width != ios->bus_width) {
+ litex_write8(host->sdphy + LITEX_PHY_SETTINGS, bus_width);
+ host->width = ios->bus_width;
+ }
/*
* The SD specification requires at least 74 idle clocks before CMD0.
@@ -463,13 +488,6 @@ static void litex_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
return;
}
- /*
- * NOTE: Ignore any ios->bus_width updates; they occur right after
- * the mmc core sends its own acmd6 bus-width change notification,
- * which is redundant since we snoop on the command flow and inject
- * an early acmd6 before the first data transfer command is sent!
- */
-
/* Update sd_clk */
if (ios->clock != host->sd_clk)
litex_mmc_setclk(host, ios->clock);
@@ -555,6 +573,7 @@ static int litex_mmc_probe(struct platform_device *pdev)
*/
host->is_bus_width_set = false;
host->app_cmd = false;
+ host->width = MMC_BUS_WIDTH_1;
/* LiteSDCard can support 64-bit DMA addressing */
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
@@ -587,6 +606,9 @@ static int litex_mmc_probe(struct platform_device *pdev)
litex_write8(host->sdreader + LITEX_BLK2MEM_ENA, 0);
litex_write8(host->sdwriter + LITEX_MEM2BLK_ENA, 0);
+ /* Ensure the litex is at bus width x1 */
+ litex_write8(host->sdphy + LITEX_PHY_SETTINGS, SD_PHY_SPEED_1X);
+
init_completion(&host->cmd_done);
ret = litex_mmc_irq_init(pdev, host);
if (ret)
--
2.54.0
next prev parent reply other threads:[~2026-06-29 7:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 7:25 [PATCH 0/2] mmc: litex_mmc: Respect the bus width request from the core Inochi Amaoto
2026-06-29 7:25 ` Inochi Amaoto [this message]
2026-06-29 7:25 ` [PATCH 2/2] mmc: litex_mmc: Remove unused logic for the fixed bus width Inochi Amaoto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260629072510.1451480-2-inochiama@gmail.com \
--to=inochiama@gmail.com \
--cc=dlan@gentoo.org \
--cc=gsomlo@gmail.com \
--cc=joel@jms.id.au \
--cc=kgugala@antmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=looong.bin@gmail.com \
--cc=mholenko@antmicro.com \
--cc=ulfh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox