1
2
3
4
5
6
7
8
9#include <common.h>
10#include <config.h>
11#include <asm/io.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/cpu.h>
14#include <asm/arch/dmc.h>
15#include <asm/arch/power.h>
16#include "common_setup.h"
17#include "exynos5_setup.h"
18#include "clock_init.h"
19
20#define TIMEOUT_US 10000
21#define NUM_BYTE_LANES 4
22#define DEFAULT_DQS 8
23#define DEFAULT_DQS_X4 ((DEFAULT_DQS << 24) || (DEFAULT_DQS << 16) \
24 || (DEFAULT_DQS << 8) || (DEFAULT_DQS << 0))
25
26#ifdef CONFIG_EXYNOS5250
27static void reset_phy_ctrl(void)
28{
29 struct exynos5_clock *clk =
30 (struct exynos5_clock *)samsung_get_base_clock();
31
32 writel(DDR3PHY_CTRL_PHY_RESET_OFF, &clk->lpddr3phy_ctrl);
33 writel(DDR3PHY_CTRL_PHY_RESET, &clk->lpddr3phy_ctrl);
34}
35
36int ddr3_mem_ctrl_init(struct mem_timings *mem, int reset)
37{
38 unsigned int val;
39 struct exynos5_phy_control *phy0_ctrl, *phy1_ctrl;
40 struct exynos5_dmc *dmc;
41 int i;
42
43 phy0_ctrl = (struct exynos5_phy_control *)samsung_get_base_dmc_phy();
44 phy1_ctrl = (struct exynos5_phy_control *)(samsung_get_base_dmc_phy()
45 + DMC_OFFSET);
46 dmc = (struct exynos5_dmc *)samsung_get_base_dmc_ctrl();
47
48 if (reset)
49 reset_phy_ctrl();
50
51
52 val = (mem->impedance << CA_CK_DRVR_DS_OFFSET) |
53 (mem->impedance << CA_CKE_DRVR_DS_OFFSET) |
54 (mem->impedance << CA_CS_DRVR_DS_OFFSET) |
55 (mem->impedance << CA_ADR_DRVR_DS_OFFSET);
56 writel(val, &phy0_ctrl->phy_con39);
57 writel(val, &phy1_ctrl->phy_con39);
58
59
60 val = (mem->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
61 (mem->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
62 writel(val, &phy0_ctrl->phy_con42);
63 writel(val, &phy1_ctrl->phy_con42);
64
65
66 if (dmc_config_zq(mem, &phy0_ctrl->phy_con16, &phy1_ctrl->phy_con16,
67 &phy0_ctrl->phy_con17, &phy1_ctrl->phy_con17))
68 return SETUP_ERR_ZQ_CALIBRATION_FAILURE;
69
70
71 writel(mem->phy0_pulld_dqs, &phy0_ctrl->phy_con14);
72 writel(mem->phy1_pulld_dqs, &phy1_ctrl->phy_con14);
73
74 writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
75 | (mem->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT),
76 &dmc->concontrol);
77
78 update_reset_dll(&dmc->phycontrol0, DDR_MODE_DDR3);
79
80
81 writel(mem->phy0_dqs, &phy0_ctrl->phy_con4);
82 writel(mem->phy1_dqs, &phy1_ctrl->phy_con4);
83
84 writel(mem->phy0_dq, &phy0_ctrl->phy_con6);
85 writel(mem->phy1_dq, &phy1_ctrl->phy_con6);
86
87 writel(mem->phy0_tFS, &phy0_ctrl->phy_con10);
88 writel(mem->phy1_tFS, &phy1_ctrl->phy_con10);
89
90 val = (mem->ctrl_start_point << PHY_CON12_CTRL_START_POINT_SHIFT) |
91 (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
92 (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
93 (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
94 writel(val, &phy0_ctrl->phy_con12);
95 writel(val, &phy1_ctrl->phy_con12);
96
97
98 writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
99 &phy0_ctrl->phy_con12);
100 writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
101 &phy1_ctrl->phy_con12);
102
103 update_reset_dll(&dmc->phycontrol0, DDR_MODE_DDR3);
104
105 writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
106 &dmc->concontrol);
107
108
109 writel(mem->iv_size, &dmc->ivcontrol);
110
111 writel(mem->memconfig, &dmc->memconfig0);
112 writel(mem->memconfig, &dmc->memconfig1);
113 writel(mem->membaseconfig0, &dmc->membaseconfig0);
114 writel(mem->membaseconfig1, &dmc->membaseconfig1);
115
116
117 writel(mem->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
118 &dmc->prechconfig);
119
120
121 writel(mem->dpwrdn_cyc << PWRDNCONFIG_DPWRDN_CYC_SHIFT |
122 mem->dsref_cyc << PWRDNCONFIG_DSREF_CYC_SHIFT,
123 &dmc->pwrdnconfig);
124
125
126
127
128 writel(mem->timing_ref, &dmc->timingref);
129 writel(mem->timing_row, &dmc->timingrow);
130 writel(mem->timing_data, &dmc->timingdata);
131 writel(mem->timing_power, &dmc->timingpower);
132
133
134 dmc_config_prech(mem, &dmc->directcmd);
135
136
137 dmc_config_mrs(mem, &dmc->directcmd);
138
139 if (mem->gate_leveling_enable) {
140 val = PHY_CON0_RESET_VAL;
141 val |= P0_CMD_EN;
142 writel(val, &phy0_ctrl->phy_con0);
143 writel(val, &phy1_ctrl->phy_con0);
144
145 val = PHY_CON2_RESET_VAL;
146 val |= INIT_DESKEW_EN;
147 writel(val, &phy0_ctrl->phy_con2);
148 writel(val, &phy1_ctrl->phy_con2);
149
150 val = PHY_CON0_RESET_VAL;
151 val |= P0_CMD_EN;
152 val |= BYTE_RDLVL_EN;
153 writel(val, &phy0_ctrl->phy_con0);
154 writel(val, &phy1_ctrl->phy_con0);
155
156 val = (mem->ctrl_start_point <<
157 PHY_CON12_CTRL_START_POINT_SHIFT) |
158 (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
159 (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
160 (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
161 (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
162 writel(val, &phy0_ctrl->phy_con12);
163 writel(val, &phy1_ctrl->phy_con12);
164
165 val = PHY_CON2_RESET_VAL;
166 val |= INIT_DESKEW_EN;
167 val |= RDLVL_GATE_EN;
168 writel(val, &phy0_ctrl->phy_con2);
169 writel(val, &phy1_ctrl->phy_con2);
170
171 val = PHY_CON0_RESET_VAL;
172 val |= P0_CMD_EN;
173 val |= BYTE_RDLVL_EN;
174 val |= CTRL_SHGATE;
175 writel(val, &phy0_ctrl->phy_con0);
176 writel(val, &phy1_ctrl->phy_con0);
177
178 val = PHY_CON1_RESET_VAL;
179 val &= ~(CTRL_GATEDURADJ_MASK);
180 writel(val, &phy0_ctrl->phy_con1);
181 writel(val, &phy1_ctrl->phy_con1);
182
183 writel(CTRL_RDLVL_GATE_ENABLE, &dmc->rdlvl_config);
184 i = TIMEOUT_US;
185 while ((readl(&dmc->phystatus) &
186 (RDLVL_COMPLETE_CHO | RDLVL_COMPLETE_CH1)) !=
187 (RDLVL_COMPLETE_CHO | RDLVL_COMPLETE_CH1) && i > 0) {
188
189
190
191
192 sdelay(100);
193 i--;
194 }
195 if (!i)
196 return SETUP_ERR_RDLV_COMPLETE_TIMEOUT;
197 writel(CTRL_RDLVL_GATE_DISABLE, &dmc->rdlvl_config);
198
199 writel(0, &phy0_ctrl->phy_con14);
200 writel(0, &phy1_ctrl->phy_con14);
201
202 val = (mem->ctrl_start_point <<
203 PHY_CON12_CTRL_START_POINT_SHIFT) |
204 (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
205 (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
206 (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
207 (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
208 (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
209 writel(val, &phy0_ctrl->phy_con12);
210 writel(val, &phy1_ctrl->phy_con12);
211
212 update_reset_dll(&dmc->phycontrol0, DDR_MODE_DDR3);
213 }
214
215
216 dmc_config_prech(mem, &dmc->directcmd);
217
218 writel(mem->memcontrol, &dmc->memcontrol);
219
220
221 writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
222 | (mem->aref_en << CONCONTROL_AREF_EN_SHIFT), &dmc->concontrol);
223 return 0;
224}
225#endif
226
227#ifdef CONFIG_EXYNOS5420
228
229
230
231
232
233
234
235
236
237
238
239
240const unsigned int test_addr = CONFIG_SYS_SDRAM_BASE;
241
242
243static const unsigned int test_pattern[] = {
244 0x5a5a5a5a,
245 0xa5a5a5a5,
246 0xf0f0f0f0,
247 0x0f0f0f0f,
248};
249
250
251
252
253
254
255
256
257
258
259static bool dmc_valid_window_test_vector(int ch, int byte_lane)
260{
261 unsigned int read_data;
262 unsigned int mask;
263 int i;
264
265 mask = 0xFF << (8 * byte_lane);
266
267 for (i = 0; i < ARRAY_SIZE(test_pattern); i++) {
268 read_data = readl(test_addr + i * 4 + ch * 0x80);
269 if ((read_data & mask) != (test_pattern[i] & mask))
270 return false;
271 }
272
273 return true;
274}
275
276
277
278
279
280
281static unsigned int dmc_get_read_offset_value(struct exynos5420_phy_control
282 *phy_ctrl)
283{
284 return readl(&phy_ctrl->phy_con4);
285}
286
287
288
289
290
291
292static void ddr_phy_set_do_resync(struct exynos5420_phy_control *phy_ctrl)
293{
294 setbits_le32(&phy_ctrl->phy_con10, PHY_CON10_CTRL_OFFSETR3);
295 clrbits_le32(&phy_ctrl->phy_con10, PHY_CON10_CTRL_OFFSETR3);
296}
297
298
299
300
301
302
303
304
305
306static void dmc_set_read_offset_value(struct exynos5420_phy_control *phy_ctrl,
307 unsigned int offset)
308{
309 writel(offset, &phy_ctrl->phy_con4);
310 ddr_phy_set_do_resync(phy_ctrl);
311}
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330unsigned char make_signed_byte(signed char b)
331{
332 if (b < 0)
333 return 0x80 | -b;
334 else
335 return b;
336}
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352void test_shifts(struct exynos5420_phy_control *phy_ctrl, int ch,
353 int start, int end, int results[NUM_BYTE_LANES])
354{
355 int incr = (start < end) ? 1 : -1;
356 int byte_lane;
357
358 for (byte_lane = 0; byte_lane < NUM_BYTE_LANES; byte_lane++) {
359 int shift;
360
361 dmc_set_read_offset_value(phy_ctrl, DEFAULT_DQS_X4);
362 results[byte_lane] = DEFAULT_DQS;
363
364 for (shift = start; shift != (end + incr); shift += incr) {
365 unsigned int byte_offsetr;
366 unsigned int offsetr;
367
368 byte_offsetr = make_signed_byte(shift);
369
370 offsetr = dmc_get_read_offset_value(phy_ctrl);
371 offsetr &= ~(0xFF << (8 * byte_lane));
372 offsetr |= (byte_offsetr << (8 * byte_lane));
373 dmc_set_read_offset_value(phy_ctrl, offsetr);
374
375 if (dmc_valid_window_test_vector(ch, byte_lane)) {
376 results[byte_lane] = shift;
377 break;
378 }
379 }
380 }
381}
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403static void software_find_read_offset(struct exynos5420_phy_control *phy_ctrl,
404 int ch, unsigned int coarse_lock_val)
405{
406 unsigned int offsetr_cent;
407 int byte_lane;
408 int left_limit;
409 int right_limit;
410 int left[NUM_BYTE_LANES];
411 int right[NUM_BYTE_LANES];
412 int i;
413
414
415 for (i = 0; i < ARRAY_SIZE(test_pattern); i++)
416 writel(test_pattern[i], test_addr + i * 4 + ch * 0x80);
417
418
419 left_limit = DEFAULT_DQS - coarse_lock_val;
420 right_limit = DEFAULT_DQS + coarse_lock_val;
421 if (right_limit > 127)
422 right_limit = 127;
423
424
425 test_shifts(phy_ctrl, ch, left_limit, right_limit, left);
426 test_shifts(phy_ctrl, ch, right_limit, left_limit, right);
427
428
429 offsetr_cent = 0;
430 for (byte_lane = 0; byte_lane < NUM_BYTE_LANES; byte_lane++) {
431 int temp_center;
432 unsigned int vmwc;
433
434 temp_center = (left[byte_lane] + right[byte_lane]) / 2;
435 vmwc = make_signed_byte(temp_center);
436 offsetr_cent |= vmwc << (8 * byte_lane);
437 }
438 dmc_set_read_offset_value(phy_ctrl, offsetr_cent);
439}
440
441int ddr3_mem_ctrl_init(struct mem_timings *mem, int reset)
442{
443 struct exynos5420_clock *clk =
444 (struct exynos5420_clock *)samsung_get_base_clock();
445 struct exynos5420_power *power =
446 (struct exynos5420_power *)samsung_get_base_power();
447 struct exynos5420_phy_control *phy0_ctrl, *phy1_ctrl;
448 struct exynos5420_dmc *drex0, *drex1;
449 struct exynos5420_tzasc *tzasc0, *tzasc1;
450 struct exynos5_power *pmu;
451 uint32_t val, n_lock_r, n_lock_w_phy0, n_lock_w_phy1;
452 uint32_t lock0_info, lock1_info;
453 int chip;
454 int i;
455
456 phy0_ctrl = (struct exynos5420_phy_control *)samsung_get_base_dmc_phy();
457 phy1_ctrl = (struct exynos5420_phy_control *)(samsung_get_base_dmc_phy()
458 + DMC_OFFSET);
459 drex0 = (struct exynos5420_dmc *)samsung_get_base_dmc_ctrl();
460 drex1 = (struct exynos5420_dmc *)(samsung_get_base_dmc_ctrl()
461 + DMC_OFFSET);
462 tzasc0 = (struct exynos5420_tzasc *)samsung_get_base_dmc_tzasc();
463 tzasc1 = (struct exynos5420_tzasc *)(samsung_get_base_dmc_tzasc()
464 + DMC_OFFSET);
465 pmu = (struct exynos5_power *)EXYNOS5420_POWER_BASE;
466
467 if (CONFIG_NR_DRAM_BANKS > 4) {
468
469 mem->memcontrol |= DMC_MEMCONTROL_NUM_CHIP_2;
470 mem->chips_per_channel = 2;
471 mem->chips_to_configure = 2;
472 } else {
473
474 mem->memcontrol |= DMC_MEMCONTROL_NUM_CHIP_1;
475 }
476
477
478 setbits_le32(&clk->pause, ENABLE_BIT);
479
480
481 setbits_le32(&clk->bpll_con1, BYPASS_EN);
482
483 writel(MUX_BPLL_SEL_FOUTBPLL, &clk->src_cdrex);
484 do {
485 val = readl(&clk->mux_stat_cdrex);
486 val &= BPLL_SEL_MASK;
487 } while (val != FOUTBPLL);
488
489 clrbits_le32(&clk->bpll_con1, BYPASS_EN);
490
491
492 val = readl(&phy0_ctrl->phy_con0);
493 val &= ~(PHY_CON0_CTRL_DDR_MODE_MASK << PHY_CON0_CTRL_DDR_MODE_SHIFT);
494 val |= (DDR_MODE_DDR3 << PHY_CON0_CTRL_DDR_MODE_SHIFT);
495 writel(val, &phy0_ctrl->phy_con0);
496
497 val = readl(&phy1_ctrl->phy_con0);
498 val &= ~(PHY_CON0_CTRL_DDR_MODE_MASK << PHY_CON0_CTRL_DDR_MODE_SHIFT);
499 val |= (DDR_MODE_DDR3 << PHY_CON0_CTRL_DDR_MODE_SHIFT);
500 writel(val, &phy1_ctrl->phy_con0);
501
502
503 val = (mem->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
504 (mem->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
505 writel(val, &phy0_ctrl->phy_con42);
506 writel(val, &phy1_ctrl->phy_con42);
507
508 val = readl(&phy0_ctrl->phy_con26);
509 val &= ~(T_WRDATA_EN_MASK << T_WRDATA_EN_OFFSET);
510 val |= (T_WRDATA_EN_DDR3 << T_WRDATA_EN_OFFSET);
511 writel(val, &phy0_ctrl->phy_con26);
512
513 val = readl(&phy1_ctrl->phy_con26);
514 val &= ~(T_WRDATA_EN_MASK << T_WRDATA_EN_OFFSET);
515 val |= (T_WRDATA_EN_DDR3 << T_WRDATA_EN_OFFSET);
516 writel(val, &phy1_ctrl->phy_con26);
517
518
519
520
521
522 val = (0x7 << CA_CK_DRVR_DS_OFFSET) | (0x7 << CA_CKE_DRVR_DS_OFFSET) |
523 (0x7 << CA_CS_DRVR_DS_OFFSET) | (0x7 << CA_ADR_DRVR_DS_OFFSET);
524 val |= (0x7 << DA_3_DS_OFFSET) | (0x7 << DA_2_DS_OFFSET) |
525 (0x7 << DA_1_DS_OFFSET) | (0x7 << DA_0_DS_OFFSET);
526 writel(val, &phy0_ctrl->phy_con39);
527 writel(val, &phy1_ctrl->phy_con39);
528
529
530 if (dmc_config_zq(mem, &phy0_ctrl->phy_con16, &phy1_ctrl->phy_con16,
531 &phy0_ctrl->phy_con17, &phy1_ctrl->phy_con17))
532 return SETUP_ERR_ZQ_CALIBRATION_FAILURE;
533
534 clrbits_le32(&phy0_ctrl->phy_con16, ZQ_CLK_DIV_EN);
535 clrbits_le32(&phy1_ctrl->phy_con16, ZQ_CLK_DIV_EN);
536
537
538 val = readl(&phy0_ctrl->phy_con14);
539 val |= mem->phy0_pulld_dqs;
540 writel(val, &phy0_ctrl->phy_con14);
541 val = readl(&phy1_ctrl->phy_con14);
542 val |= mem->phy1_pulld_dqs;
543 writel(val, &phy1_ctrl->phy_con14);
544
545 val = MEM_TERM_EN | PHY_TERM_EN;
546 writel(val, &drex0->phycontrol0);
547 writel(val, &drex1->phycontrol0);
548
549 writel(mem->concontrol |
550 (mem->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT) |
551 (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
552 &drex0->concontrol);
553 writel(mem->concontrol |
554 (mem->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT) |
555 (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
556 &drex1->concontrol);
557
558 do {
559 val = readl(&drex0->phystatus);
560 } while ((val & DFI_INIT_COMPLETE) != DFI_INIT_COMPLETE);
561 do {
562 val = readl(&drex1->phystatus);
563 } while ((val & DFI_INIT_COMPLETE) != DFI_INIT_COMPLETE);
564
565 clrbits_le32(&drex0->concontrol, DFI_INIT_START);
566 clrbits_le32(&drex1->concontrol, DFI_INIT_START);
567
568 update_reset_dll(&drex0->phycontrol0, DDR_MODE_DDR3);
569 update_reset_dll(&drex1->phycontrol0, DDR_MODE_DDR3);
570
571
572
573
574
575
576
577 val = DMC_MEMBASECONFIGX_CHIP_BASE(DMC_CHIP_BASE_0) |
578 DMC_MEMBASECONFIGX_CHIP_MASK(DMC_CHIP_MASK);
579 writel(val, &tzasc0->membaseconfig0);
580 writel(val, &tzasc1->membaseconfig0);
581
582
583 val = DMC_MEMBASECONFIGX_CHIP_BASE(DMC_CHIP_BASE_1) |
584 DMC_MEMBASECONFIGX_CHIP_MASK(DMC_CHIP_MASK);
585 writel(val, &tzasc0->membaseconfig1);
586 writel(val, &tzasc1->membaseconfig1);
587
588
589
590
591
592
593 writel(mem->memconfig, &tzasc0->memconfig0);
594 writel(mem->memconfig, &tzasc1->memconfig0);
595 writel(mem->memconfig, &tzasc0->memconfig1);
596 writel(mem->memconfig, &tzasc1->memconfig1);
597
598
599 writel(mem->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
600 &drex0->prechconfig0);
601 writel(mem->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
602 &drex1->prechconfig0);
603
604
605
606
607
608 writel(mem->timing_ref, &drex0->timingref);
609 writel(mem->timing_ref, &drex1->timingref);
610 writel(mem->timing_row, &drex0->timingrow0);
611 writel(mem->timing_row, &drex1->timingrow0);
612 writel(mem->timing_data, &drex0->timingdata0);
613 writel(mem->timing_data, &drex1->timingdata0);
614 writel(mem->timing_power, &drex0->timingpower0);
615 writel(mem->timing_power, &drex1->timingpower0);
616
617 if (reset) {
618
619
620
621
622
623
624 dmc_config_mrs(mem, &drex0->directcmd);
625 dmc_config_mrs(mem, &drex1->directcmd);
626 }
627
628
629
630
631
632
633
634
635
636
637
638 val = readl(&clk->gate_bus_cdrex);
639 while (true) {
640 writel(val & ~0x1, &clk->gate_bus_cdrex);
641 lock0_info = readl(&phy0_ctrl->phy_con13);
642 writel(val, &clk->gate_bus_cdrex);
643
644 if ((lock0_info & CTRL_FINE_LOCKED) == CTRL_FINE_LOCKED)
645 break;
646
647 sdelay(10);
648 }
649 while (true) {
650 writel(val & ~0x2, &clk->gate_bus_cdrex);
651 lock1_info = readl(&phy1_ctrl->phy_con13);
652 writel(val, &clk->gate_bus_cdrex);
653
654 if ((lock1_info & CTRL_FINE_LOCKED) == CTRL_FINE_LOCKED)
655 break;
656
657 sdelay(10);
658 }
659
660 if (!reset) {
661
662
663
664
665
666
667
668
669 writel(PAD_RETENTION_DRAM_COREBLK_VAL,
670 &power->pad_retention_dram_coreblk_option);
671 do {
672 val = readl(&power->pad_retention_dram_status);
673 } while (val != 0x1);
674
675
676
677
678
679 for (i = 0; i < 128; i++) {
680 for (chip = 0; chip < mem->chips_to_configure; chip++) {
681 writel(DIRECT_CMD_REFA |
682 (chip << DIRECT_CMD_CHIP_SHIFT),
683 &drex0->directcmd);
684 writel(DIRECT_CMD_REFA |
685 (chip << DIRECT_CMD_CHIP_SHIFT),
686 &drex1->directcmd);
687 }
688 }
689 }
690
691 if (mem->gate_leveling_enable) {
692 writel(PHY_CON0_RESET_VAL, &phy0_ctrl->phy_con0);
693 writel(PHY_CON0_RESET_VAL, &phy1_ctrl->phy_con0);
694
695 setbits_le32(&phy0_ctrl->phy_con0, P0_CMD_EN);
696 setbits_le32(&phy1_ctrl->phy_con0, P0_CMD_EN);
697
698 val = PHY_CON2_RESET_VAL;
699 val |= INIT_DESKEW_EN;
700 writel(val, &phy0_ctrl->phy_con2);
701 writel(val, &phy1_ctrl->phy_con2);
702
703 val = readl(&phy0_ctrl->phy_con1);
704 val |= (RDLVL_PASS_ADJ_VAL << RDLVL_PASS_ADJ_OFFSET);
705 writel(val, &phy0_ctrl->phy_con1);
706
707 val = readl(&phy1_ctrl->phy_con1);
708 val |= (RDLVL_PASS_ADJ_VAL << RDLVL_PASS_ADJ_OFFSET);
709 writel(val, &phy1_ctrl->phy_con1);
710
711 n_lock_w_phy0 = (lock0_info & CTRL_LOCK_COARSE_MASK) >> 2;
712 n_lock_r = readl(&phy0_ctrl->phy_con12);
713 n_lock_r &= ~CTRL_DLL_ON;
714 n_lock_r |= n_lock_w_phy0;
715 writel(n_lock_r, &phy0_ctrl->phy_con12);
716
717 n_lock_w_phy1 = (lock1_info & CTRL_LOCK_COARSE_MASK) >> 2;
718 n_lock_r = readl(&phy1_ctrl->phy_con12);
719 n_lock_r &= ~CTRL_DLL_ON;
720 n_lock_r |= n_lock_w_phy1;
721 writel(n_lock_r, &phy1_ctrl->phy_con12);
722
723 val = (0x3 << DIRECT_CMD_BANK_SHIFT) | 0x4;
724 for (chip = 0; chip < mem->chips_to_configure; chip++) {
725 writel(val | (chip << DIRECT_CMD_CHIP_SHIFT),
726 &drex0->directcmd);
727 writel(val | (chip << DIRECT_CMD_CHIP_SHIFT),
728 &drex1->directcmd);
729 }
730
731 setbits_le32(&phy0_ctrl->phy_con2, RDLVL_GATE_EN);
732 setbits_le32(&phy1_ctrl->phy_con2, RDLVL_GATE_EN);
733
734 setbits_le32(&phy0_ctrl->phy_con0, CTRL_SHGATE);
735 setbits_le32(&phy1_ctrl->phy_con0, CTRL_SHGATE);
736
737 val = readl(&phy0_ctrl->phy_con1);
738 val &= ~(CTRL_GATEDURADJ_MASK);
739 writel(val, &phy0_ctrl->phy_con1);
740
741 val = readl(&phy1_ctrl->phy_con1);
742 val &= ~(CTRL_GATEDURADJ_MASK);
743 writel(val, &phy1_ctrl->phy_con1);
744
745 writel(CTRL_RDLVL_GATE_ENABLE, &drex0->rdlvl_config);
746 i = TIMEOUT_US;
747 while (((readl(&drex0->phystatus) & RDLVL_COMPLETE_CHO) !=
748 RDLVL_COMPLETE_CHO) && (i > 0)) {
749
750
751
752
753 sdelay(100);
754 i--;
755 }
756 if (!i)
757 return SETUP_ERR_RDLV_COMPLETE_TIMEOUT;
758 writel(CTRL_RDLVL_GATE_DISABLE, &drex0->rdlvl_config);
759
760 writel(CTRL_RDLVL_GATE_ENABLE, &drex1->rdlvl_config);
761 i = TIMEOUT_US;
762 while (((readl(&drex1->phystatus) & RDLVL_COMPLETE_CHO) !=
763 RDLVL_COMPLETE_CHO) && (i > 0)) {
764
765
766
767
768 sdelay(100);
769 i--;
770 }
771 if (!i)
772 return SETUP_ERR_RDLV_COMPLETE_TIMEOUT;
773 writel(CTRL_RDLVL_GATE_DISABLE, &drex1->rdlvl_config);
774
775 writel(0, &phy0_ctrl->phy_con14);
776 writel(0, &phy1_ctrl->phy_con14);
777
778 val = (0x3 << DIRECT_CMD_BANK_SHIFT);
779 for (chip = 0; chip < mem->chips_to_configure; chip++) {
780 writel(val | (chip << DIRECT_CMD_CHIP_SHIFT),
781 &drex0->directcmd);
782 writel(val | (chip << DIRECT_CMD_CHIP_SHIFT),
783 &drex1->directcmd);
784 }
785
786
787 val = PHY_CON12_RESET_VAL;
788 writel((val + n_lock_w_phy0), &phy0_ctrl->phy_con12);
789 writel((val + n_lock_w_phy1), &phy1_ctrl->phy_con12);
790
791 setbits_le32(&phy0_ctrl->phy_con2, DLL_DESKEW_EN);
792 setbits_le32(&phy1_ctrl->phy_con2, DLL_DESKEW_EN);
793 }
794
795
796
797
798
799
800
801
802 if (!reset) {
803
804 dmc_set_read_offset_value(phy0_ctrl, readl(&pmu->pmu_spare1));
805 dmc_set_read_offset_value(phy1_ctrl, readl(&pmu->pmu_spare2));
806 } else {
807 software_find_read_offset(phy0_ctrl, 0,
808 CTRL_LOCK_COARSE(lock0_info));
809 software_find_read_offset(phy1_ctrl, 1,
810 CTRL_LOCK_COARSE(lock1_info));
811
812 writel(dmc_get_read_offset_value(phy0_ctrl), &pmu->pmu_spare1);
813 writel(dmc_get_read_offset_value(phy1_ctrl), &pmu->pmu_spare2);
814 }
815
816
817 dmc_config_prech(mem, &drex0->directcmd);
818 dmc_config_prech(mem, &drex1->directcmd);
819
820 writel(mem->memcontrol, &drex0->memcontrol);
821 writel(mem->memcontrol, &drex1->memcontrol);
822
823
824
825
826
827
828 writel(mem->concontrol | (mem->aref_en << CONCONTROL_AREF_EN_SHIFT) |
829 (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)|
830 DMC_CONCONTROL_IO_PD_CON(0x2),
831 &drex0->concontrol);
832 writel(mem->concontrol | (mem->aref_en << CONCONTROL_AREF_EN_SHIFT) |
833 (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)|
834 DMC_CONCONTROL_IO_PD_CON(0x2),
835 &drex1->concontrol);
836
837
838
839
840
841
842 setbits_le32(&drex0->cgcontrol, DMC_INTERNAL_CG);
843 setbits_le32(&drex1->cgcontrol, DMC_INTERNAL_CG);
844
845
846
847
848
849
850
851
852
853
854
855
856
857 val = readl(&drex0->concontrol);
858 val |= CONCONTROL_UPDATE_MODE;
859 writel(val, &drex0->concontrol);
860 val = readl(&drex1->concontrol);
861 val |= CONCONTROL_UPDATE_MODE;
862 writel(val, &drex1->concontrol);
863
864 return 0;
865}
866#endif
867