* [PATCH v5 1/8] phy: core: Add common helper to add phy phandle device link
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 2/8] phy: core: Add common helper for get phy phandle by index Inochi Amaoto
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
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.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/phy/phy-core.c | 46 ++++++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 597e6b234f5e..b7550ca37e66 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -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_with_args() - lookup and obtain a reference to a phy by of_phandle_args
* @args: of_phandle_args to the phy
@@ -805,7 +826,6 @@ struct phy *phy_get(struct device *dev, const char *string)
{
int index = 0;
struct phy *phy;
- struct device_link *link;
mutex_lock(&phy_provider_mutex);
if (dev->of_node) {
@@ -833,10 +853,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);
out_unlock:
mutex_unlock(&phy_provider_mutex);
@@ -912,7 +929,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)
@@ -927,10 +943,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;
}
@@ -982,7 +995,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)
@@ -1006,10 +1018,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);
out_unlock:
mutex_unlock(&phy_provider_mutex);
@@ -1059,7 +1068,6 @@ EXPORT_SYMBOL_GPL(phy_get_by_of_node);
struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np)
{
struct phy **ptr, *phy;
- struct device_link *link;
ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
if (!ptr)
@@ -1073,10 +1081,8 @@ struct phy *devm_phy_get_by_of_node(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;
}
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v5 2/8] phy: core: Add common helper for get phy phandle by index
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 1/8] phy: core: Add common helper to add phy phandle device link Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 3/8] phy: core: Make phy_put() ignore NULL and error pointers Inochi Amaoto
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
Two phy helpers use index to get phy phandle of a device node,
add a common function for the future reuse.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/phy/phy-core.c | 57 ++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 24 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index b7550ca37e66..efbd7e139dce 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -697,38 +697,55 @@ 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)) {
+ phy = ERR_PTR(-EPROBE_DEFER);
+ return phy;
+ }
+
+ 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;
+ struct phy *phy;
int index = 0;
if (con_id)
index = of_property_match_string(np, "phy-names", con_id);
mutex_lock(&phy_provider_mutex);
-
- phy = _of_phy_get(np, index);
- if (IS_ERR(phy))
- goto out_unlock;
-
- if (!try_module_get(phy->ops->owner)) {
- phy = ERR_PTR(-EPROBE_DEFER);
- goto out_unlock;
- }
-
- get_device(&phy->dev);
-
-out_unlock:
+ phy = _of_phy_get_by_index(np, index);
mutex_unlock(&phy_provider_mutex);
+
return phy;
}
EXPORT_SYMBOL_GPL(of_phy_get);
@@ -1001,20 +1018,12 @@ struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
return ERR_PTR(-ENOMEM);
mutex_lock(&phy_provider_mutex);
- phy = _of_phy_get(np, index);
+ phy = _of_phy_get_by_index(np, index);
if (IS_ERR(phy)) {
devres_free(ptr);
goto out_unlock;
}
- if (!try_module_get(phy->ops->owner)) {
- devres_free(ptr);
- phy = ERR_PTR(-EPROBE_DEFER);
- goto out_unlock;
- }
-
- get_device(&phy->dev);
-
*ptr = phy;
devres_add(dev, ptr);
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v5 3/8] phy: core: Make phy_put() ignore NULL and error pointers
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 1/8] phy: core: Add common helper to add phy phandle device link Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 2/8] phy: core: Add common helper for get phy phandle by index Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 4/8] phy: core: Add phy bulk data helper functions Inochi Amaoto
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
Add NULL and error pointer check to the phy_put(), so it can ignore
any bad and empty pointer, this will simplify the release handler
of the bulk data API.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
drivers/phy/phy-core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index efbd7e139dce..5004d28b167a 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -780,6 +780,9 @@ EXPORT_SYMBOL_GPL(of_phy_put);
*/
void phy_put(struct device *dev, struct phy *phy)
{
+ if (IS_ERR_OR_NULL(phy))
+ return;
+
device_link_remove(dev, &phy->dev);
of_phy_put(phy);
}
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v5 4/8] phy: core: Add phy bulk data helper functions
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
` (2 preceding siblings ...)
2026-11-25 4:36 ` [PATCH v5 3/8] phy: core: Make phy_put() ignore NULL and error pointers Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 5/8] phy: core: Add managed " Inochi Amaoto
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
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 <inochiama@gmail.com>
---
drivers/phy/phy-core.c | 301 ++++++++++++++++++++++++++++++++++++++++
include/linux/phy/phy.h | 38 +++++
2 files changed, 339 insertions(+)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 5004d28b167a..87a317a144b4 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -1100,6 +1100,307 @@ struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np)
}
EXPORT_SYMBOL_GPL(devm_phy_get_by_of_node);
+/**
+ * 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, int num_phys,
+ struct phy_bulk_data *phys)
+{
+ while (num_phys--) {
+ 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(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, int num_phys,
+ struct phy_bulk_data *phys)
+{
+ int ret = 0;
+ int i;
+
+ for (i = 0; i < num_phys; i++) {
+ phys[i].id = NULL;
+ phys[i].phy = NULL;
+ }
+
+ mutex_lock(&phy_provider_mutex);
+
+ 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);
+
+ if (IS_ERR(phys[i].phy)) {
+ ret = PTR_ERR(phys[i].phy);
+ break;
+ }
+ }
+
+ mutex_unlock(&phy_provider_mutex);
+
+ if (ret)
+ of_phy_bulk_put(i, phys);
+
+ return ret;
+}
+
+/**
+ * phy_bulk_get() - lookup and obtain references to multiple PHYs
+ * @dev: device that requests the PHYs
+ * @num_phys: number of entries in the phys array
+ * @phys: array of struct phy_bulk_data with PHY names set
+ *
+ * Gets each PHY using phy_get(). This supports both device tree lookups and
+ * non-device-tree lookups registered with phy_create_lookup(). The caller must
+ * call phy_bulk_put() to release the PHY references.
+ *
+ * Return: %0 if successful, a negative error code otherwise
+ */
+static int phy_bulk_get(struct device *dev, int num_phys,
+ struct phy_bulk_data *phys)
+{
+ int ret, i;
+
+ for (i = 0; i < num_phys; i++)
+ phys[i].phy = NULL;
+
+ for (i = 0; i < num_phys; i++) {
+ phys[i].phy = phy_get(dev, phys[i].id);
+
+ ret = PTR_ERR_OR_ZERO(phys[i].phy);
+ if (ret) {
+ phys[i].phy = NULL;
+
+ dev_err_probe(dev, ret, "Failed to get phy: (%s)\n",
+ phys[i].id);
+ goto err;
+ }
+ }
+
+ return 0;
+
+err:
+ phy_bulk_put(dev, 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, 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(int num_phys, struct phy_bulk_data *phys)
+{
+ int ret, i;
+
+ 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. If error occurs, all exited
+ * phys are inited again.
+ *
+ * Return: %0 if successful, or negative error code if one fails.
+ */
+int phy_bulk_exit(int num_phys, struct phy_bulk_data *phys)
+{
+ int ret, i;
+
+ for (i = num_phys - 1; i >= 0; i--) {
+ ret = phy_exit(phys[i].phy);
+ if (ret)
+ goto err;
+ }
+
+ return 0;
+
+err:
+ while (++i < num_phys)
+ phy_init(phys[i].phy);
+
+ 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, or negative error code if one fails.
+ */
+int phy_bulk_power_on(int num_phys, struct phy_bulk_data *phys)
+{
+ int ret, i;
+
+ 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
+ *
+ * Power off the PHYs in reverse order. If a powers off fails, already
+ * power-off phys are powered on again.
+ *
+ * Return: %0 if successful, the first negative error code otherwise
+ */
+int phy_bulk_power_off(int num_phys, struct phy_bulk_data *phys)
+{
+ int ret, i;
+
+ for (i = num_phys - 1; i >= 0; i--) {
+ ret = phy_power_off(phys[i].phy);
+ if (ret)
+ goto err;
+ }
+
+ return 0;
+
+err:
+ while (++i < num_phys)
+ phy_power_on(phys[i].phy);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(phy_bulk_power_off);
+
/**
* phy_create() - create a new phy
* @dev: device that is creating the new phy
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index c480d6cb42c5..c170d9aeeeb4 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -83,6 +83,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
@@ -313,6 +325,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(int num_phys, struct phy_bulk_data *phys);
+int phy_bulk_exit(int num_phys, struct phy_bulk_data *phys);
+int phy_bulk_power_on(int num_phys, struct phy_bulk_data *phys);
+int phy_bulk_power_off(int num_phys, struct phy_bulk_data *phys);
+
#else
static inline int phy_pm_runtime_get(struct phy *phy)
{
@@ -584,6 +602,26 @@ phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
}
static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
const char *dev_id) { }
+
+static inline int phy_bulk_init(int num_phys, struct phy_bulk_data *phys)
+{
+ return 0;
+}
+
+static inline int phy_bulk_exit(int num_phys, struct phy_bulk_data *phys)
+{
+ return 0;
+}
+
+static inline int phy_bulk_power_on(int num_phys, struct phy_bulk_data *phys)
+{
+ return 0;
+}
+
+static inline int phy_bulk_power_off(int num_phys, struct phy_bulk_data *phys)
+{
+ return 0;
+}
#endif
#endif /* __DRIVERS_PHY_H */
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v5 5/8] phy: core: Add managed phy bulk data helper functions
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
` (3 preceding siblings ...)
2026-11-25 4:36 ` [PATCH v5 4/8] phy: core: Add phy bulk data helper functions Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 6/8] doc: phy: Document some bulk " Inochi Amaoto
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
Add device managed variants of the phy bulk helper functions. So
the driver can benefit from automatically managed phy handles.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
drivers/phy/phy-core.c | 139 ++++++++++++++++++++++++++++++++++++++++
include/linux/phy/phy.h | 31 +++++++++
2 files changed, 170 insertions(+)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 87a317a144b4..eeba1b899c20 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -1281,6 +1281,145 @@ static void phy_bulk_put_all(struct device *dev, int num_phys,
kfree(phys);
}
+struct phy_bulk_devres {
+ struct phy_bulk_data *phys;
+ int num_phys;
+};
+
+static void devm_phy_bulk_release(struct device *dev, void *res)
+{
+ struct phy_bulk_devres *devres = res;
+
+ phy_bulk_put(dev, devres->num_phys, devres->phys);
+}
+
+/**
+ * devm_phy_bulk_get() - managed lookup of multiple PHYs
+ * @dev: device that requests the PHYs
+ * @num_phys: number of entries in the phys array
+ * @phys: array of struct phy_bulk_data with PHY names set
+ *
+ * Gets the PHYs using phy_bulk_get() and associates the references with
+ * @dev. The references are automatically released on driver detach.
+ *
+ * Return: %0 if successful, a negative error code otherwise
+ */
+int devm_phy_bulk_get(struct device *dev, int num_phys,
+ struct phy_bulk_data *phys)
+{
+ struct phy_bulk_devres *devres;
+ int ret;
+
+ devres = devres_alloc(devm_phy_bulk_release, sizeof(*devres),
+ GFP_KERNEL);
+ if (!devres)
+ return -ENOMEM;
+
+ ret = phy_bulk_get(dev, num_phys, phys);
+ if (ret) {
+ devres_free(devres);
+ return ret;
+ }
+
+ devres->phys = phys;
+ devres->num_phys = num_phys;
+ devres_add(dev, devres);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_phy_bulk_get);
+
+static int devm_phy_bulk_match(struct device *dev, void *res, void *match_data)
+{
+ struct phy_bulk_devres *devres = res;
+
+ return devres->phys == match_data;
+}
+
+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;
+
+ 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);
+
+/**
+ * devm_phy_bulk_put_all() - release the multiple PHY
+ * @dev: device that wants to release this phy
+ * @phy: the phy bulk data returned by devm_phy_bulk_get_all()
+ *
+ * destroys the devres associated with this phy bulk data and invokes
+ * phy_bulk_put to release the phy.
+ */
+void devm_phy_bulk_put_all(struct device *dev, struct phy_bulk_data *phy)
+{
+ int r;
+
+ if (!phy)
+ return;
+
+ r = devres_release(dev, devm_phy_bulk_release_all,
+ devm_phy_bulk_match, phy);
+ dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
+}
+EXPORT_SYMBOL_GPL(devm_phy_bulk_put_all);
+
/**
* phy_bulk_init() - initialize multiple PHYs
* @num_phys: number of entries in the phys array
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index c170d9aeeeb4..a51b3c283efd 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -326,6 +326,13 @@ 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(struct device *dev, int num_phys,
+ struct phy_bulk_data *phys);
+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);
+void devm_phy_bulk_put_all(struct device *dev, struct phy_bulk_data *phy);
+
int phy_bulk_init(int num_phys, struct phy_bulk_data *phys);
int phy_bulk_exit(int num_phys, struct phy_bulk_data *phys);
int phy_bulk_power_on(int num_phys, struct phy_bulk_data *phys);
@@ -603,6 +610,30 @@ phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
const char *dev_id) { }
+static inline int devm_phy_bulk_get(struct device *dev, int num_phys,
+ struct phy_bulk_data *phys)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int devm_of_phy_bulk_get_all(struct device *dev,
+ struct device_node *np,
+ struct phy_bulk_data **phys)
+{
+ return 0;
+}
+
+static inline int devm_phy_bulk_get_all(struct device *dev,
+ struct phy_bulk_data **phys)
+{
+ return 0;
+}
+
+static inline void devm_phy_bulk_put_all(struct device *dev,
+ struct phy_bulk_data *phy)
+{
+}
+
static inline int phy_bulk_init(int num_phys, struct phy_bulk_data *phys)
{
return 0;
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v5 6/8] doc: phy: Document some bulk helper functions
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
` (4 preceding siblings ...)
2026-11-25 4:36 ` [PATCH v5 5/8] phy: core: Add managed " Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 7/8] PCI: cadence: Use phy bulk data api to simplifiy the logic Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 8/8] ata: ahci_imx: Use bulk PHY APIs for calibration PHYs Inochi Amaoto
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
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.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
Documentation/driver-api/phy/phy.rst | 40 ++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/Documentation/driver-api/phy/phy.rst b/Documentation/driver-api/phy/phy.rst
index 0865c2e94eec..cae3d4700814 100644
--- a/Documentation/driver-api/phy/phy.rst
+++ b/Documentation/driver-api/phy/phy.rst
@@ -114,6 +114,12 @@ 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(struct device *dev, int num_phys,
+ struct phy_bulk_data *phys);
+ 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 +135,21 @@ 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.
+The bulk helpers are useful when a controller operates several PHYs together,
+for example the lanes of a single PCIe port. To get a set of PHYs by name,
+the driver supplies an array of ``struct phy_bulk_data`` with the ``id`` of
+each entry set to the corresponding PHY name. devm_phy_bulk_get() returns
+zero if it obtains all the requested PHYs or a negative error code on failure.
+The driver owns the array and keeps it valid until driver detach, when the
+PHY references are released.
+
+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. These functions return the number of PHYs listed in the node, which may
+be zero, or a negative error code on failure. They store the allocated array
+in ``*phys`` only when the return value is positive.
+
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 +170,14 @@ The general order of calls should be::
phy_exit()
[[of_]phy_put()]
+After acquiring a set of PHYs with a bulk helper, the order is::
+
+ phy_bulk_init()
+ phy_bulk_power_on()
+ ...
+ phy_bulk_power_off()
+ phy_bulk_exit()
+
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
@@ -172,6 +201,12 @@ PHY framework provides 2 APIs to release a reference to the PHY.
Both these APIs are used to release a reference to the PHY and devm_phy_put
destroys the devres associated with this PHY.
+For devm_phy_bulk_get_all() and devm_of_phy_bulk_get_all(), driver detach
+releases both the PHY references and the allocated array. To release them
+earlier, use::
+
+ void devm_phy_bulk_put_all(struct device *dev, struct phy_bulk_data *phy);
+
Destroying the PHY
==================
@@ -221,3 +256,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/20260904083709.425893-1-inochiama@gmail.com/
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v5 7/8] PCI: cadence: Use phy bulk data api to simplifiy the logic
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
` (5 preceding siblings ...)
2026-11-25 4:36 ` [PATCH v5 6/8] doc: phy: Document some bulk " Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
2026-11-25 4:36 ` [PATCH v5 8/8] ata: ahci_imx: Use bulk PHY APIs for calibration PHYs Inochi Amaoto
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
According the document of cadence PCI controller, it use multiple
phys for multi-lane setup, so replace the loop of phy operation
with phy bulk apis.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
drivers/pci/controller/cadence/pcie-cadence.c | 62 +++++--------------
drivers/pci/controller/cadence/pcie-cadence.h | 2 +-
2 files changed, 16 insertions(+), 48 deletions(-)
diff --git a/drivers/pci/controller/cadence/pcie-cadence.c b/drivers/pci/controller/cadence/pcie-cadence.c
index 0ac980249941..8ed2a679625d 100644
--- a/drivers/pci/controller/cadence/pcie-cadence.c
+++ b/drivers/pci/controller/cadence/pcie-cadence.c
@@ -179,39 +179,22 @@ EXPORT_SYMBOL_GPL(cdns_pcie_reset_outbound_region);
void cdns_pcie_disable_phy(struct cdns_pcie *pcie)
{
- int i = pcie->phy_count;
-
- while (i--) {
- phy_power_off(pcie->phy[i]);
- phy_exit(pcie->phy[i]);
- }
+ phy_bulk_power_off(pcie->phy_count, pcie->phy);
+ phy_bulk_exit(pcie->phy_count, pcie->phy);
}
EXPORT_SYMBOL_GPL(cdns_pcie_disable_phy);
int cdns_pcie_enable_phy(struct cdns_pcie *pcie)
{
int ret;
- int i;
- for (i = 0; i < pcie->phy_count; i++) {
- ret = phy_init(pcie->phy[i]);
- if (ret < 0)
- goto err_phy;
+ ret = phy_bulk_init(pcie->phy_count, pcie->phy);
+ if (ret)
+ return ret;
- ret = phy_power_on(pcie->phy[i]);
- if (ret < 0) {
- phy_exit(pcie->phy[i]);
- goto err_phy;
- }
- }
-
- return 0;
-
-err_phy:
- while (--i >= 0) {
- phy_power_off(pcie->phy[i]);
- phy_exit(pcie->phy[i]);
- }
+ ret = phy_bulk_power_on(pcie->phy_count, pcie->phy);
+ if (ret)
+ phy_bulk_exit(pcie->phy_count, pcie->phy);
return ret;
}
@@ -221,10 +204,8 @@ int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie)
{
struct device_node *np = dev->of_node;
int phy_count;
- struct phy **phy;
- int i;
+ struct phy_bulk_data *phy;
int ret;
- const char *name;
phy_count = of_property_count_strings(np, "phy-names");
if (phy_count < 1) {
@@ -233,31 +214,18 @@ int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie)
return 0;
}
- phy = devm_kcalloc(dev, phy_count, sizeof(*phy), GFP_KERNEL);
- if (!phy)
- return -ENOMEM;
-
- for (i = 0; i < phy_count; i++) {
- of_property_read_string_index(np, "phy-names", i, &name);
- phy[i] = devm_phy_get(dev, name);
- if (IS_ERR(phy[i])) {
- ret = PTR_ERR(phy[i]);
- goto err_phy;
- }
- }
+ phy_count = devm_phy_bulk_get_all(dev, &phy);
+ if (phy_count < 0)
+ return phy_count;
+ else if (phy_count == 0)
+ return -ENODEV;
pcie->phy_count = phy_count;
pcie->phy = phy;
ret = cdns_pcie_enable_phy(pcie);
if (ret)
- goto err_phy;
-
- return 0;
-
-err_phy:
- while (--i >= 0)
- devm_phy_put(dev, phy[i]);
+ devm_phy_bulk_put_all(dev, phy);
return ret;
}
diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h
index 4a96e1869e53..3cde29592331 100644
--- a/drivers/pci/controller/cadence/pcie-cadence.h
+++ b/drivers/pci/controller/cadence/pcie-cadence.h
@@ -274,7 +274,7 @@ struct cdns_pcie {
bool is_rc;
bool is_hpa;
int phy_count;
- struct phy **phy;
+ struct phy_bulk_data *phy;
const struct cdns_pcie_ops *ops;
const struct cdns_plat_pcie_of_data *cdns_pcie_reg_offsets;
int max_link_speed;
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v5 8/8] ata: ahci_imx: Use bulk PHY APIs for calibration PHYs
2026-11-25 4:36 [PATCH v5 0/8] phy: core: Add phy bulk helpers support Inochi Amaoto
` (6 preceding siblings ...)
2026-11-25 4:36 ` [PATCH v5 7/8] PCI: cadence: Use phy bulk data api to simplifiy the logic Inochi Amaoto
@ 2026-11-25 4:36 ` Inochi Amaoto
7 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2026-11-25 4:36 UTC (permalink / raw)
To: Andy Shevchenko, Jonathan Corbet, Shuah Khan, Randy Dunlap,
Damien Le Moal, Niklas Cassel, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Aksh Garg,
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Bjorn Helgaas, Vinod Koul,
Neil Armstrong, Inochi Amaoto, Rhys Tumelty, Manikandan K Pillai,
vladimir.oltean, Qiang Yu, Hans Zhang, Yao Zi
Cc: linux-doc, linux-kernel, linux-ide, imx, linux-arm-kernel,
linux-pci, linux-phy, Yixun Lan, Longbin Li
The i.MX8QM SATA PHY relies on the first two HSIO lanes for shared
impedance calibration. Store these calibration PHYs in a bulk array
and acquire them by name with devm_phy_bulk_get().
Initialize both calibration PHYs before powering them on in lane order,
then keep the SATA PHY initialization, mode selection and power-on
separate. Use the bulk helpers to release the calibration PHYs after
SATA startup and to unwind failures without repeating power-off after
a failed bulk power-on.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
drivers/ata/ahci_imx.c | 57 ++++++++++++++++--------------------------
1 file changed, 21 insertions(+), 36 deletions(-)
diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c
index 6aaa18e29abc..18faa033e44f 100644
--- a/drivers/ata/ahci_imx.c
+++ b/drivers/ata/ahci_imx.c
@@ -25,6 +25,8 @@
#define DRV_NAME "ahci-imx"
+#define NUM_CALIPHY 2
+
enum {
/* Timer 1-ms Register */
IMX_TIMER1MS = 0x00e0,
@@ -66,8 +68,7 @@ struct imx_ahci_priv {
struct clk *ahb_clk;
struct regmap *gpr;
struct phy *sata_phy;
- struct phy *cali_phy0;
- struct phy *cali_phy1;
+ struct phy_bulk_data cali_phys[NUM_CALIPHY];
bool no_device;
bool first_time;
u32 phy_params;
@@ -428,30 +429,20 @@ static int imx8_sata_enable(struct ahci_host_priv *hpriv)
* Initialize the first two lane PHYs here, although only the
* third lane PHY is used by SATA.
*/
- ret = phy_init(imxpriv->cali_phy0);
+ ret = phy_bulk_init(NUM_CALIPHY, imxpriv->cali_phys);
if (ret) {
dev_err(dev, "cali PHY init failed\n");
return ret;
}
- ret = phy_power_on(imxpriv->cali_phy0);
+ ret = phy_bulk_power_on(NUM_CALIPHY, imxpriv->cali_phys);
if (ret) {
dev_err(dev, "cali PHY power on failed\n");
- goto err_cali_phy0_exit;
- }
- ret = phy_init(imxpriv->cali_phy1);
- if (ret) {
- dev_err(dev, "cali PHY1 init failed\n");
- goto err_cali_phy0_off;
- }
- ret = phy_power_on(imxpriv->cali_phy1);
- if (ret) {
- dev_err(dev, "cali PHY1 power on failed\n");
- goto err_cali_phy1_exit;
+ goto err_cali_phy_exit;
}
ret = phy_init(imxpriv->sata_phy);
if (ret) {
dev_err(dev, "sata PHY init failed\n");
- goto err_cali_phy1_off;
+ goto err_cali_phy_off;
}
ret = phy_set_mode(imxpriv->sata_phy, PHY_MODE_SATA);
if (ret) {
@@ -465,10 +456,8 @@ static int imx8_sata_enable(struct ahci_host_priv *hpriv)
}
/* The cali_phy# can be turned off after SATA PHY is initialized. */
- phy_power_off(imxpriv->cali_phy1);
- phy_exit(imxpriv->cali_phy1);
- phy_power_off(imxpriv->cali_phy0);
- phy_exit(imxpriv->cali_phy0);
+ phy_bulk_power_off(NUM_CALIPHY, imxpriv->cali_phys);
+ phy_bulk_exit(NUM_CALIPHY, imxpriv->cali_phys);
/* RxWaterMark setting */
val = readl(hpriv->mmio + IMX8QM_SATA_AHCI_PTC);
@@ -480,14 +469,10 @@ static int imx8_sata_enable(struct ahci_host_priv *hpriv)
err_sata_phy_exit:
phy_exit(imxpriv->sata_phy);
-err_cali_phy1_off:
- phy_power_off(imxpriv->cali_phy1);
-err_cali_phy1_exit:
- phy_exit(imxpriv->cali_phy1);
-err_cali_phy0_off:
- phy_power_off(imxpriv->cali_phy0);
-err_cali_phy0_exit:
- phy_exit(imxpriv->cali_phy0);
+err_cali_phy_off:
+ phy_bulk_power_off(NUM_CALIPHY, imxpriv->cali_phys);
+err_cali_phy_exit:
+ phy_bulk_exit(NUM_CALIPHY, imxpriv->cali_phys);
return ret;
}
@@ -839,19 +824,19 @@ static const struct scsi_host_template ahci_platform_sht = {
static int imx8_sata_probe(struct device *dev, struct imx_ahci_priv *imxpriv)
{
+ int ret;
+
imxpriv->sata_phy = devm_phy_get(dev, "sata-phy");
if (IS_ERR(imxpriv->sata_phy))
return dev_err_probe(dev, PTR_ERR(imxpriv->sata_phy),
"Failed to get sata_phy\n");
- imxpriv->cali_phy0 = devm_phy_get(dev, "cali-phy0");
- if (IS_ERR(imxpriv->cali_phy0))
- return dev_err_probe(dev, PTR_ERR(imxpriv->cali_phy0),
- "Failed to get cali_phy0\n");
- imxpriv->cali_phy1 = devm_phy_get(dev, "cali-phy1");
- if (IS_ERR(imxpriv->cali_phy1))
- return dev_err_probe(dev, PTR_ERR(imxpriv->cali_phy1),
- "Failed to get cali_phy1\n");
+ imxpriv->cali_phys[0].id = "cali-phy0";
+ imxpriv->cali_phys[1].id = "cali-phy1";
+
+ ret = devm_phy_bulk_get(dev, NUM_CALIPHY, imxpriv->cali_phys);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to get cali_phy\n");
return 0;
}
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread