一、u-boot里面如何修改phy
static struct module_pin_mux rmii1_pin_mux[] = { {OFFSET(mii1_crs), MODE(1) | RXACTIVE}, /* RMII1_CRS */ {OFFSET(mii1_rxerr), MODE(1) | RXACTIVE}, /* RMII1_RXERR */ {OFFSET(mii1_txen), MODE(1)}, {OFFSET(mii1_txd1), MODE(1)}, {OFFSET(mii1_txd0), MODE(1)}, /* RMII1_TXEN */ /* RMII1_TXD1 */ /* RMII1_TXD0 */ {OFFSET(mii1_rxd1), MODE(1) | RXACTIVE}, {OFFSET(mii1_rxd0), MODE(1) | RXACTIVE}, /* RMII1_RXD1 */ /* RMII1_RXD0 */ {OFFSET(mdio_data), MODE(0) | RXACTIVE | PULLUP_EN}, /* MDIO_DATA */ {OFFSET(mdio_clk), MODE(0) | PULLUP_EN}, /* MDIO_CLK */ {OFFSET(rmii1_refclk), MODE(0) | RXACTIVE}, /* RMII1_REFCLK */ {-1}, };
void enable_board_pin_mux(void) { ...... // configure_module_pin_mux(rgmii1_pin_mux); configure_module_pin_mux(rmii1_pin_mux); ...... } static struct cpsw_slave_data cpsw_slaves[] = { { .slave_reg_ofs = 0x208, .sliver_reg_ofs = 0xd80, .phy_addr = 0x00, }, ...... };
int board_eth_init(bd_t *bis) { ....... writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel); ........ }
注: RMII_CHIPCKL_ENABLE 为 rmii_refclk 输入使能,即 rmii_refclk 信号由 phy 芯片提供而不是由
CPU 提供,该参数由硬件设计决定。在底板设计指导手册中,使用的是 LAN8720 输出的 rmii_refclk 信号,
因此需要添加改参数,否则会导致 rmii_refclk 信号出现问题;如果硬件设计为由 CPU 提供的话,则无需
添加该参数。
另外,要确保 include/configs/com335x.h 文件中有如下宏定义;
#define CONFIG_PHY_SMSC
该定义为 phy 芯片驱动配置,文件中默认有定义,无需修改。至此, uboot 修改完毕,重新编译即可。
二、kernel里如何修改phy(单网络,rmii1接口)
1.内核配置
Device Drivers ---> [*] Network device support ---> [*] Ethernet driver support ---> [*] Texas Instruments (TI) devices -*- TI DaVinci MDIO Support -*- TI DaVinci CPDMA Support <*> TI CPSW Switch Support [] TI CPSW Switch as Dual EMAC -*- PHY Device support and infrastructure ---> <*> Drivers for SMSC PHYs
/* Module pin mux for rmii1 */ static struct pinmux_config rmii1_pin_mux[] = { {"mii1_crs.rmii1_crs_dv", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"mii1_rxerr.mii1_rxerr", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"mii1_txen.mii1_txen", OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT}, {"mii1_txd1.mii1_txd1", OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT}, {"mii1_txd0.mii1_txd0", OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT}, {"mii1_rxd1.mii1_rxd1", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"mii1_rxd0.mii1_rxd0", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"rmii1_refclk.rmii1_refclk", OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLDOWN}, {"mdio_data.mdio_data", OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP}, {"mdio_clk.mdio_clk", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT_PULLUP}, {NULL, 0}, };
static void com335x_eth_init(void) { setup_pin_mux(rmii1_pin_mux); am33xx_cpsw_init(AM33XX_CPSW_MODE_RMII, "0:00", NULL); // int ret = phy_register_fixup_for_uid(COM335X_EVM_PHY_ID, COM335X_PHY_MASK, am33xx_tx_clk_dly_phy_fixup); }
注: am33xx_cpsw_init(AM33XX_CPSW_MODE_RMII, "0:00", NULL)里的第一个参数为指定 RMII 模
式,第二个参数为 rmii1 接口上的 phy_addr,第三个参数为 rmii2 接口上的 phy_addr。修改完成后,保存文
件。
在上一节提到,我们的设计中, rmii_refclk 信号由 phy 芯片提供,因此需要使能 rmii1_refclk 为输入,
打开 arch/arm/mach-omap2/devices.c 文件,在 am33xx_cpsw_init 函数中,增加以下内容:
int am33xx_cpsw_init(enum am33xx_cpsw_mac_mode mode, unsigned char *phy_id0, unsigned char *phy_id1) { ...... #define RMII1_IO_CLK_EN 1 << 6 gmii_sel |= (RMII1_IO_CLK_EN); writel(gmii_sel, AM33XX_CTRL_REGADDR(AM33XX_CONTROL_GMII_SEL_OFFSET)); ...... }
三、kernel里如何修改phy(双网络,rmii1、rmii2接口)
Device Drivers ---> [*] Network device support ---> [*] Ethernet driver support ---> [*] Texas Instruments (TI) devices -*- TI DaVinci MDIO Support -*- TI DaVinci CPDMA Support <*> TI CPSW Switch Support [*] TI CPSW Switch as Dual EMAC -*- PHY Device support and infrastructure ---> <*> Drivers for SMSC PHYs
/* Module pin mux for rmii1 */ static struct pinmux_config rmii1_pin_mux[] = { {"mii1_crs.rmii1_crs_dv", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"mii1_rxerr.mii1_rxerr", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"mii1_txen.mii1_txen", OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT}, {"mii1_txd1.mii1_txd1", OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT}, {"mii1_txd0.mii1_txd0", OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT}, {"mii1_rxd1.mii1_rxd1", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"mii1_rxd0.mii1_rxd0", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"rmii1_refclk.rmii1_refclk", OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLDOWN}, {"mdio_data.mdio_data", OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP}, {"mdio_clk.mdio_clk", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT_PULLUP}, {NULL, 0}, }; /* Module pin mux for rmii2 */ static struct pinmux_config rmii2_pin_mux[] = { {"gpmc_csn3.rmii2_crs_dv", OMAP_MUX_MODE2 | AM33XX_PIN_INPUT_PULLDOWN}, // {"gpmc_wpn.rmii2_rxerr", OMAP_MUX_MODE3 | AM33XX_PIN_INPUT_PULLDOWN}, {"gpmc_a0.rmii2_txen", OMAP_MUX_MODE3 | AM33XX_PIN_OUTPUT}, {"gpmc_a4.rmii2_txd1", OMAP_MUX_MODE3 | AM33XX_PIN_OUTPUT}, {"gpmc_a5.rmii2_txd0", OMAP_MUX_MODE3 | AM33XX_PIN_OUTPUT}, {"gpmc_a10.rmii2_rxd1", OMAP_MUX_MODE3 | AM33XX_PIN_INPUT_PULLDOWN}, {"gpmc_a11.rmii2_rxd0", OMAP_MUX_MODE3 | AM33XX_PIN_INPUT_PULLDOWN}, {"mii1_col.rmii2_refclk", OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN}, {"mdio_data.mdio_data", OMAP_MUX_MODE0 | AM33XX_PIN_INPUT_PULLUP}, {"mdio_clk.mdio_clk", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT_PULLUP}, {NULL, 0}, };
注意:引脚不要被其它功能复用!另外,根据底板设计手册,在 rmii2 接口中,由于 rmii2_rxerr 脚已
经被 gpmc 使用,因此 rmii2_rxerr 未与 LAN8720 连接,经测试,未发现此情况下对网络有影响。
3.驱动初始化
在 board-com335x.c 文件的 com335x_eth_init(void)函数中,做以下修改:
static void com335x_eth_init(void) { setup_pin_mux(rmii1_pin_mux); setup_pin_mux(rmii2_pin_mux); am33xx_cpsw_init(AM33XX_CPSW_MODE_RMII, "0:00", "0:01"); // int ret = phy_register_fixup_for_uid(COM335X_EVM_PHY_ID, COM335X_PHY_MASK, am33xx_tx_clk_dly_phy_fixup); }
注:详细说明请参考上一节。修改完成后,保存文件。
使能 rmii1_refclk、 rmii2_refclk 为输入(参考上一节),打开 arch/arm/mach-omap2/devices.c 文件,在
am33xx_cpsw_init 函数中,增加以下内容:
int am33xx_cpsw_init(enum am33xx_cpsw_mac_mode mode, unsigned char *phy_id0, unsigned char *phy_id1) { ...... #define RMII1_IO_CLK_EN 1 << 6 #define RMII2_IO_CLK_EN 1 << 7 gmii_sel |= (RMII1_IO_CLK_EN); writel(gmii_sel, AM33XX_CTRL_REGADDR(AM33XX_CONTROL_GMII_SEL_OFFSET)); ...... }