omap3logic.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * (C) Copyright 2011
  3. * Logic Product Development <www.logicpd.com>
  4. *
  5. * Author :
  6. * Peter Barada <peter.barada@logicpd.com>
  7. *
  8. * Derived from Beagle Board and 3430 SDP code by
  9. * Richard Woodruff <r-woodruff2@ti.com>
  10. * Syed Mohammed Khasim <khasim@ti.com>
  11. *
  12. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <common.h>
  15. #include <dm.h>
  16. #include <ns16550.h>
  17. #include <netdev.h>
  18. #include <flash.h>
  19. #include <nand.h>
  20. #include <i2c.h>
  21. #include <twl4030.h>
  22. #include <asm/io.h>
  23. #include <asm/arch/mmc_host_def.h>
  24. #include <asm/arch/mux.h>
  25. #include <asm/arch/mem.h>
  26. #include <asm/arch/sys_proto.h>
  27. #include <asm/gpio.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. /* This is only needed until SPL gets OF support */
  42. #ifdef CONFIG_SPL_BUILD
  43. static const struct ns16550_platdata omap3logic_serial = {
  44. .base = OMAP34XX_UART1,
  45. .reg_shift = 2,
  46. .clock = V_NS16550_CLK,
  47. .fcr = UART_FCR_DEFVAL,
  48. };
  49. U_BOOT_DEVICE(omap3logic_uart) = {
  50. "ns16550_serial",
  51. &omap3logic_serial
  52. };
  53. #endif
  54. /*
  55. * two dimensional array of strucures containining board name and Linux
  56. * machine IDs; row it selected based on CPU column is slected based
  57. * on hsusb0_data5 pin having a pulldown resistor
  58. */
  59. static struct board_id {
  60. char *name;
  61. int machine_id;
  62. char *fdtfile;
  63. } boards[2][2] = {
  64. {
  65. {
  66. .name = "OMAP35xx SOM LV",
  67. .machine_id = MACH_TYPE_OMAP3530_LV_SOM,
  68. .fdtfile = "logicpd-som-lv-35xx-devkit.dtb",
  69. },
  70. {
  71. .name = "OMAP35xx Torpedo",
  72. .machine_id = MACH_TYPE_OMAP3_TORPEDO,
  73. .fdtfile = "logicpd-torpedo-35xx-devkit.dtb",
  74. },
  75. },
  76. {
  77. {
  78. .name = "DM37xx SOM LV",
  79. .fdtfile = "logicpd-som-lv-37xx-devkit.dtb",
  80. },
  81. {
  82. .name = "DM37xx Torpedo",
  83. .fdtfile = "logicpd-torpedo-37xx-devkit.dtb",
  84. },
  85. },
  86. };
  87. #ifdef CONFIG_SPL_OS_BOOT
  88. int spl_start_uboot(void)
  89. {
  90. /* break into full u-boot on 'c' */
  91. return serial_tstc() && serial_getc() == 'c';
  92. }
  93. #endif
  94. #if defined(CONFIG_SPL_BUILD)
  95. /*
  96. * Routine: get_board_mem_timings
  97. * Description: If we use SPL then there is no x-loader nor config header
  98. * so we have to setup the DDR timings ourself on the first bank. This
  99. * provides the timing values back to the function that configures
  100. * the memory.
  101. */
  102. void get_board_mem_timings(struct board_sdrc_timings *timings)
  103. {
  104. timings->mr = MICRON_V_MR_165;
  105. /* 256MB DDR */
  106. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  107. timings->ctrla = MICRON_V_ACTIMA_200;
  108. timings->ctrlb = MICRON_V_ACTIMB_200;
  109. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  110. }
  111. #endif
  112. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  113. static struct musb_hdrc_config musb_config = {
  114. .multipoint = 1,
  115. .dyn_fifo = 1,
  116. .num_eps = 16,
  117. .ram_bits = 12,
  118. };
  119. static struct omap_musb_board_data musb_board_data = {
  120. .interface_type = MUSB_INTERFACE_ULPI,
  121. };
  122. static struct musb_hdrc_platform_data musb_plat = {
  123. #if defined(CONFIG_USB_MUSB_HOST)
  124. .mode = MUSB_HOST,
  125. #elif defined(CONFIG_USB_MUSB_GADGET)
  126. .mode = MUSB_PERIPHERAL,
  127. #else
  128. #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
  129. #endif
  130. .config = &musb_config,
  131. .power = 100,
  132. .platform_ops = &omap2430_ops,
  133. .board_data = &musb_board_data,
  134. };
  135. #endif
  136. #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
  137. /* Call usb_stop() before starting the kernel */
  138. void show_boot_progress(int val)
  139. {
  140. if (val == BOOTSTAGE_ID_RUN_OS)
  141. usb_stop();
  142. }
  143. static struct omap_usbhs_board_data usbhs_bdata = {
  144. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  145. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  146. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  147. };
  148. int ehci_hcd_init(int index, enum usb_init_type init,
  149. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  150. {
  151. return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  152. }
  153. int ehci_hcd_stop(int index)
  154. {
  155. return omap_ehci_hcd_stop();
  156. }
  157. #endif /* CONFIG_USB_EHCI_HCD */
  158. /*
  159. * Routine: misc_init_r
  160. * Description: Configure board specific parts
  161. */
  162. int misc_init_r(void)
  163. {
  164. twl4030_power_init();
  165. omap_die_id_display();
  166. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  167. musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
  168. #endif
  169. return 0;
  170. }
  171. /*
  172. * BOARD_ID_GPIO - GPIO of pin with optional pulldown resistor on SOM LV
  173. */
  174. #define BOARD_ID_GPIO 189 /* hsusb0_data5 pin */
  175. /*
  176. * Routine: board_init
  177. * Description: Early hardware init.
  178. */
  179. int board_init(void)
  180. {
  181. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  182. /* boot param addr */
  183. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  184. return 0;
  185. }
  186. #ifdef CONFIG_BOARD_LATE_INIT
  187. int board_late_init(void)
  188. {
  189. struct board_id *board;
  190. unsigned int val;
  191. /*
  192. * To identify between a SOM LV and Torpedo module,
  193. * a pulldown resistor is on hsusb0_data5 for the SOM LV module.
  194. * Drive the pin (and let it soak), then read it back.
  195. * If the pin is still high its a Torpedo. If low its a SOM LV
  196. */
  197. /* Mux hsusb0_data5 as a GPIO */
  198. MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M4));
  199. if (gpio_request(BOARD_ID_GPIO, "husb0_data5.gpio_189") == 0) {
  200. /*
  201. * Drive BOARD_ID_GPIO - the pulldown resistor on the SOM LV
  202. * will drain the voltage.
  203. */
  204. gpio_direction_output(BOARD_ID_GPIO, 0);
  205. gpio_set_value(BOARD_ID_GPIO, 1);
  206. /* Let it soak for a bit */
  207. sdelay(0x100);
  208. /*
  209. * Read state of BOARD_ID_GPIO as an input and if its set.
  210. * If so the board is a Torpedo
  211. */
  212. gpio_direction_input(BOARD_ID_GPIO);
  213. val = gpio_get_value(BOARD_ID_GPIO);
  214. gpio_free(BOARD_ID_GPIO);
  215. board = &boards[!!(get_cpu_family() == CPU_OMAP36XX)][!!val];
  216. printf("Board: %s\n", board->name);
  217. /* Set the machine_id passed to Linux */
  218. if (board->machine_id)
  219. gd->bd->bi_arch_number = board->machine_id;
  220. /* If the user has not set fdtimage, set the default */
  221. if (!env_get("fdtimage"))
  222. env_set("fdtimage", board->fdtfile);
  223. }
  224. /* restore hsusb0_data5 pin as hsusb0_data5 */
  225. MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M0));
  226. return 0;
  227. }
  228. #endif
  229. #if defined(CONFIG_MMC)
  230. int board_mmc_init(bd_t *bis)
  231. {
  232. return omap_mmc_init(0, 0, 0, -1, -1);
  233. }
  234. #endif
  235. #if defined(CONFIG_MMC)
  236. void board_mmc_power_init(void)
  237. {
  238. twl4030_power_mmc_init(0);
  239. }
  240. #endif
  241. #ifdef CONFIG_SMC911X
  242. /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
  243. static const u32 gpmc_lan92xx_config[] = {
  244. NET_LAN92XX_GPMC_CONFIG1,
  245. NET_LAN92XX_GPMC_CONFIG2,
  246. NET_LAN92XX_GPMC_CONFIG3,
  247. NET_LAN92XX_GPMC_CONFIG4,
  248. NET_LAN92XX_GPMC_CONFIG5,
  249. NET_LAN92XX_GPMC_CONFIG6,
  250. };
  251. int board_eth_init(bd_t *bis)
  252. {
  253. enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
  254. CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
  255. return smc911x_initialize(0, CONFIG_SMC911X_BASE);
  256. }
  257. #endif