Skip to contentSkip to conversation

net: phy: mscc: handle the clkout control on some phy variants

PATCH In review Heiko Stuebner 2 participants 2 messages Jun 8, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: phy: mscc: handle the clkout control on some phy variants

From: Heiko Stuebner <[email protected]>

At least VSC8530/8531/8540/8541 contain a clock output that can emit a predefined rate of 25, 50 or 125MHz.

This may then feed back into the network interface as source clock. So follow the example the at803x already set and introduce a vsc8531,clk-out-frequency property to set that output.

---
 .../bindings/net/mscc-phy-vsc8531.txt         |  3 +
 drivers/net/phy/mscc/mscc.h                   |  9 ++
 drivers/net/phy/mscc/mscc_main.c              | 93 +++++++++++++++++--
 3 files changed, 98 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt +3 -0
index 5ff37c68c941..4a1f50ae48e1 100644
@@ -1,6 +1,8 @@
 * Microsemi - vsc8531 Giga bit ethernet phy
 
 Optional properties:
+- vsc8531,clk-out-frequency: Clock output frequency in Hertz.
+			  Should be one of 25000000, 50000000, 125000000
 - vsc8531,vddmac	: The vddmac in mV. Allowed values is listed
 			  in the first row of Table 1 (below).
 			  This property is only used in combination
@@ -63,6 +65,7 @@ Example:
 
         vsc8531_0: ethernet-phy@0 {
                 compatible = "ethernet-phy-id0007.0570";
+                vsc8531,clk-out-frequency = <125000000>;
                 vsc8531,vddmac		= <3300>;
                 vsc8531,edge-slowdown	= <7>;
                 vsc8531,led-0-mode	= <LINK_1000_ACTIVITY>;
drivers/net/phy/mscc/mscc.h +9 -0
index 414e3b31bb1f..c8c395a041c2 100644
@@ -218,6 +218,13 @@ enum rgmii_clock_delay {
 #define INT_MEM_DATA_M			  0x00ff
 #define INT_MEM_DATA(x)			  (INT_MEM_DATA_M & (x))
 
+#define MSCC_CLKOUT_CNTL		  13
+#define CLKOUT_ENABLE			  BIT(15)
+#define CLKOUT_FREQ_MASK		  GENMASK(14, 13)
+#define CLKOUT_FREQ_25M			  (0x0 << 13)
+#define CLKOUT_FREQ_50M			  (0x1 << 13)
+#define CLKOUT_FREQ_125M		  (0x2 << 13)
+
 #define MSCC_PHY_PROC_CMD		  18
 #define PROC_CMD_NCOMPLETED		  0x8000
 #define PROC_CMD_FAILED			  0x4000
@@ -361,6 +368,8 @@ struct vsc8531_private {
 	 */
 	unsigned int base_addr;
 
+	u32 clkout_rate;
+
 #if IS_ENABLED(CONFIG_MACSEC)
 	/* MACsec fields:
 	 * - One SecY per device (enforced at the s/w implementation level)
drivers/net/phy/mscc/mscc_main.c +86 -7

159 lines not on this page · raw message

Signature · 1 line
2.26.2
maintainer
#1 lore raw
Quoted 21 lines · Heiko Stuebner
drivers/net/phy/mscc/mscc_main.c +21 -0
+static int vsc8531_probe(struct phy_device *phydev)
+{
+	struct vsc8531_private *vsc8531;
+	int rate_magic;
+	u32 default_mode[2] = {VSC8531_LINK_1000_ACTIVITY,
+	   VSC8531_LINK_100_ACTIVITY};
+
+	rate_magic = vsc85xx_edge_rate_magic_get(phydev);
+	if (rate_magic < 0)
+		return rate_magic;
+
+	vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
+	if (!vsc8531)
+		return -ENOMEM;
+
+	phydev->priv = vsc8531;
+
+	vsc8531->rate_magic = rate_magic;
+	vsc8531->nleds = 2;
+	vsc8531->supp_led_modes = VSC85XX_SUPP_LED_MODES;
+	vsc8531->hw_stats = vsc85xx_hw_stats;

drivers/net/phy/mscc/mscc_main.c static int vsc8514_probe(struct phy_device *phydev) · line 2088

Quoted 10 lines
drivers/net/phy/mscc/mscc_main.c +10 -0
+	vsc8531->nstats = ARRAY_SIZE(vsc85xx_hw_stats);
+	vsc8531->stats = devm_kcalloc(&phydev->mdio.dev, vsc8531->nstats,
+				      sizeof(u64), GFP_KERNEL);
+	if (!vsc8531->stats)
+		return -ENOMEM;
+
+	vsc8531_dt_clkout_rate_get(phydev);
+
+	return vsc85xx_dt_led_modes_get(phydev, default_mode);
+}

Hi Heiko

The clock change itself looks O.K. Maybe we want to standardize on the name of the DT property, since it could be shared across all PHYs which have a clock output?

Could you add another patch first which refactors the _probe() functions. There is a lot of repeated code which could be put into a helper.

Thanks
Andrew