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+
16 #include <asm/arch/kirkwood.h>
17 #include <asm/arch/cpu.h>
18 #include <asm/arch/mpp.h>
19 #include <asm/arch/gpio.h>
20 #include <spi_flash.h>
27 * Selected by holding the push button for 3 seconds, while powering on
30 * These linkstations don't have a (populated) serial port. There is no
31 * way to access an (unmodified) board other than using the netconsole. If
32 * you want to recover from a bad environment setting or an empty environment,
33 * you can do this only with a working network connection. Therefore, a random
34 * ethernet address is generated if none is set and a DHCP request is sent.
35 * After a successful DHCP response is received, the network settings are
36 * configured and the ncip is unset. Therefore, all netconsole packets are
38 * Additionally, the bootsource is set to 'rescue'.
41 #ifndef CONFIG_ENV_OVERWRITE
42 # error "You need to set CONFIG_ENV_OVERWRITE"
45 DECLARE_GLOBAL_DATA_PTR;
47 int board_early_init_f(void)
50 * default gpio configuration
51 * There are maximum 64 gpios controlled through 2 sets of registers
52 * the below configuration configures mainly initial LED status
54 kw_config_gpio(LSXL_OE_VAL_LOW,
56 LSXL_OE_LOW, LSXL_OE_HIGH);
59 * Multi-Purpose Pins Functionality configuration
60 * These strappings are taken from the original vendor uboot port.
62 static const u32 kwmpp_config[] = {
73 MPP10_GPO, /* HDD power */
74 MPP11_GPIO, /* USB Vbus enable */
81 MPP18_GPO, /* fan speed high */
82 MPP19_GPO, /* fan speed low */
99 MPP36_GPIO, /* function LED */
100 MPP37_GPIO, /* alarm LED */
101 MPP38_GPIO, /* info LED */
102 MPP39_GPIO, /* power LED */
103 MPP40_GPIO, /* fan alarm */
104 MPP41_GPIO, /* funtion button */
105 MPP42_GPIO, /* power switch */
106 MPP43_GPIO, /* power auto switch */
111 MPP48_GPIO, /* function red LED */
116 kirkwood_mpp_conf(kwmpp_config, NULL);
122 #define LED_ALARM_ON 1
123 #define LED_ALARM_BLINKING 2
124 #define LED_POWER_ON 3
125 #define LED_POWER_BLINKING 4
126 #define LED_INFO_ON 5
127 #define LED_INFO_BLINKING 6
129 static void __set_led(int blink_alarm, int blink_info, int blink_power,
130 int value_alarm, int value_info, int value_power)
132 kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm);
133 kw_gpio_set_blink(GPIO_INFO_LED, blink_info);
134 kw_gpio_set_blink(GPIO_POWER_LED, blink_power);
135 kw_gpio_set_value(GPIO_ALARM_LED, value_alarm);
136 kw_gpio_set_value(GPIO_INFO_LED, value_info);
137 kw_gpio_set_value(GPIO_POWER_LED, value_power);
140 static void set_led(int state)
144 __set_led(0, 0, 0, 1, 1, 1);
147 __set_led(0, 0, 0, 0, 1, 1);
149 case LED_ALARM_BLINKING:
150 __set_led(1, 0, 0, 1, 1, 1);
153 __set_led(0, 0, 0, 1, 0, 1);
155 case LED_INFO_BLINKING:
156 __set_led(0, 1, 0, 1, 1, 1);
159 __set_led(0, 0, 0, 1, 1, 0);
161 case LED_POWER_BLINKING:
162 __set_led(0, 0, 1, 1, 1, 1);
169 /* address of boot parameters */
170 gd->bd->bi_boot_params = kw_sdram_bar(0) + 0x100;
172 set_led(LED_POWER_BLINKING);
177 #ifdef CONFIG_MISC_INIT_R
178 static void check_power_switch(void)
180 if (kw_gpio_get_value(GPIO_POWER_SWITCH)) {
181 /* turn off fan, HDD and USB power */
182 kw_gpio_set_value(GPIO_HDD_POWER, 0);
183 kw_gpio_set_value(GPIO_USB_VBUS, 0);
184 kw_gpio_set_value(GPIO_FAN_HIGH, 1);
185 kw_gpio_set_value(GPIO_FAN_LOW, 1);
188 /* loop until released */
189 while (kw_gpio_get_value(GPIO_POWER_SWITCH))
192 /* turn power on again */
193 kw_gpio_set_value(GPIO_HDD_POWER, 1);
194 kw_gpio_set_value(GPIO_USB_VBUS, 1);
195 kw_gpio_set_value(GPIO_FAN_HIGH, 0);
196 kw_gpio_set_value(GPIO_FAN_LOW, 0);
197 set_led(LED_POWER_BLINKING);
201 void check_enetaddr(void)
205 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
206 /* signal unset/invalid ethaddr to user */
207 set_led(LED_INFO_BLINKING);
211 static void erase_environment(void)
213 struct spi_flash *flash;
215 printf("Erasing environment..\n");
216 flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
218 printf("Erasing flash failed\n");
222 spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
223 spi_flash_free(flash);
224 do_reset(NULL, 0, 0, NULL);
227 static void rescue_mode(void)
231 printf("Entering rescue mode..\n");
232 #ifdef CONFIG_RANDOM_MACADDR
233 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
234 eth_random_addr(enetaddr);
235 if (eth_setenv_enetaddr("ethaddr", enetaddr)) {
236 printf("Failed to set ethernet address\n");
237 set_led(LED_ALARM_BLINKING);
242 setenv("bootsource", "rescue");
245 static void check_push_button(void)
249 while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) {
254 set_led(LED_INFO_ON);
257 set_led(LED_INFO_BLINKING);
268 int misc_init_r(void)
270 check_power_switch();
278 #ifdef CONFIG_SHOW_BOOT_PROGRESS
279 void show_boot_progress(int progress)
284 /* this is not an error, eg. bootp with autoload=no will trigger this */
285 if (progress == -BOOTSTAGE_ID_NET_LOADED)
288 set_led(LED_ALARM_BLINKING);