lsxl.c 5.9 KB

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