1. 程式人生 > >TI am335x 核心分析----乙太網移植

TI am335x 核心分析----乙太網移植

TI am335x的乙太網移植:

1.1配置MII的管腳

static struct pinmux_config rmii1_pin_mux[]= {

 {"mii1_crs.rmii1_crs_dv",OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN},

 {"mii1_rxer.rmii1_rxer",OMAP_MUX_MODE1|AM33XX_PIN_INPUT_PULLDOWN}, 

 {"mii1_tx_en.rmii1_txen",OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT},

 {"mii1_tx_d1.rmii1_txd1",OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT},

 {"mii1_txd0.rmii1_txd0",OMAP_MUX_MODE1 | AM33XX_PIN_OUTPUT},

 {"mii1_rxd1.rmii1_rxd1",OMAP_MUX_MODE1 | AM33XX_PIN_INPUT_PULLDOWN},

 {"mii1_rxd0.rmii1_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 struct pinmux_config rmii2_pin_mux[]= {

 {"gpmc_csn3.rmii2_crs_dv",OMAP_MUX_MODE2 |AM33XX_PIN_INPUT_PULLDOWN},

//  {"gpmc_wpn.mii2_rxerr", OMAP_MUX_MODE3|AM33XX_PIN_INPUT_PULLDOWN},

  {"gpmc_wpn.rmii2_rxerr",OMAP_MUX_MODE3 |AM33XX_PIN_INPUT_PULLDOWN},

{"gpmc_a0.mii2_txen",OMAP_MUX_MODE3 | AM33XX_PIN_OUTPUT},

 {"gpmc_a4.mii2_txd1", OMAP_MUX_MODE3| AM33XX_PIN_OUTPUT},

 {"gpmc_a5.mii2_txd0", OMAP_MUX_MODE3| AM33XX_PIN_OUTPUT},

 {"gpmc_a10.mii2_rxd1",OMAP_MUX_MODE3| AM33XX_PIN_INPUT_PULLDOWN},

 {"gpmc_a11.mii2_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},

};

1.2初始化函式

Setup_general_purpose(void)

{

……

am33xx_cpsw_init(AM33XX_CPSW_MODE_RMII,NULL, NULL);

/* Atheros Tx Clkdelay Phy fixup */

phy_register_fixup_for_uid(AM335X_EVM_PHY_ID, AM335X_EVM_PHY_MASK,

                                beaglebone_phy_fixup);

……

}        

#defineAM335X_EVM_PHY_ID                0x20005c90                     //Tbao

 

 

staticstruct cpsw_slave_data am33xx_cpsw_slaves[] = {

{

           .slave_reg_ofs  = 0x200,

           .sliver_reg_ofs= 0xd80,

           .phy_id                = "0:01",

           .dual_emac_reserved_vlan= CPSW_PORT_VLAN_SLAVE_0,

           //.mac_addr=

},

{

           .slave_reg_ofs  = 0x300,

           .sliver_reg_ofs= 0xdc0,

           .phy_id                = "0:02",

           .dual_emac_reserved_vlan= CPSW_PORT_VLAN_SLAVE_1,

},

};

選擇暫存器的模式:

#defineAM33XX_RMII_MODE_EN           ((1 <<0) | (1 << 2) | (1<<6) | (1<<7))

am33xx_cpsw_init()

{

……

struct omap_hwmod *oh;

struct platform_device *pdev;

u32 mac_lo, mac_hi, gmii_sel;

u32 i;

 

mac_lo = omap_ctrl_readl(TI81XX_CONTROL_MAC_ID0_LO);

mac_hi =omap_ctrl_readl(TI81XX_CONTROL_MAC_ID0_HI);

am33xx_cpsw_slaves[0].mac_addr[0] = mac_hi& 0xFF;

am33xx_cpsw_slaves[0].mac_addr[1] = (mac_hi& 0xFF00) >> 8;

am33xx_cpsw_slaves[0].mac_addr[2] = (mac_hi& 0xFF0000) >> 16;

am33xx_cpsw_slaves[0].mac_addr[3] = (mac_hi& 0xFF000000) >> 24;

am33xx_cpsw_slaves[0].mac_addr[4] = mac_lo& 0xFF;

am33xx_cpsw_slaves[0].mac_addr[5] = (mac_lo& 0xFF00) >> 8;

 

/* Read MACID0 from eeprom if eFuse MACID isinvalid */

if (!is_valid_ether_addr(am33xx_cpsw_slaves[0].mac_addr)){

           for (i = 0; i < ETH_ALEN; i++)

                    am33xx_cpsw_slaves[0].mac_addr[i]= am33xx_macid0[i];

}

mac_lo =omap_ctrl_readl(TI81XX_CONTROL_MAC_ID1_LO);

mac_hi =omap_ctrl_readl(TI81XX_CONTROL_MAC_ID1_HI);

am33xx_cpsw_slaves[1].mac_addr[0] = mac_hi& 0xFF;

am33xx_cpsw_slaves[1].mac_addr[1] = (mac_hi& 0xFF00) >> 8;

am33xx_cpsw_slaves[1].mac_addr[2] = (mac_hi& 0xFF0000) >> 16;

am33xx_cpsw_slaves[1].mac_addr[3] = (mac_hi& 0xFF000000) >> 24;

am33xx_cpsw_slaves[1].mac_addr[4] = mac_lo& 0xFF;

am33xx_cpsw_slaves[1].mac_addr[5] = (mac_lo& 0xFF00) >> 8;

 

/* Read MACID1 from eeprom if eFuse MACID isinvalid */

if(!is_valid_ether_addr(am33xx_cpsw_slaves[1].mac_addr)) {

           for (i = 0; i < ETH_ALEN; i++)

                    am33xx_cpsw_slaves[1].mac_addr[i]= am33xx_macid1[i];

}

switch (mode) {

case AM33XX_CPSW_MODE_MII:

           gmii_sel = AM33XX_MII_MODE_EN;

           break;

case AM33XX_CPSW_MODE_RMII:

           gmii_sel = AM33XX_RMII_MODE_EN;                 //    1100 0101

           am33xx_cpsw_slaves[0].phy_if =PHY_INTERFACE_MODE_RMII;      //Tbao------

           am33xx_cpsw_slaves[1].phy_if =PHY_INTERFACE_MODE_RMII;

           break;

case AM33XX_CPSW_MODE_RGMII:

           gmii_sel = AM33XX_RGMII_MODE_EN;              

           am33xx_cpsw_slaves[0].phy_if =PHY_INTERFACE_MODE_RGMII;

           am33xx_cpsw_slaves[1].phy_if =PHY_INTERFACE_MODE_RGMII;

           break;

default:

           return -EINVAL;

}

writel(gmii_sel,AM33XX_CTRL_REGADDR(AM33XX_CONTROL_GMII_SEL_OFFSET));

if (phy_id0 != NULL)

           am33xx_cpsw_slaves[0].phy_id =phy_id0;

if (phy_id1 != NULL)

           am33xx_cpsw_slaves[1].phy_id =phy_id1;

memcpy(am33xx_cpsw_pdata.mac_addr,

                    am33xx_cpsw_slaves[0].mac_addr,ETH_ALEN);

oh = omap_hwmod_lookup("mdio");

if (!oh) {

           pr_err("could not find cpgmac0hwmod data\n");

           return -ENODEV;

}

pdev =omap_device_build("davinci_mdio", 0, oh, &am33xx_cpsw_mdiopdata,

                    sizeof(am33xx_cpsw_mdiopdata),NULL, 0, 0);

if (IS_ERR(pdev))

           pr_err("could not buildomap_device for cpsw\n");

oh = omap_hwmod_lookup("cpgmac0");

if (!oh) {

           pr_err("could not find cpgmac0hwmod data\n");

           return -ENODEV;

}

 

pdev = omap_device_build("cpsw", -1,oh, &am33xx_cpsw_pdata,

                    sizeof(am33xx_cpsw_pdata),NULL, 0, 0);

if (IS_ERR(pdev))

           pr_err("could not buildomap_device for cpsw\n");

 

return 0;

}

……

}

 

 經過以上的移植,乙太網能夠起來。。

                                          2017/09/21   於深圳南山