From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] mci: atmel_mci: switch PBL implementation to common mci-pbl support
Date: Tue, 6 May 2025 13:56:52 +0200 [thread overview]
Message-ID: <20250506115652.1134337-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250506115652.1134337-1-a.fatoum@pengutronix.de>
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
prev parent reply other threads:[~2025-05-06 14:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=20250506115652.1134337-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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