blob: a1f7c44abfe7dbf8d478e94c55af7f76762cd9ea [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>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010025#include <power/tps65217.h>
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010026#include <lcd.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010027#include "bur_common.h"
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010028#include "../../../drivers/video/am335x-fb.h"
Hannes Petermaier893c04e2014-02-07 08:07:36 +010029
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010030DECLARE_GLOBAL_DATA_PTR;
31
Hannes Petermaier893c04e2014-02-07 08:07:36 +010032/* --------------------------------------------------------------------------*/
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010033#if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \
34 !defined(CONFIG_SPL_BUILD)
Hannes Petermaier99f72472015-04-24 14:49:37 +020035void lcdbacklight(int on)
36{
Simon Glassbfebc8c2017-08-03 12:22:13 -060037 unsigned int driver = env_get_ulong("ds1_bright_drv", 16, 0UL);
38 unsigned int bright = env_get_ulong("ds1_bright_def", 10, 50);
39 unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL);
Hannes Petermaier99f72472015-04-24 14:49:37 +020040 unsigned int tmp;
Hannes Petermaier9b63ba32015-06-11 12:25:43 +020041 struct gptimer *timerhw;
Hannes Petermaier99f72472015-04-24 14:49:37 +020042
43 if (on)
44 bright = bright != ~0UL ? bright : 50;
45 else
46 bright = 0;
47
48 switch (driver) {
Hannes Petermaier9b63ba32015-06-11 12:25:43 +020049 case 2:
50 timerhw = (struct gptimer *)DM_TIMER5_BASE;
51 break;
52 default:
53 timerhw = (struct gptimer *)DM_TIMER6_BASE;
54 }
55
56 switch (driver) {
Hannes Petermaier99f72472015-04-24 14:49:37 +020057 case 0: /* PMIC LED-Driver */
58 /* brightness level */
59 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
60 TPS65217_WLEDCTRL2, bright, 0xFF);
61 /* current sink */
62 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
63 TPS65217_WLEDCTRL1,
64 bright != 0 ? 0x0A : 0x02,
65 0xFF);
66 break;
Hannes Petermaier9b63ba32015-06-11 12:25:43 +020067 case 1:
68 case 2: /* PWM using timer */
Hannes Petermaier99f72472015-04-24 14:49:37 +020069 if (pwmfrq != ~0UL) {
70 timerhw->tiocp_cfg = TCFG_RESET;
71 udelay(10);
72 while (timerhw->tiocp_cfg & TCFG_RESET)
73 ;
74 tmp = ~0UL-(V_OSCK/pwmfrq); /* bottom value */
75 timerhw->tldr = tmp;
76 timerhw->tcrr = tmp;
77 tmp = tmp + ((V_OSCK/pwmfrq)/100) * bright;
78 timerhw->tmar = tmp;
79 timerhw->tclr = (TCLR_PT | (2 << TCLR_TRG_SHIFT) |
80 TCLR_CE | TCLR_AR | TCLR_ST);
81 } else {
82 puts("invalid pwmfrq in env/dtb! skip PWM-setup.\n");
83 }
84 break;
85 default:
86 puts("no suitable backlightdriver in env/dtb!\n");
87 break;
88 }
89}
90
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010091int load_lcdtiming(struct am335x_lcdpanel *panel)
92{
93 struct am335x_lcdpanel pnltmp;
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010094
Simon Glassbfebc8c2017-08-03 12:22:13 -060095 pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL);
96 pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL);
97 pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL);
98 pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL);
99 pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL);
100 pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL);
101 pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL);
102 pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL);
103 pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL);
Hannes Schmelzer0fcec572018-01-09 19:01:35 +0100104 pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL);
Simon Glassbfebc8c2017-08-03 12:22:13 -0600105 pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL);
106 pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL);
107 pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL);
108 panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0);
Hannes Schmelzere31fb4d2018-07-06 15:41:18 +0200109
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100110 if (
111 ~0UL == (pnltmp.hactive) ||
112 ~0UL == (pnltmp.vactive) ||
113 ~0UL == (pnltmp.bpp) ||
114 ~0UL == (pnltmp.hfp) ||
115 ~0UL == (pnltmp.hbp) ||
116 ~0UL == (pnltmp.hsw) ||
117 ~0UL == (pnltmp.vfp) ||
118 ~0UL == (pnltmp.vbp) ||
119 ~0UL == (pnltmp.vsw) ||
Hannes Schmelzer0fcec572018-01-09 19:01:35 +0100120 ~0UL == (pnltmp.pxl_clk) ||
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100121 ~0UL == (pnltmp.pol) ||
122 ~0UL == (pnltmp.pup_delay) ||
123 ~0UL == (pnltmp.pon_delay)
124 ) {
125 puts("lcd-settings in env/dtb incomplete!\n");
126 printf("display-timings:\n"
127 "================\n"
128 "hactive: %d\n"
129 "vactive: %d\n"
130 "bpp : %d\n"
131 "hfp : %d\n"
132 "hbp : %d\n"
133 "hsw : %d\n"
134 "vfp : %d\n"
135 "vbp : %d\n"
136 "vsw : %d\n"
137 "pxlclk : %d\n"
138 "pol : 0x%08x\n"
139 "pondly : %d\n",
140 pnltmp.hactive, pnltmp.vactive, pnltmp.bpp,
141 pnltmp.hfp, pnltmp.hbp, pnltmp.hsw,
142 pnltmp.vfp, pnltmp.vbp, pnltmp.vsw,
Hannes Schmelzer0fcec572018-01-09 19:01:35 +0100143 pnltmp.pxl_clk, pnltmp.pol, pnltmp.pon_delay);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100144
145 return -1;
146 }
147 debug("lcd-settings in env complete, taking over.\n");
148 memcpy((void *)panel,
149 (void *)&pnltmp,
150 sizeof(struct am335x_lcdpanel));
151
152 return 0;
153}
154
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100155static void br_summaryscreen_printenv(char *prefix,
156 char *name, char *altname,
157 char *suffix)
158{
Simon Glass00caae62017-08-03 12:22:12 -0600159 char *envval = env_get(name);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100160 if (0 != envval) {
161 lcd_printf("%s %s %s", prefix, envval, suffix);
162 } else if (0 != altname) {
Simon Glass00caae62017-08-03 12:22:12 -0600163 envval = env_get(altname);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100164 if (0 != envval)
165 lcd_printf("%s %s %s", prefix, envval, suffix);
166 } else {
167 lcd_printf("\n");
168 }
169}
Hannes Schmelzere31fb4d2018-07-06 15:41:18 +0200170
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100171void br_summaryscreen(void)
172{
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100173 br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n");
174 br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n");
Hannes Schmelzer29309412018-07-06 15:41:22 +0200175 br_summaryscreen_printenv(" MAC1 :", "br_mac1", "ethaddr", "\n");
176 br_summaryscreen_printenv(" MAC2 :", "br_mac2", 0, "\n");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100177 lcd_puts(" Bootloader : " PLAIN_VERSION "\n");
178 lcd_puts("\n");
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100179}
180
181void lcdpower(int on)
182{
183 u32 pin, swval, i;
Hannes Schmelzere31fb4d2018-07-06 15:41:18 +0200184
Simon Glassbfebc8c2017-08-03 12:22:13 -0600185 pin = env_get_ulong("ds1_pwr", 16, ~0UL);
Hannes Schmelzere31fb4d2018-07-06 15:41:18 +0200186
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100187 if (pin == ~0UL) {
188 puts("no pwrpin in dtb/env, cannot powerup display!\n");
189 return;
190 }
191
192 for (i = 0; i < 3; i++) {
193 if (pin != 0) {
194 swval = pin & 0x80 ? 0 : 1;
195 if (on)
196 gpio_direction_output(pin & 0x7F, swval);
197 else
198 gpio_direction_output(pin & 0x7F, !swval);
199
200 debug("switched pin %d to %d\n", pin & 0x7F, swval);
201 }
202 pin >>= 8;
203 }
204}
205
206vidinfo_t panel_info = {
207 .vl_col = 1366, /*
208 * give full resolution for allocating enough
209 * memory
210 */
211 .vl_row = 768,
212 .vl_bpix = 5,
213 .priv = 0
214};
215
216void lcd_ctrl_init(void *lcdbase)
217{
218 struct am335x_lcdpanel lcd_panel;
Hannes Schmelzere31fb4d2018-07-06 15:41:18 +0200219
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100220 memset(&lcd_panel, 0, sizeof(struct am335x_lcdpanel));
221 if (load_lcdtiming(&lcd_panel) != 0)
222 return;
223
224 lcd_panel.panel_power_ctrl = &lcdpower;
225
226 if (0 != am335xfb_init(&lcd_panel))
227 printf("ERROR: failed to initialize video!");
228 /*
229 * modifiy panel info to 'real' resolution, to operate correct with
230 * lcd-framework.
231 */
232 panel_info.vl_col = lcd_panel.hactive;
233 panel_info.vl_row = lcd_panel.vactive;
234
235 lcd_set_flush_dcache(1);
236}
237
238void lcd_enable(void)
239{
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100240 br_summaryscreen();
Hannes Petermaier99f72472015-04-24 14:49:37 +0200241 lcdbacklight(1);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100242}
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100243#endif /* CONFIG_LCD */
244
Hannes Schmelzere2259702018-07-06 15:41:20 +0200245int ft_board_setup(void *blob, bd_t *bd)
246{
247 int nodeoffset;
248
249 nodeoffset = fdt_path_offset(blob, "/factory-settings");
250 if (nodeoffset < 0) {
Hannes Schmelzerd63f7132018-07-06 15:41:25 +0200251 printf("%s: cannot find /factory-settings, trying /fset\n",
252 __func__);
253 nodeoffset = fdt_path_offset(blob, "/fset");
254 if (nodeoffset < 0) {
255 printf("%s: cannot find /fset.\n", __func__);
256 return 0;
257 }
Hannes Schmelzere2259702018-07-06 15:41:20 +0200258 }
259
Hannes Schmelzerd63f7132018-07-06 15:41:25 +0200260 if (fdt_setprop(blob, nodeoffset, "bl-version",
261 PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) {
262 printf("%s: no 'bl-version' prop in fdt!\n", __func__);
263 return 0;
264 }
Hannes Schmelzere2259702018-07-06 15:41:20 +0200265 return 0;
266}
267
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100268#ifdef CONFIG_SPL_BUILD
Hannes Schmelzerfbc7c7d2018-07-06 15:41:28 +0200269
270static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
271
Hannes Schmelzera9484aa2019-01-31 09:24:45 +0100272void pmicsetup(u32 mpupll, unsigned int bus)
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100273{
274 int mpu_vdd;
275 int usb_cur_lim;
276
Hannes Schmelzera9484aa2019-01-31 09:24:45 +0100277 if (power_tps65217_init(bus)) {
278 printf("WARN: cannot setup PMIC 0x24 @ bus #%d, not found!.\n",
279 bus);
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100280 return;
281 }
282
283 /* Get the frequency which is defined by device fuses */
284 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
285 printf("detected max. frequency: %d - ", dpll_mpu_opp100.m);
286
287 if (0 != mpupll) {
Hannes Schmelzer96cf89f2018-07-06 15:41:23 +0200288 dpll_mpu_opp100.m = mpupll;
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100289 printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m);
290 } else {
291 puts("ok.\n");
292 }
293 /*
294 * Increase USB current limit to 1300mA or 1800mA and set
295 * the MPU voltage controller as needed.
296 */
297 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
298 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
299 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
300 } else {
301 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
302 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
303 }
304
305 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
306 usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK))
307 puts("tps65217_reg_write failure\n");
308
309 /* Set DCDC3 (CORE) voltage to 1.125V */
310 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
311 TPS65217_DCDC_VOLT_SEL_1125MV)) {
312 puts("tps65217_voltage_update failure\n");
313 return;
314 }
315
316 /* Set CORE Frequencies to OPP100 */
317 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
318
319 /* Set DCDC2 (MPU) voltage */
320 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
321 puts("tps65217_voltage_update failure\n");
322 return;
323 }
324
325 /* Set LDO3 to 1.8V */
326 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
327 TPS65217_DEFLS1,
328 TPS65217_LDO_VOLTAGE_OUT_1_8,
329 TPS65217_LDO_MASK))
330 puts("tps65217_reg_write failure\n");
331 /* Set LDO4 to 3.3V */
332 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
333 TPS65217_DEFLS2,
334 TPS65217_LDO_VOLTAGE_OUT_3_3,
335 TPS65217_LDO_MASK))
336 puts("tps65217_reg_write failure\n");
337
338 /* Set MPU Frequency to what we detected now that voltages are set */
339 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100340 /* Set PWR_EN bit in Status Register */
341 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
342 TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF);
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100343}
344
345void set_uart_mux_conf(void)
346{
347 enable_uart0_pin_mux();
348}
349
350void set_mux_conf_regs(void)
351{
352 enable_board_pin_mux();
353}
354
355#endif /* CONFIG_SPL_BUILD */
356
Hannes Petermaiere52e9cc2015-03-17 15:31:21 +0100357int overwrite_console(void)
358{
359 return 1;
360}