mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 17/28] mci: sdhci: atmel: extend driver for PBL usage
Date: Mon, 6 Jul 2020 00:32:41 +0200	[thread overview]
Message-ID: <502da695-af88-af2d-9e99-e40044dd6d16@pengutronix.de> (raw)
In-Reply-To: <20200705185252.GB15485@pengutronix.de>

Hi,

On 7/5/20 8:52 PM, Sascha Hauer wrote:
> On Wed, Jul 01, 2020 at 11:11:11AM +0200, Ahmad Fatoum wrote:
>> The BootROM resets both the SD/MMC host controller and the pin controller,
>> but the card itself remains in transfer mode. If we redo host-side
>> setup, we can directly read new blocks off the card.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>>  drivers/mci/Kconfig              |   4 +
>>  drivers/mci/Makefile             |   1 +
>>  drivers/mci/atmel-sdhci-common.c |   3 +
>>  drivers/mci/atmel-sdhci-pbl.c    | 128 +++++++++++++++++++++++++++++++
>>  4 files changed, 136 insertions(+)
>>  create mode 100644 drivers/mci/atmel-sdhci-pbl.c
>>
>> diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
>> index 6ae1e812528c..3026b25cadc9 100644
>> --- a/drivers/mci/Kconfig
>> +++ b/drivers/mci/Kconfig
>> @@ -187,3 +187,7 @@ endif
>>  config MCI_IMX_ESDHC_PBL
>>  	bool
>>  	select MCI_SDHCI
>> +
>> +config MCI_ATMEL_SDHCI_PBL
>> +	bool
>> +	select MCI_SDHCI
>> diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile
>> index 177483dcfba5..4a5363367476 100644
>> --- a/drivers/mci/Makefile
>> +++ b/drivers/mci/Makefile
>> @@ -5,6 +5,7 @@ obj-$(CONFIG_MCI_ATMEL_SDHCI)	+= atmel-sdhci.o atmel-sdhci-common.o
>>  obj-$(CONFIG_MCI_BCM283X)	+= mci-bcm2835.o
>>  obj-$(CONFIG_MCI_BCM283X_SDHOST)	+= bcm2835-sdhost.o
>>  obj-$(CONFIG_MCI_DOVE)		+= dove-sdhci.o
>> +pbl-$(CONFIG_MCI_ATMEL_SDHCI_PBL)	+= atmel-sdhci-pbl.o atmel-sdhci-common.o
>>  obj-$(CONFIG_MCI_IMX)		+= imx.o
>>  obj-$(CONFIG_MCI_IMX_ESDHC)	+= imx-esdhc.o imx-esdhc-common.o
>>  pbl-$(CONFIG_MCI_IMX_ESDHC_PBL)	+= imx-esdhc-pbl.o imx-esdhc-common.o
>> diff --git a/drivers/mci/atmel-sdhci-common.c b/drivers/mci/atmel-sdhci-common.c
>> index 1884f3836337..a83610c3d090 100644
>> --- a/drivers/mci/atmel-sdhci-common.c
>> +++ b/drivers/mci/atmel-sdhci-common.c
>> @@ -12,7 +12,10 @@
>>  #include <common.h>
>>  #include <mci.h>
>>  
>> +#include <mach/early_udelay.h>
>> +
>>  #ifdef __PBL__
>> +#define udelay early_udelay
>>  #undef  dev_err
>>  #define dev_err(d, ...)		pr_err(__VA_ARGS__)
>>  #undef  dev_warn
>> diff --git a/drivers/mci/atmel-sdhci-pbl.c b/drivers/mci/atmel-sdhci-pbl.c
>> new file mode 100644
>> index 000000000000..626e4008fe85
>> --- /dev/null
>> +++ b/drivers/mci/atmel-sdhci-pbl.c
>> @@ -0,0 +1,128 @@
>> +// SPDX-License-Identifier: BSD-1-Clause
>> +/*
>> + * Copyright (c) 2015, Atmel Corporation
>> + * Copyright (c) 2019, Ahmad Fatoum, Pengutronix
>> + *
>> + * Atmel's name may not be used to endorse or promote products derived from
>> + * this software without specific prior written permission.
>> + */
>> +
>> +#include <common.h>
>> +#include <pbl.h>
>> +#include <mci.h>
>> +#include <debug_ll.h>
>> +#include <mach/xload.h>
>> +#include "atmel-sdhci.h"
>> +
>> +#include <mach/early_udelay.h>
>> +
>> +#ifdef __PBL__
>> +#define udelay early_udelay
>> +#endif
>> +
>> +#define SECTOR_SIZE			512
>> +#define SUPPORT_MAX_BLOCKS		16U
>> +
>> +struct at91_sdhci_priv {
>> +	struct at91_sdhci host;
>> +	bool highcapacity_card;
>> +};
>> +
>> +static int sd_cmd_stop_transmission(struct at91_sdhci_priv *priv)
>> +{
>> +	struct mci_cmd cmd = {
>> +		.cmdidx = MMC_CMD_STOP_TRANSMISSION,
>> +		.resp_type = MMC_RSP_R1b,
>> +	};
>> +
>> +	return at91_sdhci_send_command(&priv->host, &cmd, NULL);
>> +}
>> +
>> +static int sd_cmd_read_multiple_block(struct at91_sdhci_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 at91_sdhci_send_command(&priv->host, &cmd, &data);
>> +}
>> +
>> +static int at91_sdhci_bio_read(struct pbl_bio *bio, off_t start,
>> +				void *buf, unsigned int nblocks)
>> +{
>> +	struct at91_sdhci_priv *priv = bio->priv;
>> +	unsigned int blocks_done = 0;
>> +	unsigned int blocks;
>> +	unsigned int block_len = SECTOR_SIZE;
>> +	unsigned int blocks_read;
>> +	int ret;
>> +
>> +	/*
>> +	 * Refer to the at91sam9g20 datasheet:
>> +	 * Figure 35-10. Read Function Flow Diagram
>> +	*/
>> +
>> +	while (blocks_done < nblocks) {
>> +		blocks = min(nblocks - blocks_done, SUPPORT_MAX_BLOCKS);
>> +
>> +		blocks_read = sd_cmd_read_multiple_block(priv, buf,
>> +							 start + blocks_done,
>> +							 blocks);
>> +
>> +		ret = sd_cmd_stop_transmission(priv);
>> +		if (ret)
>> +			return ret;
>> +
>> +		blocks_done += blocks_read;
>> +
>> +		if (blocks_read != blocks)
>> +			break;
>> +
>> +		buf += blocks * block_len;
>> +	}
>> +
>> +	return blocks_done;
>> +}
> 
> All this doesn't look at91 specific. It rather looks like it could be
> generic code. I know I have put similar code into the i.MX esdhc PBL
> driver, so I can't complain very much...

