mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v2 2/6] ARM: at91: xload-mmc: add sama5d3_atmci_start_image() helper
Date: Fri, 23 Apr 2021 16:28:25 +0200	[thread overview]
Message-ID: <20210423142829.29468-3-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20210423142829.29468-1-o.rempel@pengutronix.de>

This helper should be called from the xloader

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 arch/arm/mach-at91/Kconfig              |  2 +
 arch/arm/mach-at91/include/mach/xload.h |  2 +
 arch/arm/mach-at91/xload-mmc.c          | 51 +++++++++++++++++++++++++
 3 files changed, 55 insertions(+)

diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index 52eefc7361..0fc8d25111 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -45,6 +45,7 @@ config HAVE_AT91_DDRAMC
 
 config AT91_MCI_PBL
 	bool
+	depends on MCI_ATMEL_PBL
 	depends on MCI_ATMEL_SDHCI_PBL
 	default y
 
@@ -599,6 +600,7 @@ config MACH_MICROCHIP_KSZ9477_EVB
 	bool "Microchip EVB-KSZ9477 Evaluation Kit"
 	select SOC_SAMA5D3
 	select OFDEVICE
+	select MCI_ATMEL_PBL
 	select COMMON_CLK_OF_PROVIDER
 	help
 	  Select this if you are using Microchip's EVB-KSZ9477 Evaluation Kit.
diff --git a/arch/arm/mach-at91/include/mach/xload.h b/arch/arm/mach-at91/include/mach/xload.h
index 9201e7d0b7..bbc70af210 100644
--- a/arch/arm/mach-at91/include/mach/xload.h
+++ b/arch/arm/mach-at91/include/mach/xload.h
@@ -5,6 +5,8 @@
 #include <pbl.h>
 
 void __noreturn sama5d2_sdhci_start_image(u32 r4);
+void __noreturn sama5d3_atmci_start_image(u32 r4, unsigned int clock,
+					  unsigned int slot);
 
 int at91_sdhci_bio_init(struct pbl_bio *bio, void __iomem *base);
 int at91_mci_bio_init(struct pbl_bio *bio, void __iomem *base,
diff --git a/arch/arm/mach-at91/xload-mmc.c b/arch/arm/mach-at91/xload-mmc.c
index e9edeccb7f..e865f237ef 100644
--- a/arch/arm/mach-at91/xload-mmc.c
+++ b/arch/arm/mach-at91/xload-mmc.c
@@ -3,6 +3,7 @@
 #include <mach/sama5_bootsource.h>
 #include <mach/hardware.h>
 #include <mach/sama5d2_ll.h>
+#include <mach/sama5d3_ll.h>
 #include <mach/gpio.h>
 #include <linux/sizes.h>
 #include <asm/cache.h>
@@ -44,6 +45,23 @@ static const struct sdhci_instance {
 	},
 };
 
+static const struct atmci_instance {
+	void __iomem *base;
+	unsigned id;
+	u8 periph;
+	s8 pins[15];
+} atmci_instances[] = {
+	[0] = {
+		.base = IOMEM(SAMA5D3_BASE_HSMCI0),
+		.id = SAMA5D3_ID_HSMCI0,
+		.periph = AT91_MUX_PERIPH_A,
+		.pins = {
+			AT91_PIN_PD0, AT91_PIN_PD1, AT91_PIN_PD2, AT91_PIN_PD3,
+			AT91_PIN_PD4, AT91_PIN_PD5, AT91_PIN_PD6, AT91_PIN_PD7,
+			AT91_PIN_PD8, AT91_PIN_PD9, -1 }
+	},
+};
+
 /**
  * sama5d2_sdhci_start_image - Load and start an image from FAT-formatted SDHCI
  * @r4: value of r4 passed by BootROM
@@ -82,3 +100,36 @@ void __noreturn sama5d2_sdhci_start_image(u32 r4)
 out_panic:
 	panic("FAT chainloading failed\n");
 }
+
+void __noreturn sama5d3_atmci_start_image(u32 boot_src, unsigned int clock,
+					  unsigned int slot)
+{
+	void *buf = (void *)SAMA5_DDRCS;
+	const struct atmci_instance *instance;
+	struct pbl_bio bio;
+	const s8 *pin;
+	int ret;
+
+	ret = sama5_bootsource_instance(boot_src);
+	if (ret > ARRAY_SIZE(atmci_instances) - 1)
+		panic("Couldn't determine boot MCI instance\n");
+
+	instance = &atmci_instances[boot_src];
+
+	sama5d3_pmc_enable_periph_clock(SAMA5D2_ID_PIOD);
+	for (pin = instance->pins; *pin >= 0; pin++) {
+		at91_mux_pio3_pin(IOMEM(SAMA5D3_BASE_PIOD),
+					 pin_to_mask(*pin), instance->periph, 0);
+	}
+
+	sama5d3_pmc_enable_periph_clock(instance->id);
+
+	ret = at91_mci_bio_init(&bio, instance->base, clock, slot);
+	if (ret)
+		goto out_panic;
+
+	at91_fat_start_image(&bio, buf, SZ_16M, boot_src);
+
+out_panic:
+	panic("FAT chainloading failed\n");
+}
-- 
2.29.2


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


  parent reply	other threads:[~2021-04-23 14:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 14:28 [PATCH v2 0/6] add multiimage support for sama5d3 based microchip-ksz9477-evb board Oleksij Rempel
2021-04-23 14:28 ` [PATCH v2 1/6] mci: atmel_mci: add PBL support Oleksij Rempel
2021-04-23 14:28 ` Oleksij Rempel [this message]
2021-04-23 15:26   ` [PATCH v2 2/6] ARM: at91: xload-mmc: add sama5d3_atmci_start_image() helper Ahmad Fatoum
2021-04-23 15:54     ` Oleksij Rempel
2021-04-23 15:56       ` Ahmad Fatoum
2021-05-03 10:51   ` Sascha Hauer
2021-04-23 14:28 ` [PATCH v2 3/6] ARM: at91: ddramc: add sama5d3_barebox_entry() handler Oleksij Rempel
2021-04-23 14:28 ` [PATCH v2 4/6] ARM: at91: add __sama5d3_stashed_bootrom_r4 helper Oleksij Rempel
2021-04-23 14:28 ` [PATCH v2 5/6] ARM: at91: add sama5d3_lowlevel_init() helpers Oleksij Rempel
2021-04-23 14:28 ` [PATCH v2 6/6] ARM: at91: sama5d3: add multiimage support for the microchip-ksz9477-evb Oleksij Rempel
2021-04-23 15:29   ` Ahmad Fatoum
2021-04-23 15:51     ` Oleksij Rempel
2021-04-23 15:58       ` Ahmad Fatoum
2021-05-03 10:51 ` [PATCH v2 0/6] add multiimage support for sama5d3 based microchip-ksz9477-evb board 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=20210423142829.29468-3-o.rempel@pengutronix.de \
    --to=o.rempel@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