mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] mci: Add more respone types
@ 2023-01-10 15:50 Sascha Hauer
  2023-01-10 15:50 ` [PATCH 2/3] mci: handle SDIO cards gracefully Sascha Hauer
  2023-01-10 15:50 ` [PATCH 3/3] ARM: dts: rpi3: Enable sdhci controller Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2023-01-10 15:50 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/mci.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/include/mci.h b/include/mci.h
index d949310fac..d3201e17e6 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -326,6 +326,17 @@
 #define MMC_RSP_BUSY    (1 << 3)                /* card may send busy */
 #define MMC_RSP_OPCODE  (1 << 4)                /* response contains opcode */
 
+#define MMC_CMD_MASK    (3 << 5)                /* non-SPI command type */
+#define MMC_CMD_AC      (0 << 5)
+#define MMC_CMD_ADTC    (1 << 5)
+#define MMC_CMD_BC      (2 << 5)
+#define MMC_CMD_BCR     (3 << 5)
+
+#define MMC_RSP_SPI_S1  (1 << 7)                /* one status byte */
+#define MMC_RSP_SPI_S2  (1 << 8)                /* second byte */
+#define MMC_RSP_SPI_B4  (1 << 9)                /* four data bytes */
+#define MMC_RSP_SPI_BUSY (1 << 10)              /* card may send busy */
+
 #define MMC_RSP_NONE    (0)
 #define MMC_RSP_R1      (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
 #define MMC_RSP_R1b	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
@@ -336,6 +347,19 @@
 #define MMC_RSP_R6      (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
 #define MMC_RSP_R7      (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
 
+/*
+ * These are the SPI response types for MMC, SD, and SDIO cards.
+ * Commands return R1, with maybe more info.  Zero is an error type;
+ * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
+ */
+#define MMC_RSP_SPI_R1  (MMC_RSP_SPI_S1)
+#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
+#define MMC_RSP_SPI_R2  (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
+#define MMC_RSP_SPI_R3  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
+#define MMC_RSP_SPI_R4  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
+#define MMC_RSP_SPI_R5  (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
+#define MMC_RSP_SPI_R7  (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
+
 /** command information to be sent to the SD/MMC card */
 struct mci_cmd {
 	unsigned cmdidx;	/**< Command to be sent to the SD/MMC card */
-- 
2.30.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/3] mci: handle SDIO cards gracefully
  2023-01-10 15:50 [PATCH 1/3] mci: Add more respone types Sascha Hauer
@ 2023-01-10 15:50 ` Sascha Hauer
  2023-01-10 15:50 ` [PATCH 3/3] ARM: dts: rpi3: Enable sdhci controller Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2023-01-10 15:50 UTC (permalink / raw)
  To: Barebox List

Detect SDIO cards properly to be able to return from card detection
without errors. So far a SDIO card reports several errors during
detection:

ERROR: bcm2835_mci 3f300000.mmc@7e300000.of: Error while executing command 8
ERROR: bcm2835_mci 3f300000.mmc@7e300000.of: Status: 0x1FF0001, Interrupt: 0x18000
ERROR: bcm2835_mci 3f300000.mmc@7e300000.of: Error while executing command 55
ERROR: bcm2835_mci 3f300000.mmc@7e300000.of: Status: 0x1FF0001, Interrupt: 0x18000
ERROR: bcm2835_mci 3f300000.mmc@7e300000.of: Error while executing command 1
ERROR: bcm2835_mci 3f300000.mmc@7e300000.of: Status: 0x1FF0001, Interrupt: 0x18000

With this we can now detect SDIO cards without reporting errors, or
to put it differently: barebox now has SDIO support ;)

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c | 24 +++++++++++++++++++++++-
 include/mci.h          |  4 ++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 8cda07e711..44a577e8c3 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -232,6 +232,15 @@ static int mci_go_idle(struct mci *mci)
 	return 0;
 }
 
