3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Thomas Langer, Ralph Hempel
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include <asm/addrspace.h>
32 #include <asm/danube.h>
33 #include <asm/reboot.h>
35 #if defined(CONFIG_CMD_HTTPD)
38 #if defined(CONFIG_PCI)
42 extern ulong
ifx_get_ddr_hz(void);
43 extern ulong
ifx_get_cpuclk(void);
45 /* IDs and registers of known external switches */
46 #define ID_RTL8306 0x5988
47 #define CONFIG_EXTRA_SWITCH 1
48 void _machine_restart(void)
50 *DANUBE_RCU_RST_REQ
|=1<<30;
53 #ifdef CONFIG_SYS_RAMBOOT
54 phys_size_t
initdram(int board_type
)
56 return get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
, CONFIG_SYS_MAX_RAM
);
58 #elif defined(CONFIG_USE_DDR_RAM)
59 phys_size_t
initdram(int board_type
)
61 return (CONFIG_SYS_MAX_RAM
);
65 static ulong
max_sdram_size(void) /* per Chip Select */
67 /* The only supported SDRAM data width is 16bit.
71 /* The only supported number of SDRAM banks is 4.
75 ulong cfgpb0
= *DANUBE_SDRAM_MC_CFGPB0
;
76 int cols
= cfgpb0
& 0xF;
77 int rows
= (cfgpb0
& 0xF0) >> 4;
78 ulong size
= (1 << (rows
+ cols
)) * CFG_DW
* CFG_NB
;
84 * Check memory range for valid RAM. A simple memory test determines
85 * the actually available RAM size between addresses `base' and
89 static long int dram_size(long int *base
, long int maxsize
)
91 volatile long int *addr
;
93 ulong save
[32]; /* to make test non-destructive */
96 for (cnt
= (maxsize
/ sizeof (long)) >> 1; cnt
> 0; cnt
>>= 1) {
97 addr
= base
+ cnt
; /* pointer arith! */
103 /* write 0 to base address */
108 /* check at base address */
109 if ((val
= *addr
) != 0) {
114 for (cnt
= 1; cnt
< maxsize
/ sizeof (long); cnt
<<= 1) {
115 addr
= base
+ cnt
; /* pointer arith! */
121 return (cnt
* sizeof (long));
127 phys_size_t
initdram(int board_type
)
129 int rows
, cols
, best_val
= *DANUBE_SDRAM_MC_CFGPB0
;
130 ulong size
, max_size
= 0;
133 /* load t9 into our_address */
134 asm volatile ("move %0, $25" : "=r" (our_address
) :);
136 /* Can't probe for RAM size unless we are running from Flash.
137 * find out whether running from DRAM or Flash.
139 if (CPHYSADDR(our_address
) < CPHYSADDR(PHYS_FLASH_1
))
141 return max_sdram_size();
144 for (cols
= 0x8; cols
<= 0xC; cols
++)
146 for (rows
= 0xB; rows
<= 0xD; rows
++)
148 *DANUBE_SDRAM_MC_CFGPB0
= (0x14 << 8) |
150 size
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
,
155 best_val
= *DANUBE_SDRAM_MC_CFGPB0
;
161 *DANUBE_SDRAM_MC_CFGPB0
= best_val
;
166 int checkboard (void)
168 unsigned long chipid
= *DANUBE_MPS_CHIPID
;
173 part_num
= DANUBE_MPS_CHIPID_PARTNUM_GET(chipid
);
179 puts("Danube/Twinpass/Vinax-VE ");
182 printf ("unknown, chip part number 0x%03X ", part_num
);
185 printf ("V1.%ld, ", DANUBE_MPS_CHIPID_VERSION_GET(chipid
));
187 printf("DDR Speed %ld MHz, ", ifx_get_ddr_hz()/1000000);
188 printf("CPU Speed %ld MHz\n", ifx_get_cpuclk()/1000000);
193 #ifdef CONFIG_SKIP_LOWLEVEL_INIT
194 int board_early_init_f(void)
196 #ifdef CONFIG_EBU_ADDSEL0
197 (*DANUBE_EBU_ADDSEL0
) = CONFIG_EBU_ADDSEL0
;
199 #ifdef CONFIG_EBU_ADDSEL1
200 (*DANUBE_EBU_ADDSEL1
) = CONFIG_EBU_ADDSEL1
;
202 #ifdef CONFIG_EBU_ADDSEL2
203 (*DANUBE_EBU_ADDSEL2
) = CONFIG_EBU_ADDSEL2
;
205 #ifdef CONFIG_EBU_ADDSEL3
206 (*DANUBE_EBU_ADDSEL3
) = CONFIG_EBU_ADDSEL3
;
208 #ifdef CONFIG_EBU_BUSCON0
209 (*DANUBE_EBU_BUSCON0
) = CONFIG_EBU_BUSCON0
;
211 #ifdef CONFIG_EBU_BUSCON1
212 (*DANUBE_EBU_BUSCON1
) = CONFIG_EBU_BUSCON1
;
214 #ifdef CONFIG_EBU_BUSCON2
215 (*DANUBE_EBU_BUSCON2
) = CONFIG_EBU_BUSCON2
;
217 #ifdef CONFIG_EBU_BUSCON3
218 (*DANUBE_EBU_BUSCON3
) = CONFIG_EBU_BUSCON3
;
223 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
226 #ifdef CONFIG_EXTRA_SWITCH
227 static int external_switch_init(void)
229 unsigned short chipid
;
230 static char * const name
= "lq_cpe_eth";
232 /* earlier no valid response is available, at least on Twinpass & Tantos @ 111MHz, M4530 platform */
235 puts("\nsearching for rtl8306 switch ... ");
236 if (miiphy_read(name
, 4, 30, &chipid
) == 0) {
238 if (chipid
== ID_RTL8306
) {
241 miiphy_write(name
, 0, 19, 0xffff);
243 miiphy_write(name
, 4, 22, 0x877f);
249 puts("\nno known switch found ... \n");
253 #endif /* CONFIG_EXTRA_SWITCH */
255 int board_eth_init(bd_t
*bis
)
257 #if defined(CONFIG_IFX_ETOP)
259 if (!eth_getenv_enetaddr("ethaddr", enetaddr
))
260 eth_setenv_enetaddr("ethaddr", (uchar
*)0xb03f0016);
262 *DANUBE_PMU_PWDCR
&= 0xFFFFEFDF;
263 *DANUBE_PMU_PWDCR
&=~(1<<DANUBE_PMU_DMA_SHIFT
);/*enable DMA from PMU*/
265 if (lq_eth_initialize(bis
))
268 *DANUBE_RCU_RST_REQ
|=1;
270 *DANUBE_RCU_RST_REQ
&=(unsigned long)~1;
273 #ifdef CONFIG_EXTRA_SWITCH
274 if (external_switch_init()<0)
276 #endif /* CONFIG_EXTRA_SWITCH */
277 #endif /* CONFIG_IFX_ETOP */
282 #if defined(CONFIG_CMD_HTTPD)
283 int do_http_upgrade(const unsigned char *data
, const ulong size
)
287 if(getenv ("ram_addr") == NULL
)
289 if(getenv ("kernel_addr") == NULL
)
291 /* check the image */
292 if(run_command("imi ${ram_addr}", 0) < 0) {
295 /* write the image to the flash */
296 puts("http ugrade ...\n");
297 sprintf(buf
, "era ${kernel_addr} +0x%lx; cp.b ${ram_addr} ${kernel_addr} 0x%lx", size
, size
);
298 return run_command(buf
, 0);
301 int do_http_progress(const int state
)
303 /* toggle LED's here */
305 case HTTP_PROGRESS_START
:
306 puts("http start\n");
308 case HTTP_PROGRESS_TIMEOUT
:
311 case HTTP_PROGRESS_UPLOAD_READY
:
312 puts("http upload ready\n");
314 case HTTP_PROGRESS_UGRADE_READY
:
315 puts("http ugrade ready\n");
317 case HTTP_PROGRESS_UGRADE_FAILED
:
318 puts("http ugrade failed\n");
324 unsigned long do_http_tmp_address(void)
326 char *s
= getenv ("ram_addr");
328 ulong tmp
= simple_strtoul (s
, NULL
, 16);
331 return 0 /*0x80a00000*/;