Skip to contentSkip to conversation

of: add of_parse_phandle() helper for parsing phandle properties

PATCH In review Grant Likely 3 participants 21 messages Mar 19, 2009

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

PATCH 1/9 of: add of_parse_phandle() helper for parsing phandle properties

From: Grant Likely <[email protected]>

of_parse_phandle() is a helper function to read and parse a phandle property and return a pointer to the resulting device_node.

---

 drivers/of/base.c  |   23 +++++++++++++++++++++++
 include/linux/of.h |    3 +++
 2 files changed, 26 insertions(+), 0 deletions(-)
drivers/of/base.c +23 -0
index cd17092..1eaada4 100644
@@ -494,6 +494,29 @@ int of_modalias_node(struct device_node *node, char *modalias, int len)
 EXPORT_SYMBOL_GPL(of_modalias_node);
 
 /**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ *         the table
+ *
+ * Returns the device_node pointer pointed to by the phandle, or NULL
+ */
+struct device_node *
+of_parse_phandle(struct device_node *np, const char *phandle_name, int index)
+{
+	const phandle *phandle;
+	int size;
+
+	phandle = of_get_property(np, phandle_name, &size);
+	if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+		return NULL;
+
+	return of_find_node_by_phandle(phandle[index]);
+}
+EXPORT_SYMBOL(of_parse_phandle);
+
+/**
  * of_parse_phandles_with_args - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
  * @list_name:	property name that contains a list
include/linux/of.h +3 -0
index 6a7efa2..7be2d10 100644
@@ -77,6 +77,9 @@ extern int of_n_size_cells(struct device_node *np);
 extern const struct of_device_id *of_match_node(
 	const struct of_device_id *matches, const struct device_node *node);
 extern int of_modalias_node(struct device_node *node, char *modalias, int len);
+extern struct device_node *of_parse_phandle(struct device_node *np,
+					    const char *phandle_name,
+					    int index);
 extern int of_parse_phandles_with_args(struct device_node *np,
 	const char *list_name, const char *cells_name, int index,
 	struct device_node **out_node, const void **out_args);
#1 lore raw

PATCH 2/9 phylib: rework to prepare for OF registration of PHYs

From: Grant Likely <[email protected]>

This patch makes changes in preparation for supporting open firmware device tree descriptions of MDIO busses. Changes include:
- Cleanup handling of phy_map[] entries; they are already NULLed when registering and so don't need to be re-cleared, and it is good practice to clear them out when unregistering.
- Split phy_device registration out into a new function so that the OF helpers can do two stage registration (separate allocation and registration steps).

---

 drivers/net/phy/mdio_bus.c   |   29 +++-------------------------
 drivers/net/phy/phy_device.c |   43 ++++++++++++++++++++++++++++++++++++++----
 include/linux/phy.h          |    1 +
 3 files changed, 43 insertions(+), 30 deletions(-)
drivers/net/phy/mdio_bus.c +3 -26
index 811a637..3c39c7b 100644
@@ -112,7 +112,6 @@ int mdiobus_register(struct mii_bus *bus)
 		bus->reset(bus);
 
 	for (i = 0; i < PHY_MAX_ADDR; i++) {
-		bus->phy_map[i] = NULL;
 		if ((bus->phy_mask & (1 << i)) == 0) {
 			struct phy_device *phydev;
 
@@ -149,6 +148,7 @@ void mdiobus_unregister(struct mii_bus *bus)
 	for (i = 0; i < PHY_MAX_ADDR; i++) {
 		if (bus->phy_map[i])
 			device_unregister(&bus->phy_map[i]->dev);
+		bus->phy_map[i] = NULL;
 	}
 }
 EXPORT_SYMBOL(mdiobus_unregister);
@@ -187,35 +187,12 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
 	if (IS_ERR(phydev) || phydev == NULL)
 		return phydev;
 
-	/* There's a PHY at this address
-	 * We need to set:
-	 * 1) IRQ
-	 * 2) bus_id
-	 * 3) parent
-	 * 4) bus
-	 * 5) mii_bus
-	 * And, we need to register it */
-
-	phydev->irq = bus->irq != NULL ? bus->irq[addr] : PHY_POLL;
-
-	phydev->dev.parent = bus->parent;
-	phydev->dev.bus = &mdio_bus_type;
-	dev_set_name(&phydev->dev, PHY_ID_FMT, bus->id, addr);
-
-	phydev->bus = bus;
-
-	/* Run all of the fixups for this PHY */
-	phy_scan_fixups(phydev);
-
-	err = device_register(&phydev->dev);
+	err = phy_device_register(phydev);
 	if (err) {
-		printk(KERN_ERR "phy %d failed to register\n", addr);
 		phy_device_free(phydev);
-		phydev = NULL;
+		return NULL;
 	}
 
-	bus->phy_map[addr] = phydev;
-
 	return phydev;
 }
 EXPORT_SYMBOL(mdiobus_scan);
drivers/net/phy/phy_device.c +39 -4

67 lines not on this page · raw message

include/linux/phy.h +1 -0
index d7e54d9..a47d64f 100644
@@ -439,6 +439,7 @@ static inline int phy_write(struct phy_device *phydev, u16 regnum, u16 val)
 
 int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id);
 struct phy_device* get_phy_device(struct mii_bus *bus, int addr);
+int phy_device_register(struct phy_device *phy);
 int phy_clear_interrupt(struct phy_device *phydev);
 int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);
 struct phy_device * phy_attach(struct net_device *dev,
#2 lore raw

Re: [PATCH 2/9] phylib: rework to prepare for OF registration of PHYs

RFC, please don't apply yet.

Quoted 6 lines · Grant Likely

From: Grant Likely <[email protected]>

This patch makes changes in preparation for supporting open firmware device tree descriptions of MDIO busses. =A0Changes include:
- Cleanup handling of phy_map[] entries; they are already NULLed when =A0registering and so don't need to be re-cleared, and it is good practic=

e

Quoted 5 lines

=A0to clear them out when unregistering.
- Split phy_device registration out into a new function so that the =A0OF helpers can do two stage registration (separate allocation and =A0registration steps).

Quoted 8 lines

---

=A0drivers/net/phy/mdio_bus.c =A0 | =A0 29 +++------------------------- =A0drivers/net/phy/phy_device.c | =A0 43 ++++++++++++++++++++++++++++++++=

++++++----

Quoted 19 lines

=A0include/linux/phy.h =A0 =A0 =A0 =A0 =A0| =A0 =A01 + =A03 files changed, 43 insertions(+), 30 deletions(-)

drivers/net/phy/mdio_bus.c +0 -1
index 811a637..3c39c7b 100644
@@ -112,7 +112,6 @@ int mdiobus_register(struct mii_bus *bus)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0bus->reset(bus);
 
 =A0 =A0 =A0 =A0for (i =3D 0; i < PHY_MAX_ADDR; i++) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus->phy_map[i] =3D NULL;
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ((bus->phy_mask & (1 << i)) =3D=3D 0) {
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct phy_device *phydev;
 
@@ -149,6 +148,7 @@ void mdiobus_unregister(struct mii_bus *bus)
 =A0 =A0 =A0 =A0for (i =3D 0; i < PHY_MAX_ADDR; i++) {
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (bus->phy_map[i])
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0device_unregister(&bus->ph=

y_map[i]->dev);

drivers/net/phy/mdio_bus.c struct phy_device *mdiobus_scan(struct mii_bus *bus=

Quoted 5 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus->phy_map[i] =3D NULL; =A0 =A0 =A0 =A0}
=A0}
=A0EXPORT_SYMBOL(mdiobus_unregister);

drivers/net/phy/mdio_bus.c +0 -0
@@ -187,35 +187,12 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus=

, int addr)

drivers/net/phy/mdio_bus.c struct phy_device *mdiobus_scan(struct mii_bus *bus= · line 199

Quoted 13 lines
drivers/net/phy/mdio_bus.c +0 -10
 =A0 =A0 =A0 =A0if (IS_ERR(phydev) || phydev =3D=3D NULL)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return phydev;
 
- =A0 =A0 =A0 /* There's a PHY at this address
- =A0 =A0 =A0 =A0* We need to set:
- =A0 =A0 =A0 =A0* 1) IRQ
- =A0 =A0 =A0 =A0* 2) bus_id
- =A0 =A0 =A0 =A0* 3) parent
- =A0 =A0 =A0 =A0* 4) bus
- =A0 =A0 =A0 =A0* 5) mii_bus
- =A0 =A0 =A0 =A0* And, we need to register it */
-
- =A0 =A0 =A0 phydev->irq =3D bus->irq !=3D NULL ? bus->irq[addr] : PHY_P=

OLL;

Quoted 4 lines
drivers/net/phy/mdio_bus.c +0 -4
-
- =A0 =A0 =A0 phydev->dev.parent =3D bus->parent;
- =A0 =A0 =A0 phydev->dev.bus =3D &mdio_bus_type;
- =A0 =A0 =A0 dev_set_name(&phydev->dev, PHY_ID_FMT, bus->id, addr);

drivers/net/phy/mdio_bus.c struct phy_device *mdiobus_scan(struct mii_bus *bus= · line 212

Quoted 10 lines
drivers/net/phy/mdio_bus.c +1 -8
-
- =A0 =A0 =A0 phydev->bus =3D bus;
-
- =A0 =A0 =A0 /* Run all of the fixups for this PHY */
- =A0 =A0 =A0 phy_scan_fixups(phydev);
-
- =A0 =A0 =A0 err =3D device_register(&phydev->dev);
+ =A0 =A0 =A0 err =3D phy_device_register(phydev);
 =A0 =A0 =A0 =A0if (err) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "phy %d failed to register\=

n", addr);

drivers/net/phy/phy_device.c struct phy_device* phy_device_create(struct mii_bus =

Quoted 37 lines
drivers/net/phy/mdio_bus.c +1 -3
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0phy_device_free(phydev);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 phydev =3D NULL;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
 =A0 =A0 =A0 =A0}
 
- =A0 =A0 =A0 bus->phy_map[addr] =3D phydev;
-
 =A0 =A0 =A0 =A0return phydev;
 =A0}
 =A0EXPORT_SYMBOL(mdiobus_scan);
drivers/net/phy/phy_device.c +4 -4
index 0a06e4f..793332f 100644
@@ -39,10 +39,6 @@ MODULE_DESCRIPTION("PHY library");
 =A0MODULE_AUTHOR("Andy Fleming");
 =A0MODULE_LICENSE("GPL");
 
-static struct phy_driver genphy_driver;
-extern int mdio_bus_init(void);
-extern void mdio_bus_exit(void);
-
 =A0void phy_device_free(struct phy_device *phydev)
 =A0{
 =A0 =A0 =A0 =A0kfree(phydev);
@@ -53,6 +49,10 @@ static void phy_device_release(struct device *dev)
 =A0 =A0 =A0 =A0phy_device_free(to_phy_device(dev));
 =A0}
 
+static struct phy_driver genphy_driver;
+extern int mdio_bus_init(void);
+extern void mdio_bus_exit(void);
+
 =A0static LIST_HEAD(phy_fixup_list);
 =A0static DEFINE_MUTEX(phy_fixup_lock);
 
@@ -166,6 +166,10 @@ struct phy_device* phy_device_create(struct mii_bus =

*bus, int addr, int phy_id)

drivers/net/phy/phy_device.c struct phy_device* phy_device_create(struct mii_bus = · line 171

Quoted 6 lines
drivers/net/phy/phy_device.c +3 -0
 =A0 =A0 =A0 =A0dev->addr =3D addr;
 =A0 =A0 =A0 =A0dev->phy_id =3D phy_id;
 =A0 =A0 =A0 =A0dev->bus =3D bus;
+ =A0 =A0 =A0 dev->dev.parent =3D bus->parent;
+ =A0 =A0 =A0 dev->dev.bus =3D &mdio_bus_type;
+ =A0 =A0 =A0 dev->irq =3D bus->irq !=3D NULL ? bus->irq[addr] : PHY_POLL=

;

drivers/net/phy/phy_device.c struct phy_device * get_phy_device(struct mii_bus *b=

Quoted 5 lines
drivers/net/phy/phy_device.c +1 -0
+ =A0 =A0 =A0 dev_set_name(&dev->dev, PHY_ID_FMT, bus->id, addr);
 
 =A0 =A0 =A0 =A0dev->state =3D PHY_DOWN;
 
@@ -237,6 +241,37 @@ struct phy_device * get_phy_device(struct mii_bus *b=

us, int addr)

drivers/net/phy/phy_device.c struct phy_device * get_phy_device(struct mii_bus *bus, int addr)

Quoted 11 lines
drivers/net/phy/phy_device.c +0 -0
 =A0}
 

=A0/**
+ * phy_device_register - Register the phy device on the MDIO bus
+ * @phy_device: phy_device structure to be added to the MDIO bus
+ */

drivers/net/phy/phy_device.c +5 -0
+int phy_device_register(struct phy_device *phydev)
+{
+ =A0 =A0 =A0 int err;
+
+ =A0 =A0 =A0 /* Don't register a phy if one is already registered at thi=

s

drivers/net/phy/phy_device.c

Quoted 11 lines

+ =A0 =A0 =A0 =A0* address */
+ =A0 =A0 =A0 if (phydev->bus->phy_map[phydev->addr])
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
+ =A0 =A0 =A0 phydev->bus->phy_map[phydev->addr] =3D phydev;

drivers/net/phy/phy_device.c +7 -0
+
+ =A0 =A0 =A0 /* Run all of the fixups for this PHY */
+ =A0 =A0 =A0 phy_scan_fixups(phydev);
+
+ =A0 =A0 =A0 err =3D device_register(&phydev->dev);
+ =A0 =A0 =A0 if (err) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_err("phy %d failed to register\n", phyde=

v->addr);

include/linux/phy.h static inline int phy_write(struct phy_device *phydev=

Quoted 20 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out;
+ =A0 =A0 =A0 }

drivers/net/phy/phy_device.c +10 -0
+
+ =A0 =A0 =A0 return 0;
+
+ out:
+ =A0 =A0 =A0 phydev->bus->phy_map[phydev->addr] =3D NULL;
+ =A0 =A0 =A0 return err;
+}
+EXPORT_SYMBOL(phy_device_register);
+
+/**

=A0* phy_prepare_link - prepares the PHY layer to monitor link status =A0* @phydev: target phy_device struct
=A0* @handler: callback function for link status change notifications

include/linux/phy.h +0 -0
index d7e54d9..a47d64f 100644
@@ -439,6 +439,7 @@ static inline int phy_write(struct phy_device *phydev=

, u16 regnum, u16 val)

include/linux/phy.h static inline int phy_write(struct phy_device *phydev= · line 445

Quoted 9 lines
include/linux/phy.h +1 -0
 =A0int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id);
 =A0struct phy_device* get_phy_device(struct mii_bus *bus, int addr);
+int phy_device_register(struct phy_device *phy);
 =A0int phy_clear_interrupt(struct phy_device *phydev);
 =A0int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);
 =A0struct phy_device * phy_attach(struct net_device *dev,
 

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#3 lore raw

PATCH 3/9 phylib: add *_direct() variants of phy_connect and phy_attach functions

In reply to Grant Likely

From: Grant Likely <[email protected]>

Add phy_connect_direct() and phy_attach_direct() functions so that drivers can use a pointer to the phy_device instead of trying to determine the phy's bus_id string.

This patch is useful for OF device tree descriptions of phy devices where the driver doesn't need or know what the bus_id value in order to get a phy_device pointer.

---

 drivers/net/phy/phy_device.c |  118 ++++++++++++++++++++++++++++++------------
 include/linux/phy.h          |    5 ++
 2 files changed, 90 insertions(+), 33 deletions(-)
drivers/net/phy/phy_device.c +85 -33
index 793332f..238d21e 100644
@@ -290,6 +290,33 @@ void phy_prepare_link(struct phy_device *phydev,
 }
 
 /**
+ * phy_connect_direct - connect an ethernet device to a specific phy_device
+ * @dev: the network device to connect
+ * @phydev: the pointer to the phy device
+ * @handler: callback function for state change notifications
+ * @flags: PHY device's dev_flags
+ * @interface: PHY device's interface
+ */
+int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
+		       void (*handler)(struct net_device *), u32 flags,
+		       phy_interface_t interface)
+{
+	int rc;
+
+	rc = phy_attach_direct(dev, phydev, flags, interface);
+	if (rc)
+		return rc;
+
+	phy_prepare_link(phydev, handler);
+	phy_start_machine(phydev, NULL);
+	if (phydev->irq > 0)
+		phy_start_interrupts(phydev);
+
+	return 0;
+}
+EXPORT_SYMBOL(phy_connect_direct);
+
+/**
  * phy_connect - connect an ethernet device to a PHY device
  * @dev: the network device to connect
  * @bus_id: the id string of the PHY device to connect
@@ -310,18 +337,21 @@ struct phy_device * phy_connect(struct net_device *dev, const char *bus_id,
 		phy_interface_t interface)
 {
 	struct phy_device *phydev;
+	struct device *d;
+	int rc;
 
-	phydev = phy_attach(dev, bus_id, flags, interface);
-
-	if (IS_ERR(phydev))
-		return phydev;
-
-	phy_prepare_link(phydev, handler);
-
-	phy_start_machine(phydev, NULL);
+	/* Search the list of PHY devices on the mdio bus for the
+	 * PHY with the requested name */
+	d = bus_find_device_by_name(&mdio_bus_type, NULL, bus_id);
+	if (!d) {
+		pr_err("PHY %s not found\n", bus_id);
+		return ERR_PTR(-ENODEV);
+	}
+	phydev = to_phy_device(d);
 
-	if (phydev->irq > 0)
-		phy_start_interrupts(phydev);
+	rc = phy_attach_direct(dev, phydev, flags, interface);
+	if (rc)
+		return ERR_PTR(rc);
 
 	return phydev;
 }
@@ -345,9 +375,9 @@ void phy_disconnect(struct phy_device *phydev)
 EXPORT_SYMBOL(phy_disconnect);
 
 /**
- * phy_attach - attach a network device to a particular PHY device
+ * phy_attach_direct - attach a network device to a given PHY device pointer
  * @dev: network device to attach
- * @bus_id: PHY device to attach
+ * @phydev: Pointer to phy_device to attach
  * @flags: PHY device's dev_flags
  * @interface: PHY device's interface
  *
@@ -358,22 +388,10 @@ EXPORT_SYMBOL(phy_disconnect);
  *     the attaching device, and given a callback for link status
  *     change.  The phy_device is returned to the attaching driver.
  */
-struct phy_device *phy_attach(struct net_device *dev,
-		const char *bus_id, u32 flags, phy_interface_t interface)
+int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
+		      u32 flags, phy_interface_t interface)
 {
-	struct bus_type *bus = &mdio_bus_type;
-	struct phy_device *phydev;
-	struct device *d;
-
-	/* Search the list of PHY devices on the mdio bus for the
-	 * PHY with the requested name */
-	d = bus_find_device_by_name(bus, NULL, bus_id);
-	if (d) {
-		phydev = to_phy_device(d);
-	} else {
-		printk(KERN_ERR "%s not found\n", bus_id);
-		return ERR_PTR(-ENODEV);
-	}
+	struct device *d = &phydev->dev;
 
 	/* Assume that if there is no driver, that it doesn't
 	 * exist, and we should use the genphy driver. */
@@ -386,13 +404,12 @@ struct phy_device *phy_attach(struct net_device *dev,
 			err = device_bind_driver(d);
 
 		if (err)
-			return ERR_PTR(err);
+			return err;
 	}
 
 	if (phydev->attached_dev) {
-		printk(KERN_ERR "%s: %s already attached\n",
-				dev->name, bus_id);
-		return ERR_PTR(-EBUSY);
+		dev_err(&dev->dev, "PHY already attached\n");
+		return -EBUSY;
 	}
 
 	phydev->attached_dev = dev;
@@ -410,13 +427,48 @@ struct phy_device *phy_attach(struct net_device *dev,
 		err = phy_scan_fixups(phydev);
 
 		if (err < 0)
-			return ERR_PTR(err);
+			return err;
 
 		err = phydev->drv->config_init(phydev);
 
 		if (err < 0)
-			return ERR_PTR(err);
+			return err;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(phy_attach_direct);
+
+/**
+ * phy_attach - attach a network device to a particular PHY device
+ * @dev: network device to attach
+ * @bus_id: Bus ID of PHY device to attach
+ * @flags: PHY device's dev_flags
+ * @interface: PHY device's interface
+ *
+ * Description: Same as phy_attach_direct() except that a PHY bus_id
+ *     string is passed instead of a pointer to a struct phy_device.
+ */
+struct phy_device *phy_attach(struct net_device *dev,
+		const char *bus_id, u32 flags, phy_interface_t interface)
+{
+	struct bus_type *bus = &mdio_bus_type;
+	struct phy_device *phydev;
+	struct device *d;
+	int rc;
+
+	/* Search the list of PHY devices on the mdio bus for the
+	 * PHY with the requested name */
+	d = bus_find_device_by_name(bus, NULL, bus_id);
+	if (!d) {
+		pr_err("PHY %s not found\n", bus_id);
+		return ERR_PTR(-ENODEV);
 	}
+	phydev = to_phy_device(d);
+
+	rc = phy_attach_direct(dev, phydev, flags, interface);
+	if (rc)
+		return ERR_PTR(rc);
 
 	return phydev;
 }
include/linux/phy.h +5 -0
index a47d64f..97405f2 100644
@@ -442,8 +442,13 @@ struct phy_device* get_phy_device(struct mii_bus *bus, int addr);
 int phy_device_register(struct phy_device *phy);
 int phy_clear_interrupt(struct phy_device *phydev);
 int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);
+int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
+		u32 flags, phy_interface_t interface);
 struct phy_device * phy_attach(struct net_device *dev,
 		const char *bus_id, u32 flags, phy_interface_t interface);
