xref: /openbmc/u-boot/board/ti/evm/evm.c (revision 90340c87)
1 /*
2  * (C) Copyright 2004-2011
3  * 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  *
12  * SPDX-License-Identifier:	GPL-2.0+
13  */
14 #include <common.h>
15 #include <dm.h>
16 #include <ns16550.h>
17 #include <netdev.h>
18 #include <asm/io.h>
19 #include <asm/arch/mem.h>
20 #include <asm/arch/mux.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/arch/mmc_host_def.h>
23 #include <asm/gpio.h>
24 #include <i2c.h>
25 #include <twl4030.h>
26 #include <asm/mach-types.h>
27 #include <asm/omap_musb.h>
28 #include <linux/mtd/nand.h>
29 #include <linux/usb/ch9.h>
30 #include <linux/usb/gadget.h>
31 #include <linux/usb/musb.h>
32 #include "evm.h"
33 
34 #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
41 
42 DECLARE_GLOBAL_DATA_PTR;
43 
44 static 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 
51 U_BOOT_DEVICE(omap3_evm_uart) = {
52 	"ns16550_serial",
53 	&omap3_evm_serial
54 };
55 
56 static u32 omap3_evm_version;
57 
58 u32 get_omap3_evm_rev(void)
59 {
60 	return omap3_evm_version;
61 }
62 
63 static void omap3_evm_get_revision(void)
64 {
65 #if defined(CONFIG_CMD_NET)
66 	/*
67 	 * Board revision can be ascertained only by identifying
68 	 * the Ethernet chipset.
69 	 */
70 	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        }
86 #else /* !CONFIG_CMD_NET */
87 #if defined(CONFIG_STATIC_BOARD_REV)
88 	/* Look for static defintion of the board revision */
89 	omap3_evm_version = CONFIG_STATIC_BOARD_REV;
90 #else
91 	/* Fallback to the default above */
92 	omap3_evm_version = OMAP3EVM_BOARD_GEN_2;
93 #endif /* CONFIG_STATIC_BOARD_REV */
94 #endif /* CONFIG_CMD_NET */
95 }
96 
97 #if defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)
98 /* MUSB port on OMAP3EVM Rev >= E requires extvbus programming. */
99 u8 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 }
108 #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
109 
110 /*
111  * Routine: board_init
112  * Description: Early hardware init.
113  */
114 int board_init(void)
115 {
116 	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 
125 #if defined(CONFIG_SPL_BUILD)
126 /*
127  * Routine: get_board_mem_timings
128  * Description: If we use SPL then there is no x-loader nor config header
129  * so we have to setup the DDR timings ourself on the first bank.  This
130  * provides the timing values back to the function that configures
131  * the memory.
132  */
133 void get_board_mem_timings(struct board_sdrc_timings *timings)
134 {
135 	int pop_mfr, pop_id;
136 
137 	/*
138 	 * We need to identify what PoP memory is on the board so that
139 	 * we know what timings to use.  To map the ID values please see
140 	 * nand_ids.c
141 	 */
142 	identify_nand_chip(&pop_mfr, &pop_id);
143 
144 	if (pop_mfr == NAND_MFR_HYNIX && pop_id == 0xbc) {
145 		/* 256MB DDR */
146 		timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
147 		timings->ctrla = HYNIX_V_ACTIMA_200;
148 		timings->ctrlb = HYNIX_V_ACTIMB_200;
149 	} else {
150 		/* 128MB DDR */
151 		timings->mcfg = MICRON_V_MCFG_165(128 << 20);
152 		timings->ctrla = MICRON_V_ACTIMA_165;
153 		timings->ctrlb = MICRON_V_ACTIMB_165;
154 	}
155 	timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
156 	timings->mr = MICRON_V_MR_165;
157 }
158 #endif /* CONFIG_SPL_BUILD */
159 
160 #if defined(CONFIG_USB_MUSB_OMAP2PLUS)
161 static struct musb_hdrc_config musb_config = {
162 	.multipoint     = 1,
163 	.dyn_fifo       = 1,
164 	.num_eps        = 16,
165 	.ram_bits       = 12,
166 };
167 
168 static struct omap_musb_board_data musb_board_data = {
169 	.interface_type	= MUSB_INTERFACE_ULPI,
170 };
171 
172 static struct musb_hdrc_platform_data musb_plat = {
173 #if defined(CONFIG_USB_MUSB_HOST)
174 	.mode           = MUSB_HOST,
175 #elif defined(CONFIG_USB_MUSB_GADGET)
176 	.mode		= MUSB_PERIPHERAL,
177 #else
178 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
179 #endif /* CONFIG_USB_MUSB_{GADGET,HOST} */
180 	.config         = &musb_config,
181 	.power          = 100,
182 	.platform_ops	= &omap2430_ops,
183 	.board_data	= &musb_board_data,
184 };
185 #endif /* CONFIG_USB_MUSB_OMAP2PLUS */
186 
187 /*
188  * Routine: misc_init_r
189  * Description: Init ethernet (done here so udelay works)
190  */
191 int misc_init_r(void)
192 {
193 	twl4030_power_init();
194 
195 #ifdef CONFIG_SYS_I2C_OMAP24XX
196 	i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
197 #endif
198 
199 #if defined(CONFIG_CMD_NET)
200 	setup_net_chip();
201 #endif
202 	omap3_evm_get_revision();
203 
204 #if defined(CONFIG_CMD_NET)
205 	reset_net_chip();
206 #endif
207 	omap_die_id_display();
208 
209 #if defined(CONFIG_USB_MUSB_OMAP2PLUS)
210 	musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
211 #endif
212 
213 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
214 	omap_die_id_usbethaddr();
215 #endif
216 	return 0;
217 }
218 
219 /*
220  * Routine: set_muxconf_regs
221  * Description: Setting up the configuration Mux registers specific to the
222  *		hardware. Many pins need to be moved from protect to primary
223  *		mode.
224  */
225 void set_muxconf_regs(void)
226 {
227 	MUX_EVM();
228 }
229 
230 #if defined(CONFIG_CMD_NET)
231 /*
232  * Routine: setup_net_chip
233  * Description: Setting up the configuration GPMC registers specific to the
234  *		Ethernet hardware.
235  */
236 static void setup_net_chip(void)
237 {
238 	struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
239 
240 	/* Configure GPMC registers */
241 	writel(NET_GPMC_CONFIG1, &gpmc_cfg->cs[5].config1);
242 	writel(NET_GPMC_CONFIG2, &gpmc_cfg->cs[5].config2);
243 	writel(NET_GPMC_CONFIG3, &gpmc_cfg->cs[5].config3);
244 	writel(NET_GPMC_CONFIG4, &gpmc_cfg->cs[5].config4);
245 	writel(NET_GPMC_CONFIG5, &gpmc_cfg->cs[5].config5);
246 	writel(NET_GPMC_CONFIG6, &gpmc_cfg->cs[5].config6);
247 	writel(NET_GPMC_CONFIG7, &gpmc_cfg->cs[5].config7);
248 
249 	/* Enable off mode for NWE in PADCONF_GPMC_NWE register */
250 	writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
251 	/* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
252 	writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
253 	/* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
254 	writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
255 		&ctrl_base->gpmc_nadv_ale);
256 }
257 
258 /**
259  * Reset the ethernet chip.
260  */
261 static void reset_net_chip(void)
262 {
263 	int ret;
264 	int rst_gpio;
265 
266 	if (get_omap3_evm_rev() == OMAP3EVM_BOARD_GEN_1) {
267 		rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN1;
268 	} else {
269 		rst_gpio = OMAP3EVM_GPIO_ETH_RST_GEN2;
270 	}
271 
272 	ret = gpio_request(rst_gpio, "");
273 	if (ret < 0) {
274 		printf("Unable to get GPIO %d\n", rst_gpio);
275 		return ;
276 	}
277 
278 	/* Configure as output */
279 	gpio_direction_output(rst_gpio, 0);
280 
281 	/* Send a pulse on the GPIO pin */
282 	gpio_set_value(rst_gpio, 1);
283 	udelay(1);
284 	gpio_set_value(rst_gpio, 0);
285 	udelay(1);
286 	gpio_set_value(rst_gpio, 1);
287 }
288 
289 int board_eth_init(bd_t *bis)
290 {
291 	int rc = 0;
292 #if defined(CONFIG_SMC911X)
293 #define STR_ENV_ETHADDR	"ethaddr"
294 
295 	struct eth_device *dev;
296 	uchar eth_addr[6];
297 
298 	rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
299 
300 	if (!eth_env_get_enetaddr(STR_ENV_ETHADDR, eth_addr)) {
301 		dev = eth_get_dev_by_index(0);
302 		if (dev) {
303 			eth_env_set_enetaddr(STR_ENV_ETHADDR, dev->enetaddr);
304 		} else {
305 			printf("omap3evm: Couldn't get eth device\n");
306 			rc = -1;
307 		}
308 	}
309 #endif /* CONFIG_SMC911X */
310 	return rc;
311 }
312 #endif /* CONFIG_CMD_NET */
313 
314 #if defined(CONFIG_MMC)
315 int board_mmc_init(bd_t *bis)
316 {
317 	return omap_mmc_init(0, 0, 0, -1, -1);
318 }
319 
320 void board_mmc_power_init(void)
321 {
322 	twl4030_power_mmc_init(0);
323 }
324 #endif /* CONFIG_MMC */
325 
326 #if defined(CONFIG_USB_EHCI_HCD)
327 static struct omap_usbhs_board_data usbhs_bdata = {
328 	.port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
329 	.port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
330 	.port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
331 };
332 
333 int ehci_hcd_init(int index, enum usb_init_type init,
334 		struct ehci_hccr **hccr, struct ehci_hcor **hcor)
335 {
336 	return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
337 }
338 
339 int ehci_hcd_stop(int index)
340 {
341 	return omap_ehci_hcd_stop();
342 }
343 #endif /* CONFIG_USB_EHCI_HCD */
344 
345 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) && !defined(CONFIG_CMD_NET)
346 int board_eth_init(bd_t *bis)
347 {
348 	return usb_eth_initialize(bis);
349 }
350 #endif /* CONFIG_USB_ETHER */
351