Linux-Amlogic Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: jbrunet@baylibre.com (Jerome Brunet)
To: linus-amlogic@lists.infradead.org
Subject: [RFT net-next v4 1/5] net: stmmac: dwmac-meson8b: only configure the clocks in RGMII mode
Date: Mon, 15 Jan 2018 12:46:31 +0100	[thread overview]
Message-ID: <1516016791.2608.12.camel@baylibre.com> (raw)
In-Reply-To: <20180114214858.7217-2-martin.blumenstingl@googlemail.com>

On Sun, 2018-01-14 at 22:48 +0100, Martin Blumenstingl wrote:
> 

[...]

> @@ -204,12 +200,24 @@ static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac)
>  
>  		meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TXDLY_MASK,
>  					tx_dly_val << PRG_ETH0_TXDLY_SHIFT);
> +
> +		ret = clk_prepare_enable(dwmac->m25_div_clk);
> +		if (ret) {
> +			dev_err(&dwmac->pdev->dev, "failed to enable the PHY clock\n");
> +			return ret;
> +		}
> +
> +		/* Generate the 25MHz RGMII clock for the PHY */
> +		ret = clk_set_rate(dwmac->m25_div_clk, 25 * 1000 * 1000);
> +		if (ret) {
> +			clk_disable_unprepare(dwmac->m25_div_clk);
> +
> +			dev_err(&dwmac->pdev->dev, "failed to set PHY clock\n");
> +			return ret;
> +		}
>  		break;
>  
>  	case PHY_INTERFACE_MODE_RMII:
> -		/* Use the rate of the mux clock for the internal RMII PHY */
> -		clk_rate = clk_get_rate(dwmac->m250_mux_clk);
> -
>  		/* disable RGMII mode -> enables RMII mode */
>  		meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_RGMII_MODE,
>  					0);
> @@ -231,20 +239,6 @@ static int meson8b_init_prg_eth(struct meson8b_dwmac *dwmac)
>  		return -EINVAL;
>  	}
>  
> -	ret = clk_prepare_enable(dwmac->m25_div_clk);
> -	if (ret) {
> -		dev_err(&dwmac->pdev->dev, "failed to enable the PHY clock\n");
> -		return ret;
> -	}
> -
> -	ret = clk_set_rate(dwmac->m25_div_clk, clk_rate);
> -	if (ret) {
> -		clk_disable_unprepare(dwmac->m25_div_clk);
> -
> -		dev_err(&dwmac->pdev->dev, "failed to set PHY clock\n");
> -		return ret;
> -	}
> -

I would set the rate first then enable. Less chances of glitches and no need to
call clk_disable_unprepare if it fails

>  	/* enable TX_CLK and PHY_REF_CLK generator */
>  	meson8b_dwmac_mask_bits(dwmac, PRG_ETH0, PRG_ETH0_TX_AND_PHY_REF_CLK,
>  				PRG_ETH0_TX_AND_PHY_REF_CLK);
> @@ -294,7 +288,7 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
>  				 &dwmac->tx_delay_ns))
>  		dwmac->tx_delay_ns = 2;
>  
> -	ret = meson8b_init_clk(dwmac);
> +	ret = meson8b_init_rgmii_tx_clk(dwmac);
>  	if (ret)
>  		goto err_remove_config_dt;
>  
> @@ -311,7 +305,8 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
>  	return 0;
>  
>  err_clk_disable:
> -	clk_disable_unprepare(dwmac->m25_div_clk);
> +	if (phy_interface_mode_is_rgmii(dwmac->phy_mode))
> +		clk_disable_unprepare(dwmac->m25_div_clk);
>  err_remove_config_dt:
>  	stmmac_remove_config_dt(pdev, plat_dat);
>  
> @@ -322,7 +317,8 @@ static int meson8b_dwmac_remove(struct platform_device *pdev)
>  {
>  	struct meson8b_dwmac *dwmac = get_stmmac_bsp_priv(&pdev->dev);
>  
> -	clk_disable_unprepare(dwmac->m25_div_clk);
> +	if (phy_interface_mode_is_rgmii(dwmac->phy_mode))
> +		clk_disable_unprepare(dwmac->m25_div_clk);

if you use
devm_add_action_or_reset(dev, (void(*)(void *))clk_disable_unprepare,
?			 YOUR-CLK)

after enabling the clock, your can discard these conditional hunks.

>  
>  	return stmmac_pltfr_remove(pdev);
>  }

  reply	other threads:[~2018-01-15 11:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-14 21:48 [RFT net-next v4 0/5] dwmac-meson8b: clock fixes for Meson8b Martin Blumenstingl
2018-01-14 21:48 ` [RFT net-next v4 1/5] net: stmmac: dwmac-meson8b: only configure the clocks in RGMII mode Martin Blumenstingl
2018-01-15 11:46   ` Jerome Brunet [this message]
2018-01-15 12:04     ` Martin Blumenstingl
2018-01-14 21:48 ` [RFT net-next v4 2/5] net: stmmac: dwmac-meson8b: simplify generating the clock names Martin Blumenstingl
2018-01-15 11:46   ` Jerome Brunet
2018-01-15 12:02     ` Martin Blumenstingl
2018-01-15 12:36       ` Jerome Brunet
2018-01-14 21:48 ` [RFT net-next v4 3/5] net: stmmac: dwmac-meson8b: fix internal RGMII clock configuration Martin Blumenstingl
2018-01-15 11:49   ` Jerome Brunet
2018-01-15 12:08     ` Martin Blumenstingl
2018-01-15 12:45       ` Jerome Brunet
     [not found]   ` <CAFBinCDxrxuow-e3aofu6k0ShQdCehVbAJH_u3b26RKN6D0Hug@mail.gmail.com>
2018-01-18 20:05     ` Martin Blumenstingl
2018-01-14 21:48 ` [RFT net-next v4 4/5] net: stmmac: dwmac-meson8b: fix setting the RGMII TX clock on Meson8b Martin Blumenstingl
2018-01-14 21:48 ` [RFT net-next v4 5/5] net: stmmac: dwmac-meson8b: propagate rate changes to the parent clock Martin Blumenstingl
2018-01-15 11:50   ` Jerome Brunet
2018-01-15 11:45 ` [RFT net-next v4 0/5] dwmac-meson8b: clock fixes for Meson8b Jerome Brunet

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=1516016791.2608.12.camel@baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=linus-amlogic@lists.infradead.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