blob: 41db449afcd2970816a1e127b6c0773430a2605f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hannes Petermaierfb003662014-02-07 08:07:36 +01002/*
3 * board.c
4 *
Hannes Schmelzer20ccb432016-06-22 12:36:13 +02005 * Board functions for B&R BRPPT1
Hannes Petermaierfb003662014-02-07 08:07:36 +01006 *
Hannes Schmelzer7935f032015-05-28 15:41:12 +02007 * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
Hannes Petermaierfb003662014-02-07 08:07:36 +01008 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
9 *
Hannes Petermaierfb003662014-02-07 08:07:36 +010010 */
11
12#include <common.h>
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>
26#include <i2c.h>
27#include <power/tps65217.h>
28#include "../common/bur_common.h"
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +010029#include <lcd.h>
Hannes Petermaier96bc6bb2015-02-03 13:22:28 +010030#include <watchdog.h>
Hannes Petermaierfb003662014-02-07 08:07:36 +010031
32DECLARE_GLOBAL_DATA_PTR;
33
34/* --------------------------------------------------------------------------*/
35/* -- defines for GPIO -- */
Hannes Petermaierfb003662014-02-07 08:07:36 +010036#define REPSWITCH (0+20) /* GPIO0_20 */
37
Hannes Petermaierfb003662014-02-07 08:07:36 +010038#if defined(CONFIG_SPL_BUILD)
39/* TODO: check ram-timing ! */
40static const struct ddr_data ddr3_data = {
41 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
42 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
43 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
44 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
45};
46
47static const struct cmd_control ddr3_cmd_ctrl_data = {
48 .cmd0csratio = MT41K256M16HA125E_RATIO,
49 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
50
51 .cmd1csratio = MT41K256M16HA125E_RATIO,
52 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
53
54 .cmd2csratio = MT41K256M16HA125E_RATIO,
55 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
56};
57
58static struct emif_regs ddr3_emif_reg_data = {
59 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
60 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
61 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
62 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
63 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
64 .zq_config = MT41K256M16HA125E_ZQ_CFG,
65 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
66};
67
68static const struct ctrl_ioregs ddr3_ioregs = {
69 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
70 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
71 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
72 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
73 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
74};
75
76#ifdef CONFIG_SPL_OS_BOOT
77/*
78 * called from spl_nand.c
79 * return 0 for loading linux, return 1 for loading u-boot
80 */
81int spl_start_uboot(void)
82{
83 if (0 == gpio_get_value(REPSWITCH)) {
Hannes Petermaierfb003662014-02-07 08:07:36 +010084 mdelay(1000);
85 printf("SPL: entering u-boot instead kernel image.\n");
86 return 1;
87 }
88 return 0;
89}
90#endif /* CONFIG_SPL_OS_BOOT */
91
92#define OSC (V_OSCK/1000000)
93static const struct dpll_params dpll_ddr3 = { 400, OSC-1, 1, -1, -1, -1, -1};
94
95void am33xx_spl_board_init(void)
96{
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +010097 struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
98 /*struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;*/
99 struct cm_dpll *const cmdpll = (struct cm_dpll *)CM_DPLL;
100
101 /*
102 * in TRM they write a reset value of 1 (=CLK_M_OSC) for the
103 * CLKSEL_TIMER6_CLK Register, in fact reset value is 0, so we need set
104 * the source of timer6 clk to CLK_M_OSC
105 */
106 writel(0x01, &cmdpll->clktimer6clk);
107
108 /* enable additional clocks of modules which are accessed later */
109 u32 *const clk_domains[] = {
110 &cmper->lcdcclkstctrl,
111 0
112 };
113
114 u32 *const clk_modules_tsspecific[] = {
115 &cmper->lcdclkctrl,
116 &cmper->timer5clkctrl,
117 &cmper->timer6clkctrl,
118 0
119 };
120 do_enable_clocks(clk_domains, clk_modules_tsspecific, 1);
121
Hannes Petermaier2e68d2b2015-03-19 10:43:15 +0100122 /* setup I2C */
123 enable_i2c_pin_mux();
124 i2c_set_bus_num(0);
125 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +0100126 pmicsetup(0);
Hannes Petermaier763f7f32015-04-08 07:38:34 +0200127
128 gpio_direction_output(64+29, 1); /* switch NAND_RnB to GPMC_WAIT1 */
129 gpio_direction_output(64+28, 1); /* switch MII2_CRS to GPMC_WAIT0 */
Hannes Petermaierfb003662014-02-07 08:07:36 +0100130}
131
132const struct dpll_params *get_dpll_ddr_params(void)
133{
134 return &dpll_ddr3;
135}
136
137void sdram_init(void)
138{
139 config_ddr(400, &ddr3_ioregs,
140 &ddr3_data,
141 &ddr3_cmd_ctrl_data,
142 &ddr3_emif_reg_data, 0);
143}
144#endif /* CONFIG_SPL_BUILD */
145
146/* Basic board specific setup. Pinmux has been handled already. */
147int board_init(void)
148{
Hannes Petermaier96bc6bb2015-02-03 13:22:28 +0100149#if defined(CONFIG_HW_WATCHDOG)
150 hw_watchdog_init();
151#endif
Hannes Petermaierfb003662014-02-07 08:07:36 +0100152 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
Hannes Petermaierf31a98d2014-06-04 10:26:29 +0200153#ifdef CONFIG_NAND
Hannes Petermaierfb003662014-02-07 08:07:36 +0100154 gpmc_init();
Hannes Petermaierf31a98d2014-06-04 10:26:29 +0200155#endif
Hannes Petermaierfb003662014-02-07 08:07:36 +0100156 return 0;
157}
158
159#ifdef CONFIG_BOARD_LATE_INIT
160int board_late_init(void)
161{
Hannes Petermaierfb003662014-02-07 08:07:36 +0100162 if (0 == gpio_get_value(REPSWITCH)) {
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +0100163 lcd_position_cursor(1, 8);
164 lcd_puts(
165 "switching to network-console ... ");
Simon Glass6a38e412017-08-03 12:22:09 -0600166 env_set("bootcmd", "run netconsole");
Hannes Petermaierfb003662014-02-07 08:07:36 +0100167 }
Hannes Petermaierfb003662014-02-07 08:07:36 +0100168 return 0;
169}
170#endif /* CONFIG_BOARD_LATE_INIT */