2 * Board functions for Compulab CM-T54 board
4 * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
6 * Author: Dmitry Lifshitz <lifshitz@compulab.co.il>
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <fdt_support.h>
18 #include <asm/arch/sys_proto.h>
19 #include <asm/arch/mmc_host_def.h>
20 #include <asm/arch/clock.h>
21 #include <asm/arch/ehci.h>
22 #include <asm/ehci-omap.h>
24 #include "../common/eeprom.h"
26 #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000)
27 #define DIE_ID_REG_OFFSET 0x200
29 DECLARE_GLOBAL_DATA_PTR;
31 #if !defined(CONFIG_SPL_BUILD)
32 inline void set_muxconf_regs_essential(void){};
35 const struct omap_sysinfo sysinfo = {
41 * Description: hardware init.
45 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100); /* boot param addr */
51 * Routine: cm_t54_palmas_regulator_set
52 * Description: select voltage and turn on/off Palmas PMIC regulator.
54 static int cm_t54_palmas_regulator_set(u8 vreg, u8 vval, u8 creg, u8 cval)
59 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, vreg, vval);
61 printf("cm_t54: could not set regulator 0x%02x voltage : %d\n",
66 /* Turn on/off regulator */
67 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, creg, cval);
69 printf("cm_t54: could not turn on/off regulator 0x%02x : %d\n",
77 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
78 #define SB_T54_CD_GPIO 228
79 #define SB_T54_WP_GPIO 229
81 int board_mmc_getcd(struct mmc *mmc)
83 return !gpio_get_value(SB_T54_CD_GPIO);
86 int board_mmc_init(bd_t *bis)
90 ret0 = omap_mmc_init(0, 0, 0, -1, SB_T54_WP_GPIO);
92 printf("cm_t54: failed to initialize mmc0\n");
94 ret1 = omap_mmc_init(1, 0, 0, -1, -1);
96 printf("cm_t54: failed to initialize mmc1\n");
105 #ifdef CONFIG_USB_HOST_ETHER
107 void ft_board_setup(void *blob, bd_t *bd)
112 if (eth_getenv_enetaddr("usbethaddr", enetaddr)) {
113 fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address",
118 static void generate_mac_addr(uint8_t *enetaddr)
122 reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET;
125 * create a fake MAC address from the processor ID code.
126 * first byte is 0x02 to signify locally administered.
129 enetaddr[1] = readl(reg + 0x10) & 0xff;
130 enetaddr[2] = readl(reg + 0xC) & 0xff;
131 enetaddr[3] = readl(reg + 0x8) & 0xff;
132 enetaddr[4] = readl(reg) & 0xff;
133 enetaddr[5] = (readl(reg) >> 8) & 0xff;
137 * Routine: handle_mac_address
138 * Description: prepare MAC address for on-board Ethernet.
140 static int handle_mac_address(void)
145 ret = eth_getenv_enetaddr("usbethaddr", enetaddr);
149 ret = cl_eeprom_read_mac_addr(enetaddr);
150 if (!ret || !is_valid_ether_addr(enetaddr))
151 generate_mac_addr(enetaddr);
153 if (!is_valid_ether_addr(enetaddr))
156 return eth_setenv_enetaddr("usbethaddr", enetaddr);
159 int board_eth_init(bd_t *bis)
161 return handle_mac_address();
165 #ifdef CONFIG_USB_EHCI
166 static struct omap_usbhs_board_data usbhs_bdata = {
167 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
168 .port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC,
169 .port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC,
172 static void setup_host_clocks(bool enable)
174 int usbhost_clk = OPTFCLKEN_HSIC60M_P3_CLK |
175 OPTFCLKEN_HSIC480M_P3_CLK |
176 OPTFCLKEN_HSIC60M_P2_CLK |
177 OPTFCLKEN_HSIC480M_P2_CLK |
178 OPTFCLKEN_UTMI_P3_CLK |
179 OPTFCLKEN_UTMI_P2_CLK;
181 int usbtll_clk = OPTFCLKEN_USB_CH1_CLK_ENABLE |
182 OPTFCLKEN_USB_CH2_CLK_ENABLE;
184 int usbhub_clk = CKOBUFFER_CLK_ENABLE_MASK;
187 /* Enable port 2 and 3 clocks*/
188 setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
189 /* Enable port 2 and 3 usb host ports tll clocks*/
190 setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
191 /* Request FREF_XTAL_CLK clock for HSIC USB Hub */
192 setbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
194 clrbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
195 clrbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
196 clrbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
200 int ehci_hcd_init(int index, enum usb_init_type init,
201 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
206 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_3V3, SMPS9_CTRL,
207 SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO);
209 setup_host_clocks(true);
211 ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
213 printf("cm_t54: Failed to initialize ehci : %d\n", ret);
218 int ehci_hcd_stop(void)
220 int ret = omap_ehci_hcd_stop();
222 setup_host_clocks(false);
224 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_OFF,
225 SMPS9_CTRL, SMPS_MODE_SLP_AUTO);
230 void usb_hub_reset_devices(int port)
232 /* The LAN9730 needs to be reset after the port power has been set. */
234 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0);
236 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1);