mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Daniel Golle <daniel@makrotopia.org>
Cc: Bo-Cun Chen <bc-bocun.chen@mediatek.com>,
	Felix Fietkau <nbd@nbd.name>, Sean Wang <sean.wang@mediatek.com>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH net 1/5] net: ethernet: mtk_eth_soc: revise mdc divider configuration
Date: Mon, 14 Apr 2025 20:30:04 +0200	[thread overview]
Message-ID: <6c36505c-7af3-49f5-9141-8a655f90a2f9@lunn.ch> (raw)
In-Reply-To: <08498e31e830cf0ee1ceb4fc1313d5c528a69150.1744654076.git.daniel@makrotopia.org>

On Mon, Apr 14, 2025 at 07:11:20PM +0100, Daniel Golle wrote:
> From: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
> 
> In the current method, the MDC divider was reset to the default setting
> of 2.5MHz after the NETSYS SER. Therefore, we need to move the MDC
> divider configuration function to mtk_hw_init().
> 
> Fixes: c0a440031d431 ("net: ethernet: mtk_eth_soc: set MDIO bus clock frequency")
> Signed-off-by: Bo-Cun Chen <bc-bocun.chen@mediatek.com>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 60 ++++++++++++++-------
>  1 file changed, 42 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 43197b28b3e74..fd643cc1b7dd2 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -871,11 +871,11 @@ static const struct phylink_mac_ops mtk_phylink_ops = {
>  	.mac_enable_tx_lpi = mtk_mac_enable_tx_lpi,
>  };
>  
> -static int mtk_mdio_init(struct mtk_eth *eth)
> +static int mtk_mdio_config(struct mtk_eth *eth)
>  {
>  	unsigned int max_clk = 2500000, divider;
>  	struct device_node *mii_np;
> -	int ret;
> +	int ret = 0;
>  	u32 val;
>  
>  	mii_np = of_get_available_child_by_name(eth->dev->of_node, "mdio-bus");
> @@ -884,22 +884,6 @@ static int mtk_mdio_init(struct mtk_eth *eth)
>  		return -ENODEV;
>  	}
>  
> -	eth->mii_bus = devm_mdiobus_alloc(eth->dev);
> -	if (!eth->mii_bus) {
> -		ret = -ENOMEM;
> -		goto err_put_node;
> -	}
> -
> -	eth->mii_bus->name = "mdio";
> -	eth->mii_bus->read = mtk_mdio_read_c22;
> -	eth->mii_bus->write = mtk_mdio_write_c22;
> -	eth->mii_bus->read_c45 = mtk_mdio_read_c45;
> -	eth->mii_bus->write_c45 = mtk_mdio_write_c45;
> -	eth->mii_bus->priv = eth;
> -	eth->mii_bus->parent = eth->dev;
> -
> -	snprintf(eth->mii_bus->id, MII_BUS_ID_SIZE, "%pOFn", mii_np);
> -
>  	if (!of_property_read_u32(mii_np, "clock-frequency", &val)) {
>  		if (val > MDC_MAX_FREQ || val < MDC_MAX_FREQ / MDC_MAX_DIVIDER) {
>  			dev_err(eth->dev, "MDIO clock frequency out of range");
> @@ -922,6 +906,42 @@ static int mtk_mdio_init(struct mtk_eth *eth)
>  
>  	dev_dbg(eth->dev, "MDC is running on %d Hz\n", MDC_MAX_FREQ / divider);
>  
> +err_put_node:
> +	of_node_put(mii_np);
> +	return ret;
> +}
> +
> +static int mtk_mdio_init(struct mtk_eth *eth)
> +{
> +	struct device_node *mii_np;
> +	int ret;
> +
> +	mii_np = of_get_child_by_name(eth->dev->of_node, "mdio-bus");
> +	if (!mii_np) {
> +		dev_err(eth->dev, "no %s child node found", "mdio-bus");
> +		return -ENODEV;
> +	}
> +
> +	if (!of_device_is_available(mii_np)) {
> +		ret = -ENODEV;
> +		goto err_put_node;
> +	}

It seems like you end up doing these checks twice. In theory it might
change between the calls, but it is very unlikely? Maybe just keep
node reference returned by of_get_child_by_name() and release it in
mtk_mdio_cleanup()?

Or calculate the divider in mtk_mdio_init() as is, but store it away
in struct mtk_eth, so you don't need to redo all the DT parsing?

	Andrew

      parent reply	other threads:[~2025-04-14 18:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14 18:11 Daniel Golle
2025-04-14 18:11 ` [PATCH net 2/5] net: ethernet: mtk_eth_soc: correct the max weight of the queue limit for 100Mbps Daniel Golle
2025-04-14 18:12 ` [PATCH net 3/5] net: ethernet: mtk_eth_soc: revise QDMA packet scheduler settings Daniel Golle
2025-04-14 18:12 ` [PATCH net 4/5] net: ethernet: mtk_eth_soc: net: revise NETSYSv3 hardware configuration Daniel Golle
2025-04-14 18:12 ` [PATCH net 5/5] net: ethernet: mtk_eth_soc: convert cap_bit in mtk_eth_muxc struct to u64 Daniel Golle
2025-04-14 18:33   ` Andrew Lunn
2025-04-14 18:30 ` Andrew Lunn [this message]

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=6c36505c-7af3-49f5-9141-8a655f90a2f9@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=andrew+netdev@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bc-bocun.chen@mediatek.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=lorenzo@kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sean.wang@mediatek.com \
    /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

all inboxes | Powered by JetHome®