omapl138_lcdk.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*
  2. * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
  3. *
  4. * Based on da850evm.c. Original Copyrights follow:
  5. *
  6. * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
  7. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <i2c.h>
  13. #include <net.h>
  14. #include <netdev.h>
  15. #include <spi.h>
  16. #include <spi_flash.h>
  17. #include <asm/arch/hardware.h>
  18. #include <asm/ti-common/davinci_nand.h>
  19. #include <asm/io.h>
  20. #include <linux/errno.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/arch/davinci_misc.h>
  23. #ifdef CONFIG_MMC_DAVINCI
  24. #include <mmc.h>
  25. #include <asm/arch/sdmmc_defs.h>
  26. #endif
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
  29. #ifdef CONFIG_MMC_DAVINCI
  30. /* MMC0 pin muxer settings */
  31. const struct pinmux_config mmc0_pins[] = {
  32. /* GP0[11] is required for SD to work on Rev 3 EVMs */
  33. { pinmux(0), 8, 4 }, /* GP0[11] */
  34. { pinmux(10), 2, 0 }, /* MMCSD0_CLK */
  35. { pinmux(10), 2, 1 }, /* MMCSD0_CMD */
  36. { pinmux(10), 2, 2 }, /* MMCSD0_DAT_0 */
  37. { pinmux(10), 2, 3 }, /* MMCSD0_DAT_1 */
  38. { pinmux(10), 2, 4 }, /* MMCSD0_DAT_2 */
  39. { pinmux(10), 2, 5 }, /* MMCSD0_DAT_3 */
  40. /* LCDK supports only 4-bit mode, remaining pins are not configured */
  41. };
  42. #endif
  43. /* UART pin muxer settings */
  44. static const struct pinmux_config uart_pins[] = {
  45. { pinmux(0), 4, 6 },
  46. { pinmux(0), 4, 7 },
  47. { pinmux(4), 2, 4 },
  48. { pinmux(4), 2, 5 }
  49. };
  50. #ifdef CONFIG_DRIVER_TI_EMAC
  51. static const struct pinmux_config emac_pins[] = {
  52. { pinmux(2), 8, 1 },
  53. { pinmux(2), 8, 2 },
  54. { pinmux(2), 8, 3 },
  55. { pinmux(2), 8, 4 },
  56. { pinmux(2), 8, 5 },
  57. { pinmux(2), 8, 6 },
  58. { pinmux(2), 8, 7 },
  59. { pinmux(3), 8, 0 },
  60. { pinmux(3), 8, 1 },
  61. { pinmux(3), 8, 2 },
  62. { pinmux(3), 8, 3 },
  63. { pinmux(3), 8, 4 },
  64. { pinmux(3), 8, 5 },
  65. { pinmux(3), 8, 6 },
  66. { pinmux(3), 8, 7 },
  67. { pinmux(4), 8, 0 },
  68. { pinmux(4), 8, 1 }
  69. };
  70. #endif /* CONFIG_DRIVER_TI_EMAC */
  71. /* I2C pin muxer settings */
  72. static const struct pinmux_config i2c_pins[] = {
  73. { pinmux(4), 2, 2 },
  74. { pinmux(4), 2, 3 }
  75. };
  76. #ifdef CONFIG_NAND_DAVINCI
  77. const struct pinmux_config nand_pins[] = {
  78. { pinmux(7), 1, 1 },
  79. { pinmux(7), 1, 2 },
  80. { pinmux(7), 1, 4 },
  81. { pinmux(7), 1, 5 },
  82. { pinmux(8), 1, 0 },
  83. { pinmux(8), 1, 1 },
  84. { pinmux(8), 1, 2 },
  85. { pinmux(8), 1, 3 },
  86. { pinmux(8), 1, 4 },
  87. { pinmux(8), 1, 5 },
  88. { pinmux(8), 1, 6 },
  89. { pinmux(8), 1, 7 },
  90. { pinmux(9), 1, 0 },
  91. { pinmux(9), 1, 1 },
  92. { pinmux(9), 1, 2 },
  93. { pinmux(9), 1, 3 },
  94. { pinmux(9), 1, 4 },
  95. { pinmux(9), 1, 5 },
  96. { pinmux(9), 1, 6 },
  97. { pinmux(9), 1, 7 },
  98. { pinmux(12), 1, 5 },
  99. { pinmux(12), 1, 6 }
  100. };
  101. #endif
  102. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  103. #define HAS_RMII 1
  104. #else
  105. #define HAS_RMII 0
  106. #endif
  107. const struct pinmux_resource pinmuxes[] = {
  108. PINMUX_ITEM(uart_pins),
  109. PINMUX_ITEM(i2c_pins),
  110. #ifdef CONFIG_NAND_DAVINCI
  111. PINMUX_ITEM(nand_pins),
  112. #endif
  113. };
  114. const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
  115. const struct lpsc_resource lpsc[] = {
  116. { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
  117. { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
  118. { DAVINCI_LPSC_EMAC }, /* image download */
  119. { DAVINCI_LPSC_UART2 }, /* console */
  120. { DAVINCI_LPSC_GPIO },
  121. #ifdef CONFIG_MMC_DAVINCI
  122. { DAVINCI_LPSC_MMC_SD },
  123. #endif
  124. };
  125. const int lpsc_size = ARRAY_SIZE(lpsc);
  126. #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
  127. #define CONFIG_DA850_EVM_MAX_CPU_CLK 456000000
  128. #endif
  129. /*
  130. * get_board_rev() - setup to pass kernel board revision information
  131. * Returns:
  132. * bit[0-3] Maximum cpu clock rate supported by onboard SoC
  133. * 0000b - 300 MHz
  134. * 0001b - 372 MHz
  135. * 0010b - 408 MHz
  136. * 0011b - 456 MHz
  137. */
  138. u32 get_board_rev(void)
  139. {
  140. return 0;
  141. }
  142. int board_early_init_f(void)
  143. {
  144. /*
  145. * Power on required peripherals
  146. * ARM does not have access by default to PSC0 and PSC1
  147. * assuming here that the DSP bootloader has set the IOPU
  148. * such that PSC access is available to ARM
  149. */
  150. if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
  151. return 1;
  152. return 0;
  153. }
  154. int board_init(void)
  155. {
  156. irq_init();
  157. /* arch number of the board */
  158. gd->bd->bi_arch_number = MACH_TYPE_OMAPL138_LCDK;
  159. /* address of boot parameters */
  160. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  161. /* setup the SUSPSRC for ARM to control emulation suspend */
  162. writel(readl(&davinci_syscfg_regs->suspsrc) &
  163. ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
  164. DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
  165. DAVINCI_SYSCFG_SUSPSRC_UART2),
  166. &davinci_syscfg_regs->suspsrc);
  167. /* configure pinmux settings */
  168. if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
  169. return 1;
  170. #ifdef CONFIG_NAND_DAVINCI
  171. /*
  172. * NAND CS setup - cycle counts based on da850evm NAND timings in the
  173. * Linux kernel @ 25MHz EMIFA
  174. */
  175. writel((DAVINCI_ABCR_WSETUP(15) |
  176. DAVINCI_ABCR_WSTROBE(63) |
  177. DAVINCI_ABCR_WHOLD(7) |
  178. DAVINCI_ABCR_RSETUP(15) |
  179. DAVINCI_ABCR_RSTROBE(63) |
  180. DAVINCI_ABCR_RHOLD(7) |
  181. DAVINCI_ABCR_TA(3) |
  182. DAVINCI_ABCR_ASIZE_16BIT),
  183. &davinci_emif_regs->ab2cr); /* CS3 */
  184. #endif
  185. #ifdef CONFIG_MMC_DAVINCI
  186. if (davinci_configure_pin_mux(mmc0_pins, ARRAY_SIZE(mmc0_pins)) != 0)
  187. return 1;
  188. #endif
  189. #ifdef CONFIG_DRIVER_TI_EMAC
  190. if (davinci_configure_pin_mux(emac_pins, ARRAY_SIZE(emac_pins)) != 0)
  191. return 1;
  192. davinci_emac_mii_mode_sel(HAS_RMII);
  193. #endif /* CONFIG_DRIVER_TI_EMAC */
  194. /* enable the console UART */
  195. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  196. DAVINCI_UART_PWREMU_MGMT_UTRST),
  197. &davinci_uart2_ctrl_regs->pwremu_mgmt);
  198. return 0;
  199. }
  200. #ifdef CONFIG_DRIVER_TI_EMAC
  201. /*
  202. * Initializes on-board ethernet controllers.
  203. */
  204. int board_eth_init(bd_t *bis)
  205. {
  206. if (!davinci_emac_initialize()) {
  207. printf("Error: Ethernet init failed!\n");
  208. return -1;
  209. }
  210. return 0;
  211. }
  212. #endif /* CONFIG_DRIVER_TI_EMAC */
  213. #define CFG_MAC_ADDR_SPI_BUS 0
  214. #define CFG_MAC_ADDR_SPI_CS 0
  215. #define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED
  216. #define CFG_MAC_ADDR_SPI_MODE SPI_MODE_3
  217. #define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K)
  218. static int get_mac_addr(u8 *addr)
  219. {
  220. /* Need to find a way to get MAC ADDRESS */
  221. return 0;
  222. }
  223. void dsp_lpsc_on(unsigned domain, unsigned int id)
  224. {
  225. dv_reg_p mdstat, mdctl, ptstat, ptcmd;
  226. struct davinci_psc_regs *psc_regs;
  227. psc_regs = davinci_psc0_regs;
  228. mdstat = &psc_regs->psc0.mdstat[id];
  229. mdctl = &psc_regs->psc0.mdctl[id];
  230. ptstat = &psc_regs->ptstat;
  231. ptcmd = &psc_regs->ptcmd;
  232. while (*ptstat & (0x1 << domain))
  233. ;
  234. if ((*mdstat & 0x1f) == 0x03)
  235. return; /* Already on and enabled */
  236. *mdctl |= 0x03;
  237. *ptcmd = 0x1 << domain;
  238. while (*ptstat & (0x1 << domain))
  239. ;
  240. while ((*mdstat & 0x1f) != 0x03)
  241. ; /* Probably an overkill... */
  242. }
  243. static void dspwake(void)
  244. {
  245. unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
  246. /* if the device is ARM only, return */
  247. if ((REG(CHIP_REV_ID_REG) & 0x3f) == 0x10)
  248. return;
  249. if (!strcmp(env_get("dspwake"), "no"))
  250. return;
  251. *resetvect++ = 0x1E000; /* DSP Idle */
  252. /* clear out the next 10 words as NOP */
  253. memset(resetvect, 0, sizeof(unsigned) * 10);
  254. /* setup the DSP reset vector */
  255. REG(HOST1CFG) = DAVINCI_L3CBARAM_BASE;
  256. dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
  257. REG(PSC0_MDCTL + (15 * 4)) |= 0x100;
  258. }
  259. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  260. /**
  261. * rmii_hw_init
  262. *
  263. */
  264. int rmii_hw_init(void)
  265. {
  266. return 0;
  267. }
  268. #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
  269. int misc_init_r(void)
  270. {
  271. uint8_t tmp[20], addr[10];
  272. if (env_get("ethaddr") == NULL) {
  273. /* Read Ethernet MAC address from EEPROM */
  274. if (dvevm_read_mac_address(addr)) {
  275. /* Set Ethernet MAC address from EEPROM */
  276. davinci_sync_env_enetaddr(addr);
  277. } else {
  278. get_mac_addr(addr);
  279. }
  280. if (!is_multicast_ethaddr(addr) && !is_zero_ethaddr(addr)) {
  281. sprintf((char *)tmp, "%02x:%02x:%02x:%02x:%02x:%02x",
  282. addr[0], addr[1], addr[2], addr[3], addr[4],
  283. addr[5]);
  284. env_set("ethaddr", (char *)tmp);
  285. } else {
  286. printf("Invalid MAC address read.\n");
  287. }
  288. }
  289. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  290. /* Select RMII fucntion through the expander */
  291. if (rmii_hw_init())
  292. printf("RMII hardware init failed!!!\n");
  293. #endif
  294. dspwake();
  295. return 0;
  296. }
  297. #ifdef CONFIG_MMC_DAVINCI
  298. static struct davinci_mmc mmc_sd0 = {
  299. .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
  300. .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
  301. .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
  302. .version = MMC_CTLR_VERSION_2,
  303. };
  304. int board_mmc_init(bd_t *bis)
  305. {
  306. mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
  307. /* Add slot-0 to mmc subsystem */
  308. return davinci_mmc_init(bis, &mmc_sd0);
  309. }
  310. #endif