phy: core: Add phy bulk helpers support
Subsystems (2)
v4 cover phy: core: Add phy bulk helpers support
As discussed in [1], some drivers may do not care the difference between phys. Instead, they only need to treat them as a group and operate them together. This means a bulk operation is needed.
Add some bulk helper functions for phy core by referencing the design of clock/reset subsystem. This can relieve the driver owners' life who needs to handle many phys, as well as each phy error reporting.
The example consumer driver is at [2], with the following function used:
- phy_bulk_init
- phy_bulk_exit
- phy_bulk_power_on
- phy_bulk_power_off
- devm_of_phy_bulk_get_all
The devm_phy_bulk_get_all() is also added as a simple wrapper of devm_of_phy_bulk_get_all().
Note: The patch still uses -EOPNOTSUPP for dummy blob. Instead, I send a new patch [3] for fixing the left function.
[1] https://lore.kernel.org/linux-pci/[email protected]/
[2] https://lore.kernel.org/linux-pci/[email protected]/
[3] https://lore.kernel.org/linux-phy/[email protected]/
Changed from v3:
- https://lore.kernel.org/linux-phy/[email protected]/
patch 5:
1. Fix spell error in the document.
Changed from v2:
- https://lore.kernel.org/linux-phy/[email protected]/
patch 1:
1. Add Andy's tag
2. Update comment for phy_add_device_link
patch 2:
1. Add Andy's tag
2. Update comment for changed function
patch 3:
1. Remove all unused function and make the dependency as static things.
2. Update comments for struct phy_bulk_data and left functions patch 4:
1. Remove all unused function and make the dependency as static things. patch 5:
1. Add phy document for these newly added apis.
Changed from v1:
- https://lore.kernel.org/linux-phy/[email protected]/
patch 1:
1. Update document.
patch 2:
1. Fix document format.
2. Fix several document description.
patch 3:
1. Split into two patches: one for non devm helpers, one for devm helpers.
2. All the bulk helper now use unsigned int for counts.
3. Fix multiple the while loop statement.
4. Rename of_phy_get_parent_count() to of_phy_get_count().
5. Fix some 80 line function problems.
6. Use PTR_ERR_OR_ZERO() to simplify the error handle.
7. Fix zero value in the document
8. Use two separate release function for devm helpers.
Inochi Amaoto (5):
phy: core: Add common helper to add phy phandle device link
phy: core: Add common helper for get phy phandle by index
phy: core: Add phy bulk data helper functions
phy: core: Add managed phy bulk data helper functions
doc: phy: Document some bulk helper functions
Documentation/driver-api/phy/phy.rst | 29 ++ drivers/phy/phy-core.c | 416 ++++++++++++++++++++++++--- include/linux/phy/phy.h | 74 +++++ 3 files changed, 483 insertions(+), 36 deletions(-)
--
2.55.0
PATCH v4 1/5 phy: core: Add common helper to add phy phandle device link
It is very common for adding a device link for phy phandle for device managed phy helper functions. So add a common helper for future reuse.
--- drivers/phy/phy-core.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/phy/phy-core.c +24 -15
@@ -606,6 +606,27 @@ int phy_validate(struct phy *phy, enum phy_mode mode, int submode, }EXPORT_SYMBOL_GPL (phy_validate); +/** +* phy_add_device_link() - Associate the phy with the device +* @dev: the device consuming the PHY +* @phy: the PHY supplied to @dev +* +* Add a device link with @dev as the consumer and @phy as the +* PHY supplier. +*/ +static void phy_add_device_link (struct device *dev,struct phy *phy) +{ +struct device_link *link; + +if (!phy) +return ; + + link =device_link_add (dev, &phy->dev,DL_FLAG_STATELESS ); +if (!link) +dev_dbg (dev,"failed to create device link to %s\n" , +dev_name (phy->dev.parent)); +} +/** * _of_phy_get() - lookup and obtain a reference to a phy by phandle * @np: device_node for which to get the phy
@@ -784,7 +805,6 @@ struct phy *phy_get(struct device *dev, const char *string) {int index =0 ;struct phy *phy; -struct device_link *link;if (dev->of_node) {if (string)
@@ -808,10 +828,7 @@ struct phy *phy_get(struct device *dev, const char *string)get_device (&phy->dev); - link =device_link_add (dev, &phy->dev,DL_FLAG_STATELESS ); -if (!link) -dev_dbg (dev,"failed to create device link to %s\n" , -dev_name (phy->dev.parent)); +phy_add_device_link (dev, phy);return phy; }
@@ -885,7 +902,6 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, const char *con_id) {struct phy **ptr, *phy; -struct device_link *link; ptr =devres_alloc (devm_phy_release,sizeof (*ptr),GFP_KERNEL );if (!ptr)
@@ -900,10 +916,7 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,return phy; } - link =device_link_add (dev, &phy->dev,DL_FLAG_STATELESS ); -if (!link) -dev_dbg (dev,"failed to create device link to %s\n" , -dev_name (phy->dev.parent)); +phy_add_device_link (dev, phy);return phy; }
@@ -955,7 +968,6 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index) {struct phy **ptr, *phy; -struct device_link *link; ptr =devres_alloc (devm_phy_release,sizeof (*ptr),GFP_KERNEL );if (!ptr)
@@ -977,10 +989,7 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, *ptr = phy;devres_add (dev, ptr); - link =device_link_add (dev, &phy->dev,DL_FLAG_STATELESS ); -if (!link) -dev_dbg (dev,"failed to create device link to %s\n" , -dev_name (phy->dev.parent)); +phy_add_device_link (dev, phy);return phy; }
Signature · 1 line
2.55.0
PATCH v4 2/5 phy: core: Add common helper for get phy phandle by index
In reply to Inochi AmaotoTwo phy helpers use index to get phy phandle of a device node, add a common function for the future reuse.
--- drivers/phy/phy-core.c | 51 +++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-)
drivers/phy/phy-core.c +30 -21
@@ -682,33 +682,49 @@ static struct phy *_of_phy_get(struct device_node *np, int index)return phy; } +/** +* of_phy_get_by_index() - lookup and obtain a reference to a phy using a +* device_node by index. +* @np: device_node for which to get the phy +* @index: index of the phy from device's point of view +* +* Returns: the phy device, after getting a refcount to it; or +* -ENODEV if there is no such phy. The caller is responsible for +* calling of_phy_put() to release that count. +*/ +static struct phy *of_phy_get_by_index (struct device_node *np,int index) +{ +struct phy *phy; + + phy =_of_phy_get (np, index); +if (IS_ERR (phy)) +return phy; + +if (!try_module_get (phy->ops->owner)) +return ERR_PTR (-EPROBE_DEFER ); + +get_device (&phy->dev); + +return phy; +} +/** * of_phy_get() - lookup and obtain a reference to a phy using a device_node. * @np: device_node for which to get the phy * @con_id: name of the phy from device's point of view * -* Returns the phy driver, after getting a refcount to it; or +* Returns: the phy device, after getting a refcount to it; or * -ENODEV if there is no such phy. The caller is responsible for * calling of_phy_put() to release that count. */ struct phy *of_phy_get (struct device_node *np,const char *con_id) { -struct phy *phy =NULL ;int index =0 ;if (con_id) index =of_property_match_string (np,"phy-names" , con_id); - phy =_of_phy_get (np, index); -if (IS_ERR (phy)) -return phy; - -if (!try_module_get (phy->ops->owner)) -return ERR_PTR (-EPROBE_DEFER ); - -get_device (&phy->dev); - -return phy; +return of_phy_get_by_index (np, index); }EXPORT_SYMBOL_GPL (of_phy_get);
@@ -958,7 +974,7 @@ EXPORT_SYMBOL_GPL(devm_of_phy_optional_get);* @np: node containing the phy * @index: index of the phy * -* Gets the phy using _of_phy_get(), then gets a refcount to it, +* Gets the phy using of_phy_get_by_index(), then gets a refcount to it, * and associates a device with it using devres. On driver detach, * release function is invoked on the devres data, * then, devres data is freed.
@@ -973,19 +989,12 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,if (!ptr)return ERR_PTR (-ENOMEM ); - phy =_of_phy_get (np, index); + phy =of_phy_get_by_index (np, index);if (IS_ERR (phy)) {devres_free (ptr);return phy; } -if (!try_module_get (phy->ops->owner)) { -devres_free (ptr); -return ERR_PTR (-EPROBE_DEFER ); - } - -get_device (&phy->dev); - *ptr = phy;devres_add (dev, ptr);
Signature · 1 line
2.55.0
PATCH v4 3/5 phy: core: Add phy bulk data helper functions
In reply to Inochi AmaotoAdd several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
This can relieve the driver owners' life who needs to handle many phys, as well as each phy error reporting.
--- drivers/phy/phy-core.c | 253 ++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 55 +++++++++ 2 files changed, 308 insertions(+)
drivers/phy/phy-core.c +253 -0
@@ -1004,6 +1004,259 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, }EXPORT_SYMBOL_GPL (devm_of_phy_get_by_index); +/** +* of_phy_get_count() - Get the number of phys of a device node +* @np: device_node for which to get the phy +* +* Return: the phy count if successful, %0 if no phy handle is found, +* negative error value if error occurs. +*/ +static int of_phy_get_count (const struct device_node *np) +{ +int count; + + count =of_count_phandle_with_args (np,"phys" ,"#phy-cells" ); + +if (count == -ENOENT ) +return 0 ; + +return count; +} + +/** +* phy_bulk_put() - release a set of PHYs +* @dev: device that acquired the PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data with PHYs set +* +* Releases the PHY references in reverse order and clears the PHY pointer in +* each entry. The caller owns the phys array and is responsible for freeing it +* if necessary. +*/ +static void phy_bulk_put (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +while (num_phys--) { +if (!IS_ERR_OR_NULL (phys[num_phys].phy)) +phy_put (dev, phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +} + +/** +* of_phy_bulk_put() - release a set of PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data with PHYs set +* +* Releases the PHY references in reverse order and clears the PHY pointer in +* each entry. The caller owns the phys array and is responsible for freeing it +* if necessary. +*/ +static void of_phy_bulk_put (unsigned int num_phys,struct phy_bulk_data *phys) +{ +while (num_phys--) { +of_phy_put (phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +} + +static int of_phy_bulk_get_by_index (struct device_node *np, +unsigned int num_phys, +struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + phys[i].id =NULL ; + phys[i].phy =NULL ; + } + +for (i =0 ; i < num_phys; i++) { +of_property_read_string_index (np,"phy-names" , i, &phys[i].id); + + phys[i].phy =of_phy_get_by_index (np, i); + + ret =PTR_ERR_OR_ZERO (phys[i].phy); +if (ret) { + phys[i].phy =NULL ; + goto err; + } + } + +return 0 ; + +err: +of_phy_bulk_put (i, phys); + +return ret; +} + +/** +* of_phy_bulk_get_all() - obtain all PHYs from a device node +* @np: device node containing the PHY references +* @phys: pointer to store the allocated array of struct phy_bulk_data +* +* Gets every PHY referenced by the phys property in index order. PHY names are +* read from phy-names when present. +* +* Return: the number of PHYs on success, %0 if no PHYs are found, or a +* negative error code otherwise +*/ +static int of_phy_bulk_get_all (struct device_node *np, +struct phy_bulk_data **phys) +{ +struct phy_bulk_data *phy_bulk; +int num_phys; +int ret; + + num_phys =of_phy_get_count (np); +if (num_phys <=0 ) +return num_phys; + + phy_bulk =kmalloc_objs (*phy_bulk, num_phys); +if (!phy_bulk) +return -ENOMEM ; + + ret =of_phy_bulk_get_by_index (np, num_phys, phy_bulk); +if (ret) { +kfree (phy_bulk); +return ret; + } + + *phys = phy_bulk; + +return num_phys; +} + +/** +* phy_bulk_put_all() - release and free PHYs +* @dev: device that acquired the PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to release and free +*/ +static void phy_bulk_put_all (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +if (IS_ERR_OR_NULL (phys)) +return ; + +phy_bulk_put (dev, num_phys, phys); +kfree (phys); +} + +/** +* phy_bulk_init() - initialize multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to initialize +* +* Initializes the PHYs in array order. If an initialization fails, all PHYs +* initialized by this call are exited in reverse order. +* +* Return: %0 if successful, a negative error code otherwise +*/ +int phy_bulk_init (unsigned int num_phys,struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + ret =phy_init (phys[i].phy); +if (ret) + goto err; + } + +return 0 ; + +err: +while (i--) +phy_exit (phys[i].phy); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_init); + +/** +* phy_bulk_exit() - exit multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to exit +* +* Exits the PHYs in reverse array order. All PHYs are processed even if an +* error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; + +while (num_phys--) { + err =phy_exit (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_exit); + +/** +* phy_bulk_power_on() - power on multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to power on +* +* Powers on the PHYs in array order. If a power-on operation fails, all PHYs +* powered on by this call are powered off in reverse order. +* +* Return: %0 if successful, a negative error code otherwise +*/ +int phy_bulk_power_on (unsigned int num_phys,struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + ret =phy_power_on (phys[i].phy); +if (ret) + goto err; + } + +return 0 ; + +err: +while (i--) +phy_power_off (phys[i].phy); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_power_on); + +/** +* phy_bulk_power_off() - power off multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to power off +* +* Powers off the PHYs in reverse array order. All PHYs are processed even if +* an error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_power_off (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; + +while (num_phys--) { + err =phy_power_off (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_power_off); +/** * phy_create() - create a new phy * @dev: device that is creating the new phy
include/linux/phy/phy.h +55 -0
73 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
Quoted 6 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
This can relieve the driver owners' life who needs to handle many phys, as well as each phy error reporting.
...
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+/** +* of_phy_get_count() - Get the number of phys of a device node +* @np: device_node for which to get the phy +*
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1019
Quoted 10 lines
drivers/phy/phy-core.c +9
-0+* Return: the phy count if successful, %0 if no phy handle is found, +* negative error value if error occurs. +*/ +static int of_phy_get_count (const struct device_node *np) +{ +int count; + + count =of_count_phandle_with_args (np,"phys" ,"#phy-cells" ); +
I would drop this blank line.
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1021
Quoted 2 lines
drivers/phy/phy-core.c +2
-0+if (count == -ENOENT ) +return 0 ;
I'm not sure about usefulness of this kind of trick in the _count API.
Quoted 2 lines
(quoted diff) +2
-0+ return count; +}
...
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1040
Quoted 6 lines
drivers/phy/phy-core.c +5
-0+static void phy_bulk_put (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +while (num_phys--) { +if (!IS_ERR_OR_NULL (phys[num_phys].phy))
This should be part of phy_put(). In general many kernel resource release APIs are NULL and/or error pointer aware. This is a slow path and it makes user's life easier
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+phy_put (dev, phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +}
...
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1059
Quoted 6 lines
drivers/phy/phy-core.c +5
-0+static void of_phy_bulk_put (unsigned int num_phys,struct phy_bulk_data *phys) +{ +while (num_phys--) { +of_phy_put (phys[num_phys].phy); + phys[num_phys].phy =NULL ;
Is NULLification mandatory?
Quoted 2 lines
(quoted diff) +2
-0+ } +}
...
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1073
Quoted 11 lines
drivers/phy/phy-core.c +11
-0+static int of_phy_bulk_get_by_index (struct device_node *np, +unsigned int num_phys, +struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + phys[i].id =NULL ; + phys[i].phy =NULL ; + }
But why? The below does the assognments.
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1082
Quoted 8 lines
drivers/phy/phy-core.c +7
-0+for (i =0 ; i < num_phys; i++) { +of_property_read_string_index (np,"phy-names" , i, &phys[i].id); + phys[i].phy =of_phy_get_by_index (np, i); + + ret =PTR_ERR_OR_ZERO (phys[i].phy); +if (ret) { + phys[i].phy =NULL ;
Same Q: do we need a NULLification in this case? Perhaps the respective APIs should be error pointer aware?
Quoted 11 lines
drivers/phy/phy-core.c +11
-0+ goto err; + } + } + +return 0 ; + +err: +of_phy_bulk_put (i, phys); + +return ret; +}
...
Quoted 12 lines
drivers/phy/phy-core.c +12
-0+/** +* phy_bulk_exit() - exit multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to exit +* +* Exits the PHYs in reverse array order. All PHYs are processed even if an +* error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys) +{
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1200
Quoted 10 lines
drivers/phy/phy-core.c +10
-0+int ret =0 ; +int err; + +while (num_phys--) { + err =phy_exit (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret;
So, we return an arbitrary error and inconsistent state of the phys[] array. What can caller do about all this? Any type of recovery? TL;DR:
I put in doubt the function prototype and the implementation (error handling).
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
Quoted 42 lines · Andy Shevchenko
Quoted 6 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
This can relieve the driver owners' life who needs to handle many phys, as well as each phy error reporting.
...
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+/** +* of_phy_get_count() - Get the number of phys of a device node +* @np: device_node for which to get the phy +* drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1019
Quoted 10 lines
drivers/phy/phy-core.c +9
-0+* Return: the phy count if successful, %0 if no phy handle is found, +* negative error value if error occurs. +*/ +static int of_phy_get_count (const struct device_node *np) +{ +int count; + + count =of_count_phandle_with_args (np,"phys" ,"#phy-cells" ); +I would drop this blank line.
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1021
Quoted 2 lines
drivers/phy/phy-core.c +2
-0+if (count == -ENOENT ) +return 0 ;I'm not sure about usefulness of this kind of trick in the
_countAPI.Quoted 2 lines
(quoted diff) +2
-0+ return count; +}...
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+static void phy_bulk_put (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +while (num_phys--) {
Quoted 6 lines
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1040
Quoted 1 line
drivers/phy/phy-core.c +1
-0+if (!IS_ERR_OR_NULL (phys[num_phys].phy))This should be part of
phy_put(). In general many kernel resource release APIs are NULL and/or error pointer aware. This is a slow path and it makes user's life easier
Something reasonable, As of_phy_put does have a check, but phy_put does not and it use phy->dev directly. I think this is acceptable QoL change.
Quoted 7 lines
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+phy_put (dev, phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +}...
Quoted 9 lines
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1059
Quoted 6 lines
drivers/phy/phy-core.c +5
-0+static void of_phy_bulk_put (unsigned int num_phys,struct phy_bulk_data *phys) +{ +while (num_phys--) { +of_phy_put (phys[num_phys].phy); + phys[num_phys].phy =NULL ;Is NULLification mandatory?
I think it may not be as the phy is managed internally. But I think it could be keeped to avoid misuse.
Quoted 5 lines
Quoted 2 lines
(quoted diff) +2
-0+ } +}...
Quoted 14 lines
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1073
Quoted 11 lines
drivers/phy/phy-core.c +11
-0+static int of_phy_bulk_get_by_index (struct device_node *np, +unsigned int num_phys, +struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + phys[i].id =NULL ; + phys[i].phy =NULL ; + }But why? The below does the assognments.
I refered of_clk_bulk_get(). And at least I think the init for phy field should be kept for an initial state. For id, I think it is possible to be removed.
Quoted 12 lines
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1082
Quoted 8 lines
drivers/phy/phy-core.c +7
-0+for (i =0 ; i < num_phys; i++) { +of_property_read_string_index (np,"phy-names" , i, &phys[i].id); + phys[i].phy =of_phy_get_by_index (np, i); + + ret =PTR_ERR_OR_ZERO (phys[i].phy); +if (ret) { + phys[i].phy =NULL ;Same Q: do we need a NULLification in this case? Perhaps the respective APIs should be error pointer aware?
I think this should be removed to keep the error info. This is the thing I have missed. Thanks.
Quoted 32 lines
Quoted 11 lines
drivers/phy/phy-core.c +11
-0+ goto err; + } + } + +return 0 ; + +err: +of_phy_bulk_put (i, phys); + +return ret; +}...
Quoted 18 lines
drivers/phy/phy-core.c +18
-0+/** +* phy_bulk_exit() - exit multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to exit +* +* Exits the PHYs in reverse array order. All PHYs are processed even if an +* error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; + +while (num_phys--) { + err =phy_exit (phys[num_phys].phy); +if (err && !ret)
Quoted 9 lines
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1200
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+ ret = err; + } + +return ret;So, we return an arbitrary error and inconsistent state of the phys[] array. What can caller do about all this? Any type of recovery? TL;DR:
I put in doubt the function prototype and the implementation (error handling).
This is something I have done wrongly. It should return when the first error occurs. So the caller can continue to exit the left phys.
As the phy_exit() does not check whether the init_count is 0, I think an additional check is needed fpr phy_exit() to avoid a negative init_count.
Quoted 7 lines
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Vinod Koul
maintainerRe: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
In reply to Inochi AmaotoQuoted 3 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
Do we have many such examples? Phy is not a many resource like clock/regulators... Do we really need this. How many in kernel users will benefit from this API?
Quoted 356 lines
This can relieve the driver owners' life who needs to handle many phys, as well as each phy error reporting.
Signed-off-by Inochi Amaoto <[email protected]>--- drivers/phy/phy-core.c | 253 ++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 55 +++++++++ 2 files changed, 308 insertions(+)drivers/phy/phy-core.c +253
-0@@ -1004,6 +1004,259 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, }EXPORT_SYMBOL_GPL (devm_of_phy_get_by_index); +/** +* of_phy_get_count() - Get the number of phys of a device node +* @np: device_node for which to get the phy +* +* Return: the phy count if successful, %0 if no phy handle is found, +* negative error value if error occurs. +*/ +static int of_phy_get_count (const struct device_node *np) +{ +int count; + + count =of_count_phandle_with_args (np,"phys" ,"#phy-cells" ); + +if (count == -ENOENT ) +return 0 ; + +return count; +} + +/** +* phy_bulk_put() - release a set of PHYs +* @dev: device that acquired the PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data with PHYs set +* +* Releases the PHY references in reverse order and clears the PHY pointer in +* each entry. The caller owns the phys array and is responsible for freeing it +* if necessary. +*/ +static void phy_bulk_put (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +while (num_phys--) { +if (!IS_ERR_OR_NULL (phys[num_phys].phy)) +phy_put (dev, phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +} + +/** +* of_phy_bulk_put() - release a set of PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data with PHYs set +* +* Releases the PHY references in reverse order and clears the PHY pointer in +* each entry. The caller owns the phys array and is responsible for freeing it +* if necessary. +*/ +static void of_phy_bulk_put (unsigned int num_phys,struct phy_bulk_data *phys) +{ +while (num_phys--) { +of_phy_put (phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +} + +static int of_phy_bulk_get_by_index (struct device_node *np, +unsigned int num_phys, +struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + phys[i].id =NULL ; + phys[i].phy =NULL ; + } + +for (i =0 ; i < num_phys; i++) { +of_property_read_string_index (np,"phy-names" , i, &phys[i].id); + + phys[i].phy =of_phy_get_by_index (np, i); + + ret =PTR_ERR_OR_ZERO (phys[i].phy); +if (ret) { + phys[i].phy =NULL ; + goto err; + } + } + +return 0 ; + +err: +of_phy_bulk_put (i, phys); + +return ret; +} + +/** +* of_phy_bulk_get_all() - obtain all PHYs from a device node +* @np: device node containing the PHY references +* @phys: pointer to store the allocated array of struct phy_bulk_data +* +* Gets every PHY referenced by the phys property in index order. PHY names are +* read from phy-names when present. +* +* Return: the number of PHYs on success, %0 if no PHYs are found, or a +* negative error code otherwise +*/ +static int of_phy_bulk_get_all (struct device_node *np, +struct phy_bulk_data **phys) +{ +struct phy_bulk_data *phy_bulk; +int num_phys; +int ret; + + num_phys =of_phy_get_count (np); +if (num_phys <=0 ) +return num_phys; + + phy_bulk =kmalloc_objs (*phy_bulk, num_phys); +if (!phy_bulk) +return -ENOMEM ; + + ret =of_phy_bulk_get_by_index (np, num_phys, phy_bulk); +if (ret) { +kfree (phy_bulk); +return ret; + } + + *phys = phy_bulk; + +return num_phys; +} + +/** +* phy_bulk_put_all() - release and free PHYs +* @dev: device that acquired the PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to release and free +*/ +static void phy_bulk_put_all (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +if (IS_ERR_OR_NULL (phys)) +return ; + +phy_bulk_put (dev, num_phys, phys); +kfree (phys); +} + +/** +* phy_bulk_init() - initialize multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to initialize +* +* Initializes the PHYs in array order. If an initialization fails, all PHYs +* initialized by this call are exited in reverse order. +* +* Return: %0 if successful, a negative error code otherwise +*/ +int phy_bulk_init (unsigned int num_phys,struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + ret =phy_init (phys[i].phy); +if (ret) + goto err; + } + +return 0 ; + +err: +while (i--) +phy_exit (phys[i].phy); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_init); + +/** +* phy_bulk_exit() - exit multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to exit +* +* Exits the PHYs in reverse array order. All PHYs are processed even if an +* error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; + +while (num_phys--) { + err =phy_exit (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_exit); + +/** +* phy_bulk_power_on() - power on multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to power on +* +* Powers on the PHYs in array order. If a power-on operation fails, all PHYs +* powered on by this call are powered off in reverse order. +* +* Return: %0 if successful, a negative error code otherwise +*/ +int phy_bulk_power_on (unsigned int num_phys,struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + ret =phy_power_on (phys[i].phy); +if (ret) + goto err; + } + +return 0 ; + +err: +while (i--) +phy_power_off (phys[i].phy); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_power_on); + +/** +* phy_bulk_power_off() - power off multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to power off +* +* Powers off the PHYs in reverse array order. All PHYs are processed even if +* an error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_power_off (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; + +while (num_phys--) { + err =phy_power_off (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_power_off); +/** * phy_create() - create a new phy * @dev: device that is creating the new phy include/linux/phy/phy.h +55
-0@@ -81,6 +81,18 @@ union phy_configure_opts {struct phy_configure_opts_hdmi hdmi; }; +/** +* struct phy_bulk_data - Data used for bulk phy operations. +* +* @id: phy consumer ID +*/ +struct phy_bulk_data { +const char *id; + +/* private: Internal use */ +struct phy *phy; +}; +/** * struct phy_ops - set of function pointers for performing phy operations * @init: operation to be performed for initializing phy @@ -309,6 +321,12 @@ void devm_of_phy_provider_unregister(struct device *dev, struct phy_provider *phy_provider);int phy_create_lookup (struct phy *phy,const char *con_id,const char *dev_id);void phy_remove_lookup (struct phy *phy,const char *con_id,const char *dev_id); + +int phy_bulk_init (unsigned int num_phys,struct phy_bulk_data *phys); +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys); +int phy_bulk_power_on (unsigned int num_phys,struct phy_bulk_data *phys); +int phy_bulk_power_off (unsigned int num_phys,struct phy_bulk_data *phys); +#else static inline int phy_pm_runtime_get (struct phy *phy) {@@ -493,6 +511,43 @@ static inline struct phy *devm_of_phy_get_by_index(struct device *dev,return ERR_PTR (-ENOSYS ); } +static inline int phy_bulk_check_disabled (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +if (!phys) +return 0 ; + +for (unsigned int i =0 ; i < num_phys; i++) +if (phys[i].phy) +return -EOPNOTSUPP ; + +return 0 ; +} + +static inline int phy_bulk_init (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} + +static inline int phy_bulk_exit (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} + +static inline int phy_bulk_power_on (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} + +static inline int phy_bulk_power_off (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} +static inline void of_phy_put (struct phy *phy) { }Signature · 1 line
2.55.0
Signature · 1 line
~Vinod
Re: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
Quoted 9 lines · Vinod Koul
Quoted 3 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
Do we have many such examples? Phy is not a many resource like clock/regulators... Do we really need this. How many in kernel users will benefit from this API?
I guess the following driver may benefit from bulk api. Most of them are PCIe drivers....
drivers/ata/ahci_imx.cdrivers/pci/controller/cadence/pcie-cadence.cdrivers/pci/controller/dwc/pci-dra7xx.cdrivers/pci/controller/dwc/pcie-tegra194.cdrivers/pci/controller/pcie-rockchip.cdrivers/pci/controller/dwc/pcie-qcom.c
Note: I mean the bulk api, not just the things I added. I guess many may want devm_phy_bulk_get() or devm_of_phy_bulk_get() instead of devm_phy_bulk_get_all().
Regards,
Inochi
Quoted 359 lines
Quoted 356 lines
This can relieve the driver owners' life who needs to handle many phys, as well as each phy error reporting.
Signed-off-by Inochi Amaoto <[email protected]>--- drivers/phy/phy-core.c | 253 ++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 55 +++++++++ 2 files changed, 308 insertions(+)drivers/phy/phy-core.c +253
-0@@ -1004,6 +1004,259 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, }EXPORT_SYMBOL_GPL (devm_of_phy_get_by_index); +/** +* of_phy_get_count() - Get the number of phys of a device node +* @np: device_node for which to get the phy +* +* Return: the phy count if successful, %0 if no phy handle is found, +* negative error value if error occurs. +*/ +static int of_phy_get_count (const struct device_node *np) +{ +int count; + + count =of_count_phandle_with_args (np,"phys" ,"#phy-cells" ); + +if (count == -ENOENT ) +return 0 ; + +return count; +} + +/** +* phy_bulk_put() - release a set of PHYs +* @dev: device that acquired the PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data with PHYs set +* +* Releases the PHY references in reverse order and clears the PHY pointer in +* each entry. The caller owns the phys array and is responsible for freeing it +* if necessary. +*/ +static void phy_bulk_put (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +while (num_phys--) { +if (!IS_ERR_OR_NULL (phys[num_phys].phy)) +phy_put (dev, phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +} + +/** +* of_phy_bulk_put() - release a set of PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data with PHYs set +* +* Releases the PHY references in reverse order and clears the PHY pointer in +* each entry. The caller owns the phys array and is responsible for freeing it +* if necessary. +*/ +static void of_phy_bulk_put (unsigned int num_phys,struct phy_bulk_data *phys) +{ +while (num_phys--) { +of_phy_put (phys[num_phys].phy); + phys[num_phys].phy =NULL ; + } +} + +static int of_phy_bulk_get_by_index (struct device_node *np, +unsigned int num_phys, +struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + phys[i].id =NULL ; + phys[i].phy =NULL ; + } + +for (i =0 ; i < num_phys; i++) { +of_property_read_string_index (np,"phy-names" , i, &phys[i].id); + + phys[i].phy =of_phy_get_by_index (np, i); + + ret =PTR_ERR_OR_ZERO (phys[i].phy); +if (ret) { + phys[i].phy =NULL ; + goto err; + } + } + +return 0 ; + +err: +of_phy_bulk_put (i, phys); + +return ret; +} + +/** +* of_phy_bulk_get_all() - obtain all PHYs from a device node +* @np: device node containing the PHY references +* @phys: pointer to store the allocated array of struct phy_bulk_data +* +* Gets every PHY referenced by the phys property in index order. PHY names are +* read from phy-names when present. +* +* Return: the number of PHYs on success, %0 if no PHYs are found, or a +* negative error code otherwise +*/ +static int of_phy_bulk_get_all (struct device_node *np, +struct phy_bulk_data **phys) +{ +struct phy_bulk_data *phy_bulk; +int num_phys; +int ret; + + num_phys =of_phy_get_count (np); +if (num_phys <=0 ) +return num_phys; + + phy_bulk =kmalloc_objs (*phy_bulk, num_phys); +if (!phy_bulk) +return -ENOMEM ; + + ret =of_phy_bulk_get_by_index (np, num_phys, phy_bulk); +if (ret) { +kfree (phy_bulk); +return ret; + } + + *phys = phy_bulk; + +return num_phys; +} + +/** +* phy_bulk_put_all() - release and free PHYs +* @dev: device that acquired the PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to release and free +*/ +static void phy_bulk_put_all (struct device *dev,unsigned int num_phys, +struct phy_bulk_data *phys) +{ +if (IS_ERR_OR_NULL (phys)) +return ; + +phy_bulk_put (dev, num_phys, phys); +kfree (phys); +} + +/** +* phy_bulk_init() - initialize multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to initialize +* +* Initializes the PHYs in array order. If an initialization fails, all PHYs +* initialized by this call are exited in reverse order. +* +* Return: %0 if successful, a negative error code otherwise +*/ +int phy_bulk_init (unsigned int num_phys,struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + ret =phy_init (phys[i].phy); +if (ret) + goto err; + } + +return 0 ; + +err: +while (i--) +phy_exit (phys[i].phy); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_init); + +/** +* phy_bulk_exit() - exit multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to exit +* +* Exits the PHYs in reverse array order. All PHYs are processed even if an +* error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; + +while (num_phys--) { + err =phy_exit (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_exit); + +/** +* phy_bulk_power_on() - power on multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to power on +* +* Powers on the PHYs in array order. If a power-on operation fails, all PHYs +* powered on by this call are powered off in reverse order. +* +* Return: %0 if successful, a negative error code otherwise +*/ +int phy_bulk_power_on (unsigned int num_phys,struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + ret =phy_power_on (phys[i].phy); +if (ret) + goto err; + } + +return 0 ; + +err: +while (i--) +phy_power_off (phys[i].phy); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_power_on); + +/** +* phy_bulk_power_off() - power off multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to power off +* +* Powers off the PHYs in reverse array order. All PHYs are processed even if +* an error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_power_off (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; + +while (num_phys--) { + err =phy_power_off (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_power_off); +/** * phy_create() - create a new phy * @dev: device that is creating the new phy include/linux/phy/phy.h +55
-0@@ -81,6 +81,18 @@ union phy_configure_opts {struct phy_configure_opts_hdmi hdmi; }; +/** +* struct phy_bulk_data - Data used for bulk phy operations. +* +* @id: phy consumer ID +*/ +struct phy_bulk_data { +const char *id; + +/* private: Internal use */ +struct phy *phy; +}; +/** * struct phy_ops - set of function pointers for performing phy operations * @init: operation to be performed for initializing phy @@ -309,6 +321,12 @@ void devm_of_phy_provider_unregister(struct device *dev, struct phy_provider *phy_provider);int phy_create_lookup (struct phy *phy,const char *con_id,const char *dev_id);void phy_remove_lookup (struct phy *phy,const char *con_id,const char *dev_id); + +int phy_bulk_init (unsigned int num_phys,struct phy_bulk_data *phys); +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys); +int phy_bulk_power_on (unsigned int num_phys,struct phy_bulk_data *phys); +int phy_bulk_power_off (unsigned int num_phys,struct phy_bulk_data *phys); +#else static inline int phy_pm_runtime_get (struct phy *phy) {@@ -493,6 +511,43 @@ static inline struct phy *devm_of_phy_get_by_index(struct device *dev,return ERR_PTR (-ENOSYS ); } +static inline int phy_bulk_check_disabled (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +if (!phys) +return 0 ; + +for (unsigned int i =0 ; i < num_phys; i++) +if (phys[i].phy) +return -EOPNOTSUPP ; + +return 0 ; +} + +static inline int phy_bulk_init (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} + +static inline int phy_bulk_exit (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} + +static inline int phy_bulk_power_on (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} + +static inline int phy_bulk_power_off (unsigned int num_phys, +struct phy_bulk_data *phys) +{ +return phy_bulk_check_disabled (num_phys, phys); +} +static inline void of_phy_put (struct phy *phy) { }Signature · 1 line
2.55.0Signature · 1 line
~Vinod
Re: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
Quoted 22 lines · Inochi Amaoto
Quoted 9 lines · Vinod Koul
Quoted 3 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
Do we have many such examples? Phy is not a many resource like clock/regulators... Do we really need this. How many in kernel users will benefit from this API?
I guess the following driver may benefit from bulk api. Most of them are PCIe drivers....
drivers/ata/ahci_imx.cdrivers/pci/controller/cadence/pcie-cadence.cdrivers/pci/controller/dwc/pci-dra7xx.cdrivers/pci/controller/dwc/pcie-tegra194.cdrivers/pci/controller/pcie-rockchip.cdrivers/pci/controller/dwc/pcie-qcom.c
Quoted 6 lines
Note: I mean the bulk api, not just the things I added. I guess many may want
devm_phy_bulk_get()ordevm_of_phy_bulk_get()instead ofdevm_phy_bulk_get_all().Regards,
Inochi
Why didn't you try to convert some of them, to make the case for your patch set stronger?
Manivannan Sadhasivam
reviewerRe: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
In reply to Inochi AmaotoQuoted 22 lines · Inochi Amaoto
Quoted 9 lines · Vinod Koul
Quoted 3 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
Do we have many such examples? Phy is not a many resource like clock/regulators... Do we really need this. How many in kernel users will benefit from this API?
I guess the following driver may benefit from bulk api. Most of them are PCIe drivers....
drivers/ata/ahci_imx.cdrivers/pci/controller/cadence/pcie-cadence.cdrivers/pci/controller/dwc/pci-dra7xx.cdrivers/pci/controller/dwc/pcie-tegra194.cdrivers/pci/controller/pcie-rockchip.cdrivers/pci/controller/dwc/pcie-qcom.c
Quoted 4 lines
Note: I mean the bulk api, not just the things I added. I guess many may want
devm_phy_bulk_get()ordevm_of_phy_bulk_get()instead ofdevm_phy_bulk_get_all().
No. I don't think the PCIe host controllers need the PHY bulk APIs. Most of the time they need to control each PHY independently in a multi-port setup. So having the bulk API doesn't seem logical to me.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Re: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
Quoted 28 lines · Manivannan Sadhasivam
Quoted 22 lines · Inochi Amaoto
Quoted 9 lines · Vinod Koul
Quoted 3 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
Do we have many such examples? Phy is not a many resource like clock/regulators... Do we really need this. How many in kernel users will benefit from this API?
I guess the following driver may benefit from bulk api. Most of them are PCIe drivers....
drivers/ata/ahci_imx.cdrivers/pci/controller/cadence/pcie-cadence.cdrivers/pci/controller/dwc/pci-dra7xx.cdrivers/pci/controller/dwc/pcie-tegra194.cdrivers/pci/controller/pcie-rockchip.cdrivers/pci/controller/dwc/pcie-qcom.cQuoted 4 lines
Note: I mean the bulk api, not just the things I added. I guess many may want
devm_phy_bulk_get()ordevm_of_phy_bulk_get()instead ofdevm_phy_bulk_get_all().
Quoted 8 lines
No. I don't think the PCIe host controllers need the PHY bulk APIs. Most of the time they need to control each PHY independently in a multi-port setup. So having the bulk API doesn't seem logical to me.
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Sorry for missing this one. For multi-port setup, the answer is no. The bulk API is not a good choice. But for multi-lane setup of one port, I think the answer is yes, the driver can just control the phy together and do not need a loop for that. At least for pcie-rockchip.c, I think it is reasonable, its logic show it use multi-lane setup, so I think it is fine to port.
Regards,
Inochi
Manivannan Sadhasivam
reviewerRe: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
Quoted 35 lines · Inochi Amaoto
Quoted 34 lines · Manivannan Sadhasivam
Quoted 22 lines · Inochi Amaoto
Quoted 9 lines · Vinod Koul
Quoted 3 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
Do we have many such examples? Phy is not a many resource like clock/regulators... Do we really need this. How many in kernel users will benefit from this API?
I guess the following driver may benefit from bulk api. Most of them are PCIe drivers....
drivers/ata/ahci_imx.cdrivers/pci/controller/cadence/pcie-cadence.cdrivers/pci/controller/dwc/pci-dra7xx.cdrivers/pci/controller/dwc/pcie-tegra194.cdrivers/pci/controller/pcie-rockchip.cdrivers/pci/controller/dwc/pcie-qcom.cQuoted 4 lines
Note: I mean the bulk api, not just the things I added. I guess many may want
devm_phy_bulk_get()ordevm_of_phy_bulk_get()instead ofdevm_phy_bulk_get_all().No. I don't think the PCIe host controllers need the PHY bulk APIs. Most of the time they need to control each PHY independently in a multi-port setup. So having the bulk API doesn't seem logical to me.
- Mani
Quoted 9 lines
Quoted 2 lines
Signature · 1 line
மணிவண்ணன் சதாசிவம்Sorry for missing this one. For multi-port setup, the answer is no. The bulk API is not a good choice. But for multi-lane setup of one port, I think the answer is yes, the driver can just control the phy together and do not need a loop for that. At least for
pcie-rockchip.c, I think it is reasonable, its logic show it use multi-lane setup, so I think it is fine to port.
Yeah, if there are multiple PHYs to be controlled within a single RP for lane muxing, then bulk APIs do make sense.
- Mani
Re: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
In reply to Vinod KoulQuoted 8 lines · Vinod Koul
Quoted 3 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
Do we have many such examples? Phy is not a many resource like clock/regulators... Do we really need this. How many in kernel users will benefit from this API?
I have another case for more than 1 PHY. On some NXP boards, retimers like phy-ds125df111.c are used for networking, but not in the way you'd expect, i.e. not like this:
SerDes SerDes Lane A Lane B RX TX RX TX ^ | ^ | | | | | | v | v Retimer C Retimer D ch0 ch1 ch0 ch1 ^ | ^ | | | | | | | | | | | | | | v | v
but like this:
SerDes SerDes SerDes SerDes Lane A Lane B Lane A Lane B RX RX TX TX ^ ^ | | | | | | | | v v Retimer C Retimer D ch0 ch1 ch0 ch1 ^ ^ | | | | | | | | | | | | | | | | v v
Since the retimer channels are bidirectional and not hardcoded for RX/TX function (unlike the SerDes differential pairs), this is not a problem.
Since one SerDes lane is one struct phy, its RX side and its TX side need to configure the channels of physically different retimer devices.
The retimer driver was modeled to permit this configuration, and it exposes each channel as a separate struct phy. The implication is that any consumer of this retimer needs two 'phys' phandles to have both RX and TX retimed.
Actually I'm interested in this series too, specifically due to retimers/ repeaters. I believe they should gain core PHY support, because the current support is very sporadic and not homogenous.
Today all SerDes PHYs capable of supporting repeaters/retimers need to manually acquire their phy->repeater using phy_get(), and forward all ops from their consumer to the repeater as well. But this creates the odd situation where maybe the SerDes PHY doesn't need to do anything on, say, phy_init(), yet it needs to implement it anyway, just to call phy_init(phy->repeater). The existence of downstream repeaters can be made very transparent to the top-level struct phy (the one that the consumer interacts with).
And because in general, there could be >1 repeater in the signal path, I was thinking the bulk API could be a good candidate for managing the list of repeaters of a PHY.
Re: [PATCH v4 3/5] phy: core: Add phy bulk data helper functions
In reply to Inochi AmaotoQuoted 20 lines · Inochi Amaoto
Add several helper functions that allow drivers to get several phy consumers in one operation. If any of the phy cannot be acquired then any phys that were got will be put before returning to the caller.
This can relieve the driver owners' life who needs to handle many phys, as well as each phy error reporting.
Signed-off-by Inochi Amaoto <[email protected]>--- drivers/phy/phy-core.c | 253 ++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 55 +++++++++ 2 files changed, 308 insertions(+)drivers/phy/phy-core.c +0
-0@@ -1004,6 +1004,259 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, }EXPORT_SYMBOL_GPL (devm_of_phy_get_by_index);
[...]
Quoted 46 lines
drivers/phy/phy-core.c +46
-0+/** +* phy_bulk_init() - initialize multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to initialize +* +* Initializes the PHYs in array order. If an initialization fails, all PHYs +* initialized by this call are exited in reverse order. +* +* Return: %0 if successful, a negative error code otherwise +*/ +int phy_bulk_init (unsigned int num_phys,struct phy_bulk_data *phys) +{ +unsigned int i; +int ret; + +for (i =0 ; i < num_phys; i++) { + ret =phy_init (phys[i].phy); +if (ret) + goto err; + } + +return 0 ; + +err: +while (i--) +phy_exit (phys[i].phy); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_init); + +/** +* phy_bulk_exit() - exit multiple PHYs +* @num_phys: number of entries in the phys array +* @phys: array of struct phy_bulk_data to exit +* +* Exits the PHYs in reverse array order. All PHYs are processed even if an +* error occurs. +* +* Return: %0 if successful, the first negative error code otherwise +*/ +int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys) +{ +int ret =0 ; +int err; +
drivers/phy/phy-core.c struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, · line 1203
Quoted 10 lines
drivers/phy/phy-core.c +10
-0+while (num_phys--) { + err =phy_exit (phys[num_phys].phy); +if (err && !ret) + ret = err; + } + +return ret; +} +EXPORT_SYMBOL_GPL (phy_bulk_exit); +
Hi Vinod, Vladimir and Manivannan,
Before sending the next patch (I guess I can update it in the next week), I have a question for the error handle.
As the phy_exit()/phy_power_off()/phy_power_on() can return an error code, should the corresponding bulk api need to call the corresponding phy_init()/phy_power_on()/phy_power_off() when there is an error occurs. Or just leave the state as it is. I saw the reset subsystem does this rollback.
Regards,
Inochi
PATCH v4 4/5 phy: core: Add managed phy bulk data helper functions
In reply to Inochi AmaotoAdd device managed variants of the phy bulk helper functions. So the driver can benefit from automatically managed phy handles.
--- drivers/phy/phy-core.c | 73 +++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 19 +++++++++++ 2 files changed, 92 insertions(+)
drivers/phy/phy-core.c +73 -0
@@ -1145,6 +1145,79 @@ static void phy_bulk_put_all(struct device *dev, unsigned int num_phys,kfree (phys); } +struct phy_bulk_devres { +struct phy_bulk_data *phys; +unsigned int num_phys; +}; + +static void devm_phy_bulk_release_all (struct device *dev,void *res) +{ +struct phy_bulk_devres *devres = res; + +phy_bulk_put_all (dev, devres->num_phys, devres->phys); +} + +/** +* devm_phy_bulk_get_all() - managed lookup of all PHYs requested by a device +* @dev: device that requests the PHYs +* @phys: pointer to store the allocated array of struct phy_bulk_data +* +* The function calls devm_of_phy_bulk_get_all() directly, but sets the +* @np parameter to dev_of_node(dev). +* +* Return: the number of PHYs on success, %0 if no PHYs are found, or a +* negative error code otherwise +*/ +int devm_phy_bulk_get_all (struct device *dev,struct phy_bulk_data **phys) +{ +return devm_of_phy_bulk_get_all (dev,dev_of_node (dev), phys); +} +EXPORT_SYMBOL_GPL (devm_phy_bulk_get_all); + +/** +* devm_of_phy_bulk_get_all() - managed lookup of all PHYs from a device node +* @dev: device that requests the PHYs +* @np: device node containing the PHY references +* @phys: pointer to store the allocated array of struct phy_bulk_data +* +* Gets all PHYs from the specified device node, associates the allocated array +* and PHY references with @dev, and creates a device link for each PHY. They +* are automatically released on driver detach. +* +* Return: the number of PHYs on success, %0 if no PHYs are found, or a +* negative error code otherwise +*/ +int devm_of_phy_bulk_get_all (struct device *dev,struct device_node *np, +struct phy_bulk_data **phys) +{ +struct phy_bulk_devres *devres; +int ret; + + *phys =NULL ; + +if (!np) +return 0 ; + + devres =devres_alloc (devm_phy_bulk_release_all,sizeof (*devres), +GFP_KERNEL ); +if (!devres) +return -ENOMEM ; + + ret =of_phy_bulk_get_all (np, &devres->phys); +if (ret >0 ) { +for (int i =0 ; i < ret; i++) +phy_add_device_link (dev, devres->phys[i].phy); + *phys = devres->phys; + devres->num_phys = ret; +devres_add (dev, devres); + }else { +devres_free (devres); + } + +return ret; +} +EXPORT_SYMBOL_GPL (devm_of_phy_bulk_get_all); +/** * phy_bulk_init() - initialize multiple PHYs * @num_phys: number of entries in the phys array
include/linux/phy/phy.h +19 -0
@@ -322,6 +322,9 @@ void devm_of_phy_provider_unregister(struct device *dev,int phy_create_lookup (struct phy *phy,const char *con_id,const char *dev_id);void phy_remove_lookup (struct phy *phy,const char *con_id,const char *dev_id); +int devm_phy_bulk_get_all (struct device *dev,struct phy_bulk_data **phys); +int devm_of_phy_bulk_get_all (struct device *dev,struct device_node *np, +struct phy_bulk_data **phys);int phy_bulk_init (unsigned int num_phys,struct phy_bulk_data *phys);int phy_bulk_exit (unsigned int num_phys,struct phy_bulk_data *phys);int phy_bulk_power_on (unsigned int num_phys,struct phy_bulk_data *phys);
@@ -511,6 +514,22 @@ static inline struct phy *devm_of_phy_get_by_index(struct device *dev,return ERR_PTR (-ENOSYS ); } +static inline int devm_of_phy_bulk_get_all (struct device *dev, +struct device_node *np, +struct phy_bulk_data **phys) +{ +if (phys) + *phys =NULL ; + +return 0 ; +} + +static inline int devm_phy_bulk_get_all (struct device *dev, +struct phy_bulk_data **phys) +{ +return devm_of_phy_bulk_get_all (dev,dev_of_node (dev), phys); +} +static inline int phy_bulk_check_disabled (unsigned int num_phys,struct phy_bulk_data *phys) {
Signature · 1 line
2.55.0
Re: [PATCH v4 4/5] phy: core: Add managed phy bulk data helper functions
Quoted 2 lines · Inochi Amaoto
Add device managed variants of the phy bulk helper functions. So the driver can benefit from automatically managed phy handles.
...
drivers/phy/phy-core.c static void phy_bulk_put_all(struct device *dev, unsigned int num_phys, · line 1196
Quoted 7 lines
drivers/phy/phy-core.c +6
-0+int devm_of_phy_bulk_get_all (struct device *dev,struct device_node *np, +struct phy_bulk_data **phys) +{ +struct phy_bulk_devres *devres; +int ret; + *phys =NULL ;
Why?! In case of error we modify the output, this is usually not the best approach as in most of the cases the expectation is that whatever user provide (including a garbage) should be left untouched in case of an error.
drivers/phy/phy-core.c static void phy_bulk_put_all(struct device *dev, unsigned int num_phys, · line 1199
Quoted 2 lines
drivers/phy/phy-core.c +2
-0+if (!np) +return 0 ;
Same here. On top why do we even care about np like this? Interestingly that some other APIs consider this as np == dev_of_node(dev) case, and automatically propagate that.
Quoted 18 lines
drivers/phy/phy-core.c +18
-0+ devres =devres_alloc (devm_phy_bulk_release_all,sizeof (*devres), +GFP_KERNEL ); +if (!devres) +return -ENOMEM ; + + ret =of_phy_bulk_get_all (np, &devres->phys); +if (ret >0 ) { +for (int i =0 ; i < ret; i++) +phy_add_device_link (dev, devres->phys[i].phy); + *phys = devres->phys; + devres->num_phys = ret; +devres_add (dev, devres); + }else { +devres_free (devres); + } + +return ret; +}
...
include/linux/phy/phy.h static inline struct phy *devm_of_phy_get_by_index(struct device *dev, · line 522
Quoted 6 lines
include/linux/phy/phy.h +6
-0+static inline int devm_of_phy_bulk_get_all (struct device *dev, +struct device_node *np, +struct phy_bulk_data **phys) +{ +if (phys) + *phys =NULL ;
Same as per above.
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;
Why not an error? I do not see the _optional word in the function name.
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 4/5] phy: core: Add managed phy bulk data helper functions
Quoted 12 lines · Andy Shevchenko
Quoted 2 lines · Inochi Amaoto
Add device managed variants of the phy bulk helper functions. So the driver can benefit from automatically managed phy handles.
...
Quoted 5 lines
drivers/phy/phy-core.c +5
-0+int devm_of_phy_bulk_get_all (struct device *dev,struct device_node *np, +struct phy_bulk_data **phys) +{ +struct phy_bulk_devres *devres; +int ret;
Quoted 6 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ *phys = NULL;Why?! In case of error we modify the output, this is usually not the best approach as in most of the cases the expectation is that whatever user provide (including a garbage) should be left untouched in case of an error.
This is something I think this is wrong and I need to removed.
Quoted 7 lines
drivers/phy/phy-core.c static void phy_bulk_put_all(struct device *dev, unsigned int num_phys, · line 1199
Quoted 2 lines
drivers/phy/phy-core.c +2
-0+if (!np) +return 0 ;Same here. On top why do we even care about np like this? Interestingly that some other APIs consider this as np ==
dev_of_node(dev)case, and automatically propagate that.
After a deep recheck. I think you are true. We do not need to care about that, just let the internal api decide whether it should be an error is better. I misunderstand that it should check it at early stage to avoid some bad use in the following logic. Now I found it is meaningless.
Quoted 30 lines
Quoted 18 lines
drivers/phy/phy-core.c +18
-0+ devres =devres_alloc (devm_phy_bulk_release_all,sizeof (*devres), +GFP_KERNEL ); +if (!devres) +return -ENOMEM ; + + ret =of_phy_bulk_get_all (np, &devres->phys); +if (ret >0 ) { +for (int i =0 ; i < ret; i++) +phy_add_device_link (dev, devres->phys[i].phy); + *phys = devres->phys; + devres->num_phys = ret; +devres_add (dev, devres); + }else { +devres_free (devres); + } + +return ret; +}...
include/linux/phy/phy.h static inline struct phy *devm_of_phy_get_by_index(struct device *dev, · line 522
Quoted 6 lines
include/linux/phy/phy.h +6
-0+static inline int devm_of_phy_bulk_get_all (struct device *dev, +struct device_node *np, +struct phy_bulk_data **phys) +{ +if (phys) + *phys =NULL ;Same as per above.
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;Why not an error? I do not see the
_optionalword in the function name.
IIRC get_all it a special optional meaning: treat not existing device as 0, this follows the same meaning like clk. Vladimir has a good explaination on this in the previous version:
https://lore.kernel.org/linux-phy/20260907124318.6q4rr2huxyehm3zs@skbuf/
Quoted 7 lines
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 4/5] phy: core: Add managed phy bulk data helper functions
Quoted 71 lines · Inochi Amaoto
Quoted 12 lines · Andy Shevchenko
Quoted 2 lines · Inochi Amaoto
Add device managed variants of the phy bulk helper functions. So the driver can benefit from automatically managed phy handles.
...
Quoted 5 lines
drivers/phy/phy-core.c +5
-0+int devm_of_phy_bulk_get_all (struct device *dev,struct device_node *np, +struct phy_bulk_data **phys) +{ +struct phy_bulk_devres *devres; +int ret;Quoted 6 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ *phys = NULL;Why?! In case of error we modify the output, this is usually not the best approach as in most of the cases the expectation is that whatever user provide (including a garbage) should be left untouched in case of an error.
This is something I think this is wrong and I need to removed.
Quoted 7 lines
drivers/phy/phy-core.c static void phy_bulk_put_all(struct device *dev, unsigned int num_phys, · line 1199
Quoted 2 lines
drivers/phy/phy-core.c +2
-0+if (!np) +return 0 ;Same here. On top why do we even care about np like this? Interestingly that some other APIs consider this as np ==
dev_of_node(dev)case, and automatically propagate that.After a deep recheck. I think you are true. We do not need to care about that, just let the internal api decide whether it should be an error is better. I misunderstand that it should check it at early stage to avoid some bad use in the following logic. Now I found it is meaningless.
Quoted 30 lines
Quoted 18 lines
drivers/phy/phy-core.c +18
-0+ devres =devres_alloc (devm_phy_bulk_release_all,sizeof (*devres), +GFP_KERNEL ); +if (!devres) +return -ENOMEM ; + + ret =of_phy_bulk_get_all (np, &devres->phys); +if (ret >0 ) { +for (int i =0 ; i < ret; i++) +phy_add_device_link (dev, devres->phys[i].phy); + *phys = devres->phys; + devres->num_phys = ret; +devres_add (dev, devres); + }else { +devres_free (devres); + } + +return ret; +}...
include/linux/phy/phy.h static inline struct phy *devm_of_phy_get_by_index(struct device *dev, · line 522
Quoted 6 lines
include/linux/phy/phy.h +6
-0+static inline int devm_of_phy_bulk_get_all (struct device *dev, +struct device_node *np, +struct phy_bulk_data **phys) +{ +if (phys) + *phys =NULL ;Same as per above.
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;Why not an error? I do not see the
_optionalword in the function name.
Quoted 5 lines
IIRC
get_allit a special optional meaning: treat not existing device as 0, this follows the same meaning like clk. Vladimir has a good explaination on this in the previous version:
https://lore.kernel.org/linux-phy/20260907124318.6q4rr2huxyehm3zs@skbuf/
s/device/property/.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 4/5] phy: core: Add managed phy bulk data helper functions
In reply to Inochi AmaotoQuoted 2 lines · Inochi Amaoto
Quoted 1 line · Andy Shevchenko
On Tue, Sep 29, 2026 at 04:52:34PM +0800, Inochi Amaoto wrote:
...
Quoted 6 lines
Quoted 1 line
Why not an error? I do not see the
_optionalword in the function name.IIRC
get_allit a special optional meaning: treat not existing device as 0, this follows the same meaning like clk. Vladimir has a good explaination on this in the previous version:
https://lore.kernel.org/linux-phy/20260907124318.6q4rr2huxyehm3zs@skbuf/
Thank you for the pointer. Perhaps add a short comment or a sentence into kernel-doc to summarize that reasoning?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v4 5/5 doc: phy: Document some bulk helper functions
In reply to Inochi AmaotoDocument all newly added bulk helper function, it can be used to manage a set of PHYs automatically. This is useful when the driver want to simplify the management of multiple PHYs.
--- Documentation/driver-api/phy/phy.rst | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
Documentation/driver-api/phy/phy.rst +29 -0
@@ -114,6 +114,10 @@ it. This framework provides the following APIs to get a reference to the PHY. struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index); + int devm_phy_bulk_get_all(struct device *dev, + struct phy_bulk_data **phys); + int devm_of_phy_bulk_get_all(struct device *dev, struct device_node *np, + struct phy_bulk_data **phys); phy_get, devm_phy_get and devm_phy_optional_get can be used to get the PHY. In the case of dt boot, the string arguments
@@ -129,6 +133,13 @@ Some generic drivers, such as ehci, may use multiple phys. In this case, devm_of_phy_get or devm_of_phy_get_by_index can be used to get a phy reference based on name or index. +When a controller needs every PHY listed in a device node's ``phys`` property, +devm_phy_bulk_get_all() obtains them from the controller's device node. +devm_of_phy_bulk_get_all() does the same for an explicitly supplied device +node. On success, these functions return the number of PHYs and store an array +of ``struct phy_bulk_data`` in ``*phys``. The PHY references and array are +managed by devres and are released when the device is detached. + It should be noted that NULL is a valid phy reference. All phy consumer calls on the NULL phy become NOPs. That is the release calls, the phy_init() and phy_exit() calls, and phy_power_on() and
@@ -149,6 +160,19 @@ The general order of calls should be:: phy_exit() [[of_]phy_put()] +For a set of PHYs acquired with devm_phy_bulk_get_all() or +devm_of_phy_bulk_get_all(), the corresponding order is:: + + devm_[of_]phy_bulk_get_all() + phy_bulk_init() + phy_bulk_power_on() + ... + phy_bulk_power_off() + phy_bulk_exit() + +The bulk get-all APIs release the PHY references and the array automatically +when the device is detached. + Some PHY drivers may not implement :c:func:`phy_init` or :c:func:`phy_power_on`, but controllers should always call these functions to be compatible with other PHYs. Some PHYs may require :c:func:`phy_set_mode <phy_set_mode_ext>`, while
@@ -221,3 +245,8 @@ DeviceTree Binding The documentation for PHY dt binding can be found @ Documentation/devicetree/bindings/phy/phy-bindings.txt + +Missing Bulk Helpers +==================== +Currently, only a few bulk helper functions are added as they have users. +Function not upstreamed can be found at https://lore.kernel.org/linux-phy/[email protected]/
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v4 5/5] doc: phy: Document some bulk helper functions
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] doc: out-of-tree patch link in permanent documentation --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] doc: out-of-tree patch link in permanent documentation
--
commit 2b386d50e0a3a5183371e47d0b4d4b3c1f5d09e8
Author: Inochi Amaoto <[email protected]>
doc: phy: Document some bulk helper functions
Document newly added bulk helper functions that can be used to manage a set of PHYs automatically. This simplifies the management of multiple PHYs for drivers.
Quoted 4 lines
Documentation/driver-api/phy/phy.rst +0
-0
[ ... ]
Documentation/driver-api/phy/phy.rst DeviceTree Binding · line 252
Quoted 9 lines
Documentation/driver-api/phy/phy.rst +5
-0@@ -221,3 +245,8 @@ DeviceTree Binding The documentation for PHY dt binding can be found @ Documentation/devicetree/bindings/phy/phy-bindings.txt + +Missing Bulk Helpers +==================== +Currently, only a few bulk helper functions are added as they have users. +Function not upstreamed can be found at https://lore.kernel.org/linux-phy/[email protected]/
[Severity: Low]
Is it appropriate to include links to out-of-tree patches in the permanent kernel documentation?
This type of historical context and reference to unmerged code generally belongs in the patch commit message or cover letter, rather than the official API documentation.
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
Re: [PATCH v4 5/5] doc: phy: Document some bulk helper functions
In reply to Inochi AmaotoQuoted 3 lines · Inochi Amaoto
Document all newly added bulk helper function, it can be used to manage a set of PHYs automatically. This is useful when the driver want to simplify the management of multiple PHYs.
It misses to document unusual behaviour on an error and np==NULL cases. But before updating let's discuss first if that kind of behaviour is even desired.
Signature · 2 lines
With Best Regards, Andy Shevchenko