1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2018 Rockchip Electronics Co., Ltd
6 #ifndef _ASM_ARCH_SDRAM_COMMON_H
7 #define _ASM_ARCH_SDRAM_COMMON_H
9 struct sdram_cap_info {
11 /* dram column number, 0 means this channel is invalid */
13 /* dram bank number, 3:8bank, 2:4bank */
15 /* channel buswidth, 2:32bit, 1:16bit, 0:8bit */
17 /* die buswidth, 2:32bit, 1:16bit, 0:8bit */
20 * row_3_4 = 1: 6Gb or 12Gb die
21 * row_3_4 = 0: normal die, power of 2
26 unsigned int cs0_high16bit_row;
27 unsigned int cs1_high16bit_row;
28 unsigned int ddrconfig;
31 struct sdram_base_params {
32 unsigned int ddr_freq;
33 unsigned int dramtype;
34 unsigned int num_channels;
39 #define DDR_SYS_REG_VERSION (0x2)
41 * sys_reg2 bitfield struct
62 #define SYS_REG_ENC_ROW_3_4(n, ch) ((n) << (30 + (ch)))
63 #define SYS_REG_DEC_ROW_3_4(n, ch) (((n) >> (30 + (ch))) & 0x1)
64 #define SYS_REG_ENC_CHINFO(ch) (1 << (28 + (ch)))
65 #define SYS_REG_ENC_DDRTYPE(n) ((n) << 13)
66 #define SYS_REG_DEC_DDRTYPE(n) (((n) >> 13) & 0x7)
67 #define SYS_REG_ENC_NUM_CH(n) (((n) - 1) << 12)
68 #define SYS_REG_DEC_NUM_CH(n) (1 + (((n) >> 12) & 0x1))
69 #define SYS_REG_ENC_RANK(n, ch) (((n) - 1) << (11 + ((ch) * 16)))
70 #define SYS_REG_DEC_RANK(n, ch) (1 + (((n) >> (11 + 16 * (ch))) & 0x1))
71 #define SYS_REG_ENC_COL(n, ch) (((n) - 9) << (9 + ((ch) * 16)))
72 #define SYS_REG_DEC_COL(n, ch) (9 + (((n) >> (9 + 16 * (ch))) & 0x3))
73 #define SYS_REG_ENC_BK(n, ch) (((n) == 3 ? 0 : 1) << \
75 #define SYS_REG_DEC_BK(n, ch) (3 - (((n) >> (8 + 16 * (ch))) & 0x1))
76 #define SYS_REG_ENC_BW(n, ch) ((2 >> (n)) << (2 + ((ch) * 16)))
77 #define SYS_REG_DEC_BW(n, ch) (2 >> (((n) >> (2 + 16 * (ch))) & 0x3))
78 #define SYS_REG_ENC_DBW(n, ch) ((2 >> (n)) << (0 + ((ch) * 16)))
79 #define SYS_REG_DEC_DBW(n, ch) (2 >> (((n) >> (0 + 16 * (ch))) & 0x3))
81 #define SYS_REG_ENC_VERSION(n) ((n) << 28)
82 #define SYS_REG_DEC_VERSION(n) (((n) >> 28) & 0xf)
83 #define SYS_REG_ENC_CS0_ROW(n, os_reg2, os_reg3, ch) do { \
84 (os_reg2) |= (((n) - 13) & 0x3) << (6 + 16 * (ch)); \
85 (os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
89 #define SYS_REG_DEC_CS0_ROW(os_reg2, os_reg3, ch) \
90 ((((((os_reg2) >> (6 + 16 * (ch)) & 0x3) | \
91 ((((os_reg3) >> (5 + 2 * (ch))) & 0x1) << 2)) + 1) & 0x7) + 12)
93 #define SYS_REG_ENC_CS1_ROW(n, os_reg2, os_reg3, ch) do { \
94 (os_reg2) &= (~(0x3 << (4 + 16 * (ch)))); \
95 (os_reg3) &= (~(0x1 << (4 + 2 * (ch)))); \
96 (os_reg2) |= (((n) - 13) & 0x3) << (4 + 16 * (ch)); \
97 (os_reg3) |= ((((n) - 13) & 0x4) >> 2) << \
101 #define SYS_REG_DEC_CS1_ROW(os_reg2, os_reg3, ch) \
102 ((((((os_reg2) >> (4 + 16 * (ch)) & 0x3) | \
103 ((((os_reg3) >> (4 + 2 * (ch))) & 0x1) << 2)) + 1) & 0x7) + 12)
105 #define SYS_REG_ENC_CS1_COL(n, ch) (((n) - 9) << (0 + 2 * (ch)))
106 #define SYS_REG_DEC_CS1_COL(n, ch) (9 + (((n) >> (0 + 2 * (ch))) & 0x3))
108 #if !defined(CONFIG_RAM_ROCKCHIP_DEBUG)
109 inline void sdram_print_dram_type(unsigned char dramtype)
113 inline void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
114 struct sdram_base_params *base)
118 inline void sdram_print_stride(unsigned int stride)
122 void sdram_print_dram_type(unsigned char dramtype);
123 void sdram_print_ddr_info(struct sdram_cap_info *cap_info,
124 struct sdram_base_params *base);
125 void sdram_print_stride(unsigned int stride);
126 #endif /* CONFIG_RAM_ROCKCHIP_DEBUG */