1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
6 #ifndef _ASM_ARCH_SDRAM_COMMON_H
7 #define _ASM_ARCH_SDRAM_COMMON_H
18 struct sdram_cap_info {
20 /* dram column number, 0 means this channel is invalid */
22 /* dram bank number, 3:8bank, 2:4bank */
24 /* channel buswidth, 2:32bit, 1:16bit, 0:8bit */
26 /* die buswidth, 2:32bit, 1:16bit, 0:8bit */
29 * row_3_4 = 1: 6Gb or 12Gb die
30 * row_3_4 = 0: normal die, power of 2
35 unsigned int ddrconfig;
38 struct sdram_base_params {
39 unsigned int ddr_freq;
40 unsigned int dramtype;
41 unsigned int num_channels;
47 * sys_reg bitfield struct
68 #define SYS_REG_DDRTYPE_SHIFT 13
69 #define DDR_SYS_REG_VERSION 2
70 #define SYS_REG_DDRTYPE_MASK 7
71 #define SYS_REG_NUM_CH_SHIFT 12
72 #define SYS_REG_NUM_CH_MASK 1
73 #define SYS_REG_ROW_3_4_SHIFT(ch) (30 + (ch))
74 #define SYS_REG_ROW_3_4_MASK 1
75 #define SYS_REG_ENC_ROW_3_4(n, ch) ((n) << (30 + (ch)))
76 #define SYS_REG_CHINFO_SHIFT(ch) (28 + (ch))
77 #define SYS_REG_ENC_CHINFO(ch) (1 << SYS_REG_CHINFO_SHIFT(ch))
78 #define SYS_REG_ENC_DDRTYPE(n) ((n) << SYS_REG_DDRTYPE_SHIFT)
79 #define SYS_REG_ENC_NUM_CH(n) (((n) - SYS_REG_NUM_CH_MASK) << \
81 #define SYS_REG_RANK_SHIFT(ch) (11 + (ch) * 16)
82 #define SYS_REG_RANK_MASK 1
83 #define SYS_REG_ENC_RANK(n, ch) (((n) - SYS_REG_RANK_MASK) << \
84 SYS_REG_RANK_SHIFT(ch))
85 #define SYS_REG_COL_SHIFT(ch) (9 + (ch) * 16)
86 #define SYS_REG_COL_MASK 3
87 #define SYS_REG_ENC_COL(n, ch) (((n) - 9) << SYS_REG_COL_SHIFT(ch))
88 #define SYS_REG_BK_SHIFT(ch) (8 + (ch) * 16)
89 #define SYS_REG_BK_MASK 1
90 #define SYS_REG_ENC_BK(n, ch) (((n) == 3 ? 0 : 1) << \
92 #define SYS_REG_CS0_ROW_SHIFT(ch) (6 + (ch) * 16)
93 #define SYS_REG_CS0_ROW_MASK 3
94 #define SYS_REG_CS1_ROW_SHIFT(ch) (4 + (ch) * 16)
95 #define SYS_REG_CS1_ROW_MASK 3
96 #define SYS_REG_BW_SHIFT(ch) (2 + (ch) * 16)
97 #define SYS_REG_BW_MASK 3
98 #define SYS_REG_ENC_BW(n, ch) ((2 >> (n)) << SYS_REG_BW_SHIFT(ch))
99 #define SYS_REG_DBW_SHIFT(ch) ((ch) * 16)
100 #define SYS_REG_DBW_MASK 3
101 #define SYS_REG_ENC_DBW(n, ch) ((2 >> (n)) << SYS_REG_DBW_SHIFT(ch))
103 #define SYS_REG_ENC_VERSION(n) ((n) << 28)
104 #define SYS_REG_ENC_CS0_ROW(n, os_reg2, os_reg3, ch) do { \
105 (os_reg2) |= (((n) - 13) & 0x3) << (6 + 16 * (ch)); \
106 (os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
110 #define SYS_REG_ENC_CS1_ROW(n, os_reg2, os_reg3, ch) do { \
111 (os_reg2) &= (~(0x3 << (4 + 16 * (ch)))); \
112 (os_reg3) &= (~(0x1 << (4 + 2 * (ch)))); \
113 (os_reg2) |= (((n) - 13) & 0x3) << (4 + 16 * (ch)); \
114 (os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
118 #define SYS_REG_CS1_COL_SHIFT(ch) (0 + 2 * (ch))
119 #define SYS_REG_ENC_CS1_COL(n, ch) (((n) - 9) << SYS_REG_CS1_COL_SHIFT(ch))
121 /* Get sdram size decode from reg */
122 size_t rockchip_sdram_size(phys_addr_t reg);
124 /* Called by U-Boot board_init_r for Rockchip SoCs */
127 #if !defined(CONFIG_RAM_ROCKCHIP_DEBUG)
128 inline void sdram_print_dram_type(unsigned char dramtype)
132 inline void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
133 struct sdram_base_params *base)
137 inline void sdram_print_stride(unsigned int stride)
141 void sdram_print_dram_type(unsigned char dramtype);
142 void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
143 struct sdram_base_params *base);
144 void sdram_print_stride(unsigned int stride);
145 #endif /* CONFIG_RAM_ROCKCHIP_DEBUG */