blob: 9df19791c22a0a7242c32bb1530651a454a1f0d7 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hannes Petermaier893c04e2014-02-07 08:07:36 +01002/*
3 * common.c
4 *
5 * common board functions for B&R boards
6 *
Hannes Schmelzer4c302b92015-05-28 15:41:12 +02007 * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
Hannes Petermaier893c04e2014-02-07 08:07:36 +01008 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
9 *
Hannes Petermaier893c04e2014-02-07 08:07:36 +010010 */
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010011#include <version.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010012#include <common.h>
Alex Kiernan9925f1d2018-04-01 09:22:38 +000013#include <environment.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010014#include <errno.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010015#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>
Hannes Petermaier46c8ebc2014-04-08 08:39:20 +020021#include <asm/arch/mmc_host_def.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010022#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>
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010028#include <lcd.h>
29#include <fs.h>
30#ifdef CONFIG_USE_FDT
31 #include <fdt_support.h>
32#endif
Hannes Petermaier893c04e2014-02-07 08:07:36 +010033#include "bur_common.h"
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010034#include "../../../drivers/video/am335x-fb.h"
Hannes Petermaierd79c1382015-04-08 07:38:34 +020035#include <nand.h>
Hannes Petermaier99f72472015-04-24 14:49:37 +020036#include <fdt_simplefb.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010037
38static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010039
40DECLARE_GLOBAL_DATA_PTR;
41
42#ifdef CONFIG_USE_FDT
Hannes Petermaier47c14222015-04-08 07:38:33 +020043 #define FDTPROP(b, c) fdt_getprop_u32_default(gd->fdt_blob, b, c, ~0UL)
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010044 #define PATHTIM "/panel/display-timings/default"
45 #define PATHINF "/panel/panel-info"
46#endif
Hannes Petermaier893c04e2014-02-07 08:07:36 +010047/* --------------------------------------------------------------------------*/
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010048#if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \
49 !defined(CONFIG_SPL_BUILD)
Hannes Petermaier99f72472015-04-24 14:49:37 +020050void lcdbacklight(int on)
51{
52#ifdef CONFIG_USE_FDT
53 if (gd->fdt_blob == NULL) {
54 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
55 return;
56 }
57 unsigned int driver = FDTPROP(PATHINF, "brightdrv");
58 unsigned int bright = FDTPROP(PATHINF, "brightdef");
59 unsigned int pwmfrq = FDTPROP(PATHINF, "brightfdim");
60#else
Simon Glassbfebc8c2017-08-03 12:22:13 -060061 unsigned int driver = env_get_ulong("ds1_bright_drv", 16, 0UL);
62 unsigned int bright = env_get_ulong("ds1_bright_def", 10, 50);
63 unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL);
Hannes Petermaier99f72472015-04-24 14:49:37 +020064#endif
65 unsigned int tmp;
Hannes Petermaier9b63ba32015-06-11 12:25:43 +020066 struct gptimer *timerhw;
Hannes Petermaier99f72472015-04-24 14:49:37 +020067
68 if (on)
69 bright = bright != ~0UL ? bright : 50;
70 else
71 bright = 0;
72
73 switch (driver) {
Hannes Petermaier9b63ba32015-06-11 12:25:43 +020074 case 2:
75 timerhw = (struct gptimer *)DM_TIMER5_BASE;
76 break;
77 default:
78 timerhw = (struct gptimer *)DM_TIMER6_BASE;
79 }
80
81 switch (driver) {
Hannes Petermaier99f72472015-04-24 14:49:37 +020082 case 0: /* PMIC LED-Driver */
83 /* brightness level */
84 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
85 TPS65217_WLEDCTRL2, bright, 0xFF);
86 /* current sink */
87 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
88 TPS65217_WLEDCTRL1,
89 bright != 0 ? 0x0A : 0x02,
90 0xFF);
91 break;
Hannes Petermaier9b63ba32015-06-11 12:25:43 +020092 case 1:
93 case 2: /* PWM using timer */
Hannes Petermaier99f72472015-04-24 14:49:37 +020094 if (pwmfrq != ~0UL) {
95 timerhw->tiocp_cfg = TCFG_RESET;
96 udelay(10);
97 while (timerhw->tiocp_cfg & TCFG_RESET)
98 ;
99 tmp = ~0UL-(V_OSCK/pwmfrq); /* bottom value */
100 timerhw->tldr = tmp;
101 timerhw->tcrr = tmp;
102 tmp = tmp + ((V_OSCK/pwmfrq)/100) * bright;
103 timerhw->tmar = tmp;
104 timerhw->tclr = (TCLR_PT | (2 << TCLR_TRG_SHIFT) |
105 TCLR_CE | TCLR_AR | TCLR_ST);
106 } else {
107 puts("invalid pwmfrq in env/dtb! skip PWM-setup.\n");
108 }
109 break;
110 default:
111 puts("no suitable backlightdriver in env/dtb!\n");
112 break;
113 }
114}
115
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100116int load_lcdtiming(struct am335x_lcdpanel *panel)
117{
118 struct am335x_lcdpanel pnltmp;
119#ifdef CONFIG_USE_FDT
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100120 u32 dtbprop;
Hannes Petermaierd8044522015-04-24 14:49:35 +0200121 char buf[32];
122 const char *nodep = 0;
123 int nodeoff;
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100124
Hannes Petermaier47c14222015-04-08 07:38:33 +0200125 if (gd->fdt_blob == NULL) {
126 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100127 return -1;
128 }
129 memcpy(&pnltmp, (void *)panel, sizeof(struct am335x_lcdpanel));
130
Hannes Petermaier47c14222015-04-08 07:38:33 +0200131 pnltmp.hactive = FDTPROP(PATHTIM, "hactive");
132 pnltmp.vactive = FDTPROP(PATHTIM, "vactive");
133 pnltmp.bpp = FDTPROP(PATHINF, "bpp");
134 pnltmp.hfp = FDTPROP(PATHTIM, "hfront-porch");
135 pnltmp.hbp = FDTPROP(PATHTIM, "hback-porch");
136 pnltmp.hsw = FDTPROP(PATHTIM, "hsync-len");
137 pnltmp.vfp = FDTPROP(PATHTIM, "vfront-porch");
138 pnltmp.vbp = FDTPROP(PATHTIM, "vback-porch");
139 pnltmp.vsw = FDTPROP(PATHTIM, "vsync-len");
140 pnltmp.pup_delay = FDTPROP(PATHTIM, "pupdelay");
141 pnltmp.pon_delay = FDTPROP(PATHTIM, "pondelay");
Hannes Schmelzer0fcec572018-01-09 19:01:35 +0100142 pnltmp.pxl_clk = FDTPROP(PATHTIM, "clock-frequency");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100143
144 /* check polarity of control-signals */
Hannes Petermaier47c14222015-04-08 07:38:33 +0200145 dtbprop = FDTPROP(PATHTIM, "hsync-active");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100146 if (dtbprop == 0)
147 pnltmp.pol |= HSYNC_INVERT;
Hannes Petermaier47c14222015-04-08 07:38:33 +0200148 dtbprop = FDTPROP(PATHTIM, "vsync-active");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100149 if (dtbprop == 0)
150 pnltmp.pol |= VSYNC_INVERT;
Hannes Petermaier47c14222015-04-08 07:38:33 +0200151 dtbprop = FDTPROP(PATHINF, "sync-ctrl");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100152 if (dtbprop == 1)
153 pnltmp.pol |= HSVS_CONTROL;
Hannes Petermaier47c14222015-04-08 07:38:33 +0200154 dtbprop = FDTPROP(PATHINF, "sync-edge");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100155 if (dtbprop == 1)
156 pnltmp.pol |= HSVS_RISEFALL;
Hannes Petermaier47c14222015-04-08 07:38:33 +0200157 dtbprop = FDTPROP(PATHTIM, "pixelclk-active");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100158 if (dtbprop == 0)
159 pnltmp.pol |= PXCLK_INVERT;
Hannes Petermaier47c14222015-04-08 07:38:33 +0200160 dtbprop = FDTPROP(PATHTIM, "de-active");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100161 if (dtbprop == 0)
162 pnltmp.pol |= DE_INVERT;
Hannes Petermaierd8044522015-04-24 14:49:35 +0200163
164 nodeoff = fdt_path_offset(gd->fdt_blob, "/factory-settings");
165 if (nodeoff >= 0) {
166 nodep = fdt_getprop(gd->fdt_blob, nodeoff, "rotation", NULL);
167 if (nodep != 0) {
168 if (strcmp(nodep, "cw") == 0)
169 panel_info.vl_rot = 1;
170 else if (strcmp(nodep, "ud") == 0)
171 panel_info.vl_rot = 2;
172 else if (strcmp(nodep, "ccw") == 0)
173 panel_info.vl_rot = 3;
174 else
175 panel_info.vl_rot = 0;
176 }
177 } else {
178 puts("no 'factory-settings / rotation' in dtb!\n");
179 }
180 snprintf(buf, sizeof(buf), "fbcon=rotate:%d", panel_info.vl_rot);
Simon Glass382bee52017-08-03 12:22:09 -0600181 env_set("optargs_rot", buf);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100182#else
Simon Glassbfebc8c2017-08-03 12:22:13 -0600183 pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL);
184 pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL);
185 pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL);
186 pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL);
187 pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL);
188 pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL);
189 pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL);
190 pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL);
191 pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL);
Hannes Schmelzer0fcec572018-01-09 19:01:35 +0100192 pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL);
Simon Glassbfebc8c2017-08-03 12:22:13 -0600193 pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL);
194 pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL);
195 pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL);
196 panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100197#endif
198 if (
199 ~0UL == (pnltmp.hactive) ||
200 ~0UL == (pnltmp.vactive) ||
201 ~0UL == (pnltmp.bpp) ||
202 ~0UL == (pnltmp.hfp) ||
203 ~0UL == (pnltmp.hbp) ||
204 ~0UL == (pnltmp.hsw) ||
205 ~0UL == (pnltmp.vfp) ||
206 ~0UL == (pnltmp.vbp) ||
207 ~0UL == (pnltmp.vsw) ||
Hannes Schmelzer0fcec572018-01-09 19:01:35 +0100208 ~0UL == (pnltmp.pxl_clk) ||
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100209 ~0UL == (pnltmp.pol) ||
210 ~0UL == (pnltmp.pup_delay) ||
211 ~0UL == (pnltmp.pon_delay)
212 ) {
213 puts("lcd-settings in env/dtb incomplete!\n");
214 printf("display-timings:\n"
215 "================\n"
216 "hactive: %d\n"
217 "vactive: %d\n"
218 "bpp : %d\n"
219 "hfp : %d\n"
220 "hbp : %d\n"
221 "hsw : %d\n"
222 "vfp : %d\n"
223 "vbp : %d\n"
224 "vsw : %d\n"
225 "pxlclk : %d\n"
226 "pol : 0x%08x\n"
227 "pondly : %d\n",
228 pnltmp.hactive, pnltmp.vactive, pnltmp.bpp,
229 pnltmp.hfp, pnltmp.hbp, pnltmp.hsw,
230 pnltmp.vfp, pnltmp.vbp, pnltmp.vsw,
Hannes Schmelzer0fcec572018-01-09 19:01:35 +0100231 pnltmp.pxl_clk, pnltmp.pol, pnltmp.pon_delay);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100232
233 return -1;
234 }
235 debug("lcd-settings in env complete, taking over.\n");
236 memcpy((void *)panel,
237 (void *)&pnltmp,
238 sizeof(struct am335x_lcdpanel));
239
240 return 0;
241}
242
243#ifdef CONFIG_USE_FDT
244static int load_devicetree(void)
245{
Hannes Petermaier47c14222015-04-08 07:38:33 +0200246 int rc;
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100247 loff_t dtbsize;
Simon Glassbfebc8c2017-08-03 12:22:13 -0600248 u32 dtbaddr = env_get_ulong("dtbaddr", 16, 0UL);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100249
Hannes Petermaier47c14222015-04-08 07:38:33 +0200250 if (dtbaddr == 0) {
251 printf("%s: don't have a valid <dtbaddr> in env!\n", __func__);
252 return -1;
253 }
Hannes Petermaierd79c1382015-04-08 07:38:34 +0200254#ifdef CONFIG_NAND
255 dtbsize = 0x20000;
Grygorii Strashko573cc462017-06-26 19:13:05 -0500256 rc = nand_read_skip_bad(get_nand_dev_by_index(0), 0x40000,
257 (size_t *)&dtbsize,
Hannes Petermaierd79c1382015-04-08 07:38:34 +0200258 NULL, 0x20000, (u_char *)dtbaddr);
259#else
Simon Glass00caae62017-08-03 12:22:12 -0600260 char *dtbname = env_get("dtb");
261 char *dtbdev = env_get("dtbdev");
262 char *dtbpart = env_get("dtbpart");
xypron.glpk@gmx.de169b50e2017-05-05 20:57:32 +0200263 if (!dtbdev || !dtbpart || !dtbname) {
Hannes Petermaier47c14222015-04-08 07:38:33 +0200264 printf("%s: <dtbdev>/<dtbpart>/<dtb> missing.\n", __func__);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100265 return -1;
266 }
267
xypron.glpk@gmx.de169b50e2017-05-05 20:57:32 +0200268 if (fs_set_blk_dev(dtbdev, dtbpart, FS_TYPE_EXT)) {
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100269 puts("load_devicetree: set_blk_dev failed.\n");
270 return -1;
271 }
Hannes Petermaier47c14222015-04-08 07:38:33 +0200272 rc = fs_read(dtbname, (u32)dtbaddr, 0, 0, &dtbsize);
Hannes Petermaierd79c1382015-04-08 07:38:34 +0200273#endif
Hannes Petermaier47c14222015-04-08 07:38:33 +0200274 if (rc == 0) {
275 gd->fdt_blob = (void *)dtbaddr;
276 gd->fdt_size = dtbsize;
277 debug("loaded %d bytes of dtb onto 0x%08x\n",
278 (u32)dtbsize, (u32)gd->fdt_blob);
279 return dtbsize;
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100280 }
281
Hannes Petermaier47c14222015-04-08 07:38:33 +0200282 printf("%s: load dtb failed!\n", __func__);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100283 return -1;
284}
285
286static const char *dtbmacaddr(u32 ifno)
287{
288 int node, len;
289 char enet[16];
290 const char *mac;
291 const char *path;
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100292
Hannes Petermaier47c14222015-04-08 07:38:33 +0200293 if (gd->fdt_blob == NULL) {
294 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100295 return NULL;
296 }
297
Hannes Petermaier47c14222015-04-08 07:38:33 +0200298 node = fdt_path_offset(gd->fdt_blob, "/aliases");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100299 if (node < 0)
300 return NULL;
301
302 sprintf(enet, "ethernet%d", ifno);
Hannes Petermaier47c14222015-04-08 07:38:33 +0200303 path = fdt_getprop(gd->fdt_blob, node, enet, NULL);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100304 if (!path) {
305 printf("no alias for %s\n", enet);
306 return NULL;
307 }
308
Hannes Petermaier47c14222015-04-08 07:38:33 +0200309 node = fdt_path_offset(gd->fdt_blob, path);
310 mac = fdt_getprop(gd->fdt_blob, node, "mac-address", &len);
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500311 if (mac && is_valid_ethaddr((u8 *)mac))
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100312 return mac;
313
314 return NULL;
315}
316
317static void br_summaryscreen_printdtb(char *prefix,
318 char *name,
319 char *suffix)
320{
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100321 char buf[32] = { 0 };
322 const char *nodep = buf;
323 char *mac = 0;
324 int nodeoffset;
325 int len;
326
Hannes Petermaier47c14222015-04-08 07:38:33 +0200327 if (gd->fdt_blob == NULL) {
328 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100329 return;
330 }
331
332 if (strcmp(name, "brmac1") == 0) {
333 mac = (char *)dtbmacaddr(0);
334 if (mac)
335 sprintf(buf, "%pM", mac);
336 } else if (strcmp(name, "brmac2") == 0) {
337 mac = (char *)dtbmacaddr(1);
338 if (mac)
339 sprintf(buf, "%pM", mac);
340 } else {
Hannes Petermaier47c14222015-04-08 07:38:33 +0200341 nodeoffset = fdt_path_offset(gd->fdt_blob,
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100342 "/factory-settings");
343 if (nodeoffset < 0) {
344 puts("no 'factory-settings' in dtb!\n");
345 return;
346 }
Hannes Petermaier47c14222015-04-08 07:38:33 +0200347 nodep = fdt_getprop(gd->fdt_blob, nodeoffset, name, &len);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100348 }
349 if (nodep && strlen(nodep) > 1)
350 lcd_printf("%s %s %s", prefix, nodep, suffix);
351 else
352 lcd_printf("\n");
353}
354int ft_board_setup(void *blob, bd_t *bd)
355{
356 int nodeoffset;
357
358 nodeoffset = fdt_path_offset(blob, "/factory-settings");
359 if (nodeoffset < 0) {
360 puts("set bootloader version 'factory-settings' not in dtb!\n");
361 return -1;
362 }
363 if (fdt_setprop(blob, nodeoffset, "bl-version",
364 PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) {
365 puts("set bootloader version 'bl-version' prop. not in dtb!\n");
366 return -1;
367 }
Hannes Petermaier99f72472015-04-24 14:49:37 +0200368 /*
369 * if no simplefb is requested through environment, we don't set up
370 * one, instead we turn off backlight.
371 */
Simon Glassbfebc8c2017-08-03 12:22:13 -0600372 if (env_get_ulong("simplefb", 10, 0) == 0) {
Hannes Petermaier99f72472015-04-24 14:49:37 +0200373 lcdbacklight(0);
374 return 0;
375 }
376 /* Setup simplefb devicetree node, also adapt memory-node,
377 * upper limit for kernel e.g. linux is memtop-framebuffer alligned
378 * to a full megabyte.
379 */
380 u64 start = gd->bd->bi_dram[0].start;
381 u64 size = (gd->fb_base - start) & ~0xFFFFF;
382 int rc = fdt_fixup_memory_banks(blob, &start, &size, 1);
383
384 if (rc) {
385 puts("cannot setup simplefb: Error reserving memory!\n");
386 return rc;
387 }
388 rc = lcd_dt_simplefb_enable_existing_node(blob);
389 if (rc) {
390 puts("cannot setup simplefb: error enabling simplefb node!\n");
391 return rc;
392 }
393
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100394 return 0;
395}
396#else
397
398static void br_summaryscreen_printenv(char *prefix,
399 char *name, char *altname,
400 char *suffix)
401{
Simon Glass00caae62017-08-03 12:22:12 -0600402 char *envval = env_get(name);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100403 if (0 != envval) {
404 lcd_printf("%s %s %s", prefix, envval, suffix);
405 } else if (0 != altname) {
Simon Glass00caae62017-08-03 12:22:12 -0600406 envval = env_get(altname);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100407 if (0 != envval)
408 lcd_printf("%s %s %s", prefix, envval, suffix);
409 } else {
410 lcd_printf("\n");
411 }
412}
413#endif
414void br_summaryscreen(void)
415{
416#ifdef CONFIG_USE_FDT
417 br_summaryscreen_printdtb(" - B&R -", "order-no", "-\n");
418 br_summaryscreen_printdtb(" Serial/Rev :", "serial-no", " /");
419 br_summaryscreen_printdtb(" ", "hw-revision", "\n");
420 br_summaryscreen_printdtb(" MAC (IF1) :", "brmac1", "\n");
421 br_summaryscreen_printdtb(" MAC (IF2) :", "brmac2", "\n");
422 lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
423 lcd_puts("\n");
424#else
425 br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n");
426 br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n");
427 br_summaryscreen_printenv(" MAC (IF1) :", "br_mac1", "ethaddr", "\n");
428 br_summaryscreen_printenv(" MAC (IF2) :", "br_mac2", 0, "\n");
429 lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
430 lcd_puts("\n");
431#endif
432}
433
434void lcdpower(int on)
435{
436 u32 pin, swval, i;
437#ifdef CONFIG_USE_FDT
Hannes Petermaier47c14222015-04-08 07:38:33 +0200438 if (gd->fdt_blob == NULL) {
439 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100440 return;
441 }
Hannes Petermaier47c14222015-04-08 07:38:33 +0200442 pin = FDTPROP(PATHINF, "pwrpin");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100443#else
Simon Glassbfebc8c2017-08-03 12:22:13 -0600444 pin = env_get_ulong("ds1_pwr", 16, ~0UL);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100445#endif
446 if (pin == ~0UL) {
447 puts("no pwrpin in dtb/env, cannot powerup display!\n");
448 return;
449 }
450
451 for (i = 0; i < 3; i++) {
452 if (pin != 0) {
453 swval = pin & 0x80 ? 0 : 1;
454 if (on)
455 gpio_direction_output(pin & 0x7F, swval);
456 else
457 gpio_direction_output(pin & 0x7F, !swval);
458
459 debug("switched pin %d to %d\n", pin & 0x7F, swval);
460 }
461 pin >>= 8;
462 }
463}
464
465vidinfo_t panel_info = {
466 .vl_col = 1366, /*
467 * give full resolution for allocating enough
468 * memory
469 */
470 .vl_row = 768,
471 .vl_bpix = 5,
472 .priv = 0
473};
474
475void lcd_ctrl_init(void *lcdbase)
476{
477 struct am335x_lcdpanel lcd_panel;
478#ifdef CONFIG_USE_FDT
479 /* TODO: is there a better place to load the dtb ? */
480 load_devicetree();
481#endif
482 memset(&lcd_panel, 0, sizeof(struct am335x_lcdpanel));
483 if (load_lcdtiming(&lcd_panel) != 0)
484 return;
485
486 lcd_panel.panel_power_ctrl = &lcdpower;
487
488 if (0 != am335xfb_init(&lcd_panel))
489 printf("ERROR: failed to initialize video!");
490 /*
491 * modifiy panel info to 'real' resolution, to operate correct with
492 * lcd-framework.
493 */
494 panel_info.vl_col = lcd_panel.hactive;
495 panel_info.vl_row = lcd_panel.vactive;
496
497 lcd_set_flush_dcache(1);
498}
499
500void lcd_enable(void)
501{
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100502 br_summaryscreen();
Hannes Petermaier99f72472015-04-24 14:49:37 +0200503 lcdbacklight(1);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100504}
505#elif CONFIG_SPL_BUILD
506#else
507#error "LCD-support with a suitable FB-Driver is mandatory !"
508#endif /* CONFIG_LCD */
509
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100510#ifdef CONFIG_SPL_BUILD
511void pmicsetup(u32 mpupll)
512{
513 int mpu_vdd;
514 int usb_cur_lim;
515
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100516 if (i2c_probe(TPS65217_CHIP_PM)) {
517 puts("PMIC (0x24) not found! skip further initalization.\n");
518 return;
519 }
520
521 /* Get the frequency which is defined by device fuses */
522 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
523 printf("detected max. frequency: %d - ", dpll_mpu_opp100.m);
524
525 if (0 != mpupll) {
526 dpll_mpu_opp100.m = MPUPLL_M_1000;
527 printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m);
528 } else {
529 puts("ok.\n");
530 }
531 /*
532 * Increase USB current limit to 1300mA or 1800mA and set
533 * the MPU voltage controller as needed.
534 */
535 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
536 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
537 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
538 } else {
539 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
540 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
541 }
542
543 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
544 usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK))
545 puts("tps65217_reg_write failure\n");
546
547 /* Set DCDC3 (CORE) voltage to 1.125V */
548 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
549 TPS65217_DCDC_VOLT_SEL_1125MV)) {
550 puts("tps65217_voltage_update failure\n");
551 return;
552 }
553
554 /* Set CORE Frequencies to OPP100 */
555 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
556
557 /* Set DCDC2 (MPU) voltage */
558 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
559 puts("tps65217_voltage_update failure\n");
560 return;
561 }
562
563 /* Set LDO3 to 1.8V */
564 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
565 TPS65217_DEFLS1,
566 TPS65217_LDO_VOLTAGE_OUT_1_8,
567 TPS65217_LDO_MASK))
568 puts("tps65217_reg_write failure\n");
569 /* Set LDO4 to 3.3V */
570 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
571 TPS65217_DEFLS2,
572 TPS65217_LDO_VOLTAGE_OUT_3_3,
573 TPS65217_LDO_MASK))
574 puts("tps65217_reg_write failure\n");
575
576 /* Set MPU Frequency to what we detected now that voltages are set */
577 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100578 /* Set PWR_EN bit in Status Register */
579 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
580 TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF);
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100581}
582
583void set_uart_mux_conf(void)
584{
585 enable_uart0_pin_mux();
586}
587
588void set_mux_conf_regs(void)
589{
590 enable_board_pin_mux();
591}
592
593#endif /* CONFIG_SPL_BUILD */
594
595#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
596 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
597static void cpsw_control(int enabled)
598{
599 /* VTP can be added here */
600 return;
601}
602
603/* describing port offsets of TI's CPSW block */
604static struct cpsw_slave_data cpsw_slaves[] = {
605 {
606 .slave_reg_ofs = 0x208,
607 .sliver_reg_ofs = 0xd80,
Hannes Petermaier4b75fd52014-03-06 07:03:24 +0100608 .phy_addr = 1,
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100609 },
610 {
611 .slave_reg_ofs = 0x308,
612 .sliver_reg_ofs = 0xdc0,
Hannes Petermaier4b75fd52014-03-06 07:03:24 +0100613 .phy_addr = 2,
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100614 },
615};
616
617static struct cpsw_platform_data cpsw_data = {
618 .mdio_base = CPSW_MDIO_BASE,
619 .cpsw_base = CPSW_BASE,
620 .mdio_div = 0xff,
621 .channels = 8,
622 .cpdma_reg_ofs = 0x800,
623 .slaves = 1,
624 .slave_data = cpsw_slaves,
625 .ale_reg_ofs = 0xd00,
626 .ale_entries = 1024,
627 .host_port_reg_ofs = 0x108,
628 .hw_stats_reg_ofs = 0x900,
629 .bd_ram_ofs = 0x2000,
630 .mac_control = (1 << 5),
631 .control = cpsw_control,
632 .host_port_num = 0,
633 .version = CPSW_CTRL_VERSION_2,
634};
635#endif /* CONFIG_DRIVER_TI_CPSW, ... */
636
Hannes Schmelzer568cfb42016-02-19 12:09:42 +0100637#if defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100638int board_eth_init(bd_t *bis)
639{
640 int rv = 0;
Hannes Petermaierd3014252015-02-03 13:22:27 +0100641 char mac_addr[6];
642 const char *mac = 0;
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100643 uint32_t mac_hi, mac_lo;
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100644 /* try reading mac address from efuse */
645 mac_lo = readl(&cdev->macid0l);
646 mac_hi = readl(&cdev->macid0h);
647 mac_addr[0] = mac_hi & 0xFF;
648 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
649 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
650 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
651 mac_addr[4] = mac_lo & 0xFF;
652 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
653
Simon Glass00caae62017-08-03 12:22:12 -0600654 if (!env_get("ethaddr")) {
Hannes Petermaierd3014252015-02-03 13:22:27 +0100655 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USE_FDT)
656 printf("<ethaddr> not set. trying DTB ... ");
657 mac = dtbmacaddr(0);
658 #endif
659 if (!mac) {
660 printf("<ethaddr> not set. validating E-fuse MAC ... ");
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500661 if (is_valid_ethaddr((const u8 *)mac_addr))
Hannes Petermaierd3014252015-02-03 13:22:27 +0100662 mac = (const char *)mac_addr;
663 }
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100664
Hannes Petermaierd3014252015-02-03 13:22:27 +0100665 if (mac) {
666 printf("using: %pM on ", mac);
Simon Glassfd1e9592017-08-03 12:22:11 -0600667 eth_env_set_enetaddr("ethaddr", (const u8 *)mac);
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100668 }
669 }
670 writel(MII_MODE_ENABLE, &cdev->miisel);
671 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII;
672 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_MII;
673
674 rv = cpsw_register(&cpsw_data);
675 if (rv < 0) {
676 printf("Error %d registering CPSW switch\n", rv);
677 return 0;
678 }
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100679 return rv;
680}
Hannes Schmelzer568cfb42016-02-19 12:09:42 +0100681#endif /* defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD) */
Masahiro Yamada4aa2ba32017-05-09 20:31:39 +0900682#if defined(CONFIG_MMC)
Hannes Petermaier46c8ebc2014-04-08 08:39:20 +0200683int board_mmc_init(bd_t *bis)
684{
Hannes Schmelzerf6877372017-06-13 14:11:29 +0200685 int rc = 0;
686
687 rc |= omap_mmc_init(0, 0, 0, -1, -1);
688 rc |= omap_mmc_init(1, 0, 0, -1, -1);
689
690 return rc;
Hannes Petermaier46c8ebc2014-04-08 08:39:20 +0200691}
692#endif
Hannes Petermaiere52e9cc2015-03-17 15:31:21 +0100693int overwrite_console(void)
694{
695 return 1;
696}