blob: 82c53d5bc2bcba6b09c0a1267c2f37349843fd17 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hannes Petermaier94360592014-02-07 14:06:50 +01002/*
3 * board.c
4 *
Hannes Schmelzer46dc5cb2016-06-22 12:36:14 +02005 * Board functions for B&R BRXRE1 Board
Hannes Petermaier94360592014-02-07 14:06:50 +01006 *
Hannes Schmelzer7935f032015-05-28 15:41:12 +02007 * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
Hannes Petermaier94360592014-02-07 14:06:50 +01008 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
9 *
Hannes Petermaier94360592014-02-07 14:06:50 +010010 */
11#include <common.h>
12#include <errno.h>
13#include <spl.h>
14#include <asm/arch/cpu.h>
15#include <asm/arch/hardware.h>
16#include <asm/arch/omap.h>
17#include <asm/arch/ddr_defs.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/gpio.h>
20#include <asm/arch/sys_proto.h>
21#include <asm/arch/mem.h>
22#include <asm/io.h>
23#include <asm/emif.h>
24#include <asm/gpio.h>
25#include <i2c.h>
26#include <power/tps65217.h>
27#include "../common/bur_common.h"
Hannes Petermaierc96a9b12015-02-03 13:22:39 +010028#include <lcd.h>
Hannes Petermaier94360592014-02-07 14:06:50 +010029
30/* -------------------------------------------------------------------------*/
31/* -- defines for used GPIO Hardware -- */
Hannes Petermaierc96a9b12015-02-03 13:22:39 +010032#define ESC_KEY (0+19)
33#define LCD_PWR (0+5)
34#define PUSH_KEY (0+31)
Hannes Petermaier94360592014-02-07 14:06:50 +010035/* -------------------------------------------------------------------------*/
36/* -- PSOC Resetcontroller Register defines -- */
37
38/* I2C Address of controller */
39#define RSTCTRL_ADDR 0x75
40/* Register for CTRL-word */
41#define RSTCTRL_CTRLREG 0x01
42/* Register for giving some information to VxWorks OS */
43#define RSTCTRL_SCRATCHREG 0x04
44
45/* -- defines for RSTCTRL_CTRLREG -- */
46#define RSTCTRL_FORCE_PWR_NEN 0x0404
Hannes Petermaierc96a9b12015-02-03 13:22:39 +010047#define RSTCTRL_CAN_STB 0x4040
Hannes Petermaier94360592014-02-07 14:06:50 +010048
Hannes Petermaierb6bb11d2015-02-03 13:22:42 +010049DECLARE_GLOBAL_DATA_PTR;
50
Hannes Petermaier94360592014-02-07 14:06:50 +010051#if defined(CONFIG_SPL_BUILD)
52/* TODO: check ram-timing ! */
53static const struct ddr_data ddr3_data = {
54 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
55 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
56 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
57 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
58};
59static const struct cmd_control ddr3_cmd_ctrl_data = {
60 .cmd0csratio = MT41K256M16HA125E_RATIO,
61 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
62
63 .cmd1csratio = MT41K256M16HA125E_RATIO,
64 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
65
66 .cmd2csratio = MT41K256M16HA125E_RATIO,
67 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
68};
69static struct emif_regs ddr3_emif_reg_data = {
70 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
71 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
72 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
73 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
74 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
75 .zq_config = MT41K256M16HA125E_ZQ_CFG,
76 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
77};
78
79static const struct ctrl_ioregs ddr3_ioregs = {
80 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
81 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
82 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
83 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
84 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
85};
86
87#define OSC (V_OSCK/1000000)
88const struct dpll_params dpll_ddr3 = { 400, OSC-1, 1, -1, -1, -1, -1};
89
90void am33xx_spl_board_init(void)
91{
92 unsigned int oldspeed;
93 unsigned short buf;
94
95 struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
96 struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;
97 /*
98 * enable additional clocks of modules which are accessed later from
99 * VxWorks OS
100 */
101 u32 *const clk_domains[] = { 0 };
102
Hannes Schmelzer46dc5cb2016-06-22 12:36:14 +0200103 u32 *const clk_modules_xre1specific[] = {
Hannes Petermaier94360592014-02-07 14:06:50 +0100104 &cmwkup->wkup_adctscctrl,
105 &cmper->spi1clkctrl,
106 &cmper->dcan0clkctrl,
107 &cmper->dcan1clkctrl,
108 &cmper->epwmss0clkctrl,
109 &cmper->epwmss1clkctrl,
110 &cmper->epwmss2clkctrl,
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100111 &cmper->lcdclkctrl,
112 &cmper->lcdcclkstctrl,
Hannes Petermaier94360592014-02-07 14:06:50 +0100113 0
114 };
Hannes Schmelzer46dc5cb2016-06-22 12:36:14 +0200115 do_enable_clocks(clk_domains, clk_modules_xre1specific, 1);
Hannes Petermaier94360592014-02-07 14:06:50 +0100116 /* power-OFF LCD-Display */
117 gpio_direction_output(LCD_PWR, 0);
118
119 /* setup I2C */
Hannes Petermaier2e68d2b2015-03-19 10:43:15 +0100120 enable_i2c_pin_mux();
121 i2c_set_bus_num(0);
Hannes Petermaier94360592014-02-07 14:06:50 +0100122 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
123
124 /* power-ON 3V3 via Resetcontroller */
125 oldspeed = i2c_get_bus_speed();
Hannes Petermaierfc375ca2014-03-08 19:09:32 +0100126 if (i2c_set_bus_speed(CONFIG_SYS_OMAP24_I2C_SPEED_PSOC) >= 0) {
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100127 buf = RSTCTRL_FORCE_PWR_NEN | RSTCTRL_CAN_STB;
Hannes Petermaier94360592014-02-07 14:06:50 +0100128 i2c_write(RSTCTRL_ADDR, RSTCTRL_CTRLREG, 1,
129 (uint8_t *)&buf, sizeof(buf));
130 i2c_set_bus_speed(oldspeed);
131 } else {
132 puts("ERROR: i2c_set_bus_speed failed! (turn on PWR_nEN)\n");
133 }
134
Hannes Schmelzer717ee362019-01-31 09:24:45 +0100135 pmicsetup(0, 0);
Hannes Petermaier94360592014-02-07 14:06:50 +0100136}
137
138const struct dpll_params *get_dpll_ddr_params(void)
139{
140 return &dpll_ddr3;
141}
142
143void sdram_init(void)
144{
145 config_ddr(400, &ddr3_ioregs,
146 &ddr3_data,
147 &ddr3_cmd_ctrl_data,
148 &ddr3_emif_reg_data, 0);
149}
150#endif /* CONFIG_SPL_BUILD */
151/*
152 * Basic board specific setup. Pinmux has been handled already.
153 */
154int board_init(void)
155{
156 gpmc_init();
157 return 0;
158}
159
160#ifdef CONFIG_BOARD_LATE_INIT
161int board_late_init(void)
162{
Hannes Petermaier94360592014-02-07 14:06:50 +0100163 const unsigned int toff = 1000;
164 unsigned int cnt = 3;
165 unsigned short buf = 0xAAAA;
Hannes Petermaier7c277992015-02-03 13:22:43 +0100166 unsigned char scratchreg = 0;
Hannes Petermaier94360592014-02-07 14:06:50 +0100167 unsigned int oldspeed;
168
Hannes Petermaier7c277992015-02-03 13:22:43 +0100169 /* try to read out some boot-instruction from resetcontroller */
170 oldspeed = i2c_get_bus_speed();
171 if (i2c_set_bus_speed(CONFIG_SYS_OMAP24_I2C_SPEED_PSOC) >= 0) {
172 i2c_read(RSTCTRL_ADDR, RSTCTRL_SCRATCHREG, 1,
173 &scratchreg, sizeof(scratchreg));
174 i2c_set_bus_speed(oldspeed);
175 } else {
176 puts("ERROR: i2c_set_bus_speed failed! (scratchregister)\n");
177 }
Hannes Petermaier94360592014-02-07 14:06:50 +0100178
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100179 if (gpio_get_value(ESC_KEY)) {
Hannes Petermaier94360592014-02-07 14:06:50 +0100180 do {
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100181 lcd_position_cursor(1, 8);
182 switch (cnt) {
183 case 3:
184 lcd_puts(
185 "release ESC-KEY to enter SERVICE-mode.");
186 break;
187 case 2:
188 lcd_puts(
189 "release ESC-KEY to enter DIAGNOSE-mode.");
190 break;
191 case 1:
192 lcd_puts(
193 "release ESC-KEY to enter BOOT-mode. ");
194 break;
195 }
Hannes Petermaier94360592014-02-07 14:06:50 +0100196 mdelay(toff);
197 cnt--;
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100198 if (!gpio_get_value(ESC_KEY) &&
199 gpio_get_value(PUSH_KEY) && 2 == cnt) {
200 lcd_position_cursor(1, 8);
201 lcd_puts(
202 "switching to network-console ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600203 env_set("bootcmd", "run netconsole");
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100204 cnt = 4;
205 break;
206 } else if (!gpio_get_value(ESC_KEY) &&
Hannes Petermaier94360592014-02-07 14:06:50 +0100207 gpio_get_value(PUSH_KEY) && 1 == cnt) {
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100208 lcd_position_cursor(1, 8);
209 lcd_puts(
Hannes Petermaier98267732015-04-24 14:49:39 +0200210 "starting u-boot script from USB ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600211 env_set("bootcmd", "run usbscript");
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100212 cnt = 4;
Hannes Petermaier94360592014-02-07 14:06:50 +0100213 break;
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100214 } else if ((!gpio_get_value(ESC_KEY) &&
215 gpio_get_value(PUSH_KEY) && cnt == 0) ||
216 (gpio_get_value(ESC_KEY) &&
217 gpio_get_value(PUSH_KEY) && cnt == 0)) {
218 lcd_position_cursor(1, 8);
219 lcd_puts(
220 "starting script from network ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600221 env_set("bootcmd", "run netscript");
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100222 cnt = 4;
223 break;
224 } else if (!gpio_get_value(ESC_KEY)) {
Hannes Petermaier94360592014-02-07 14:06:50 +0100225 break;
226 }
227 } while (cnt);
Hannes Petermaier7c277992015-02-03 13:22:43 +0100228 } else if (scratchreg == 0xCC) {
229 lcd_position_cursor(1, 8);
230 lcd_puts(
231 "starting vxworks from network ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600232 env_set("bootcmd", "run netboot");
Hannes Petermaier7c277992015-02-03 13:22:43 +0100233 cnt = 4;
234 } else if (scratchreg == 0xCD) {
235 lcd_position_cursor(1, 8);
236 lcd_puts(
237 "starting script from network ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600238 env_set("bootcmd", "run netscript");
Hannes Petermaier7c277992015-02-03 13:22:43 +0100239 cnt = 4;
240 } else if (scratchreg == 0xCE) {
241 lcd_position_cursor(1, 8);
242 lcd_puts(
243 "starting AR from eMMC ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600244 env_set("bootcmd", "run mmcboot");
Hannes Petermaier7c277992015-02-03 13:22:43 +0100245 cnt = 4;
Hannes Petermaier94360592014-02-07 14:06:50 +0100246 }
247
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100248 lcd_position_cursor(1, 8);
Hannes Petermaier94360592014-02-07 14:06:50 +0100249 switch (cnt) {
250 case 0:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100251 lcd_puts("entering BOOT-mode. ");
Simon Glass6a38e412017-08-03 12:22:09 -0600252 env_set("bootcmd", "run defaultAR");
Hannes Petermaier94360592014-02-07 14:06:50 +0100253 buf = 0x0000;
254 break;
255 case 1:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100256 lcd_puts("entering DIAGNOSE-mode. ");
Hannes Petermaier94360592014-02-07 14:06:50 +0100257 buf = 0x0F0F;
258 break;
259 case 2:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100260 lcd_puts("entering SERVICE mode. ");
Hannes Petermaier94360592014-02-07 14:06:50 +0100261 buf = 0xB4B4;
262 break;
263 case 3:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100264 lcd_puts("loading OS... ");
Hannes Petermaier94360592014-02-07 14:06:50 +0100265 buf = 0x0404;
266 break;
267 }
Hannes Petermaier94360592014-02-07 14:06:50 +0100268 /* write bootinfo into scratchregister of resetcontroller */
269 oldspeed = i2c_get_bus_speed();
Hannes Petermaierfc375ca2014-03-08 19:09:32 +0100270 if (i2c_set_bus_speed(CONFIG_SYS_OMAP24_I2C_SPEED_PSOC) >= 0) {
Hannes Petermaier94360592014-02-07 14:06:50 +0100271 i2c_write(RSTCTRL_ADDR, RSTCTRL_SCRATCHREG, 1,
272 (uint8_t *)&buf, sizeof(buf));
273 i2c_set_bus_speed(oldspeed);
274 } else {
275 puts("ERROR: i2c_set_bus_speed failed! (scratchregister)\n");
276 }
Hannes Petermaier73914df2015-09-29 08:43:33 +0200277 /* setup othbootargs for bootvx-command (vxWorks bootline) */
278 char othbootargs[128];
279 snprintf(othbootargs, sizeof(othbootargs),
280 "u=vxWorksFTP pw=vxWorks o=0x%08x;0x%08x;0x%08x;0x%08x",
281 (unsigned int) gd->fb_base-0x20,
Simon Glass22c34c22017-08-03 12:22:13 -0600282 (u32)env_get_ulong("vx_memtop", 16, gd->fb_base-0x20),
283 (u32)env_get_ulong("vx_romfsbase", 16, 0),
284 (u32)env_get_ulong("vx_romfssize", 16, 0));
Simon Glass6a38e412017-08-03 12:22:09 -0600285 env_set("othbootargs", othbootargs);
Hannes Petermaier94360592014-02-07 14:06:50 +0100286 /*
287 * reset VBAR registers to its reset location, VxWorks 6.9.3.2 does
288 * expect that vectors are there, original u-boot moves them to _start
289 */
290 __asm__("ldr r0,=0x20000");
291 __asm__("mcr p15, 0, r0, c12, c0, 0"); /* Set VBAR */
292
293 return 0;
294}
295#endif /* CONFIG_BOARD_LATE_INIT */