PCI: cadence: Simplify code to get register base address for configuring BAR
authorKishon Vijay Abraham I <kishon@ti.com>
Thu, 19 Aug 2021 12:33:40 +0000 (18:03 +0530)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Thu, 19 Aug 2021 13:13:29 +0000 (14:13 +0100)
No functional change. Simplify code to get register base address for
configuring PCI BAR.

Link: https://lore.kernel.org/r/20210819123343.1951-6-kishon@ti.com
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
drivers/pci/controller/cadence/pcie-cadence-ep.c
drivers/pci/controller/cadence/pcie-cadence.h

index 912a15b..f337f08 100644 (file)
@@ -97,13 +97,8 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, u8 vfn,
        cdns_pcie_writel(pcie, CDNS_PCIE_AT_IB_EP_FUNC_BAR_ADDR1(fn, bar),
                         addr1);
 
-       if (bar < BAR_4) {
-               reg = CDNS_PCIE_LM_EP_FUNC_BAR_CFG0(fn);
-               b = bar;
-       } else {
-               reg = CDNS_PCIE_LM_EP_FUNC_BAR_CFG1(fn);
-               b = bar - BAR_4;
-       }
+       reg = CDNS_PCIE_LM_EP_FUNC_BAR_CFG(bar, fn);
+       b = (bar < BAR_4) ? bar : bar - BAR_4;
 
        cfg = cdns_pcie_readl(pcie, reg);
        cfg &= ~(CDNS_PCIE_LM_EP_FUNC_BAR_CFG_BAR_APERTURE_MASK(b) |
@@ -126,13 +121,8 @@ static void cdns_pcie_ep_clear_bar(struct pci_epc *epc, u8 fn, u8 vfn,
        enum pci_barno bar = epf_bar->barno;
        u32 reg, cfg, b, ctrl;
 
-       if (bar < BAR_4) {
-               reg = CDNS_PCIE_LM_EP_FUNC_BAR_CFG0(fn);
-               b = bar;
-       } else {
-               reg = CDNS_PCIE_LM_EP_FUNC_BAR_CFG1(fn);
-               b = bar - BAR_4;
-       }
+       reg = CDNS_PCIE_LM_EP_FUNC_BAR_CFG(bar, fn);
+       b = (bar < BAR_4) ? bar : bar - BAR_4;
 
        ctrl = CDNS_PCIE_LM_BAR_CFG_CTRL_DISABLED;
        cfg = cdns_pcie_readl(pcie, reg);
index 30db2d6..347ed7b 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/kernel.h>
 #include <linux/pci.h>
+#include <linux/pci-epf.h>
 #include <linux/phy/phy.h>
 
 /* Parameters for the waiting for link up routine */
@@ -46,6 +47,8 @@
 #define  CDNS_PCIE_LM_EP_ID_BUS_SHIFT  8
 
 /* Endpoint Function f BAR b Configuration Registers */
+#define CDNS_PCIE_LM_EP_FUNC_BAR_CFG(bar, fn) \
+       (((bar) < BAR_4) ? CDNS_PCIE_LM_EP_FUNC_BAR_CFG0(fn) : CDNS_PCIE_LM_EP_FUNC_BAR_CFG1(fn))
 #define CDNS_PCIE_LM_EP_FUNC_BAR_CFG0(fn) \
        (CDNS_PCIE_LM_BASE + 0x0240 + (fn) * 0x0008)
 #define CDNS_PCIE_LM_EP_FUNC_BAR_CFG1(fn) \