summaryrefslogtreecommitdiff
path: root/drivers/ddr/mvebu/ddr3_init.c
blob: 11b85916b72836cf47be922b4995f9adca23a91c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
/*
 * Copyright (C) Marvell International Ltd. and its affiliates
 *
 * SPDX-License-Identifier:	GPL-2.0
 */

#include <common.h>
#include <i2c.h>
#include <spl.h>
#include <asm/io.h>
#include <asm/arch/cpu.h>
#include <asm/arch/soc.h>

#include "ddr3_init.h"

#if defined(MV88F78X60)
#include "ddr3_axp_vars.h"
#elif defined(MV88F67XX)
#include "ddr3_a370_vars.h"
#elif defined(MV88F672X)
#include "ddr3_a375_vars.h"
#endif

#ifdef STATIC_TRAINING
static void ddr3_static_training_init(void);
#endif
#ifdef DUNIT_STATIC
static void ddr3_static_mc_init(void);
#endif
#if defined(DUNIT_STATIC) || defined(STATIC_TRAINING)
MV_DRAM_MODES *ddr3_get_static_ddr_mode(void);
#endif
#if defined(MV88F672X)
void get_target_freq(u32 freq_mode, u32 *ddr_freq, u32 *hclk_ps);
#endif
u32 mv_board_id_get(void);
extern void ddr3_set_sw_wl_rl_debug(u32);
extern void ddr3_set_pbs(u32);
extern void ddr3_set_log_level(u32 val);

static u32 log_level = DDR3_LOG_LEVEL;

static u32 ddr3_init_main(void);

/*
 * Name:     ddr3_set_log_level
 * Desc:     This routine initialize the log_level acording to nLogLevel
 *           which getting from user
 * Args:     nLogLevel
 * Notes:
 * Returns:  None.
 */
void ddr3_set_log_level(u32 val)
{
	log_level = val;
}

/*
 * Name:     ddr3_get_log_level
 * Desc:     This routine returns the log level
 * Args:     none
 * Notes:
 * Returns:  log level.
 */
u32 ddr3_get_log_level(void)
{
	return log_level;
}

static void debug_print_reg(u32 reg)
{
	printf("0x%08x = 0x%08x\n", reg, reg_read(reg));
}

static void print_dunit_setup(void)
{
	puts("\n########### LOG LEVEL 1 (D-UNIT SETUP)###########\n");

#ifdef DUNIT_STATIC
	puts("\nStatic D-UNIT Setup:\n");
#endif
#ifdef DUNIT_SPD
	puts("\nDynamic(using SPD) D-UNIT Setup:\n");
#endif
	debug_print_reg(REG_SDRAM_CONFIG_ADDR);
	debug_print_reg(REG_DUNIT_CTRL_LOW_ADDR);
	debug_print_reg(REG_SDRAM_TIMING_LOW_ADDR);
	debug_print_reg(REG_SDRAM_TIMING_HIGH_ADDR);
	debug_print_reg(REG_SDRAM_ADDRESS_CTRL_ADDR);
	debug_print_reg(REG_SDRAM_OPEN_PAGES_ADDR);
	debug_print_reg(REG_SDRAM_OPERATION_ADDR);
	debug_print_reg(REG_SDRAM_MODE_ADDR);
	debug_print_reg(REG_SDRAM_EXT_MODE_ADDR);
	debug_print_reg(REG_DDR_CONT_HIGH_ADDR);
	debug_print_reg(REG_ODT_TIME_LOW_ADDR);
	debug_print_reg(REG_SDRAM_ERROR_ADDR);
	debug_print_reg(REG_SDRAM_AUTO_PWR_SAVE_ADDR);
	debug_print_reg(REG_OUDDR3_TIMING_ADDR);
	debug_print_reg(REG_ODT_TIME_HIGH_ADDR);
	debug_print_reg(REG_SDRAM_ODT_CTRL_LOW_ADDR);
	debug_print_reg(REG_SDRAM_ODT_CTRL_HIGH_ADDR);
	debug_print_reg(REG_DUNIT_ODT_CTRL_ADDR);
#ifndef MV88F67XX
	debug_print_reg(REG_DRAM_FIFO_CTRL_ADDR);
	debug_print_reg(REG_DRAM_AXI_CTRL_ADDR);
	debug_print_reg(REG_DRAM_ADDR_CTRL_DRIVE_STRENGTH_ADDR);
	debug_print_reg(REG_DRAM_DATA_DQS_DRIVE_STRENGTH_ADDR);
	debug_print_reg(REG_DRAM_VER_CAL_MACHINE_CTRL_ADDR);
	debug_print_reg(REG_DRAM_MAIN_PADS_CAL_ADDR);
	debug_print_reg(REG_DRAM_HOR_CAL_MACHINE_CTRL_ADDR);
	debug_print_reg(REG_CS_SIZE_SCRATCH_ADDR);
	debug_print_reg(REG_DYNAMIC_POWER_SAVE_ADDR);
	debug_print_reg(REG_READ_DATA_SAMPLE_DELAYS_ADDR);
	debug_print_reg(REG_READ_DATA_READY_DELAYS_ADDR);
	debug_print_reg(REG_DDR3_MR0_ADDR);
	debug_print_reg(REG_DDR3_MR1_ADDR);
	debug_print_reg(REG_DDR3_MR2_ADDR);
	debug_print_reg(REG_DDR3_MR3_ADDR);
	debug_print_reg(REG_DDR3_RANK_CTRL_ADDR);
	debug_print_reg(REG_DRAM_PHY_CONFIG_ADDR);
	debug_print_reg(REG_STATIC_DRAM_DLB_CONTROL);
	debug_print_reg(DLB_BUS_OPTIMIZATION_WEIGHTS_REG);
	debug_print_reg(DLB_AGING_REGISTER);
	debug_print_reg(DLB_EVICTION_CONTROL_REG);
	debug_print_reg(DLB_EVICTION_TIMERS_REGISTER_REG);
#if defined(MV88F672X)
	debug_print_reg(REG_FASTPATH_WIN_CTRL_ADDR(0));
	debug_print_reg(REG_FASTPATH_WIN_BASE_ADDR(0));
	debug_print_reg(REG_FASTPATH_WIN_CTRL_ADDR(1));
	debug_print_reg(REG_FASTPATH_WIN_BASE_ADDR(1));
#else
	debug_print_reg(REG_FASTPATH_WIN_0_CTRL_ADDR);
#endif
	debug_print_reg(REG_CDI_CONFIG_ADDR);
#endif
}

