From 9cb221ea7b4c720898617eae1c684863f29206f3 Mon Sep 17 00:00:00 2001 From: wdc Date: Sat, 12 Oct 2013 20:52:56 +0800 Subject: [PATCH] ethernet: add rmii clkin support and support rmii data package without header --- arch/arm/mach-rk30/board-rk30-sdk-vmac.c | 10 ++ arch/arm/mach-rk30/board-rk31-sdk-vmac.c | 31 ++++- arch/arm/mach-rk3188/board-rk3188-ac.c | 1 + arch/arm/plat-rk/include/plat/board.h | 1 + drivers/net/rk29_vmac.c | 139 ++++++++++++++--------- 5 files changed, 120 insertions(+), 62 deletions(-) diff --git a/arch/arm/mach-rk30/board-rk30-sdk-vmac.c b/arch/arm/mach-rk30/board-rk30-sdk-vmac.c index 0a43c75aca87..76837f701c3d 100755 --- a/arch/arm/mach-rk30/board-rk30-sdk-vmac.c +++ b/arch/arm/mach-rk30/board-rk30-sdk-vmac.c @@ -1,3 +1,4 @@ +static rmii_extclk_sel = 0; static int rk30_vmac_register_set(void) { //config rk30 vmac as rmii @@ -83,10 +84,19 @@ static int rk29_vmac_speed_switch(int speed) } } +static int rk30_rmii_extclk_sel(void) +{ +#ifdef RMII_EXT_CLK + rmii_extclk_sel = 1; //0:select internal divider clock, 1:select external input clock +#endif + return rmii_extclk_sel; +} + struct rk29_vmac_platform_data board_vmac_data = { .vmac_register_set = rk30_vmac_register_set, .rmii_io_init = rk30_rmii_io_init, .rmii_io_deinit = rk30_rmii_io_deinit, .rmii_power_control = rk30_rmii_power_control, .rmii_speed_switch = rk29_vmac_speed_switch, + .rmii_extclk_sel = rk30_rmii_extclk_sel, }; diff --git a/arch/arm/mach-rk30/board-rk31-sdk-vmac.c b/arch/arm/mach-rk30/board-rk31-sdk-vmac.c index 56901da8876e..35b9b79210b7 100644 --- a/arch/arm/mach-rk30/board-rk31-sdk-vmac.c +++ b/arch/arm/mach-rk30/board-rk31-sdk-vmac.c @@ -1,25 +1,31 @@ -//$_FOR_ROCKCHIP_RBOX_$ - +static rmii_extclk_sel = 0; static int rk30_vmac_register_set(void) { //config rk30 vmac as rmii writel_relaxed(0x3 << 16 | 0x2, RK30_GRF_BASE + GRF_SOC_CON1); int val = readl_relaxed(RK30_GRF_BASE + GRF_IO_CON3); writel_relaxed(val | 0xf << 16 | 0xf, RK30_GRF_BASE + GRF_IO_CON3); + val = readl(RK30_GRF_BASE + GRF_SOC_CON2); + writel(0x1 << 6 | 0x1 << 22 | val, RK30_GRF_BASE + GRF_SOC_CON2); + return 0; } static int rk30_rmii_io_init(void) { int err; - printk("enter %s ",__func__); + printk("enter %s \n",__func__); iomux_set(RMII_TXEN); iomux_set(RMII_TXD1); iomux_set(RMII_TXD0); iomux_set(RMII_RXD0); iomux_set(RMII_RXD1); - iomux_set(RMII_CLKOUT); +#ifdef RMII_EXT_CLK + iomux_set(RMII_CLKIN); +#else + iomux_set(RMII_CLKOUT); +#endif iomux_set(RMII_RXERR); iomux_set(RMII_CRS); iomux_set(RMII_MD); @@ -44,7 +50,7 @@ static int rk30_rmii_io_init(void) static int rk30_rmii_io_deinit(void) { //phy power down - printk("enter %s ",__func__); + printk("enter %s \n",__func__); if(INVALID_GPIO != PHY_PWR_EN_GPIO) { @@ -58,7 +64,7 @@ static int rk30_rmii_io_deinit(void) static int rk30_rmii_power_control(int enable) { - printk("enter %s ,enable = %d ",__func__,enable); + printk("enter %s ,enable = %d \n",__func__,enable); if (enable){ iomux_set(RMII_TXEN); @@ -66,7 +72,11 @@ static int rk30_rmii_power_control(int enable) iomux_set(RMII_TXD0); iomux_set(RMII_RXD0); iomux_set(RMII_RXD1); +#ifdef RMII_EXT_CLK + iomux_set(RMII_CLKIN); +#else iomux_set(RMII_CLKOUT); +#endif iomux_set(RMII_RXERR); iomux_set(RMII_CRS); iomux_set(RMII_MD); @@ -100,10 +110,19 @@ static int rk29_vmac_speed_switch(int speed) } } +static int rk30_rmii_extclk_sel(void) +{ +#ifdef RMII_EXT_CLK + rmii_extclk_sel = 1; //0:select internal divider clock, 1:select external input clock +#endif + return rmii_extclk_sel; +} + struct rk29_vmac_platform_data board_vmac_data = { .vmac_register_set = rk30_vmac_register_set, .rmii_io_init = rk30_rmii_io_init, .rmii_io_deinit = rk30_rmii_io_deinit, .rmii_power_control = rk30_rmii_power_control, .rmii_speed_switch = rk29_vmac_speed_switch, + .rmii_extclk_sel = rk30_rmii_extclk_sel, }; diff --git a/arch/arm/mach-rk3188/board-rk3188-ac.c b/arch/arm/mach-rk3188/board-rk3188-ac.c index 6805fbe04f02..f718a942ff55 100755 --- a/arch/arm/mach-rk3188/board-rk3188-ac.c +++ b/arch/arm/mach-rk3188/board-rk3188-ac.c @@ -1115,6 +1115,7 @@ struct platform_device pwm_regulator_device[1] = { #define PHY_PWR_EN_GPIO INVALID_GPIO #define PHY_PWR_EN_IOMUX GPIO3_D2 #define PHY_PWR_EN_VALUE GPIO_HIGH +#define RMII_EXT_CLK #include "../mach-rk30/board-rk31-sdk-vmac.c" #endif diff --git a/arch/arm/plat-rk/include/plat/board.h b/arch/arm/plat-rk/include/plat/board.h index 89fc19aa1733..b149bcdc6c41 100755 --- a/arch/arm/plat-rk/include/plat/board.h +++ b/arch/arm/plat-rk/include/plat/board.h @@ -274,6 +274,7 @@ struct rk29_vmac_platform_data { int (*rmii_io_deinit)(void); int (*rmii_power_control)(int enable); int(*rmii_speed_switch)(int speed); + int(*rmii_extclk_sel)(void); }; /* adc battery */ #define LCDC_ON 0x0001 diff --git a/drivers/net/rk29_vmac.c b/drivers/net/rk29_vmac.c index d32da064eaad..d5c24dcfec1e 100755 --- a/drivers/net/rk29_vmac.c +++ b/drivers/net/rk29_vmac.c @@ -1037,6 +1037,8 @@ int vmac_open(struct net_device *dev) struct clk *mac_parent = NULL; struct clk *arm_clk = NULL; struct rk29_vmac_platform_data *pdata = ap->pdev->dev.platform_data; + unsigned char current_mac[6]; + int ret = 0; printk("enter func %s...\n", __func__); @@ -1048,7 +1050,7 @@ int vmac_open(struct net_device *dev) ap->shutdown = 0; //set rmii ref clock 50MHz - mac_clk = clk_get(NULL, "mac_ref_div"); + mac_clk = clk_get(NULL, "mac_ref"); if (IS_ERR(mac_clk)) mac_clk = NULL; arm_clk = clk_get(NULL, "arm_pll"); @@ -1061,7 +1063,17 @@ int vmac_open(struct net_device *dev) } if (arm_clk && mac_parent && (arm_clk == mac_parent)) wake_lock(&idlelock); - + + if(pdata && pdata->rmii_extclk_sel && pdata->rmii_extclk_sel()) + { + struct clk * mac_clkin = NULL; + mac_clkin = clk_get(NULL, "rmii_clkin"); + if (IS_ERR(mac_clkin)) { + pr_err("mac_clkin get fail\n"); + } + clk_set_parent(mac_clk, mac_clkin); + } + clk_set_rate(mac_clk, 50000000); clk_enable(mac_clk); clk_enable(clk_get(NULL,"mii_rx")); @@ -1070,16 +1082,70 @@ int vmac_open(struct net_device *dev) clk_enable(clk_get(NULL,"mac_ref")); //phy power on - if (pdata && pdata->rmii_power_control) { - pdata->rmii_power_control(0); - msleep(100); + if (pdata && pdata->rmii_power_control) pdata->rmii_power_control(1); - } msleep(1000); vmac_hw_init(dev); +//$_rbox_$_modify_$_chenxiao + if (is_valid_ether_addr(dev->dev_addr)){ + strlcpy(current_mac,dev->dev_addr,6); + } + +#ifdef CONFIG_ETH_MAC_FROM_EEPROM + ret = eeprom_read_data(0,dev->dev_addr,6); + if (ret != 6){ + printk("read mac from Eeprom fail.\n"); + }else { + if (is_valid_ether_addr(dev->dev_addr)){ + printk("eth_mac_from_eeprom***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], + dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], + dev->dev_addr[4],dev->dev_addr[5] ); + } + } +#endif + +#ifdef CONFIG_ETH_MAC_FROM_IDB + err = eth_mac_idb(dev->dev_addr); + if (err) { + printk("read mac from IDB fail.\n"); + } else { + if (is_valid_ether_addr(dev->dev_addr)) { + printk("eth_mac_from_idb***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], + dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], + dev->dev_addr[4],dev->dev_addr[5] ); + } + } +#endif + +#ifdef CONFIG_ETH_MAC_FROM_WIFI_MAC + err = eth_mac_wifi(dev->dev_addr); + if (err) { + printk("read mac from Wifi fail.\n"); + } else { + if (is_valid_ether_addr(dev->dev_addr)) { + printk("eth_mac_from_wifi_mac***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], + dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], + dev->dev_addr[4],dev->dev_addr[5] ); + } + } +#endif + +#ifdef CONFIG_ETH_MAC_FROM_SECURE_CHIP + +#endif + + + if (!is_valid_ether_addr(dev->dev_addr)) { + strlcpy(dev->dev_addr,current_mac,6); + printk("eth_mac_from_RANDOM***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], + dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], + dev->dev_addr[4],dev->dev_addr[5] ); + } +//add end + /* mac address changed? */ write_mac_reg(dev, dev->dev_addr); @@ -1552,56 +1618,8 @@ static int __devinit vmac_probe(struct platform_device *pdev) /* mac address intialize, set vmac_open */ read_mac_reg(dev, dev->dev_addr); - if (!is_valid_ether_addr(dev->dev_addr)) { - //add by cx@rock-chips.com - - #ifdef CONFIG_ETH_MAC_FROM_EEPROM - ret = eeprom_read_data(0,dev->dev_addr,6); - if (ret != 6){ - printk("read mac from Eeprom fail.\n"); - }else { - if (is_valid_ether_addr(dev->dev_addr)){ - printk("eth_mac_from_eeprom***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], - dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], - dev->dev_addr[4],dev->dev_addr[5] ); - } - } - #endif - - #ifdef CONFIG_ETH_MAC_FROM_IDB - err = eth_mac_idb(dev->dev_addr); - if (err) { - printk("read mac from IDB fail.\n"); - } else { - if (is_valid_ether_addr(dev->dev_addr)) { - printk("eth_mac_from_idb***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], - dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], - dev->dev_addr[4],dev->dev_addr[5] ); - } - } - #endif - - /*#ifdef CONFIG_ETH_MAC_FROM_WIFI_MAC - err = eth_mac_wifi(dev->dev_addr); - if (err) { - printk("read mac from Wifi fail.\n"); - } else { - if (is_valid_ether_addr(dev->dev_addr)) { - printk("eth_mac_from_wifi_mac***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], - dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], - dev->dev_addr[4],dev->dev_addr[5] ); - } - } - #endif*/ - - #ifdef CONFIG_ETH_MAC_FROM_RANDOM - random_ether_addr(dev->dev_addr); - printk("random_ether_addr***********:%X:%X:%X:%X:%X:%X\n",dev->dev_addr[0], - dev->dev_addr[1],dev->dev_addr[2],dev->dev_addr[3], - dev->dev_addr[4],dev->dev_addr[5] ); - #endif - //add end - } + if (!is_valid_ether_addr(dev->dev_addr)) + random_ether_addr(dev->dev_addr); err = register_netdev(dev); if (err) { @@ -1702,8 +1720,11 @@ rk29_vmac_suspend(struct device *dev) netif_stop_queue(ndev); netif_device_detach(ndev); if (ap->suspending == 0) { +//$_rbox_$_modify_$_chenzhi: for ethernet sleep +#if 0 vmac_shutdown(ndev); rk29_vmac_power_off(ndev); +#endif ap->suspending = 1; } } @@ -1722,6 +1743,12 @@ rk29_vmac_resume(struct device *dev) if (ap->open_flag == 1) { netif_device_attach(ndev); netif_start_queue(ndev); +//$_rbox_$_modify_$_chenzhi: +//$_rbox_$_modify_$_begin + if (ap->suspending == 1) { + ap->suspending = 0; + } +//$_rbox_$_modify_$_end } } return 0; -- 2.34.1