blob: f5c99fea8b378835f04d0187a2232fc502c9b32f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Kever Yang5db9e672017-06-23 16:11:05 +08002/*
3 * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
Kever Yang5db9e672017-06-23 16:11:05 +08004 */
5
6#ifndef _ASM_ARCH_SDRAM_COMMON_H
7#define _ASM_ARCH_SDRAM_COMMON_H
Jagan Teki3d401b22019-07-15 23:51:07 +05308
Jagan Teki7ab369c2019-07-15 23:51:08 +05309enum {
Jagan Teki90974d42019-07-15 23:51:09 +053010 DDR4 = 0,
Jagan Teki7ab369c2019-07-15 23:51:08 +053011 DDR3 = 0x3,
12 LPDDR2 = 0x5,
13 LPDDR3 = 0x6,
14 LPDDR4 = 0x7,
15 UNUSED = 0xFF
16};
17
Jagan Teki3d401b22019-07-15 23:51:07 +053018struct sdram_cap_info {
19 unsigned int rank;
20 /* dram column number, 0 means this channel is invalid */
21 unsigned int col;
22 /* dram bank number, 3:8bank, 2:4bank */
23 unsigned int bk;
24 /* channel buswidth, 2:32bit, 1:16bit, 0:8bit */
25 unsigned int bw;
26 /* die buswidth, 2:32bit, 1:16bit, 0:8bit */
27 unsigned int dbw;
28 /*
29 * row_3_4 = 1: 6Gb or 12Gb die
30 * row_3_4 = 0: normal die, power of 2
31 */
32 unsigned int row_3_4;
33 unsigned int cs0_row;
34 unsigned int cs1_row;
35 unsigned int ddrconfig;
36};
37
38struct sdram_base_params {
39 unsigned int ddr_freq;
40 unsigned int dramtype;
41 unsigned int num_channels;
42 unsigned int stride;
43 unsigned int odt;
44};
45
Kever Yang5db9e672017-06-23 16:11:05 +080046/*
47 * sys_reg bitfield struct
48 * [31] row_3_4_ch1
49 * [30] row_3_4_ch0
50 * [29:28] chinfo
51 * [27] rank_ch1
52 * [26:25] col_ch1
53 * [24] bk_ch1
54 * [23:22] cs0_row_ch1
55 * [21:20] cs1_row_ch1
56 * [19:18] bw_ch1
57 * [17:16] dbw_ch1;
58 * [15:13] ddrtype
59 * [12] channelnum
60 * [11] rank_ch0
61 * [10:9] col_ch0
62 * [8] bk_ch0
63 * [7:6] cs0_row_ch0
64 * [5:4] cs1_row_ch0
65 * [3:2] bw_ch0
66 * [1:0] dbw_ch0
67*/
68#define SYS_REG_DDRTYPE_SHIFT 13
69#define SYS_REG_DDRTYPE_MASK 7
70#define SYS_REG_NUM_CH_SHIFT 12
71#define SYS_REG_NUM_CH_MASK 1
72#define SYS_REG_ROW_3_4_SHIFT(ch) (30 + (ch))
73#define SYS_REG_ROW_3_4_MASK 1
Jagan Tekie79ea0e2019-07-16 17:26:49 +053074#define SYS_REG_ENC_ROW_3_4(n, ch) ((n) << (30 + (ch)))
Kever Yang5db9e672017-06-23 16:11:05 +080075#define SYS_REG_CHINFO_SHIFT(ch) (28 + (ch))
Jagan Tekie79ea0e2019-07-16 17:26:49 +053076#define SYS_REG_ENC_CHINFO(ch) (1 << SYS_REG_CHINFO_SHIFT(ch))
77#define SYS_REG_ENC_DDRTYPE(n) ((n) << SYS_REG_DDRTYPE_SHIFT)
78#define SYS_REG_ENC_NUM_CH(n) (((n) - SYS_REG_NUM_CH_MASK) << \
79 SYS_REG_NUM_CH_SHIFT)
Kever Yang5db9e672017-06-23 16:11:05 +080080#define SYS_REG_RANK_SHIFT(ch) (11 + (ch) * 16)
81#define SYS_REG_RANK_MASK 1
Jagan Tekie79ea0e2019-07-16 17:26:49 +053082#define SYS_REG_ENC_RANK(n, ch) (((n) - SYS_REG_RANK_MASK) << \
83 SYS_REG_RANK_SHIFT(ch))
Kever Yang5db9e672017-06-23 16:11:05 +080084#define SYS_REG_COL_SHIFT(ch) (9 + (ch) * 16)
85#define SYS_REG_COL_MASK 3
Jagan Tekie79ea0e2019-07-16 17:26:49 +053086#define SYS_REG_ENC_COL(n, ch) (((n) - 9) << SYS_REG_COL_SHIFT(ch))
Kever Yang5db9e672017-06-23 16:11:05 +080087#define SYS_REG_BK_SHIFT(ch) (8 + (ch) * 16)
88#define SYS_REG_BK_MASK 1
Jagan Tekie79ea0e2019-07-16 17:26:49 +053089#define SYS_REG_ENC_BK(n, ch) (((n) == 3 ? 0 : 1) << \
90 SYS_REG_BK_SHIFT(ch))
Kever Yang5db9e672017-06-23 16:11:05 +080091#define SYS_REG_CS0_ROW_SHIFT(ch) (6 + (ch) * 16)
92#define SYS_REG_CS0_ROW_MASK 3
93#define SYS_REG_CS1_ROW_SHIFT(ch) (4 + (ch) * 16)
94#define SYS_REG_CS1_ROW_MASK 3
95#define SYS_REG_BW_SHIFT(ch) (2 + (ch) * 16)
96#define SYS_REG_BW_MASK 3
Jagan Tekie79ea0e2019-07-16 17:26:49 +053097#define SYS_REG_ENC_BW(n, ch) ((2 >> (n)) << SYS_REG_BW_SHIFT(ch))
Kever Yang5db9e672017-06-23 16:11:05 +080098#define SYS_REG_DBW_SHIFT(ch) ((ch) * 16)
99#define SYS_REG_DBW_MASK 3
Jagan Tekie79ea0e2019-07-16 17:26:49 +0530100#define SYS_REG_ENC_DBW(n, ch) ((2 >> (n)) << SYS_REG_DBW_SHIFT(ch))
Kever Yang5db9e672017-06-23 16:11:05 +0800101
Jagan Teki9d8769c2019-07-16 17:27:01 +0530102#define SYS_REG_ENC_CS0_ROW(n, os_reg2, os_reg3, ch) do { \
103 (os_reg2) |= (((n) - 13) & 0x3) << (6 + 16 * (ch)); \
104 (os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
105 (5 + 2 * (ch)); \
106 } while (0)
107
108#define SYS_REG_ENC_CS1_ROW(n, os_reg2, os_reg3, ch) do { \
109 (os_reg2) &= (~(0x3 << (4 + 16 * (ch)))); \
110 (os_reg3) &= (~(0x1 << (4 + 2 * (ch)))); \
111 (os_reg2) |= (((n) - 13) & 0x3) << (4 + 16 * (ch)); \
112 (os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
113 (4 + 2 * (ch)); \
114 } while (0)
115
116#define SYS_REG_CS1_COL_SHIFT(ch) (0 + 2 * (ch))
117#define SYS_REG_ENC_CS1_COL(n, ch) (((n) - 9) << SYS_REG_CS1_COL_SHIFT(ch))
118
Kever Yang5db9e672017-06-23 16:11:05 +0800119/* Get sdram size decode from reg */
120size_t rockchip_sdram_size(phys_addr_t reg);
121
122/* Called by U-Boot board_init_r for Rockchip SoCs */
123int dram_init(void);
Jagan Tekiced3ea62019-07-15 23:58:48 +0530124
125#if !defined(CONFIG_RAM_ROCKCHIP_DEBUG)
126inline void sdram_print_dram_type(unsigned char dramtype)
127{
128}
Jagan Tekifb20cf92019-07-15 23:58:49 +0530129
130inline void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
131 struct sdram_base_params *base)
132{
133}
Jagan Teki0d11fa32019-07-15 23:58:51 +0530134
135inline void sdram_print_stride(unsigned int stride)
136{
137}
Jagan Tekiced3ea62019-07-15 23:58:48 +0530138#else
139void sdram_print_dram_type(unsigned char dramtype);
Jagan Tekifb20cf92019-07-15 23:58:49 +0530140void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
141 struct sdram_base_params *base);
Jagan Teki0d11fa32019-07-15 23:58:51 +0530142void sdram_print_stride(unsigned int stride);
Jagan Tekiced3ea62019-07-15 23:58:48 +0530143#endif /* CONFIG_RAM_ROCKCHIP_DEBUG */
144
Kever Yang5db9e672017-06-23 16:11:05 +0800145#endif