#if !defined(STATIC_TRAINING)
static void ddr3_restore_and_set_final_windows(u32 *win_backup)
{
	u32 ui, reg, cs;
	u32 win_ctrl_reg, num_of_win_regs;
	u32 cs_ena = ddr3_get_cs_ena_from_reg();

#if defined(MV88F672X)
	if (DDR3_FAST_PATH_EN == 0)
		return;
#endif

#if defined(MV88F672X)
	win_ctrl_reg = REG_XBAR_WIN_16_CTRL_ADDR;
	num_of_win_regs = 8;
#else
	win_ctrl_reg = REG_XBAR_WIN_4_CTRL_ADDR;
	num_of_win_regs = 16;
#endif

	/* Return XBAR windows 4-7 or 16-19 init configuration */
	for (ui = 0; ui < num_of_win_regs; ui++)
		reg_write((win_ctrl_reg + 0x4 * ui), win_backup[ui]);

	DEBUG_INIT_FULL_S("DDR3 Training Sequence - Switching XBAR Window to FastPath Window\n");

#if defined(MV88F672X)
	/* Set L2 filtering to 1G */
	reg_write(0x8c04, 0x40000000);

	/* Open fast path windows */
	for (cs = 0; cs < MAX_CS; cs++) {
		if (cs_ena & (1 << cs)) {
			/* set fast path window control for the cs */
			reg = 0x1FFFFFE1;
			reg |= (cs << 2);
			reg |= (SDRAM_CS_SIZE & 0xFFFF0000);
			/* Open fast path Window */
			reg_write(REG_FASTPATH_WIN_CTRL_ADDR(cs), reg);
			/* set fast path window base address for the cs */
			reg = (((SDRAM_CS_SIZE + 1) * cs) & 0xFFFF0000);
			/* Set base address */
			reg_write(REG_FASTPATH_WIN_BASE_ADDR(cs), reg);
		}
	}
#else
	reg = 0x1FFFFFE1;
	for (cs = 0; cs < MAX_CS; cs++) {
		if (cs_ena & (1 << cs)) {
			reg |= (cs << 2);
			break;
		}
	}

	/* Open fast path Window to - 0.5G */
	reg_write(REG_FASTPATH_WIN_0_CTRL_ADDR, reg);
#endif
}

static void ddr3_save_and_set_training_windows(u32 *win_backup)
{
	u32 cs_ena = ddr3_get_cs_ena_from_reg();
	u32 reg, tmp_count, cs, ui;
	u32 win_ctrl_reg, win_base_reg, win_remap_reg;
	u32 num_of_win_regs, win_jump_index;

#if defined(MV88F672X)
	/* Disable L2 filtering */
	reg_write(0x8c04, 0);

	win_ctrl_reg = REG_XBAR_WIN_16_CTRL_ADDR;
	win_base_reg = REG_XBAR_WIN_16_BASE_ADDR;
	win_remap_reg = REG_XBAR_WIN_16_REMAP_ADDR;
	win_jump_index = 0x8;
	num_of_win_regs = 8;
#else
	win_ctrl_reg = REG_XBAR_WIN_4_CTRL_ADDR;
	win_base_reg = REG_XBAR_WIN_4_BASE_ADDR;
	win_remap_reg = REG_XBAR_WIN_4_REMAP_ADDR;
	win_jump_index = 0x10;
	num_of_win_regs = 16;
#endif

	/* Close XBAR Window 19 - Not needed */
	/* {0x000200e8}  -   Open Mbus Window - 2G */
	reg_write(REG_XBAR_WIN_19_CTRL_ADDR, 0);

	/* Save XBAR Windows 4-19 init configurations */
	for (ui = 0; ui < num_of_win_regs; ui++)
		win_backup[ui] = reg_read(win_ctrl_reg + 0x4 * ui);

	/* Open XBAR Windows 4-7 or 16-19 for other CS */
	reg = 0;
	tmp_count = 0;
	for (cs = 0; cs < MAX_CS; cs++) {
		if (cs_ena & (1 << cs)) {
			switch (cs) {
			case 0:
				reg = 0x0E00;
				break;
			case 1:
				reg = 0x0D00;
				break;
			case 2:
				reg = 0x0B00;
				break;
			case 3:
				reg = 0x0700;
				break;
			}
			reg |= (1 << 0);
			reg |= (SDRAM_CS_SIZE & 0xFFFF0000);

			reg_write(win_ctrl_reg + win_jump_index * tmp_count,
				  reg);
			reg = ((SDRAM_CS_SIZE + 1) * (tmp_count)) & 0xFFFF0000;
			reg_write(win_base_reg + win_jump_index * tmp_count,
				  reg);

			if (win_remap_reg <= REG_XBAR_WIN_7_REMAP_ADDR) {
				reg_write(win_remap_reg +
					  win_jump_index * tmp_count, 0);
			}

			tmp_count++;
		}
	}
}
#endif /*  !defined(STATIC_TRAINING) */

