da850evm.c 13 KB

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