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