/*
 * Name:     ddr3_init - Main DDR3 Init function
 * Desc:     This routine initialize the DDR3 MC and runs HW training.
 * Args:     None.
 * Notes:
 * Returns:  None.
 */
int ddr3_init(void)
{
	unsigned int status;

	ddr3_set_pbs(DDR3_PBS);
	ddr3_set_sw_wl_rl_debug(DDR3_RUN_SW_WHEN_HW_FAIL);

	status = ddr3_init_main();
	if (status == MV_DDR3_TRAINING_ERR_BAD_SAR)
		DEBUG_INIT_S("DDR3 Training Error: Bad sample at reset");
	if (status == MV_DDR3_TRAINING_ERR_BAD_DIMM_SETUP)
		DEBUG_INIT_S("DDR3 Training Error: Bad DIMM setup");
	if (status == MV_DDR3_TRAINING_ERR_MAX_CS_LIMIT)
		DEBUG_INIT_S("DDR3 Training Error: Max CS limit");
	if (status == MV_DDR3_TRAINING_ERR_MAX_ENA_CS_LIMIT)
		DEBUG_INIT_S("DDR3 Training Error: Max enable CS limit");
	if (status == MV_DDR3_TRAINING_ERR_BAD_R_DIMM_SETUP)
		DEBUG_INIT_S("DDR3 Training Error: Bad R-DIMM setup");
	if (status == MV_DDR3_TRAINING_ERR_TWSI_FAIL)
		DEBUG_INIT_S("DDR3 Training Error: TWSI failure");
	if (status == MV_DDR3_TRAINING_ERR_DIMM_TYPE_NO_MATCH)
		DEBUG_INIT_S("DDR3 Training Error: DIMM type no match");
	if (status == MV_DDR3_TRAINING_ERR_TWSI_BAD_TYPE)
		DEBUG_INIT_S("DDR3 Training Error: TWSI bad type");
	if (status == MV_DDR3_TRAINING_ERR_BUS_WIDTH_NOT_MATCH)
		DEBUG_INIT_S("DDR3 Training Error: bus width no match");
	if (status > MV_DDR3_TRAINING_ERR_HW_FAIL_BASE)
		DEBUG_INIT_C("DDR3 Training Error: HW Failure 0x", status, 8);

	return status;
}

static void print_ddr_target_freq(u32 cpu_freq, u32 fab_opt)
{
	puts("\nDDR3 Training Sequence - Run DDR3 at ");

	switch (cpu_freq) {
#if defined(MV88F672X)
	case 21:
		puts("533 Mhz\n");
		break;
#else
	case 1:
		puts("533 Mhz\n");
		break;
	case 2:
		if (fab_opt == 5)
			puts("600 Mhz\n");
		if (fab_opt == 9)
			puts("400 Mhz\n");
		break;
	case 3:
		puts("667 Mhz\n");
		break;
	case 4:
		if (fab_opt == 5)
			puts("750 Mhz\n");
		if (fab_opt == 9)
			puts("500 Mhz\n");
		break;
	case 0xa:
		puts("400 Mhz\n");
		break;
	case 0xb:
		if (fab_opt == 5)
			puts("800 Mhz\n");
		if (fab_opt == 9)
			puts("553 Mhz\n");
		if (fab_opt == 0xA)
			puts("640 Mhz\n");
		break;
#endif
	default:
		puts("NOT DEFINED FREQ\n");
	}
}

