Skip to content

Commit 9de3f3c

Browse files
nxpfranklibjorn-helgaas
authored andcommitted
PCI: dwc: Add dw_pcie_parent_bus_offset()
Return the offset from CPU physical address to the parent bus address of the specified element of the devicetree 'reg' property. [bhelgaas: cpu_phy_addr -> cpu_phys_addr, return offset, split .cpu_addr_fixup() checking and debug to separate patch] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Frank Li <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 2ce107e commit 9de3f3c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

drivers/pci/controller/dwc/pcie-designware.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/gpio/consumer.h>
1717
#include <linux/ioport.h>
1818
#include <linux/of.h>
19+
#include <linux/of_address.h>
1920
#include <linux/platform_device.h>
2021
#include <linux/sizes.h>
2122
#include <linux/types.h>
@@ -1105,3 +1106,25 @@ void dw_pcie_setup(struct dw_pcie *pci)
11051106

11061107
dw_pcie_link_set_max_link_width(pci, pci->num_lanes);
11071108
}
1109+
1110+
resource_size_t dw_pcie_parent_bus_offset(struct dw_pcie *pci,
1111+
const char *reg_name,
1112+
resource_size_t cpu_phys_addr)
1113+
{
1114+
struct device *dev = pci->dev;
1115+
struct device_node *np = dev->of_node;
1116+
int index;
1117+
u64 reg_addr;
1118+
1119+
/* Look up reg_name address on parent bus */
1120+
index = of_property_match_string(np, "reg-names", reg_name);
1121+
1122+
if (index < 0) {
1123+
dev_err(dev, "No %s in devicetree \"reg\" property\n", reg_name);
1124+
return 0;
1125+
}
1126+
1127+
of_property_read_reg(np, index, &reg_addr, NULL);
1128+
1129+
return cpu_phys_addr - reg_addr;
1130+
}

drivers/pci/controller/dwc/pcie-designware.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ void dw_pcie_setup(struct dw_pcie *pci);
500500
void dw_pcie_iatu_detect(struct dw_pcie *pci);
501501
int dw_pcie_edma_detect(struct dw_pcie *pci);
502502
void dw_pcie_edma_remove(struct dw_pcie *pci);
503+
resource_size_t dw_pcie_parent_bus_offset(struct dw_pcie *pci,
504+
const char *reg_name,
505+
resource_size_t cpu_phy_addr);
503506

504507
static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val)
505508
{

0 commit comments

Comments
 (0)