board.c 8.9 KB

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