omap3logic.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. /*
  42. * two dimensional array of strucures containining board name and Linux
  43. * machine IDs; row it selected based on CPU column is slected based
  44. * on hsusb0_data5 pin having a pulldown resistor
  45. */
  46. static struct board_id {
  47. char *name;
  48. int machine_id;
  49. char *fdtfile;
  50. } boards[2][2] = {
  51. {
  52. {
  53. .name = "OMAP35xx SOM LV",
  54. .machine_id = MACH_TYPE_OMAP3530_LV_SOM,
  55. .fdtfile = "logicpd-som-lv-35xx-devkit.dtb",
  56. },
  57. {
  58. .name = "OMAP35xx Torpedo",
  59. .machine_id = MACH_TYPE_OMAP3_TORPEDO,
  60. .fdtfile = "logicpd-torpedo-35xx-devkit.dtb",
  61. },
  62. },
  63. {
  64. {
  65. .name = "DM37xx SOM LV",
  66. .fdtfile = "logicpd-som-lv-37xx-devkit.dtb",
  67. },
  68. {
  69. .name = "DM37xx Torpedo",
  70. .fdtfile = "logicpd-torpedo-37xx-devkit.dtb",
  71. },
  72. },
  73. };
  74. #ifdef CONFIG_SPL_OS_BOOT
  75. int spl_start_uboot(void)
  76. {
  77. /* break into full u-boot on 'c' */
  78. return serial_tstc() && serial_getc() == 'c';
  79. }
  80. #endif
  81. #if defined(CONFIG_SPL_BUILD)
  82. /*
  83. * Routine: get_board_mem_timings
  84. * Description: If we use SPL then there is no x-loader nor config header
  85. * so we have to setup the DDR timings ourself on the first bank. This
  86. * provides the timing values back to the function that configures
  87. * the memory.
  88. */
  89. void get_board_mem_timings(struct board_sdrc_timings *timings)
  90. {
  91. timings->mr = MICRON_V_MR_165;
  92. /* 256MB DDR */
  93. timings->mcfg = MICRON_V_MCFG_200(256 << 20);
  94. timings->ctrla = MICRON_V_ACTIMA_200;
  95. timings->ctrlb = MICRON_V_ACTIMB_200;
  96. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  97. }
  98. #define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c)
  99. #define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84)
  100. #define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80)
  101. void spl_board_prepare_for_linux(void)
  102. {
  103. /* The Micron NAND starts locked which
  104. * prohibits mounting the NAND as RW
  105. * The following commands are what unlocks
  106. * the NAND to become RW Falcon Mode does not
  107. * have as many smarts as U-Boot, but Logic PD
  108. * only makes NAND with 512MB so these hard coded
  109. * values should work for all current models
  110. */
  111. writeb(0x70, GPMC_NAND_COMMAND_0);
  112. writeb(-1, GPMC_NAND_DATA_0);
  113. writeb(0x7a, GPMC_NAND_COMMAND_0);
  114. writeb(0x00, GPMC_NAND_ADDRESS_0);
  115. writeb(0x00, GPMC_NAND_ADDRESS_0);
  116. writeb(0x00, GPMC_NAND_ADDRESS_0);
  117. writeb(-1, GPMC_NAND_COMMAND_0);
  118. /* Begin address 0 */
  119. writeb(NAND_CMD_UNLOCK1, 0x6e00007c);
  120. writeb(0x00, GPMC_NAND_ADDRESS_0);
  121. writeb(0x00, GPMC_NAND_ADDRESS_0);
  122. writeb(0x00, GPMC_NAND_ADDRESS_0);
  123. writeb(-1, GPMC_NAND_DATA_0);
  124. /* Ending address at the end of Flash */
  125. writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0);
  126. writeb(0xc0, GPMC_NAND_ADDRESS_0);
  127. writeb(0xff, GPMC_NAND_ADDRESS_0);
  128. writeb(0x03, GPMC_NAND_ADDRESS_0);
  129. writeb(-1, GPMC_NAND_DATA_0);
  130. writeb(0x79, GPMC_NAND_COMMAND_0);
  131. writeb(-1, GPMC_NAND_DATA_0);
  132. writeb(-1, GPMC_NAND_DATA_0);
  133. }
  134. #endif
  135. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  136. static struct musb_hdrc_config musb_config = {
  137. .multipoint = 1,
  138. .dyn_fifo = 1,
  139. .num_eps = 16,
  140. .ram_bits = 12,
  141. };
  142. static struct omap_musb_board_data musb_board_data = {
  143. .interface_type = MUSB_INTERFACE_ULPI,
  144. };
  145. static struct musb_hdrc_platform_data musb_plat = {
  146. #if defined(CONFIG_USB_MUSB_HOST)
  147. .mode = MUSB_HOST,
  148. #elif defined(CONFIG_USB_MUSB_GADGET)
  149. .mode = MUSB_PERIPHERAL,
  150. #else
  151. #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
  152. #endif
  153. .config = &musb_config,
  154. .power = 100,
  155. .platform_ops = &omap2430_ops,
  156. .board_data = &musb_board_data,
  157. };
  158. #endif
  159. #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
  160. /* Call usb_stop() before starting the kernel */
  161. void show_boot_progress(int val)
  162. {
  163. if (val == BOOTSTAGE_ID_RUN_OS)
  164. usb_stop();
  165. }
  166. static struct omap_usbhs_board_data usbhs_bdata = {
  167. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  168. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  169. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  170. };
  171. int ehci_hcd_init(int index, enum usb_init_type init,
  172. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  173. {
  174. return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  175. }
  176. int ehci_hcd_stop(int index)
  177. {
  178. return omap_ehci_hcd_stop();
  179. }
  180. #endif /* CONFIG_USB_EHCI_HCD */
  181. /*
  182. * Routine: misc_init_r
  183. * Description: Configure board specific parts
  184. */
  185. int misc_init_r(void)
  186. {
  187. twl4030_power_init();
  188. omap_die_id_display();
  189. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  190. musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
  191. #endif
  192. return 0;
  193. }
  194. /*
  195. * BOARD_ID_GPIO - GPIO of pin with optional pulldown resistor on SOM LV
  196. */
  197. #define BOARD_ID_GPIO 189 /* hsusb0_data5 pin */
  198. /*
  199. * Routine: board_init
  200. * Description: Early hardware init.
  201. */
  202. int board_init(void)
  203. {
  204. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  205. /* boot param addr */
  206. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  207. return 0;
  208. }
  209. #ifdef CONFIG_BOARD_LATE_INIT
  210. static void unlock_nand(void)
  211. {
  212. int dev = nand_curr_device;
  213. struct mtd_info *mtd;
  214. mtd = get_nand_dev_by_index(dev);
  215. nand_unlock(mtd, 0, mtd->size, 0);
  216. }
  217. int board_late_init(void)
  218. {
  219. struct board_id *board;
  220. unsigned int val;
  221. /*
  222. * To identify between a SOM LV and Torpedo module,
  223. * a pulldown resistor is on hsusb0_data5 for the SOM LV module.
  224. * Drive the pin (and let it soak), then read it back.
  225. * If the pin is still high its a Torpedo. If low its a SOM LV
  226. */
  227. /* Mux hsusb0_data5 as a GPIO */
  228. MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M4));
  229. if (gpio_request(BOARD_ID_GPIO, "husb0_data5.gpio_189") == 0) {
  230. /*
  231. * Drive BOARD_ID_GPIO - the pulldown resistor on the SOM LV
  232. * will drain the voltage.
  233. */
  234. gpio_direction_output(BOARD_ID_GPIO, 0);
  235. gpio_set_value(BOARD_ID_GPIO, 1);
  236. /* Let it soak for a bit */
  237. sdelay(0x100);
  238. /*
  239. * Read state of BOARD_ID_GPIO as an input and if its set.
  240. * If so the board is a Torpedo
  241. */
  242. gpio_direction_input(BOARD_ID_GPIO);
  243. val = gpio_get_value(BOARD_ID_GPIO);
  244. gpio_free(BOARD_ID_GPIO);
  245. board = &boards[!!(get_cpu_family() == CPU_OMAP36XX)][!!val];
  246. printf("Board: %s\n", board->name);
  247. /* Set the machine_id passed to Linux */
  248. if (board->machine_id)
  249. gd->bd->bi_arch_number = board->machine_id;
  250. /* If the user has not set fdtimage, set the default */
  251. if (!env_get("fdtimage"))
  252. env_set("fdtimage", board->fdtfile);
  253. }
  254. /* restore hsusb0_data5 pin as hsusb0_data5 */
  255. MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M0));
  256. #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
  257. unlock_nand();
  258. #endif
  259. return 0;
  260. }
  261. #endif
  262. #if defined(CONFIG_MMC)
  263. int board_mmc_init(bd_t *bis)
  264. {
  265. return omap_mmc_init(0, 0, 0, -1, -1);
  266. }
  267. #endif
  268. #if defined(CONFIG_MMC)
  269. void board_mmc_power_init(void)
  270. {
  271. twl4030_power_mmc_init(0);
  272. }
  273. #endif
  274. #ifdef CONFIG_SMC911X
  275. /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
  276. static const u32 gpmc_lan92xx_config[] = {
  277. NET_LAN92XX_GPMC_CONFIG1,
  278. NET_LAN92XX_GPMC_CONFIG2,
  279. NET_LAN92XX_GPMC_CONFIG3,
  280. NET_LAN92XX_GPMC_CONFIG4,
  281. NET_LAN92XX_GPMC_CONFIG5,
  282. NET_LAN92XX_GPMC_CONFIG6,
  283. };
  284. int board_eth_init(bd_t *bis)
  285. {
  286. enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
  287. CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
  288. return smc911x_initialize(0, CONFIG_SMC911X_BASE);
  289. }
  290. #endif