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