static u32 ddr3_init_main(void)
{
	u32 target_freq;
	u32 reg = 0;
	u32 cpu_freq, fab_opt, hclk_time_ps, soc_num;
	__maybe_unused u32 ecc = DRAM_ECC;
	__maybe_unused int dqs_clk_aligned = 0;
	__maybe_unused u32 scrub_offs, scrub_size;
	__maybe_unused u32 ddr_width = BUS_WIDTH;
	__maybe_unused int status;
	__maybe_unused u32 win_backup[16];

	/* SoC/Board special Initializtions */
	fab_opt = ddr3_get_fab_opt();

#ifdef CONFIG_SPD_EEPROM
	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
#endif

	ddr3_print_version();
	DEBUG_INIT_S("4\n");
	/* Lib version 5.5.4 */

	fab_opt = ddr3_get_fab_opt();

	/* Switching CPU to MRVL ID */
	soc_num = (reg_read(REG_SAMPLE_RESET_HIGH_ADDR) & SAR1_CPU_CORE_MASK) >>
		SAR1_CPU_CORE_OFFSET;
	switch (soc_num) {
	case 0x3:
		reg_bit_set(CPU_CONFIGURATION_REG(3), CPU_MRVL_ID_OFFSET);
		reg_bit_set(CPU_CONFIGURATION_REG(2), CPU_MRVL_ID_OFFSET);
	case 0x1:
		reg_bit_set(CPU_CONFIGURATION_REG(1), CPU_MRVL_ID_OFFSET);
	case 0x0:
		reg_bit_set(CPU_CONFIGURATION_REG(0), CPU_MRVL_ID_OFFSET);
	default:
		break;
	}

	/* Power down deskew PLL */
#if !defined(MV88F672X)
	/* 0x18780 [25] */
	reg = (reg_read(REG_DDRPHY_APLL_CTRL_ADDR) & ~(1 << 25));
	reg_write(REG_DDRPHY_APLL_CTRL_ADDR, reg);
#endif

	/*
	 * Stage 0 - Set board configuration
	 */
	cpu_freq = ddr3_get_cpu_freq();
	if (fab_opt > FAB_OPT)
		fab_opt = FAB_OPT - 1;

	if (ddr3_get_log_level() > 0)
		print_ddr_target_freq(cpu_freq, fab_opt);

#if defined(MV88F672X)
	get_target_freq(cpu_freq, &target_freq, &hclk_time_ps);
#else
	target_freq = cpu_ddr_ratios[fab_opt][cpu_freq];
	hclk_time_ps = cpu_fab_clk_to_hclk[fab_opt][cpu_freq];
#endif
	if ((target_freq == 0) || (hclk_time_ps == 0)) {
		DEBUG_INIT_S("DDR3 Training Sequence - FAILED - Wrong Sample at Reset Configurations\n");
		if (target_freq == 0) {
			DEBUG_INIT_C("target_freq", target_freq, 2);
			DEBUG_INIT_C("fab_opt", fab_opt, 2);
			DEBUG_INIT_C("cpu_freq", cpu_freq, 2);
		} else if (hclk_time_ps == 0) {
			DEBUG_INIT_C("hclk_time_ps", hclk_time_ps, 2);
			DEBUG_INIT_C("fab_opt", fab_opt, 2);
			DEBUG_INIT_C("cpu_freq", cpu_freq, 2);
		}

		return MV_DDR3_TRAINING_ERR_BAD_SAR;
	}

#if defined(ECC_SUPPORT)
	scrub_offs = U_BOOT_START_ADDR;
	scrub_size = U_BOOT_SCRUB_SIZE;
#else
	scrub_offs = 0;
	scrub_size = 0;
#endif

#if defined(ECC_SUPPORT) && defined(AUTO_DETECTION_SUPPORT)
	ecc = DRAM_ECC;
#endif

#if defined(ECC_SUPPORT) && defined(AUTO_DETECTION_SUPPORT)
	ecc = 0;
	if (ddr3_check_config(BUS_WIDTH_ECC_TWSI_ADDR, CONFIG_ECC))
		ecc = 1;
#endif

#ifdef DQS_CLK_ALIGNED
	dqs_clk_aligned = 1;
#endif

	/* Check if DRAM is already initialized  */
	if (reg_read(REG_BOOTROM_ROUTINE_ADDR) &
	    (1 << REG_BOOTROM_ROUTINE_DRAM_INIT_OFFS)) {
		DEBUG_INIT_S("DDR3 Training Sequence - 2nd boot - Skip\n");
		return MV_OK;
	}

	/*
	 * Stage 1 - Dunit Setup
	 */

#ifdef DUNIT_STATIC
	/*
	 * For Static D-Unit Setup use must set the correct static values
	 * at the ddr3_*soc*_vars.h file
	 */
	DEBUG_INIT_FULL_S("DDR3 Training Sequence - Static MC Init\n");
	ddr3_static_mc_init();

#ifdef ECC_SUPPORT
	ecc = DRAM_ECC;
	if (ecc) {
		reg = reg_read(REG_SDRAM_CONFIG_ADDR);
		reg |= (1 << REG_SDRAM_CONFIG_ECC_OFFS);
		reg_write(REG_SDRAM_CONFIG_ADDR, reg);
	}
#endif
#endif

#if defined(MV88F78X60) || defined(MV88F672X)
#if defined(AUTO_DETECTION_SUPPORT)
	/*
	 * Configurations for both static and dynamic MC setups
	 *
	 * Dynamically Set 32Bit and ECC for AXP (Relevant only for
	 * Marvell DB boards)
	 */
	if (ddr3_check_config(BUS_WIDTH_ECC_TWSI_ADDR, CONFIG_BUS_WIDTH)) {
		ddr_width = 32;
		DEBUG_INIT_S("DDR3 Training Sequence - DRAM bus width 32Bit\n");
	}
#endif

#if defined(MV88F672X)
	reg = reg_read(REG_SDRAM_CONFIG_ADDR);
	if ((reg >> 15) & 1)
		ddr_width = 32;
	else
		ddr_width = 16;
#endif
#endif

#ifdef DUNIT_SPD
	status = ddr3_dunit_setup(ecc, hclk_time_ps, &ddr_width);
	if (MV_OK != status) {
		DEBUG_INIT_S("DDR3 Training Sequence - FAILED (ddr3 Dunit Setup)\n");
		return status;
	}
#endif

	/* Fix read ready phases for all SOC in reg 0x15C8 */
	reg = reg_read(REG_TRAINING_DEBUG_3_ADDR);
	reg &= ~(REG_TRAINING_DEBUG_3_MASK);
	reg |= 0x4;		/* Phase 0 */
	reg &= ~(REG_TRAINING_DEBUG_3_MASK << REG_TRAINING_DEBUG_3_OFFS);
	reg |= (0x4 << (1 * REG_TRAINING_DEBUG_3_OFFS));	/* Phase 1 */
	reg &= ~(REG_TRAINING_DEBUG_3_MASK << (3 * REG_TRAINING_DEBUG_3_OFFS));
	reg |= (0x6 << (3 * REG_TRAINING_DEBUG_3_OFFS));	/* Phase 3 */
	reg &= ~(REG_TRAINING_DEBUG_3_MASK << (4 * REG_TRAINING_DEBUG_3_OFFS));
	reg |= (0x6 << (4 * REG_TRAINING_DEBUG_3_OFFS));
	reg &= ~(REG_TRAINING_DEBUG_3_MASK << (5 * REG_TRAINING_DEBUG_3_OFFS));
	reg |= (0x6 << (5 * REG_TRAINING_DEBUG_3_OFFS));
	reg_write(REG_TRAINING_DEBUG_3_ADDR, reg);

#if defined(MV88F672X)
	/*
	 * AxiBrespMode[8] = Compliant,
	 * AxiAddrDecodeCntrl[11] = Internal,
	 * AxiDataBusWidth[0] = 128bit
	 */
	/* 0x14A8 - AXI Control Register */
	reg_write(REG_DRAM_AXI_CTRL_ADDR, 0);
#else
	/* 0x14A8 - AXI Control Register */
	reg_write(REG_DRAM_AXI_CTRL_ADDR, 0x00000100);
	reg_write(REG_CDI_CONFIG_ADDR, 0x00000006);

	if ((ddr_width == 64) && (reg_read(REG_DDR_IO_ADDR) &
				  (1 << REG_DDR_IO_CLK_RATIO_OFFS))) {
		/* 0x14A8 - AXI Control Register */
		reg_write(REG_DRAM_AXI_CTRL_ADDR, 0x00000101);
		reg_write(REG_CDI_CONFIG_ADDR, 0x00000007);
	}
#endif

#if !defined(MV88F67XX)
	/*
	 * ARMADA-370 activate DLB later at the u-boot,
	 * Armada38x - No DLB activation at this time
	 */
	reg_write(DLB_BUS_OPTIMIZATION_WEIGHTS_REG, 0x18C01E);

#if defined(MV88F78X60)
	/* WA according to eratta GL-8672902*/
	if (mv_ctrl_rev_get() == MV_78XX0_B0_REV)
		reg_write(DLB_BUS_OPTIMIZATION_WEIGHTS_REG, 0xc19e);
#endif

	reg_write(DLB_AGING_REGISTER, 0x0f7f007f);
	reg_write(DLB_EVICTION_CONTROL_REG, 0x0);
	reg_write(DLB_EVICTION_TIMERS_REGISTER_REG, 0x00FF3C1F);

	reg_write(MBUS_UNITS_PRIORITY_CONTROL_REG, 0x55555555);
	reg_write(FABRIC_UNITS_PRIORITY_CONTROL_REG, 0xAA);
	reg_write(MBUS_UNITS_PREFETCH_CONTROL_REG, 0xffff);
	reg_write(FABRIC_UNITS_PREFETCH_CONTROL_REG, 0xf0f);

#if defined(MV88F78X60)
	/* WA according to eratta GL-8672902 */
	if (mv_ctrl_rev_get() == MV_78XX0_B0_REV) {
		reg = reg_read(REG_STATIC_DRAM_DLB_CONTROL);
		reg |= DLB_ENABLE;
		reg_write(REG_STATIC_DRAM_DLB_CONTROL, reg);
	}
#endif /* end defined(MV88F78X60) */
#endif /* end !defined(MV88F67XX) */

	if (ddr3_get_log_level() >= MV_LOG_LEVEL_1)
		print_dunit_setup();

	/*
	 * Stage 2 - Training Values Setup
	 */
#ifdef STATIC_TRAINING
	/*
	 * DRAM Init - After all the D-unit values are set, its time to init
	 * the D-unit
	 */
	/* Wait for '0' */
	reg_write(REG_SDRAM_INIT_CTRL_ADDR, 0x1);
	do {
		reg = (reg_read(REG_SDRAM_INIT_CTRL_ADDR)) &
			(1 << REG_SDRAM_INIT_CTRL_OFFS);
	} while (reg);

	/* ddr3 init using static parameters - HW training is disabled */
	DEBUG_INIT_FULL_S("DDR3 Training Sequence - Static Training Parameters\n");
	ddr3_static_training_init();

#if defined(MV88F78X60)
	/*
	 * If ECC is enabled, need to scrub the U-Boot area memory region -
	 * Run training function with Xor bypass just to scrub the memory
	 */
	status = ddr3_hw_training(target_freq, ddr_width,
				  1, scrub_offs, scrub_size,
				  dqs_clk_aligned, DDR3_TRAINING_DEBUG,
				  REG_DIMM_SKIP_WL);
	if (MV_OK != status) {
		DEBUG_INIT_FULL_S("DDR3 Training Sequence - FAILED\n");
		return status;
	}
#endif
#else
	/* Set X-BAR windows for the training sequence */
	ddr3_save_and_set_training_windows(win_backup);

	/* Run DDR3 Training Sequence */
	/* DRAM Init */
	reg_write(REG_SDRAM_INIT_CTRL_ADDR, 0x1);
	do {
		reg = (reg_read(REG_SDRAM_INIT_CTRL_ADDR)) &
			(1 << REG_SDRAM_INIT_CTRL_OFFS);
	} while (reg);		/* Wait for '0' */

	/* ddr3 init using DDR3 HW training procedure */
	DEBUG_INIT_FULL_S("DDR3 Training Sequence - HW Training Procedure\n");
	status = ddr3_hw_training(target_freq, ddr_width,
				  0, scrub_offs, scrub_size,
				  dqs_clk_aligned, DDR3_TRAINING_DEBUG,
				  REG_DIMM_SKIP_WL);
	if (MV_OK != status) {
		DEBUG_INIT_FULL_S("DDR3 Training Sequence - FAILED\n");
		return status;
	}
#endif

	/*
	 * Stage 3 - Finish
	 */
#if defined(MV88F78X60) || defined(MV88F672X)
	/* Disable ECC Ignore bit */
	reg = reg_read(REG_SDRAM_CONFIG_ADDR) &
		~(1 << REG_SDRAM_CONFIG_IERR_OFFS);
	reg_write(REG_SDRAM_CONFIG_ADDR, reg);
#endif

#if !defined(STATIC_TRAINING)
	/* Restore and set windows */
	ddr3_restore_and_set_final_windows(win_backup);
#endif

	/* Update DRAM init indication in bootROM register */
	reg = reg_read(REG_BOOTROM_ROUTINE_ADDR);
	reg_write(REG_BOOTROM_ROUTINE_ADDR,
		  reg | (1 << REG_BOOTROM_ROUTINE_DRAM_INIT_OFFS));

#if !defined(MV88F67XX)
#if defined(MV88F78X60)
	if (mv_ctrl_rev_get() == MV_78XX0_B0_REV) {
		reg = reg_read(REG_SDRAM_CONFIG_ADDR);
		if (ecc == 0)
			reg_write(REG_SDRAM_CONFIG_ADDR, reg | (1 << 19));
	}
#endif /* end defined(MV88F78X60) */

	reg_write(DLB_EVICTION_CONTROL_REG, 0x9);

	reg = reg_read(REG_STATIC_DRAM_DLB_CONTROL);
	reg |= (DLB_ENABLE | DLB_WRITE_COALESING | DLB_AXI_PREFETCH_EN |
		DLB_MBUS_PREFETCH_EN | PREFETCH_NLNSZTR);
	reg_write(REG_STATIC_DRAM_DLB_CONTROL, reg);
#endif /* end !defined(MV88F67XX) */

#ifdef STATIC_TRAINING
	DEBUG_INIT_S("DDR3 Training Sequence - Ended Successfully (S)\n");
#else
	DEBUG_INIT_S("DDR3 Training Sequence - Ended Successfully\n");
#endif

	return MV_OK;
}

