blob: d26dd5ba84080b66f45670f4f88ef9ec035f2fec [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>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050016#include <ns16550.h>
Ben Warrenfbfdd3a2009-07-20 22:01:11 -070017#include <netdev.h>
Simon Glass36736182019-11-14 12:57:24 -070018#include <serial.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010019#include <asm/io.h>
20#include <asm/arch/mem.h>
21#include <asm/arch/mux.h>
22#include <asm/arch/sys_proto.h>
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -040023#include <asm/arch/mmc_host_def.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040024#include <asm/gpio.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010025#include <i2c.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>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050028#include <asm/omap_musb.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090029#include <linux/mtd/rawnand.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050030#include <linux/usb/ch9.h>
31#include <linux/usb/gadget.h>
32#include <linux/usb/musb.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010033#include "evm.h"
34
Derald D. Woods1b01bf92017-08-06 00:00:21 -050035#define OMAP3EVM_GPIO_ETH_RST_GEN1 64
36#define OMAP3EVM_GPIO_ETH_RST_GEN2 7
Sriramakrishnan0f188c32011-07-18 09:21:55 -040037
John Rigby0d21ed02010-12-20 18:27:51 -070038DECLARE_GLOBAL_DATA_PTR;
39
Dirk Behme85ed7092010-12-18 07:40:28 +010040static u32 omap3_evm_version;
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053041
Dirk Behme85ed7092010-12-18 07:40:28 +010042u32 get_omap3_evm_rev(void)
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053043{
44 return omap3_evm_version;
45}
46
47static void omap3_evm_get_revision(void)
48{
Sanjeev Premi88105fb2010-11-04 16:02:32 -040049#if defined(CONFIG_CMD_NET)
50 /*
51 * Board revision can be ascertained only by identifying
52 * the Ethernet chipset.
53 */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053054 unsigned int smsc_id;
55
56 /* Ethernet PHY ID is stored at ID_REV register */
57 smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000;
58 printf("Read back SMSC id 0x%x\n", smsc_id);
59
60 switch (smsc_id) {
61 /* SMSC9115 chipset */
62 case 0x01150000:
63 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
64 break;
65 /* SMSC 9220 chipset */
66 case 0x92200000:
67 default:
68 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
69 }
Derald D. Woods1b01bf92017-08-06 00:00:21 -050070#else /* !CONFIG_CMD_NET */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040071#if defined(CONFIG_STATIC_BOARD_REV)
Derald D. Woods1b01bf92017-08-06 00:00:21 -050072 /* Look for static defintion of the board revision */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040073 omap3_evm_version = CONFIG_STATIC_BOARD_REV;
74#else
Derald D. Woods1b01bf92017-08-06 00:00:21 -050075 /* Fallback to the default above */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040076 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
Derald D. Woods1b01bf92017-08-06 00:00:21 -050077#endif /* CONFIG_STATIC_BOARD_REV */
78#endif /* CONFIG_CMD_NET */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053079}
80
Derald D. Woods1b01bf92017-08-06 00:00:21 -050081#if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
82/* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +053083u8 omap3_evm_need_extvbus(void)
84{
85 u8 retval = 0;
86
87 if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2)
88 retval = 1;
89
90 return retval;
91}
Derald D. Woods1b01bf92017-08-06 00:00:21 -050092#endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +053093
94/*
Dirk Behmebb732be2009-01-28 21:39:58 +010095 * Routine: board_init
96 * Description: Early hardware init.
Tom Rix558bb832009-04-01 22:02:20 -050097 */
Dirk Behmebb732be2009-01-28 21:39:58 +010098int board_init(void)
99{
Dirk Behmebb732be2009-01-28 21:39:58 +0100100 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
101 /* board id for Linux */
102 gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM;
103 /* boot param addr */
104 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
105
106 return 0;
107}
108
Derald D. Woods17f8f982017-09-02 17:43:05 -0500109#if defined(CONFIG_SPL_OS_BOOT)
110int spl_start_uboot(void)
111{
112 /* break into full u-boot on 'c' */
113 if (serial_tstc() && serial_getc() == 'c')
114 return 1;
115
116 return 0;
117}
118#endif /* CONFIG_SPL_OS_BOOT */
119
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500120#if defined(CONFIG_SPL_BUILD)
Tom Rini988a2352011-11-18 12:48:09 +0000121/*
122 * Routine: get_board_mem_timings
123 * Description: If we use SPL then there is no x-loader nor config header
124 * so we have to setup the DDR timings ourself on the first bank. This
125 * provides the timing values back to the function that configures
126 * the memory.
127 */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000128void get_board_mem_timings(struct board_sdrc_timings *timings)
Tom Rini988a2352011-11-18 12:48:09 +0000129{
130 int pop_mfr, pop_id;
131
132 /*
133 * We need to identify what PoP memory is on the board so that
134 * we know what timings to use. To map the ID values please see
135 * nand_ids.c
136 */
137 identify_nand_chip(&pop_mfr, &pop_id);
138
139 if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
140 /* 256MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000141 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
142 timings->ctrla = HYNIX_V_ACTIMA_200;
143 timings->ctrlb = HYNIX_V_ACTIMB_200;
Tom Rini988a2352011-11-18 12:48:09 +0000144 } else {
145 /* 128MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000146 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
147 timings->ctrla = MICRON_V_ACTIMA_165;
148 timings->ctrlb = MICRON_V_ACTIMB_165;
Tom Rini988a2352011-11-18 12:48:09 +0000149 }
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000150 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
151 timings->mr = MICRON_V_MR_165;
Tom Rini988a2352011-11-18 12:48:09 +0000152}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500153#endif /* CONFIG_SPL_BUILD */
154
155#if defined(CONFIG_USB_MUSB_OMAP2PLUS)
156static struct musb_hdrc_config musb_config = {
157 .multipoint = 1,
158 .dyn_fifo = 1,
159 .num_eps = 16,
160 .ram_bits = 12,
161};
162
163static struct omap_musb_board_data musb_board_data = {
164 .interface_type = MUSB_INTERFACE_ULPI,
165};
166
167static struct musb_hdrc_platform_data musb_plat = {
168#if defined(CONFIG_USB_MUSB_HOST)
169 .mode = MUSB_HOST,
170#elif defined(CONFIG_USB_MUSB_GADGET)
171 .mode = MUSB_PERIPHERAL,
172#else
173#error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
174#endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
175 .config = &musb_config,
176 .power = 100,
177 .platform_ops = &omap2430_ops,
178 .board_data = &musb_board_data,
179};
180#endif /* CONFIG_USB_MUSB_OMAP2PLUS */
Tom Rini988a2352011-11-18 12:48:09 +0000181
Tom Rix558bb832009-04-01 22:02:20 -0500182/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100183 * Routine: misc_init_r
184 * Description: Init ethernet (done here so udelay works)
Tom Rix558bb832009-04-01 22:02:20 -0500185 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100186int misc_init_r(void)
187{
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500188 twl4030_power_init();
Dirk Behmebb732be2009-01-28 21:39:58 +0100189
Adam Ford49e96f22017-08-07 13:11:19 -0500190#ifdef CONFIG_SYS_I2C_OMAP24XX
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200191 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Dirk Behmebb732be2009-01-28 21:39:58 +0100192#endif
193
194#if defined(CONFIG_CMD_NET)
195 setup_net_chip();
196#endif
Sanjeev Premi88105fb2010-11-04 16:02:32 -0400197 omap3_evm_get_revision();
Dirk Behmebb732be2009-01-28 21:39:58 +0100198
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400199#if defined(CONFIG_CMD_NET)
200 reset_net_chip();
201#endif
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200202 omap_die_id_display();
Dirk Behme12dbcf62009-03-12 19:30:50 +0100203
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500204#if defined(CONFIG_USB_MUSB_OMAP2PLUS)
205 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
206#endif
207
208#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
209 omap_die_id_usbethaddr();
210#endif
Dirk Behmebb732be2009-01-28 21:39:58 +0100211 return 0;
212}
213
Tom Rix558bb832009-04-01 22:02:20 -0500214/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100215 * Routine: set_muxconf_regs
216 * Description: Setting up the configuration Mux registers specific to the
217 * hardware. Many pins need to be moved from protect to primary
218 * mode.
Tom Rix558bb832009-04-01 22:02:20 -0500219 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100220void set_muxconf_regs(void)
221{
222 MUX_EVM();
223}
224
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500225#if defined(CONFIG_CMD_NET)
Tom Rix558bb832009-04-01 22:02:20 -0500226/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100227 * Routine: setup_net_chip
228 * Description: Setting up the configuration GPMC registers specific to the
229 * Ethernet hardware.
Tom Rix558bb832009-04-01 22:02:20 -0500230 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100231static void setup_net_chip(void)
232{
Dirk Behmedc7af202009-08-08 09:30:21 +0200233 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
Dirk Behmebb732be2009-01-28 21:39:58 +0100234
235 /* Configure GPMC registers */
Dirk Behmea4becd62009-08-08 09:30:22 +0200236 writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
237 writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
238 writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
239 writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
240 writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
241 writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
242 writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
Dirk Behmebb732be2009-01-28 21:39:58 +0100243
244 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
245 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
246 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
247 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
248 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
249 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
250 &ctrl_base->gpmc_nadv_ale);
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400251}
252
253/**
254 * Reset the ethernet chip.
255 */
256static void reset_net_chip(void)
257{
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400258 int ret;
259 int rst_gpio;
260
261 if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
262 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
263 } else {
264 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
265 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100266
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400267 ret = gpio_request(rst_gpio, "");
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400268 if (ret < 0) {
269 printf("Unable to get GPIO %d\n", rst_gpio);
270 return ;
271 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100272
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400273 /* Configure as output */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400274 gpio_direction_output(rst_gpio, 0);
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400275
276 /* Send a pulse on the GPIO pin */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400277 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100278 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400279 gpio_set_value(rst_gpio, 0);
Dirk Behmebb732be2009-01-28 21:39:58 +0100280 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400281 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100282}
Ben Warrenfbfdd3a2009-07-20 22:01:11 -0700283
284int board_eth_init(bd_t *bis)
285{
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500286#if defined(CONFIG_SMC911X)
Derald D. Woodsad147bf2017-12-16 14:14:50 -0600287 env_set("ethaddr", NULL);
288 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
289#else
290 return 0;
291#endif
Ben Warrenfbfdd3a2009-07-20 22:01:11 -0700292}
Sanjeev Premi654e3ce2011-07-18 09:23:00 -0400293#endif /* CONFIG_CMD_NET */
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400294
Masahiro Yamada0a780172017-05-09 20:31:39 +0900295#if defined(CONFIG_MMC)
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400296int board_mmc_init(bd_t *bis)
297{
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000298 return omap_mmc_init(0, 0, 0, -1, -1);
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400299}
Paul Kocialkowski69559892014-11-08 20:55:47 +0100300
Paul Kocialkowski69559892014-11-08 20:55:47 +0100301void board_mmc_power_init(void)
302{
303 twl4030_power_mmc_init(0);
304}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500305#endif /* CONFIG_MMC */
306
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500307#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && !defined(CONFIG_CMD_NET)
308int board_eth_init(bd_t *bis)
309{
310 return usb_eth_initialize(bis);
311}
312#endif /* CONFIG_USB_ETHER */