+int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
+		void (*handler)(struct net_device *), u32 flags,
+		phy_interface_t interface);
 struct phy_device * phy_connect(struct net_device *dev, const char *bus_id,
 		void (*handler)(struct net_device *), u32 flags,
 		phy_interface_t interface);
#4 lore raw

Re: [PATCH 3/9] phylib: add *_direct() variants of phy_connect and phy_attach functions

RFC, please don't apply yet.

Quoted 4 lines · Grant Likely

From: Grant Likely <[email protected]>

Add phy_connect_direct() and phy_attach_direct() functions so that drivers can use a pointer to the phy_device instead of trying to determin=

e

Quoted 10 lines

the phy's bus_id string.

This patch is useful for OF device tree descriptions of phy devices where the driver doesn't need or know what the bus_id value in order to get a phy_device pointer.

---

=A0drivers/net/phy/phy_device.c | =A0118 ++++++++++++++++++++++++++++++--=

----------

Quoted 11 lines

=A0include/linux/phy.h =A0 =A0 =A0 =A0 =A0| =A0 =A05 ++ =A02 files changed, 90 insertions(+), 33 deletions(-)

drivers/net/phy/phy_device.c +0 -0
index 793332f..238d21e 100644
@@ -290,6 +290,33 @@ void phy_prepare_link(struct phy_device *phydev,
 =A0}
 
Quoted 2 lines

=A0/**
+ * phy_connect_direct - connect an ethernet device to a specific phy_dev=

ice

Quoted 7 lines

+ * @dev: the network device to connect
+ * @phydev: the pointer to the phy device
+ * @handler: callback function for state change notifications
+ * @flags: PHY device's dev_flags
+ * @interface: PHY device's interface
+ */
+int phy_connect_direct(struct net_device *dev, struct phy_device *phydev=

,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0void (*handler)(struct net_d=

evice *), u32 flags,

drivers/net/phy/phy_device.c struct phy_device * phy_connect(struct net_device *=

Quoted 22 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0phy_interface_t interface)

drivers/net/phy/phy_device.c +17 -0
+{
+ =A0 =A0 =A0 int rc;
+
+ =A0 =A0 =A0 rc =3D phy_attach_direct(dev, phydev, flags, interface);
+ =A0 =A0 =A0 if (rc)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return rc;
+
+ =A0 =A0 =A0 phy_prepare_link(phydev, handler);
+ =A0 =A0 =A0 phy_start_machine(phydev, NULL);
+ =A0 =A0 =A0 if (phydev->irq > 0)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_start_interrupts(phydev);
+
+ =A0 =A0 =A0 return 0;
+}
+EXPORT_SYMBOL(phy_connect_direct);
+
+/**

=A0* phy_connect - connect an ethernet device to a PHY device =A0* @dev: the network device to connect
=A0* @bus_id: the id string of the PHY device to connect

drivers/net/phy/phy_device.c +0 -0
@@ -310,18 +337,21 @@ struct phy_device * phy_connect(struct net_device *=

dev, const char *bus_id,

Quoted 7 lines
drivers/net/phy/phy_device.c +2 -1
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0phy_interface_t interface)
 =A0{
 =A0 =A0 =A0 =A0struct phy_device *phydev;
+ =A0 =A0 =A0 struct device *d;
+ =A0 =A0 =A0 int rc;
 
- =A0 =A0 =A0 phydev =3D phy_attach(dev, bus_id, flags, interface);

drivers/net/phy/phy_device.c struct phy_device * phy_connect(struct net_device *= · line 345

Quoted 10 lines
drivers/net/phy/phy_device.c +3 -7
-
- =A0 =A0 =A0 if (IS_ERR(phydev))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return phydev;
-
- =A0 =A0 =A0 phy_prepare_link(phydev, handler);
-
- =A0 =A0 =A0 phy_start_machine(phydev, NULL);
+ =A0 =A0 =A0 /* Search the list of PHY devices on the mdio bus for the
+ =A0 =A0 =A0 =A0* PHY with the requested name */
+ =A0 =A0 =A0 d =3D bus_find_device_by_name(&mdio_bus_type, NULL, bus_id)=

;

Quoted 17 lines
drivers/net/phy/phy_device.c +8 -2
+ =A0 =A0 =A0 if (!d) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_err("PHY %s not found\n", bus_id);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(-ENODEV);
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 phydev =3D to_phy_device(d);
 
- =A0 =A0 =A0 if (phydev->irq > 0)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_start_interrupts(phydev);
+ =A0 =A0 =A0 rc =3D phy_attach_direct(dev, phydev, flags, interface);
+ =A0 =A0 =A0 if (rc)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(rc);
 
 =A0 =A0 =A0 =A0return phydev;
 =A0}
@@ -345,9 +375,9 @@ void phy_disconnect(struct phy_device *phydev)
 =A0EXPORT_SYMBOL(phy_disconnect);
 
Quoted 3 lines

=A0/**
- * phy_attach - attach a network device to a particular PHY device
+ * phy_attach_direct - attach a network device to a given PHY device poi=

nter

Quoted 9 lines

=A0* @dev: network device to attach
- * @bus_id: PHY device to attach
+ * @phydev: Pointer to phy_device to attach
=A0* @flags: PHY device's dev_flags
=A0* @interface: PHY device's interface
=A0*

drivers/net/phy/phy_device.c +0 -0
@@ -358,22 +388,10 @@ EXPORT_SYMBOL(phy_disconnect);

=A0* =A0 =A0 the attaching device, and given a callback for link status =A0* =A0 =A0 change. =A0The phy_device is returned to the attaching drive=

r.

Quoted 3 lines

=A0*/
-struct phy_device *phy_attach(struct net_device *dev,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *bus_id, u32 flags, phy_interfac=

e_t interface)

Quoted 2 lines

+int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 flags, phy_interface_t inte=

rface)

drivers/net/phy/phy_device.c struct phy_device *phy_attach(struct net_device *de=

Quoted 19 lines

=A0{
- =A0 =A0 =A0 struct bus_type *bus =3D &mdio_bus_type;
- =A0 =A0 =A0 struct phy_device *phydev;
- =A0 =A0 =A0 struct device *d;
-
- =A0 =A0 =A0 /* Search the list of PHY devices on the mdio bus for the
- =A0 =A0 =A0 =A0* PHY with the requested name */
- =A0 =A0 =A0 d =3D bus_find_device_by_name(bus, NULL, bus_id);
- =A0 =A0 =A0 if (d) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 phydev =3D to_phy_device(d);
- =A0 =A0 =A0 } else {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "%s not found\n", bus_id);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(-ENODEV);
- =A0 =A0 =A0 }
+ =A0 =A0 =A0 struct device *d =3D &phydev->dev;

=A0 =A0 =A0 =A0/* Assume that if there is no driver, that it doesn't =A0 =A0 =A0 =A0 * exist, and we should use the genphy driver. */

drivers/net/phy/phy_device.c +0 -0
@@ -386,13 +404,12 @@ struct phy_device *phy_attach(struct net_device *de=

v,

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D device_bind_driver=

(d);

Quoted 8 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (err)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(err);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return err; =A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0if (phydev->attached_dev) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "%s: %s already attached\n"=

,

Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev->name, =

bus_id);

Quoted 2 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(-EBUSY);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "PHY already attached\n"=

);

drivers/net/phy/phy_device.c struct phy_device *phy_attach(struct net_device *de=

Quoted 5 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EBUSY;
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0phydev->attached_dev =3D dev;

drivers/net/phy/phy_device.c +0 -0
@@ -410,13 +427,48 @@ struct phy_device *phy_attach(struct net_device *de=

v,

Quoted 19 lines
drivers/net/phy/phy_device.c +10 -2
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D phy_scan_fixups(phydev);
 
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (err < 0)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(err);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return err;
 
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D phydev->drv->config_init(phydev);
 
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (err < 0)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(err);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return err;
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 return 0;
+}
+EXPORT_SYMBOL(phy_attach_direct);
+
+/**
+ * phy_attach - attach a network device to a particular PHY device

drivers/net/phy/phy_device.c struct phy_device *phy_attach(struct net_device *dev,

Quoted 10 lines
drivers/net/phy/phy_device.c +10 -0
+ * @dev: network device to attach
+ * @bus_id: Bus ID of PHY device to attach
+ * @flags: PHY device's dev_flags
+ * @interface: PHY device's interface
+ *
+ * Description: Same as phy_attach_direct() except that a PHY bus_id
+ * =A0 =A0 string is passed instead of a pointer to a struct phy_device.
+ */
+struct phy_device *phy_attach(struct net_device *dev,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const char *bus_id, u32 flags, phy_interfac=

e_t interface)

include/linux/phy.h struct phy_device* get_phy_device(struct mii_bus *bu=

Quoted 26 lines
drivers/net/phy/phy_device.c +17 -0
+{
+ =A0 =A0 =A0 struct bus_type *bus =3D &mdio_bus_type;
+ =A0 =A0 =A0 struct phy_device *phydev;
+ =A0 =A0 =A0 struct device *d;
+ =A0 =A0 =A0 int rc;
+
+ =A0 =A0 =A0 /* Search the list of PHY devices on the mdio bus for the
+ =A0 =A0 =A0 =A0* PHY with the requested name */
+ =A0 =A0 =A0 d =3D bus_find_device_by_name(bus, NULL, bus_id);
+ =A0 =A0 =A0 if (!d) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_err("PHY %s not found\n", bus_id);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(-ENODEV);
 =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 phydev =3D to_phy_device(d);
+
+ =A0 =A0 =A0 rc =3D phy_attach_direct(dev, phydev, flags, interface);
+ =A0 =A0 =A0 if (rc)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ERR_PTR(rc);
 
 =A0 =A0 =A0 =A0return phydev;
 =A0}
include/linux/phy.h +0 -0
index a47d64f..97405f2 100644
@@ -442,8 +442,13 @@ struct phy_device* get_phy_device(struct mii_bus *bu=

s, int addr);

Quoted 7 lines
include/linux/phy.h +2 -0
 =A0int phy_device_register(struct phy_device *phy);
 =A0int phy_clear_interrupt(struct phy_device *phydev);
 =A0int phy_config_interrupt(struct phy_device *phydev, u32 interrupts);
+int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 u32 flags, phy_interface_t interface);
 =A0struct phy_device * phy_attach(struct net_device *dev,

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const char *bus_id, u32 flags, phy_interfa=

ce_t interface);

Quoted 1 line

+int phy_connect_direct(struct net_device *dev, struct phy_device *phydev=

,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 void (*handler)(struct net_device *), u32 f=

lags,

Quoted 2 lines

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_interface_t interface); =A0struct phy_device * phy_connect(struct net_device *dev, const char *bu=

s_id,

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0void (*handler)(struct net_device *), u32 =

flags,

Quoted 3 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0phy_interface_t interface);

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#5 lore raw

PATCH 4/9 openfirmware: Add OF phylib support code

In reply to Grant Likely

From: Grant Likely <[email protected]>

Add support for parsing the device tree for PHY devices on an MDIO bus

---

 drivers/of/Kconfig      |    6 ++
 drivers/of/Makefile     |    1 
 drivers/of/of_mdio.c    |  130 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_mdio.h |   21 ++++++++
 4 files changed, 158 insertions(+), 0 deletions(-)
 create mode 100644 drivers/of/of_mdio.c
 create mode 100644 include/linux/of_mdio.h
drivers/of/Kconfig +6 -0
index f821dbc..6fe043b 100644
@@ -19,3 +19,9 @@ config OF_SPI
 	depends on OF && PPC_OF && SPI
 	help
 	  OpenFirmware SPI accessors
+
+config OF_MDIO
+	def_tristate PHYLIB
+	depends on OF && PHYLIB
+	help
+	  OpenFirmware MDIO bus (Ethernet PHY) accessors
drivers/of/Makefile +1 -0
index 4c3c6f8..bdfb5f5 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
 obj-$(CONFIG_OF_I2C)	+= of_i2c.o
 obj-$(CONFIG_OF_SPI)	+= of_spi.o
+obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
drivers/of/of_mdio.c new file +130 -0

130 lines not on this page · raw message

include/linux/of_mdio.h new file +21 -0
new file mode 100644
index 0000000..ec092cc
@@ -0,0 +1,21 @@
+/*
+ * OF helpers for the MDIO (Ethernet PHY) API
+ *
+ * Copyright (c) 2009 Secret Lab Technologies, Ltd.
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MDIO_H
+#define __LINUX_OF_MDIO_H
+
+#include <linux/phy.h>
+#include <linux/of.h>
+
+extern int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
+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);
+
+#endif /* __LINUX_OF_MDIO_H */
#6 lore raw

Re: [PATCH 4/9] openfirmware: Add OF phylib support code

RFC, please don't apply yet.

Quoted 8 lines · Grant Likely

From: Grant Likely <[email protected]>

Add support for parsing the device tree for PHY devices on an MDIO bus

Quoted 6 lines

---

=A0drivers/of/Kconfig =A0 =A0 =A0| =A0 =A06 ++ =A0drivers/of/Makefile =A0 =A0 | =A0 =A01 =A0drivers/of/of_mdio.c =A0 =A0| =A0130 +++++++++++++++++++++++++++++++++=

++++++++++++++

Quoted 35 lines

=A0include/linux/of_mdio.h | =A0 21 ++++++++ =A04 files changed, 158 insertions(+), 0 deletions(-) =A0create mode 100644 drivers/of/of_mdio.c =A0create mode 100644 include/linux/of_mdio.h

drivers/of/Kconfig +0 -0
index f821dbc..6fe043b 100644
@@ -19,3 +19,9 @@ config OF_SPI

=A0 =A0 =A0 =A0depends on OF && PPC_OF && SPI
=A0 =A0 =A0 =A0help
=A0 =A0 =A0 =A0 =A0OpenFirmware SPI accessors

drivers/of/Kconfig +6 -0
+
+config OF_MDIO
+ =A0 =A0 =A0 def_tristate PHYLIB
+ =A0 =A0 =A0 depends on OF && PHYLIB
+ =A0 =A0 =A0 help
+ =A0 =A0 =A0 =A0 OpenFirmware MDIO bus (Ethernet PHY) accessors
drivers/of/Makefile +0 -0
index 4c3c6f8..bdfb5f5 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_OF_DEVICE) +=3D device.o platform.o

=A0obj-$(CONFIG_OF_GPIO) =A0 +=3D gpio.o
=A0obj-$(CONFIG_OF_I2C) =A0 +=3D of_i2c.o
=A0obj-$(CONFIG_OF_SPI) =A0 +=3D of_spi.o

