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#include <common.h>
30#include <mpc83xx.h>
31#include <spd_sdram.h>
32#include <asm/bitops.h>
33#include <asm/io.h>
34#include <asm/processor.h>
35#include <asm/mmu.h>
36
37DECLARE_GLOBAL_DATA_PTR;
38
39static long fixed_sdram(void);
40
41#if defined(CONFIG_NAND_SPL)
42void si_wait_i2c(void)
43{
44 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
45
46 while (!(__raw_readb(&im->i2c[0].sr) & 0x02))
47 ;
48
49 __raw_writeb(0x00, &im->i2c[0].sr);
50
51 sync();
52
53 return;
54}
55
56void si_read_i2c(u32 lbyte, int count, u8 *buffer)
57{
58 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
59 u32 i;
60 u8 chip = 0x50 << 1;
61 u32 ubyte = (lbyte & 0xff00) >> 8;
62
63 lbyte &= 0xff;
64
65
66
67
68 __raw_writeb(0x3f, &im->i2c[0].fdr);
69 __raw_writeb(0x00, &im->i2c[0].adr);
70 __raw_writeb(0x00, &im->i2c[0].sr);
71 __raw_writeb(0x00, &im->i2c[0].dr);
72
73 while (__raw_readb(&im->i2c[0].sr) & 0x20)
74 ;
75
76
77
78
79 __raw_writeb(0xb0, &im->i2c[0].cr);
80 sync();
81 __raw_writeb(chip, &im->i2c[0].dr);
82 si_wait_i2c();
83
84 __raw_writeb(0xb0, &im->i2c[0].cr);
85 sync();
86 __raw_writeb(ubyte, &im->i2c[0].dr);
87 si_wait_i2c();
88
89 __raw_writeb(lbyte, &im->i2c[0].dr);
90 si_wait_i2c();
91
92 __raw_writeb(0xb4, &im->i2c[0].cr);
93 sync();
94 __raw_writeb(chip + 1, &im->i2c[0].dr);
95 si_wait_i2c();
96
97 __raw_writeb(0xa0, &im->i2c[0].cr);
98 sync();
99
100
101
102
103 __raw_readb(&im->i2c[0].dr);
104
105 si_wait_i2c();
106
107
108
109
110 for (i = 0; i < count; i++)
111 {
112 if (i == (count - 2))
113 __raw_writeb(0xa8, &im->i2c[0].cr);
114 if (i == (count - 1))
115 __raw_writeb(0x88, &im->i2c[0].cr);
116
117
118 buffer[i] = __raw_readb(&im->i2c[0].dr);
119
120 if (i == (count - 1))
121 break;
122 si_wait_i2c();
123 }
124
125 return;
126}
127#endif
128
129phys_size_t initdram(int board_type)
130{
131 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
132 volatile fsl_lbc_t *lbc = &im->im_lbc;
133 u32 msize;
134
135 if ((__raw_readl(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32) im)
136 return -1;
137
138
139 __raw_writel(CONFIG_SYS_DDR_BASE & LAWBAR_BAR, &im->sysconf.ddrlaw[0].bar);
140
141 msize = fixed_sdram();
142
143
144 __raw_writel(CONFIG_SYS_LBC_LBCR, &lbc->lbcr);
145 __raw_writel(CONFIG_SYS_LBC_MRTPR, &lbc->mrtpr);
146 sync();
147
148
149 return (msize * 1024 * 1024);
150}
151
152
153
154
155static long fixed_sdram(void)
156{
157 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
158 u32 msizelog2, msize = 1;
159#if defined(CONFIG_NAND_SPL)
160 u32 i;
161 const u8 bytecount = 135;
162 u8 buffer[bytecount];
163 u32 addr, data;
164
165 si_read_i2c(0, bytecount, buffer);
166
167 for (i = 18; i < bytecount; i += 7){
168 addr = (u32)buffer[i];
169 addr <<= 8;
170 addr |= (u32)buffer[i + 1];
171 addr <<= 2;
172 data = (u32)buffer[i + 2];
173 data <<= 8;
174 data |= (u32)buffer[i + 3];
175 data <<= 8;
176 data |= (u32)buffer[i + 4];
177 data <<= 8;
178 data |= (u32)buffer[i + 5];
179
180 __raw_writel(data, (u32 *)(CONFIG_SYS_IMMR + addr));
181 }
182
183 sync();
184
185
186 __raw_writel((__raw_readl(&im->ddr.sdram_cfg) | SDRAM_CFG_MEM_EN), &im->ddr.sdram_cfg);
187#endif
188
189 msizelog2 = ((__raw_readl(&im->sysconf.ddrlaw[0].ar) & LAWAR_SIZE) + 1);
190 msize <<= (msizelog2 - 20);
191
192 return msize;
193}
194