common.c 18 KB

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