2 * lowlevel_init.S - basic hardware initialization for the KS8695 CPU
4 * Copyright (c) 2004-2005, Greg Ungerer <greg.ungerer@opengear.com>
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/arch/platform.h>
13 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
16 *************************************************************************
20 *************************************************************************
24 .macro DELAY_FOR cycles, reg0
31 *************************************************************************
35 *************************************************************************
38 /* Should we boot with an interactive console or not */
42 *************************************************************************
44 * Raw hardware initialization code. The important thing is to get
45 * SDRAM setup and running. We do some other basic things here too,
46 * like getting the PLL set for high speed, and init the LEDs.
48 *************************************************************************
56 * enable UART for early debug trace
58 ldr r1, =(KS8695_IO_BASE+KS8695_UART_DIVISOR)
59 mov r2, #((25000000+CONFIG_BAUDRATE/2) / CONFIG_BAUDRATE)
61 ldr r1, =(KS8695_IO_BASE+KS8695_UART_LINE_CTRL)
62 mov r2, #KS8695_UART_LINEC_WLEN8
63 str r2, [r1] /* 8 data bits, no parity, 1 stop */
64 ldr r1, =(KS8695_IO_BASE+KS8695_UART_TX_HOLDING)
66 str r2, [r1] /* write 'A' */
69 ldr r1, =(KS8695_IO_BASE+KS8695_UART_TX_HOLDING)
75 * remap the memory and flash regions. we want to end up with
76 * ram from address 0, and flash at 32MB.
78 ldr r1, =(KS8695_IO_BASE+KS8695_MEM_CTRL0)
80 str r2, [r1] /* large flash map */
81 ldr pc, =(highflash+0x02000000-0x00f00000) /* jump to high flash address */
84 str r2, [r1] /* remap flash range */
87 * remap the second select region to the 4MB immediately after
88 * the first region. This way if you have a larger flash (say 8Mb)
89 * then you can have it all mapped nicely. Has no effect if you
90 * only have a 4Mb or smaller flash.
92 ldr r1, =(KS8695_IO_BASE+KS8695_MEM_CTRL1)
94 str r2, [r1] /* remap flash2 region, contiguous */
95 ldr r1, =(KS8695_IO_BASE+KS8695_MEM_GENERAL)
97 str r2, [r1] /* enable both flash selects */
101 * map the second flash chip, using the external IO lines.
103 ldr r1, =(KS8695_IO_BASE+KS8695_IO_CTRL0)
105 str r2, [r1] /* remap io0 region, contiguous */
106 ldr r1, =(KS8695_IO_BASE+KS8695_IO_CTRL1)
108 str r2, [r1] /* remap io1 region, contiguous */
109 ldr r1, =(KS8695_IO_BASE+KS8695_MEM_GENERAL)
111 str r2, [r1] /* enable second flash */
115 * before relocating, we have to setup RAM timing
117 ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_CTRL0)
118 #if (PHYS_SDRAM_1_SIZE == 0x02000000)
119 ldr r2, =0x7fc0000e /* 32MB */
121 ldr r2, =0x3fc0000e /* 16MB */
123 str r2, [r1] /* configure sdram bank0 setup */
124 ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_CTRL1)
126 str r2, [r1] /* configure sdram bank1 setup */
128 ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_GENERAL)
130 str r2, [r1] /* set RAS/CAS timing */
132 ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_BUFFER)
134 str r2, [r1] /* send NOP command */
137 str r2, [r1] /* send PRECHARGE-ALL */
140 ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_REFRESH)
142 str r2, [r1] /* set for fast refresh */
145 str r2, [r1] /* set normal refresh timing */
147 ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_BUFFER)
149 str r2, [r1] /* send mode command */
152 str r2, [r1] /* enable sdram fifos */
155 * set pll to top speed
157 ldr r1, =(KS8695_IO_BASE+KS8695_SYSTEN_BUS_CLOCK)
159 str r2, [r1] /* set pll clock to 166MHz */
161 ldr r1, =(KS8695_IO_BASE+KS8695_SWITCH_CTRL0)
162 ldr r2, [r1] /* Get switch ctrl0 register */
163 and r2, r2, #0x0fc00000 /* Mask out LED control bits */
164 orr r2, r2, #0x01800000 /* Set Link/activity/speed actions */
168 ldr r1, =(KS8695_IO_BASE+KS8695_GPIO_MODE)
170 str r2, [r1] /* enable LED's as outputs */
171 ldr r1, =(KS8695_IO_BASE+KS8695_GPIO_DATA)
173 str r2, [r1] /* turn on power LED */
175 #if defined(CONFIG_CM4008) || defined(CONFIG_CM41xx)
176 ldr r2, [r1] /* get current GPIO input data */
177 tst r2, #0x8 /* check if "erase" depressed */
179 mov r2, #0 /* be quiet on boot, no console */
180 ldr r1, =serial_console
185 add lr, lr, #0x02000000 /* flash is now mapped high */
186 add ip, ip, #0x02000000 /* this is a hack */
187 mov pc, lr /* all done, return */
189 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */