1 // SPDX-License-Identifier: GPL-2.0+
3 * Board functions for Compulab CM-T335 board
5 * Copyright (C) 2013, Compulab Ltd - http://compulab.co.il/
7 * Author: Ilya Ledvich <ilya@compulab.co.il>
15 #include <status_led.h>
17 #include <asm/global_data.h>
18 #include <linux/delay.h>
20 #include <asm/arch/sys_proto.h>
21 #include <asm/arch/hardware_am33xx.h>
25 #include "../common/eeprom.h"
27 DECLARE_GLOBAL_DATA_PTR;
30 * Basic board specific setup. Pinmux has been handled already.
34 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
38 #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
39 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_OFF);
44 #if defined (CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)
45 static void cpsw_control(int enabled)
47 /* VTP can be added here */
51 static struct cpsw_slave_data cpsw_slave = {
52 .slave_reg_ofs = 0x208,
53 .sliver_reg_ofs = 0xd80,
55 .phy_if = PHY_INTERFACE_MODE_RGMII,
58 static struct cpsw_platform_data cpsw_data = {
59 .mdio_base = CPSW_MDIO_BASE,
60 .cpsw_base = CPSW_BASE,
63 .cpdma_reg_ofs = 0x800,
65 .slave_data = &cpsw_slave,
68 .host_port_reg_ofs = 0x108,
69 .hw_stats_reg_ofs = 0x900,
71 .mac_control = (1 << 5),
72 .control = cpsw_control,
74 .version = CPSW_CTRL_VERSION_2,
78 #define GPIO_PHY_RST GPIO_PIN(3, 7)
80 static void board_phy_init(void)
82 gpio_request(GPIO_PHY_RST, "phy_rst");
83 gpio_direction_output(GPIO_PHY_RST, 0);
85 gpio_set_value(GPIO_PHY_RST, 1);
89 static void get_efuse_mac_addr(uchar *enetaddr)
91 uint32_t mac_hi, mac_lo;
92 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
94 mac_lo = readl(&cdev->macid0l);
95 mac_hi = readl(&cdev->macid0h);
96 enetaddr[0] = mac_hi & 0xFF;
97 enetaddr[1] = (mac_hi & 0xFF00) >> 8;
98 enetaddr[2] = (mac_hi & 0xFF0000) >> 16;
99 enetaddr[3] = (mac_hi & 0xFF000000) >> 24;
100 enetaddr[4] = mac_lo & 0xFF;
101 enetaddr[5] = (mac_lo & 0xFF00) >> 8;
105 * Routine: handle_mac_address
106 * Description: prepare MAC address for on-board Ethernet.
108 static int handle_mac_address(void)
113 rv = eth_env_get_enetaddr("ethaddr", enetaddr);
117 rv = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
119 get_efuse_mac_addr(enetaddr);
121 if (!is_valid_ethaddr(enetaddr))
124 return eth_env_set_enetaddr("ethaddr", enetaddr);
127 #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
128 #define AR8051_PHY_DEBUG_DATA_REG 0x1e
129 #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
130 #define AR8051_RGMII_TX_CLK_DLY 0x100
132 int board_eth_init(struct bd_info *bis)
136 struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
138 rv = handle_mac_address();
140 printf("No MAC address found!\n");
142 writel(RGMII_MODE_ENABLE | RGMII_INT_DELAY, &cdev->miisel);
146 rv = cpsw_register(&cpsw_data);
148 printf("Error %d registering CPSW switch\n", rv);
153 * CPSW RGMII Internal Delay Mode is not supported in all PVT
154 * operating points. So we must set the TX clock delay feature
155 * in the AR8051 PHY. Since we only support a single ethernet
156 * device, we only do this for the first instance.
158 devname = miiphy_get_current_dev();
160 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
161 AR8051_DEBUG_RGMII_CLK_DLY_REG);
162 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
163 AR8051_RGMII_TX_CLK_DLY);
166 #endif /* CONFIG_DRIVER_TI_CPSW && !CONFIG_SPL_BUILD */