da850evm.c 11 KB

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