Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michael Walle | dccfa46 | 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 | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 11 | #include <environment.h> |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 12 | #include <net.h> |
| 13 | #include <malloc.h> |
| 14 | #include <netdev.h> |
| 15 | #include <miiphy.h> |
Simon Glass | d34b456 | 2014-10-13 23:42:04 -0600 | [diff] [blame] | 16 | #include <spi.h> |
| 17 | #include <spi_flash.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 18 | #include <asm/arch/soc.h> |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 19 | #include <asm/arch/cpu.h> |
| 20 | #include <asm/arch/mpp.h> |
| 21 | #include <asm/arch/gpio.h> |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 22 | |
| 23 | #include "lsxl.h" |
| 24 | |
| 25 | /* |
| 26 | * Rescue mode |
| 27 | * |
| 28 | * Selected by holding the push button for 3 seconds, while powering on |
| 29 | * the device. |
| 30 | * |
| 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 |
Michael Walle | dc3ba8e | 2012-10-04 06:54:25 +0000 | [diff] [blame] | 37 | * configured and the ncip is unset. Therefore, all netconsole packets are |
| 38 | * broadcasted. |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 39 | * Additionally, the bootsource is set to 'rescue'. |
| 40 | */ |
| 41 | |
| 42 | #ifndef CONFIG_ENV_OVERWRITE |
| 43 | # error "You need to set CONFIG_ENV_OVERWRITE" |
| 44 | #endif |
| 45 | |
| 46 | DECLARE_GLOBAL_DATA_PTR; |
| 47 | |
| 48 | int board_early_init_f(void) |
| 49 | { |
| 50 | /* |
| 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 |
| 54 | */ |
Stefan Roese | c50ab39 | 2014-10-22 12:13:11 +0200 | [diff] [blame] | 55 | mvebu_config_gpio(LSXL_OE_VAL_LOW, |
| 56 | LSXL_OE_VAL_HIGH, |
| 57 | LSXL_OE_LOW, LSXL_OE_HIGH); |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Multi-Purpose Pins Functionality configuration |
| 61 | * These strappings are taken from the original vendor uboot port. |
| 62 | */ |
Albert ARIBAUD | 4d42431 | 2012-11-26 11:27:36 +0000 | [diff] [blame] | 63 | static const u32 kwmpp_config[] = { |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 64 | MPP0_SPI_SCn, |
| 65 | MPP1_SPI_MOSI, |
| 66 | MPP2_SPI_SCK, |
| 67 | MPP3_SPI_MISO, |
| 68 | MPP4_UART0_RXD, |
| 69 | MPP5_UART0_TXD, |
| 70 | MPP6_SYSRST_OUTn, |
| 71 | MPP7_GPO, |
| 72 | MPP8_GPIO, |
| 73 | MPP9_GPIO, |
| 74 | MPP10_GPO, /* HDD power */ |
| 75 | MPP11_GPIO, /* USB Vbus enable */ |
| 76 | MPP12_SD_CLK, |
| 77 | MPP13_SD_CMD, |
| 78 | MPP14_SD_D0, |
| 79 | MPP15_SD_D1, |
| 80 | MPP16_SD_D2, |
| 81 | MPP17_SD_D3, |
| 82 | MPP18_GPO, /* fan speed high */ |
| 83 | MPP19_GPO, /* fan speed low */ |
| 84 | MPP20_GE1_0, |
| 85 | MPP21_GE1_1, |
| 86 | MPP22_GE1_2, |
| 87 | MPP23_GE1_3, |
| 88 | MPP24_GE1_4, |
| 89 | MPP25_GE1_5, |
| 90 | MPP26_GE1_6, |
| 91 | MPP27_GE1_7, |
| 92 | MPP28_GPIO, |
| 93 | MPP29_GPIO, |
| 94 | MPP30_GE1_10, |
| 95 | MPP31_GE1_11, |
| 96 | MPP32_GE1_12, |
| 97 | MPP33_GE1_13, |
| 98 | MPP34_GPIO, |
| 99 | MPP35_GPIO, |
| 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 */ |
| 108 | MPP44_GPIO, |
| 109 | MPP45_GPIO, |
| 110 | MPP46_GPIO, |
| 111 | MPP47_GPIO, |
| 112 | MPP48_GPIO, /* function red LED */ |
| 113 | MPP49_GPIO, |
| 114 | 0 |
| 115 | }; |
| 116 | |
| 117 | kirkwood_mpp_conf(kwmpp_config, NULL); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | #define LED_OFF 0 |
| 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 |
| 129 | |
| 130 | static void __set_led(int blink_alarm, int blink_info, int blink_power, |
| 131 | int value_alarm, int value_info, int value_power) |
| 132 | { |
| 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); |
| 139 | } |
| 140 | |
| 141 | static void set_led(int state) |
| 142 | { |
| 143 | switch (state) { |
| 144 | case LED_OFF: |
Michael Walle | b31f384 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 145 | __set_led(0, 0, 0, 1, 1, 1); |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 146 | break; |
| 147 | case LED_ALARM_ON: |
| 148 | __set_led(0, 0, 0, 0, 1, 1); |
| 149 | break; |
| 150 | case LED_ALARM_BLINKING: |
| 151 | __set_led(1, 0, 0, 1, 1, 1); |
| 152 | break; |
| 153 | case LED_INFO_ON: |
| 154 | __set_led(0, 0, 0, 1, 0, 1); |
| 155 | break; |
| 156 | case LED_INFO_BLINKING: |
| 157 | __set_led(0, 1, 0, 1, 1, 1); |
| 158 | break; |
| 159 | case LED_POWER_ON: |
| 160 | __set_led(0, 0, 0, 1, 1, 0); |
| 161 | break; |
| 162 | case LED_POWER_BLINKING: |
| 163 | __set_led(0, 0, 1, 1, 1, 1); |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | int board_init(void) |
| 169 | { |
| 170 | /* address of boot parameters */ |
Stefan Roese | 0b74175 | 2014-10-22 12:13:13 +0200 | [diff] [blame] | 171 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 172 | |
| 173 | set_led(LED_POWER_BLINKING); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | #ifdef CONFIG_MISC_INIT_R |
Michael Walle | b31f384 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 179 | static void check_power_switch(void) |
| 180 | { |
| 181 | if (kw_gpio_get_value(GPIO_POWER_SWITCH)) { |
Michael Walle | 61aa89f | 2012-09-30 03:11:05 +0000 | [diff] [blame] | 182 | /* turn off fan, HDD and USB power */ |
Michael Walle | b31f384 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 183 | kw_gpio_set_value(GPIO_HDD_POWER, 0); |
| 184 | kw_gpio_set_value(GPIO_USB_VBUS, 0); |
Michael Walle | 61aa89f | 2012-09-30 03:11:05 +0000 | [diff] [blame] | 185 | kw_gpio_set_value(GPIO_FAN_HIGH, 1); |
| 186 | kw_gpio_set_value(GPIO_FAN_LOW, 1); |
Michael Walle | b31f384 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 187 | set_led(LED_OFF); |
| 188 | |
| 189 | /* loop until released */ |
| 190 | while (kw_gpio_get_value(GPIO_POWER_SWITCH)) |
| 191 | ; |
| 192 | |
| 193 | /* turn power on again */ |
| 194 | kw_gpio_set_value(GPIO_HDD_POWER, 1); |
| 195 | kw_gpio_set_value(GPIO_USB_VBUS, 1); |
Michael Walle | 61aa89f | 2012-09-30 03:11:05 +0000 | [diff] [blame] | 196 | kw_gpio_set_value(GPIO_FAN_HIGH, 0); |
| 197 | kw_gpio_set_value(GPIO_FAN_LOW, 0); |
Michael Walle | b31f384 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 198 | set_led(LED_POWER_BLINKING); |
| 199 | } |
| 200 | } |
| 201 | |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 202 | void check_enetaddr(void) |
| 203 | { |
| 204 | uchar enetaddr[6]; |
| 205 | |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 206 | if (!eth_env_get_enetaddr("ethaddr", enetaddr)) { |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 207 | /* signal unset/invalid ethaddr to user */ |
| 208 | set_led(LED_INFO_BLINKING); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | static void erase_environment(void) |
| 213 | { |
| 214 | struct spi_flash *flash; |
| 215 | |
| 216 | printf("Erasing environment..\n"); |
| 217 | flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3); |
| 218 | if (!flash) { |
| 219 | printf("Erasing flash failed\n"); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE); |
| 224 | spi_flash_free(flash); |
| 225 | do_reset(NULL, 0, 0, NULL); |
| 226 | } |
| 227 | |
| 228 | static void rescue_mode(void) |
| 229 | { |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 230 | printf("Entering rescue mode..\n"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 231 | env_set("bootsource", "rescue"); |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static void check_push_button(void) |
| 235 | { |
| 236 | int i = 0; |
| 237 | |
| 238 | while (!kw_gpio_get_value(GPIO_FUNC_BUTTON)) { |
| 239 | udelay(100000); |
| 240 | i++; |
| 241 | |
| 242 | if (i == 10) |
| 243 | set_led(LED_INFO_ON); |
| 244 | |
| 245 | if (i >= 100) { |
| 246 | set_led(LED_INFO_BLINKING); |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | if (i >= 100) |
| 252 | erase_environment(); |
| 253 | else if (i >= 10) |
| 254 | rescue_mode(); |
| 255 | } |
| 256 | |
| 257 | int misc_init_r(void) |
| 258 | { |
Michael Walle | b31f384 | 2012-07-30 10:47:12 +0000 | [diff] [blame] | 259 | check_power_switch(); |
Michael Walle | dccfa46 | 2012-06-05 11:33:17 +0000 | [diff] [blame] | 260 | check_enetaddr(); |
| 261 | check_push_button(); |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | #endif |
| 266 | |
| 267 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 268 | void show_boot_progress(int progress) |
| 269 | { |
| 270 | if (progress > 0) |
| 271 | return; |
| 272 | |
| 273 | /* this is not an error, eg. bootp with autoload=no will trigger this */ |
| 274 | if (progress == -BOOTSTAGE_ID_NET_LOADED) |
| 275 | return; |
| 276 | |
| 277 | set_led(LED_ALARM_BLINKING); |
| 278 | } |
| 279 | #endif |