Skip to contentSkip to conversation

phylib: Add of_phy_attach

PATCH Superseded [email protected] 2 participants 2 messages Nov 26, 2013 – Nov 27, 2013

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 5/5 phylib: Add of_phy_attach

From: Andy Fleming <[email protected]>

10G PHYs don't currently support running the state machine, which is implicitly setup via of_phy_connect(). Therefore, it is necessary to implement an OF version of phy_attach(), which does everything except start the state machine.

---
v2: no changes.

 drivers/of/of_mdio.c    | 19 +++++++++++++++++++
 include/linux/of_mdio.h |  9 +++++++++
 2 files changed, 28 insertions(+)
drivers/of/of_mdio.c +19 -0
index d5a57a9..21076ac 100644
@@ -247,3 +247,22 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
 	return IS_ERR(phy) ? NULL : phy;
 }
 EXPORT_SYMBOL(of_phy_connect_fixed_link);
+
+/**
+ * of_phy_attach - Attach to a PHY without starting the state machine
+ * @dev: pointer to net_device claiming the phy
+ * @phy_np: Node pointer for the PHY
+ * @flags: flags to pass to the PHY
+ * @iface: PHY data interface type
+ */
+struct phy_device *of_phy_attach(struct net_device *dev,
+		struct device_node *phy_np, u32 flags, phy_interface_t iface)
+{
+	struct phy_device *phy = of_phy_find_device(phy_np);
+
+	if (!phy)
+		return NULL;
+
+	return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy;
+}
+EXPORT_SYMBOL(of_phy_attach);
include/linux/of_mdio.h +9 -0
index 8163107..108583a 100644
@@ -19,6 +19,9 @@ extern struct phy_device *of_phy_connect(struct net_device *dev,
 					 struct device_node *phy_np,
 					 void (*hndlr)(struct net_device *),
 					 u32 flags, phy_interface_t iface);
+struct phy_device *of_phy_attach(struct net_device *dev,
+				 struct device_node *phy_np, u32 flags,
+				 phy_interface_t iface);
 extern struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
 					 void (*hndlr)(struct net_device *),
 					 phy_interface_t iface);
@@ -44,6 +47,12 @@ static inline struct phy_device *of_phy_connect(struct net_device *dev,
 	return NULL;
 }
 
+static inline struct phy_device *of_phy_attach(struct net_device *dev,
+		struct device_node *phy_np, u32 flags, phy_interface_t iface)
+{
+	return NULL;
+}
+
 static inline struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
 							   void (*hndlr)(struct net_device *),
 							   phy_interface_t iface)
Signature · 1 line
1.8.4.1
Acked-by on v2 5/5
#1 lore raw

2013/11/26 <[email protected]>:

Quoted 9 lines

From: Andy Fleming <[email protected]>

10G PHYs don't currently support running the state machine, which is implicitly setup via of_phy_connect(). Therefore, it is necessary to implement an OF version of phy_attach(), which does everything except start the state machine.

Quoted 65 lines

---
v2: no changes.

 drivers/of/of_mdio.c    | 19 +++++++++++++++++++
 include/linux/of_mdio.h |  9 +++++++++
 2 files changed, 28 insertions(+)
drivers/of/of_mdio.c +19 -0
index d5a57a9..21076ac 100644
@@ -247,3 +247,22 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
        return IS_ERR(phy) ? NULL : phy;
 }
 EXPORT_SYMBOL(of_phy_connect_fixed_link);
+
+/**
+ * of_phy_attach - Attach to a PHY without starting the state machine
+ * @dev: pointer to net_device claiming the phy
+ * @phy_np: Node pointer for the PHY
+ * @flags: flags to pass to the PHY
+ * @iface: PHY data interface type
+ */
+struct phy_device *of_phy_attach(struct net_device *dev,
+               struct device_node *phy_np, u32 flags, phy_interface_t iface)
+{
+       struct phy_device *phy = of_phy_find_device(phy_np);
+
+       if (!phy)
+               return NULL;
+
+       return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy;
+}
+EXPORT_SYMBOL(of_phy_attach);
include/linux/of_mdio.h +9 -1
index 8163107..108583a 100644
@@ -19,6 +19,9 @@ extern struct phy_device *of_phy_connect(struct net_device *dev,
                                         struct device_node *phy_np,
                                         void (*hndlr)(struct net_device *),
                                         u32 flags, phy_interface_t iface);
+struct phy_device *of_phy_attach(struct net_device *dev,
+                                struct device_node *phy_np, u32 flags,
+                                phy_interface_t iface);
 extern struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
                                         void (*hndlr)(struct net_device *),
                                         phy_interface_t iface);
@@ -44,6 +47,12 @@ static inline struct phy_device *of_phy_connect(struct net_device *dev,
        return NULL;
 }
 
+static inline struct phy_device *of_phy_attach(struct net_device *dev,
+               struct device_node *phy_np, u32 flags, phy_interface_t iface)
+{
+       return NULL;
+}
+
 static inline struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
                                                           void (*hndlr)(struct net_device *),
                                                           phy_interface_t iface)
--

1.8.4.1

Signature · 1 line
Florian