4 * common board functions for B&R boards
7 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
9 * SPDX-License-Identifier: GPL-2.0+
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>
28 #include <power/tps65217.h>
32 #include <fdt_support.h>
34 #include "bur_common.h"
35 #include "../../../drivers/video/am335x-fb.h"
38 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
40 DECLARE_GLOBAL_DATA_PTR;
43 #define FDTPROP(b, c) fdt_getprop_u32_default(gd->fdt_blob, b, c, ~0UL)
44 #define PATHTIM "/panel/display-timings/default"
45 #define PATHINF "/panel/panel-info"
47 /* --------------------------------------------------------------------------*/
48 #if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \
49 !defined(CONFIG_SPL_BUILD)
50 int load_lcdtiming(struct am335x_lcdpanel *panel)
52 struct am335x_lcdpanel pnltmp;
56 if (gd->fdt_blob == NULL) {
57 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
60 memcpy(&pnltmp, (void *)panel, sizeof(struct am335x_lcdpanel));
62 pnltmp.hactive = FDTPROP(PATHTIM, "hactive");
63 pnltmp.vactive = FDTPROP(PATHTIM, "vactive");
64 pnltmp.bpp = FDTPROP(PATHINF, "bpp");
65 pnltmp.hfp = FDTPROP(PATHTIM, "hfront-porch");
66 pnltmp.hbp = FDTPROP(PATHTIM, "hback-porch");
67 pnltmp.hsw = FDTPROP(PATHTIM, "hsync-len");
68 pnltmp.vfp = FDTPROP(PATHTIM, "vfront-porch");
69 pnltmp.vbp = FDTPROP(PATHTIM, "vback-porch");
70 pnltmp.vsw = FDTPROP(PATHTIM, "vsync-len");
71 pnltmp.pup_delay = FDTPROP(PATHTIM, "pupdelay");
72 pnltmp.pon_delay = FDTPROP(PATHTIM, "pondelay");
74 /* calc. proper clk-divisor */
75 dtbprop = FDTPROP(PATHTIM, "clock-frequency");
77 pnltmp.pxl_clk_div = 192000000 / dtbprop;
79 pnltmp.pxl_clk_div = ~0UL;
81 /* check polarity of control-signals */
82 dtbprop = FDTPROP(PATHTIM, "hsync-active");
84 pnltmp.pol |= HSYNC_INVERT;
85 dtbprop = FDTPROP(PATHTIM, "vsync-active");
87 pnltmp.pol |= VSYNC_INVERT;
88 dtbprop = FDTPROP(PATHINF, "sync-ctrl");
90 pnltmp.pol |= HSVS_CONTROL;
91 dtbprop = FDTPROP(PATHINF, "sync-edge");
93 pnltmp.pol |= HSVS_RISEFALL;
94 dtbprop = FDTPROP(PATHTIM, "pixelclk-active");
96 pnltmp.pol |= PXCLK_INVERT;
97 dtbprop = FDTPROP(PATHTIM, "de-active");
99 pnltmp.pol |= DE_INVERT;
101 pnltmp.hactive = getenv_ulong("ds1_hactive", 10, ~0UL);
102 pnltmp.vactive = getenv_ulong("ds1_vactive", 10, ~0UL);
103 pnltmp.bpp = getenv_ulong("ds1_bpp", 10, ~0UL);
104 pnltmp.hfp = getenv_ulong("ds1_hfp", 10, ~0UL);
105 pnltmp.hbp = getenv_ulong("ds1_hbp", 10, ~0UL);
106 pnltmp.hsw = getenv_ulong("ds1_hsw", 10, ~0UL);
107 pnltmp.vfp = getenv_ulong("ds1_vfp", 10, ~0UL);
108 pnltmp.vbp = getenv_ulong("ds1_vbp", 10, ~0UL);
109 pnltmp.vsw = getenv_ulong("ds1_vsw", 10, ~0UL);
110 pnltmp.pxl_clk_div = getenv_ulong("ds1_pxlclkdiv", 10, ~0UL);
111 pnltmp.pol = getenv_ulong("ds1_pol", 16, ~0UL);
112 pnltmp.pup_delay = getenv_ulong("ds1_pupdelay", 10, ~0UL);
113 pnltmp.pon_delay = getenv_ulong("ds1_tondelay", 10, ~0UL);
116 ~0UL == (pnltmp.hactive) ||
117 ~0UL == (pnltmp.vactive) ||
118 ~0UL == (pnltmp.bpp) ||
119 ~0UL == (pnltmp.hfp) ||
120 ~0UL == (pnltmp.hbp) ||
121 ~0UL == (pnltmp.hsw) ||
122 ~0UL == (pnltmp.vfp) ||
123 ~0UL == (pnltmp.vbp) ||
124 ~0UL == (pnltmp.vsw) ||
125 ~0UL == (pnltmp.pxl_clk_div) ||
126 ~0UL == (pnltmp.pol) ||
127 ~0UL == (pnltmp.pup_delay) ||
128 ~0UL == (pnltmp.pon_delay)
130 puts("lcd-settings in env/dtb incomplete!\n");
131 printf("display-timings:\n"
145 pnltmp.hactive, pnltmp.vactive, pnltmp.bpp,
146 pnltmp.hfp, pnltmp.hbp, pnltmp.hsw,
147 pnltmp.vfp, pnltmp.vbp, pnltmp.vsw,
148 pnltmp.pxl_clk_div, pnltmp.pol, pnltmp.pon_delay);
152 debug("lcd-settings in env complete, taking over.\n");
153 memcpy((void *)panel,
155 sizeof(struct am335x_lcdpanel));
160 #ifdef CONFIG_USE_FDT
161 static int load_devicetree(void)
165 u32 dtbaddr = getenv_ulong("dtbaddr", 16, 0UL);
168 printf("%s: don't have a valid <dtbaddr> in env!\n", __func__);
173 rc = nand_read_skip_bad(&nand_info[0], 0x40000, (size_t *)&dtbsize,
174 NULL, 0x20000, (u_char *)dtbaddr);
176 char *dtbname = getenv("dtb");
177 char *dtbdev = getenv("dtbdev");
178 char *dtppart = getenv("dtbpart");
179 if (!dtbdev || !dtbdev || !dtbname) {
180 printf("%s: <dtbdev>/<dtbpart>/<dtb> missing.\n", __func__);
184 if (fs_set_blk_dev(dtbdev, dtppart, FS_TYPE_EXT)) {
185 puts("load_devicetree: set_blk_dev failed.\n");
188 rc = fs_read(dtbname, (u32)dtbaddr, 0, 0, &dtbsize);
191 gd->fdt_blob = (void *)dtbaddr;
192 gd->fdt_size = dtbsize;
193 debug("loaded %d bytes of dtb onto 0x%08x\n",
194 (u32)dtbsize, (u32)gd->fdt_blob);
198 printf("%s: load dtb failed!\n", __func__);
202 static const char *dtbmacaddr(u32 ifno)
209 if (gd->fdt_blob == NULL) {
210 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
214 node = fdt_path_offset(gd->fdt_blob, "/aliases");
218 sprintf(enet, "ethernet%d", ifno);
219 path = fdt_getprop(gd->fdt_blob, node, enet, NULL);
221 printf("no alias for %s\n", enet);
225 node = fdt_path_offset(gd->fdt_blob, path);
226 mac = fdt_getprop(gd->fdt_blob, node, "mac-address", &len);
227 if (mac && is_valid_ethaddr((u8 *)mac))
233 static void br_summaryscreen_printdtb(char *prefix,
237 char buf[32] = { 0 };
238 const char *nodep = buf;
243 if (gd->fdt_blob == NULL) {
244 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
248 if (strcmp(name, "brmac1") == 0) {
249 mac = (char *)dtbmacaddr(0);
251 sprintf(buf, "%pM", mac);
252 } else if (strcmp(name, "brmac2") == 0) {
253 mac = (char *)dtbmacaddr(1);
255 sprintf(buf, "%pM", mac);
257 nodeoffset = fdt_path_offset(gd->fdt_blob,
258 "/factory-settings");
259 if (nodeoffset < 0) {
260 puts("no 'factory-settings' in dtb!\n");
263 nodep = fdt_getprop(gd->fdt_blob, nodeoffset, name, &len);
265 if (nodep && strlen(nodep) > 1)
266 lcd_printf("%s %s %s", prefix, nodep, suffix);
270 int ft_board_setup(void *blob, bd_t *bd)
274 nodeoffset = fdt_path_offset(blob, "/factory-settings");
275 if (nodeoffset < 0) {
276 puts("set bootloader version 'factory-settings' not in dtb!\n");
279 if (fdt_setprop(blob, nodeoffset, "bl-version",
280 PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) {
281 puts("set bootloader version 'bl-version' prop. not in dtb!\n");
288 static void br_summaryscreen_printenv(char *prefix,
289 char *name, char *altname,
292 char *envval = getenv(name);
294 lcd_printf("%s %s %s", prefix, envval, suffix);
295 } else if (0 != altname) {
296 envval = getenv(altname);
298 lcd_printf("%s %s %s", prefix, envval, suffix);
304 void br_summaryscreen(void)
306 #ifdef CONFIG_USE_FDT
307 br_summaryscreen_printdtb(" - B&R -", "order-no", "-\n");
308 br_summaryscreen_printdtb(" Serial/Rev :", "serial-no", " /");
309 br_summaryscreen_printdtb(" ", "hw-revision", "\n");
310 br_summaryscreen_printdtb(" MAC (IF1) :", "brmac1", "\n");
311 br_summaryscreen_printdtb(" MAC (IF2) :", "brmac2", "\n");
312 lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
315 br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n");
316 br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n");
317 br_summaryscreen_printenv(" MAC (IF1) :", "br_mac1", "ethaddr", "\n");
318 br_summaryscreen_printenv(" MAC (IF2) :", "br_mac2", 0, "\n");
319 lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
324 void lcdpower(int on)
327 #ifdef CONFIG_USE_FDT
328 if (gd->fdt_blob == NULL) {
329 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
332 pin = FDTPROP(PATHINF, "pwrpin");
334 pin = getenv_ulong("ds1_pwr", 16, ~0UL);
337 puts("no pwrpin in dtb/env, cannot powerup display!\n");
341 for (i = 0; i < 3; i++) {
343 swval = pin & 0x80 ? 0 : 1;
345 gpio_direction_output(pin & 0x7F, swval);
347 gpio_direction_output(pin & 0x7F, !swval);
349 debug("switched pin %d to %d\n", pin & 0x7F, swval);
355 vidinfo_t panel_info = {
357 * give full resolution for allocating enough
365 void lcd_ctrl_init(void *lcdbase)
367 struct am335x_lcdpanel lcd_panel;
368 #ifdef CONFIG_USE_FDT
369 /* TODO: is there a better place to load the dtb ? */
372 memset(&lcd_panel, 0, sizeof(struct am335x_lcdpanel));
373 if (load_lcdtiming(&lcd_panel) != 0)
376 lcd_panel.panel_power_ctrl = &lcdpower;
378 if (0 != am335xfb_init(&lcd_panel))
379 printf("ERROR: failed to initialize video!");
381 * modifiy panel info to 'real' resolution, to operate correct with
384 panel_info.vl_col = lcd_panel.hactive;
385 panel_info.vl_row = lcd_panel.vactive;
387 lcd_set_flush_dcache(1);
390 void lcd_enable(void)
392 #ifdef CONFIG_USE_FDT
393 if (gd->fdt_blob == NULL) {
394 printf("%s: don't have a valid gd->fdt_blob!\n", __func__);
397 unsigned int driver = FDTPROP(PATHINF, "brightdrv");
398 unsigned int bright = FDTPROP(PATHINF, "brightdef");
399 unsigned int pwmfrq = FDTPROP(PATHINF, "brightfdim");
401 unsigned int driver = getenv_ulong("ds1_bright_drv", 16, 0UL);
402 unsigned int bright = getenv_ulong("ds1_bright_def", 10, 50);
403 unsigned int pwmfrq = getenv_ulong("ds1_pwmfreq", 10, ~0UL);
406 struct gptimer *const timerhw = (struct gptimer *)DM_TIMER6_BASE;
408 bright = bright != ~0UL ? bright : 50;
411 case 0: /* PMIC LED-Driver */
412 /* brightness level */
413 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
414 TPS65217_WLEDCTRL2, bright, 0xFF);
416 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
417 TPS65217_WLEDCTRL1, 0x0A, 0xFF);
419 case 1: /* PWM using timer6 */
420 if (pwmfrq != ~0UL) {
421 timerhw->tiocp_cfg = TCFG_RESET;
423 while (timerhw->tiocp_cfg & TCFG_RESET)
425 tmp = ~0UL-(V_OSCK/pwmfrq); /* bottom value */
428 tmp = tmp + ((V_OSCK/pwmfrq)/100) * bright;
430 timerhw->tclr = (TCLR_PT | (2 << TCLR_TRG_SHIFT) |
431 TCLR_CE | TCLR_AR | TCLR_ST);
433 puts("invalid pwmfrq in env/dtb! skip PWM-setup.\n");
437 puts("no suitable backlightdriver in env/dtb!\n");
442 #elif CONFIG_SPL_BUILD
444 #error "LCD-support with a suitable FB-Driver is mandatory !"
445 #endif /* CONFIG_LCD */
447 #ifdef CONFIG_SPL_BUILD
448 void pmicsetup(u32 mpupll)
453 if (i2c_probe(TPS65217_CHIP_PM)) {
454 puts("PMIC (0x24) not found! skip further initalization.\n");
458 /* Get the frequency which is defined by device fuses */
459 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
460 printf("detected max. frequency: %d - ", dpll_mpu_opp100.m);
463 dpll_mpu_opp100.m = MPUPLL_M_1000;
464 printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m);
469 * Increase USB current limit to 1300mA or 1800mA and set
470 * the MPU voltage controller as needed.
472 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
473 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
474 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
476 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
477 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
480 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
481 usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK))
482 puts("tps65217_reg_write failure\n");
484 /* Set DCDC3 (CORE) voltage to 1.125V */
485 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
486 TPS65217_DCDC_VOLT_SEL_1125MV)) {
487 puts("tps65217_voltage_update failure\n");
491 /* Set CORE Frequencies to OPP100 */
492 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
494 /* Set DCDC2 (MPU) voltage */
495 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
496 puts("tps65217_voltage_update failure\n");
500 /* Set LDO3 to 1.8V */
501 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
503 TPS65217_LDO_VOLTAGE_OUT_1_8,
505 puts("tps65217_reg_write failure\n");
506 /* Set LDO4 to 3.3V */
507 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
509 TPS65217_LDO_VOLTAGE_OUT_3_3,
511 puts("tps65217_reg_write failure\n");
513 /* Set MPU Frequency to what we detected now that voltages are set */
514 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
515 /* Set PWR_EN bit in Status Register */
516 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
517 TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF);
520 void set_uart_mux_conf(void)
522 enable_uart0_pin_mux();
525 void set_mux_conf_regs(void)
527 enable_board_pin_mux();
530 #endif /* CONFIG_SPL_BUILD */
532 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
533 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
534 static void cpsw_control(int enabled)
536 /* VTP can be added here */
540 /* describing port offsets of TI's CPSW block */
541 static struct cpsw_slave_data cpsw_slaves[] = {
543 .slave_reg_ofs = 0x208,
544 .sliver_reg_ofs = 0xd80,
548 .slave_reg_ofs = 0x308,
549 .sliver_reg_ofs = 0xdc0,
554 static struct cpsw_platform_data cpsw_data = {
555 .mdio_base = CPSW_MDIO_BASE,
556 .cpsw_base = CPSW_BASE,
559 .cpdma_reg_ofs = 0x800,
561 .slave_data = cpsw_slaves,
562 .ale_reg_ofs = 0xd00,
564 .host_port_reg_ofs = 0x108,
565 .hw_stats_reg_ofs = 0x900,
566 .bd_ram_ofs = 0x2000,
567 .mac_control = (1 << 5),
568 .control = cpsw_control,
570 .version = CPSW_CTRL_VERSION_2,
572 #endif /* CONFIG_DRIVER_TI_CPSW, ... */
574 #if defined(CONFIG_DRIVER_TI_CPSW)
576 int board_eth_init(bd_t *bis)
581 uint32_t mac_hi, mac_lo;
582 /* try reading mac address from efuse */
583 mac_lo = readl(&cdev->macid0l);
584 mac_hi = readl(&cdev->macid0h);
585 mac_addr[0] = mac_hi & 0xFF;
586 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
587 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
588 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
589 mac_addr[4] = mac_lo & 0xFF;
590 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
592 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
593 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
594 if (!getenv("ethaddr")) {
595 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USE_FDT)
596 printf("<ethaddr> not set. trying DTB ... ");
600 printf("<ethaddr> not set. validating E-fuse MAC ... ");
601 if (is_valid_ethaddr((const u8 *)mac_addr))
602 mac = (const char *)mac_addr;
606 printf("using: %pM on ", mac);
607 eth_setenv_enetaddr("ethaddr", (const u8 *)mac);
610 writel(MII_MODE_ENABLE, &cdev->miisel);
611 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII;
612 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_MII;
614 rv = cpsw_register(&cpsw_data);
616 printf("Error %d registering CPSW switch\n", rv);
619 #endif /* CONFIG_DRIVER_TI_CPSW, ... */
622 #endif /* CONFIG_DRIVER_TI_CPSW */
623 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
624 int board_mmc_init(bd_t *bis)
626 return omap_mmc_init(1, 0, 0, -1, -1);
629 int overwrite_console(void)