blob: 1f0433dcc0471fb638748f67829f974a9cafc3e8 [file] [log] [blame]
Dirk Behmebb732be2009-01-28 21:39:58 +01001/*
Tom Rini988a2352011-11-18 12:48:09 +00002 * (C) Copyright 2004-2011
Dirk Behmebb732be2009-01-28 21:39:58 +01003 * Texas Instruments, <www.ti.com>
4 *
5 * Author :
6 * Manikandan Pillai <mani.pillai@ti.com>
7 *
8 * Derived from Beagle Board and 3430 SDP code by
9 * Richard Woodruff <r-woodruff2@ti.com>
10 * Syed Mohammed Khasim <khasim@ti.com>
11 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Dirk Behmebb732be2009-01-28 21:39:58 +010013 */
14#include <common.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050015#include <dm.h>
16#include <ns16550.h>
Ben Warrenfbfdd3a2009-07-20 22:01:11 -070017#include <netdev.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010018#include <asm/io.h>
19#include <asm/arch/mem.h>
20#include <asm/arch/mux.h>
21#include <asm/arch/sys_proto.h>
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -040022#include <asm/arch/mmc_host_def.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040023#include <asm/gpio.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010024#include <i2c.h>
Paul Kocialkowski69559892014-11-08 20:55:47 +010025#include <twl4030.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010026#include <asm/mach-types.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050027#include <asm/omap_musb.h>
Tom Rini988a2352011-11-18 12:48:09 +000028#include <linux/mtd/nand.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050029#include <linux/usb/ch9.h>
30#include <linux/usb/gadget.h>
31#include <linux/usb/musb.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010032#include "evm.h"
33
Derald D. Woods1b01bf92017-08-06 00:00:21 -050034#ifdef CONFIG_USB_EHCI_HCD
35#include <usb.h>
36#include <asm/ehci-omap.h>
37#endif
38
39#define OMAP3EVM_GPIO_ETH_RST_GEN1 64
40#define OMAP3EVM_GPIO_ETH_RST_GEN2 7
Sriramakrishnan0f188c32011-07-18 09:21:55 -040041
John Rigby0d21ed02010-12-20 18:27:51 -070042DECLARE_GLOBAL_DATA_PTR;
43
Derald D. Woods1b01bf92017-08-06 00:00:21 -050044static const struct ns16550_platdata omap3_evm_serial = {
45 .base = OMAP34XX_UART1,
46 .reg_shift = 2,
47 .clock = V_NS16550_CLK,
48 .fcr = UART_FCR_DEFVAL,
49};
50
51U_BOOT_DEVICE(omap3_evm_uart) = {
52 "ns16550_serial",
53 &omap3_evm_serial
54};
55
Dirk Behme85ed7092010-12-18 07:40:28 +010056static u32 omap3_evm_version;
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053057
Dirk Behme85ed7092010-12-18 07:40:28 +010058u32 get_omap3_evm_rev(void)
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053059{
60 return omap3_evm_version;
61}
62
63static void omap3_evm_get_revision(void)
64{
Sanjeev Premi88105fb2010-11-04 16:02:32 -040065#if defined(CONFIG_CMD_NET)
66 /*
67 * Board revision can be ascertained only by identifying
68 * the Ethernet chipset.
69 */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053070 unsigned int smsc_id;
71
72 /* Ethernet PHY ID is stored at ID_REV register */
73 smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000;
74 printf("Read back SMSC id 0x%x\n", smsc_id);
75
76 switch (smsc_id) {
77 /* SMSC9115 chipset */
78 case 0x01150000:
79 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
80 break;
81 /* SMSC 9220 chipset */
82 case 0x92200000:
83 default:
84 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
85 }
Derald D. Woods1b01bf92017-08-06 00:00:21 -050086#else /* !CONFIG_CMD_NET */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040087#if defined(CONFIG_STATIC_BOARD_REV)
Derald D. Woods1b01bf92017-08-06 00:00:21 -050088 /* Look for static defintion of the board revision */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040089 omap3_evm_version = CONFIG_STATIC_BOARD_REV;
90#else
Derald D. Woods1b01bf92017-08-06 00:00:21 -050091 /* Fallback to the default above */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040092 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
Derald D. Woods1b01bf92017-08-06 00:00:21 -050093#endif /* CONFIG_STATIC_BOARD_REV */
94#endif /* CONFIG_CMD_NET */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053095}
96
Derald D. Woods1b01bf92017-08-06 00:00:21 -050097#if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
98/* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +053099u8 omap3_evm_need_extvbus(void)
100{
101 u8 retval = 0;
102
103 if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2)
104 retval = 1;
105
106 return retval;
107}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500108#endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +0530109
110/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100111 * Routine: board_init
112 * Description: Early hardware init.
Tom Rix558bb832009-04-01 22:02:20 -0500113 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100114int board_init(void)
115{
Dirk Behmebb732be2009-01-28 21:39:58 +0100116 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
117 /* board id for Linux */
118 gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM;
119 /* boot param addr */
120 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
121
122 return 0;
123}
124
Derald D. Woods17f8f982017-09-02 17:43:05 -0500125#if defined(CONFIG_SPL_OS_BOOT)
126int spl_start_uboot(void)
127{
128 /* break into full u-boot on 'c' */
129 if (serial_tstc() && serial_getc() == 'c')
130 return 1;
131
132 return 0;
133}
134#endif /* CONFIG_SPL_OS_BOOT */
135
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500136#if defined(CONFIG_SPL_BUILD)
Tom Rini988a2352011-11-18 12:48:09 +0000137/*
138 * Routine: get_board_mem_timings
139 * Description: If we use SPL then there is no x-loader nor config header
140 * so we have to setup the DDR timings ourself on the first bank. This
141 * provides the timing values back to the function that configures
142 * the memory.
143 */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000144void get_board_mem_timings(struct board_sdrc_timings *timings)
Tom Rini988a2352011-11-18 12:48:09 +0000145{
146 int pop_mfr, pop_id;
147
148 /*
149 * We need to identify what PoP memory is on the board so that
150 * we know what timings to use. To map the ID values please see
151 * nand_ids.c
152 */
153 identify_nand_chip(&pop_mfr, &pop_id);
154
155 if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
156 /* 256MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000157 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
158 timings->ctrla = HYNIX_V_ACTIMA_200;
159 timings->ctrlb = HYNIX_V_ACTIMB_200;
Tom Rini988a2352011-11-18 12:48:09 +0000160 } else {
161 /* 128MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000162 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
163 timings->ctrla = MICRON_V_ACTIMA_165;
164 timings->ctrlb = MICRON_V_ACTIMB_165;
Tom Rini988a2352011-11-18 12:48:09 +0000165 }
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000166 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
167 timings->mr = MICRON_V_MR_165;
Tom Rini988a2352011-11-18 12:48:09 +0000168}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500169#endif /* CONFIG_SPL_BUILD */
170
171#if defined(CONFIG_USB_MUSB_OMAP2PLUS)
172static struct musb_hdrc_config musb_config = {
173 .multipoint = 1,
174 .dyn_fifo = 1,
175 .num_eps = 16,
176 .ram_bits = 12,
177};
178
179static struct omap_musb_board_data musb_board_data = {
180 .interface_type = MUSB_INTERFACE_ULPI,
181};
182
183static struct musb_hdrc_platform_data musb_plat = {
184#if defined(CONFIG_USB_MUSB_HOST)
185 .mode = MUSB_HOST,
186#elif defined(CONFIG_USB_MUSB_GADGET)
187 .mode = MUSB_PERIPHERAL,
188#else
189#error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
190#endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
191 .config = &musb_config,
192 .power = 100,
193 .platform_ops = &omap2430_ops,
194 .board_data = &musb_board_data,
195};
196#endif /* CONFIG_USB_MUSB_OMAP2PLUS */
Tom Rini988a2352011-11-18 12:48:09 +0000197
Tom Rix558bb832009-04-01 22:02:20 -0500198/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100199 * Routine: misc_init_r
200 * Description: Init ethernet (done here so udelay works)
Tom Rix558bb832009-04-01 22:02:20 -0500201 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100202int misc_init_r(void)
203{
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500204 twl4030_power_init();
Dirk Behmebb732be2009-01-28 21:39:58 +0100205
Adam Ford49e96f22017-08-07 13:11:19 -0500206#ifdef CONFIG_SYS_I2C_OMAP24XX
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200207 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Dirk Behmebb732be2009-01-28 21:39:58 +0100208#endif
209
210#if defined(CONFIG_CMD_NET)
211 setup_net_chip();
212#endif
Sanjeev Premi88105fb2010-11-04 16:02:32 -0400213 omap3_evm_get_revision();
Dirk Behmebb732be2009-01-28 21:39:58 +0100214
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400215#if defined(CONFIG_CMD_NET)
216 reset_net_chip();
217#endif
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200218 omap_die_id_display();
Dirk Behme12dbcf62009-03-12 19:30:50 +0100219
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500220#if defined(CONFIG_USB_MUSB_OMAP2PLUS)
221 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
222#endif
223
224#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
225 omap_die_id_usbethaddr();
226#endif
Dirk Behmebb732be2009-01-28 21:39:58 +0100227 return 0;
228}
229
Tom Rix558bb832009-04-01 22:02:20 -0500230/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100231 * Routine: set_muxconf_regs
232 * Description: Setting up the configuration Mux registers specific to the
233 * hardware. Many pins need to be moved from protect to primary
234 * mode.
Tom Rix558bb832009-04-01 22:02:20 -0500235 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100236void set_muxconf_regs(void)
237{
238 MUX_EVM();
239}
240
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500241#if defined(CONFIG_CMD_NET)
Tom Rix558bb832009-04-01 22:02:20 -0500242/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100243 * Routine: setup_net_chip
244 * Description: Setting up the configuration GPMC registers specific to the
245 * Ethernet hardware.
Tom Rix558bb832009-04-01 22:02:20 -0500246 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100247static void setup_net_chip(void)
248{
Dirk Behmedc7af202009-08-08 09:30:21 +0200249 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
Dirk Behmebb732be2009-01-28 21:39:58 +0100250
251 /* Configure GPMC registers */
Dirk Behmea4becd62009-08-08 09:30:22 +0200252 writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
253 writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
254 writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
255 writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
256 writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
257 writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
258 writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
Dirk Behmebb732be2009-01-28 21:39:58 +0100259
260 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
261 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
262 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
263 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
264 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
265 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
266 &ctrl_base->gpmc_nadv_ale);
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400267}
268
269/**
270 * Reset the ethernet chip.
271 */
272static void reset_net_chip(void)
273{
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400274 int ret;
275 int rst_gpio;
276
277 if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
278 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
279 } else {
280 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
281 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100282
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400283 ret = gpio_request(rst_gpio, "");
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400284 if (ret < 0) {
285 printf("Unable to get GPIO %d\n", rst_gpio);
286 return ;
287 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100288
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400289 /* Configure as output */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400290 gpio_direction_output(rst_gpio, 0);
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400291
292 /* Send a pulse on the GPIO pin */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400293 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100294 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400295 gpio_set_value(rst_gpio, 0);
Dirk Behmebb732be2009-01-28 21:39:58 +0100296 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400297 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100298}
Ben Warrenfbfdd3a2009-07-20 22:01:11 -0700299
300int board_eth_init(bd_t *bis)
301{
302 int rc = 0;
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500303#if defined(CONFIG_SMC911X)
Sanjeev Premi9a2c3ac2011-09-02 05:57:16 +0000304#define STR_ENV_ETHADDR "ethaddr"
305
306 struct eth_device *dev;
307 uchar eth_addr[6];
308
Ben Warrenfbfdd3a2009-07-20 22:01:11 -0700309 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
Sanjeev Premi9a2c3ac2011-09-02 05:57:16 +0000310
Simon Glass399a9ce2017-08-03 12:22:14 -0600311 if (!eth_env_get_enetaddr(STR_ENV_ETHADDR, eth_addr)) {
Sanjeev Premi9a2c3ac2011-09-02 05:57:16 +0000312 dev = eth_get_dev_by_index(0);
313 if (dev) {
Simon Glass8551d552017-08-03 12:22:11 -0600314 eth_env_set_enetaddr(STR_ENV_ETHADDR, dev->enetaddr);
Sanjeev Premi9a2c3ac2011-09-02 05:57:16 +0000315 } else {
316 printf("omap3evm: Couldn't get eth device\n");
317 rc = -1;
318 }
319 }
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500320#endif /* CONFIG_SMC911X */
Ben Warrenfbfdd3a2009-07-20 22:01:11 -0700321 return rc;
322}
Sanjeev Premi654e3ce2011-07-18 09:23:00 -0400323#endif /* CONFIG_CMD_NET */
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400324
Masahiro Yamada0a780172017-05-09 20:31:39 +0900325#if defined(CONFIG_MMC)
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400326int board_mmc_init(bd_t *bis)
327{
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000328 return omap_mmc_init(0, 0, 0, -1, -1);
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400329}
Paul Kocialkowski69559892014-11-08 20:55:47 +0100330
Paul Kocialkowski69559892014-11-08 20:55:47 +0100331void board_mmc_power_init(void)
332{
333 twl4030_power_mmc_init(0);
334}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500335#endif /* CONFIG_MMC */
336
Derald D. Woods17f8f982017-09-02 17:43:05 -0500337#if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
338/* Call usb_stop() before starting the kernel */
339void show_boot_progress(int val)
340{
341 if (val == BOOTSTAGE_ID_RUN_OS)
342 usb_stop();
343}
344
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500345static struct omap_usbhs_board_data usbhs_bdata = {
346 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
347 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
348 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
349};
350
351int ehci_hcd_init(int index, enum usb_init_type init,
352 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
353{
354 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
355}
356
357int ehci_hcd_stop(int index)
358{
359 return omap_ehci_hcd_stop();
360}
361#endif /* CONFIG_USB_EHCI_HCD */
362
363#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && !defined(CONFIG_CMD_NET)
364int board_eth_init(bd_t *bis)
365{
366 return usb_eth_initialize(bis);
367}
368#endif /* CONFIG_USB_ETHER */