board.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * board.c
  3. *
  4. * Common board functions for AM33XX based boards
  5. *
  6. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <common.h>
  19. #include <errno.h>
  20. #include <spl.h>
  21. #include <asm/arch/cpu.h>
  22. #include <asm/arch/hardware.h>
  23. #include <asm/arch/omap.h>
  24. #include <asm/arch/ddr_defs.h>
  25. #include <asm/arch/clock.h>
  26. #include <asm/arch/gpio.h>
  27. #include <asm/arch/mmc_host_def.h>
  28. #include <asm/arch/sys_proto.h>
  29. #include <asm/io.h>
  30. #include <asm/emif.h>
  31. #include <asm/gpio.h>
  32. #include <i2c.h>
  33. #include <miiphy.h>
  34. #include <cpsw.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. static struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
  37. #ifdef CONFIG_SPL_BUILD
  38. static struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
  39. #endif
  40. static const struct gpio_bank gpio_bank_am33xx[4] = {
  41. { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
  42. { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
  43. { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
  44. { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
  45. };
  46. const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
  47. /* MII mode defines */
  48. #define MII_MODE_ENABLE 0x0
  49. #define RGMII_MODE_ENABLE 0xA
  50. /* GPIO that controls power to DDR on EVM-SK */
  51. #define GPIO_DDR_VTT_EN 7
  52. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  53. static struct am335x_baseboard_id __attribute__((section (".data"))) header;
  54. static inline int board_is_bone(void)
  55. {
  56. return !strncmp(header.name, "A335BONE", HDR_NAME_LEN);
  57. }
  58. static inline int board_is_bone_lt(void)
  59. {
  60. return !strncmp(header.name, "A335BNLT", HDR_NAME_LEN);
  61. }
  62. static inline int board_is_evm_sk(void)
  63. {
  64. return !strncmp("A335X_SK", header.name, HDR_NAME_LEN);
  65. }
  66. /*
  67. * Read header information from EEPROM into global structure.
  68. */
  69. static int read_eeprom(void)
  70. {
  71. /* Check if baseboard eeprom is available */
  72. if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
  73. puts("Could not probe the EEPROM; something fundamentally "
  74. "wrong on the I2C bus.\n");
  75. return -ENODEV;
  76. }
  77. /* read the eeprom using i2c */
  78. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
  79. sizeof(header))) {
  80. puts("Could not read the EEPROM; something fundamentally"
  81. " wrong on the I2C bus.\n");
  82. return -EIO;
  83. }
  84. if (header.magic != 0xEE3355AA) {
  85. /*
  86. * read the eeprom using i2c again,
  87. * but use only a 1 byte address
  88. */
  89. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
  90. (uchar *)&header, sizeof(header))) {
  91. puts("Could not read the EEPROM; something "
  92. "fundamentally wrong on the I2C bus.\n");
  93. return -EIO;
  94. }
  95. if (header.magic != 0xEE3355AA) {
  96. printf("Incorrect magic number (0x%x) in EEPROM\n",
  97. header.magic);
  98. return -EINVAL;
  99. }
  100. }
  101. return 0;
  102. }
  103. #ifdef CONFIG_SPL_BUILD
  104. /* UART Defines */
  105. #define UART_RESET (0x1 << 1)
  106. #define UART_CLK_RUNNING_MASK 0x1
  107. #define UART_SMART_IDLE_EN (0x1 << 0x3)
  108. static void rtc32k_enable(void)
  109. {
  110. struct rtc_regs *rtc = (struct rtc_regs *)AM335X_RTC_BASE;
  111. /*
  112. * Unlock the RTC's registers. For more details please see the
  113. * RTC_SS section of the TRM. In order to unlock we need to
  114. * write these specific values (keys) in this order.
  115. */
  116. writel(0x83e70b13, &rtc->kick0r);
  117. writel(0x95a4f1e0, &rtc->kick1r);
  118. /* Enable the RTC 32K OSC by setting bits 3 and 6. */
  119. writel((1 << 3) | (1 << 6), &rtc->osc);
  120. }
  121. #endif
  122. /*
  123. * Determine what type of DDR we have.
  124. */
  125. static short inline board_memory_type(void)
  126. {
  127. /* The following boards are known to use DDR3. */
  128. if (board_is_evm_sk() || board_is_bone_lt())
  129. return EMIF_REG_SDRAM_TYPE_DDR3;
  130. return EMIF_REG_SDRAM_TYPE_DDR2;
  131. }
  132. /*
  133. * early system init of muxing and clocks.
  134. */
  135. void s_init(void)
  136. {
  137. /* WDT1 is already running when the bootloader gets control
  138. * Disable it to avoid "random" resets
  139. */
  140. writel(0xAAAA, &wdtimer->wdtwspr);
  141. while (readl(&wdtimer->wdtwwps) != 0x0)
  142. ;
  143. writel(0x5555, &wdtimer->wdtwspr);
  144. while (readl(&wdtimer->wdtwwps) != 0x0)
  145. ;
  146. #ifdef CONFIG_SPL_BUILD
  147. /* Setup the PLLs and the clocks for the peripherals */
  148. pll_init();
  149. /* Enable RTC32K clock */
  150. rtc32k_enable();
  151. /* UART softreset */
  152. u32 regVal;
  153. enable_uart0_pin_mux();
  154. regVal = readl(&uart_base->uartsyscfg);
  155. regVal |= UART_RESET;
  156. writel(regVal, &uart_base->uartsyscfg);
  157. while ((readl(&uart_base->uartsyssts) &
  158. UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
  159. ;
  160. /* Disable smart idle */
  161. regVal = readl(&uart_base->uartsyscfg);
  162. regVal |= UART_SMART_IDLE_EN;
  163. writel(regVal, &uart_base->uartsyscfg);
  164. gd = &gdata;
  165. preloader_console_init();
  166. /* Initalize the board header */
  167. enable_i2c0_pin_mux();
  168. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  169. if (read_eeprom() < 0)
  170. puts("Could not get board ID.\n");
  171. enable_board_pin_mux(&header);
  172. if (board_is_evm_sk()) {
  173. /*
  174. * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
  175. * This is safe enough to do on older revs.
  176. */
  177. gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
  178. gpio_direction_output(GPIO_DDR_VTT_EN, 1);
  179. }
  180. config_ddr(board_memory_type());
  181. #endif
  182. }
  183. #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
  184. int board_mmc_init(bd_t *bis)
  185. {
  186. int ret;
  187. ret = omap_mmc_init(0, 0, 0);
  188. if (ret)
  189. return ret;
  190. return omap_mmc_init(1, 0, 0);
  191. }
  192. #endif
  193. void setup_clocks_for_console(void)
  194. {
  195. /* Not yet implemented */
  196. return;
  197. }
  198. /*
  199. * Basic board specific setup. Pinmux has been handled already.
  200. */
  201. int board_init(void)
  202. {
  203. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  204. if (read_eeprom() < 0)
  205. puts("Could not get board ID.\n");
  206. gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
  207. return 0;
  208. }
  209. #ifdef CONFIG_DRIVER_TI_CPSW
  210. static void cpsw_control(int enabled)
  211. {
  212. /* VTP can be added here */
  213. return;
  214. }
  215. static struct cpsw_slave_data cpsw_slaves[] = {
  216. {
  217. .slave_reg_ofs = 0x208,
  218. .sliver_reg_ofs = 0xd80,
  219. .phy_id = 0,
  220. },
  221. {
  222. .slave_reg_ofs = 0x308,
  223. .sliver_reg_ofs = 0xdc0,
  224. .phy_id = 1,
  225. },
  226. };
  227. static struct cpsw_platform_data cpsw_data = {
  228. .mdio_base = AM335X_CPSW_MDIO_BASE,
  229. .cpsw_base = AM335X_CPSW_BASE,
  230. .mdio_div = 0xff,
  231. .channels = 8,
  232. .cpdma_reg_ofs = 0x800,
  233. .slaves = 1,
  234. .slave_data = cpsw_slaves,
  235. .ale_reg_ofs = 0xd00,
  236. .ale_entries = 1024,
  237. .host_port_reg_ofs = 0x108,
  238. .hw_stats_reg_ofs = 0x900,
  239. .mac_control = (1 << 5),
  240. .control = cpsw_control,
  241. .host_port_num = 0,
  242. .version = CPSW_CTRL_VERSION_2,
  243. };
  244. int board_eth_init(bd_t *bis)
  245. {
  246. uint8_t mac_addr[6];
  247. uint32_t mac_hi, mac_lo;
  248. if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
  249. debug("<ethaddr> not set. Reading from E-fuse\n");
  250. /* try reading mac address from efuse */
  251. mac_lo = readl(&cdev->macid0l);
  252. mac_hi = readl(&cdev->macid0h);
  253. mac_addr[0] = mac_hi & 0xFF;
  254. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  255. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  256. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  257. mac_addr[4] = mac_lo & 0xFF;
  258. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  259. if (is_valid_ether_addr(mac_addr))
  260. eth_setenv_enetaddr("ethaddr", mac_addr);
  261. else
  262. return -1;
  263. }
  264. if (board_is_bone() || board_is_bone_lt()) {
  265. writel(MII_MODE_ENABLE, &cdev->miisel);
  266. cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
  267. PHY_INTERFACE_MODE_MII;
  268. } else {
  269. writel(RGMII_MODE_ENABLE, &cdev->miisel);
  270. cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
  271. PHY_INTERFACE_MODE_RGMII;
  272. }
  273. return cpsw_register(&cpsw_data);
  274. }
  275. #endif