add fwnode based mdiobus registration
Subsystems (4)
v2 cover add fwnode based mdiobus registration
In order to allow the mdiobus to be used completely with fwnode and continue to add fwnode support. This series adds fwnode_mdiobus_register() which allows to register a MDIO bus with a fwnode_handle. This support also works with device-tree and thus allows to integrate of_mdobus_register on top of fwnode support.
ACPI acpi_mdiobus_register() function seems similar enough with fwnode_mdiobus_register() to be integrated into that later one and thus remove ACPI specific registration, keeping only the fwnode one for all types of node. I'm not able to test that specific part so I did not do it in this series.
This series is a subset of the one that was first submitted as a larger series to add swnode support [1]. In this one, it will be focused on fwnode support only since it seems to have reach a consensus that adding fwnode to subsystems makes sense.
Additional information:
The device I'm trying to support is a PCIe card that uses a lan9662 SoC. This card is meant to be used an ethernet switch with 2 x RJ45 ports and 2 x 10G SFPs. The lan966x SoCs can be used in two different ways:
- It can run Linux by itself, on ARM64 cores included in the SoC. This use-case of the lan966x is currently being upstreamed, using a traditional Device Tree representation of the lan996x HW blocks [1] A number of drivers for the different IPs of the SoC have already been merged in upstream Linux.
- It can be used as a PCIe endpoint, connected to a separate platform that acts as the PCIe root complex. In this case, all the devices that are embedded on this SoC are exposed through PCIe BARs and the ARM64 cores of the SoC are not used. Since this is a PCIe card, it can be plugged on any platform, of any architecture supporting PCIe.
The goal if this work is to allow OF based drivers to be reused with software nodes by supporting fwnode in multiple subsystems.
[1] https://lore.kernel.org/netdev/[email protected]/T/
---
Changes in V2:
- Split legacy phy compatible checking in of as preliminary work
- Fix missing static inline in fwnode_mdio.h file
- Split fwnode conversion into multiple patches
- Split OF conversion in multiple patches
- Remove legacy OF handling from fwnode_mdiobus_* variants
- Switch to RFC since net-next is closed
Clément Léger (11):
net: mdio: fwnode: import of_mdiobus_register() and needed functions
net: mdio: fwnode: remove legacy compatible checking for phy child
net: mdio: fwnode: remove legacy phy scanning
net: mdio: fwnode: convert fwnode_mdiobus_register() for fwnode
net: mdio: fwnode: add fwnode_mdiobus_register()
net: mdio: of: wrap fwnode_mdio_parse_addr() in of_mdio_parse_addr()
net: mdio: fwnode: avoid calling of_* functions with non OF nodes
net: mdio: fwnode: allow phy device registration with non OF nodes
net: mdio: of: use fwnode_mdiobus_child_is_phy()
net: mdio: of: use fwnode_mdiobus_register() in of_mdiobus_register()
net: mdio: mscc-miim: use fwnode_mdiobus_register()
drivers/net/mdio/fwnode_mdio.c | 157 +++++++++++++++++++++++++++++- drivers/net/mdio/mdio-mscc-miim.c | 4 +- drivers/net/mdio/of_mdio.c | 100 +------------------ include/linux/fwnode_mdio.h | 28 +++++- include/linux/of_mdio.h | 23 +---- 5 files changed, 188 insertions(+), 124 deletions(-)
Signature · 1 line
2.34.1
RFC PATCH v2 1/11 net: mdio: fwnode: import of_mdiobus_register() and needed functions
Import of_mdiobus_register and needed functions to allow visualizing a pretty diff of the modifications that are going to be done for fwnode support. While importing, did a few modifications to ensure it compiles correctly:
- Renamed of_mdiobus_register() to fwnode_mdiobus_register()
- Renamed of_mdiobus_child_is_phy() to fwnode_mdiobus_child_is_phy()
- Call fwnode_get_phy_id() instead of of_get_phy_id() which is already a wrapper ended up calling fwnode_get_phy_id().
--- drivers/net/mdio/fwnode_mdio.c | 195 +++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+)
drivers/net/mdio/fwnode_mdio.c +195 -0
@@ -9,8 +9,11 @@#include <linux/acpi.h> #include <linux/fwnode_mdio.h> #include <linux/of.h> +#include <linux/of_mdio.h> #include <linux/phy.h> +#define DEFAULT_GPIO_RESET_DELAY 10/* in microseconds */ +MODULE_AUTHOR ("Calvin Johnson <[email protected]>" );MODULE_LICENSE ("GPL" );
@@ -142,3 +145,195 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,return 0 ; }EXPORT_SYMBOL (fwnode_mdiobus_register_phy); + +static int of_mdiobus_register_device (struct mii_bus *mdio, +struct device_node *child,u32 addr) +{ +struct fwnode_handle *fwnode =of_fwnode_handle (child); +struct mdio_device *mdiodev; +int rc; + + mdiodev =mdio_device_create (mdio, addr); +if (IS_ERR (mdiodev)) +return PTR_ERR (mdiodev); + +/* Associate the OF node with the device structure so it +* can be looked up later. +*/ +fwnode_handle_get (fwnode); +device_set_node (&mdiodev->dev, fwnode); + +/* All data is now stored in the mdiodev struct; register it. */ + rc =mdio_device_register (mdiodev); +if (rc) { +mdio_device_free (mdiodev); +of_node_put (child); +return rc; + } + +dev_dbg (&mdio->dev,"registered mdio device %pOFn at address %i\n" , + child, addr); +return 0 ; +} + +/* The following is a list of PHY compatible strings which appear in +* some DTBs. The compatible string is never matched against a PHY +* driver, so is pointless. We only expect devices which are not PHYs +* to have a compatible string, so they can be matched to an MDIO +* driver. Encourage users to upgrade their DT blobs to remove these. +*/ +static const struct of_device_id whitelist_phys[] = { + { .compatible ="brcm,40nm-ephy" }, + { .compatible ="broadcom,bcm5241" }, + { .compatible ="marvell,88E1111" , }, + { .compatible ="marvell,88e1116" , }, + { .compatible ="marvell,88e1118" , }, + { .compatible ="marvell,88e1145" , }, + { .compatible ="marvell,88e1149r" , }, + { .compatible ="marvell,88e1310" , }, + { .compatible ="marvell,88E1510" , }, + { .compatible ="marvell,88E1514" , }, + { .compatible ="moxa,moxart-rtl8201cp" , }, + {} +}; + +/* +* Return true if the child node is for a phy. It must either: +* o Compatible string of "ethernet-phy-idX.X" +* o Compatible string of "ethernet-phy-ieee802.3-c45" +* o Compatible string of "ethernet-phy-ieee802.3-c22" +* o In the white list above (and issue a warning) +* o No compatibility string +* +* A device which is not a phy is expected to have a compatible string +* indicating what sort of device it is. +*/ +bool fwnode_mdiobus_child_is_phy (struct device_node *child) +{ +u32 phy_id; + +if (of_get_phy_id (child, &phy_id) != -EINVAL ) +return true; + +if (of_device_is_compatible (child,"ethernet-phy-ieee802.3-c45" )) +return true; + +if (of_device_is_compatible (child,"ethernet-phy-ieee802.3-c22" )) +return true; + +if (of_match_node (whitelist_phys, child)) { +pr_warn (FW_WARN +"%pOF: Whitelisted compatible string. Please remove\n" , + child); +return true; + } + +if (!of_find_property (child,"compatible" ,NULL )) +return true; + +return false; +} +EXPORT_SYMBOL (fwnode_mdiobus_child_is_phy); + +/** +* of_mdiobus_register - Register mii_bus and create PHYs from the device tree +* @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_device +* for each child node of @np. +*/ +int fwnode_mdiobus_register (struct mii_bus *mdio,struct device_node *np) +{ +struct device_node *child; +bool scanphys = false; +int addr, rc; + +if (!np) +return mdiobus_register (mdio); + +/* Do not continue if the node is disabled */ +if (!of_device_is_available (np)) +return -ENODEV ; + +/* Mask out all PHYs from auto probing. Instead the PHYs listed in +* the device tree are populated after the bus has been registered */ + mdio->phy_mask = ~0 ; + +device_set_node (&mdio->dev,of_fwnode_handle (np)); + +/* Get bus level PHY reset GPIO details */ + mdio->reset_delay_us =DEFAULT_GPIO_RESET_DELAY ; +of_property_read_u32 (np,"reset-delay-us" , &mdio->reset_delay_us); + mdio->reset_post_delay_us =0 ; +of_property_read_u32 (np,"reset-post-delay-us" , &mdio->reset_post_delay_us); + +/* Register the MDIO bus */ + rc =mdiobus_register (mdio); +if (rc) +return rc; + +/* Loop over the child nodes and register a phy_device for each phy */ +for_each_available_child_of_node (np, child) { + addr =of_mdio_parse_addr (&mdio->dev, child); +if (addr <0 ) { + scanphys = true; +continue ; + } + +if (of_mdiobus_child_is_phy (child)) + rc =fwnode_mdiobus_register_phy (mdio, +of_fwnode_handle (child), + addr); +else + rc =of_mdiobus_register_device (mdio, child, addr); + +if (rc == -ENODEV ) +dev_err (&mdio->dev, +"MDIO device at address %d is missing.\n" , + addr); +else if (rc) + goto unregister; + } + +if (!scanphys) +return 0 ; + +/* auto scan for PHYs with empty reg property */ +for_each_available_child_of_node (np, child) { +/* Skip PHYs with reg property set */ +if (of_find_property (child,"reg" ,NULL )) +continue ; + +for (addr =0 ; addr <PHY_MAX_ADDR ; addr++) { +/* skip already registered PHYs */ +if (mdiobus_is_registered_device (mdio, addr)) +continue ; + +/* be noisy to encourage people to set reg property */ +dev_info (&mdio->dev,"scan phy %pOFn at address %i\n" , + child, addr); + +if (of_mdiobus_child_is_phy (child)) { +/* -ENODEV is the return code that PHYLIB has +* standardized on to indicate that bus +* scanning should continue. +*/ + rc =fwnode_mdiobus_register_phy (mdio, +of_fwnode_handle (child), + addr); +if (!rc) +break ; +if (rc != -ENODEV ) + goto unregister; + } + } + } + +return 0 ; + +unregister: +mdiobus_unregister (mdio); +return rc; +} +EXPORT_SYMBOL (fwnode_mdiobus_register);
Signature · 1 line
2.34.1
RFC PATCH v2 2/11 net: mdio: fwnode: remove legacy compatible checking for phy child
In reply to Clément LégerRemove legacy checking for specific phy compatibles.
--- drivers/net/mdio/fwnode_mdio.c | 29 ----------------------------- 1 file changed, 29 deletions(-)
drivers/net/mdio/fwnode_mdio.c +0 -29
@@ -176,33 +176,11 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,return 0 ; } -/* The following is a list of PHY compatible strings which appear in -* some DTBs. The compatible string is never matched against a PHY -* driver, so is pointless. We only expect devices which are not PHYs -* to have a compatible string, so they can be matched to an MDIO -* driver. Encourage users to upgrade their DT blobs to remove these. -*/ -static const struct of_device_id whitelist_phys[] = { - { .compatible ="brcm,40nm-ephy" }, - { .compatible ="broadcom,bcm5241" }, - { .compatible ="marvell,88E1111" , }, - { .compatible ="marvell,88e1116" , }, - { .compatible ="marvell,88e1118" , }, - { .compatible ="marvell,88e1145" , }, - { .compatible ="marvell,88e1149r" , }, - { .compatible ="marvell,88e1310" , }, - { .compatible ="marvell,88E1510" , }, - { .compatible ="marvell,88E1514" , }, - { .compatible ="moxa,moxart-rtl8201cp" , }, - {} -}; -/* * Return true if the child node is for a phy. It must either: * o Compatible string of "ethernet-phy-idX.X" * o Compatible string of "ethernet-phy-ieee802.3-c45" * o Compatible string of "ethernet-phy-ieee802.3-c22" -* o In the white list above (and issue a warning) * o No compatibility string * * A device which is not a phy is expected to have a compatible string
@@ -221,13 +199,6 @@ bool fwnode_mdiobus_child_is_phy(struct device_node *child)if (of_device_is_compatible (child,"ethernet-phy-ieee802.3-c22" ))return true; -if (of_match_node (whitelist_phys, child)) { -pr_warn (FW_WARN -"%pOF: Whitelisted compatible string. Please remove\n" , - child); -return true; - } -if (!of_find_property (child,"compatible" ,NULL ))return true;
Signature · 1 line
2.34.1
RFC PATCH v2 3/11 net: mdio: fwnode: remove legacy phy scanning
In reply to Clément LégerWhen 'reg' property is missing from child MDIO nodes, an automatic scan is done to find phy devices that are present on the bus. Since the 'reg' property is marked as required in the mdio.yaml bindings, remove this legacy scan mechanism.
--- drivers/net/mdio/fwnode_mdio.c | 39 +--------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-)
drivers/net/mdio/fwnode_mdio.c +1 -38
@@ -217,7 +217,6 @@ EXPORT_SYMBOL(fwnode_mdiobus_child_is_phy);int fwnode_mdiobus_register (struct mii_bus *mdio,struct device_node *np) {struct device_node *child; -bool scanphys = false;int addr, rc;if (!np)
@@ -247,10 +246,8 @@ int fwnode_mdiobus_register(struct mii_bus *mdio, struct device_node *np)/* Loop over the child nodes and register a phy_device for each phy */ for_each_available_child_of_node (np, child) { addr =of_mdio_parse_addr (&mdio->dev, child); -if (addr <0 ) { - scanphys = true; +if (addr <0 )continue ; - }if (of_mdiobus_child_is_phy (child)) rc = fwnode_mdiobus_register_phy(mdio,
@@ -267,40 +264,6 @@ int fwnode_mdiobus_register(struct mii_bus *mdio, struct device_node *np) goto unregister; } -if (!scanphys) -return 0 ; - -/* auto scan for PHYs with empty reg property */ -for_each_available_child_of_node (np, child) { -/* Skip PHYs with reg property set */ -if (of_find_property (child,"reg" ,NULL )) -continue ; - -for (addr =0 ; addr <PHY_MAX_ADDR ; addr++) { -/* skip already registered PHYs */ -if (mdiobus_is_registered_device (mdio, addr)) -continue ; - -/* be noisy to encourage people to set reg property */ -dev_info (&mdio->dev,"scan phy %pOFn at address %i\n" , - child, addr); - -if (of_mdiobus_child_is_phy (child)) { -/* -ENODEV is the return code that PHYLIB has -* standardized on to indicate that bus -* scanning should continue. -*/ - rc =fwnode_mdiobus_register_phy (mdio, -of_fwnode_handle (child), - addr); -if (!rc) -break ; -if (rc != -ENODEV ) - goto unregister; - } - } - } -return 0 ; unregister:
Signature · 1 line
2.34.1
RFC PATCH v2 4/11 net: mdio: fwnode: convert fwnode_mdiobus_register() for fwnode
In reply to Clément LégerFirst version was added as a simple copy of of_mdiobus_register() to allow compiling and being able to see the diff of modifications that are going to be done. This commits convert the code that was imported to handle a fwnode_handle properly.
--- drivers/net/mdio/fwnode_mdio.c | 76 ++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 26 deletions(-)
drivers/net/mdio/fwnode_mdio.c +50 -26
@@ -146,10 +146,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, }EXPORT_SYMBOL (fwnode_mdiobus_register_phy); -static int of_mdiobus_register_device (struct mii_bus *mdio, -struct device_node *child,u32 addr) +static int fwnode_mdiobus_register_device (struct mii_bus *mdio, +struct fwnode_handle *child,u32 addr) { -struct fwnode_handle *fwnode =of_fwnode_handle (child);struct mdio_device *mdiodev;int rc;
@@ -160,18 +159,18 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,/* Associate the OF node with the device structure so it * can be looked up later. */ -fwnode_handle_get (fwnode); -device_set_node (&mdiodev->dev, fwnode); +fwnode_handle_get (child); +device_set_node (&mdiodev->dev, child);/* All data is now stored in the mdiodev struct; register it. */ rc =mdio_device_register (mdiodev);if (rc) {mdio_device_free (mdiodev); -of_node_put (child); +fwnode_handle_put (child);return rc; } -dev_dbg (&mdio->dev,"registered mdio device %pOFn at address %i\n" , +dev_dbg (&mdio->dev,"registered mdio device %pfwP at address %i\n" , child, addr);return 0 ; }
@@ -186,26 +185,51 @@ static int of_mdiobus_register_device(struct mii_bus *mdio,* A device which is not a phy is expected to have a compatible string * indicating what sort of device it is. */ -bool fwnode_mdiobus_child_is_phy (struct device_node *child) +bool fwnode_mdiobus_child_is_phy (struct fwnode_handle *child) {u32 phy_id; -if (of_get_phy_id (child, &phy_id) != -EINVAL ) +if (fwnode_get_phy_id (child, &phy_id) != -EINVAL )return true; -if (of_device_is_compatible (child,"ethernet-phy-ieee802.3-c45" )) +if (fwnode_property_match_string (child,"compatible" , +"ethernet-phy-ieee802.3-c45" ) >=0 )return true; -if (of_device_is_compatible (child,"ethernet-phy-ieee802.3-c22" )) +if (fwnode_property_match_string (child,"compatible" , +"ethernet-phy-ieee802.3-c22" ) >=0 )return true; -if (!of_find_property (child,"compatible" ,NULL )) +if (!fwnode_property_present (child,"compatible" ))return true;return false; }EXPORT_SYMBOL (fwnode_mdiobus_child_is_phy); +int fwnode_mdio_parse_addr (struct device *dev, +const struct fwnode_handle *fwnode) +{ +u32 addr; +int ret; + + ret =fwnode_property_read_u32 (fwnode,"reg" , &addr); +if (ret <0 ) { +dev_err (dev,"%pfwP has invalid PHY address\n" , fwnode); +return ret; + } + +/* A PHY must have a reg property in the range [0-31] */ +if (addr >=PHY_MAX_ADDR ) { +dev_err (dev,"%pfwP PHY address %i is too large\n" , + fwnode, addr); +return -EINVAL ; + } + +return addr; +} +EXPORT_SYMBOL (fwnode_mdio_parse_addr); +/** * of_mdiobus_register - Register mii_bus and create PHYs from the device tree * @mdio: pointer to mii_bus structure
@@ -214,29 +238,31 @@ EXPORT_SYMBOL(fwnode_mdiobus_child_is_phy);* This function registers the mii_bus structure and registers a phy_device * for each child node of @np. */ -int fwnode_mdiobus_register (struct mii_bus *mdio,struct device_node *np) +int fwnode_mdiobus_register (struct mii_bus *mdio,struct fwnode_handle *fwnode) { -struct device_node *child; +struct fwnode_handle *child;int addr, rc; -if (!np) +if (!fwnode)return mdiobus_register (mdio);/* Do not continue if the node is disabled */ -if (!of_device_is_available (np)) +if (!fwnode_device_is_available (fwnode))return -ENODEV ;/* Mask out all PHYs from auto probing. Instead the PHYs listed in * the device tree are populated after the bus has been registered */ mdio->phy_mask = ~0 ; -device_set_node (&mdio->dev,of_fwnode_handle (np)); +device_set_node (&mdio->dev, fwnode);/* Get bus level PHY reset GPIO details */ mdio->reset_delay_us =DEFAULT_GPIO_RESET_DELAY ; -of_property_read_u32 (np,"reset-delay-us" , &mdio->reset_delay_us); +fwnode_property_read_u32 (fwnode,"reset-delay-us" , + &mdio->reset_delay_us); mdio->reset_post_delay_us =0 ; -of_property_read_u32 (np,"reset-post-delay-us" , &mdio->reset_post_delay_us); +fwnode_property_read_u32 (fwnode,"reset-post-delay-us" , + &mdio->reset_post_delay_us);/* Register the MDIO bus */ rc =mdiobus_register (mdio);
@@ -244,17 +270,15 @@ int fwnode_mdiobus_register(struct mii_bus *mdio, struct device_node *np)return rc;/* Loop over the child nodes and register a phy_device for each phy */ -for_each_available_child_of_node (np, child) { - addr =of_mdio_parse_addr (&mdio->dev, child); +fwnode_for_each_available_child_node (fwnode, child) { + addr =fwnode_mdio_parse_addr (&mdio->dev, child);if (addr <0 )continue ; -if (of_mdiobus_child_is_phy (child)) - rc =fwnode_mdiobus_register_phy (mdio, -of_fwnode_handle (child), - addr); +if (fwnode_mdiobus_child_is_phy (child)) + rc =fwnode_mdiobus_register_phy (mdio, child, addr);else - rc =of_mdiobus_register_device (mdio, child, addr); + rc =fwnode_mdiobus_register_device (mdio, child, addr);if (rc == -ENODEV ) dev_err(&mdio->dev,
Signature · 1 line
2.34.1
RFC PATCH v2 5/11 net: mdio: fwnode: add fwnode_mdiobus_register()
In reply to Clément LégerIn order to support software node description transparently, add fwnode support with fwnode_mdiobus_register(). This function behaves exactly like of_mdiobus_register() function but using the fwnode node agnostic API. This support might also be used to merge ACPI mdiobus support which is quite similar to the fwnode one.
Some part such as the whitelist matching are kept exclusively for OF nodes since it uses an of_device_id struct and seems tightly coupled with OF. Other parts are generic and will allow to move the existing OF support on top of this fwnode version.
--- include/linux/fwnode_mdio.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
include/linux/fwnode_mdio.h +25 -3
@@ -9,6 +9,9 @@#include <linux/phy.h> #if IS_ENABLED (CONFIG_FWNODE_MDIO ) +int fwnode_mdio_parse_addr (struct device *dev, +const struct fwnode_handle *fwnode); +bool fwnode_mdiobus_child_is_phy (struct fwnode_handle *child);int fwnode_mdiobus_phy_device_register (struct mii_bus *mdio,struct phy_device *phy,struct fwnode_handle *child,u32 addr);
@@ -16,10 +19,23 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,int fwnode_mdiobus_register_phy (struct mii_bus *bus,struct fwnode_handle *child,u32 addr); +int fwnode_mdiobus_register (struct mii_bus *mdio,struct fwnode_handle *fwnode);#else /* CONFIG_FWNODE_MDIO */ -int fwnode_mdiobus_phy_device_register (struct mii_bus *mdio, -struct phy_device *phy, -struct fwnode_handle *child,u32 addr) + +static inline int fwnode_mdio_parse_addr (struct device *dev, +const struct fwnode_handle *fwnode) +{ +return -EINVAL ; +} + +static inline bool fwnode_mdiobus_child_is_phy (struct fwnode_handle *child) +{ +return false; +} + +static inline int +fwnode_mdiobus_phy_device_register (struct mii_bus *mdio,struct phy_device *phy, +struct fwnode_handle *child,u32 addr) {return -EINVAL ; }
@@ -30,6 +46,12 @@ static inline int fwnode_mdiobus_register_phy(struct mii_bus *bus, {return -EINVAL ; } + +static inline int fwnode_mdiobus_register (struct mii_bus *mdio, +struct fwnode_handle *fwnode) +{ +return -EINVAL ; +}#endif #endif /* __LINUX_FWNODE_MDIO_H */
Signature · 1 line
2.34.1
RFC PATCH v2 6/11 net: mdio: of: wrap fwnode_mdio_parse_addr() in of_mdio_parse_addr()
In reply to Clément LégerSince function fwnode_mdio_parse_addr() returns the same value that is done by of_mdio_parse_addr() and has the same behavior, wrap the first one. The function was switched as non static in of_mdio.c to avoid including fwnode_mdio.h in of_mdio.h.
--- drivers/net/mdio/of_mdio.c | 6 ++++++ include/linux/of_mdio.h | 23 +---------------------- 2 files changed, 7 insertions(+), 22 deletions(-)
drivers/net/mdio/of_mdio.c +6 -0
@@ -26,6 +26,12 @@MODULE_AUTHOR ("Grant Likely <[email protected]>" );MODULE_LICENSE ("GPL" ); +int of_mdio_parse_addr (struct device *dev,const struct device_node *np) +{ +return fwnode_mdio_parse_addr (dev,of_fwnode_handle (np)); +} +EXPORT_SYMBOL (of_mdio_parse_addr); +/* Extract the clause 22 phy ID from the compatible string of the form * ethernet-phy-idAAAA.BBBB */ static int of_get_phy_id (struct device_node *device,u32 *phy_id)
include/linux/of_mdio.h +1 -22
@@ -33,28 +33,7 @@ void of_phy_deregister_fixed_link(struct device_node *np);bool of_phy_is_fixed_link (struct device_node *np);int of_mdiobus_phy_device_register (struct mii_bus *mdio,struct phy_device *phy,struct device_node *child,u32 addr); - -static inline int of_mdio_parse_addr (struct device *dev, -const struct device_node *np) -{ -u32 addr; -int ret; - - ret =of_property_read_u32 (np,"reg" , &addr); -if (ret <0 ) { -dev_err (dev,"%s has invalid PHY address\n" , np->full_name); -return ret; - } - -/* A PHY must have a reg property in the range [0-31] */ -if (addr >=PHY_MAX_ADDR ) { -dev_err (dev,"%s PHY address %i is too large\n" , - np->full_name, addr); -return -EINVAL ; - } - -return addr; -} +int of_mdio_parse_addr (struct device *dev,const struct device_node *np);#else /* CONFIG_OF_MDIO */ static inline bool of_mdiobus_child_is_phy (struct device_node *child)
Signature · 1 line
2.34.1
RFC PATCH v2 7/11 net: mdio: fwnode: avoid calling of_* functions with non OF nodes
In reply to Clément LégerWithout this check, of_parse_phandle_with_fixed_args() will be called with whatever the type of the node. Use !is_of_node() which will work for all node types supported by the fwnode API (ACPI, software nodes).
--- drivers/net/mdio/fwnode_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mdio/fwnode_mdio.c +1 -1
@@ -23,7 +23,7 @@ fwnode_find_mii_timestamper(struct fwnode_handle *fwnode)struct of_phandle_args arg;int err; -if (is_acpi_node (fwnode)) +if (!is_of_node (fwnode))return NULL ; err = of_parse_phandle_with_fixed_args(to_of_node(fwnode),
Signature · 1 line
2.34.1
RFC PATCH v2 8/11 net: mdio: fwnode: allow phy device registration with non OF nodes
In reply to Clément LégerWhen using a software node, we also want to call fwnode_mdiobus_phy_device_register() which support all nodes type. Remove the is_of_node() check to allow that.
--- drivers/net/mdio/fwnode_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mdio/fwnode_mdio.c +1 -1
@@ -127,7 +127,7 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,fwnode_handle_put (phy->mdio.dev.fwnode);return rc; } - }else if (is_of_node (child)) { + }else { rc =fwnode_mdiobus_phy_device_register (bus, phy, child, addr);if (rc) {unregister_mii_timestamper (mii_ts);
Signature · 1 line
2.34.1
RFC PATCH v2 9/11 net: mdio: of: use fwnode_mdiobus_child_is_phy()
In reply to Clément LégerSince fwnode_mdiobus_child_is_phy() does almost the same filtering than done by of_mdiobus_child_is_phy() except the legacy OF compatible list checking, modify the later one to use the fwnode variant. However, keep the legacy compatible list checking for legacy purpose.
--- drivers/net/mdio/of_mdio.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-)
drivers/net/mdio/of_mdio.c +1 -22
@@ -32,13 +32,6 @@ int of_mdio_parse_addr(struct device *dev, const struct device_node *np) }EXPORT_SYMBOL (of_mdio_parse_addr); -/* Extract the clause 22 phy ID from the compatible string of the form -* ethernet-phy-idAAAA.BBBB */ -static int of_get_phy_id (struct device_node *device,u32 *phy_id) -{ -return fwnode_get_phy_id (of_fwnode_handle (device), phy_id); -} -int of_mdiobus_phy_device_register (struct mii_bus *mdio,struct phy_device *phy,struct device_node *child,u32 addr) {
@@ -118,17 +111,6 @@ static const struct of_device_id whitelist_phys[] = {*/ bool of_mdiobus_child_is_phy (struct device_node *child) { -u32 phy_id; - -if (of_get_phy_id (child, &phy_id) != -EINVAL ) -return true; - -if (of_device_is_compatible (child,"ethernet-phy-ieee802.3-c45" )) -return true; - -if (of_device_is_compatible (child,"ethernet-phy-ieee802.3-c22" )) -return true; -if (of_match_node (whitelist_phys, child)) { pr_warn(FW_WARN "%pOF: Whitelisted compatible string. Please remove\n",
@@ -136,10 +118,7 @@ bool of_mdiobus_child_is_phy(struct device_node *child)return true; } -if (!of_find_property (child,"compatible" ,NULL )) -return true; - -return false; +return fwnode_mdiobus_child_is_phy (of_fwnode_handle (child)); }EXPORT_SYMBOL (of_mdiobus_child_is_phy);
Signature · 1 line
2.34.1
RFC PATCH v2 10/11 net: mdio: of: use fwnode_mdiobus_register() in of_mdiobus_register()
In reply to Clément LégerNow that fwnode_mdiobus_register() also handle phy registration, modify of_mdiobus_register() to use this one but keep ilegacy scanning of nodes that don't have a "reg" property. The behavior is a bit different since the scanning loop will always be executed even if all nodes have a "reg" property. However, since the "reg" property is checked in that loop, the final outcome will be the same (ie scan only the node that don't have a "reg" property). Since of_mdiobus_register_device() is not used anymore, remove it.
--- drivers/net/mdio/of_mdio.c | 77 +------------------------------------- 1 file changed, 1 insertion(+), 76 deletions(-)
drivers/net/mdio/of_mdio.c +1 -76
@@ -47,36 +47,6 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,return fwnode_mdiobus_register_phy (mdio,of_fwnode_handle (child), addr); } -static int of_mdiobus_register_device (struct mii_bus *mdio, -struct device_node *child,u32 addr) -{ -struct fwnode_handle *fwnode =of_fwnode_handle (child); -struct mdio_device *mdiodev; -int rc; - - mdiodev =mdio_device_create (mdio, addr); -if (IS_ERR (mdiodev)) -return PTR_ERR (mdiodev); - -/* Associate the OF node with the device structure so it -* can be looked up later. -*/ -fwnode_handle_get (fwnode); -device_set_node (&mdiodev->dev, fwnode); - -/* All data is now stored in the mdiodev struct; register it. */ - rc =mdio_device_register (mdiodev); -if (rc) { -mdio_device_free (mdiodev); -of_node_put (child); -return rc; - } - -dev_dbg (&mdio->dev,"registered mdio device %pOFn at address %i\n" , - child, addr); -return 0 ; -} -/* The following is a list of PHY compatible strings which appear in * some DTBs. The compatible string is never matched against a PHY * driver, so is pointless. We only expect devices which are not PHYs
@@ -133,57 +103,12 @@ EXPORT_SYMBOL(of_mdiobus_child_is_phy);int of_mdiobus_register (struct mii_bus *mdio,struct device_node *np) {struct device_node *child; -bool scanphys = false;int addr, rc; -if (!np) -return mdiobus_register (mdio); - -/* Do not continue if the node is disabled */ -if (!of_device_is_available (np)) -return -ENODEV ; - -/* Mask out all PHYs from auto probing. Instead the PHYs listed in -* the device tree are populated after the bus has been registered */ - mdio->phy_mask = ~0 ; - -device_set_node (&mdio->dev,of_fwnode_handle (np)); - -/* Get bus level PHY reset GPIO details */ - mdio->reset_delay_us =DEFAULT_GPIO_RESET_DELAY ; -of_property_read_u32 (np,"reset-delay-us" , &mdio->reset_delay_us); - mdio->reset_post_delay_us =0 ; -of_property_read_u32 (np,"reset-post-delay-us" , &mdio->reset_post_delay_us); - -/* Register the MDIO bus */ - rc =mdiobus_register (mdio); + rc =fwnode_mdiobus_register (mdio,of_fwnode_handle (np));if (rc)return rc; -/* Loop over the child nodes and register a phy_device for each phy */ -for_each_available_child_of_node (np, child) { - addr =of_mdio_parse_addr (&mdio->dev, child); -if (addr <0 ) { - scanphys = true; -continue ; - } - -if (of_mdiobus_child_is_phy (child)) - rc =of_mdiobus_register_phy (mdio, child, addr); -else - rc =of_mdiobus_register_device (mdio, child, addr); - -if (rc == -ENODEV ) -dev_err (&mdio->dev, -"MDIO device at address %d is missing.\n" , - addr); -else if (rc) - goto unregister; - } - -if (!scanphys) -return 0 ; -/* auto scan for PHYs with empty reg property */ for_each_available_child_of_node (np, child) {/* Skip PHYs with reg property set */
Signature · 1 line
2.34.1
RFC PATCH v2 11/11 net: mdio: mscc-miim: use fwnode_mdiobus_register()
In reply to Clément LégerUse fwnode_mdiobus_register() to be compatible with devices described with device-tree and software nodes.
--- drivers/net/mdio/mdio-mscc-miim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mdio/mdio-mscc-miim.c +2 -2
@@ -7,12 +7,12 @@*/ #include <linux/bitops.h> +#include <linux/fwnode_mdio.h> #include <linux/io.h> #include <linux/iopoll.h> #include <linux/kernel.h> #include <linux/mdio/mdio-mscc-miim.h> #include <linux/module.h> -#include <linux/of_mdio.h> #include <linux/phy.h> #include <linux/platform_device.h> #include <linux/property.h>
@@ -288,7 +288,7 @@ static int mscc_miim_probe(struct platform_device *pdev)if (!miim->info)return -EINVAL ; - ret =of_mdiobus_register (bus, pdev->dev.of_node); + ret =fwnode_mdiobus_register (bus,dev_fwnode (&pdev->dev));if (ret <0 ) {dev_err (&pdev->dev,"Cannot register MDIO bus (%d)\n" , ret);return ret;
Signature · 1 line
2.34.1