da850evm.c 11 KB

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