omap3logic.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2011
  4. * Logic Product Development <www.logicpd.com>
  5. *
  6. * Author :
  7. * Peter Barada <peter.barada@logicpd.com>
  8. *
  9. * Derived from Beagle Board and 3430 SDP code by
  10. * Richard Woodruff <r-woodruff2@ti.com>
  11. * Syed Mohammed Khasim <khasim@ti.com>
  12. */
  13. #include <common.h>
  14. #include <dm.h>
  15. #include <ns16550.h>
  16. #include <netdev.h>
  17. #include <flash.h>
  18. #include <nand.h>
  19. #include <i2c.h>
  20. #include <twl4030.h>
  21. #include <asm/io.h>
  22. #include <asm/arch/mmc_host_def.h>
  23. #include <asm/arch/mux.h>
  24. #include <asm/arch/mem.h>
  25. #include <asm/arch/sys_proto.h>
  26. #include <asm/gpio.h>
  27. #include <asm/omap_mmc.h>
  28. #include <asm/mach-types.h>
  29. #include <linux/mtd/rawnand.h>
  30. #include <asm/omap_musb.h>
  31. #include <linux/errno.h>
  32. #include <linux/usb/ch9.h>
  33. #include <linux/usb/gadget.h>
  34. #include <linux/usb/musb.h>
  35. #include "omap3logic.h"
  36. #ifdef CONFIG_USB_EHCI_HCD
  37. #include <usb.h>
  38. #include <asm/ehci-omap.h>
  39. #endif
  40. DECLARE_GLOBAL_DATA_PTR;
  41. #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1 0x00011203
  42. #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2 0x000A1302
  43. #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3 0x000F1302
  44. #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4 0x0A021303
  45. #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5 0x00120F18
  46. #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6 0x0A030000
  47. #define LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7 0x00000C50
  48. #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1 0x00011203
  49. #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2 0x00091102
  50. #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3 0x000D1102
  51. #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4 0x09021103
  52. #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5 0x00100D15
  53. #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6 0x09030000
  54. #define LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7 0x00000C50
  55. /* This is only needed until SPL gets OF support */
  56. #ifdef CONFIG_SPL_BUILD
  57. static const struct ns16550_platdata omap3logic_serial = {
  58. .base = OMAP34XX_UART1,
  59. .reg_shift = 2,
  60. .clock = V_NS16550_CLK,
  61. .fcr = UART_FCR_DEFVAL,
  62. };
  63. U_BOOT_DEVICE(omap3logic_uart) = {
  64. "omap_serial",
  65. &omap3logic_serial
  66. };
  67. static const struct omap_hsmmc_plat omap3_logic_mmc0_platdata = {
  68. .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
  69. .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
  70. .cfg.f_min = 400000,
  71. .cfg.f_max = 52000000,
  72. .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
  73. .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
  74. };
  75. U_BOOT_DEVICE(omap3_logic_mmc0) = {
  76. .name = "omap_hsmmc",
  77. .platdata = &omap3_logic_mmc0_platdata,
  78. };
  79. #endif
  80. #ifdef CONFIG_SPL_OS_BOOT
  81. int spl_start_uboot(void)
  82. {
  83. /* break into full u-boot on 'c' */
  84. return serial_tstc() && serial_getc() == 'c';
  85. }
  86. #endif
  87. #if defined(CONFIG_SPL_BUILD)
  88. /*
  89. * Routine: get_board_mem_timings
  90. * Description: If we use SPL then there is no x-loader nor config header
  91. * so we have to setup the DDR timings ourself on the first bank. This
  92. * provides the timing values back to the function that configures
  93. * the memory.
  94. */
  95. void get_board_mem_timings(struct board_sdrc_timings *timings)
  96. {
  97. timings->mr = MICRON_V_MR_165;
  98. if (get_cpu_family() == CPU_OMAP36XX) {
  99. /* 200 MHz works for OMAP36/DM37 */
  100. /* 256MB DDR */
  101. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  102. timings->ctrla = MICRON_V_ACTIMA_200;
  103. timings->ctrlb = MICRON_V_ACTIMB_200;
  104. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  105. } else {
  106. /* 165 MHz works for OMAP35 */
  107. timings->mcfg = MICRON_V_MCFG_165(256 << 20);
  108. timings->ctrla = MICRON_V_ACTIMA_165;
  109. timings->ctrlb = MICRON_V_ACTIMB_165;
  110. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  111. }
  112. }
  113. #define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c)
  114. #define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84)
  115. #define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80)
  116. void spl_board_prepare_for_linux(void)
  117. {
  118. /* The Micron NAND starts locked which
  119. * prohibits mounting the NAND as RW
  120. * The following commands are what unlocks
  121. * the NAND to become RW Falcon Mode does not
  122. * have as many smarts as U-Boot, but Logic PD
  123. * only makes NAND with 512MB so these hard coded
  124. * values should work for all current models
  125. */
  126. writeb(0x70, GPMC_NAND_COMMAND_0);
  127. writeb(-1, GPMC_NAND_DATA_0);
  128. writeb(0x7a, GPMC_NAND_COMMAND_0);
  129. writeb(0x00, GPMC_NAND_ADDRESS_0);
  130. writeb(0x00, GPMC_NAND_ADDRESS_0);
  131. writeb(0x00, GPMC_NAND_ADDRESS_0);
  132. writeb(-1, GPMC_NAND_COMMAND_0);
  133. /* Begin address 0 */
  134. writeb(NAND_CMD_UNLOCK1, 0x6e00007c);
  135. writeb(0x00, GPMC_NAND_ADDRESS_0);
  136. writeb(0x00, GPMC_NAND_ADDRESS_0);
  137. writeb(0x00, GPMC_NAND_ADDRESS_0);
  138. writeb(-1, GPMC_NAND_DATA_0);
  139. /* Ending address at the end of Flash */
  140. writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0);
  141. writeb(0xc0, GPMC_NAND_ADDRESS_0);
  142. writeb(0xff, GPMC_NAND_ADDRESS_0);
  143. writeb(0x03, GPMC_NAND_ADDRESS_0);
  144. writeb(-1, GPMC_NAND_DATA_0);
  145. writeb(0x79, GPMC_NAND_COMMAND_0);
  146. writeb(-1, GPMC_NAND_DATA_0);
  147. writeb(-1, GPMC_NAND_DATA_0);
  148. }
  149. #endif
  150. #if !CONFIG_IS_ENABLED(DM_USB)
  151. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  152. static struct musb_hdrc_config musb_config = {
  153. .multipoint = 1,
  154. .dyn_fifo = 1,
  155. .num_eps = 16,
  156. .ram_bits = 12,
  157. };
  158. static struct omap_musb_board_data musb_board_data = {
  159. .interface_type = MUSB_INTERFACE_ULPI,
  160. };
  161. static struct musb_hdrc_platform_data musb_plat = {
  162. #if defined(CONFIG_USB_MUSB_HOST)
  163. .mode = MUSB_HOST,
  164. #elif defined(CONFIG_USB_MUSB_GADGET)
  165. .mode = MUSB_PERIPHERAL,
  166. #else
  167. #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
  168. #endif
  169. .config = &musb_config,
  170. .power = 100,
  171. .platform_ops = &omap2430_ops,
  172. .board_data = &musb_board_data,
  173. };
  174. #endif
  175. #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
  176. /* Call usb_stop() before starting the kernel */
  177. void show_boot_progress(int val)
  178. {
  179. if (val == BOOTSTAGE_ID_RUN_OS)
  180. usb_stop();
  181. }
  182. static struct omap_usbhs_board_data usbhs_bdata = {
  183. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  184. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  185. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  186. };
  187. int ehci_hcd_init(int index, enum usb_init_type init,
  188. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  189. {
  190. return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  191. }
  192. int ehci_hcd_stop(int index)
  193. {
  194. return omap_ehci_hcd_stop();
  195. }
  196. #endif /* CONFIG_USB_EHCI_HCD */
  197. #endif /* !DM_USB*/
  198. /*
  199. * Routine: misc_init_r
  200. * Description: Configure board specific parts
  201. */
  202. int misc_init_r(void)
  203. {
  204. twl4030_power_init();
  205. omap_die_id_display();
  206. #if !CONFIG_IS_ENABLED(DM_USB)
  207. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  208. musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
  209. #endif
  210. #endif
  211. return 0;
  212. }
  213. #if defined(CONFIG_FLASH_CFI_DRIVER)
  214. static const u32 gpmc_dm37_c2nor_config[] = {
  215. LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG1,
  216. LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG2,
  217. LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG3,
  218. LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG4,
  219. LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG5,
  220. LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG6,
  221. LOGIC_MT28_DM37_ASYNC_GPMC_CONFIG7
  222. };
  223. static const u32 gpmc_omap35_c2nor_config[] = {
  224. LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG1,
  225. LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG2,
  226. LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG3,
  227. LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG4,
  228. LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG5,
  229. LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG6,
  230. LOGIC_MT28_OMAP35_ASYNC_GPMC_CONFIG7
  231. };
  232. #endif
  233. /*
  234. * Routine: board_init
  235. * Description: Early hardware init.
  236. */
  237. int board_init(void)
  238. {
  239. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  240. /* boot param addr */
  241. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  242. #if defined(CONFIG_FLASH_CFI_DRIVER)
  243. if (get_cpu_family() == CPU_OMAP36XX) {
  244. /* Enable CS2 for NOR Flash */
  245. enable_gpmc_cs_config(gpmc_dm37_c2nor_config, &gpmc_cfg->cs[2],
  246. 0x10000000, GPMC_SIZE_64M);
  247. } else {
  248. enable_gpmc_cs_config(gpmc_omap35_c2nor_config, &gpmc_cfg->cs[2],
  249. 0x10000000, GPMC_SIZE_64M);
  250. }
  251. #endif
  252. return 0;
  253. }
  254. #ifdef CONFIG_BOARD_LATE_INIT
  255. static void unlock_nand(void)
  256. {
  257. int dev = nand_curr_device;
  258. struct mtd_info *mtd;
  259. mtd = get_nand_dev_by_index(dev);
  260. nand_unlock(mtd, 0, mtd->size, 0);
  261. }
  262. int board_late_init(void)
  263. {
  264. #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
  265. unlock_nand();
  266. #endif
  267. return 0;
  268. }
  269. #endif
  270. #if defined(CONFIG_MMC)
  271. void board_mmc_power_init(void)
  272. {
  273. twl4030_power_mmc_init(0);
  274. }
  275. #endif
  276. #ifdef CONFIG_SMC911X
  277. /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
  278. static const u32 gpmc_lan92xx_config[] = {
  279. NET_LAN92XX_GPMC_CONFIG1,
  280. NET_LAN92XX_GPMC_CONFIG2,
  281. NET_LAN92XX_GPMC_CONFIG3,
  282. NET_LAN92XX_GPMC_CONFIG4,
  283. NET_LAN92XX_GPMC_CONFIG5,
  284. NET_LAN92XX_GPMC_CONFIG6,
  285. };
  286. int board_eth_init(bd_t *bis)
  287. {
  288. enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
  289. CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
  290. return smc911x_initialize(0, CONFIG_SMC911X_BASE);
  291. }
  292. #endif