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 <dm.h>
16 #include <ns16550.h>
17 #include <asm/io.h>
18 #include <asm/omap_musb.h>
19 #include <asm/arch/am35x_def.h>
20 #include <asm/arch/mem.h>
21 #include <asm/arch/mux.h>
22 #include <asm/arch/sys_proto.h>
23 #include <asm/arch/mmc_host_def.h>
24 #include <asm/arch/musb.h>
25 #include <asm/mach-types.h>
26 #include <linux/errno.h>
27 #include <asm/gpio.h>
28 #include <linux/usb/ch9.h>
29 #include <linux/usb/gadget.h>
30 #include <linux/usb/musb.h>
31 #include <i2c.h>
32 #include <netdev.h>
33 #include "am3517evm.h"
34 
35 DECLARE_GLOBAL_DATA_PTR;
36 
37 #define AM3517_IP_SW_RESET	0x48002598
38 #define CPGMACSS_SW_RST		(1 << 1)
39 #define PHY_GPIO		30
40 
41 /* This is only needed until SPL gets OF support */
42 #ifdef CONFIG_SPL_BUILD
43 static const struct ns16550_platdata am3517_serial = {
44 	.base = OMAP34XX_UART3,
45 	.reg_shift = 2,
46 	.clock = V_NS16550_CLK,
47 	.fcr = UART_FCR_DEFVAL,
48 };
49 
50 U_BOOT_DEVICE(am3517_uart) = {
51 	"ns16550_serial",
52 	&am3517_serial
53 };
54 #endif
55 
56 /*
57  * Routine: board_init
58  * Description: Early hardware init.
59  */
60 int board_init(void)
61 {
62 	gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
63 	/* board id for Linux */
64 	gd->bd->bi_arch_number = MACH_TYPE_OMAP3517EVM;
65 	/* boot param addr */
66 	gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
67 
68 	return 0;
69 }
70 
71 #ifdef CONFIG_USB_MUSB_AM35X
72 static struct musb_hdrc_config musb_config = {
73 	.multipoint     = 1,
74 	.dyn_fifo       = 1,
75 	.num_eps        = 16,
76 	.ram_bits       = 12,
77 };
78 
79 static struct omap_musb_board_data musb_board_data = {
80 	.set_phy_power		= am35x_musb_phy_power,
81 	.clear_irq		= am35x_musb_clear_irq,
82 	.reset			= am35x_musb_reset,
83 };
84 
85 static struct musb_hdrc_platform_data musb_plat = {
86 #if defined(CONFIG_USB_MUSB_HOST)
87 	.mode           = MUSB_HOST,
88 #elif defined(CONFIG_USB_MUSB_GADGET)
89 	.mode		= MUSB_PERIPHERAL,
90 #else
91 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
92 #endif
93 	.config         = &musb_config,
94 	.power          = 250,
95 	.platform_ops	= &am35x_ops,
96 	.board_data	= &musb_board_data,
97 };
98 
99 static void am3517_evm_musb_init(void)
100 {
101 	/*
102 	 * Set up USB clock/mode in the DEVCONF2 register.
103 	 * USB2.0 PHY reference clock is 13 MHz
104 	 */
105 	clrsetbits_le32(&am35x_scm_general_regs->devconf2,
106 			CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE,
107 			CONF2_REFFREQ_13MHZ | CONF2_SESENDEN |
108 			CONF2_VBDTCTEN | CONF2_DATPOL);
109 
110 	musb_register(&musb_plat, &musb_board_data,
111 			(void *)AM35XX_IPSS_USBOTGSS_BASE);
112 }
113 #else
114 #define am3517_evm_musb_init() do {} while (0)
115 #endif
116 
117 /*
118  * Routine: misc_init_r
119  * Description: Init i2c, ethernet, etc... (done here so udelay works)
120  */
121 int misc_init_r(void)
122 {
123 	volatile unsigned int ctr;
124 	u32 reset;
125 
126 #ifdef CONFIG_SYS_I2C_OMAP24XX
127 	i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
128 #endif
129 
130 	omap_die_id_display();
131 
132 	am3517_evm_musb_init();
133 
134 	if (gpio_request(PHY_GPIO, "gpio_30") == 0) {
135 		/* activate PHY reset */
136 		gpio_direction_output(PHY_GPIO, 0);
137 		gpio_set_value(PHY_GPIO, 0);
138 
139 		ctr  = 0;
140 		do {
141 			udelay(1000);
142 			ctr++;
143 		} while (ctr < 300);
144 
145 		/* deactivate PHY reset */
146 		gpio_set_value(PHY_GPIO, 1);
147 
148 		/* allow the PHY to stabilize and settle down */
149 		ctr = 0;
150 		do {
151 			udelay(1000);
152 			ctr++;
153 		} while (ctr < 300);
154 
155 		/* ensure that the module is out of reset */
156 		reset = readl(AM3517_IP_SW_RESET);
157 		reset &= (~CPGMACSS_SW_RST);
158 		writel(reset, AM3517_IP_SW_RESET);
159 
160 		/* Free requested GPIO */
161 		gpio_free(PHY_GPIO);
162 	}
163 
164 	return 0;
165 }
166 
167 /*
168  * Routine: set_muxconf_regs
169  * Description: Setting up the configuration Mux registers specific to the
170  *		hardware. Many pins need to be moved from protect to primary
171  *		mode.
172  */
173 void set_muxconf_regs(void)
174 {
175 	MUX_AM3517EVM();
176 }
177 
178 #if defined(CONFIG_MMC)
179 int board_mmc_init(bd_t *bis)
180 {
181 	return omap_mmc_init(0, 0, 0, -1, -1);
182 }
183 #endif
184 
185 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
186 int board_eth_init(bd_t *bis)
187 {
188 	int rv, n = 0;
189 
190 	rv = cpu_eth_init(bis);
191 	if (rv > 0)
192 		n += rv;
193 
194 	rv = usb_eth_initialize(bis);
195 	if (rv > 0)
196 		n += rv;
197 
198 	return n;
199 }
200 #endif
201