diff mbox

[U-Boot,1/2] net: fec_mxc: configure MDIO hold time

Message ID 1449589126-10530-1-git-send-email-mans@mansr.com
State Awaiting Upstream
Delegated to: Stefano Babic
Headers show

Commit Message

Måns Rullgård Dec. 8, 2015, 3:38 p.m. UTC
If the host clock frequency is higher than 100 MHz, the MDIO hold
time needs to be increased from its current setting of one cycle in
order to meet the specified minium of 10 ns.  Writing an appropriate
value to the HOLDTIME field of the MII_SPEED register achieves this.

Comment copied from Linux kernel.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
 drivers/net/fec_mxc.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Comments

Eric Nelson Dec. 8, 2015, 4:08 p.m. UTC | #1
Hi Mans,

On 12/08/2015 08:38 AM, Mans Rullgard wrote:
> If the host clock frequency is higher than 100 MHz, the MDIO hold
> time needs to be increased from its current setting of one cycle in
> order to meet the specified minium of 10 ns.  Writing an appropriate
> value to the HOLDTIME field of the MII_SPEED register achieves this.
> 
> Comment copied from Linux kernel.
> 
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  drivers/net/fec_mxc.c | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
> index 79f6737..1250d2a 100644
> --- a/drivers/net/fec_mxc.c
> +++ b/drivers/net/fec_mxc.c
> @@ -131,13 +131,25 @@ static void fec_mii_setspeed(struct ethernet_regs *eth)
>  	/*
>  	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
>  	 * and do not drop the Preamble.
> +	 *

s/filed/field/

> +	 * The i.MX28 and i.MX6 types have another filed in the MSCR (aka
> +	 * MII_SPEED) register that defines the MDIO output hold time. Earlier
> +	 * versions are RAZ there, so just ignore the difference and write the
> +	 * register always.
> +	 * The minimal hold time according to IEE802.3 (clause 22) is 10 ns.
> +	 * HOLDTIME + 1 is the number of clk cycles the fec is holding the
> +	 * output.
> +	 * The HOLDTIME bitfield takes values between 0 and 7 (inclusive).
> +	 * Given that ceil(clkrate / 5000000) <= 64, the calculation for
> +	 * holdtime cannot result in a value greater than 3.
>  	 */
> -	register u32 speed = DIV_ROUND_UP(imx_get_fecclk(), 5000000);
> +	u32 pclk = imx_get_fecclk();
> +	u32 speed = DIV_ROUND_UP(pclk, 5000000);
> +	u32 hold = DIV_ROUND_UP(pclk, 100000000) - 1;
>  #ifdef FEC_QUIRK_ENET_MAC
>  	speed--;
>  #endif
> -	speed <<= 1;
> -	writel(speed, &eth->mii_speed);
> +	writel(speed << 1 | hold << 8, &eth->mii_speed);
>  	debug("%s: mii_speed %08x\n", __func__, readl(&eth->mii_speed));
>  }
>  
> 
Otherwise,

Reviewed-by: Eric Nelson <eric@nelint.com>
Stefano Babic Jan. 3, 2016, 2:27 p.m. UTC | #2
On 08/12/2015 17:08, Eric Nelson wrote:
> Hi Mans,
> 
> On 12/08/2015 08:38 AM, Mans Rullgard wrote:
>> If the host clock frequency is higher than 100 MHz, the MDIO hold
>> time needs to be increased from its current setting of one cycle in
>> order to meet the specified minium of 10 ns.  Writing an appropriate
>> value to the HOLDTIME field of the MII_SPEED register achieves this.
>>
>> Comment copied from Linux kernel.
>>
>> Signed-off-by: Mans Rullgard <mans@mansr.com>
>> ---
>>  drivers/net/fec_mxc.c | 18 +++++++++++++++---
>>  1 file changed, 15 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
>> index 79f6737..1250d2a 100644
>> --- a/drivers/net/fec_mxc.c
>> +++ b/drivers/net/fec_mxc.c
>> @@ -131,13 +131,25 @@ static void fec_mii_setspeed(struct ethernet_regs *eth)
>>  	/*
>>  	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
>>  	 * and do not drop the Preamble.
>> +	 *
> 
> s/filed/field/

Fixed by applying.

Applied to u-boot-imx, thanks!

Best regards,
Stefano Babic
diff mbox

Patch

diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index 79f6737..1250d2a 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -131,13 +131,25 @@  static void fec_mii_setspeed(struct ethernet_regs *eth)
 	/*
 	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
 	 * and do not drop the Preamble.
+	 *
+	 * The i.MX28 and i.MX6 types have another filed in the MSCR (aka
+	 * MII_SPEED) register that defines the MDIO output hold time. Earlier
+	 * versions are RAZ there, so just ignore the difference and write the
+	 * register always.
+	 * The minimal hold time according to IEE802.3 (clause 22) is 10 ns.
+	 * HOLDTIME + 1 is the number of clk cycles the fec is holding the
+	 * output.
+	 * The HOLDTIME bitfield takes values between 0 and 7 (inclusive).
+	 * Given that ceil(clkrate / 5000000) <= 64, the calculation for
+	 * holdtime cannot result in a value greater than 3.
 	 */
-	register u32 speed = DIV_ROUND_UP(imx_get_fecclk(), 5000000);
+	u32 pclk = imx_get_fecclk();
+	u32 speed = DIV_ROUND_UP(pclk, 5000000);
+	u32 hold = DIV_ROUND_UP(pclk, 100000000) - 1;
 #ifdef FEC_QUIRK_ENET_MAC
 	speed--;
 #endif
-	speed <<= 1;
-	writel(speed, &eth->mii_speed);
+	writel(speed << 1 | hold << 8, &eth->mii_speed);
 	debug("%s: mii_speed %08x\n", __func__, readl(&eth->mii_speed));
 }