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)
39 extern ulong
ifx_get_ddr_hz(void);
40 extern ulong
ifx_get_cpuclk(void);
42 /* definitions for external PHYs / Switches */
43 /* Split values into phy address and register address */
44 #define PHYADDR(_reg) ((_reg >> 5) & 0xff), (_reg & 0x1f)
46 /* IDs and registers of known external switches */
47 #define ID_SAMURAI_0 0x1020
48 #define ID_SAMURAI_1 0x0007
49 #define SAMURAI_ID_REG0 0xA0
50 #define SAMURAI_ID_REG1 0xA1
52 #define ID_TANTOS 0x2599
54 void _machine_restart(void)
56 *DANUBE_RCU_RST_REQ
|=1<<30;
59 #ifdef CONFIG_SYS_RAMBOOT
60 phys_size_t
initdram(int board_type
)
62 return get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
, CONFIG_SYS_MAX_RAM
);
64 #elif defined(CONFIG_USE_DDR_RAM)
65 phys_size_t
initdram(int board_type
)
67 return (CONFIG_SYS_MAX_RAM
);
71 static ulong
max_sdram_size(void) /* per Chip Select */
73 /* The only supported SDRAM data width is 16bit.
77 /* The only supported number of SDRAM banks is 4.
81 ulong cfgpb0
= *DANUBE_SDRAM_MC_CFGPB0
;
82 int cols
= cfgpb0
& 0xF;
83 int rows
= (cfgpb0
& 0xF0) >> 4;
84 ulong size
= (1 << (rows
+ cols
)) * CFG_DW
* CFG_NB
;
90 * Check memory range for valid RAM. A simple memory test determines
91 * the actually available RAM size between addresses `base' and
95 static long int dram_size(long int *base
, long int maxsize
)
97 volatile long int *addr
;
99 ulong save
[32]; /* to make test non-destructive */
102 for (cnt
= (maxsize
/ sizeof (long)) >> 1; cnt
> 0; cnt
>>= 1) {
103 addr
= base
+ cnt
; /* pointer arith! */
109 /* write 0 to base address */
114 /* check at base address */
115 if ((val
= *addr
) != 0) {
120 for (cnt
= 1; cnt
< maxsize
/ sizeof (long); cnt
<<= 1) {
121 addr
= base
+ cnt
; /* pointer arith! */
127 return (cnt
* sizeof (long));
133 phys_size_t
initdram(int board_type
)
135 int rows
, cols
, best_val
= *DANUBE_SDRAM_MC_CFGPB0
;
136 ulong size
, max_size
= 0;
139 /* load t9 into our_address */
140 asm volatile ("move %0, $25" : "=r" (our_address
) :);
142 /* Can't probe for RAM size unless we are running from Flash.
143 * find out whether running from DRAM or Flash.
145 if (CPHYSADDR(our_address
) < CPHYSADDR(PHYS_FLASH_1
))
147 return max_sdram_size();
150 for (cols
= 0x8; cols
<= 0xC; cols
++)
152 for (rows
= 0xB; rows
<= 0xD; rows
++)
154 *DANUBE_SDRAM_MC_CFGPB0
= (0x14 << 8) |
156 size
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
,
161 best_val
= *DANUBE_SDRAM_MC_CFGPB0
;
167 *DANUBE_SDRAM_MC_CFGPB0
= best_val
;
172 int checkboard (void)
174 unsigned long chipid
= *DANUBE_MPS_CHIPID
;
179 part_num
= DANUBE_MPS_CHIPID_PARTNUM_GET(chipid
);
184 puts("Danube/Twinpass/Vinax-VE ");
187 printf ("unknown, chip part number 0x%03X ", part_num
);
190 printf ("V1.%ld, ", DANUBE_MPS_CHIPID_VERSION_GET(chipid
));
192 printf("DDR Speed %ld MHz, ", ifx_get_ddr_hz()/1000000);
193 printf("CPU Speed %ld MHz\n", ifx_get_cpuclk()/1000000);
198 #ifdef CONFIG_SKIP_LOWLEVEL_INIT
199 int board_early_init_f(void)
201 #ifdef CONFIG_EBU_ADDSEL0
202 (*DANUBE_EBU_ADDSEL0
) = CONFIG_EBU_ADDSEL0
;
204 #ifdef CONFIG_EBU_ADDSEL1
205 (*DANUBE_EBU_ADDSEL1
) = CONFIG_EBU_ADDSEL1
;
207 #ifdef CONFIG_EBU_ADDSEL2
208 (*DANUBE_EBU_ADDSEL2
) = CONFIG_EBU_ADDSEL2
;
210 #ifdef CONFIG_EBU_ADDSEL3
211 (*DANUBE_EBU_ADDSEL3
) = CONFIG_EBU_ADDSEL3
;
213 #ifdef CONFIG_EBU_BUSCON0
214 (*DANUBE_EBU_BUSCON0
) = CONFIG_EBU_BUSCON0
;
216 #ifdef CONFIG_EBU_BUSCON1
217 (*DANUBE_EBU_BUSCON1
) = CONFIG_EBU_BUSCON1
;
219 #ifdef CONFIG_EBU_BUSCON2
220 (*DANUBE_EBU_BUSCON2
) = CONFIG_EBU_BUSCON2
;
222 #ifdef CONFIG_EBU_BUSCON3
223 (*DANUBE_EBU_BUSCON3
) = CONFIG_EBU_BUSCON3
;
228 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
230 #ifdef CONFIG_EXTRA_SWITCH
231 static int external_switch_init(void)
233 unsigned short chipid0
=0xdead, chipid1
=0xbeef;
234 static char * const name
= "lq_cpe_eth";
236 #ifdef CLK_OUT2_25MHZ
237 *DANUBE_GPIO_P0_DIR
=0x0000ae78;
238 *DANUBE_GPIO_P0_ALTSEL0
=0x00008078;
239 //joelin for Mii-1 *DANUBE_GPIO_P0_ALTSEL1=0x80000080;
240 *DANUBE_GPIO_P0_ALTSEL1
=0x80000000; //joelin for Mii-1
241 *DANUBE_CGU_IFCCR
=0x00400010;
242 *DANUBE_GPIO_P0_OD
=0x0000ae78;
245 /* earlier no valid response is available, at least on Twinpass & Tantos @ 111MHz, M4530 platform */
248 debug("\nsearching for Samurai switch ... ");
249 if ( (miiphy_read(name
, PHYADDR(SAMURAI_ID_REG0
), &chipid0
)==0) &&
250 (miiphy_read(name
, PHYADDR(SAMURAI_ID_REG1
), &chipid1
)==0) ) {
251 if (((chipid0
& 0xFFF0) == ID_SAMURAI_0
) &&
252 ((chipid1
& 0x000F) == ID_SAMURAI_1
)) {
255 /* enable "Crossover Auto Detect" + defaults */
257 miiphy_write(name
, PHYADDR(0x01), 0x840F);
259 miiphy_write(name
, PHYADDR(0x03), 0x840F);
261 miiphy_write(name
, PHYADDR(0x05), 0x840F);
263 miiphy_write(name
, PHYADDR(0x07), 0x840F);
265 miiphy_write(name
, PHYADDR(0x08), 0x840F);
267 miiphy_write(name
, PHYADDR(0x09), 0x840F);
268 /* System Control 4: CPU on port 1 and other */
269 miiphy_write(name
, PHYADDR(0x12), 0x3602);
270 #ifdef CLK_OUT2_25MHZ
271 /* Bandwidth Control Enable Register: enable */
272 miiphy_write(name
, PHYADDR(0x33), 0x4000);
277 debug("\nsearching for TANTOS switch ... ");
278 if (miiphy_read(name
, PHYADDR(0x101), &chipid0
) == 0) {
279 if (chipid0
== ID_TANTOS
) {
282 /* P5 Basic Control: Force Link Up */
283 miiphy_write(name
, PHYADDR(0xA1), 0x0004);
284 /* P6 Basic Control: Force Link Up */
285 miiphy_write(name
, PHYADDR(0xC1), 0x0004);
286 /* RGMII/MII Port Control (P4/5/6) */
287 miiphy_write(name
, PHYADDR(0xF5), 0x0773);
289 /* Software workaround. */
290 /* PHY reset from P0 to P4. */
292 /* set data for indirect write */
293 miiphy_write(name
, PHYADDR(0x121), 0x8000);
296 miiphy_write(name
, PHYADDR(0x120), 0x0400);
299 miiphy_write(name
, PHYADDR(0x120), 0x0420);
302 miiphy_write(name
, PHYADDR(0x120), 0x0440);
305 miiphy_write(name
, PHYADDR(0x120), 0x0460);
308 miiphy_write(name
, PHYADDR(0x120), 0x0480);
316 #endif /* CONFIG_EXTRA_SWITCH */
318 int board_eth_init(bd_t
*bis
)
320 #if defined(CONFIG_IFX_ETOP)
322 *DANUBE_PMU_PWDCR
&= 0xFFFFEFDF;
323 *DANUBE_PMU_PWDCR
&=~(1<<DANUBE_PMU_DMA_SHIFT
);/*enable DMA from PMU*/
325 if (lq_eth_initialize(bis
)<0)
328 *DANUBE_RCU_RST_REQ
|=1;
330 *DANUBE_RCU_RST_REQ
&=(unsigned long)~1;
333 #ifdef CONFIG_EXTRA_SWITCH
334 if (external_switch_init()<0)
336 #endif /* CONFIG_EXTRA_SWITCH */
337 #endif /* CONFIG_IFX_ETOP */
342 #if defined(CONFIG_CMD_HTTPD)
343 int do_http_upgrade(const unsigned char *data
, const ulong size
)
347 if(getenv ("ram_addr") == NULL
)
349 if(getenv ("kernel_addr") == NULL
)
351 /* check the image */
352 if(run_command("imi ${ram_addr}", 0) < 0) {
355 /* write the image to the flash */
356 puts("http ugrade ...\n");
357 sprintf(buf
, "era ${kernel_addr} +0x%x; cp.b ${ram_addr} ${kernel_addr} 0x%x", size
, size
);
358 return run_command(buf
, 0);
361 int do_http_progress(const int state
)
363 /* toggle LED's here */
365 case HTTP_PROGRESS_START
:
366 puts("http start\n");
368 case HTTP_PROGRESS_TIMEOUT
:
371 case HTTP_PROGRESS_UPLOAD_READY
:
372 puts("http upload ready\n");
374 case HTTP_PROGRESS_UGRADE_READY
:
375 puts("http ugrade ready\n");
377 case HTTP_PROGRESS_UGRADE_FAILED
:
378 puts("http ugrade failed\n");
384 unsigned long do_http_tmp_address(void)
386 char *s
= getenv ("ram_addr");
388 ulong tmp
= simple_strtoul (s
, NULL
, 16);
391 return 0 /*0x80a00000*/;