2 * Board functions for Compulab CM-T335 board
4 * Copyright (C) 2013, Compulab Ltd - http://compulab.co.il/
6 * Author: Ilya Ledvich <ilya@compulab.co.il>
8 * SPDX-License-Identifier: GPL-2.0+
16 #include <asm/arch/sys_proto.h>
17 #include <asm/arch/hardware_am33xx.h>
21 #include "../common/eeprom.h"
23 DECLARE_GLOBAL_DATA_PTR
;
26 * Basic board specific setup. Pinmux has been handled already.
30 gd
->bd
->bi_boot_params
= CONFIG_SYS_SDRAM_BASE
+ 0x100;
34 #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
35 status_led_set(CONFIG_LED_STATUS_BOOT
, CONFIG_LED_STATUS_OFF
);
40 #if defined (CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)
41 static void cpsw_control(int enabled
)
43 /* VTP can be added here */
47 static struct cpsw_slave_data cpsw_slave
= {
48 .slave_reg_ofs
= 0x208,
49 .sliver_reg_ofs
= 0xd80,
51 .phy_if
= PHY_INTERFACE_MODE_RGMII
,
54 static struct cpsw_platform_data cpsw_data
= {
55 .mdio_base
= CPSW_MDIO_BASE
,
56 .cpsw_base
= CPSW_BASE
,
59 .cpdma_reg_ofs
= 0x800,
61 .slave_data
= &cpsw_slave
,
64 .host_port_reg_ofs
= 0x108,
65 .hw_stats_reg_ofs
= 0x900,
67 .mac_control
= (1 << 5),
68 .control
= cpsw_control
,
70 .version
= CPSW_CTRL_VERSION_2
,
74 #define GPIO_PHY_RST GPIO_PIN(3, 7)
76 static void board_phy_init(void)
78 gpio_request(GPIO_PHY_RST
, "phy_rst");
79 gpio_direction_output(GPIO_PHY_RST
, 0);
81 gpio_set_value(GPIO_PHY_RST
, 1);
85 static void get_efuse_mac_addr(uchar
*enetaddr
)
87 uint32_t mac_hi
, mac_lo
;
88 struct ctrl_dev
*cdev
= (struct ctrl_dev
*)CTRL_DEVICE_BASE
;
90 mac_lo
= readl(&cdev
->macid0l
);
91 mac_hi
= readl(&cdev
->macid0h
);
92 enetaddr
[0] = mac_hi
& 0xFF;
93 enetaddr
[1] = (mac_hi
& 0xFF00) >> 8;
94 enetaddr
[2] = (mac_hi
& 0xFF0000) >> 16;
95 enetaddr
[3] = (mac_hi
& 0xFF000000) >> 24;
96 enetaddr
[4] = mac_lo
& 0xFF;
97 enetaddr
[5] = (mac_lo
& 0xFF00) >> 8;
101 * Routine: handle_mac_address
102 * Description: prepare MAC address for on-board Ethernet.
104 static int handle_mac_address(void)
109 rv
= eth_getenv_enetaddr("ethaddr", enetaddr
);
113 rv
= cl_eeprom_read_mac_addr(enetaddr
, CONFIG_SYS_I2C_EEPROM_BUS
);
115 get_efuse_mac_addr(enetaddr
);
117 if (!is_valid_ethaddr(enetaddr
))
120 return eth_setenv_enetaddr("ethaddr", enetaddr
);
123 #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
124 #define AR8051_PHY_DEBUG_DATA_REG 0x1e
125 #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
126 #define AR8051_RGMII_TX_CLK_DLY 0x100
128 int board_eth_init(bd_t
*bis
)
132 struct ctrl_dev
*cdev
= (struct ctrl_dev
*)CTRL_DEVICE_BASE
;
134 rv
= handle_mac_address();
136 printf("No MAC address found!\n");
138 writel(RGMII_MODE_ENABLE
| RGMII_INT_DELAY
, &cdev
->miisel
);
142 rv
= cpsw_register(&cpsw_data
);
144 printf("Error %d registering CPSW switch\n", rv
);
149 * CPSW RGMII Internal Delay Mode is not supported in all PVT
150 * operating points. So we must set the TX clock delay feature
151 * in the AR8051 PHY. Since we only support a single ethernet
152 * device, we only do this for the first instance.
154 devname
= miiphy_get_current_dev();
156 miiphy_write(devname
, 0x0, AR8051_PHY_DEBUG_ADDR_REG
,
157 AR8051_DEBUG_RGMII_CLK_DLY_REG
);
158 miiphy_write(devname
, 0x0, AR8051_PHY_DEBUG_DATA_REG
,
159 AR8051_RGMII_TX_CLK_DLY
);
162 #endif /* CONFIG_DRIVER_TI_CPSW && !CONFIG_SPL_BUILD */