da850evm.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*
  2. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  3. *
  4. * Based on da830evm.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 <asm/arch/hardware.h>
  28. #include <asm/arch/emif_defs.h>
  29. #include <asm/arch/emac_defs.h>
  30. #include <asm/arch/pinmux_defs.h>
  31. #include <asm/io.h>
  32. #include <asm/arch/davinci_misc.h>
  33. #include <hwconfig.h>
  34. DECLARE_GLOBAL_DATA_PTR;
  35. #ifdef CONFIG_DRIVER_TI_EMAC
  36. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  37. #define HAS_RMII 1
  38. #else
  39. #define HAS_RMII 0
  40. #endif
  41. #endif /* CONFIG_DRIVER_TI_EMAC */
  42. void dsp_lpsc_on(unsigned domain, unsigned int id)
  43. {
  44. dv_reg_p mdstat, mdctl, ptstat, ptcmd;
  45. struct davinci_psc_regs *psc_regs;
  46. psc_regs = davinci_psc0_regs;
  47. mdstat = &psc_regs->psc0.mdstat[id];
  48. mdctl = &psc_regs->psc0.mdctl[id];
  49. ptstat = &psc_regs->ptstat;
  50. ptcmd = &psc_regs->ptcmd;
  51. while (*ptstat & (0x1 << domain))
  52. ;
  53. if ((*mdstat & 0x1f) == 0x03)
  54. return; /* Already on and enabled */
  55. *mdctl |= 0x03;
  56. *ptcmd = 0x1 << domain;
  57. while (*ptstat & (0x1 << domain))
  58. ;
  59. while ((*mdstat & 0x1f) != 0x03)
  60. ; /* Probably an overkill... */
  61. }
  62. static void dspwake(void)
  63. {
  64. unsigned *resetvect = (unsigned *)DAVINCI_L3CBARAM_BASE;
  65. u32 val;
  66. /* if the device is ARM only, return */
  67. if ((readl(CHIP_REV_ID_REG) & 0x3f) == 0x10)
  68. return;
  69. if (hwconfig_subarg_cmp_f("dsp", "wake", "no", NULL))
  70. return;
  71. *resetvect++ = 0x1E000; /* DSP Idle */
  72. /* clear out the next 10 words as NOP */
  73. memset(resetvect, 0, sizeof(unsigned) *10);
  74. /* setup the DSP reset vector */
  75. writel(DAVINCI_L3CBARAM_BASE, HOST1CFG);
  76. dsp_lpsc_on(1, DAVINCI_LPSC_GEM);
  77. val = readl(PSC0_MDCTL + (15 * 4));
  78. val |= 0x100;
  79. writel(val, (PSC0_MDCTL + (15 * 4)));
  80. }
  81. int misc_init_r(void)
  82. {
  83. dspwake();
  84. return 0;
  85. }
  86. static const struct pinmux_config gpio_pins[] = {
  87. #ifdef CONFIG_USE_NOR
  88. /* GP0[11] is required for NOR to work on Rev 3 EVMs */
  89. { pinmux(0), 8, 4 }, /* GP0[11] */
  90. #endif
  91. };
  92. const struct pinmux_resource pinmuxes[] = {
  93. #ifdef CONFIG_DRIVER_TI_EMAC
  94. PINMUX_ITEM(emac_pins_mdio),
  95. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  96. PINMUX_ITEM(emac_pins_rmii),
  97. #else
  98. PINMUX_ITEM(emac_pins_mii),
  99. #endif
  100. #endif
  101. #ifdef CONFIG_SPI_FLASH
  102. PINMUX_ITEM(spi1_pins_base),
  103. PINMUX_ITEM(spi1_pins_scs0),
  104. #endif
  105. PINMUX_ITEM(uart2_pins_txrx),
  106. PINMUX_ITEM(uart2_pins_rtscts),
  107. PINMUX_ITEM(i2c0_pins),
  108. #ifdef CONFIG_NAND_DAVINCI
  109. PINMUX_ITEM(emifa_pins_cs3),
  110. PINMUX_ITEM(emifa_pins_cs4),
  111. PINMUX_ITEM(emifa_pins_nand),
  112. #elif defined(CONFIG_USE_NOR)
  113. PINMUX_ITEM(emifa_pins_cs2),
  114. PINMUX_ITEM(emifa_pins_nor),
  115. #endif
  116. PINMUX_ITEM(gpio_pins),
  117. };
  118. const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
  119. static const struct lpsc_resource lpsc[] = {
  120. { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
  121. { DAVINCI_LPSC_SPI1 }, /* Serial Flash */
  122. { DAVINCI_LPSC_EMAC }, /* image download */
  123. { DAVINCI_LPSC_UART2 }, /* console */
  124. { DAVINCI_LPSC_GPIO },
  125. };
  126. #ifndef CONFIG_DA850_EVM_MAX_CPU_CLK
  127. #define CONFIG_DA850_EVM_MAX_CPU_CLK 300000000
  128. #endif
  129. #define REV_AM18X_EVM 0x100
  130. /*
  131. * get_board_rev() - setup to pass kernel board revision information
  132. * Returns:
  133. * bit[0-3] Maximum cpu clock rate supported by onboard SoC
  134. * 0000b - 300 MHz
  135. * 0001b - 372 MHz
  136. * 0010b - 408 MHz
  137. * 0011b - 456 MHz
  138. */
  139. u32 get_board_rev(void)
  140. {
  141. char *s;
  142. u32 maxcpuclk = CONFIG_DA850_EVM_MAX_CPU_CLK;
  143. u32 rev = 0;
  144. s = getenv("maxcpuclk");
  145. if (s)
  146. maxcpuclk = simple_strtoul(s, NULL, 10);
  147. if (maxcpuclk >= 456000000)
  148. rev = 3;
  149. else if (maxcpuclk >= 408000000)
  150. rev = 2;
  151. else if (maxcpuclk >= 372000000)
  152. rev = 1;
  153. #ifdef CONFIG_DA850_AM18X_EVM
  154. rev |= REV_AM18X_EVM;
  155. #endif
  156. return rev;
  157. }
  158. int board_early_init_f(void)
  159. {
  160. /*
  161. * Power on required peripherals
  162. * ARM does not have access by default to PSC0 and PSC1
  163. * assuming here that the DSP bootloader has set the IOPU
  164. * such that PSC access is available to ARM
  165. */
  166. if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
  167. return 1;
  168. return 0;
  169. }
  170. int board_init(void)
  171. {
  172. #ifdef CONFIG_USE_NOR
  173. u32 val;
  174. #endif
  175. #ifndef CONFIG_USE_IRQ
  176. irq_init();
  177. #endif
  178. #ifdef CONFIG_NAND_DAVINCI
  179. /*
  180. * NAND CS setup - cycle counts based on da850evm NAND timings in the
  181. * Linux kernel @ 25MHz EMIFA
  182. */
  183. writel((DAVINCI_ABCR_WSETUP(0) |
  184. DAVINCI_ABCR_WSTROBE(1) |
  185. DAVINCI_ABCR_WHOLD(0) |
  186. DAVINCI_ABCR_RSETUP(0) |
  187. DAVINCI_ABCR_RSTROBE(1) |
  188. DAVINCI_ABCR_RHOLD(0) |
  189. DAVINCI_ABCR_TA(1) |
  190. DAVINCI_ABCR_ASIZE_8BIT),
  191. &davinci_emif_regs->ab2cr); /* CS3 */
  192. #endif
  193. /* arch number of the board */
  194. gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
  195. /* address of boot parameters */
  196. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  197. /* setup the SUSPSRC for ARM to control emulation suspend */
  198. writel(readl(&davinci_syscfg_regs->suspsrc) &
  199. ~(DAVINCI_SYSCFG_SUSPSRC_EMAC | DAVINCI_SYSCFG_SUSPSRC_I2C |
  200. DAVINCI_SYSCFG_SUSPSRC_SPI1 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
  201. DAVINCI_SYSCFG_SUSPSRC_UART2),
  202. &davinci_syscfg_regs->suspsrc);
  203. /* configure pinmux settings */
  204. if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
  205. return 1;
  206. #ifdef CONFIG_USE_NOR
  207. /* Set the GPIO direction as output */
  208. clrbits_be32((u32 *)GPIO_BANK0_REG_DIR_ADDR, (0x01 << 11));
  209. /* Set the output as low */
  210. val = readl(GPIO_BANK0_REG_SET_ADDR);
  211. val |= (0x01 << 11);
  212. writel(val, GPIO_BANK0_REG_CLR_ADDR);
  213. #endif
  214. #ifdef CONFIG_DRIVER_TI_EMAC
  215. davinci_emac_mii_mode_sel(HAS_RMII);
  216. #endif /* CONFIG_DRIVER_TI_EMAC */
  217. /* enable the console UART */
  218. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  219. DAVINCI_UART_PWREMU_MGMT_UTRST),
  220. &davinci_uart2_ctrl_regs->pwremu_mgmt);
  221. return 0;
  222. }
  223. #ifdef CONFIG_DRIVER_TI_EMAC
  224. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  225. /**
  226. * rmii_hw_init
  227. *
  228. * DA850/OMAP-L138 EVM can interface to a daughter card for
  229. * additional features. This card has an I2C GPIO Expander TCA6416
  230. * to select the required functions like camera, RMII Ethernet,
  231. * character LCD, video.
  232. *
  233. * Initialization of the expander involves configuring the
  234. * polarity and direction of the ports. P07-P05 are used here.
  235. * These ports are connected to a Mux chip which enables only one
  236. * functionality at a time.
  237. *
  238. * For RMII phy to respond, the MII MDIO clock has to be disabled
  239. * since both the PHY devices have address as zero. The MII MDIO
  240. * clock is controlled via GPIO2[6].
  241. *
  242. * This code is valid for Beta version of the hardware
  243. */
  244. int rmii_hw_init(void)
  245. {
  246. const struct pinmux_config gpio_pins[] = {
  247. { pinmux(6), 8, 1 }
  248. };
  249. u_int8_t buf[2];
  250. unsigned int temp;
  251. int ret;
  252. /* PinMux for GPIO */
  253. if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
  254. return 1;
  255. /* I2C Exapnder configuration */
  256. /* Set polarity to non-inverted */
  257. buf[0] = 0x0;
  258. buf[1] = 0x0;
  259. ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
  260. if (ret) {
  261. printf("\nExpander @ 0x%02x write FAILED!!!\n",
  262. CONFIG_SYS_I2C_EXPANDER_ADDR);
  263. return ret;
  264. }
  265. /* Configure P07-P05 as outputs */
  266. buf[0] = 0x1f;
  267. buf[1] = 0xff;
  268. ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
  269. if (ret) {
  270. printf("\nExpander @ 0x%02x write FAILED!!!\n",
  271. CONFIG_SYS_I2C_EXPANDER_ADDR);
  272. }
  273. /* For Ethernet RMII selection
  274. * P07(SelA)=0
  275. * P06(SelB)=1
  276. * P05(SelC)=1
  277. */
  278. if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
  279. printf("\nExpander @ 0x%02x read FAILED!!!\n",
  280. CONFIG_SYS_I2C_EXPANDER_ADDR);
  281. }
  282. buf[0] &= 0x1f;
  283. buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
  284. if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
  285. printf("\nExpander @ 0x%02x write FAILED!!!\n",
  286. CONFIG_SYS_I2C_EXPANDER_ADDR);
  287. }
  288. /* Set the output as high */
  289. temp = REG(GPIO_BANK2_REG_SET_ADDR);
  290. temp |= (0x01 << 6);
  291. REG(GPIO_BANK2_REG_SET_ADDR) = temp;
  292. /* Set the GPIO direction as output */
  293. temp = REG(GPIO_BANK2_REG_DIR_ADDR);
  294. temp &= ~(0x01 << 6);
  295. REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
  296. return 0;
  297. }
  298. #endif /* CONFIG_DRIVER_TI_EMAC_USE_RMII */
  299. /*
  300. * Initializes on-board ethernet controllers.
  301. */
  302. int board_eth_init(bd_t *bis)
  303. {
  304. #ifdef CONFIG_DRIVER_TI_EMAC_USE_RMII
  305. /* Select RMII fucntion through the expander */
  306. if (rmii_hw_init())
  307. printf("RMII hardware init failed!!!\n");
  308. #endif
  309. if (!davinci_emac_initialize()) {
  310. printf("Error: Ethernet init failed!\n");
  311. return -1;
  312. }
  313. return 0;
  314. }
  315. #endif /* CONFIG_DRIVER_TI_EMAC */