1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012 Michael Walle
6 * Based on sheevaplug/sheevaplug.c by
7 * Marvell Semiconductor <www.marvell.com>
11 #include <bootstage.h>
14 #include <env_internal.h>
22 #include <spi_flash.h>
23 #include <asm/arch/soc.h>
24 #include <asm/arch/cpu.h>
25 #include <asm/arch/mpp.h>
26 #include <asm/arch/gpio.h>
33 * Selected by holding the push button for 3 seconds, while powering on
36 * These linkstations don't have a (populated) serial port. There is no
37 * way to access an (unmodified) board other than using the netconsole. If
38 * you want to recover from a bad environment setting or an empty environment,
39 * you can do this only with a working network connection. Therefore, a random
40 * ethernet address is generated if none is set and a DHCP request is sent.
41 * After a successful DHCP response is received, the network settings are
42 * configured and the ncip is unset. Therefore, all netconsole packets are
44 * Additionally, the bootsource is set to 'rescue'.
47 #ifndef CONFIG_ENV_OVERWRITE
48 # error "You need to set CONFIG_ENV_OVERWRITE"
51 DECLARE_GLOBAL_DATA_PTR;
53 int board_early_init_f(void)
56 * default gpio configuration
57 * There are maximum 64 gpios controlled through 2 sets of registers
58 * the below configuration configures mainly initial LED status
60 mvebu_config_gpio(LSXL_OE_VAL_LOW,
62 LSXL_OE_LOW, LSXL_OE_HIGH);
65 * Multi-Purpose Pins Functionality configuration
66 * These strappings are taken from the original vendor uboot port.
68 static const u32 kwmpp_config[] = {
79 MPP10_GPO, /* HDD power */
80 MPP11_GPIO, /* USB Vbus enable */
87 MPP18_GPO, /* fan speed high */
88 MPP19_GPO, /* fan speed low */
105 MPP36_GPIO, /* function LED */
106 MPP37_GPIO, /* alarm LED */
107 MPP38_GPIO, /* info LED */
108 MPP39_GPIO, /* power LED */
109 MPP40_GPIO, /* fan alarm */
110 MPP41_GPIO, /* funtion button */
111 MPP42_GPIO, /* power switch */
112 MPP43_GPIO, /* power auto switch */
117 MPP48_GPIO, /* function red LED */
122 kirkwood_mpp_conf(kwmpp_config, NULL);
128 #define LED_ALARM_ON 1
129 #define LED_ALARM_BLINKING 2
130 #define LED_POWER_ON 3
131 #define LED_POWER_BLINKING 4
132 #define LED_INFO_ON 5
133 #define LED_INFO_BLINKING 6
135 static void __set_led(int blink_alarm, int blink_info, int blink_power,
136 int value_alarm, int value_info, int value_power)
138 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
139 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
140 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
141 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
142 kw_gpio_set_value(GPIO_INFO_LED, value_info);
143 kw_gpio_set_value(GPIO_POWER_LED, value_power);
146 static void set_led(int state)
150 __set_led(0, 0, 0, 1, 1, 1);
153 __set_led(0, 0, 0, 0, 1, 1);
155 case LED_ALARM_BLINKING:
156 __set_led(1, 0, 0, 1, 1, 1);
159 __set_led(0, 0, 0, 1, 0, 1);
161 case LED_INFO_BLINKING:
162 __set_led(0, 1, 0, 1, 1, 1);
165 __set_led(0, 0, 0, 1, 1, 0);
167 case LED_POWER_BLINKING:
168 __set_led(0, 0, 1, 1, 1, 1);
175 /* address of boot parameters */
176 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
178 set_led(LED_POWER_BLINKING);
183 #ifdef CONFIG_MISC_INIT_R
184 static void check_power_switch(void)
186 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
187 /* turn off fan, HDD and USB power */
188 kw_gpio_set_value(GPIO_HDD_POWER, 0);
189 kw_gpio_set_value(GPIO_USB_VBUS, 0);
190 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
191 kw_gpio_set_value(GPIO_FAN_LOW, 1);
194 /* loop until released */
195 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
198 /* turn power on again */
199 kw_gpio_set_value(GPIO_HDD_POWER, 1);
200 kw_gpio_set_value(GPIO_USB_VBUS, 1);
201 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
202 kw_gpio_set_value(GPIO_FAN_LOW, 0);
203 set_led(LED_POWER_BLINKING);
207 void check_enetaddr(void)
211 if (!eth_env_get_enetaddr("ethaddr", enetaddr)) {
212 /* signal unset/invalid ethaddr to user */
213 set_led(LED_INFO_BLINKING);
217 static void erase_environment(void)
219 struct spi_flash *flash;
221 printf("Erasing environment..\n");
222 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
224 printf("Erasing flash failed\n");
228 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
229 spi_flash_free(flash);
230 do_reset(NULL, 0, 0, NULL);
233 static void rescue_mode(void)
235 printf("Entering rescue mode..\n");
236 env_set("bootsource", "rescue");
239 static void check_push_button(void)
243 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
248 set_led(LED_INFO_ON);
251 set_led(LED_INFO_BLINKING);
262 int misc_init_r(void)
264 check_power_switch();
272 #ifdef CONFIG_SHOW_BOOT_PROGRESS
273 void show_boot_progress(int progress)
278 /* this is not an error, eg. bootp with autoload=no will trigger this */
279 if (progress == -BOOTSTAGE_ID_NET_LOADED)
282 set_led(LED_ALARM_BLINKING);