linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: Andy Chiu <andy.chiu@sifive.com>
Cc: davem@davemloft.net, kuba@kernel.org, michal.simek@xilinx.com,
	radhey.shyam.pandey@xilinx.com, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org,
	pabeni@redhat.com, edumazet@google.com, andy.chiu@sifive.com,
	greentime.hu@sifive.com
Subject: Re: [PATCH net-next 1/2] net:xilinx_axi: set mdio frequency according to DT
Date: Thu, 20 Oct 2022 13:35:06 +0200	[thread overview]
Message-ID: <5953785.aeNJFYEL58@steina-w> (raw)
In-Reply-To: <20221020094106.559266-2-andy.chiu@sifive.com>

Hi,

Am Donnerstag, 20. Oktober 2022, 11:41:05 CEST schrieb Andy Chiu:
> Some FPGA platforms has 80KHz MDIO bus frequency constraint when
> conecting Ethernet to its on-board external Marvell PHY. Thus, we may
> have to set MDIO clock according to the DT. Otherwise, use the default
> 2.5 MHz, as specified by 802.3, if the entry is not present.
> 
> Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
> Reviewed-by: Greentime Hu <greentime.hu@sifive.com>
> ---
>  .../net/ethernet/xilinx/xilinx_axienet_mdio.c | 25 ++++++++++++++++---
>  1 file changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
> b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c index
> 0b3b6935c558..d07c39d3bcf0 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
> @@ -18,6 +18,7 @@
>  #include "xilinx_axienet.h"
> 
>  #define MAX_MDIO_FREQ		2500000 /* 2.5 MHz */
> +#define MDIO_CLK_DIV_MASK	0x3f /* bits[5:0] */
>  #define DEFAULT_HOST_CLOCK	150000000 /* 150 MHz */
> 
>  /* Wait till MDIO interface is ready to accept a new transaction.*/
> @@ -155,7 +156,9 @@ static int axienet_mdio_write(struct mii_bus *bus, int
> phy_id, int reg, **/
>  int axienet_mdio_enable(struct axienet_local *lp)
>  {
> +	u32 clk_div;
>  	u32 host_clock;
> +	u32 mdio_freq;
> 
>  	lp->mii_clk_div = 0;
> 
> @@ -184,6 +187,13 @@ int axienet_mdio_enable(struct axienet_local *lp)
>  			    host_clock);
>  	}
> 
> +	if (of_property_read_u32(lp->dev->of_node, "xlnx,mdio-freq",
> +				 &mdio_freq)) {
> +		mdio_freq = MAX_MDIO_FREQ;
> +		netdev_info(lp->ndev, "Setting default mdio clock to 
%u\n",
> +			    mdio_freq);

I would opt to print this message only if using non-default frequency.

Best regards,
Alexander

> +	}
> +
>  	/* clk_div can be calculated by deriving it from the equation:
>  	 * fMDIO = fHOST / ((1 + clk_div) * 2)
>  	 *
> @@ -209,13 +219,20 @@ int axienet_mdio_enable(struct axienet_local *lp)
>  	 * "clock-frequency" from the CPU
>  	 */
> 
> -	lp->mii_clk_div = (host_clock / (MAX_MDIO_FREQ * 2)) - 1;
> +	clk_div = (host_clock / (mdio_freq * 2)) - 1;
>  	/* If there is any remainder from the division of
> -	 * fHOST / (MAX_MDIO_FREQ * 2), then we need to add
> +	 * fHOST / (mdio_freq * 2), then we need to add
>  	 * 1 to the clock divisor or we will surely be above 2.5 MHz
>  	 */
> -	if (host_clock % (MAX_MDIO_FREQ * 2))
> -		lp->mii_clk_div++;
> +	if (host_clock % (mdio_freq * 2))
> +		clk_div++;
> +
> +	/* Check for overflow of mii_clk_div */
> +	if (clk_div & ~MDIO_CLK_DIV_MASK) {
> +		netdev_dbg(lp->ndev, "MDIO clock divisor overflow, 
setting to maximum
> value\n"); +		clk_div = MDIO_CLK_DIV_MASK;
> +	}
> +	lp->mii_clk_div = (u8)clk_div;
> 
>  	netdev_dbg(lp->ndev,
>  		   "Setting MDIO clock divisor to %u/%u Hz host clock.
\n",





_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-10-20 12:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20  9:41 [PATCH net-next 0/2] net:axienet: Add a DT property to configure frequency of the MDIO bus Andy Chiu
2022-10-20  9:41 ` [PATCH net-next 1/2] net:xilinx_axi: set mdio frequency according to DT Andy Chiu
2022-10-20 11:35   ` Alexander Stein [this message]
2022-10-20  9:41 ` [PATCH net-next 2/2] dt-bindings: add mdio frequency description Andy Chiu
2022-10-20 10:39   ` Michal Simek
2022-10-21  2:20     ` Rob Herring
2022-10-23 15:04       ` Andy Chiu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5953785.aeNJFYEL58@steina-w \
    --to=alexander.stein@ew.tq-group.com \
    --cc=andy.chiu@sifive.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=greentime.hu@sifive.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=michal.simek@xilinx.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=radhey.shyam.pandey@xilinx.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).