4 * Board functions for TI AM335X based boards
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
8 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm/arch/cpu.h>
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/omap.h>
18 #include <asm/arch/ddr_defs.h>
19 #include <asm/arch/clock.h>
20 #include <asm/arch/clk_synthesizer.h>
21 #include <asm/arch/gpio.h>
22 #include <asm/arch/mmc_host_def.h>
23 #include <asm/arch/sys_proto.h>
24 #include <asm/arch/mem.h>
28 #include <asm/omap_sec_common.h>
32 #include <power/tps65217.h>
33 #include <power/tps65910.h>
34 #include <environment.h>
36 #include <environment.h>
37 #include "../common/board_detect.h"
40 DECLARE_GLOBAL_DATA_PTR;
42 /* GPIO that controls power to DDR on EVM-SK */
43 #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
44 #define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
45 #define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
46 #define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
47 #define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
48 #define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
49 #define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
50 #define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
51 #define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
53 #if defined(CONFIG_SPL_BUILD) || \
54 (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
55 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
58 #define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
59 #define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
61 #define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
62 #define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
64 #define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
65 #define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
68 * Read header information from EEPROM into global structure.
70 static inline int __maybe_unused read_eeprom(void)
72 return ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR);
75 #ifndef CONFIG_DM_SERIAL
76 struct serial_device *default_serial_console(void)
79 return &eserial4_device;
81 return &eserial1_device;
85 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
86 static const struct ddr_data ddr2_data = {
87 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
88 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
89 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
92 static const struct cmd_control ddr2_cmd_ctrl_data = {
93 .cmd0csratio = MT47H128M16RT25E_RATIO,
95 .cmd1csratio = MT47H128M16RT25E_RATIO,
97 .cmd2csratio = MT47H128M16RT25E_RATIO,
100 static const struct emif_regs ddr2_emif_reg_data = {
101 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
102 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
103 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
104 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
105 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
106 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
109 static const struct ddr_data ddr3_data = {
110 .datardsratio0 = MT41J128MJT125_RD_DQS,
111 .datawdsratio0 = MT41J128MJT125_WR_DQS,
112 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
113 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
116 static const struct ddr_data ddr3_beagleblack_data = {
117 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
118 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
119 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
120 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
123 static const struct ddr_data ddr3_evm_data = {
124 .datardsratio0 = MT41J512M8RH125_RD_DQS,
125 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
126 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
127 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
130 static const struct ddr_data ddr3_icev2_data = {
131 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
132 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
133 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
134 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
137 static const struct cmd_control ddr3_cmd_ctrl_data = {
138 .cmd0csratio = MT41J128MJT125_RATIO,
139 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
141 .cmd1csratio = MT41J128MJT125_RATIO,
142 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
144 .cmd2csratio = MT41J128MJT125_RATIO,
145 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
148 static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
149 .cmd0csratio = MT41K256M16HA125E_RATIO,
150 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
152 .cmd1csratio = MT41K256M16HA125E_RATIO,
153 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
155 .cmd2csratio = MT41K256M16HA125E_RATIO,
156 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
159 static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
160 .cmd0csratio = MT41J512M8RH125_RATIO,
161 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
163 .cmd1csratio = MT41J512M8RH125_RATIO,
164 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
166 .cmd2csratio = MT41J512M8RH125_RATIO,
167 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
170 static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
171 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
172 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
174 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
175 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
177 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
178 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
181 static struct emif_regs ddr3_emif_reg_data = {
182 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
183 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
184 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
185 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
186 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
187 .zq_config = MT41J128MJT125_ZQ_CFG,
188 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
192 static struct emif_regs ddr3_beagleblack_emif_reg_data = {
193 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
194 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
195 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
196 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
197 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
198 .zq_config = MT41K256M16HA125E_ZQ_CFG,
199 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
202 static struct emif_regs ddr3_evm_emif_reg_data = {
203 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
204 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
205 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
206 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
207 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
208 .zq_config = MT41J512M8RH125_ZQ_CFG,
209 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
213 static struct emif_regs ddr3_icev2_emif_reg_data = {
214 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
215 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
216 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
217 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
218 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
219 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
220 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
224 #ifdef CONFIG_SPL_OS_BOOT
225 int spl_start_uboot(void)
227 /* break into full u-boot on 'c' */
228 if (serial_tstc() && serial_getc() == 'c')
231 #ifdef CONFIG_SPL_ENV_SUPPORT
234 if (getenv_yesno("boot_os") != 1)
242 #define OSC (V_OSCK/1000000)
243 const struct dpll_params dpll_ddr = {
244 266, OSC-1, 1, -1, -1, -1, -1};
245 const struct dpll_params dpll_ddr_evm_sk = {
246 303, OSC-1, 1, -1, -1, -1, -1};
247 const struct dpll_params dpll_ddr_bone_black = {
248 400, OSC-1, 1, -1, -1, -1, -1};
250 void am33xx_spl_board_init(void)
254 if (read_eeprom() < 0)
255 puts("Could not get board ID.\n");
257 /* Get the frequency */
258 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
260 if (board_is_bone() || board_is_bone_lt()) {
261 /* BeagleBone PMIC Code */
265 * Only perform PMIC configurations if board rev > A1
266 * on Beaglebone White
268 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
271 if (i2c_probe(TPS65217_CHIP_PM))
275 * On Beaglebone White we need to ensure we have AC power
276 * before increasing the frequency.
278 if (board_is_bone()) {
279 uchar pmic_status_reg;
280 if (tps65217_reg_read(TPS65217_STATUS,
283 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
284 puts("No AC power, disabling frequency switch\n");
290 * Override what we have detected since we know if we have
291 * a Beaglebone Black it supports 1GHz.
293 if (board_is_bone_lt())
294 dpll_mpu_opp100.m = MPUPLL_M_1000;
297 * Increase USB current limit to 1300mA or 1800mA and set
298 * the MPU voltage controller as needed.
300 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
301 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
302 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
304 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
305 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
308 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
311 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
312 puts("tps65217_reg_write failure\n");
314 /* Set DCDC3 (CORE) voltage to 1.125V */
315 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
316 TPS65217_DCDC_VOLT_SEL_1125MV)) {
317 puts("tps65217_voltage_update failure\n");
321 /* Set CORE Frequencies to OPP100 */
322 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
324 /* Set DCDC2 (MPU) voltage */
325 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
326 puts("tps65217_voltage_update failure\n");
331 * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
332 * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
334 if (board_is_bone()) {
335 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
337 TPS65217_LDO_VOLTAGE_OUT_3_3,
339 puts("tps65217_reg_write failure\n");
341 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
343 TPS65217_LDO_VOLTAGE_OUT_1_8,
345 puts("tps65217_reg_write failure\n");
348 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
350 TPS65217_LDO_VOLTAGE_OUT_3_3,
352 puts("tps65217_reg_write failure\n");
357 * The GP EVM, IDK and EVM SK use a TPS65910 PMIC. For all
358 * MPU frequencies we support we use a CORE voltage of
359 * 1.1375V. For MPU voltage we need to switch based on
360 * the frequency we are running at.
362 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
366 * Depending on MPU clock and PG we will need a different
367 * VDD to drive at that speed.
369 sil_rev = readl(&cdev->deviceid) >> 28;
370 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev,
373 /* Tell the TPS65910 to use i2c */
374 tps65910_set_i2c_control();
376 /* First update MPU voltage. */
377 if (tps65910_voltage_update(MPU, mpu_vdd))
380 /* Second, update the CORE voltage. */
381 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3))
384 /* Set CORE Frequencies to OPP100 */
385 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
388 /* Set MPU Frequency to what we detected now that voltages are set */
389 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
392 const struct dpll_params *get_dpll_ddr_params(void)
394 enable_i2c0_pin_mux();
395 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
396 if (read_eeprom() < 0)
397 puts("Could not get board ID.\n");
399 if (board_is_evm_sk())
400 return &dpll_ddr_evm_sk;
401 else if (board_is_bone_lt() || board_is_icev2())
402 return &dpll_ddr_bone_black;
403 else if (board_is_evm_15_or_later())
404 return &dpll_ddr_evm_sk;
409 void set_uart_mux_conf(void)
411 #if CONFIG_CONS_INDEX == 1
412 enable_uart0_pin_mux();
413 #elif CONFIG_CONS_INDEX == 2
414 enable_uart1_pin_mux();
415 #elif CONFIG_CONS_INDEX == 3
416 enable_uart2_pin_mux();
417 #elif CONFIG_CONS_INDEX == 4
418 enable_uart3_pin_mux();
419 #elif CONFIG_CONS_INDEX == 5
420 enable_uart4_pin_mux();
421 #elif CONFIG_CONS_INDEX == 6
422 enable_uart5_pin_mux();
426 void set_mux_conf_regs(void)
428 if (read_eeprom() < 0)
429 puts("Could not get board ID.\n");
431 enable_board_pin_mux();
434 const struct ctrl_ioregs ioregs_evmsk = {
435 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
436 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
437 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
438 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
439 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
442 const struct ctrl_ioregs ioregs_bonelt = {
443 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
444 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
445 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
446 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
447 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
450 const struct ctrl_ioregs ioregs_evm15 = {
451 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
452 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
453 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
454 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
455 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
458 const struct ctrl_ioregs ioregs = {
459 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
460 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
461 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
462 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
463 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
466 void sdram_init(void)
468 if (read_eeprom() < 0)
469 puts("Could not get board ID.\n");
471 if (board_is_evm_sk()) {
473 * EVM SK 1.2A and later use gpio0_7 to enable DDR3.
474 * This is safe enough to do on older revs.
476 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
477 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
480 if (board_is_icev2()) {
481 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
482 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
485 if (board_is_evm_sk())
486 config_ddr(303, &ioregs_evmsk, &ddr3_data,
487 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
488 else if (board_is_bone_lt())
489 config_ddr(400, &ioregs_bonelt,
490 &ddr3_beagleblack_data,
491 &ddr3_beagleblack_cmd_ctrl_data,
492 &ddr3_beagleblack_emif_reg_data, 0);
493 else if (board_is_evm_15_or_later())
494 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
495 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
496 else if (board_is_icev2())
497 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
498 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
501 config_ddr(266, &ioregs, &ddr2_data,
502 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
506 #if !defined(CONFIG_SPL_BUILD) || \
507 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
508 static void request_and_set_gpio(int gpio, char *name, int val)
512 ret = gpio_request(gpio, name);
514 printf("%s: Unable to request %s\n", __func__, name);
518 ret = gpio_direction_output(gpio, 0);
520 printf("%s: Unable to set %s as output\n", __func__, name);
524 gpio_set_value(gpio, val);
532 #define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
533 #define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
536 * RMII mode on ICEv2 board needs 50MHz clock. Given the clock
537 * synthesizer With a capacitor of 18pF, and 25MHz input clock cycle
538 * PLL1 gives an output of 100MHz. So, configuring the div2/3 as 2 to
539 * give 50MHz output for Eth0 and 1.
541 static struct clk_synth cdce913_data = {
551 * Basic board specific setup. Pinmux has been handled already.
555 #if defined(CONFIG_HW_WATCHDOG)
559 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
560 #if defined(CONFIG_NOR) || defined(CONFIG_NAND)
564 #if !defined(CONFIG_SPL_BUILD) || \
565 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
566 if (board_is_icev2()) {
570 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
571 /* Make J19 status available on GPIO1_26 */
572 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
574 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
576 * Both ports can be set as RMII-CPSW or MII-PRU-ETH using
577 * jumpers near the port. Read the jumper value and set
578 * the pinmux, external mux and PHY clock accordingly.
579 * As jumper line is overridden by PHY RX_DV pin immediately
580 * after bootstrap (power-up/reset), we need to sample
581 * it during PHY reset using GPIO rising edge detection.
583 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
584 /* Enable rising edge IRQ on GPIO0_11 and GPIO 1_26 */
585 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
586 writel(reg, GPIO0_RISINGDETECT);
587 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
588 writel(reg, GPIO1_RISINGDETECT);
589 /* Reset PHYs to capture the Jumper setting */
590 gpio_set_value(GPIO_PHY_RESET, 0);
591 udelay(2); /* PHY datasheet states 1uS min. */
592 gpio_set_value(GPIO_PHY_RESET, 1);
594 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
596 writel(reg, GPIO0_IRQSTATUS1); /* clear irq */
598 printf("ETH0, CPSW\n");
601 printf("ETH0, PRU\n");
602 cdce913_data.pdiv3 = 4; /* 25MHz PHY clk */
605 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
607 writel(reg, GPIO1_IRQSTATUS1); /* clear irq */
609 printf("ETH1, CPSW\n");
610 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
613 printf("ETH1, PRU\n");
614 cdce913_data.pdiv2 = 4; /* 25MHz PHY clk */
617 /* disable rising edge IRQs */
618 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
619 writel(reg, GPIO0_RISINGDETECT);
620 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
621 writel(reg, GPIO1_RISINGDETECT);
623 rv = setup_clock_synthesizer(&cdce913_data);
625 printf("Clock synthesizer setup failed %d\n", rv);
630 gpio_set_value(GPIO_PHY_RESET, 0);
631 udelay(2); /* PHY datasheet states 1uS min. */
632 gpio_set_value(GPIO_PHY_RESET, 1);
639 #ifdef CONFIG_BOARD_LATE_INIT
640 int board_late_init(void)
642 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
648 puts("Could not get board ID.\n");
652 set_board_info_env(name);
659 #ifndef CONFIG_DM_ETH
661 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
662 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
663 static void cpsw_control(int enabled)
665 /* VTP can be added here */
670 static struct cpsw_slave_data cpsw_slaves[] = {
672 .slave_reg_ofs = 0x208,
673 .sliver_reg_ofs = 0xd80,
677 .slave_reg_ofs = 0x308,
678 .sliver_reg_ofs = 0xdc0,
683 static struct cpsw_platform_data cpsw_data = {
684 .mdio_base = CPSW_MDIO_BASE,
685 .cpsw_base = CPSW_BASE,
688 .cpdma_reg_ofs = 0x800,
690 .slave_data = cpsw_slaves,
691 .ale_reg_ofs = 0xd00,
693 .host_port_reg_ofs = 0x108,
694 .hw_stats_reg_ofs = 0x900,
695 .bd_ram_ofs = 0x2000,
696 .mac_control = (1 << 5),
697 .control = cpsw_control,
699 .version = CPSW_CTRL_VERSION_2,
703 #if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) &&\
704 defined(CONFIG_SPL_BUILD)) || \
705 ((defined(CONFIG_DRIVER_TI_CPSW) || \
706 defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)) && \
707 !defined(CONFIG_SPL_BUILD))
710 * This function will:
711 * Read the eFuse for MAC addresses, and set ethaddr/eth1addr/usbnet_devaddr
713 * Perform fixups to the PHY present on certain boards. We only need this
715 * - SPL with either CPSW or USB ethernet support
716 * - Full U-Boot, with either CPSW or USB ethernet
717 * Build in only these cases to avoid warnings about unused variables
718 * when we build an SPL that has neither option but full U-Boot will.
720 int board_eth_init(bd_t *bis)
724 uint32_t mac_hi, mac_lo;
725 __maybe_unused struct ti_am_eeprom *header;
727 /* try reading mac address from efuse */
728 mac_lo = readl(&cdev->macid0l);
729 mac_hi = readl(&cdev->macid0h);
730 mac_addr[0] = mac_hi & 0xFF;
731 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
732 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
733 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
734 mac_addr[4] = mac_lo & 0xFF;
735 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
737 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
738 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
739 if (!getenv("ethaddr")) {
740 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
742 if (is_valid_ethaddr(mac_addr))
743 eth_setenv_enetaddr("ethaddr", mac_addr);
746 #ifdef CONFIG_DRIVER_TI_CPSW
748 mac_lo = readl(&cdev->macid1l);
749 mac_hi = readl(&cdev->macid1h);
750 mac_addr[0] = mac_hi & 0xFF;
751 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
752 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
753 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
754 mac_addr[4] = mac_lo & 0xFF;
755 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
757 if (!getenv("eth1addr")) {
758 if (is_valid_ethaddr(mac_addr))
759 eth_setenv_enetaddr("eth1addr", mac_addr);
762 if (read_eeprom() < 0)
763 puts("Could not get board ID.\n");
765 if (board_is_bone() || board_is_bone_lt() ||
767 writel(MII_MODE_ENABLE, &cdev->miisel);
768 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
769 PHY_INTERFACE_MODE_MII;
770 } else if (board_is_icev2()) {
771 writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
772 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
773 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII;
774 cpsw_slaves[0].phy_addr = 1;
775 cpsw_slaves[1].phy_addr = 3;
777 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
778 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
779 PHY_INTERFACE_MODE_RGMII;
782 rv = cpsw_register(&cpsw_data);
784 printf("Error %d registering CPSW switch\n", rv);
791 * CPSW RGMII Internal Delay Mode is not supported in all PVT
792 * operating points. So we must set the TX clock delay feature
793 * in the AR8051 PHY. Since we only support a single ethernet
794 * device in U-Boot, we only do this for the first instance.
796 #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
797 #define AR8051_PHY_DEBUG_DATA_REG 0x1e
798 #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
799 #define AR8051_RGMII_TX_CLK_DLY 0x100
801 if (board_is_evm_sk() || board_is_gp_evm()) {
803 devname = miiphy_get_current_dev();
805 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
806 AR8051_DEBUG_RGMII_CLK_DLY_REG);
807 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
808 AR8051_RGMII_TX_CLK_DLY);
811 #if defined(CONFIG_USB_ETHER) && \
812 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
813 if (is_valid_ethaddr(mac_addr))
814 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
816 rv = usb_eth_initialize(bis);
818 printf("Error %d registering USB_ETHER\n", rv);
826 #endif /* CONFIG_DM_ETH */
828 #ifdef CONFIG_SPL_LOAD_FIT
829 int board_fit_config_name_match(const char *name)
831 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
833 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
835 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
837 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
839 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
841 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
848 #ifdef CONFIG_TI_SECURE_DEVICE
849 void board_fit_image_post_process(void **p_image, size_t *p_size)
851 secure_boot_verify_image(p_image, p_size);