/*
 * Name:     ddr3_get_cpu_freq
 * Desc:     read S@R and return CPU frequency
 * Args:
 * Notes:
 * Returns:  required value
 */

u32 ddr3_get_cpu_freq(void)
{
	u32 reg, cpu_freq;

#if defined(MV88F672X)
	/* Read sample at reset setting */
	reg = reg_read(REG_SAMPLE_RESET_HIGH_ADDR);	/* 0xE8200 */
	cpu_freq = (reg & REG_SAMPLE_RESET_CPU_FREQ_MASK) >>
		REG_SAMPLE_RESET_CPU_FREQ_OFFS;
#else
	/* Read sample at reset setting */
	reg = reg_read(REG_SAMPLE_RESET_LOW_ADDR);	/* 0x18230 [23:21] */
#if defined(MV88F78X60)
	cpu_freq = (reg & REG_SAMPLE_RESET_CPU_FREQ_MASK) >>
		REG_SAMPLE_RESET_CPU_FREQ_OFFS;
	reg = reg_read(REG_SAMPLE_RESET_HIGH_ADDR);	/* 0x18234 [20] */
	cpu_freq |= (((reg >> REG_SAMPLE_RESET_HIGH_CPU_FREQ_OFFS) & 0x1) << 3);
#elif defined(MV88F67XX)
	cpu_freq = (reg & REG_SAMPLE_RESET_CPU_FREQ_MASK) >>
		REG_SAMPLE_RESET_CPU_FREQ_OFFS;
#endif
#endif

	return cpu_freq;
}

/*
 * Name:     ddr3_get_fab_opt
 * Desc:     read S@R and return CPU frequency
 * Args:
 * Notes:
 * Returns:  required value
 */
u32 ddr3_get_fab_opt(void)
{
	__maybe_unused u32 reg, fab_opt;

#if defined(MV88F672X)
	return 0;		/* No fabric */
#else
	/* Read sample at reset setting */
	reg = reg_read(REG_SAMPLE_RESET_LOW_ADDR);
	fab_opt = (reg & REG_SAMPLE_RESET_FAB_MASK) >>
		REG_SAMPLE_RESET_FAB_OFFS;

#if defined(MV88F78X60)
	reg = reg_read(REG_SAMPLE_RESET_HIGH_ADDR);
	fab_opt |= (((reg >> 19) & 0x1) << 4);
#endif

	return fab_opt;
#endif
}

/*
 * Name:     ddr3_get_vco_freq
 * Desc:     read S@R and return VCO frequency
 * Args:
 * Notes:
 * Returns:  required value
 */
u32 ddr3_get_vco_freq(void)
{
	u32 fab, cpu_freq, ui_vco_freq;

	fab = ddr3_get_fab_opt();
	cpu_freq = ddr3_get_cpu_freq();

	if (fab == 2 || fab == 3 || fab == 7 || fab == 8 || fab == 10 ||
	    fab == 15 || fab == 17 || fab == 20)
		ui_vco_freq = cpu_freq + CLK_CPU;
	else
		ui_vco_freq = cpu_freq;

	return ui_vco_freq;
}

#ifdef STATIC_TRAINING
/*
 * Name:     ddr3_static_training_init - Init DDR3 Training with
 *           static parameters
 * Desc:     Use this routine to init the controller without the HW training
 *           procedure
 *           User must provide compatible header file with registers data.
 * Args:     None.
 * Notes:
 * Returns:  None.
 */
void ddr3_static_training_init(void)
{
	MV_DRAM_MODES *ddr_mode;
	u32 reg;
	int j;

	ddr_mode = ddr3_get_static_ddr_mode();

	j = 0;
	while (ddr_mode->vals[j].reg_addr != 0) {
		udelay(10);	/* haim want to delay each write */
		reg_write(ddr_mode->vals[j].reg_addr,
			  ddr_mode->vals[j].reg_value);

		if (ddr_mode->vals[j].reg_addr ==
		    REG_PHY_REGISTRY_FILE_ACCESS_ADDR)
			do {
				reg = reg_read(REG_PHY_REGISTRY_FILE_ACCESS_ADDR) &
					REG_PHY_REGISTRY_FILE_ACCESS_OP_DONE;
			} while (reg);
		j++;
	}
}
#endif

/*
 * Name:     ddr3_get_static_mc_value - Init Memory controller with static
 *           parameters
 * Desc:     Use this routine to init the controller without the HW training
 *           procedure
 *           User must provide compatible header file with registers data.
 * Args:     None.
 * Notes:
 * Returns:  None.
 */
u32 ddr3_get_static_mc_value(u32 reg_addr, u32 offset1, u32 mask1, u32 offset2,
			     u32 mask2)
{
	u32 reg, tmp;

	reg = reg_read(reg_addr);

	tmp = (reg >> offset1) & mask1;
	if (mask2)
		tmp |= (reg >> offset2) & mask2;

	return tmp;
}

