board.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * board.c
  3. *
  4. * Board functions for TI AM43XX based boards
  5. *
  6. * Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <i2c.h>
  12. #include <asm/errno.h>
  13. #include <spl.h>
  14. #include <asm/arch/clock.h>
  15. #include <asm/arch/sys_proto.h>
  16. #include <asm/arch/mux.h>
  17. #include <asm/arch/ddr_defs.h>
  18. #include <asm/arch/gpio.h>
  19. #include <asm/emif.h>
  20. #include "board.h"
  21. DECLARE_GLOBAL_DATA_PTR;
  22. /*
  23. * Read header information from EEPROM into global structure.
  24. */
  25. static int read_eeprom(struct am43xx_board_id *header)
  26. {
  27. /* Check if baseboard eeprom is available */
  28. if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
  29. printf("Could not probe the EEPROM at 0x%x\n",
  30. CONFIG_SYS_I2C_EEPROM_ADDR);
  31. return -ENODEV;
  32. }
  33. /* read the eeprom using i2c */
  34. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
  35. sizeof(struct am43xx_board_id))) {
  36. printf("Could not read the EEPROM\n");
  37. return -EIO;
  38. }
  39. if (header->magic != 0xEE3355AA) {
  40. /*
  41. * read the eeprom using i2c again,
  42. * but use only a 1 byte address
  43. */
  44. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
  45. sizeof(struct am43xx_board_id))) {
  46. printf("Could not read the EEPROM at 0x%x\n",
  47. CONFIG_SYS_I2C_EEPROM_ADDR);
  48. return -EIO;
  49. }
  50. if (header->magic != 0xEE3355AA) {
  51. printf("Incorrect magic number (0x%x) in EEPROM\n",
  52. header->magic);
  53. return -EINVAL;
  54. }
  55. }
  56. strncpy(am43xx_board_name, (char *)header->name, sizeof(header->name));
  57. am43xx_board_name[sizeof(header->name)] = 0;
  58. return 0;
  59. }
  60. #ifdef CONFIG_SPL_BUILD
  61. #define NUM_OPPS 6
  62. const struct dpll_params dpll_mpu[NUM_CRYSTAL_FREQ][NUM_OPPS] = {
  63. { /* 19.2 MHz */
  64. {-1, -1, -1, -1, -1, -1, -1}, /* OPP 50 */
  65. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  66. {-1, -1, -1, -1, -1, -1, -1}, /* OPP 100 */
  67. {-1, -1, -1, -1, -1, -1, -1}, /* OPP 120 */
  68. {-1, -1, -1, -1, -1, -1, -1}, /* OPP TB */
  69. {-1, -1, -1, -1, -1, -1, -1} /* OPP NT */
  70. },
  71. { /* 24 MHz */
  72. {300, 23, 1, -1, -1, -1, -1}, /* OPP 50 */
  73. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  74. {600, 23, 1, -1, -1, -1, -1}, /* OPP 100 */
  75. {720, 23, 1, -1, -1, -1, -1}, /* OPP 120 */
  76. {800, 23, 1, -1, -1, -1, -1}, /* OPP TB */
  77. {1000, 23, 1, -1, -1, -1, -1} /* OPP NT */
  78. },
  79. { /* 25 MHz */
  80. {300, 24, 1, -1, -1, -1, -1}, /* OPP 50 */
  81. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  82. {600, 24, 1, -1, -1, -1, -1}, /* OPP 100 */
  83. {720, 24, 1, -1, -1, -1, -1}, /* OPP 120 */
  84. {800, 24, 1, -1, -1, -1, -1}, /* OPP TB */
  85. {1000, 24, 1, -1, -1, -1, -1} /* OPP NT */
  86. },
  87. { /* 26 MHz */
  88. {300, 25, 1, -1, -1, -1, -1}, /* OPP 50 */
  89. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  90. {600, 25, 1, -1, -1, -1, -1}, /* OPP 100 */
  91. {720, 25, 1, -1, -1, -1, -1}, /* OPP 120 */
  92. {800, 25, 1, -1, -1, -1, -1}, /* OPP TB */
  93. {1000, 25, 1, -1, -1, -1, -1} /* OPP NT */
  94. },
  95. };
  96. const struct dpll_params dpll_core[NUM_CRYSTAL_FREQ] = {
  97. {-1, -1, -1, -1, -1, -1, -1}, /* 19.2 MHz */
  98. {1000, 23, -1, -1, 10, 8, 4}, /* 24 MHz */
  99. {1000, 24, -1, -1, 10, 8, 4}, /* 25 MHz */
  100. {1000, 25, -1, -1, 10, 8, 4} /* 26 MHz */
  101. };
  102. const struct dpll_params dpll_per[NUM_CRYSTAL_FREQ] = {
  103. {-1, -1, -1, -1, -1, -1, -1}, /* 19.2 MHz */
  104. {960, 23, 5, -1, -1, -1, -1}, /* 24 MHz */
  105. {960, 24, 5, -1, -1, -1, -1}, /* 25 MHz */
  106. {960, 25, 5, -1, -1, -1, -1} /* 26 MHz */
  107. };
  108. const struct dpll_params epos_evm_dpll_ddr = {
  109. 266, 24, 1, -1, 1, -1, -1};
  110. const struct dpll_params gp_evm_dpll_ddr = {
  111. 400, 23, 1, -1, 1, -1, -1};
  112. const struct ctrl_ioregs ioregs_lpddr2 = {
  113. .cm0ioctl = LPDDR2_ADDRCTRL_IOCTRL_VALUE,
  114. .cm1ioctl = LPDDR2_ADDRCTRL_WD0_IOCTRL_VALUE,
  115. .cm2ioctl = LPDDR2_ADDRCTRL_WD1_IOCTRL_VALUE,
  116. .dt0ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
  117. .dt1ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
  118. .dt2ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
  119. .dt3ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
  120. .emif_sdram_config_ext = 0x1,
  121. };
  122. const struct emif_regs emif_regs_lpddr2 = {
  123. .sdram_config = 0x808012BA,
  124. .ref_ctrl = 0x0000040D,
  125. .sdram_tim1 = 0xEA86B411,
  126. .sdram_tim2 = 0x103A094A,
  127. .sdram_tim3 = 0x0F6BA37F,
  128. .read_idle_ctrl = 0x00050000,
  129. .zq_config = 0x50074BE4,
  130. .temp_alert_config = 0x0,
  131. .emif_rd_wr_lvl_rmp_win = 0x0,
  132. .emif_rd_wr_lvl_rmp_ctl = 0x0,
  133. .emif_rd_wr_lvl_ctl = 0x0,
  134. .emif_ddr_phy_ctlr_1 = 0x0E084006,
  135. .emif_rd_wr_exec_thresh = 0x00000405,
  136. .emif_ddr_ext_phy_ctrl_1 = 0x04010040,
  137. .emif_ddr_ext_phy_ctrl_2 = 0x00500050,
  138. .emif_ddr_ext_phy_ctrl_3 = 0x00500050,
  139. .emif_ddr_ext_phy_ctrl_4 = 0x00500050,
  140. .emif_ddr_ext_phy_ctrl_5 = 0x00500050
  141. };
  142. const u32 ext_phy_ctrl_const_base_lpddr2[] = {
  143. 0x00500050,
  144. 0x00350035,
  145. 0x00350035,
  146. 0x00350035,
  147. 0x00350035,
  148. 0x00350035,
  149. 0x00000000,
  150. 0x00000000,
  151. 0x00000000,
  152. 0x00000000,
  153. 0x00000000,
  154. 0x00000000,
  155. 0x00000000,
  156. 0x00000000,
  157. 0x00000000,
  158. 0x00000000,
  159. 0x00000000,
  160. 0x00000000,
  161. 0x40001000,
  162. 0x08102040
  163. };
  164. const struct ctrl_ioregs ioregs_ddr3 = {
  165. .cm0ioctl = DDR3_ADDRCTRL_IOCTRL_VALUE,
  166. .cm1ioctl = DDR3_ADDRCTRL_WD0_IOCTRL_VALUE,
  167. .cm2ioctl = DDR3_ADDRCTRL_WD1_IOCTRL_VALUE,
  168. .dt0ioctl = DDR3_DATA0_IOCTRL_VALUE,
  169. .dt1ioctl = DDR3_DATA0_IOCTRL_VALUE,
  170. .dt2ioctrl = DDR3_DATA0_IOCTRL_VALUE,
  171. .dt3ioctrl = DDR3_DATA0_IOCTRL_VALUE,
  172. .emif_sdram_config_ext = 0x0143,
  173. };
  174. const struct emif_regs ddr3_emif_regs_400Mhz = {
  175. .sdram_config = 0x638413B2,
  176. .ref_ctrl = 0x00000C30,
  177. .sdram_tim1 = 0xEAAAD4DB,
  178. .sdram_tim2 = 0x266B7FDA,
  179. .sdram_tim3 = 0x107F8678,
  180. .read_idle_ctrl = 0x00050000,
  181. .zq_config = 0x50074BE4,
  182. .temp_alert_config = 0x0,
  183. .emif_ddr_phy_ctlr_1 = 0x0E084008,
  184. .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
  185. .emif_ddr_ext_phy_ctrl_2 = 0x00400040,
  186. .emif_ddr_ext_phy_ctrl_3 = 0x00400040,
  187. .emif_ddr_ext_phy_ctrl_4 = 0x00400040,
  188. .emif_ddr_ext_phy_ctrl_5 = 0x00400040,
  189. .emif_rd_wr_lvl_rmp_win = 0x0,
  190. .emif_rd_wr_lvl_rmp_ctl = 0x0,
  191. .emif_rd_wr_lvl_ctl = 0x0,
  192. .emif_rd_wr_exec_thresh = 0x00000405
  193. };
  194. const u32 ext_phy_ctrl_const_base_ddr3[] = {
  195. 0x00400040,
  196. 0x00350035,
  197. 0x00350035,
  198. 0x00350035,
  199. 0x00350035,
  200. 0x00350035,
  201. 0x00000000,
  202. 0x00000000,
  203. 0x00000000,
  204. 0x00000000,
  205. 0x00000000,
  206. 0x00340034,
  207. 0x00340034,
  208. 0x00340034,
  209. 0x00340034,
  210. 0x00340034,
  211. 0x0,
  212. 0x0,
  213. 0x40000000,
  214. 0x08102040
  215. };
  216. void emif_get_ext_phy_ctrl_const_regs(const u32 **regs, u32 *size)
  217. {
  218. if (board_is_eposevm()) {
  219. *regs = ext_phy_ctrl_const_base_lpddr2;
  220. *size = ARRAY_SIZE(ext_phy_ctrl_const_base_lpddr2);
  221. } else if (board_is_gpevm()) {
  222. *regs = ext_phy_ctrl_const_base_ddr3;
  223. *size = ARRAY_SIZE(ext_phy_ctrl_const_base_ddr3);
  224. }
  225. return;
  226. }
  227. const struct dpll_params *get_dpll_ddr_params(void)
  228. {
  229. struct am43xx_board_id header;
  230. enable_i2c0_pin_mux();
  231. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  232. if (read_eeprom(&header) < 0)
  233. puts("Could not get board ID.\n");
  234. if (board_is_eposevm())
  235. return &epos_evm_dpll_ddr;
  236. else if (board_is_gpevm())
  237. return &gp_evm_dpll_ddr;
  238. puts(" Board not supported\n");
  239. return NULL;
  240. }
  241. /*
  242. * get_sys_clk_index : returns the index of the sys_clk read from
  243. * ctrl status register. This value is either
  244. * read from efuse or sysboot pins.
  245. */
  246. static u32 get_sys_clk_index(void)
  247. {
  248. struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
  249. u32 ind = readl(&ctrl->statusreg), src;
  250. src = (ind & CTRL_CRYSTAL_FREQ_SRC_MASK) >> CTRL_CRYSTAL_FREQ_SRC_SHIFT;
  251. if (src == CTRL_CRYSTAL_FREQ_SRC_EFUSE) /* Value read from EFUSE */
  252. return ((ind & CTRL_CRYSTAL_FREQ_SELECTION_MASK) >>
  253. CTRL_CRYSTAL_FREQ_SELECTION_SHIFT);
  254. else /* Value read from SYS BOOT pins */
  255. return ((ind & CTRL_SYSBOOT_15_14_MASK) >>
  256. CTRL_SYSBOOT_15_14_SHIFT);
  257. }
  258. /*
  259. * get_opp_offset:
  260. * Returns the index for safest OPP of the device to boot.
  261. * max_off: Index of the MAX OPP in DEV ATTRIBUTE register.
  262. * min_off: Index of the MIN OPP in DEV ATTRIBUTE register.
  263. * This data is read from dev_attribute register which is e-fused.
  264. * A'1' in bit indicates OPP disabled and not available, a '0' indicates
  265. * OPP available. Lowest OPP starts with min_off. So returning the
  266. * bit with rightmost '0'.
  267. */
  268. static int get_opp_offset(int max_off, int min_off)
  269. {
  270. struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
  271. int opp = readl(&ctrl->dev_attr), offset, i;
  272. for (i = max_off; i >= min_off; i--) {
  273. offset = opp & (1 << i);
  274. if (!offset)
  275. return i;
  276. }
  277. return min_off;
  278. }
  279. const struct dpll_params *get_dpll_mpu_params(void)
  280. {
  281. int opp = get_opp_offset(DEV_ATTR_MAX_OFFSET, DEV_ATTR_MIN_OFFSET);
  282. u32 ind = get_sys_clk_index();
  283. return &dpll_mpu[ind][opp];
  284. }
  285. const struct dpll_params *get_dpll_core_params(void)
  286. {
  287. int ind = get_sys_clk_index();
  288. return &dpll_core[ind];
  289. }
  290. const struct dpll_params *get_dpll_per_params(void)
  291. {
  292. int ind = get_sys_clk_index();
  293. return &dpll_per[ind];
  294. }
  295. void set_uart_mux_conf(void)
  296. {
  297. enable_uart0_pin_mux();
  298. }
  299. void set_mux_conf_regs(void)
  300. {
  301. enable_board_pin_mux();
  302. }
  303. static void enable_vtt_regulator(void)
  304. {
  305. u32 temp;
  306. /* enable module */
  307. writel(GPIO_CTRL_ENABLEMODULE, AM33XX_GPIO5_BASE + OMAP_GPIO_CTRL);
  308. /* enable output for GPIO5_7 */
  309. writel(GPIO_SETDATAOUT(7),
  310. AM33XX_GPIO5_BASE + OMAP_GPIO_SETDATAOUT);
  311. temp = readl(AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
  312. temp = temp & ~(GPIO_OE_ENABLE(7));
  313. writel(temp, AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
  314. }
  315. void sdram_init(void)
  316. {
  317. /*
  318. * EPOS EVM has 1GB LPDDR2 connected to EMIF.
  319. * GP EMV has 1GB DDR3 connected to EMIF
  320. * along with VTT regulator.
  321. */
  322. if (board_is_eposevm()) {
  323. config_ddr(0, &ioregs_lpddr2, NULL, NULL, &emif_regs_lpddr2, 0);
  324. } else if (board_is_gpevm()) {
  325. enable_vtt_regulator();
  326. config_ddr(0, &ioregs_ddr3, NULL, NULL,
  327. &ddr3_emif_regs_400Mhz, 0);
  328. }
  329. }
  330. #endif
  331. int board_init(void)
  332. {
  333. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  334. return 0;
  335. }
  336. #ifdef CONFIG_BOARD_LATE_INIT
  337. int board_late_init(void)
  338. {
  339. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  340. char safe_string[HDR_NAME_LEN + 1];
  341. struct am43xx_board_id header;
  342. if (read_eeprom(&header) < 0)
  343. puts("Could not get board ID.\n");
  344. /* Now set variables based on the header. */
  345. strncpy(safe_string, (char *)header.name, sizeof(header.name));
  346. safe_string[sizeof(header.name)] = 0;
  347. setenv("board_name", safe_string);
  348. strncpy(safe_string, (char *)header.version, sizeof(header.version));
  349. safe_string[sizeof(header.version)] = 0;
  350. setenv("board_rev", safe_string);
  351. #endif
  352. return 0;
  353. }
  354. #endif