1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2010
4  * Texas Instruments Incorporated, <www.ti.com>
5  * Aneesh V       <aneesh@ti.com>
6  * Steve Sakoman  <steve@sakoman.com>
7  */
8 #include <common.h>
9 #include <init.h>
10 #include <net.h>
11 #include <palmas.h>
12 #include <asm/arch/omap.h>
13 #include <asm/arch/sys_proto.h>
14 #include <asm/arch/mmc_host_def.h>
15 #include <serial.h>
16 #include <tca642x.h>
17 #include <usb.h>
18 #include <asm/global_data.h>
19 #include <linux/delay.h>
20 #include <linux/usb/gadget.h>
21 #include <dwc3-uboot.h>
22 #include <dwc3-omap-uboot.h>
23 #include <ti-usb-phy-uboot.h>
24 
25 #include "mux_data.h"
26 
27 #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_XHCI_OMAP)
28 #include <sata.h>
29 #include <usb.h>
30 #include <asm/gpio.h>
31 #include <asm/mach-types.h>
32 #include <asm/arch/clock.h>
33 #include <asm/arch/ehci.h>
34 #include <asm/ehci-omap.h>
35 #include <asm/arch/sata.h>
36 
37 #define DIE_ID_REG_BASE     (OMAP54XX_L4_CORE_BASE + 0x2000)
38 #define DIE_ID_REG_OFFSET	0x200
39 
40 #endif
41 
42 DECLARE_GLOBAL_DATA_PTR;
43 
44 const struct omap_sysinfo sysinfo = {
45 	"Board: OMAP5432 uEVM\n"
46 };
47 
48 /**
49  * @brief tca642x_init - uEVM default values for the GPIO expander
50  * input reg, output reg, polarity reg, configuration reg
51  */
52 struct tca642x_bank_info tca642x_init[] = {
53 	{ .input_reg = 0x00,
54 	  .output_reg = 0x04,
55 	  .polarity_reg = 0x00,
56 	  .configuration_reg = 0x80 },
57 	{ .input_reg = 0x00,
58 	  .output_reg = 0x00,
59 	  .polarity_reg = 0x00,
60 	  .configuration_reg = 0xff },
61 	{ .input_reg = 0x00,
62 	  .output_reg = 0x00,
63 	  .polarity_reg = 0x00,
64 	  .configuration_reg = 0x40 },
65 };
66 
67 #ifdef CONFIG_USB_DWC3
68 static struct dwc3_device usb_otg_ss = {
69 	.maximum_speed = USB_SPEED_SUPER,
70 	.base = OMAP5XX_USB_OTG_SS_BASE,
71 	.tx_fifo_resize = false,
72 	.index = 0,
73 };
74 
75 static struct dwc3_omap_device usb_otg_ss_glue = {
76 	.base = (void *)OMAP5XX_USB_OTG_SS_GLUE_BASE,
77 	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
78 	.index = 0,
79 };
80 
81 static struct ti_usb_phy_device usb_phy_device = {
82 	.pll_ctrl_base = (void *)OMAP5XX_USB3_PHY_PLL_CTRL,
83 	.usb2_phy_power = (void *)OMAP5XX_USB2_PHY_POWER,
84 	.usb3_phy_power = (void *)OMAP5XX_USB3_PHY_POWER,
85 	.index = 0,
86 };
87 
board_usb_init(int index,enum usb_init_type init)88 int board_usb_init(int index, enum usb_init_type init)
89 {
90 	if (index) {
91 		printf("Invalid Controller Index\n");
92 		return -EINVAL;
93 	}
94 
95 	if (init == USB_INIT_DEVICE) {
96 		usb_otg_ss.dr_mode = USB_DR_MODE_PERIPHERAL;
97 		usb_otg_ss_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
98 	} else {
99 		usb_otg_ss.dr_mode = USB_DR_MODE_HOST;
100 		usb_otg_ss_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
101 	}
102 
103 	enable_usb_clocks(index);
104 	ti_usb_phy_uboot_init(&usb_phy_device);
105 	dwc3_omap_uboot_init(&usb_otg_ss_glue);
106 	dwc3_uboot_init(&usb_otg_ss);
107 
108 	return 0;
109 }
110 
board_usb_cleanup(int index,enum usb_init_type init)111 int board_usb_cleanup(int index, enum usb_init_type init)
112 {
113 	if (index) {
114 		printf("Invalid Controller Index\n");
115 		return -EINVAL;
116 	}
117 
118 	ti_usb_phy_uboot_exit(index);
119 	dwc3_uboot_exit(index);
120 	dwc3_omap_uboot_exit(index);
121 	disable_usb_clocks(index);
122 
123 	return 0;
124 }
125 
usb_gadget_handle_interrupts(int index)126 int usb_gadget_handle_interrupts(int index)
127 {
128 	u32 status;
129 
130 	status = dwc3_omap_uboot_interrupt_status(index);
131 	if (status)
132 		dwc3_uboot_handle_interrupt(index);
133 
134 	return 0;
135 }
136 #endif
137 
138 /**
139  * @brief board_init
140  *
141  * @return 0
142  */
board_init(void)143 int board_init(void)
144 {
145 	gpmc_init();
146 	gd->bd->bi_arch_number = MACH_TYPE_OMAP5_SEVM;
147 	gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
148 
149 	tca642x_set_inital_state(CONFIG_SYS_I2C_TCA642X_ADDR, tca642x_init);
150 
151 	return 0;
152 }
153 
154 #if defined(CONFIG_SPL_OS_BOOT)
spl_start_uboot(void)155 int spl_start_uboot(void)
156 {
157 	/* break into full u-boot on 'c' */
158 	if (serial_tstc() && serial_getc() == 'c')
159 		return 1;
160 
161 	return 0;
162 }
163 #endif /* CONFIG_SPL_OS_BOOT */
164 
board_eth_init(struct bd_info * bis)165 int board_eth_init(struct bd_info *bis)
166 {
167 	return 0;
168 }
169 
170 /**
171  * @brief misc_init_r - Configure EVM board specific configurations
172  * such as power configurations, ethernet initialization as phase2 of
173  * boot sequence
174  *
175  * @return 0
176  */
misc_init_r(void)177 int misc_init_r(void)
178 {
179 #ifdef CONFIG_PALMAS_POWER
180 	palmas_init_settings();
181 #endif
182 
183 	omap_die_id_usbethaddr();
184 
185 	return 0;
186 }
187 
set_muxconf_regs(void)188 void set_muxconf_regs(void)
189 {
190 	do_set_mux((*ctrl)->control_padconf_core_base,
191 		   core_padconf_array_essential,
192 		   sizeof(core_padconf_array_essential) /
193 		   sizeof(struct pad_conf_entry));
194 
195 	do_set_mux((*ctrl)->control_padconf_wkup_base,
196 		   wkup_padconf_array_essential,
197 		   sizeof(wkup_padconf_array_essential) /
198 		   sizeof(struct pad_conf_entry));
199 }
200 
201 #if defined(CONFIG_MMC)
board_mmc_init(struct bd_info * bis)202 int board_mmc_init(struct bd_info *bis)
203 {
204 	omap_mmc_init(0, 0, 0, -1, -1);
205 	omap_mmc_init(1, 0, 0, -1, -1);
206 	return 0;
207 }
208 #endif
209 
210 #ifdef CONFIG_USB_XHCI_OMAP
211 /**
212  * @brief board_usb_init - Configure EVM board specific configurations
213  * for the LDO's and clocks for the USB blocks.
214  *
215  * @return 0
216  */
board_usb_init(int index,enum usb_init_type init)217 int board_usb_init(int index, enum usb_init_type init)
218 {
219 	int ret;
220 #ifdef CONFIG_PALMAS_USB_SS_PWR
221 	ret = palmas_enable_ss_ldo();
222 #endif
223 
224 	return 0;
225 }
226 #endif
227