2 * Copyright (c) 2012 Michael Walle
3 * Michael Walle <michael@walle.cc>
5 * Based on sheevaplug/sheevaplug.c by
6 * Marvell Semiconductor <www.marvell.com>
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., 51 Franklin Street, Fifth Floor, Boston,
32 #include <asm/arch/kirkwood.h>
33 #include <asm/arch/cpu.h>
34 #include <asm/arch/mpp.h>
35 #include <asm/arch/gpio.h>
36 #include <spi_flash.h>
43 * Selected by holding the push button for 3 seconds, while powering on
46 * These linkstations don't have a (populated) serial port. There is no
47 * way to access an (unmodified) board other than using the netconsole. If
48 * you want to recover from a bad environment setting or an empty environment,
49 * you can do this only with a working network connection. Therefore, a random
50 * ethernet address is generated if none is set and a DHCP request is sent.
51 * After a successful DHCP response is received, the network settings are
52 * configured and the ncip parameter is set to the serverip. Eg. for a working
53 * resuce mode, you should set 'next-server' to the host where the netconsole
55 * Additionally, the bootsource is set to 'rescue'.
58 #ifndef CONFIG_ENV_OVERWRITE
59 # error "You need to set CONFIG_ENV_OVERWRITE"
62 DECLARE_GLOBAL_DATA_PTR;
64 int board_early_init_f(void)
67 * default gpio configuration
68 * There are maximum 64 gpios controlled through 2 sets of registers
69 * the below configuration configures mainly initial LED status
71 kw_config_gpio(LSXL_OE_VAL_LOW,
73 LSXL_OE_LOW, LSXL_OE_HIGH);
76 * Multi-Purpose Pins Functionality configuration
77 * These strappings are taken from the original vendor uboot port.
79 u32 kwmpp_config[] = {
90 MPP10_GPO, /* HDD power */
91 MPP11_GPIO, /* USB Vbus enable */
98 MPP18_GPO, /* fan speed high */
99 MPP19_GPO, /* fan speed low */
116 MPP36_GPIO, /* function LED */
117 MPP37_GPIO, /* alarm LED */
118 MPP38_GPIO, /* info LED */
119 MPP39_GPIO, /* power LED */
120 MPP40_GPIO, /* fan alarm */
121 MPP41_GPIO, /* funtion button */
122 MPP42_GPIO, /* power switch */
123 MPP43_GPIO, /* power auto switch */
128 MPP48_GPIO, /* function red LED */
133 kirkwood_mpp_conf(kwmpp_config, NULL);
139 #define LED_ALARM_ON 1
140 #define LED_ALARM_BLINKING 2
141 #define LED_POWER_ON 3
142 #define LED_POWER_BLINKING 4
143 #define LED_INFO_ON 5
144 #define LED_INFO_BLINKING 6
146 static void __set_led(int blink_alarm, int blink_info, int blink_power,
147 int value_alarm, int value_info, int value_power)
149 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
150 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
151 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
152 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
153 kw_gpio_set_value(GPIO_INFO_LED, value_info);
154 kw_gpio_set_value(GPIO_POWER_LED, value_power);
157 static void set_led(int state)
161 __set_led(0, 0, 0, 1, 1, 1);
164 __set_led(0, 0, 0, 0, 1, 1);
166 case LED_ALARM_BLINKING:
167 __set_led(1, 0, 0, 1, 1, 1);
170 __set_led(0, 0, 0, 1, 0, 1);
172 case LED_INFO_BLINKING:
173 __set_led(0, 1, 0, 1, 1, 1);
176 __set_led(0, 0, 0, 1, 1, 0);
178 case LED_POWER_BLINKING:
179 __set_led(0, 0, 1, 1, 1, 1);
186 /* address of boot parameters */
187 gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
189 set_led(LED_POWER_BLINKING);
194 #ifdef CONFIG_MISC_INIT_R
195 static void check_power_switch(void)
197 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
198 /* turn off HDD and USB power */
199 kw_gpio_set_value(GPIO_HDD_POWER, 0);
200 kw_gpio_set_value(GPIO_USB_VBUS, 0);
203 /* loop until released */
204 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
207 /* turn power on again */
208 kw_gpio_set_value(GPIO_HDD_POWER, 1);
209 kw_gpio_set_value(GPIO_USB_VBUS, 1);
210 set_led(LED_POWER_BLINKING);
214 void check_enetaddr(void)
218 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
219 /* signal unset/invalid ethaddr to user */
220 set_led(LED_INFO_BLINKING);
224 static void erase_environment(void)
226 struct spi_flash *flash;
228 printf("Erasing environment..\n");
229 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
231 printf("Erasing flash failed\n");
235 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
236 spi_flash_free(flash);
237 do_reset(NULL, 0, 0, NULL);
240 static void rescue_mode(void)
244 printf("Entering rescue mode..\n");
245 #ifdef CONFIG_RANDOM_MACADDR
246 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
247 eth_random_enetaddr(enetaddr);
248 if (eth_setenv_enetaddr("ethaddr", enetaddr)) {
249 printf("Failed to set ethernet address\n");
250 set_led(LED_ALARM_BLINKING);
255 setenv("bootsource", "rescue");
258 static void check_push_button(void)
262 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
267 set_led(LED_INFO_ON);
270 set_led(LED_INFO_BLINKING);
281 int misc_init_r(void)
283 check_power_switch();
291 #ifdef CONFIG_SHOW_BOOT_PROGRESS
292 void show_boot_progress(int progress)
297 /* this is not an error, eg. bootp with autoload=no will trigger this */
298 if (progress == -BOOTSTAGE_ID_NET_LOADED)
301 set_led(LED_ALARM_BLINKING);