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