blob: 4fb45ac5c76e671e9fbccde651840910ddfdde01 [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
Kever Yange47db832019-11-15 11:04:33 +08006#ifndef _ASM_ARCH_SDRAM_H
7#define _ASM_ARCH_SDRAM_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,
Jonas Karlmanf570c252023-02-07 17:27:10 +000011 DDR3 = 3,
12 LPDDR2 = 5,
13 LPDDR3 = 6,
14 LPDDR4 = 7,
15 LPDDR4X = 8,
16 LPDDR5 = 9,
17 DDR5 = 10,
Jagan Teki7ab369c2019-07-15 23:51:08 +053018 UNUSED = 0xFF
19};
20
Kever Yang5db9e672017-06-23 16:11:05 +080021/*
Kever Yang117585a2019-11-15 11:04:35 +080022 * sys_reg2 bitfield struct
Kever Yang5db9e672017-06-23 16:11:05 +080023 * [31] row_3_4_ch1
24 * [30] row_3_4_ch0
25 * [29:28] chinfo
26 * [27] rank_ch1
Jonas Karlmanf570c252023-02-07 17:27:10 +000027 * [26:25] cs0_col_ch1
Kever Yang5db9e672017-06-23 16:11:05 +080028 * [24] bk_ch1
Kever Yang117585a2019-11-15 11:04:35 +080029 * [23:22] low bits of cs0_row_ch1
30 * [21:20] low bits of cs1_row_ch1
Kever Yang5db9e672017-06-23 16:11:05 +080031 * [19:18] bw_ch1
Jonas Karlmanf570c252023-02-07 17:27:10 +000032 * [17:16] dbw_ch1
33 * [15:13] low bits of ddrtype
Kever Yang5db9e672017-06-23 16:11:05 +080034 * [12] channelnum
Jonas Karlmanf570c252023-02-07 17:27:10 +000035 * [11] low bit of rank_ch0
36 * [10:9] cs0_col_ch0
Kever Yang5db9e672017-06-23 16:11:05 +080037 * [8] bk_ch0
Kever Yang117585a2019-11-15 11:04:35 +080038 * [7:6] low bits of cs0_row_ch0
39 * [5:4] low bits of cs1_row_ch0
Kever Yang5db9e672017-06-23 16:11:05 +080040 * [3:2] bw_ch0
41 * [1:0] dbw_ch0
Kever Yang117585a2019-11-15 11:04:35 +080042 */
Kever Yang5db9e672017-06-23 16:11:05 +080043#define SYS_REG_DDRTYPE_SHIFT 13
44#define SYS_REG_DDRTYPE_MASK 7
45#define SYS_REG_NUM_CH_SHIFT 12
46#define SYS_REG_NUM_CH_MASK 1
47#define SYS_REG_ROW_3_4_SHIFT(ch) (30 + (ch))
48#define SYS_REG_ROW_3_4_MASK 1
49#define SYS_REG_CHINFO_SHIFT(ch) (28 + (ch))
50#define SYS_REG_RANK_SHIFT(ch) (11 + (ch) * 16)
51#define SYS_REG_RANK_MASK 1
52#define SYS_REG_COL_SHIFT(ch) (9 + (ch) * 16)
53#define SYS_REG_COL_MASK 3
54#define SYS_REG_BK_SHIFT(ch) (8 + (ch) * 16)
55#define SYS_REG_BK_MASK 1
56#define SYS_REG_CS0_ROW_SHIFT(ch) (6 + (ch) * 16)
57#define SYS_REG_CS0_ROW_MASK 3
58#define SYS_REG_CS1_ROW_SHIFT(ch) (4 + (ch) * 16)
59#define SYS_REG_CS1_ROW_MASK 3
60#define SYS_REG_BW_SHIFT(ch) (2 + (ch) * 16)
61#define SYS_REG_BW_MASK 3
62#define SYS_REG_DBW_SHIFT(ch) ((ch) * 16)
63#define SYS_REG_DBW_MASK 3
Jagan Teki9d8769c2019-07-16 17:27:01 +053064
Kever Yang117585a2019-11-15 11:04:35 +080065/*
66 * sys_reg3 bitfield struct
Jonas Karlmanf570c252023-02-07 17:27:10 +000067 * [31:28] version
68 * [16] cs3_delta_row
69 * [15] cs2_delta_row
70 * [14] high bit of rank_ch0
71 * [13:12] high bits of ddrtype
Kever Yang117585a2019-11-15 11:04:35 +080072 * [7] high bit of cs0_row_ch1
73 * [6] high bit of cs1_row_ch1
74 * [5] high bit of cs0_row_ch0
75 * [4] high bit of cs1_row_ch0
76 * [3:2] cs1_col_ch1
77 * [1:0] cs1_col_ch0
78 */
79#define SYS_REG_VERSION_SHIFT 28
80#define SYS_REG_VERSION_MASK 0xf
Jonas Karlmanf570c252023-02-07 17:27:10 +000081#define SYS_REG_EXTEND_DDRTYPE_SHIFT 12
82#define SYS_REG_EXTEND_DDRTYPE_MASK 3
Kever Yang117585a2019-11-15 11:04:35 +080083#define SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) (5 + (ch) * 2)
84#define SYS_REG_EXTEND_CS0_ROW_MASK 1
85#define SYS_REG_EXTEND_CS1_ROW_SHIFT(ch) (4 + (ch) * 2)
86#define SYS_REG_EXTEND_CS1_ROW_MASK 1
87#define SYS_REG_CS1_COL_SHIFT(ch) (0 + (ch) * 2)
88#define SYS_REG_CS1_COL_MASK 3
Jagan Teki9d8769c2019-07-16 17:27:01 +053089
Kever Yang5db9e672017-06-23 16:11:05 +080090/* Get sdram size decode from reg */
91size_t rockchip_sdram_size(phys_addr_t reg);
92
93/* Called by U-Boot board_init_r for Rockchip SoCs */
94int dram_init(void);
Jagan Tekiced3ea62019-07-15 23:58:48 +053095
Kever Yang5db9e672017-06-23 16:11:05 +080096#endif