summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-at91
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-07-01 11:11:12 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-07-11 06:14:04 +0200
commitf322224716c394c9825a553b16b25db243e8d868 (patch)
tree210e0c6a16f85e0116af42f769959175906a5497 /arch/arm/mach-at91
parent76b717212c8d907508ce2737ecb155a71aa789db (diff)
downloadbarebox-f322224716c394c9825a553b16b25db243e8d868.tar.gz
barebox-f322224716c394c9825a553b16b25db243e8d868.tar.xz
ARM: at91: add code for sama5 boot source detection
SAMA5 BootROM passes information about the boot source in the r4 register. Add functions to parse these. To make use of this, entry point must back up the r4 register, because otherwise it's clobbered by local variable use. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-at91')
-rw-r--r--arch/arm/mach-at91/include/mach/sama5_bootsource.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/arch/arm/mach-at91/include/mach/sama5_bootsource.h b/arch/arm/mach-at91/include/mach/sama5_bootsource.h
new file mode 100644
index 0000000000..29354dcaf3
--- /dev/null
+++ b/arch/arm/mach-at91/include/mach/sama5_bootsource.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef AT91_SAMA5_BOOTSOURCE_H_
+#define AT91_SAMA5_BOOTSOURCE_H_
+
+#include <errno.h>
+#include <bootsource.h>
+#include <linux/bitops.h>
+#include <linux/bitfield.h>
+#include <mach/hardware.h>
+
+/* Boot modes stored by BootROM in r4 */
+#define SAMA5_BOOTSOURCE_SPI 0
+#define SAMA5_BOOTSOURCE_MCI 1
+#define SAMA5_BOOTSOURCE_SMC 2
+#define SAMA5_BOOTSOURCE_TWI 3
+#define SAMA5_BOOTSOURCE_QSPI 4
+#define SAMA5_BOOTSOURCE_SAM_BA 7
+
+#define SAMA5_BOOTSOURCE GENMASK(3, 0)
+#define SAMA5_BOOTSOURCE_INSTANCE GENMASK(7, 4)
+
+static inline int sama5_bootsource(u32 reg)
+{
+ u32 dev = FIELD_GET(SAMA5_BOOTSOURCE, reg);
+
+ switch(dev) {
+ case SAMA5_BOOTSOURCE_MCI:
+ return BOOTSOURCE_MMC;
+ case SAMA5_BOOTSOURCE_SPI:
+ return BOOTSOURCE_SPI_NOR;
+ case SAMA5_BOOTSOURCE_QSPI:
+ return BOOTSOURCE_SPI;
+ case SAMA5_BOOTSOURCE_SMC:
+ return BOOTSOURCE_NAND;
+ case SAMA5_BOOTSOURCE_SAM_BA:
+ return BOOTSOURCE_SERIAL;
+ }
+ return BOOTSOURCE_UNKNOWN;
+}
+
+static inline int sama5_bootsource_instance(u32 reg)
+{
+ return FIELD_GET(SAMA5_BOOTSOURCE_INSTANCE, reg);
+}
+
+#endif