Kever Yang | 6fc9ebf | 2018-12-20 11:33:42 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016-2017 Rockchip Inc. |
| 4 | * |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 5 | * Adapted from coreboot. |
| 6 | */ |
Philipp Tomsich | c69b309 | 2017-05-31 18:16:34 +0200 | [diff] [blame] | 7 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <clk.h> |
| 10 | #include <dm.h> |
| 11 | #include <dt-structs.h> |
| 12 | #include <ram.h> |
| 13 | #include <regmap.h> |
| 14 | #include <syscon.h> |
| 15 | #include <asm/io.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 16 | #include <asm/arch-rockchip/clock.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 17 | #include <asm/arch-rockchip/cru_rk3399.h> |
| 18 | #include <asm/arch-rockchip/grf_rk3399.h> |
| 19 | #include <asm/arch-rockchip/hardware.h> |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 20 | #include <asm/arch-rockchip/sdram_common.h> |
| 21 | #include <asm/arch-rockchip/sdram_rk3399.h> |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 22 | #include <linux/err.h> |
Philipp Tomsich | c69b309 | 2017-05-31 18:16:34 +0200 | [diff] [blame] | 23 | #include <time.h> |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 24 | |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 25 | #define PRESET_SGRF_HOLD(n) ((0x1 << (6 + 16)) | ((n) << 6)) |
| 26 | #define PRESET_GPIO0_HOLD(n) ((0x1 << (7 + 16)) | ((n) << 7)) |
| 27 | #define PRESET_GPIO1_HOLD(n) ((0x1 << (8 + 16)) | ((n) << 8)) |
| 28 | |
| 29 | #define PHY_DRV_ODT_HI_Z 0x0 |
| 30 | #define PHY_DRV_ODT_240 0x1 |
| 31 | #define PHY_DRV_ODT_120 0x8 |
| 32 | #define PHY_DRV_ODT_80 0x9 |
| 33 | #define PHY_DRV_ODT_60 0xc |
| 34 | #define PHY_DRV_ODT_48 0xd |
| 35 | #define PHY_DRV_ODT_40 0xe |
| 36 | #define PHY_DRV_ODT_34_3 0xf |
| 37 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 38 | struct chan_info { |
| 39 | struct rk3399_ddr_pctl_regs *pctl; |
| 40 | struct rk3399_ddr_pi_regs *pi; |
| 41 | struct rk3399_ddr_publ_regs *publ; |
| 42 | struct rk3399_msch_regs *msch; |
| 43 | }; |
| 44 | |
| 45 | struct dram_info { |
Kever Yang | 7f34784 | 2019-04-01 17:20:53 +0800 | [diff] [blame] | 46 | #if defined(CONFIG_TPL_BUILD) || \ |
| 47 | (!defined(CONFIG_TPL) && defined(CONFIG_SPL_BUILD)) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 48 | struct chan_info chan[2]; |
| 49 | struct clk ddr_clk; |
| 50 | struct rk3399_cru *cru; |
| 51 | struct rk3399_pmucru *pmucru; |
| 52 | struct rk3399_pmusgrf_regs *pmusgrf; |
| 53 | struct rk3399_ddr_cic_regs *cic; |
| 54 | #endif |
| 55 | struct ram_info info; |
| 56 | struct rk3399_pmugrf_regs *pmugrf; |
| 57 | }; |
| 58 | |
Kever Yang | 7f34784 | 2019-04-01 17:20:53 +0800 | [diff] [blame] | 59 | #if defined(CONFIG_TPL_BUILD) || \ |
| 60 | (!defined(CONFIG_TPL) && defined(CONFIG_SPL_BUILD)) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 61 | |
| 62 | struct rockchip_dmc_plat { |
| 63 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 64 | struct dtd_rockchip_rk3399_dmc dtplat; |
| 65 | #else |
| 66 | struct rk3399_sdram_params sdram_params; |
| 67 | #endif |
| 68 | struct regmap *map; |
| 69 | }; |
| 70 | |
| 71 | static void copy_to_reg(u32 *dest, const u32 *src, u32 n) |
| 72 | { |
| 73 | int i; |
| 74 | |
| 75 | for (i = 0; i < n / sizeof(u32); i++) { |
| 76 | writel(*src, dest); |
| 77 | src++; |
| 78 | dest++; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static void phy_dll_bypass_set(struct rk3399_ddr_publ_regs *ddr_publ_regs, |
| 83 | u32 freq) |
| 84 | { |
| 85 | u32 *denali_phy = ddr_publ_regs->denali_phy; |
| 86 | |
| 87 | /* From IP spec, only freq small than 125 can enter dll bypass mode */ |
| 88 | if (freq <= 125) { |
| 89 | /* phy_sw_master_mode_X PHY_86/214/342/470 4bits offset_8 */ |
| 90 | setbits_le32(&denali_phy[86], (0x3 << 2) << 8); |
| 91 | setbits_le32(&denali_phy[214], (0x3 << 2) << 8); |
| 92 | setbits_le32(&denali_phy[342], (0x3 << 2) << 8); |
| 93 | setbits_le32(&denali_phy[470], (0x3 << 2) << 8); |
| 94 | |
| 95 | /* phy_adrctl_sw_master_mode PHY_547/675/803 4bits offset_16 */ |
| 96 | setbits_le32(&denali_phy[547], (0x3 << 2) << 16); |
| 97 | setbits_le32(&denali_phy[675], (0x3 << 2) << 16); |
| 98 | setbits_le32(&denali_phy[803], (0x3 << 2) << 16); |
| 99 | } else { |
| 100 | /* phy_sw_master_mode_X PHY_86/214/342/470 4bits offset_8 */ |
| 101 | clrbits_le32(&denali_phy[86], (0x3 << 2) << 8); |
| 102 | clrbits_le32(&denali_phy[214], (0x3 << 2) << 8); |
| 103 | clrbits_le32(&denali_phy[342], (0x3 << 2) << 8); |
| 104 | clrbits_le32(&denali_phy[470], (0x3 << 2) << 8); |
| 105 | |
| 106 | /* phy_adrctl_sw_master_mode PHY_547/675/803 4bits offset_16 */ |
| 107 | clrbits_le32(&denali_phy[547], (0x3 << 2) << 16); |
| 108 | clrbits_le32(&denali_phy[675], (0x3 << 2) << 16); |
| 109 | clrbits_le32(&denali_phy[803], (0x3 << 2) << 16); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | static void set_memory_map(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 114 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 115 | { |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 116 | const struct rk3399_sdram_channel *sdram_ch = ¶ms->ch[channel]; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 117 | u32 *denali_ctl = chan->pctl->denali_ctl; |
| 118 | u32 *denali_pi = chan->pi->denali_pi; |
| 119 | u32 cs_map; |
| 120 | u32 reduc; |
| 121 | u32 row; |
| 122 | |
| 123 | /* Get row number from ddrconfig setting */ |
| 124 | if (sdram_ch->ddrconfig < 2 || sdram_ch->ddrconfig == 4) |
| 125 | row = 16; |
| 126 | else if (sdram_ch->ddrconfig == 3) |
| 127 | row = 14; |
| 128 | else |
| 129 | row = 15; |
| 130 | |
| 131 | cs_map = (sdram_ch->rank > 1) ? 3 : 1; |
| 132 | reduc = (sdram_ch->bw == 2) ? 0 : 1; |
| 133 | |
| 134 | /* Set the dram configuration to ctrl */ |
| 135 | clrsetbits_le32(&denali_ctl[191], 0xF, (12 - sdram_ch->col)); |
| 136 | clrsetbits_le32(&denali_ctl[190], (0x3 << 16) | (0x7 << 24), |
| 137 | ((3 - sdram_ch->bk) << 16) | |
| 138 | ((16 - row) << 24)); |
| 139 | |
| 140 | clrsetbits_le32(&denali_ctl[196], 0x3 | (1 << 16), |
| 141 | cs_map | (reduc << 16)); |
| 142 | |
| 143 | /* PI_199 PI_COL_DIFF:RW:0:4 */ |
| 144 | clrsetbits_le32(&denali_pi[199], 0xF, (12 - sdram_ch->col)); |
| 145 | |
| 146 | /* PI_155 PI_ROW_DIFF:RW:24:3 PI_BANK_DIFF:RW:16:2 */ |
| 147 | clrsetbits_le32(&denali_pi[155], (0x3 << 16) | (0x7 << 24), |
| 148 | ((3 - sdram_ch->bk) << 16) | |
| 149 | ((16 - row) << 24)); |
| 150 | /* PI_41 PI_CS_MAP:RW:24:4 */ |
| 151 | clrsetbits_le32(&denali_pi[41], 0xf << 24, cs_map << 24); |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 152 | if (sdram_ch->rank == 1 && params->base.dramtype == DDR3) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 153 | writel(0x2EC7FFFF, &denali_pi[34]); |
| 154 | } |
| 155 | |
| 156 | static void set_ds_odt(const struct chan_info *chan, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 157 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 158 | { |
| 159 | u32 *denali_phy = chan->publ->denali_phy; |
| 160 | |
| 161 | u32 tsel_idle_en, tsel_wr_en, tsel_rd_en; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 162 | u32 tsel_idle_select_p, tsel_rd_select_p; |
| 163 | u32 tsel_idle_select_n, tsel_rd_select_n; |
| 164 | u32 tsel_wr_select_dq_p, tsel_wr_select_ca_p; |
| 165 | u32 tsel_wr_select_dq_n, tsel_wr_select_ca_n; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 166 | u32 reg_value; |
| 167 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 168 | if (params->base.dramtype == LPDDR4) { |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 169 | tsel_rd_select_p = PHY_DRV_ODT_HI_Z; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 170 | tsel_rd_select_n = PHY_DRV_ODT_240; |
| 171 | |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 172 | tsel_idle_select_p = PHY_DRV_ODT_HI_Z; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 173 | tsel_idle_select_n = PHY_DRV_ODT_240; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 174 | |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 175 | tsel_wr_select_dq_p = PHY_DRV_ODT_40; |
Jagan Teki | 3666714 | 2019-07-15 23:51:00 +0530 | [diff] [blame] | 176 | tsel_wr_select_dq_n = PHY_DRV_ODT_40; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 177 | |
| 178 | tsel_wr_select_ca_p = PHY_DRV_ODT_40; |
Jagan Teki | 0fd5efb | 2019-07-15 23:51:02 +0530 | [diff] [blame] | 179 | tsel_wr_select_ca_n = PHY_DRV_ODT_40; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 180 | } else if (params->base.dramtype == LPDDR3) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 181 | tsel_rd_select_p = PHY_DRV_ODT_240; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 182 | tsel_rd_select_n = PHY_DRV_ODT_HI_Z; |
| 183 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 184 | tsel_idle_select_p = PHY_DRV_ODT_240; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 185 | tsel_idle_select_n = PHY_DRV_ODT_HI_Z; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 186 | |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 187 | tsel_wr_select_dq_p = PHY_DRV_ODT_34_3; |
Jagan Teki | 3666714 | 2019-07-15 23:51:00 +0530 | [diff] [blame] | 188 | tsel_wr_select_dq_n = PHY_DRV_ODT_34_3; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 189 | |
| 190 | tsel_wr_select_ca_p = PHY_DRV_ODT_48; |
Jagan Teki | 0fd5efb | 2019-07-15 23:51:02 +0530 | [diff] [blame] | 191 | tsel_wr_select_ca_n = PHY_DRV_ODT_48; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 192 | } else { |
| 193 | tsel_rd_select_p = PHY_DRV_ODT_240; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 194 | tsel_rd_select_n = PHY_DRV_ODT_240; |
| 195 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 196 | tsel_idle_select_p = PHY_DRV_ODT_240; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 197 | tsel_idle_select_n = PHY_DRV_ODT_240; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 198 | |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 199 | tsel_wr_select_dq_p = PHY_DRV_ODT_34_3; |
Jagan Teki | 3666714 | 2019-07-15 23:51:00 +0530 | [diff] [blame] | 200 | tsel_wr_select_dq_n = PHY_DRV_ODT_34_3; |
Jagan Teki | 5c3251f | 2019-07-15 23:51:04 +0530 | [diff] [blame^] | 201 | |
| 202 | tsel_wr_select_ca_p = PHY_DRV_ODT_34_3; |
Jagan Teki | 0fd5efb | 2019-07-15 23:51:02 +0530 | [diff] [blame] | 203 | tsel_wr_select_ca_n = PHY_DRV_ODT_34_3; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 204 | } |
| 205 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 206 | if (params->base.odt == 1) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 207 | tsel_rd_en = 1; |
| 208 | else |
| 209 | tsel_rd_en = 0; |
| 210 | |
| 211 | tsel_wr_en = 0; |
| 212 | tsel_idle_en = 0; |
| 213 | |
| 214 | /* |
| 215 | * phy_dq_tsel_select_X 24bits DENALI_PHY_6/134/262/390 offset_0 |
| 216 | * sets termination values for read/idle cycles and drive strength |
| 217 | * for write cycles for DQ/DM |
| 218 | */ |
| 219 | reg_value = tsel_rd_select_n | (tsel_rd_select_p << 0x4) | |
Jagan Teki | b3b3439 | 2019-07-15 23:51:01 +0530 | [diff] [blame] | 220 | (tsel_wr_select_dq_n << 8) | (tsel_wr_select_dq_p << 12) | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 221 | (tsel_idle_select_n << 16) | (tsel_idle_select_p << 20); |
| 222 | clrsetbits_le32(&denali_phy[6], 0xffffff, reg_value); |
| 223 | clrsetbits_le32(&denali_phy[134], 0xffffff, reg_value); |
| 224 | clrsetbits_le32(&denali_phy[262], 0xffffff, reg_value); |
| 225 | clrsetbits_le32(&denali_phy[390], 0xffffff, reg_value); |
| 226 | |
| 227 | /* |
| 228 | * phy_dqs_tsel_select_X 24bits DENALI_PHY_7/135/263/391 offset_0 |
| 229 | * sets termination values for read/idle cycles and drive strength |
| 230 | * for write cycles for DQS |
| 231 | */ |
| 232 | clrsetbits_le32(&denali_phy[7], 0xffffff, reg_value); |
| 233 | clrsetbits_le32(&denali_phy[135], 0xffffff, reg_value); |
| 234 | clrsetbits_le32(&denali_phy[263], 0xffffff, reg_value); |
| 235 | clrsetbits_le32(&denali_phy[391], 0xffffff, reg_value); |
| 236 | |
| 237 | /* phy_adr_tsel_select_ 8bits DENALI_PHY_544/672/800 offset_0 */ |
Jagan Teki | 7caa3e9 | 2019-07-15 23:51:03 +0530 | [diff] [blame] | 238 | reg_value = tsel_wr_select_ca_n | (tsel_wr_select_ca_p << 0x4); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 239 | clrsetbits_le32(&denali_phy[544], 0xff, reg_value); |
| 240 | clrsetbits_le32(&denali_phy[672], 0xff, reg_value); |
| 241 | clrsetbits_le32(&denali_phy[800], 0xff, reg_value); |
| 242 | |
| 243 | /* phy_pad_addr_drive 8bits DENALI_PHY_928 offset_0 */ |
| 244 | clrsetbits_le32(&denali_phy[928], 0xff, reg_value); |
| 245 | |
| 246 | /* phy_pad_rst_drive 8bits DENALI_PHY_937 offset_0 */ |
| 247 | clrsetbits_le32(&denali_phy[937], 0xff, reg_value); |
| 248 | |
| 249 | /* phy_pad_cke_drive 8bits DENALI_PHY_935 offset_0 */ |
| 250 | clrsetbits_le32(&denali_phy[935], 0xff, reg_value); |
| 251 | |
| 252 | /* phy_pad_cs_drive 8bits DENALI_PHY_939 offset_0 */ |
| 253 | clrsetbits_le32(&denali_phy[939], 0xff, reg_value); |
| 254 | |
| 255 | /* phy_pad_clk_drive 8bits DENALI_PHY_929 offset_0 */ |
| 256 | clrsetbits_le32(&denali_phy[929], 0xff, reg_value); |
| 257 | |
| 258 | /* phy_pad_fdbk_drive 23bit DENALI_PHY_924/925 */ |
| 259 | clrsetbits_le32(&denali_phy[924], 0xff, |
Jagan Teki | b3b3439 | 2019-07-15 23:51:01 +0530 | [diff] [blame] | 260 | tsel_wr_select_dq_n | (tsel_wr_select_dq_p << 4)); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 261 | clrsetbits_le32(&denali_phy[925], 0xff, |
| 262 | tsel_rd_select_n | (tsel_rd_select_p << 4)); |
| 263 | |
| 264 | /* phy_dq_tsel_enable_X 3bits DENALI_PHY_5/133/261/389 offset_16 */ |
| 265 | reg_value = (tsel_rd_en | (tsel_wr_en << 1) | (tsel_idle_en << 2)) |
| 266 | << 16; |
| 267 | clrsetbits_le32(&denali_phy[5], 0x7 << 16, reg_value); |
| 268 | clrsetbits_le32(&denali_phy[133], 0x7 << 16, reg_value); |
| 269 | clrsetbits_le32(&denali_phy[261], 0x7 << 16, reg_value); |
| 270 | clrsetbits_le32(&denali_phy[389], 0x7 << 16, reg_value); |
| 271 | |
| 272 | /* phy_dqs_tsel_enable_X 3bits DENALI_PHY_6/134/262/390 offset_24 */ |
| 273 | reg_value = (tsel_rd_en | (tsel_wr_en << 1) | (tsel_idle_en << 2)) |
| 274 | << 24; |
| 275 | clrsetbits_le32(&denali_phy[6], 0x7 << 24, reg_value); |
| 276 | clrsetbits_le32(&denali_phy[134], 0x7 << 24, reg_value); |
| 277 | clrsetbits_le32(&denali_phy[262], 0x7 << 24, reg_value); |
| 278 | clrsetbits_le32(&denali_phy[390], 0x7 << 24, reg_value); |
| 279 | |
| 280 | /* phy_adr_tsel_enable_ 1bit DENALI_PHY_518/646/774 offset_8 */ |
| 281 | reg_value = tsel_wr_en << 8; |
| 282 | clrsetbits_le32(&denali_phy[518], 0x1 << 8, reg_value); |
| 283 | clrsetbits_le32(&denali_phy[646], 0x1 << 8, reg_value); |
| 284 | clrsetbits_le32(&denali_phy[774], 0x1 << 8, reg_value); |
| 285 | |
| 286 | /* phy_pad_addr_term tsel 1bit DENALI_PHY_933 offset_17 */ |
| 287 | reg_value = tsel_wr_en << 17; |
| 288 | clrsetbits_le32(&denali_phy[933], 0x1 << 17, reg_value); |
| 289 | /* |
| 290 | * pad_rst/cke/cs/clk_term tsel 1bits |
| 291 | * DENALI_PHY_938/936/940/934 offset_17 |
| 292 | */ |
| 293 | clrsetbits_le32(&denali_phy[938], 0x1 << 17, reg_value); |
| 294 | clrsetbits_le32(&denali_phy[936], 0x1 << 17, reg_value); |
| 295 | clrsetbits_le32(&denali_phy[940], 0x1 << 17, reg_value); |
| 296 | clrsetbits_le32(&denali_phy[934], 0x1 << 17, reg_value); |
| 297 | |
| 298 | /* phy_pad_fdbk_term 1bit DENALI_PHY_930 offset_17 */ |
| 299 | clrsetbits_le32(&denali_phy[930], 0x1 << 17, reg_value); |
| 300 | } |
| 301 | |
| 302 | static int phy_io_config(const struct chan_info *chan, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 303 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 304 | { |
| 305 | u32 *denali_phy = chan->publ->denali_phy; |
| 306 | u32 vref_mode_dq, vref_value_dq, vref_mode_ac, vref_value_ac; |
| 307 | u32 mode_sel; |
| 308 | u32 reg_value; |
| 309 | u32 drv_value, odt_value; |
| 310 | u32 speed; |
| 311 | |
| 312 | /* vref setting */ |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 313 | if (params->base.dramtype == LPDDR4) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 314 | /* LPDDR4 */ |
| 315 | vref_mode_dq = 0x6; |
| 316 | vref_value_dq = 0x1f; |
| 317 | vref_mode_ac = 0x6; |
| 318 | vref_value_ac = 0x1f; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 319 | } else if (params->base.dramtype == LPDDR3) { |
| 320 | if (params->base.odt == 1) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 321 | vref_mode_dq = 0x5; /* LPDDR3 ODT */ |
| 322 | drv_value = (readl(&denali_phy[6]) >> 12) & 0xf; |
| 323 | odt_value = (readl(&denali_phy[6]) >> 4) & 0xf; |
| 324 | if (drv_value == PHY_DRV_ODT_48) { |
| 325 | switch (odt_value) { |
| 326 | case PHY_DRV_ODT_240: |
| 327 | vref_value_dq = 0x16; |
| 328 | break; |
| 329 | case PHY_DRV_ODT_120: |
| 330 | vref_value_dq = 0x26; |
| 331 | break; |
| 332 | case PHY_DRV_ODT_60: |
| 333 | vref_value_dq = 0x36; |
| 334 | break; |
| 335 | default: |
| 336 | debug("Invalid ODT value.\n"); |
| 337 | return -EINVAL; |
| 338 | } |
| 339 | } else if (drv_value == PHY_DRV_ODT_40) { |
| 340 | switch (odt_value) { |
| 341 | case PHY_DRV_ODT_240: |
| 342 | vref_value_dq = 0x19; |
| 343 | break; |
| 344 | case PHY_DRV_ODT_120: |
| 345 | vref_value_dq = 0x23; |
| 346 | break; |
| 347 | case PHY_DRV_ODT_60: |
| 348 | vref_value_dq = 0x31; |
| 349 | break; |
| 350 | default: |
| 351 | debug("Invalid ODT value.\n"); |
| 352 | return -EINVAL; |
| 353 | } |
| 354 | } else if (drv_value == PHY_DRV_ODT_34_3) { |
| 355 | switch (odt_value) { |
| 356 | case PHY_DRV_ODT_240: |
| 357 | vref_value_dq = 0x17; |
| 358 | break; |
| 359 | case PHY_DRV_ODT_120: |
| 360 | vref_value_dq = 0x20; |
| 361 | break; |
| 362 | case PHY_DRV_ODT_60: |
| 363 | vref_value_dq = 0x2e; |
| 364 | break; |
| 365 | default: |
| 366 | debug("Invalid ODT value.\n"); |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | } else { |
| 370 | debug("Invalid DRV value.\n"); |
| 371 | return -EINVAL; |
| 372 | } |
| 373 | } else { |
| 374 | vref_mode_dq = 0x2; /* LPDDR3 */ |
| 375 | vref_value_dq = 0x1f; |
| 376 | } |
| 377 | vref_mode_ac = 0x2; |
| 378 | vref_value_ac = 0x1f; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 379 | } else if (params->base.dramtype == DDR3) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 380 | /* DDR3L */ |
| 381 | vref_mode_dq = 0x1; |
| 382 | vref_value_dq = 0x1f; |
| 383 | vref_mode_ac = 0x1; |
| 384 | vref_value_ac = 0x1f; |
| 385 | } else { |
| 386 | debug("Unknown DRAM type.\n"); |
| 387 | return -EINVAL; |
| 388 | } |
| 389 | |
| 390 | reg_value = (vref_mode_dq << 9) | (0x1 << 8) | vref_value_dq; |
| 391 | |
| 392 | /* PHY_913 PHY_PAD_VREF_CTRL_DQ_0 12bits offset_8 */ |
| 393 | clrsetbits_le32(&denali_phy[913], 0xfff << 8, reg_value << 8); |
| 394 | /* PHY_914 PHY_PAD_VREF_CTRL_DQ_1 12bits offset_0 */ |
| 395 | clrsetbits_le32(&denali_phy[914], 0xfff, reg_value); |
| 396 | /* PHY_914 PHY_PAD_VREF_CTRL_DQ_2 12bits offset_16 */ |
| 397 | clrsetbits_le32(&denali_phy[914], 0xfff << 16, reg_value << 16); |
| 398 | /* PHY_915 PHY_PAD_VREF_CTRL_DQ_3 12bits offset_0 */ |
| 399 | clrsetbits_le32(&denali_phy[915], 0xfff, reg_value); |
| 400 | |
| 401 | reg_value = (vref_mode_ac << 9) | (0x1 << 8) | vref_value_ac; |
| 402 | |
| 403 | /* PHY_915 PHY_PAD_VREF_CTRL_AC 12bits offset_16 */ |
| 404 | clrsetbits_le32(&denali_phy[915], 0xfff << 16, reg_value << 16); |
| 405 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 406 | if (params->base.dramtype == LPDDR4) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 407 | mode_sel = 0x6; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 408 | else if (params->base.dramtype == LPDDR3) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 409 | mode_sel = 0x0; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 410 | else if (params->base.dramtype == DDR3) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 411 | mode_sel = 0x1; |
| 412 | else |
| 413 | return -EINVAL; |
| 414 | |
| 415 | /* PHY_924 PHY_PAD_FDBK_DRIVE */ |
| 416 | clrsetbits_le32(&denali_phy[924], 0x7 << 15, mode_sel << 15); |
| 417 | /* PHY_926 PHY_PAD_DATA_DRIVE */ |
| 418 | clrsetbits_le32(&denali_phy[926], 0x7 << 6, mode_sel << 6); |
| 419 | /* PHY_927 PHY_PAD_DQS_DRIVE */ |
| 420 | clrsetbits_le32(&denali_phy[927], 0x7 << 6, mode_sel << 6); |
| 421 | /* PHY_928 PHY_PAD_ADDR_DRIVE */ |
| 422 | clrsetbits_le32(&denali_phy[928], 0x7 << 14, mode_sel << 14); |
| 423 | /* PHY_929 PHY_PAD_CLK_DRIVE */ |
| 424 | clrsetbits_le32(&denali_phy[929], 0x7 << 14, mode_sel << 14); |
| 425 | /* PHY_935 PHY_PAD_CKE_DRIVE */ |
| 426 | clrsetbits_le32(&denali_phy[935], 0x7 << 14, mode_sel << 14); |
| 427 | /* PHY_937 PHY_PAD_RST_DRIVE */ |
| 428 | clrsetbits_le32(&denali_phy[937], 0x7 << 14, mode_sel << 14); |
| 429 | /* PHY_939 PHY_PAD_CS_DRIVE */ |
| 430 | clrsetbits_le32(&denali_phy[939], 0x7 << 14, mode_sel << 14); |
| 431 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 432 | /* speed setting */ |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 433 | if (params->base.ddr_freq < 400) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 434 | speed = 0x0; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 435 | else if (params->base.ddr_freq < 800) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 436 | speed = 0x1; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 437 | else if (params->base.ddr_freq < 1200) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 438 | speed = 0x2; |
| 439 | else |
| 440 | speed = 0x3; |
| 441 | |
| 442 | /* PHY_924 PHY_PAD_FDBK_DRIVE */ |
| 443 | clrsetbits_le32(&denali_phy[924], 0x3 << 21, speed << 21); |
| 444 | /* PHY_926 PHY_PAD_DATA_DRIVE */ |
| 445 | clrsetbits_le32(&denali_phy[926], 0x3 << 9, speed << 9); |
| 446 | /* PHY_927 PHY_PAD_DQS_DRIVE */ |
| 447 | clrsetbits_le32(&denali_phy[927], 0x3 << 9, speed << 9); |
| 448 | /* PHY_928 PHY_PAD_ADDR_DRIVE */ |
| 449 | clrsetbits_le32(&denali_phy[928], 0x3 << 17, speed << 17); |
| 450 | /* PHY_929 PHY_PAD_CLK_DRIVE */ |
| 451 | clrsetbits_le32(&denali_phy[929], 0x3 << 17, speed << 17); |
| 452 | /* PHY_935 PHY_PAD_CKE_DRIVE */ |
| 453 | clrsetbits_le32(&denali_phy[935], 0x3 << 17, speed << 17); |
| 454 | /* PHY_937 PHY_PAD_RST_DRIVE */ |
| 455 | clrsetbits_le32(&denali_phy[937], 0x3 << 17, speed << 17); |
| 456 | /* PHY_939 PHY_PAD_CS_DRIVE */ |
| 457 | clrsetbits_le32(&denali_phy[939], 0x3 << 17, speed << 17); |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static int pctl_cfg(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 463 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 464 | { |
| 465 | u32 *denali_ctl = chan->pctl->denali_ctl; |
| 466 | u32 *denali_pi = chan->pi->denali_pi; |
| 467 | u32 *denali_phy = chan->publ->denali_phy; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 468 | const u32 *params_ctl = params->pctl_regs.denali_ctl; |
| 469 | const u32 *params_phy = params->phy_regs.denali_phy; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 470 | u32 tmp, tmp1, tmp2; |
| 471 | u32 pwrup_srefresh_exit; |
| 472 | int ret; |
Philipp Tomsich | c69b309 | 2017-05-31 18:16:34 +0200 | [diff] [blame] | 473 | const ulong timeout_ms = 200; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 474 | |
| 475 | /* |
| 476 | * work around controller bug: |
| 477 | * Do not program DRAM_CLASS until NO_PHY_IND_TRAIN_INT is programmed |
| 478 | */ |
| 479 | copy_to_reg(&denali_ctl[1], ¶ms_ctl[1], |
| 480 | sizeof(struct rk3399_ddr_pctl_regs) - 4); |
| 481 | writel(params_ctl[0], &denali_ctl[0]); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 482 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 483 | copy_to_reg(denali_pi, ¶ms->pi_regs.denali_pi[0], |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 484 | sizeof(struct rk3399_ddr_pi_regs)); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 485 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 486 | /* rank count need to set for init */ |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 487 | set_memory_map(chan, channel, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 488 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 489 | writel(params->phy_regs.denali_phy[910], &denali_phy[910]); |
| 490 | writel(params->phy_regs.denali_phy[911], &denali_phy[911]); |
| 491 | writel(params->phy_regs.denali_phy[912], &denali_phy[912]); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 492 | |
| 493 | pwrup_srefresh_exit = readl(&denali_ctl[68]) & PWRUP_SREFRESH_EXIT; |
| 494 | clrbits_le32(&denali_ctl[68], PWRUP_SREFRESH_EXIT); |
| 495 | |
| 496 | /* PHY_DLL_RST_EN */ |
| 497 | clrsetbits_le32(&denali_phy[957], 0x3 << 24, 1 << 24); |
| 498 | |
| 499 | setbits_le32(&denali_pi[0], START); |
| 500 | setbits_le32(&denali_ctl[0], START); |
| 501 | |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 502 | /* Waiting for phy DLL lock */ |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 503 | while (1) { |
| 504 | tmp = readl(&denali_phy[920]); |
| 505 | tmp1 = readl(&denali_phy[921]); |
| 506 | tmp2 = readl(&denali_phy[922]); |
| 507 | if ((((tmp >> 16) & 0x1) == 0x1) && |
| 508 | (((tmp1 >> 16) & 0x1) == 0x1) && |
| 509 | (((tmp1 >> 0) & 0x1) == 0x1) && |
| 510 | (((tmp2 >> 0) & 0x1) == 0x1)) |
| 511 | break; |
| 512 | } |
| 513 | |
| 514 | copy_to_reg(&denali_phy[896], ¶ms_phy[896], (958 - 895) * 4); |
| 515 | copy_to_reg(&denali_phy[0], ¶ms_phy[0], (90 - 0 + 1) * 4); |
| 516 | copy_to_reg(&denali_phy[128], ¶ms_phy[128], (218 - 128 + 1) * 4); |
| 517 | copy_to_reg(&denali_phy[256], ¶ms_phy[256], (346 - 256 + 1) * 4); |
| 518 | copy_to_reg(&denali_phy[384], ¶ms_phy[384], (474 - 384 + 1) * 4); |
| 519 | copy_to_reg(&denali_phy[512], ¶ms_phy[512], (549 - 512 + 1) * 4); |
| 520 | copy_to_reg(&denali_phy[640], ¶ms_phy[640], (677 - 640 + 1) * 4); |
| 521 | copy_to_reg(&denali_phy[768], ¶ms_phy[768], (805 - 768 + 1) * 4); |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 522 | set_ds_odt(chan, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 523 | |
| 524 | /* |
| 525 | * phy_dqs_tsel_wr_timing_X 8bits DENALI_PHY_84/212/340/468 offset_8 |
| 526 | * dqs_tsel_wr_end[7:4] add Half cycle |
| 527 | */ |
| 528 | tmp = (readl(&denali_phy[84]) >> 8) & 0xff; |
| 529 | clrsetbits_le32(&denali_phy[84], 0xff << 8, (tmp + 0x10) << 8); |
| 530 | tmp = (readl(&denali_phy[212]) >> 8) & 0xff; |
| 531 | clrsetbits_le32(&denali_phy[212], 0xff << 8, (tmp + 0x10) << 8); |
| 532 | tmp = (readl(&denali_phy[340]) >> 8) & 0xff; |
| 533 | clrsetbits_le32(&denali_phy[340], 0xff << 8, (tmp + 0x10) << 8); |
| 534 | tmp = (readl(&denali_phy[468]) >> 8) & 0xff; |
| 535 | clrsetbits_le32(&denali_phy[468], 0xff << 8, (tmp + 0x10) << 8); |
| 536 | |
| 537 | /* |
| 538 | * phy_dqs_tsel_wr_timing_X 8bits DENALI_PHY_83/211/339/467 offset_8 |
| 539 | * dq_tsel_wr_end[7:4] add Half cycle |
| 540 | */ |
| 541 | tmp = (readl(&denali_phy[83]) >> 16) & 0xff; |
| 542 | clrsetbits_le32(&denali_phy[83], 0xff << 16, (tmp + 0x10) << 16); |
| 543 | tmp = (readl(&denali_phy[211]) >> 16) & 0xff; |
| 544 | clrsetbits_le32(&denali_phy[211], 0xff << 16, (tmp + 0x10) << 16); |
| 545 | tmp = (readl(&denali_phy[339]) >> 16) & 0xff; |
| 546 | clrsetbits_le32(&denali_phy[339], 0xff << 16, (tmp + 0x10) << 16); |
| 547 | tmp = (readl(&denali_phy[467]) >> 16) & 0xff; |
| 548 | clrsetbits_le32(&denali_phy[467], 0xff << 16, (tmp + 0x10) << 16); |
| 549 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 550 | ret = phy_io_config(chan, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 551 | if (ret) |
| 552 | return ret; |
| 553 | |
| 554 | /* PHY_DLL_RST_EN */ |
| 555 | clrsetbits_le32(&denali_phy[957], 0x3 << 24, 0x2 << 24); |
| 556 | |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 557 | /* Waiting for PHY and DRAM init complete */ |
Philipp Tomsich | c69b309 | 2017-05-31 18:16:34 +0200 | [diff] [blame] | 558 | tmp = get_timer(0); |
| 559 | do { |
| 560 | if (get_timer(tmp) > timeout_ms) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 561 | pr_err("DRAM (%s): phy failed to lock within %ld ms\n", |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 562 | __func__, timeout_ms); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 563 | return -ETIME; |
Philipp Tomsich | c69b309 | 2017-05-31 18:16:34 +0200 | [diff] [blame] | 564 | } |
| 565 | } while (!(readl(&denali_ctl[203]) & (1 << 3))); |
| 566 | debug("DRAM (%s): phy locked after %ld ms\n", __func__, get_timer(tmp)); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 567 | |
| 568 | clrsetbits_le32(&denali_ctl[68], PWRUP_SREFRESH_EXIT, |
| 569 | pwrup_srefresh_exit); |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static void select_per_cs_training_index(const struct chan_info *chan, |
| 574 | u32 rank) |
| 575 | { |
| 576 | u32 *denali_phy = chan->publ->denali_phy; |
| 577 | |
| 578 | /* PHY_84 PHY_PER_CS_TRAINING_EN_0 1bit offset_16 */ |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 579 | if ((readl(&denali_phy[84]) >> 16) & 1) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 580 | /* |
| 581 | * PHY_8/136/264/392 |
| 582 | * phy_per_cs_training_index_X 1bit offset_24 |
| 583 | */ |
| 584 | clrsetbits_le32(&denali_phy[8], 0x1 << 24, rank << 24); |
| 585 | clrsetbits_le32(&denali_phy[136], 0x1 << 24, rank << 24); |
| 586 | clrsetbits_le32(&denali_phy[264], 0x1 << 24, rank << 24); |
| 587 | clrsetbits_le32(&denali_phy[392], 0x1 << 24, rank << 24); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | static void override_write_leveling_value(const struct chan_info *chan) |
| 592 | { |
| 593 | u32 *denali_ctl = chan->pctl->denali_ctl; |
| 594 | u32 *denali_phy = chan->publ->denali_phy; |
| 595 | u32 byte; |
| 596 | |
| 597 | /* PHY_896 PHY_FREQ_SEL_MULTICAST_EN 1bit offset_0 */ |
| 598 | setbits_le32(&denali_phy[896], 1); |
| 599 | |
| 600 | /* |
| 601 | * PHY_8/136/264/392 |
| 602 | * phy_per_cs_training_multicast_en_X 1bit offset_16 |
| 603 | */ |
| 604 | clrsetbits_le32(&denali_phy[8], 0x1 << 16, 1 << 16); |
| 605 | clrsetbits_le32(&denali_phy[136], 0x1 << 16, 1 << 16); |
| 606 | clrsetbits_le32(&denali_phy[264], 0x1 << 16, 1 << 16); |
| 607 | clrsetbits_le32(&denali_phy[392], 0x1 << 16, 1 << 16); |
| 608 | |
| 609 | for (byte = 0; byte < 4; byte++) |
| 610 | clrsetbits_le32(&denali_phy[63 + (128 * byte)], 0xffff << 16, |
| 611 | 0x200 << 16); |
| 612 | |
| 613 | /* PHY_896 PHY_FREQ_SEL_MULTICAST_EN 1bit offset_0 */ |
| 614 | clrbits_le32(&denali_phy[896], 1); |
| 615 | |
| 616 | /* CTL_200 ctrlupd_req 1bit offset_8 */ |
| 617 | clrsetbits_le32(&denali_ctl[200], 0x1 << 8, 0x1 << 8); |
| 618 | } |
| 619 | |
| 620 | static int data_training_ca(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 621 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 622 | { |
| 623 | u32 *denali_pi = chan->pi->denali_pi; |
| 624 | u32 *denali_phy = chan->publ->denali_phy; |
| 625 | u32 i, tmp; |
| 626 | u32 obs_0, obs_1, obs_2, obs_err = 0; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 627 | u32 rank = params->ch[channel].rank; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 628 | |
| 629 | for (i = 0; i < rank; i++) { |
| 630 | select_per_cs_training_index(chan, i); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 631 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 632 | /* PI_100 PI_CALVL_EN:RW:8:2 */ |
| 633 | clrsetbits_le32(&denali_pi[100], 0x3 << 8, 0x2 << 8); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 634 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 635 | /* PI_92 PI_CALVL_REQ:WR:16:1,PI_CALVL_CS:RW:24:2 */ |
| 636 | clrsetbits_le32(&denali_pi[92], |
| 637 | (0x1 << 16) | (0x3 << 24), |
| 638 | (0x1 << 16) | (i << 24)); |
| 639 | |
| 640 | /* Waiting for training complete */ |
| 641 | while (1) { |
| 642 | /* PI_174 PI_INT_STATUS:RD:8:18 */ |
| 643 | tmp = readl(&denali_pi[174]) >> 8; |
| 644 | /* |
| 645 | * check status obs |
| 646 | * PHY_532/660/789 phy_adr_calvl_obs1_:0:32 |
| 647 | */ |
| 648 | obs_0 = readl(&denali_phy[532]); |
| 649 | obs_1 = readl(&denali_phy[660]); |
| 650 | obs_2 = readl(&denali_phy[788]); |
| 651 | if (((obs_0 >> 30) & 0x3) || |
| 652 | ((obs_1 >> 30) & 0x3) || |
| 653 | ((obs_2 >> 30) & 0x3)) |
| 654 | obs_err = 1; |
| 655 | if ((((tmp >> 11) & 0x1) == 0x1) && |
| 656 | (((tmp >> 13) & 0x1) == 0x1) && |
| 657 | (((tmp >> 5) & 0x1) == 0x0) && |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 658 | obs_err == 0) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 659 | break; |
| 660 | else if ((((tmp >> 5) & 0x1) == 0x1) || |
| 661 | (obs_err == 1)) |
| 662 | return -EIO; |
| 663 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 664 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 665 | /* clear interrupt,PI_175 PI_INT_ACK:WR:0:17 */ |
| 666 | writel(0x00003f7c, (&denali_pi[175])); |
| 667 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 668 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 669 | clrbits_le32(&denali_pi[100], 0x3 << 8); |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | static int data_training_wl(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 675 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 676 | { |
| 677 | u32 *denali_pi = chan->pi->denali_pi; |
| 678 | u32 *denali_phy = chan->publ->denali_phy; |
| 679 | u32 i, tmp; |
| 680 | u32 obs_0, obs_1, obs_2, obs_3, obs_err = 0; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 681 | u32 rank = params->ch[channel].rank; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 682 | |
| 683 | for (i = 0; i < rank; i++) { |
| 684 | select_per_cs_training_index(chan, i); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 685 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 686 | /* PI_60 PI_WRLVL_EN:RW:8:2 */ |
| 687 | clrsetbits_le32(&denali_pi[60], 0x3 << 8, 0x2 << 8); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 688 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 689 | /* PI_59 PI_WRLVL_REQ:WR:8:1,PI_WRLVL_CS:RW:16:2 */ |
| 690 | clrsetbits_le32(&denali_pi[59], |
| 691 | (0x1 << 8) | (0x3 << 16), |
| 692 | (0x1 << 8) | (i << 16)); |
| 693 | |
| 694 | /* Waiting for training complete */ |
| 695 | while (1) { |
| 696 | /* PI_174 PI_INT_STATUS:RD:8:18 */ |
| 697 | tmp = readl(&denali_pi[174]) >> 8; |
| 698 | |
| 699 | /* |
| 700 | * check status obs, if error maybe can not |
| 701 | * get leveling done PHY_40/168/296/424 |
| 702 | * phy_wrlvl_status_obs_X:0:13 |
| 703 | */ |
| 704 | obs_0 = readl(&denali_phy[40]); |
| 705 | obs_1 = readl(&denali_phy[168]); |
| 706 | obs_2 = readl(&denali_phy[296]); |
| 707 | obs_3 = readl(&denali_phy[424]); |
| 708 | if (((obs_0 >> 12) & 0x1) || |
| 709 | ((obs_1 >> 12) & 0x1) || |
| 710 | ((obs_2 >> 12) & 0x1) || |
| 711 | ((obs_3 >> 12) & 0x1)) |
| 712 | obs_err = 1; |
| 713 | if ((((tmp >> 10) & 0x1) == 0x1) && |
| 714 | (((tmp >> 13) & 0x1) == 0x1) && |
| 715 | (((tmp >> 4) & 0x1) == 0x0) && |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 716 | obs_err == 0) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 717 | break; |
| 718 | else if ((((tmp >> 4) & 0x1) == 0x1) || |
| 719 | (obs_err == 1)) |
| 720 | return -EIO; |
| 721 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 722 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 723 | /* clear interrupt,PI_175 PI_INT_ACK:WR:0:17 */ |
| 724 | writel(0x00003f7c, (&denali_pi[175])); |
| 725 | } |
| 726 | |
| 727 | override_write_leveling_value(chan); |
| 728 | clrbits_le32(&denali_pi[60], 0x3 << 8); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static int data_training_rg(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 734 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 735 | { |
| 736 | u32 *denali_pi = chan->pi->denali_pi; |
| 737 | u32 *denali_phy = chan->publ->denali_phy; |
| 738 | u32 i, tmp; |
| 739 | u32 obs_0, obs_1, obs_2, obs_3, obs_err = 0; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 740 | u32 rank = params->ch[channel].rank; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 741 | |
| 742 | for (i = 0; i < rank; i++) { |
| 743 | select_per_cs_training_index(chan, i); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 744 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 745 | /* PI_80 PI_RDLVL_GATE_EN:RW:24:2 */ |
| 746 | clrsetbits_le32(&denali_pi[80], 0x3 << 24, 0x2 << 24); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 747 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 748 | /* |
| 749 | * PI_74 PI_RDLVL_GATE_REQ:WR:16:1 |
| 750 | * PI_RDLVL_CS:RW:24:2 |
| 751 | */ |
| 752 | clrsetbits_le32(&denali_pi[74], |
| 753 | (0x1 << 16) | (0x3 << 24), |
| 754 | (0x1 << 16) | (i << 24)); |
| 755 | |
| 756 | /* Waiting for training complete */ |
| 757 | while (1) { |
| 758 | /* PI_174 PI_INT_STATUS:RD:8:18 */ |
| 759 | tmp = readl(&denali_pi[174]) >> 8; |
| 760 | |
| 761 | /* |
| 762 | * check status obs |
| 763 | * PHY_43/171/299/427 |
| 764 | * PHY_GTLVL_STATUS_OBS_x:16:8 |
| 765 | */ |
| 766 | obs_0 = readl(&denali_phy[43]); |
| 767 | obs_1 = readl(&denali_phy[171]); |
| 768 | obs_2 = readl(&denali_phy[299]); |
| 769 | obs_3 = readl(&denali_phy[427]); |
| 770 | if (((obs_0 >> (16 + 6)) & 0x3) || |
| 771 | ((obs_1 >> (16 + 6)) & 0x3) || |
| 772 | ((obs_2 >> (16 + 6)) & 0x3) || |
| 773 | ((obs_3 >> (16 + 6)) & 0x3)) |
| 774 | obs_err = 1; |
| 775 | if ((((tmp >> 9) & 0x1) == 0x1) && |
| 776 | (((tmp >> 13) & 0x1) == 0x1) && |
| 777 | (((tmp >> 3) & 0x1) == 0x0) && |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 778 | obs_err == 0) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 779 | break; |
| 780 | else if ((((tmp >> 3) & 0x1) == 0x1) || |
| 781 | (obs_err == 1)) |
| 782 | return -EIO; |
| 783 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 784 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 785 | /* clear interrupt,PI_175 PI_INT_ACK:WR:0:17 */ |
| 786 | writel(0x00003f7c, (&denali_pi[175])); |
| 787 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 788 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 789 | clrbits_le32(&denali_pi[80], 0x3 << 24); |
| 790 | |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | static int data_training_rl(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 795 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 796 | { |
| 797 | u32 *denali_pi = chan->pi->denali_pi; |
| 798 | u32 i, tmp; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 799 | u32 rank = params->ch[channel].rank; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 800 | |
| 801 | for (i = 0; i < rank; i++) { |
| 802 | select_per_cs_training_index(chan, i); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 803 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 804 | /* PI_80 PI_RDLVL_EN:RW:16:2 */ |
| 805 | clrsetbits_le32(&denali_pi[80], 0x3 << 16, 0x2 << 16); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 806 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 807 | /* PI_74 PI_RDLVL_REQ:WR:8:1,PI_RDLVL_CS:RW:24:2 */ |
| 808 | clrsetbits_le32(&denali_pi[74], |
| 809 | (0x1 << 8) | (0x3 << 24), |
| 810 | (0x1 << 8) | (i << 24)); |
| 811 | |
| 812 | /* Waiting for training complete */ |
| 813 | while (1) { |
| 814 | /* PI_174 PI_INT_STATUS:RD:8:18 */ |
| 815 | tmp = readl(&denali_pi[174]) >> 8; |
| 816 | |
| 817 | /* |
| 818 | * make sure status obs not report error bit |
| 819 | * PHY_46/174/302/430 |
| 820 | * phy_rdlvl_status_obs_X:16:8 |
| 821 | */ |
| 822 | if ((((tmp >> 8) & 0x1) == 0x1) && |
| 823 | (((tmp >> 13) & 0x1) == 0x1) && |
| 824 | (((tmp >> 2) & 0x1) == 0x0)) |
| 825 | break; |
| 826 | else if (((tmp >> 2) & 0x1) == 0x1) |
| 827 | return -EIO; |
| 828 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 829 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 830 | /* clear interrupt,PI_175 PI_INT_ACK:WR:0:17 */ |
| 831 | writel(0x00003f7c, (&denali_pi[175])); |
| 832 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 833 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 834 | clrbits_le32(&denali_pi[80], 0x3 << 16); |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | static int data_training_wdql(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 840 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 841 | { |
| 842 | u32 *denali_pi = chan->pi->denali_pi; |
| 843 | u32 i, tmp; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 844 | u32 rank = params->ch[channel].rank; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 845 | |
| 846 | for (i = 0; i < rank; i++) { |
| 847 | select_per_cs_training_index(chan, i); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 848 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 849 | /* |
| 850 | * disable PI_WDQLVL_VREF_EN before wdq leveling? |
| 851 | * PI_181 PI_WDQLVL_VREF_EN:RW:8:1 |
| 852 | */ |
| 853 | clrbits_le32(&denali_pi[181], 0x1 << 8); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 854 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 855 | /* PI_124 PI_WDQLVL_EN:RW:16:2 */ |
| 856 | clrsetbits_le32(&denali_pi[124], 0x3 << 16, 0x2 << 16); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 857 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 858 | /* PI_121 PI_WDQLVL_REQ:WR:8:1,PI_WDQLVL_CS:RW:16:2 */ |
| 859 | clrsetbits_le32(&denali_pi[121], |
| 860 | (0x1 << 8) | (0x3 << 16), |
| 861 | (0x1 << 8) | (i << 16)); |
| 862 | |
| 863 | /* Waiting for training complete */ |
| 864 | while (1) { |
| 865 | /* PI_174 PI_INT_STATUS:RD:8:18 */ |
| 866 | tmp = readl(&denali_pi[174]) >> 8; |
| 867 | if ((((tmp >> 12) & 0x1) == 0x1) && |
| 868 | (((tmp >> 13) & 0x1) == 0x1) && |
| 869 | (((tmp >> 6) & 0x1) == 0x0)) |
| 870 | break; |
| 871 | else if (((tmp >> 6) & 0x1) == 0x1) |
| 872 | return -EIO; |
| 873 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 874 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 875 | /* clear interrupt,PI_175 PI_INT_ACK:WR:0:17 */ |
| 876 | writel(0x00003f7c, (&denali_pi[175])); |
| 877 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 878 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 879 | clrbits_le32(&denali_pi[124], 0x3 << 16); |
| 880 | |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | static int data_training(const struct chan_info *chan, u32 channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 885 | const struct rk3399_sdram_params *params, |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 886 | u32 training_flag) |
| 887 | { |
| 888 | u32 *denali_phy = chan->publ->denali_phy; |
| 889 | |
| 890 | /* PHY_927 PHY_PAD_DQS_DRIVE RPULL offset_22 */ |
| 891 | setbits_le32(&denali_phy[927], (1 << 22)); |
| 892 | |
| 893 | if (training_flag == PI_FULL_TRAINING) { |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 894 | if (params->base.dramtype == LPDDR4) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 895 | training_flag = PI_CA_TRAINING | PI_WRITE_LEVELING | |
| 896 | PI_READ_GATE_TRAINING | |
| 897 | PI_READ_LEVELING | PI_WDQ_LEVELING; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 898 | } else if (params->base.dramtype == LPDDR3) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 899 | training_flag = PI_CA_TRAINING | PI_WRITE_LEVELING | |
| 900 | PI_READ_GATE_TRAINING; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 901 | } else if (params->base.dramtype == DDR3) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 902 | training_flag = PI_WRITE_LEVELING | |
| 903 | PI_READ_GATE_TRAINING | |
| 904 | PI_READ_LEVELING; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | /* ca training(LPDDR4,LPDDR3 support) */ |
| 909 | if ((training_flag & PI_CA_TRAINING) == PI_CA_TRAINING) |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 910 | data_training_ca(chan, channel, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 911 | |
| 912 | /* write leveling(LPDDR4,LPDDR3,DDR3 support) */ |
| 913 | if ((training_flag & PI_WRITE_LEVELING) == PI_WRITE_LEVELING) |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 914 | data_training_wl(chan, channel, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 915 | |
| 916 | /* read gate training(LPDDR4,LPDDR3,DDR3 support) */ |
| 917 | if ((training_flag & PI_READ_GATE_TRAINING) == PI_READ_GATE_TRAINING) |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 918 | data_training_rg(chan, channel, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 919 | |
| 920 | /* read leveling(LPDDR4,LPDDR3,DDR3 support) */ |
| 921 | if ((training_flag & PI_READ_LEVELING) == PI_READ_LEVELING) |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 922 | data_training_rl(chan, channel, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 923 | |
| 924 | /* wdq leveling(LPDDR4 support) */ |
| 925 | if ((training_flag & PI_WDQ_LEVELING) == PI_WDQ_LEVELING) |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 926 | data_training_wdql(chan, channel, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 927 | |
| 928 | /* PHY_927 PHY_PAD_DQS_DRIVE RPULL offset_22 */ |
| 929 | clrbits_le32(&denali_phy[927], (1 << 22)); |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static void set_ddrconfig(const struct chan_info *chan, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 935 | const struct rk3399_sdram_params *params, |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 936 | unsigned char channel, u32 ddrconfig) |
| 937 | { |
| 938 | /* only need to set ddrconfig */ |
| 939 | struct rk3399_msch_regs *ddr_msch_regs = chan->msch; |
| 940 | unsigned int cs0_cap = 0; |
| 941 | unsigned int cs1_cap = 0; |
| 942 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 943 | cs0_cap = (1 << (params->ch[channel].cs0_row |
| 944 | + params->ch[channel].col |
| 945 | + params->ch[channel].bk |
| 946 | + params->ch[channel].bw - 20)); |
| 947 | if (params->ch[channel].rank > 1) |
| 948 | cs1_cap = cs0_cap >> (params->ch[channel].cs0_row |
| 949 | - params->ch[channel].cs1_row); |
| 950 | if (params->ch[channel].row_3_4) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 951 | cs0_cap = cs0_cap * 3 / 4; |
| 952 | cs1_cap = cs1_cap * 3 / 4; |
| 953 | } |
| 954 | |
| 955 | writel(ddrconfig | (ddrconfig << 8), &ddr_msch_regs->ddrconf); |
| 956 | writel(((cs0_cap / 32) & 0xff) | (((cs1_cap / 32) & 0xff) << 8), |
| 957 | &ddr_msch_regs->ddrsize); |
| 958 | } |
| 959 | |
| 960 | static void dram_all_config(struct dram_info *dram, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 961 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 962 | { |
| 963 | u32 sys_reg = 0; |
| 964 | unsigned int channel, idx; |
| 965 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 966 | sys_reg |= params->base.dramtype << SYS_REG_DDRTYPE_SHIFT; |
| 967 | sys_reg |= (params->base.num_channels - 1) << SYS_REG_NUM_CH_SHIFT; |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 968 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 969 | for (channel = 0, idx = 0; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 970 | (idx < params->base.num_channels) && (channel < 2); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 971 | channel++) { |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 972 | const struct rk3399_sdram_channel *info = ¶ms->ch[channel]; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 973 | struct rk3399_msch_regs *ddr_msch_regs; |
| 974 | const struct rk3399_msch_timings *noc_timing; |
| 975 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 976 | if (params->ch[channel].col == 0) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 977 | continue; |
| 978 | idx++; |
| 979 | sys_reg |= info->row_3_4 << SYS_REG_ROW_3_4_SHIFT(channel); |
| 980 | sys_reg |= 1 << SYS_REG_CHINFO_SHIFT(channel); |
| 981 | sys_reg |= (info->rank - 1) << SYS_REG_RANK_SHIFT(channel); |
| 982 | sys_reg |= (info->col - 9) << SYS_REG_COL_SHIFT(channel); |
| 983 | sys_reg |= info->bk == 3 ? 0 : 1 << SYS_REG_BK_SHIFT(channel); |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 984 | sys_reg |= (info->cs0_row - 13) << |
| 985 | SYS_REG_CS0_ROW_SHIFT(channel); |
| 986 | sys_reg |= (info->cs1_row - 13) << |
| 987 | SYS_REG_CS1_ROW_SHIFT(channel); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 988 | sys_reg |= (2 >> info->bw) << SYS_REG_BW_SHIFT(channel); |
| 989 | sys_reg |= (2 >> info->dbw) << SYS_REG_DBW_SHIFT(channel); |
| 990 | |
| 991 | ddr_msch_regs = dram->chan[channel].msch; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 992 | noc_timing = ¶ms->ch[channel].noc_timings; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 993 | writel(noc_timing->ddrtiminga0, |
| 994 | &ddr_msch_regs->ddrtiminga0); |
| 995 | writel(noc_timing->ddrtimingb0, |
| 996 | &ddr_msch_regs->ddrtimingb0); |
| 997 | writel(noc_timing->ddrtimingc0, |
| 998 | &ddr_msch_regs->ddrtimingc0); |
| 999 | writel(noc_timing->devtodev0, |
| 1000 | &ddr_msch_regs->devtodev0); |
| 1001 | writel(noc_timing->ddrmode, |
| 1002 | &ddr_msch_regs->ddrmode); |
| 1003 | |
| 1004 | /* rank 1 memory clock disable (dfi_dram_clk_disable = 1) */ |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1005 | if (params->ch[channel].rank == 1) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1006 | setbits_le32(&dram->chan[channel].pctl->denali_ctl[276], |
| 1007 | 1 << 17); |
| 1008 | } |
| 1009 | |
| 1010 | writel(sys_reg, &dram->pmugrf->os_reg2); |
| 1011 | rk_clrsetreg(&dram->pmusgrf->soc_con4, 0x1f << 10, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1012 | params->base.stride << 10); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1013 | |
| 1014 | /* reboot hold register set */ |
| 1015 | writel(PRESET_SGRF_HOLD(0) | PRESET_GPIO0_HOLD(1) | |
| 1016 | PRESET_GPIO1_HOLD(1), |
| 1017 | &dram->pmucru->pmucru_rstnhold_con[1]); |
| 1018 | clrsetbits_le32(&dram->cru->glb_rst_con, 0x3, 0x3); |
| 1019 | } |
| 1020 | |
| 1021 | static int switch_to_phy_index1(struct dram_info *dram, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1022 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1023 | { |
| 1024 | u32 channel; |
| 1025 | u32 *denali_phy; |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1026 | u32 ch_count = params->base.num_channels; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1027 | int ret; |
| 1028 | int i = 0; |
| 1029 | |
| 1030 | writel(RK_CLRSETBITS(0x03 << 4 | 1 << 2 | 1, |
| 1031 | 1 << 4 | 1 << 2 | 1), |
| 1032 | &dram->cic->cic_ctrl0); |
| 1033 | while (!(readl(&dram->cic->cic_status0) & (1 << 2))) { |
| 1034 | mdelay(10); |
| 1035 | i++; |
| 1036 | if (i > 10) { |
| 1037 | debug("index1 frequency change overtime\n"); |
| 1038 | return -ETIME; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | i = 0; |
| 1043 | writel(RK_CLRSETBITS(1 << 1, 1 << 1), &dram->cic->cic_ctrl0); |
| 1044 | while (!(readl(&dram->cic->cic_status0) & (1 << 0))) { |
| 1045 | mdelay(10); |
Heinrich Schuchardt | 8051659 | 2018-03-18 12:10:55 +0100 | [diff] [blame] | 1046 | i++; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1047 | if (i > 10) { |
| 1048 | debug("index1 frequency done overtime\n"); |
| 1049 | return -ETIME; |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | for (channel = 0; channel < ch_count; channel++) { |
| 1054 | denali_phy = dram->chan[channel].publ->denali_phy; |
| 1055 | clrsetbits_le32(&denali_phy[896], (0x3 << 8) | 1, 1 << 8); |
| 1056 | ret = data_training(&dram->chan[channel], channel, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1057 | params, PI_FULL_TRAINING); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1058 | if (ret) { |
| 1059 | debug("index1 training failed\n"); |
| 1060 | return ret; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | return 0; |
| 1065 | } |
| 1066 | |
| 1067 | static int sdram_init(struct dram_info *dram, |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1068 | const struct rk3399_sdram_params *params) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1069 | { |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1070 | unsigned char dramtype = params->base.dramtype; |
| 1071 | unsigned int ddr_freq = params->base.ddr_freq; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1072 | int channel; |
Jagan Teki | 2ef77ed | 2019-07-15 23:50:59 +0530 | [diff] [blame] | 1073 | int ret; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1074 | |
| 1075 | debug("Starting SDRAM initialization...\n"); |
| 1076 | |
Philipp Tomsich | 39dce4a | 2017-05-31 18:16:35 +0200 | [diff] [blame] | 1077 | if ((dramtype == DDR3 && ddr_freq > 933) || |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1078 | (dramtype == LPDDR3 && ddr_freq > 933) || |
| 1079 | (dramtype == LPDDR4 && ddr_freq > 800)) { |
| 1080 | debug("SDRAM frequency is to high!"); |
| 1081 | return -E2BIG; |
| 1082 | } |
| 1083 | |
| 1084 | for (channel = 0; channel < 2; channel++) { |
| 1085 | const struct chan_info *chan = &dram->chan[channel]; |
| 1086 | struct rk3399_ddr_publ_regs *publ = chan->publ; |
| 1087 | |
| 1088 | phy_dll_bypass_set(publ, ddr_freq); |
| 1089 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1090 | if (channel >= params->base.num_channels) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1091 | continue; |
| 1092 | |
Jagan Teki | 2ef77ed | 2019-07-15 23:50:59 +0530 | [diff] [blame] | 1093 | ret = pctl_cfg(chan, channel, params); |
| 1094 | if (ret < 0) { |
| 1095 | printf("%s: pctl config failed\n", __func__); |
| 1096 | return ret; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /* LPDDR2/LPDDR3 need to wait DAI complete, max 10us */ |
| 1100 | if (dramtype == LPDDR3) |
| 1101 | udelay(10); |
| 1102 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1103 | if (data_training(chan, channel, params, PI_FULL_TRAINING)) { |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1104 | printf("SDRAM initialization failed, reset\n"); |
| 1105 | return -EIO; |
| 1106 | } |
| 1107 | |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1108 | set_ddrconfig(chan, params, channel, |
| 1109 | params->ch[channel].ddrconfig); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1110 | } |
Jagan Teki | a58ff79 | 2019-07-15 23:50:58 +0530 | [diff] [blame] | 1111 | dram_all_config(dram, params); |
| 1112 | switch_to_phy_index1(dram, params); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1113 | |
| 1114 | debug("Finish SDRAM initialization...\n"); |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static int rk3399_dmc_ofdata_to_platdata(struct udevice *dev) |
| 1119 | { |
| 1120 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 1121 | struct rockchip_dmc_plat *plat = dev_get_platdata(dev); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1122 | int ret; |
| 1123 | |
Philipp Tomsich | 0250c23 | 2017-06-07 18:46:03 +0200 | [diff] [blame] | 1124 | ret = dev_read_u32_array(dev, "rockchip,sdram-params", |
| 1125 | (u32 *)&plat->sdram_params, |
| 1126 | sizeof(plat->sdram_params) / sizeof(u32)); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1127 | if (ret) { |
| 1128 | printf("%s: Cannot read rockchip,sdram-params %d\n", |
| 1129 | __func__, ret); |
| 1130 | return ret; |
| 1131 | } |
Masahiro Yamada | e4873e3 | 2018-04-19 12:14:03 +0900 | [diff] [blame] | 1132 | ret = regmap_init_mem(dev_ofnode(dev), &plat->map); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1133 | if (ret) |
| 1134 | printf("%s: regmap failed %d\n", __func__, ret); |
| 1135 | |
| 1136 | #endif |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 1141 | static int conv_of_platdata(struct udevice *dev) |
| 1142 | { |
| 1143 | struct rockchip_dmc_plat *plat = dev_get_platdata(dev); |
| 1144 | struct dtd_rockchip_rk3399_dmc *dtplat = &plat->dtplat; |
| 1145 | int ret; |
| 1146 | |
| 1147 | ret = regmap_init_mem_platdata(dev, dtplat->reg, |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 1148 | ARRAY_SIZE(dtplat->reg) / 2, |
| 1149 | &plat->map); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1150 | if (ret) |
| 1151 | return ret; |
| 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | #endif |
| 1156 | |
| 1157 | static int rk3399_dmc_init(struct udevice *dev) |
| 1158 | { |
| 1159 | struct dram_info *priv = dev_get_priv(dev); |
| 1160 | struct rockchip_dmc_plat *plat = dev_get_platdata(dev); |
| 1161 | int ret; |
| 1162 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 1163 | struct rk3399_sdram_params *params = &plat->sdram_params; |
| 1164 | #else |
| 1165 | struct dtd_rockchip_rk3399_dmc *dtplat = &plat->dtplat; |
| 1166 | struct rk3399_sdram_params *params = |
| 1167 | (void *)dtplat->rockchip_sdram_params; |
| 1168 | |
| 1169 | ret = conv_of_platdata(dev); |
| 1170 | if (ret) |
| 1171 | return ret; |
| 1172 | #endif |
| 1173 | |
| 1174 | priv->cic = syscon_get_first_range(ROCKCHIP_SYSCON_CIC); |
| 1175 | priv->pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF); |
| 1176 | priv->pmusgrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUSGRF); |
| 1177 | priv->pmucru = rockchip_get_pmucru(); |
| 1178 | priv->cru = rockchip_get_cru(); |
| 1179 | priv->chan[0].pctl = regmap_get_range(plat->map, 0); |
| 1180 | priv->chan[0].pi = regmap_get_range(plat->map, 1); |
| 1181 | priv->chan[0].publ = regmap_get_range(plat->map, 2); |
| 1182 | priv->chan[0].msch = regmap_get_range(plat->map, 3); |
| 1183 | priv->chan[1].pctl = regmap_get_range(plat->map, 4); |
| 1184 | priv->chan[1].pi = regmap_get_range(plat->map, 5); |
| 1185 | priv->chan[1].publ = regmap_get_range(plat->map, 6); |
| 1186 | priv->chan[1].msch = regmap_get_range(plat->map, 7); |
| 1187 | |
| 1188 | debug("con reg %p %p %p %p %p %p %p %p\n", |
| 1189 | priv->chan[0].pctl, priv->chan[0].pi, |
| 1190 | priv->chan[0].publ, priv->chan[0].msch, |
| 1191 | priv->chan[1].pctl, priv->chan[1].pi, |
| 1192 | priv->chan[1].publ, priv->chan[1].msch); |
| 1193 | debug("cru %p, cic %p, grf %p, sgrf %p, pmucru %p\n", priv->cru, |
| 1194 | priv->cic, priv->pmugrf, priv->pmusgrf, priv->pmucru); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 1195 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1196 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 1197 | ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->ddr_clk); |
| 1198 | #else |
| 1199 | ret = clk_get_by_index(dev, 0, &priv->ddr_clk); |
| 1200 | #endif |
| 1201 | if (ret) { |
| 1202 | printf("%s clk get failed %d\n", __func__, ret); |
| 1203 | return ret; |
| 1204 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 1205 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1206 | ret = clk_set_rate(&priv->ddr_clk, params->base.ddr_freq * MHz); |
| 1207 | if (ret < 0) { |
| 1208 | printf("%s clk set failed %d\n", __func__, ret); |
| 1209 | return ret; |
| 1210 | } |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 1211 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1212 | ret = sdram_init(priv, params); |
| 1213 | if (ret < 0) { |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 1214 | printf("%s DRAM init failed %d\n", __func__, ret); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1215 | return ret; |
| 1216 | } |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | #endif |
| 1221 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1222 | static int rk3399_dmc_probe(struct udevice *dev) |
| 1223 | { |
Kever Yang | 7f34784 | 2019-04-01 17:20:53 +0800 | [diff] [blame] | 1224 | #if defined(CONFIG_TPL_BUILD) || \ |
| 1225 | (!defined(CONFIG_TPL) && defined(CONFIG_SPL_BUILD)) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1226 | if (rk3399_dmc_init(dev)) |
| 1227 | return 0; |
| 1228 | #else |
| 1229 | struct dram_info *priv = dev_get_priv(dev); |
| 1230 | |
| 1231 | priv->pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF); |
Jagan Teki | acf8e0f | 2019-07-15 23:50:57 +0530 | [diff] [blame] | 1232 | debug("%s: pmugrf = %p\n", __func__, priv->pmugrf); |
Kever Yang | 6c15a54 | 2017-06-23 16:11:06 +0800 | [diff] [blame] | 1233 | priv->info.base = CONFIG_SYS_SDRAM_BASE; |
Jagan Teki | f676c7c | 2019-07-15 23:50:56 +0530 | [diff] [blame] | 1234 | priv->info.size = |
| 1235 | rockchip_sdram_size((phys_addr_t)&priv->pmugrf->os_reg2); |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1236 | #endif |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | static int rk3399_dmc_get_info(struct udevice *dev, struct ram_info *info) |
| 1241 | { |
| 1242 | struct dram_info *priv = dev_get_priv(dev); |
| 1243 | |
Kever Yang | ea61d14 | 2017-04-19 16:01:14 +0800 | [diff] [blame] | 1244 | *info = priv->info; |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1245 | |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static struct ram_ops rk3399_dmc_ops = { |
| 1250 | .get_info = rk3399_dmc_get_info, |
| 1251 | }; |
| 1252 | |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1253 | static const struct udevice_id rk3399_dmc_ids[] = { |
| 1254 | { .compatible = "rockchip,rk3399-dmc" }, |
| 1255 | { } |
| 1256 | }; |
| 1257 | |
| 1258 | U_BOOT_DRIVER(dmc_rk3399) = { |
| 1259 | .name = "rockchip_rk3399_dmc", |
| 1260 | .id = UCLASS_RAM, |
| 1261 | .of_match = rk3399_dmc_ids, |
| 1262 | .ops = &rk3399_dmc_ops, |
Kever Yang | 7f34784 | 2019-04-01 17:20:53 +0800 | [diff] [blame] | 1263 | #if defined(CONFIG_TPL_BUILD) || \ |
| 1264 | (!defined(CONFIG_TPL) && defined(CONFIG_SPL_BUILD)) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1265 | .ofdata_to_platdata = rk3399_dmc_ofdata_to_platdata, |
| 1266 | #endif |
| 1267 | .probe = rk3399_dmc_probe, |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1268 | .priv_auto_alloc_size = sizeof(struct dram_info), |
Kever Yang | 7f34784 | 2019-04-01 17:20:53 +0800 | [diff] [blame] | 1269 | #if defined(CONFIG_TPL_BUILD) || \ |
| 1270 | (!defined(CONFIG_TPL) && defined(CONFIG_SPL_BUILD)) |
Kever Yang | 50fb998 | 2017-02-22 16:56:35 +0800 | [diff] [blame] | 1271 | .platdata_auto_alloc_size = sizeof(struct rockchip_dmc_plat), |
| 1272 | #endif |
| 1273 | }; |