da850evm.c 12 KB

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