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