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 is unset. Therefore, all netconsole packets are
54 * Additionally, the bootsource is set to 'rescue'.
57 #ifndef CONFIG_ENV_OVERWRITE
58 # error "You need to set CONFIG_ENV_OVERWRITE"
61 DECLARE_GLOBAL_DATA_PTR;
63 int board_early_init_f(void)
66 * default gpio configuration
67 * There are maximum 64 gpios controlled through 2 sets of registers
68 * the below configuration configures mainly initial LED status
70 kw_config_gpio(LSXL_OE_VAL_LOW,
72 LSXL_OE_LOW, LSXL_OE_HIGH);
75 * Multi-Purpose Pins Functionality configuration
76 * These strappings are taken from the original vendor uboot port.
78 static const u32 kwmpp_config[] = {
89 MPP10_GPO, /* HDD power */
90 MPP11_GPIO, /* USB Vbus enable */
97 MPP18_GPO, /* fan speed high */
98 MPP19_GPO, /* fan speed low */
115 MPP36_GPIO, /* function LED */
116 MPP37_GPIO, /* alarm LED */
117 MPP38_GPIO, /* info LED */
118 MPP39_GPIO, /* power LED */
119 MPP40_GPIO, /* fan alarm */
120 MPP41_GPIO, /* funtion button */
121 MPP42_GPIO, /* power switch */
122 MPP43_GPIO, /* power auto switch */
127 MPP48_GPIO, /* function red LED */
132 kirkwood_mpp_conf(kwmpp_config, NULL);
138 #define LED_ALARM_ON 1
139 #define LED_ALARM_BLINKING 2
140 #define LED_POWER_ON 3
141 #define LED_POWER_BLINKING 4
142 #define LED_INFO_ON 5
143 #define LED_INFO_BLINKING 6
145 static void __set_led(int blink_alarm, int blink_info, int blink_power,
146 int value_alarm, int value_info, int value_power)
148 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
149 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
150 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
151 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
152 kw_gpio_set_value(GPIO_INFO_LED, value_info);
153 kw_gpio_set_value(GPIO_POWER_LED, value_power);
156 static void set_led(int state)
160 __set_led(0, 0, 0, 1, 1, 1);
163 __set_led(0, 0, 0, 0, 1, 1);
165 case LED_ALARM_BLINKING:
166 __set_led(1, 0, 0, 1, 1, 1);
169 __set_led(0, 0, 0, 1, 0, 1);
171 case LED_INFO_BLINKING:
172 __set_led(0, 1, 0, 1, 1, 1);
175 __set_led(0, 0, 0, 1, 1, 0);
177 case LED_POWER_BLINKING:
178 __set_led(0, 0, 1, 1, 1, 1);
185 /* address of boot parameters */
186 gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
188 set_led(LED_POWER_BLINKING);
193 #ifdef CONFIG_MISC_INIT_R
194 static void check_power_switch(void)
196 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
197 /* turn off fan, HDD and USB power */
198 kw_gpio_set_value(GPIO_HDD_POWER, 0);
199 kw_gpio_set_value(GPIO_USB_VBUS, 0);
200 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
201 kw_gpio_set_value(GPIO_FAN_LOW, 1);
204 /* loop until released */
205 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
208 /* turn power on again */
209 kw_gpio_set_value(GPIO_HDD_POWER, 1);
210 kw_gpio_set_value(GPIO_USB_VBUS, 1);
211 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
212 kw_gpio_set_value(GPIO_FAN_LOW, 0);
213 set_led(LED_POWER_BLINKING);
217 void check_enetaddr(void)
221 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
222 /* signal unset/invalid ethaddr to user */
223 set_led(LED_INFO_BLINKING);
227 static void erase_environment(void)
229 struct spi_flash *flash;
231 printf("Erasing environment..\n");
232 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
234 printf("Erasing flash failed\n");
238 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
239 spi_flash_free(flash);
240 do_reset(NULL, 0, 0, NULL);
243 static void rescue_mode(void)
247 printf("Entering rescue mode..\n");
248 #ifdef CONFIG_RANDOM_MACADDR
249 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
250 eth_random_enetaddr(enetaddr);
251 if (eth_setenv_enetaddr("ethaddr", enetaddr)) {
252 printf("Failed to set ethernet address\n");
253 set_led(LED_ALARM_BLINKING);
258 setenv("bootsource", "rescue");
261 static void check_push_button(void)
265 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
270 set_led(LED_INFO_ON);
273 set_led(LED_INFO_BLINKING);
284 int misc_init_r(void)
286 check_power_switch();
294 #ifdef CONFIG_SHOW_BOOT_PROGRESS
295 void show_boot_progress(int progress)
300 /* this is not an error, eg. bootp with autoload=no will trigger this */
301 if (progress == -BOOTSTAGE_ID_NET_LOADED)
304 set_led(LED_ALARM_BLINKING);