2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-05-19 09:50:54 +00:00
|
|
|
/*
|
|
|
|
* Board functions for Compulab CM-T54 board
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
|
|
|
|
*
|
|
|
|
* Author: Dmitry Lifshitz <lifshitz@compulab.co.il>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-04-01 09:22:38 +00:00
|
|
|
#include <environment.h>
|
2014-04-27 10:18:46 +00:00
|
|
|
#include <fdt_support.h>
|
2014-05-19 09:50:54 +00:00
|
|
|
#include <usb.h>
|
|
|
|
#include <mmc.h>
|
|
|
|
#include <palmas.h>
|
2014-04-27 10:18:48 +00:00
|
|
|
#include <spl.h>
|
2014-05-19 09:50:54 +00:00
|
|
|
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/arch/mmc_host_def.h>
|
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#include <asm/arch/ehci.h>
|
|
|
|
#include <asm/ehci-omap.h>
|
|
|
|
|
2014-04-27 10:18:46 +00:00
|
|
|
#include "../common/eeprom.h"
|
|
|
|
|
2014-05-19 09:50:54 +00:00
|
|
|
#define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000)
|
|
|
|
#define DIE_ID_REG_OFFSET 0x200
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#if !defined(CONFIG_SPL_BUILD)
|
2016-02-27 18:18:56 +00:00
|
|
|
inline void set_muxconf_regs(void){};
|
2014-05-19 09:50:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const struct omap_sysinfo sysinfo = {
|
|
|
|
"Board: CM-T54\n"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine: board_init
|
|
|
|
* Description: hardware init.
|
|
|
|
*/
|
|
|
|
int board_init(void)
|
|
|
|
{
|
2014-07-31 11:30:39 +00:00
|
|
|
gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
|
2014-05-19 09:50:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine: cm_t54_palmas_regulator_set
|
|
|
|
* Description: select voltage and turn on/off Palmas PMIC regulator.
|
|
|
|
*/
|
|
|
|
static int cm_t54_palmas_regulator_set(u8 vreg, u8 vval, u8 creg, u8 cval)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Setup voltage */
|
|
|
|
err = palmas_i2c_write_u8(TWL603X_CHIP_P1, vreg, vval);
|
|
|
|
if (err) {
|
|
|
|
printf("cm_t54: could not set regulator 0x%02x voltage : %d\n",
|
|
|
|
vreg, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn on/off regulator */
|
|
|
|
err = palmas_i2c_write_u8(TWL603X_CHIP_P1, creg, cval);
|
|
|
|
if (err) {
|
|
|
|
printf("cm_t54: could not turn on/off regulator 0x%02x : %d\n",
|
|
|
|
creg, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-27 10:18:48 +00:00
|
|
|
/*
|
|
|
|
* Routine: mmc_get_env_part
|
|
|
|
* Description: setup environment storage device partition.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_SYS_MMC_ENV_PART
|
|
|
|
uint mmc_get_env_part(struct mmc *mmc)
|
|
|
|
{
|
2015-07-15 14:02:19 +00:00
|
|
|
u32 bootmode = gd->arch.omap_boot_mode;
|
2014-04-27 10:18:48 +00:00
|
|
|
uint bootpart = CONFIG_SYS_MMC_ENV_PART;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If booted from eMMC boot partition then force eMMC
|
|
|
|
* FIRST boot partition to be env storage
|
|
|
|
*/
|
2014-07-31 11:30:40 +00:00
|
|
|
if (bootmode == BOOT_DEVICE_MMC2)
|
2014-04-27 10:18:48 +00:00
|
|
|
bootpart = 1;
|
|
|
|
|
|
|
|
return bootpart;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-09 11:31:39 +00:00
|
|
|
#if defined(CONFIG_MMC)
|
2014-05-19 09:50:54 +00:00
|
|
|
#define SB_T54_CD_GPIO 228
|
|
|
|
#define SB_T54_WP_GPIO 229
|
|
|
|
|
|
|
|
int board_mmc_init(bd_t *bis)
|
|
|
|
{
|
|
|
|
int ret0, ret1;
|
|
|
|
|
2014-11-03 09:32:23 +00:00
|
|
|
ret0 = omap_mmc_init(0, 0, 0, SB_T54_CD_GPIO, SB_T54_WP_GPIO);
|
2014-05-19 09:50:54 +00:00
|
|
|
if (ret0)
|
|
|
|
printf("cm_t54: failed to initialize mmc0\n");
|
|
|
|
|
|
|
|
ret1 = omap_mmc_init(1, 0, 0, -1, -1);
|
|
|
|
if (ret1)
|
|
|
|
printf("cm_t54: failed to initialize mmc1\n");
|
|
|
|
|
|
|
|
if (ret0 && ret1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-27 10:18:46 +00:00
|
|
|
#ifdef CONFIG_USB_HOST_ETHER
|
|
|
|
|
2014-10-24 00:58:47 +00:00
|
|
|
int ft_board_setup(void *blob, bd_t *bd)
|
2014-04-27 10:18:46 +00:00
|
|
|
{
|
|
|
|
uint8_t enetaddr[6];
|
|
|
|
|
|
|
|
/* MAC addr */
|
2017-08-03 18:22:14 +00:00
|
|
|
if (eth_env_get_enetaddr("usbethaddr", enetaddr)) {
|
2014-04-27 10:18:46 +00:00
|
|
|
fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address",
|
|
|
|
enetaddr, 6, 1);
|
|
|
|
}
|
2014-10-24 00:58:47 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-04-27 10:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void generate_mac_addr(uint8_t *enetaddr)
|
|
|
|
{
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create a fake MAC address from the processor ID code.
|
|
|
|
* first byte is 0x02 to signify locally administered.
|
|
|
|
*/
|
|
|
|
enetaddr[0] = 0x02;
|
|
|
|
enetaddr[1] = readl(reg + 0x10) & 0xff;
|
|
|
|
enetaddr[2] = readl(reg + 0xC) & 0xff;
|
|
|
|
enetaddr[3] = readl(reg + 0x8) & 0xff;
|
|
|
|
enetaddr[4] = readl(reg) & 0xff;
|
|
|
|
enetaddr[5] = (readl(reg) >> 8) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine: handle_mac_address
|
|
|
|
* Description: prepare MAC address for on-board Ethernet.
|
|
|
|
*/
|
|
|
|
static int handle_mac_address(void)
|
|
|
|
{
|
|
|
|
uint8_t enetaddr[6];
|
|
|
|
int ret;
|
|
|
|
|
2017-08-03 18:22:14 +00:00
|
|
|
ret = eth_env_get_enetaddr("usbethaddr", enetaddr);
|
2014-04-27 10:18:46 +00:00
|
|
|
if (ret)
|
|
|
|
return 0;
|
|
|
|
|
2015-01-14 08:42:43 +00:00
|
|
|
ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
|
2015-04-08 06:41:04 +00:00
|
|
|
if (ret || !is_valid_ethaddr(enetaddr))
|
2014-04-27 10:18:46 +00:00
|
|
|
generate_mac_addr(enetaddr);
|
|
|
|
|
2015-04-08 06:41:04 +00:00
|
|
|
if (!is_valid_ethaddr(enetaddr))
|
2014-04-27 10:18:46 +00:00
|
|
|
return -1;
|
|
|
|
|
2017-08-03 18:22:11 +00:00
|
|
|
return eth_env_set_enetaddr("usbethaddr", enetaddr);
|
2014-04-27 10:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int board_eth_init(bd_t *bis)
|
|
|
|
{
|
|
|
|
return handle_mac_address();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-13 02:33:27 +00:00
|
|
|
#ifdef CONFIG_USB_EHCI_HCD
|
2014-05-19 09:50:54 +00:00
|
|
|
static struct omap_usbhs_board_data usbhs_bdata = {
|
|
|
|
.port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
|
|
|
|
.port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC,
|
|
|
|
.port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void setup_host_clocks(bool enable)
|
|
|
|
{
|
|
|
|
int usbhost_clk = OPTFCLKEN_HSIC60M_P3_CLK |
|
|
|
|
OPTFCLKEN_HSIC480M_P3_CLK |
|
|
|
|
OPTFCLKEN_HSIC60M_P2_CLK |
|
|
|
|
OPTFCLKEN_HSIC480M_P2_CLK |
|
|
|
|
OPTFCLKEN_UTMI_P3_CLK |
|
|
|
|
OPTFCLKEN_UTMI_P2_CLK;
|
|
|
|
|
|
|
|
int usbtll_clk = OPTFCLKEN_USB_CH1_CLK_ENABLE |
|
|
|
|
OPTFCLKEN_USB_CH2_CLK_ENABLE;
|
|
|
|
|
|
|
|
int usbhub_clk = CKOBUFFER_CLK_ENABLE_MASK;
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
/* Enable port 2 and 3 clocks*/
|
|
|
|
setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
|
|
|
|
/* Enable port 2 and 3 usb host ports tll clocks*/
|
|
|
|
setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
|
|
|
|
/* Request FREF_XTAL_CLK clock for HSIC USB Hub */
|
|
|
|
setbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
|
|
|
|
} else {
|
|
|
|
clrbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
|
|
|
|
clrbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
|
|
|
|
clrbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ehci_hcd_init(int index, enum usb_init_type init,
|
|
|
|
struct ehci_hccr **hccr, struct ehci_hcor **hcor)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* VCC_3V3_ETH */
|
|
|
|
cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_3V3, SMPS9_CTRL,
|
|
|
|
SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO);
|
|
|
|
|
|
|
|
setup_host_clocks(true);
|
|
|
|
|
|
|
|
ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
|
|
|
|
if (ret < 0)
|
|
|
|
printf("cm_t54: Failed to initialize ehci : %d\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ehci_hcd_stop(void)
|
|
|
|
{
|
|
|
|
int ret = omap_ehci_hcd_stop();
|
|
|
|
|
|
|
|
setup_host_clocks(false);
|
|
|
|
|
|
|
|
cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_OFF,
|
|
|
|
SMPS9_CTRL, SMPS_MODE_SLP_AUTO);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-11-22 16:15:17 +00:00
|
|
|
void usb_hub_reset_devices(struct usb_hub_device *hub, int port)
|
2014-05-19 09:50:54 +00:00
|
|
|
{
|
|
|
|
/* The LAN9730 needs to be reset after the port power has been set. */
|
|
|
|
if (port == 3) {
|
|
|
|
gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0);
|
|
|
|
udelay(10);
|
|
|
|
gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|