2014-04-04 17:16:53 +00:00
|
|
|
/*
|
|
|
|
* Keystone2: Asynchronous EMIF Configuration
|
|
|
|
*
|
|
|
|
* (C) Copyright 2012-2014
|
|
|
|
* Texas Instruments Incorporated, <www.ti.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2014-06-07 02:10:49 +00:00
|
|
|
#include <asm/ti-common/ti-aemif.h>
|
|
|
|
|
|
|
|
#define AEMIF_WAITCYCLE_CONFIG (CONFIG_AEMIF_CNTRL_BASE + 0x4)
|
|
|
|
#define AEMIF_NAND_CONTROL (CONFIG_AEMIF_CNTRL_BASE + 0x60)
|
|
|
|
#define AEMIF_ONENAND_CONTROL (CONFIG_AEMIF_CNTRL_BASE + 0x5c)
|
|
|
|
#define AEMIF_CONFIG(cs) (CONFIG_AEMIF_CNTRL_BASE + 0x10 \
|
|
|
|
+ (cs * 4))
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
#define AEMIF_CFG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0)
|
|
|
|
#define AEMIF_CFG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0)
|
|
|
|
#define AEMIF_CFG_WR_SETUP(v) (((v) & 0x0f) << 26)
|
|
|
|
#define AEMIF_CFG_WR_STROBE(v) (((v) & 0x3f) << 20)
|
|
|
|
#define AEMIF_CFG_WR_HOLD(v) (((v) & 0x07) << 17)
|
|
|
|
#define AEMIF_CFG_RD_SETUP(v) (((v) & 0x0f) << 13)
|
|
|
|
#define AEMIF_CFG_RD_STROBE(v) (((v) & 0x3f) << 7)
|
|
|
|
#define AEMIF_CFG_RD_HOLD(v) (((v) & 0x07) << 4)
|
|
|
|
#define AEMIF_CFG_TURN_AROUND(v) (((v) & 0x03) << 2)
|
|
|
|
#define AEMIF_CFG_WIDTH(v) (((v) & 0x03) << 0)
|
|
|
|
|
|
|
|
#define set_config_field(reg, field, val) \
|
|
|
|
do { \
|
|
|
|
if (val != -1) { \
|
|
|
|
reg &= ~AEMIF_CFG_##field(0xffffffff); \
|
|
|
|
reg |= AEMIF_CFG_##field(val); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-06-07 02:10:49 +00:00
|
|
|
static void aemif_configure(int cs, struct aemif_config *cfg)
|
2014-04-04 17:16:53 +00:00
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
|
2014-06-07 02:10:49 +00:00
|
|
|
if (cfg->mode == AEMIF_MODE_NAND) {
|
|
|
|
tmp = __raw_readl(AEMIF_NAND_CONTROL);
|
2014-04-04 17:16:53 +00:00
|
|
|
tmp |= (1 << cs);
|
2014-06-07 02:10:49 +00:00
|
|
|
__raw_writel(tmp, AEMIF_NAND_CONTROL);
|
2014-04-04 17:16:53 +00:00
|
|
|
|
2014-06-07 02:10:49 +00:00
|
|
|
} else if (cfg->mode == AEMIF_MODE_ONENAND) {
|
|
|
|
tmp = __raw_readl(AEMIF_ONENAND_CONTROL);
|
2014-04-04 17:16:53 +00:00
|
|
|
tmp |= (1 << cs);
|
2014-06-07 02:10:49 +00:00
|
|
|
__raw_writel(tmp, AEMIF_ONENAND_CONTROL);
|
2014-04-04 17:16:53 +00:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:10:49 +00:00
|
|
|
tmp = __raw_readl(AEMIF_CONFIG(cs));
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
set_config_field(tmp, SELECT_STROBE, cfg->select_strobe);
|
|
|
|
set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait);
|
|
|
|
set_config_field(tmp, WR_SETUP, cfg->wr_setup);
|
|
|
|
set_config_field(tmp, WR_STROBE, cfg->wr_strobe);
|
|
|
|
set_config_field(tmp, WR_HOLD, cfg->wr_hold);
|
|
|
|
set_config_field(tmp, RD_SETUP, cfg->rd_setup);
|
|
|
|
set_config_field(tmp, RD_STROBE, cfg->rd_strobe);
|
|
|
|
set_config_field(tmp, RD_HOLD, cfg->rd_hold);
|
|
|
|
set_config_field(tmp, TURN_AROUND, cfg->turn_around);
|
|
|
|
set_config_field(tmp, WIDTH, cfg->width);
|
|
|
|
|
2014-06-07 02:10:49 +00:00
|
|
|
__raw_writel(tmp, AEMIF_CONFIG(cs));
|
2014-04-04 17:16:53 +00:00
|
|
|
}
|
|
|
|
|
2014-06-07 02:10:49 +00:00
|
|
|
void aemif_init(int num_cs, struct aemif_config *config)
|
2014-04-04 17:16:53 +00:00
|
|
|
{
|
|
|
|
int cs;
|
|
|
|
|
2014-06-07 02:10:49 +00:00
|
|
|
if (num_cs > AEMIF_NUM_CS) {
|
|
|
|
num_cs = AEMIF_NUM_CS;
|
|
|
|
printf("AEMIF: csnum has to be <= 5");
|
|
|
|
}
|
|
|
|
|
2014-04-04 17:16:53 +00:00
|
|
|
for (cs = 0; cs < num_cs; cs++)
|
2014-06-07 02:10:49 +00:00
|
|
|
aemif_configure(cs, config + cs);
|
2014-04-04 17:16:53 +00:00
|
|
|
}
|