blob: daecb4af3e88a225212f5ac8301f760491d446b0 [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>
15#include <ns16550.h>
Ben Warrenfbfdd3a2009-07-20 22:01:11 -070016#include <netdev.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010017#include <asm/io.h>
18#include <asm/arch/mem.h>
19#include <asm/arch/mux.h>
20#include <asm/arch/sys_proto.h>
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -040021#include <asm/arch/mmc_host_def.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040022#include <asm/gpio.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010023#include <i2c.h>
Paul Kocialkowski69559892014-11-08 20:55:47 +010024#include <twl4030.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010025#include <asm/mach-types.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050026#include <asm/omap_musb.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090027#include <linux/mtd/rawnand.h>
Derald D. Woods1b01bf92017-08-06 00:00:21 -050028#include <linux/usb/ch9.h>
29#include <linux/usb/gadget.h>
30#include <linux/usb/musb.h>
Dirk Behmebb732be2009-01-28 21:39:58 +010031#include "evm.h"
32
Derald D. Woods1b01bf92017-08-06 00:00:21 -050033#ifdef CONFIG_USB_EHCI_HCD
34#include <usb.h>
35#include <asm/ehci-omap.h>
36#endif
37
38#define OMAP3EVM_GPIO_ETH_RST_GEN1 64
39#define OMAP3EVM_GPIO_ETH_RST_GEN2 7
Sriramakrishnan0f188c32011-07-18 09:21:55 -040040
John Rigby0d21ed02010-12-20 18:27:51 -070041DECLARE_GLOBAL_DATA_PTR;
42
Dirk Behme85ed7092010-12-18 07:40:28 +010043static u32 omap3_evm_version;
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053044
Dirk Behme85ed7092010-12-18 07:40:28 +010045u32 get_omap3_evm_rev(void)
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053046{
47 return omap3_evm_version;
48}
49
50static void omap3_evm_get_revision(void)
51{
Sanjeev Premi88105fb2010-11-04 16:02:32 -040052#if defined(CONFIG_CMD_NET)
53 /*
54 * Board revision can be ascertained only by identifying
55 * the Ethernet chipset.
56 */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053057 unsigned int smsc_id;
58
59 /* Ethernet PHY ID is stored at ID_REV register */
60 smsc_id = readl(CONFIG_SMC911X_BASE + 0x50) & 0xFFFF0000;
61 printf("Read back SMSC id 0x%x\n", smsc_id);
62
63 switch (smsc_id) {
64 /* SMSC9115 chipset */
65 case 0x01150000:
66 omap3_evm_version = OMAP3EVM_BOARD_GEN_1;
67 break;
68 /* SMSC 9220 chipset */
69 case 0x92200000:
70 default:
71 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
72 }
Derald D. Woods1b01bf92017-08-06 00:00:21 -050073#else /* !CONFIG_CMD_NET */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040074#if defined(CONFIG_STATIC_BOARD_REV)
Derald D. Woods1b01bf92017-08-06 00:00:21 -050075 /* Look for static defintion of the board revision */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040076 omap3_evm_version = CONFIG_STATIC_BOARD_REV;
77#else
Derald D. Woods1b01bf92017-08-06 00:00:21 -050078 /* Fallback to the default above */
Sanjeev Premi88105fb2010-11-04 16:02:32 -040079 omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
Derald D. Woods1b01bf92017-08-06 00:00:21 -050080#endif /* CONFIG_STATIC_BOARD_REV */
81#endif /* CONFIG_CMD_NET */
Ajay Kumar Gupta13fc2bd2010-06-10 11:20:49 +053082}
83
Derald D. Woods1b01bf92017-08-06 00:00:21 -050084#if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
85/* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +053086u8 omap3_evm_need_extvbus(void)
87{
88 u8 retval = 0;
89
90 if (get_omap3_evm_rev() >= OMAP3EVM_BOARD_GEN_2)
91 retval = 1;
92
93 return retval;
94}
Derald D. Woods1b01bf92017-08-06 00:00:21 -050095#endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
Ajay Kumar Guptaaeeac6b2010-06-10 11:20:50 +053096
97/*
Dirk Behmebb732be2009-01-28 21:39:58 +010098 * Routine: board_init
99 * Description: Early hardware init.
Tom Rix558bb832009-04-01 22:02:20 -0500100 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100101int board_init(void)
102{
Dirk Behmebb732be2009-01-28 21:39:58 +0100103 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
104 /* board id for Linux */
105 gd->bd->bi_arch_number = MACH_TYPE_OMAP3EVM;
106 /* boot param addr */
107 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
108
109 return 0;
110}
111
Derald D. Woods17f8f982017-09-02 17:43:05 -0500112#if defined(CONFIG_SPL_OS_BOOT)
113int spl_start_uboot(void)
114{
115 /* break into full u-boot on 'c' */
116 if (serial_tstc() && serial_getc() == 'c')
117 return 1;
118
119 return 0;
120}
121#endif /* CONFIG_SPL_OS_BOOT */
122
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500123#if defined(CONFIG_SPL_BUILD)
Tom Rini988a2352011-11-18 12:48:09 +0000124/*
125 * Routine: get_board_mem_timings
126 * Description: If we use SPL then there is no x-loader nor config header
127 * so we have to setup the DDR timings ourself on the first bank. This
128 * provides the timing values back to the function that configures
129 * the memory.
130 */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000131void get_board_mem_timings(struct board_sdrc_timings *timings)
Tom Rini988a2352011-11-18 12:48:09 +0000132{
133 int pop_mfr, pop_id;
134
135 /*
136 * We need to identify what PoP memory is on the board so that
137 * we know what timings to use. To map the ID values please see
138 * nand_ids.c
139 */
140 identify_nand_chip(&pop_mfr, &pop_id);
141
142 if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
143 /* 256MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000144 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
145 timings->ctrla = HYNIX_V_ACTIMA_200;
146 timings->ctrlb = HYNIX_V_ACTIMB_200;
Tom Rini988a2352011-11-18 12:48:09 +0000147 } else {
148 /* 128MB DDR */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000149 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
150 timings->ctrla = MICRON_V_ACTIMA_165;
151 timings->ctrlb = MICRON_V_ACTIMB_165;
Tom Rini988a2352011-11-18 12:48:09 +0000152 }
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000153 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
154 timings->mr = MICRON_V_MR_165;
Tom Rini988a2352011-11-18 12:48:09 +0000155}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500156#endif /* CONFIG_SPL_BUILD */
157
158#if defined(CONFIG_USB_MUSB_OMAP2PLUS)
159static struct musb_hdrc_config musb_config = {
160 .multipoint = 1,
161 .dyn_fifo = 1,
162 .num_eps = 16,
163 .ram_bits = 12,
164};
165
166static struct omap_musb_board_data musb_board_data = {
167 .interface_type = MUSB_INTERFACE_ULPI,
168};
169
170static struct musb_hdrc_platform_data musb_plat = {
171#if defined(CONFIG_USB_MUSB_HOST)
172 .mode = MUSB_HOST,
173#elif defined(CONFIG_USB_MUSB_GADGET)
174 .mode = MUSB_PERIPHERAL,
175#else
176#error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
177#endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
178 .config = &musb_config,
179 .power = 100,
180 .platform_ops = &omap2430_ops,
181 .board_data = &musb_board_data,
182};
183#endif /* CONFIG_USB_MUSB_OMAP2PLUS */
Tom Rini988a2352011-11-18 12:48:09 +0000184
Tom Rix558bb832009-04-01 22:02:20 -0500185/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100186 * Routine: misc_init_r
187 * Description: Init ethernet (done here so udelay works)
Tom Rix558bb832009-04-01 22:02:20 -0500188 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100189int misc_init_r(void)
190{
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500191 twl4030_power_init();
Dirk Behmebb732be2009-01-28 21:39:58 +0100192
Adam Ford49e96f22017-08-07 13:11:19 -0500193#ifdef CONFIG_SYS_I2C_OMAP24XX
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200194 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
Dirk Behmebb732be2009-01-28 21:39:58 +0100195#endif
196
197#if defined(CONFIG_CMD_NET)
198 setup_net_chip();
199#endif
Sanjeev Premi88105fb2010-11-04 16:02:32 -0400200 omap3_evm_get_revision();
Dirk Behmebb732be2009-01-28 21:39:58 +0100201
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400202#if defined(CONFIG_CMD_NET)
203 reset_net_chip();
204#endif
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200205 omap_die_id_display();
Dirk Behme12dbcf62009-03-12 19:30:50 +0100206
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500207#if defined(CONFIG_USB_MUSB_OMAP2PLUS)
208 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
209#endif
210
211#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
212 omap_die_id_usbethaddr();
213#endif
Dirk Behmebb732be2009-01-28 21:39:58 +0100214 return 0;
215}
216
Tom Rix558bb832009-04-01 22:02:20 -0500217/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100218 * Routine: set_muxconf_regs
219 * Description: Setting up the configuration Mux registers specific to the
220 * hardware. Many pins need to be moved from protect to primary
221 * mode.
Tom Rix558bb832009-04-01 22:02:20 -0500222 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100223void set_muxconf_regs(void)
224{
225 MUX_EVM();
226}
227
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500228#if defined(CONFIG_CMD_NET)
Tom Rix558bb832009-04-01 22:02:20 -0500229/*
Dirk Behmebb732be2009-01-28 21:39:58 +0100230 * Routine: setup_net_chip
231 * Description: Setting up the configuration GPMC registers specific to the
232 * Ethernet hardware.
Tom Rix558bb832009-04-01 22:02:20 -0500233 */
Dirk Behmebb732be2009-01-28 21:39:58 +0100234static void setup_net_chip(void)
235{
Dirk Behmedc7af202009-08-08 09:30:21 +0200236 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
Dirk Behmebb732be2009-01-28 21:39:58 +0100237
238 /* Configure GPMC registers */
Dirk Behmea4becd62009-08-08 09:30:22 +0200239 writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
240 writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
241 writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
242 writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
243 writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
244 writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
245 writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
Dirk Behmebb732be2009-01-28 21:39:58 +0100246
247 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
248 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
249 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
250 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
251 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
252 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
253 &ctrl_base->gpmc_nadv_ale);
Sanjeev Premi5e09e442011-07-18 09:20:15 -0400254}
255
256/**
257 * Reset the ethernet chip.
258 */
259static void reset_net_chip(void)
260{
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400261 int ret;
262 int rst_gpio;
263
264 if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
265 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
266 } else {
267 rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
268 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100269
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400270 ret = gpio_request(rst_gpio, "");
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400271 if (ret < 0) {
272 printf("Unable to get GPIO %d\n", rst_gpio);
273 return ;
274 }
Dirk Behmebb732be2009-01-28 21:39:58 +0100275
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400276 /* Configure as output */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400277 gpio_direction_output(rst_gpio, 0);
Sriramakrishnan0f188c32011-07-18 09:21:55 -0400278
279 /* Send a pulse on the GPIO pin */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400280 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100281 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400282 gpio_set_value(rst_gpio, 0);
Dirk Behmebb732be2009-01-28 21:39:58 +0100283 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400284 gpio_set_value(rst_gpio, 1);
Dirk Behmebb732be2009-01-28 21:39:58 +0100285}
Ben Warrenfbfdd3a2009-07-20 22:01:11 -0700286
287int board_eth_init(bd_t *bis)
288{
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500289#if defined(CONFIG_SMC911X)
Derald D. Woodsad147bf2017-12-16 14:14:50 -0600290 env_set("ethaddr", NULL);
291 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
292#else
293 return 0;
294#endif
Ben Warrenfbfdd3a2009-07-20 22:01:11 -0700295}
Sanjeev Premi654e3ce2011-07-18 09:23:00 -0400296#endif /* CONFIG_CMD_NET */
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400297
Masahiro Yamada0a780172017-05-09 20:31:39 +0900298#if defined(CONFIG_MMC)
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400299int board_mmc_init(bd_t *bis)
300{
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000301 return omap_mmc_init(0, 0, 0, -1, -1);
Vaibhav Hiremath4fdf2b72011-09-03 21:42:35 -0400302}
Paul Kocialkowski69559892014-11-08 20:55:47 +0100303
Paul Kocialkowski69559892014-11-08 20:55:47 +0100304void board_mmc_power_init(void)
305{
306 twl4030_power_mmc_init(0);
307}
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500308#endif /* CONFIG_MMC */
309
Derald D. Woods17f8f982017-09-02 17:43:05 -0500310#if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
311/* Call usb_stop() before starting the kernel */
312void show_boot_progress(int val)
313{
314 if (val == BOOTSTAGE_ID_RUN_OS)
315 usb_stop();
316}
317
Derald D. Woods1b01bf92017-08-06 00:00:21 -0500318static struct omap_usbhs_board_data usbhs_bdata = {
319 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
320 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
321 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
322};
323
324int ehci_hcd_init(int index, enum usb_init_type init,
325 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
326{
327 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
328}
329
330int ehci_hcd_stop(int index)
331{
332 return omap_ehci_hcd_stop();
333}
334#endif /* CONFIG_USB_EHCI_HCD */
335
336#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && !defined(CONFIG_CMD_NET)
337int board_eth_init(bd_t *bis)
338{
339 return usb_eth_initialize(bis);
340}
341#endif /* CONFIG_USB_ETHER */