A PCI bus may be a bridge device where the controller is the bridge's
parent. Add a function to return the controller device, given a PCI device.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
        return dev_get_uclass_priv(bus);
 }
 
+struct udevice *pci_get_controller(struct udevice *dev)
+{
+       while (device_is_on_pci_bus(dev))
+               dev = dev->parent;
+
+       return dev;
+}
+
 pci_dev_t pci_get_bdf(struct udevice *dev)
 {
        struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
 
 ulong pci_conv_size_to_32(ulong old, ulong value, uint offset,
                          enum pci_size_t size);
 
+/**
+ * pci_get_controller() - obtain the controller to use for a bus
+ *
+ * @dev:       Device to check
+ * @return pointer to the controller device for this bus
+ */
+struct udevice *pci_get_controller(struct udevice *dev);
+
 /**
  * struct dm_pci_emul_ops - PCI device emulator operations
  */