From 2b0606f603de13524ce9b63578f4c3358c3ac6df Mon Sep 17 00:00:00 2001
From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Date: Thu, 22 Dec 2022 12:15:42 +0000
Subject: [PATCH 29/43] sandbox64: add support for NVMXIP QSPI

enable NVMXIP QSPI for sandbox 64-bit

Adding two NVM XIP QSPI storage devices.

Upstream-Status: Submitted
Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
---
 arch/sandbox/dts/sandbox64.dts | 13 +++++++++++++
 arch/sandbox/dts/test.dts      | 14 ++++++++++++++
 configs/sandbox_defconfig      |  1 +
 drivers/nvmxip/nvmxip.c        |  4 ++++
 drivers/nvmxip/nvmxip.h        |  3 +++
 5 files changed, 35 insertions(+)

diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts
index a9cd7908f83e..aed3801af8a9 100644
--- a/arch/sandbox/dts/sandbox64.dts
+++ b/arch/sandbox/dts/sandbox64.dts
@@ -89,6 +89,19 @@
 		cs-gpios = <0>, <&gpio_a 0>;
 	};
 
+	nvmxip-qspi1@08000000 {
+		compatible = "nvmxip,qspi";
+		reg = <0x0 0x08000000 0x0 0x00200000>;
+		lba_shift = <9>;
+		lba = <4096>;
+	};
+
+	nvmxip-qspi2@08200000 {
+		compatible = "nvmxip,qspi";
+		reg = <0x0 0x08200000 0x0 0x00100000>;
+		lba_shift = <9>;
+		lba = <2048>;
+	};
 };
 
 #include "sandbox.dtsi"
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 2e580f980fc6..54f2b308e793 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1756,6 +1756,20 @@
 		compatible = "u-boot,fwu-mdata-gpt";
 		fwu-mdata-store = <&mmc0>;
 	};
+
+	nvmxip-qspi1@08000000 {
+		compatible = "nvmxip,qspi";
+		reg = <0x08000000 0x00200000>;
+		lba_shift = <9>;
+		lba = <4096>;
+	};
+
+	nvmxip-qspi2@08200000 {
+		compatible = "nvmxip,qspi";
+		reg = <0x08200000 0x00100000>;
+		lba_shift = <9>;
+		lba = <2048>;
+	};
 };
 
 #include "sandbox_pmic.dtsi"
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index e6ea96a6b924..f22230b5cce2 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -138,6 +138,7 @@ CONFIG_NETCONSOLE=y
 CONFIG_IP_DEFRAG=y
 CONFIG_BOOTP_SERVERIP=y
 CONFIG_IPV6=y
+CONFIG_NVMXIP_QSPI=y
 CONFIG_DM_DMA=y
 CONFIG_DEVRES=y
 CONFIG_DEBUG_DEVRES=y
diff --git a/drivers/nvmxip/nvmxip.c b/drivers/nvmxip/nvmxip.c
index 6ba48183c575..af9c9a3b7270 100644
--- a/drivers/nvmxip/nvmxip.c
+++ b/drivers/nvmxip/nvmxip.c
@@ -85,6 +85,10 @@ int nvmxip_init(struct udevice *udev)
 	priv_data->udev = udev;
 	priv_data->plat_data = plat_data;
 
+#if CONFIG_IS_ENABLED(SANDBOX64)
+	sandbox_set_enable_memio(true);
+#endif
+
 	nvmxip_bdev_max_devs++;
 
 	snprintf(bdev_name, NVMXIP_BLKDEV_NAME_SZ, "nvmxip-blk#%d", nvmxip_bdev_max_devs);
diff --git a/drivers/nvmxip/nvmxip.h b/drivers/nvmxip/nvmxip.h
index 393172cc2f86..0384ce2e2b47 100644
--- a/drivers/nvmxip/nvmxip.h
+++ b/drivers/nvmxip/nvmxip.h
@@ -8,6 +8,9 @@
 #define __DRIVER_NVMXIP_H__
 
 #include <asm/io.h>
+#if CONFIG_IS_ENABLED(SANDBOX64)
+#include <asm/test.h>
+#endif
 #include <blk.h>
 #include <linux/bitops.h>
 #include <linux/compat.h>
-- 
2.39.2

