mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] ARM: at91: xload: make capacity an argument to at91_mci_bio_set_highcapacity
@ 2025-05-06 11:56 Ahmad Fatoum
  2025-05-06 11:56 ` [PATCH 2/2] mci: atmel_mci: switch PBL implementation to common mci-pbl support Ahmad Fatoum
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 11:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

In preparation for a switch to the common mci-pbl support, merge
at91_mci_bio_init & at91_mci_bio_set_highcapacity, because
pbl_mci_bio_init() expects these parameters to be already set.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-at91/at91sam9_xload_mmc.c |  5 +----
 arch/arm/mach-at91/xload.c              |  3 ++-
 drivers/mci/atmel_mci_pbl.c             | 13 ++++++-------
 include/mach/at91/xload.h               |  6 +++---
 4 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/arch/arm/mach-at91/at91sam9_xload_mmc.c b/arch/arm/mach-at91/at91sam9_xload_mmc.c
index 26f268ae91dc..b84c4b275d4e 100644
--- a/arch/arm/mach-at91/at91sam9_xload_mmc.c
+++ b/arch/arm/mach-at91/at91sam9_xload_mmc.c
@@ -94,15 +94,12 @@ void __noreturn sam9263_atmci_start_image(u32 mmc_id, unsigned int clock,
 		at91_pmc_enable_periph_clock(IOMEM(AT91SAM926X_BASE_PMC),  AT91SAM9263_ID_MCI1);
 	}
 
-	ret = at91_mci_bio_init(&bio, base, clock, (int)slot_b);
+	ret = at91_mci_bio_init(&bio, base, clock, (int)slot_b, PBL_MCI_STANDARD_CAPACITY);
 	if (ret) {
 		pr_err("atmci_start_image: bio init faild: %d\n", ret);
 		goto out_panic;
 	}
 
-	/* at91sam9x do not support high capacity */
-	at91_mci_bio_set_highcapacity(false);
-
 	ret = pbl_fat_load(&bio, "barebox.bin", buf, SZ_16M);
 	if (ret < 0) {
 		pr_err("pbl_fat_load: error %d\n", ret);
diff --git a/arch/arm/mach-at91/xload.c b/arch/arm/mach-at91/xload.c
index 5d8105f07fe4..709bf054874a 100644
--- a/arch/arm/mach-at91/xload.c
+++ b/arch/arm/mach-at91/xload.c
@@ -228,7 +228,8 @@ void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 
 	sama5d3_pmc_enable_periph_clock(instance->id);
 
-	ret = at91_mci_bio_init(&bio, instance->base, clock, slot);
+	ret = at91_mci_bio_init(&bio, instance->base, clock, slot,
+				PBL_MCI_UNKNOWN_CAPACITY);
 	if (ret)
 		goto out_panic;
 
diff --git a/drivers/mci/atmel_mci_pbl.c b/drivers/mci/atmel_mci_pbl.c
index bd4faa4de5f0..d7343246abbb 100644
--- a/drivers/mci/atmel_mci_pbl.c
+++ b/drivers/mci/atmel_mci_pbl.c
@@ -83,7 +83,8 @@ static int at91_mci_bio_read(struct pbl_bio *bio, off_t start,
 }
 
 int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
-		      unsigned int clock, unsigned int slot)
+		      unsigned int clock, unsigned int slot,
+		      enum pbl_mci_capacity capacity)
 {
 	struct atmel_mci_priv *priv = &atmci_sdcard;
 	struct atmel_mci *host = &priv->host;
@@ -111,12 +112,10 @@ int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
 
 	atmci_common_set_ios(host, &ios);
 
-	priv->highcapacity_card = 1;
+	if (capacity == PBL_MCI_STANDARD_CAPACITY)
+		atmci_sdcard.highcapacity_card = false;
+	else
+		atmci_sdcard.highcapacity_card = true;
 
 	return 0;
 }
-
-void at91_mci_bio_set_highcapacity(bool highcapacity_card)
-{
-	atmci_sdcard.highcapacity_card = highcapacity_card;
-}
diff --git a/include/mach/at91/xload.h b/include/mach/at91/xload.h
index d5fc7596fda6..21840fecbd08 100644
--- a/include/mach/at91/xload.h
+++ b/include/mach/at91/xload.h
@@ -4,7 +4,7 @@
 #define __MACH_AT91_XLOAD_H
 
 #include <linux/compiler.h>
-#include <pbl/bio.h>
+#include <pbl/mci.h>
 
 void __noreturn sama5d2_start_image(u32 r4);
 void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
@@ -12,8 +12,8 @@ void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
 
 int at91_sdhci_bio_init(struct pbl_bio *bio, void __iomem *base);
 int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
-		      unsigned int clock, unsigned int slot);
-void at91_mci_bio_set_highcapacity(bool highcapacity_card);
+		      unsigned int clock, unsigned int slot,
+		      enum pbl_mci_capacity capacity);
 
 void __noreturn sam9263_atmci_start_image(u32 mmc_id, unsigned int clock,
 					  bool slot_b);
-- 
2.39.5




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

* [PATCH 2/2] mci: atmel_mci: switch PBL implementation to common mci-pbl support
  2025-05-06 11:56 [PATCH 1/2] ARM: at91: xload: make capacity an argument to at91_mci_bio_set_highcapacity Ahmad Fatoum
@ 2025-05-06 11:56 ` Ahmad Fatoum
  0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 11:56 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We don't reinitialize the SD-Card when barebox is used as a first stage,
