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>
31 int gunzip(void *, int, unsigned char *, unsigned long *);
32 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
33 int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
34 int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
41 /* predefine these here for FPGA programming (before including fpga.c) */
42 #define SET_FPGA(data) mbar2_writeLong(MCFSIM_GPIO1_OUT, data)
43 #define FPGA_DONE_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_DONE)
44 #define FPGA_INIT_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_INIT)
45 #define FPGA_PROG_ACTIVE_HIGH /* on this platform is PROG active high! */
46 #define out32(a,b) /* nothing to do (gpio already configured) */
49 /* fpga configuration data - generated by bin2cc */
50 const unsigned char fpgadata[] =
56 * include common fpga code (for esd boards)
58 #include "../common/fpga.c"
61 int checkboard (void) {
67 val8 = ((uchar)~((uchar)mbar2_readLong(MCFSIM_GPIO1_READ) >> 4)) & 0xf;
68 printf(" (Switch=%1X)\n", val8);
73 val = mbar2_readLong(MCFSIM_GPIO1_OUT) & ~CONFIG_SYS_GPIO1_LED;
74 mbar2_writeLong(MCFSIM_GPIO1_OUT, val); /* Set LED on */
80 phys_size_t initdram (int board_type) {
81 unsigned long junk = 0xa5a59696;
85 * RC = ([(RefreshTime/#rows) / (1/BusClk)] / 16) - 1
88 #ifdef CONFIG_SYS_FAST_CLK
90 * Busclk=70MHz, RefreshTime=64ms, #rows=4096 (4K)
91 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=39
93 mbar_writeShort(MCFSIM_DCR, 0x8239);
94 #elif CONFIG_SYS_PLL_BYPASS
96 * Busclk=5.6448MHz, RefreshTime=64ms, #rows=8192 (8K)
97 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=02
99 mbar_writeShort(MCFSIM_DCR, 0x8202);
102 * Busclk=36MHz, RefreshTime=64ms, #rows=4096 (4K)
103 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=22 (562 bus clock cycles)
105 mbar_writeShort(MCFSIM_DCR, 0x8222);
109 * SDRAM starts at 0x0000_0000, CASL=10, CBM=010, PS=10 (16bit port),
110 * PM=1 (continuous page mode)
113 /* RE=0 (keep auto-refresh disabled while setting up registers) */
114 mbar_writeLong(MCFSIM_DACR0, 0x00003324);
116 /* BAM=007c (bits 22,21 are bank selects; 256kB blocks) */
117 mbar_writeLong(MCFSIM_DMR0, 0x01fc0001);
119 /** Precharge sequence **/
120 mbar_writeLong(MCFSIM_DACR0, 0x0000332c); /* Set DACR0[IP] (bit 3) */
121 *((volatile unsigned long *) 0x00) = junk; /* write to a memory location to init. precharge */
122 udelay(0x10); /* Allow several Precharge cycles */
124 /** Refresh Sequence **/
125 mbar_writeLong(MCFSIM_DACR0, 0x0000b324); /* Enable the refresh bit, DACR0[RE] (bit 15) */
126 udelay(0x7d0); /* Allow gobs of refresh cycles */
128 /** Mode Register initialization **/
129 mbar_writeLong(MCFSIM_DACR0, 0x0000b364); /* Enable DACR0[IMRS] (bit 6); RE remains enabled */
130 *((volatile unsigned long *) 0x800) = junk; /* Access RAM to initialize the mode register */
132 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
136 int testdram (void) {
137 /* TODO: XXX XXX XXX */
138 printf ("DRAM test not implemented!\n");
144 int misc_init_r (void)
147 ulong len = sizeof(fpgadata);
153 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
154 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
155 printf ("GUNZIP ERROR - must RESET board to recover\n");
156 do_reset (NULL, 0, 0, NULL);
159 status = fpga_boot(dst, len);
161 printf("\nFPGA: Booting failed ");
163 case ERROR_FPGA_PRG_INIT_LOW:
164 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
166 case ERROR_FPGA_PRG_INIT_HIGH:
167 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
169 case ERROR_FPGA_PRG_DONE:
170 printf("(Timeout: DONE not high after programming FPGA)\n ");
174 /* display infos on fpgaimage */
176 for (i=0; i<4; i++) {
178 printf("FPGA: %s\n", &(dst[index+1]));
183 for (i=20; i>0; i--) {
184 printf("Rebooting in %2d seconds \r",i);
185 for (index=0;index<1000;index++)
189 do_reset(NULL, 0, 0, NULL);
194 /* display infos on fpgaimage */
196 for (i=0; i<4; i++) {
198 printf("%s ", &(dst[index+1]));
211 i2c_write(0x38, 0, 0, buf, 3);
217 #if 1 /* test-only: board specific test commands */
218 int i2c_probe(uchar addr);
222 int do_iploop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
231 addr = simple_strtol (argv[1], NULL, 16);
233 printf("iprobe looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
238 /* Abort if ctrl-c was pressed */
250 iploop, 2, 1, do_iploop,
251 "iprobe loop <addr>",
257 int do_codec(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
261 *(volatile ushort *)0xe0000000 = 0x4000;
263 udelay(5000); /* wait for 5ms */
268 i2c_write(0x10, 0, 0, buf, 3);
273 i2c_write(0x10, 0, 0, buf, 3);
278 i2c_write(0x10, 0, 0, buf, 3);
283 i2c_write(0x10, 0, 0, buf, 3);
288 i2c_write(0x10, 0, 0, buf, 3);
293 i2c_write(0x10, 0, 0, buf, 3);
298 i2c_write(0x10, 0, 0, buf, 3);
303 codec, 1, 1, do_codec,
310 int do_saa(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
323 addr = simple_strtol (argv[1], NULL, 16);
324 instr = simple_strtol (argv[2], NULL, 16);
325 cntrl = simple_strtol (argv[3], NULL, 16);
326 data = simple_strtol (argv[4], NULL, 16);
328 buf[0] = (uchar)instr;
329 buf[1] = (uchar)cntrl;
330 buf[2] = (uchar)data;
331 i2c_write(addr, 0, 0, buf, 3);
337 "Write to SAA1064 <addr> <instr> <cntrl> <data>",
343 int do_iwrite(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
358 addr = simple_strtol (argv[1], NULL, 16);
359 cnt = simple_strtol (argv[2], NULL, 16);
360 data0 = simple_strtol (argv[3], NULL, 16);
361 data1 = simple_strtol (argv[4], NULL, 16);
362 data2 = simple_strtol (argv[5], NULL, 16);
363 data3 = simple_strtol (argv[6], NULL, 16);
365 printf("Writing %d bytes to device %lx!\n", cnt, addr);
366 buf[0] = (uchar)data0;
367 buf[1] = (uchar)data1;
368 buf[2] = (uchar)data2;
369 buf[3] = (uchar)data3;
370 i2c_write(addr, 0, 0, buf, cnt);
375 iwrite, 6, 1, do_iwrite,
376 "Write n bytes to I2C-device",
377 "addr cnt data0 ... datan\n"
382 int do_iread(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
394 addr = simple_strtol (argv[1], NULL, 16);
395 cnt = simple_strtol (argv[2], NULL, 16);
397 i2c_read(addr, 0, 0, buf, cnt);
399 for (i=0; i<cnt; i++) {
400 printf(" %02X", buf[i]);
407 iread, 3, 1, do_iread,
408 "Read from I2C <addr> <cnt>",
414 int do_ireadl(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
425 addr = simple_strtol (argv[1], NULL, 16);
428 printf("iread looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
431 i2c_read(addr, 0, 0, buf, cnt);
433 /* Abort if ctrl-c was pressed */
445 ireadl, 2, 1, do_ireadl,
446 "Read-loop from I2C <addr>",