display5.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 DENX Software Engineering
  4. * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/clock.h>
  10. #include <asm/arch/imx-regs.h>
  11. #include <asm/arch/iomux.h>
  12. #include <asm/arch/mx6-pins.h>
  13. #include <asm/arch/mx6-ddr.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <env.h>
  16. #include <errno.h>
  17. #include <asm/gpio.h>
  18. #include <malloc.h>
  19. #include <asm/mach-imx/iomux-v3.h>
  20. #include <asm/mach-imx/boot_mode.h>
  21. #include <miiphy.h>
  22. #include <netdev.h>
  23. #include <i2c.h>
  24. #include <dm.h>
  25. #include <dm/platform_data/serial_mxc.h>
  26. #include <dm/platdata.h>
  27. #include "common.h"
  28. DECLARE_GLOBAL_DATA_PTR;
  29. static bool hw_ids_valid;
  30. static bool sw_ids_valid;
  31. static u32 cpu_id;
  32. static u32 unit_id;
  33. const char *gpio_table_sw_names[] = {
  34. "GPIO2_4", "GPIO2_5", "GPIO2_6", "GPIO2_7"
  35. };
  36. const char *gpio_table_sw_ids_names[] = {
  37. "sw0", "sw1", "sw2", "sw3"
  38. };
  39. const char *gpio_table_hw_names[] = {
  40. "GPIO6_7", "GPIO6_9", "GPIO6_10", "GPIO6_11",
  41. "GPIO4_7", "GPIO4_11", "GPIO4_13", "GPIO4_15"
  42. };
  43. const char *gpio_table_hw_ids_names[] = {
  44. "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7"
  45. };
  46. static int get_board_id(const char **pin_names, const char **ids_names,
  47. int size, bool *valid, u32 *id)
  48. {
  49. struct gpio_desc desc;
  50. int i, ret, val;
  51. *valid = false;
  52. for (i = 0; i < size; i++) {
  53. memset(&desc, 0, sizeof(desc));
  54. ret = dm_gpio_lookup_name(pin_names[i], &desc);
  55. if (ret) {
  56. printf("Can't lookup request SWx gpios\n");
  57. return ret;
  58. }
  59. ret = dm_gpio_request(&desc, ids_names[i]);
  60. if (ret) {
  61. printf("Can't lookup request SWx gpios\n");
  62. return ret;
  63. }
  64. dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN);
  65. val = dm_gpio_get_value(&desc);
  66. if (val < 0) {
  67. printf("Can't get SW%d ID\n", i);
  68. *id = 0;
  69. return val;
  70. }
  71. *id |= val << i;
  72. }
  73. *valid = true;
  74. return 0;
  75. }
  76. int dram_init(void)
  77. {
  78. gd->ram_size = imx_ddr_size();
  79. return 0;
  80. }
  81. iomux_v3_cfg_t const misc_pads[] = {
  82. /* Prod ID GPIO pins */
  83. MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL),
  84. MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL),
  85. MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL),
  86. MX6_PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
  87. /* HW revision GPIO pins */
  88. MX6_PAD_NANDF_CLE__GPIO6_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
  89. MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
  90. MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
  91. MX6_PAD_NANDF_CS0__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
  92. MX6_PAD_KEY_ROW0__GPIO4_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
  93. MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
  94. MX6_PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL),
  95. MX6_PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL),
  96. /* XTALOSC */
  97. MX6_PAD_GPIO_3__XTALOSC_REF_CLK_24M | MUX_PAD_CTRL(NO_PAD_CTRL),
  98. /* Emergency recovery pin */
  99. MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL),
  100. };
  101. /*
  102. * Do not overwrite the console
  103. * Always use serial for U-Boot console
  104. */
  105. int overwrite_console(void)
  106. {
  107. return 1;
  108. }
  109. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  110. int ft_board_setup(void *blob, bd_t *bd)
  111. {
  112. fdt_fixup_ethernet(blob);
  113. return 0;
  114. }
  115. #endif
  116. int board_phy_config(struct phy_device *phydev)
  117. {
  118. /* display5 due to PCB routing can only work with 100 Mbps */
  119. phydev->advertising &= ~(ADVERTISED_1000baseX_Half |
  120. ADVERTISED_1000baseX_Full |
  121. SUPPORTED_1000baseT_Half |
  122. SUPPORTED_1000baseT_Full);
  123. if (phydev->drv->config)
  124. return phydev->drv->config(phydev);
  125. return 0;
  126. }
  127. int board_init(void)
  128. {
  129. struct gpio_desc phy_int_gbe, spi2_wp;
  130. int ret;
  131. debug("board init\n");
  132. /* address of boot parameters */
  133. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  134. /* Setup misc (application specific) stuff */
  135. SETUP_IOMUX_PADS(misc_pads);
  136. get_board_id(gpio_table_sw_names, &gpio_table_sw_ids_names[0],
  137. ARRAY_SIZE(gpio_table_sw_names), &sw_ids_valid, &unit_id);
  138. debug("SWx unit_id 0x%x\n", unit_id);
  139. get_board_id(gpio_table_hw_names, &gpio_table_hw_ids_names[0],
  140. ARRAY_SIZE(gpio_table_hw_names), &hw_ids_valid, &cpu_id);
  141. debug("HWx cpu_id 0x%x\n", cpu_id);
  142. if (hw_ids_valid && sw_ids_valid)
  143. printf("ID: unit type 0x%x rev 0x%x\n", unit_id, cpu_id);
  144. udelay(25);
  145. /* Setup low level FEC (ETH) */
  146. ret = dm_gpio_lookup_name("GPIO1_28", &phy_int_gbe);
  147. if (ret) {
  148. printf("Cannot get GPIO1_28\n");
  149. } else {
  150. ret = dm_gpio_request(&phy_int_gbe, "INT_GBE");
  151. if (!ret)
  152. dm_gpio_set_dir_flags(&phy_int_gbe, GPIOD_IS_IN);
  153. }
  154. iomuxc_set_rgmii_io_voltage(DDR_SEL_1P5V_IO);
  155. enable_fec_anatop_clock(0, ENET_125MHZ);
  156. /* Setup #WP for SPI-NOR memory */
  157. ret = dm_gpio_lookup_name("GPIO7_0", &spi2_wp);
  158. if (ret) {
  159. printf("Cannot get GPIO7_0\n");
  160. } else {
  161. ret = dm_gpio_request(&spi2_wp, "spi2_#wp");
  162. if (!ret)
  163. dm_gpio_set_dir_flags(&spi2_wp, GPIOD_IS_OUT |
  164. GPIOD_IS_OUT_ACTIVE);
  165. }
  166. return 0;
  167. }
  168. #ifdef CONFIG_CMD_BMODE
  169. static const struct boot_mode board_boot_modes[] = {
  170. /* eMMC, USDHC-4, 8-bit bus width */
  171. /* SPI-NOR, ECSPI-2 SS0, 3-bytes addressing */
  172. {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)},
  173. {"spinor", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x09)},
  174. {NULL, 0},
  175. };
  176. static void setup_boot_modes(void)
  177. {
  178. add_board_boot_modes(board_boot_modes);
  179. }
  180. #else
  181. static inline void setup_boot_modes(void) {}
  182. #endif
  183. int misc_init_r(void)
  184. {
  185. struct gpio_desc em_pad;
  186. int ret;
  187. setup_boot_modes();
  188. ret = dm_gpio_lookup_name("GPIO3_29", &em_pad);
  189. if (ret) {
  190. printf("Can't find emergency PAD gpio\n");
  191. return ret;
  192. }
  193. ret = dm_gpio_request(&em_pad, "Emergency_PAD");
  194. if (ret) {
  195. printf("Can't request emergency PAD gpio\n");
  196. return ret;
  197. }
  198. dm_gpio_set_dir_flags(&em_pad, GPIOD_IS_IN);
  199. return 0;
  200. }