1ed01e45cSVaibhav Hiremath /*
2ed01e45cSVaibhav Hiremath * am3517evm.c - board file for TI's AM3517 family of devices.
3ed01e45cSVaibhav Hiremath *
4ed01e45cSVaibhav Hiremath * Author: Vaibhav Hiremath <hvaibhav@ti.com>
5ed01e45cSVaibhav Hiremath *
6ed01e45cSVaibhav Hiremath * Based on ti/evm/evm.c
7ed01e45cSVaibhav Hiremath *
8ed01e45cSVaibhav Hiremath * Copyright (C) 2010
9ed01e45cSVaibhav Hiremath * Texas Instruments Incorporated - http://www.ti.com/
10ed01e45cSVaibhav Hiremath *
111a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
12ed01e45cSVaibhav Hiremath */
13ed01e45cSVaibhav Hiremath
14ed01e45cSVaibhav Hiremath #include <common.h>
15ed01e45cSVaibhav Hiremath #include <asm/io.h>
1688919ff7SIlya Yanok #include <asm/omap_musb.h>
1788919ff7SIlya Yanok #include <asm/arch/am35x_def.h>
18ed01e45cSVaibhav Hiremath #include <asm/arch/mem.h>
19ed01e45cSVaibhav Hiremath #include <asm/arch/mux.h>
20ed01e45cSVaibhav Hiremath #include <asm/arch/sys_proto.h>
21122e6e0aSVaibhav Hiremath #include <asm/arch/mmc_host_def.h>
2288919ff7SIlya Yanok #include <asm/arch/musb.h>
23ed01e45cSVaibhav Hiremath #include <asm/mach-types.h>
241221ce45SMasahiro Yamada #include <linux/errno.h>
256a1df373SYegor Yefremov #include <asm/gpio.h>
2688919ff7SIlya Yanok #include <linux/usb/ch9.h>
2788919ff7SIlya Yanok #include <linux/usb/gadget.h>
2888919ff7SIlya Yanok #include <linux/usb/musb.h>
29ed01e45cSVaibhav Hiremath #include <i2c.h>
3088919ff7SIlya Yanok #include <netdev.h>
31ed01e45cSVaibhav Hiremath #include "am3517evm.h"
32ed01e45cSVaibhav Hiremath
33ed01e45cSVaibhav Hiremath DECLARE_GLOBAL_DATA_PTR;
34ed01e45cSVaibhav Hiremath
356a1df373SYegor Yefremov #define AM3517_IP_SW_RESET 0x48002598
366a1df373SYegor Yefremov #define CPGMACSS_SW_RST (1 << 1)
376a1df373SYegor Yefremov
38ed01e45cSVaibhav Hiremath /*
39ed01e45cSVaibhav Hiremath * Routine: board_init
40ed01e45cSVaibhav Hiremath * Description: Early hardware init.
41ed01e45cSVaibhav Hiremath */
board_init(void)42ed01e45cSVaibhav Hiremath int board_init(void)
43ed01e45cSVaibhav Hiremath {
44ed01e45cSVaibhav Hiremath gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
45ed01e45cSVaibhav Hiremath /* board id for Linux */
46ed01e45cSVaibhav Hiremath gd->bd->bi_arch_number = MACH_TYPE_OMAP3517EVM;
47ed01e45cSVaibhav Hiremath /* boot param addr */
48ed01e45cSVaibhav Hiremath gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
49ed01e45cSVaibhav Hiremath
50ed01e45cSVaibhav Hiremath return 0;
51ed01e45cSVaibhav Hiremath }
52ed01e45cSVaibhav Hiremath
5388919ff7SIlya Yanok #ifdef CONFIG_USB_MUSB_AM35X
5488919ff7SIlya Yanok static struct musb_hdrc_config musb_config = {
5588919ff7SIlya Yanok .multipoint = 1,
5688919ff7SIlya Yanok .dyn_fifo = 1,
5788919ff7SIlya Yanok .num_eps = 16,
5888919ff7SIlya Yanok .ram_bits = 12,
5988919ff7SIlya Yanok };
6088919ff7SIlya Yanok
6188919ff7SIlya Yanok static struct omap_musb_board_data musb_board_data = {
6288919ff7SIlya Yanok .set_phy_power = am35x_musb_phy_power,
6388919ff7SIlya Yanok .clear_irq = am35x_musb_clear_irq,
6488919ff7SIlya Yanok .reset = am35x_musb_reset,
6588919ff7SIlya Yanok };
6688919ff7SIlya Yanok
6788919ff7SIlya Yanok static struct musb_hdrc_platform_data musb_plat = {
6895de1e2fSPaul Kocialkowski #if defined(CONFIG_USB_MUSB_HOST)
6988919ff7SIlya Yanok .mode = MUSB_HOST,
7095de1e2fSPaul Kocialkowski #elif defined(CONFIG_USB_MUSB_GADGET)
7188919ff7SIlya Yanok .mode = MUSB_PERIPHERAL,
7288919ff7SIlya Yanok #else
7395de1e2fSPaul Kocialkowski #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
7488919ff7SIlya Yanok #endif
7588919ff7SIlya Yanok .config = &musb_config,
7688919ff7SIlya Yanok .power = 250,
7788919ff7SIlya Yanok .platform_ops = &am35x_ops,
7888919ff7SIlya Yanok .board_data = &musb_board_data,
7988919ff7SIlya Yanok };
8088919ff7SIlya Yanok
am3517_evm_musb_init(void)8188919ff7SIlya Yanok static void am3517_evm_musb_init(void)
8288919ff7SIlya Yanok {
8388919ff7SIlya Yanok /*
8488919ff7SIlya Yanok * Set up USB clock/mode in the DEVCONF2 register.
8588919ff7SIlya Yanok * USB2.0 PHY reference clock is 13 MHz
8688919ff7SIlya Yanok */
8788919ff7SIlya Yanok clrsetbits_le32(&am35x_scm_general_regs->devconf2,
8888919ff7SIlya Yanok CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE,
8988919ff7SIlya Yanok CONF2_REFFREQ_13MHZ | CONF2_SESENDEN |
9088919ff7SIlya Yanok CONF2_VBDTCTEN | CONF2_DATPOL);
9188919ff7SIlya Yanok
9288919ff7SIlya Yanok musb_register(&musb_plat, &musb_board_data,
9388919ff7SIlya Yanok (void *)AM35XX_IPSS_USBOTGSS_BASE);
9488919ff7SIlya Yanok }
9588919ff7SIlya Yanok #else
9688919ff7SIlya Yanok #define am3517_evm_musb_init() do {} while (0)
9788919ff7SIlya Yanok #endif
9888919ff7SIlya Yanok
99ed01e45cSVaibhav Hiremath /*
100ed01e45cSVaibhav Hiremath * Routine: misc_init_r
101ed01e45cSVaibhav Hiremath * Description: Init i2c, ethernet, etc... (done here so udelay works)
102ed01e45cSVaibhav Hiremath */
misc_init_r(void)103ed01e45cSVaibhav Hiremath int misc_init_r(void)
104ed01e45cSVaibhav Hiremath {
1056a1df373SYegor Yefremov volatile unsigned int ctr;
1066a1df373SYegor Yefremov u32 reset;
1076a1df373SYegor Yefremov
108*94d50bedSAdam Ford #ifdef CONFIG_SYS_I2C_OMAP24XX
1096789e84eSHeiko Schocher i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
110ed01e45cSVaibhav Hiremath #endif
111ed01e45cSVaibhav Hiremath
112679f82c3SPaul Kocialkowski omap_die_id_display();
113ed01e45cSVaibhav Hiremath
11488919ff7SIlya Yanok am3517_evm_musb_init();
11588919ff7SIlya Yanok
1166a1df373SYegor Yefremov /* activate PHY reset */
1176a1df373SYegor Yefremov gpio_direction_output(30, 0);
1186a1df373SYegor Yefremov gpio_set_value(30, 0);
1196a1df373SYegor Yefremov
1206a1df373SYegor Yefremov ctr = 0;
1216a1df373SYegor Yefremov do {
1226a1df373SYegor Yefremov udelay(1000);
1236a1df373SYegor Yefremov ctr++;
1246a1df373SYegor Yefremov } while (ctr < 300);
1256a1df373SYegor Yefremov
1266a1df373SYegor Yefremov /* deactivate PHY reset */
1276a1df373SYegor Yefremov gpio_set_value(30, 1);
1286a1df373SYegor Yefremov
1296a1df373SYegor Yefremov /* allow the PHY to stabilize and settle down */
1306a1df373SYegor Yefremov ctr = 0;
1316a1df373SYegor Yefremov do {
1326a1df373SYegor Yefremov udelay(1000);
1336a1df373SYegor Yefremov ctr++;
1346a1df373SYegor Yefremov } while (ctr < 300);
1356a1df373SYegor Yefremov
1366a1df373SYegor Yefremov /* ensure that the module is out of reset */
1376a1df373SYegor Yefremov reset = readl(AM3517_IP_SW_RESET);
1386a1df373SYegor Yefremov reset &= (~CPGMACSS_SW_RST);
1396a1df373SYegor Yefremov writel(reset,AM3517_IP_SW_RESET);
1406a1df373SYegor Yefremov
141ed01e45cSVaibhav Hiremath return 0;
142ed01e45cSVaibhav Hiremath }
143ed01e45cSVaibhav Hiremath
144ed01e45cSVaibhav Hiremath /*
145ed01e45cSVaibhav Hiremath * Routine: set_muxconf_regs
146ed01e45cSVaibhav Hiremath * Description: Setting up the configuration Mux registers specific to the
147ed01e45cSVaibhav Hiremath * hardware. Many pins need to be moved from protect to primary
148ed01e45cSVaibhav Hiremath * mode.
149ed01e45cSVaibhav Hiremath */
set_muxconf_regs(void)150ed01e45cSVaibhav Hiremath void set_muxconf_regs(void)
151ed01e45cSVaibhav Hiremath {
152ed01e45cSVaibhav Hiremath MUX_AM3517EVM();
153ed01e45cSVaibhav Hiremath }
154122e6e0aSVaibhav Hiremath
1554aa2ba3aSMasahiro Yamada #if defined(CONFIG_MMC)
board_mmc_init(bd_t * bis)156122e6e0aSVaibhav Hiremath int board_mmc_init(bd_t *bis)
157122e6e0aSVaibhav Hiremath {
158e3913f56SNikita Kiryanov return omap_mmc_init(0, 0, 0, -1, -1);
159122e6e0aSVaibhav Hiremath }
160122e6e0aSVaibhav Hiremath #endif
16188919ff7SIlya Yanok
16295de1e2fSPaul Kocialkowski #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
board_eth_init(bd_t * bis)16388919ff7SIlya Yanok int board_eth_init(bd_t *bis)
16488919ff7SIlya Yanok {
16588919ff7SIlya Yanok int rv, n = 0;
16688919ff7SIlya Yanok
16788919ff7SIlya Yanok rv = cpu_eth_init(bis);
16888919ff7SIlya Yanok if (rv > 0)
16988919ff7SIlya Yanok n += rv;
17088919ff7SIlya Yanok
17188919ff7SIlya Yanok rv = usb_eth_initialize(bis);
17288919ff7SIlya Yanok if (rv > 0)
17388919ff7SIlya Yanok n += rv;
17488919ff7SIlya Yanok
17588919ff7SIlya Yanok return n;
17688919ff7SIlya Yanok }
17788919ff7SIlya Yanok #endif
178