board.c 7.7 KB

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