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 gunzip(void *, int, unsigned char *, unsigned long *);
33 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
34 int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
35 int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
42 /* predefine these here for FPGA programming (before including fpga.c) */
43 #define SET_FPGA(data) mbar2_writeLong(MCFSIM_GPIO1_OUT, data)
44 #define FPGA_DONE_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_DONE)
45 #define FPGA_INIT_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_INIT)
46 #define FPGA_PROG_ACTIVE_HIGH /* on this platform is PROG active high! */
47 #define out32(a,b) /* nothing to do (gpio already configured) */
50 /* fpga configuration data - generated by bin2cc */
51 const unsigned char fpgadata[] =
57 * include common fpga code (for esd boards)
59 #include "../common/fpga.c"
62 int checkboard (void) {
68 val8 = ((uchar)~((uchar)mbar2_readLong(MCFSIM_GPIO1_READ) >> 4)) & 0xf;
69 printf(" (Switch=%1X)\n", val8);
74 val = mbar2_readLong(MCFSIM_GPIO1_OUT) & ~CONFIG_SYS_GPIO1_LED;
75 mbar2_writeLong(MCFSIM_GPIO1_OUT, val); /* Set LED on */
81 phys_size_t initdram (int board_type) {
82 unsigned long junk = 0xa5a59696;
86 * RC = ([(RefreshTime/#rows) / (1/BusClk)] / 16) - 1
89 #ifdef CONFIG_SYS_FAST_CLK
91 * Busclk=70MHz, RefreshTime=64ms, #rows=4096 (4K)
92 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=39
94 mbar_writeShort(MCFSIM_DCR, 0x8239);
95 #elif CONFIG_SYS_PLL_BYPASS
97 * Busclk=5.6448MHz, RefreshTime=64ms, #rows=8192 (8K)
98 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=02
100 mbar_writeShort(MCFSIM_DCR, 0x8202);
103 * Busclk=36MHz, RefreshTime=64ms, #rows=4096 (4K)
104 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=22 (562 bus clock cycles)
106 mbar_writeShort(MCFSIM_DCR, 0x8222);
110 * SDRAM starts at 0x0000_0000, CASL=10, CBM=010, PS=10 (16bit port),
111 * PM=1 (continuous page mode)
114 /* RE=0 (keep auto-refresh disabled while setting up registers) */
115 mbar_writeLong(MCFSIM_DACR0, 0x00003324);
117 /* BAM=007c (bits 22,21 are bank selects; 256kB blocks) */
118 mbar_writeLong(MCFSIM_DMR0, 0x01fc0001);
120 /** Precharge sequence **/
121 mbar_writeLong(MCFSIM_DACR0, 0x0000332c); /* Set DACR0[IP] (bit 3) */
122 out_be32((void *)0, junk); /* write to a memory location to init. precharge */
123 udelay(0x10); /* Allow several Precharge cycles */
125 /** Refresh Sequence **/
126 mbar_writeLong(MCFSIM_DACR0, 0x0000b324); /* Enable the refresh bit, DACR0[RE] (bit 15) */
127 udelay(0x7d0); /* Allow gobs of refresh cycles */
129 /** Mode Register initialization **/
130 mbar_writeLong(MCFSIM_DACR0, 0x0000b364); /* Enable DACR0[IMRS] (bit 6); RE remains enabled */
131 out_be32((void *)0x800, junk); /* Access RAM to initialize the mode register */
133 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
137 int testdram (void) {
138 /* TODO: XXX XXX XXX */
139 printf ("DRAM test not implemented!\n");
145 int misc_init_r (void)
148 ulong len = sizeof(fpgadata);
154 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
155 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
156 printf ("GUNZIP ERROR - must RESET board to recover\n");
157 do_reset (NULL, 0, 0, NULL);
160 status = fpga_boot(dst, len);
162 printf("\nFPGA: Booting failed ");
164 case ERROR_FPGA_PRG_INIT_LOW:
165 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
167 case ERROR_FPGA_PRG_INIT_HIGH:
168 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
170 case ERROR_FPGA_PRG_DONE:
171 printf("(Timeout: DONE not high after programming FPGA)\n ");
175 /* display infos on fpgaimage */
177 for (i=0; i<4; i++) {
179 printf("FPGA: %s\n", &(dst[index+1]));
184 for (i=20; i>0; i--) {
185 printf("Rebooting in %2d seconds \r",i);
186 for (index=0;index<1000;index++)
190 do_reset(NULL, 0, 0, NULL);
195 /* display infos on fpgaimage */
197 for (i=0; i<4; i++) {
199 printf("%s ", &(dst[index+1]));
212 i2c_write(0x38, 0, 0, buf, 3);
218 #if 1 /* test-only: board specific test commands */
219 int i2c_probe(uchar addr);
223 int do_iploop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
232 addr = simple_strtol (argv[1], NULL, 16);
234 printf("i2c probe looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
239 /* Abort if ctrl-c was pressed */
251 iploop, 2, 1, do_iploop,
252 "i2c probe loop <addr>",
258 int do_codec(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
262 out_be16((void *)0xe0000000, 0x4000);
264 udelay(5000); /* wait for 5ms */
269 i2c_write(0x10, 0, 0, buf, 3);
274 i2c_write(0x10, 0, 0, buf, 3);
279 i2c_write(0x10, 0, 0, buf, 3);
284 i2c_write(0x10, 0, 0, buf, 3);
289 i2c_write(0x10, 0, 0, buf, 3);
294 i2c_write(0x10, 0, 0, buf, 3);
299 i2c_write(0x10, 0, 0, buf, 3);
304 codec, 1, 1, do_codec,
311 int do_saa(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
324 addr = simple_strtol (argv[1], NULL, 16);
325 instr = simple_strtol (argv[2], NULL, 16);
326 cntrl = simple_strtol (argv[3], NULL, 16);
327 data = simple_strtol (argv[4], NULL, 16);
329 buf[0] = (uchar)instr;
330 buf[1] = (uchar)cntrl;
331 buf[2] = (uchar)data;
332 i2c_write(addr, 0, 0, buf, 3);
338 "Write to SAA1064 <addr> <instr> <cntrl> <data>",
344 int do_iwrite(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
359 addr = simple_strtol (argv[1], NULL, 16);
360 cnt = simple_strtol (argv[2], NULL, 16);
361 data0 = simple_strtol (argv[3], NULL, 16);
362 data1 = simple_strtol (argv[4], NULL, 16);
363 data2 = simple_strtol (argv[5], NULL, 16);
364 data3 = simple_strtol (argv[6], NULL, 16);
366 printf("Writing %d bytes to device %lx!\n", cnt, addr);
367 buf[0] = (uchar)data0;
368 buf[1] = (uchar)data1;
369 buf[2] = (uchar)data2;
370 buf[3] = (uchar)data3;
371 i2c_write(addr, 0, 0, buf, cnt);
376 iwrite, 6, 1, do_iwrite,
377 "Write n bytes to I2C-device",
378 "addr cnt data0 ... datan"
383 int do_iread(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
395 addr = simple_strtol (argv[1], NULL, 16);
396 cnt = simple_strtol (argv[2], NULL, 16);
398 i2c_read(addr, 0, 0, buf, cnt);
400 for (i=0; i<cnt; i++) {
401 printf(" %02X", buf[i]);
408 iread, 3, 1, do_iread,
409 "Read from I2C <addr> <cnt>",
415 int do_ireadl(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
426 addr = simple_strtol (argv[1], NULL, 16);
429 printf("iread looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
432 i2c_read(addr, 0, 0, buf, cnt);
434 /* Abort if ctrl-c was pressed */
446 ireadl, 2, 1, do_ireadl,
447 "Read-loop from I2C <addr>",