memory: ti-aemif: Make AEMIF driver architecture agnostic

AEMIF controller is present on other SoCs than the Keystone ones.

Remove Keystone specificities from the driver to be able to use it from
other architectures.
Adapt the ks2_evm/board.c to fit the new driver.

Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
diff --git a/arch/arm/include/asm/ti-common/ti-aemif.h b/arch/arm/include/asm/ti-common/ti-aemif.h
index a775386..11a7384 100644
--- a/arch/arm/include/asm/ti-common/ti-aemif.h
+++ b/arch/arm/include/asm/ti-common/ti-aemif.h
@@ -16,6 +16,7 @@
 #define AEMIF_PRESERVE             -1
 
 struct aemif_config {
+	void *base;
 	unsigned mode;
 	unsigned select_strobe;
 	unsigned extend_wait;
diff --git a/board/ti/ks2_evm/board.c b/board/ti/ks2_evm/board.c
index c6735d3..b2f0dce 100644
--- a/board/ti/ks2_evm/board.c
+++ b/board/ti/ks2_evm/board.c
@@ -49,8 +49,10 @@
 	gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE,
 				    CFG_MAX_RAM_BANK_SIZE);
 #if defined(CONFIG_TI_AEMIF)
-	if (!(board_is_k2g_ice() || board_is_k2g_i1()))
+	if (!(board_is_k2g_ice() || board_is_k2g_i1())) {
+		aemif_configs->base = (void *)KS2_AEMIF_CNTRL_BASE;
 		aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
+	}
 #endif
 
 	if (!(board_is_k2g_ice() || board_is_k2g_i1())) {
diff --git a/drivers/memory/ti-aemif.c b/drivers/memory/ti-aemif.c
index 127a262..8e7ddde 100644
--- a/drivers/memory/ti-aemif.c
+++ b/drivers/memory/ti-aemif.c
@@ -9,10 +9,10 @@
 #include <asm/arch/hardware.h>
 #include <asm/ti-common/ti-aemif.h>
 
-#define AEMIF_WAITCYCLE_CONFIG		(KS2_AEMIF_CNTRL_BASE + 0x4)
-#define AEMIF_NAND_CONTROL		(KS2_AEMIF_CNTRL_BASE + 0x60)
-#define AEMIF_ONENAND_CONTROL		(KS2_AEMIF_CNTRL_BASE + 0x5c)
-#define AEMIF_CONFIG(cs)		(KS2_AEMIF_CNTRL_BASE + 0x10 + ((cs) * 4))
+#define AEMIF_WAITCYCLE_CONFIG		(0x4)
+#define AEMIF_NAND_CONTROL		(0x60)
+#define AEMIF_ONENAND_CONTROL		(0x5c)
+#define AEMIF_CONFIG(cs)		(0x10 + ((cs) * 4))
 
 #define AEMIF_CFG_SELECT_STROBE(v)	((v) ? 1 << 31 : 0)
 #define AEMIF_CFG_EXTEND_WAIT(v)	((v) ? 1 << 30 : 0)
@@ -38,17 +38,17 @@
 	unsigned long tmp;
 
 	if (cfg->mode == AEMIF_MODE_NAND) {
-		tmp = __raw_readl(AEMIF_NAND_CONTROL);
+		tmp = __raw_readl(cfg->base + AEMIF_NAND_CONTROL);
 		tmp |= (1 << cs);
-		__raw_writel(tmp, AEMIF_NAND_CONTROL);
+		__raw_writel(tmp, cfg->base + AEMIF_NAND_CONTROL);
 
 	} else if (cfg->mode == AEMIF_MODE_ONENAND) {
-		tmp = __raw_readl(AEMIF_ONENAND_CONTROL);
+		tmp = __raw_readl(cfg->base + AEMIF_ONENAND_CONTROL);
 		tmp |= (1 << cs);
-		__raw_writel(tmp, AEMIF_ONENAND_CONTROL);
+		__raw_writel(tmp, cfg->base + AEMIF_ONENAND_CONTROL);
 	}
 
-	tmp = __raw_readl(AEMIF_CONFIG(cs));
+	tmp = __raw_readl(cfg->base + AEMIF_CONFIG(cs));
 
 	set_config_field(tmp, SELECT_STROBE,	cfg->select_strobe);
 	set_config_field(tmp, EXTEND_WAIT,	cfg->extend_wait);
@@ -61,7 +61,7 @@
 	set_config_field(tmp, TURN_AROUND,	cfg->turn_around);
 	set_config_field(tmp, WIDTH,		cfg->width);
 
-	__raw_writel(tmp, AEMIF_CONFIG(cs));
+	__raw_writel(tmp, cfg->base + AEMIF_CONFIG(cs));
 }
 
 void aemif_init(int num_cs, struct aemif_config *config)