summaryrefslogtreecommitdiff
path: root/drivers/pci
diff options
context:
space:
mode:
authorStefan Roese <sr@denx.de>2019-01-25 11:52:42 +0100
committerStefan Roese <sr@denx.de>2019-02-05 14:22:24 +0100
commitb52142004fbdfd6db0091ba7ae33c91e3b459034 (patch)
tree82a451e32969f8ee4d49448b82f751ecdb816f41 /drivers/pci
parente5fd39c886485e3dec77f4438a6e364c2987cf5f (diff)
pci: Add pci_get_devfn() to extract devfn from the fdt_pci_addr
This function will be used by the Marvell Armada XP/38x PCIe driver, which is moved to DM right now. So let's extract the functionality from pci_uclass_child_post_bind() to make it available. Signed-off-by: Stefan Roese <sr@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/pci-uclass.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 2cf55cb743..47f3cc9107 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -1007,10 +1007,25 @@ static int pci_uclass_post_probe(struct udevice *bus)
return 0;
}
+int pci_get_devfn(struct udevice *dev)
+{
+ struct fdt_pci_addr addr;
+ int ret;
+
+ /* Extract the devfn from fdt_pci_addr */
+ ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
+ "reg", &addr);
+ if (ret) {
+ if (ret != -ENOENT)
+ return -EINVAL;
+ }
+
+ return addr.phys_hi & 0xff00;
+}
+
static int pci_uclass_child_post_bind(struct udevice *dev)
{
struct pci_child_platdata *pplat;
- struct fdt_pci_addr addr;
int ret;
if (!dev_of_valid(dev))
@@ -1022,14 +1037,9 @@ static int pci_uclass_child_post_bind(struct udevice *dev)
ofnode_read_pci_vendev(dev_ofnode(dev), &pplat->vendor, &pplat->device);
/* Extract the devfn from fdt_pci_addr */
- ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, "reg",
- &addr);
- if (ret) {
- if (ret != -ENOENT)
- return -EINVAL;
- } else {
- pplat->devfn = addr.phys_hi & 0xff00;
- }
+ pplat->devfn = pci_get_devfn(dev);
+ if (ret < 0)
+ return ret;
return 0;
}