board.c 7.7 KB

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