omapl138_lcdk.c 9.0 KB

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