Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il> |
| 4 | * |
| 5 | * Authors: Igor Grinberg <grinberg@compulab.co.il> |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 9 | #include <environment.h> |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 10 | #include <status_led.h> |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 11 | #include <net.h> |
| 12 | #include <netdev.h> |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 13 | #include <usb.h> |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 14 | #include <mmc.h> |
| 15 | #include <linux/compiler.h> |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 16 | #include <linux/usb/musb.h> |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 17 | |
| 18 | #include <asm/io.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> |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 23 | #include <asm/arch/musb.h> |
| 24 | #include <asm/omap_musb.h> |
| 25 | #include <asm/ehci-omap.h> |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 26 | |
| 27 | #include "../common/common.h" |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 28 | #include "../common/eeprom.h" |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | const omap3_sysinfo sysinfo = { |
| 33 | DDR_DISCRETE, |
| 34 | "CM-T3517 board", |
| 35 | "NAND 128/512M", |
| 36 | }; |
| 37 | |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 38 | #ifdef CONFIG_USB_MUSB_AM35X |
| 39 | static struct musb_hdrc_config cm_t3517_musb_config = { |
| 40 | .multipoint = 1, |
| 41 | .dyn_fifo = 1, |
| 42 | .num_eps = 16, |
| 43 | .ram_bits = 12, |
| 44 | }; |
| 45 | |
| 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, |
| 50 | }; |
| 51 | |
| 52 | static struct musb_hdrc_platform_data cm_t3517_musb_pdata = { |
Paul Kocialkowski | f34dfcb | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 53 | #if defined(CONFIG_USB_MUSB_HOST) |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 54 | .mode = MUSB_HOST, |
Paul Kocialkowski | f34dfcb | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 55 | #elif defined(CONFIG_USB_MUSB_GADGET) |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 56 | .mode = MUSB_PERIPHERAL, |
| 57 | #else |
Paul Kocialkowski | f34dfcb | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 58 | #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET" |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 59 | #endif |
| 60 | .config = &cm_t3517_musb_config, |
| 61 | .power = 250, |
| 62 | .platform_ops = &am35x_ops, |
| 63 | .board_data = &cm_t3517_musb_board_data, |
| 64 | }; |
| 65 | |
| 66 | static void cm_t3517_musb_init(void) |
| 67 | { |
| 68 | /* |
| 69 | * Set up USB clock/mode in the DEVCONF2 register. |
| 70 | * USB2.0 PHY reference clock is 13 MHz |
| 71 | */ |
| 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); |
| 76 | |
Jagan Teki | f0a6d79 | 2018-07-20 12:43:56 +0530 | [diff] [blame] | 77 | if (!musb_register(&cm_t3517_musb_pdata, &cm_t3517_musb_board_data, |
| 78 | (void *)AM35XX_IPSS_USBOTGSS_BASE)) |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 79 | printf("Failed initializing AM35x MUSB!\n"); |
| 80 | } |
| 81 | #else |
| 82 | static inline void am3517_evm_musb_init(void) {} |
| 83 | #endif |
| 84 | |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 85 | int board_init(void) |
| 86 | { |
| 87 | gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ |
| 88 | |
| 89 | /* boot param addr */ |
| 90 | gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); |
| 91 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 92 | #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE) |
| 93 | status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON); |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 94 | #endif |
| 95 | |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 96 | cm_t3517_musb_init(); |
| 97 | |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
Dmitry Lifshitz | 6c2deee | 2015-11-10 15:17:44 +0200 | [diff] [blame] | 101 | /* |
| 102 | * Routine: get_board_rev |
| 103 | * Description: read system revision |
| 104 | */ |
| 105 | u32 get_board_rev(void) |
| 106 | { |
| 107 | return cl_eeprom_get_board_rev(CONFIG_SYS_I2C_EEPROM_BUS); |
| 108 | }; |
| 109 | |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 110 | int misc_init_r(void) |
| 111 | { |
| 112 | cl_print_pcb_info(); |
Paul Kocialkowski | 6bc318e | 2015-08-27 19:37:13 +0200 | [diff] [blame] | 113 | omap_die_id_display(); |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 118 | #if defined(CONFIG_MMC) |
Igor Grinberg | c3373ee | 2014-11-05 14:25:35 +0200 | [diff] [blame] | 119 | #define SB_T35_CD_GPIO 144 |
| 120 | #define SB_T35_WP_GPIO 59 |
| 121 | |
| 122 | int board_mmc_init(bd_t *bis) |
| 123 | { |
| 124 | return omap_mmc_init(0, 0, 0, SB_T35_CD_GPIO, SB_T35_WP_GPIO); |
| 125 | } |
| 126 | #endif |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 127 | |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 128 | #ifdef CONFIG_DRIVER_TI_EMAC |
| 129 | #define CONTROL_EFUSE_EMAC_LSB 0x48002380 |
| 130 | #define CONTROL_EFUSE_EMAC_MSB 0x48002384 |
| 131 | |
| 132 | static int am3517_get_efuse_enetaddr(u8 *enetaddr) |
| 133 | { |
| 134 | u32 lsb = __raw_readl(CONTROL_EFUSE_EMAC_LSB); |
| 135 | u32 msb = __raw_readl(CONTROL_EFUSE_EMAC_MSB); |
| 136 | |
| 137 | enetaddr[0] = (u8)((msb >> 16) & 0xff); |
| 138 | enetaddr[1] = (u8)((msb >> 8) & 0xff); |
| 139 | enetaddr[2] = (u8)(msb & 0xff); |
| 140 | enetaddr[3] = (u8)((lsb >> 16) & 0xff); |
| 141 | enetaddr[4] = (u8)((lsb >> 8) & 0xff); |
| 142 | enetaddr[5] = (u8)(lsb & 0xff); |
| 143 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 144 | return is_valid_ethaddr(enetaddr); |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static inline int cm_t3517_init_emac(bd_t *bis) |
| 148 | { |
| 149 | int ret = cpu_eth_init(bis); |
| 150 | |
| 151 | if (ret > 0) |
| 152 | return ret; |
| 153 | |
| 154 | printf("Failed initializing EMAC! "); |
| 155 | return 0; |
| 156 | } |
| 157 | #else /* !CONFIG_DRIVER_TI_EMAC */ |
| 158 | static inline int am3517_get_efuse_enetaddr(u8 *enetaddr) { return 1; } |
| 159 | static inline int cm_t3517_init_emac(bd_t *bis) { return 0; } |
| 160 | #endif /* CONFIG_DRIVER_TI_EMAC */ |
| 161 | |
| 162 | /* |
| 163 | * Routine: handle_mac_address |
| 164 | * Description: prepare MAC address for on-board Ethernet. |
| 165 | */ |
| 166 | static int cm_t3517_handle_mac_address(void) |
| 167 | { |
| 168 | unsigned char enetaddr[6]; |
| 169 | int ret; |
| 170 | |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 171 | ret = eth_env_get_enetaddr("ethaddr", enetaddr); |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 172 | if (ret) |
| 173 | return 0; |
| 174 | |
Nikita Kiryanov | b2c5547 | 2015-01-14 10:42:43 +0200 | [diff] [blame] | 175 | ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS); |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 176 | if (ret) { |
| 177 | ret = am3517_get_efuse_enetaddr(enetaddr); |
| 178 | if (ret) |
| 179 | return ret; |
| 180 | } |
| 181 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 182 | if (!is_valid_ethaddr(enetaddr)) |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 183 | return -1; |
| 184 | |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 185 | return eth_env_set_enetaddr("ethaddr", enetaddr); |
Igor Grinberg | dfb92d0 | 2014-11-03 11:32:26 +0200 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | #define SB_T35_ETH_RST_GPIO 164 |
| 189 | |
| 190 | /* |
| 191 | * Routine: board_eth_init |
| 192 | * Description: initialize module and base-board Ethernet chips |
| 193 | */ |
| 194 | int board_eth_init(bd_t *bis) |
| 195 | { |
| 196 | int rc = 0, rc1 = 0; |
| 197 | |
| 198 | rc1 = cm_t3517_handle_mac_address(); |
| 199 | if (rc1) |
| 200 | printf("No MAC address found! "); |
| 201 | |
| 202 | rc1 = cm_t3517_init_emac(bis); |
| 203 | if (rc1 > 0) |
| 204 | rc++; |
| 205 | |
| 206 | rc1 = cl_omap3_smc911x_init(0, 4, CONFIG_SMC911X_BASE, |
| 207 | NULL, SB_T35_ETH_RST_GPIO); |
| 208 | if (rc1 > 0) |
| 209 | rc++; |
| 210 | |
| 211 | return rc; |
| 212 | } |
| 213 | |
Igor Grinberg | f7fd7e4 | 2014-11-03 11:32:25 +0200 | [diff] [blame] | 214 | #ifdef CONFIG_USB_EHCI_OMAP |
| 215 | static struct omap_usbhs_board_data cm_t3517_usbhs_bdata = { |
| 216 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
| 217 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
| 218 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
| 219 | }; |
| 220 | |
| 221 | #define CM_T3517_USB_HUB_RESET_GPIO 152 |
| 222 | #define SB_T35_USB_HUB_RESET_GPIO 98 |
| 223 | |
| 224 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 225 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
| 226 | { |
| 227 | cl_usb_hub_init(CM_T3517_USB_HUB_RESET_GPIO, "cm-t3517 hub rst"); |
| 228 | cl_usb_hub_init(SB_T35_USB_HUB_RESET_GPIO, "sb-t35 hub rst"); |
| 229 | |
| 230 | return omap_ehci_hcd_init(index, &cm_t3517_usbhs_bdata, hccr, hcor); |
| 231 | } |
| 232 | |
| 233 | int ehci_hcd_stop(void) |
| 234 | { |
| 235 | cl_usb_hub_deinit(CM_T3517_USB_HUB_RESET_GPIO); |
| 236 | cl_usb_hub_deinit(SB_T35_USB_HUB_RESET_GPIO); |
| 237 | |
| 238 | return omap_ehci_hcd_stop(); |
| 239 | } |
| 240 | #endif /* CONFIG_USB_EHCI_OMAP */ |