Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Rockchip Electronics Co., Ltd. |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _ASM_ARCH_SDRAM_COMMON_H |
| 7 | #define _ASM_ARCH_SDRAM_COMMON_H |
Jagan Teki | 3d401b2 | 2019-07-15 23:51:07 +0530 | [diff] [blame] | 8 | |
Jagan Teki | 7ab369c | 2019-07-15 23:51:08 +0530 | [diff] [blame] | 9 | enum { |
Jagan Teki | 90974d4 | 2019-07-15 23:51:09 +0530 | [diff] [blame] | 10 | DDR4 = 0, |
Jagan Teki | 7ab369c | 2019-07-15 23:51:08 +0530 | [diff] [blame] | 11 | DDR3 = 0x3, |
| 12 | LPDDR2 = 0x5, |
| 13 | LPDDR3 = 0x6, |
| 14 | LPDDR4 = 0x7, |
| 15 | UNUSED = 0xFF |
| 16 | }; |
| 17 | |
Jagan Teki | 3d401b2 | 2019-07-15 23:51:07 +0530 | [diff] [blame] | 18 | struct 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 | |
| 38 | struct 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 Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 46 | /* |
| 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 Teki | e79ea0e | 2019-07-16 17:26:49 +0530 | [diff] [blame] | 74 | #define SYS_REG_ENC_ROW_3_4(n, ch) ((n) << (30 + (ch))) |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 75 | #define SYS_REG_CHINFO_SHIFT(ch) (28 + (ch)) |
Jagan Teki | e79ea0e | 2019-07-16 17:26:49 +0530 | [diff] [blame] | 76 | #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 Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 80 | #define SYS_REG_RANK_SHIFT(ch) (11 + (ch) * 16) |
| 81 | #define SYS_REG_RANK_MASK 1 |
Jagan Teki | e79ea0e | 2019-07-16 17:26:49 +0530 | [diff] [blame] | 82 | #define SYS_REG_ENC_RANK(n, ch) (((n) - SYS_REG_RANK_MASK) << \ |
| 83 | SYS_REG_RANK_SHIFT(ch)) |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 84 | #define SYS_REG_COL_SHIFT(ch) (9 + (ch) * 16) |
| 85 | #define SYS_REG_COL_MASK 3 |
Jagan Teki | e79ea0e | 2019-07-16 17:26:49 +0530 | [diff] [blame] | 86 | #define SYS_REG_ENC_COL(n, ch) (((n) - 9) << SYS_REG_COL_SHIFT(ch)) |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 87 | #define SYS_REG_BK_SHIFT(ch) (8 + (ch) * 16) |
| 88 | #define SYS_REG_BK_MASK 1 |
Jagan Teki | e79ea0e | 2019-07-16 17:26:49 +0530 | [diff] [blame] | 89 | #define SYS_REG_ENC_BK(n, ch) (((n) == 3 ? 0 : 1) << \ |
| 90 | SYS_REG_BK_SHIFT(ch)) |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 91 | #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 Teki | e79ea0e | 2019-07-16 17:26:49 +0530 | [diff] [blame] | 97 | #define SYS_REG_ENC_BW(n, ch) ((2 >> (n)) << SYS_REG_BW_SHIFT(ch)) |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 98 | #define SYS_REG_DBW_SHIFT(ch) ((ch) * 16) |
| 99 | #define SYS_REG_DBW_MASK 3 |
Jagan Teki | e79ea0e | 2019-07-16 17:26:49 +0530 | [diff] [blame] | 100 | #define SYS_REG_ENC_DBW(n, ch) ((2 >> (n)) << SYS_REG_DBW_SHIFT(ch)) |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 101 | |
Jagan Teki | 9d8769c | 2019-07-16 17:27:01 +0530 | [diff] [blame^] | 102 | #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 Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 119 | /* Get sdram size decode from reg */ |
| 120 | size_t rockchip_sdram_size(phys_addr_t reg); |
| 121 | |
| 122 | /* Called by U-Boot board_init_r for Rockchip SoCs */ |
| 123 | int dram_init(void); |
Jagan Teki | ced3ea6 | 2019-07-15 23:58:48 +0530 | [diff] [blame] | 124 | |
| 125 | #if !defined(CONFIG_RAM_ROCKCHIP_DEBUG) |
| 126 | inline void sdram_print_dram_type(unsigned char dramtype) |
| 127 | { |
| 128 | } |
Jagan Teki | fb20cf9 | 2019-07-15 23:58:49 +0530 | [diff] [blame] | 129 | |
| 130 | inline void sdram_print_ddr_info(struct sdram_cap_info *cap_info, |
| 131 | struct sdram_base_params *base) |
| 132 | { |
| 133 | } |
Jagan Teki | 0d11fa3 | 2019-07-15 23:58:51 +0530 | [diff] [blame] | 134 | |
| 135 | inline void sdram_print_stride(unsigned int stride) |
| 136 | { |
| 137 | } |
Jagan Teki | ced3ea6 | 2019-07-15 23:58:48 +0530 | [diff] [blame] | 138 | #else |
| 139 | void sdram_print_dram_type(unsigned char dramtype); |
Jagan Teki | fb20cf9 | 2019-07-15 23:58:49 +0530 | [diff] [blame] | 140 | void sdram_print_ddr_info(struct sdram_cap_info *cap_info, |
| 141 | struct sdram_base_params *base); |
Jagan Teki | 0d11fa3 | 2019-07-15 23:58:51 +0530 | [diff] [blame] | 142 | void sdram_print_stride(unsigned int stride); |
Jagan Teki | ced3ea6 | 2019-07-15 23:58:48 +0530 | [diff] [blame] | 143 | #endif /* CONFIG_RAM_ROCKCHIP_DEBUG */ |
| 144 | |
Kever Yang | 5db9e67 | 2017-06-23 16:11:05 +0800 | [diff] [blame] | 145 | #endif |