blob: ecbd843676a775d9ef933338973b93280b966b0a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Behmebb732be2009-01-28 21:39:58 +01002/*
Tom Rini988a2352011-11-18 12:48:09 +00003 * (C) Copyright 2004-2011
Dirk Behmebb732be2009-01-28 21:39:58 +01004 * Texas Instruments, <www.ti.com>
5 *
6 * Author :
7 * Manikandan Pillai <mani.pillai@ti.com>
8 *
9 * Derived from Beagle Board and 3430 SDP code by
10 * Richard Woodruff <r-woodruff2@ti.com>
11 * Syed Mohammed Khasim <khasim@ti.com>
Dirk Behmebb732be2009-01-28 21:39:58 +010012 */
13#include <common.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050014#include <dm.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060015#include <env.h>
Simon Glass97589732020-05-10 11:40:02 -060016#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <net.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050018#include <ns16550.h>
Simon Glass36736182019-11-14 12:57:24 -070019#include <serial.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010020#include <asm/io.h>
21#include <asm/arch/mem.h>
22#include <asm/arch/mux.h>
23#include <asm/arch/sys_proto.h>
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -040024#include <asm/arch/mmc_host_def.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040025#include <asm/gpio.h>
Paul Kocialkowski69559892014-11-08 20:55:47 +010026#include <twl4030.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010027#include <asm/mach-types.h>
Simon Glassdbd79542020-05-10 11:40:11 -060028#include <linux/delay.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090029#include <linux/mtd/rawnand.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010030#include "evm.h"
31
Derald D. Woods1b01bf92017-08-06 00:00:21 -050032#define OMAP3EVM_GPIO_ETH_RST_GEN1 64
33#define OMAP3EVM_GPIO_ETH_RST_GEN2 7
Sriramakrishnan0f188c32011-07-18 09:21:55 -040034
Derald D. Woods9aa45bc2020-07-18 19:23:04 -050035#define CONFIG_SMC911X_BASE 0x2C000000
36
John Rigby0d21ed02010-12-20 18:27:51 -070037DECLARE_GLOBAL_DATA_PTR;
38
Dirk Behme85ed7092010-12-18 07:40:28 +010039static u32 omap3_evm_version;
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053040
Dirk Behme85ed7092010-12-18 07:40:28 +010041u32 get_omap3_evm_rev(void)
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053042{
43 return omap3_evm_version;
44}
45
46static void omap3_evm_get_revision(void)
47{
Derald D. Woods9aa45bc2020-07-18 19:23:04 -050048#if defined(CONFIG_SMC911X)
Sanjeev Premi88105fb2010-11-04 16:02:32 -040049 /*
50 * Board revision can be ascertained only by identifying
51 * the Ethernet chipset.
52 */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053053 unsigned int smsc_id;
54
55 /* Ethernet PHY ID is stored at ID_REV register */
56 smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000;
57 printf("Read back SMSC id 0x%x\n", smsc_id);
58
59 switch (smsc_id) {
60 /* SMSC9115 chipset */
61 case 0x01150000:
62 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
63 break;
64 /* SMSC 9220 chipset */
65 case 0x92200000:
66 default:
67 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
68 }
Derald D. Woods9aa45bc2020-07-18 19:23:04 -050069#else /* !CONFIG_SMC911X */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040070#if defined(CONFIG_STATIC_BOARD_REV)
Derald D. Woods1b01bf92017-08-06 00:00:21 -050071 /* Look for static defintion of the board revision */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040072 omap3_evm_version = CONFIG_STATIC_BOARD_REV;
73#else
Derald D. Woods1b01bf92017-08-06 00:00:21 -050074 /* Fallback to the default above */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040075 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
Derald D. Woods1b01bf92017-08-06 00:00:21 -050076#endif /* CONFIG_STATIC_BOARD_REV */
Derald D. Woods9aa45bc2020-07-18 19:23:04 -050077#endif /* CONFIG_SMC911X */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053078}
79
Derald D. Woods1b01bf92017-08-06 00:00:21 -050080#if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
81/* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +053082u8 omap3_evm_need_extvbus(void)
83{
84 u8 retval = 0;
85
86 if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2)
87 retval = 1;
88
89 return retval;
90}
Derald D. Woods1b01bf92017-08-06 00:00:21 -050091#endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +053092
93/*
Dirk Behmebb732be2009-01-28 21:39:58 +010094 * Routine: board_init
95 * Description: Early hardware init.
Tom Rix558bb832009-04-01 22:02:20 -050096 */
Dirk Behmebb732be2009-01-28 21:39:58 +010097int board_init(void)
98{
Dirk Behmebb732be2009-01-28 21:39:58 +010099 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
100 /* board id for Linux */
101 gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM;
102 /* boot param addr */
103 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
104
105 return 0;
106}
107
Derald D. Woods17f8f982017-09-02 17:43:05 -0500108#if defined(CONFIG_SPL_OS_BOOT)
109int spl_start_uboot(void)
110{
111 /* break into full u-boot on 'c' */
112 if (serial_tstc() && serial_getc() == 'c')
113 return 1;
114
115 return 0;
116}
117#endif /* CONFIG_SPL_OS_BOOT */
118
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500119#if defined(CONFIG_SPL_BUILD)
Tom Rini988a2352011-11-18 12:48:09 +0000120/*
121 * Routine: get_board_mem_timings
122 * Description: If we use SPL then there is no x-loader nor config header
123 * so we have to setup the DDR timings ourself on the first bank. This
124 * provides the timing values back to the function that configures
125 * the memory.
126 */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000127void get_board_mem_timings(struct board_sdrc_timings *timings)
Tom Rini988a2352011-11-18 12:48:09 +0000128{
129 int pop_mfr, pop_id;
130
131 /*
132 * We need to identify what PoP memory is on the board so that
133 * we know what timings to use. To map the ID values please see
134 * nand_ids.c
135 */
136 identify_nand_chip(&pop_mfr, &pop_id);
137
138 if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
139 /* 256MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000140 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
141 timings->ctrla = HYNIX_V_ACTIMA_200;
142 timings->ctrlb = HYNIX_V_ACTIMB_200;
Tom Rini988a2352011-11-18 12:48:09 +0000143 } else {
144 /* 128MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000145 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
146 timings->ctrla = MICRON_V_ACTIMA_165;
147 timings->ctrlb = MICRON_V_ACTIMB_165;
Tom Rini988a2352011-11-18 12:48:09 +0000148 }
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000149 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
150 timings->mr = MICRON_V_MR_165;
Tom Rini988a2352011-11-18 12:48:09 +0000151}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500152#endif /* CONFIG_SPL_BUILD */
153
Tom Rix558bb832009-04-01 22:02:20 -0500154/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100155 * Routine: misc_init_r
156 * Description: Init ethernet (done here so udelay works)
Tom Rix558bb832009-04-01 22:02:20 -0500157 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100158int misc_init_r(void)
159{
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500160 twl4030_power_init();
Dirk Behmebb732be2009-01-28 21:39:58 +0100161
Derald D. Woods9aa45bc2020-07-18 19:23:04 -0500162#if defined(CONFIG_SMC911X)
Dirk Behmebb732be2009-01-28 21:39:58 +0100163 setup_net_chip();
164#endif
Sanjeev Premi88105fb2010-11-04 16:02:32 -0400165 omap3_evm_get_revision();
Dirk Behmebb732be2009-01-28 21:39:58 +0100166
Derald D. Woods9aa45bc2020-07-18 19:23:04 -0500167#if defined(CONFIG_SMC911X)
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400168 reset_net_chip();
169#endif
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200170 omap_die_id_display();
Dirk Behme12dbcf62009-03-12 19:30:50 +0100171
Derald D. Woods9aa45bc2020-07-18 19:23:04 -0500172#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && \
173 !defined(CONFIG_SMC911X)
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500174 omap_die_id_usbethaddr();
175#endif
Dirk Behmebb732be2009-01-28 21:39:58 +0100176 return 0;
177}
178
Tom Rix558bb832009-04-01 22:02:20 -0500179/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100180 * Routine: set_muxconf_regs
181 * Description: Setting up the configuration Mux registers specific to the
182 * hardware. Many pins need to be moved from protect to primary
183 * mode.
Tom Rix558bb832009-04-01 22:02:20 -0500184 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100185void set_muxconf_regs(void)
186{
187 MUX_EVM();
188}
189
Derald D. Woods9aa45bc2020-07-18 19:23:04 -0500190#if defined(CONFIG_SMC911X)
Tom Rix558bb832009-04-01 22:02:20 -0500191/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100192 * Routine: setup_net_chip
193 * Description: Setting up the configuration GPMC registers specific to the
194 * Ethernet hardware.
Tom Rix558bb832009-04-01 22:02:20 -0500195 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100196static void setup_net_chip(void)
197{
Dirk Behmedc7af202009-08-08 09:30:21 +0200198 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
Dirk Behmebb732be2009-01-28 21:39:58 +0100199
200 /* Configure GPMC registers */
Dirk Behmea4becd62009-08-08 09:30:22 +0200201 writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
202 writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
203 writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
204 writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
205 writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
206 writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
207 writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
Dirk Behmebb732be2009-01-28 21:39:58 +0100208
209 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
210 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
211 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
212 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
213 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
214 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
215 &ctrl_base->gpmc_nadv_ale);
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400216}
217
218/**
219 * Reset the ethernet chip.
220 */
221static void reset_net_chip(void)
222{
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400223 int ret;
224 int rst_gpio;
225
226 if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
227 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
228 } else {
229 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
230 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100231
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400232 ret = gpio_request(rst_gpio, "");
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400233 if (ret < 0) {
234 printf("Unable to get GPIO %d\n", rst_gpio);
235 return ;
236 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100237
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400238 /* Configure as output */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400239 gpio_direction_output(rst_gpio, 0);
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400240
241 /* Send a pulse on the GPIO pin */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400242 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100243 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400244 gpio_set_value(rst_gpio, 0);
Dirk Behmebb732be2009-01-28 21:39:58 +0100245 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400246 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100247}
Derald D. Woods9aa45bc2020-07-18 19:23:04 -0500248#endif /* CONFIG_SMC911X */
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400249
Masahiro Yamada0a780172017-05-09 20:31:39 +0900250#if defined(CONFIG_MMC)
Paul Kocialkowski69559892014-11-08 20:55:47 +0100251void board_mmc_power_init(void)
252{
253 twl4030_power_mmc_init(0);
254}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500255#endif /* CONFIG_MMC */