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)
41 #if defined(CONFIG_AR8216_SWITCH)
42 #include "athrs26_phy.h"
45 extern ulong ifx_get_ddr_hz(void);
46 extern ulong ifx_get_cpuclk(void);
48 /* IDs and registers of known external switches */
49 void _machine_restart(void)
51 *DANUBE_RCU_RST_REQ |=1<<30;
54 #ifdef CONFIG_SYS_RAMBOOT
55 phys_size_t initdram(int board_type)
57 return get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_MAX_RAM);
59 #elif defined(CONFIG_USE_DDR_RAM)
60 phys_size_t initdram(int board_type)
62 return (CONFIG_SYS_MAX_RAM);
66 static ulong max_sdram_size(void) /* per Chip Select */
68 /* The only supported SDRAM data width is 16bit.
72 /* The only supported number of SDRAM banks is 4.
76 ulong cfgpb0 = *DANUBE_SDRAM_MC_CFGPB0;
77 int cols = cfgpb0 & 0xF;
78 int rows = (cfgpb0 & 0xF0) >> 4;
79 ulong size = (1 << (rows + cols)) * CFG_DW * CFG_NB;
85 * Check memory range for valid RAM. A simple memory test determines
86 * the actually available RAM size between addresses `base' and
90 static long int dram_size(long int *base, long int maxsize)
92 volatile long int *addr;
94 ulong save[32]; /* to make test non-destructive */
97 for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
98 addr = base + cnt; /* pointer arith! */
104 /* write 0 to base address */
109 /* check at base address */
110 if ((val = *addr) != 0) {
115 for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
116 addr = base + cnt; /* pointer arith! */
122 return (cnt * sizeof (long));
128 phys_size_t initdram(int board_type)
130 int rows, cols, best_val = *DANUBE_SDRAM_MC_CFGPB0;
131 ulong size, max_size = 0;
134 /* load t9 into our_address */
135 asm volatile ("move %0, $25" : "=r" (our_address) :);
137 /* Can't probe for RAM size unless we are running from Flash.
138 * find out whether running from DRAM or Flash.
140 if (CPHYSADDR(our_address) < CPHYSADDR(PHYS_FLASH_1))
142 return max_sdram_size();
145 for (cols = 0x8; cols <= 0xC; cols++)
147 for (rows = 0xB; rows <= 0xD; rows++)
149 *DANUBE_SDRAM_MC_CFGPB0 = (0x14 << 8) |
151 size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
156 best_val = *DANUBE_SDRAM_MC_CFGPB0;
162 *DANUBE_SDRAM_MC_CFGPB0 = best_val;
167 static void gpio_default(void)
169 #ifdef CONFIG_SWITCH_PORT0
170 *DANUBE_GPIO_P0_ALTSEL0 &= ~(1<<CONFIG_SWITCH_PIN);
171 *DANUBE_GPIO_P0_ALTSEL1 &= ~(1<<CONFIG_SWITCH_PIN);
172 *DANUBE_GPIO_P0_OD |= (1<<CONFIG_SWITCH_PIN);
173 *DANUBE_GPIO_P0_DIR |= (1<<CONFIG_SWITCH_PIN);
174 *DANUBE_GPIO_P0_OUT |= (1<<CONFIG_SWITCH_PIN);
175 #elif defined(CONFIG_SWITCH_PORT1)
176 *DANUBE_GPIO_P1_ALTSEL0 &= ~(1<<CONFIG_SWITCH_PIN);
177 *DANUBE_GPIO_P1_ALTSEL1 &= ~(1<<CONFIG_SWITCH_PIN);
178 *DANUBE_GPIO_P1_OD |= (1<<CONFIG_SWITCH_PIN);
179 *DANUBE_GPIO_P1_DIR |= (1<<CONFIG_SWITCH_PIN);
180 *DANUBE_GPIO_P1_OUT |= (1<<CONFIG_SWITCH_PIN);
182 #ifdef CONFIG_EBU_GPIO
185 printf ("bring up ebu gpio\n");
186 *DANUBE_EBU_BUSCON1 = 0x1e7ff;
187 *DANUBE_EBU_ADDSEL1 = 0x14000001;
189 *((volatile u16*)0xb4000000) = 0x0;
190 for(i = 0; i < 1000; i++)
192 *((volatile u16*)0xb4000000) = CONFIG_EBU_GPIO;
193 *DANUBE_EBU_BUSCON1 = 0x8001e7ff;
196 #ifdef CONFIG_BUTTON_PORT0
197 *DANUBE_GPIO_P0_ALTSEL0 &= ~(1<<CONFIG_BUTTON_PIN);
198 *DANUBE_GPIO_P0_ALTSEL1 &= ~(1<<CONFIG_BUTTON_PIN);
199 *DANUBE_GPIO_P0_DIR &= ~(1<<CONFIG_BUTTON_PIN);
200 if(!!(*DANUBE_GPIO_P0_IN & (1<<CONFIG_BUTTON_PIN)) == CONFIG_BUTTON_LEVEL)
202 printf("button is pressed\n");
203 setenv("bootdelay", "0");
204 setenv("bootcmd", "httpd");
206 #elif defined(CONFIG_BUTTON_PORT1)
207 *DANUBE_GPIO_P1_ALTSEL0 &= ~(1<<CONFIG_BUTTON_PIN);
208 *DANUBE_GPIO_P1_ALTSEL1 &= ~(1<<CONFIG_BUTTON_PIN);
209 *DANUBE_GPIO_P1_DIR &= ~(1<<CONFIG_BUTTON_PIN);
210 if(!!(*DANUBE_GPIO_P1_IN & (1<<CONFIG_BUTTON_PIN)) == CONFIG_BUTTON_LEVEL)
212 printf("button is pressed\n");
213 setenv("bootdelay", "0");
214 setenv("bootcmd", "httpd");
220 int checkboard (void)
222 unsigned long chipid = *DANUBE_MPS_CHIPID;
225 puts ("Board: "CONFIG_ARCADYAN"\n");
228 part_num = DANUBE_MPS_CHIPID_PARTNUM_GET(chipid);
234 puts("Danube/Twinpass/Vinax-VE ");
237 printf ("unknown, chip part number 0x%03X ", part_num);
240 printf ("V1.%ld, ", DANUBE_MPS_CHIPID_VERSION_GET(chipid));
242 printf("DDR Speed %ld MHz, ", ifx_get_ddr_hz()/1000000);
243 printf("CPU Speed %ld MHz\n", ifx_get_cpuclk()/1000000);
249 #ifdef CONFIG_SKIP_LOWLEVEL_INIT
250 int board_early_init_f(void)
252 #ifdef CONFIG_EBU_ADDSEL0
253 (*DANUBE_EBU_ADDSEL0) = CONFIG_EBU_ADDSEL0;
255 #ifdef CONFIG_EBU_ADDSEL1
256 (*DANUBE_EBU_ADDSEL1) = CONFIG_EBU_ADDSEL1;
258 #ifdef CONFIG_EBU_ADDSEL2
259 (*DANUBE_EBU_ADDSEL2) = CONFIG_EBU_ADDSEL2;
261 #ifdef CONFIG_EBU_ADDSEL3
262 (*DANUBE_EBU_ADDSEL3) = CONFIG_EBU_ADDSEL3;
264 #ifdef CONFIG_EBU_BUSCON0
265 (*DANUBE_EBU_BUSCON0) = CONFIG_EBU_BUSCON0;
267 #ifdef CONFIG_EBU_BUSCON1
268 (*DANUBE_EBU_BUSCON1) = CONFIG_EBU_BUSCON1;
270 #ifdef CONFIG_EBU_BUSCON2
271 (*DANUBE_EBU_BUSCON2) = CONFIG_EBU_BUSCON2;
273 #ifdef CONFIG_EBU_BUSCON3
274 (*DANUBE_EBU_BUSCON3) = CONFIG_EBU_BUSCON3;
279 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
281 #ifdef CONFIG_RTL8306_SWITCH
282 #define ID_RTL8306 0x5988
283 static int external_switch_rtl8306(void)
285 unsigned short chipid;
286 static char * const name = "lq_cpe_eth";
290 puts("\nsearching for rtl8306 switch ... ");
291 if (miiphy_read(name, 4, 30, &chipid) == 0) {
292 if (chipid == ID_RTL8306) {
295 miiphy_write(name, 0, 19, 0xffff);
297 miiphy_write(name, 4, 22, 0x877f);
303 puts("\nno known switch found ... \n");
309 #ifdef CONFIG_AR8216_SWITCH
310 static int external_switch_ar8216(void)
312 puts("initializing ar8216 switch... ");
313 if (athrs26_phy_setup(0)==0) {
314 printf("initialized\n");
317 puts("failed ... \n");
322 int board_eth_init(bd_t *bis)
326 #if defined(CONFIG_IFX_ETOP)
328 if (!eth_getenv_enetaddr("ethaddr", enetaddr))
329 eth_setenv_enetaddr("ethaddr", (uchar *)0xb03f0016);
331 *DANUBE_PMU_PWDCR &= 0xFFFFEFDF;
332 *DANUBE_PMU_PWDCR &=~(1<<DANUBE_PMU_DMA_SHIFT);/*enable DMA from PMU*/
334 if (lq_eth_initialize(bis))
337 *DANUBE_RCU_RST_REQ |=1;
339 *DANUBE_RCU_RST_REQ &=(unsigned long)~1;
342 #ifdef CONFIG_RTL8306_SWITCH
343 if (external_switch_rtl8306()<0)
346 #ifdef CONFIG_AR8216_SWITCH
347 if (external_switch_ar8216()<0)
354 #if defined(CONFIG_CMD_HTTPD)
355 int do_http_upgrade(const unsigned char *data, const ulong size)
359 if(getenv ("ram_addr") == NULL)
361 if(getenv ("kernel_addr") == NULL)
363 /* check the image */
364 if(run_command("imi ${ram_addr}", 0) < 0) {
367 /* write the image to the flash */
368 puts("http ugrade ...\n");
369 sprintf(buf, "era ${kernel_addr} +0x%lx; cp.b ${ram_addr} ${kernel_addr} 0x%lx", size, size);
370 return run_command(buf, 0);
373 int do_http_progress(const int state)
375 /* toggle LED's here */
377 case HTTP_PROGRESS_START:
378 puts("http start\n");
380 case HTTP_PROGRESS_TIMEOUT:
383 case HTTP_PROGRESS_UPLOAD_READY:
384 puts("http upload ready\n");
386 case HTTP_PROGRESS_UGRADE_READY:
387 puts("http ugrade ready\n");
389 case HTTP_PROGRESS_UGRADE_FAILED:
390 puts("http ugrade failed\n");
396 unsigned long do_http_tmp_address(void)
398 char *s = getenv ("ram_addr");
400 ulong tmp = simple_strtoul (s, NULL, 16);
403 return 0 /*0x80a00000*/;