1 /*
2  * am3517evm.c - board file for TI's AM3517 family of devices.
3  *
4  * Author: Vaibhav Hiremath <hvaibhav@ti.com>
5  *
6  * Based on ti/evm/evm.c
7  *
8  * Copyright (C) 2010
9  * Texas Instruments Incorporated - http://www.ti.com/
10  *
11  * SPDX-License-Identifier:	GPL-2.0+
12  */
13 
14 #include <common.h>
15 #include <asm/io.h>
16 #include <asm/omap_musb.h>
17 #include <asm/arch/am35x_def.h>
18 #include <asm/arch/mem.h>
19 #include <asm/arch/mux.h>
20 #include <asm/arch/sys_proto.h>
21 #include <asm/arch/mmc_host_def.h>
22 #include <asm/arch/musb.h>
23 #include <asm/mach-types.h>
24 #include <linux/errno.h>
25 #include <asm/gpio.h>
26 #include <linux/usb/ch9.h>
27 #include <linux/usb/gadget.h>
28 #include <linux/usb/musb.h>
29 #include <i2c.h>
30 #include <netdev.h>
31 #include "am3517evm.h"
32 
33 DECLARE_GLOBAL_DATA_PTR;
34 
35 #define AM3517_IP_SW_RESET	0x48002598
36 #define CPGMACSS_SW_RST		(1 << 1)
37 
38 /*
39  * Routine: board_init
40  * Description: Early hardware init.
41  */
42 int board_init(void)
43 {
44 	gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
45 	/* board id for Linux */
46 	gd->bd->bi_arch_number = MACH_TYPE_OMAP3517EVM;
47 	/* boot param addr */
48 	gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
49 
50 	return 0;
51 }
52 
53 #ifdef CONFIG_USB_MUSB_AM35X
54 static struct musb_hdrc_config musb_config = {
55 	.multipoint     = 1,
56 	.dyn_fifo       = 1,
57 	.num_eps        = 16,
58 	.ram_bits       = 12,
59 };
60 
61 static struct omap_musb_board_data musb_board_data = {
62 	.set_phy_power		= am35x_musb_phy_power,
63 	.clear_irq		= am35x_musb_clear_irq,
64 	.reset			= am35x_musb_reset,
65 };
66 
67 static struct musb_hdrc_platform_data musb_plat = {
68 #if defined(CONFIG_USB_MUSB_HOST)
69 	.mode           = MUSB_HOST,
70 #elif defined(CONFIG_USB_MUSB_GADGET)
71 	.mode		= MUSB_PERIPHERAL,
72 #else
73 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
74 #endif
75 	.config         = &musb_config,
76 	.power          = 250,
77 	.platform_ops	= &am35x_ops,
78 	.board_data	= &musb_board_data,
79 };
80 
81 static void am3517_evm_musb_init(void)
82 {
83 	/*
84 	 * Set up USB clock/mode in the DEVCONF2 register.
85 	 * USB2.0 PHY reference clock is 13 MHz
86 	 */
87 	clrsetbits_le32(&am35x_scm_general_regs->devconf2,
88 			CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE,
89 			CONF2_REFFREQ_13MHZ | CONF2_SESENDEN |
90 			CONF2_VBDTCTEN | CONF2_DATPOL);
91 
92 	musb_register(&musb_plat, &musb_board_data,
93 			(void *)AM35XX_IPSS_USBOTGSS_BASE);
94 }
95 #else
96 #define am3517_evm_musb_init() do {} while (0)
97 #endif
98 
99 /*
100  * Routine: misc_init_r
101  * Description: Init i2c, ethernet, etc... (done here so udelay works)
102  */
103 int misc_init_r(void)
104 {
105 	volatile unsigned int ctr;
106 	u32 reset;
107 
108 #ifdef CONFIG_SYS_I2C_OMAP34XX
109 	i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
110 #endif
111 
112 	omap_die_id_display();
113 
114 	am3517_evm_musb_init();
115 
116 	/* activate PHY reset */
117 	gpio_direction_output(30, 0);
118 	gpio_set_value(30, 0);
119 
120 	ctr  = 0;
121 	do {
122 		udelay(1000);
123 		ctr++;
124 	} while (ctr < 300);
125 
126 	/* deactivate PHY reset */
127 	gpio_set_value(30, 1);
128 
129 	/* allow the PHY to stabilize and settle down */
130 	ctr = 0;
131 	do {
132 		udelay(1000);
133 		ctr++;
134 	} while (ctr < 300);
135 
136 	/* ensure that the module is out of reset */
137 	reset = readl(AM3517_IP_SW_RESET);
138 	reset &= (~CPGMACSS_SW_RST);
139 	writel(reset,AM3517_IP_SW_RESET);
140 
141 	return 0;
142 }
143 
144 /*
145  * Routine: set_muxconf_regs
146  * Description: Setting up the configuration Mux registers specific to the
147  *		hardware. Many pins need to be moved from protect to primary
148  *		mode.
149  */
150 void set_muxconf_regs(void)
151 {
152 	MUX_AM3517EVM();
153 }
154 
155 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
156 int board_mmc_init(bd_t *bis)
157 {
158 	return omap_mmc_init(0, 0, 0, -1, -1);
159 }
160 #endif
161 
162 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
163 int board_eth_init(bd_t *bis)
164 {
165 	int rv, n = 0;
166 
167 	rv = cpu_eth_init(bis);
168 	if (rv > 0)
169 		n += rv;
170 
171 	rv = usb_eth_initialize(bis);
172 	if (rv > 0)
173 		n += rv;
174 
175 	return n;
176 }
177 #endif
178