[PATCH v2 1/3] PCI/pwrctrl: Export per-device APIs
From: Yureka Lilian
Date: Wed Nov 04 2026 - 06:42:47 EST
Export the `pci_pwrctrl_power_on_device()` and
`pci_pwrctrl_power_off_device()` functions to allow PCIe host drivers
to call manage power control on a per-port basis.
Signed-off-by: Yureka Lilian <yureka@xxxxxxxxxxxxxx>
---
drivers/pci/pwrctrl/core.c | 51 ++++++++++++++++++++++++++++++++++++++++-----
include/linux/pci-pwrctrl.h | 4 ++++
2 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/pwrctrl/core.c b/drivers/pci/pwrctrl/core.c
index 0e2387cf4657..b59dbedf251b 100644
--- a/drivers/pci/pwrctrl/core.c
+++ b/drivers/pci/pwrctrl/core.c
@@ -191,7 +191,16 @@ static int __pci_pwrctrl_power_off_device(struct device *dev)
return pwrctrl->power_off(pwrctrl);
}
-static void pci_pwrctrl_power_off_device(struct device_node *np)
+/**
+ * pci_pwrctrl_power_off_device - Power off pwrctrl devices
+ *
+ * @device_node: PCI port or device to operate on
+ *
+ * Recursively traverse all pwrctrl devices for the devicetree hierarchy
+ * below the specified PCI port or device and power them off in a depth
+ * first manner.
+ */
+void pci_pwrctrl_power_off_device(struct device_node *np)
{
struct platform_device *pdev;
int ret;
@@ -216,6 +225,7 @@ static void pci_pwrctrl_power_off_device(struct device_node *np)
platform_device_put(pdev);
}
+EXPORT_SYMBOL_GPL(pci_pwrctrl_power_off_device);
/**
* pci_pwrctrl_power_off_devices - Power off pwrctrl devices
@@ -245,11 +255,21 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)
return pwrctrl->power_on(pwrctrl);
}
-/*
+/**
+ * pci_pwrctrl_power_on_device - Power on pwrctrl devices
+ *
+ * @device_node: PCI port or device to operate on
+ *
* Power on the devices in a depth first manner. Before powering on the device,
* make sure its driver is bound.
+ * Recursively traverse all pwrctrl devices for the devicetree hierarchy
+ * below the specified PCI port or device and power them on in a depth
+ * first manner. Before powering on the device, make sure its driver is bound.
+ *
+ * Return: 0 on success, -EPROBE_DEFER if any pwrctrl driver is not bound, an
+ * appropriate error code otherwise.
*/
-static int pci_pwrctrl_power_on_device(struct device_node *np)
+int pci_pwrctrl_power_on_device(struct device_node *np)
{
struct platform_device *pdev;
struct device_node *child;
@@ -296,6 +316,7 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)
return ret;
}
+EXPORT_SYMBOL_GPL(pci_pwrctrl_power_on_device);
/**
* pci_pwrctrl_power_on_devices - Power on pwrctrl devices
@@ -335,7 +356,17 @@ int pci_pwrctrl_power_on_devices(struct device *parent)
}
EXPORT_SYMBOL_GPL(pci_pwrctrl_power_on_devices);
-static int pci_pwrctrl_create_device(struct device_node *np,
+/**
+ * pci_pwrctrl_create_device - Create pwrctrl devices
+ *
+ * @device_node: PCI port or device to operate on
+ *
+ * Recursively create pwrctrl devices for the devicetree hierarchy below
+ * the specified PCI port or device in a depth first manner.
+ *
+ * Return: 0 on success, negative error number on error.
+ */
+int pci_pwrctrl_create_device(struct device_node *np,
struct device *parent)
{
struct platform_device *pdev;
@@ -368,6 +399,7 @@ static int pci_pwrctrl_create_device(struct device_node *np,
return 0;
}
+EXPORT_SYMBOL_GPL(pci_pwrctrl_create_device);
/**
* pci_pwrctrl_create_devices - Create pwrctrl devices
@@ -396,7 +428,15 @@ int pci_pwrctrl_create_devices(struct device *parent)
}
EXPORT_SYMBOL_GPL(pci_pwrctrl_create_devices);
-static void pci_pwrctrl_destroy_device(struct device_node *np)
+/**
+ * pci_pwrctrl_destroy_device - Destroy pwrctrl devices
+ *
+ * @device_node: PCI port or device to operate on
+ *
+ * Recursively destroy pwrctrl devices for the devicetree hierarchy below
+ * the specified PCI port or device in a depth first manner.
+ */
+void pci_pwrctrl_destroy_device(struct device_node *np)
{
struct platform_device *pdev;
@@ -415,6 +455,7 @@ static void pci_pwrctrl_destroy_device(struct device_node *np)
of_node_clear_flag(np, OF_POPULATED);
}
+EXPORT_SYMBOL_GPL(pci_pwrctrl_destroy_device);
/**
* pci_pwrctrl_destroy_devices - Destroy pwrctrl devices
diff --git a/include/linux/pci-pwrctrl.h b/include/linux/pci-pwrctrl.h
index 1192a2527521..f27be6489b50 100644
--- a/include/linux/pci-pwrctrl.h
+++ b/include/linux/pci-pwrctrl.h
@@ -59,6 +59,10 @@ int pci_pwrctrl_create_devices(struct device *parent);
void pci_pwrctrl_destroy_devices(struct device *parent);
int pci_pwrctrl_power_on_devices(struct device *parent);
void pci_pwrctrl_power_off_devices(struct device *parent);
+int pci_pwrctrl_create_device(struct device_node *np, struct device *parent);
+void pci_pwrctrl_destroy_device(struct device_node *np);
+int pci_pwrctrl_power_on_device(struct device_node *np);
+void pci_pwrctrl_power_off_device(struct device_node *np);
#else
static inline int pci_pwrctrl_create_devices(struct device *parent) { return 0; }
static void pci_pwrctrl_destroy_devices(struct device *parent) { }
--
2.56.0