1 // SPDX-License-Identifier: GPL-2.0+
5 * Board functions for TI AM335X based boards
7 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
19 #include <asm/arch/cpu.h>
20 #include <asm/arch/hardware.h>
21 #include <asm/arch/omap.h>
22 #include <asm/arch/ddr_defs.h>
23 #include <asm/arch/clock.h>
24 #include <asm/arch/clk_synthesizer.h>
25 #include <asm/arch/gpio.h>
26 #include <asm/arch/mmc_host_def.h>
27 #include <asm/arch/sys_proto.h>
28 #include <asm/arch/mem.h>
32 #include <asm/omap_common.h>
33 #include <asm/omap_sec_common.h>
34 #include <asm/omap_mmc.h>
38 #include <power/tps65217.h>
39 #include <power/tps65910.h>
40 #include <env_internal.h>
42 #include "../common/board_detect.h"
45 DECLARE_GLOBAL_DATA_PTR;
47 /* GPIO that controls power to DDR on EVM-SK */
48 #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
49 #define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
50 #define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
51 #define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
52 #define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
53 #define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
54 #define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
55 #define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
56 #define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
58 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
60 #define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
61 #define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
63 #define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
64 #define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
66 #define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
67 #define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
70 * Read header information from EEPROM into global structure.
72 #ifdef CONFIG_TI_I2C_BOARD_DETECT
73 void do_board_detect(void)
75 enable_i2c0_pin_mux();
77 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
79 if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
80 CONFIG_EEPROM_CHIP_ADDRESS))
81 printf("ti_i2c_eeprom_init failed\n");
85 #ifndef CONFIG_DM_SERIAL
86 struct serial_device *default_serial_console(void)
89 return &eserial4_device;
91 return &eserial1_device;
95 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
96 static const struct ddr_data ddr2_data = {
97 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
98 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
99 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
102 static const struct cmd_control ddr2_cmd_ctrl_data = {
103 .cmd0csratio = MT47H128M16RT25E_RATIO,
105 .cmd1csratio = MT47H128M16RT25E_RATIO,
107 .cmd2csratio = MT47H128M16RT25E_RATIO,
110 static const struct emif_regs ddr2_emif_reg_data = {
111 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
112 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
113 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
114 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
115 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
116 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
119 static const struct emif_regs ddr2_evm_emif_reg_data = {
120 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
121 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
122 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
123 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
124 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
125 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
126 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
129 static const struct ddr_data ddr3_data = {
130 .datardsratio0 = MT41J128MJT125_RD_DQS,
131 .datawdsratio0 = MT41J128MJT125_WR_DQS,
132 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
133 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
136 static const struct ddr_data ddr3_beagleblack_data = {
137 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
138 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
139 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
140 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
143 static const struct ddr_data ddr3_evm_data = {
144 .datardsratio0 = MT41J512M8RH125_RD_DQS,
145 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
146 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
147 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
150 static const struct ddr_data ddr3_icev2_data = {
151 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
152 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
153 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
154 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
157 static const struct cmd_control ddr3_cmd_ctrl_data = {
158 .cmd0csratio = MT41J128MJT125_RATIO,
159 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
161 .cmd1csratio = MT41J128MJT125_RATIO,
162 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
164 .cmd2csratio = MT41J128MJT125_RATIO,
165 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
168 static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
169 .cmd0csratio = MT41K256M16HA125E_RATIO,
170 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
172 .cmd1csratio = MT41K256M16HA125E_RATIO,
173 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
175 .cmd2csratio = MT41K256M16HA125E_RATIO,
176 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
179 static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
180 .cmd0csratio = MT41J512M8RH125_RATIO,
181 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
183 .cmd1csratio = MT41J512M8RH125_RATIO,
184 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
186 .cmd2csratio = MT41J512M8RH125_RATIO,
187 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
190 static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
191 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
192 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
194 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
195 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
197 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
198 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
201 static struct emif_regs ddr3_emif_reg_data = {
202 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
203 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
204 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
205 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
206 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
207 .zq_config = MT41J128MJT125_ZQ_CFG,
208 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
212 static struct emif_regs ddr3_beagleblack_emif_reg_data = {
213 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
214 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
215 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
216 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
217 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
218 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
219 .zq_config = MT41K256M16HA125E_ZQ_CFG,
220 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
223 static struct emif_regs ddr3_evm_emif_reg_data = {
224 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
225 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
226 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
227 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
228 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
229 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
230 .zq_config = MT41J512M8RH125_ZQ_CFG,
231 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
235 static struct emif_regs ddr3_icev2_emif_reg_data = {
236 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
237 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
238 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
239 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
240 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
241 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
242 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
246 #ifdef CONFIG_SPL_OS_BOOT
247 int spl_start_uboot(void)
249 #ifdef CONFIG_SPL_SERIAL_SUPPORT
250 /* break into full u-boot on 'c' */
251 if (serial_tstc() && serial_getc() == 'c')
255 #ifdef CONFIG_SPL_ENV_SUPPORT
258 if (env_get_yesno("boot_os") != 1)
266 const struct dpll_params *get_dpll_ddr_params(void)
268 int ind = get_sys_clk_index();
270 if (board_is_evm_sk())
271 return &dpll_ddr3_303MHz[ind];
272 else if (board_is_pb() || board_is_bone_lt() || board_is_icev2())
273 return &dpll_ddr3_400MHz[ind];
274 else if (board_is_evm_15_or_later())
275 return &dpll_ddr3_303MHz[ind];
277 return &dpll_ddr2_266MHz[ind];
280 static u8 bone_not_connected_to_ac_power(void)
282 if (board_is_bone()) {
283 uchar pmic_status_reg;
284 if (tps65217_reg_read(TPS65217_STATUS,
287 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
288 puts("No AC power, switching to default OPP\n");
295 const struct dpll_params *get_dpll_mpu_params(void)
297 int ind = get_sys_clk_index();
298 int freq = am335x_get_efuse_mpu_max_freq(cdev);
300 if (bone_not_connected_to_ac_power())
303 if (board_is_pb() || board_is_bone_lt())
304 freq = MPUPLL_M_1000;
308 return &dpll_mpu_opp[ind][5];
310 return &dpll_mpu_opp[ind][4];
312 return &dpll_mpu_opp[ind][3];
314 return &dpll_mpu_opp[ind][2];
316 return &dpll_mpu_opp100;
318 return &dpll_mpu_opp[ind][0];
321 return &dpll_mpu_opp[ind][0];
324 static void scale_vcores_bone(int freq)
326 int usb_cur_lim, mpu_vdd;
329 * Only perform PMIC configurations if board rev > A1
330 * on Beaglebone White
332 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
335 #ifndef CONFIG_DM_I2C
336 if (i2c_probe(TPS65217_CHIP_PM))
339 if (power_tps65217_init(0))
345 * On Beaglebone White we need to ensure we have AC power
346 * before increasing the frequency.
348 if (bone_not_connected_to_ac_power())
352 * Override what we have detected since we know if we have
353 * a Beaglebone Black it supports 1GHz.
355 if (board_is_pb() || board_is_bone_lt())
356 freq = MPUPLL_M_1000;
360 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
361 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
364 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
365 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
368 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
369 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
375 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
376 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
380 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
383 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
384 puts("tps65217_reg_write failure\n");
386 /* Set DCDC3 (CORE) voltage to 1.10V */
387 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
388 TPS65217_DCDC_VOLT_SEL_1100MV)) {
389 puts("tps65217_voltage_update failure\n");
393 /* Set DCDC2 (MPU) voltage */
394 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
395 puts("tps65217_voltage_update failure\n");
400 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
401 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
403 if (board_is_bone()) {
404 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
406 TPS65217_LDO_VOLTAGE_OUT_3_3,
408 puts("tps65217_reg_write failure\n");
410 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
412 TPS65217_LDO_VOLTAGE_OUT_1_8,
414 puts("tps65217_reg_write failure\n");
417 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
419 TPS65217_LDO_VOLTAGE_OUT_3_3,
421 puts("tps65217_reg_write failure\n");
424 void scale_vcores_generic(int freq)
426 int sil_rev, mpu_vdd;
429 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
430 * MPU frequencies we support we use a CORE voltage of
431 * 1.10V. For MPU voltage we need to switch based on
432 * the frequency we are running at.
434 #ifndef CONFIG_DM_I2C
435 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
438 if (power_tps65910_init(0))
442 * Depending on MPU clock and PG we will need a different
443 * VDD to drive at that speed.
445 sil_rev = readl(&cdev->deviceid) >> 28;
446 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
448 /* Tell the TPS65910 to use i2c */
449 tps65910_set_i2c_control();
451 /* First update MPU voltage. */
452 if (tps65910_voltage_update(MPU, mpu_vdd))
455 /* Second, update the CORE voltage. */
456 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
461 void gpi2c_init(void)
463 /* When needed to be invoked prior to BSS initialization */
464 static bool first_time = true;
467 enable_i2c0_pin_mux();
468 #ifndef CONFIG_DM_I2C
469 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
470 CONFIG_SYS_OMAP24_I2C_SLAVE);
476 void scale_vcores(void)
481 freq = am335x_get_efuse_mpu_max_freq(cdev);
483 if (board_is_beaglebonex())
484 scale_vcores_bone(freq);
486 scale_vcores_generic(freq);
489 void set_uart_mux_conf(void)
491 #if CONFIG_CONS_INDEX == 1
492 enable_uart0_pin_mux();
493 #elif CONFIG_CONS_INDEX == 2
494 enable_uart1_pin_mux();
495 #elif CONFIG_CONS_INDEX == 3
496 enable_uart2_pin_mux();
497 #elif CONFIG_CONS_INDEX == 4
498 enable_uart3_pin_mux();
499 #elif CONFIG_CONS_INDEX == 5
500 enable_uart4_pin_mux();
501 #elif CONFIG_CONS_INDEX == 6
502 enable_uart5_pin_mux();
506 void set_mux_conf_regs(void)
508 enable_board_pin_mux();
511 const struct ctrl_ioregs ioregs_evmsk = {
512 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
513 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
514 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
515 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
516 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
519 const struct ctrl_ioregs ioregs_bonelt = {
520 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
521 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
522 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
523 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
524 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
527 const struct ctrl_ioregs ioregs_evm15 = {
528 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
529 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
530 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
531 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
532 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
535 const struct ctrl_ioregs ioregs = {
536 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
537 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
538 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
539 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
540 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
543 void sdram_init(void)
545 if (board_is_evm_sk()) {
547 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
548 * This is safe enough to do on older revs.
550 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
551 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
554 if (board_is_icev2()) {
555 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
556 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
559 if (board_is_evm_sk())
560 config_ddr(303, &ioregs_evmsk, &ddr3_data,
561 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
562 else if (board_is_pb() || board_is_bone_lt())
563 config_ddr(400, &ioregs_bonelt,
564 &ddr3_beagleblack_data,
565 &ddr3_beagleblack_cmd_ctrl_data,
566 &ddr3_beagleblack_emif_reg_data, 0);
567 else if (board_is_evm_15_or_later())
568 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
569 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
570 else if (board_is_icev2())
571 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
572 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
574 else if (board_is_gp_evm())
575 config_ddr(266, &ioregs, &ddr2_data,
576 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
578 config_ddr(266, &ioregs, &ddr2_data,
579 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
583 #if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
584 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
585 static void request_and_set_gpio(int gpio, char *name, int val)
589 ret = gpio_request(gpio, name);
591 printf("%s: Unable to request %s\n", __func__, name);
595 ret = gpio_direction_output(gpio, 0);
597 printf("%s: Unable to set %s as output\n", __func__, name);
601 gpio_set_value(gpio, val);
609 #define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
610 #define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
613 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
614 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
615 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
616 * give 50MHz output for Eth0 and 1.
618 static struct clk_synth cdce913_data = {
627 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_CONTROL) && \
628 defined(CONFIG_DM_ETH) && defined(CONFIG_DRIVER_TI_CPSW)
630 #define MAX_CPSW_SLAVES 2
632 /* At the moment, we do not want to stop booting for any failures here */
633 int ft_board_setup(void *fdt, bd_t *bd)
635 const char *slave_path, *enet_name;
636 int enetnode, slavenode, phynode;
637 struct udevice *ethdev;
643 /* phy address fixup needed only on beagle bone family */
644 if (!board_is_beaglebonex())
647 for (i = 0; i < MAX_CPSW_SLAVES; i++) {
648 sprintf(alias, "ethernet%d", i);
650 slave_path = fdt_get_alias(fdt, alias);
654 slavenode = fdt_path_offset(fdt, slave_path);
658 enetnode = fdt_parent_offset(fdt, slavenode);
659 enet_name = fdt_get_name(fdt, enetnode, NULL);
661 ethdev = eth_get_dev_by_name(enet_name);
665 phy_addr = cpsw_get_slave_phy_addr(ethdev, i);
667 /* check for phy_id as well as phy-handle properties */
668 ret = fdtdec_get_int_array_count(fdt, slavenode, "phy_id",
671 if (phy_id[1] != phy_addr) {
672 printf("fixing up phy_id for %s, old: %d, new: %d\n",
673 alias, phy_id[1], phy_addr);
675 phy_id[0] = cpu_to_fdt32(phy_id[0]);
676 phy_id[1] = cpu_to_fdt32(phy_addr);
677 do_fixup_by_path(fdt, slave_path, "phy_id",
678 phy_id, sizeof(phy_id), 0);
681 phynode = fdtdec_lookup_phandle(fdt, slavenode,
686 ret = fdtdec_get_int(fdt, phynode, "reg", -ENOENT);
690 if (ret != phy_addr) {
691 printf("fixing up phy-handle for %s, old: %d, new: %d\n",
692 alias, ret, phy_addr);
694 fdt_setprop_u32(fdt, phynode, "reg",
695 cpu_to_fdt32(phy_addr));
706 * Basic board specific setup. Pinmux has been handled already.
710 #if defined(CONFIG_HW_WATCHDOG)
714 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
715 #if defined(CONFIG_NOR) || defined(CONFIG_MTD_RAW_NAND)
719 #if defined(CONFIG_CLOCK_SYNTHESIZER) && (!defined(CONFIG_SPL_BUILD) || \
720 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)))
721 if (board_is_icev2()) {
725 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
726 /* Make J19 status available on GPIO1_26 */
727 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
729 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
731 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
732 * jumpers near the port. Read the jumper value and set
733 * the pinmux, external mux and PHY clock accordingly.
734 * As jumper line is overridden by PHY RX_DV pin immediately
735 * after bootstrap (power-up/reset), we need to sample
736 * it during PHY reset using GPIO rising edge detection.
738 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
739 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
740 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
741 writel(reg, GPIO0_RISINGDETECT);
742 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
743 writel(reg, GPIO1_RISINGDETECT);
744 /* Reset PHYs to capture the Jumper setting */
745 gpio_set_value(GPIO_PHY_RESET, 0);
746 udelay(2); /* PHY datasheet states 1uS min. */
747 gpio_set_value(GPIO_PHY_RESET, 1);
749 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
751 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
753 printf("ETH0, CPSW\n");
756 printf("ETH0, PRU\n");
757 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
760 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
762 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
764 printf("ETH1, CPSW\n");
765 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
768 printf("ETH1, PRU\n");
769 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
772 /* disable rising edge IRQs */
773 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
774 writel(reg, GPIO0_RISINGDETECT);
775 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
776 writel(reg, GPIO1_RISINGDETECT);
778 rv = setup_clock_synthesizer(&cdce913_data);
780 printf("Clock synthesizer setup failed %d\n", rv);
785 gpio_set_value(GPIO_PHY_RESET, 0);
786 udelay(2); /* PHY datasheet states 1uS min. */
787 gpio_set_value(GPIO_PHY_RESET, 1);
794 #ifdef CONFIG_BOARD_LATE_INIT
795 int board_late_init(void)
798 #if !defined(CONFIG_SPL_BUILD)
800 uint32_t mac_hi, mac_lo;
803 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
806 if (board_is_bone_lt()) {
807 /* BeagleBoard.org BeagleBone Black Wireless: */
808 if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
811 /* SeeedStudio BeagleBone Green Wireless */
812 if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
815 /* BeagleBoard.org BeagleBone Blue */
816 if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
825 set_board_info_env(name);
828 * Default FIT boot on HS devices. Non FIT images are not allowed
831 if (get_device_type() == HS_DEVICE)
832 env_set("boot_fit", "1");
835 #if !defined(CONFIG_SPL_BUILD)
836 /* try reading mac address from efuse */
837 mac_lo = readl(&cdev->macid0l);
838 mac_hi = readl(&cdev->macid0h);
839 mac_addr[0] = mac_hi & 0xFF;
840 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
841 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
842 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
843 mac_addr[4] = mac_lo & 0xFF;
844 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
846 if (!env_get("ethaddr")) {
847 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
849 if (is_valid_ethaddr(mac_addr))
850 eth_env_set_enetaddr("ethaddr", mac_addr);
853 mac_lo = readl(&cdev->macid1l);
854 mac_hi = readl(&cdev->macid1h);
855 mac_addr[0] = mac_hi & 0xFF;
856 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
857 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
858 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
859 mac_addr[4] = mac_lo & 0xFF;
860 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
862 if (!env_get("eth1addr")) {
863 if (is_valid_ethaddr(mac_addr))
864 eth_env_set_enetaddr("eth1addr", mac_addr);
868 if (!env_get("serial#")) {
869 char *board_serial = env_get("board_serial");
870 char *ethaddr = env_get("ethaddr");
872 if (!board_serial || !strncmp(board_serial, "unknown", 7))
873 env_set("serial#", ethaddr);
875 env_set("serial#", board_serial);
878 /* Just probe the potentially supported cdce913 device */
879 uclass_get_device(UCLASS_CLK, 0, &dev);
886 #if !CONFIG_IS_ENABLED(OF_CONTROL)
887 struct cpsw_slave_data slave_data[] = {
889 .slave_reg_ofs = CPSW_SLAVE0_OFFSET,
890 .sliver_reg_ofs = CPSW_SLIVER0_OFFSET,
894 .slave_reg_ofs = CPSW_SLAVE1_OFFSET,
895 .sliver_reg_ofs = CPSW_SLIVER1_OFFSET,
900 struct cpsw_platform_data am335_eth_data = {
901 .cpsw_base = CPSW_BASE,
902 .version = CPSW_CTRL_VERSION_2,
903 .bd_ram_ofs = CPSW_BD_OFFSET,
904 .ale_reg_ofs = CPSW_ALE_OFFSET,
905 .cpdma_reg_ofs = CPSW_CPDMA_OFFSET,
906 .mdio_div = CPSW_MDIO_DIV,
907 .host_port_reg_ofs = CPSW_HOST_PORT_OFFSET,
910 .slave_data = slave_data,
912 .bd_ram_ofs = 0x2000,
915 .mdio_base = 0x4a101000,
916 .gmii_sel = 0x44e10650,
917 .phy_sel_compat = "ti,am3352-cpsw-phy-sel",
918 .syscon_addr = 0x44e10630,
919 .macid_sel_compat = "cpsw,am33xx",
922 struct eth_pdata cpsw_pdata = {
923 .iobase = 0x4a100000,
925 .priv_pdata = &am335_eth_data,
928 U_BOOT_DEVICE(am335x_eth) = {
930 .platdata = &cpsw_pdata,
934 #ifdef CONFIG_SPL_LOAD_FIT
935 int board_fit_config_name_match(const char *name)
937 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
939 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
941 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
943 else if (board_is_pb() && !strcmp(name, "am335x-pocketbeagle"))
945 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
947 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
949 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
956 #ifdef CONFIG_TI_SECURE_DEVICE
957 void board_fit_image_post_process(void **p_image, size_t *p_size)
959 secure_boot_verify_image(p_image, p_size);
963 #if !CONFIG_IS_ENABLED(OF_CONTROL)
964 static const struct omap_hsmmc_plat am335x_mmc0_platdata = {
965 .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
966 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
968 .cfg.f_max = 52000000,
969 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
970 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
973 U_BOOT_DEVICE(am335x_mmc0) = {
974 .name = "omap_hsmmc",
975 .platdata = &am335x_mmc0_platdata,
978 static const struct omap_hsmmc_plat am335x_mmc1_platdata = {
979 .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
980 .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
982 .cfg.f_max = 52000000,
983 .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
984 .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
987 U_BOOT_DEVICE(am335x_mmc1) = {
988 .name = "omap_hsmmc",
989 .platdata = &am335x_mmc1_platdata,