sbx81lifkw.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2010, 2018
  4. * Allied Telesis <www.alliedtelesis.com>
  5. */
  6. #include <common.h>
  7. #include <init.h>
  8. #include <net.h>
  9. #include <linux/bitops.h>
  10. #include <linux/delay.h>
  11. #include <linux/io.h>
  12. #include <miiphy.h>
  13. #include <netdev.h>
  14. #include <status_led.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/soc.h>
  17. #include <asm/arch/mpp.h>
  18. #include <asm/arch/gpio.h>
  19. /* Note: GPIO differences between specific boards
  20. *
  21. * We're trying to avoid having multiple build targets for all the Kirkwood
  22. * based boards one area where things tend to differ is GPIO usage. For the
  23. * most part the GPIOs driven by the bootloader are similar enough in function
  24. * that there is no harm in driving them.
  25. *
  26. * XZ4 XS6 XS16 GS24A GT40 GP24A GT24A
  27. * GPIO39 - INT(<) NC MUX_RST_N(>) NC POE_DIS_N(>) NC
  28. */
  29. #define SBX81LIFKW_OE_LOW ~(BIT(31) | BIT(30) | BIT(28) | BIT(27) | \
  30. BIT(18) | BIT(17) | BIT(13) | BIT(12) | \
  31. BIT(10))
  32. #define SBX81LIFKW_OE_HIGH ~(BIT(0) | BIT(1) | BIT(7))
  33. #define SBX81LIFKW_OE_VAL_LOW (BIT(31) | BIT(30) | BIT(28) | BIT(27))
  34. #define SBX81LIFKW_OE_VAL_HIGH (BIT(0) | BIT(1))
  35. #define MV88E6097_RESET 27
  36. DECLARE_GLOBAL_DATA_PTR;
  37. struct led {
  38. u32 reg;
  39. u32 value;
  40. u32 mask;
  41. };
  42. struct led amber_solid = {
  43. MVEBU_GPIO0_BASE,
  44. BIT(10),
  45. BIT(18) | BIT(10)
  46. };
  47. struct led green_solid = {
  48. MVEBU_GPIO0_BASE,
  49. BIT(18) | BIT(10),
  50. BIT(18) | BIT(10)
  51. };
  52. struct led amber_flash = {
  53. MVEBU_GPIO0_BASE,
  54. 0,
  55. BIT(18) | BIT(10)
  56. };
  57. struct led green_flash = {
  58. MVEBU_GPIO0_BASE,
  59. BIT(18),
  60. BIT(18) | BIT(10)
  61. };
  62. static void status_led_set(struct led *led)
  63. {
  64. clrsetbits_le32(led->reg, led->mask, led->value);
  65. }
  66. int board_early_init_f(void)
  67. {
  68. /*
  69. * default gpio configuration
  70. * There are maximum 64 gpios controlled through 2 sets of registers
  71. * the below configuration configures mainly initial LED status
  72. */
  73. mvebu_config_gpio(SBX81LIFKW_OE_VAL_LOW,
  74. SBX81LIFKW_OE_VAL_HIGH,
  75. SBX81LIFKW_OE_LOW, SBX81LIFKW_OE_HIGH);
  76. /* Multi-Purpose Pins Functionality configuration */
  77. static const u32 kwmpp_config[] = {
  78. MPP0_SPI_SCn,
  79. MPP1_SPI_MOSI,
  80. MPP2_SPI_SCK,
  81. MPP3_SPI_MISO,
  82. MPP4_UART0_RXD,
  83. MPP5_UART0_TXD,
  84. MPP6_SYSRST_OUTn,
  85. MPP7_PEX_RST_OUTn,
  86. MPP8_TW_SDA,
  87. MPP9_TW_SCK,
  88. MPP10_GPO,
  89. MPP11_GPIO,
  90. MPP12_GPO,
  91. MPP13_GPIO,
  92. MPP14_GPIO,
  93. MPP15_UART0_RTS,
  94. MPP16_UART0_CTS,
  95. MPP17_GPIO,
  96. MPP18_GPO,
  97. MPP19_GPO,
  98. MPP20_GPIO,
  99. MPP21_GPIO,
  100. MPP22_GPIO,
  101. MPP23_GPIO,
  102. MPP24_GPIO,
  103. MPP25_GPIO,
  104. MPP26_GPIO,
  105. MPP27_GPIO,
  106. MPP28_GPIO,
  107. MPP29_GPIO,
  108. MPP30_GPIO,
  109. MPP31_GPIO,
  110. MPP32_GPIO,
  111. MPP33_GPIO,
  112. MPP34_GPIO,
  113. MPP35_GPIO,
  114. MPP36_GPIO,
  115. MPP37_GPIO,
  116. MPP38_GPIO,
  117. MPP39_GPIO,
  118. MPP40_GPIO,
  119. MPP41_GPIO,
  120. MPP42_GPIO,
  121. MPP43_GPIO,
  122. MPP44_GPIO,
  123. MPP45_GPIO,
  124. MPP46_GPIO,
  125. MPP47_GPIO,
  126. MPP48_GPIO,
  127. MPP49_GPIO,
  128. 0
  129. };
  130. kirkwood_mpp_conf(kwmpp_config, NULL);
  131. return 0;
  132. }
  133. int board_init(void)
  134. {
  135. /* Power-down unused subsystems. The required
  136. * subsystems are:
  137. *
  138. * GE0 b0
  139. * PEX0 PHY b1
  140. * PEX0.0 b2
  141. * TSU b5
  142. * SDRAM b6
  143. * RUNIT b7
  144. */
  145. writel((BIT(0) | BIT(1) | BIT(2) |
  146. BIT(5) | BIT(6) | BIT(7)),
  147. KW_CPU_REG_BASE + 0x1c);
  148. /* address of boot parameters */
  149. gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
  150. status_led_set(&amber_solid);
  151. return 0;
  152. }
  153. #ifdef CONFIG_RESET_PHY_R
  154. /* automatically defined by kirkwood config.h */
  155. void reset_phy(void)
  156. {
  157. }
  158. #endif
  159. #ifdef CONFIG_MV88E61XX_SWITCH
  160. int mv88e61xx_hw_reset(struct phy_device *phydev)
  161. {
  162. /* Ensure the 88e6097 gets at least 10ms Reset
  163. */
  164. kw_gpio_set_value(MV88E6097_RESET, 0);
  165. mdelay(20);
  166. kw_gpio_set_value(MV88E6097_RESET, 1);
  167. mdelay(20);
  168. phydev->advertising = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full;
  169. return 0;
  170. }
  171. #endif
  172. #ifdef CONFIG_MISC_INIT_R
  173. int misc_init_r(void)
  174. {
  175. status_led_set(&green_flash);
  176. return 0;
  177. }
  178. #endif