omap3logic.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. #define GPMC_NAND_COMMAND_0 (OMAP34XX_GPMC_BASE + 0x7c)
  112. #define GPMC_NAND_DATA_0 (OMAP34XX_GPMC_BASE + 0x84)
  113. #define GPMC_NAND_ADDRESS_0 (OMAP34XX_GPMC_BASE + 0x80)
  114. void spl_board_prepare_for_linux(void)
  115. {
  116. /* The Micron NAND starts locked which
  117. * prohibits mounting the NAND as RW
  118. * The following commands are what unlocks
  119. * the NAND to become RW Falcon Mode does not
  120. * have as many smarts as U-Boot, but Logic PD
  121. * only makes NAND with 512MB so these hard coded
  122. * values should work for all current models
  123. */
  124. writeb(0x70, GPMC_NAND_COMMAND_0);
  125. writeb(-1, GPMC_NAND_DATA_0);
  126. writeb(0x7a, GPMC_NAND_COMMAND_0);
  127. writeb(0x00, GPMC_NAND_ADDRESS_0);
  128. writeb(0x00, GPMC_NAND_ADDRESS_0);
  129. writeb(0x00, GPMC_NAND_ADDRESS_0);
  130. writeb(-1, GPMC_NAND_COMMAND_0);
  131. /* Begin address 0 */
  132. writeb(NAND_CMD_UNLOCK1, 0x6e00007c);
  133. writeb(0x00, GPMC_NAND_ADDRESS_0);
  134. writeb(0x00, GPMC_NAND_ADDRESS_0);
  135. writeb(0x00, GPMC_NAND_ADDRESS_0);
  136. writeb(-1, GPMC_NAND_DATA_0);
  137. /* Ending address at the end of Flash */
  138. writeb(NAND_CMD_UNLOCK2, GPMC_NAND_COMMAND_0);
  139. writeb(0xc0, GPMC_NAND_ADDRESS_0);
  140. writeb(0xff, GPMC_NAND_ADDRESS_0);
  141. writeb(0x03, GPMC_NAND_ADDRESS_0);
  142. writeb(-1, GPMC_NAND_DATA_0);
  143. writeb(0x79, GPMC_NAND_COMMAND_0);
  144. writeb(-1, GPMC_NAND_DATA_0);
  145. writeb(-1, GPMC_NAND_DATA_0);
  146. }
  147. #endif
  148. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  149. static struct musb_hdrc_config musb_config = {
  150. .multipoint = 1,
  151. .dyn_fifo = 1,
  152. .num_eps = 16,
  153. .ram_bits = 12,
  154. };
  155. static struct omap_musb_board_data musb_board_data = {
  156. .interface_type = MUSB_INTERFACE_ULPI,
  157. };
  158. static struct musb_hdrc_platform_data musb_plat = {
  159. #if defined(CONFIG_USB_MUSB_HOST)
  160. .mode = MUSB_HOST,
  161. #elif defined(CONFIG_USB_MUSB_GADGET)
  162. .mode = MUSB_PERIPHERAL,
  163. #else
  164. #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
  165. #endif
  166. .config = &musb_config,
  167. .power = 100,
  168. .platform_ops = &omap2430_ops,
  169. .board_data = &musb_board_data,
  170. };
  171. #endif
  172. #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
  173. /* Call usb_stop() before starting the kernel */
  174. void show_boot_progress(int val)
  175. {
  176. if (val == BOOTSTAGE_ID_RUN_OS)
  177. usb_stop();
  178. }
  179. static struct omap_usbhs_board_data usbhs_bdata = {
  180. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  181. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  182. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  183. };
  184. int ehci_hcd_init(int index, enum usb_init_type init,
  185. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  186. {
  187. return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  188. }
  189. int ehci_hcd_stop(int index)
  190. {
  191. return omap_ehci_hcd_stop();
  192. }
  193. #endif /* CONFIG_USB_EHCI_HCD */
  194. /*
  195. * Routine: misc_init_r
  196. * Description: Configure board specific parts
  197. */
  198. int misc_init_r(void)
  199. {
  200. twl4030_power_init();
  201. omap_die_id_display();
  202. #ifdef CONFIG_USB_MUSB_OMAP2PLUS
  203. musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
  204. #endif
  205. return 0;
  206. }
  207. /*
  208. * BOARD_ID_GPIO - GPIO of pin with optional pulldown resistor on SOM LV
  209. */
  210. #define BOARD_ID_GPIO 189 /* hsusb0_data5 pin */
  211. /*
  212. * Routine: board_init
  213. * Description: Early hardware init.
  214. */
  215. int board_init(void)
  216. {
  217. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  218. /* boot param addr */
  219. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  220. return 0;
  221. }
  222. #ifdef CONFIG_BOARD_LATE_INIT
  223. static void unlock_nand(void)
  224. {
  225. int dev = nand_curr_device;
  226. struct mtd_info *mtd;
  227. mtd = get_nand_dev_by_index(dev);
  228. nand_unlock(mtd, 0, mtd->size, 0);
  229. }
  230. int board_late_init(void)
  231. {
  232. struct board_id *board;
  233. unsigned int val;
  234. /*
  235. * To identify between a SOM LV and Torpedo module,
  236. * a pulldown resistor is on hsusb0_data5 for the SOM LV module.
  237. * Drive the pin (and let it soak), then read it back.
  238. * If the pin is still high its a Torpedo. If low its a SOM LV
  239. */
  240. /* Mux hsusb0_data5 as a GPIO */
  241. MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M4));
  242. if (gpio_request(BOARD_ID_GPIO, "husb0_data5.gpio_189") == 0) {
  243. /*
  244. * Drive BOARD_ID_GPIO - the pulldown resistor on the SOM LV
  245. * will drain the voltage.
  246. */
  247. gpio_direction_output(BOARD_ID_GPIO, 0);
  248. gpio_set_value(BOARD_ID_GPIO, 1);
  249. /* Let it soak for a bit */
  250. sdelay(0x100);
  251. /*
  252. * Read state of BOARD_ID_GPIO as an input and if its set.
  253. * If so the board is a Torpedo
  254. */
  255. gpio_direction_input(BOARD_ID_GPIO);
  256. val = gpio_get_value(BOARD_ID_GPIO);
  257. gpio_free(BOARD_ID_GPIO);
  258. board = &boards[!!(get_cpu_family() == CPU_OMAP36XX)][!!val];
  259. printf("Board: %s\n", board->name);
  260. /* Set the machine_id passed to Linux */
  261. if (board->machine_id)
  262. gd->bd->bi_arch_number = board->machine_id;
  263. /* If the user has not set fdtimage, set the default */
  264. if (!env_get("fdtimage"))
  265. env_set("fdtimage", board->fdtfile);
  266. }
  267. /* restore hsusb0_data5 pin as hsusb0_data5 */
  268. MUX_VAL(CP(HSUSB0_DATA5), (IEN | PTD | DIS | M0));
  269. #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK
  270. unlock_nand();
  271. #endif
  272. return 0;
  273. }
  274. #endif
  275. #if defined(CONFIG_MMC)
  276. int board_mmc_init(bd_t *bis)
  277. {
  278. return omap_mmc_init(0, 0, 0, -1, -1);
  279. }
  280. #endif
  281. #if defined(CONFIG_MMC)
  282. void board_mmc_power_init(void)
  283. {
  284. twl4030_power_mmc_init(0);
  285. }
  286. #endif
  287. #ifdef CONFIG_SMC911X
  288. /* GPMC CS1 settings for Logic SOM LV/Torpedo LAN92xx Ethernet chip */
  289. static const u32 gpmc_lan92xx_config[] = {
  290. NET_LAN92XX_GPMC_CONFIG1,
  291. NET_LAN92XX_GPMC_CONFIG2,
  292. NET_LAN92XX_GPMC_CONFIG3,
  293. NET_LAN92XX_GPMC_CONFIG4,
  294. NET_LAN92XX_GPMC_CONFIG5,
  295. NET_LAN92XX_GPMC_CONFIG6,
  296. };
  297. int board_eth_init(bd_t *bis)
  298. {
  299. enable_gpmc_cs_config(gpmc_lan92xx_config, &gpmc_cfg->cs[1],
  300. CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
  301. return smc911x_initialize(0, CONFIG_SMC911X_BASE);
  302. }
  303. #endif