3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/m5249.h>
16 int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
17 int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
24 /* predefine these here for FPGA programming (before including fpga.c) */
25 #define SET_FPGA(data) mbar2_writeLong(MCFSIM_GPIO1_OUT, data)
26 #define FPGA_DONE_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_DONE)
27 #define FPGA_INIT_STATE (mbar2_readLong(MCFSIM_GPIO1_READ) & CONFIG_SYS_FPGA_INIT)
28 #define FPGA_PROG_ACTIVE_HIGH /* on this platform is PROG active high! */
29 #define out32(a,b) /* nothing to do (gpio already configured) */
32 /* fpga configuration data - generated by bin2cc */
33 const unsigned char fpgadata[] =
39 * include common fpga code (for esd boards)
41 #include "../common/fpga.c"
44 int checkboard (void) {
50 val8 = ((uchar)~((uchar)mbar2_readLong(MCFSIM_GPIO1_READ) >> 4)) & 0xf;
51 printf(" (Switch=%1X)\n", val8);
56 val = mbar2_readLong(MCFSIM_GPIO1_OUT) & ~CONFIG_SYS_GPIO1_LED;
57 mbar2_writeLong(MCFSIM_GPIO1_OUT, val); /* Set LED on */
63 phys_size_t initdram (int board_type) {
64 unsigned long junk = 0xa5a59696;
68 * RC = ([(RefreshTime/#rows) / (1/BusClk)] / 16) - 1
71 #ifdef CONFIG_SYS_FAST_CLK
73 * Busclk=70MHz, RefreshTime=64ms, #rows=4096 (4K)
74 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=39
76 mbar_writeShort(MCFSIM_DCR, 0x8239);
77 #elif CONFIG_SYS_PLL_BYPASS
79 * Busclk=5.6448MHz, RefreshTime=64ms, #rows=8192 (8K)
80 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=02
82 mbar_writeShort(MCFSIM_DCR, 0x8202);
85 * Busclk=36MHz, RefreshTime=64ms, #rows=4096 (4K)
86 * SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=22 (562 bus clock cycles)
88 mbar_writeShort(MCFSIM_DCR, 0x8222);
92 * SDRAM starts at 0x0000_0000, CASL=10, CBM=010, PS=10 (16bit port),
93 * PM=1 (continuous page mode)
96 /* RE=0 (keep auto-refresh disabled while setting up registers) */
97 mbar_writeLong(MCFSIM_DACR0, 0x00003324);
99 /* BAM=007c (bits 22,21 are bank selects; 256kB blocks) */
100 mbar_writeLong(MCFSIM_DMR0, 0x01fc0001);
102 /** Precharge sequence **/
103 mbar_writeLong(MCFSIM_DACR0, 0x0000332c); /* Set DACR0[IP] (bit 3) */
104 out_be32((void *)0, junk); /* write to a memory location to init. precharge */
105 udelay(0x10); /* Allow several Precharge cycles */
107 /** Refresh Sequence **/
108 mbar_writeLong(MCFSIM_DACR0, 0x0000b324); /* Enable the refresh bit, DACR0[RE] (bit 15) */
109 udelay(0x7d0); /* Allow gobs of refresh cycles */
111 /** Mode Register initialization **/
112 mbar_writeLong(MCFSIM_DACR0, 0x0000b364); /* Enable DACR0[IMRS] (bit 6); RE remains enabled */
113 out_be32((void *)0x800, junk); /* Access RAM to initialize the mode register */
115 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
119 int testdram (void) {
120 /* TODO: XXX XXX XXX */
121 printf ("DRAM test not implemented!\n");
127 int misc_init_r (void)
130 ulong len = sizeof(fpgadata);
136 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
137 if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
138 printf ("GUNZIP ERROR - must RESET board to recover\n");
139 do_reset (NULL, 0, 0, NULL);
142 status = fpga_boot(dst, len);
144 printf("\nFPGA: Booting failed ");
146 case ERROR_FPGA_PRG_INIT_LOW:
147 printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
149 case ERROR_FPGA_PRG_INIT_HIGH:
150 printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
152 case ERROR_FPGA_PRG_DONE:
153 printf("(Timeout: DONE not high after programming FPGA)\n ");
157 /* display infos on fpgaimage */
159 for (i=0; i<4; i++) {
161 printf("FPGA: %s\n", &(dst[index+1]));
166 for (i=20; i>0; i--) {
167 printf("Rebooting in %2d seconds \r",i);
168 for (index=0;index<1000;index++)
172 do_reset(NULL, 0, 0, NULL);
177 /* display infos on fpgaimage */
179 for (i=0; i<4; i++) {
181 printf("%s ", &(dst[index+1]));
194 i2c_write(0x38, 0, 0, buf, 3);
200 #if 1 /* test-only: board specific test commands */
201 int i2c_probe(uchar addr);
205 int do_iploop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
214 addr = simple_strtol (argv[1], NULL, 16);
216 printf("i2c probe looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
221 /* Abort if ctrl-c was pressed */
233 iploop, 2, 1, do_iploop,
234 "i2c probe loop <addr>",
240 int do_codec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
244 out_be16((void *)0xe0000000, 0x4000);
246 udelay(5000); /* wait for 5ms */
251 i2c_write(0x10, 0, 0, buf, 3);
256 i2c_write(0x10, 0, 0, buf, 3);
261 i2c_write(0x10, 0, 0, buf, 3);
266 i2c_write(0x10, 0, 0, buf, 3);
271 i2c_write(0x10, 0, 0, buf, 3);
276 i2c_write(0x10, 0, 0, buf, 3);
281 i2c_write(0x10, 0, 0, buf, 3);
286 codec, 1, 1, do_codec,
293 int do_saa(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
306 addr = simple_strtol (argv[1], NULL, 16);
307 instr = simple_strtol (argv[2], NULL, 16);
308 cntrl = simple_strtol (argv[3], NULL, 16);
309 data = simple_strtol (argv[4], NULL, 16);
311 buf[0] = (uchar)instr;
312 buf[1] = (uchar)cntrl;
313 buf[2] = (uchar)data;
314 i2c_write(addr, 0, 0, buf, 3);
320 "Write to SAA1064 <addr> <instr> <cntrl> <data>",
326 int do_iwrite(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
341 addr = simple_strtol (argv[1], NULL, 16);
342 cnt = simple_strtol (argv[2], NULL, 16);
343 data0 = simple_strtol (argv[3], NULL, 16);
344 data1 = simple_strtol (argv[4], NULL, 16);
345 data2 = simple_strtol (argv[5], NULL, 16);
346 data3 = simple_strtol (argv[6], NULL, 16);
348 printf("Writing %d bytes to device %lx!\n", cnt, addr);
349 buf[0] = (uchar)data0;
350 buf[1] = (uchar)data1;
351 buf[2] = (uchar)data2;
352 buf[3] = (uchar)data3;
353 i2c_write(addr, 0, 0, buf, cnt);
358 iwrite, 6, 1, do_iwrite,
359 "Write n bytes to I2C-device",
360 "addr cnt data0 ... datan"
365 int do_iread(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
377 addr = simple_strtol (argv[1], NULL, 16);
378 cnt = simple_strtol (argv[2], NULL, 16);
380 i2c_read(addr, 0, 0, buf, cnt);
382 for (i=0; i<cnt; i++) {
383 printf(" %02X", buf[i]);
390 iread, 3, 1, do_iread,
391 "Read from I2C <addr> <cnt>",
397 int do_ireadl(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
408 addr = simple_strtol (argv[1], NULL, 16);
411 printf("iread looping on addr 0x%lx (cntrl-c aborts)...\n", addr);
414 i2c_read(addr, 0, 0, buf, cnt);
416 /* Abort if ctrl-c was pressed */
428 ireadl, 2, 1, do_ireadl,
429 "Read-loop from I2C <addr>",