git: 07da3bb5d56c - main - mmc: support for SPI bus type
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 09 Apr 2025 11:23:24 UTC
The branch main has been updated by br:
URL: https://cgit.FreeBSD.org/src/commit/?id=07da3bb5d56c85325252cd1a9ae32fb5d3536dea
commit 07da3bb5d56c85325252cd1a9ae32fb5d3536dea
Author: Ruslan Bukin <br@FreeBSD.org>
AuthorDate: 2025-04-09 10:20:51 +0000
Commit: Ruslan Bukin <br@FreeBSD.org>
CommitDate: 2025-04-09 11:20:54 +0000
mmc: support for SPI bus type
- Introduce the bus_type accessor, which allows to skip card selection
and timing settings in SPI mode;
- Add MMC_CMD_IS_APP flag for commands followed by the APP command,
which is required by the upcoming MMCSPI driver.
Reviewed by: pkelsey
Sponsored by: UKRI
Differential Revision: https://reviews.freebsd.org/D49249
---
sys/dev/mmc/bridge.h | 5 +++++
sys/dev/mmc/mmc.c | 8 ++++++++
sys/dev/mmc/mmc_subr.c | 2 ++
sys/dev/mmc/mmcbrvar.h | 12 ++++++++++++
sys/dev/mmc/mmcreg.h | 1 +
5 files changed, 28 insertions(+)
diff --git a/sys/dev/mmc/bridge.h b/sys/dev/mmc/bridge.h
index 4ec082a61b55..bd08b695c84a 100644
--- a/sys/dev/mmc/bridge.h
+++ b/sys/dev/mmc/bridge.h
@@ -103,6 +103,10 @@ enum mmc_chip_select {
cs_dontcare = 0, cs_high, cs_low
};
+enum mmc_bus_type {
+ bus_type_default = 0, bus_type_spi
+};
+
enum mmc_bus_width {
bus_width_1 = 0, bus_width_4 = 2, bus_width_8 = 3
};
@@ -123,6 +127,7 @@ struct mmc_ios {
uint32_t clock; /* Speed of the clock in Hz to move data */
enum mmc_vdd vdd; /* Voltage to apply to the power pins */
enum mmc_vccq vccq; /* Voltage to use for signaling */
+ enum mmc_bus_type bus_type;
enum mmc_bus_mode bus_mode;
enum mmc_chip_select chip_select;
enum mmc_bus_width bus_width;
diff --git a/sys/dev/mmc/mmc.c b/sys/dev/mmc/mmc.c
index 78b38f91a1f0..f4ea8faca35c 100644
--- a/sys/dev/mmc/mmc.c
+++ b/sys/dev/mmc/mmc.c
@@ -701,6 +701,10 @@ mmc_select_card(struct mmc_softc *sc, uint16_t rca)
{
int err, flags;
+ /* No card selection in SPI mode. */
+ if (mmcbr_get_bus_type(sc->dev) == bus_type_spi)
+ return (MMC_ERR_NONE);
+
flags = (rca ? MMC_RSP_R1B : MMC_RSP_NONE) | MMC_CMD_AC;
sc->retune_paused++;
err = mmc_wait_for_command(sc, MMC_SELECT_CARD, (uint32_t)rca << 16,
@@ -900,6 +904,10 @@ mmc_set_timing(struct mmc_softc *sc, struct mmc_ivars *ivar,
uint8_t value;
int err;
+ /* No timings in SPI mode. */
+ if (mmcbr_get_bus_type(sc->dev) == bus_type_spi)
+ return (MMC_ERR_NONE);
+
if (mmcbr_get_mode(sc->dev) == mode_sd) {
switch (timing) {
case bus_timing_normal:
diff --git a/sys/dev/mmc/mmc_subr.c b/sys/dev/mmc/mmc_subr.c
index 0a555cd74c97..fba99e791dff 100644
--- a/sys/dev/mmc/mmc_subr.c
+++ b/sys/dev/mmc/mmc_subr.c
@@ -112,6 +112,8 @@ mmc_wait_for_app_cmd(device_t busdev, device_t dev, uint16_t rca,
sc = device_get_softc(busdev);
+ cmd->flags |= MMC_CMD_IS_APP;
+
/* Squelch error reporting at lower levels, we report below. */
sc->squelched++;
do {
diff --git a/sys/dev/mmc/mmcbrvar.h b/sys/dev/mmc/mmcbrvar.h
index 8faef227324b..c47966793098 100644
--- a/sys/dev/mmc/mmcbrvar.h
+++ b/sys/dev/mmc/mmcbrvar.h
@@ -60,6 +60,7 @@
#include "mmcbr_if.h"
enum mmcbr_device_ivars {
+ MMCBR_IVAR_BUS_TYPE,
MMCBR_IVAR_BUS_MODE,
MMCBR_IVAR_BUS_WIDTH,
MMCBR_IVAR_CHIP_SELECT,
@@ -113,6 +114,17 @@ mmcbr_get_retune_req(device_t dev)
return ((int)v);
}
+static int __inline
+mmcbr_get_bus_type(device_t dev)
+{
+ uintptr_t v;
+
+ if (__predict_false(BUS_READ_IVAR(device_get_parent(dev), dev,
+ MMCBR_IVAR_BUS_TYPE, &v) != 0))
+ return (bus_type_default);
+ return ((int)v);
+}
+
/*
* Convenience wrappers for the mmcbr interface
*/
diff --git a/sys/dev/mmc/mmcreg.h b/sys/dev/mmc/mmcreg.h
index b544e3dd41e5..e5783249c67b 100644
--- a/sys/dev/mmc/mmcreg.h
+++ b/sys/dev/mmc/mmcreg.h
@@ -80,6 +80,7 @@ struct mmc_command {
#define MMC_CMD_BC (2ul << 5) /* Broadcast command, no response */
#define MMC_CMD_BCR (3ul << 5) /* Broadcast command with response */
#define MMC_CMD_MASK (3ul << 5)
+#define MMC_CMD_IS_APP (1ul << 7) /* Next cmd after MMC_APP_CMD */
/* Possible response types defined in the standard: */
#define MMC_RSP_NONE (0)