evm.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2004-2011
  4. * Texas Instruments, <www.ti.com>
  5. *
  6. * Author :
  7. * Manikandan Pillai <mani.pillai@ti.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 <asm/io.h>
  18. #include <asm/arch/mem.h>
  19. #include <asm/arch/mux.h>
  20. #include <asm/arch/sys_proto.h>
  21. #include <asm/arch/mmc_host_def.h>
  22. #include <asm/gpio.h>
  23. #include <i2c.h>
  24. #include <twl4030.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/omap_musb.h>
  27. #include <linux/mtd/rawnand.h>
  28. #include <linux/usb/ch9.h>
  29. #include <linux/usb/gadget.h>
  30. #include <linux/usb/musb.h>
  31. #include "evm.h"
  32. #ifdef CONFIG_USB_EHCI_HCD
  33. #include <usb.h>
  34. #include <asm/ehci-omap.h>
  35. #endif
  36. #define OMAP3EVM_GPIO_ETH_RST_GEN1 64
  37. #define OMAP3EVM_GPIO_ETH_RST_GEN2 7
  38. DECLARE_GLOBAL_DATA_PTR;
  39. static const struct ns16550_platdata omap3_evm_serial = {
  40. .base = OMAP34XX_UART1,
  41. .reg_shift = 2,
  42. .clock = V_NS16550_CLK,
  43. .fcr = UART_FCR_DEFVAL,
  44. };
  45. U_BOOT_DEVICE(omap3_evm_uart) = {
  46. "ns16550_serial",
  47. &omap3_evm_serial
  48. };
  49. static u32 omap3_evm_version;
  50. u32 get_omap3_evm_rev(void)
  51. {
  52. return omap3_evm_version;
  53. }
  54. static void omap3_evm_get_revision(void)
  55. {
  56. #if defined(CONFIG_CMD_NET)
  57. /*
  58. * Board revision can be ascertained only by identifying
  59. * the Ethernet chipset.
  60. */
  61. unsigned int smsc_id;
  62. /* Ethernet PHY ID is stored at ID_REV register */
  63. smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000;
  64. printf("Read back SMSC id 0x%x\n", smsc_id);
  65. switch (smsc_id) {
  66. /* SMSC9115 chipset */
  67. case 0x01150000:
  68. omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
  69. break;
  70. /* SMSC 9220 chipset */
  71. case 0x92200000:
  72. default:
  73. omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
  74. }
  75. #else /* !CONFIG_CMD_NET */
  76. #if defined(CONFIG_STATIC_BOARD_REV)
  77. /* Look for static defintion of the board revision */
  78. omap3_evm_version = CONFIG_STATIC_BOARD_REV;
  79. #else
  80. /* Fallback to the default above */
  81. omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
  82. #endif /* CONFIG_STATIC_BOARD_REV */
  83. #endif /* CONFIG_CMD_NET */
  84. }
  85. #if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
  86. /* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
  87. u8 omap3_evm_need_extvbus(void)
  88. {
  89. u8 retval = 0;
  90. if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2)
  91. retval = 1;
  92. return retval;
  93. }
  94. #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
  95. /*
  96. * Routine: board_init
  97. * Description: Early hardware init.
  98. */
  99. int board_init(void)
  100. {
  101. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  102. /* board id for Linux */
  103. gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM;
  104. /* boot param addr */
  105. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  106. return 0;
  107. }
  108. #if defined(CONFIG_SPL_OS_BOOT)
  109. int spl_start_uboot(void)
  110. {
  111. /* break into full u-boot on 'c' */
  112. if (serial_tstc() && serial_getc() == 'c')
  113. return 1;
  114. return 0;
  115. }
  116. #endif /* CONFIG_SPL_OS_BOOT */
  117. #if defined(CONFIG_SPL_BUILD)
  118. /*
  119. * Routine: get_board_mem_timings
  120. * Description: If we use SPL then there is no x-loader nor config header
  121. * so we have to setup the DDR timings ourself on the first bank. This
  122. * provides the timing values back to the function that configures
  123. * the memory.
  124. */
  125. void get_board_mem_timings(struct board_sdrc_timings *timings)
  126. {
  127. int pop_mfr, pop_id;
  128. /*
  129. * We need to identify what PoP memory is on the board so that
  130. * we know what timings to use. To map the ID values please see
  131. * nand_ids.c
  132. */
  133. identify_nand_chip(&pop_mfr, &pop_id);
  134. if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
  135. /* 256MB DDR */
  136. timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
  137. timings->ctrla = HYNIX_V_ACTIMA_200;
  138. timings->ctrlb = HYNIX_V_ACTIMB_200;
  139. } else {
  140. /* 128MB DDR */
  141. timings->mcfg = MICRON_V_MCFG_165(128 << 20);
  142. timings->ctrla = MICRON_V_ACTIMA_165;
  143. timings->ctrlb = MICRON_V_ACTIMB_165;
  144. }
  145. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
  146. timings->mr = MICRON_V_MR_165;
  147. }
  148. #endif /* CONFIG_SPL_BUILD */
  149. #if defined(CONFIG_USB_MUSB_OMAP2PLUS)
  150. static struct musb_hdrc_config musb_config = {
  151. .multipoint = 1,
  152. .dyn_fifo = 1,
  153. .num_eps = 16,
  154. .ram_bits = 12,
  155. };
  156. static struct omap_musb_board_data musb_board_data = {
  157. .interface_type = MUSB_INTERFACE_ULPI,
  158. };
  159. static struct musb_hdrc_platform_data musb_plat = {
  160. #if defined(CONFIG_USB_MUSB_HOST)
  161. .mode = MUSB_HOST,
  162. #elif defined(CONFIG_USB_MUSB_GADGET)
  163. .mode = MUSB_PERIPHERAL,
  164. #else
  165. #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
  166. #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
  167. .config = &musb_config,
  168. .power = 100,
  169. .platform_ops = &omap2430_ops,
  170. .board_data = &musb_board_data,
  171. };
  172. #endif /* CONFIG_USB_MUSB_OMAP2PLUS */
  173. /*
  174. * Routine: misc_init_r
  175. * Description: Init ethernet (done here so udelay works)
  176. */
  177. int misc_init_r(void)
  178. {
  179. twl4030_power_init();
  180. #ifdef CONFIG_SYS_I2C_OMAP24XX
  181. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  182. #endif
  183. #if defined(CONFIG_CMD_NET)
  184. setup_net_chip();
  185. #endif
  186. omap3_evm_get_revision();
  187. #if defined(CONFIG_CMD_NET)
  188. reset_net_chip();
  189. #endif
  190. omap_die_id_display();
  191. #if defined(CONFIG_USB_MUSB_OMAP2PLUS)
  192. musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
  193. #endif
  194. #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
  195. omap_die_id_usbethaddr();
  196. #endif
  197. return 0;
  198. }
  199. /*
  200. * Routine: set_muxconf_regs
  201. * Description: Setting up the configuration Mux registers specific to the
  202. * hardware. Many pins need to be moved from protect to primary
  203. * mode.
  204. */
  205. void set_muxconf_regs(void)
  206. {
  207. MUX_EVM();
  208. }
  209. #if defined(CONFIG_CMD_NET)
  210. /*
  211. * Routine: setup_net_chip
  212. * Description: Setting up the configuration GPMC registers specific to the
  213. * Ethernet hardware.
  214. */
  215. static void setup_net_chip(void)
  216. {
  217. struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
  218. /* Configure GPMC registers */
  219. writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
  220. writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
  221. writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
  222. writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
  223. writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
  224. writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
  225. writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
  226. /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
  227. writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
  228. /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
  229. writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
  230. /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
  231. writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
  232. &ctrl_base->gpmc_nadv_ale);
  233. }
  234. /**
  235. * Reset the ethernet chip.
  236. */
  237. static void reset_net_chip(void)
  238. {
  239. int ret;
  240. int rst_gpio;
  241. if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
  242. rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
  243. } else {
  244. rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
  245. }
  246. ret = gpio_request(rst_gpio, "");
  247. if (ret < 0) {
  248. printf("Unable to get GPIO %d\n", rst_gpio);
  249. return ;
  250. }
  251. /* Configure as output */
  252. gpio_direction_output(rst_gpio, 0);
  253. /* Send a pulse on the GPIO pin */
  254. gpio_set_value(rst_gpio, 1);
  255. udelay(1);
  256. gpio_set_value(rst_gpio, 0);
  257. udelay(1);
  258. gpio_set_value(rst_gpio, 1);
  259. }
  260. int board_eth_init(bd_t *bis)
  261. {
  262. #if defined(CONFIG_SMC911X)
  263. env_set("ethaddr", NULL);
  264. return smc911x_initialize(0, CONFIG_SMC911X_BASE);
  265. #else
  266. return 0;
  267. #endif
  268. }
  269. #endif /* CONFIG_CMD_NET */
  270. #if defined(CONFIG_MMC)
  271. int board_mmc_init(bd_t *bis)
  272. {
  273. return omap_mmc_init(0, 0, 0, -1, -1);
  274. }
  275. void board_mmc_power_init(void)
  276. {
  277. twl4030_power_mmc_init(0);
  278. }
  279. #endif /* CONFIG_MMC */
  280. #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
  281. /* Call usb_stop() before starting the kernel */
  282. void show_boot_progress(int val)
  283. {
  284. if (val == BOOTSTAGE_ID_RUN_OS)
  285. usb_stop();
  286. }
  287. static struct omap_usbhs_board_data usbhs_bdata = {
  288. .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
  289. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  290. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
  291. };
  292. int ehci_hcd_init(int index, enum usb_init_type init,
  293. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  294. {
  295. return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  296. }
  297. int ehci_hcd_stop(int index)
  298. {
  299. return omap_ehci_hcd_stop();
  300. }
  301. #endif /* CONFIG_USB_EHCI_HCD */
  302. #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && !defined(CONFIG_CMD_NET)
  303. int board_eth_init(bd_t *bis)
  304. {
  305. return usb_eth_initialize(bis);
  306. }
  307. #endif /* CONFIG_USB_ETHER */