Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 2 | /* |
| 3 | * board.c |
| 4 | * |
Hannes Schmelzer | a4d7999 | 2016-06-22 12:36:14 +0200 | [diff] [blame] | 5 | * Board functions for B&R BRXRE1 Board |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 6 | * |
Hannes Schmelzer | 4c302b9 | 2015-05-28 15:41:12 +0200 | [diff] [blame] | 7 | * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at> |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 8 | * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com |
| 9 | * |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 10 | */ |
| 11 | #include <common.h> |
Simon Glass | 9eef56d | 2019-08-01 09:46:48 -0600 | [diff] [blame] | 12 | #include <env.h> |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 13 | #include <errno.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 15 | #include <spl.h> |
| 16 | #include <asm/arch/cpu.h> |
| 17 | #include <asm/arch/hardware.h> |
| 18 | #include <asm/arch/omap.h> |
| 19 | #include <asm/arch/ddr_defs.h> |
| 20 | #include <asm/arch/clock.h> |
| 21 | #include <asm/arch/gpio.h> |
| 22 | #include <asm/arch/sys_proto.h> |
| 23 | #include <asm/arch/mem.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 24 | #include <asm/global_data.h> |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 25 | #include <asm/io.h> |
| 26 | #include <asm/emif.h> |
| 27 | #include <asm/gpio.h> |
Hannes Schmelzer | eaba7df | 2019-02-06 13:25:59 +0100 | [diff] [blame] | 28 | #include <dm.h> |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 29 | #include <power/tps65217.h> |
| 30 | #include "../common/bur_common.h" |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 31 | #include "../common/br_resetc.h" |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 32 | |
| 33 | /* -------------------------------------------------------------------------*/ |
| 34 | /* -- defines for used GPIO Hardware -- */ |
Hannes Schmelzer | 2b1e242 | 2019-04-10 14:13:15 +0200 | [diff] [blame] | 35 | #define ESC_KEY (0 + 19) |
| 36 | #define LCD_PWR (0 + 5) |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 37 | |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 38 | #define RSTCTRL_FORCE_PWR_NEN 0x04 |
| 39 | #define RSTCTRL_CAN_STB 0x40 |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 40 | |
Hannes Petermaier | a964292 | 2015-02-03 13:22:42 +0100 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 43 | #if defined(CONFIG_SPL_BUILD) |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 44 | static const struct ddr_data ddr3_data = { |
| 45 | .datardsratio0 = MT41K256M16HA125E_RD_DQS, |
| 46 | .datawdsratio0 = MT41K256M16HA125E_WR_DQS, |
| 47 | .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE, |
| 48 | .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA, |
| 49 | }; |
Hannes Schmelzer | 2b1e242 | 2019-04-10 14:13:15 +0200 | [diff] [blame] | 50 | |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 51 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
| 52 | .cmd0csratio = MT41K256M16HA125E_RATIO, |
| 53 | .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 54 | |
| 55 | .cmd1csratio = MT41K256M16HA125E_RATIO, |
| 56 | .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 57 | |
| 58 | .cmd2csratio = MT41K256M16HA125E_RATIO, |
| 59 | .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT, |
| 60 | }; |
Hannes Schmelzer | 2b1e242 | 2019-04-10 14:13:15 +0200 | [diff] [blame] | 61 | |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 62 | static struct emif_regs ddr3_emif_reg_data = { |
| 63 | .sdram_config = MT41K256M16HA125E_EMIF_SDCFG, |
| 64 | .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF, |
| 65 | .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1, |
| 66 | .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2, |
| 67 | .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3, |
| 68 | .zq_config = MT41K256M16HA125E_ZQ_CFG, |
| 69 | .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY, |
| 70 | }; |
| 71 | |
| 72 | static const struct ctrl_ioregs ddr3_ioregs = { |
| 73 | .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 74 | .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 75 | .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 76 | .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 77 | .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE, |
| 78 | }; |
| 79 | |
Hannes Schmelzer | 2b1e242 | 2019-04-10 14:13:15 +0200 | [diff] [blame] | 80 | #define OSC (V_OSCK / 1000000) |
| 81 | const struct dpll_params dpll_ddr3 = { 400, OSC - 1, 1, -1, -1, -1, -1}; |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 82 | |
| 83 | void am33xx_spl_board_init(void) |
| 84 | { |
Hannes Schmelzer | eaba7df | 2019-02-06 13:25:59 +0100 | [diff] [blame] | 85 | int rc; |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 86 | |
| 87 | struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER; |
| 88 | struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP; |
| 89 | /* |
| 90 | * enable additional clocks of modules which are accessed later from |
| 91 | * VxWorks OS |
| 92 | */ |
| 93 | u32 *const clk_domains[] = { 0 }; |
| 94 | |
Hannes Schmelzer | a4d7999 | 2016-06-22 12:36:14 +0200 | [diff] [blame] | 95 | u32 *const clk_modules_xre1specific[] = { |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 96 | &cmwkup->wkup_adctscctrl, |
| 97 | &cmper->spi1clkctrl, |
| 98 | &cmper->dcan0clkctrl, |
| 99 | &cmper->dcan1clkctrl, |
| 100 | &cmper->epwmss0clkctrl, |
| 101 | &cmper->epwmss1clkctrl, |
| 102 | &cmper->epwmss2clkctrl, |
Hannes Petermaier | cf630f2 | 2015-02-03 13:22:39 +0100 | [diff] [blame] | 103 | &cmper->lcdclkctrl, |
| 104 | &cmper->lcdcclkstctrl, |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 105 | 0 |
| 106 | }; |
Hannes Schmelzer | a4d7999 | 2016-06-22 12:36:14 +0200 | [diff] [blame] | 107 | do_enable_clocks(clk_domains, clk_modules_xre1specific, 1); |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 108 | /* power-OFF LCD-Display */ |
Hannes Schmelzer | eaba7df | 2019-02-06 13:25:59 +0100 | [diff] [blame] | 109 | if (gpio_request(LCD_PWR, "LCD_PWR") != 0) |
| 110 | printf("cannot request gpio for LCD_PWR!\n"); |
| 111 | else if (gpio_direction_output(LCD_PWR, 0) != 0) |
| 112 | printf("cannot set direction output on LCD_PWR!\n"); |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 113 | |
| 114 | /* setup I2C */ |
Hannes Petermaier | 2b5b2be | 2015-03-19 10:43:15 +0100 | [diff] [blame] | 115 | enable_i2c_pin_mux(); |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 116 | |
Hannes Schmelzer | eaba7df | 2019-02-06 13:25:59 +0100 | [diff] [blame] | 117 | /* power-ON 3V3 via Resetcontroller */ |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 118 | rc = br_resetc_regset(RSTCTRL_CTRLREG, |
| 119 | RSTCTRL_FORCE_PWR_NEN | RSTCTRL_CAN_STB); |
Hannes Schmelzer | eaba7df | 2019-02-06 13:25:59 +0100 | [diff] [blame] | 120 | if (rc != 0) |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 121 | printf("ERROR: cannot write to resetc (turn on PWR_nEN)!\n"); |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 122 | |
Hannes Schmelzer | a9484aa | 2019-01-31 09:24:45 +0100 | [diff] [blame] | 123 | pmicsetup(0, 0); |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | const struct dpll_params *get_dpll_ddr_params(void) |
| 127 | { |
| 128 | return &dpll_ddr3; |
| 129 | } |
| 130 | |
| 131 | void sdram_init(void) |
| 132 | { |
| 133 | config_ddr(400, &ddr3_ioregs, |
| 134 | &ddr3_data, |
| 135 | &ddr3_cmd_ctrl_data, |
| 136 | &ddr3_emif_reg_data, 0); |
| 137 | } |
| 138 | #endif /* CONFIG_SPL_BUILD */ |
| 139 | /* |
| 140 | * Basic board specific setup. Pinmux has been handled already. |
| 141 | */ |
| 142 | int board_init(void) |
| 143 | { |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 144 | /* request common used gpios */ |
| 145 | gpio_request(ESC_KEY, "boot-key"); |
| 146 | |
Hannes Schmelzer | eaba7df | 2019-02-06 13:25:59 +0100 | [diff] [blame] | 147 | if (power_tps65217_init(0)) |
| 148 | printf("WARN: cannot setup PMIC 0x24 @ bus #0, not found!.\n"); |
| 149 | |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | #ifdef CONFIG_BOARD_LATE_INIT |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 154 | |
| 155 | int board_boot_key(void) |
| 156 | { |
| 157 | return gpio_get_value(ESC_KEY); |
| 158 | } |
| 159 | |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 160 | int board_late_init(void) |
| 161 | { |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 162 | char othbootargs[128]; |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 163 | |
Hannes Schmelzer | 1d26073 | 2019-04-10 14:13:16 +0200 | [diff] [blame] | 164 | br_resetc_bmode(); |
Hannes Schmelzer | eaba7df | 2019-02-06 13:25:59 +0100 | [diff] [blame] | 165 | |
Hannes Petermaier | 91931f7 | 2015-09-29 08:43:33 +0200 | [diff] [blame] | 166 | /* setup othbootargs for bootvx-command (vxWorks bootline) */ |
Anatolij Gustschin | ac36dc7 | 2021-05-24 17:19:56 +0200 | [diff] [blame] | 167 | snprintf(othbootargs, sizeof(othbootargs), |
| 168 | "u=vxWorksFTP pw=vxWorks o=0x%08x;0x%08x;0x%08x;0x%08x", |
| 169 | (u32)gd->relocaddr, |
| 170 | (u32)env_get_ulong("vx_memtop", 16, gd->relocaddr), |
| 171 | (u32)env_get_ulong("vx_romfsbase", 16, 0), |
| 172 | (u32)env_get_ulong("vx_romfssize", 16, 0)); |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 173 | env_set("othbootargs", othbootargs); |
Hannes Petermaier | 072cefe | 2014-02-07 14:06:50 +0100 | [diff] [blame] | 174 | /* |
| 175 | * reset VBAR registers to its reset location, VxWorks 6.9.3.2 does |
| 176 | * expect that vectors are there, original u-boot moves them to _start |
| 177 | */ |
| 178 | __asm__("ldr r0,=0x20000"); |
| 179 | __asm__("mcr p15, 0, r0, c12, c0, 0"); /* Set VBAR */ |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | #endif /* CONFIG_BOARD_LATE_INIT */ |