drivers/of/Makefile +1 -0
+obj-$(CONFIG_OF_MDIO) =A0+=3D of_mdio.o
drivers/of/of_mdio.c new file +0 -0
new file mode 100644
index 0000000..6f3038a

drivers/of/of_mdio.c line 8

Quoted 8 lines
drivers/of/of_mdio.c new file +8 -0
@@ -0,0 +1,130 @@
+/*
+ * OF helpers for the MDIO (Ethernet PHY) API
+ *
+ * Copyright (c) 2009 Secret Lab Technologies, Ltd.
+ *
+ * This file is released under the GPLv2
+ *
+ * This file provides helper functions for extracting PHY device informa=

tion

drivers/of/of_mdio.c line 9

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ * out of the OpenFirmware device tree and using it to populate an mii_b=

us.

drivers/of/of_mdio.c

Quoted 12 lines
drivers/of/of_mdio.c new file +12 -0
+ */
+
+#include <linux/phy.h>
+#include <linux/of.h>
+#include <linux/of_mdio.h>
+#include <linux/module.h>
+
+MODULE_AUTHOR("Grant Likely <[email protected]>");
+MODULE_LICENSE("GPL");
+
+/**
+ * of_mdiobus_register - Register mii_bus and create PHYs from the devic=

e tree

drivers/of/of_mdio.c

Quoted 4 lines
drivers/of/of_mdio.c new file +4 -0
+ * @mdio: pointer to mii_bus structure
+ * @np: pointer to device_node of MDIO bus.
+ *
+ * This function registers the mii_bus structure and registers a phy_dev=

ice

drivers/of/of_mdio.c

Quoted 9 lines
drivers/of/of_mdio.c new file +9 -0
+ * for each child node of @np.
+ */
+int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
+{
+ =A0 =A0 =A0 struct phy_device *phy;
+ =A0 =A0 =A0 struct device_node *child;
+ =A0 =A0 =A0 int rc, i;
+
+ =A0 =A0 =A0 /* Mask out all PHYs from auto probing. =A0Instead the PHYs=

listed in

drivers/of/of_mdio.c line 35

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ =A0 =A0 =A0 =A0* the device tree are populated after the bus has been r=

egistered */

drivers/of/of_mdio.c line 48

Quoted 13 lines
drivers/of/of_mdio.c new file +13 -0
+ =A0 =A0 =A0 mdio->phy_mask =3D ~0;
+
+ =A0 =A0 =A0 /* Clear all the IRQ properties */
+ =A0 =A0 =A0 if (mdio->irq)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 for (i=3D0; i<PHY_MAX_ADDR; i++)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mdio->irq[i] =3D PHY_POLL;
+
+ =A0 =A0 =A0 /* Register the MDIO bus */
+ =A0 =A0 =A0 rc =3D mdiobus_register(mdio);
+ =A0 =A0 =A0 if (rc)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return rc;
+
+ =A0 =A0 =A0 /* Loop over the child nodes and register a phy_device for =

each one */

drivers/of/of_mdio.c line 53

Quoted 5 lines
drivers/of/of_mdio.c new file +5 -0
+ =A0 =A0 =A0 for_each_child_of_node(np, child) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 *addr;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 int len;
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* A PHY must have a reg property in the ra=

nge [0-31] */

drivers/of/of_mdio.c line 54

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 addr =3D of_get_property(child, "reg", &len=

);

drivers/of/of_mdio.c line 55

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!addr || len < sizeof(*addr) || *addr >=

=3D 32 || *addr < 0) {

drivers/of/of_mdio.c line 56

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&mdio->dev, "%s has=

invalid PHY address\n",

drivers/of/of_mdio.c line 57

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 child->full=

_name);

drivers/of/of_mdio.c line 62

Quoted 5 lines
drivers/of/of_mdio.c new file +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (mdio->irq) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mdio->irq[*addr] =3D irq_of=

_parse_and_map(child, 0);

drivers/of/of_mdio.c line 64

Quoted 2 lines
drivers/of/of_mdio.c new file +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!mdio->irq[*addr])
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mdio->irq[*=

addr] =3D PHY_POLL;

drivers/of/of_mdio.c line 69

Quoted 5 lines
drivers/of/of_mdio.c new file +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy =3D get_phy_device(mdio, *addr);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!phy) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&mdio->dev, "error =

probing PHY at address %i\n",

drivers/of/of_mdio.c line 75

Quoted 6 lines
drivers/of/of_mdio.c new file +6 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *addr);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_scan_fixups(phy);
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Associate the OF node with the device st=

ructure so it

drivers/of/of_mdio.c line 78

Quoted 3 lines
drivers/of/of_mdio.c new file +3 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0* can be looked up later */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_node_get(child);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_archdata_set_node(&phy->dev.archdata, c=

hild);

drivers/of/of_mdio.c line 80

Quoted 2 lines
drivers/of/of_mdio.c new file +2 -0
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* All data is now stored in the phy struct=

; register it */

drivers/of/of_mdio.c line 88

Quoted 8 lines
drivers/of/of_mdio.c new file +8 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 rc =3D phy_device_register(phy);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rc) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_device_free(phy);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(child);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_dbg(&mdio->dev, "registered phy %s at a=

ddress %i\n",

Quoted 8 lines
drivers/of/of_mdio.c new file +8 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 child->name, *addr);
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 return 0;
+}
+EXPORT_SYMBOL(of_mdiobus_register);
+
+/**

drivers/of/of_mdio.c

Quoted 10 lines
drivers/of/of_mdio.c new file +10 -0
+ * of_phy_connect - Connect to the phy described in the device tree
+ * @dev: pointer to net_device claiming the phy
+ * @phy_np: Pointer to device tree node for the PHY
+ * @hndlr: Link state callback for the network device
+ * @iface: PHY data interface type
+ *
+ * Returns a pointer to the phy_device if successfull. =A0NULL otherwise
+ */
+struct phy_device *of_phy_connect(struct net_device *dev,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct =

device_node *phy_np,

drivers/of/of_mdio.c line 107

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 void (*=

hndlr)(struct net_device *), u32 flags,

drivers/of/of_mdio.c line 108

Quoted 1 line
drivers/of/of_mdio.c new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_int=

erface_t iface)

drivers/of/of_mdio.c line 112

Quoted 4 lines
drivers/of/of_mdio.c new file +4 -0
+{
+ =A0 =A0 =A0 int match(struct device *dev, void *phy_np)
+ =A0 =A0 =A0 {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return dev_archdata_get_node(&dev->archdata=

) =3D=3D phy_np;

drivers/of/of_mdio.c line 124

Quoted 12 lines
drivers/of/of_mdio.c new file +12 -0
+ =A0 =A0 =A0 }
+ =A0 =A0 =A0 struct device *d;
+ =A0 =A0 =A0 int rc;
+
+ =A0 =A0 =A0 if (!phy_np)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+
+ =A0 =A0 =A0 d =3D bus_find_device(&mdio_bus_type, NULL, phy_np, match);
+ =A0 =A0 =A0 if (!d)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+
+ =A0 =A0 =A0 rc =3D phy_connect_direct(dev, to_phy_device(d), hndlr, fla=

gs, iface);

Quoted 17 lines
drivers/of/of_mdio.c new file +6 -0
+ =A0 =A0 =A0 if (rc)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+
+ =A0 =A0 =A0 return to_phy_device(d);
+}
+EXPORT_SYMBOL(of_phy_connect);
include/linux/of_mdio.h new file +5 -0
new file mode 100644
index 0000000..ec092cc
@@ -0,0 +1,21 @@
+/*
+ * OF helpers for the MDIO (Ethernet PHY) API
+ *
+ * Copyright (c) 2009 Secret Lab Technologies, Ltd.
+ *

include/linux/of_mdio.h line 15

Quoted 10 lines
include/linux/of_mdio.h new file +10 -0
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_OF_MDIO_H
+#define __LINUX_OF_MDIO_H
+
+#include <linux/phy.h>
+#include <linux/of.h>
+
+extern int of_mdiobus_register(struct mii_bus *mdio, struct device_node =

*np);

include/linux/of_mdio.h line 17

Quoted 2 lines
include/linux/of_mdio.h new file +2 -0
+extern struct phy_device *of_phy_connect(struct net_device *dev,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0struct device_node *phy_np,

include/linux/of_mdio.h line 18

Quoted 1 line
include/linux/of_mdio.h new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0void (*hndlr)(struct net_device *),

include/linux/of_mdio.h line 19

Quoted 1 line
include/linux/of_mdio.h new file +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0u32 flags, phy_interface_t iface);

include/linux/of_mdio.h line 21

Quoted 4 lines
include/linux/of_mdio.h new file +2 -0
+
+#endif /* __LINUX_OF_MDIO_H */

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#7 lore raw

PATCH 5/9 net: make mpc5200 fec driver use of_mdio infrastructure

In reply to Grant Likely

From: Grant Likely <[email protected]>

The patch reworks the MPC5200 Fast Ethernet Controller (FEC) driver to use the of_mdio infrastructure for registering PHY devices from data out openfirmware device tree, and eliminates the assumption that the PHY for the FEC is always attached to the FEC's own MDIO bus. With this patch, the FEC can use a PHY attached to any MDIO bus if it is described in the device tree.
---

 drivers/net/Kconfig           |    2 
 drivers/net/fec_mpc52xx.c     |  175 +++++++++++------------------------------
 drivers/net/fec_mpc52xx_phy.c |   26 +-----
 3 files changed, 53 insertions(+), 150 deletions(-)
drivers/net/Kconfig +1 -1
index a2f185f..3aa24f6 100644
@@ -1854,7 +1854,7 @@ config FEC_MPC52xx
 
 config FEC_MPC52xx_MDIO
 	bool "MPC52xx FEC MDIO bus driver"
-	depends on FEC_MPC52xx
+	depends on FEC_MPC52xx && OF_MDIO
 	default y
 	---help---
 	  The MPC5200's FEC can connect to the Ethernet either with
drivers/net/fec_mpc52xx.c +46 -129

312 lines not on this page · raw message

drivers/net/fec_mpc52xx_phy.c +6 -20
index dd9bfa4..fec9f24 100644
@@ -14,12 +14,14 @@
 #include <linux/netdevice.h>
 #include <linux/phy.h>
 #include <linux/of_platform.h>
