xref: /openbmc/u-boot/board/birdland/bav335x/board.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a2bc4321SGilles Gameiro /*
3a2bc4321SGilles Gameiro  * board.c
4a2bc4321SGilles Gameiro  *
5a2bc4321SGilles Gameiro  * Board functions for Birdland Audio BAV335x Network Processor
6a2bc4321SGilles Gameiro  *
7a2bc4321SGilles Gameiro  * Copyright (c) 2012-2014 Birdland Audio - http://birdland.com/oem
8a2bc4321SGilles Gameiro  */
9a2bc4321SGilles Gameiro 
10a2bc4321SGilles Gameiro #include <common.h>
11a2bc4321SGilles Gameiro #include <errno.h>
12a2bc4321SGilles Gameiro #include <spl.h>
13a2bc4321SGilles Gameiro #include <asm/arch/cpu.h>
14a2bc4321SGilles Gameiro #include <asm/arch/hardware.h>
15a2bc4321SGilles Gameiro #include <asm/arch/omap.h>
16a2bc4321SGilles Gameiro #include <asm/arch/ddr_defs.h>
17a2bc4321SGilles Gameiro #include <asm/arch/clock.h>
18a2bc4321SGilles Gameiro #include <asm/arch/gpio.h>
19a2bc4321SGilles Gameiro #include <asm/arch/mmc_host_def.h>
20a2bc4321SGilles Gameiro #include <asm/arch/sys_proto.h>
21a2bc4321SGilles Gameiro #include <asm/arch/mem.h>
22a2bc4321SGilles Gameiro #include <asm/io.h>
23a2bc4321SGilles Gameiro #include <asm/emif.h>
24a2bc4321SGilles Gameiro #include <asm/gpio.h>
25a2bc4321SGilles Gameiro #include <i2c.h>
26a2bc4321SGilles Gameiro #include <miiphy.h>
27a2bc4321SGilles Gameiro #include <cpsw.h>
28a2bc4321SGilles Gameiro #include <power/tps65217.h>
29a2bc4321SGilles Gameiro #include <power/tps65910.h>
30a2bc4321SGilles Gameiro #include <environment.h>
31a2bc4321SGilles Gameiro #include <watchdog.h>
32a2bc4321SGilles Gameiro #include <environment.h>
33a2bc4321SGilles Gameiro #include "board.h"
34a2bc4321SGilles Gameiro 
35a2bc4321SGilles Gameiro DECLARE_GLOBAL_DATA_PTR;
36a2bc4321SGilles Gameiro 
37a2bc4321SGilles Gameiro /* GPIO that controls power to DDR on EVM-SK */
38a2bc4321SGilles Gameiro #define GPIO_DDR_VTT_EN		7
39a2bc4321SGilles Gameiro 
40a2bc4321SGilles Gameiro static __maybe_unused struct ctrl_dev *cdev =
41a2bc4321SGilles Gameiro 		(struct ctrl_dev *)CTRL_DEVICE_BASE;
42a2bc4321SGilles Gameiro 
43a2bc4321SGilles Gameiro 
44a2bc4321SGilles Gameiro 
45a2bc4321SGilles Gameiro /*
46a2bc4321SGilles Gameiro  * Read header information from EEPROM into global structure.
47a2bc4321SGilles Gameiro  */
read_eeprom(struct board_eeconfig * header)48a2bc4321SGilles Gameiro static int read_eeprom(struct board_eeconfig *header)
49a2bc4321SGilles Gameiro {
50a2bc4321SGilles Gameiro 	/* Check if baseboard eeprom is available */
51a2bc4321SGilles Gameiro 	if (i2c_probe(CONFIG_SYS_I2C_EEPROM_ADDR))
52a2bc4321SGilles Gameiro 		return -ENODEV;
53a2bc4321SGilles Gameiro 
54a2bc4321SGilles Gameiro 	/* read the eeprom using i2c */
55a2bc4321SGilles Gameiro 	if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, (uchar *)header,
56a2bc4321SGilles Gameiro 		     sizeof(struct board_eeconfig)))
57a2bc4321SGilles Gameiro 		return -EIO;
58a2bc4321SGilles Gameiro 
59a2bc4321SGilles Gameiro 	if (header->magic != BOARD_MAGIC) {
60a2bc4321SGilles Gameiro 		/* read the i2c eeprom again using only a 1 byte address */
61a2bc4321SGilles Gameiro 		if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 1, (uchar *)header,
62a2bc4321SGilles Gameiro 			     sizeof(struct board_eeconfig)))
63a2bc4321SGilles Gameiro 			return -EIO;
64a2bc4321SGilles Gameiro 
65a2bc4321SGilles Gameiro 		if (header->magic != BOARD_MAGIC)
66a2bc4321SGilles Gameiro 			return -EINVAL;
67a2bc4321SGilles Gameiro 	}
68a2bc4321SGilles Gameiro 	return 0;
69a2bc4321SGilles Gameiro }
70a2bc4321SGilles Gameiro 
71a2bc4321SGilles Gameiro 
72a2bc4321SGilles Gameiro 
73a2bc4321SGilles Gameiro 
get_board_type(bool debug)74a2bc4321SGilles Gameiro enum board_type get_board_type(bool debug)
75a2bc4321SGilles Gameiro {
76a2bc4321SGilles Gameiro 	int ecode;
77a2bc4321SGilles Gameiro 	struct board_eeconfig header;
78a2bc4321SGilles Gameiro 
79a2bc4321SGilles Gameiro 	ecode = read_eeprom(&header);
80a2bc4321SGilles Gameiro 	if (ecode == 0) {
81a2bc4321SGilles Gameiro 		if (header.version[1] == 'A') {
82a2bc4321SGilles Gameiro 			if (debug)
83a2bc4321SGilles Gameiro 				puts("=== Detected Board model BAV335x Rev.A");
84a2bc4321SGilles Gameiro 			return BAV335A;
85a2bc4321SGilles Gameiro 		} else if (header.version[1] == 'B') {
86a2bc4321SGilles Gameiro 			if (debug)
87a2bc4321SGilles Gameiro 				puts("=== Detected Board model BAV335x Rev.B");
88a2bc4321SGilles Gameiro 			return BAV335B;
89a2bc4321SGilles Gameiro 		} else if (debug) {
90a2bc4321SGilles Gameiro 			puts("### Un-known board model in serial-EE\n");
91a2bc4321SGilles Gameiro 		}
92a2bc4321SGilles Gameiro 	} else if (debug) {
93a2bc4321SGilles Gameiro 		switch (ecode) {
94a2bc4321SGilles Gameiro 		case -ENODEV:
95a2bc4321SGilles Gameiro 			puts("### Board doesn't have a serial-EE\n");
96a2bc4321SGilles Gameiro 			break;
97a2bc4321SGilles Gameiro 		case -EINVAL:
98a2bc4321SGilles Gameiro 			puts("### Board serial-EE signature is incorrect.\n");
99a2bc4321SGilles Gameiro 			break;
100a2bc4321SGilles Gameiro 		default:
101a2bc4321SGilles Gameiro 			puts("### IO Error reading serial-EE.\n");
102a2bc4321SGilles Gameiro 			break;
103a2bc4321SGilles Gameiro 		}
104a2bc4321SGilles Gameiro 	}
105a2bc4321SGilles Gameiro 
106a2bc4321SGilles Gameiro #if (CONFIG_BAV_VERSION == 1)
107a2bc4321SGilles Gameiro 	if (debug)
108a2bc4321SGilles Gameiro 		puts("### Selecting BAV335A as per config\n");
109a2bc4321SGilles Gameiro 	return BAV335A;
110a2bc4321SGilles Gameiro #elif (CONFIG_BAV_VERSION == 2)
111a2bc4321SGilles Gameiro 	if (debug)
112a2bc4321SGilles Gameiro 		puts("### Selecting BAV335B as per config\n");
113a2bc4321SGilles Gameiro 	return BAV335B;
114a2bc4321SGilles Gameiro #endif
115a2bc4321SGilles Gameiro #if (NOT_DEFINED == 2)
116a2bc4321SGilles Gameiro #error "SHOULD NEVER DISPLAY THIS"
117a2bc4321SGilles Gameiro #endif
118a2bc4321SGilles Gameiro 
119a2bc4321SGilles Gameiro 	if (debug)
120a2bc4321SGilles Gameiro 		puts("### Defaulting to model BAV335x Rev.B\n");
121a2bc4321SGilles Gameiro 	return BAV335B;
122a2bc4321SGilles Gameiro }
123a2bc4321SGilles Gameiro 
124a2bc4321SGilles Gameiro 
125a2bc4321SGilles Gameiro 
126a2bc4321SGilles Gameiro #ifndef CONFIG_SKIP_LOWLEVEL_INIT
127a2bc4321SGilles Gameiro static const struct ddr_data ddr3_bav335x_data = {
128a2bc4321SGilles Gameiro 	.datardsratio0 = MT41K256M16HA125E_RD_DQS,
129a2bc4321SGilles Gameiro 	.datawdsratio0 = MT41K256M16HA125E_WR_DQS,
130a2bc4321SGilles Gameiro 	.datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
131a2bc4321SGilles Gameiro 	.datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
132a2bc4321SGilles Gameiro };
133a2bc4321SGilles Gameiro 
134a2bc4321SGilles Gameiro static const struct cmd_control ddr3_bav335x_cmd_ctrl_data = {
135a2bc4321SGilles Gameiro 	.cmd0csratio = MT41K256M16HA125E_RATIO,
136a2bc4321SGilles Gameiro 	.cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
137a2bc4321SGilles Gameiro 	.cmd1csratio = MT41K256M16HA125E_RATIO,
138a2bc4321SGilles Gameiro 	.cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
139a2bc4321SGilles Gameiro 	.cmd2csratio = MT41K256M16HA125E_RATIO,
140a2bc4321SGilles Gameiro 	.cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
141a2bc4321SGilles Gameiro };
142a2bc4321SGilles Gameiro 
143a2bc4321SGilles Gameiro 
144a2bc4321SGilles Gameiro static struct emif_regs ddr3_bav335x_emif_reg_data = {
145a2bc4321SGilles Gameiro 	.sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
146a2bc4321SGilles Gameiro 	.ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
147a2bc4321SGilles Gameiro 	.sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
148a2bc4321SGilles Gameiro 	.sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
149a2bc4321SGilles Gameiro 	.sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
150a2bc4321SGilles Gameiro 	.zq_config = MT41K256M16HA125E_ZQ_CFG,
151a2bc4321SGilles Gameiro 	.emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
152a2bc4321SGilles Gameiro };
153a2bc4321SGilles Gameiro 
154a2bc4321SGilles Gameiro 
155a2bc4321SGilles Gameiro #ifdef CONFIG_SPL_OS_BOOT
spl_start_uboot(void)156a2bc4321SGilles Gameiro int spl_start_uboot(void)
157a2bc4321SGilles Gameiro {
158a2bc4321SGilles Gameiro 	/* break into full u-boot on 'c' */
159a2bc4321SGilles Gameiro 	if (serial_tstc() && serial_getc() == 'c')
160a2bc4321SGilles Gameiro 		return 1;
161a2bc4321SGilles Gameiro 
162a2bc4321SGilles Gameiro #ifdef CONFIG_SPL_ENV_SUPPORT
163a2bc4321SGilles Gameiro 	env_init();
164310fb14bSSimon Glass 	env_load();
165bfebc8c9SSimon Glass 	if (env_get_yesno("boot_os") != 1)
166a2bc4321SGilles Gameiro 		return 1;
167a2bc4321SGilles Gameiro #endif
168a2bc4321SGilles Gameiro 
169a2bc4321SGilles Gameiro 	return 0;
170a2bc4321SGilles Gameiro }
171a2bc4321SGilles Gameiro #endif
172a2bc4321SGilles Gameiro 
173a2bc4321SGilles Gameiro #define OSC	(V_OSCK/1000000)
174a2bc4321SGilles Gameiro const struct dpll_params dpll_ddr = {
175a2bc4321SGilles Gameiro 		266, OSC-1, 1, -1, -1, -1, -1};
176a2bc4321SGilles Gameiro const struct dpll_params dpll_ddr_evm_sk = {
177a2bc4321SGilles Gameiro 		303, OSC-1, 1, -1, -1, -1, -1};
178a2bc4321SGilles Gameiro const struct dpll_params dpll_ddr_bone_black = {
179a2bc4321SGilles Gameiro 		400, OSC-1, 1, -1, -1, -1, -1};
180a2bc4321SGilles Gameiro 
am33xx_spl_board_init(void)181a2bc4321SGilles Gameiro void am33xx_spl_board_init(void)
182a2bc4321SGilles Gameiro {
183a2bc4321SGilles Gameiro 	/* debug print detect status */
184a2bc4321SGilles Gameiro 	(void)get_board_type(true);
185a2bc4321SGilles Gameiro 
186a2bc4321SGilles Gameiro 	/* Get the frequency */
187a2bc4321SGilles Gameiro 	/* dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev); */
188a2bc4321SGilles Gameiro 	dpll_mpu_opp100.m = MPUPLL_M_1000;
189a2bc4321SGilles Gameiro 
190a2bc4321SGilles Gameiro 	if (i2c_probe(TPS65217_CHIP_PM))
191a2bc4321SGilles Gameiro 		return;
192a2bc4321SGilles Gameiro 
193a2bc4321SGilles Gameiro 	/* Set the USB Current Limit */
194a2bc4321SGilles Gameiro 	if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
195a2bc4321SGilles Gameiro 			       TPS65217_USB_INPUT_CUR_LIMIT_1800MA,
196a2bc4321SGilles Gameiro 			       TPS65217_USB_INPUT_CUR_LIMIT_MASK))
197a2bc4321SGilles Gameiro 		puts("! tps65217_reg_write: could not set USB limit\n");
198a2bc4321SGilles Gameiro 
199a2bc4321SGilles Gameiro 	/* Set the Core Voltage (DCDC3) to 1.125V */
200a2bc4321SGilles Gameiro 	if (tps65217_voltage_update(TPS65217_DEFDCDC3,
201a2bc4321SGilles Gameiro 				    TPS65217_DCDC_VOLT_SEL_1125MV)) {
202a2bc4321SGilles Gameiro 		puts("! tps65217_reg_write: could not set Core Voltage\n");
203a2bc4321SGilles Gameiro 		return;
204a2bc4321SGilles Gameiro 	}
205a2bc4321SGilles Gameiro 
206a2bc4321SGilles Gameiro 	/* Set CORE Frequencies to OPP100 */
207a2bc4321SGilles Gameiro 	do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
208a2bc4321SGilles Gameiro 
209a2bc4321SGilles Gameiro 	/* Set the MPU Voltage (DCDC2) */
210a2bc4321SGilles Gameiro 	if (tps65217_voltage_update(TPS65217_DEFDCDC2,
211a2bc4321SGilles Gameiro 				    TPS65217_DCDC_VOLT_SEL_1325MV)) {
212a2bc4321SGilles Gameiro 		puts("! tps65217_reg_write: could not set MPU Voltage\n");
213a2bc4321SGilles Gameiro 		return;
214a2bc4321SGilles Gameiro 	}
215a2bc4321SGilles Gameiro 
216a2bc4321SGilles Gameiro 	/*
217a2bc4321SGilles Gameiro 	 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
218a2bc4321SGilles Gameiro 	 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
219a2bc4321SGilles Gameiro 	 */
220a2bc4321SGilles Gameiro 	if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, TPS65217_DEFLS1,
221a2bc4321SGilles Gameiro 			       TPS65217_LDO_VOLTAGE_OUT_1_8, TPS65217_LDO_MASK))
222a2bc4321SGilles Gameiro 		puts("! tps65217_reg_write: could not set LDO3\n");
223a2bc4321SGilles Gameiro 
224a2bc4321SGilles Gameiro 	if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, TPS65217_DEFLS2,
225a2bc4321SGilles Gameiro 			       TPS65217_LDO_VOLTAGE_OUT_3_3, TPS65217_LDO_MASK))
226a2bc4321SGilles Gameiro 		puts("! tps65217_reg_write: could not set LDO4\n");
227a2bc4321SGilles Gameiro 
228a2bc4321SGilles Gameiro 	/* Set MPU Frequency to what we detected now that voltages are set */
229a2bc4321SGilles Gameiro 	do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
230a2bc4321SGilles Gameiro }
231a2bc4321SGilles Gameiro 
get_dpll_ddr_params(void)232a2bc4321SGilles Gameiro const struct dpll_params *get_dpll_ddr_params(void)
233a2bc4321SGilles Gameiro {
234a2bc4321SGilles Gameiro 	enable_i2c0_pin_mux();
235a2bc4321SGilles Gameiro 	i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
236a2bc4321SGilles Gameiro 
237a2bc4321SGilles Gameiro 	return &dpll_ddr_bone_black;
238a2bc4321SGilles Gameiro }
239a2bc4321SGilles Gameiro 
set_uart_mux_conf(void)240a2bc4321SGilles Gameiro void set_uart_mux_conf(void)
241a2bc4321SGilles Gameiro {
242a2bc4321SGilles Gameiro #if CONFIG_CONS_INDEX == 1
243a2bc4321SGilles Gameiro 	enable_uart0_pin_mux();
244a2bc4321SGilles Gameiro #elif CONFIG_CONS_INDEX == 2
245a2bc4321SGilles Gameiro 	enable_uart1_pin_mux();
246a2bc4321SGilles Gameiro #elif CONFIG_CONS_INDEX == 3
247a2bc4321SGilles Gameiro 	enable_uart2_pin_mux();
248a2bc4321SGilles Gameiro #elif CONFIG_CONS_INDEX == 4
249a2bc4321SGilles Gameiro 	enable_uart3_pin_mux();
250a2bc4321SGilles Gameiro #elif CONFIG_CONS_INDEX == 5
251a2bc4321SGilles Gameiro 	enable_uart4_pin_mux();
252a2bc4321SGilles Gameiro #elif CONFIG_CONS_INDEX == 6
253a2bc4321SGilles Gameiro 	enable_uart5_pin_mux();
254a2bc4321SGilles Gameiro #endif
255a2bc4321SGilles Gameiro }
256a2bc4321SGilles Gameiro 
set_mux_conf_regs(void)257a2bc4321SGilles Gameiro void set_mux_conf_regs(void)
258a2bc4321SGilles Gameiro {
259a2bc4321SGilles Gameiro 	enum board_type board;
260a2bc4321SGilles Gameiro 
261a2bc4321SGilles Gameiro 	board = get_board_type(false);
262a2bc4321SGilles Gameiro 	enable_board_pin_mux(board);
263a2bc4321SGilles Gameiro }
264a2bc4321SGilles Gameiro 
265a2bc4321SGilles Gameiro const struct ctrl_ioregs ioregs_bonelt = {
266a2bc4321SGilles Gameiro 	.cm0ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
267a2bc4321SGilles Gameiro 	.cm1ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
268a2bc4321SGilles Gameiro 	.cm2ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
269a2bc4321SGilles Gameiro 	.dt0ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
270a2bc4321SGilles Gameiro 	.dt1ioctl		= MT41K256M16HA125E_IOCTRL_VALUE,
271a2bc4321SGilles Gameiro };
272a2bc4321SGilles Gameiro 
273a2bc4321SGilles Gameiro 
sdram_init(void)274a2bc4321SGilles Gameiro void sdram_init(void)
275a2bc4321SGilles Gameiro {
276a2bc4321SGilles Gameiro 	config_ddr(400, &ioregs_bonelt,
277a2bc4321SGilles Gameiro 		   &ddr3_bav335x_data,
278a2bc4321SGilles Gameiro 		   &ddr3_bav335x_cmd_ctrl_data,
279a2bc4321SGilles Gameiro 		   &ddr3_bav335x_emif_reg_data, 0);
280a2bc4321SGilles Gameiro }
281a2bc4321SGilles Gameiro #endif
282a2bc4321SGilles Gameiro 
283a2bc4321SGilles Gameiro /*
284a2bc4321SGilles Gameiro  * Basic board specific setup.  Pinmux has been handled already.
285a2bc4321SGilles Gameiro  */
board_init(void)286a2bc4321SGilles Gameiro int board_init(void)
287a2bc4321SGilles Gameiro {
288a2bc4321SGilles Gameiro #if defined(CONFIG_HW_WATCHDOG)
289a2bc4321SGilles Gameiro 	hw_watchdog_init();
290a2bc4321SGilles Gameiro #endif
291a2bc4321SGilles Gameiro 
292a2bc4321SGilles Gameiro 	gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
293a2bc4321SGilles Gameiro #if defined(CONFIG_NOR) || defined(CONFIG_NAND)
294a2bc4321SGilles Gameiro 	gpmc_init();
295a2bc4321SGilles Gameiro #endif
296a2bc4321SGilles Gameiro 	return 0;
297a2bc4321SGilles Gameiro }
298a2bc4321SGilles Gameiro 
299a2bc4321SGilles Gameiro #ifdef CONFIG_BOARD_LATE_INIT
board_late_init(void)300a2bc4321SGilles Gameiro int board_late_init(void)
301a2bc4321SGilles Gameiro {
302a2bc4321SGilles Gameiro #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
303382bee57SSimon Glass 	env_set("board_name", "BAV335xB");
304382bee57SSimon Glass 	env_set("board_rev", "B"); /* Fix me, but why bother.. */
305a2bc4321SGilles Gameiro #endif
306a2bc4321SGilles Gameiro 	return 0;
307a2bc4321SGilles Gameiro }
308a2bc4321SGilles Gameiro #endif
309a2bc4321SGilles Gameiro 
310a2bc4321SGilles Gameiro 
311a2bc4321SGilles Gameiro #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
312a2bc4321SGilles Gameiro 	(defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
cpsw_control(int enabled)313a2bc4321SGilles Gameiro static void cpsw_control(int enabled)
314a2bc4321SGilles Gameiro {
315a2bc4321SGilles Gameiro 	/* VTP can be added here */
316a2bc4321SGilles Gameiro 	return;
317a2bc4321SGilles Gameiro }
318a2bc4321SGilles Gameiro 
319a2bc4321SGilles Gameiro static struct cpsw_slave_data cpsw_slaves[] = {
320a2bc4321SGilles Gameiro 	{
321a2bc4321SGilles Gameiro 		.slave_reg_ofs	= 0x208,
322a2bc4321SGilles Gameiro 		.sliver_reg_ofs	= 0xd80,
323a2bc4321SGilles Gameiro 		.phy_addr	= 0,
324a2bc4321SGilles Gameiro 	},
325a2bc4321SGilles Gameiro 	{
326a2bc4321SGilles Gameiro 		.slave_reg_ofs	= 0x308,
327a2bc4321SGilles Gameiro 		.sliver_reg_ofs	= 0xdc0,
328a2bc4321SGilles Gameiro 		.phy_addr	= 1,
329a2bc4321SGilles Gameiro 	},
330a2bc4321SGilles Gameiro };
331a2bc4321SGilles Gameiro 
332a2bc4321SGilles Gameiro static struct cpsw_platform_data cpsw_data = {
333a2bc4321SGilles Gameiro 	.mdio_base		= CPSW_MDIO_BASE,
334a2bc4321SGilles Gameiro 	.cpsw_base		= CPSW_BASE,
335a2bc4321SGilles Gameiro 	.mdio_div		= 0xff,
336a2bc4321SGilles Gameiro 	.channels		= 8,
337a2bc4321SGilles Gameiro 	.cpdma_reg_ofs	= 0x800,
338a2bc4321SGilles Gameiro 	.slaves			= 1,
339a2bc4321SGilles Gameiro 	.slave_data		= cpsw_slaves,
340a2bc4321SGilles Gameiro 	.ale_reg_ofs	= 0xd00,
341a2bc4321SGilles Gameiro 	.ale_entries	= 1024,
342a2bc4321SGilles Gameiro 	.host_port_reg_ofs	= 0x108,
343a2bc4321SGilles Gameiro 	.hw_stats_reg_ofs	= 0x900,
344a2bc4321SGilles Gameiro 	.bd_ram_ofs		= 0x2000,
345a2bc4321SGilles Gameiro 	.mac_control	= (1 << 5),
346a2bc4321SGilles Gameiro 	.control		= cpsw_control,
347a2bc4321SGilles Gameiro 	.host_port_num	= 0,
348a2bc4321SGilles Gameiro 	.version		= CPSW_CTRL_VERSION_2,
349a2bc4321SGilles Gameiro };
350a2bc4321SGilles Gameiro #endif
351a2bc4321SGilles Gameiro 
352a2bc4321SGilles Gameiro 
353a2bc4321SGilles Gameiro /*
354a2bc4321SGilles Gameiro  * This function will:
355a2bc4321SGilles Gameiro  * Perform fixups to the PHY present on certain boards.  We only need this
356a2bc4321SGilles Gameiro  * function in:
357a2bc4321SGilles Gameiro  * - SPL with either CPSW or USB ethernet support
358a2bc4321SGilles Gameiro  * - Full U-Boot, with either CPSW or USB ethernet
359a2bc4321SGilles Gameiro  * Build in only these cases to avoid warnings about unused variables
360a2bc4321SGilles Gameiro  * when we build an SPL that has neither option but full U-Boot will.
361a2bc4321SGilles Gameiro  */
362b432b1ebSFaiz Abbas #if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USB_ETHER)) &&\
363a2bc4321SGilles Gameiro 		defined(CONFIG_SPL_BUILD)) || \
364a2bc4321SGilles Gameiro 	((defined(CONFIG_DRIVER_TI_CPSW) || \
36595de1e2fSPaul Kocialkowski 	  defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) && \
366a2bc4321SGilles Gameiro 	 !defined(CONFIG_SPL_BUILD))
board_eth_init(bd_t * bis)367a2bc4321SGilles Gameiro int board_eth_init(bd_t *bis)
368a2bc4321SGilles Gameiro {
369a2bc4321SGilles Gameiro 	int ecode, rv, n;
370a2bc4321SGilles Gameiro 	uint8_t mac_addr[6];
371a2bc4321SGilles Gameiro 	struct board_eeconfig header;
372a2bc4321SGilles Gameiro 	__maybe_unused enum board_type board;
373a2bc4321SGilles Gameiro 
374a2bc4321SGilles Gameiro 	/* Default manufacturing address; used when no EE or invalid */
375a2bc4321SGilles Gameiro 	n = 0;
376a2bc4321SGilles Gameiro 	mac_addr[0] = 0;
377a2bc4321SGilles Gameiro 	mac_addr[1] = 0x20;
378a2bc4321SGilles Gameiro 	mac_addr[2] = 0x18;
379a2bc4321SGilles Gameiro 	mac_addr[3] = 0x1C;
380a2bc4321SGilles Gameiro 	mac_addr[4] = 0x00;
381a2bc4321SGilles Gameiro 	mac_addr[5] = 0x01;
382a2bc4321SGilles Gameiro 
383a2bc4321SGilles Gameiro 	ecode = read_eeprom(&header);
384a2bc4321SGilles Gameiro 	/* if we have a valid EE, get mac address from there */
385a2bc4321SGilles Gameiro 	if ((ecode == 0) &&
3860adb5b76SJoe Hershberger 	    is_valid_ethaddr((const u8 *)&header.mac_addr[0][0])) {
387a2bc4321SGilles Gameiro 		memcpy(mac_addr, (const void *)&header.mac_addr[0][0], 6);
388a2bc4321SGilles Gameiro 	}
389a2bc4321SGilles Gameiro 
390a2bc4321SGilles Gameiro 
391a2bc4321SGilles Gameiro #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
392a2bc4321SGilles Gameiro 	(defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
393a2bc4321SGilles Gameiro 
39400caae6dSSimon Glass 	if (!env_get("ethaddr")) {
395a2bc4321SGilles Gameiro 		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
396a2bc4321SGilles Gameiro 
3970adb5b76SJoe Hershberger 		if (is_valid_ethaddr(mac_addr))
398fd1e959eSSimon Glass 			eth_env_set_enetaddr("ethaddr", mac_addr);
399a2bc4321SGilles Gameiro 	}
400a2bc4321SGilles Gameiro 
401a2bc4321SGilles Gameiro #ifdef CONFIG_DRIVER_TI_CPSW
402a2bc4321SGilles Gameiro 
403a2bc4321SGilles Gameiro 	board = get_board_type(false);
404a2bc4321SGilles Gameiro 
405a2bc4321SGilles Gameiro 	/* Rev.A uses 10/100 PHY in mii mode */
406a2bc4321SGilles Gameiro 	if (board == BAV335A) {
407a2bc4321SGilles Gameiro 		writel(MII_MODE_ENABLE, &cdev->miisel);
408a2bc4321SGilles Gameiro 		cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII;
409a2bc4321SGilles Gameiro 		cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_MII;
410a2bc4321SGilles Gameiro 	}
411a2bc4321SGilles Gameiro 	/* Rev.B (default) uses GB PHY in rmii mode */
412a2bc4321SGilles Gameiro 	else {
413a2bc4321SGilles Gameiro 		writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
414a2bc4321SGilles Gameiro 		cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if
415a2bc4321SGilles Gameiro 				= PHY_INTERFACE_MODE_RGMII;
416a2bc4321SGilles Gameiro 	}
417a2bc4321SGilles Gameiro 
418a2bc4321SGilles Gameiro 	rv = cpsw_register(&cpsw_data);
419a2bc4321SGilles Gameiro 	if (rv < 0)
420a2bc4321SGilles Gameiro 		printf("Error %d registering CPSW switch\n", rv);
421a2bc4321SGilles Gameiro 	else
422a2bc4321SGilles Gameiro 		n += rv;
423a2bc4321SGilles Gameiro #endif
424a2bc4321SGilles Gameiro 
425a2bc4321SGilles Gameiro #endif
426a2bc4321SGilles Gameiro 
427a2bc4321SGilles Gameiro 	return n;
428a2bc4321SGilles Gameiro }
429a2bc4321SGilles Gameiro #endif
430