summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/pci/pwrctrl/core.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/drivers/pci/pwrctrl/core.c b/drivers/pci/pwrctrl/core.c
index 6f7dea6746e0..8325858cc379 100644
--- a/drivers/pci/pwrctrl/core.c
+++ b/drivers/pci/pwrctrl/core.c
@@ -268,6 +268,39 @@ err_power_off:
}
EXPORT_SYMBOL_GPL(pci_pwrctrl_power_on_devices);
+/*
+ * Check whether the pwrctrl device really needs to be created or not. The
+ * pwrctrl device will only be created if the node satisfies below requirements:
+ *
+ * 1. Presence of compatible property to match against the pwrctrl driver (AND)
+ * 2. At least one of the power supplies defined in the devicetree node of the
+ * device (OR) in the remote endpoint parent node to indicate pwrctrl
+ * requirement.
+ */
+static bool pci_pwrctrl_is_required(struct device_node *np)
+{
+ struct device_node *endpoint;
+
+ if (!of_property_present(np, "compatible"))
+ return false;
+
+ if (of_pci_supply_present(np))
+ return true;
+
+ if (of_graph_is_present(np)) {
+ for_each_endpoint_of_node(np, endpoint) {
+ struct device_node *remote __free(device_node) =
+ of_graph_get_remote_port_parent(endpoint);
+ if (remote) {
+ if (of_pci_supply_present(remote))
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
static int pci_pwrctrl_create_device(struct device_node *np,
struct device *parent)
{
@@ -287,19 +320,7 @@ static int pci_pwrctrl_create_device(struct device_node *np,
return 0;
}
- /*
- * Sanity check to make sure that the node has the compatible property
- * to allow driver binding.
- */
- if (!of_property_present(np, "compatible"))
- return 0;
-
- /*
- * Check whether the pwrctrl device really needs to be created or not.
- * This is decided based on at least one of the power supplies defined
- * in the devicetree node of the device or the graph property.
- */
- if (!of_pci_supply_present(np) && !of_graph_is_present(np)) {
+ if (!pci_pwrctrl_is_required(np)) {
dev_dbg(parent, "Skipping OF node: %s\n", np->name);
return 0;
}