+static int sdio_send_op_cond(struct mci *mci)
+{
+	struct mci_cmd cmd;
+
+	mci_setup_cmd(&cmd, SD_IO_SEND_OP_COND, 0, MMC_RSP_SPI_R4 | MMC_RSP_R4 | MMC_CMD_BCR);
+
+	return mci_send_cmd(mci, &cmd, NULL);
+}
+
 /**
  * FIXME
  * @param mci MCI instance
@@ -1596,7 +1605,9 @@ static void mci_info(struct device_d *dev)
 	mci_print_caps(host->host_caps);
 
 	printf("Card information:\n");
-	printf("  Attached is a %s card\n", IS_SD(mci) ? "SD" : "MMC");
+	printf("  Card type: %s\n", mci->sdio ? "SDIO" : IS_SD(mci) ? "SD" : "MMC");
+	if (mci->sdio)
+		return;
 	printf("  Version: %s\n", mci_version_string(mci));
 	printf("  Capacity: %u MiB\n", (unsigned)(mci->capacity >> 20));
 
@@ -1809,6 +1820,16 @@ static int mci_card_probe(struct mci *mci)
 		goto on_error;
 	}
 
+	if (!host->no_sdio) {
+		rc = sdio_send_op_cond(mci);
+		if (!rc) {
+			mci->ready_for_use = true;
+			mci->sdio = true;
+			dev_info(&mci->dev, "SDIO card detected, ignoring\n");
+			return 0;
+		}
+	}
+
 	/* Check if this card can handle the "SD Card Physical Layer Specification 2.0" */
 	if (!host->no_sd) {
 		rc = sd_send_if_cond(mci);
@@ -2086,6 +2107,7 @@ void mci_of_parse_node(struct mci_host *host,
 	host->broken_cd = of_property_read_bool(np, "broken-cd");
 	host->non_removable = of_property_read_bool(np, "non-removable");
 	host->no_sd = of_property_read_bool(np, "no-sd");
+	host->no_sdio = of_property_read_bool(np, "no-sdio");
 	host->disable_wp = of_property_read_bool(np, "disable-wp");
 }
 
diff --git a/include/mci.h b/include/mci.h
index d3201e17e6..56a5659e50 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -91,6 +91,8 @@
 #define SD_CMD_APP_SEND_OP_COND		41
 #define SD_CMD_APP_SEND_SCR		51
 
+#define SD_IO_SEND_OP_COND		5 /* bcr  [23:0] OCR         R4  */
+
 /* SCR definitions in different words */
 #define SD_HIGHSPEED_BUSY	0x00020000
 #define SD_HIGHSPEED_SUPPORTED	0x00020000
@@ -431,6 +433,7 @@ struct mci_host {
 	int broken_cd;		/**< card detect is broken */
 	bool non_removable;	/**< device is non removable */
 	bool no_sd;		/**< do not send SD commands during initialization */
+	bool no_sdio;		/**< do not send SDIO commands during initialization */
 	bool disable_wp;	/**< ignore write-protect detection logic */
 	struct regulator *supply;
 
@@ -469,6 +472,7 @@ struct mci {
 	struct mci_host *host;		/**< the host for this card */
 	struct device_d dev;		/**< the device for our disk (mcix) */
 	unsigned version;
+	bool sdio;		/**< card is a SDIO card */
 	/** != 0 when a high capacity card is connected (OCR -> OCR_HCS) */
 	int high_capacity;
 	unsigned card_caps;	/**< Card's capabilities */
-- 
2.30.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 3/3] ARM: dts: rpi3: Enable sdhci controller
  2023-01-10 15:50 [PATCH 1/3] mci: Add more respone types Sascha Hauer
  2023-01-10 15:50 ` [PATCH 2/3] mci: handle SDIO cards gracefully Sascha Hauer
@ 2023-01-10 15:50 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2023-01-10 15:50 UTC (permalink / raw)
  To: Barebox List

We disabled the sdhci controller in the devicetree because trying
to detect the attached SDIO resulted in annoying error messages.
As we can now gracefully detect SDIO cards we can enable the
controller. This has the advantage that Linux gains WiFi support
when the kernel is started with the barebox live tree.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/dts/bcm2837-rpi-3.dts | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/dts/bcm2837-rpi-3.dts b/arch/arm/dts/bcm2837-rpi-3.dts
index e82d518fa5..38d673aec4 100644
--- a/arch/arm/dts/bcm2837-rpi-3.dts
+++ b/arch/arm/dts/bcm2837-rpi-3.dts
@@ -3,7 +3,3 @@
 &{/memory@0} {
 	reg = <0x0 0x0>;
 };
-
-&sdhci {
-	status = "disabled";
-};
-- 
2.30.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-10 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 15:50 [PATCH 1/3] mci: Add more respone types Sascha Hauer
2023-01-10 15:50 ` [PATCH 2/3] mci: handle SDIO cards gracefully Sascha Hauer
2023-01-10 15:50 ` [PATCH 3/3] ARM: dts: rpi3: Enable sdhci controller Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox