Blame view

board/socrates/sdram.c 2.12 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
5d108ac8f   Sergei Poselenov   Initial support f...
2
3
4
  /*
   * (C) Copyright 2008
   * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com.
5d108ac8f   Sergei Poselenov   Initial support f...
5
   */
5d108ac8f   Sergei Poselenov   Initial support f...
6
7
8
  #include <common.h>
  #include <asm/processor.h>
  #include <asm/immap_85xx.h>
5614e71b4   York Sun   Driver/DDR: Movin...
9
  #include <fsl_ddr_sdram.h>
5d108ac8f   Sergei Poselenov   Initial support f...
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <asm/processor.h>
  #include <asm/mmu.h>
  #include <spd_sdram.h>
  
  
  #if !defined(CONFIG_SPD_EEPROM)
  /*
   * Autodetect onboard DDR SDRAM on 85xx platforms
   *
   * NOTE: Some of the hardcoded values are hardware dependant,
   *       so this should be extended for other future boards
   *       using this routine!
   */
38dba0c2f   Becky Bruce   mpc85xx boards: i...
23
  phys_size_t fixed_sdram(void)
5d108ac8f   Sergei Poselenov   Initial support f...
24
  {
9a17eb5b7   York Sun   Driver/DDR: combi...
25
26
  	struct ccsr_ddr __iomem *ddr =
  		(struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR);
5d108ac8f   Sergei Poselenov   Initial support f...
27
28
29
30
31
32
  
  	/*
  	 * Disable memory controller.
  	 */
  	ddr->cs0_config = 0;
  	ddr->sdram_cfg = 0;
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
33
34
35
36
37
38
39
40
41
  	ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  	ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  	ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  	ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  	ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  	ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
  	ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  	ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONFIG_2;
  	ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CONTROL;
5d108ac8f   Sergei Poselenov   Initial support f...
42
43
44
  
  	asm ("sync;isync;msync");
  	udelay(1000);
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
45
  	ddr->sdram_cfg = CONFIG_SYS_DDR_CONFIG;
5d108ac8f   Sergei Poselenov   Initial support f...
46
47
  	asm ("sync; isync; msync");
  	udelay(1000);
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
48
  	if (get_ram_size(0, CONFIG_SYS_SDRAM_SIZE<<20) == CONFIG_SYS_SDRAM_SIZE<<20) {
5d108ac8f   Sergei Poselenov   Initial support f...
49
50
51
  		/*
  		 * OK, size detected -> all done
  		 */
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
52
  		return CONFIG_SYS_SDRAM_SIZE<<20;
5d108ac8f   Sergei Poselenov   Initial support f...
53
54
55
56
57
  	}
  
  	return 0;				/* nothing found !		*/
  }
  #endif
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
58
  #if defined(CONFIG_SYS_DRAM_TEST)
5d108ac8f   Sergei Poselenov   Initial support f...
59
60
  int testdram (void)
  {
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
61
62
  	uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  	uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
5d108ac8f   Sergei Poselenov   Initial support f...
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
  	uint *p;
  
  	printf ("SDRAM test phase 1:
  ");
  	for (p = pstart; p < pend; p++)
  		*p = 0xaaaaaaaa;
  
  	for (p = pstart; p < pend; p++) {
  		if (*p != 0xaaaaaaaa) {
  			printf ("SDRAM test fails at: %08x
  ", (uint) p);
  			return 1;
  		}
  	}
  
  	printf ("SDRAM test phase 2:
  ");
  	for (p = pstart; p < pend; p++)
  		*p = 0x55555555;
  
  	for (p = pstart; p < pend; p++) {
  		if (*p != 0x55555555) {
  			printf ("SDRAM test fails at: %08x
  ", (uint) p);
  			return 1;
  		}
  	}
  
  	printf ("SDRAM test passed.
  ");
  	return 0;
  }
  #endif