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>
19 #include <asm/arch/sys_proto.h>
20 #include <asm/arch/mmc_host_def.h>
21 #include <asm/arch/clock.h>
22 #include <asm/arch/ehci.h>
23 #include <asm/ehci-omap.h>
25 #include "../common/eeprom.h"
27 #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000)
28 #define DIE_ID_REG_OFFSET 0x200
30 DECLARE_GLOBAL_DATA_PTR
;
32 #if !defined(CONFIG_SPL_BUILD)
33 inline void set_muxconf_regs_essential(void){};
36 const struct omap_sysinfo sysinfo
= {
42 * Description: hardware init.
46 gd
->bd
->bi_boot_params
= (CONFIG_SYS_SDRAM_BASE
+ 0x100);
52 * Routine: cm_t54_palmas_regulator_set
53 * Description: select voltage and turn on/off Palmas PMIC regulator.
55 static int cm_t54_palmas_regulator_set(u8 vreg
, u8 vval
, u8 creg
, u8 cval
)
60 err
= palmas_i2c_write_u8(TWL603X_CHIP_P1
, vreg
, vval
);
62 printf("cm_t54: could not set regulator 0x%02x voltage : %d\n",
67 /* Turn on/off regulator */
68 err
= palmas_i2c_write_u8(TWL603X_CHIP_P1
, creg
, cval
);
70 printf("cm_t54: could not turn on/off regulator 0x%02x : %d\n",
79 * Routine: mmc_get_env_part
80 * Description: setup environment storage device partition.
82 #ifdef CONFIG_SYS_MMC_ENV_PART
83 uint
mmc_get_env_part(struct mmc
*mmc
)
85 u32 bootmode
= gd
->arch
.omap_boot_params
.omap_bootmode
;
86 uint bootpart
= CONFIG_SYS_MMC_ENV_PART
;
89 * If booted from eMMC boot partition then force eMMC
90 * FIRST boot partition to be env storage
92 if (bootmode
== BOOT_DEVICE_MMC2
)
99 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
100 #define SB_T54_CD_GPIO 228
101 #define SB_T54_WP_GPIO 229
103 int board_mmc_getcd(struct mmc
*mmc
)
105 return !gpio_get_value(SB_T54_CD_GPIO
);
108 int board_mmc_init(bd_t
*bis
)
112 ret0
= omap_mmc_init(0, 0, 0, -1, SB_T54_WP_GPIO
);
114 printf("cm_t54: failed to initialize mmc0\n");
116 ret1
= omap_mmc_init(1, 0, 0, -1, -1);
118 printf("cm_t54: failed to initialize mmc1\n");
127 #ifdef CONFIG_USB_HOST_ETHER
129 void ft_board_setup(void *blob
, bd_t
*bd
)
134 if (eth_getenv_enetaddr("usbethaddr", enetaddr
)) {
135 fdt_find_and_setprop(blob
, "/smsc95xx@0", "mac-address",
140 static void generate_mac_addr(uint8_t *enetaddr
)
144 reg
= DIE_ID_REG_BASE
+ DIE_ID_REG_OFFSET
;
147 * create a fake MAC address from the processor ID code.
148 * first byte is 0x02 to signify locally administered.
151 enetaddr
[1] = readl(reg
+ 0x10) & 0xff;
152 enetaddr
[2] = readl(reg
+ 0xC) & 0xff;
153 enetaddr
[3] = readl(reg
+ 0x8) & 0xff;
154 enetaddr
[4] = readl(reg
) & 0xff;
155 enetaddr
[5] = (readl(reg
) >> 8) & 0xff;
159 * Routine: handle_mac_address
160 * Description: prepare MAC address for on-board Ethernet.
162 static int handle_mac_address(void)
167 ret
= eth_getenv_enetaddr("usbethaddr", enetaddr
);
171 ret
= cl_eeprom_read_mac_addr(enetaddr
);
172 if (ret
|| !is_valid_ether_addr(enetaddr
))
173 generate_mac_addr(enetaddr
);
175 if (!is_valid_ether_addr(enetaddr
))
178 return eth_setenv_enetaddr("usbethaddr", enetaddr
);
181 int board_eth_init(bd_t
*bis
)
183 return handle_mac_address();
187 #ifdef CONFIG_USB_EHCI
188 static struct omap_usbhs_board_data usbhs_bdata
= {
189 .port_mode
[0] = OMAP_USBHS_PORT_MODE_UNUSED
,
190 .port_mode
[1] = OMAP_EHCI_PORT_MODE_HSIC
,
191 .port_mode
[2] = OMAP_EHCI_PORT_MODE_HSIC
,
194 static void setup_host_clocks(bool enable
)
196 int usbhost_clk
= OPTFCLKEN_HSIC60M_P3_CLK
|
197 OPTFCLKEN_HSIC480M_P3_CLK
|
198 OPTFCLKEN_HSIC60M_P2_CLK
|
199 OPTFCLKEN_HSIC480M_P2_CLK
|
200 OPTFCLKEN_UTMI_P3_CLK
|
201 OPTFCLKEN_UTMI_P2_CLK
;
203 int usbtll_clk
= OPTFCLKEN_USB_CH1_CLK_ENABLE
|
204 OPTFCLKEN_USB_CH2_CLK_ENABLE
;
206 int usbhub_clk
= CKOBUFFER_CLK_ENABLE_MASK
;
209 /* Enable port 2 and 3 clocks*/
210 setbits_le32((*prcm
)->cm_l3init_hsusbhost_clkctrl
, usbhost_clk
);
211 /* Enable port 2 and 3 usb host ports tll clocks*/
212 setbits_le32((*prcm
)->cm_l3init_hsusbtll_clkctrl
, usbtll_clk
);
213 /* Request FREF_XTAL_CLK clock for HSIC USB Hub */
214 setbits_le32((*ctrl
)->control_ckobuffer
, usbhub_clk
);
216 clrbits_le32((*ctrl
)->control_ckobuffer
, usbhub_clk
);
217 clrbits_le32((*prcm
)->cm_l3init_hsusbtll_clkctrl
, usbtll_clk
);
218 clrbits_le32((*prcm
)->cm_l3init_hsusbhost_clkctrl
, usbhost_clk
);
222 int ehci_hcd_init(int index
, enum usb_init_type init
,
223 struct ehci_hccr
**hccr
, struct ehci_hcor
**hcor
)
228 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE
, SMPS_VOLT_3V3
, SMPS9_CTRL
,
229 SMPS_MODE_SLP_AUTO
| SMPS_MODE_ACT_AUTO
);
231 setup_host_clocks(true);
233 ret
= omap_ehci_hcd_init(index
, &usbhs_bdata
, hccr
, hcor
);
235 printf("cm_t54: Failed to initialize ehci : %d\n", ret
);
240 int ehci_hcd_stop(void)
242 int ret
= omap_ehci_hcd_stop();
244 setup_host_clocks(false);
246 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE
, SMPS_VOLT_OFF
,
247 SMPS9_CTRL
, SMPS_MODE_SLP_AUTO
);
252 void usb_hub_reset_devices(int port
)
254 /* The LAN9730 needs to be reset after the port power has been set. */
256 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
, 0);
258 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO
, 1);