common.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * common.c
  4. *
  5. * common board functions for B&R boards
  6. *
  7. * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
  8. * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
  9. *
  10. */
  11. #include <version.h>
  12. #include <common.h>
  13. #include <environment.h>
  14. #include <errno.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/hardware.h>
  17. #include <asm/arch/omap.h>
  18. #include <asm/arch/clock.h>
  19. #include <asm/arch/gpio.h>
  20. #include <asm/arch/sys_proto.h>
  21. #include <asm/arch/mmc_host_def.h>
  22. #include <asm/io.h>
  23. #include <asm/gpio.h>
  24. #include <i2c.h>
  25. #include <miiphy.h>
  26. #include <cpsw.h>
  27. #include <power/tps65217.h>
  28. #include <lcd.h>
  29. #include <fs.h>
  30. #ifdef CONFIG_USE_FDT
  31. #include <fdt_support.h>
  32. #endif
  33. #include "bur_common.h"
  34. #include "../../../drivers/video/am335x-fb.h"
  35. #include <nand.h>
  36. #include <fdt_simplefb.h>
  37. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  38. DECLARE_GLOBAL_DATA_PTR;
  39. #ifdef CONFIG_USE_FDT
  40. #define FDTPROP(b, c) fdt_getprop_u32_default(gd->fdt_blob, b, c, ~0UL)
  41. #define PATHTIM "/panel/display-timings/default"
  42. #define PATHINF "/panel/panel-info"
  43. #endif
  44. /* --------------------------------------------------------------------------*/
  45. #if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \
  46. !defined(CONFIG_SPL_BUILD)
  47. void lcdbacklight(int on)
  48. {
  49. #ifdef CONFIG_USE_FDT
  50. if (gd->fdt_blob == NULL) {
  51. printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
  52. return;
  53. }
  54. unsigned int driver = FDTPROP(PATHINF, "brightdrv");
  55. unsigned int bright = FDTPROP(PATHINF, "brightdef");
  56. unsigned int pwmfrq = FDTPROP(PATHINF, "brightfdim");
  57. #else
  58. unsigned int driver = env_get_ulong("ds1_bright_drv", 16, 0UL);
  59. unsigned int bright = env_get_ulong("ds1_bright_def", 10, 50);
  60. unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL);
  61. #endif
  62. unsigned int tmp;
  63. struct gptimer *timerhw;
  64. if (on)
  65. bright = bright != ~0UL ? bright : 50;
  66. else
  67. bright = 0;
  68. switch (driver) {
  69. case 2:
  70. timerhw = (struct gptimer *)DM_TIMER5_BASE;
  71. break;
  72. default:
  73. timerhw = (struct gptimer *)DM_TIMER6_BASE;
  74. }
  75. switch (driver) {
  76. case 0: /* PMIC LED-Driver */
  77. /* brightness level */
  78. tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
  79. TPS65217_WLEDCTRL2, bright, 0xFF);
  80. /* current sink */
  81. tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
  82. TPS65217_WLEDCTRL1,
  83. bright != 0 ? 0x0A : 0x02,
  84. 0xFF);
  85. break;
  86. case 1:
  87. case 2: /* PWM using timer */
  88. if (pwmfrq != ~0UL) {
  89. timerhw->tiocp_cfg = TCFG_RESET;
  90. udelay(10);
  91. while (timerhw->tiocp_cfg & TCFG_RESET)
  92. ;
  93. tmp = ~0UL-(V_OSCK/pwmfrq); /* bottom value */
  94. timerhw->tldr = tmp;
  95. timerhw->tcrr = tmp;
  96. tmp = tmp + ((V_OSCK/pwmfrq)/100) * bright;
  97. timerhw->tmar = tmp;
  98. timerhw->tclr = (TCLR_PT | (2 << TCLR_TRG_SHIFT) |
  99. TCLR_CE | TCLR_AR | TCLR_ST);
  100. } else {
  101. puts("invalid pwmfrq in env/dtb! skip PWM-setup.\n");
  102. }
  103. break;
  104. default:
  105. puts("no suitable backlightdriver in env/dtb!\n");
  106. break;
  107. }
  108. }
  109. int load_lcdtiming(struct am335x_lcdpanel *panel)
  110. {
  111. struct am335x_lcdpanel pnltmp;
  112. #ifdef CONFIG_USE_FDT
  113. u32 dtbprop;
  114. char buf[32];
  115. const char *nodep = 0;
  116. int nodeoff;
  117. if (gd->fdt_blob == NULL) {
  118. printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
  119. return -1;
  120. }
  121. memcpy(&pnltmp, (void *)panel, sizeof(struct am335x_lcdpanel));
  122. pnltmp.hactive = FDTPROP(PATHTIM, "hactive");
  123. pnltmp.vactive = FDTPROP(PATHTIM, "vactive");
  124. pnltmp.bpp = FDTPROP(PATHINF, "bpp");
  125. pnltmp.hfp = FDTPROP(PATHTIM, "hfront-porch");
  126. pnltmp.hbp = FDTPROP(PATHTIM, "hback-porch");
  127. pnltmp.hsw = FDTPROP(PATHTIM, "hsync-len");
  128. pnltmp.vfp = FDTPROP(PATHTIM, "vfront-porch");
  129. pnltmp.vbp = FDTPROP(PATHTIM, "vback-porch");
  130. pnltmp.vsw = FDTPROP(PATHTIM, "vsync-len");
  131. pnltmp.pup_delay = FDTPROP(PATHTIM, "pupdelay");
  132. pnltmp.pon_delay = FDTPROP(PATHTIM, "pondelay");
  133. pnltmp.pxl_clk = FDTPROP(PATHTIM, "clock-frequency");
  134. /* check polarity of control-signals */
  135. dtbprop = FDTPROP(PATHTIM, "hsync-active");
  136. if (dtbprop == 0)
  137. pnltmp.pol |= HSYNC_INVERT;
  138. dtbprop = FDTPROP(PATHTIM, "vsync-active");
  139. if (dtbprop == 0)
  140. pnltmp.pol |= VSYNC_INVERT;
  141. dtbprop = FDTPROP(PATHINF, "sync-ctrl");
  142. if (dtbprop == 1)
  143. pnltmp.pol |= HSVS_CONTROL;
  144. dtbprop = FDTPROP(PATHINF, "sync-edge");
  145. if (dtbprop == 1)
  146. pnltmp.pol |= HSVS_RISEFALL;
  147. dtbprop = FDTPROP(PATHTIM, "pixelclk-active");
  148. if (dtbprop == 0)
  149. pnltmp.pol |= PXCLK_INVERT;
  150. dtbprop = FDTPROP(PATHTIM, "de-active");
  151. if (dtbprop == 0)
  152. pnltmp.pol |= DE_INVERT;
  153. nodeoff = fdt_path_offset(gd->fdt_blob, "/factory-settings");
  154. if (nodeoff >= 0) {
  155. nodep = fdt_getprop(gd->fdt_blob, nodeoff, "rotation", NULL);
  156. if (nodep != 0) {
  157. if (strcmp(nodep, "cw") == 0)
  158. panel_info.vl_rot = 1;
  159. else if (strcmp(nodep, "ud") == 0)
  160. panel_info.vl_rot = 2;
  161. else if (strcmp(nodep, "ccw") == 0)
  162. panel_info.vl_rot = 3;
  163. else
  164. panel_info.vl_rot = 0;
  165. }
  166. } else {
  167. puts("no 'factory-settings / rotation' in dtb!\n");
  168. }
  169. snprintf(buf, sizeof(buf), "fbcon=rotate:%d", panel_info.vl_rot);
  170. env_set("optargs_rot", buf);
  171. #else
  172. pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL);
  173. pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL);
  174. pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL);
  175. pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL);
  176. pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL);
  177. pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL);
  178. pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL);
  179. pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL);
  180. pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL);
  181. pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL);
  182. pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL);
  183. pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL);
  184. pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL);
  185. panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0);
  186. #endif
  187. if (
  188. ~0UL == (pnltmp.hactive) ||
  189. ~0UL == (pnltmp.vactive) ||
  190. ~0UL == (pnltmp.bpp) ||
  191. ~0UL == (pnltmp.hfp) ||
  192. ~0UL == (pnltmp.hbp) ||
  193. ~0UL == (pnltmp.hsw) ||
  194. ~0UL == (pnltmp.vfp) ||
  195. ~0UL == (pnltmp.vbp) ||
  196. ~0UL == (pnltmp.vsw) ||
  197. ~0UL == (pnltmp.pxl_clk) ||
  198. ~0UL == (pnltmp.pol) ||
  199. ~0UL == (pnltmp.pup_delay) ||
  200. ~0UL == (pnltmp.pon_delay)
  201. ) {
  202. puts("lcd-settings in env/dtb incomplete!\n");
  203. printf("display-timings:\n"
  204. "================\n"
  205. "hactive: %d\n"
  206. "vactive: %d\n"
  207. "bpp : %d\n"
  208. "hfp : %d\n"
  209. "hbp : %d\n"
  210. "hsw : %d\n"
  211. "vfp : %d\n"
  212. "vbp : %d\n"
  213. "vsw : %d\n"
  214. "pxlclk : %d\n"
  215. "pol : 0x%08x\n"
  216. "pondly : %d\n",
  217. pnltmp.hactive, pnltmp.vactive, pnltmp.bpp,
  218. pnltmp.hfp, pnltmp.hbp, pnltmp.hsw,
  219. pnltmp.vfp, pnltmp.vbp, pnltmp.vsw,
  220. pnltmp.pxl_clk, pnltmp.pol, pnltmp.pon_delay);
  221. return -1;
  222. }
  223. debug("lcd-settings in env complete, taking over.\n");
  224. memcpy((void *)panel,
  225. (void *)&pnltmp,
  226. sizeof(struct am335x_lcdpanel));
  227. return 0;
  228. }
  229. #ifdef CONFIG_USE_FDT
  230. static int load_devicetree(void)
  231. {
  232. int rc;
  233. loff_t dtbsize;
  234. u32 dtbaddr = env_get_ulong("dtbaddr", 16, 0UL);
  235. if (dtbaddr == 0) {
  236. printf("%s: don't have a valid <dtbaddr> in env!\n", __func__);
  237. return -1;
  238. }
  239. #ifdef CONFIG_NAND
  240. dtbsize = 0x20000;
  241. rc = nand_read_skip_bad(get_nand_dev_by_index(0), 0x40000,
  242. (size_t *)&dtbsize,
  243. NULL, 0x20000, (u_char *)dtbaddr);
  244. #else
  245. char *dtbname = env_get("dtb");
  246. char *dtbdev = env_get("dtbdev");
  247. char *dtbpart = env_get("dtbpart");
  248. if (!dtbdev || !dtbpart || !dtbname) {
  249. printf("%s: <dtbdev>/<dtbpart>/<dtb> missing.\n", __func__);
  250. return -1;
  251. }
  252. if (fs_set_blk_dev(dtbdev, dtbpart, FS_TYPE_EXT)) {
  253. puts("load_devicetree: set_blk_dev failed.\n");
  254. return -1;
  255. }
  256. rc = fs_read(dtbname, (u32)dtbaddr, 0, 0, &dtbsize);
  257. #endif
  258. if (rc == 0) {
  259. gd->fdt_blob = (void *)dtbaddr;
  260. gd->fdt_size = dtbsize;
  261. debug("loaded %d bytes of dtb onto 0x%08x\n",
  262. (u32)dtbsize, (u32)gd->fdt_blob);
  263. return dtbsize;
  264. }
  265. printf("%s: load dtb failed!\n", __func__);
  266. return -1;
  267. }
  268. static const char *dtbmacaddr(u32 ifno)
  269. {
  270. int node, len;
  271. char enet[16];
  272. const char *mac;
  273. const char *path;
  274. if (gd->fdt_blob == NULL) {
  275. printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
  276. return NULL;
  277. }
  278. node = fdt_path_offset(gd->fdt_blob, "/aliases");
  279. if (node < 0)
  280. return NULL;
  281. sprintf(enet, "ethernet%d", ifno);
  282. path = fdt_getprop(gd->fdt_blob, node, enet, NULL);
  283. if (!path) {
  284. printf("no alias for %s\n", enet);
  285. return NULL;
  286. }
  287. node = fdt_path_offset(gd->fdt_blob, path);
  288. mac = fdt_getprop(gd->fdt_blob, node, "mac-address", &len);
  289. if (mac && is_valid_ethaddr((u8 *)mac))
  290. return mac;
  291. return NULL;
  292. }
  293. static void br_summaryscreen_printdtb(char *prefix,
  294. char *name,
  295. char *suffix)
  296. {
  297. char buf[32] = { 0 };
  298. const char *nodep = buf;
  299. char *mac = 0;
  300. int nodeoffset;
  301. int len;
  302. if (gd->fdt_blob == NULL) {
  303. printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
  304. return;
  305. }
  306. if (strcmp(name, "brmac1") == 0) {
  307. mac = (char *)dtbmacaddr(0);
  308. if (mac)
  309. sprintf(buf, "%pM", mac);
  310. } else if (strcmp(name, "brmac2") == 0) {
  311. mac = (char *)dtbmacaddr(1);
  312. if (mac)
  313. sprintf(buf, "%pM", mac);
  314. } else {
  315. nodeoffset = fdt_path_offset(gd->fdt_blob,
  316. "/factory-settings");
  317. if (nodeoffset < 0) {
  318. puts("no 'factory-settings' in dtb!\n");
  319. return;
  320. }
  321. nodep = fdt_getprop(gd->fdt_blob, nodeoffset, name, &len);
  322. }
  323. if (nodep && strlen(nodep) > 1)
  324. lcd_printf("%s %s %s", prefix, nodep, suffix);
  325. else
  326. lcd_printf("\n");
  327. }
  328. int ft_board_setup(void *blob, bd_t *bd)
  329. {
  330. int nodeoffset;
  331. nodeoffset = fdt_path_offset(blob, "/factory-settings");
  332. if (nodeoffset < 0) {
  333. puts("set bootloader version 'factory-settings' not in dtb!\n");
  334. return -1;
  335. }
  336. if (fdt_setprop(blob, nodeoffset, "bl-version",
  337. PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) {
  338. puts("set bootloader version 'bl-version' prop. not in dtb!\n");
  339. return -1;
  340. }
  341. /*
  342. * if no simplefb is requested through environment, we don't set up
  343. * one, instead we turn off backlight.
  344. */
  345. if (env_get_ulong("simplefb", 10, 0) == 0) {
  346. lcdbacklight(0);
  347. return 0;
  348. }
  349. /* Setup simplefb devicetree node, also adapt memory-node,
  350. * upper limit for kernel e.g. linux is memtop-framebuffer alligned
  351. * to a full megabyte.
  352. */
  353. u64 start = gd->bd->bi_dram[0].start;
  354. u64 size = (gd->fb_base - start) & ~0xFFFFF;
  355. int rc = fdt_fixup_memory_banks(blob, &start, &size, 1);
  356. if (rc) {
  357. puts("cannot setup simplefb: Error reserving memory!\n");
  358. return rc;
  359. }
  360. rc = lcd_dt_simplefb_enable_existing_node(blob);
  361. if (rc) {
  362. puts("cannot setup simplefb: error enabling simplefb node!\n");
  363. return rc;
  364. }
  365. return 0;
  366. }
  367. #else
  368. static void br_summaryscreen_printenv(char *prefix,
  369. char *name, char *altname,
  370. char *suffix)
  371. {
  372. char *envval = env_get(name);
  373. if (0 != envval) {
  374. lcd_printf("%s %s %s", prefix, envval, suffix);
  375. } else if (0 != altname) {
  376. envval = env_get(altname);
  377. if (0 != envval)
  378. lcd_printf("%s %s %s", prefix, envval, suffix);
  379. } else {
  380. lcd_printf("\n");
  381. }
  382. }
  383. #endif
  384. void br_summaryscreen(void)
  385. {
  386. #ifdef CONFIG_USE_FDT
  387. br_summaryscreen_printdtb(" - B&R -", "order-no", "-\n");
  388. br_summaryscreen_printdtb(" Serial/Rev :", "serial-no", " /");
  389. br_summaryscreen_printdtb(" ", "hw-revision", "\n");
  390. br_summaryscreen_printdtb(" MAC (IF1) :", "brmac1", "\n");
  391. br_summaryscreen_printdtb(" MAC (IF2) :", "brmac2", "\n");
  392. lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
  393. lcd_puts("\n");
  394. #else
  395. br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n");
  396. br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n");
  397. br_summaryscreen_printenv(" MAC (IF1) :", "br_mac1", "ethaddr", "\n");
  398. br_summaryscreen_printenv(" MAC (IF2) :", "br_mac2", 0, "\n");
  399. lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
  400. lcd_puts("\n");
  401. #endif
  402. }
  403. void lcdpower(int on)
  404. {
  405. u32 pin, swval, i;
  406. #ifdef CONFIG_USE_FDT
  407. if (gd->fdt_blob == NULL) {
  408. printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
  409. return;
  410. }
  411. pin = FDTPROP(PATHINF, "pwrpin");
  412. #else
  413. pin = env_get_ulong("ds1_pwr", 16, ~0UL);
  414. #endif
  415. if (pin == ~0UL) {
  416. puts("no pwrpin in dtb/env, cannot powerup display!\n");
  417. return;
  418. }
  419. for (i = 0; i < 3; i++) {
  420. if (pin != 0) {
  421. swval = pin & 0x80 ? 0 : 1;
  422. if (on)
  423. gpio_direction_output(pin & 0x7F, swval);
  424. else
  425. gpio_direction_output(pin & 0x7F, !swval);
  426. debug("switched pin %d to %d\n", pin & 0x7F, swval);
  427. }
  428. pin >>= 8;
  429. }
  430. }
  431. vidinfo_t panel_info = {
  432. .vl_col = 1366, /*
  433. * give full resolution for allocating enough
  434. * memory
  435. */
  436. .vl_row = 768,
  437. .vl_bpix = 5,
  438. .priv = 0
  439. };
  440. void lcd_ctrl_init(void *lcdbase)
  441. {
  442. struct am335x_lcdpanel lcd_panel;
  443. #ifdef CONFIG_USE_FDT
  444. /* TODO: is there a better place to load the dtb ? */
  445. load_devicetree();
  446. #endif
  447. memset(&lcd_panel, 0, sizeof(struct am335x_lcdpanel));
  448. if (load_lcdtiming(&lcd_panel) != 0)
  449. return;
  450. lcd_panel.panel_power_ctrl = &lcdpower;
  451. if (0 != am335xfb_init(&lcd_panel))
  452. printf("ERROR: failed to initialize video!");
  453. /*
  454. * modifiy panel info to 'real' resolution, to operate correct with
  455. * lcd-framework.
  456. */
  457. panel_info.vl_col = lcd_panel.hactive;
  458. panel_info.vl_row = lcd_panel.vactive;
  459. lcd_set_flush_dcache(1);
  460. }
  461. void lcd_enable(void)
  462. {
  463. br_summaryscreen();
  464. lcdbacklight(1);
  465. }
  466. #elif CONFIG_SPL_BUILD
  467. #else
  468. #error "LCD-support with a suitable FB-Driver is mandatory !"
  469. #endif /* CONFIG_LCD */
  470. #ifdef CONFIG_SPL_BUILD
  471. void pmicsetup(u32 mpupll)
  472. {
  473. int mpu_vdd;
  474. int usb_cur_lim;
  475. if (i2c_probe(TPS65217_CHIP_PM)) {
  476. puts("PMIC (0x24) not found! skip further initalization.\n");
  477. return;
  478. }
  479. /* Get the frequency which is defined by device fuses */
  480. dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
  481. printf("detected max. frequency: %d - ", dpll_mpu_opp100.m);
  482. if (0 != mpupll) {
  483. dpll_mpu_opp100.m = MPUPLL_M_1000;
  484. printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m);
  485. } else {
  486. puts("ok.\n");
  487. }
  488. /*
  489. * Increase USB current limit to 1300mA or 1800mA and set
  490. * the MPU voltage controller as needed.
  491. */
  492. if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
  493. usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
  494. mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
  495. } else {
  496. usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
  497. mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
  498. }
  499. if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
  500. usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK))
  501. puts("tps65217_reg_write failure\n");
  502. /* Set DCDC3 (CORE) voltage to 1.125V */
  503. if (tps65217_voltage_update(TPS65217_DEFDCDC3,
  504. TPS65217_DCDC_VOLT_SEL_1125MV)) {
  505. puts("tps65217_voltage_update failure\n");
  506. return;
  507. }
  508. /* Set CORE Frequencies to OPP100 */
  509. do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
  510. /* Set DCDC2 (MPU) voltage */
  511. if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
  512. puts("tps65217_voltage_update failure\n");
  513. return;
  514. }
  515. /* Set LDO3 to 1.8V */
  516. if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
  517. TPS65217_DEFLS1,
  518. TPS65217_LDO_VOLTAGE_OUT_1_8,
  519. TPS65217_LDO_MASK))
  520. puts("tps65217_reg_write failure\n");
  521. /* Set LDO4 to 3.3V */
  522. if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
  523. TPS65217_DEFLS2,
  524. TPS65217_LDO_VOLTAGE_OUT_3_3,
  525. TPS65217_LDO_MASK))
  526. puts("tps65217_reg_write failure\n");
  527. /* Set MPU Frequency to what we detected now that voltages are set */
  528. do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
  529. /* Set PWR_EN bit in Status Register */
  530. tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
  531. TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF);
  532. }
  533. void set_uart_mux_conf(void)
  534. {
  535. enable_uart0_pin_mux();
  536. }
  537. void set_mux_conf_regs(void)
  538. {
  539. enable_board_pin_mux();
  540. }
  541. #endif /* CONFIG_SPL_BUILD */
  542. #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
  543. (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
  544. static void cpsw_control(int enabled)
  545. {
  546. /* VTP can be added here */
  547. return;
  548. }
  549. /* describing port offsets of TI's CPSW block */
  550. static struct cpsw_slave_data cpsw_slaves[] = {
  551. {
  552. .slave_reg_ofs = 0x208,
  553. .sliver_reg_ofs = 0xd80,
  554. .phy_addr = 1,
  555. },
  556. {
  557. .slave_reg_ofs = 0x308,
  558. .sliver_reg_ofs = 0xdc0,
  559. .phy_addr = 2,
  560. },
  561. };
  562. static struct cpsw_platform_data cpsw_data = {
  563. .mdio_base = CPSW_MDIO_BASE,
  564. .cpsw_base = CPSW_BASE,
  565. .mdio_div = 0xff,
  566. .channels = 8,
  567. .cpdma_reg_ofs = 0x800,
  568. .slaves = 1,
  569. .slave_data = cpsw_slaves,
  570. .ale_reg_ofs = 0xd00,
  571. .ale_entries = 1024,
  572. .host_port_reg_ofs = 0x108,
  573. .hw_stats_reg_ofs = 0x900,
  574. .bd_ram_ofs = 0x2000,
  575. .mac_control = (1 << 5),
  576. .control = cpsw_control,
  577. .host_port_num = 0,
  578. .version = CPSW_CTRL_VERSION_2,
  579. };
  580. #endif /* CONFIG_DRIVER_TI_CPSW, ... */
  581. #if defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)
  582. int board_eth_init(bd_t *bis)
  583. {
  584. int rv = 0;
  585. char mac_addr[6];
  586. const char *mac = 0;
  587. uint32_t mac_hi, mac_lo;
  588. /* try reading mac address from efuse */
  589. mac_lo = readl(&cdev->macid0l);
  590. mac_hi = readl(&cdev->macid0h);
  591. mac_addr[0] = mac_hi & 0xFF;
  592. mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  593. mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  594. mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  595. mac_addr[4] = mac_lo & 0xFF;
  596. mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  597. if (!env_get("ethaddr")) {
  598. #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USE_FDT)
  599. printf("<ethaddr> not set. trying DTB ... ");
  600. mac = dtbmacaddr(0);
  601. #endif
  602. if (!mac) {
  603. printf("<ethaddr> not set. validating E-fuse MAC ... ");
  604. if (is_valid_ethaddr((const u8 *)mac_addr))
  605. mac = (const char *)mac_addr;
  606. }
  607. if (mac) {
  608. printf("using: %pM on ", mac);
  609. eth_env_set_enetaddr("ethaddr", (const u8 *)mac);
  610. }
  611. }
  612. writel(MII_MODE_ENABLE, &cdev->miisel);
  613. cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII;
  614. cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_MII;
  615. rv = cpsw_register(&cpsw_data);
  616. if (rv < 0) {
  617. printf("Error %d registering CPSW switch\n", rv);
  618. return 0;
  619. }
  620. return rv;
  621. }
  622. #endif /* defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD) */
  623. #if defined(CONFIG_MMC)
  624. int board_mmc_init(bd_t *bis)
  625. {
  626. int rc = 0;
  627. rc |= omap_mmc_init(0, 0, 0, -1, -1);
  628. rc |= omap_mmc_init(1, 0, 0, -1, -1);
  629. return rc;
  630. }
  631. #endif
  632. int overwrite_console(void)
  633. {
  634. return 1;
  635. }