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
);
185 puts("Danube/Twinpass/Vinax-VE ");
188 printf ("unknown, chip part number 0x%03X ", part_num
);
191 printf ("V1.%ld, ", DANUBE_MPS_CHIPID_VERSION_GET(chipid
));
193 printf("DDR Speed %ld MHz, ", ifx_get_ddr_hz()/1000000);
194 printf("CPU Speed %ld MHz\n", ifx_get_cpuclk()/1000000);
199 #ifdef CONFIG_SKIP_LOWLEVEL_INIT
200 int board_early_init_f(void)
202 #ifdef CONFIG_EBU_ADDSEL0
203 (*DANUBE_EBU_ADDSEL0
) = CONFIG_EBU_ADDSEL0
;
205 #ifdef CONFIG_EBU_ADDSEL1
206 (*DANUBE_EBU_ADDSEL1
) = CONFIG_EBU_ADDSEL1
;
208 #ifdef CONFIG_EBU_ADDSEL2
209 (*DANUBE_EBU_ADDSEL2
) = CONFIG_EBU_ADDSEL2
;
211 #ifdef CONFIG_EBU_ADDSEL3
212 (*DANUBE_EBU_ADDSEL3
) = CONFIG_EBU_ADDSEL3
;
214 #ifdef CONFIG_EBU_BUSCON0
215 (*DANUBE_EBU_BUSCON0
) = CONFIG_EBU_BUSCON0
;
217 #ifdef CONFIG_EBU_BUSCON1
218 (*DANUBE_EBU_BUSCON1
) = CONFIG_EBU_BUSCON1
;
220 #ifdef CONFIG_EBU_BUSCON2
221 (*DANUBE_EBU_BUSCON2
) = CONFIG_EBU_BUSCON2
;
223 #ifdef CONFIG_EBU_BUSCON3
224 (*DANUBE_EBU_BUSCON3
) = CONFIG_EBU_BUSCON3
;
229 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
231 #ifdef CONFIG_EXTRA_SWITCH
232 static int external_switch_init(void)
234 unsigned short chipid0
=0xdead, chipid1
=0xbeef;
235 static char * const name
= "lq_cpe_eth";
237 #ifdef CONFIG_SWITCH_PORT0
238 *DANUBE_GPIO_P0_ALTSEL0
&= ~(1<<CONFIG_SWITCH_PIN
);
239 *DANUBE_GPIO_P0_ALTSEL1
&= ~(1<<CONFIG_SWITCH_PIN
);
240 *DANUBE_GPIO_P0_OD
|= (1<<CONFIG_SWITCH_PIN
);
241 *DANUBE_GPIO_P0_DIR
|= (1<<CONFIG_SWITCH_PIN
);
242 *DANUBE_GPIO_P0_OUT
|= (1<<CONFIG_SWITCH_PIN
);
243 #elif defined(CONFIG_SWITCH_PORT1)
244 *DANUBE_GPIO_P1_ALTSEL0
&= ~(1<<CONFIG_SWITCH_PIN
);
245 *DANUBE_GPIO_P1_ALTSEL1
&= ~(1<<CONFIG_SWITCH_PIN
);
246 *DANUBE_GPIO_P1_OD
|= (1<<CONFIG_SWITCH_PIN
);
247 *DANUBE_GPIO_P1_DIR
|= (1<<CONFIG_SWITCH_PIN
);
248 *DANUBE_GPIO_P1_OUT
|= (1<<CONFIG_SWITCH_PIN
);
250 #ifdef CLK_OUT2_25MHZ
251 *DANUBE_GPIO_P0_DIR
=0x0000ae78;
252 *DANUBE_GPIO_P0_ALTSEL0
=0x00008078;
253 //joelin for Mii-1 *DANUBE_GPIO_P0_ALTSEL1=0x80000080;
254 *DANUBE_GPIO_P0_ALTSEL1
=0x80000000; //joelin for Mii-1
255 *DANUBE_CGU_IFCCR
=0x00400010;
256 *DANUBE_GPIO_P0_OD
=0x0000ae78;
259 /* earlier no valid response is available, at least on Twinpass & Tantos @ 111MHz, M4530 platform */
262 debug("\nsearching for Samurai switch ... ");
263 if ( (miiphy_read(name
, PHYADDR(SAMURAI_ID_REG0
), &chipid0
)==0) &&
264 (miiphy_read(name
, PHYADDR(SAMURAI_ID_REG1
), &chipid1
)==0) ) {
265 if (((chipid0
& 0xFFF0) == ID_SAMURAI_0
) &&
266 ((chipid1
& 0x000F) == ID_SAMURAI_1
)) {
269 /* enable "Crossover Auto Detect" + defaults */
271 miiphy_write(name
, PHYADDR(0x01), 0x840F);
273 miiphy_write(name
, PHYADDR(0x03), 0x840F);
275 miiphy_write(name
, PHYADDR(0x05), 0x840F);
277 miiphy_write(name
, PHYADDR(0x07), 0x840F);
279 miiphy_write(name
, PHYADDR(0x08), 0x840F);
281 miiphy_write(name
, PHYADDR(0x09), 0x840F);
282 /* System Control 4: CPU on port 1 and other */
283 miiphy_write(name
, PHYADDR(0x12), 0x3602);
284 #ifdef CLK_OUT2_25MHZ
285 /* Bandwidth Control Enable Register: enable */
286 miiphy_write(name
, PHYADDR(0x33), 0x4000);
291 debug("\nsearching for TANTOS switch ... ");
292 if (miiphy_read(name
, PHYADDR(0x101), &chipid0
) == 0) {
293 if (chipid0
== ID_TANTOS
) {
296 /* P5 Basic Control: Force Link Up */
297 miiphy_write(name
, PHYADDR(0xA1), 0x0004);
298 /* P6 Basic Control: Force Link Up */
299 miiphy_write(name
, PHYADDR(0xC1), 0x0004);
300 /* RGMII/MII Port Control (P4/5/6) */
301 miiphy_write(name
, PHYADDR(0xF5), 0x0773);
303 /* Software workaround. */
304 /* PHY reset from P0 to P4. */
306 /* set data for indirect write */
307 miiphy_write(name
, PHYADDR(0x121), 0x8000);
310 miiphy_write(name
, PHYADDR(0x120), 0x0400);
313 miiphy_write(name
, PHYADDR(0x120), 0x0420);
316 miiphy_write(name
, PHYADDR(0x120), 0x0440);
319 miiphy_write(name
, PHYADDR(0x120), 0x0460);
322 miiphy_write(name
, PHYADDR(0x120), 0x0480);
330 #endif /* CONFIG_EXTRA_SWITCH */
332 int board_gpio_init(void)
334 #ifdef CONFIG_BUTTON_PORT0
335 *DANUBE_GPIO_P0_ALTSEL0
&= ~(1<<CONFIG_BUTTON_PIN
);
336 *DANUBE_GPIO_P0_ALTSEL1
&= ~(1<<CONFIG_BUTTON_PIN
);
337 *DANUBE_GPIO_P0_DIR
&= ~(1<<CONFIG_BUTTON_PIN
);
338 if(!!(*DANUBE_GPIO_P0_IN
& (1<<CONFIG_BUTTON_PIN
)) == CONFIG_BUTTON_LEVEL
)
340 printf("button is pressed\n");
341 setenv("bootdelay", "0");
342 setenv("bootcmd", "httpd");
344 #elif defined(CONFIG_BUTTON_PORT1)
345 *DANUBE_GPIO_P1_ALTSEL0
&= ~(1<<CONFIG_BUTTON_PIN
);
346 *DANUBE_GPIO_P1_ALTSEL1
&= ~(1<<CONFIG_BUTTON_PIN
);
347 *DANUBE_GPIO_P1_DIR
&= ~(1<<CONFIG_BUTTON_PIN
);
348 if(!!(*DANUBE_GPIO_P1_IN
& (1<<CONFIG_BUTTON_PIN
)) == CONFIG_BUTTON_LEVEL
)
350 printf("button is pressed\n");
351 setenv("bootdelay", "0");
352 setenv("bootcmd", "httpd");
357 int board_eth_init(bd_t
*bis
)
362 #if defined(CONFIG_IFX_ETOP)
364 *DANUBE_PMU_PWDCR
&= 0xFFFFEFDF;
365 *DANUBE_PMU_PWDCR
&=~(1<<DANUBE_PMU_DMA_SHIFT
);/*enable DMA from PMU*/
367 if (lq_eth_initialize(bis
)<0)
370 *DANUBE_RCU_RST_REQ
|=1;
372 *DANUBE_RCU_RST_REQ
&=(unsigned long)~1;
375 #ifdef CONFIG_EXTRA_SWITCH
376 if (external_switch_init()<0)
378 #endif /* CONFIG_EXTRA_SWITCH */
379 #endif /* CONFIG_IFX_ETOP */
384 #if defined(CONFIG_CMD_HTTPD)
385 int do_http_upgrade(const unsigned char *data
, const ulong size
)
389 if(getenv ("ram_addr") == NULL
)
391 if(getenv ("kernel_addr") == NULL
)
393 /* check the image */
394 if(run_command("imi ${ram_addr}", 0) < 0) {
397 /* write the image to the flash */
398 puts("http ugrade ...\n");
399 sprintf(buf
, "era ${kernel_addr} +0x%x; cp.b ${ram_addr} ${kernel_addr} 0x%x", size
, size
);
400 return run_command(buf
, 0);
403 int do_http_progress(const int state
)
405 /* toggle LED's here */
407 case HTTP_PROGRESS_START
:
408 puts("http start\n");
410 case HTTP_PROGRESS_TIMEOUT
:
413 case HTTP_PROGRESS_UPLOAD_READY
:
414 puts("http upload ready\n");
416 case HTTP_PROGRESS_UGRADE_READY
:
417 puts("http ugrade ready\n");
419 case HTTP_PROGRESS_UGRADE_FAILED
:
420 puts("http ugrade failed\n");
426 unsigned long do_http_tmp_address(void)
428 char *s
= getenv ("ram_addr");
430 ulong tmp
= simple_strtoul (s
, NULL
, 16);
433 return 0 /*0x80a00000*/;