3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/m5249.h>
32 int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
33 int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
40 /* predefine these here for FPGA programming (before including fpga.c) */
41 #define SET_FPGA(data) mbar2_writeLong(MCFSIM_GPIO1_OUT, data)
42 #define FPGA_DONE_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_DONE)
43 #define FPGA_INIT_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_INIT)
44 #define FPGA_PROG_ACTIVE_HIGH /* on this platform is PROG active high! */
45 #define out32(a,b) /* nothing to do (gpio already configured) */
48 /* fpga configuration data - generated by bin2cc */
49 const unsigned char fpgadata[] =
55 * include common fpga code (for esd boards)
57 #include "../common/fpga.c"
60 int checkboard (void) {
66 val8 = ((uchar)~((uchar)mbar2_readLong(MCFSIM_GPIO1_READ) >> 4)) & 0xf;
67 printf(" (Switch=%1X)\n", val8);
72 val = mbar2_readLong(MCFSIM_GPIO1_OUT) & ~CONFIG_SYS_GPIO1_LED;
73 mbar2_writeLong(MCFSIM_GPIO1_OUT, val); /* Set LED on */
79 phys_size_t initdram (int board_type) {
80 unsigned long junk = 0xa5a59696;
84 * RC = ([(RefreshTime/#rows) / (1/BusClk)] / 16) - 1
87 #ifdef CONFIG_SYS_FAST_CLK
89 * Busclk=70MHz, RefreshTime=64ms, #rows=4096 (4K)
90 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=39
92 mbar_writeShort(MCFSIM_DCR, 0x8239);
93 #elif CONFIG_SYS_PLL_BYPASS
95 * Busclk=5.6448MHz, RefreshTime=64ms, #rows=8192 (8K)
96 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=02
98 mbar_writeShort(MCFSIM_DCR, 0x8202);
101 * Busclk=36MHz, RefreshTime=64ms, #rows=4096 (4K)
102 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=22 (562 bus clock cycles)
104 mbar_writeShort(MCFSIM_DCR, 0x8222);
108 * SDRAM starts at 0x0000_0000, CASL=10, CBM=010, PS=10 (16bit port),
109 * PM=1 (continuous page mode)
112 /* RE=0 (keep auto-refresh disabled while setting up registers) */
113 mbar_writeLong(MCFSIM_DACR0, 0x00003324);
115 /* BAM=007c (bits 22,21 are bank selects; 256kB blocks) */
116 mbar_writeLong(MCFSIM_DMR0, 0x01fc0001);
118 /** Precharge sequence **/
119 mbar_writeLong(MCFSIM_DACR0, 0x0000332c); /* Set DACR0[IP] (bit 3) */
120 out_be32((void *)0, junk); /* write to a memory location to init. precharge */
121 udelay(0x10); /* Allow several Precharge cycles */
123 /** Refresh Sequence **/
124 mbar_writeLong(MCFSIM_DACR0, 0x0000b324); /* Enable the refresh bit, DACR0[RE] (bit 15) */
125 udelay(0x7d0); /* Allow gobs of refresh cycles */
127 /** Mode Register initialization **/
128 mbar_writeLong(MCFSIM_DACR0, 0x0000b364); /* Enable DACR0[IMRS] (bit 6); RE remains enabled */
129 out_be32((void *)0x800, junk); /* Access RAM to initialize the mode register */
131 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
135 int testdram (void) {
136 /* TODO: XXX XXX XXX */
137 printf ("DRAM test not implemented!\n");
143 int misc_init_r (void)
146 ulong len = sizeof(fpgadata);
152 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
153 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
154 printf ("GUNZIP ERROR - must RESET board to recover\n");
155 do_reset (NULL, 0, 0, NULL);
158 status = fpga_boot(dst, len);
160 printf("\nFPGA: Booting failed ");
162 case ERROR_FPGA_PRG_INIT_LOW:
163 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
165 case ERROR_FPGA_PRG_INIT_HIGH:
166 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
168 case ERROR_FPGA_PRG_DONE:
169 printf("(Timeout: DONE not high after programming FPGA)\n ");
173 /* display infos on fpgaimage */
175 for (i=0; i<4; i++) {
177 printf("FPGA: %s\n", &(dst[index+1]));
182 for (i=20; i>0; i--) {
183 printf("Rebooting in %2d seconds \r",i);
184 for (index=0;index<1000;index++)
188 do_reset(NULL, 0, 0, NULL);
193 /* display infos on fpgaimage */
195 for (i=0; i<4; i++) {
197 printf("%s ", &(dst[index+1]));
210 i2c_write(0x38, 0, 0, buf, 3);
216 #if 1 /* test-only: board specific test commands */
217 int i2c_probe(uchar addr);
221 int do_iploop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
230 addr = simple_strtol (argv[1], NULL, 16);
232 printf("i2c probe looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
237 /* Abort if ctrl-c was pressed */
249 iploop, 2, 1, do_iploop,
250 "i2c probe loop <addr>",
256 int do_codec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
260 out_be16((void *)0xe0000000, 0x4000);
262 udelay(5000); /* wait for 5ms */
267 i2c_write(0x10, 0, 0, buf, 3);
272 i2c_write(0x10, 0, 0, buf, 3);
277 i2c_write(0x10, 0, 0, buf, 3);
282 i2c_write(0x10, 0, 0, buf, 3);
287 i2c_write(0x10, 0, 0, buf, 3);
292 i2c_write(0x10, 0, 0, buf, 3);
297 i2c_write(0x10, 0, 0, buf, 3);
302 codec, 1, 1, do_codec,
309 int do_saa(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
322 addr = simple_strtol (argv[1], NULL, 16);
323 instr = simple_strtol (argv[2], NULL, 16);
324 cntrl = simple_strtol (argv[3], NULL, 16);
325 data = simple_strtol (argv[4], NULL, 16);
327 buf[0] = (uchar)instr;
328 buf[1] = (uchar)cntrl;
329 buf[2] = (uchar)data;
330 i2c_write(addr, 0, 0, buf, 3);
336 "Write to SAA1064 <addr> <instr> <cntrl> <data>",
342 int do_iwrite(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
357 addr = simple_strtol (argv[1], NULL, 16);
358 cnt = simple_strtol (argv[2], NULL, 16);
359 data0 = simple_strtol (argv[3], NULL, 16);
360 data1 = simple_strtol (argv[4], NULL, 16);
361 data2 = simple_strtol (argv[5], NULL, 16);
362 data3 = simple_strtol (argv[6], NULL, 16);
364 printf("Writing %d bytes to device %lx!\n", cnt, addr);
365 buf[0] = (uchar)data0;
366 buf[1] = (uchar)data1;
367 buf[2] = (uchar)data2;
368 buf[3] = (uchar)data3;
369 i2c_write(addr, 0, 0, buf, cnt);
374 iwrite, 6, 1, do_iwrite,
375 "Write n bytes to I2C-device",
376 "addr cnt data0 ... datan"
381 int do_iread(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
393 addr = simple_strtol (argv[1], NULL, 16);
394 cnt = simple_strtol (argv[2], NULL, 16);
396 i2c_read(addr, 0, 0, buf, cnt);
398 for (i=0; i<cnt; i++) {
399 printf(" %02X", buf[i]);
406 iread, 3, 1, do_iread,
407 "Read from I2C <addr> <cnt>",
413 int do_ireadl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
424 addr = simple_strtol (argv[1], NULL, 16);
427 printf("iread looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
430 i2c_read(addr, 0, 0, buf, cnt);
432 /* Abort if ctrl-c was pressed */
444 ireadl, 2, 1, do_ireadl,
445 "Read-loop from I2C <addr>",