blob: 413f3c9c8f28e2ec4e9f3114f3e7e19776cfc4ab [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +03002/*
3 * Board functions for Compulab CM-T54 board
4 *
5 * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
6 *
7 * Author: Dmitry Lifshitz <lifshitz@compulab.co.il>
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +03008 */
9
10#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +030012#include <fdt_support.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +030014#include <usb.h>
15#include <mmc.h>
16#include <palmas.h>
Dmitry Lifshitzf0ead5d2014-04-27 13:18:48 +030017#include <spl.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +030019
20#include <asm/gpio.h>
21#include <asm/arch/sys_proto.h>
22#include <asm/arch/mmc_host_def.h>
23#include <asm/arch/clock.h>
24#include <asm/arch/ehci.h>
25#include <asm/ehci-omap.h>
26
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +030027#include "../common/eeprom.h"
28
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +030029#define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000)
30#define DIE_ID_REG_OFFSET 0x200
31
32DECLARE_GLOBAL_DATA_PTR;
33
34#if !defined(CONFIG_SPL_BUILD)
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +010035inline void set_muxconf_regs(void){};
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +030036#endif
37
38const struct omap_sysinfo sysinfo = {
39 "Board: CM-T54\n"
40};
41
42/*
43 * Routine: board_init
44 * Description: hardware init.
45 */
46int board_init(void)
47{
Dmitry Lifshitz29525de2014-07-31 14:30:39 +030048 gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +030049
50 return 0;
51}
52
53/*
54 * Routine: cm_t54_palmas_regulator_set
55 * Description: select voltage and turn on/off Palmas PMIC regulator.
56 */
57static int cm_t54_palmas_regulator_set(u8 vreg, u8 vval, u8 creg, u8 cval)
58{
59 int err;
60
61 /* Setup voltage */
62 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, vreg, vval);
63 if (err) {
64 printf("cm_t54: could not set regulator 0x%02x voltage : %d\n",
65 vreg, err);
66 return err;
67 }
68
69 /* Turn on/off regulator */
70 err = palmas_i2c_write_u8(TWL603X_CHIP_P1, creg, cval);
71 if (err) {
72 printf("cm_t54: could not turn on/off regulator 0x%02x : %d\n",
73 creg, err);
74 return err;
75 }
76
77 return 0;
78}
79
Dmitry Lifshitzf0ead5d2014-04-27 13:18:48 +030080/*
81 * Routine: mmc_get_env_part
82 * Description: setup environment storage device partition.
83 */
84#ifdef CONFIG_SYS_MMC_ENV_PART
85uint mmc_get_env_part(struct mmc *mmc)
86{
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020087 u32 bootmode = gd->arch.omap_boot_mode;
Dmitry Lifshitzf0ead5d2014-04-27 13:18:48 +030088 uint bootpart = CONFIG_SYS_MMC_ENV_PART;
89
90 /*
91 * If booted from eMMC boot partition then force eMMC
92 * FIRST boot partition to be env storage
93 */
Dmitry Lifshitz3f1546d2014-07-31 14:30:40 +030094 if (bootmode == BOOT_DEVICE_MMC2)
Dmitry Lifshitzf0ead5d2014-04-27 13:18:48 +030095 bootpart = 1;
96
97 return bootpart;
98}
99#endif
100
Masahiro Yamada0a780172017-05-09 20:31:39 +0900101#if defined(CONFIG_MMC)
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +0300102#define SB_T54_CD_GPIO 228
103#define SB_T54_WP_GPIO 229
104
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +0300105int board_mmc_init(bd_t *bis)
106{
107 int ret0, ret1;
108
Igor Grinberg2f4e0952014-11-03 11:32:23 +0200109 ret0 = omap_mmc_init(0, 0, 0, SB_T54_CD_GPIO, SB_T54_WP_GPIO);
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +0300110 if (ret0)
111 printf("cm_t54: failed to initialize mmc0\n");
112
113 ret1 = omap_mmc_init(1, 0, 0, -1, -1);
114 if (ret1)
115 printf("cm_t54: failed to initialize mmc1\n");
116
117 if (ret0 && ret1)
118 return -1;
119
120 return 0;
121}
122#endif
123
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300124#ifdef CONFIG_USB_HOST_ETHER
125
Simon Glass2aec3cc2014-10-23 18:58:47 -0600126int ft_board_setup(void *blob, bd_t *bd)
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300127{
128 uint8_t enetaddr[6];
129
130 /* MAC addr */
Simon Glass399a9ce2017-08-03 12:22:14 -0600131 if (eth_env_get_enetaddr("usbethaddr", enetaddr)) {
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300132 fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address",
133 enetaddr, 6, 1);
134 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600135
136 return 0;
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300137}
138
139static void generate_mac_addr(uint8_t *enetaddr)
140{
141 int reg;
142
143 reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET;
144
145 /*
146 * create a fake MAC address from the processor ID code.
147 * first byte is 0x02 to signify locally administered.
148 */
149 enetaddr[0] = 0x02;
150 enetaddr[1] = readl(reg + 0x10) & 0xff;
151 enetaddr[2] = readl(reg + 0xC) & 0xff;
152 enetaddr[3] = readl(reg + 0x8) & 0xff;
153 enetaddr[4] = readl(reg) & 0xff;
154 enetaddr[5] = (readl(reg) >> 8) & 0xff;
155}
156
157/*
158 * Routine: handle_mac_address
159 * Description: prepare MAC address for on-board Ethernet.
160 */
161static int handle_mac_address(void)
162{
163 uint8_t enetaddr[6];
164 int ret;
165
Simon Glass399a9ce2017-08-03 12:22:14 -0600166 ret = eth_env_get_enetaddr("usbethaddr", enetaddr);
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300167 if (ret)
168 return 0;
169
Nikita Kiryanovb2c55472015-01-14 10:42:43 +0200170 ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500171 if (ret || !is_valid_ethaddr(enetaddr))
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300172 generate_mac_addr(enetaddr);
173
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500174 if (!is_valid_ethaddr(enetaddr))
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300175 return -1;
176
Simon Glass8551d552017-08-03 12:22:11 -0600177 return eth_env_set_enetaddr("usbethaddr", enetaddr);
Dmitry Lifshitz0cc0b242014-04-27 13:18:46 +0300178}
179
180int board_eth_init(bd_t *bis)
181{
182 return handle_mac_address();
183}
184#endif
185
Tom Riniceed5d22017-05-12 22:33:27 -0400186#ifdef CONFIG_USB_EHCI_HCD
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +0300187static struct omap_usbhs_board_data usbhs_bdata = {
188 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
189 .port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC,
190 .port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC,
191};
192
193static void setup_host_clocks(bool enable)
194{
195 int usbhost_clk = OPTFCLKEN_HSIC60M_P3_CLK |
196 OPTFCLKEN_HSIC480M_P3_CLK |
197 OPTFCLKEN_HSIC60M_P2_CLK |
198 OPTFCLKEN_HSIC480M_P2_CLK |
199 OPTFCLKEN_UTMI_P3_CLK |
200 OPTFCLKEN_UTMI_P2_CLK;
201
202 int usbtll_clk = OPTFCLKEN_USB_CH1_CLK_ENABLE |
203 OPTFCLKEN_USB_CH2_CLK_ENABLE;
204
205 int usbhub_clk = CKOBUFFER_CLK_ENABLE_MASK;
206
207 if (enable) {
208 /* Enable port 2 and 3 clocks*/
209 setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
210 /* Enable port 2 and 3 usb host ports tll clocks*/
211 setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
212 /* Request FREF_XTAL_CLK clock for HSIC USB Hub */
213 setbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
214 } else {
215 clrbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
216 clrbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
217 clrbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
218 }
219}
220
221int ehci_hcd_init(int index, enum usb_init_type init,
222 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
223{
224 int ret;
225
226 /* VCC_3V3_ETH */
227 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_3V3, SMPS9_CTRL,
228 SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO);
229
230 setup_host_clocks(true);
231
232 ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
233 if (ret < 0)
234 printf("cm_t54: Failed to initialize ehci : %d\n", ret);
235
236 return ret;
237}
238
239int ehci_hcd_stop(void)
240{
241 int ret = omap_ehci_hcd_stop();
242
243 setup_host_clocks(false);
244
245 cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_OFF,
246 SMPS9_CTRL, SMPS_MODE_SLP_AUTO);
247
248 return ret;
249}
250
Philipp Tomsich693f4922017-11-22 17:15:17 +0100251void usb_hub_reset_devices(struct usb_hub_device *hub, int port)
Dmitry Lifshitzc3ad3a02014-05-19 12:50:54 +0300252{
253 /* The LAN9730 needs to be reset after the port power has been set. */
254 if (port == 3) {
255 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0);
256 udelay(10);
257 gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1);
258 }
259}
260#endif
261