Skip to content

Commit 278dd09

Browse files
Mani-Sadhasivamkwilczynski
authored andcommitted
PCI/pwrctl: Create pwrctl device only if at least one power supply is present
Currently, pwrctl devices are created if the corresponding PCI nodes are defined in devicetree. But this is not correct, because not all PCI nodes require pwrctl support. Pwrctl comes into the picture only when the device requires kernel to manage its power state. This can be determined using the power supply properties present in the devicetree node of the device. Add of_pci_supply_present() to check whether the devicetree contains at least one power supply property for a device. If one is present, create a pwrctl device for that PCI node. Suggested-by: Dmitry Baryshkov <[email protected]> Fixes: 8fb1861 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node") Link: https://lore.kernel.org/r/[email protected] Tested-by: Bartosz Golaszewski <[email protected]> Tested-by: Krishna chaitanya chundru <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> [bhelgaas: rename of_pci_is_supply_present() to of_pci_supply_present() for readability] Signed-off-by: Bjorn Helgaas <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Bartosz Golaszewski <[email protected]> Cc: [email protected] # Depends on of_platform_device_create() rework
1 parent 7582fe0 commit 278dd09

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

drivers/pci/bus.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@ void pci_bus_add_device(struct pci_dev *dev)
354354

355355
if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) {
356356
for_each_available_child_of_node_scoped(dn, child) {
357+
/*
358+
* First check whether the pwrctl device needs to be
359+
* created or not. This is decided based on at least
360+
* one of the power supplies being defined in the
361+
* devicetree node of the device.
362+
*/
363+
if (!of_pci_supply_present(child)) {
364+
pci_dbg(dev, "skipping OF node: %s\n", child->name);
365+
continue;
366+
}
367+
357368
pdev = of_platform_device_create(child, NULL, &dev->dev);
358369
if (!pdev)
359370
pci_err(dev, "failed to create OF node: %s\n", child->name);

drivers/pci/of.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,33 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
728728
}
729729
#endif
730730

731+
/**
732+
* of_pci_supply_present() - Check if the power supply is present for the PCI
733+
* device
734+
* @np: Device tree node
735+
*
736+
* Check if the power supply for the PCI device is present in the device tree
737+
* node or not.
738+
*
739+
* Return: true if at least one power supply exists; false otherwise.
740+
*/
741+
bool of_pci_supply_present(struct device_node *np)
742+
{
743+
struct property *prop;
744+
char *supply;
745+
746+
if (!np)
747+
return false;
748+
749+
for_each_property_of_node(np, prop) {
750+
supply = strrchr(prop->name, '-');
751+
if (supply && !strcmp(supply, "-supply"))
752+
return true;
753+
}
754+
755+
return false;
756+
}
757+
731758
#endif /* CONFIG_PCI */
732759

733760
/**

drivers/pci/pci.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ void pci_set_bus_of_node(struct pci_bus *bus);
746746
void pci_release_bus_of_node(struct pci_bus *bus);
747747

748748
int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
749+
bool of_pci_supply_present(struct device_node *np);
749750

750751
#else
751752
static inline int
@@ -793,6 +794,10 @@ static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_br
793794
return 0;
794795
}
795796

797+
static inline bool of_pci_supply_present(struct device_node *np)
798+
{
799+
return false;
800+
}
796801
#endif /* CONFIG_OF */
797802

798803
struct of_changeset;

0 commit comments

Comments
 (0)