1 // SPDX-License-Identifier: GPL-2.0+
5 * common board functions for B&R boards
7 * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
8 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
17 #include "bur_common.h"
19 DECLARE_GLOBAL_DATA_PTR;
21 /* --------------------------------------------------------------------------*/
22 #if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \
23 !defined(CONFIG_DM_VIDEO) && !defined(CONFIG_SPL_BUILD)
24 #include <asm/arch/hardware.h>
25 #include <asm/arch/cpu.h>
27 #include <power/tps65217.h>
28 #include "../../../drivers/video/am335x-fb.h"
30 void lcdbacklight(int on)
32 unsigned int driver = env_get_ulong("ds1_bright_drv", 16, 0UL);
33 unsigned int bright = env_get_ulong("ds1_bright_def", 10, 50);
34 unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL);
36 struct gptimer *timerhw;
39 bright = bright != ~0UL ? bright : 50;
45 timerhw = (struct gptimer *)DM_TIMER5_BASE;
48 timerhw = (struct gptimer *)DM_TIMER6_BASE;
52 case 0: /* PMIC LED-Driver */
53 /* brightness level */
54 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
55 TPS65217_WLEDCTRL2, bright, 0xFF);
57 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
59 bright != 0 ? 0x0A : 0x02,
63 case 2: /* PWM using timer */
65 timerhw->tiocp_cfg = TCFG_RESET;
67 while (timerhw->tiocp_cfg & TCFG_RESET)
69 tmp = ~0UL-(V_OSCK/pwmfrq); /* bottom value */
72 tmp = tmp + ((V_OSCK/pwmfrq)/100) * bright;
74 timerhw->tclr = (TCLR_PT | (2 << TCLR_TRG_SHIFT) |
75 TCLR_CE | TCLR_AR | TCLR_ST);
77 puts("invalid pwmfrq in env/dtb! skip PWM-setup.\n");
81 puts("no suitable backlightdriver in env/dtb!\n");
86 int load_lcdtiming(struct am335x_lcdpanel *panel)
88 struct am335x_lcdpanel pnltmp;
90 pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL);
91 pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL);
92 pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL);
93 pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL);
94 pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL);
95 pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL);
96 pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL);
97 pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL);
98 pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL);
99 pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL);
100 pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL);
101 pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL);
102 pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL);
103 panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0);
106 ~0UL == (pnltmp.hactive) ||
107 ~0UL == (pnltmp.vactive) ||
108 ~0UL == (pnltmp.bpp) ||
109 ~0UL == (pnltmp.hfp) ||
110 ~0UL == (pnltmp.hbp) ||
111 ~0UL == (pnltmp.hsw) ||
112 ~0UL == (pnltmp.vfp) ||
113 ~0UL == (pnltmp.vbp) ||
114 ~0UL == (pnltmp.vsw) ||
115 ~0UL == (pnltmp.pxl_clk) ||
116 ~0UL == (pnltmp.pol) ||
117 ~0UL == (pnltmp.pup_delay) ||
118 ~0UL == (pnltmp.pon_delay)
120 puts("lcd-settings in env/dtb incomplete!\n");
121 printf("display-timings:\n"
135 pnltmp.hactive, pnltmp.vactive, pnltmp.bpp,
136 pnltmp.hfp, pnltmp.hbp, pnltmp.hsw,
137 pnltmp.vfp, pnltmp.vbp, pnltmp.vsw,
138 pnltmp.pxl_clk, pnltmp.pol, pnltmp.pon_delay);
142 debug("lcd-settings in env complete, taking over.\n");
143 memcpy((void *)panel,
145 sizeof(struct am335x_lcdpanel));
150 static void br_summaryscreen_printenv(char *prefix,
151 char *name, char *altname,
154 char *envval = env_get(name);
156 lcd_printf("%s %s %s", prefix, envval, suffix);
157 } else if (0 != altname) {
158 envval = env_get(altname);
160 lcd_printf("%s %s %s", prefix, envval, suffix);
166 void br_summaryscreen(void)
168 br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n");
169 br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n");
170 br_summaryscreen_printenv(" MAC1 :", "br_mac1", "ethaddr", "\n");
171 br_summaryscreen_printenv(" MAC2 :", "br_mac2", 0, "\n");
172 lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
176 void lcdpower(int on)
179 char buf[16] = { 0 };
181 pin = env_get_ulong("ds1_pwr", 16, ~0UL);
184 puts("no pwrpin in dtb/env, cannot powerup display!\n");
188 for (i = 0; i < 3; i++) {
190 snprintf(buf, sizeof(buf), "ds1_pwr#%d", i);
191 if (gpio_request(pin & 0x7F, buf) != 0) {
192 printf("%s: not able to request gpio %s",
196 swval = pin & 0x80 ? 0 : 1;
198 gpio_direction_output(pin & 0x7F, swval);
200 gpio_direction_output(pin & 0x7F, !swval);
202 debug("switched pin %d to %d\n", pin & 0x7F, swval);
208 vidinfo_t panel_info = {
210 * give full resolution for allocating enough
218 void lcd_ctrl_init(void *lcdbase)
220 struct am335x_lcdpanel lcd_panel;
222 memset(&lcd_panel, 0, sizeof(struct am335x_lcdpanel));
223 if (load_lcdtiming(&lcd_panel) != 0)
226 lcd_panel.panel_power_ctrl = &lcdpower;
228 if (0 != am335xfb_init(&lcd_panel))
229 printf("ERROR: failed to initialize video!");
231 * modifiy panel info to 'real' resolution, to operate correct with
234 panel_info.vl_col = lcd_panel.hactive;
235 panel_info.vl_row = lcd_panel.vactive;
237 lcd_set_flush_dcache(1);
240 void lcd_enable(void)
245 #endif /* CONFIG_LCD */
247 int ft_board_setup(void *blob, bd_t *bd)
251 nodeoffset = fdt_path_offset(blob, "/factory-settings");
252 if (nodeoffset < 0) {
253 printf("%s: cannot find /factory-settings, trying /fset\n",
255 nodeoffset = fdt_path_offset(blob, "/fset");
256 if (nodeoffset < 0) {
257 printf("%s: cannot find /fset.\n", __func__);
262 if (fdt_setprop(blob, nodeoffset, "bl-version",
263 PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) {
264 printf("%s: no 'bl-version' prop in fdt!\n", __func__);
270 int brdefaultip_setup(int bus, int chip)
273 struct udevice *i2cdev;
275 char defip[256] = { 0 };
277 rc = i2c_get_chip_for_busnum(bus, chip, 2, &i2cdev);
279 printf("WARN: cannot probe baseboard EEPROM!\n");
283 rc = dm_i2c_read(i2cdev, 0, &u8buf, 1);
285 printf("WARN: cannot read baseboard EEPROM!\n");
290 snprintf(defip, sizeof(defip),
291 "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.%d; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;",
295 "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.1; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;",
298 env_set("brdefaultip", defip);
299 env_set_hex("board_id", u8buf);
304 int overwrite_console(void)
309 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_AM33XX)
310 #include <asm/arch/hardware.h>
311 #include <asm/arch/omap.h>
312 #include <asm/arch/clock.h>
313 #include <asm/arch/sys_proto.h>
314 #include <power/tps65217.h>
316 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
318 void pmicsetup(u32 mpupll, unsigned int bus)
323 if (power_tps65217_init(bus)) {
324 printf("WARN: cannot setup PMIC 0x24 @ bus #%d, not found!.\n",
329 /* Get the frequency which is defined by device fuses */
330 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
331 printf("detected max. frequency: %d - ", dpll_mpu_opp100.m);
334 dpll_mpu_opp100.m = mpupll;
335 printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m);
340 * Increase USB current limit to 1300mA or 1800mA and set
341 * the MPU voltage controller as needed.
343 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
344 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
345 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
347 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
348 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
351 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
352 usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK))
353 puts("tps65217_reg_write failure\n");
355 /* Set DCDC3 (CORE) voltage to 1.125V */
356 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
357 TPS65217_DCDC_VOLT_SEL_1125MV)) {
358 puts("tps65217_voltage_update failure\n");
362 /* Set CORE Frequencies to OPP100 */
363 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
365 /* Set DCDC2 (MPU) voltage */
366 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
367 puts("tps65217_voltage_update failure\n");
371 /* Set LDO3 to 1.8V */
372 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
374 TPS65217_LDO_VOLTAGE_OUT_1_8,
376 puts("tps65217_reg_write failure\n");
377 /* Set LDO4 to 3.3V */
378 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
380 TPS65217_LDO_VOLTAGE_OUT_3_3,
382 puts("tps65217_reg_write failure\n");
384 /* Set MPU Frequency to what we detected now that voltages are set */
385 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
386 /* Set PWR_EN bit in Status Register */
387 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
388 TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF);
391 void set_uart_mux_conf(void)
393 enable_uart0_pin_mux();
396 void set_mux_conf_regs(void)
398 enable_board_pin_mux();
401 #endif /* CONFIG_SPL_BUILD && CONFIG_AM33XX */