board.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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/emif.h>
  19. #include "board.h"
  20. DECLARE_GLOBAL_DATA_PTR;
  21. /*
  22. * Read header information from EEPROM into global structure.
  23. */
  24. static int read_eeprom(struct am43xx_board_id *header)
  25. {
  26. /* Check if baseboard eeprom is available */
  27. if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR)) {
  28. printf("Could not probe the EEPROM at 0x%x\n",
  29. CONFIG_SYS_I2C_EEPROM_ADDR);
  30. return -ENODEV;
  31. }
  32. /* read the eeprom using i2c */
  33. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
  34. sizeof(struct am43xx_board_id))) {
  35. printf("Could not read the EEPROM\n");
  36. return -EIO;
  37. }
  38. if (header->magic != 0xEE3355AA) {
  39. /*
  40. * read the eeprom using i2c again,
  41. * but use only a 1 byte address
  42. */
  43. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
  44. sizeof(struct am43xx_board_id))) {
  45. printf("Could not read the EEPROM at 0x%x\n",
  46. CONFIG_SYS_I2C_EEPROM_ADDR);
  47. return -EIO;
  48. }
  49. if (header->magic != 0xEE3355AA) {
  50. printf("Incorrect magic number (0x%x) in EEPROM\n",
  51. header->magic);
  52. return -EINVAL;
  53. }
  54. }
  55. strncpy(am43xx_board_name, (char *)header->name, sizeof(header->name));
  56. am43xx_board_name[sizeof(header->name)] = 0;
  57. return 0;
  58. }
  59. #ifdef CONFIG_SPL_BUILD
  60. #define NUM_OPPS 6
  61. const struct dpll_params dpll_mpu[NUM_CRYSTAL_FREQ][NUM_OPPS] = {
  62. { /* 19.2 MHz */
  63. {-1, -1, -1, -1, -1, -1, -1}, /* OPP 50 */
  64. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  65. {-1, -1, -1, -1, -1, -1, -1}, /* OPP 100 */
  66. {-1, -1, -1, -1, -1, -1, -1}, /* OPP 120 */
  67. {-1, -1, -1, -1, -1, -1, -1}, /* OPP TB */
  68. {-1, -1, -1, -1, -1, -1, -1} /* OPP NT */
  69. },
  70. { /* 24 MHz */
  71. {300, 23, 1, -1, -1, -1, -1}, /* OPP 50 */
  72. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  73. {600, 23, 1, -1, -1, -1, -1}, /* OPP 100 */
  74. {720, 23, 1, -1, -1, -1, -1}, /* OPP 120 */
  75. {800, 23, 1, -1, -1, -1, -1}, /* OPP TB */
  76. {1000, 23, 1, -1, -1, -1, -1} /* OPP NT */
  77. },
  78. { /* 25 MHz */
  79. {300, 24, 1, -1, -1, -1, -1}, /* OPP 50 */
  80. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  81. {600, 24, 1, -1, -1, -1, -1}, /* OPP 100 */
  82. {720, 24, 1, -1, -1, -1, -1}, /* OPP 120 */
  83. {800, 24, 1, -1, -1, -1, -1}, /* OPP TB */
  84. {1000, 24, 1, -1, -1, -1, -1} /* OPP NT */
  85. },
  86. { /* 26 MHz */
  87. {300, 25, 1, -1, -1, -1, -1}, /* OPP 50 */
  88. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  89. {600, 25, 1, -1, -1, -1, -1}, /* OPP 100 */
  90. {720, 25, 1, -1, -1, -1, -1}, /* OPP 120 */
  91. {800, 25, 1, -1, -1, -1, -1}, /* OPP TB */
  92. {1000, 25, 1, -1, -1, -1, -1} /* OPP NT */
  93. },
  94. };
  95. const struct dpll_params dpll_core[NUM_CRYSTAL_FREQ] = {
  96. {-1, -1, -1, -1, -1, -1, -1}, /* 19.2 MHz */
  97. {1000, 23, -1, -1, 10, 8, 4}, /* 24 MHz */
  98. {1000, 24, -1, -1, 10, 8, 4}, /* 25 MHz */
  99. {1000, 25, -1, -1, 10, 8, 4} /* 26 MHz */
  100. };
  101. const struct dpll_params dpll_per[NUM_CRYSTAL_FREQ] = {
  102. {-1, -1, -1, -1, -1, -1, -1}, /* 19.2 MHz */
  103. {960, 23, 5, -1, -1, -1, -1}, /* 24 MHz */
  104. {960, 24, 5, -1, -1, -1, -1}, /* 25 MHz */
  105. {960, 25, 5, -1, -1, -1, -1} /* 26 MHz */
  106. };
  107. const struct dpll_params epos_evm_dpll_ddr = {
  108. 266, 24, 1, -1, 1, -1, -1};
  109. const struct dpll_params gp_evm_dpll_ddr = {
  110. 400, 23, 1, -1, 1, -1, -1};
  111. const struct ctrl_ioregs ioregs_lpddr2 = {
  112. .cm0ioctl = LPDDR2_ADDRCTRL_IOCTRL_VALUE,
  113. .cm1ioctl = LPDDR2_ADDRCTRL_WD0_IOCTRL_VALUE,
  114. .cm2ioctl = LPDDR2_ADDRCTRL_WD1_IOCTRL_VALUE,
  115. .dt0ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
  116. .dt1ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
  117. .dt2ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
  118. .dt3ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
  119. .emif_sdram_config_ext = 0x1,
  120. };
  121. const struct emif_regs emif_regs_lpddr2 = {
  122. .sdram_config = 0x808012BA,
  123. .ref_ctrl = 0x0000040D,
  124. .sdram_tim1 = 0xEA86B411,
  125. .sdram_tim2 = 0x103A094A,
  126. .sdram_tim3 = 0x0F6BA37F,
  127. .read_idle_ctrl = 0x00050000,
  128. .zq_config = 0x50074BE4,
  129. .temp_alert_config = 0x0,
  130. .emif_rd_wr_lvl_rmp_win = 0x0,
  131. .emif_rd_wr_lvl_rmp_ctl = 0x0,
  132. .emif_rd_wr_lvl_ctl = 0x0,
  133. .emif_ddr_phy_ctlr_1 = 0x0E084006,
  134. .emif_rd_wr_exec_thresh = 0x00000405,
  135. .emif_ddr_ext_phy_ctrl_1 = 0x04010040,
  136. .emif_ddr_ext_phy_ctrl_2 = 0x00500050,
  137. .emif_ddr_ext_phy_ctrl_3 = 0x00500050,
  138. .emif_ddr_ext_phy_ctrl_4 = 0x00500050,
  139. .emif_ddr_ext_phy_ctrl_5 = 0x00500050
  140. };
  141. const u32 ext_phy_ctrl_const_base_lpddr2[] = {
  142. 0x00500050,
  143. 0x00350035,
  144. 0x00350035,
  145. 0x00350035,
  146. 0x00350035,
  147. 0x00350035,
  148. 0x00000000,
  149. 0x00000000,
  150. 0x00000000,
  151. 0x00000000,
  152. 0x00000000,
  153. 0x00000000,
  154. 0x00000000,
  155. 0x00000000,
  156. 0x00000000,
  157. 0x00000000,
  158. 0x00000000,
  159. 0x00000000,
  160. 0x40001000,
  161. 0x08102040
  162. };
  163. void emif_get_ext_phy_ctrl_const_regs(const u32 **regs, u32 *size)
  164. {
  165. *regs = ext_phy_ctrl_const_base_lpddr2;
  166. *size = ARRAY_SIZE(ext_phy_ctrl_const_base_lpddr2);
  167. return;
  168. }
  169. const struct dpll_params *get_dpll_ddr_params(void)
  170. {
  171. struct am43xx_board_id header;
  172. enable_i2c0_pin_mux();
  173. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  174. if (read_eeprom(&header) < 0)
  175. puts("Could not get board ID.\n");
  176. if (board_is_eposevm())
  177. return &epos_evm_dpll_ddr;
  178. else if (board_is_gpevm())
  179. return &gp_evm_dpll_ddr;
  180. puts(" Board not supported\n");
  181. return NULL;
  182. }
  183. /*
  184. * get_sys_clk_index : returns the index of the sys_clk read from
  185. * ctrl status register. This value is either
  186. * read from efuse or sysboot pins.
  187. */
  188. static u32 get_sys_clk_index(void)
  189. {
  190. struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
  191. u32 ind = readl(&ctrl->statusreg), src;
  192. src = (ind & CTRL_CRYSTAL_FREQ_SRC_MASK) >> CTRL_CRYSTAL_FREQ_SRC_SHIFT;
  193. if (src == CTRL_CRYSTAL_FREQ_SRC_EFUSE) /* Value read from EFUSE */
  194. return ((ind & CTRL_CRYSTAL_FREQ_SELECTION_MASK) >>
  195. CTRL_CRYSTAL_FREQ_SELECTION_SHIFT);
  196. else /* Value read from SYS BOOT pins */
  197. return ((ind & CTRL_SYSBOOT_15_14_MASK) >>
  198. CTRL_SYSBOOT_15_14_SHIFT);
  199. }
  200. /*
  201. * get_opp_offset:
  202. * Returns the index for safest OPP of the device to boot.
  203. * max_off: Index of the MAX OPP in DEV ATTRIBUTE register.
  204. * min_off: Index of the MIN OPP in DEV ATTRIBUTE register.
  205. * This data is read from dev_attribute register which is e-fused.
  206. * A'1' in bit indicates OPP disabled and not available, a '0' indicates
  207. * OPP available. Lowest OPP starts with min_off. So returning the
  208. * bit with rightmost '0'.
  209. */
  210. static int get_opp_offset(int max_off, int min_off)
  211. {
  212. struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
  213. int opp = readl(&ctrl->dev_attr), offset, i;
  214. for (i = max_off; i >= min_off; i--) {
  215. offset = opp & (1 << i);
  216. if (!offset)
  217. return i;
  218. }
  219. return min_off;
  220. }
  221. const struct dpll_params *get_dpll_mpu_params(void)
  222. {
  223. int opp = get_opp_offset(DEV_ATTR_MAX_OFFSET, DEV_ATTR_MIN_OFFSET);
  224. u32 ind = get_sys_clk_index();
  225. return &dpll_mpu[ind][opp];
  226. }
  227. const struct dpll_params *get_dpll_core_params(void)
  228. {
  229. int ind = get_sys_clk_index();
  230. return &dpll_core[ind];
  231. }
  232. const struct dpll_params *get_dpll_per_params(void)
  233. {
  234. int ind = get_sys_clk_index();
  235. return &dpll_per[ind];
  236. }
  237. void set_uart_mux_conf(void)
  238. {
  239. enable_uart0_pin_mux();
  240. }
  241. void set_mux_conf_regs(void)
  242. {
  243. enable_board_pin_mux();
  244. }
  245. void sdram_init(void)
  246. {
  247. config_ddr(0, &ioregs_lpddr2, NULL, NULL, &emif_regs_lpddr2, 0);
  248. }
  249. #endif
  250. int board_init(void)
  251. {
  252. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  253. return 0;
  254. }
  255. #ifdef CONFIG_BOARD_LATE_INIT
  256. int board_late_init(void)
  257. {
  258. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  259. char safe_string[HDR_NAME_LEN + 1];
  260. struct am43xx_board_id header;
  261. if (read_eeprom(&header) < 0)
  262. puts("Could not get board ID.\n");
  263. /* Now set variables based on the header. */
  264. strncpy(safe_string, (char *)header.name, sizeof(header.name));
  265. safe_string[sizeof(header.name)] = 0;
  266. setenv("board_name", safe_string);
  267. strncpy(safe_string, (char *)header.version, sizeof(header.version));
  268. safe_string[sizeof(header.version)] = 0;
  269. setenv("board_rev", safe_string);
  270. #endif
  271. return 0;
  272. }
  273. #endif