board.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * board.c
  4. *
  5. * Board functions for TI AM43XX based boards
  6. *
  7. * Copyright (C) 2013, Texas Instruments, Incorporated - http://www.ti.com/
  8. */
  9. #include <common.h>
  10. #include <environment.h>
  11. #include <i2c.h>
  12. #include <linux/errno.h>
  13. #include <spl.h>
  14. #include <usb.h>
  15. #include <asm/omap_sec_common.h>
  16. #include <asm/arch/clock.h>
  17. #include <asm/arch/sys_proto.h>
  18. #include <asm/arch/mux.h>
  19. #include <asm/arch/ddr_defs.h>
  20. #include <asm/arch/gpio.h>
  21. #include <asm/emif.h>
  22. #include <asm/omap_common.h>
  23. #include "../common/board_detect.h"
  24. #include "board.h"
  25. #include <power/pmic.h>
  26. #include <power/tps65218.h>
  27. #include <power/tps62362.h>
  28. #include <miiphy.h>
  29. #include <cpsw.h>
  30. #include <linux/usb/gadget.h>
  31. #include <dwc3-uboot.h>
  32. #include <dwc3-omap-uboot.h>
  33. #include <ti-usb-phy-uboot.h>
  34. DECLARE_GLOBAL_DATA_PTR;
  35. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  36. /*
  37. * Read header information from EEPROM into global structure.
  38. */
  39. #ifdef CONFIG_TI_I2C_BOARD_DETECT
  40. void do_board_detect(void)
  41. {
  42. if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
  43. CONFIG_EEPROM_CHIP_ADDRESS))
  44. printf("ti_i2c_eeprom_init failed\n");
  45. }
  46. #endif
  47. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  48. const struct dpll_params dpll_mpu[NUM_CRYSTAL_FREQ][NUM_OPPS] = {
  49. { /* 19.2 MHz */
  50. {125, 3, 2, -1, -1, -1, -1}, /* OPP 50 */
  51. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  52. {125, 3, 1, -1, -1, -1, -1}, /* OPP 100 */
  53. {150, 3, 1, -1, -1, -1, -1}, /* OPP 120 */
  54. {125, 2, 1, -1, -1, -1, -1}, /* OPP TB */
  55. {625, 11, 1, -1, -1, -1, -1} /* OPP NT */
  56. },
  57. { /* 24 MHz */
  58. {300, 23, 1, -1, -1, -1, -1}, /* OPP 50 */
  59. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  60. {600, 23, 1, -1, -1, -1, -1}, /* OPP 100 */
  61. {720, 23, 1, -1, -1, -1, -1}, /* OPP 120 */
  62. {800, 23, 1, -1, -1, -1, -1}, /* OPP TB */
  63. {1000, 23, 1, -1, -1, -1, -1} /* OPP NT */
  64. },
  65. { /* 25 MHz */
  66. {300, 24, 1, -1, -1, -1, -1}, /* OPP 50 */
  67. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  68. {600, 24, 1, -1, -1, -1, -1}, /* OPP 100 */
  69. {720, 24, 1, -1, -1, -1, -1}, /* OPP 120 */
  70. {800, 24, 1, -1, -1, -1, -1}, /* OPP TB */
  71. {1000, 24, 1, -1, -1, -1, -1} /* OPP NT */
  72. },
  73. { /* 26 MHz */
  74. {300, 25, 1, -1, -1, -1, -1}, /* OPP 50 */
  75. {-1, -1, -1, -1, -1, -1, -1}, /* OPP RESERVED */
  76. {600, 25, 1, -1, -1, -1, -1}, /* OPP 100 */
  77. {720, 25, 1, -1, -1, -1, -1}, /* OPP 120 */
  78. {800, 25, 1, -1, -1, -1, -1}, /* OPP TB */
  79. {1000, 25, 1, -1, -1, -1, -1} /* OPP NT */
  80. },
  81. };
  82. const struct dpll_params dpll_core[NUM_CRYSTAL_FREQ] = {
  83. {625, 11, -1, -1, 10, 8, 4}, /* 19.2 MHz */
  84. {1000, 23, -1, -1, 10, 8, 4}, /* 24 MHz */
  85. {1000, 24, -1, -1, 10, 8, 4}, /* 25 MHz */
  86. {1000, 25, -1, -1, 10, 8, 4} /* 26 MHz */
  87. };
  88. const struct dpll_params dpll_per[NUM_CRYSTAL_FREQ] = {
  89. {400, 7, 5, -1, -1, -1, -1}, /* 19.2 MHz */
  90. {400, 9, 5, -1, -1, -1, -1}, /* 24 MHz */
  91. {384, 9, 5, -1, -1, -1, -1}, /* 25 MHz */
  92. {480, 12, 5, -1, -1, -1, -1} /* 26 MHz */
  93. };
  94. const struct dpll_params epos_evm_dpll_ddr[NUM_CRYSTAL_FREQ] = {
  95. {665, 47, 1, -1, 4, -1, -1}, /*19.2*/
  96. {133, 11, 1, -1, 4, -1, -1}, /* 24 MHz */
  97. {266, 24, 1, -1, 4, -1, -1}, /* 25 MHz */
  98. {133, 12, 1, -1, 4, -1, -1} /* 26 MHz */
  99. };
  100. const struct dpll_params gp_evm_dpll_ddr = {
  101. 50, 2, 1, -1, 2, -1, -1};
  102. static const struct dpll_params idk_dpll_ddr = {
  103. 400, 23, 1, -1, 2, -1, -1
  104. };
  105. static const u32 ext_phy_ctrl_const_base_lpddr2[] = {
  106. 0x00500050,
  107. 0x00350035,
  108. 0x00350035,
  109. 0x00350035,
  110. 0x00350035,
  111. 0x00350035,
  112. 0x00000000,
  113. 0x00000000,
  114. 0x00000000,
  115. 0x00000000,
  116. 0x00000000,
  117. 0x00000000,
  118. 0x00000000,
  119. 0x00000000,
  120. 0x00000000,
  121. 0x00000000,
  122. 0x00000000,
  123. 0x00000000,
  124. 0x40001000,
  125. 0x08102040
  126. };
  127. const struct ctrl_ioregs ioregs_lpddr2 = {
  128. .cm0ioctl = LPDDR2_ADDRCTRL_IOCTRL_VALUE,
  129. .cm1ioctl = LPDDR2_ADDRCTRL_WD0_IOCTRL_VALUE,
  130. .cm2ioctl = LPDDR2_ADDRCTRL_WD1_IOCTRL_VALUE,
  131. .dt0ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
  132. .dt1ioctl = LPDDR2_DATA0_IOCTRL_VALUE,
  133. .dt2ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
  134. .dt3ioctrl = LPDDR2_DATA0_IOCTRL_VALUE,
  135. .emif_sdram_config_ext = 0x1,
  136. };
  137. const struct emif_regs emif_regs_lpddr2 = {
  138. .sdram_config = 0x808012BA,
  139. .ref_ctrl = 0x0000040D,
  140. .sdram_tim1 = 0xEA86B411,
  141. .sdram_tim2 = 0x103A094A,
  142. .sdram_tim3 = 0x0F6BA37F,
  143. .read_idle_ctrl = 0x00050000,
  144. .zq_config = 0x50074BE4,
  145. .temp_alert_config = 0x0,
  146. .emif_rd_wr_lvl_rmp_win = 0x0,
  147. .emif_rd_wr_lvl_rmp_ctl = 0x0,
  148. .emif_rd_wr_lvl_ctl = 0x0,
  149. .emif_ddr_phy_ctlr_1 = 0x0E284006,
  150. .emif_rd_wr_exec_thresh = 0x80000405,
  151. .emif_ddr_ext_phy_ctrl_1 = 0x04010040,
  152. .emif_ddr_ext_phy_ctrl_2 = 0x00500050,
  153. .emif_ddr_ext_phy_ctrl_3 = 0x00500050,
  154. .emif_ddr_ext_phy_ctrl_4 = 0x00500050,
  155. .emif_ddr_ext_phy_ctrl_5 = 0x00500050,
  156. .emif_prio_class_serv_map = 0x80000001,
  157. .emif_connect_id_serv_1_map = 0x80000094,
  158. .emif_connect_id_serv_2_map = 0x00000000,
  159. .emif_cos_config = 0x000FFFFF
  160. };
  161. const struct ctrl_ioregs ioregs_ddr3 = {
  162. .cm0ioctl = DDR3_ADDRCTRL_IOCTRL_VALUE,
  163. .cm1ioctl = DDR3_ADDRCTRL_WD0_IOCTRL_VALUE,
  164. .cm2ioctl = DDR3_ADDRCTRL_WD1_IOCTRL_VALUE,
  165. .dt0ioctl = DDR3_DATA0_IOCTRL_VALUE,
  166. .dt1ioctl = DDR3_DATA0_IOCTRL_VALUE,
  167. .dt2ioctrl = DDR3_DATA0_IOCTRL_VALUE,
  168. .dt3ioctrl = DDR3_DATA0_IOCTRL_VALUE,
  169. .emif_sdram_config_ext = 0xc163,
  170. };
  171. const struct emif_regs ddr3_emif_regs_400Mhz = {
  172. .sdram_config = 0x638413B2,
  173. .ref_ctrl = 0x00000C30,
  174. .sdram_tim1 = 0xEAAAD4DB,
  175. .sdram_tim2 = 0x266B7FDA,
  176. .sdram_tim3 = 0x107F8678,
  177. .read_idle_ctrl = 0x00050000,
  178. .zq_config = 0x50074BE4,
  179. .temp_alert_config = 0x0,
  180. .emif_ddr_phy_ctlr_1 = 0x0E004008,
  181. .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
  182. .emif_ddr_ext_phy_ctrl_2 = 0x00400040,
  183. .emif_ddr_ext_phy_ctrl_3 = 0x00400040,
  184. .emif_ddr_ext_phy_ctrl_4 = 0x00400040,
  185. .emif_ddr_ext_phy_ctrl_5 = 0x00400040,
  186. .emif_rd_wr_lvl_rmp_win = 0x0,
  187. .emif_rd_wr_lvl_rmp_ctl = 0x0,
  188. .emif_rd_wr_lvl_ctl = 0x0,
  189. .emif_rd_wr_exec_thresh = 0x80000405,
  190. .emif_prio_class_serv_map = 0x80000001,
  191. .emif_connect_id_serv_1_map = 0x80000094,
  192. .emif_connect_id_serv_2_map = 0x00000000,
  193. .emif_cos_config = 0x000FFFFF
  194. };
  195. /* EMIF DDR3 Configurations are different for beta AM43X GP EVMs */
  196. const struct emif_regs ddr3_emif_regs_400Mhz_beta = {
  197. .sdram_config = 0x638413B2,
  198. .ref_ctrl = 0x00000C30,
  199. .sdram_tim1 = 0xEAAAD4DB,
  200. .sdram_tim2 = 0x266B7FDA,
  201. .sdram_tim3 = 0x107F8678,
  202. .read_idle_ctrl = 0x00050000,
  203. .zq_config = 0x50074BE4,
  204. .temp_alert_config = 0x0,
  205. .emif_ddr_phy_ctlr_1 = 0x0E004008,
  206. .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
  207. .emif_ddr_ext_phy_ctrl_2 = 0x00000065,
  208. .emif_ddr_ext_phy_ctrl_3 = 0x00000091,
  209. .emif_ddr_ext_phy_ctrl_4 = 0x000000B5,
  210. .emif_ddr_ext_phy_ctrl_5 = 0x000000E5,
  211. .emif_rd_wr_exec_thresh = 0x80000405,
  212. .emif_prio_class_serv_map = 0x80000001,
  213. .emif_connect_id_serv_1_map = 0x80000094,
  214. .emif_connect_id_serv_2_map = 0x00000000,
  215. .emif_cos_config = 0x000FFFFF
  216. };
  217. /* EMIF DDR3 Configurations are different for production AM43X GP EVMs */
  218. const struct emif_regs ddr3_emif_regs_400Mhz_production = {
  219. .sdram_config = 0x638413B2,
  220. .ref_ctrl = 0x00000C30,
  221. .sdram_tim1 = 0xEAAAD4DB,
  222. .sdram_tim2 = 0x266B7FDA,
  223. .sdram_tim3 = 0x107F8678,
  224. .read_idle_ctrl = 0x00050000,
  225. .zq_config = 0x50074BE4,
  226. .temp_alert_config = 0x0,
  227. .emif_ddr_phy_ctlr_1 = 0x0E004008,
  228. .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
  229. .emif_ddr_ext_phy_ctrl_2 = 0x00000066,
  230. .emif_ddr_ext_phy_ctrl_3 = 0x00000091,
  231. .emif_ddr_ext_phy_ctrl_4 = 0x000000B9,
  232. .emif_ddr_ext_phy_ctrl_5 = 0x000000E6,
  233. .emif_rd_wr_exec_thresh = 0x80000405,
  234. .emif_prio_class_serv_map = 0x80000001,
  235. .emif_connect_id_serv_1_map = 0x80000094,
  236. .emif_connect_id_serv_2_map = 0x00000000,
  237. .emif_cos_config = 0x000FFFFF
  238. };
  239. static const struct emif_regs ddr3_sk_emif_regs_400Mhz = {
  240. .sdram_config = 0x638413b2,
  241. .sdram_config2 = 0x00000000,
  242. .ref_ctrl = 0x00000c30,
  243. .sdram_tim1 = 0xeaaad4db,
  244. .sdram_tim2 = 0x266b7fda,
  245. .sdram_tim3 = 0x107f8678,
  246. .read_idle_ctrl = 0x00050000,
  247. .zq_config = 0x50074be4,
  248. .temp_alert_config = 0x0,
  249. .emif_ddr_phy_ctlr_1 = 0x0e084008,
  250. .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
  251. .emif_ddr_ext_phy_ctrl_2 = 0x89,
  252. .emif_ddr_ext_phy_ctrl_3 = 0x90,
  253. .emif_ddr_ext_phy_ctrl_4 = 0x8e,
  254. .emif_ddr_ext_phy_ctrl_5 = 0x8d,
  255. .emif_rd_wr_lvl_rmp_win = 0x0,
  256. .emif_rd_wr_lvl_rmp_ctl = 0x00000000,
  257. .emif_rd_wr_lvl_ctl = 0x00000000,
  258. .emif_rd_wr_exec_thresh = 0x80000000,
  259. .emif_prio_class_serv_map = 0x80000001,
  260. .emif_connect_id_serv_1_map = 0x80000094,
  261. .emif_connect_id_serv_2_map = 0x00000000,
  262. .emif_cos_config = 0x000FFFFF
  263. };
  264. static const struct emif_regs ddr3_idk_emif_regs_400Mhz = {
  265. .sdram_config = 0x61a11b32,
  266. .sdram_config2 = 0x00000000,
  267. .ref_ctrl = 0x00000c30,
  268. .sdram_tim1 = 0xeaaad4db,
  269. .sdram_tim2 = 0x266b7fda,
  270. .sdram_tim3 = 0x107f8678,
  271. .read_idle_ctrl = 0x00050000,
  272. .zq_config = 0x50074be4,
  273. .temp_alert_config = 0x00000000,
  274. .emif_ddr_phy_ctlr_1 = 0x00008009,
  275. .emif_ddr_ext_phy_ctrl_1 = 0x08020080,
  276. .emif_ddr_ext_phy_ctrl_2 = 0x00000040,
  277. .emif_ddr_ext_phy_ctrl_3 = 0x0000003e,
  278. .emif_ddr_ext_phy_ctrl_4 = 0x00000051,
  279. .emif_ddr_ext_phy_ctrl_5 = 0x00000051,
  280. .emif_rd_wr_lvl_rmp_win = 0x00000000,
  281. .emif_rd_wr_lvl_rmp_ctl = 0x00000000,
  282. .emif_rd_wr_lvl_ctl = 0x00000000,
  283. .emif_rd_wr_exec_thresh = 0x00000405,
  284. .emif_prio_class_serv_map = 0x00000000,
  285. .emif_connect_id_serv_1_map = 0x00000000,
  286. .emif_connect_id_serv_2_map = 0x00000000,
  287. .emif_cos_config = 0x00ffffff
  288. };
  289. void emif_get_ext_phy_ctrl_const_regs(const u32 **regs, u32 *size)
  290. {
  291. if (board_is_eposevm()) {
  292. *regs = ext_phy_ctrl_const_base_lpddr2;
  293. *size = ARRAY_SIZE(ext_phy_ctrl_const_base_lpddr2);
  294. }
  295. return;
  296. }
  297. const struct dpll_params *get_dpll_ddr_params(void)
  298. {
  299. int ind = get_sys_clk_index();
  300. if (board_is_eposevm())
  301. return &epos_evm_dpll_ddr[ind];
  302. else if (board_is_evm() || board_is_sk())
  303. return &gp_evm_dpll_ddr;
  304. else if (board_is_idk())
  305. return &idk_dpll_ddr;
  306. printf(" Board '%s' not supported\n", board_ti_get_name());
  307. return NULL;
  308. }
  309. /*
  310. * get_opp_offset:
  311. * Returns the index for safest OPP of the device to boot.
  312. * max_off: Index of the MAX OPP in DEV ATTRIBUTE register.
  313. * min_off: Index of the MIN OPP in DEV ATTRIBUTE register.
  314. * This data is read from dev_attribute register which is e-fused.
  315. * A'1' in bit indicates OPP disabled and not available, a '0' indicates
  316. * OPP available. Lowest OPP starts with min_off. So returning the
  317. * bit with rightmost '0'.
  318. */
  319. static int get_opp_offset(int max_off, int min_off)
  320. {
  321. struct ctrl_stat *ctrl = (struct ctrl_stat *)CTRL_BASE;
  322. int opp, offset, i;
  323. /* Bits 0:11 are defined to be the MPU_MAX_FREQ */
  324. opp = readl(&ctrl->dev_attr) & ~0xFFFFF000;
  325. for (i = max_off; i >= min_off; i--) {
  326. offset = opp & (1 << i);
  327. if (!offset)
  328. return i;
  329. }
  330. return min_off;
  331. }
  332. const struct dpll_params *get_dpll_mpu_params(void)
  333. {
  334. int opp = get_opp_offset(DEV_ATTR_MAX_OFFSET, DEV_ATTR_MIN_OFFSET);
  335. u32 ind = get_sys_clk_index();
  336. return &dpll_mpu[ind][opp];
  337. }
  338. const struct dpll_params *get_dpll_core_params(void)
  339. {
  340. int ind = get_sys_clk_index();
  341. return &dpll_core[ind];
  342. }
  343. const struct dpll_params *get_dpll_per_params(void)
  344. {
  345. int ind = get_sys_clk_index();
  346. return &dpll_per[ind];
  347. }
  348. void scale_vcores_generic(u32 m)
  349. {
  350. int mpu_vdd, ddr_volt;
  351. if (i2c_probe(TPS65218_CHIP_PM))
  352. return;
  353. switch (m) {
  354. case 1000:
  355. mpu_vdd = TPS65218_DCDC_VOLT_SEL_1330MV;
  356. break;
  357. case 800:
  358. mpu_vdd = TPS65218_DCDC_VOLT_SEL_1260MV;
  359. break;
  360. case 720:
  361. mpu_vdd = TPS65218_DCDC_VOLT_SEL_1200MV;
  362. break;
  363. case 600:
  364. mpu_vdd = TPS65218_DCDC_VOLT_SEL_1100MV;
  365. break;
  366. case 300:
  367. mpu_vdd = TPS65218_DCDC_VOLT_SEL_0950MV;
  368. break;
  369. default:
  370. puts("Unknown MPU clock, not scaling\n");
  371. return;
  372. }
  373. /* Set DCDC1 (CORE) voltage to 1.1V */
  374. if (tps65218_voltage_update(TPS65218_DCDC1,
  375. TPS65218_DCDC_VOLT_SEL_1100MV)) {
  376. printf("%s failure\n", __func__);
  377. return;
  378. }
  379. /* Set DCDC2 (MPU) voltage */
  380. if (tps65218_voltage_update(TPS65218_DCDC2, mpu_vdd)) {
  381. printf("%s failure\n", __func__);
  382. return;
  383. }
  384. if (board_is_eposevm())
  385. ddr_volt = TPS65218_DCDC3_VOLT_SEL_1200MV;
  386. else
  387. ddr_volt = TPS65218_DCDC3_VOLT_SEL_1350MV;
  388. /* Set DCDC3 (DDR) voltage */
  389. if (tps65218_voltage_update(TPS65218_DCDC3, ddr_volt)) {
  390. printf("%s failure\n", __func__);
  391. return;
  392. }
  393. }
  394. void scale_vcores_idk(u32 m)
  395. {
  396. int mpu_vdd;
  397. if (i2c_probe(TPS62362_I2C_ADDR))
  398. return;
  399. switch (m) {
  400. case 1000:
  401. mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV;
  402. break;
  403. case 800:
  404. mpu_vdd = TPS62362_DCDC_VOLT_SEL_1260MV;
  405. break;
  406. case 720:
  407. mpu_vdd = TPS62362_DCDC_VOLT_SEL_1200MV;
  408. break;
  409. case 600:
  410. mpu_vdd = TPS62362_DCDC_VOLT_SEL_1100MV;
  411. break;
  412. case 300:
  413. mpu_vdd = TPS62362_DCDC_VOLT_SEL_1330MV;
  414. break;
  415. default:
  416. puts("Unknown MPU clock, not scaling\n");
  417. return;
  418. }
  419. /* Set VDD_MPU voltage */
  420. if (tps62362_voltage_update(TPS62362_SET3, mpu_vdd)) {
  421. printf("%s failure\n", __func__);
  422. return;
  423. }
  424. }
  425. void gpi2c_init(void)
  426. {
  427. /* When needed to be invoked prior to BSS initialization */
  428. static bool first_time = true;
  429. if (first_time) {
  430. enable_i2c0_pin_mux();
  431. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
  432. CONFIG_SYS_OMAP24_I2C_SLAVE);
  433. first_time = false;
  434. }
  435. }
  436. void scale_vcores(void)
  437. {
  438. const struct dpll_params *mpu_params;
  439. /* Ensure I2C is initialized for PMIC configuration */
  440. gpi2c_init();
  441. /* Get the frequency */
  442. mpu_params = get_dpll_mpu_params();
  443. if (board_is_idk())
  444. scale_vcores_idk(mpu_params->m);
  445. else
  446. scale_vcores_generic(mpu_params->m);
  447. }
  448. void set_uart_mux_conf(void)
  449. {
  450. enable_uart0_pin_mux();
  451. }
  452. void set_mux_conf_regs(void)
  453. {
  454. enable_board_pin_mux();
  455. }
  456. static void enable_vtt_regulator(void)
  457. {
  458. u32 temp;
  459. /* enable module */
  460. writel(GPIO_CTRL_ENABLEMODULE, AM33XX_GPIO5_BASE + OMAP_GPIO_CTRL);
  461. /* enable output for GPIO5_7 */
  462. writel(GPIO_SETDATAOUT(7),
  463. AM33XX_GPIO5_BASE + OMAP_GPIO_SETDATAOUT);
  464. temp = readl(AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
  465. temp = temp & ~(GPIO_OE_ENABLE(7));
  466. writel(temp, AM33XX_GPIO5_BASE + OMAP_GPIO_OE);
  467. }
  468. enum {
  469. RTC_BOARD_EPOS = 1,
  470. RTC_BOARD_EVM14,
  471. RTC_BOARD_EVM12,
  472. RTC_BOARD_GPEVM,
  473. RTC_BOARD_SK,
  474. };
  475. /*
  476. * In the rtc_only+DRR in self-refresh boot path we have the board type info
  477. * in the rtc scratch pad register hence we bypass the costly i2c reads to
  478. * eeprom and directly programthe board name string
  479. */
  480. void rtc_only_update_board_type(u32 btype)
  481. {
  482. const char *name = "";
  483. const char *rev = "1.0";
  484. switch (btype) {
  485. case RTC_BOARD_EPOS:
  486. name = "AM43EPOS";
  487. break;
  488. case RTC_BOARD_EVM14:
  489. name = "AM43__GP";
  490. rev = "1.4";
  491. break;
  492. case RTC_BOARD_EVM12:
  493. name = "AM43__GP";
  494. rev = "1.2";
  495. break;
  496. case RTC_BOARD_GPEVM:
  497. name = "AM43__GP";
  498. break;
  499. case RTC_BOARD_SK:
  500. name = "AM43__SK";
  501. break;
  502. }
  503. ti_i2c_eeprom_am_set(name, rev);
  504. }
  505. u32 rtc_only_get_board_type(void)
  506. {
  507. if (board_is_eposevm())
  508. return RTC_BOARD_EPOS;
  509. else if (board_is_evm_14_or_later())
  510. return RTC_BOARD_EVM14;
  511. else if (board_is_evm_12_or_later())
  512. return RTC_BOARD_EVM12;
  513. else if (board_is_gpevm())
  514. return RTC_BOARD_GPEVM;
  515. else if (board_is_sk())
  516. return RTC_BOARD_SK;
  517. return 0;
  518. }
  519. void sdram_init(void)
  520. {
  521. /*
  522. * EPOS EVM has 1GB LPDDR2 connected to EMIF.
  523. * GP EMV has 1GB DDR3 connected to EMIF
  524. * along with VTT regulator.
  525. */
  526. if (board_is_eposevm()) {
  527. config_ddr(0, &ioregs_lpddr2, NULL, NULL, &emif_regs_lpddr2, 0);
  528. } else if (board_is_evm_14_or_later()) {
  529. enable_vtt_regulator();
  530. config_ddr(0, &ioregs_ddr3, NULL, NULL,
  531. &ddr3_emif_regs_400Mhz_production, 0);
  532. } else if (board_is_evm_12_or_later()) {
  533. enable_vtt_regulator();
  534. config_ddr(0, &ioregs_ddr3, NULL, NULL,
  535. &ddr3_emif_regs_400Mhz_beta, 0);
  536. } else if (board_is_evm()) {
  537. enable_vtt_regulator();
  538. config_ddr(0, &ioregs_ddr3, NULL, NULL,
  539. &ddr3_emif_regs_400Mhz, 0);
  540. } else if (board_is_sk()) {
  541. config_ddr(400, &ioregs_ddr3, NULL, NULL,
  542. &ddr3_sk_emif_regs_400Mhz, 0);
  543. } else if (board_is_idk()) {
  544. config_ddr(400, &ioregs_ddr3, NULL, NULL,
  545. &ddr3_idk_emif_regs_400Mhz, 0);
  546. }
  547. }
  548. #endif
  549. /* setup board specific PMIC */
  550. int power_init_board(void)
  551. {
  552. struct pmic *p;
  553. if (board_is_idk()) {
  554. power_tps62362_init(I2C_PMIC);
  555. p = pmic_get("TPS62362");
  556. if (p && !pmic_probe(p))
  557. puts("PMIC: TPS62362\n");
  558. } else {
  559. power_tps65218_init(I2C_PMIC);
  560. p = pmic_get("TPS65218_PMIC");
  561. if (p && !pmic_probe(p))
  562. puts("PMIC: TPS65218\n");
  563. }
  564. return 0;
  565. }
  566. int board_init(void)
  567. {
  568. struct l3f_cfg_bwlimiter *bwlimiter = (struct l3f_cfg_bwlimiter *)L3F_CFG_BWLIMITER;
  569. u32 mreqprio_0, mreqprio_1, modena_init0_bw_fractional,
  570. modena_init0_bw_integer, modena_init0_watermark_0;
  571. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  572. gpmc_init();
  573. /*
  574. * Call this to initialize *ctrl again
  575. */
  576. hw_data_init();
  577. /* Clear all important bits for DSS errata that may need to be tweaked*/
  578. mreqprio_0 = readl(&cdev->mreqprio_0) & MREQPRIO_0_SAB_INIT1_MASK &
  579. MREQPRIO_0_SAB_INIT0_MASK;
  580. mreqprio_1 = readl(&cdev->mreqprio_1) & MREQPRIO_1_DSS_MASK;
  581. modena_init0_bw_fractional = readl(&bwlimiter->modena_init0_bw_fractional) &
  582. BW_LIMITER_BW_FRAC_MASK;
  583. modena_init0_bw_integer = readl(&bwlimiter->modena_init0_bw_integer) &
  584. BW_LIMITER_BW_INT_MASK;
  585. modena_init0_watermark_0 = readl(&bwlimiter->modena_init0_watermark_0) &
  586. BW_LIMITER_BW_WATERMARK_MASK;
  587. /* Setting MReq Priority of the DSS*/
  588. mreqprio_0 |= 0x77;
  589. /*
  590. * Set L3 Fast Configuration Register
  591. * Limiting bandwith for ARM core to 700 MBPS
  592. */
  593. modena_init0_bw_fractional |= 0x10;
  594. modena_init0_bw_integer |= 0x3;
  595. writel(mreqprio_0, &cdev->mreqprio_0);
  596. writel(mreqprio_1, &cdev->mreqprio_1);
  597. writel(modena_init0_bw_fractional, &bwlimiter->modena_init0_bw_fractional);
  598. writel(modena_init0_bw_integer, &bwlimiter->modena_init0_bw_integer);
  599. writel(modena_init0_watermark_0, &bwlimiter->modena_init0_watermark_0);
  600. return 0;
  601. }
  602. #ifdef CONFIG_BOARD_LATE_INIT
  603. int board_late_init(void)
  604. {
  605. #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
  606. set_board_info_env(NULL);
  607. /*
  608. * Default FIT boot on HS devices. Non FIT images are not allowed
  609. * on HS devices.
  610. */
  611. if (get_device_type() == HS_DEVICE)
  612. env_set("boot_fit", "1");
  613. #endif
  614. return 0;
  615. }
  616. #endif
  617. #ifdef CONFIG_USB_DWC3
  618. static struct dwc3_device usb_otg_ss1 = {
  619. .maximum_speed = USB_SPEED_HIGH,
  620. .base = USB_OTG_SS1_BASE,
  621. .tx_fifo_resize = false,
  622. .index = 0,
  623. };
  624. static struct dwc3_omap_device usb_otg_ss1_glue = {
  625. .base = (void *)USB_OTG_SS1_GLUE_BASE,
  626. .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
  627. .index = 0,
  628. };
  629. static struct ti_usb_phy_device usb_phy1_device = {
  630. .usb2_phy_power = (void *)USB2_PHY1_POWER,
  631. .index = 0,
  632. };
  633. static struct dwc3_device usb_otg_ss2 = {
  634. .maximum_speed = USB_SPEED_HIGH,
  635. .base = USB_OTG_SS2_BASE,
  636. .tx_fifo_resize = false,
  637. .index = 1,
  638. };
  639. static struct dwc3_omap_device usb_otg_ss2_glue = {
  640. .base = (void *)USB_OTG_SS2_GLUE_BASE,
  641. .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
  642. .index = 1,
  643. };
  644. static struct ti_usb_phy_device usb_phy2_device = {
  645. .usb2_phy_power = (void *)USB2_PHY2_POWER,
  646. .index = 1,
  647. };
  648. int usb_gadget_handle_interrupts(int index)
  649. {
  650. u32 status;
  651. status = dwc3_omap_uboot_interrupt_status(index);
  652. if (status)
  653. dwc3_uboot_handle_interrupt(index);
  654. return 0;
  655. }
  656. #endif /* CONFIG_USB_DWC3 */
  657. #if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP)
  658. int board_usb_init(int index, enum usb_init_type init)
  659. {
  660. enable_usb_clocks(index);
  661. #ifdef CONFIG_USB_DWC3
  662. switch (index) {
  663. case 0:
  664. if (init == USB_INIT_DEVICE) {
  665. usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
  666. usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
  667. dwc3_omap_uboot_init(&usb_otg_ss1_glue);
  668. ti_usb_phy_uboot_init(&usb_phy1_device);
  669. dwc3_uboot_init(&usb_otg_ss1);
  670. }
  671. break;
  672. case 1:
  673. if (init == USB_INIT_DEVICE) {
  674. usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
  675. usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
  676. ti_usb_phy_uboot_init(&usb_phy2_device);
  677. dwc3_omap_uboot_init(&usb_otg_ss2_glue);
  678. dwc3_uboot_init(&usb_otg_ss2);
  679. }
  680. break;
  681. default:
  682. printf("Invalid Controller Index\n");
  683. }
  684. #endif
  685. return 0;
  686. }
  687. int board_usb_cleanup(int index, enum usb_init_type init)
  688. {
  689. #ifdef CONFIG_USB_DWC3
  690. switch (index) {
  691. case 0:
  692. case 1:
  693. if (init == USB_INIT_DEVICE) {
  694. ti_usb_phy_uboot_exit(index);
  695. dwc3_uboot_exit(index);
  696. dwc3_omap_uboot_exit(index);
  697. }
  698. break;
  699. default:
  700. printf("Invalid Controller Index\n");
  701. }
  702. #endif
  703. disable_usb_clocks(index);
  704. return 0;
  705. }
  706. #endif /* defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP) */
  707. #ifdef CONFIG_DRIVER_TI_CPSW
  708. static void cpsw_control(int enabled)
  709. {
  710. /* Additional controls can be added here */
  711. return;
  712. }
  713. static struct cpsw_slave_data cpsw_slaves[] = {
  714. {
  715. .slave_reg_ofs = 0x208,
  716. .sliver_reg_ofs = 0xd80,
  717. .phy_addr = 16,
  718. },
  719. {
  720. .slave_reg_ofs = 0x308,
  721. .sliver_reg_ofs = 0xdc0,
  722. .phy_addr = 1,
  723. },
  724. };
  725. static struct cpsw_platform_data cpsw_data = {
  726. .mdio_base = CPSW_MDIO_BASE,
  727. .cpsw_base = CPSW_BASE,
  728. .mdio_div = 0xff,
  729. .channels = 8,
  730. .cpdma_reg_ofs = 0x800,
  731. .slaves = 1,
  732. .slave_data = cpsw_slaves,
  733. .ale_reg_ofs = 0xd00,
  734. .ale_entries = 1024,
  735. .host_port_reg_ofs = 0x108,
  736. .hw_stats_reg_ofs = 0x900,
  737. .bd_ram_ofs = 0x2000,
  738. .mac_control = (1 << 5),
  739. .control = cpsw_control,
  740. .host_port_num = 0,
  741. .version = CPSW_CTRL_VERSION_2,
  742. };
  743. int board_eth_init(bd_t *bis)
  744. {
  745. int rv;
  746. uint8_t mac_addr[6];
  747. uint32_t mac_hi, mac_lo;
  748. /* try reading mac address from efuse */
  749. mac_lo = readl(&cdev->macid0l);
  750. mac_hi = readl(&cdev->macid0h);
  751. mac_addr[0] = mac_hi & 0xFF;
  752. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  753. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  754. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  755. mac_addr[4] = mac_lo & 0xFF;
  756. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  757. if (!env_get("ethaddr")) {
  758. puts("<ethaddr> not set. Validating first E-fuse MAC\n");
  759. if (is_valid_ethaddr(mac_addr))
  760. eth_env_set_enetaddr("ethaddr", mac_addr);
  761. }
  762. mac_lo = readl(&cdev->macid1l);
  763. mac_hi = readl(&cdev->macid1h);
  764. mac_addr[0] = mac_hi & 0xFF;
  765. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  766. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  767. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  768. mac_addr[4] = mac_lo & 0xFF;
  769. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  770. if (!env_get("eth1addr")) {
  771. if (is_valid_ethaddr(mac_addr))
  772. eth_env_set_enetaddr("eth1addr", mac_addr);
  773. }
  774. if (board_is_eposevm()) {
  775. writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
  776. cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
  777. cpsw_slaves[0].phy_addr = 16;
  778. } else if (board_is_sk()) {
  779. writel(RGMII_MODE_ENABLE, &cdev->miisel);
  780. cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
  781. cpsw_slaves[0].phy_addr = 4;
  782. cpsw_slaves[1].phy_addr = 5;
  783. } else if (board_is_idk()) {
  784. writel(RGMII_MODE_ENABLE, &cdev->miisel);
  785. cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
  786. cpsw_slaves[0].phy_addr = 0;
  787. } else {
  788. writel(RGMII_MODE_ENABLE, &cdev->miisel);
  789. cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RGMII;
  790. cpsw_slaves[0].phy_addr = 0;
  791. }
  792. rv = cpsw_register(&cpsw_data);
  793. if (rv < 0)
  794. printf("Error %d registering CPSW switch\n", rv);
  795. return rv;
  796. }
  797. #endif
  798. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  799. int ft_board_setup(void *blob, bd_t *bd)
  800. {
  801. ft_cpu_setup(blob, bd);
  802. return 0;
  803. }
  804. #endif
  805. #if defined(CONFIG_SPL_LOAD_FIT) || defined(CONFIG_DTB_RESELECT)
  806. int board_fit_config_name_match(const char *name)
  807. {
  808. bool eeprom_read = board_ti_was_eeprom_read();
  809. if (!strcmp(name, "am4372-generic") && !eeprom_read)
  810. return 0;
  811. else if (board_is_evm() && !strcmp(name, "am437x-gp-evm"))
  812. return 0;
  813. else if (board_is_sk() && !strcmp(name, "am437x-sk-evm"))
  814. return 0;
  815. else if (board_is_eposevm() && !strcmp(name, "am43x-epos-evm"))
  816. return 0;
  817. else if (board_is_idk() && !strcmp(name, "am437x-idk-evm"))
  818. return 0;
  819. else
  820. return -1;
  821. }
  822. #endif
  823. #ifdef CONFIG_DTB_RESELECT
  824. int embedded_dtb_select(void)
  825. {
  826. do_board_detect();
  827. fdtdec_setup();
  828. return 0;
  829. }
  830. #endif
  831. #ifdef CONFIG_TI_SECURE_DEVICE
  832. void board_fit_image_post_process(void **p_image, size_t *p_size)
  833. {
  834. secure_boot_verify_image(p_image, p_size);
  835. }
  836. void board_tee_image_process(ulong tee_image, size_t tee_size)
  837. {
  838. secure_tee_install((u32)tee_image);
  839. }
  840. U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
  841. #endif