12c2a9f3aSSRICHARAN R /*
22c2a9f3aSSRICHARAN R * (C) Copyright 2010
32c2a9f3aSSRICHARAN R * Texas Instruments Incorporated, <www.ti.com>
42c2a9f3aSSRICHARAN R * Aneesh V <aneesh@ti.com>
52c2a9f3aSSRICHARAN R * Steve Sakoman <steve@sakoman.com>
62c2a9f3aSSRICHARAN R *
71a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
82c2a9f3aSSRICHARAN R */
92c2a9f3aSSRICHARAN R #include <common.h>
10cb199102SNishanth Menon #include <palmas.h>
117ba792c0SKishon Vijay Abraham I #include <asm/arch/omap.h>
122c2a9f3aSSRICHARAN R #include <asm/arch/sys_proto.h>
132c2a9f3aSSRICHARAN R #include <asm/arch/mmc_host_def.h>
14fdce7b63SDan Murphy #include <tca642x.h>
157ba792c0SKishon Vijay Abraham I #include <usb.h>
167ba792c0SKishon Vijay Abraham I #include <linux/usb/gadget.h>
177ba792c0SKishon Vijay Abraham I #include <dwc3-uboot.h>
187ba792c0SKishon Vijay Abraham I #include <dwc3-omap-uboot.h>
197ba792c0SKishon Vijay Abraham I #include <ti-usb-phy-uboot.h>
202c2a9f3aSSRICHARAN R
212c2a9f3aSSRICHARAN R #include "mux_data.h"
222c2a9f3aSSRICHARAN R
238850c5d5STom Rini #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_XHCI_OMAP)
24e9024ef2SDan Murphy #include <sata.h>
255e5cfaf9SDan Murphy #include <usb.h>
261572eadfSDan Murphy #include <asm/gpio.h>
27c62db35dSSimon Glass #include <asm/mach-types.h>
285e5cfaf9SDan Murphy #include <asm/arch/clock.h>
295e5cfaf9SDan Murphy #include <asm/arch/ehci.h>
305e5cfaf9SDan Murphy #include <asm/ehci-omap.h>
31afdc6321SRoger Quadros #include <asm/arch/sata.h>
3204025b42SDan Murphy
3304025b42SDan Murphy #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000)
3404025b42SDan Murphy #define DIE_ID_REG_OFFSET 0x200
3504025b42SDan Murphy
365e5cfaf9SDan Murphy #endif
375e5cfaf9SDan Murphy
382c2a9f3aSSRICHARAN R DECLARE_GLOBAL_DATA_PTR;
392c2a9f3aSSRICHARAN R
402c2a9f3aSSRICHARAN R const struct omap_sysinfo sysinfo = {
415a7bd384SDan Murphy "Board: OMAP5432 uEVM\n"
422c2a9f3aSSRICHARAN R };
432c2a9f3aSSRICHARAN R
442c2a9f3aSSRICHARAN R /**
45fdce7b63SDan Murphy * @brief tca642x_init - uEVM default values for the GPIO expander
46fdce7b63SDan Murphy * input reg, output reg, polarity reg, configuration reg
47fdce7b63SDan Murphy */
48fdce7b63SDan Murphy struct tca642x_bank_info tca642x_init[] = {
49fdce7b63SDan Murphy { .input_reg = 0x00,
50fdce7b63SDan Murphy .output_reg = 0x04,
51fdce7b63SDan Murphy .polarity_reg = 0x00,
52fdce7b63SDan Murphy .configuration_reg = 0x80 },
53fdce7b63SDan Murphy { .input_reg = 0x00,
54fdce7b63SDan Murphy .output_reg = 0x00,
55fdce7b63SDan Murphy .polarity_reg = 0x00,
56fdce7b63SDan Murphy .configuration_reg = 0xff },
57fdce7b63SDan Murphy { .input_reg = 0x00,
58fdce7b63SDan Murphy .output_reg = 0x00,
59fdce7b63SDan Murphy .polarity_reg = 0x00,
60fdce7b63SDan Murphy .configuration_reg = 0x40 },
61fdce7b63SDan Murphy };
62fdce7b63SDan Murphy
637ba792c0SKishon Vijay Abraham I #ifdef CONFIG_USB_DWC3
647ba792c0SKishon Vijay Abraham I static struct dwc3_device usb_otg_ss = {
657ba792c0SKishon Vijay Abraham I .maximum_speed = USB_SPEED_SUPER,
667ba792c0SKishon Vijay Abraham I .base = OMAP5XX_USB_OTG_SS_BASE,
677ba792c0SKishon Vijay Abraham I .tx_fifo_resize = false,
687ba792c0SKishon Vijay Abraham I .index = 0,
697ba792c0SKishon Vijay Abraham I };
707ba792c0SKishon Vijay Abraham I
717ba792c0SKishon Vijay Abraham I static struct dwc3_omap_device usb_otg_ss_glue = {
727ba792c0SKishon Vijay Abraham I .base = (void *)OMAP5XX_USB_OTG_SS_GLUE_BASE,
737ba792c0SKishon Vijay Abraham I .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
747ba792c0SKishon Vijay Abraham I .index = 0,
757ba792c0SKishon Vijay Abraham I };
767ba792c0SKishon Vijay Abraham I
777ba792c0SKishon Vijay Abraham I static struct ti_usb_phy_device usb_phy_device = {
787ba792c0SKishon Vijay Abraham I .pll_ctrl_base = (void *)OMAP5XX_USB3_PHY_PLL_CTRL,
797ba792c0SKishon Vijay Abraham I .usb2_phy_power = (void *)OMAP5XX_USB2_PHY_POWER,
807ba792c0SKishon Vijay Abraham I .usb3_phy_power = (void *)OMAP5XX_USB3_PHY_POWER,
817ba792c0SKishon Vijay Abraham I .index = 0,
827ba792c0SKishon Vijay Abraham I };
837ba792c0SKishon Vijay Abraham I
board_usb_init(int index,enum usb_init_type init)847ba792c0SKishon Vijay Abraham I int board_usb_init(int index, enum usb_init_type init)
857ba792c0SKishon Vijay Abraham I {
867ba792c0SKishon Vijay Abraham I if (index) {
877ba792c0SKishon Vijay Abraham I printf("Invalid Controller Index\n");
887ba792c0SKishon Vijay Abraham I return -EINVAL;
897ba792c0SKishon Vijay Abraham I }
907ba792c0SKishon Vijay Abraham I
917ba792c0SKishon Vijay Abraham I if (init == USB_INIT_DEVICE) {
927ba792c0SKishon Vijay Abraham I usb_otg_ss.dr_mode = USB_DR_MODE_PERIPHERAL;
937ba792c0SKishon Vijay Abraham I usb_otg_ss_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
947ba792c0SKishon Vijay Abraham I } else {
957ba792c0SKishon Vijay Abraham I usb_otg_ss.dr_mode = USB_DR_MODE_HOST;
967ba792c0SKishon Vijay Abraham I usb_otg_ss_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
977ba792c0SKishon Vijay Abraham I }
987ba792c0SKishon Vijay Abraham I
996f1af1e3SKishon Vijay Abraham I enable_usb_clocks(index);
1007ba792c0SKishon Vijay Abraham I ti_usb_phy_uboot_init(&usb_phy_device);
1017ba792c0SKishon Vijay Abraham I dwc3_omap_uboot_init(&usb_otg_ss_glue);
1027ba792c0SKishon Vijay Abraham I dwc3_uboot_init(&usb_otg_ss);
1037ba792c0SKishon Vijay Abraham I
1047ba792c0SKishon Vijay Abraham I return 0;
1057ba792c0SKishon Vijay Abraham I }
1067ba792c0SKishon Vijay Abraham I
board_usb_cleanup(int index,enum usb_init_type init)1077ba792c0SKishon Vijay Abraham I int board_usb_cleanup(int index, enum usb_init_type init)
1087ba792c0SKishon Vijay Abraham I {
1097ba792c0SKishon Vijay Abraham I if (index) {
1107ba792c0SKishon Vijay Abraham I printf("Invalid Controller Index\n");
1117ba792c0SKishon Vijay Abraham I return -EINVAL;
1127ba792c0SKishon Vijay Abraham I }
1137ba792c0SKishon Vijay Abraham I
1147ba792c0SKishon Vijay Abraham I ti_usb_phy_uboot_exit(index);
1157ba792c0SKishon Vijay Abraham I dwc3_uboot_exit(index);
1167ba792c0SKishon Vijay Abraham I dwc3_omap_uboot_exit(index);
1176f1af1e3SKishon Vijay Abraham I disable_usb_clocks(index);
1187ba792c0SKishon Vijay Abraham I
1197ba792c0SKishon Vijay Abraham I return 0;
1207ba792c0SKishon Vijay Abraham I }
1217ba792c0SKishon Vijay Abraham I
usb_gadget_handle_interrupts(int index)1227ba792c0SKishon Vijay Abraham I int usb_gadget_handle_interrupts(int index)
1237ba792c0SKishon Vijay Abraham I {
1247ba792c0SKishon Vijay Abraham I u32 status;
1257ba792c0SKishon Vijay Abraham I
1267ba792c0SKishon Vijay Abraham I status = dwc3_omap_uboot_interrupt_status(index);
1277ba792c0SKishon Vijay Abraham I if (status)
1287ba792c0SKishon Vijay Abraham I dwc3_uboot_handle_interrupt(index);
1297ba792c0SKishon Vijay Abraham I
1307ba792c0SKishon Vijay Abraham I return 0;
1317ba792c0SKishon Vijay Abraham I }
1327ba792c0SKishon Vijay Abraham I #endif
1337ba792c0SKishon Vijay Abraham I
134fdce7b63SDan Murphy /**
1352c2a9f3aSSRICHARAN R * @brief board_init
1362c2a9f3aSSRICHARAN R *
1372c2a9f3aSSRICHARAN R * @return 0
1382c2a9f3aSSRICHARAN R */
board_init(void)1392c2a9f3aSSRICHARAN R int board_init(void)
1402c2a9f3aSSRICHARAN R {
1412c2a9f3aSSRICHARAN R gpmc_init();
14294ba26f2STom Rini gd->bd->bi_arch_number = MACH_TYPE_OMAP5_SEVM;
1432c2a9f3aSSRICHARAN R gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
1442c2a9f3aSSRICHARAN R
145fdce7b63SDan Murphy tca642x_set_inital_state(CONFIG_SYS_I2C_TCA642X_ADDR, tca642x_init);
146fdce7b63SDan Murphy
1472c2a9f3aSSRICHARAN R return 0;
1482c2a9f3aSSRICHARAN R }
1492c2a9f3aSSRICHARAN R
board_eth_init(bd_t * bis)1502c2a9f3aSSRICHARAN R int board_eth_init(bd_t *bis)
1512c2a9f3aSSRICHARAN R {
1522c2a9f3aSSRICHARAN R return 0;
1532c2a9f3aSSRICHARAN R }
1542c2a9f3aSSRICHARAN R
1558850c5d5STom Rini #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_XHCI_OMAP)
enable_host_clocks(void)15696805532SDan Murphy static void enable_host_clocks(void)
15796805532SDan Murphy {
15896805532SDan Murphy int auxclk;
15996805532SDan Murphy int hs_clk_ctrl_val = (OPTFCLKEN_HSIC60M_P3_CLK |
16096805532SDan Murphy OPTFCLKEN_HSIC480M_P3_CLK |
16196805532SDan Murphy OPTFCLKEN_HSIC60M_P2_CLK |
16296805532SDan Murphy OPTFCLKEN_HSIC480M_P2_CLK |
16396805532SDan Murphy OPTFCLKEN_UTMI_P3_CLK | OPTFCLKEN_UTMI_P2_CLK);
16496805532SDan Murphy
16596805532SDan Murphy /* Enable port 2 and 3 clocks*/
16696805532SDan Murphy setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, hs_clk_ctrl_val);
16796805532SDan Murphy
16896805532SDan Murphy /* Enable port 2 and 3 usb host ports tll clocks*/
16996805532SDan Murphy setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl,
17096805532SDan Murphy (OPTFCLKEN_USB_CH1_CLK_ENABLE | OPTFCLKEN_USB_CH2_CLK_ENABLE));
17196805532SDan Murphy #ifdef CONFIG_USB_XHCI_OMAP
17296805532SDan Murphy /* Enable the USB OTG Super speed clocks */
17396805532SDan Murphy setbits_le32((*prcm)->cm_l3init_usb_otg_ss_clkctrl,
17496805532SDan Murphy (OPTFCLKEN_REFCLK960M | OTG_SS_CLKCTRL_MODULEMODE_HW));
17596805532SDan Murphy #endif
17696805532SDan Murphy
17796805532SDan Murphy auxclk = readl((*prcm)->scrm_auxclk1);
17896805532SDan Murphy /* Request auxilary clock */
17996805532SDan Murphy auxclk |= AUXCLK_ENABLE_MASK;
18096805532SDan Murphy writel(auxclk, (*prcm)->scrm_auxclk1);
18196805532SDan Murphy }
18296805532SDan Murphy #endif
18396805532SDan Murphy
1842c2a9f3aSSRICHARAN R /**
1852c2a9f3aSSRICHARAN R * @brief misc_init_r - Configure EVM board specific configurations
1862c2a9f3aSSRICHARAN R * such as power configurations, ethernet initialization as phase2 of
1872c2a9f3aSSRICHARAN R * boot sequence
1882c2a9f3aSSRICHARAN R *
1892c2a9f3aSSRICHARAN R * @return 0
1902c2a9f3aSSRICHARAN R */
misc_init_r(void)1912c2a9f3aSSRICHARAN R int misc_init_r(void)
1922c2a9f3aSSRICHARAN R {
193cb199102SNishanth Menon #ifdef CONFIG_PALMAS_POWER
19412733881SNishanth Menon palmas_init_settings();
1952c2a9f3aSSRICHARAN R #endif
19696805532SDan Murphy
19707815eb9SPaul Kocialkowski omap_die_id_usbethaddr();
198ea02b653SDan Murphy
1992c2a9f3aSSRICHARAN R return 0;
2002c2a9f3aSSRICHARAN R }
2012c2a9f3aSSRICHARAN R
set_muxconf_regs(void)2023ef56e61SPaul Kocialkowski void set_muxconf_regs(void)
2032c2a9f3aSSRICHARAN R {
2049239f5b6SLokesh Vutla do_set_mux((*ctrl)->control_padconf_core_base,
2059239f5b6SLokesh Vutla core_padconf_array_essential,
2062c2a9f3aSSRICHARAN R sizeof(core_padconf_array_essential) /
2072c2a9f3aSSRICHARAN R sizeof(struct pad_conf_entry));
2082c2a9f3aSSRICHARAN R
2099239f5b6SLokesh Vutla do_set_mux((*ctrl)->control_padconf_wkup_base,
2109239f5b6SLokesh Vutla wkup_padconf_array_essential,
2112c2a9f3aSSRICHARAN R sizeof(wkup_padconf_array_essential) /
2122c2a9f3aSSRICHARAN R sizeof(struct pad_conf_entry));
2132c2a9f3aSSRICHARAN R }
2142c2a9f3aSSRICHARAN R
2154aa2ba3aSMasahiro Yamada #if defined(CONFIG_MMC)
board_mmc_init(bd_t * bis)2162c2a9f3aSSRICHARAN R int board_mmc_init(bd_t *bis)
2172c2a9f3aSSRICHARAN R {
2182c2a9f3aSSRICHARAN R omap_mmc_init(0, 0, 0, -1, -1);
2192c2a9f3aSSRICHARAN R omap_mmc_init(1, 0, 0, -1, -1);
2202c2a9f3aSSRICHARAN R return 0;
2212c2a9f3aSSRICHARAN R }
2222c2a9f3aSSRICHARAN R #endif
2235e5cfaf9SDan Murphy
2248850c5d5STom Rini #ifdef CONFIG_USB_EHCI_HCD
2255e5cfaf9SDan Murphy static struct omap_usbhs_board_data usbhs_bdata = {
2265e5cfaf9SDan Murphy .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
2275e5cfaf9SDan Murphy .port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC,
2285e5cfaf9SDan Murphy .port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC,
2295e5cfaf9SDan Murphy };
2305e5cfaf9SDan Murphy
ehci_hcd_init(int index,enum usb_init_type init,struct ehci_hccr ** hccr,struct ehci_hcor ** hcor)231127efc4fSTroy Kisky int ehci_hcd_init(int index, enum usb_init_type init,
232127efc4fSTroy Kisky struct ehci_hccr **hccr, struct ehci_hcor **hcor)
2335e5cfaf9SDan Murphy {
2345e5cfaf9SDan Murphy int ret;
2355e5cfaf9SDan Murphy
2365e5cfaf9SDan Murphy enable_host_clocks();
2375e5cfaf9SDan Murphy
23816297cfbSMateusz Zalega ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
2395e5cfaf9SDan Murphy if (ret < 0) {
2405e5cfaf9SDan Murphy puts("Failed to initialize ehci\n");
2415e5cfaf9SDan Murphy return ret;
2425e5cfaf9SDan Murphy }
2435e5cfaf9SDan Murphy
2445e5cfaf9SDan Murphy return 0;
2455e5cfaf9SDan Murphy }
2465e5cfaf9SDan Murphy
ehci_hcd_stop(void)2475e5cfaf9SDan Murphy int ehci_hcd_stop(void)
2485e5cfaf9SDan Murphy {
24963a7578eSMasahiro Yamada return omap_ehci_hcd_stop();
2505e5cfaf9SDan Murphy }
2511572eadfSDan Murphy
usb_hub_reset_devices(struct usb_hub_device * hub,int port)252*3f6e9bd9SPhilipp Tomsich void usb_hub_reset_devices(struct usb_hub_device *hub, int port)
2531572eadfSDan Murphy {
2541572eadfSDan Murphy /* The LAN9730 needs to be reset after the port power has been set. */
2551572eadfSDan Murphy if (port == 3) {
2561572eadfSDan Murphy gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0);
2571572eadfSDan Murphy udelay(10);
2581572eadfSDan Murphy gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1);
2591572eadfSDan Murphy }
2601572eadfSDan Murphy }
2615e5cfaf9SDan Murphy #endif
26296805532SDan Murphy
26396805532SDan Murphy #ifdef CONFIG_USB_XHCI_OMAP
26496805532SDan Murphy /**
26596805532SDan Murphy * @brief board_usb_init - Configure EVM board specific configurations
26696805532SDan Murphy * for the LDO's and clocks for the USB blocks.
26796805532SDan Murphy *
26896805532SDan Murphy * @return 0
26996805532SDan Murphy */
board_usb_init(int index,enum usb_init_type init)2707e575c46STroy Kisky int board_usb_init(int index, enum usb_init_type init)
27196805532SDan Murphy {
27296805532SDan Murphy int ret;
27396805532SDan Murphy #ifdef CONFIG_PALMAS_USB_SS_PWR
27496805532SDan Murphy ret = palmas_enable_ss_ldo();
27596805532SDan Murphy #endif
27696805532SDan Murphy
27796805532SDan Murphy enable_host_clocks();
27896805532SDan Murphy
27996805532SDan Murphy return 0;
28096805532SDan Murphy }
28196805532SDan Murphy #endif
282