+#include <linux/of_mdio.h>
 #include <asm/io.h>
 #include <asm/mpc52xx.h>
 #include "fec_mpc52xx.h"
 
 struct mpc52xx_fec_mdio_priv {
 	struct mpc52xx_fec __iomem *regs;
+	int mdio_irqs[PHY_MAX_ADDR];
 };
 
 static int mpc52xx_fec_mdio_transfer(struct mii_bus *bus, int phy_id,
@@ -27,7 +29,7 @@ static int mpc52xx_fec_mdio_transfer(struct mii_bus *bus, int phy_id,
 {
 	struct mpc52xx_fec_mdio_priv *priv = bus->priv;
 	struct mpc52xx_fec __iomem *fec;
-	int tries = 100;
+	int tries = 3;
 
 	value |= (phy_id << FEC_MII_DATA_PA_SHIFT) & FEC_MII_DATA_PA_MSK;
 	value |= (reg << FEC_MII_DATA_RA_SHIFT) & FEC_MII_DATA_RA_MSK;
@@ -38,7 +40,7 @@ static int mpc52xx_fec_mdio_transfer(struct mii_bus *bus, int phy_id,
 
 	/* wait for it to finish, this takes about 23 us on lite5200b */
 	while (!(in_be32(&fec->ievent) & FEC_IEVENT_MII) && --tries)
-		udelay(5);
+		msleep(1);
 
 	if (!tries)
 		return -ETIMEDOUT;
@@ -64,7 +66,6 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of,
 {
 	struct device *dev = &of->dev;
 	struct device_node *np = of->node;
-	struct device_node *child = NULL;
 	struct mii_bus *bus;
 	struct mpc52xx_fec_mdio_priv *priv;
 	struct resource res = {};
@@ -85,22 +86,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of,
 	bus->write = mpc52xx_fec_mdio_write;
 
 	/* setup irqs */
-	bus->irq = kmalloc(sizeof(bus->irq[0]) * PHY_MAX_ADDR, GFP_KERNEL);
-	if (bus->irq == NULL) {
-		err = -ENOMEM;
-		goto out_free;
-	}
-	for (i=0; i<PHY_MAX_ADDR; i++)
-		bus->irq[i] = PHY_POLL;
-
-	while ((child = of_get_next_child(np, child)) != NULL) {
-		int irq = irq_of_parse_and_map(child, 0);
-		if (irq != NO_IRQ) {
-			const u32 *id = of_get_property(child, "reg", NULL);
-			if (id)
-				bus->irq[*id] = irq;
-		}
-	}
+	bus->irq = priv->mdio_irqs;
 
 	/* setup registers */
 	err = of_address_to_resource(np, 0, &res);
@@ -122,7 +108,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of,
 	out_be32(&priv->regs->mii_speed,
 		((mpc52xx_find_ipb_freq(of->node) >> 20) / 5) << 1);
 
-	err = mdiobus_register(bus);
+	err = of_mdiobus_register(bus, np);
 	if (err)
 		goto out_unmap;
 
#8 lore raw

Re: [PATCH 5/9] net: make mpc5200 fec driver use of_mdio infrastructure

RFC, please don't apply yet.

Quoted 10 lines · Grant Likely

From: Grant Likely <[email protected]>

The patch reworks the MPC5200 Fast Ethernet Controller (FEC) driver to use the of_mdio infrastructure for registering PHY devices from data out openfirmware device tree, and eliminates the assumption that the PHY for the FEC is always attached to the FEC's own MDIO bus. =A0With this patch, the FEC can use a PHY attached to any MDIO bus if it is described in the device tree.
---

Quoted 2 lines

=A0drivers/net/Kconfig =A0 =A0 =A0 =A0 =A0 | =A0 =A02 =A0drivers/net/fec_mpc52xx.c =A0 =A0 | =A0175 +++++++++++----------------=

--------------

Quoted 10 lines

=A0drivers/net/fec_mpc52xx_phy.c | =A0 26 +----- =A03 files changed, 53 insertions(+), 150 deletions(-)

drivers/net/Kconfig +0 -0
index a2f185f..3aa24f6 100644
@@ -1854,7 +1854,7 @@ config FEC_MPC52xx
 
Quoted 7 lines

=A0config FEC_MPC52xx_MDIO
=A0 =A0 =A0 =A0bool "MPC52xx FEC MDIO bus driver"
- =A0 =A0 =A0 depends on FEC_MPC52xx
+ =A0 =A0 =A0 depends on FEC_MPC52xx && OF_MDIO
=A0 =A0 =A0 =A0default y
=A0 =A0 =A0 =A0---help---
=A0 =A0 =A0 =A0 =A0The MPC5200's FEC can connect to the Ethernet either w=

ith

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_adjust_link(struct net_devic=

Quoted 40 lines
drivers/net/fec_mpc52xx.c +0 -0
index 3d55f9a..12ab8ae 100644
@@ -25,6 +25,7 @@

=A0#include <linux/hardirq.h>
=A0#include <linux/delay.h>
=A0#include <linux/of_device.h>
+#include <linux/of_mdio.h>
=A0#include <linux/of_platform.h>

=A0#include <linux/netdevice.h>

drivers/net/fec_mpc52xx.c +0 -0
@@ -43,11 +44,9 @@
 

=A0#define DRIVER_NAME "mpc52xx-fec"

drivers/net/fec_mpc52xx.c +0 -3
-#define FEC5200_PHYADDR_NONE =A0 (-1)
-#define FEC5200_PHYADDR_7WIRE =A0(-2)
-

=A0/* Private driver data structure */
=A0struct mpc52xx_fec_priv {
+ =A0 =A0 =A0 struct net_device *ndev;
=A0 =A0 =A0 =A0int duplex;
=A0 =A0 =A0 =A0int speed;
=A0 =A0 =A0 =A0int r_irq;

drivers/net/fec_mpc52xx.c +0 -0
@@ -59,10 +58,11 @@ struct mpc52xx_fec_priv {
 =A0 =A0 =A0 =A0int msg_enable;
 

=A0 =A0 =A0 =A0/* MDIO link details */
- =A0 =A0 =A0 int phy_addr;
- =A0 =A0 =A0 unsigned int phy_speed;
+ =A0 =A0 =A0 unsigned int mdio_speed;
+ =A0 =A0 =A0 struct device_node *phy_node;
=A0 =A0 =A0 =A0struct phy_device *phydev;
=A0 =A0 =A0 =A0enum phy_state link;
+ =A0 =A0 =A0 int seven_wire_mode;
=A0};

drivers/net/fec_mpc52xx.c +0 -0
@@ -210,66 +210,6 @@ static void mpc52xx_fec_adjust_link(struct net_devic=

e *dev)

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_adjust_link(struct net_devic= · line 220

Quoted 11 lines
drivers/net/fec_mpc52xx.c +0 -8
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0phy_print_status(phydev);
 =A0}
 
-static int mpc52xx_fec_init_phy(struct net_device *dev)
-{
- =A0 =A0 =A0 struct mpc52xx_fec_priv *priv =3D netdev_priv(dev);
- =A0 =A0 =A0 struct phy_device *phydev;
- =A0 =A0 =A0 char phy_id[BUS_ID_SIZE];
-
- =A0 =A0 =A0 snprintf(phy_id, sizeof(phy_id), "%x:%02x",
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (unsigned int)dev->base_add=

r, priv->phy_addr);

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_adjust_link(struct net_devic= · line 226

Quoted 6 lines
drivers/net/fec_mpc52xx.c +0 -6
-
- =A0 =A0 =A0 priv->link =3D PHY_DOWN;
- =A0 =A0 =A0 priv->speed =3D 0;
- =A0 =A0 =A0 priv->duplex =3D -1;
-
- =A0 =A0 =A0 phydev =3D phy_connect(dev, phy_id, &mpc52xx_fec_adjust_lin=

k, 0, PHY_INTERFACE_MODE_MII);

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_adjust_link(struct net_devic= · line 232

Quoted 6 lines
drivers/net/fec_mpc52xx.c +0 -6
- =A0 =A0 =A0 if (IS_ERR(phydev)) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "phy_connect failed\n");
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PTR_ERR(phydev);
- =A0 =A0 =A0 }
- =A0 =A0 =A0 dev_info(&dev->dev, "attached phy %i to driver %s\n",
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 phydev->addr, phydev->drv->=

name);

Quoted 7 lines
drivers/net/fec_mpc52xx.c +0 -7
-
- =A0 =A0 =A0 priv->phydev =3D phydev;
-
- =A0 =A0 =A0 return 0;
-}
-
-static int mpc52xx_fec_phy_start(struct net_device *dev)

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_adjust_link(struct net_devic= · line 249

Quoted 10 lines
drivers/net/fec_mpc52xx.c +0 -10
-{
- =A0 =A0 =A0 struct mpc52xx_fec_priv *priv =3D netdev_priv(dev);
- =A0 =A0 =A0 int err;
-
- =A0 =A0 =A0 if (priv->phy_addr < 0)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
-
- =A0 =A0 =A0 err =3D mpc52xx_fec_init_phy(dev);
- =A0 =A0 =A0 if (err) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "mpc52xx_fec_init_phy fa=

iled\n");

drivers/net/fec_mpc52xx.c static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx=

Quoted 27 lines
drivers/net/fec_mpc52xx.c +0 -23
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return err;
- =A0 =A0 =A0 }
-
- =A0 =A0 =A0 /* reset phy - this also wakes it from PDOWN */
- =A0 =A0 =A0 phy_write(priv->phydev, MII_BMCR, BMCR_RESET);
- =A0 =A0 =A0 phy_start(priv->phydev);
-
- =A0 =A0 =A0 return 0;
-}
-
-static void mpc52xx_fec_phy_stop(struct net_device *dev)
-{
- =A0 =A0 =A0 struct mpc52xx_fec_priv *priv =3D netdev_priv(dev);
-
- =A0 =A0 =A0 if (!priv->phydev)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
-
- =A0 =A0 =A0 phy_disconnect(priv->phydev);
- =A0 =A0 =A0 /* power down phy */
- =A0 =A0 =A0 phy_stop(priv->phydev);
- =A0 =A0 =A0 phy_write(priv->phydev, MII_BMCR, BMCR_PDOWN);
-}
-
 =A0static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx_fec_priv *priv,
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct mii_ioctl_data *mii_data, int cmd)
 =A0{
@@ -279,25 +219,25 @@ static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx=

_fec_priv *priv,

Quoted 10 lines
drivers/net/fec_mpc52xx.c +0 -7
 =A0 =A0 =A0 =A0return phy_mii_ioctl(priv->phydev, mii_data, cmd);
 =A0}
 
-static void mpc52xx_fec_phy_hw_init(struct mpc52xx_fec_priv *priv)
-{
- =A0 =A0 =A0 struct mpc52xx_fec __iomem *fec =3D priv->fec;
-
- =A0 =A0 =A0 if (priv->phydev)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
-

drivers/net/fec_mpc52xx.c static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx= · line 228

Quoted 10 lines
drivers/net/fec_mpc52xx.c +2 -3
- =A0 =A0 =A0 out_be32(&fec->mii_speed, priv->phy_speed);
-}
-
 =A0static int mpc52xx_fec_open(struct net_device *dev)
 =A0{
 =A0 =A0 =A0 =A0struct mpc52xx_fec_priv *priv =3D netdev_priv(dev);
 =A0 =A0 =A0 =A0int err =3D -EBUSY;
 
+ =A0 =A0 =A0 if (priv->phy_node) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->phydev =3D of_phy_connect(priv->ndev,=

priv->phy_node,

drivers/net/fec_mpc52xx.c static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx= · line 229

Quoted 1 line
drivers/net/fec_mpc52xx.c +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 mpc52xx_fec_adjust_link, 0, 0);

drivers/net/fec_mpc52xx.c static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx= · line 231

Quoted 2 lines
drivers/net/fec_mpc52xx.c +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!priv->phydev) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "of_phy_=

connect failed\n");

Quoted 6 lines
drivers/net/fec_mpc52xx.c +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENODEV;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_start(priv->phydev);
+ =A0 =A0 =A0 }
+

=A0 =A0 =A0 =A0if (request_irq(dev->irq, &mpc52xx_fec_interrupt, IRQF_SHA=

RED,

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DRIVER_NAME "_ctrl", dev))=

{

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev_err(&dev->dev, "ctrl interrupt request=

failed\n");

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_hw_init(struct net_device *de=

Quoted 54 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto free_phy;
=A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0if (request_irq(priv->r_irq, &mpc52xx_fec_rx_interrupt, 0, =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DRIVER_NAME "_rx", dev)) {

drivers/net/fec_mpc52xx.c +0 -7
@@ -319,10 +259,6 @@ static int mpc52xx_fec_open(struct net_device *dev)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto free_irqs;
 =A0 =A0 =A0 =A0}
 
- =A0 =A0 =A0 err =3D mpc52xx_fec_phy_start(dev);
- =A0 =A0 =A0 if (err)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto free_skbs;
-
 =A0 =A0 =A0 =A0bcom_enable(priv->rx_dmatsk);
 =A0 =A0 =A0 =A0bcom_enable(priv->tx_dmatsk);
 
@@ -332,16 +268,18 @@ static int mpc52xx_fec_open(struct net_device *dev)
 
 =A0 =A0 =A0 =A0return 0;
 
- free_skbs:
- =A0 =A0 =A0 mpc52xx_fec_free_rx_buffers(dev, priv->rx_dmatsk);
-

=A0free_irqs:
=A0 =A0 =A0 =A0free_irq(priv->t_irq, dev); =A0free_2irqs:
=A0 =A0 =A0 =A0free_irq(priv->r_irq, dev); =A0free_ctrl_irq:
=A0 =A0 =A0 =A0free_irq(dev->irq, dev);
- out:
+ free_phy:
+ =A0 =A0 =A0 if (priv->phydev) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_stop(priv->phydev);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_disconnect(priv->phydev);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->phydev =3D NULL;
+ =A0 =A0 =A0 }

=A0 =A0 =A0 =A0return err;
=A0}

drivers/net/fec_mpc52xx.c +6 -1
@@ -360,7 +298,12 @@ static int mpc52xx_fec_close(struct net_device *dev)
 =A0 =A0 =A0 =A0free_irq(priv->r_irq, dev);
 =A0 =A0 =A0 =A0free_irq(priv->t_irq, dev);
 
- =A0 =A0 =A0 mpc52xx_fec_phy_stop(dev);
+ =A0 =A0 =A0 if (priv->phydev) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* power down phy */
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_stop(priv->phydev);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_disconnect(priv->phydev);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->phydev =3D NULL;
+ =A0 =A0 =A0 }
 
 =A0 =A0 =A0 =A0return 0;
 =A0}
@@ -700,7 +643,7 @@ static void mpc52xx_fec_hw_init(struct net_device *de=

v)

Quoted 2 lines

=A0 =A0 =A0 =A0/* set phy speed.
=A0 =A0 =A0 =A0 * this can't be done in phy driver, since it needs to be =

called

Quoted 8 lines

=A0 =A0 =A0 =A0 * before fec stuff (even on resume) */
- =A0 =A0 =A0 mpc52xx_fec_phy_hw_init(priv);
+ =A0 =A0 =A0 out_be32(&fec->mii_speed, priv->mdio_speed); =A0}

=A0/**

drivers/net/fec_mpc52xx.c +0 -0
@@ -736,7 +679,7 @@ static void mpc52xx_fec_start(struct net_device *dev)

=A0 =A0 =A0 =A0rcntrl =3D FEC_RX_BUFFER_SIZE << 16; =A0 =A0 =A0/* max fra=

me length */

Quoted 11 lines

=A0 =A0 =A0 =A0rcntrl |=3D FEC_RCNTRL_FCE;

- =A0 =A0 =A0 if (priv->phy_addr !=3D FEC5200_PHYADDR_7WIRE)
+ =A0 =A0 =A0 if (!priv->seven_wire_mode)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rcntrl |=3D FEC_RCNTRL_MII_MODE;

=A0 =A0 =A0 =A0if (priv->duplex =3D=3D DUPLEX_FULL)

drivers/net/fec_mpc52xx.c +0 -0
@@ -802,8 +745,6 @@ static void mpc52xx_fec_stop(struct net_device *dev)
 

=A0 =A0 =A0 =A0/* Stop FEC */
=A0 =A0 =A0 =A0out_be32(&fec->ecntrl, in_be32(&fec->ecntrl) & ~FEC_ECNTRL=

_ETHER_EN);

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_reset(struct net_device *dev=

Quoted 6 lines

-
- =A0 =A0 =A0 return;
=A0}

=A0/* reset fec and bestcomm tasks */

drivers/net/fec_mpc52xx.c +0 -0
@@ -821,9 +762,11 @@ static void mpc52xx_fec_reset(struct net_device *dev=

)

drivers/net/fec_mpc52xx.c static void mpc52xx_fec_reset(struct net_device *dev= · line 766

Quoted 9 lines
drivers/net/fec_mpc52xx.c +3 -3
 =A0 =A0 =A0 =A0mpc52xx_fec_hw_init(dev);
 
- =A0 =A0 =A0 phy_stop(priv->phydev);
- =A0 =A0 =A0 phy_write(priv->phydev, MII_BMCR, BMCR_RESET);
- =A0 =A0 =A0 phy_start(priv->phydev);
+ =A0 =A0 =A0 if (priv->phydev) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_stop(priv->phydev);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_write(priv->phydev, MII_BMCR, BMCR_RESE=

T);

drivers/net/fec_mpc52xx.c static const struct net_device_ops mpc52xx_fec_netdev=

Quoted 6 lines
drivers/net/fec_mpc52xx.c +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_start(priv->phydev);
+ =A0 =A0 =A0 }
 
 =A0 =A0 =A0 =A0bcom_fec_rx_reset(priv->rx_dmatsk);
 =A0 =A0 =A0 =A0bcom_fec_tx_reset(priv->tx_dmatsk);
@@ -923,7 +866,6 @@ static const struct net_device_ops mpc52xx_fec_netdev=

_ops =3D {

Quoted 6 lines

=A0#endif
=A0};

-
=A0static int __devinit
=A0mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *mat=

ch)

drivers/net/fec_mpc52xx.c mpc52xx_fec_probe(struct of_device *op, const struct =

Quoted 2 lines

=A0{

drivers/net/fec_mpc52xx.c +0 -0
@@ -931,8 +873,6 @@ mpc52xx_fec_probe(struct of_device *op, const struct =

of_device_id *match)

drivers/net/fec_mpc52xx.c mpc52xx_fec_probe(struct of_device *op, const struct =

Quoted 9 lines
drivers/net/fec_mpc52xx.c +0 -2
 =A0 =A0 =A0 =A0struct net_device *ndev;
 =A0 =A0 =A0 =A0struct mpc52xx_fec_priv *priv =3D NULL;
 =A0 =A0 =A0 =A0struct resource mem;
- =A0 =A0 =A0 struct device_node *phy_node;
- =A0 =A0 =A0 const phandle *phy_handle;
 =A0 =A0 =A0 =A0const u32 *prop;
 =A0 =A0 =A0 =A0int prop_size;
 
@@ -945,6 +885,7 @@ mpc52xx_fec_probe(struct of_device *op, const struct =

of_device_id *match)

drivers/net/fec_mpc52xx.c mpc52xx_fec_probe(struct of_device *op, const struct =

Quoted 8 lines
drivers/net/fec_mpc52xx.c +1 -0
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ENOMEM;
 
 =A0 =A0 =A0 =A0priv =3D netdev_priv(ndev);
+ =A0 =A0 =A0 priv->ndev =3D ndev;
 

=A0 =A0 =A0 =A0/* Reserve FEC control zone */
=A0 =A0 =A0 =A0rv =3D of_address_to_resource(op->node, 0, &mem);

drivers/net/fec_mpc52xx.c +0 -0
@@ -968,6 +909,7 @@ mpc52xx_fec_probe(struct of_device *op, const struct =

of_device_id *match)

Quoted 6 lines
drivers/net/fec_mpc52xx.c +1 -0
 =A0 =A0 =A0 =A0ndev->watchdog_timeo =A0 =A0=3D FEC_WATCHDOG_TIMEOUT;
 =A0 =A0 =A0 =A0ndev->base_addr =A0 =A0 =A0 =A0 =3D mem.start;
 =A0 =A0 =A0 =A0ndev->netdev_ops =3D &mpc52xx_fec_netdev_ops;
+ =A0 =A0 =A0 SET_NETDEV_DEV(ndev, &op->dev);
 

=A0 =A0 =A0 =A0priv->t_irq =3D priv->r_irq =3D ndev->irq =3D NO_IRQ; /* I=

RQ are free for now */

drivers/net/fec_mpc52xx.c mpc52xx_fec_probe(struct of_device *op, const struc=

Quoted 2 lines
drivers/net/fec_mpc52xx.c +0 -0
@@ -1017,14 +959,9 @@ mpc52xx_fec_probe(struct of_device *op, const struc=

t of_device_id *match)

Quoted 8 lines

=A0 =A0 =A0 =A0 */

=A0 =A0 =A0 =A0/* Start with safe defaults for link connection */
- =A0 =A0 =A0 priv->phy_addr =3D FEC5200_PHYADDR_NONE;
- =A0 =A0 =A0 priv->speed =3D 100;
+ =A0 =A0 =A0 priv->speed =3D 10;
=A0 =A0 =A0 =A0priv->duplex =3D DUPLEX_HALF;
- =A0 =A0 =A0 priv->phy_speed =3D ((mpc52xx_find_ipb_freq(op->node) >> 20=

) / 5) << 1;

Quoted 5 lines

-
- =A0 =A0 =A0 /* the 7-wire property means don't use MII mode */
- =A0 =A0 =A0 if (of_find_property(op->node, "fsl,7-wire-mode", NULL))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->phy_addr =3D FEC5200_PHYADDR_7WIRE;
+ =A0 =A0 =A0 priv->mdio_speed =3D ((mpc52xx_find_ipb_freq(op->node) >> 2=

0) / 5) << 1;

Quoted 2 lines

=A0 =A0 =A0 =A0/* The current speed preconfigures the speed of the MII li=

nk */

Quoted 1 line

=A0 =A0 =A0 =A0prop =3D of_get_property(op->node, "current-speed", &prop_=

size);

drivers/net/fec_mpc52xx.c mpc52xx_fec_probe(struct of_device *op, const stru=

Quoted 1 line
drivers/net/fec_mpc52xx.c +0 -0
@@ -1033,43 +970,23 @@ mpc52xx_fec_probe(struct of_device *op, const stru=

ct of_device_id *match)

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0priv->duplex =3D prop[1] ? DUPLEX_FULL : D=

UPLEX_HALF;

Quoted 4 lines

=A0 =A0 =A0 =A0}

- =A0 =A0 =A0 /* If there is a phy handle, setup link to that phy */
- =A0 =A0 =A0 phy_handle =3D of_get_property(op->node, "phy-handle", &pro=

p_size);

Quoted 2 lines

- =A0 =A0 =A0 if (phy_handle && (prop_size >=3D sizeof(phandle))) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_node =3D of_find_node_by_phandle(*phy_h=

andle);

Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 prop =3D of_get_property(phy_node, "reg", &=

prop_size);

Quoted 2 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (prop && (prop_size >=3D sizeof(u32)))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ((*prop >=3D 0) && (*pro=

p < PHY_MAX_ADDR))

Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->phy_a=

ddr =3D *prop;

Quoted 3 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(phy_node);
+ =A0 =A0 =A0 /* If there is a phy handle, then get the PHY node */
+ =A0 =A0 =A0 priv->phy_node =3D of_parse_phandle(op->node, "phy-handle",=

0);

Quoted 5 lines

+
+ =A0 =A0 =A0 /* the 7-wire property means don't use MII mode */
+ =A0 =A0 =A0 if (of_find_property(op->node, "fsl,7-wire-mode", NULL)) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->seven_wire_mode =3D 1;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_info(&ndev->dev, "using 7-wire PHY mode=

\n");

Quoted 14 lines

=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0/* Hardware init */
=A0 =A0 =A0 =A0mpc52xx_fec_hw_init(ndev);
-
=A0 =A0 =A0 =A0mpc52xx_fec_reset_stats(ndev);

- =A0 =A0 =A0 SET_NETDEV_DEV(ndev, &op->dev); -
- =A0 =A0 =A0 /* Register the new network device */ =A0 =A0 =A0 =A0rv =3D register_netdev(ndev); =A0 =A0 =A0 =A0if (rv < 0)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto probe_error;

Quoted 4 lines

- =A0 =A0 =A0 /* Now report the link setup */
- =A0 =A0 =A0 switch (priv->phy_addr) {
- =A0 =A0 =A0 =A0case FEC5200_PHYADDR_NONE:
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_info(&ndev->dev, "Fixed speed MII link:=

%i%cD\n",

Quoted 1 line

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0priv->speed, priv->duple=

x ? 'F' : 'H');

Quoted 3 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
- =A0 =A0 =A0 =A0case FEC5200_PHYADDR_7WIRE:
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_info(&ndev->dev, "using 7-wire PHY mode=

\n");

Quoted 3 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
- =A0 =A0 =A0 =A0default:
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_info(&ndev->dev, "Using PHY at MDIO add=

ress %i\n",

drivers/net/fec_mpc52xx_phy.=

Quoted 7 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0priv->phy_addr);
- =A0 =A0 =A0 }
-
=A0 =A0 =A0 =A0/* We're done ! */
=A0 =A0 =A0 =A0dev_set_drvdata(&op->dev, ndev);

drivers/net/fec_mpc52xx_phy.= renamed from drivers/net/fec_mpc52xx_phy.c +0 -0

c

drivers/net/fec_mpc52xx_phy.c static int mpc52xx_fec_mdio_transfer(struct mii_bus *bu=

Quoted 19 lines

index dd9bfa4..fec9f24 100644

drivers/net/fec_mpc52xx_phy.c +0 -0
@@ -14,12 +14,14 @@

=A0#include <linux/netdevice.h>
=A0#include <linux/phy.h>
=A0#include <linux/of_platform.h>
+#include <linux/of_mdio.h>
=A0#include <asm/io.h>
=A0#include <asm/mpc52xx.h>
=A0#include "fec_mpc52xx.h"

=A0struct mpc52xx_fec_mdio_priv {
=A0 =A0 =A0 =A0struct mpc52xx_fec __iomem *regs;
+ =A0 =A0 =A0 int mdio_irqs[PHY_MAX_ADDR];
=A0};

=A0static int mpc52xx_fec_mdio_transfer(struct mii_bus *bus, int phy_id,

drivers/net/fec_mpc52xx_phy.c +0 -0
@@ -27,7 +29,7 @@ static int mpc52xx_fec_mdio_transfer(struct mii_bus *bu=

s, int phy_id,

Quoted 7 lines
drivers/net/fec_mpc52xx_phy.c +1 -1
 =A0{
 =A0 =A0 =A0 =A0struct mpc52xx_fec_mdio_priv *priv =3D bus->priv;
 =A0 =A0 =A0 =A0struct mpc52xx_fec __iomem *fec;
- =A0 =A0 =A0 int tries =3D 100;
+ =A0 =A0 =A0 int tries =3D 3;
 

=A0 =A0 =A0 =A0value |=3D (phy_id << FEC_MII_DATA_PA_SHIFT) & FEC_MII_DAT=

A_PA_MSK;

Quoted 1 line

=A0 =A0 =A0 =A0value |=3D (reg << FEC_MII_DATA_RA_SHIFT) & FEC_MII_DATA_R=

A_MSK;

drivers/net/fec_mpc52xx_phy.c static int mpc52xx_fec_mdio_transfer(struct mii_bus *bu=

Quoted 1 line
drivers/net/fec_mpc52xx_phy.c +0 -0
@@ -38,7 +40,7 @@ static int mpc52xx_fec_mdio_transfer(struct mii_bus *bu=

s, int phy_id,

Quoted 2 lines

=A0 =A0 =A0 =A0/* wait for it to finish, this takes about 23 us on lite52=

00b */

Quoted 1 line

=A0 =A0 =A0 =A0while (!(in_be32(&fec->ievent) & FEC_IEVENT_MII) && --trie=

s)

drivers/net/fec_mpc52xx_phy.c static int mpc52xx_fec_mdio_probe(struct of_device *of=

Quoted 14 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 udelay(5);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 msleep(1);

=A0 =A0 =A0 =A0if (!tries)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ETIMEDOUT;

drivers/net/fec_mpc52xx_phy.c +0 -1
@@ -64,7 +66,6 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of,
 =A0{
 =A0 =A0 =A0 =A0struct device *dev =3D &of->dev;
 =A0 =A0 =A0 =A0struct device_node *np =3D of->node;
- =A0 =A0 =A0 struct device_node *child =3D NULL;
 =A0 =A0 =A0 =A0struct mii_bus *bus;
 =A0 =A0 =A0 =A0struct mpc52xx_fec_mdio_priv *priv;
 =A0 =A0 =A0 =A0struct resource res =3D {};
@@ -85,22 +86,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of=

,

Quoted 4 lines
drivers/net/fec_mpc52xx_phy.c +0 -0
 =A0 =A0 =A0 =A0bus->write =3D mpc52xx_fec_mdio_write;
 

=A0 =A0 =A0 =A0/* setup irqs */
- =A0 =A0 =A0 bus->irq =3D kmalloc(sizeof(bus->irq[0]) * PHY_MAX_ADDR, GF=

P_KERNEL);

Quoted 8 lines

- =A0 =A0 =A0 if (bus->irq =3D=3D NULL) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -ENOMEM;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_free;
- =A0 =A0 =A0 }
- =A0 =A0 =A0 for (i=3D0; i<PHY_MAX_ADDR; i++)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus->irq[i] =3D PHY_POLL;
-
- =A0 =A0 =A0 while ((child =3D of_get_next_child(np, child)) !=3D NULL) =

{

Quoted 3 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 int irq =3D irq_of_parse_and_map(child, 0);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (irq !=3D NO_IRQ) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 *id =3D of_get_pr=

operty(child, "reg", NULL);

Quoted 2 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (id)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus->irq[*i=

d] =3D irq;

drivers/net/fec_mpc52xx_phy.c static int mpc52xx_fec_mdio_probe(struct of_device *o=

Quoted 7 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
- =A0 =A0 =A0 }
+ =A0 =A0 =A0 bus->irq =3D priv->mdio_irqs;

=A0 =A0 =A0 =A0/* setup registers */
=A0 =A0 =A0 =A0err =3D of_address_to_resource(np, 0, &res);

drivers/net/fec_mpc52xx_phy.c +0 -0
@@ -122,7 +108,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *o=

f,

Quoted 2 lines
drivers/net/fec_mpc52xx_phy.c +0 -0
 =A0 =A0 =A0 =A0out_be32(&priv->regs->mii_speed,

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0((mpc52xx_find_ipb_freq(of->node) >> 20) /=

5) << 1);

Quoted 8 lines

- =A0 =A0 =A0 err =3D mdiobus_register(bus);
+ =A0 =A0 =A0 err =3D of_mdiobus_register(bus, np); =A0 =A0 =A0 =A0if (err)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_unmap;

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#9 lore raw

PATCH 6/9 net/gianfar: Rework gianfar driver to use OF PHY/MDIO helper functions

In reply to Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

 drivers/net/gianfar.c     |   94 ++++++++++++++-------------------------------
 drivers/net/gianfar.h     |    3 +
 drivers/net/gianfar_mii.c |   52 +------------------------
 3 files changed, 34 insertions(+), 115 deletions(-)
drivers/net/gianfar.c +29 -65
index 9831b3f..0521267 100644
@@ -75,6 +75,7 @@
 #include <linux/if_vlan.h>
 #include <linux/spinlock.h>
 #include <linux/mm.h>
+#include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 #include <linux/ip.h>
 #include <linux/tcp.h>
@@ -155,17 +156,13 @@ static inline int gfar_uses_fcb(struct gfar_private *priv)
 
 static int gfar_of_init(struct net_device *dev)
 {
-	struct device_node *phy, *mdio;
-	const unsigned int *id;
 	const char *model;
 	const char *ctype;
 	const void *mac_addr;
-	const phandle *ph;
 	u64 addr, size;
 	int err = 0;
 	struct gfar_private *priv = netdev_priv(dev);
 	struct device_node *np = priv->node;
-	char bus_name[MII_BUS_ID_SIZE];
 
 	if (!np || !of_device_is_available(np))
 		return -ENODEV;
@@ -228,8 +225,8 @@ static int gfar_of_init(struct net_device *dev)
 	if (of_get_property(np, "fsl,magic-packet", NULL))
 		priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
 
-	ph = of_get_property(np, "phy-handle", NULL);
-	if (ph == NULL) {
+	priv->phy_node = of_parse_phandle(np, "phy-device", 0);
+	if (!priv->phy_node) {
 		u32 *fixed_link;
 
 		fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
@@ -237,57 +234,10 @@ static int gfar_of_init(struct net_device *dev)
 			err = -ENODEV;
 			goto err_out;
 		}
-
-		snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id),
-				PHY_ID_FMT, "0", fixed_link[0]);
-	} else {
-		phy = of_find_node_by_phandle(*ph);
-
-		if (phy == NULL) {
-			err = -ENODEV;
-			goto err_out;
-		}
-
-		mdio = of_get_parent(phy);
-
-		id = of_get_property(phy, "reg", NULL);
-
-		of_node_put(phy);
-		of_node_put(mdio);
-
-		gfar_mdio_bus_name(bus_name, mdio);
-		snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id), "%s:%02x",
-				bus_name, *id);
 	}
 
 	/* Find the TBI PHY.  If it's not there, we don't support SGMII */
-	ph = of_get_property(np, "tbi-handle", NULL);
-	if (ph) {
-		struct device_node *tbi = of_find_node_by_phandle(*ph);
-		struct of_device *ofdev;
-		struct mii_bus *bus;
-
-		if (!tbi)
-			return 0;
-
-		mdio = of_get_parent(tbi);
-		if (!mdio)
-			return 0;
-
-		ofdev = of_find_device_by_node(mdio);
-
-		of_node_put(mdio);
-
-		id = of_get_property(tbi, "reg", NULL);
-		if (!id)
-			return 0;
-
-		of_node_put(tbi);
-
-		bus = dev_get_drvdata(&ofdev->dev);
-
-		priv->tbiphy = bus->phy_map[*id];
-	}
+	priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
 
 	return 0;
 
@@ -661,7 +611,6 @@ static int init_phy(struct net_device *dev)
 	uint gigabit_support =
 		priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
 		SUPPORTED_1000baseT_Full : 0;
-	struct phy_device *phydev;
 	phy_interface_t interface;
 
 	priv->oldlink = 0;
@@ -670,23 +619,38 @@ static int init_phy(struct net_device *dev)
 
 	interface = gfar_get_interface(dev);
 
-	phydev = phy_connect(dev, priv->phy_bus_id, &adjust_link, 0, interface);
+	if (priv->phy_node) {
+		priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link,
+					      0, interface);
+		if (!priv->phydev) {
+			dev_err(&dev->dev, "error: Could not attach to PHY\n");
+			return -ENODEV;
+		}
+	}
+
+	if (priv->tbi_node) {
+		priv->tbiphy = of_phy_connect(dev, priv->tbi_node, &adjust_link,
+					      0, interface);
+		if (!priv->tbiphy) {
+			dev_err(&dev->dev, "error: Could not attach to TBI\n");
+			goto err_tbiphy;
+		}
+	}
 
 	if (interface == PHY_INTERFACE_MODE_SGMII)
 		gfar_configure_serdes(dev);
 
-	if (IS_ERR(phydev)) {
-		printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
-		return PTR_ERR(phydev);
-	}
-
 	/* Remove any features not supported by the controller */
-	phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
-	phydev->advertising = phydev->supported;
-
-	priv->phydev = phydev;
+	priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
+	priv->phydev->advertising = priv->phydev->supported;
 
 	return 0;
+
+ err_tbiphy:
+	if (priv->phy_node)
+		phy_disconnect(priv->phydev);
+	priv->phydev = NULL;
+	return -ENODEV;
 }
 
 /*
drivers/net/gianfar.h +2 -1
index eaa8689..d3d56a9 100644
@@ -775,7 +775,8 @@ struct gfar_private {
 	spinlock_t bflock;
 
 	phy_interface_t interface;
-	char	phy_bus_id[BUS_ID_SIZE];
+	struct device_node *phy_node;
+	struct device_node *tbi_node;
 	u32 device_flags;
 	unsigned char rx_csum_enable:1,
 		extended_hash:1,
drivers/net/gianfar_mii.c +3 -49

76 lines not on this page · raw message

#10 lore raw

Re: [PATCH 6/9] net/gianfar: Rework gianfar driver to use OF PHY/MDIO helper functions

RFC, please don't apply yet.

Quoted 8 lines · Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

=A0drivers/net/gianfar.c =A0 =A0 | =A0 94 ++++++++++++++-----------------=

--------------

drivers/net/gianfar.c static inline int gfar_uses_fcb(struct gfar_private=

Quoted 18 lines

=A0drivers/net/gianfar.h =A0 =A0 | =A0 =A03 + =A0drivers/net/gianfar_mii.c | =A0 52 +------------------------ =A03 files changed, 34 insertions(+), 115 deletions(-)

drivers/net/gianfar.c +0 -0
index 9831b3f..0521267 100644
@@ -75,6 +75,7 @@

=A0#include <linux/if_vlan.h>
=A0#include <linux/spinlock.h>
=A0#include <linux/mm.h>
+#include <linux/of_mdio.h>
=A0#include <linux/of_platform.h>
=A0#include <linux/ip.h>
=A0#include <linux/tcp.h>

drivers/net/gianfar.c +0 -0
@@ -155,17 +156,13 @@ static inline int gfar_uses_fcb(struct gfar_private=

*priv)

Quoted 19 lines
drivers/net/gianfar.c +0 -4
 =A0static int gfar_of_init(struct net_device *dev)
 =A0{
- =A0 =A0 =A0 struct device_node *phy, *mdio;
- =A0 =A0 =A0 const unsigned int *id;
 =A0 =A0 =A0 =A0const char *model;
 =A0 =A0 =A0 =A0const char *ctype;
 =A0 =A0 =A0 =A0const void *mac_addr;
- =A0 =A0 =A0 const phandle *ph;
 =A0 =A0 =A0 =A0u64 addr, size;
 =A0 =A0 =A0 =A0int err =3D 0;
 =A0 =A0 =A0 =A0struct gfar_private *priv =3D netdev_priv(dev);
 =A0 =A0 =A0 =A0struct device_node *np =3D priv->node;
- =A0 =A0 =A0 char bus_name[MII_BUS_ID_SIZE];
 
 =A0 =A0 =A0 =A0if (!np || !of_device_is_available(np))
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ENODEV;
@@ -228,8 +225,8 @@ static int gfar_of_init(struct net_device *dev)
 =A0 =A0 =A0 =A0if (of_get_property(np, "fsl,magic-packet", NULL))
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0priv->device_flags |=3D FSL_GIANFAR_DEV_HA=

S_MAGIC_PACKET;

Quoted 8 lines

- =A0 =A0 =A0 ph =3D of_get_property(np, "phy-handle", NULL);
- =A0 =A0 =A0 if (ph =3D=3D NULL) {
+ =A0 =A0 =A0 priv->phy_node =3D of_parse_phandle(np, "phy-device", 0);
+ =A0 =A0 =A0 if (!priv->phy_node) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0u32 *fixed_link;

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0fixed_link =3D (u32 *)of_get_property(np, =

"fixed-link", NULL);

drivers/net/gianfar.c static int gfar_of_init(struct net_device *dev) · line 241

Quoted 6 lines
drivers/net/gianfar.c +0 -2
@@ -237,57 +234,10 @@ static int gfar_of_init(struct net_device *dev)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -ENODEV;
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto err_out;
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 snprintf(priv->phy_bus_id, sizeof(priv->phy=

_bus_id),

drivers/net/gianfar.c static int gfar_of_init(struct net_device *dev) · line 242

Quoted 1 line
drivers/net/gianfar.c +0 -1
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 PHY_ID_FMT,=

"0", fixed_link[0]);

Quoted 7 lines
drivers/net/gianfar.c +0 -7
- =A0 =A0 =A0 } else {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy =3D of_find_node_by_phandle(*ph);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (phy =3D=3D NULL) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -ENODEV;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err_out;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 }

drivers/net/gianfar.c static int gfar_of_init(struct net_device *dev) · line 259

Quoted 10 lines
drivers/net/gianfar.c +0 -10
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 mdio =3D of_get_parent(phy);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 id =3D of_get_property(phy, "reg", NULL);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(phy);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(mdio);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 gfar_mdio_bus_name(bus_name, mdio);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 snprintf(priv->phy_bus_id, sizeof(priv->phy=

_bus_id), "%s:%02x",

drivers/net/gianfar.c static int gfar_of_init(struct net_device *dev) · line 260

Quoted 1 line
drivers/net/gianfar.c +0 -1
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus_name, *=

id);

Quoted 3 lines
drivers/net/gianfar.c +0 -0
 =A0 =A0 =A0 =A0}
 

=A0 =A0 =A0 =A0/* Find the TBI PHY. =A0If it's not there, we don't suppor=

t SGMII */

Quoted 3 lines

- =A0 =A0 =A0 ph =3D of_get_property(np, "tbi-handle", NULL);
- =A0 =A0 =A0 if (ph) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct device_node *tbi =3D of_find_node_by=

_phandle(*ph);

Quoted 29 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct of_device *ofdev;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct mii_bus *bus;

drivers/net/gianfar.c +1 -22
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!tbi)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 mdio =3D of_get_parent(tbi);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!mdio)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 ofdev =3D of_find_device_by_node(mdio);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(mdio);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 id =3D of_get_property(tbi, "reg", NULL);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!id)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_node_put(tbi);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus =3D dev_get_drvdata(&ofdev->dev);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->tbiphy =3D bus->phy_map[*id];
- =A0 =A0 =A0 }
+ =A0 =A0 =A0 priv->tbi_node =3D of_parse_phandle(np, "tbi-handle", 0);

=A0 =A0 =A0 =A0return 0;

drivers/net/gianfar.c +0 -0
@@ -661,7 +611,6 @@ static int init_phy(struct net_device *dev)
Quoted 2 lines

=A0 =A0 =A0 =A0uint gigabit_support =3D
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0priv->device_flags & FSL_GIANFAR_DEV_HAS_G=

IGABIT ?

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 673

Quoted 10 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0SUPPORTED_1000baseT_Full : 0;
- =A0 =A0 =A0 struct phy_device *phydev;
=A0 =A0 =A0 =A0phy_interface_t interface;

=A0 =A0 =A0 =A0priv->oldlink =3D 0;

drivers/net/gianfar.c +0 -1
@@ -670,23 +619,38 @@ static int init_phy(struct net_device *dev)
 
 =A0 =A0 =A0 =A0interface =3D gfar_get_interface(dev);
 
- =A0 =A0 =A0 phydev =3D phy_connect(dev, priv->phy_bus_id, &adjust_link,=

0, interface);

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 623

Quoted 2 lines
drivers/net/gianfar.c +2 -0
+ =A0 =A0 =A0 if (priv->phy_node) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->phydev =3D of_phy_connect(dev, priv->=

phy_node, &adjust_link,

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 624

Quoted 1 line
drivers/net/gianfar.c +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 0, interface);

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 626

Quoted 2 lines
drivers/net/gianfar.c +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!priv->phydev) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "error: =

Could not attach to PHY\n");

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 632

Quoted 6 lines
drivers/net/gianfar.c +6 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENODEV;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 if (priv->tbi_node) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 priv->tbiphy =3D of_phy_connect(dev, priv->=

tbi_node, &adjust_link,

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 633

Quoted 1 line
drivers/net/gianfar.c +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 0, interface);

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 635

Quoted 2 lines
drivers/net/gianfar.c +2 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!priv->tbiphy) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dev_err(&dev->dev, "error: =

Could not attach to TBI\n");

drivers/net/gianfar.c static int init_phy(struct net_device *dev) · line 679

Quoted 9 lines
drivers/net/gianfar.c +3 -2
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err_tbiphy;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 }
 
 =A0 =A0 =A0 =A0if (interface =3D=3D PHY_INTERFACE_MODE_SGMII)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gfar_configure_serdes(dev);
 
- =A0 =A0 =A0 if (IS_ERR(phydev)) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_ERR "%s: Could not attach to PH=

Y\n", dev->name);

Quoted 9 lines
drivers/net/gianfar.c +0 -3
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PTR_ERR(phydev);
- =A0 =A0 =A0 }
-

=A0 =A0 =A0 =A0/* Remove any features not supported by the controller */
- =A0 =A0 =A0 phydev->supported &=3D (GFAR_SUPPORTED | gigabit_support);
- =A0 =A0 =A0 phydev->advertising =3D phydev->supported;
-
- =A0 =A0 =A0 priv->phydev =3D phydev;
+ =A0 =A0 =A0 priv->phydev->supported &=3D (GFAR_SUPPORTED | gigabit_supp=

ort);

Quoted 39 lines

+ =A0 =A0 =A0 priv->phydev->advertising =3D priv->phydev->supported;

=A0 =A0 =A0 =A0return 0;
+
+ err_tbiphy:
+ =A0 =A0 =A0 if (priv->phy_node)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phy_disconnect(priv->phydev);
+ =A0 =A0 =A0 priv->phydev =3D NULL;
+ =A0 =A0 =A0 return -ENODEV;
=A0}

=A0/*

drivers/net/gianfar.h +2 -1
index eaa8689..d3d56a9 100644
@@ -775,7 +775,8 @@ struct gfar_private {
 =A0 =A0 =A0 =A0spinlock_t bflock;
 
 =A0 =A0 =A0 =A0phy_interface_t interface;
- =A0 =A0 =A0 char =A0 =A0phy_bus_id[BUS_ID_SIZE];
+ =A0 =A0 =A0 struct device_node *phy_node;
+ =A0 =A0 =A0 struct device_node *tbi_node;
 =A0 =A0 =A0 =A0u32 device_flags;
 =A0 =A0 =A0 =A0unsigned char rx_csum_enable:1,
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0extended_hash:1,
drivers/net/gianfar_mii.c +0 -0
index f49a426..c6d77bd 100644
@@ -35,6 +35,7 @@

=A0#include <linux/mii.h>
=A0#include <linux/phy.h>
=A0#include <linux/of.h>
+#include <linux/of_mdio.h>
=A0#include <linux/of_platform.h>

=A0#include <asm/io.h>

drivers/net/gianfar_mii.c static int gfar_mdio_reset(struct mii_bus *bus) · line 155

Quoted 4 lines
drivers/net/gianfar_mii.c +0 -1
@@ -152,45 +153,6 @@ static int gfar_mdio_reset(struct mii_bus *bus)
 =A0 =A0 =A0 =A0return 0;
 =A0}
 
-/* Allocate an array which provides irq #s for each PHY on the given bus=

*/

Quoted 5 lines
drivers/net/gianfar_mii.c +0 -5
-static int *create_irq_map(struct device_node *np)
-{
- =A0 =A0 =A0 int *irqs;
- =A0 =A0 =A0 int i;
- =A0 =A0 =A0 struct device_node *child =3D NULL;

drivers/net/gianfar_mii.c static int gfar_mdio_reset(struct mii_bus *bus) · line 170

Quoted 10 lines
drivers/net/gianfar_mii.c +0 -10
-
- =A0 =A0 =A0 irqs =3D kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
-
- =A0 =A0 =A0 if (!irqs)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
-
- =A0 =A0 =A0 for (i =3D 0; i < PHY_MAX_ADDR; i++)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 irqs[i] =3D PHY_POLL;
-
- =A0 =A0 =A0 while ((child =3D of_get_next_child(np, child)) !=3D NULL) =

{

Quoted 6 lines
drivers/net/gianfar_mii.c +0 -6
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 int irq =3D irq_of_parse_and_map(child, 0);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 *id;
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (irq =3D=3D NO_IRQ)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
-

drivers/net/gianfar_mii.c static int gfar_mdio_reset(struct mii_bus *bus) · line 186

Quoted 10 lines
drivers/net/gianfar_mii.c +0 -10
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 id =3D of_get_property(child, "reg", NULL);
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!id)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue;
-
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (*id < PHY_MAX_ADDR && *id >=3D 0)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 irqs[*id] =3D irq;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_WARNING "%s: "
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 "%d is not a valid PHY address\n",

drivers/net/gianfar_mii.c static int gfar_mdio_reset(struct mii_bus *bus) · line 187

Quoted 1 line
drivers/net/gianfar_mii.c +0 -1
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 np->full_name, *id);

Quoted 10 lines
drivers/net/gianfar_mii.c +0 -6
- =A0 =A0 =A0 }
-
- =A0 =A0 =A0 return irqs;
-}
-
-
 =A0void gfar_mdio_bus_name(char *name, struct device_node *np)
 =A0{
 =A0 =A0 =A0 =A0const u32 *reg;

drivers/net/gianfar_mii.c static int gfar_mdio_probe(struct of_device *ofdev, · line 218

Quoted 5 lines
drivers/net/gianfar_mii.c +1 -1
@@ -253,7 +215,7 @@ static int gfar_mdio_probe(struct of_device *ofdev,
 
 =A0 =A0 =A0 =A0new_bus->priv =3D (void __force *)regs;
 
- =A0 =A0 =A0 new_bus->irq =3D create_irq_map(np);
+ =A0 =A0 =A0 new_bus->irq =3D kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KER=

NEL);

Quoted 18 lines
drivers/net/gianfar_mii.c +1 -9
 =A0 =A0 =A0 =A0if (new_bus->irq =3D=3D NULL) {
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -ENOMEM;
@@ -301,15 +263,7 @@ static int gfar_mdio_probe(struct of_device *ofdev,
 
 =A0 =A0 =A0 =A0gfar_write(&enet_regs->tbipa, tbiaddr);
 
- =A0 =A0 =A0 /*
- =A0 =A0 =A0 =A0* The TBIPHY-only buses will find PHYs at every address,
- =A0 =A0 =A0 =A0* so we mask them all but the TBI
- =A0 =A0 =A0 =A0*/
- =A0 =A0 =A0 if (!of_device_is_compatible(np, "fsl,gianfar-mdio"))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 new_bus->phy_mask =3D ~(1 << tbiaddr);
-
- =A0 =A0 =A0 err =3D mdiobus_register(new_bus);
-
+ =A0 =A0 =A0 err =3D of_mdiobus_register(new_bus, np);
 =A0 =A0 =A0 =A0if (err !=3D 0) {
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk (KERN_ERR "%s: Cannot register as M=

DIO bus\n",

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0new_bus->n=

ame);

Quoted 2 lines

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#11 lore raw

PATCH 7/9 net/ucc_geth: Rework ucc_geth driver to use OF PHY/MDIO helper functions

In reply to Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

 drivers/net/ucc_geth.c     |   27 ++++++---------------------
 drivers/net/ucc_geth_mii.c |   17 +++--------------
 2 files changed, 9 insertions(+), 35 deletions(-)
drivers/net/ucc_geth.c +6 -21
index e879868..45bb627 100644
@@ -28,6 +28,7 @@
 #include <linux/mii.h>
 #include <linux/phy.h>
 #include <linux/workqueue.h>
+#include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 
 #include <asm/uaccess.h>
@@ -1537,35 +1538,19 @@ static int init_phy(struct net_device *dev)
 {
 	struct ucc_geth_private *priv = netdev_priv(dev);
 	struct device_node *np = priv->node;
-	struct device_node *phy, *mdio;
-	const phandle *ph;
-	char bus_name[MII_BUS_ID_SIZE];
-	const unsigned int *id;
+	struct device_node *phy;
 	struct phy_device *phydev;
-	char phy_id[BUS_ID_SIZE];
 
 	priv->oldlink = 0;
 	priv->oldspeed = 0;
 	priv->oldduplex = -1;
 
-	ph = of_get_property(np, "phy-handle", NULL);
-	phy = of_find_node_by_phandle(*ph);
-	mdio = of_get_parent(phy);
-
-	id = of_get_property(phy, "reg", NULL);
-
+	phy = of_parse_phandle(np, "phy-handle", 0);
+	phydev = of_phy_connect(dev, phy, &adjust_link, 0, priv->phy_interface);
 	of_node_put(phy);
-	of_node_put(mdio);
-
-	uec_mdio_bus_name(bus_name, mdio);
-	snprintf(phy_id, sizeof(phy_id), "%s:%02x",
-                                bus_name, *id);
-
-	phydev = phy_connect(dev, phy_id, &adjust_link, 0, priv->phy_interface);
-
-	if (IS_ERR(phydev)) {
+	if (!phydev) {
 		printk("%s: Could not attach to PHY\n", dev->name);
-		return PTR_ERR(phydev);
+		return -ENODEV;
 	}
 
 	phydev->supported &= (ADVERTISED_10baseT_Half |
drivers/net/ucc_geth_mii.c +3 -14
index 0ada4ed..9f2492f 100644
@@ -36,6 +36,7 @@
 #include <linux/mii.h>
 #include <linux/phy.h>
 #include <linux/fsl_devices.h>
+#include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 
 #include <asm/io.h>
@@ -135,11 +136,10 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
 {
 	struct device *device = &ofdev->dev;
 	struct device_node *np = ofdev->node, *tempnp = NULL;
-	struct device_node *child = NULL;
 	struct ucc_mii_mng __iomem *regs;
 	struct mii_bus *new_bus;
 	struct resource res;
-	int k, err = 0;
+	int err = 0;
 
 	new_bus = mdiobus_alloc();
 	if (NULL == new_bus)
@@ -165,17 +165,6 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
 		goto reg_map_fail;
 	}
 
-	for (k = 0; k < 32; k++)
-		new_bus->irq[k] = PHY_POLL;
-
-	while ((child = of_get_next_child(np, child)) != NULL) {
-		int irq = irq_of_parse_and_map(child, 0);
-		if (irq != NO_IRQ) {
-			const u32 *id = of_get_property(child, "reg", NULL);
-			new_bus->irq[*id] = irq;
-		}
-	}
-
 	/* Set the base address */
 	regs = ioremap(res.start, sizeof(struct ucc_mii_mng));
 
@@ -220,7 +209,7 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
 		}
 	}
 
-	err = mdiobus_register(new_bus);
+	err = of_mdiobus_register(new_bus, np);
 	if (0 != err) {
 		printk(KERN_ERR "%s: Cannot register as MDIO bus\n",
 		       new_bus->name);
#12 lore raw

Re: [PATCH 7/9] net/ucc_geth: Rework ucc_geth driver to use OF PHY/MDIO helper functions

RFC, please don't apply yet.

Quoted 38 lines · Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

=A0drivers/net/ucc_geth.c =A0 =A0 | =A0 27 ++++++--------------------- =A0drivers/net/ucc_geth_mii.c | =A0 17 +++-------------- =A02 files changed, 9 insertions(+), 35 deletions(-)

drivers/net/ucc_geth.c +0 -0
index e879868..45bb627 100644
@@ -28,6 +28,7 @@

=A0#include <linux/mii.h>
=A0#include <linux/phy.h>
=A0#include <linux/workqueue.h>
+#include <linux/of_mdio.h>
=A0#include <linux/of_platform.h>

=A0#include <asm/uaccess.h>

drivers/net/ucc_geth.c +1 -5
@@ -1537,35 +1538,19 @@ static int init_phy(struct net_device *dev)
 =A0{
 =A0 =A0 =A0 =A0struct ucc_geth_private *priv =3D netdev_priv(dev);
 =A0 =A0 =A0 =A0struct device_node *np =3D priv->node;
- =A0 =A0 =A0 struct device_node *phy, *mdio;
- =A0 =A0 =A0 const phandle *ph;
- =A0 =A0 =A0 char bus_name[MII_BUS_ID_SIZE];
- =A0 =A0 =A0 const unsigned int *id;
+ =A0 =A0 =A0 struct device_node *phy;
 =A0 =A0 =A0 =A0struct phy_device *phydev;
- =A0 =A0 =A0 char phy_id[BUS_ID_SIZE];
 
 =A0 =A0 =A0 =A0priv->oldlink =3D 0;
 =A0 =A0 =A0 =A0priv->oldspeed =3D 0;

drivers/net/ucc_geth.c static int init_phy(struct net_device *dev) · line 1549

Quoted 10 lines
drivers/net/ucc_geth.c +2 -6
 =A0 =A0 =A0 =A0priv->oldduplex =3D -1;
 
- =A0 =A0 =A0 ph =3D of_get_property(np, "phy-handle", NULL);
- =A0 =A0 =A0 phy =3D of_find_node_by_phandle(*ph);
- =A0 =A0 =A0 mdio =3D of_get_parent(phy);
-
- =A0 =A0 =A0 id =3D of_get_property(phy, "reg", NULL);
-
+ =A0 =A0 =A0 phy =3D of_parse_phandle(np, "phy-handle", 0);
+ =A0 =A0 =A0 phydev =3D of_phy_connect(dev, phy, &adjust_link, 0, priv->=

phy_interface);

drivers/net/ucc_geth.c static int init_phy(struct net_device *dev) · line 1562

Quoted 6 lines
drivers/net/ucc_geth.c +0 -5
 =A0 =A0 =A0 =A0of_node_put(phy);
- =A0 =A0 =A0 of_node_put(mdio);
-
- =A0 =A0 =A0 uec_mdio_bus_name(bus_name, mdio);
- =A0 =A0 =A0 snprintf(phy_id, sizeof(phy_id), "%s:%02x",
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0bus_name=

, *id);

drivers/net/ucc_geth.c static int init_phy(struct net_device *dev) · line 1564

Quoted 2 lines
drivers/net/ucc_geth.c +0 -2
-
- =A0 =A0 =A0 phydev =3D phy_connect(dev, phy_id, &adjust_link, 0, priv->=

phy_interface);

Quoted 4 lines
drivers/net/ucc_geth.c +1 -2
-
- =A0 =A0 =A0 if (IS_ERR(phydev)) {
+ =A0 =A0 =A0 if (!phydev) {

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk("%s: Could not attach to PHY\n", de=

v->name);

drivers/net/ucc_geth_mii.c static int uec_mdio_probe(struct of_device *ofdev, =

Quoted 18 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PTR_ERR(phydev);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENODEV; =A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0phydev->supported &=3D (ADVERTISED_10baseT_Half |

drivers/net/ucc_geth_mii.c +0 -0
index 0ada4ed..9f2492f 100644
@@ -36,6 +36,7 @@

=A0#include <linux/mii.h>
=A0#include <linux/phy.h>
=A0#include <linux/fsl_devices.h>
+#include <linux/of_mdio.h>
=A0#include <linux/of_platform.h>

=A0#include <asm/io.h>

drivers/net/ucc_geth_mii.c +0 -0
@@ -135,11 +136,10 @@ static int uec_mdio_probe(struct of_device *ofdev, =

const struct of_device_id *ma

drivers/net/ucc_geth_mii.c static int uec_mdio_probe(struct of_device *ofdev, c=

Quoted 13 lines
drivers/net/ucc_geth_mii.c +1 -2
 =A0{
 =A0 =A0 =A0 =A0struct device *device =3D &ofdev->dev;
 =A0 =A0 =A0 =A0struct device_node *np =3D ofdev->node, *tempnp =3D NULL;
- =A0 =A0 =A0 struct device_node *child =3D NULL;
 =A0 =A0 =A0 =A0struct ucc_mii_mng __iomem *regs;
 =A0 =A0 =A0 =A0struct mii_bus *new_bus;
 =A0 =A0 =A0 =A0struct resource res;
- =A0 =A0 =A0 int k, err =3D 0;
+ =A0 =A0 =A0 int err =3D 0;
 
 =A0 =A0 =A0 =A0new_bus =3D mdiobus_alloc();
 =A0 =A0 =A0 =A0if (NULL =3D=3D new_bus)
@@ -165,17 +165,6 @@ static int uec_mdio_probe(struct of_device *ofdev, c=

onst struct of_device_id *ma

drivers/net/ucc_geth_mii.c static int uec_mdio_probe(struct of_device *ofdev, c= · line 171

Quoted 7 lines
drivers/net/ucc_geth_mii.c +0 -4
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto reg_map_fail;
 =A0 =A0 =A0 =A0}
 
- =A0 =A0 =A0 for (k =3D 0; k < 32; k++)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 new_bus->irq[k] =3D PHY_POLL;
-
- =A0 =A0 =A0 while ((child =3D of_get_next_child(np, child)) !=3D NULL) =

{

drivers/net/ucc_geth_mii.c static int uec_mdio_probe(struct of_device *ofdev, c= · line 174

Quoted 3 lines
drivers/net/ucc_geth_mii.c +0 -3
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 int irq =3D irq_of_parse_and_map(child, 0);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (irq !=3D NO_IRQ) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const u32 *id =3D of_get_pr=

operty(child, "reg", NULL);

drivers/net/ucc_geth_mii.c static int uec_mdio_probe(struct of_device *ofdev, co=

Quoted 8 lines
drivers/net/ucc_geth_mii.c +0 -4
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 new_bus->irq[*id] =3D irq;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
- =A0 =A0 =A0 }
-

=A0 =A0 =A0 =A0/* Set the base address */
=A0 =A0 =A0 =A0regs =3D ioremap(res.start, sizeof(struct ucc_mii_mng));

drivers/net/ucc_geth_mii.c +0 -0
@@ -220,7 +209,7 @@ static int uec_mdio_probe(struct of_device *ofdev, co=

nst struct of_device_id *ma

Quoted 7 lines
drivers/net/ucc_geth_mii.c +1 -1
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
 =A0 =A0 =A0 =A0}
 
- =A0 =A0 =A0 err =3D mdiobus_register(new_bus);
+ =A0 =A0 =A0 err =3D of_mdiobus_register(new_bus, np);
 =A0 =A0 =A0 =A0if (0 !=3D err) {

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(KERN_ERR "%s: Cannot register as MD=

IO bus\n",

Quoted 3 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 new_bus->name);

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#13 lore raw

PATCH 8/9 net/pasemi_mac: Rework pasemi_mac driver to use of_mdio infrastructure

In reply to Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

 drivers/net/pasemi_mac.c |   19 +++----------------
 drivers/net/pasemi_mac.h |    1 -
 2 files changed, 3 insertions(+), 17 deletions(-)
drivers/net/pasemi_mac.c +3 -16
index d0349e7..8c92d1f 100644
@@ -1086,34 +1086,21 @@ static int pasemi_mac_phy_init(struct net_device *dev)
 	struct pasemi_mac *mac = netdev_priv(dev);
 	struct device_node *dn, *phy_dn;
 	struct phy_device *phydev;
-	unsigned int phy_id;
 	const phandle *ph;
 	const unsigned int *prop;
 	struct resource r;
 	int ret;
 
 	dn = pci_device_to_OF_node(mac->pdev);
-	ph = of_get_property(dn, "phy-handle", NULL);
-	if (!ph)
-		return -ENODEV;
-	phy_dn = of_find_node_by_phandle(*ph);
-
-	prop = of_get_property(phy_dn, "reg", NULL);
-	ret = of_address_to_resource(phy_dn->parent, 0, &r);
-	if (ret)
-		goto err;
-
-	phy_id = *prop;
-	snprintf(mac->phy_id, sizeof(mac->phy_id), "%x:%02x",
-		 (int)r.start, phy_id);
-
+	phy_dn = of_parse_phandle(dn, "phy-handle", 0);
 	of_node_put(phy_dn);
 
 	mac->link = 0;
 	mac->speed = 0;
 	mac->duplex = -1;
 
-	phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII);
+	phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
+				PHY_INTERFACE_MODE_SGMII);
 
 	if (IS_ERR(phydev)) {
 		printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
drivers/net/pasemi_mac.h +0 -1
index 1a115ec..e2f4efa 100644
@@ -100,7 +100,6 @@ struct pasemi_mac {
 	int	duplex;
 
 	unsigned int	msg_enable;
-	char	phy_id[BUS_ID_SIZE];
 };
 
 /* Software status descriptor (ring_info) */
#14 lore raw

Re: [PATCH 8/9] net/pasemi_mac: Rework pasemi_mac driver to use of_mdio infrastructure

RFC, please don't apply yet.

drivers/net/pasemi_mac.c static int pasemi_mac_phy_init(struct net_device =

Quoted 17 lines · Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

=A0drivers/net/pasemi_mac.c | =A0 19 +++---------------- =A0drivers/net/pasemi_mac.h | =A0 =A01 -
=A02 files changed, 3 insertions(+), 17 deletions(-)

drivers/net/pasemi_mac.c +0 -0
index d0349e7..8c92d1f 100644
@@ -1086,34 +1086,21 @@ static int pasemi_mac_phy_init(struct net_device =

*dev)

Quoted 22 lines
drivers/net/pasemi_mac.c +0 -13
 =A0 =A0 =A0 =A0struct pasemi_mac *mac =3D netdev_priv(dev);
 =A0 =A0 =A0 =A0struct device_node *dn, *phy_dn;
 =A0 =A0 =A0 =A0struct phy_device *phydev;
- =A0 =A0 =A0 unsigned int phy_id;
 =A0 =A0 =A0 =A0const phandle *ph;
 =A0 =A0 =A0 =A0const unsigned int *prop;
 =A0 =A0 =A0 =A0struct resource r;
 =A0 =A0 =A0 =A0int ret;
 
 =A0 =A0 =A0 =A0dn =3D pci_device_to_OF_node(mac->pdev);
- =A0 =A0 =A0 ph =3D of_get_property(dn, "phy-handle", NULL);
- =A0 =A0 =A0 if (!ph)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENODEV;
- =A0 =A0 =A0 phy_dn =3D of_find_node_by_phandle(*ph);
-
- =A0 =A0 =A0 prop =3D of_get_property(phy_dn, "reg", NULL);
- =A0 =A0 =A0 ret =3D of_address_to_resource(phy_dn->parent, 0, &r);
- =A0 =A0 =A0 if (ret)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err;
-
- =A0 =A0 =A0 phy_id =3D *prop;
- =A0 =A0 =A0 snprintf(mac->phy_id, sizeof(mac->phy_id), "%x:%02x",

drivers/net/pasemi_mac.c static int pasemi_mac_phy_init(struct net_device = · line 1116

Quoted 10 lines
drivers/net/pasemi_mac.c +1 -3
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(int)r.start, phy_id);
-
+ =A0 =A0 =A0 phy_dn =3D of_parse_phandle(dn, "phy-handle", 0);
 =A0 =A0 =A0 =A0of_node_put(phy_dn);
 
 =A0 =A0 =A0 =A0mac->link =3D 0;
 =A0 =A0 =A0 =A0mac->speed =3D 0;
 =A0 =A0 =A0 =A0mac->duplex =3D -1;
 
- =A0 =A0 =A0 phydev =3D phy_connect(dev, mac->phy_id, &pasemi_adjust_lin=

k, 0, PHY_INTERFACE_MODE_SGMII);

drivers/net/pasemi_mac.c static int pasemi_mac_phy_init(struct net_device = · line 1102

Quoted 1 line
drivers/net/pasemi_mac.c +1 -0
+ =A0 =A0 =A0 phydev =3D of_phy_connect(dev, phy_dn, &pasemi_adjust_link,=

0,

drivers/net/pasemi_mac.c static int pasemi_mac_phy_init(struct net_device = · line 1103

Quoted 1 line
drivers/net/pasemi_mac.c +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 PHY_INTERFA=

CE_MODE_SGMII);

Quoted 3 lines
drivers/net/pasemi_mac.c +0 -0
 =A0 =A0 =A0 =A0if (IS_ERR(phydev)) {

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(KERN_ERR "%s: Could not attach to p=

hy\n", dev->name);

Quoted 11 lines
drivers/net/pasemi_mac.h +0 -1
index 1a115ec..e2f4efa 100644
@@ -100,7 +100,6 @@ struct pasemi_mac {
 =A0 =A0 =A0 =A0int =A0 =A0 duplex;
 
 =A0 =A0 =A0 =A0unsigned int =A0 =A0msg_enable;
- =A0 =A0 =A0 char =A0 =A0phy_id[BUS_ID_SIZE];
 =A0};
 
Quoted 3 lines

=A0/* Software status descriptor (ring_info) */

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#15 lore raw

PATCH 9/9 net/fs_enet: Rework fs_enet driver to use of_mdio infrastructure

In reply to Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

 drivers/net/fs_enet/fs_enet-main.c |   66 +++++-------------------------------
 drivers/net/fs_enet/mii-bitbang.c  |   29 +---------------
 drivers/net/fs_enet/mii-fec.c      |   26 +-------------
 include/linux/fs_enet_pd.h         |    6 +--
 4 files changed, 14 insertions(+), 113 deletions(-)
drivers/net/fs_enet/fs_enet-main.c +9 -57
index ce900e5..e039d6a 100644
@@ -36,6 +36,8 @@
 #include <linux/fs.h>
 #include <linux/platform_device.h>
 #include <linux/phy.h>
+#include <linux/of.h>
+#include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 #include <linux/of_gpio.h>
 
@@ -752,9 +754,10 @@ static int fs_init_phy(struct net_device *dev)
 	fep->oldlink = 0;
 	fep->oldspeed = 0;
 	fep->oldduplex = -1;
-	if(fep->fpi->bus_id)
-		phydev = phy_connect(dev, fep->fpi->bus_id, &fs_adjust_link, 0,
-				PHY_INTERFACE_MODE_MII);
+	if(fep->fpi->phy_node)
+		phydev = of_phy_connect(dev, fep->fpi->phy_node,
+					&fs_adjust_link, 0,
+					PHY_INTERFACE_MODE_MII);
 	else {
 		printk("No phy bus ID specified in BSP code\n");
 		return -EINVAL;
@@ -962,57 +965,6 @@ static void cleanup_immap(void)
 
 /**************************************************************************************/
 
-static int __devinit find_phy(struct device_node *np,
-                              struct fs_platform_info *fpi)
-{
-	struct device_node *phynode, *mdionode;
-	int ret = 0, len, bus_id;
-	const u32 *data;
-
-	data  = of_get_property(np, "fixed-link", NULL);
-	if (data) {
-		snprintf(fpi->bus_id, 16, "%x:%02x", 0, *data);
-		return 0;
-	}
-
-	data = of_get_property(np, "phy-handle", &len);
-	if (!data || len != 4)
-		return -EINVAL;
-
-	phynode = of_find_node_by_phandle(*data);
-	if (!phynode)
-		return -EINVAL;
-
-	data = of_get_property(phynode, "reg", &len);
-	if (!data || len != 4) {
-		ret = -EINVAL;
-		goto out_put_phy;
-	}
-
-	mdionode = of_get_parent(phynode);
-	if (!mdionode) {
-		ret = -EINVAL;
-		goto out_put_phy;
-	}
-
-	bus_id = of_get_gpio(mdionode, 0);
-	if (bus_id < 0) {
-		struct resource res;
-		ret = of_address_to_resource(mdionode, 0, &res);
-		if (ret)
-			goto out_put_mdio;
-		bus_id = res.start;
-	}
-
-	snprintf(fpi->bus_id, 16, "%x:%02x", bus_id, *data);
-
-out_put_mdio:
-	of_node_put(mdionode);
-out_put_phy:
-	of_node_put(phynode);
-	return ret;
-}
-
 #ifdef CONFIG_FS_ENET_HAS_FEC
 #define IS_FEC(match) ((match)->data == &fs_fec_ops)
 #else
@@ -1046,9 +998,9 @@ static int __devinit fs_enet_probe(struct of_device *ofdev,
 	fpi->rx_copybreak = 240;
 	fpi->use_napi = 1;
 	fpi->napi_weight = 17;
-
-	ret = find_phy(ofdev->node, fpi);
-	if (ret)
+	fpi->phy_node = of_parse_phandle(ofdev->node, "phy-handle", 0);
+	if ((!fpi->phy_node) && (!of_get_property(ofdev->node, "fixed-link",
+						  NULL)))
 		goto out_free_fpi;
 
 	privsize = sizeof(*fep) +
drivers/net/fs_enet/mii-bitbang.c +2 -27
index 49b6645..93b481b 100644
@@ -22,6 +22,7 @@
 #include <linux/mii.h>
 #include <linux/platform_device.h>
 #include <linux/mdio-bitbang.h>
+#include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 
 #include "fs_enet.h"
@@ -149,31 +150,12 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
 	return 0;
 }
 
-static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
-{
-	const u32 *data;
-	int len, id, irq;
-
-	data = of_get_property(np, "reg", &len);
-	if (!data || len != 4)
-		return;
-
-	id = *data;
-	bus->phy_mask &= ~(1 << id);
-
-	irq = of_irq_to_resource(np, 0, NULL);
-	if (irq != NO_IRQ)
-		bus->irq[id] = irq;
-}
-
 static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
                                         const struct of_device_id *match)
 {
-	struct device_node *np = NULL;
 	struct mii_bus *new_bus;
 	struct bb_info *bitbang;
 	int ret = -ENOMEM;
-	int i;
 
 	bitbang = kzalloc(sizeof(struct bb_info), GFP_KERNEL);
 	if (!bitbang)
@@ -196,17 +178,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
 	if (!new_bus->irq)
 		goto out_unmap_regs;
 
-	for (i = 0; i < PHY_MAX_ADDR; i++)
-		new_bus->irq[i] = -1;
-
-	while ((np = of_get_next_child(ofdev->node, np)))
-		if (!strcmp(np->type, "ethernet-phy"))
-			add_phy(new_bus, np);
-
 	new_bus->parent = &ofdev->dev;
 	dev_set_drvdata(&ofdev->dev, new_bus);
 
-	ret = mdiobus_register(new_bus);
+	ret = of_mdiobus_register(new_bus, ofdev->node);
 	if (ret)
 		goto out_free_irqs;
 
drivers/net/fs_enet/mii-fec.c +1 -25
index 28077cc..bdc3160 100644
@@ -102,23 +102,6 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus)
 	return 0;
 }
 
-static void __devinit add_phy(struct mii_bus *bus, struct device_node *np)
-{
-	const u32 *data;
-	int len, id, irq;
-
-	data = of_get_property(np, "reg", &len);
-	if (!data || len != 4)
-		return;
-
-	id = *data;
-	bus->phy_mask &= ~(1 << id);
-
-	irq = of_irq_to_resource(np, 0, NULL);
-	if (irq != NO_IRQ)
-		bus->irq[id] = irq;
-}
-
 static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
                                         const struct of_device_id *match)
 {
@@ -165,17 +148,10 @@ static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
 	if (!new_bus->irq)
 		goto out_unmap_regs;
 
-	for (i = 0; i < PHY_MAX_ADDR; i++)
-		new_bus->irq[i] = -1;
-
-	while ((np = of_get_next_child(ofdev->node, np)))
-		if (!strcmp(np->type, "ethernet-phy"))
-			add_phy(new_bus, np);
-
 	new_bus->parent = &ofdev->dev;
 	dev_set_drvdata(&ofdev->dev, new_bus);
 
-	ret = mdiobus_register(new_bus);
+	ret = of_mdiobus_register(new_bus, ofdev->node);
 	if (ret)
 		goto out_free_irqs;
 
include/linux/fs_enet_pd.h +2 -4
index 8300cab..51b7934 100644
@@ -17,6 +17,7 @@
 #define FS_ENET_PD_H
 
 #include <linux/string.h>
+#include <linux/of_mdio.h>
 #include <asm/types.h>
 
 #define FS_ENET_NAME	"fs_enet"
@@ -130,10 +131,7 @@ struct fs_platform_info {
 	
 	u32 device_flags;
 
-	int phy_addr;		/* the phy address (-1 no phy) */
-	char bus_id[16];
-	int phy_irq;		/* the phy irq (if it exists)  */
-
+	struct device_node *phy_node;
 	const struct fs_mii_bus_info *bus_info;
 
 	int rx_ring, tx_ring;	/* number of buffers on rx     */
#16 lore raw

Re: [PATCH 9/9] net/fs_enet: Rework fs_enet driver to use of_mdio infrastructure

RFC, please don't apply yet.

Quoted 8 lines · Grant Likely

From: Grant Likely <[email protected]>

This patch simplifies the driver by making use of more common code.

---

=A0drivers/net/fs_enet/fs_enet-main.c | =A0 66 +++++---------------------=

----------

drivers/net/fs_enet/fs_=

Quoted 7 lines

=A0drivers/net/fs_enet/mii-bitbang.c =A0| =A0 29 +--------------- =A0drivers/net/fs_enet/mii-fec.c =A0 =A0 =A0| =A0 26 +------------- =A0include/linux/fs_enet_pd.h =A0 =A0 =A0 =A0 | =A0 =A06 +-- =A04 files changed, 14 insertions(+), 113 deletions(-)

drivers/net/fs_enet/fs_= renamed from drivers/net/fs_enet/fs_enet-main.c +0 -0

enet-main.c

Quoted 13 lines

index ce900e5..e039d6a 100644

drivers/net/fs_enet/fs_enet-main.c +0 -0
@@ -36,6 +36,8 @@

=A0#include <linux/fs.h>
=A0#include <linux/platform_device.h>
=A0#include <linux/phy.h>

drivers/net/fs_enet/fs_enet-main.c +2 -0
+#include <linux/of.h>
+#include <linux/of_mdio.h>

=A0#include <linux/of_platform.h>
=A0#include <linux/of_gpio.h>

drivers/net/fs_enet/fs_enet-main.c static int fs_init_phy(struct net_device *dev) · line 756

Quoted 5 lines
drivers/net/fs_enet/fs_enet-main.c +0 -2
@@ -752,9 +754,10 @@ static int fs_init_phy(struct net_device *dev)
 =A0 =A0 =A0 =A0fep->oldlink =3D 0;
 =A0 =A0 =A0 =A0fep->oldspeed =3D 0;
 =A0 =A0 =A0 =A0fep->oldduplex =3D -1;
- =A0 =A0 =A0 if(fep->fpi->bus_id)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 phydev =3D phy_connect(dev, fep->fpi->bus_i=

d, &fs_adjust_link, 0,

drivers/net/fs_enet/fs_enet-main.c static int fs_init_phy(struct net_device *dev) · line 757

Quoted 1 line
drivers/net/fs_enet/fs_enet-main.c +0 -1
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 PHY_INTERFA=

CE_MODE_MII);

drivers/net/fs_enet/fs_enet-main.c static int fs_init_phy(struct net_device *dev) · line 758

Quoted 2 lines
drivers/net/fs_enet/fs_enet-main.c +2 -0
+ =A0 =A0 =A0 if(fep->fpi->phy_node)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 phydev =3D of_phy_connect(dev, fep->fpi->ph=

y_node,

drivers/net/fs_enet/fs_enet-main.c static int fs_init_phy(struct net_device *dev) · line 759

Quoted 1 line
drivers/net/fs_enet/fs_enet-main.c +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 &fs_adjust_link, 0,

drivers/net/fs_enet/fs_enet-main.c static int fs_init_phy(struct net_device *dev) · line 760

Quoted 1 line
drivers/net/fs_enet/fs_enet-main.c +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 PHY_INTERFACE_MODE_MII);

Quoted 2 lines
drivers/net/fs_enet/fs_enet-main.c +0 -0
 =A0 =A0 =A0 =A0else {

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk("No phy bus ID specified in BSP cod=

e\n");

Quoted 4 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -EINVAL;

drivers/net/fs_enet/fs_enet-main.c +0 -0
@@ -962,57 +965,6 @@ static void cleanup_immap(void)
 

=A0/*********************************************************************=

*****************/

Quoted 3 lines

-static int __devinit find_phy(struct device_node *np,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct fs_pl=

atform_info *fpi)

drivers/net/fs_enet/fs_enet-main.c

Quoted 8 lines
drivers/net/fs_enet/fs_enet-main.c +0 -8
-{
- =A0 =A0 =A0 struct device_node *phynode, *mdionode;
- =A0 =A0 =A0 int ret =3D 0, len, bus_id;
- =A0 =A0 =A0 const u32 *data;
-
- =A0 =A0 =A0 data =A0=3D of_get_property(np, "fixed-link", NULL);
- =A0 =A0 =A0 if (data) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 snprintf(fpi->bus_id, 16, "%x:%02x", 0, *da=

ta);

Quoted 17 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
- =A0 =A0 =A0 }

drivers/net/fs_enet/fs_enet-main.c +0 -15
-
- =A0 =A0 =A0 data =3D of_get_property(np, "phy-handle", &len);
- =A0 =A0 =A0 if (!data || len !=3D 4)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
-
- =A0 =A0 =A0 phynode =3D of_find_node_by_phandle(*data);
- =A0 =A0 =A0 if (!phynode)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
-
- =A0 =A0 =A0 data =3D of_get_property(phynode, "reg", &len);
- =A0 =A0 =A0 if (!data || len !=3D 4) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EINVAL;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_put_phy;
- =A0 =A0 =A0 }
-

drivers/net/fs_enet/fs_enet-main.c

Quoted 10 lines
drivers/net/fs_enet/fs_enet-main.c +0 -10
- =A0 =A0 =A0 mdionode =3D of_get_parent(phynode);
- =A0 =A0 =A0 if (!mdionode) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EINVAL;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_put_phy;
- =A0 =A0 =A0 }
-
- =A0 =A0 =A0 bus_id =3D of_get_gpio(mdionode, 0);
- =A0 =A0 =A0 if (bus_id < 0) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct resource res;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_address_to_resource(mdionode, 0,=

&res);

drivers/net/fs_enet/fs_enet-main.c static int __devinit fs_enet_probe(struct of_device =

Quoted 18 lines

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out_put_mdio;
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus_id =3D res.start;
- =A0 =A0 =A0 }

drivers/net/fs_enet/fs_enet-main.c +0 -10
-
- =A0 =A0 =A0 snprintf(fpi->bus_id, 16, "%x:%02x", bus_id, *data);
-
-out_put_mdio:
- =A0 =A0 =A0 of_node_put(mdionode);
-out_put_phy:
- =A0 =A0 =A0 of_node_put(phynode);
- =A0 =A0 =A0 return ret;
-}
-

=A0#ifdef CONFIG_FS_ENET_HAS_FEC
=A0#define IS_FEC(match) ((match)->data =3D=3D &fs_fec_ops) =A0#else

drivers/net/fs_enet/fs_enet-main.c +0 -0
@@ -1046,9 +998,9 @@ static int __devinit fs_enet_probe(struct of_device =

*ofdev,

drivers/net/fs_enet/fs_enet-main.c static int __devinit fs_enet_probe(struct of_device = · line 1001

Quoted 7 lines
drivers/net/fs_enet/fs_enet-main.c +1 -3
 =A0 =A0 =A0 =A0fpi->rx_copybreak =3D 240;
 =A0 =A0 =A0 =A0fpi->use_napi =3D 1;
 =A0 =A0 =A0 =A0fpi->napi_weight =3D 17;
-
- =A0 =A0 =A0 ret =3D find_phy(ofdev->node, fpi);
- =A0 =A0 =A0 if (ret)
+ =A0 =A0 =A0 fpi->phy_node =3D of_parse_phandle(ofdev->node, "phy-handle=

", 0);

drivers/net/fs_enet/fs_enet-main.c static int __devinit fs_enet_probe(struct of_device = · line 1002

Quoted 1 line
drivers/net/fs_enet/fs_enet-main.c +1 -0
+ =A0 =A0 =A0 if ((!fpi->phy_node) && (!of_get_property(ofdev->node, "fix=

ed-link",

drivers/net/fs_enet/fs_enet-main.c static int __devinit fs_enet_probe(struct of_device = · line 1003

Quoted 1 line
drivers/net/fs_enet/fs_enet-main.c +1 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 =A0 =A0 =A0 NULL)))

drivers/net/fs_enet/mii-=

Quoted 4 lines
drivers/net/fs_enet/fs_enet-main.c +0 -0
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_free_fpi;
 

=A0 =A0 =A0 =A0privsize =3D sizeof(*fep) +

drivers/net/fs_enet/mii-= renamed from drivers/net/fs_enet/mii-bitbang.c +0 -0

bitbang.c

drivers/net/fs_enet/mii-bitbang.c static int __devinit fs_mii_bitbang_init(struct mii=

Quoted 12 lines

index 49b6645..93b481b 100644

drivers/net/fs_enet/mii-bitbang.c +0 -0
@@ -22,6 +22,7 @@

=A0#include <linux/mii.h>
=A0#include <linux/platform_device.h>
=A0#include <linux/mdio-bitbang.h>
+#include <linux/of_mdio.h>
=A0#include <linux/of_platform.h>

=A0#include "fs_enet.h"

drivers/net/fs_enet/mii-bitbang.c +0 -0
@@ -149,31 +150,12 @@ static int __devinit fs_mii_bitbang_init(struct mii=

_bus *bus,

drivers/net/fs_enet/mii-bitbang.c static int __devinit fs_mii_bitbang_init(struct mii= · line 152

Quoted 4 lines
drivers/net/fs_enet/mii-bitbang.c +0 -1
 =A0 =A0 =A0 =A0return 0;
 =A0}
 
-static void __devinit add_phy(struct mii_bus *bus, struct device_node *n=

p)

Quoted 17 lines
drivers/net/fs_enet/mii-bitbang.c +0 -16
-{
- =A0 =A0 =A0 const u32 *data;
- =A0 =A0 =A0 int len, id, irq;
-
- =A0 =A0 =A0 data =3D of_get_property(np, "reg", &len);
- =A0 =A0 =A0 if (!data || len !=3D 4)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
-
- =A0 =A0 =A0 id =3D *data;
- =A0 =A0 =A0 bus->phy_mask &=3D ~(1 << id);
-
- =A0 =A0 =A0 irq =3D of_irq_to_resource(np, 0, NULL);
- =A0 =A0 =A0 if (irq !=3D NO_IRQ)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus->irq[id] =3D irq;
-}
-
 =A0static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 const struct of_device_id *match)

drivers/net/fs_enet/mii-bitbang.c static int __devinit fs_enet_mdio_probe(struct of_d=

Quoted 10 lines

=A0{
- =A0 =A0 =A0 struct device_node *np =3D NULL;
=A0 =A0 =A0 =A0struct mii_bus *new_bus;
=A0 =A0 =A0 =A0struct bb_info *bitbang;
=A0 =A0 =A0 =A0int ret =3D -ENOMEM;
- =A0 =A0 =A0 int i;

=A0 =A0 =A0 =A0bitbang =3D kzalloc(sizeof(struct bb_info), GFP_KERNEL); =A0 =A0 =A0 =A0if (!bitbang)

drivers/net/fs_enet/mii-bitbang.c +0 -0
@@ -196,17 +178,10 @@ static int __devinit fs_enet_mdio_probe(struct of_d=

evice *ofdev,

drivers/net/fs_enet/mii-fec.=

Quoted 19 lines
drivers/net/fs_enet/mii-bitbang.c +1 -8
 =A0 =A0 =A0 =A0if (!new_bus->irq)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_unmap_regs;
 
- =A0 =A0 =A0 for (i =3D 0; i < PHY_MAX_ADDR; i++)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 new_bus->irq[i] =3D -1;
-
- =A0 =A0 =A0 while ((np =3D of_get_next_child(ofdev->node, np)))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!strcmp(np->type, "ethernet-phy"))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 add_phy(new_bus, np);
-
 =A0 =A0 =A0 =A0new_bus->parent =3D &ofdev->dev;
 =A0 =A0 =A0 =A0dev_set_drvdata(&ofdev->dev, new_bus);
 
- =A0 =A0 =A0 ret =3D mdiobus_register(new_bus);
+ =A0 =A0 =A0 ret =3D of_mdiobus_register(new_bus, ofdev->node);
 =A0 =A0 =A0 =A0if (ret)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_free_irqs;
 
drivers/net/fs_enet/mii-fec.= renamed from drivers/net/fs_enet/mii-fec.c +0 -0

c

drivers/net/fs_enet/mii-fec.c static int fs_enet_fec_mii_reset(struct mii_bus *bus=

Quoted 4 lines

index 28077cc..bdc3160 100644

drivers/net/fs_enet/mii-fec.c +0 -0
@@ -102,23 +102,6 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus=

)

drivers/net/fs_enet/mii-fec.c static int fs_enet_fec_mii_reset(struct mii_bus *bus= · line 105

Quoted 4 lines
drivers/net/fs_enet/mii-fec.c +0 -1
 =A0 =A0 =A0 =A0return 0;
 =A0}
 
-static void __devinit add_phy(struct mii_bus *bus, struct device_node *n=

p)

Quoted 17 lines
drivers/net/fs_enet/mii-fec.c +0 -16
-{
- =A0 =A0 =A0 const u32 *data;
- =A0 =A0 =A0 int len, id, irq;
-
- =A0 =A0 =A0 data =3D of_get_property(np, "reg", &len);
- =A0 =A0 =A0 if (!data || len !=3D 4)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
-
- =A0 =A0 =A0 id =3D *data;
- =A0 =A0 =A0 bus->phy_mask &=3D ~(1 << id);
-
- =A0 =A0 =A0 irq =3D of_irq_to_resource(np, 0, NULL);
- =A0 =A0 =A0 if (irq !=3D NO_IRQ)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 bus->irq[id] =3D irq;
-}
-
 =A0static int __devinit fs_enet_mdio_probe(struct of_device *ofdev,
Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0 const struct of_device_id *match)

drivers/net/fs_enet/mii-fec.c static int __devinit fs_enet_mdio_probe(struct of_d=

Quoted 2 lines

=A0{

drivers/net/fs_enet/mii-fec.c +0 -0
@@ -165,17 +148,10 @@ static int __devinit fs_enet_mdio_probe(struct of_d=

evice *ofdev,

Quoted 31 lines
drivers/net/fs_enet/mii-fec.c +1 -8
 =A0 =A0 =A0 =A0if (!new_bus->irq)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_unmap_regs;
 
- =A0 =A0 =A0 for (i =3D 0; i < PHY_MAX_ADDR; i++)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 new_bus->irq[i] =3D -1;
-
- =A0 =A0 =A0 while ((np =3D of_get_next_child(ofdev->node, np)))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!strcmp(np->type, "ethernet-phy"))
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 add_phy(new_bus, np);
-
 =A0 =A0 =A0 =A0new_bus->parent =3D &ofdev->dev;
 =A0 =A0 =A0 =A0dev_set_drvdata(&ofdev->dev, new_bus);
 
- =A0 =A0 =A0 ret =3D mdiobus_register(new_bus);
+ =A0 =A0 =A0 ret =3D of_mdiobus_register(new_bus, ofdev->node);
 =A0 =A0 =A0 =A0if (ret)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_free_irqs;
 
include/linux/fs_enet_pd.h +0 -0
index 8300cab..51b7934 100644
@@ -17,6 +17,7 @@

=A0#define FS_ENET_PD_H

=A0#include <linux/string.h>
+#include <linux/of_mdio.h>
=A0#include <asm/types.h>

=A0#define FS_ENET_NAME =A0 "fs_enet"

include/linux/fs_enet_pd.h struct fs_platform_info { · line 133

Quoted 4 lines
include/linux/fs_enet_pd.h +0 -1
@@ -130,10 +131,7 @@ struct fs_platform_info {
 
 =A0 =A0 =A0 =A0u32 device_flags;
 
- =A0 =A0 =A0 int phy_addr; =A0 =A0 =A0 =A0 =A0 /* the phy address (-1 no=

phy) */

include/linux/fs_enet_pd.h struct fs_platform_info { · line 135

Quoted 2 lines
include/linux/fs_enet_pd.h +0 -2
- =A0 =A0 =A0 char bus_id[16];
- =A0 =A0 =A0 int phy_irq; =A0 =A0 =A0 =A0 =A0 =A0/* the phy irq (if it e=

xists) =A0*/

Quoted 5 lines
include/linux/fs_enet_pd.h +1 -1
-
+ =A0 =A0 =A0 struct device_node *phy_node;
 =A0 =A0 =A0 =A0const struct fs_mii_bus_info *bus_info;
 

=A0 =A0 =A0 =A0int rx_ring, tx_ring; =A0 /* number of buffers on rx =A0 =

=A0 */

Quoted 2 lines

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

maintainer
#17 lore raw

Re: [PATCH 9/9] net/fs_enet: Rework fs_enet driver to use of_mdio infrastructure

From: Grant Likely <[email protected]>
Date: Wed, 18 Mar 2009 23:07:35 -0600

Quoted 1 line

RFC, please don't apply yet.

You know, if you have posted a "0/9" patch explaining the purpose and intent of the patch series, you'd only need to re-shit into my inbox one time to say this stuff is RFC and "don't apply yet" instead of 9 FREAKIN' TIMES!

#18 lore raw

Re: [PATCH 9/9] net/fs_enet: Rework fs_enet driver to use of_mdio infrastructure

Quoted 9 lines · David Miller

From: Grant Likely <[email protected]>
Date: Wed, 18 Mar 2009 23:07:35 -0600

Quoted 1 line

RFC, please don't apply yet.

You know, if you have posted a "0/9" patch explaining the purpose and intent of the patch series, you'd only need to re-shit into my inbox one time to say this stuff is RFC and "don't apply yet" instead of 9 FREAKIN' TIMES!

Ugh. Sorry. My lame excuse is that its late and I'm tired. Normally I do actually know better.

g.

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#19 lore raw
In reply to Grant Likely

Bah! Messed up the 'stg mail' command when sending this series and the 'RFC' tag didn't get added.

This is firmly in the RFC category. Please don't apply. It doesn't have the level of polish that I'm happy with.

This series is intended to make phy_device connecting simpler and more robust by using the PHY's device_node as the search key when connecting to PHY. Changes are made to both the MDIO busses to extract the PHY data out of the device tree, and to the drivers to use a common helper function for finding the PHY it is interested in.

Comments please.
g.

drivers/of/base.c int of_modalias_node(struct device_node *node, char =

Quoted 18 lines · Grant Likely

From: Grant Likely <[email protected]>

of_parse_phandle() is a helper function to read and parse a phandle property and return a pointer to the resulting device_node.

---

=A0drivers/of/base.c =A0| =A0 23 +++++++++++++++++++++++ =A0include/linux/of.h | =A0 =A03 +++
=A02 files changed, 26 insertions(+), 0 deletions(-)

drivers/of/base.c +0 -0
index cd17092..1eaada4 100644
@@ -494,6 +494,29 @@ int of_modalias_node(struct device_node *node, char =

*modalias, int len)

Quoted 4 lines
drivers/of/base.c +0 -0
 =A0EXPORT_SYMBOL_GPL(of_modalias_node);
 

=A0/**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointe=

r

Quoted 3 lines

+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index=

into

drivers/of/base.c

Quoted 6 lines

+ * =A0 =A0 =A0 =A0 the table
+ *
+ * Returns the device_node pointer pointed to by the phandle, or NULL
+ */

drivers/of/base.c +2 -0
+struct device_node *
+of_parse_phandle(struct device_node *np, const char *phandle_name, int i=

ndex)

Quoted 13 lines
drivers/of/base.c +13 -0
+{
+ =A0 =A0 =A0 const phandle *phandle;
+ =A0 =A0 =A0 int size;
+
+ =A0 =A0 =A0 phandle =3D of_get_property(np, phandle_name, &size);
+ =A0 =A0 =A0 if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
+
+ =A0 =A0 =A0 return of_find_node_by_phandle(phandle[index]);
+}
+EXPORT_SYMBOL(of_parse_phandle);
+
+/**
Quoted 1 line

=A0* of_parse_phandles_with_args - Find a node pointed by phandle in a li=

st

Quoted 1 line

=A0* @np: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pointer to a device tree node co=

ntaining a list

Quoted 8 lines

=A0* @list_name: property name that contains a list

include/linux/of.h +0 -0
index 6a7efa2..7be2d10 100644
@@ -77,6 +77,9 @@ extern int of_n_size_cells(struct device_node *np);

=A0extern const struct of_device_id *of_match_node(
=A0 =A0 =A0 =A0const struct of_device_id *matches, const struct device_no=

de *node);

Quoted 1 line

=A0extern int of_modalias_node(struct device_node *node, char *modalias, =

int len);

Quoted 2 lines

+extern struct device_node *of_parse_phandle(struct device_node *np,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 const char *phandle_name,

Quoted 1 line

+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=

=A0 =A0 =A0 int index);

Quoted 5 lines

=A0extern int of_parse_phandles_with_args(struct device_node *np, =A0 =A0 =A0 =A0const char *list_name, const char *cells_name, int index, =A0 =A0 =A0 =A0struct device_node **out_node, const void **out_args);

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#20 lore raw
In reply to Grant Likely
Quoted 19 lines · Grant Likely

From: Grant Likely <[email protected]>

of_parse_phandle() is a helper function to read and parse a phandle property and return a pointer to the resulting device_node.

---

 drivers/of/base.c  |   23 +++++++++++++++++++++++
 include/linux/of.h |    3 +++
 2 files changed, 26 insertions(+), 0 deletions(-)
drivers/of/base.c +0 -0
index cd17092..1eaada4 100644
@@ -494,6 +494,29 @@ int of_modalias_node(struct device_node *node, char *modalias, int len)
 EXPORT_SYMBOL_GPL(of_modalias_node);

drivers/of/base.c int of_modalias_node(struct device_node *node, char *modalias, int len) · line 504

Quoted 10 lines
drivers/of/base.c +8 -0
 
 /**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ *         the table
+ *
+ * Returns the device_node pointer pointed to by the phandle, or NULL
+ */

I think it would good to follow the convention of many of the other of_ routines and have an explicit comment about the refcounting, eg:

* Returns a node pointer with refcount incremented, use
* of_node_put() on it when done.

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person