lsxl.c 6.0 KB

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