[PATCH 05/14] phylib: add *_direct() variants of phy_connect and phy_attach functions

Grant Likely grant.likely at secretlab.ca
Sat Apr 18 16:18:35 EST 2009


On Sat, Apr 18, 2009 at 12:08 AM, Grant Likely
<grant.likely at secretlab.ca> wrote:
> On Wed, Apr 15, 2009 at 3:10 PM, Andy Fleming <afleming at freescale.com> wrote:
>>
>> On Mar 31, 2009, at 3:27 AM, Grant Likely wrote:
>>
>>> From: Grant Likely <grant.likely at secretlab.ca>
>>>
>>> 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.
>>>
>>> Signed-off-by: Grant Likely <grant.likely at secretlab.ca>
>>> ---
>>> @@ -312,18 +339,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);
>>
>>
>> Why not just invoke phy_attach(), here, and thereby avoid the duplicate
>> search code?
>
> Yeah, you're right.  I had done it this way for symmetry, but calling
> phy_attach_direct is probably better.

Actually, no, my change is buggy.  I should be calling
phy_connect_direct() here, not phy_attach_direct().  Plus, either way
I do it there will be a few lines of duplicate code.  It will be fixed
in the next version.

g.

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



More information about the Linuxppc-dev mailing list