2 * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il>
4 * Authors: Igor Grinberg <grinberg@compulab.co.il>
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <status_led.h>
15 #include <linux/compiler.h>
16 #include <linux/usb/musb.h>
19 #include <asm/arch/mem.h>
20 #include <asm/arch/am35x_def.h>
21 #include <asm/arch/mmc_host_def.h>
22 #include <asm/arch/sys_proto.h>
23 #include <asm/arch/musb.h>
24 #include <asm/omap_musb.h>
25 #include <asm/ehci-omap.h>
27 #include "../common/common.h"
28 #include "../common/eeprom.h"
30 DECLARE_GLOBAL_DATA_PTR;
32 const omap3_sysinfo sysinfo = {
38 #ifdef CONFIG_USB_MUSB_AM35X
39 static struct musb_hdrc_config cm_t3517_musb_config = {
46 static struct omap_musb_board_data cm_t3517_musb_board_data = {
47 .set_phy_power = am35x_musb_phy_power,
48 .clear_irq = am35x_musb_clear_irq,
49 .reset = am35x_musb_reset,
52 static struct musb_hdrc_platform_data cm_t3517_musb_pdata = {
53 #if defined(CONFIG_MUSB_HOST)
55 #elif defined(CONFIG_MUSB_GADGET)
56 .mode = MUSB_PERIPHERAL,
58 #error "Please define either CONFIG_MUSB_HOST or CONFIG_MUSB_GADGET"
60 .config = &cm_t3517_musb_config,
62 .platform_ops = &am35x_ops,
63 .board_data = &cm_t3517_musb_board_data,
66 static void cm_t3517_musb_init(void)
69 * Set up USB clock/mode in the DEVCONF2 register.
70 * USB2.0 PHY reference clock is 13 MHz
72 clrsetbits_le32(&am35x_scm_general_regs->devconf2,
73 CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE,
74 CONF2_REFFREQ_13MHZ | CONF2_SESENDEN |
75 CONF2_VBDTCTEN | CONF2_DATPOL);
77 if (musb_register(&cm_t3517_musb_pdata, &cm_t3517_musb_board_data,
78 (void *)AM35XX_IPSS_USBOTGSS_BASE))
79 printf("Failed initializing AM35x MUSB!\n");
82 static inline void am3517_evm_musb_init(void) {}
87 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
90 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
92 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
93 status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
101 int misc_init_r(void)
109 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
110 #define SB_T35_CD_GPIO 144
111 #define SB_T35_WP_GPIO 59
113 int board_mmc_init(bd_t *bis)
115 return omap_mmc_init(0, 0, 0, SB_T35_CD_GPIO, SB_T35_WP_GPIO);
119 #ifdef CONFIG_DRIVER_TI_EMAC
120 #define CONTROL_EFUSE_EMAC_LSB 0x48002380
121 #define CONTROL_EFUSE_EMAC_MSB 0x48002384
123 static int am3517_get_efuse_enetaddr(u8 *enetaddr)
125 u32 lsb = __raw_readl(CONTROL_EFUSE_EMAC_LSB);
126 u32 msb = __raw_readl(CONTROL_EFUSE_EMAC_MSB);
128 enetaddr[0] = (u8)((msb >> 16) & 0xff);
129 enetaddr[1] = (u8)((msb >> 8) & 0xff);
130 enetaddr[2] = (u8)(msb & 0xff);
131 enetaddr[3] = (u8)((lsb >> 16) & 0xff);
132 enetaddr[4] = (u8)((lsb >> 8) & 0xff);
133 enetaddr[5] = (u8)(lsb & 0xff);
135 return is_valid_ethaddr(enetaddr);
138 static inline int cm_t3517_init_emac(bd_t *bis)
140 int ret = cpu_eth_init(bis);
145 printf("Failed initializing EMAC! ");
148 #else /* !CONFIG_DRIVER_TI_EMAC */
149 static inline int am3517_get_efuse_enetaddr(u8 *enetaddr) { return 1; }
150 static inline int cm_t3517_init_emac(bd_t *bis) { return 0; }
151 #endif /* CONFIG_DRIVER_TI_EMAC */
154 * Routine: handle_mac_address
155 * Description: prepare MAC address for on-board Ethernet.
157 static int cm_t3517_handle_mac_address(void)
159 unsigned char enetaddr[6];
162 ret = eth_getenv_enetaddr("ethaddr", enetaddr);
166 ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
168 ret = am3517_get_efuse_enetaddr(enetaddr);
173 if (!is_valid_ethaddr(enetaddr))
176 return eth_setenv_enetaddr("ethaddr", enetaddr);
179 #define SB_T35_ETH_RST_GPIO 164
182 * Routine: board_eth_init
183 * Description: initialize module and base-board Ethernet chips
185 int board_eth_init(bd_t *bis)
189 rc1 = cm_t3517_handle_mac_address();
191 printf("No MAC address found! ");
193 rc1 = cm_t3517_init_emac(bis);
197 rc1 = cl_omap3_smc911x_init(0, 4, CONFIG_SMC911X_BASE,
198 NULL, SB_T35_ETH_RST_GPIO);
205 #ifdef CONFIG_USB_EHCI_OMAP
206 static struct omap_usbhs_board_data cm_t3517_usbhs_bdata = {
207 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
208 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
209 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
212 #define CM_T3517_USB_HUB_RESET_GPIO 152
213 #define SB_T35_USB_HUB_RESET_GPIO 98
215 int ehci_hcd_init(int index, enum usb_init_type init,
216 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
218 cl_usb_hub_init(CM_T3517_USB_HUB_RESET_GPIO, "cm-t3517 hub rst");
219 cl_usb_hub_init(SB_T35_USB_HUB_RESET_GPIO, "sb-t35 hub rst");
221 return omap_ehci_hcd_init(index, &cm_t3517_usbhs_bdata, hccr, hcor);
224 int ehci_hcd_stop(void)
226 cl_usb_hub_deinit(CM_T3517_USB_HUB_RESET_GPIO);
227 cl_usb_hub_deinit(SB_T35_USB_HUB_RESET_GPIO);
229 return omap_ehci_hcd_stop();
231 #endif /* CONFIG_USB_EHCI_OMAP */