From: Alexander Dahl <ada@thorsis.com>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org, mgr@pengutronix.de, ore@pengutronix.de
Subject: Re: [PATCH 2/3] ARM: at91: mmc-xload: allow overriding card capacity
Date: Thu, 3 Jun 2021 07:34:53 +0200 [thread overview]
Message-ID: <YLhp/edqhhkc5hEp@ada-deb-carambola.ifak-system.com> (raw)
In-Reply-To: <20210602102524.20034-2-a.fatoum@pengutronix.de>
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@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@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-06-03 5:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-02 10:25 [PATCH 1/3] ARM: at91: microchip-ksz9477-evb: support PBL console Ahmad Fatoum
2021-06-02 10:25 ` [PATCH 2/3] ARM: at91: mmc-xload: allow overriding card capacity Ahmad Fatoum
2021-06-02 10:30 ` Ahmad Fatoum
2021-06-03 5:34 ` Alexander Dahl [this message]
2021-06-03 6:28 ` Ahmad Fatoum
2021-06-03 6:53 ` Alexander Dahl
2021-06-03 7:01 ` Ahmad Fatoum
2021-06-02 10:25 ` [PATCH 3/3] ARM: at91: xload-mmc: add prominent note about PBL MMC limitation Ahmad Fatoum
2021-06-02 10:29 ` [PATCH 1/3] ARM: at91: microchip-ksz9477-evb: support PBL console Ahmad Fatoum
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=YLhp/edqhhkc5hEp@ada-deb-carambola.ifak-system.com \
--to=ada@thorsis.com \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=mgr@pengutronix.de \
--cc=ore@pengutronix.de \
/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