blob: 2d0ed41ddee57f925cfa65b1a588c3775ca2f35c [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>
Hannes Schmelzer008c6b52019-02-06 13:25:59 +010025#include <dm.h>
Hannes Petermaier94360592014-02-07 14:06:50 +010026#include <i2c.h>
27#include <power/tps65217.h>
28#include "../common/bur_common.h"
Hannes Petermaierc96a9b12015-02-03 13:22:39 +010029#include <lcd.h>
Hannes Petermaier94360592014-02-07 14:06:50 +010030
31/* -------------------------------------------------------------------------*/
32/* -- defines for used GPIO Hardware -- */
Hannes Petermaierc96a9b12015-02-03 13:22:39 +010033#define ESC_KEY (0+19)
34#define LCD_PWR (0+5)
35#define PUSH_KEY (0+31)
Hannes Petermaier94360592014-02-07 14:06:50 +010036/* -------------------------------------------------------------------------*/
37/* -- PSOC Resetcontroller Register defines -- */
38
39/* I2C Address of controller */
40#define RSTCTRL_ADDR 0x75
41/* Register for CTRL-word */
42#define RSTCTRL_CTRLREG 0x01
43/* Register for giving some information to VxWorks OS */
44#define RSTCTRL_SCRATCHREG 0x04
45
46/* -- defines for RSTCTRL_CTRLREG -- */
47#define RSTCTRL_FORCE_PWR_NEN 0x0404
Hannes Petermaierc96a9b12015-02-03 13:22:39 +010048#define RSTCTRL_CAN_STB 0x4040
Hannes Petermaier94360592014-02-07 14:06:50 +010049
Hannes Petermaierb6bb11d2015-02-03 13:22:42 +010050DECLARE_GLOBAL_DATA_PTR;
51
Hannes Schmelzer008c6b52019-02-06 13:25:59 +010052static int rstctrl_rw(u8 reg, unsigned char rnw, void *pdat, int size)
53{
54 struct udevice *i2cdev;
55 int rc;
56
57 rc = i2c_get_chip_for_busnum(0, RSTCTRL_ADDR, 1, &i2cdev);
58 if (rc >= 0) {
59 if (rnw)
60 rc = dm_i2c_read(i2cdev, reg, pdat, size);
61 else
62 rc = dm_i2c_write(i2cdev, reg, pdat, size);
63 } else {
64 printf("%s: cannot get udevice for chip 0x%02x!\n",
65 __func__, RSTCTRL_ADDR);
66 }
67
68 return rc;
69}
70
Hannes Petermaier94360592014-02-07 14:06:50 +010071#if defined(CONFIG_SPL_BUILD)
72/* TODO: check ram-timing ! */
73static const struct ddr_data ddr3_data = {
74 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
75 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
76 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
77 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
78};
79static const struct cmd_control ddr3_cmd_ctrl_data = {
80 .cmd0csratio = MT41K256M16HA125E_RATIO,
81 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
82
83 .cmd1csratio = MT41K256M16HA125E_RATIO,
84 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
85
86 .cmd2csratio = MT41K256M16HA125E_RATIO,
87 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
88};
89static struct emif_regs ddr3_emif_reg_data = {
90 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
91 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
92 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
93 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
94 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
95 .zq_config = MT41K256M16HA125E_ZQ_CFG,
96 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
97};
98
99static const struct ctrl_ioregs ddr3_ioregs = {
100 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
101 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
102 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
103 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
104 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
105};
106
107#define OSC (V_OSCK/1000000)
108const struct dpll_params dpll_ddr3 = { 400, OSC-1, 1, -1, -1, -1, -1};
109
110void am33xx_spl_board_init(void)
111{
Hannes Petermaier94360592014-02-07 14:06:50 +0100112 unsigned short buf;
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100113 int rc;
Hannes Petermaier94360592014-02-07 14:06:50 +0100114
115 struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
116 struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;
117 /*
118 * enable additional clocks of modules which are accessed later from
119 * VxWorks OS
120 */
121 u32 *const clk_domains[] = { 0 };
122
Hannes Schmelzer46dc5cb2016-06-22 12:36:14 +0200123 u32 *const clk_modules_xre1specific[] = {
Hannes Petermaier94360592014-02-07 14:06:50 +0100124 &cmwkup->wkup_adctscctrl,
125 &cmper->spi1clkctrl,
126 &cmper->dcan0clkctrl,
127 &cmper->dcan1clkctrl,
128 &cmper->epwmss0clkctrl,
129 &cmper->epwmss1clkctrl,
130 &cmper->epwmss2clkctrl,
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100131 &cmper->lcdclkctrl,
132 &cmper->lcdcclkstctrl,
Hannes Petermaier94360592014-02-07 14:06:50 +0100133 0
134 };
Hannes Schmelzer46dc5cb2016-06-22 12:36:14 +0200135 do_enable_clocks(clk_domains, clk_modules_xre1specific, 1);
Hannes Petermaier94360592014-02-07 14:06:50 +0100136 /* power-OFF LCD-Display */
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100137 if (gpio_request(LCD_PWR, "LCD_PWR") != 0)
138 printf("cannot request gpio for LCD_PWR!\n");
139 else if (gpio_direction_output(LCD_PWR, 0) != 0)
140 printf("cannot set direction output on LCD_PWR!\n");
Hannes Petermaier94360592014-02-07 14:06:50 +0100141
142 /* setup I2C */
Hannes Petermaier2e68d2b2015-03-19 10:43:15 +0100143 enable_i2c_pin_mux();
Hannes Petermaier94360592014-02-07 14:06:50 +0100144
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100145 /* power-ON 3V3 via Resetcontroller */
146 buf = RSTCTRL_FORCE_PWR_NEN | RSTCTRL_CAN_STB;
147 rc = rstctrl_rw(RSTCTRL_CTRLREG, 0, (uint8_t *)&buf, sizeof(buf));
148 if (rc != 0)
149 printf("ERROR: cannot write to resetc (turn on PWR_nEN)\n");
Hannes Petermaier94360592014-02-07 14:06:50 +0100150
Hannes Schmelzer717ee362019-01-31 09:24:45 +0100151 pmicsetup(0, 0);
Hannes Petermaier94360592014-02-07 14:06:50 +0100152}
153
154const struct dpll_params *get_dpll_ddr_params(void)
155{
156 return &dpll_ddr3;
157}
158
159void sdram_init(void)
160{
161 config_ddr(400, &ddr3_ioregs,
162 &ddr3_data,
163 &ddr3_cmd_ctrl_data,
164 &ddr3_emif_reg_data, 0);
165}
166#endif /* CONFIG_SPL_BUILD */
167/*
168 * Basic board specific setup. Pinmux has been handled already.
169 */
170int board_init(void)
171{
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100172 if (power_tps65217_init(0))
173 printf("WARN: cannot setup PMIC 0x24 @ bus #0, not found!.\n");
174
Hannes Petermaier94360592014-02-07 14:06:50 +0100175 return 0;
176}
177
178#ifdef CONFIG_BOARD_LATE_INIT
179int board_late_init(void)
180{
Hannes Petermaier94360592014-02-07 14:06:50 +0100181 const unsigned int toff = 1000;
182 unsigned int cnt = 3;
183 unsigned short buf = 0xAAAA;
Hannes Petermaier7c277992015-02-03 13:22:43 +0100184 unsigned char scratchreg = 0;
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100185 int rc;
Hannes Petermaier94360592014-02-07 14:06:50 +0100186
Hannes Petermaier7c277992015-02-03 13:22:43 +0100187 /* try to read out some boot-instruction from resetcontroller */
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100188 rc = rstctrl_rw(RSTCTRL_SCRATCHREG, 1, &scratchreg, sizeof(scratchreg));
189 if (rc != 0)
190 printf("ERROR: read scratchregister (resetc) failed!\n");
Hannes Petermaier94360592014-02-07 14:06:50 +0100191
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100192 if (gpio_request(ESC_KEY, "boot-key") != 0) {
193 printf("cannot request boot-key!\n");
194 } else if (gpio_get_value(ESC_KEY)) {
Hannes Petermaier94360592014-02-07 14:06:50 +0100195 do {
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100196 lcd_position_cursor(1, 8);
197 switch (cnt) {
198 case 3:
199 lcd_puts(
200 "release ESC-KEY to enter SERVICE-mode.");
201 break;
202 case 2:
203 lcd_puts(
204 "release ESC-KEY to enter DIAGNOSE-mode.");
205 break;
206 case 1:
207 lcd_puts(
208 "release ESC-KEY to enter BOOT-mode. ");
209 break;
210 }
Hannes Petermaier94360592014-02-07 14:06:50 +0100211 mdelay(toff);
212 cnt--;
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100213 if (!gpio_get_value(ESC_KEY) &&
214 gpio_get_value(PUSH_KEY) && 2 == cnt) {
215 lcd_position_cursor(1, 8);
216 lcd_puts(
217 "switching to network-console ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600218 env_set("bootcmd", "run netconsole");
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100219 cnt = 4;
220 break;
221 } else if (!gpio_get_value(ESC_KEY) &&
Hannes Petermaier94360592014-02-07 14:06:50 +0100222 gpio_get_value(PUSH_KEY) && 1 == cnt) {
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100223 lcd_position_cursor(1, 8);
224 lcd_puts(
Hannes Petermaier98267732015-04-24 14:49:39 +0200225 "starting u-boot script from USB ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600226 env_set("bootcmd", "run usbscript");
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100227 cnt = 4;
Hannes Petermaier94360592014-02-07 14:06:50 +0100228 break;
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100229 } else if ((!gpio_get_value(ESC_KEY) &&
230 gpio_get_value(PUSH_KEY) && cnt == 0) ||
231 (gpio_get_value(ESC_KEY) &&
232 gpio_get_value(PUSH_KEY) && cnt == 0)) {
233 lcd_position_cursor(1, 8);
234 lcd_puts(
235 "starting script from network ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600236 env_set("bootcmd", "run netscript");
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100237 cnt = 4;
238 break;
239 } else if (!gpio_get_value(ESC_KEY)) {
Hannes Petermaier94360592014-02-07 14:06:50 +0100240 break;
241 }
242 } while (cnt);
Hannes Petermaier7c277992015-02-03 13:22:43 +0100243 } else if (scratchreg == 0xCC) {
244 lcd_position_cursor(1, 8);
245 lcd_puts(
246 "starting vxworks from network ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600247 env_set("bootcmd", "run netboot");
Hannes Petermaier7c277992015-02-03 13:22:43 +0100248 cnt = 4;
249 } else if (scratchreg == 0xCD) {
250 lcd_position_cursor(1, 8);
251 lcd_puts(
252 "starting script from network ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600253 env_set("bootcmd", "run netscript");
Hannes Petermaier7c277992015-02-03 13:22:43 +0100254 cnt = 4;
255 } else if (scratchreg == 0xCE) {
256 lcd_position_cursor(1, 8);
257 lcd_puts(
258 "starting AR from eMMC ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600259 env_set("bootcmd", "run mmcboot");
Hannes Petermaier7c277992015-02-03 13:22:43 +0100260 cnt = 4;
Hannes Petermaier94360592014-02-07 14:06:50 +0100261 }
262
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100263 lcd_position_cursor(1, 8);
Hannes Petermaier94360592014-02-07 14:06:50 +0100264 switch (cnt) {
265 case 0:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100266 lcd_puts("entering BOOT-mode. ");
Simon Glass6a38e412017-08-03 12:22:09 -0600267 env_set("bootcmd", "run defaultAR");
Hannes Petermaier94360592014-02-07 14:06:50 +0100268 buf = 0x0000;
269 break;
270 case 1:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100271 lcd_puts("entering DIAGNOSE-mode. ");
Hannes Petermaier94360592014-02-07 14:06:50 +0100272 buf = 0x0F0F;
273 break;
274 case 2:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100275 lcd_puts("entering SERVICE mode. ");
Hannes Petermaier94360592014-02-07 14:06:50 +0100276 buf = 0xB4B4;
277 break;
278 case 3:
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100279 lcd_puts("loading OS... ");
Hannes Petermaier94360592014-02-07 14:06:50 +0100280 buf = 0x0404;
281 break;
282 }
Hannes Petermaier94360592014-02-07 14:06:50 +0100283 /* write bootinfo into scratchregister of resetcontroller */
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100284 rc = rstctrl_rw(RSTCTRL_SCRATCHREG, 0, (uint8_t *)&buf, sizeof(buf));
285 if (rc != 0)
286 printf("ERROR: write scratchregister (resetc) failed!\n");
287
Hannes Petermaier73914df2015-09-29 08:43:33 +0200288 /* setup othbootargs for bootvx-command (vxWorks bootline) */
289 char othbootargs[128];
290 snprintf(othbootargs, sizeof(othbootargs),
291 "u=vxWorksFTP pw=vxWorks o=0x%08x;0x%08x;0x%08x;0x%08x",
292 (unsigned int) gd->fb_base-0x20,
Simon Glass22c34c22017-08-03 12:22:13 -0600293 (u32)env_get_ulong("vx_memtop", 16, gd->fb_base-0x20),
294 (u32)env_get_ulong("vx_romfsbase", 16, 0),
295 (u32)env_get_ulong("vx_romfssize", 16, 0));
Simon Glass6a38e412017-08-03 12:22:09 -0600296 env_set("othbootargs", othbootargs);
Hannes Petermaier94360592014-02-07 14:06:50 +0100297 /*
298 * reset VBAR registers to its reset location, VxWorks 6.9.3.2 does
299 * expect that vectors are there, original u-boot moves them to _start
300 */
301 __asm__("ldr r0,=0x20000");
302 __asm__("mcr p15, 0, r0, c12, c0, 0"); /* Set VBAR */
303
304 return 0;
305}
306#endif /* CONFIG_BOARD_LATE_INIT */