blob: a1c6887b1be7915290fe09cea12b66b49b215a0c [file] [log] [blame]
Hannes Petermaier893c04e2014-02-07 08:07:36 +01001/*
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 Petermaierfbd5aed2015-02-03 13:22:26 +010030#include <lcd.h>
Hannes Petermaiercf1331f2015-02-03 13:22:28 +010031#include <watchdog.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010032
33DECLARE_GLOBAL_DATA_PTR;
34
35/* --------------------------------------------------------------------------*/
36/* -- defines for GPIO -- */
37#define ETHLED_ORANGE (96+16) /* GPIO3_16 */
38#define REPSWITCH (0+20) /* GPIO0_20 */
39
40
41#if defined(CONFIG_SPL_BUILD)
42/* TODO: check ram-timing ! */
43static const struct ddr_data ddr3_data = {
44 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
45 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
46 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
47 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
48};
49
50static const struct cmd_control ddr3_cmd_ctrl_data = {
51 .cmd0csratio = MT41K256M16HA125E_RATIO,
52 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
53
54 .cmd1csratio = MT41K256M16HA125E_RATIO,
55 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
56
57 .cmd2csratio = MT41K256M16HA125E_RATIO,
58 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
59};
60
61static struct emif_regs ddr3_emif_reg_data = {
62 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
63 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
64 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
65 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
66 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
67 .zq_config = MT41K256M16HA125E_ZQ_CFG,
68 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
69};
70
71static const struct ctrl_ioregs ddr3_ioregs = {
72 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
73 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
74 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
75 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
76 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
77};
78
79#ifdef CONFIG_SPL_OS_BOOT
80/*
81 * called from spl_nand.c
82 * return 0 for loading linux, return 1 for loading u-boot
83 */
84int spl_start_uboot(void)
85{
86 if (0 == gpio_get_value(REPSWITCH)) {
Hannes Petermaier893c04e2014-02-07 08:07:36 +010087 mdelay(1000);
88 printf("SPL: entering u-boot instead kernel image.\n");
89 return 1;
90 }
91 return 0;
92}
93#endif /* CONFIG_SPL_OS_BOOT */
94
95#define OSC (V_OSCK/1000000)
96static const struct dpll_params dpll_ddr3 = { 400, OSC-1, 1, -1, -1, -1, -1};
97
98void am33xx_spl_board_init(void)
99{
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100100 struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
101 /*struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;*/
102 struct cm_dpll *const cmdpll = (struct cm_dpll *)CM_DPLL;
103
104 /*
105 * in TRM they write a reset value of 1 (=CLK_M_OSC) for the
106 * CLKSEL_TIMER6_CLK Register, in fact reset value is 0, so we need set
107 * the source of timer6 clk to CLK_M_OSC
108 */
109 writel(0x01, &cmdpll->clktimer6clk);
110
111 /* enable additional clocks of modules which are accessed later */
112 u32 *const clk_domains[] = {
113 &cmper->lcdcclkstctrl,
114 0
115 };
116
117 u32 *const clk_modules_tsspecific[] = {
118 &cmper->lcdclkctrl,
119 &cmper->timer5clkctrl,
120 &cmper->timer6clkctrl,
121 0
122 };
123 do_enable_clocks(clk_domains, clk_modules_tsspecific, 1);
124
125 /* setup LCD-Pixel Clock */
126 writel(0x2, &cmdpll->clklcdcpixelclk); /* clock comes from perPLL M2 */
127
128 pmicsetup(0);
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100129}
130
131const struct dpll_params *get_dpll_ddr_params(void)
132{
133 return &dpll_ddr3;
134}
135
136void sdram_init(void)
137{
138 config_ddr(400, &ddr3_ioregs,
139 &ddr3_data,
140 &ddr3_cmd_ctrl_data,
141 &ddr3_emif_reg_data, 0);
142}
143#endif /* CONFIG_SPL_BUILD */
144
145/* Basic board specific setup. Pinmux has been handled already. */
146int board_init(void)
147{
Hannes Petermaiercf1331f2015-02-03 13:22:28 +0100148#if defined(CONFIG_HW_WATCHDOG)
149 hw_watchdog_init();
150#endif
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100151 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Hannes Petermaieref1bd8f2014-06-04 10:26:29 +0200152#ifdef CONFIG_NAND
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100153 gpmc_init();
Hannes Petermaieref1bd8f2014-06-04 10:26:29 +0200154#endif
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100155 return 0;
156}
157
158#ifdef CONFIG_BOARD_LATE_INIT
159int board_late_init(void)
160{
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100161 if (0 == gpio_get_value(REPSWITCH)) {
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +0100162 lcd_position_cursor(1, 8);
163 lcd_puts(
164 "switching to network-console ... ");
165 setenv("bootcmd", "run netconsole");
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100166 }
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100167 return 0;
168}
169#endif /* CONFIG_BOARD_LATE_INIT */