because it's already initialized by the BootROM and thus we don't use
the MMC stack. Recently, a very stripped down version was added that
doesn't initialize cards, but determines wheter a card is high or
standard capacity and then starts reading blocks directly.
Make use of it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/atmel_mci_pbl.c | 99 +++++++------------------------------
 1 file changed, 18 insertions(+), 81 deletions(-)

diff --git a/drivers/mci/atmel_mci_pbl.c b/drivers/mci/atmel_mci_pbl.c
index d7343246abbb..27727b27343c 100644
--- a/drivers/mci/atmel_mci_pbl.c
+++ b/drivers/mci/atmel_mci_pbl.c
@@ -6,95 +6,32 @@
 
 #include "atmel-mci-regs.h"
 
-#define SECTOR_SIZE			512
 #define SUPPORT_MAX_BLOCKS		16U
 
-struct atmel_mci_priv {
-	struct atmel_mci host;
-	bool highcapacity_card;
-};
-
-static struct atmel_mci_priv atmci_sdcard;
-
-static int atmel_mci_pbl_stop_transmission(struct atmel_mci_priv *priv)
+static int pbl_atmci_common_request(struct pbl_mci *mci,
+				    struct mci_cmd *cmd,
+				    struct mci_data *data)
 {
-	struct mci_cmd cmd = {
-		.cmdidx = MMC_CMD_STOP_TRANSMISSION,
-		.resp_type = MMC_RSP_R1b,
-	};
-
-	return atmci_common_request(&priv->host, &cmd, NULL);
+	return atmci_common_request(mci->priv, cmd, data);
 }
 
-static int at91_mci_sd_cmd_read_multiple_block(struct atmel_mci_priv *priv,
-				      void *buf,
-				      unsigned int start,
-				      unsigned int block_count)
-{
-	u16 block_len = SECTOR_SIZE;
-	struct mci_data data;
-	struct mci_cmd cmd = {
-		.cmdidx = MMC_CMD_READ_MULTIPLE_BLOCK,
-		.resp_type = MMC_RSP_R1,
-		.cmdarg = start,
-	};
-
-	if (!priv->highcapacity_card)
-		cmd.cmdarg *= block_len;
-
-	data.dest = buf;
-	data.flags = MMC_DATA_READ;
-	data.blocksize = block_len;
-	data.blocks = block_count;
-
-	return atmci_common_request(&priv->host, &cmd, &data);
-}
-
-static int at91_mci_bio_read(struct pbl_bio *bio, off_t start,
-				void *buf, unsigned int nblocks)
-{
-	struct atmel_mci_priv *priv = bio->priv;
-	unsigned int blocks_done = 0;
-	unsigned int blocks;
-	unsigned int block_len = SECTOR_SIZE;
-	unsigned int blocks_read;
-	int ret;
-
-	while (blocks_done < nblocks) {
-		blocks = min(nblocks - blocks_done, SUPPORT_MAX_BLOCKS);
-
-		blocks_read = at91_mci_sd_cmd_read_multiple_block(priv, buf,
-							 start + blocks_done,
-							 blocks);
-
-		ret = atmel_mci_pbl_stop_transmission(priv);
-		if (ret)
-			return ret;
-
-		blocks_done += blocks_read;
-
-		if (blocks_read != blocks)
-			break;
-
-		buf += blocks * block_len;
-	}
-
-	return blocks_done;
-}
+static struct atmel_mci atmci_host;
+static struct pbl_mci mci;
 
 int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
 		      unsigned int clock, unsigned int slot,
 		      enum pbl_mci_capacity capacity)
 {
-	struct atmel_mci_priv *priv = &atmci_sdcard;
-	struct atmel_mci *host = &priv->host;
+	struct atmel_mci *host = &atmci_host;
 	struct mci_ios ios = { .bus_width = MMC_BUS_WIDTH_4, .clock = 25000000 };
 
-	/* PBL will get MCI controller in disabled state. We need to reconfigure
-	 * it. */
-	bio->priv = priv;
-	bio->read = at91_mci_bio_read;
+	mci.priv = host;
+	mci.send_cmd = pbl_atmci_common_request;
 
+	/*
+	 * PBL will get MCI controller in disabled state,
+	 * so we need to reconfigure it.
+	 */
 	host->regs = base;
 
 	atmci_get_cap(host);
@@ -112,10 +49,10 @@ int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
 
 	atmci_common_set_ios(host, &ios);
 
-	if (capacity == PBL_MCI_STANDARD_CAPACITY)
-		atmci_sdcard.highcapacity_card = false;
-	else
-		atmci_sdcard.highcapacity_card = true;
+	mci.priv = host;
+	mci.send_cmd = pbl_atmci_common_request;
+	mci.max_blocks_per_read = SUPPORT_MAX_BLOCKS;
+	mci.capacity = capacity;
 
-	return 0;
+	return pbl_mci_bio_init(&mci, bio);
 }
-- 
2.39.5




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

end of thread, other threads:[~2025-05-06 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-06 11:56 [PATCH 1/2] ARM: at91: xload: make capacity an argument to at91_mci_bio_set_highcapacity Ahmad Fatoum
2025-05-06 11:56 ` [PATCH 2/2] mci: atmel_mci: switch PBL implementation to common mci-pbl support Ahmad Fatoum

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