board.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net>
  3. *
  4. * (C) Copyright 2007-2011
  5. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  6. * Tom Cubie <tangliang@allwinnertech.com>
  7. *
  8. * Some init for sunxi platform.
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <i2c.h>
  14. #include <netdev.h>
  15. #include <miiphy.h>
  16. #include <serial.h>
  17. #ifdef CONFIG_SPL_BUILD
  18. #include <spl.h>
  19. #endif
  20. #include <asm/gpio.h>
  21. #include <asm/io.h>
  22. #include <asm/arch/clock.h>
  23. #include <asm/arch/gpio.h>
  24. #include <asm/arch/sys_proto.h>
  25. #include <asm/arch/timer.h>
  26. #include <linux/compiler.h>
  27. #ifdef CONFIG_SPL_BUILD
  28. /* Pointer to the global data structure for SPL */
  29. DECLARE_GLOBAL_DATA_PTR;
  30. /* The sunxi internal brom will try to loader external bootloader
  31. * from mmc0, nand flash, mmc2.
  32. * Unfortunately we can't check how SPL was loaded so assume
  33. * it's always the first SD/MMC controller
  34. */
  35. u32 spl_boot_device(void)
  36. {
  37. return BOOT_DEVICE_MMC1;
  38. }
  39. /* No confirmation data available in SPL yet. Hardcode bootmode */
  40. u32 spl_boot_mode(void)
  41. {
  42. return MMCSD_MODE_RAW;
  43. }
  44. #endif
  45. int gpio_init(void)
  46. {
  47. #if CONFIG_CONS_INDEX == 1 && defined(CONFIG_UART0_PORT_F)
  48. #if defined(CONFIG_SUN4I) || defined(CONFIG_SUN7I)
  49. /* disable GPB22,23 as uart0 tx,rx to avoid conflict */
  50. sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUNXI_GPIO_INPUT);
  51. sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUNXI_GPIO_INPUT);
  52. #endif
  53. sunxi_gpio_set_cfgpin(SUNXI_GPF(2), SUNXI_GPF2_UART0_TX);
  54. sunxi_gpio_set_cfgpin(SUNXI_GPF(4), SUNXI_GPF4_UART0_RX);
  55. sunxi_gpio_set_pull(SUNXI_GPF(4), 1);
  56. #elif CONFIG_CONS_INDEX == 1 && (defined(CONFIG_SUN4I) || defined(CONFIG_SUN7I))
  57. sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUN4I_GPB22_UART0_TX);
  58. sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUN4I_GPB23_UART0_RX);
  59. sunxi_gpio_set_pull(SUNXI_GPB(23), SUNXI_GPIO_PULL_UP);
  60. #elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_SUN5I)
  61. sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN5I_GPB19_UART0_TX);
  62. sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN5I_GPB20_UART0_RX);
  63. sunxi_gpio_set_pull(SUNXI_GPB(20), SUNXI_GPIO_PULL_UP);
  64. #elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_SUN6I)
  65. sunxi_gpio_set_cfgpin(SUNXI_GPH(20), SUN6I_GPH20_UART0_TX);
  66. sunxi_gpio_set_cfgpin(SUNXI_GPH(21), SUN6I_GPH21_UART0_RX);
  67. sunxi_gpio_set_pull(SUNXI_GPH(21), SUNXI_GPIO_PULL_UP);
  68. #elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_SUN5I)
  69. sunxi_gpio_set_cfgpin(SUNXI_GPG(3), SUN5I_GPG3_UART1_TX);
  70. sunxi_gpio_set_cfgpin(SUNXI_GPG(4), SUN5I_GPG4_UART1_RX);
  71. sunxi_gpio_set_pull(SUNXI_GPG(4), SUNXI_GPIO_PULL_UP);
  72. #elif CONFIG_CONS_INDEX == 5 && defined(CONFIG_SUN8I)
  73. sunxi_gpio_set_cfgpin(SUNXI_GPL(2), SUN8I_GPL2_R_UART_TX);
  74. sunxi_gpio_set_cfgpin(SUNXI_GPL(3), SUN8I_GPL3_R_UART_RX);
  75. sunxi_gpio_set_pull(SUNXI_GPL(3), SUNXI_GPIO_PULL_UP);
  76. #else
  77. #error Unsupported console port number. Please fix pin mux settings in board.c
  78. #endif
  79. return 0;
  80. }
  81. void reset_cpu(ulong addr)
  82. {
  83. #if defined(CONFIG_SUN4I) || defined(CONFIG_SUN5I) || defined(CONFIG_SUN7I)
  84. static const struct sunxi_wdog *wdog =
  85. &((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
  86. /* Set the watchdog for its shortest interval (.5s) and wait */
  87. writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
  88. writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
  89. while (1) {
  90. /* sun5i sometimes gets stuck without this */
  91. writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
  92. }
  93. #else /* CONFIG_SUN6I || CONFIG_SUN8I || .. */
  94. static const struct sunxi_wdog *wdog =
  95. ((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
  96. /* Set the watchdog for its shortest interval (.5s) and wait */
  97. writel(WDT_CFG_RESET, &wdog->cfg);
  98. writel(WDT_MODE_EN, &wdog->mode);
  99. writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
  100. #endif
  101. }
  102. /* do some early init */
  103. void s_init(void)
  104. {
  105. #if !defined CONFIG_SPL_BUILD && (defined CONFIG_SUN7I || \
  106. defined CONFIG_SUN6I || defined CONFIG_SUN8I)
  107. /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
  108. asm volatile(
  109. "mrc p15, 0, r0, c1, c0, 1\n"
  110. "orr r0, r0, #1 << 6\n"
  111. "mcr p15, 0, r0, c1, c0, 1\n");
  112. #endif
  113. clock_init();
  114. timer_init();
  115. gpio_init();
  116. i2c_init_board();
  117. #ifdef CONFIG_SPL_BUILD
  118. gd = &gdata;
  119. preloader_console_init();
  120. #ifdef CONFIG_SPL_I2C_SUPPORT
  121. /* Needed early by sunxi_board_init if PMU is enabled */
  122. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  123. #endif
  124. sunxi_board_init();
  125. #endif
  126. }
  127. #ifndef CONFIG_SYS_DCACHE_OFF
  128. void enable_caches(void)
  129. {
  130. /* Enable D-cache. I-cache is already enabled in start.S */
  131. dcache_enable();
  132. }
  133. #endif
  134. #ifdef CONFIG_CMD_NET
  135. /*
  136. * Initializes on-chip ethernet controllers.
  137. * to override, implement board_eth_init()
  138. */
  139. int cpu_eth_init(bd_t *bis)
  140. {
  141. __maybe_unused int rc;
  142. #ifdef CONFIG_MACPWR
  143. gpio_direction_output(CONFIG_MACPWR, 1);
  144. mdelay(200);
  145. #endif
  146. #ifdef CONFIG_SUNXI_EMAC
  147. rc = sunxi_emac_initialize(bis);
  148. if (rc < 0) {
  149. printf("sunxi: failed to initialize emac\n");
  150. return rc;
  151. }
  152. #endif
  153. #ifdef CONFIG_SUNXI_GMAC
  154. rc = sunxi_gmac_initialize(bis);
  155. if (rc < 0) {
  156. printf("sunxi: failed to initialize gmac\n");
  157. return rc;
  158. }
  159. #endif
  160. return 0;
  161. }
  162. #endif