lsxl.c 5.9 KB

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