da850evm.c 13 KB

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