blob: 0d1c6c47205fb419970f8e983b42d6a781193508 [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 <power/tps65217.h>
27#include "../common/bur_common.h"
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +020028#include "../common/br_resetc.h"
Hannes Petermaier94360592014-02-07 14:06:50 +010029
30/* -------------------------------------------------------------------------*/
31/* -- defines for used GPIO Hardware -- */
Hannes Schmelzer80624c02019-04-10 14:13:15 +020032#define ESC_KEY (0 + 19)
33#define LCD_PWR (0 + 5)
Hannes Petermaier94360592014-02-07 14:06:50 +010034
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +020035#define RSTCTRL_FORCE_PWR_NEN 0x04
36#define RSTCTRL_CAN_STB 0x40
Hannes Petermaier94360592014-02-07 14:06:50 +010037
Hannes Petermaierb6bb11d2015-02-03 13:22:42 +010038DECLARE_GLOBAL_DATA_PTR;
39
Hannes Petermaier94360592014-02-07 14:06:50 +010040#if defined(CONFIG_SPL_BUILD)
Hannes Petermaier94360592014-02-07 14:06:50 +010041static const struct ddr_data ddr3_data = {
42 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
43 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
44 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
45 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
46};
Hannes Schmelzer80624c02019-04-10 14:13:15 +020047
Hannes Petermaier94360592014-02-07 14:06:50 +010048static const struct cmd_control ddr3_cmd_ctrl_data = {
49 .cmd0csratio = MT41K256M16HA125E_RATIO,
50 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
51
52 .cmd1csratio = MT41K256M16HA125E_RATIO,
53 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
54
55 .cmd2csratio = MT41K256M16HA125E_RATIO,
56 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
57};
Hannes Schmelzer80624c02019-04-10 14:13:15 +020058
Hannes Petermaier94360592014-02-07 14:06:50 +010059static struct emif_regs ddr3_emif_reg_data = {
60 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
61 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
62 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
63 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
64 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
65 .zq_config = MT41K256M16HA125E_ZQ_CFG,
66 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
67};
68
69static const struct ctrl_ioregs ddr3_ioregs = {
70 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
71 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
72 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
73 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
74 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
75};
76
Hannes Schmelzer80624c02019-04-10 14:13:15 +020077#define OSC (V_OSCK / 1000000)
78const struct dpll_params dpll_ddr3 = { 400, OSC - 1, 1, -1, -1, -1, -1};
Hannes Petermaier94360592014-02-07 14:06:50 +010079
80void am33xx_spl_board_init(void)
81{
Hannes Schmelzer008c6b52019-02-06 13:25:59 +010082 int rc;
Hannes Petermaier94360592014-02-07 14:06:50 +010083
84 struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
85 struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;
86 /*
87 * enable additional clocks of modules which are accessed later from
88 * VxWorks OS
89 */
90 u32 *const clk_domains[] = { 0 };
91
Hannes Schmelzer46dc5cb2016-06-22 12:36:14 +020092 u32 *const clk_modules_xre1specific[] = {
Hannes Petermaier94360592014-02-07 14:06:50 +010093 &cmwkup->wkup_adctscctrl,
94 &cmper->spi1clkctrl,
95 &cmper->dcan0clkctrl,
96 &cmper->dcan1clkctrl,
97 &cmper->epwmss0clkctrl,
98 &cmper->epwmss1clkctrl,
99 &cmper->epwmss2clkctrl,
Hannes Petermaierc96a9b12015-02-03 13:22:39 +0100100 &cmper->lcdclkctrl,
101 &cmper->lcdcclkstctrl,
Hannes Petermaier94360592014-02-07 14:06:50 +0100102 0
103 };
Hannes Schmelzer46dc5cb2016-06-22 12:36:14 +0200104 do_enable_clocks(clk_domains, clk_modules_xre1specific, 1);
Hannes Petermaier94360592014-02-07 14:06:50 +0100105 /* power-OFF LCD-Display */
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100106 if (gpio_request(LCD_PWR, "LCD_PWR") != 0)
107 printf("cannot request gpio for LCD_PWR!\n");
108 else if (gpio_direction_output(LCD_PWR, 0) != 0)
109 printf("cannot set direction output on LCD_PWR!\n");
Hannes Petermaier94360592014-02-07 14:06:50 +0100110
111 /* setup I2C */
Hannes Petermaier2e68d2b2015-03-19 10:43:15 +0100112 enable_i2c_pin_mux();
Hannes Petermaier94360592014-02-07 14:06:50 +0100113
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100114 /* power-ON 3V3 via Resetcontroller */
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +0200115 rc = br_resetc_regset(RSTCTRL_CTRLREG,
116 RSTCTRL_FORCE_PWR_NEN | RSTCTRL_CAN_STB);
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100117 if (rc != 0)
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +0200118 printf("ERROR: cannot write to resetc (turn on PWR_nEN)!\n");
Hannes Petermaier94360592014-02-07 14:06:50 +0100119
Hannes Schmelzer717ee362019-01-31 09:24:45 +0100120 pmicsetup(0, 0);
Hannes Petermaier94360592014-02-07 14:06:50 +0100121}
122
123const struct dpll_params *get_dpll_ddr_params(void)
124{
125 return &dpll_ddr3;
126}
127
128void sdram_init(void)
129{
130 config_ddr(400, &ddr3_ioregs,
131 &ddr3_data,
132 &ddr3_cmd_ctrl_data,
133 &ddr3_emif_reg_data, 0);
134}
135#endif /* CONFIG_SPL_BUILD */
136/*
137 * Basic board specific setup. Pinmux has been handled already.
138 */
139int board_init(void)
140{
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +0200141 /* request common used gpios */
142 gpio_request(ESC_KEY, "boot-key");
143
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100144 if (power_tps65217_init(0))
145 printf("WARN: cannot setup PMIC 0x24 @ bus #0, not found!.\n");
146
Hannes Petermaier94360592014-02-07 14:06:50 +0100147 return 0;
148}
149
150#ifdef CONFIG_BOARD_LATE_INIT
Hannes Petermaier94360592014-02-07 14:06:50 +0100151
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +0200152int board_boot_key(void)
153{
154 return gpio_get_value(ESC_KEY);
155}
Hannes Petermaier94360592014-02-07 14:06:50 +0100156
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +0200157int board_late_init(void)
158{
159 char othbootargs[128];
Hannes Petermaier94360592014-02-07 14:06:50 +0100160
Hannes Schmelzer08cd4cb2019-04-10 14:13:16 +0200161 br_resetc_bmode();
Hannes Schmelzer008c6b52019-02-06 13:25:59 +0100162
Hannes Petermaier73914df2015-09-29 08:43:33 +0200163 /* setup othbootargs for bootvx-command (vxWorks bootline) */
Hannes Petermaier73914df2015-09-29 08:43:33 +0200164 snprintf(othbootargs, sizeof(othbootargs),
165 "u=vxWorksFTP pw=vxWorks o=0x%08x;0x%08x;0x%08x;0x%08x",
Hannes Schmelzer80624c02019-04-10 14:13:15 +0200166 (u32)gd->fb_base - 0x20,
167 (u32)env_get_ulong("vx_memtop", 16, gd->fb_base - 0x20),
Simon Glass22c34c22017-08-03 12:22:13 -0600168 (u32)env_get_ulong("vx_romfsbase", 16, 0),
169 (u32)env_get_ulong("vx_romfssize", 16, 0));
Simon Glass6a38e412017-08-03 12:22:09 -0600170 env_set("othbootargs", othbootargs);
Hannes Petermaier94360592014-02-07 14:06:50 +0100171 /*
172 * reset VBAR registers to its reset location, VxWorks 6.9.3.2 does
173 * expect that vectors are there, original u-boot moves them to _start
174 */
175 __asm__("ldr r0,=0x20000");
176 __asm__("mcr p15, 0, r0, c12, c0, 0"); /* Set VBAR */
177
178 return 0;
179}
180#endif /* CONFIG_BOARD_LATE_INIT */