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