blob: f821daea4e1438f2535126716d67246d3b485e91 [file] [log] [blame]
Vitaly Andrianovef509b92014-04-04 13:16:53 -04001/*
2 * Keystone2: Asynchronous EMIF Configuration
3 *
4 * (C) Copyright 2012-2014
5 * Texas Instruments Incorporated, <www.ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030011#include <asm/ti-common/ti-aemif.h>
12
13#define AEMIF_WAITCYCLE_CONFIG (CONFIG_AEMIF_CNTRL_BASE + 0x4)
14#define AEMIF_NAND_CONTROL (CONFIG_AEMIF_CNTRL_BASE + 0x60)
15#define AEMIF_ONENAND_CONTROL (CONFIG_AEMIF_CNTRL_BASE + 0x5c)
16#define AEMIF_CONFIG(cs) (CONFIG_AEMIF_CNTRL_BASE + 0x10 \
17 + (cs * 4))
Vitaly Andrianovef509b92014-04-04 13:16:53 -040018
19#define AEMIF_CFG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0)
20#define AEMIF_CFG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0)
21#define AEMIF_CFG_WR_SETUP(v) (((v) & 0x0f) << 26)
22#define AEMIF_CFG_WR_STROBE(v) (((v) & 0x3f) << 20)
23#define AEMIF_CFG_WR_HOLD(v) (((v) & 0x07) << 17)
24#define AEMIF_CFG_RD_SETUP(v) (((v) & 0x0f) << 13)
25#define AEMIF_CFG_RD_STROBE(v) (((v) & 0x3f) << 7)
26#define AEMIF_CFG_RD_HOLD(v) (((v) & 0x07) << 4)
27#define AEMIF_CFG_TURN_AROUND(v) (((v) & 0x03) << 2)
28#define AEMIF_CFG_WIDTH(v) (((v) & 0x03) << 0)
29
30#define set_config_field(reg, field, val) \
31 do { \
32 if (val != -1) { \
33 reg &= ~AEMIF_CFG_##field(0xffffffff); \
34 reg |= AEMIF_CFG_##field(val); \
35 } \
36 } while (0)
37
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030038static void aemif_configure(int cs, struct aemif_config *cfg)
Vitaly Andrianovef509b92014-04-04 13:16:53 -040039{
40 unsigned long tmp;
41
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030042 if (cfg->mode == AEMIF_MODE_NAND) {
43 tmp = __raw_readl(AEMIF_NAND_CONTROL);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040044 tmp |= (1 << cs);
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030045 __raw_writel(tmp, AEMIF_NAND_CONTROL);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040046
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030047 } else if (cfg->mode == AEMIF_MODE_ONENAND) {
48 tmp = __raw_readl(AEMIF_ONENAND_CONTROL);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040049 tmp |= (1 << cs);
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030050 __raw_writel(tmp, AEMIF_ONENAND_CONTROL);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040051 }
52
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030053 tmp = __raw_readl(AEMIF_CONFIG(cs));
Vitaly Andrianovef509b92014-04-04 13:16:53 -040054
55 set_config_field(tmp, SELECT_STROBE, cfg->select_strobe);
56 set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait);
57 set_config_field(tmp, WR_SETUP, cfg->wr_setup);
58 set_config_field(tmp, WR_STROBE, cfg->wr_strobe);
59 set_config_field(tmp, WR_HOLD, cfg->wr_hold);
60 set_config_field(tmp, RD_SETUP, cfg->rd_setup);
61 set_config_field(tmp, RD_STROBE, cfg->rd_strobe);
62 set_config_field(tmp, RD_HOLD, cfg->rd_hold);
63 set_config_field(tmp, TURN_AROUND, cfg->turn_around);
64 set_config_field(tmp, WIDTH, cfg->width);
65
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030066 __raw_writel(tmp, AEMIF_CONFIG(cs));
Vitaly Andrianovef509b92014-04-04 13:16:53 -040067}
68
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030069void aemif_init(int num_cs, struct aemif_config *config)
Vitaly Andrianovef509b92014-04-04 13:16:53 -040070{
71 int cs;
72
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030073 if (num_cs > AEMIF_NUM_CS) {
74 num_cs = AEMIF_NUM_CS;
75 printf("AEMIF: csnum has to be <= 5");
76 }
77
Vitaly Andrianovef509b92014-04-04 13:16:53 -040078 for (cs = 0; cs < num_cs; cs++)
Khoronzhuk, Ivan909ea9a2014-06-07 05:10:49 +030079 aemif_configure(cs, config + cs);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040080}