da850evm.c 12 KB

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