/*
 * Name:     ddr3_get_static_ddr_mode - Init Memory controller with static
 *           parameters
 * Desc:     Use this routine to init the controller without the HW training
 *           procedure
 *           User must provide compatible header file with registers data.
 * Args:     None.
 * Notes:
 * Returns:  None.
 */
__weak MV_DRAM_MODES *ddr3_get_static_ddr_mode(void)
{
	u32 chip_board_rev, i;
	u32 size;

	/* Do not modify this code. relevant only for marvell Boards */
#if defined(DB_78X60_PCAC)
	chip_board_rev = Z1_PCAC;
#elif defined(DB_78X60_AMC)
	chip_board_rev = A0_AMC;
#elif defined(DB_88F6710_PCAC)
	chip_board_rev = A0_PCAC;
#elif defined(RD_88F6710)
	chip_board_rev = A0_RD;
#elif defined(MV88F672X)
	chip_board_rev = mv_board_id_get();
#else
	chip_board_rev = A0;
#endif

	size = sizeof(ddr_modes) / sizeof(MV_DRAM_MODES);
	for (i = 0; i < size; i++) {
		if ((ddr3_get_cpu_freq() == ddr_modes[i].cpu_freq) &&
		    (ddr3_get_fab_opt() == ddr_modes[i].fab_freq) &&
		    (chip_board_rev == ddr_modes[i].chip_board_rev))
			return &ddr_modes[i];
	}

	return &ddr_modes[0];
}

#ifdef DUNIT_STATIC
/*
 * Name:     ddr3_static_mc_init - Init Memory controller with static parameters
 * Desc:     Use this routine to init the controller without the HW training
 *           procedure
 *           User must provide compatible header file with registers data.
 * Args:     None.
 * Notes:
 * Returns:  None.
 */
void ddr3_static_mc_init(void)
{
	MV_DRAM_MODES *ddr_mode;
	u32 reg;
	int j;

	ddr_mode = ddr3_get_static_ddr_mode();
	j = 0;
	while (ddr_mode->regs[j].reg_addr != 0) {
		reg_write(ddr_mode->regs[j].reg_addr,
			  ddr_mode->regs[j].reg_value);
		if (ddr_mode->regs[j].reg_addr ==
		    REG_PHY_REGISTRY_FILE_ACCESS_ADDR)
			do {
				reg = reg_read(REG_PHY_REGISTRY_FILE_ACCESS_ADDR) &
					REG_PHY_REGISTRY_FILE_ACCESS_OP_DONE;
			} while (reg);
		j++;
	}
}
#endif

/*
 * Name:     ddr3_check_config - Check user configurations: ECC/MultiCS
 * Desc:
 * Args:     twsi Address
 * Notes:    Only Available for ArmadaXP/Armada 370 DB boards
 * Returns:  None.
 */
int ddr3_check_config(u32 twsi_addr, MV_CONFIG_TYPE config_type)
{
#ifdef AUTO_DETECTION_SUPPORT
	u8 data = 0;
	int ret;
	int offset;

	if ((config_type == CONFIG_ECC) || (config_type == CONFIG_BUS_WIDTH))
		offset = 1;
	else
		offset = 0;

	ret = i2c_read(twsi_addr, offset, 1, (u8 *)&data, 1);
	if (!ret) {
		switch (config_type) {
		case CONFIG_ECC:
			if (data & 0x2)
				return 1;
			break;
		case CONFIG_BUS_WIDTH:
			if (data & 0x1)
				return 1;
			break;
#ifdef DB_88F6710
		case CONFIG_MULTI_CS:
			if (CFG_MULTI_CS_MODE(data))
				return 1;
			break;
#else
		case CONFIG_MULTI_CS:
			break;
#endif
		}
	}
#endif

	return 0;
}

#if defined(DB_88F78X60_REV2)
/*
 * Name:     ddr3_get_eprom_fabric - Get Fabric configuration from EPROM
 * Desc:
 * Args:     twsi Address
 * Notes:    Only Available for ArmadaXP DB Rev2 boards
 * Returns:  None.
 */
u8 ddr3_get_eprom_fabric(void)
{
#ifdef AUTO_DETECTION_SUPPORT
	u8 data = 0;
	int ret;

	ret = i2c_read(NEW_FABRIC_TWSI_ADDR, 1, 1, (u8 *)&data, 1);
	if (!ret)
		return data & 0x1F;
#endif

	return 0;
}

#endif

/*
 * Name:     ddr3_cl_to_valid_cl - this return register matching CL value
 * Desc:
 * Args:     clValue - the value

 * Notes:
 * Returns:  required CL value
 */
u32 ddr3_cl_to_valid_cl(u32 cl)
{
	switch (cl) {
	case 5:
		return 2;
		break;
	case 6:
		return 4;
		break;
	case 7:
		return 6;
		break;
	case 8:
		return 8;
		break;
	case 9:
		return 10;
		break;
	case 10:
		return 12;
		break;
	case 11:
		return 14;
		break;
	case 12:
		return 1;
		break;
	case 13:
		return 3;
		break;
	case 14:
		return 5;
		break;
	default:
		return 2;
	}
}

/*
 * Name:     ddr3_cl_to_valid_cl - this return register matching CL value
 * Desc:
 * Args:     clValue - the value
 * Notes:
 * Returns:  required CL value
 */
u32 ddr3_valid_cl_to_cl(u32 ui_valid_cl)
{
	switch (ui_valid_cl) {
	case 1:
		return 12;
		break;
	case 2:
		return 5;
		break;
	case 3:
		return 13;
		break;
	case 4:
		return 6;
		break;
	case 5:
		return 14;
		break;
	case 6:
		return 7;
		break;
	case 8:
		return 8;
		break;
	case 10:
		return 9;
		break;
	case 12:
		return 10;
		break;
	case 14:
		return 11;
		break;
	default:
		return 0;
	}
}

