common.c 17 KB

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