1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012 Michael Walle
4 * Michael Walle <michael@walle.cc>
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>
27 #include <asm/global_data.h>
28 #include <linux/delay.h>
35 * Selected by holding the push button for 3 seconds, while powering on
38 * These linkstations don't have a (populated) serial port. There is no
39 * way to access an (unmodified) board other than using the netconsole. If
40 * you want to recover from a bad environment setting or an empty environment,
41 * you can do this only with a working network connection. Therefore, a random
42 * ethernet address is generated if none is set and a DHCP request is sent.
43 * After a successful DHCP response is received, the network settings are
44 * configured and the ncip is unset. Therefore, all netconsole packets are
46 * Additionally, the bootsource is set to 'rescue'.
49 #ifndef CONFIG_ENV_OVERWRITE
50 # error "You need to set CONFIG_ENV_OVERWRITE"
53 DECLARE_GLOBAL_DATA_PTR;
55 int board_early_init_f(void)
58 * default gpio configuration
59 * There are maximum 64 gpios controlled through 2 sets of registers
60 * the below configuration configures mainly initial LED status
62 mvebu_config_gpio(LSXL_OE_VAL_LOW,
64 LSXL_OE_LOW, LSXL_OE_HIGH);
67 * Multi-Purpose Pins Functionality configuration
68 * These strappings are taken from the original vendor uboot port.
70 static const u32 kwmpp_config[] = {
81 MPP10_GPO, /* HDD power */
82 MPP11_GPIO, /* USB Vbus enable */
89 MPP18_GPO, /* fan speed high */
90 MPP19_GPO, /* fan speed low */
107 MPP36_GPIO, /* function LED */
108 MPP37_GPIO, /* alarm LED */
109 MPP38_GPIO, /* info LED */
110 MPP39_GPIO, /* power LED */
111 MPP40_GPIO, /* fan alarm */
112 MPP41_GPIO, /* funtion button */
113 MPP42_GPIO, /* power switch */
114 MPP43_GPIO, /* power auto switch */
119 MPP48_GPIO, /* function red LED */
124 kirkwood_mpp_conf(kwmpp_config, NULL);
130 #define LED_ALARM_ON 1
131 #define LED_ALARM_BLINKING 2
132 #define LED_POWER_ON 3
133 #define LED_POWER_BLINKING 4
134 #define LED_INFO_ON 5
135 #define LED_INFO_BLINKING 6
137 static void __set_led(int blink_alarm, int blink_info, int blink_power,
138 int value_alarm, int value_info, int value_power)
140 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
141 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
142 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
143 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
144 kw_gpio_set_value(GPIO_INFO_LED, value_info);
145 kw_gpio_set_value(GPIO_POWER_LED, value_power);
148 static void set_led(int state)
152 __set_led(0, 0, 0, 1, 1, 1);
155 __set_led(0, 0, 0, 0, 1, 1);
157 case LED_ALARM_BLINKING:
158 __set_led(1, 0, 0, 1, 1, 1);
161 __set_led(0, 0, 0, 1, 0, 1);
163 case LED_INFO_BLINKING:
164 __set_led(0, 1, 0, 1, 1, 1);
167 __set_led(0, 0, 0, 1, 1, 0);
169 case LED_POWER_BLINKING:
170 __set_led(0, 0, 1, 1, 1, 1);
177 /* address of boot parameters */
178 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
180 set_led(LED_POWER_BLINKING);
185 #ifdef CONFIG_MISC_INIT_R
186 static void check_power_switch(void)
188 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
189 /* turn off fan, HDD and USB power */
190 kw_gpio_set_value(GPIO_HDD_POWER, 0);
191 kw_gpio_set_value(GPIO_USB_VBUS, 0);
192 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
193 kw_gpio_set_value(GPIO_FAN_LOW, 1);
196 /* loop until released */
197 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
200 /* turn power on again */
201 kw_gpio_set_value(GPIO_HDD_POWER, 1);
202 kw_gpio_set_value(GPIO_USB_VBUS, 1);
203 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
204 kw_gpio_set_value(GPIO_FAN_LOW, 0);
205 set_led(LED_POWER_BLINKING);
209 void check_enetaddr(void)
213 if (!eth_env_get_enetaddr("ethaddr", enetaddr)) {
214 /* signal unset/invalid ethaddr to user */
215 set_led(LED_INFO_BLINKING);
219 static void erase_environment(void)
221 struct spi_flash *flash;
223 printf("Erasing environment..\n");
224 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
226 printf("Erasing flash failed\n");
230 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
231 spi_flash_free(flash);
232 do_reset(NULL, 0, 0, NULL);
235 static void rescue_mode(void)
237 printf("Entering rescue mode..\n");
238 env_set("bootsource", "rescue");
241 static void check_push_button(void)
245 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
250 set_led(LED_INFO_ON);
253 set_led(LED_INFO_BLINKING);
264 int misc_init_r(void)
266 check_power_switch();
274 #if CONFIG_IS_ENABLED(BOOTSTAGE)
275 void show_boot_progress(int progress)
280 /* this is not an error, eg. bootp with autoload=no will trigger this */
281 if (progress == -BOOTSTAGE_ID_NET_LOADED)
284 set_led(LED_ALARM_BLINKING);