Skip to content

Commit 62c953f

Browse files
author
Bartosz Golaszewski
committed
PCI/pwrctl: Reuse the OF node for power controlled devices
With PCI power control we deal with two struct device objects bound to two different drivers but consuming the same OF node. We must not bind the pinctrl twice. To that end: before setting the OF node of the newly instantiated PCI device, check if a platform device consuming the same OF node doesn't already exist on the platform bus and - if so - mark the PCI device as reusing the OF node. Tested-by: Amit Pundir <[email protected]> Tested-by: Neil Armstrong <[email protected]> # on SM8550-QRD, SM8650-QRD & SM8650-HDK Tested-by: Caleb Connolly <[email protected]> # OnePlus 8T Acked-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 5799eba commit 62c953f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/pci/of.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
*/
77
#define pr_fmt(fmt) "PCI: OF: " fmt
88

9+
#include <linux/cleanup.h>
910
#include <linux/irqdomain.h>
1011
#include <linux/kernel.h>
1112
#include <linux/pci.h>
1213
#include <linux/of.h>
1314
#include <linux/of_irq.h>
1415
#include <linux/of_address.h>
1516
#include <linux/of_pci.h>
17+
#include <linux/platform_device.h>
1618
#include "pci.h"
1719

1820
#ifdef CONFIG_PCI
@@ -25,16 +27,20 @@
2527
*/
2628
int pci_set_of_node(struct pci_dev *dev)
2729
{
28-
struct device_node *node;
29-
3030
if (!dev->bus->dev.of_node)
3131
return 0;
3232

33-
node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
33+
struct device_node *node __free(device_node) =
34+
of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
3435
if (!node)
3536
return 0;
3637

37-
device_set_node(&dev->dev, of_fwnode_handle(node));
38+
struct device *pdev __free(put_device) =
39+
bus_find_device_by_of_node(&platform_bus_type, node);
40+
if (pdev)
41+
dev->bus->dev.of_node_reused = true;
42+
43+
device_set_node(&dev->dev, of_fwnode_handle(no_free_ptr(node)));
3844
return 0;
3945
}
4046

0 commit comments

Comments
 (0)