Cyril Chemparathy | 692a7af | 2010-06-07 14:13:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * TNETV107X: Asynchronous EMIF Configuration |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Cyril Chemparathy | 692a7af | 2010-06-07 14:13:32 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/clock.h> |
| 10 | #include <asm/arch/mux.h> |
| 11 | |
| 12 | #define ASYNC_EMIF_BASE TNETV107X_ASYNC_EMIF_CNTRL_BASE |
| 13 | #define ASYNC_EMIF_CONFIG(cs) (ASYNC_EMIF_BASE+0x10+(cs)*4) |
| 14 | #define ASYNC_EMIF_ONENAND_CONTROL (ASYNC_EMIF_BASE+0x5c) |
| 15 | #define ASYNC_EMIF_NAND_CONTROL (ASYNC_EMIF_BASE+0x60) |
| 16 | #define ASYNC_EMIF_WAITCYCLE_CONFIG (ASYNC_EMIF_BASE+0x4) |
| 17 | |
| 18 | #define CONFIG_SELECT_STROBE(v) ((v) ? 1 << 31 : 0) |
| 19 | #define CONFIG_EXTEND_WAIT(v) ((v) ? 1 << 30 : 0) |
| 20 | #define CONFIG_WR_SETUP(v) (((v) & 0x0f) << 26) |
| 21 | #define CONFIG_WR_STROBE(v) (((v) & 0x3f) << 20) |
| 22 | #define CONFIG_WR_HOLD(v) (((v) & 0x07) << 17) |
| 23 | #define CONFIG_RD_SETUP(v) (((v) & 0x0f) << 13) |
| 24 | #define CONFIG_RD_STROBE(v) (((v) & 0x3f) << 7) |
| 25 | #define CONFIG_RD_HOLD(v) (((v) & 0x07) << 4) |
| 26 | #define CONFIG_TURN_AROUND(v) (((v) & 0x03) << 2) |
| 27 | #define CONFIG_WIDTH(v) (((v) & 0x03) << 0) |
| 28 | |
| 29 | #define NUM_CS 4 |
| 30 | |
| 31 | #define set_config_field(reg, field, val) \ |
| 32 | do { \ |
| 33 | if (val != -1) { \ |
| 34 | reg &= ~CONFIG_##field(0xffffffff); \ |
| 35 | reg |= CONFIG_##field(val); \ |
| 36 | } \ |
| 37 | } while (0) |
| 38 | |
| 39 | void configure_async_emif(int cs, struct async_emif_config *cfg) |
| 40 | { |
| 41 | unsigned long tmp; |
| 42 | |
| 43 | if (cfg->mode == ASYNC_EMIF_MODE_NAND) { |
| 44 | tmp = __raw_readl(ASYNC_EMIF_NAND_CONTROL); |
| 45 | tmp |= (1 << cs); |
| 46 | __raw_writel(tmp, ASYNC_EMIF_NAND_CONTROL); |
| 47 | |
| 48 | } else if (cfg->mode == ASYNC_EMIF_MODE_ONENAND) { |
| 49 | tmp = __raw_readl(ASYNC_EMIF_ONENAND_CONTROL); |
| 50 | tmp |= (1 << cs); |
| 51 | __raw_writel(tmp, ASYNC_EMIF_ONENAND_CONTROL); |
| 52 | } |
| 53 | |
| 54 | tmp = __raw_readl(ASYNC_EMIF_CONFIG(cs)); |
| 55 | |
| 56 | set_config_field(tmp, SELECT_STROBE, cfg->select_strobe); |
| 57 | set_config_field(tmp, EXTEND_WAIT, cfg->extend_wait); |
| 58 | set_config_field(tmp, WR_SETUP, cfg->wr_setup); |
| 59 | set_config_field(tmp, WR_STROBE, cfg->wr_strobe); |
| 60 | set_config_field(tmp, WR_HOLD, cfg->wr_hold); |
| 61 | set_config_field(tmp, RD_SETUP, cfg->rd_setup); |
| 62 | set_config_field(tmp, RD_STROBE, cfg->rd_strobe); |
| 63 | set_config_field(tmp, RD_HOLD, cfg->rd_hold); |
| 64 | set_config_field(tmp, TURN_AROUND, cfg->turn_around); |
| 65 | set_config_field(tmp, WIDTH, cfg->width); |
| 66 | |
| 67 | __raw_writel(tmp, ASYNC_EMIF_CONFIG(cs)); |
| 68 | } |
| 69 | |
| 70 | void init_async_emif(int num_cs, struct async_emif_config *config) |
| 71 | { |
| 72 | int cs; |
| 73 | |
| 74 | clk_enable(TNETV107X_LPSC_AEMIF); |
| 75 | |
| 76 | for (cs = 0; cs < num_cs; cs++) |
| 77 | configure_async_emif(cs, config + cs); |
| 78 | } |