|
@@ -291,6 +291,33 @@ void phy_prepare_link(struct phy_device *phydev,
|
|
phydev->adjust_link = handler;
|
|
phydev->adjust_link = handler;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * 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
|
|
* phy_connect - connect an ethernet device to a PHY device
|
|
* @dev: the network device to connect
|
|
* @dev: the network device to connect
|
|
@@ -312,18 +339,21 @@ struct phy_device * phy_connect(struct net_device *dev, const char *bus_id,
|
|
phy_interface_t interface)
|
|
phy_interface_t interface)
|
|
{
|
|
{
|
|
struct phy_device *phydev;
|
|
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_connect_direct(dev, phydev, handler, flags, interface);
|
|
|
|
+ if (rc)
|
|
|
|
+ return ERR_PTR(rc);
|
|
|
|
|
|
return phydev;
|
|
return phydev;
|
|
}
|
|
}
|
|
@@ -347,9 +377,9 @@ void phy_disconnect(struct phy_device *phydev)
|
|
EXPORT_SYMBOL(phy_disconnect);
|
|
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
|
|
* @dev: network device to attach
|
|
- * @bus_id: PHY device to attach
|
|
|
|
|
|
+ * @phydev: Pointer to phy_device to attach
|
|
* @flags: PHY device's dev_flags
|
|
* @flags: PHY device's dev_flags
|
|
* @interface: PHY device's interface
|
|
* @interface: PHY device's interface
|
|
*
|
|
*
|
|
@@ -360,22 +390,10 @@ EXPORT_SYMBOL(phy_disconnect);
|
|
* the attaching device, and given a callback for link status
|
|
* the attaching device, and given a callback for link status
|
|
* change. The phy_device is returned to the attaching driver.
|
|
* 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
|
|
/* Assume that if there is no driver, that it doesn't
|
|
* exist, and we should use the genphy driver. */
|
|
* exist, and we should use the genphy driver. */
|
|
@@ -388,13 +406,12 @@ struct phy_device *phy_attach(struct net_device *dev,
|
|
err = device_bind_driver(d);
|
|
err = device_bind_driver(d);
|
|
|
|
|
|
if (err)
|
|
if (err)
|
|
- return ERR_PTR(err);
|
|
|
|
|
|
+ return err;
|
|
}
|
|
}
|
|
|
|
|
|
if (phydev->attached_dev) {
|
|
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;
|
|
phydev->attached_dev = dev;
|
|
@@ -412,13 +429,48 @@ struct phy_device *phy_attach(struct net_device *dev,
|
|
err = phy_scan_fixups(phydev);
|
|
err = phy_scan_fixups(phydev);
|
|
|
|
|
|
if (err < 0)
|
|
if (err < 0)
|
|
- return ERR_PTR(err);
|
|
|
|
|
|
+ return err;
|
|
|
|
|
|
err = phydev->drv->config_init(phydev);
|
|
err = phydev->drv->config_init(phydev);
|
|
|
|
|
|
if (err < 0)
|
|
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;
|
|
return phydev;
|
|
}
|
|
}
|