board.c 6.8 KB

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