blob: 7bf19ed9665f1b40ab98d2aa997f4a656989fc73 [file] [log] [blame]
Chandan Nath62d7fe7c2011-10-14 02:58:24 +00001/*
2 * DDR Configuration for AM33xx devices.
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
Chandan Nath62d7fe7c2011-10-14 02:58:24 +00005 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath62d7fe7c2011-10-14 02:58:24 +00007 */
8
9#include <asm/arch/cpu.h>
10#include <asm/arch/ddr_defs.h>
Satyanarayana, Sandhya6995a282012-08-09 18:29:57 +000011#include <asm/arch/sys_proto.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000012#include <asm/io.h>
Tom Rini7d5eb342012-05-29 09:02:15 -070013#include <asm/emif.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000014
15/**
16 * Base address for EMIF instances
17 */
Matt Porter3ba65f92013-03-15 10:07:03 +000018static struct emif_reg_struct *emif_reg[2] = {
19 (struct emif_reg_struct *)EMIF4_0_CFG_BASE,
20 (struct emif_reg_struct *)EMIF4_1_CFG_BASE};
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000021
22/**
Matt Porter3ba65f92013-03-15 10:07:03 +000023 * Base addresses for DDR PHY cmd/data regs
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000024 */
Matt Porter3ba65f92013-03-15 10:07:03 +000025static struct ddr_cmd_regs *ddr_cmd_reg[2] = {
26 (struct ddr_cmd_regs *)DDR_PHY_CMD_ADDR,
27 (struct ddr_cmd_regs *)DDR_PHY_CMD_ADDR2};
28
29static struct ddr_data_regs *ddr_data_reg[2] = {
30 (struct ddr_data_regs *)DDR_PHY_DATA_ADDR,
31 (struct ddr_data_regs *)DDR_PHY_DATA_ADDR2};
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000032
33/**
34 * Base address for ddr io control instances
35 */
36static struct ddr_cmdtctrl *ioctrl_reg = {
37 (struct ddr_cmdtctrl *)DDR_CONTROL_BASE_ADDR};
38
Lokesh Vutlad3daba12013-12-10 15:02:22 +053039static inline u32 get_mr(int nr, u32 cs, u32 mr_addr)
40{
41 u32 mr;
42
43 mr_addr |= cs << EMIF_REG_CS_SHIFT;
44 writel(mr_addr, &emif_reg[nr]->emif_lpddr2_mode_reg_cfg);
45
46 mr = readl(&emif_reg[nr]->emif_lpddr2_mode_reg_data);
47 debug("get_mr: EMIF1 cs %d mr %08x val 0x%x\n", cs, mr_addr, mr);
48 if (((mr & 0x0000ff00) >> 8) == (mr & 0xff) &&
49 ((mr & 0x00ff0000) >> 16) == (mr & 0xff) &&
50 ((mr & 0xff000000) >> 24) == (mr & 0xff))
51 return mr & 0xff;
52 else
53 return mr;
54}
55
56static inline void set_mr(int nr, u32 cs, u32 mr_addr, u32 mr_val)
57{
58 mr_addr |= cs << EMIF_REG_CS_SHIFT;
59 writel(mr_addr, &emif_reg[nr]->emif_lpddr2_mode_reg_cfg);
60 writel(mr_val, &emif_reg[nr]->emif_lpddr2_mode_reg_data);
61}
62
63static void configure_mr(int nr, u32 cs)
64{
65 u32 mr_addr;
66
67 while (get_mr(nr, cs, LPDDR2_MR0) & LPDDR2_MR0_DAI_MASK)
68 ;
69 set_mr(nr, cs, LPDDR2_MR10, 0x56);
70
71 set_mr(nr, cs, LPDDR2_MR1, 0x43);
72 set_mr(nr, cs, LPDDR2_MR2, 0x2);
73
74 mr_addr = LPDDR2_MR2 | EMIF_REG_REFRESH_EN_MASK;
75 set_mr(nr, cs, mr_addr, 0x2);
76}
77
78/*
James Doublesinfc46bae2014-12-22 16:26:11 -060079 * Configure EMIF4D5 registers and MR registers For details about these magic
80 * values please see the EMIF registers section of the TRM.
Lokesh Vutlad3daba12013-12-10 15:02:22 +053081 */
82void config_sdram_emif4d5(const struct emif_regs *regs, int nr)
83{
Dave Gerlach4800be42014-02-18 07:31:59 -050084 writel(0xA0, &emif_reg[nr]->emif_pwr_mgmt_ctrl);
85 writel(0xA0, &emif_reg[nr]->emif_pwr_mgmt_ctrl_shdw);
Lokesh Vutlad3daba12013-12-10 15:02:22 +053086 writel(regs->zq_config, &emif_reg[nr]->emif_zq_config);
87
88 writel(regs->temp_alert_config, &emif_reg[nr]->emif_temp_alert_config);
89 writel(regs->emif_rd_wr_lvl_rmp_win,
90 &emif_reg[nr]->emif_rd_wr_lvl_rmp_win);
91 writel(regs->emif_rd_wr_lvl_rmp_ctl,
92 &emif_reg[nr]->emif_rd_wr_lvl_rmp_ctl);
93 writel(regs->emif_rd_wr_lvl_ctl, &emif_reg[nr]->emif_rd_wr_lvl_ctl);
94 writel(regs->emif_rd_wr_exec_thresh,
95 &emif_reg[nr]->emif_rd_wr_exec_thresh);
96
Cooper Jr., Franklin8038b492014-06-27 13:31:15 -050097 /*
98 * for most SOCs these registers won't need to be changed so only
99 * write to these registers if someone explicitly has set the
100 * register's value.
101 */
102 if(regs->emif_cos_config) {
103 writel(regs->emif_prio_class_serv_map, &emif_reg[nr]->emif_prio_class_serv_map);
104 writel(regs->emif_connect_id_serv_1_map, &emif_reg[nr]->emif_connect_id_serv_1_map);
105 writel(regs->emif_connect_id_serv_2_map, &emif_reg[nr]->emif_connect_id_serv_2_map);
106 writel(regs->emif_cos_config, &emif_reg[nr]->emif_cos_config);
107 }
108
James Doublesinfc46bae2014-12-22 16:26:11 -0600109 /*
110 * Sequence to ensure that the PHY is in a known state prior to
111 * startting hardware leveling. Also acts as to latch some state from
112 * the EMIF into the PHY.
113 */
114 writel(0x2011, &emif_reg[nr]->emif_iodft_tlgc);
115 writel(0x2411, &emif_reg[nr]->emif_iodft_tlgc);
116 writel(0x2011, &emif_reg[nr]->emif_iodft_tlgc);
117
118 clrbits_le32(&emif_reg[nr]->emif_sdram_ref_ctrl,
119 EMIF_REG_INITREF_DIS_MASK);
120
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530121 writel(regs->sdram_config, &emif_reg[nr]->emif_sdram_config);
Dave Gerlachf84880f2014-02-18 07:32:00 -0500122 writel(regs->sdram_config, &cstat->secure_emif_sdram_config);
Russ Dill3325b062016-07-21 04:28:31 -0700123
124 /* Wait 1ms because of L3 timeout error */
125 udelay(1000);
126
James Doublesinfc46bae2014-12-22 16:26:11 -0600127 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl);
128 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl_shdw);
129
Tom Rini7c352cd2015-06-05 15:51:11 +0530130 /* Perform hardware leveling for DDR3 */
131 if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3) {
Tom Rini7c352cd2015-06-05 15:51:11 +0530132 writel(readl(&emif_reg[nr]->emif_ddr_ext_phy_ctrl_36) |
133 0x100, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_36);
134 writel(readl(&emif_reg[nr]->emif_ddr_ext_phy_ctrl_36_shdw) |
135 0x100, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_36_shdw);
James Doublesinfc46bae2014-12-22 16:26:11 -0600136
Tom Rini7c352cd2015-06-05 15:51:11 +0530137 writel(0x80000000, &emif_reg[nr]->emif_rd_wr_lvl_rmp_ctl);
James Doublesinfc46bae2014-12-22 16:26:11 -0600138
Tom Rini7c352cd2015-06-05 15:51:11 +0530139 /* Enable read leveling */
140 writel(0x80000000, &emif_reg[nr]->emif_rd_wr_lvl_ctl);
James Doublesinfc46bae2014-12-22 16:26:11 -0600141
Tom Rini7c352cd2015-06-05 15:51:11 +0530142 /*
143 * Enable full read and write leveling. Wait for read and write
144 * leveling bit to clear RDWRLVLFULL_START bit 31
145 */
146 while ((readl(&emif_reg[nr]->emif_rd_wr_lvl_ctl) & 0x80000000)
147 != 0)
148 ;
James Doublesinfc46bae2014-12-22 16:26:11 -0600149
Tom Rini7c352cd2015-06-05 15:51:11 +0530150 /* Check the timeout register to see if leveling is complete */
151 if ((readl(&emif_reg[nr]->emif_status) & 0x70) != 0)
152 puts("DDR3 H/W leveling incomplete with errors\n");
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530153
Tom Rini7c352cd2015-06-05 15:51:11 +0530154 } else {
155 /* DDR2 */
Lokesh Vutlab5e01ee2013-12-10 15:02:23 +0530156 configure_mr(nr, 0);
157 configure_mr(nr, 1);
158 }
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530159}
160
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000161/**
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000162 * Configure SDRAM
163 */
Matt Porter3ba65f92013-03-15 10:07:03 +0000164void config_sdram(const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000165{
Tom Rini86277332017-05-16 14:46:35 -0400166#ifdef CONFIG_TI816X
167 writel(regs->sdram_config, &emif_reg[nr]->emif_sdram_config);
168 writel(regs->emif_ddr_phy_ctlr_1, &emif_reg[nr]->emif_ddr_phy_ctrl_1);
169 writel(regs->emif_ddr_phy_ctlr_1, &emif_reg[nr]->emif_ddr_phy_ctrl_1_shdw);
170 writel(0x0000613B, &emif_reg[nr]->emif_sdram_ref_ctrl); /* initially a large refresh period */
171 writel(0x1000613B, &emif_reg[nr]->emif_sdram_ref_ctrl); /* trigger initialization */
172 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl);
173#else
Tom Rini1c382ea2013-02-26 16:35:33 -0500174 if (regs->zq_config) {
Matt Porter3ba65f92013-03-15 10:07:03 +0000175 writel(regs->zq_config, &emif_reg[nr]->emif_zq_config);
Satyanarayana, Sandhya6995a282012-08-09 18:29:57 +0000176 writel(regs->sdram_config, &cstat->secure_emif_sdram_config);
Matt Porter3ba65f92013-03-15 10:07:03 +0000177 writel(regs->sdram_config, &emif_reg[nr]->emif_sdram_config);
Egli, Samuel69b918b2015-12-02 15:27:56 +0100178
179 /* Trigger initialization */
180 writel(0x00003100, &emif_reg[nr]->emif_sdram_ref_ctrl);
181 /* Wait 1ms because of L3 timeout error */
182 udelay(1000);
183
184 /* Write proper sdram_ref_cref_ctrl value */
Matt Porter3ba65f92013-03-15 10:07:03 +0000185 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl);
186 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl_shdw);
Satyanarayana, Sandhya6995a282012-08-09 18:29:57 +0000187 }
Matt Porter3ba65f92013-03-15 10:07:03 +0000188 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl);
189 writel(regs->ref_ctrl, &emif_reg[nr]->emif_sdram_ref_ctrl_shdw);
Tom Rinie049b772015-04-02 16:01:33 -0400190 writel(regs->sdram_config, &emif_reg[nr]->emif_sdram_config);
Jyri Sarha8c17cbd2016-12-09 12:29:13 +0200191
192 /* Write REG_COS_COUNT_1, REG_COS_COUNT_2, and REG_PR_OLD_COUNT. */
193 if (regs->ocp_config)
194 writel(regs->ocp_config, &emif_reg[nr]->emif_l3_config);
Tom Rini86277332017-05-16 14:46:35 -0400195#endif
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000196}
197
198/**
199 * Set SDRAM timings
200 */
Matt Porter3ba65f92013-03-15 10:07:03 +0000201void set_sdram_timings(const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000202{
Matt Porter3ba65f92013-03-15 10:07:03 +0000203 writel(regs->sdram_tim1, &emif_reg[nr]->emif_sdram_tim_1);
204 writel(regs->sdram_tim1, &emif_reg[nr]->emif_sdram_tim_1_shdw);
205 writel(regs->sdram_tim2, &emif_reg[nr]->emif_sdram_tim_2);
206 writel(regs->sdram_tim2, &emif_reg[nr]->emif_sdram_tim_2_shdw);
207 writel(regs->sdram_tim3, &emif_reg[nr]->emif_sdram_tim_3);
208 writel(regs->sdram_tim3, &emif_reg[nr]->emif_sdram_tim_3_shdw);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000209}
210
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530211/*
Tom Rini7c352cd2015-06-05 15:51:11 +0530212 * Configure EXT PHY registers for software leveling
213 */
214static void ext_phy_settings_swlvl(const struct emif_regs *regs, int nr)
215{
216 u32 *ext_phy_ctrl_base = 0;
217 u32 *emif_ext_phy_ctrl_base = 0;
218 __maybe_unused const u32 *ext_phy_ctrl_const_regs;
219 u32 i = 0;
220 __maybe_unused u32 size;
221
222 ext_phy_ctrl_base = (u32 *)&(regs->emif_ddr_ext_phy_ctrl_1);
223 emif_ext_phy_ctrl_base =
224 (u32 *)&(emif_reg[nr]->emif_ddr_ext_phy_ctrl_1);
225
226 /* Configure external phy control timing registers */
227 for (i = 0; i < EMIF_EXT_PHY_CTRL_TIMING_REG; i++) {
228 writel(*ext_phy_ctrl_base, emif_ext_phy_ctrl_base++);
229 /* Update shadow registers */
230 writel(*ext_phy_ctrl_base++, emif_ext_phy_ctrl_base++);
231 }
232
233#ifdef CONFIG_AM43XX
234 /*
235 * External phy 6-24 registers do not change with ddr frequency.
236 * These only need to be set on DDR2 on AM43xx.
237 */
238 emif_get_ext_phy_ctrl_const_regs(&ext_phy_ctrl_const_regs, &size);
239
240 if (!size)
241 return;
242
243 for (i = 0; i < size; i++) {
244 writel(ext_phy_ctrl_const_regs[i], emif_ext_phy_ctrl_base++);
245 /* Update shadow registers */
246 writel(ext_phy_ctrl_const_regs[i], emif_ext_phy_ctrl_base++);
247 }
248#endif
249}
250
251/*
James Doublesinfc46bae2014-12-22 16:26:11 -0600252 * Configure EXT PHY registers for hardware leveling
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530253 */
Tom Rini7c352cd2015-06-05 15:51:11 +0530254static void ext_phy_settings_hwlvl(const struct emif_regs *regs, int nr)
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530255{
James Doublesinfc46bae2014-12-22 16:26:11 -0600256 /*
257 * Enable hardware leveling on the EMIF. For details about these
258 * magic values please see the EMIF registers section of the TRM.
259 */
260 writel(0x08020080, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_1);
261 writel(0x08020080, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_1_shdw);
262 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_22);
263 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_22_shdw);
264 writel(0x00600020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_23);
265 writel(0x00600020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_23_shdw);
266 writel(0x40010080, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_24);
267 writel(0x40010080, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_24_shdw);
268 writel(0x08102040, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_25);
269 writel(0x08102040, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_25_shdw);
270 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_26);
271 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_26_shdw);
272 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_27);
273 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_27_shdw);
274 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_28);
275 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_28_shdw);
276 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_29);
277 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_29_shdw);
278 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_30);
279 writel(0x00200020, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_30_shdw);
280 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_31);
281 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_31_shdw);
282 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_32);
283 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_32_shdw);
284 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_33);
285 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_33_shdw);
286 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_34);
287 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_34_shdw);
288 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_35);
289 writel(0x00000000, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_35_shdw);
290 writel(0x000000FF, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_36);
291 writel(0x000000FF, &emif_reg[nr]->emif_ddr_ext_phy_ctrl_36_shdw);
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530292
293 /*
James Doublesinfc46bae2014-12-22 16:26:11 -0600294 * Sequence to ensure that the PHY is again in a known state after
295 * hardware leveling.
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530296 */
James Doublesinfc46bae2014-12-22 16:26:11 -0600297 writel(0x2011, &emif_reg[nr]->emif_iodft_tlgc);
298 writel(0x2411, &emif_reg[nr]->emif_iodft_tlgc);
299 writel(0x2011, &emif_reg[nr]->emif_iodft_tlgc);
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530300}
301
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000302/**
303 * Configure DDR PHY
304 */
Matt Porter3ba65f92013-03-15 10:07:03 +0000305void config_ddr_phy(const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000306{
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530307 /*
Russ Dill335b4e52016-07-21 04:28:32 -0700308 * Disable initialization and refreshes for now until we finish
309 * programming EMIF regs and set time between rising edge of
310 * DDR_RESET to rising edge of DDR_CKE to > 500us per memory spec.
311 * We currently hardcode a value based on a max expected frequency
312 * of 400MHz.
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530313 */
Russ Dill335b4e52016-07-21 04:28:32 -0700314 writel(EMIF_REG_INITREF_DIS_MASK | 0x3100,
315 &emif_reg[nr]->emif_sdram_ref_ctrl);
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530316
Matt Porter3ba65f92013-03-15 10:07:03 +0000317 writel(regs->emif_ddr_phy_ctlr_1,
318 &emif_reg[nr]->emif_ddr_phy_ctrl_1);
319 writel(regs->emif_ddr_phy_ctlr_1,
320 &emif_reg[nr]->emif_ddr_phy_ctrl_1_shdw);
Lokesh Vutlad3daba12013-12-10 15:02:22 +0530321
Tom Rini7c352cd2015-06-05 15:51:11 +0530322 if (get_emif_rev((u32)emif_reg[nr]) == EMIF_4D5) {
323 if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3)
324 ext_phy_settings_hwlvl(regs, nr);
325 else
326 ext_phy_settings_swlvl(regs, nr);
327 }
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000328}
329
330/**
331 * Configure DDR CMD control registers
332 */
Matt Porter3ba65f92013-03-15 10:07:03 +0000333void config_cmd_ctrl(const struct cmd_control *cmd, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000334{
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530335 if (!cmd)
336 return;
337
Matt Porter3ba65f92013-03-15 10:07:03 +0000338 writel(cmd->cmd0csratio, &ddr_cmd_reg[nr]->cm0csratio);
Matt Porter3ba65f92013-03-15 10:07:03 +0000339 writel(cmd->cmd0iclkout, &ddr_cmd_reg[nr]->cm0iclkout);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000340
Matt Porter3ba65f92013-03-15 10:07:03 +0000341 writel(cmd->cmd1csratio, &ddr_cmd_reg[nr]->cm1csratio);
Matt Porter3ba65f92013-03-15 10:07:03 +0000342 writel(cmd->cmd1iclkout, &ddr_cmd_reg[nr]->cm1iclkout);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000343
Matt Porter3ba65f92013-03-15 10:07:03 +0000344 writel(cmd->cmd2csratio, &ddr_cmd_reg[nr]->cm2csratio);
Matt Porter3ba65f92013-03-15 10:07:03 +0000345 writel(cmd->cmd2iclkout, &ddr_cmd_reg[nr]->cm2iclkout);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000346}
347
348/**
349 * Configure DDR DATA registers
350 */
Matt Porter3ba65f92013-03-15 10:07:03 +0000351void config_ddr_data(const struct ddr_data *data, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000352{
Matt Porter3ba65f92013-03-15 10:07:03 +0000353 int i;
354
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530355 if (!data)
356 return;
357
Matt Porter3ba65f92013-03-15 10:07:03 +0000358 for (i = 0; i < DDR_DATA_REGS_NR; i++) {
359 writel(data->datardsratio0,
360 &(ddr_data_reg[nr]+i)->dt0rdsratio0);
361 writel(data->datawdsratio0,
362 &(ddr_data_reg[nr]+i)->dt0wdsratio0);
363 writel(data->datawiratio0,
364 &(ddr_data_reg[nr]+i)->dt0wiratio0);
365 writel(data->datagiratio0,
366 &(ddr_data_reg[nr]+i)->dt0giratio0);
367 writel(data->datafwsratio0,
368 &(ddr_data_reg[nr]+i)->dt0fwsratio0);
369 writel(data->datawrsratio0,
370 &(ddr_data_reg[nr]+i)->dt0wrsratio0);
Matt Porter3ba65f92013-03-15 10:07:03 +0000371 }
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000372}
373
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530374void config_io_ctrl(const struct ctrl_ioregs *ioregs)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000375{
Lokesh Vutla965de8b2013-12-10 15:02:21 +0530376 if (!ioregs)
377 return;
378
379 writel(ioregs->cm0ioctl, &ioctrl_reg->cm0ioctl);
380 writel(ioregs->cm1ioctl, &ioctrl_reg->cm1ioctl);
381 writel(ioregs->cm2ioctl, &ioctrl_reg->cm2ioctl);
382 writel(ioregs->dt0ioctl, &ioctrl_reg->dt0ioctl);
383 writel(ioregs->dt1ioctl, &ioctrl_reg->dt1ioctl);
384#ifdef CONFIG_AM43XX
385 writel(ioregs->dt2ioctrl, &ioctrl_reg->dt2ioctrl);
386 writel(ioregs->dt3ioctrl, &ioctrl_reg->dt3ioctrl);
387 writel(ioregs->emif_sdram_config_ext,
388 &ioctrl_reg->emif_sdram_config_ext);
389#endif
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000390}