4 * common board functions for B&R boards
6 * Copyright (C) 2013 Hannes Petermaier <oe5hpm@oevsv.at>
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"
37 static struct ctrl_dev
*cdev
= (struct ctrl_dev
*)CTRL_DEVICE_BASE
;
39 DECLARE_GLOBAL_DATA_PTR
;
42 #define FDTPROP(a, b, c) fdt_getprop_u32_default((void *)a, b, c, ~0UL)
43 #define PATHTIM "/panel/display-timings/default"
44 #define PATHINF "/panel/panel-info"
46 /* --------------------------------------------------------------------------*/
47 #if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \
48 !defined(CONFIG_SPL_BUILD)
49 int load_lcdtiming(struct am335x_lcdpanel
*panel
)
51 struct am335x_lcdpanel pnltmp
;
53 u32 dtbaddr
= getenv_ulong("dtbaddr", 16, ~0UL);
56 if (dtbaddr
== ~0UL) {
57 puts("load_lcdtiming: failed to get 'dtbaddr' from env!\n");
60 memcpy(&pnltmp
, (void *)panel
, sizeof(struct am335x_lcdpanel
));
62 pnltmp
.hactive
= FDTPROP(dtbaddr
, PATHTIM
, "hactive");
63 pnltmp
.vactive
= FDTPROP(dtbaddr
, PATHTIM
, "vactive");
64 pnltmp
.bpp
= FDTPROP(dtbaddr
, PATHINF
, "bpp");
65 pnltmp
.hfp
= FDTPROP(dtbaddr
, PATHTIM
, "hfront-porch");
66 pnltmp
.hbp
= FDTPROP(dtbaddr
, PATHTIM
, "hback-porch");
67 pnltmp
.hsw
= FDTPROP(dtbaddr
, PATHTIM
, "hsync-len");
68 pnltmp
.vfp
= FDTPROP(dtbaddr
, PATHTIM
, "vfront-porch");
69 pnltmp
.vbp
= FDTPROP(dtbaddr
, PATHTIM
, "vback-porch");
70 pnltmp
.vsw
= FDTPROP(dtbaddr
, PATHTIM
, "vsync-len");
71 pnltmp
.pup_delay
= FDTPROP(dtbaddr
, PATHTIM
, "pupdelay");
72 pnltmp
.pon_delay
= FDTPROP(dtbaddr
, PATHTIM
, "pondelay");
74 /* calc. proper clk-divisor */
75 dtbprop
= FDTPROP(dtbaddr
, 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(dtbaddr
, PATHTIM
, "hsync-active");
84 pnltmp
.pol
|= HSYNC_INVERT
;
85 dtbprop
= FDTPROP(dtbaddr
, PATHTIM
, "vsync-active");
87 pnltmp
.pol
|= VSYNC_INVERT
;
88 dtbprop
= FDTPROP(dtbaddr
, PATHINF
, "sync-ctrl");
90 pnltmp
.pol
|= HSVS_CONTROL
;
91 dtbprop
= FDTPROP(dtbaddr
, PATHINF
, "sync-edge");
93 pnltmp
.pol
|= HSVS_RISEFALL
;
94 dtbprop
= FDTPROP(dtbaddr
, PATHTIM
, "pixelclk-active");
96 pnltmp
.pol
|= PXCLK_INVERT
;
97 dtbprop
= FDTPROP(dtbaddr
, 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)
163 char *dtbname
= getenv("dtb");
164 char *dtbdev
= getenv("dtbdev");
165 char *dtppart
= getenv("dtbpart");
166 u32 dtbaddr
= getenv_ulong("dtbaddr", 16, ~0UL);
169 if (!dtbdev
|| !dtbdev
) {
170 puts("load_devicetree: <dtbdev>/<dtbpart> missing.\n");
174 if (fs_set_blk_dev(dtbdev
, dtppart
, FS_TYPE_EXT
)) {
175 puts("load_devicetree: set_blk_dev failed.\n");
178 if (dtbname
&& dtbaddr
!= ~0UL) {
179 if (fs_read(dtbname
, dtbaddr
, 0, 0, &dtbsize
) == 0) {
180 gd
->fdt_blob
= (void *)dtbaddr
;
181 gd
->fdt_size
= dtbsize
;
182 debug("loaded %d bytes of dtb onto 0x%08x\n",
183 (u32
)dtbsize
, dtbaddr
);
186 puts("load_devicetree: load dtb failed,file does not exist!\n");
189 puts("load_devicetree: <dtb>/<dtbaddr> missing!\n");
193 static const char *dtbmacaddr(u32 ifno
)
199 u32 dtbaddr
= getenv_ulong("dtbaddr", 16, ~0UL);
201 if (dtbaddr
== ~0UL) {
202 puts("dtbmacaddr: failed to get 'dtbaddr' from env!\n");
206 node
= fdt_path_offset((void *)dtbaddr
, "/aliases");
210 sprintf(enet
, "ethernet%d", ifno
);
211 path
= fdt_getprop((void *)dtbaddr
, node
, enet
, NULL
);
213 printf("no alias for %s\n", enet
);
217 node
= fdt_path_offset((void *)dtbaddr
, path
);
218 mac
= fdt_getprop((void *)dtbaddr
, node
, "mac-address", &len
);
219 if (mac
&& is_valid_ether_addr((u8
*)mac
))
225 static void br_summaryscreen_printdtb(char *prefix
,
229 u32 dtbaddr
= getenv_ulong("dtbaddr", 16, ~0UL);
230 char buf
[32] = { 0 };
231 const char *nodep
= buf
;
236 if (dtbaddr
== ~0UL) {
237 puts("br_summaryscreen: failed to get 'dtbaddr' from env!\n");
241 if (strcmp(name
, "brmac1") == 0) {
242 mac
= (char *)dtbmacaddr(0);
244 sprintf(buf
, "%pM", mac
);
245 } else if (strcmp(name
, "brmac2") == 0) {
246 mac
= (char *)dtbmacaddr(1);
248 sprintf(buf
, "%pM", mac
);
250 nodeoffset
= fdt_path_offset((void *)dtbaddr
,
251 "/factory-settings");
252 if (nodeoffset
< 0) {
253 puts("no 'factory-settings' in dtb!\n");
256 nodep
= fdt_getprop((void *)dtbaddr
, nodeoffset
, name
, &len
);
258 if (nodep
&& strlen(nodep
) > 1)
259 lcd_printf("%s %s %s", prefix
, nodep
, suffix
);
263 int ft_board_setup(void *blob
, bd_t
*bd
)
267 nodeoffset
= fdt_path_offset(blob
, "/factory-settings");
268 if (nodeoffset
< 0) {
269 puts("set bootloader version 'factory-settings' not in dtb!\n");
272 if (fdt_setprop(blob
, nodeoffset
, "bl-version",
273 PLAIN_VERSION
, strlen(PLAIN_VERSION
)) != 0) {
274 puts("set bootloader version 'bl-version' prop. not in dtb!\n");
281 static void br_summaryscreen_printenv(char *prefix
,
282 char *name
, char *altname
,
285 char *envval
= getenv(name
);
287 lcd_printf("%s %s %s", prefix
, envval
, suffix
);
288 } else if (0 != altname
) {
289 envval
= getenv(altname
);
291 lcd_printf("%s %s %s", prefix
, envval
, suffix
);
297 void br_summaryscreen(void)
299 #ifdef CONFIG_USE_FDT
300 br_summaryscreen_printdtb(" - B&R -", "order-no", "-\n");
301 br_summaryscreen_printdtb(" Serial/Rev :", "serial-no", " /");
302 br_summaryscreen_printdtb(" ", "hw-revision", "\n");
303 br_summaryscreen_printdtb(" MAC (IF1) :", "brmac1", "\n");
304 br_summaryscreen_printdtb(" MAC (IF2) :", "brmac2", "\n");
305 lcd_puts(" Bootloader : " PLAIN_VERSION
"\n");
308 br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n");
309 br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n");
310 br_summaryscreen_printenv(" MAC (IF1) :", "br_mac1", "ethaddr", "\n");
311 br_summaryscreen_printenv(" MAC (IF2) :", "br_mac2", 0, "\n");
312 lcd_puts(" Bootloader : " PLAIN_VERSION
"\n");
317 void lcdpower(int on
)
320 #ifdef CONFIG_USE_FDT
321 u32 dtbaddr
= getenv_ulong("dtbaddr", 16, ~0UL);
323 if (dtbaddr
== ~0UL) {
324 puts("lcdpower: failed to get 'dtbaddr' from env!\n");
327 pin
= FDTPROP(dtbaddr
, PATHINF
, "pwrpin");
329 pin
= getenv_ulong("ds1_pwr", 16, ~0UL);
332 puts("no pwrpin in dtb/env, cannot powerup display!\n");
336 for (i
= 0; i
< 3; i
++) {
338 swval
= pin
& 0x80 ? 0 : 1;
340 gpio_direction_output(pin
& 0x7F, swval
);
342 gpio_direction_output(pin
& 0x7F, !swval
);
344 debug("switched pin %d to %d\n", pin
& 0x7F, swval
);
350 vidinfo_t panel_info
= {
352 * give full resolution for allocating enough
360 void lcd_ctrl_init(void *lcdbase
)
362 struct am335x_lcdpanel lcd_panel
;
363 #ifdef CONFIG_USE_FDT
364 /* TODO: is there a better place to load the dtb ? */
367 memset(&lcd_panel
, 0, sizeof(struct am335x_lcdpanel
));
368 if (load_lcdtiming(&lcd_panel
) != 0)
371 lcd_panel
.panel_power_ctrl
= &lcdpower
;
373 if (0 != am335xfb_init(&lcd_panel
))
374 printf("ERROR: failed to initialize video!");
376 * modifiy panel info to 'real' resolution, to operate correct with
379 panel_info
.vl_col
= lcd_panel
.hactive
;
380 panel_info
.vl_row
= lcd_panel
.vactive
;
382 lcd_set_flush_dcache(1);
385 void lcd_enable(void)
387 #ifdef CONFIG_USE_FDT
388 u32 dtbaddr
= getenv_ulong("dtbaddr", 16, ~0UL);
390 if (dtbaddr
== ~0UL) {
391 puts("lcdpower: failed to get 'dtbaddr' from env!\n");
394 unsigned int driver
= FDTPROP(dtbaddr
, PATHINF
, "brightdrv");
395 unsigned int bright
= FDTPROP(dtbaddr
, PATHINF
, "brightdef");
396 unsigned int pwmfrq
= FDTPROP(dtbaddr
, PATHINF
, "brightfdim");
398 unsigned int driver
= getenv_ulong("ds1_bright_drv", 16, 0UL);
399 unsigned int bright
= getenv_ulong("ds1_bright_def", 10, 50);
400 unsigned int pwmfrq
= getenv_ulong("ds1_pwmfreq", 10, ~0UL);
403 struct gptimer
*const timerhw
= (struct gptimer
*)DM_TIMER6_BASE
;
405 bright
= bright
!= ~0UL ? bright
: 50;
408 case 0: /* PMIC LED-Driver */
409 /* brightness level */
410 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE
,
411 TPS65217_WLEDCTRL2
, bright
, 0xFF);
413 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE
,
414 TPS65217_WLEDCTRL1
, 0x0A, 0xFF);
416 case 1: /* PWM using timer6 */
417 if (pwmfrq
!= ~0UL) {
418 timerhw
->tiocp_cfg
= TCFG_RESET
;
420 while (timerhw
->tiocp_cfg
& TCFG_RESET
)
422 tmp
= ~0UL-(V_OSCK
/pwmfrq
); /* bottom value */
425 tmp
= tmp
+ ((V_OSCK
/pwmfrq
)/100) * bright
;
427 timerhw
->tclr
= (TCLR_PT
| (2 << TCLR_TRG_SHIFT
) |
428 TCLR_CE
| TCLR_AR
| TCLR_ST
);
430 puts("invalid pwmfrq in env/dtb! skip PWM-setup.\n");
434 puts("no suitable backlightdriver in env/dtb!\n");
439 #elif CONFIG_SPL_BUILD
441 #error "LCD-support with a suitable FB-Driver is mandatory !"
442 #endif /* CONFIG_LCD */
444 void blink(u32 blinks
, u32 intervall
, u32 pin
)
446 gpio_direction_output(pin
, 0);
451 gpio_set_value(pin
, val
);
455 gpio_set_value(pin
, 0);
458 #ifdef CONFIG_SPL_BUILD
459 void pmicsetup(u32 mpupll
)
465 enable_i2c0_pin_mux();
466 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED
, CONFIG_SYS_OMAP24_I2C_SLAVE
);
468 if (i2c_probe(TPS65217_CHIP_PM
)) {
469 puts("PMIC (0x24) not found! skip further initalization.\n");
473 /* Get the frequency which is defined by device fuses */
474 dpll_mpu_opp100
.m
= am335x_get_efuse_mpu_max_freq(cdev
);
475 printf("detected max. frequency: %d - ", dpll_mpu_opp100
.m
);
478 dpll_mpu_opp100
.m
= MPUPLL_M_1000
;
479 printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100
.m
);
484 * Increase USB current limit to 1300mA or 1800mA and set
485 * the MPU voltage controller as needed.
487 if (dpll_mpu_opp100
.m
== MPUPLL_M_1000
) {
488 usb_cur_lim
= TPS65217_USB_INPUT_CUR_LIMIT_1800MA
;
489 mpu_vdd
= TPS65217_DCDC_VOLT_SEL_1325MV
;
491 usb_cur_lim
= TPS65217_USB_INPUT_CUR_LIMIT_1300MA
;
492 mpu_vdd
= TPS65217_DCDC_VOLT_SEL_1275MV
;
495 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE
, TPS65217_POWER_PATH
,
496 usb_cur_lim
, TPS65217_USB_INPUT_CUR_LIMIT_MASK
))
497 puts("tps65217_reg_write failure\n");
499 /* Set DCDC3 (CORE) voltage to 1.125V */
500 if (tps65217_voltage_update(TPS65217_DEFDCDC3
,
501 TPS65217_DCDC_VOLT_SEL_1125MV
)) {
502 puts("tps65217_voltage_update failure\n");
506 /* Set CORE Frequencies to OPP100 */
507 do_setup_dpll(&dpll_core_regs
, &dpll_core_opp100
);
509 /* Set DCDC2 (MPU) voltage */
510 if (tps65217_voltage_update(TPS65217_DEFDCDC2
, mpu_vdd
)) {
511 puts("tps65217_voltage_update failure\n");
515 /* Set LDO3 to 1.8V */
516 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2
,
518 TPS65217_LDO_VOLTAGE_OUT_1_8
,
520 puts("tps65217_reg_write failure\n");
521 /* Set LDO4 to 3.3V */
522 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2
,
524 TPS65217_LDO_VOLTAGE_OUT_3_3
,
526 puts("tps65217_reg_write failure\n");
528 /* Set MPU Frequency to what we detected now that voltages are set */
529 do_setup_dpll(&dpll_mpu_regs
, &dpll_mpu_opp100
);
530 /* Set PWR_EN bit in Status Register */
531 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE
,
532 TPS65217_STATUS
, TPS65217_PWR_OFF
, TPS65217_PWR_OFF
);
535 void set_uart_mux_conf(void)
537 enable_uart0_pin_mux();
540 void set_mux_conf_regs(void)
542 enable_board_pin_mux();
545 #endif /* CONFIG_SPL_BUILD */
547 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
548 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
549 static void cpsw_control(int enabled
)
551 /* VTP can be added here */
555 /* describing port offsets of TI's CPSW block */
556 static struct cpsw_slave_data cpsw_slaves
[] = {
558 .slave_reg_ofs
= 0x208,
559 .sliver_reg_ofs
= 0xd80,
563 .slave_reg_ofs
= 0x308,
564 .sliver_reg_ofs
= 0xdc0,
569 static struct cpsw_platform_data cpsw_data
= {
570 .mdio_base
= CPSW_MDIO_BASE
,
571 .cpsw_base
= CPSW_BASE
,
574 .cpdma_reg_ofs
= 0x800,
576 .slave_data
= cpsw_slaves
,
577 .ale_reg_ofs
= 0xd00,
579 .host_port_reg_ofs
= 0x108,
580 .hw_stats_reg_ofs
= 0x900,
581 .bd_ram_ofs
= 0x2000,
582 .mac_control
= (1 << 5),
583 .control
= cpsw_control
,
585 .version
= CPSW_CTRL_VERSION_2
,
587 #endif /* CONFIG_DRIVER_TI_CPSW, ... */
589 #if defined(CONFIG_DRIVER_TI_CPSW)
591 int board_eth_init(bd_t
*bis
)
596 uint32_t mac_hi
, mac_lo
;
597 /* try reading mac address from efuse */
598 mac_lo
= readl(&cdev
->macid0l
);
599 mac_hi
= readl(&cdev
->macid0h
);
600 mac_addr
[0] = mac_hi
& 0xFF;
601 mac_addr
[1] = (mac_hi
& 0xFF00) >> 8;
602 mac_addr
[2] = (mac_hi
& 0xFF0000) >> 16;
603 mac_addr
[3] = (mac_hi
& 0xFF000000) >> 24;
604 mac_addr
[4] = mac_lo
& 0xFF;
605 mac_addr
[5] = (mac_lo
& 0xFF00) >> 8;
607 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
608 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
609 if (!getenv("ethaddr")) {
610 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USE_FDT)
611 printf("<ethaddr> not set. trying DTB ... ");
615 printf("<ethaddr> not set. validating E-fuse MAC ... ");
616 if (is_valid_ether_addr((const u8
*)mac_addr
))
617 mac
= (const char *)mac_addr
;
621 printf("using: %pM on ", mac
);
622 eth_setenv_enetaddr("ethaddr", (const u8
*)mac
);
625 writel(MII_MODE_ENABLE
, &cdev
->miisel
);
626 cpsw_slaves
[0].phy_if
= PHY_INTERFACE_MODE_MII
;
627 cpsw_slaves
[1].phy_if
= PHY_INTERFACE_MODE_MII
;
629 rv
= cpsw_register(&cpsw_data
);
631 printf("Error %d registering CPSW switch\n", rv
);
634 #endif /* CONFIG_DRIVER_TI_CPSW, ... */
637 #endif /* CONFIG_DRIVER_TI_CPSW */
638 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
639 int board_mmc_init(bd_t
*bis
)
641 return omap_mmc_init(1, 0, 0, -1, -1);