board.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 <dm.h>
  12. #include <errno.h>
  13. #include <ns16550.h>
  14. #include <spl.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/hardware.h>
  17. #include <asm/arch/omap.h>
  18. #include <asm/arch/ddr_defs.h>
  19. #include <asm/arch/clock.h>
  20. #include <asm/arch/gpio.h>
  21. #include <asm/arch/mem.h>
  22. #include <asm/arch/mmc_host_def.h>
  23. #include <asm/arch/sys_proto.h>
  24. #include <asm/io.h>
  25. #include <asm/emif.h>
  26. #include <asm/gpio.h>
  27. #include <i2c.h>
  28. #include <miiphy.h>
  29. #include <cpsw.h>
  30. #include <asm/errno.h>
  31. #include <linux/compiler.h>
  32. #include <linux/usb/ch9.h>
  33. #include <linux/usb/gadget.h>
  34. #include <linux/usb/musb.h>
  35. #include <asm/omap_musb.h>
  36. #include <asm/davinci_rtc.h>
  37. DECLARE_GLOBAL_DATA_PTR;
  38. #ifdef CONFIG_DM_GPIO
  39. static const struct omap_gpio_platdata am33xx_gpio[] = {
  40. { 0, AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
  41. { 1, AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
  42. { 2, AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
  43. { 3, AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
  44. #ifdef CONFIG_AM43XX
  45. { 4, AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
  46. { 5, AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
  47. #endif
  48. };
  49. U_BOOT_DEVICES(am33xx_gpios) = {
  50. { "gpio_omap", &am33xx_gpio[0] },
  51. { "gpio_omap", &am33xx_gpio[1] },
  52. { "gpio_omap", &am33xx_gpio[2] },
  53. { "gpio_omap", &am33xx_gpio[3] },
  54. #ifdef CONFIG_AM43XX
  55. { "gpio_omap", &am33xx_gpio[4] },
  56. { "gpio_omap", &am33xx_gpio[5] },
  57. #endif
  58. };
  59. # ifndef CONFIG_OF_CONTROL
  60. /*
  61. * TODO(sjg@chromium.org): When we can move SPL serial to DM, we can remove
  62. * the CONFIGs. At the same time, we should move this to the board files.
  63. */
  64. static const struct ns16550_platdata am33xx_serial[] = {
  65. { CONFIG_SYS_NS16550_COM1, 2, CONFIG_SYS_NS16550_CLK },
  66. # ifdef CONFIG_SYS_NS16550_COM2
  67. { CONFIG_SYS_NS16550_COM2, 2, CONFIG_SYS_NS16550_CLK },
  68. # ifdef CONFIG_SYS_NS16550_COM3
  69. { CONFIG_SYS_NS16550_COM3, 2, CONFIG_SYS_NS16550_CLK },
  70. { CONFIG_SYS_NS16550_COM4, 2, CONFIG_SYS_NS16550_CLK },
  71. { CONFIG_SYS_NS16550_COM5, 2, CONFIG_SYS_NS16550_CLK },
  72. { CONFIG_SYS_NS16550_COM6, 2, CONFIG_SYS_NS16550_CLK },
  73. # endif
  74. # endif
  75. };
  76. U_BOOT_DEVICES(am33xx_uarts) = {
  77. { "serial_omap", &am33xx_serial[0] },
  78. # ifdef CONFIG_SYS_NS16550_COM2
  79. { "serial_omap", &am33xx_serial[1] },
  80. # ifdef CONFIG_SYS_NS16550_COM3
  81. { "serial_omap", &am33xx_serial[2] },
  82. { "serial_omap", &am33xx_serial[3] },
  83. { "serial_omap", &am33xx_serial[4] },
  84. { "serial_omap", &am33xx_serial[5] },
  85. # endif
  86. # endif
  87. };
  88. # endif
  89. #else
  90. static const struct gpio_bank gpio_bank_am33xx[] = {
  91. { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
  92. { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
  93. { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
  94. { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
  95. #ifdef CONFIG_AM43XX
  96. { (void *)AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
  97. { (void *)AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
  98. #endif
  99. };
  100. const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
  101. #endif
  102. #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
  103. int cpu_mmc_init(bd_t *bis)
  104. {
  105. int ret;
  106. ret = omap_mmc_init(0, 0, 0, -1, -1);
  107. if (ret)
  108. return ret;
  109. return omap_mmc_init(1, 0, 0, -1, -1);
  110. }
  111. #endif
  112. /* AM33XX has two MUSB controllers which can be host or gadget */
  113. #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
  114. (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
  115. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  116. /* USB 2.0 PHY Control */
  117. #define CM_PHY_PWRDN (1 << 0)
  118. #define CM_PHY_OTG_PWRDN (1 << 1)
  119. #define OTGVDET_EN (1 << 19)
  120. #define OTGSESSENDEN (1 << 20)
  121. static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
  122. {
  123. if (on) {
  124. clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
  125. OTGVDET_EN | OTGSESSENDEN);
  126. } else {
  127. clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
  128. }
  129. }
  130. static struct musb_hdrc_config musb_config = {
  131. .multipoint = 1,
  132. .dyn_fifo = 1,
  133. .num_eps = 16,
  134. .ram_bits = 12,
  135. };
  136. #ifdef CONFIG_AM335X_USB0
  137. static void am33xx_otg0_set_phy_power(u8 on)
  138. {
  139. am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
  140. }
  141. struct omap_musb_board_data otg0_board_data = {
  142. .set_phy_power = am33xx_otg0_set_phy_power,
  143. };
  144. static struct musb_hdrc_platform_data otg0_plat = {
  145. .mode = CONFIG_AM335X_USB0_MODE,
  146. .config = &musb_config,
  147. .power = 50,
  148. .platform_ops = &musb_dsps_ops,
  149. .board_data = &otg0_board_data,
  150. };
  151. #endif
  152. #ifdef CONFIG_AM335X_USB1
  153. static void am33xx_otg1_set_phy_power(u8 on)
  154. {
  155. am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
  156. }
  157. struct omap_musb_board_data otg1_board_data = {
  158. .set_phy_power = am33xx_otg1_set_phy_power,
  159. };
  160. static struct musb_hdrc_platform_data otg1_plat = {
  161. .mode = CONFIG_AM335X_USB1_MODE,
  162. .config = &musb_config,
  163. .power = 50,
  164. .platform_ops = &musb_dsps_ops,
  165. .board_data = &otg1_board_data,
  166. };
  167. #endif
  168. #endif
  169. int arch_misc_init(void)
  170. {
  171. #ifdef CONFIG_AM335X_USB0
  172. musb_register(&otg0_plat, &otg0_board_data,
  173. (void *)USB0_OTG_BASE);
  174. #endif
  175. #ifdef CONFIG_AM335X_USB1
  176. musb_register(&otg1_plat, &otg1_board_data,
  177. (void *)USB1_OTG_BASE);
  178. #endif
  179. return 0;
  180. }
  181. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  182. /*
  183. * In the case of non-SPL based booting we'll want to call these
  184. * functions a tiny bit later as it will require gd to be set and cleared
  185. * and that's not true in s_init in this case so we cannot do it there.
  186. */
  187. int board_early_init_f(void)
  188. {
  189. prcm_init();
  190. set_mux_conf_regs();
  191. return 0;
  192. }
  193. /*
  194. * This function is the place to do per-board things such as ramp up the
  195. * MPU clock frequency.
  196. */
  197. __weak void am33xx_spl_board_init(void)
  198. {
  199. do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
  200. do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
  201. }
  202. #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
  203. static void rtc32k_enable(void)
  204. {
  205. struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
  206. /*
  207. * Unlock the RTC's registers. For more details please see the
  208. * RTC_SS section of the TRM. In order to unlock we need to
  209. * write these specific values (keys) in this order.
  210. */
  211. writel(RTC_KICK0R_WE, &rtc->kick0r);
  212. writel(RTC_KICK1R_WE, &rtc->kick1r);
  213. /* Enable the RTC 32K OSC by setting bits 3 and 6. */
  214. writel((1 << 3) | (1 << 6), &rtc->osc);
  215. }
  216. #endif
  217. static void uart_soft_reset(void)
  218. {
  219. struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
  220. u32 regval;
  221. regval = readl(&uart_base->uartsyscfg);
  222. regval |= UART_RESET;
  223. writel(regval, &uart_base->uartsyscfg);
  224. while ((readl(&uart_base->uartsyssts) &
  225. UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
  226. ;
  227. /* Disable smart idle */
  228. regval = readl(&uart_base->uartsyscfg);
  229. regval |= UART_SMART_IDLE_EN;
  230. writel(regval, &uart_base->uartsyscfg);
  231. }
  232. static void watchdog_disable(void)
  233. {
  234. struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
  235. writel(0xAAAA, &wdtimer->wdtwspr);
  236. while (readl(&wdtimer->wdtwwps) != 0x0)
  237. ;
  238. writel(0x5555, &wdtimer->wdtwspr);
  239. while (readl(&wdtimer->wdtwwps) != 0x0)
  240. ;
  241. }
  242. void s_init(void)
  243. {
  244. /*
  245. * The ROM will only have set up sufficient pinmux to allow for the
  246. * first 4KiB NOR to be read, we must finish doing what we know of
  247. * the NOR mux in this space in order to continue.
  248. */
  249. #ifdef CONFIG_NOR_BOOT
  250. enable_norboot_pin_mux();
  251. #endif
  252. /*
  253. * Save the boot parameters passed from romcode.
  254. * We cannot delay the saving further than this,
  255. * to prevent overwrites.
  256. */
  257. #ifdef CONFIG_SPL_BUILD
  258. save_omap_boot_params();
  259. #endif
  260. watchdog_disable();
  261. set_uart_mux_conf();
  262. setup_clocks_for_console();
  263. uart_soft_reset();
  264. #if defined(CONFIG_NOR_BOOT) || defined(CONFIG_QSPI_BOOT)
  265. gd->baudrate = CONFIG_BAUDRATE;
  266. serial_init();
  267. gd->have_console = 1;
  268. #elif defined(CONFIG_SPL_BUILD)
  269. gd = &gdata;
  270. preloader_console_init();
  271. #endif
  272. #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
  273. /* Enable RTC32K clock */
  274. rtc32k_enable();
  275. #endif
  276. #ifdef CONFIG_SPL_BUILD
  277. board_early_init_f();
  278. sdram_init();
  279. #endif
  280. }
  281. #endif