Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012 Michael Walle |
| 4 | * Michael Walle <michael@walle.cc> |
| 5 | * |
| 6 | * Based on sheevaplug/sheevaplug.c by |
| 7 | * Marvell Semiconductor <www.marvell.com> |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 52f2423 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 11 | #include <bootstage.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | #include <command.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 14 | #include <init.h> |
Simon Glass | ff0960f | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 15 | #include <spi.h> |
| 16 | #include <spi_flash.h> |
Stefan Roese | 3dc23f7 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 17 | #include <asm/arch/soc.h> |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 18 | #include <asm/arch/cpu.h> |
| 19 | #include <asm/arch/mpp.h> |
| 20 | #include <asm/arch/gpio.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 22 | #include <linux/delay.h> |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 23 | |
| 24 | #include "lsxl.h" |
| 25 | |
| 26 | /* |
| 27 | * Rescue mode |
| 28 | * |
| 29 | * Selected by holding the push button for 3 seconds, while powering on |
| 30 | * the device. |
| 31 | * |
| 32 | * These linkstations don't have a (populated) serial port. There is no |
| 33 | * way to access an (unmodified) board other than using the netconsole. If |
| 34 | * you want to recover from a bad environment setting or an empty environment, |
| 35 | * you can do this only with a working network connection. Therefore, a random |
| 36 | * ethernet address is generated if none is set and a DHCP request is sent. |
| 37 | * After a successful DHCP response is received, the network settings are |
Michael Walle | 23c9946 | 2012-10-04 06:54:25 +0000 | [diff] [blame] | 38 | * configured and the ncip is unset. Therefore, all netconsole packets are |
| 39 | * broadcasted. |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 40 | * Additionally, the bootsource is set to 'rescue'. |
| 41 | */ |
| 42 | |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 43 | DECLARE_GLOBAL_DATA_PTR; |
| 44 | |
| 45 | int board_early_init_f(void) |
| 46 | { |
| 47 | /* |
| 48 | * default gpio configuration |
| 49 | * There are maximum 64 gpios controlled through 2 sets of registers |
| 50 | * the below configuration configures mainly initial LED status |
| 51 | */ |
Stefan Roese | d5c5132 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 52 | mvebu_config_gpio(LSXL_OE_VAL_LOW, |
| 53 | LSXL_OE_VAL_HIGH, |
| 54 | LSXL_OE_LOW, LSXL_OE_HIGH); |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * Multi-Purpose Pins Functionality configuration |
| 58 | * These strappings are taken from the original vendor uboot port. |
| 59 | */ |
Albert ARIBAUD | 9d86f0c | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 60 | static const u32 kwmpp_config[] = { |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 61 | MPP0_SPI_SCn, |
| 62 | MPP1_SPI_MOSI, |
| 63 | MPP2_SPI_SCK, |
| 64 | MPP3_SPI_MISO, |
| 65 | MPP4_UART0_RXD, |
| 66 | MPP5_UART0_TXD, |
| 67 | MPP6_SYSRST_OUTn, |
| 68 | MPP7_GPO, |
| 69 | MPP8_GPIO, |
| 70 | MPP9_GPIO, |
| 71 | MPP10_GPO, /* HDD power */ |
| 72 | MPP11_GPIO, /* USB Vbus enable */ |
| 73 | MPP12_SD_CLK, |
| 74 | MPP13_SD_CMD, |
| 75 | MPP14_SD_D0, |
| 76 | MPP15_SD_D1, |
| 77 | MPP16_SD_D2, |
| 78 | MPP17_SD_D3, |
| 79 | MPP18_GPO, /* fan speed high */ |
| 80 | MPP19_GPO, /* fan speed low */ |
| 81 | MPP20_GE1_0, |
| 82 | MPP21_GE1_1, |
| 83 | MPP22_GE1_2, |
| 84 | MPP23_GE1_3, |
| 85 | MPP24_GE1_4, |
| 86 | MPP25_GE1_5, |
| 87 | MPP26_GE1_6, |
| 88 | MPP27_GE1_7, |
| 89 | MPP28_GPIO, |
| 90 | MPP29_GPIO, |
| 91 | MPP30_GE1_10, |
| 92 | MPP31_GE1_11, |
| 93 | MPP32_GE1_12, |
| 94 | MPP33_GE1_13, |
| 95 | MPP34_GPIO, |
| 96 | MPP35_GPIO, |
| 97 | MPP36_GPIO, /* function LED */ |
| 98 | MPP37_GPIO, /* alarm LED */ |
| 99 | MPP38_GPIO, /* info LED */ |
| 100 | MPP39_GPIO, /* power LED */ |
| 101 | MPP40_GPIO, /* fan alarm */ |
| 102 | MPP41_GPIO, /* funtion button */ |
| 103 | MPP42_GPIO, /* power switch */ |
| 104 | MPP43_GPIO, /* power auto switch */ |
| 105 | MPP44_GPIO, |
| 106 | MPP45_GPIO, |
| 107 | MPP46_GPIO, |
| 108 | MPP47_GPIO, |
| 109 | MPP48_GPIO, /* function red LED */ |
| 110 | MPP49_GPIO, |
| 111 | 0 |
| 112 | }; |
| 113 | |
| 114 | kirkwood_mpp_conf(kwmpp_config, NULL); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | #define LED_OFF 0 |
| 120 | #define LED_ALARM_ON 1 |
| 121 | #define LED_ALARM_BLINKING 2 |
| 122 | #define LED_POWER_ON 3 |
| 123 | #define LED_POWER_BLINKING 4 |
| 124 | #define LED_INFO_ON 5 |
| 125 | #define LED_INFO_BLINKING 6 |
| 126 | |
| 127 | static void __set_led(int blink_alarm, int blink_info, int blink_power, |
| 128 | int value_alarm, int value_info, int value_power) |
| 129 | { |
| 130 | kw_gpio_set_blink(GPIO_ALARM_LED, blink_alarm); |
| 131 | kw_gpio_set_blink(GPIO_INFO_LED, blink_info); |
| 132 | kw_gpio_set_blink(GPIO_POWER_LED, blink_power); |
| 133 | kw_gpio_set_value(GPIO_ALARM_LED, value_alarm); |
| 134 | kw_gpio_set_value(GPIO_INFO_LED, value_info); |
| 135 | kw_gpio_set_value(GPIO_POWER_LED, value_power); |
| 136 | } |
| 137 | |
| 138 | static void set_led(int state) |
| 139 | { |
| 140 | switch (state) { |
| 141 | case LED_OFF: |
Michael Walle | a9f1a48 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 142 | __set_led(0, 0, 0, 1, 1, 1); |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 143 | break; |
| 144 | case LED_ALARM_ON: |
| 145 | __set_led(0, 0, 0, 0, 1, 1); |
| 146 | break; |
| 147 | case LED_ALARM_BLINKING: |
| 148 | __set_led(1, 0, 0, 1, 1, 1); |
| 149 | break; |
| 150 | case LED_INFO_ON: |
| 151 | __set_led(0, 0, 0, 1, 0, 1); |
| 152 | break; |
| 153 | case LED_INFO_BLINKING: |
| 154 | __set_led(0, 1, 0, 1, 1, 1); |
| 155 | break; |
| 156 | case LED_POWER_ON: |
| 157 | __set_led(0, 0, 0, 1, 1, 0); |
| 158 | break; |
| 159 | case LED_POWER_BLINKING: |
| 160 | __set_led(0, 0, 1, 1, 1, 1); |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | int board_init(void) |
| 166 | { |
| 167 | /* address of boot parameters */ |
Stefan Roese | 96c5f08 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 168 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 169 | |
| 170 | set_led(LED_POWER_BLINKING); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Michael Walle | a9f1a48 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 175 | static void check_power_switch(void) |
| 176 | { |
| 177 | if (kw_gpio_get_value(GPIO_POWER_SWITCH)) { |
Michael Walle | 9bd2317 | 2012-09-30 03:11:05 +0000 | [diff] [blame] | 178 | /* turn off fan, HDD and USB power */ |
Michael Walle | a9f1a48 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 179 | kw_gpio_set_value(GPIO_HDD_POWER, 0); |
| 180 | kw_gpio_set_value(GPIO_USB_VBUS, 0); |
Michael Walle | 9bd2317 | 2012-09-30 03:11:05 +0000 | [diff] [blame] | 181 | kw_gpio_set_value(GPIO_FAN_HIGH, 1); |
| 182 | kw_gpio_set_value(GPIO_FAN_LOW, 1); |
Michael Walle | a9f1a48 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 183 | set_led(LED_OFF); |
| 184 | |
| 185 | /* loop until released */ |
| 186 | while (kw_gpio_get_value(GPIO_POWER_SWITCH)) |
| 187 | ; |
| 188 | |
| 189 | /* turn power on again */ |
| 190 | kw_gpio_set_value(GPIO_HDD_POWER, 1); |
| 191 | kw_gpio_set_value(GPIO_USB_VBUS, 1); |
Michael Walle | 9bd2317 | 2012-09-30 03:11:05 +0000 | [diff] [blame] | 192 | kw_gpio_set_value(GPIO_FAN_HIGH, 0); |
| 193 | kw_gpio_set_value(GPIO_FAN_LOW, 0); |
Michael Walle | a9f1a48 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 194 | set_led(LED_POWER_BLINKING); |
| 195 | } |
| 196 | } |
| 197 | |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 198 | void check_enetaddr(void) |
| 199 | { |
| 200 | uchar enetaddr[6]; |
| 201 | |
Simon Glass | 35affd7 | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 202 | if (!eth_env_get_enetaddr("ethaddr", enetaddr)) { |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 203 | /* signal unset/invalid ethaddr to user */ |
| 204 | set_led(LED_INFO_BLINKING); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | static void erase_environment(void) |
| 209 | { |
| 210 | struct spi_flash *flash; |
| 211 | |
| 212 | printf("Erasing environment..\n"); |
| 213 | flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3); |
| 214 | if (!flash) { |
| 215 | printf("Erasing flash failed\n"); |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE); |
| 220 | spi_flash_free(flash); |
| 221 | do_reset(NULL, 0, 0, NULL); |
| 222 | } |
| 223 | |
| 224 | static void rescue_mode(void) |
| 225 | { |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 226 | printf("Entering rescue mode..\n"); |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 227 | env_set("bootsource", "rescue"); |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static void check_push_button(void) |
| 231 | { |
| 232 | int i = 0; |
| 233 | |
| 234 | while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) { |
| 235 | udelay(100000); |
| 236 | i++; |
| 237 | |
| 238 | if (i == 10) |
| 239 | set_led(LED_INFO_ON); |
| 240 | |
| 241 | if (i >= 100) { |
| 242 | set_led(LED_INFO_BLINKING); |
| 243 | break; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | if (i >= 100) |
| 248 | erase_environment(); |
| 249 | else if (i >= 10) |
| 250 | rescue_mode(); |
| 251 | } |
| 252 | |
| 253 | int misc_init_r(void) |
| 254 | { |
Michael Walle | a9f1a48 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 255 | check_power_switch(); |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 256 | check_enetaddr(); |
| 257 | check_push_button(); |
| 258 | |
| 259 | return 0; |
| 260 | } |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 261 | |
Tom Rini | cb80ff2 | 2021-05-03 16:48:58 -0400 | [diff] [blame] | 262 | #if CONFIG_IS_ENABLED(BOOTSTAGE) |
Michael Walle | f214a20 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 263 | void show_boot_progress(int progress) |
| 264 | { |
| 265 | if (progress > 0) |
| 266 | return; |
| 267 | |
| 268 | /* this is not an error, eg. bootp with autoload=no will trigger this */ |
| 269 | if (progress == -BOOTSTAGE_ID_NET_LOADED) |
| 270 | return; |
| 271 | |
| 272 | set_led(LED_ALARM_BLINKING); |
| 273 | } |
| 274 | #endif |