lkml.org 
[lkml]   [2018]   [Jul]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5/7] net: phy: Add support to configure clock in Broadcom iProc mdio mux
    Date
    Add support to configure the internal rate adjust register based on the
    core clock supplied through device tree in the Broadcom iProc mdio mux.

    The operating frequency of the mdio mux block is 11MHz. This is derrived
    by dividing the clock to the mdio mux with the rate adjust register.

    In some SoC's the default values of the rate adjust register do not yield
    11MHz. These SoC's are required to specify the clock via the device tree
    for proper operation.

    Signed-off-by: Arun Parameswaran <arun.parameswaran@broadcom.com>
    ---
    drivers/net/phy/mdio-mux-bcm-iproc.c | 33 ++++++++++++++++++++++++++++++++-
    1 file changed, 32 insertions(+), 1 deletion(-)

    diff --git a/drivers/net/phy/mdio-mux-bcm-iproc.c b/drivers/net/phy/mdio-mux-bcm-iproc.c
    index dc65e95..6b400dd 100644
    --- a/drivers/net/phy/mdio-mux-bcm-iproc.c
    +++ b/drivers/net/phy/mdio-mux-bcm-iproc.c
    @@ -13,7 +13,7 @@
    * You should have received a copy of the GNU General Public License
    * version 2 (GPLv2) along with this source code.
    */
    -
    +#include <linux/clk.h>
    #include <linux/platform_device.h>
    #include <linux/device.h>
    #include <linux/of_mdio.h>
    @@ -22,6 +22,10 @@
    #include <linux/mdio-mux.h>
    #include <linux/delay.h>

    +#define MDIO_RATE_ADJ_EXT_OFFSET 0x000
    +#define MDIO_RATE_ADJ_INT_OFFSET 0x004
    +#define MDIO_RATE_ADJ_DIVIDENT_SHIFT 16
    +
    #define MDIO_PARAM_OFFSET 0x23c
    #define MDIO_PARAM_MIIM_CYCLE 29
    #define MDIO_PARAM_INTERNAL_SEL 25
    @@ -44,13 +48,32 @@
    #define BUS_MAX_ADDR 32
    #define EXT_BUS_START_ADDR 16

    +#define MDIO_OPERATING_FREQUENCY 11000000
    +#define MDIO_RATE_ADJ_DIVIDENT 1
    +
    struct iproc_mdiomux_desc {
    void *mux_handle;
    void __iomem *base;
    struct device *dev;
    struct mii_bus *mii_bus;
    + struct clk *core_clk;
    };

    +static void mdio_mux_iproc_config_clk(struct iproc_mdiomux_desc *md)
    +{
    + u32 val;
    + u32 divisor;
    +
    + if (md->core_clk) {
    + divisor = clk_get_rate(md->core_clk) / MDIO_OPERATING_FREQUENCY;
    + divisor = divisor / (MDIO_RATE_ADJ_DIVIDENT + 1);
    + val = divisor;
    + val |= MDIO_RATE_ADJ_DIVIDENT << MDIO_RATE_ADJ_DIVIDENT_SHIFT;
    + writel(val, md->base + MDIO_RATE_ADJ_EXT_OFFSET);
    + writel(val, md->base + MDIO_RATE_ADJ_INT_OFFSET);
    + }
    +}
    +
    static int iproc_mdio_wait_for_idle(void __iomem *base, bool result)
    {
    unsigned int timeout = 1000; /* loop for 1s */
    @@ -175,6 +198,12 @@ static int mdio_mux_iproc_probe(struct platform_device *pdev)
    return PTR_ERR(md->base);
    }

    + md->core_clk = devm_clk_get(&pdev->dev, NULL);
    + if (IS_ERR(md->core_clk)) {
    + dev_info(&pdev->dev, "core_clk not specified\n");
    + md->core_clk = NULL;
    + }
    +
    md->mii_bus = mdiobus_alloc();
    if (!md->mii_bus) {
    dev_err(&pdev->dev, "mdiomux bus alloc failed\n");
    @@ -206,6 +235,8 @@ static int mdio_mux_iproc_probe(struct platform_device *pdev)
    goto out_register;
    }

    + mdio_mux_iproc_config_clk(md);
    +
    dev_info(md->dev, "iProc mdiomux registered\n");
    return 0;

    --
    1.9.1
    \
     
     \ /
      Last update: 2018-07-26 20:37    [W:4.222 / U:0.124 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site