blob: e0d1707ac13e2a1c4ab7772a0b72ed0146c3317e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hannes Petermaier893c04e2014-02-07 08:07:36 +01002/*
3 * board.c
4 *
Hannes Schmelzer2290fe02016-06-22 12:36:13 +02005 * Board functions for B&R BRPPT1
Hannes Petermaier893c04e2014-02-07 08:07:36 +01006 *
Hannes Schmelzer4c302b92015-05-28 15:41:12 +02007 * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
Hannes Petermaier893c04e2014-02-07 08:07:36 +01008 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
9 *
Hannes Petermaier893c04e2014-02-07 08:07:36 +010010 */
11
12#include <common.h>
Simon Glassf0835832019-11-14 12:57:18 -070013#include <bootcount.h>
Simon Glass168068f2019-08-01 09:46:47 -060014#include <env.h>
Hannes Petermaier893c04e2014-02-07 08:07:36 +010015#include <errno.h>
16#include <spl.h>
17#include <asm/arch/cpu.h>
18#include <asm/arch/hardware.h>
19#include <asm/arch/omap.h>
20#include <asm/arch/ddr_defs.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/gpio.h>
23#include <asm/arch/sys_proto.h>
24#include <asm/arch/mem.h>
25#include <asm/io.h>
26#include <asm/emif.h>
27#include <asm/gpio.h>
28#include <i2c.h>
29#include <power/tps65217.h>
30#include "../common/bur_common.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 -- */
Hannes Petermaier893c04e2014-02-07 08:07:36 +010037#define REPSWITCH (0+20) /* GPIO0_20 */
38
Hannes Petermaier893c04e2014-02-07 08:07:36 +010039#if defined(CONFIG_SPL_BUILD)
40/* TODO: check ram-timing ! */
41static const struct ddr_data ddr3_data = {
42 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
43 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
44 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
45 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
46};
47
48static const struct cmd_control ddr3_cmd_ctrl_data = {
49 .cmd0csratio = MT41K256M16HA125E_RATIO,
50 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
51
52 .cmd1csratio = MT41K256M16HA125E_RATIO,
53 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
54
55 .cmd2csratio = MT41K256M16HA125E_RATIO,
56 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
57};
58
59static struct emif_regs ddr3_emif_reg_data = {
60 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
61 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
62 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
63 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
64 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
65 .zq_config = MT41K256M16HA125E_ZQ_CFG,
66 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
67};
68
69static const struct ctrl_ioregs ddr3_ioregs = {
70 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
71 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
72 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
73 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
74 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
75};
76
Hannes Petermaier893c04e2014-02-07 08:07:36 +010077#define OSC (V_OSCK/1000000)
78static const struct dpll_params dpll_ddr3 = { 400, OSC-1, 1, -1, -1, -1, -1};
79
80void am33xx_spl_board_init(void)
81{
Hannes Schmelzerfbc7c7d2018-07-06 15:41:28 +020082 int rc;
83
Hannes Petermaierfbd5aed2015-02-03 13:22:26 +010084 struct cm_perpll *const cmper = (struct cm_perpll *)CM_PER;
85 /*struct cm_wkuppll *const cmwkup = (struct cm_wkuppll *)CM_WKUP;*/
86 struct cm_dpll *const cmdpll = (struct cm_dpll *)CM_DPLL;
87
88 /*
89 * in TRM they write a reset value of 1 (=CLK_M_OSC) for the
90 * CLKSEL_TIMER6_CLK Register, in fact reset value is 0, so we need set
91 * the source of timer6 clk to CLK_M_OSC
92 */
93 writel(0x01, &cmdpll->clktimer6clk);
94
95 /* enable additional clocks of modules which are accessed later */
96 u32 *const clk_domains[] = {
97 &cmper->lcdcclkstctrl,
98 0
99 };
100
101 u32 *const clk_modules_tsspecific[] = {
102 &cmper->lcdclkctrl,
103 &cmper->timer5clkctrl,
104 &cmper->timer6clkctrl,
105 0
106 };
107 do_enable_clocks(clk_domains, clk_modules_tsspecific, 1);
108
Hannes Petermaier2b5b2be2015-03-19 10:43:15 +0100109 /* setup I2C */
110 enable_i2c_pin_mux();
Hannes Schmelzera9484aa2019-01-31 09:24:45 +0100111
112 pmicsetup(0, 0);
Hannes Petermaierd79c1382015-04-08 07:38:34 +0200113
Hannes Schmelzerfbc7c7d2018-07-06 15:41:28 +0200114 /* peripheral reset */
115 rc = gpio_request(64 + 29, "GPMC_WAIT1");
116 if (rc != 0)
117 printf("cannot request GPMC_WAIT1 GPIO!\n");
118 rc = gpio_direction_output(64 + 29, 1);
119 if (rc != 0)
120 printf("cannot set GPMC_WAIT1 GPIO!\n");
121
122 rc = gpio_request(64 + 28, "GPMC_WAIT0");
123 if (rc != 0)
124 printf("cannot request GPMC_WAIT0 GPIO!\n");
125 rc = gpio_direction_output(64 + 28, 1);
126 if (rc != 0)
127 printf("cannot set GPMC_WAIT0 GPIO!\n");
128
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
Hannes Schmelzer73e9db22018-07-06 15:41:26 +0200159static char *bootmodeascii[16] = {
160 "BOOT", "reserved", "reserved", "reserved",
161 "RUN", "reserved", "reserved", "reserved",
162 "reserved", "reserved", "reserved", "reserved",
163 "PME", "reserved", "reserved", "DIAG",
164};
165
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100166int board_late_init(void)
167{
Hannes Schmelzer73e9db22018-07-06 15:41:26 +0200168 unsigned char bmode = 0;
169 ulong bootcount = 0;
Hannes Schmelzerfbc7c7d2018-07-06 15:41:28 +0200170 int rc;
Hannes Schmelzer73e9db22018-07-06 15:41:26 +0200171
172 bootcount = bootcount_load() & 0xF;
173
Hannes Schmelzerfbc7c7d2018-07-06 15:41:28 +0200174 rc = gpio_request(REPSWITCH, "REPSWITCH");
175
176 if (rc != 0 || gpio_get_value(REPSWITCH) == 0 || bootcount == 12)
Hannes Schmelzer73e9db22018-07-06 15:41:26 +0200177 bmode = 12;
178 else if (bootcount > 0)
179 bmode = 0;
180 else
181 bmode = 4;
182
183 printf("Mode: %s\n", bootmodeascii[bmode & 0x0F]);
184 env_set_ulong("b_mode", bmode);
185
186 /* get sure that bootcmd isn't affected by any bootcount value */
187 env_set_ulong("bootlimit", 0);
188
Hannes Petermaier893c04e2014-02-07 08:07:36 +0100189 return 0;
190}
191#endif /* CONFIG_BOARD_LATE_INIT */