When I port the at91_mci to PBL (sama5d3 and older SoCs), I will take care not
to duplicate this part. The other first stage MCI implementation can then
be migrated to this.

> 
> Sascha
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-07-05 22:32 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01  9:10 [PATCH RESEND 00/28] ARM: at91: add sama5d2 first stage support Ahmad Fatoum
2020-07-01  9:10 ` [PATCH 01/28] ARM: at91: remove <mach/hardware.h> include from assembly code Ahmad Fatoum
2020-07-01  9:10 ` [PATCH 02/28] ARM: at91: sama5d2: cast peripheral base addresses to __iomem pointers Ahmad Fatoum
2020-07-01  9:10 ` [PATCH 03/28] ARM: at91: import at91bootstrap's at91_ddrsdrc.h Ahmad Fatoum
2020-07-01  9:10 ` [PATCH 04/28] ARM: at91: migrate at91sam9_ddrsdr.h to use " Ahmad Fatoum
2020-07-01  9:10 ` [PATCH 05/28] ARM: at91: replace at91sam9_ddrsdr.h with " Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 06/28] ARM: at91: import early_udelay from at91bootstrap Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 07/28] ARM: at91: import low level DDRAMC initialization code " Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 08/28] ARM: at91: watchdog: implement at91_wdt_disable Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 09/28] watchdog: add support for at91sam9/sama5 watchdog Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 10/28] ARM: at91: implement sama5d2 lowlevel init Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 11/28] ARM: at91: sama5d2: add sama5d2 matrix configuration Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 12/28] ARM: at91: add sama5d2 cache init Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 13/28] ARM: at91: add necessary Advanced Interrupt Controller configuration Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 14/28] ARM: at91: extend low level PMC driver for generic clk support Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 15/28] pbl: add block I/O API Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 16/28] fs: fat: extend for in-PBL support Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 17/28] mci: sdhci: atmel: extend driver for PBL usage Ahmad Fatoum
2020-07-05 18:52   ` Sascha Hauer
2020-07-05 22:32     ` Ahmad Fatoum [this message]
2020-07-01  9:11 ` [PATCH 18/28] ARM: at91: add code for sama5 boot source detection Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 19/28] ARM: at91: add helpers for chain-loading barebox from SD-card Ahmad Fatoum
2020-07-05 18:42   ` Sascha Hauer
2020-07-05 22:35     ` Ahmad Fatoum
2020-07-06  6:26       ` [PATCH] fixup! " Ahmad Fatoum
2020-07-09 14:19       ` [PATCH 19/28] " Sascha Hauer
2020-07-09 15:01         ` [PATCH v2] fixup! " Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 20/28] ARM: at91: sama5d2: reuse stack set-up by first stage Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 21/28] ARM: at91: debug_ll: remove duplicated IS_ENABLED(CONFIG_DEBUG_LL) condition Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 22/28] ARM: at91: sama5d2: reduce UART setup boilerplate with new helpers Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 23/28] ARM: at91: sama5d27-som1: add additional first stage entry point Ahmad Fatoum
2020-07-05 18:46   ` Sascha Hauer
2020-07-06  6:22   ` [PATCH] fixup! " Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 24/28] ARM: at91: sama5d2: read back memory size from DDRAM controller Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 25/28] ARM: at91: sama5d2: populate $bootsource and $bootsource_instance Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 26/28] ARM: at91: sama5d27-som1-ek: add barebox_update and multi environment support Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 27/28] ARM: at91: sama5d27-giantboard: add additional first stage entry point Ahmad Fatoum
2020-07-06  6:22   ` [PATCH] fixup! " Ahmad Fatoum
2020-07-01  9:11 ` [PATCH 28/28] ARM: at91: sama5d27-giantboard: add default environment/bbu Ahmad Fatoum
2020-07-11  5:13 ` [PATCH RESEND 00/28] ARM: at91: add sama5d2 first stage support Sascha Hauer

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=502da695-af88-af2d-9e99-e40044dd6d16@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@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