Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * board.c |
| 3 | * |
| 4 | * Board functions for B&R LEIT Board |
| 5 | * |
| 6 | * Copyright (C) 2013 Hannes Petermaier <oe5hpm@oevsv.at> |
| 7 | * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0+ |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <errno.h> |
| 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> |
| 24 | #include <asm/io.h> |
| 25 | #include <asm/emif.h> |
| 26 | #include <asm/gpio.h> |
| 27 | #include <i2c.h> |
| 28 | #include <power/tps65217.h> |
| 29 | #include "../common/bur_common.h" |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame^] | 30 | #include <lcd.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | /* --------------------------------------------------------------------------*/ |
| 35 | /* -- defines for GPIO -- */ |
| 36 | #define ETHLED_ORANGE (96+16) /* GPIO3_16 */ |
| 37 | #define REPSWITCH (0+20) /* GPIO0_20 */ |
| 38 | |
| 39 | |
| 40 | #if defined(CONFIG_SPL_BUILD) |
| 41 | /* TODO: check ram-timing ! */ |
| 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 | }; |
| 48 | |
| 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 | }; |
| 59 | |
| 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 | |
| 78 | #ifdef CONFIG_SPL_OS_BOOT |
| 79 | /* |
| 80 | * called from spl_nand.c |
| 81 | * return 0 for loading linux, return 1 for loading u-boot |
| 82 | */ |
| 83 | int spl_start_uboot(void) |
| 84 | { |
| 85 | if (0 == gpio_get_value(REPSWITCH)) { |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 86 | mdelay(1000); |
| 87 | printf("SPL: entering u-boot instead kernel image.\n"); |
| 88 | return 1; |
| 89 | } |
| 90 | return 0; |
| 91 | } |
| 92 | #endif /* CONFIG_SPL_OS_BOOT */ |
| 93 | |
| 94 | #define OSC (V_OSCK/1000000) |
| 95 | static const struct dpll_params dpll_ddr3 = { 400, OSC-1, 1, -1, -1, -1, -1}; |
| 96 | |
| 97 | void am33xx_spl_board_init(void) |
| 98 | { |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame^] | 99 | struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER; |
| 100 | /*struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;*/ |
| 101 | struct cm_dpll *const cmdpll = (struct cm_dpll *)CM_DPLL; |
| 102 | |
| 103 | /* |
| 104 | * in TRM they write a reset value of 1 (=CLK_M_OSC) for the |
| 105 | * CLKSEL_TIMER6_CLK Register, in fact reset value is 0, so we need set |
| 106 | * the source of timer6 clk to CLK_M_OSC |
| 107 | */ |
| 108 | writel(0x01, &cmdpll->clktimer6clk); |
| 109 | |
| 110 | /* enable additional clocks of modules which are accessed later */ |
| 111 | u32 *const clk_domains[] = { |
| 112 | &cmper->lcdcclkstctrl, |
| 113 | 0 |
| 114 | }; |
| 115 | |
| 116 | u32 *const clk_modules_tsspecific[] = { |
| 117 | &cmper->lcdclkctrl, |
| 118 | &cmper->timer5clkctrl, |
| 119 | &cmper->timer6clkctrl, |
| 120 | 0 |
| 121 | }; |
| 122 | do_enable_clocks(clk_domains, clk_modules_tsspecific, 1); |
| 123 | |
| 124 | /* setup LCD-Pixel Clock */ |
| 125 | writel(0x2, &cmdpll->clklcdcpixelclk); /* clock comes from perPLL M2 */ |
| 126 | |
| 127 | pmicsetup(0); |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | const struct dpll_params *get_dpll_ddr_params(void) |
| 131 | { |
| 132 | return &dpll_ddr3; |
| 133 | } |
| 134 | |
| 135 | void sdram_init(void) |
| 136 | { |
| 137 | config_ddr(400, &ddr3_ioregs, |
| 138 | &ddr3_data, |
| 139 | &ddr3_cmd_ctrl_data, |
| 140 | &ddr3_emif_reg_data, 0); |
| 141 | } |
| 142 | #endif /* CONFIG_SPL_BUILD */ |
| 143 | |
| 144 | /* Basic board specific setup. Pinmux has been handled already. */ |
| 145 | int board_init(void) |
| 146 | { |
| 147 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Hannes Petermaier | f31a98d | 2014-06-04 10:26:29 +0200 | [diff] [blame] | 148 | #ifdef CONFIG_NAND |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 149 | gpmc_init(); |
Hannes Petermaier | f31a98d | 2014-06-04 10:26:29 +0200 | [diff] [blame] | 150 | #endif |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | #ifdef CONFIG_BOARD_LATE_INIT |
| 155 | int board_late_init(void) |
| 156 | { |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 157 | if (0 == gpio_get_value(REPSWITCH)) { |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame^] | 158 | lcd_position_cursor(1, 8); |
| 159 | lcd_puts( |
| 160 | "switching to network-console ... "); |
| 161 | setenv("bootcmd", "run netconsole"); |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 162 | } |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 163 | return 0; |
| 164 | } |
| 165 | #endif /* CONFIG_BOARD_LATE_INIT */ |