board.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 <asm/arch/cpu.h>
  21. #include <asm/arch/hardware.h>
  22. #include <asm/arch/omap.h>
  23. #include <asm/arch/ddr_defs.h>
  24. #include <asm/arch/clock.h>
  25. #include <asm/arch/gpio.h>
  26. #include <asm/arch/mmc_host_def.h>
  27. #include <asm/arch/common_def.h>
  28. #include <asm/io.h>
  29. #include <asm/omap_common.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. struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
  37. struct gptimer *timer_base = (struct gptimer *)CONFIG_SYS_TIMERBASE;
  38. struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
  39. static const struct gpio_bank gpio_bank_am33xx[4] = {
  40. { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
  41. { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
  42. { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
  43. { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
  44. };
  45. const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
  46. /* MII mode defines */
  47. #define MII_MODE_ENABLE 0x0
  48. #define RGMII_MODE_ENABLE 0xA
  49. /* GPIO that controls power to DDR on EVM-SK */
  50. #define GPIO_DDR_VTT_EN 7
  51. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  52. #define NO_OF_MAC_ADDR 3
  53. #define ETH_ALEN 6
  54. #define NAME_LEN 8
  55. struct am335x_baseboard_id {
  56. unsigned int magic;
  57. char name[NAME_LEN];
  58. char version[4];
  59. char serial[12];
  60. char config[32];
  61. char mac_addr[NO_OF_MAC_ADDR][ETH_ALEN];
  62. };
  63. static struct am335x_baseboard_id __attribute__((section (".data"))) header;
  64. static inline int board_is_bone(void)
  65. {
  66. return !strncmp(header.name, "A335BONE", NAME_LEN);
  67. }
  68. static inline int board_is_evm_sk(void)
  69. {
  70. return !strncmp("A335X_SK", header.name, NAME_LEN);
  71. }
  72. /*
  73. * Read header information from EEPROM into global structure.
  74. */
  75. static int read_eeprom(void)
  76. {
  77. /* Check if baseboard eeprom is available */
  78. if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
  79. puts("Could not probe the EEPROM; something fundamentally "
  80. "wrong on the I2C bus.\n");
  81. return -ENODEV;
  82. }
  83. /* read the eeprom using i2c */
  84. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)&header,
  85. sizeof(header))) {
  86. puts("Could not read the EEPROM; something fundamentally"
  87. " wrong on the I2C bus.\n");
  88. return -EIO;
  89. }
  90. if (header.magic != 0xEE3355AA) {
  91. /*
  92. * read the eeprom using i2c again,
  93. * but use only a 1 byte address
  94. */
  95. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1,
  96. (uchar *)&header, sizeof(header))) {
  97. puts("Could not read the EEPROM; something "
  98. "fundamentally wrong on the I2C bus.\n");
  99. return -EIO;
  100. }
  101. if (header.magic != 0xEE3355AA) {
  102. printf("Incorrect magic number (0x%x) in EEPROM\n",
  103. header.magic);
  104. return -EINVAL;
  105. }
  106. }
  107. return 0;
  108. }
  109. /* UART Defines */
  110. #ifdef CONFIG_SPL_BUILD
  111. #define UART_RESET (0x1 << 1)
  112. #define UART_CLK_RUNNING_MASK 0x1
  113. #define UART_SMART_IDLE_EN (0x1 << 0x3)
  114. #endif
  115. #ifdef CONFIG_SPL_BUILD
  116. /* Initialize timer */
  117. static void init_timer(void)
  118. {
  119. /* Reset the Timer */
  120. writel(0x2, (&timer_base->tscir));
  121. /* Wait until the reset is done */
  122. while (readl(&timer_base->tiocp_cfg) & 1)
  123. ;
  124. /* Start the Timer */
  125. writel(0x1, (&timer_base->tclr));
  126. }
  127. #endif
  128. /*
  129. * Determine what type of DDR we have.
  130. */
  131. static short inline board_memory_type(void)
  132. {
  133. /* The following boards are known to use DDR3. */
  134. if (board_is_evm_sk())
  135. return EMIF_REG_SDRAM_TYPE_DDR3;
  136. return EMIF_REG_SDRAM_TYPE_DDR2;
  137. }
  138. /*
  139. * early system init of muxing and clocks.
  140. */
  141. void s_init(void)
  142. {
  143. /* WDT1 is already running when the bootloader gets control
  144. * Disable it to avoid "random" resets
  145. */
  146. writel(0xAAAA, &wdtimer->wdtwspr);
  147. while (readl(&wdtimer->wdtwwps) != 0x0)
  148. ;
  149. writel(0x5555, &wdtimer->wdtwspr);
  150. while (readl(&wdtimer->wdtwwps) != 0x0)
  151. ;
  152. #ifdef CONFIG_SPL_BUILD
  153. /* Setup the PLLs and the clocks for the peripherals */
  154. pll_init();
  155. /* UART softreset */
  156. u32 regVal;
  157. enable_uart0_pin_mux();
  158. regVal = readl(&uart_base->uartsyscfg);
  159. regVal |= UART_RESET;
  160. writel(regVal, &uart_base->uartsyscfg);
  161. while ((readl(&uart_base->uartsyssts) &
  162. UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
  163. ;
  164. /* Disable smart idle */
  165. regVal = readl(&uart_base->uartsyscfg);
  166. regVal |= UART_SMART_IDLE_EN;
  167. writel(regVal, &uart_base->uartsyscfg);
  168. /* Initialize the Timer */
  169. init_timer();
  170. preloader_console_init();
  171. /* Initalize the board header */
  172. enable_i2c0_pin_mux();
  173. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  174. if (read_eeprom() < 0)
  175. puts("Could not get board ID.\n");
  176. if (board_is_evm_sk()) {
  177. /*
  178. * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
  179. * This is safe enough to do on older revs.
  180. */
  181. enable_gpio0_7_pin_mux();
  182. gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
  183. gpio_direction_output(GPIO_DDR_VTT_EN, 1);
  184. }
  185. config_ddr(board_memory_type());
  186. #endif
  187. /* Enable MMC0 */
  188. enable_mmc0_pin_mux();
  189. }
  190. #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
  191. int board_mmc_init(bd_t *bis)
  192. {
  193. return omap_mmc_init(0, 0, 0);
  194. }
  195. #endif
  196. void setup_clocks_for_console(void)
  197. {
  198. /* Not yet implemented */
  199. return;
  200. }
  201. /*
  202. * Basic board specific setup
  203. */
  204. int board_init(void)
  205. {
  206. enable_uart0_pin_mux();
  207. enable_i2c0_pin_mux();
  208. enable_i2c1_pin_mux();
  209. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  210. if (read_eeprom() < 0)
  211. puts("Could not get board ID.\n");
  212. gd->bd->bi_boot_params = PHYS_DRAM_1 + 0x100;
  213. return 0;
  214. }
  215. #ifdef CONFIG_DRIVER_TI_CPSW
  216. static void cpsw_control(int enabled)
  217. {
  218. /* VTP can be added here */
  219. return;
  220. }
  221. static struct cpsw_slave_data cpsw_slaves[] = {
  222. {
  223. .slave_reg_ofs = 0x208,
  224. .sliver_reg_ofs = 0xd80,
  225. .phy_id = 0,
  226. },
  227. {
  228. .slave_reg_ofs = 0x308,
  229. .sliver_reg_ofs = 0xdc0,
  230. .phy_id = 1,
  231. },
  232. };
  233. static struct cpsw_platform_data cpsw_data = {
  234. .mdio_base = AM335X_CPSW_MDIO_BASE,
  235. .cpsw_base = AM335X_CPSW_BASE,
  236. .mdio_div = 0xff,
  237. .channels = 8,
  238. .cpdma_reg_ofs = 0x800,
  239. .slaves = 1,
  240. .slave_data = cpsw_slaves,
  241. .ale_reg_ofs = 0xd00,
  242. .ale_entries = 1024,
  243. .host_port_reg_ofs = 0x108,
  244. .hw_stats_reg_ofs = 0x900,
  245. .mac_control = (1 << 5),
  246. .control = cpsw_control,
  247. .host_port_num = 0,
  248. .version = CPSW_CTRL_VERSION_2,
  249. };
  250. int board_eth_init(bd_t *bis)
  251. {
  252. uint8_t mac_addr[6];
  253. uint32_t mac_hi, mac_lo;
  254. if (!eth_getenv_enetaddr("ethaddr", mac_addr)) {
  255. debug("<ethaddr> not set. Reading from E-fuse\n");
  256. /* try reading mac address from efuse */
  257. mac_lo = readl(&cdev->macid0l);
  258. mac_hi = readl(&cdev->macid0h);
  259. mac_addr[0] = mac_hi & 0xFF;
  260. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  261. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  262. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  263. mac_addr[4] = mac_lo & 0xFF;
  264. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  265. if (is_valid_ether_addr(mac_addr))
  266. eth_setenv_enetaddr("ethaddr", mac_addr);
  267. else
  268. return -1;
  269. }
  270. if (board_is_bone()) {
  271. enable_mii1_pin_mux();
  272. writel(MII_MODE_ENABLE, &cdev->miisel);
  273. cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
  274. PHY_INTERFACE_MODE_MII;
  275. } else {
  276. enable_rgmii1_pin_mux();
  277. writel(RGMII_MODE_ENABLE, &cdev->miisel);
  278. cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
  279. PHY_INTERFACE_MODE_RGMII;
  280. }
  281. return cpsw_register(&cpsw_data);
  282. }
  283. #endif