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+
17 #include <spi_flash.h>
18 #include <asm/arch/soc.h>
19 #include <asm/arch/cpu.h>
20 #include <asm/arch/mpp.h>
21 #include <asm/arch/gpio.h>
28 * Selected by holding the push button for 3 seconds, while powering on
31 * These linkstations don't have a (populated) serial port. There is no
32 * way to access an (unmodified) board other than using the netconsole. If
33 * you want to recover from a bad environment setting or an empty environment,
34 * you can do this only with a working network connection. Therefore, a random
35 * ethernet address is generated if none is set and a DHCP request is sent.
36 * After a successful DHCP response is received, the network settings are
37 * configured and the ncip is unset. Therefore, all netconsole packets are
39 * Additionally, the bootsource is set to 'rescue'.
42 #ifndef CONFIG_ENV_OVERWRITE
43 # error "You need to set CONFIG_ENV_OVERWRITE"
46 DECLARE_GLOBAL_DATA_PTR;
48 int board_early_init_f(void)
51 * default gpio configuration
52 * There are maximum 64 gpios controlled through 2 sets of registers
53 * the below configuration configures mainly initial LED status
55 mvebu_config_gpio(LSXL_OE_VAL_LOW,
57 LSXL_OE_LOW, LSXL_OE_HIGH);
60 * Multi-Purpose Pins Functionality configuration
61 * These strappings are taken from the original vendor uboot port.
63 static const u32 kwmpp_config[] = {
74 MPP10_GPO, /* HDD power */
75 MPP11_GPIO, /* USB Vbus enable */
82 MPP18_GPO, /* fan speed high */
83 MPP19_GPO, /* fan speed low */
100 MPP36_GPIO, /* function LED */
101 MPP37_GPIO, /* alarm LED */
102 MPP38_GPIO, /* info LED */
103 MPP39_GPIO, /* power LED */
104 MPP40_GPIO, /* fan alarm */
105 MPP41_GPIO, /* funtion button */
106 MPP42_GPIO, /* power switch */
107 MPP43_GPIO, /* power auto switch */
112 MPP48_GPIO, /* function red LED */
117 kirkwood_mpp_conf(kwmpp_config, NULL);
123 #define LED_ALARM_ON 1
124 #define LED_ALARM_BLINKING 2
125 #define LED_POWER_ON 3
126 #define LED_POWER_BLINKING 4
127 #define LED_INFO_ON 5
128 #define LED_INFO_BLINKING 6
130 static void __set_led(int blink_alarm, int blink_info, int blink_power,
131 int value_alarm, int value_info, int value_power)
133 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
134 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
135 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
136 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
137 kw_gpio_set_value(GPIO_INFO_LED, value_info);
138 kw_gpio_set_value(GPIO_POWER_LED, value_power);
141 static void set_led(int state)
145 __set_led(0, 0, 0, 1, 1, 1);
148 __set_led(0, 0, 0, 0, 1, 1);
150 case LED_ALARM_BLINKING:
151 __set_led(1, 0, 0, 1, 1, 1);
154 __set_led(0, 0, 0, 1, 0, 1);
156 case LED_INFO_BLINKING:
157 __set_led(0, 1, 0, 1, 1, 1);
160 __set_led(0, 0, 0, 1, 1, 0);
162 case LED_POWER_BLINKING:
163 __set_led(0, 0, 1, 1, 1, 1);
170 /* address of boot parameters */
171 gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
173 set_led(LED_POWER_BLINKING);
178 #ifdef CONFIG_MISC_INIT_R
179 static void check_power_switch(void)
181 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
182 /* turn off fan, HDD and USB power */
183 kw_gpio_set_value(GPIO_HDD_POWER, 0);
184 kw_gpio_set_value(GPIO_USB_VBUS, 0);
185 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
186 kw_gpio_set_value(GPIO_FAN_LOW, 1);
189 /* loop until released */
190 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
193 /* turn power on again */
194 kw_gpio_set_value(GPIO_HDD_POWER, 1);
195 kw_gpio_set_value(GPIO_USB_VBUS, 1);
196 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
197 kw_gpio_set_value(GPIO_FAN_LOW, 0);
198 set_led(LED_POWER_BLINKING);
202 void check_enetaddr(void)
206 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
207 /* signal unset/invalid ethaddr to user */
208 set_led(LED_INFO_BLINKING);
212 static void erase_environment(void)
214 struct spi_flash *flash;
216 printf("Erasing environment..\n");
217 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
219 printf("Erasing flash failed\n");
223 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
224 spi_flash_free(flash);
225 do_reset(NULL, 0, 0, NULL);
228 static void rescue_mode(void)
230 printf("Entering rescue mode..\n");
231 setenv("bootsource", "rescue");
234 static void check_push_button(void)
238 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
243 set_led(LED_INFO_ON);
246 set_led(LED_INFO_BLINKING);
257 int misc_init_r(void)
259 check_power_switch();
267 #ifdef CONFIG_SHOW_BOOT_PROGRESS
268 void show_boot_progress(int progress)
273 /* this is not an error, eg. bootp with autoload=no will trigger this */
274 if (progress == -BOOTSTAGE_ID_NET_LOADED)
277 set_led(LED_ALARM_BLINKING);