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 * SPDX-License-Identifier: GPL-2.0+
12 #include <environment.h>
18 #include <spi_flash.h>
19 #include <asm/arch/soc.h>
20 #include <asm/arch/cpu.h>
21 #include <asm/arch/mpp.h>
22 #include <asm/arch/gpio.h>
29 * Selected by holding the push button for 3 seconds, while powering on
32 * These linkstations don't have a (populated) serial port. There is no
33 * way to access an (unmodified) board other than using the netconsole. If
34 * you want to recover from a bad environment setting or an empty environment,
35 * you can do this only with a working network connection. Therefore, a random
36 * ethernet address is generated if none is set and a DHCP request is sent.
37 * After a successful DHCP response is received, the network settings are
38 * configured and the ncip is unset. Therefore, all netconsole packets are
40 * Additionally, the bootsource is set to 'rescue'.
43 #ifndef CONFIG_ENV_OVERWRITE
44 # error "You need to set CONFIG_ENV_OVERWRITE"
47 DECLARE_GLOBAL_DATA_PTR;
49 int board_early_init_f(void)
52 * default gpio configuration
53 * There are maximum 64 gpios controlled through 2 sets of registers
54 * the below configuration configures mainly initial LED status
56 mvebu_config_gpio(LSXL_OE_VAL_LOW,
58 LSXL_OE_LOW, LSXL_OE_HIGH);
61 * Multi-Purpose Pins Functionality configuration
62 * These strappings are taken from the original vendor uboot port.
64 static const u32 kwmpp_config[] = {
75 MPP10_GPO, /* HDD power */
76 MPP11_GPIO, /* USB Vbus enable */
83 MPP18_GPO, /* fan speed high */
84 MPP19_GPO, /* fan speed low */
101 MPP36_GPIO, /* function LED */
102 MPP37_GPIO, /* alarm LED */
103 MPP38_GPIO, /* info LED */
104 MPP39_GPIO, /* power LED */
105 MPP40_GPIO, /* fan alarm */
106 MPP41_GPIO, /* funtion button */
107 MPP42_GPIO, /* power switch */
108 MPP43_GPIO, /* power auto switch */
113 MPP48_GPIO, /* function red LED */
118 kirkwood_mpp_conf(kwmpp_config, NULL);
124 #define LED_ALARM_ON 1
125 #define LED_ALARM_BLINKING 2
126 #define LED_POWER_ON 3
127 #define LED_POWER_BLINKING 4
128 #define LED_INFO_ON 5
129 #define LED_INFO_BLINKING 6
131 static void __set_led(int blink_alarm, int blink_info, int blink_power,
132 int value_alarm, int value_info, int value_power)
134 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
135 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
136 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
137 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
138 kw_gpio_set_value(GPIO_INFO_LED, value_info);
139 kw_gpio_set_value(GPIO_POWER_LED, value_power);
142 static void set_led(int state)
146 __set_led(0, 0, 0, 1, 1, 1);
149 __set_led(0, 0, 0, 0, 1, 1);
151 case LED_ALARM_BLINKING:
152 __set_led(1, 0, 0, 1, 1, 1);
155 __set_led(0, 0, 0, 1, 0, 1);
157 case LED_INFO_BLINKING:
158 __set_led(0, 1, 0, 1, 1, 1);
161 __set_led(0, 0, 0, 1, 1, 0);
163 case LED_POWER_BLINKING:
164 __set_led(0, 0, 1, 1, 1, 1);
171 /* address of boot parameters */
172 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
174 set_led(LED_POWER_BLINKING);
179 #ifdef CONFIG_MISC_INIT_R
180 static void check_power_switch(void)
182 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
183 /* turn off fan, HDD and USB power */
184 kw_gpio_set_value(GPIO_HDD_POWER, 0);
185 kw_gpio_set_value(GPIO_USB_VBUS, 0);
186 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
187 kw_gpio_set_value(GPIO_FAN_LOW, 1);
190 /* loop until released */
191 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
194 /* turn power on again */
195 kw_gpio_set_value(GPIO_HDD_POWER, 1);
196 kw_gpio_set_value(GPIO_USB_VBUS, 1);
197 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
198 kw_gpio_set_value(GPIO_FAN_LOW, 0);
199 set_led(LED_POWER_BLINKING);
203 void check_enetaddr(void)
207 if (!eth_env_get_enetaddr("ethaddr", enetaddr)) {
208 /* signal unset/invalid ethaddr to user */
209 set_led(LED_INFO_BLINKING);
213 static void erase_environment(void)
215 struct spi_flash *flash;
217 printf("Erasing environment..\n");
218 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
220 printf("Erasing flash failed\n");
224 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
225 spi_flash_free(flash);
226 do_reset(NULL, 0, 0, NULL);
229 static void rescue_mode(void)
231 printf("Entering rescue mode..\n");
232 env_set("bootsource", "rescue");
235 static void check_push_button(void)
239 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
244 set_led(LED_INFO_ON);
247 set_led(LED_INFO_BLINKING);
258 int misc_init_r(void)
260 check_power_switch();
268 #ifdef CONFIG_SHOW_BOOT_PROGRESS
269 void show_boot_progress(int progress)
274 /* this is not an error, eg. bootp with autoload=no will trigger this */
275 if (progress == -BOOTSTAGE_ID_NET_LOADED)
278 set_led(LED_ALARM_BLINKING);