• Christian Marangi's avatar
    net: mdio: ipq4019: add support for clock-frequency property · bdce82e9
    Christian Marangi authored
    The IPQ4019 MDIO internally divide the clock feed by AHB based on the
    MDIO_MODE reg. On reset or power up, the default value for the
    divider is 0xff that reflect the divider set to /256.
    
    This makes the MDC run at a very low rate, that is, considering AHB is
    always fixed to 100Mhz, a value of 390KHz.
    
    This hasn't have been a problem as MDIO wasn't used for time sensitive
    operation, it is now that on IPQ807x is usually mounted with PHY that
    requires MDIO to load their firmware (example Aquantia PHY).
    
    To handle this problem and permit to set the correct designed MDC
    frequency for the SoC add support for the standard "clock-frequency"
    property for the MDIO node.
    
    The divider supports value from /1 to /256 and the common value are to
    set it to /16 to reflect 6.25Mhz or to /8 on newer platform to reflect
    12.5Mhz.
    
    To scan if the requested rate is supported by the divider, loop with
    each supported divider and stop when the requested rate match the final
    rate with the current divider. An error is returned if the rate doesn't
    match any value.
    
    On MDIO reset, the divider is restored to the requested value to prevent
    any kind of downclocking caused by the divider reverting to a default
    value.
    
    To follow 802.3 spec of 2.5MHz of default value, if divider is set at
    /256 and "clock-frequency" is not set in DT, assume nobody set the
    divider and try to find the closest MDC rate to 2.5MHz. (in the case of
    AHB set to 100MHz, it's 1.5625MHz)
    
    While at is also document other bits of the MDIO_MODE reg to have a
    clear idea of what is actually applied there.
    
    Documentation of some BITs is skipped as they are marked as reserved and
    their usage is not clear (RES 11:9 GENPHY 16:13 RES1 19:17)
    Signed-off-by: default avatarChristian Marangi <ansuelsmth@gmail.com>
    Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    bdce82e9
mdio-ipq4019.c 10.1 KB