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.fat...@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


Reply via email to