omap3logic.c 7.9 KB

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