1 // SPDX-License-Identifier: GPL-2.0+
3 * Board functions for Compulab CM-T54 board
5 * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
7 * Author: Dmitry Lifshitz <lifshitz@compulab.co.il>
12 #include <fdt_support.h>
18 #include <linux/delay.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/arch/mmc_host_def.h>
23 #include <asm/arch/clock.h>
24 #include <asm/arch/ehci.h>
25 #include <asm/ehci-omap.h>
27 #include "../common/eeprom.h"
29 #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000)
30 #define DIE_ID_REG_OFFSET 0x200
32 DECLARE_GLOBAL_DATA_PTR;
34 #if !defined(CONFIG_SPL_BUILD)
35 inline void set_muxconf_regs(void){};
38 const struct omap_sysinfo sysinfo = {
44 * Description: hardware init.
48 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
54 * Routine: cm_t54_palmas_regulator_set
55 * Description: select voltage and turn on/off Palmas PMIC regulator.
57 static int cm_t54_palmas_regulator_set(u8 vreg, u8 vval, u8 creg, u8 cval)
62 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, vreg, vval);
64 printf("cm_t54: could not set regulator 0x%02x voltage : %d\n",
69 /* Turn on/off regulator */
70 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, creg, cval);
72 printf("cm_t54: could not turn on/off regulator 0x%02x : %d\n",
81 * Routine: mmc_get_env_part
82 * Description: setup environment storage device partition.
84 #ifdef CONFIG_SYS_MMC_ENV_PART
85 uint mmc_get_env_part(struct mmc *mmc)
87 u32 bootmode = gd->arch.omap_boot_mode;
88 uint bootpart = CONFIG_SYS_MMC_ENV_PART;
91 * If booted from eMMC boot partition then force eMMC
92 * FIRST boot partition to be env storage
94 if (bootmode == BOOT_DEVICE_MMC2)
101 #if defined(CONFIG_MMC)
102 #define SB_T54_CD_GPIO 228
103 #define SB_T54_WP_GPIO 229
105 int board_mmc_init(bd_t *bis)
109 ret0 = omap_mmc_init(0, 0, 0, SB_T54_CD_GPIO, SB_T54_WP_GPIO);
111 printf("cm_t54: failed to initialize mmc0\n");
113 ret1 = omap_mmc_init(1, 0, 0, -1, -1);
115 printf("cm_t54: failed to initialize mmc1\n");
124 #ifdef CONFIG_USB_HOST_ETHER
126 int ft_board_setup(void *blob, bd_t *bd)
131 if (eth_env_get_enetaddr("usbethaddr", enetaddr)) {
132 fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address",
139 static void generate_mac_addr(uint8_t *enetaddr)
143 reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET;
146 * create a fake MAC address from the processor ID code.
147 * first byte is 0x02 to signify locally administered.
150 enetaddr[1] = readl(reg + 0x10) & 0xff;
151 enetaddr[2] = readl(reg + 0xC) & 0xff;
152 enetaddr[3] = readl(reg + 0x8) & 0xff;
153 enetaddr[4] = readl(reg) & 0xff;
154 enetaddr[5] = (readl(reg) >> 8) & 0xff;
158 * Routine: handle_mac_address
159 * Description: prepare MAC address for on-board Ethernet.
161 static int handle_mac_address(void)
166 ret = eth_env_get_enetaddr("usbethaddr", enetaddr);
170 ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
171 if (ret || !is_valid_ethaddr(enetaddr))
172 generate_mac_addr(enetaddr);
174 if (!is_valid_ethaddr(enetaddr))
177 return eth_env_set_enetaddr("usbethaddr", enetaddr);
180 int board_eth_init(bd_t *bis)
182 return handle_mac_address();
186 #ifdef CONFIG_USB_EHCI_HCD
187 static struct omap_usbhs_board_data usbhs_bdata = {
188 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
189 .port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC,
190 .port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC,
193 static void setup_host_clocks(bool enable)
195 int usbhost_clk = OPTFCLKEN_HSIC60M_P3_CLK |
196 OPTFCLKEN_HSIC480M_P3_CLK |
197 OPTFCLKEN_HSIC60M_P2_CLK |
198 OPTFCLKEN_HSIC480M_P2_CLK |
199 OPTFCLKEN_UTMI_P3_CLK |
200 OPTFCLKEN_UTMI_P2_CLK;
202 int usbtll_clk = OPTFCLKEN_USB_CH1_CLK_ENABLE |
203 OPTFCLKEN_USB_CH2_CLK_ENABLE;
205 int usbhub_clk = CKOBUFFER_CLK_ENABLE_MASK;
208 /* Enable port 2 and 3 clocks*/
209 setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
210 /* Enable port 2 and 3 usb host ports tll clocks*/
211 setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
212 /* Request FREF_XTAL_CLK clock for HSIC USB Hub */
213 setbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
215 clrbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
216 clrbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
217 clrbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
221 int ehci_hcd_init(int index, enum usb_init_type init,
222 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
227 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_3V3, SMPS9_CTRL,
228 SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO);
230 setup_host_clocks(true);
232 ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
234 printf("cm_t54: Failed to initialize ehci : %d\n", ret);
239 int ehci_hcd_stop(void)
241 int ret = omap_ehci_hcd_stop();
243 setup_host_clocks(false);
245 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_OFF,
246 SMPS9_CTRL, SMPS_MODE_SLP_AUTO);
251 void usb_hub_reset_devices(struct usb_hub_device *hub, int port)
253 /* The LAN9730 needs to be reset after the port power has been set. */
255 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0);
257 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1);