[PATCH 2/3] ARM: at91: mmc-xload: allow overriding card capacity
Alexander Dahl
ada at thorsis.com
Wed Jun 2 22:34:53 PDT 2021
Hello Ahmad,
just glanced over this series by accident, something catched my eye …
Am Wed, Jun 02, 2021 at 12:25:23PM +0200 schrieb Ahmad Fatoum:
> The PBL MMC driver works with the assumption that the BootROM has left
> the SD-Card in transfer mode. There seems to be no definitive way
> to find out whether a running card is high capacity (> 2G) or not,
> but we need this info when reading, because default capacities accept
> their read offset in bytes while high capacity deal in 512 byte blocks.
I'm a little surprised there's not. Once like ten years ago I had to
write a SD card driver for a small microcontroller. In the firmware I
switched to high capacity mode just based on the Card Capacity Status
(CCS) bit in the Operation Conditions Register (OCR) of the SD card.
Got that after sending advanced command 41 (send op cond) to the card.
Not sure if it's that easy, or if that command was only sent under
certain conditions, but I can not remember just guessing high capacity
based on some heuristics nor hard code it. We certainly used low
capacity (like 32 MB for example) and high capacity cards (4G or more)
with that system.
You probably already looked for a reliable way to detect this. I was
just curious why this needs to be hardcoded.
Have a nice day
Alex
> For i.MX, this is elegantly solved by just reading from sector 0.
> For AT91, we chainload barebox from FAT, so we need to seek around.
> So far, we just had an assumption buried in the driver that we are
> always highcapacity.
>
> Export a knob to change this, so we can move the hardcoding from
> driver to board code, where it's more prominent. This is done
> in a follow-up commit.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> arch/arm/mach-at91/include/mach/xload.h | 3 +++
> drivers/mci/atmel-sdhci-pbl.c | 8 +++++++-
> drivers/mci/atmel_mci_pbl.c | 8 +++++++-
> 3 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mach-at91/include/mach/xload.h b/arch/arm/mach-at91/include/mach/xload.h
> index bbc70af2108a..038f32554568 100644
> --- a/arch/arm/mach-at91/include/mach/xload.h
> +++ b/arch/arm/mach-at91/include/mach/xload.h
> @@ -12,4 +12,7 @@ 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_set_highcapacity(struct pbl_bio *bio, bool highcap);
> +void at91_sdhci_set_highcapacity(struct pbl_bio *bio, bool highcap);
> +
> #endif /* __MACH_XLOAD_H */
> diff --git a/drivers/mci/atmel-sdhci-pbl.c b/drivers/mci/atmel-sdhci-pbl.c
> index 626e4008fe85..317f26f8af0d 100644
> --- a/drivers/mci/atmel-sdhci-pbl.c
> +++ b/drivers/mci/atmel-sdhci-pbl.c
> @@ -99,6 +99,12 @@ static int at91_sdhci_bio_read(struct pbl_bio *bio, off_t start,
> return blocks_done;
> }
>
> +void at91_sdhci_set_highcapacity(struct pbl_bio *bio, bool highcap)
> +{
> + struct at91_sdhci_priv *priv = bio->priv;
> + priv->highcapacity_card = highcap;
> +}
> +
> static struct at91_sdhci_priv atmel_sdcard;
>
> int at91_sdhci_bio_init(struct pbl_bio *bio, void __iomem *base)
> @@ -122,7 +128,7 @@ int at91_sdhci_bio_init(struct pbl_bio *bio, void __iomem *base)
> ret = at91_sdhci_set_ios(host, &ios);
>
> // FIXME can we determine this without leaving SD transfer mode?
> - priv->highcapacity_card = 1;
> + at91_sdhci_set_highcapacity(bio, true);
>
> return 0;
> }
> diff --git a/drivers/mci/atmel_mci_pbl.c b/drivers/mci/atmel_mci_pbl.c
> index 767d6f3ce2d7..82e45fd4e89e 100644
> --- a/drivers/mci/atmel_mci_pbl.c
> +++ b/drivers/mci/atmel_mci_pbl.c
> @@ -82,6 +82,12 @@ static int at91_mci_bio_read(struct pbl_bio *bio, off_t start,
> return blocks_done;
> }
>
> +void at91_mci_set_highcapacity(struct pbl_bio *bio, bool highcap)
> +{
> + struct atmel_mci_priv *priv = bio->priv;
> + priv->highcapacity_card = highcap;
> +}
> +
> int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
> unsigned int clock, unsigned int slot)
> {
> @@ -110,7 +116,7 @@ int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
>
> atmci_common_set_ios(host, &ios);
>
> - priv->highcapacity_card = 1;
> + at91_mci_set_highcapacity(bio, true);
>
> return 0;
> }
> --
> 2.29.2
>
>
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
More information about the barebox
mailing list