/*
 * Name:     ddr3_get_cs_num_from_reg
 * Desc:
 * Args:
 * Notes:
 * Returns:
 */
u32 ddr3_get_cs_num_from_reg(void)
{
	u32 cs_ena = ddr3_get_cs_ena_from_reg();
	u32 cs_count = 0;
	u32 cs;

	for (cs = 0; cs < MAX_CS; cs++) {
		if (cs_ena & (1 << cs))
			cs_count++;
	}

	return cs_count;
}

/*
 * Name:     ddr3_get_cs_ena_from_reg
 * Desc:
 * Args:
 * Notes:
 * Returns:
 */
u32 ddr3_get_cs_ena_from_reg(void)
{
	return reg_read(REG_DDR3_RANK_CTRL_ADDR) &
		REG_DDR3_RANK_CTRL_CS_ENA_MASK;
}

/*
 * mv_ctrl_rev_get - Get Marvell controller device revision number
 *
 * DESCRIPTION:
 *       This function returns 8bit describing the device revision as defined
 *       in PCI Express Class Code and Revision ID Register.
 *
 * INPUT:
 *       None.
 *
 * OUTPUT:
 *       None.
 *
 * RETURN:
 *       8bit desscribing Marvell controller revision number
 *
 */
#if !defined(MV88F672X)
u8 mv_ctrl_rev_get(void)
{
	u8 rev_num;

#if defined(MV_INCLUDE_CLK_PWR_CNTRL)
	/* Check pex power state */
	u32 pex_power;
	pex_power = mv_ctrl_pwr_clck_get(PEX_UNIT_ID, 0);
	if (pex_power == 0)
		mv_ctrl_pwr_clck_set(PEX_UNIT_ID, 0, 1);
#endif
	rev_num = (u8)reg_read(PEX_CFG_DIRECT_ACCESS(0,
			PCI_CLASS_CODE_AND_REVISION_ID));

#if defined(MV_INCLUDE_CLK_PWR_CNTRL)
	/* Return to power off state */
	if (pex_power == 0)
		mv_ctrl_pwr_clck_set(PEX_UNIT_ID, 0, 0);
#endif

	return (rev_num & PCCRIR_REVID_MASK) >> PCCRIR_REVID_OFFS;
}

#endif

#if defined(MV88F672X)
void get_target_freq(u32 freq_mode, u32 *ddr_freq, u32 *hclk_ps)
{
	u32 tmp, hclk;

	switch (freq_mode) {
	case CPU_333MHz_DDR_167MHz_L2_167MHz:
		hclk = 84;
		tmp = DDR_100;
		break;
	case CPU_266MHz_DDR_266MHz_L2_133MHz:
	case CPU_333MHz_DDR_222MHz_L2_167MHz:
	case CPU_400MHz_DDR_200MHz_L2_200MHz:
	case CPU_400MHz_DDR_267MHz_L2_200MHz:
	case CPU_533MHz_DDR_267MHz_L2_267MHz:
	case CPU_500MHz_DDR_250MHz_L2_250MHz:
	case CPU_600MHz_DDR_300MHz_L2_300MHz:
	case CPU_800MHz_DDR_267MHz_L2_400MHz:
	case CPU_900MHz_DDR_300MHz_L2_450MHz:
		tmp = DDR_300;
		hclk = 150;
		break;
	case CPU_333MHz_DDR_333MHz_L2_167MHz:
	case CPU_500MHz_DDR_334MHz_L2_250MHz:
	case CPU_666MHz_DDR_333MHz_L2_333MHz:
		tmp = DDR_333;
		hclk = 165;
		break;
	case CPU_533MHz_DDR_356MHz_L2_267MHz:
		tmp = DDR_360;
		hclk = 180;
		break;
	case CPU_400MHz_DDR_400MHz_L2_200MHz:
	case CPU_600MHz_DDR_400MHz_L2_300MHz:
	case CPU_800MHz_DDR_400MHz_L2_400MHz:
	case CPU_400MHz_DDR_400MHz_L2_400MHz:
		tmp = DDR_400;
		hclk = 200;
		break;
	case CPU_666MHz_DDR_444MHz_L2_333MHz:
	case CPU_900MHz_DDR_450MHz_L2_450MHz:
		tmp = DDR_444;
		hclk = 222;
		break;
	case CPU_500MHz_DDR_500MHz_L2_250MHz:
	case CPU_1000MHz_DDR_500MHz_L2_500MHz:
	case CPU_1000MHz_DDR_500MHz_L2_333MHz:
		tmp = DDR_500;
		hclk = 250;
		break;
	case CPU_533MHz_DDR_533MHz_L2_267MHz:
	case CPU_800MHz_DDR_534MHz_L2_400MHz:
	case CPU_1100MHz_DDR_550MHz_L2_550MHz:
		tmp = DDR_533;
		hclk = 267;
		break;
	case CPU_600MHz_DDR_600MHz_L2_300MHz:
	case CPU_900MHz_DDR_600MHz_L2_450MHz:
	case CPU_1200MHz_DDR_600MHz_L2_600MHz:
		tmp = DDR_600;
		hclk = 300;
		break;
	case CPU_666MHz_DDR_666MHz_L2_333MHz:
	case CPU_1000MHz_DDR_667MHz_L2_500MHz:
		tmp = DDR_666;
		hclk = 333;
		break;
	default:
		*ddr_freq = 0;
		*hclk_ps = 0;
		break;
	}

	*ddr_freq = tmp;		/* DDR freq define */
	*hclk_ps = 1000000 / hclk;	/* values are 1/HCLK in ps */

	return;
}
#endif