Subject: Re: [PATCH v3 net] net: phy: micrel: Dynamically control external clock of KSZ PHY

From: Jakub Kicinski <[email-masked]>
Date: Mon, 9 Dec 2024 18:14:51 -0800

On Fri,  6 Dec 2024 09:21:13 +0800 Wei Fang wrote:
> On the i.MX6ULL-14x14-EVK board, enet1_ref and enet2_ref are used as the
> clock sources for two external KSZ PHYs. However, after closing the two
> FEC ports, the clk_enable_count of the enet1_ref and enet2_ref clocks is
> not 0. The root cause is that since the commit 985329462723 ("net: phy:
> micrel: use devm_clk_get_optional_enabled for the rmii-ref clock"), the
> external clock of KSZ PHY has been enabled when the PHY driver probes,
> and it can only be disabled when the PHY driver is removed. This causes
> the clock to continue working when the system is suspended or the network
> port is down.
> 
> To solve this problem, the clock is enabled when phy_driver::resume() is
> called, and the clock is disabled when phy_driver::suspend() is called.
> Since phy_driver::resume() and phy_driver::suspend() are not called in
> pairs, an additional clk_enable flag is added. When phy_driver::suspend()
> is called, the clock is disabled only if clk_enable is true. Conversely,
> when phy_driver::resume() is called, the clock is enabled if clk_enable
> is false.

Sorry that nobody replied to you but yes, I believe the simpler fix you
proposed here:
https://lore.kernel.org/all/[email-masked]/
is better for net. In net-next we can try to keep the clock enabled
and/or try to fix the imbalance in resume calls that forces you to track
manually if the clock was enabled.