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>
12 #include <env_internal.h>
19 #include <spi_flash.h>
20 #include <asm/arch/soc.h>
21 #include <asm/arch/cpu.h>
22 #include <asm/arch/mpp.h>
23 #include <asm/arch/gpio.h>
30 * Selected by holding the push button for 3 seconds, while powering on
33 * These linkstations don't have a (populated) serial port. There is no
34 * way to access an (unmodified) board other than using the netconsole. If
35 * you want to recover from a bad environment setting or an empty environment,
36 * you can do this only with a working network connection. Therefore, a random
37 * ethernet address is generated if none is set and a DHCP request is sent.
38 * After a successful DHCP response is received, the network settings are
39 * configured and the ncip is unset. Therefore, all netconsole packets are
41 * Additionally, the bootsource is set to 'rescue'.
44 #ifndef CONFIG_ENV_OVERWRITE
45 # error "You need to set CONFIG_ENV_OVERWRITE"
48 DECLARE_GLOBAL_DATA_PTR;
50 int board_early_init_f(void)
53 * default gpio configuration
54 * There are maximum 64 gpios controlled through 2 sets of registers
55 * the below configuration configures mainly initial LED status
57 mvebu_config_gpio(LSXL_OE_VAL_LOW,
59 LSXL_OE_LOW, LSXL_OE_HIGH);
62 * Multi-Purpose Pins Functionality configuration
63 * These strappings are taken from the original vendor uboot port.
65 static const u32 kwmpp_config[] = {
76 MPP10_GPO, /* HDD power */
77 MPP11_GPIO, /* USB Vbus enable */
84 MPP18_GPO, /* fan speed high */
85 MPP19_GPO, /* fan speed low */
102 MPP36_GPIO, /* function LED */
103 MPP37_GPIO, /* alarm LED */
104 MPP38_GPIO, /* info LED */
105 MPP39_GPIO, /* power LED */
106 MPP40_GPIO, /* fan alarm */
107 MPP41_GPIO, /* funtion button */
108 MPP42_GPIO, /* power switch */
109 MPP43_GPIO, /* power auto switch */
114 MPP48_GPIO, /* function red LED */
119 kirkwood_mpp_conf(kwmpp_config, NULL);
125 #define LED_ALARM_ON 1
126 #define LED_ALARM_BLINKING 2
127 #define LED_POWER_ON 3
128 #define LED_POWER_BLINKING 4
129 #define LED_INFO_ON 5
130 #define LED_INFO_BLINKING 6
132 static void __set_led(int blink_alarm, int blink_info, int blink_power,
133 int value_alarm, int value_info, int value_power)
135 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
136 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
137 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
138 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
139 kw_gpio_set_value(GPIO_INFO_LED, value_info);
140 kw_gpio_set_value(GPIO_POWER_LED, value_power);
143 static void set_led(int state)
147 __set_led(0, 0, 0, 1, 1, 1);
150 __set_led(0, 0, 0, 0, 1, 1);
152 case LED_ALARM_BLINKING:
153 __set_led(1, 0, 0, 1, 1, 1);
156 __set_led(0, 0, 0, 1, 0, 1);
158 case LED_INFO_BLINKING:
159 __set_led(0, 1, 0, 1, 1, 1);
162 __set_led(0, 0, 0, 1, 1, 0);
164 case LED_POWER_BLINKING:
165 __set_led(0, 0, 1, 1, 1, 1);
172 /* address of boot parameters */
173 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
175 set_led(LED_POWER_BLINKING);
180 #ifdef CONFIG_MISC_INIT_R
181 static void check_power_switch(void)
183 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
184 /* turn off fan, HDD and USB power */
185 kw_gpio_set_value(GPIO_HDD_POWER, 0);
186 kw_gpio_set_value(GPIO_USB_VBUS, 0);
187 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
188 kw_gpio_set_value(GPIO_FAN_LOW, 1);
191 /* loop until released */
192 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
195 /* turn power on again */
196 kw_gpio_set_value(GPIO_HDD_POWER, 1);
197 kw_gpio_set_value(GPIO_USB_VBUS, 1);
198 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
199 kw_gpio_set_value(GPIO_FAN_LOW, 0);
200 set_led(LED_POWER_BLINKING);
204 void check_enetaddr(void)
208 if (!eth_env_get_enetaddr("ethaddr", enetaddr)) {
209 /* signal unset/invalid ethaddr to user */
210 set_led(LED_INFO_BLINKING);
214 static void erase_environment(void)
216 struct spi_flash *flash;
218 printf("Erasing environment..\n");
219 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
221 printf("Erasing flash failed\n");
225 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
226 spi_flash_free(flash);
227 do_reset(NULL, 0, 0, NULL);
230 static void rescue_mode(void)
232 printf("Entering rescue mode..\n");
233 env_set("bootsource", "rescue");
236 static void check_push_button(void)
240 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
245 set_led(LED_INFO_ON);
248 set_led(LED_INFO_BLINKING);
259 int misc_init_r(void)
261 check_power_switch();
269 #ifdef CONFIG_SHOW_BOOT_PROGRESS
270 void show_boot_progress(int progress)
275 /* this is not an error, eg. bootp with autoload=no will trigger this */
276 if (progress == -BOOTSTAGE_ID_NET_LOADED)
279 set_led(LED_ALARM_BLINKING);