lsxl.c 6.0 KB

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