Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Board functions for Compulab CM-T54 board |
| 3 | * |
| 4 | * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/ |
| 5 | * |
| 6 | * Author: Dmitry Lifshitz <lifshitz@compulab.co.il> |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 12 | #include <environment.h> |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 13 | #include <fdt_support.h> |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 14 | #include <usb.h> |
| 15 | #include <mmc.h> |
| 16 | #include <palmas.h> |
Dmitry Lifshitz | f0ead5d | 2014-04-27 13:18:48 +0300 | [diff] [blame] | 17 | #include <spl.h> |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 18 | |
| 19 | #include <asm/gpio.h> |
| 20 | #include <asm/arch/sys_proto.h> |
| 21 | #include <asm/arch/mmc_host_def.h> |
| 22 | #include <asm/arch/clock.h> |
| 23 | #include <asm/arch/ehci.h> |
| 24 | #include <asm/ehci-omap.h> |
| 25 | |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 26 | #include "../common/eeprom.h" |
| 27 | |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 28 | #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000) |
| 29 | #define DIE_ID_REG_OFFSET 0x200 |
| 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
| 33 | #if !defined(CONFIG_SPL_BUILD) |
Paul Kocialkowski | a00b1e5 | 2016-02-27 19:18:56 +0100 | [diff] [blame] | 34 | inline void set_muxconf_regs(void){}; |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 35 | #endif |
| 36 | |
| 37 | const struct omap_sysinfo sysinfo = { |
| 38 | "Board: CM-T54\n" |
| 39 | }; |
| 40 | |
| 41 | /* |
| 42 | * Routine: board_init |
| 43 | * Description: hardware init. |
| 44 | */ |
| 45 | int board_init(void) |
| 46 | { |
Dmitry Lifshitz | 29525de | 2014-07-31 14:30:39 +0300 | [diff] [blame] | 47 | gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100); |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Routine: cm_t54_palmas_regulator_set |
| 54 | * Description: select voltage and turn on/off Palmas PMIC regulator. |
| 55 | */ |
| 56 | static int cm_t54_palmas_regulator_set(u8 vreg, u8 vval, u8 creg, u8 cval) |
| 57 | { |
| 58 | int err; |
| 59 | |
| 60 | /* Setup voltage */ |
| 61 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, vreg, vval); |
| 62 | if (err) { |
| 63 | printf("cm_t54: could not set regulator 0x%02x voltage : %d\n", |
| 64 | vreg, err); |
| 65 | return err; |
| 66 | } |
| 67 | |
| 68 | /* Turn on/off regulator */ |
| 69 | err = palmas_i2c_write_u8(TWL603X_CHIP_P1, creg, cval); |
| 70 | if (err) { |
| 71 | printf("cm_t54: could not turn on/off regulator 0x%02x : %d\n", |
| 72 | creg, err); |
| 73 | return err; |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
Dmitry Lifshitz | f0ead5d | 2014-04-27 13:18:48 +0300 | [diff] [blame] | 79 | /* |
| 80 | * Routine: mmc_get_env_part |
| 81 | * Description: setup environment storage device partition. |
| 82 | */ |
| 83 | #ifdef CONFIG_SYS_MMC_ENV_PART |
| 84 | uint mmc_get_env_part(struct mmc *mmc) |
| 85 | { |
Paul Kocialkowski | d5b7624 | 2015-07-15 16:02:19 +0200 | [diff] [blame] | 86 | u32 bootmode = gd->arch.omap_boot_mode; |
Dmitry Lifshitz | f0ead5d | 2014-04-27 13:18:48 +0300 | [diff] [blame] | 87 | uint bootpart = CONFIG_SYS_MMC_ENV_PART; |
| 88 | |
| 89 | /* |
| 90 | * If booted from eMMC boot partition then force eMMC |
| 91 | * FIRST boot partition to be env storage |
| 92 | */ |
Dmitry Lifshitz | 3f1546d | 2014-07-31 14:30:40 +0300 | [diff] [blame] | 93 | if (bootmode == BOOT_DEVICE_MMC2) |
Dmitry Lifshitz | f0ead5d | 2014-04-27 13:18:48 +0300 | [diff] [blame] | 94 | bootpart = 1; |
| 95 | |
| 96 | return bootpart; |
| 97 | } |
| 98 | #endif |
| 99 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 100 | #if defined(CONFIG_MMC) |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 101 | #define SB_T54_CD_GPIO 228 |
| 102 | #define SB_T54_WP_GPIO 229 |
| 103 | |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 104 | int board_mmc_init(bd_t *bis) |
| 105 | { |
| 106 | int ret0, ret1; |
| 107 | |
Igor Grinberg | 2f4e095 | 2014-11-03 11:32:23 +0200 | [diff] [blame] | 108 | ret0 = omap_mmc_init(0, 0, 0, SB_T54_CD_GPIO, SB_T54_WP_GPIO); |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 109 | if (ret0) |
| 110 | printf("cm_t54: failed to initialize mmc0\n"); |
| 111 | |
| 112 | ret1 = omap_mmc_init(1, 0, 0, -1, -1); |
| 113 | if (ret1) |
| 114 | printf("cm_t54: failed to initialize mmc1\n"); |
| 115 | |
| 116 | if (ret0 && ret1) |
| 117 | return -1; |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | #endif |
| 122 | |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 123 | #ifdef CONFIG_USB_HOST_ETHER |
| 124 | |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 125 | int ft_board_setup(void *blob, bd_t *bd) |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 126 | { |
| 127 | uint8_t enetaddr[6]; |
| 128 | |
| 129 | /* MAC addr */ |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 130 | if (eth_env_get_enetaddr("usbethaddr", enetaddr)) { |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 131 | fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address", |
| 132 | enetaddr, 6, 1); |
| 133 | } |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 134 | |
| 135 | return 0; |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void generate_mac_addr(uint8_t *enetaddr) |
| 139 | { |
| 140 | int reg; |
| 141 | |
| 142 | reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET; |
| 143 | |
| 144 | /* |
| 145 | * create a fake MAC address from the processor ID code. |
| 146 | * first byte is 0x02 to signify locally administered. |
| 147 | */ |
| 148 | enetaddr[0] = 0x02; |
| 149 | enetaddr[1] = readl(reg + 0x10) & 0xff; |
| 150 | enetaddr[2] = readl(reg + 0xC) & 0xff; |
| 151 | enetaddr[3] = readl(reg + 0x8) & 0xff; |
| 152 | enetaddr[4] = readl(reg) & 0xff; |
| 153 | enetaddr[5] = (readl(reg) >> 8) & 0xff; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Routine: handle_mac_address |
| 158 | * Description: prepare MAC address for on-board Ethernet. |
| 159 | */ |
| 160 | static int handle_mac_address(void) |
| 161 | { |
| 162 | uint8_t enetaddr[6]; |
| 163 | int ret; |
| 164 | |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 165 | ret = eth_env_get_enetaddr("usbethaddr", enetaddr); |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 166 | if (ret) |
| 167 | return 0; |
| 168 | |
Nikita Kiryanov | b2c5547 | 2015-01-14 10:42:43 +0200 | [diff] [blame] | 169 | ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS); |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 170 | if (ret || !is_valid_ethaddr(enetaddr)) |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 171 | generate_mac_addr(enetaddr); |
| 172 | |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 173 | if (!is_valid_ethaddr(enetaddr)) |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 174 | return -1; |
| 175 | |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 176 | return eth_env_set_enetaddr("usbethaddr", enetaddr); |
Dmitry Lifshitz | 0cc0b24 | 2014-04-27 13:18:46 +0300 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | int board_eth_init(bd_t *bis) |
| 180 | { |
| 181 | return handle_mac_address(); |
| 182 | } |
| 183 | #endif |
| 184 | |
Tom Rini | ceed5d2 | 2017-05-12 22:33:27 -0400 | [diff] [blame] | 185 | #ifdef CONFIG_USB_EHCI_HCD |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 186 | static struct omap_usbhs_board_data usbhs_bdata = { |
| 187 | .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, |
| 188 | .port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC, |
| 189 | .port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC, |
| 190 | }; |
| 191 | |
| 192 | static void setup_host_clocks(bool enable) |
| 193 | { |
| 194 | int usbhost_clk = OPTFCLKEN_HSIC60M_P3_CLK | |
| 195 | OPTFCLKEN_HSIC480M_P3_CLK | |
| 196 | OPTFCLKEN_HSIC60M_P2_CLK | |
| 197 | OPTFCLKEN_HSIC480M_P2_CLK | |
| 198 | OPTFCLKEN_UTMI_P3_CLK | |
| 199 | OPTFCLKEN_UTMI_P2_CLK; |
| 200 | |
| 201 | int usbtll_clk = OPTFCLKEN_USB_CH1_CLK_ENABLE | |
| 202 | OPTFCLKEN_USB_CH2_CLK_ENABLE; |
| 203 | |
| 204 | int usbhub_clk = CKOBUFFER_CLK_ENABLE_MASK; |
| 205 | |
| 206 | if (enable) { |
| 207 | /* Enable port 2 and 3 clocks*/ |
| 208 | setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk); |
| 209 | /* Enable port 2 and 3 usb host ports tll clocks*/ |
| 210 | setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk); |
| 211 | /* Request FREF_XTAL_CLK clock for HSIC USB Hub */ |
| 212 | setbits_le32((*ctrl)->control_ckobuffer, usbhub_clk); |
| 213 | } else { |
| 214 | clrbits_le32((*ctrl)->control_ckobuffer, usbhub_clk); |
| 215 | clrbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk); |
| 216 | clrbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 221 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
| 222 | { |
| 223 | int ret; |
| 224 | |
| 225 | /* VCC_3V3_ETH */ |
| 226 | cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_3V3, SMPS9_CTRL, |
| 227 | SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO); |
| 228 | |
| 229 | setup_host_clocks(true); |
| 230 | |
| 231 | ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor); |
| 232 | if (ret < 0) |
| 233 | printf("cm_t54: Failed to initialize ehci : %d\n", ret); |
| 234 | |
| 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | int ehci_hcd_stop(void) |
| 239 | { |
| 240 | int ret = omap_ehci_hcd_stop(); |
| 241 | |
| 242 | setup_host_clocks(false); |
| 243 | |
| 244 | cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_OFF, |
| 245 | SMPS9_CTRL, SMPS_MODE_SLP_AUTO); |
| 246 | |
| 247 | return ret; |
| 248 | } |
| 249 | |
Philipp Tomsich | 693f492 | 2017-11-22 17:15:17 +0100 | [diff] [blame] | 250 | void usb_hub_reset_devices(struct usb_hub_device *hub, int port) |
Dmitry Lifshitz | c3ad3a0 | 2014-05-19 12:50:54 +0300 | [diff] [blame] | 251 | { |
| 252 | /* The LAN9730 needs to be reset after the port power has been set. */ |
| 253 | if (port == 3) { |
| 254 | gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0); |
| 255 | udelay(10); |
| 256 | gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1); |
| 257 | } |
| 258 | } |
| 259 | #endif |
| 260 | |