board.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * board.c
  3. *
  4. * Common board functions for AM33XX based boards
  5. *
  6. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <errno.h>
  12. #include <spl.h>
  13. #include <asm/arch/cpu.h>
  14. #include <asm/arch/hardware.h>
  15. #include <asm/arch/omap.h>
  16. #include <asm/arch/ddr_defs.h>
  17. #include <asm/arch/clock.h>
  18. #include <asm/arch/gpio.h>
  19. #include <asm/arch/mem.h>
  20. #include <asm/arch/mmc_host_def.h>
  21. #include <asm/arch/sys_proto.h>
  22. #include <asm/io.h>
  23. #include <asm/emif.h>
  24. #include <asm/gpio.h>
  25. #include <i2c.h>
  26. #include <miiphy.h>
  27. #include <cpsw.h>
  28. #include <asm/errno.h>
  29. #include <linux/compiler.h>
  30. #include <linux/usb/ch9.h>
  31. #include <linux/usb/gadget.h>
  32. #include <linux/usb/musb.h>
  33. #include <asm/omap_musb.h>
  34. #include <asm/davinci_rtc.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. static const struct gpio_bank gpio_bank_am33xx[] = {
  37. { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
  38. { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
  39. { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
  40. { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
  41. #ifdef CONFIG_AM43XX
  42. { (void *)AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
  43. { (void *)AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
  44. #endif
  45. };
  46. const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
  47. #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
  48. int cpu_mmc_init(bd_t *bis)
  49. {
  50. int ret;
  51. ret = omap_mmc_init(0, 0, 0, -1, -1);
  52. if (ret)
  53. return ret;
  54. return omap_mmc_init(1, 0, 0, -1, -1);
  55. }
  56. #endif
  57. /* AM33XX has two MUSB controllers which can be host or gadget */
  58. #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
  59. (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
  60. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  61. /* USB 2.0 PHY Control */
  62. #define CM_PHY_PWRDN (1 << 0)
  63. #define CM_PHY_OTG_PWRDN (1 << 1)
  64. #define OTGVDET_EN (1 << 19)
  65. #define OTGSESSENDEN (1 << 20)
  66. static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
  67. {
  68. if (on) {
  69. clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
  70. OTGVDET_EN | OTGSESSENDEN);
  71. } else {
  72. clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
  73. }
  74. }
  75. static struct musb_hdrc_config musb_config = {
  76. .multipoint = 1,
  77. .dyn_fifo = 1,
  78. .num_eps = 16,
  79. .ram_bits = 12,
  80. };
  81. #ifdef CONFIG_AM335X_USB0
  82. static void am33xx_otg0_set_phy_power(u8 on)
  83. {
  84. am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
  85. }
  86. struct omap_musb_board_data otg0_board_data = {
  87. .set_phy_power = am33xx_otg0_set_phy_power,
  88. };
  89. static struct musb_hdrc_platform_data otg0_plat = {
  90. .mode = CONFIG_AM335X_USB0_MODE,
  91. .config = &musb_config,
  92. .power = 50,
  93. .platform_ops = &musb_dsps_ops,
  94. .board_data = &otg0_board_data,
  95. };
  96. #endif
  97. #ifdef CONFIG_AM335X_USB1
  98. static void am33xx_otg1_set_phy_power(u8 on)
  99. {
  100. am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
  101. }
  102. struct omap_musb_board_data otg1_board_data = {
  103. .set_phy_power = am33xx_otg1_set_phy_power,
  104. };
  105. static struct musb_hdrc_platform_data otg1_plat = {
  106. .mode = CONFIG_AM335X_USB1_MODE,
  107. .config = &musb_config,
  108. .power = 50,
  109. .platform_ops = &musb_dsps_ops,
  110. .board_data = &otg1_board_data,
  111. };
  112. #endif
  113. #endif
  114. int arch_misc_init(void)
  115. {
  116. #ifdef CONFIG_AM335X_USB0
  117. musb_register(&otg0_plat, &otg0_board_data,
  118. (void *)USB0_OTG_BASE);
  119. #endif
  120. #ifdef CONFIG_AM335X_USB1
  121. musb_register(&otg1_plat, &otg1_board_data,
  122. (void *)USB1_OTG_BASE);
  123. #endif
  124. return 0;
  125. }
  126. #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
  127. /*
  128. * This function is the place to do per-board things such as ramp up the
  129. * MPU clock frequency.
  130. */
  131. __weak void am33xx_spl_board_init(void)
  132. {
  133. do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
  134. do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
  135. }
  136. #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
  137. static void rtc32k_enable(void)
  138. {
  139. struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
  140. /*
  141. * Unlock the RTC's registers. For more details please see the
  142. * RTC_SS section of the TRM. In order to unlock we need to
  143. * write these specific values (keys) in this order.
  144. */
  145. writel(RTC_KICK0R_WE, &rtc->kick0r);
  146. writel(RTC_KICK1R_WE, &rtc->kick1r);
  147. /* Enable the RTC 32K OSC by setting bits 3 and 6. */
  148. writel((1 << 3) | (1 << 6), &rtc->osc);
  149. }
  150. #endif
  151. static void uart_soft_reset(void)
  152. {
  153. struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
  154. u32 regval;
  155. regval = readl(&uart_base->uartsyscfg);
  156. regval |= UART_RESET;
  157. writel(regval, &uart_base->uartsyscfg);
  158. while ((readl(&uart_base->uartsyssts) &
  159. UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
  160. ;
  161. /* Disable smart idle */
  162. regval = readl(&uart_base->uartsyscfg);
  163. regval |= UART_SMART_IDLE_EN;
  164. writel(regval, &uart_base->uartsyscfg);
  165. }
  166. static void watchdog_disable(void)
  167. {
  168. struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
  169. writel(0xAAAA, &wdtimer->wdtwspr);
  170. while (readl(&wdtimer->wdtwwps) != 0x0)
  171. ;
  172. writel(0x5555, &wdtimer->wdtwspr);
  173. while (readl(&wdtimer->wdtwwps) != 0x0)
  174. ;
  175. }
  176. #endif
  177. void s_init(void)
  178. {
  179. /*
  180. * The ROM will only have set up sufficient pinmux to allow for the
  181. * first 4KiB NOR to be read, we must finish doing what we know of
  182. * the NOR mux in this space in order to continue.
  183. */
  184. #ifdef CONFIG_NOR_BOOT
  185. enable_norboot_pin_mux();
  186. #endif
  187. /*
  188. * Save the boot parameters passed from romcode.
  189. * We cannot delay the saving further than this,
  190. * to prevent overwrites.
  191. */
  192. #ifdef CONFIG_SPL_BUILD
  193. save_omap_boot_params();
  194. #endif
  195. #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
  196. watchdog_disable();
  197. timer_init();
  198. set_uart_mux_conf();
  199. setup_clocks_for_console();
  200. uart_soft_reset();
  201. #endif
  202. #ifdef CONFIG_NOR_BOOT
  203. gd->baudrate = CONFIG_BAUDRATE;
  204. serial_init();
  205. gd->have_console = 1;
  206. #else
  207. gd = &gdata;
  208. preloader_console_init();
  209. #endif
  210. #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
  211. prcm_init();
  212. set_mux_conf_regs();
  213. #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
  214. /* Enable RTC32K clock */
  215. rtc32k_enable();
  216. #endif
  217. sdram_init();
  218. #endif
  219. }
  220. #ifndef CONFIG_SYS_DCACHE_OFF
  221. void enable_caches(void)
  222. {
  223. /* Enable D-cache. I-cache is already enabled in start.S */
  224. dcache_enable();
  225. }
  226. #endif /* !CONFIG_SYS_DCACHE_OFF */