diff mbox

[1/2] netdev/fec: fix phy_speed caculating

Message ID 1270709099-9303-1-git-send-email-bryan.wu@canonical.com
State Accepted
Delegated to: Andy Whitcroft
Headers show

Commit Message

Bryan Wu April 8, 2010, 6:44 a.m. UTC
BugLink: http://bugs.launchpad.net/bugs/546649
BugLink: http://bugs.launchpad.net/bugs/457878

 - remove duplicated phy_speed caculation
 - fix the phy_speed caculation according to the DataSheet

Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
 drivers/net/fec.c |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)

Comments

Andy Whitcroft April 13, 2010, 7:02 p.m. UTC | #1
On Thu, Apr 08, 2010 at 02:44:58PM +0800, Bryan Wu wrote:
> BugLink: http://bugs.launchpad.net/bugs/546649
> BugLink: http://bugs.launchpad.net/bugs/457878
> 
>  - remove duplicated phy_speed caculation
>  - fix the phy_speed caculation according to the DataSheet
> 
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
>  drivers/net/fec.c |    9 ++-------
>  1 files changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> index 9d99359..53240d3 100644
> --- a/drivers/net/fec.c
> +++ b/drivers/net/fec.c
> @@ -737,10 +737,9 @@ static int fec_enet_mii_init(struct platform_device *pdev)
>  	fep->mii_timeout = 0;
>  
>  	/*
> -	 * Set MII speed to 2.5 MHz
> +	 * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
>  	 */
> -	fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
> -					/ 2500000) / 2) & 0x3F) << 1;
> +	fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk), 5000000) << 1;
>  	writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
>  
>  	fep->mii_bus = mdiobus_alloc();
> @@ -1121,10 +1120,6 @@ int __init fec_enet_init(struct net_device *dev, int index)
>  	dev->netdev_ops = &fec_netdev_ops;
>  	dev->ethtool_ops = &fec_enet_ethtool_ops;
>  
> -	/* Set MII speed to 2.5 MHz */
> -	fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
> -					/ 2500000) / 2) & 0x3F) << 1;
> -
>  	/* Initialize the receive buffer descriptors. */
>  	bdp = fep->rx_bd_base;
>  	for (i = 0; i < RX_RING_SIZE; i++) {

Looks ok.  Seems to do what is claimed.

Acked-by: Andy Whitcroft <apw@canonical.com>

-apw
John Johansen April 13, 2010, 7:04 p.m. UTC | #2
On 04/07/2010 11:44 PM, Bryan Wu wrote:
> BugLink: http://bugs.launchpad.net/bugs/546649
> BugLink: http://bugs.launchpad.net/bugs/457878
> 
>  - remove duplicated phy_speed caculation
>  - fix the phy_speed caculation according to the DataSheet
> 
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>

Not having the data sheet I am going to make the assumption that the
calculation is correct.  Other than that ack.

acked-by: John Johansen <john.johansen@canonical.com>

> ---
>  drivers/net/fec.c |    9 ++-------
>  1 files changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/fec.c b/drivers/net/fec.c
> index 9d99359..53240d3 100644
> --- a/drivers/net/fec.c
> +++ b/drivers/net/fec.c
> @@ -737,10 +737,9 @@ static int fec_enet_mii_init(struct platform_device *pdev)
>  	fep->mii_timeout = 0;
>  
>  	/*
> -	 * Set MII speed to 2.5 MHz
> +	 * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
>  	 */
> -	fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
> -					/ 2500000) / 2) & 0x3F) << 1;
> +	fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk), 5000000) << 1;
>  	writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
>  
>  	fep->mii_bus = mdiobus_alloc();
> @@ -1121,10 +1120,6 @@ int __init fec_enet_init(struct net_device *dev, int index)
>  	dev->netdev_ops = &fec_netdev_ops;
>  	dev->ethtool_ops = &fec_enet_ethtool_ops;
>  
> -	/* Set MII speed to 2.5 MHz */
> -	fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
> -					/ 2500000) / 2) & 0x3F) << 1;
> -
>  	/* Initialize the receive buffer descriptors. */
>  	bdp = fep->rx_bd_base;
>  	for (i = 0; i < RX_RING_SIZE; i++) {
diff mbox

Patch

diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 9d99359..53240d3 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -737,10 +737,9 @@  static int fec_enet_mii_init(struct platform_device *pdev)
 	fep->mii_timeout = 0;
 
 	/*
-	 * Set MII speed to 2.5 MHz
+	 * Set MII speed to 2.5 MHz (= clk_get_rate() / 2 * phy_speed)
 	 */
-	fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
-					/ 2500000) / 2) & 0x3F) << 1;
+	fep->phy_speed = DIV_ROUND_UP(clk_get_rate(fep->clk), 5000000) << 1;
 	writel(fep->phy_speed, fep->hwp + FEC_MII_SPEED);
 
 	fep->mii_bus = mdiobus_alloc();
@@ -1121,10 +1120,6 @@  int __init fec_enet_init(struct net_device *dev, int index)
 	dev->netdev_ops = &fec_netdev_ops;
 	dev->ethtool_ops = &fec_enet_ethtool_ops;
 
-	/* Set MII speed to 2.5 MHz */
-	fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
-					/ 2500000) / 2) & 0x3F) << 1;
-
 	/* Initialize the receive buffer descriptors. */
 	bdp = fep->rx_bd_base;
 	for (i = 0; i < RX_RING_SIZE; i++) {