diff mbox series

[net-next,1/4] net: phylib: add getting reference clock

Message ID 97e1f180-ae4e-7314-a736-748bb6746d82@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: phy: move getting (R)MII refclock to phylib | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 426 this patch: 426
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 300 this patch: 300
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 412 this patch: 412
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 35 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Heiner Kallweit March 24, 2023, 6:03 p.m. UTC
Few PHY drivers (smsc, bcm7xxx, micrel) get and enable the (R)MII
reference clock in their probe() callback. Move this common
functionality to phylib, this allows to remove it from the drivers
in a follow-up.

Note that we now enable the reference clock before deasserting the
PHY reset signal. Maybe this even allows us to get rid of
phy_reset_after_clk_enable().

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy_device.c | 6 ++++++
 include/linux/phy.h          | 5 +++++
 2 files changed, 11 insertions(+)

Comments

Florian Fainelli March 24, 2023, 7:10 p.m. UTC | #1
On 3/24/23 11:03, Heiner Kallweit wrote:
> Few PHY drivers (smsc, bcm7xxx, micrel) get and enable the (R)MII
> reference clock in their probe() callback. Move this common
> functionality to phylib, this allows to remove it from the drivers
> in a follow-up.
> 
> Note that we now enable the reference clock before deasserting the
> PHY reset signal. Maybe this even allows us to get rid of
> phy_reset_after_clk_enable().
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>   drivers/net/phy/phy_device.c | 6 ++++++
>   include/linux/phy.h          | 5 +++++
>   2 files changed, 11 insertions(+)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index c0760cbf5..6668487e2 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -3096,6 +3096,12 @@ static int phy_probe(struct device *dev)
>   	if (phydrv->flags & PHY_IS_INTERNAL)
>   		phydev->is_internal = true;
>   
> +	phydev->refclk = devm_clk_get_optional_enabled(dev, NULL);
> +	if (IS_ERR(phydev->refclk)) {
> +		err = PTR_ERR(phydev->refclk);
> +		goto out;
> +	}

My comment in patch 2 should have been there, I would add a flag that 
the PHY driver can set that tells the core that it is OK to fetch the 
clock. In the case of bcm7xxx.c is it not the reference clock, so while 
we can use phydev->refclk for the same purpose, it could be a tad confusing.
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index c0760cbf5..6668487e2 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -3096,6 +3096,12 @@  static int phy_probe(struct device *dev)
 	if (phydrv->flags & PHY_IS_INTERNAL)
 		phydev->is_internal = true;
 
+	phydev->refclk = devm_clk_get_optional_enabled(dev, NULL);
+	if (IS_ERR(phydev->refclk)) {
+		err = PTR_ERR(phydev->refclk);
+		goto out;
+	}
+
 	/* Deassert the reset signal */
 	phy_device_reset(phydev, 0);
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index fefd5091b..6d6129674 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -11,6 +11,7 @@ 
 #ifndef __PHY_H
 #define __PHY_H
 
+#include <linux/clk.h>
 #include <linux/compiler.h>
 #include <linux/spinlock.h>
 #include <linux/ethtool.h>
@@ -595,6 +596,7 @@  struct macsec_ops;
  * @interface: enum phy_interface_t value
  * @skb: Netlink message for cable diagnostics
  * @nest: Netlink nest used for cable diagnostics
+ * @refclk: External (R)MII reference clock
  * @ehdr: nNtlink header for cable diagnostics
  * @phy_led_triggers: Array of LED triggers
  * @phy_num_led_triggers: Number of triggers in @phy_led_triggers
@@ -719,6 +721,9 @@  struct phy_device {
 	void *ehdr;
 	struct nlattr *nest;
 
+	/* external (R)MII reference clock */
+	struct clk *refclk;
+
 	/* Interrupt and Polling infrastructure */
 	struct delayed_work state_queue;