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 <linux/delay.h>
34 * Selected by holding the push button for 3 seconds, while powering on
37 * These linkstations don't have a (populated) serial port. There is no
38 * way to access an (unmodified) board other than using the netconsole. If
39 * you want to recover from a bad environment setting or an empty environment,
40 * you can do this only with a working network connection. Therefore, a random
41 * ethernet address is generated if none is set and a DHCP request is sent.
42 * After a successful DHCP response is received, the network settings are
43 * configured and the ncip is unset. Therefore, all netconsole packets are
45 * Additionally, the bootsource is set to 'rescue'.
48 #ifndef CONFIG_ENV_OVERWRITE
49 # error "You need to set CONFIG_ENV_OVERWRITE"
52 DECLARE_GLOBAL_DATA_PTR;
54 int board_early_init_f(void)
57 * default gpio configuration
58 * There are maximum 64 gpios controlled through 2 sets of registers
59 * the below configuration configures mainly initial LED status
61 mvebu_config_gpio(LSXL_OE_VAL_LOW,
63 LSXL_OE_LOW, LSXL_OE_HIGH);
66 * Multi-Purpose Pins Functionality configuration
67 * These strappings are taken from the original vendor uboot port.
69 static const u32 kwmpp_config[] = {
80 MPP10_GPO, /* HDD power */
81 MPP11_GPIO, /* USB Vbus enable */
88 MPP18_GPO, /* fan speed high */
89 MPP19_GPO, /* fan speed low */
106 MPP36_GPIO, /* function LED */
107 MPP37_GPIO, /* alarm LED */
108 MPP38_GPIO, /* info LED */
109 MPP39_GPIO, /* power LED */
110 MPP40_GPIO, /* fan alarm */
111 MPP41_GPIO, /* funtion button */
112 MPP42_GPIO, /* power switch */
113 MPP43_GPIO, /* power auto switch */
118 MPP48_GPIO, /* function red LED */
123 kirkwood_mpp_conf(kwmpp_config, NULL);
129 #define LED_ALARM_ON 1
130 #define LED_ALARM_BLINKING 2
131 #define LED_POWER_ON 3
132 #define LED_POWER_BLINKING 4
133 #define LED_INFO_ON 5
134 #define LED_INFO_BLINKING 6
136 static void __set_led(int blink_alarm, int blink_info, int blink_power,
137 int value_alarm, int value_info, int value_power)
139 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
140 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
141 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
142 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
143 kw_gpio_set_value(GPIO_INFO_LED, value_info);
144 kw_gpio_set_value(GPIO_POWER_LED, value_power);
147 static void set_led(int state)
151 __set_led(0, 0, 0, 1, 1, 1);
154 __set_led(0, 0, 0, 0, 1, 1);
156 case LED_ALARM_BLINKING:
157 __set_led(1, 0, 0, 1, 1, 1);
160 __set_led(0, 0, 0, 1, 0, 1);
162 case LED_INFO_BLINKING:
163 __set_led(0, 1, 0, 1, 1, 1);
166 __set_led(0, 0, 0, 1, 1, 0);
168 case LED_POWER_BLINKING:
169 __set_led(0, 0, 1, 1, 1, 1);
176 /* address of boot parameters */
177 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
179 set_led(LED_POWER_BLINKING);
184 #ifdef CONFIG_MISC_INIT_R
185 static void check_power_switch(void)
187 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
188 /* turn off fan, HDD and USB power */
189 kw_gpio_set_value(GPIO_HDD_POWER, 0);
190 kw_gpio_set_value(GPIO_USB_VBUS, 0);
191 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
192 kw_gpio_set_value(GPIO_FAN_LOW, 1);
195 /* loop until released */
196 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
199 /* turn power on again */
200 kw_gpio_set_value(GPIO_HDD_POWER, 1);
201 kw_gpio_set_value(GPIO_USB_VBUS, 1);
202 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
203 kw_gpio_set_value(GPIO_FAN_LOW, 0);
204 set_led(LED_POWER_BLINKING);
208 void check_enetaddr(void)
212 if (!eth_env_get_enetaddr("ethaddr", enetaddr)) {
213 /* signal unset/invalid ethaddr to user */
214 set_led(LED_INFO_BLINKING);
218 static void erase_environment(void)
220 struct spi_flash *flash;
222 printf("Erasing environment..\n");
223 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
225 printf("Erasing flash failed\n");
229 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
230 spi_flash_free(flash);
231 do_reset(NULL, 0, 0, NULL);
234 static void rescue_mode(void)
236 printf("Entering rescue mode..\n");
237 env_set("bootsource", "rescue");
240 static void check_push_button(void)
244 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
249 set_led(LED_INFO_ON);
252 set_led(LED_INFO_BLINKING);
263 int misc_init_r(void)
265 check_power_switch();
273 #ifdef CONFIG_SHOW_BOOT_PROGRESS
274 void show_boot_progress(int progress)
279 /* this is not an error, eg. bootp with autoload=no will trigger this */
280 if (progress == -BOOTSTAGE_ID_NET_LOADED)
283 set_led(LED_ALARM_BLINKING);