Message ID | 20200424031617.24033-2-calvin.johnson@oss.nxp.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Introduce new APIs to support phylink and phy layers | expand |
On 4/23/2020 8:16 PM, Calvin Johnson wrote: > Define fwnode_phy_find_device() to iterate an mdiobus and find the > phy device of the provided phy fwnode. > > Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com> If you forget to update the MAINTAINERS file, or do not place this code under drivers/net/phy/* or drivers/of/of_mdio.c then this is going to completely escape the sight of the PHYLIB/PHYLINK maintainers...
On Thu, Apr 23, 2020 at 08:45:03PM -0700, Florian Fainelli wrote: > > > On 4/23/2020 8:16 PM, Calvin Johnson wrote: > > Define fwnode_phy_find_device() to iterate an mdiobus and find the > > phy device of the provided phy fwnode. > > > > Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com> > > If you forget to update the MAINTAINERS file, or do not place this code > under drivers/net/phy/* or drivers/of/of_mdio.c then this is going to > completely escape the sight of the PHYLIB/PHYLINK maintainers... Did you mean the following change? --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6354,6 +6354,7 @@ F: Documentation/devicetree/bindings/net/ethernet-phy.yaml F: Documentation/devicetree/bindings/net/mdio* F: Documentation/devicetree/bindings/net/qca,ar803x.yaml F: Documentation/networking/phy.rst +F: drivers/base/property.c F: drivers/net/phy/ F: drivers/of/of_mdio.c Do I need to send v2 with this? On checking CC and MAINTAINERS, I see only hkallweit1@gmail.com was missed. Please let me know. Regards Calvin
On Fri, Apr 24, 2020 at 02:56:51PM +0530, Calvin Johnson wrote: > On Thu, Apr 23, 2020 at 08:45:03PM -0700, Florian Fainelli wrote: > > > > > > On 4/23/2020 8:16 PM, Calvin Johnson wrote: > > > Define fwnode_phy_find_device() to iterate an mdiobus and find the > > > phy device of the provided phy fwnode. > > > > > > Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com> > > > > If you forget to update the MAINTAINERS file, or do not place this code > > under drivers/net/phy/* or drivers/of/of_mdio.c then this is going to > > completely escape the sight of the PHYLIB/PHYLINK maintainers... > > Did you mean the following change? > > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -6354,6 +6354,7 @@ F: > Documentation/devicetree/bindings/net/ethernet-phy.yaml > F: Documentation/devicetree/bindings/net/mdio* > F: Documentation/devicetree/bindings/net/qca,ar803x.yaml > F: Documentation/networking/phy.rst > +F: drivers/base/property.c > F: drivers/net/phy/ > F: drivers/of/of_mdio.c I really doubt the phy maintainers want to maintain all of property.c, right? Please be kinder... greg k-h
On Fri, Apr 24, 2020 at 12:27 PM Calvin Johnson <calvin.johnson@oss.nxp.com> wrote: > On Thu, Apr 23, 2020 at 08:45:03PM -0700, Florian Fainelli wrote: > > On 4/23/2020 8:16 PM, Calvin Johnson wrote: > > If you forget to update the MAINTAINERS file, or do not place this code > > under drivers/net/phy/* or drivers/of/of_mdio.c then this is going to > > completely escape the sight of the PHYLIB/PHYLINK maintainers... > > Did you mean the following change? I don't think this is an appreciated option. Second one was to locate this code under drivers/net, which may be better. And perhaps other not basic (to the properties) stuff should be also moved to respective subsystems.
On Fri, Apr 24, 2020 at 08:46:16AM +0530, Calvin Johnson wrote: > Define fwnode_phy_find_device() to iterate an mdiobus and find the > phy device of the provided phy fwnode. > > Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com> > --- > > drivers/base/property.c | 41 ++++++++++++++++++++++++++++++++++++++++ > include/linux/property.h | 5 +++++ > 2 files changed, 46 insertions(+) > > diff --git a/drivers/base/property.c b/drivers/base/property.c > index 5f35c0ccf5e0..7c0c14c800b7 100644 > --- a/drivers/base/property.c > +++ b/drivers/base/property.c > @@ -870,6 +870,47 @@ int device_get_phy_mode(struct device *dev) > } > EXPORT_SYMBOL_GPL(device_get_phy_mode); > > +/** > + * fwnode_phy_find_device - Give a phy fwnode to find the corresponding > + * phy_device on the mdiobus. > + * @phy_fwnode: Pointer to the phy's fwnode. > + * > + * If successful, returns a pointer to the phy_device with the embedded > + * struct device refcount incremented by one, or NULL on failure. > + */ > +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) > +{ > + struct device *d; > + struct mdio_device *mdiodev; > + > + if (!phy_fwnode) > + return NULL; > + > + d = bus_find_device_by_fwnode(&mdio_bus_type, phy_fwnode); > + if (d) { > + mdiodev = to_mdio_device(d); > + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) > + return to_phy_device(d); > + put_device(d); > + } > + > + return NULL; > +} > +EXPORT_SYMBOL(fwnode_phy_find_device); > + > +/** > + * device_phy_find_device - For the given device, get the phy_device > + * @dev: Pointer to the given device > + * > + * If successful, returns a pointer to the phy_device with the embedded > + * struct device refcount incremented by one, or NULL on failure. > + */ > +struct phy_device *device_phy_find_device(struct device *dev) > +{ > + return fwnode_phy_find_device(dev_fwnode(dev)); > +} > +EXPORT_SYMBOL_GPL(device_phy_find_device); Let's not put any more subsystem specific functions into property.c. thanks,
On Fri, Apr 24, 2020 at 12:54:26PM +0300, Andy Shevchenko wrote: > On Fri, Apr 24, 2020 at 12:27 PM Calvin Johnson > <calvin.johnson@oss.nxp.com> wrote: > > On Thu, Apr 23, 2020 at 08:45:03PM -0700, Florian Fainelli wrote: > > > On 4/23/2020 8:16 PM, Calvin Johnson wrote: > > > > If you forget to update the MAINTAINERS file, or do not place this code > > > under drivers/net/phy/* or drivers/of/of_mdio.c then this is going to > > > completely escape the sight of the PHYLIB/PHYLINK maintainers... > > > > Did you mean the following change? > > I don't think this is an appreciated option. > Second one was to locate this code under drivers/net, which may be > better. And perhaps other not basic (to the properties) stuff should > be also moved to respective subsystems. How about placing it in drivers/net/phy/phy_device.c? If it is ok, I can do it in v2. Thanks Calvin
diff --git a/drivers/base/property.c b/drivers/base/property.c index 5f35c0ccf5e0..7c0c14c800b7 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -870,6 +870,47 @@ int device_get_phy_mode(struct device *dev) } EXPORT_SYMBOL_GPL(device_get_phy_mode); +/** + * fwnode_phy_find_device - Give a phy fwnode to find the corresponding + * phy_device on the mdiobus. + * @phy_fwnode: Pointer to the phy's fwnode. + * + * If successful, returns a pointer to the phy_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + */ +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) +{ + struct device *d; + struct mdio_device *mdiodev; + + if (!phy_fwnode) + return NULL; + + d = bus_find_device_by_fwnode(&mdio_bus_type, phy_fwnode); + if (d) { + mdiodev = to_mdio_device(d); + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) + return to_phy_device(d); + put_device(d); + } + + return NULL; +} +EXPORT_SYMBOL(fwnode_phy_find_device); + +/** + * device_phy_find_device - For the given device, get the phy_device + * @dev: Pointer to the given device + * + * If successful, returns a pointer to the phy_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + */ +struct phy_device *device_phy_find_device(struct device *dev) +{ + return fwnode_phy_find_device(dev_fwnode(dev)); +} +EXPORT_SYMBOL_GPL(device_phy_find_device); + static void *fwnode_get_mac_addr(struct fwnode_handle *fwnode, const char *name, char *addr, int alen) diff --git a/include/linux/property.h b/include/linux/property.h index d86de017c689..236d656a2981 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -370,9 +370,14 @@ const void *device_get_match_data(struct device *dev); int device_get_phy_mode(struct device *dev); +struct phy_device *device_phy_find_device(struct device *dev); + void *device_get_mac_address(struct device *dev, char *addr, int alen); int fwnode_get_phy_mode(struct fwnode_handle *fwnode); + +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode); + void *fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr, int alen); struct fwnode_handle *fwnode_graph_get_next_endpoint(
Define fwnode_phy_find_device() to iterate an mdiobus and find the phy device of the provided phy fwnode. Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com> --- drivers/base/property.c | 41 ++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 5 +++++ 2 files changed, 46 insertions(+)