Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Keystone2: Asynchronous EMIF Configuration |
| 4 | * |
| 5 | * (C) Copyright 2012-2014 |
| 6 | * Texas Instruments Incorporated, <www.ti.com> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Davis | ab82af6 | 2023-11-17 16:38:28 -0600 | [diff] [blame] | 9 | #include <asm/arch/hardware.h> |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 10 | #include <asm/ti-common/ti-aemif.h> |
| 11 | |
Tom Rini | 4d01402 | 2021-09-12 20:32:20 -0400 | [diff] [blame] | 12 | #define AEMIF_WAITCYCLE_CONFIG (KS2_AEMIF_CNTRL_BASE + 0x4) |
| 13 | #define AEMIF_NAND_CONTROL (KS2_AEMIF_CNTRL_BASE + 0x60) |
| 14 | #define AEMIF_ONENAND_CONTROL (KS2_AEMIF_CNTRL_BASE + 0x5c) |
| 15 | #define AEMIF_CONFIG(cs) (KS2_AEMIF_CNTRL_BASE + 0x10 + (cs * 4)) |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 16 | |
| 17 | #define AEMIF_CFG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0) |
| 18 | #define AEMIF_CFG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0) |
| 19 | #define AEMIF_CFG_WR_SETUP(v) (((v) & 0x0f) << 26) |
| 20 | #define AEMIF_CFG_WR_STROBE(v) (((v) & 0x3f) << 20) |
| 21 | #define AEMIF_CFG_WR_HOLD(v) (((v) & 0x07) << 17) |
| 22 | #define AEMIF_CFG_RD_SETUP(v) (((v) & 0x0f) << 13) |
| 23 | #define AEMIF_CFG_RD_STROBE(v) (((v) & 0x3f) << 7) |
| 24 | #define AEMIF_CFG_RD_HOLD(v) (((v) & 0x07) << 4) |
| 25 | #define AEMIF_CFG_TURN_AROUND(v) (((v) & 0x03) << 2) |
| 26 | #define AEMIF_CFG_WIDTH(v) (((v) & 0x03) << 0) |
| 27 | |
| 28 | #define set_config_field(reg, field, val) \ |
| 29 | do { \ |
| 30 | if (val != -1) { \ |
| 31 | reg &= ~AEMIF_CFG_##field(0xffffffff); \ |
| 32 | reg |= AEMIF_CFG_##field(val); \ |
| 33 | } \ |
| 34 | } while (0) |
| 35 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 36 | static void aemif_configure(int cs, struct aemif_config *cfg) |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 37 | { |
| 38 | unsigned long tmp; |
| 39 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 40 | if (cfg->mode == AEMIF_MODE_NAND) { |
| 41 | tmp = __raw_readl(AEMIF_NAND_CONTROL); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 42 | tmp |= (1 << cs); |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 43 | __raw_writel(tmp, AEMIF_NAND_CONTROL); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 44 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 45 | } else if (cfg->mode == AEMIF_MODE_ONENAND) { |
| 46 | tmp = __raw_readl(AEMIF_ONENAND_CONTROL); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 47 | tmp |= (1 << cs); |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 48 | __raw_writel(tmp, AEMIF_ONENAND_CONTROL); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 51 | tmp = __raw_readl(AEMIF_CONFIG(cs)); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 52 | |
| 53 | set_config_field(tmp, SELECT_STROBE, cfg->select_strobe); |
| 54 | set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait); |
| 55 | set_config_field(tmp, WR_SETUP, cfg->wr_setup); |
| 56 | set_config_field(tmp, WR_STROBE, cfg->wr_strobe); |
| 57 | set_config_field(tmp, WR_HOLD, cfg->wr_hold); |
| 58 | set_config_field(tmp, RD_SETUP, cfg->rd_setup); |
| 59 | set_config_field(tmp, RD_STROBE, cfg->rd_strobe); |
| 60 | set_config_field(tmp, RD_HOLD, cfg->rd_hold); |
| 61 | set_config_field(tmp, TURN_AROUND, cfg->turn_around); |
| 62 | set_config_field(tmp, WIDTH, cfg->width); |
| 63 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 64 | __raw_writel(tmp, AEMIF_CONFIG(cs)); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 67 | void aemif_init(int num_cs, struct aemif_config *config) |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 68 | { |
| 69 | int cs; |
| 70 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 71 | if (num_cs > AEMIF_NUM_CS) { |
| 72 | num_cs = AEMIF_NUM_CS; |
| 73 | printf("AEMIF: csnum has to be <= 5"); |
| 74 | } |
| 75 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 76 | for (cs = 0; cs < num_cs; cs++) |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 77 | aemif_configure(cs, config + cs); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 78 | } |