Skip to content

Commit 5e5a3bf

Browse files
Hans ZhangMani-Sadhasivam
authored andcommitted
PCI: dw-rockchip: Use rockchip_pcie_link_up() to check link up instead of open coding
Some of the callers of rockchip_pcie_link_up() are open coding the rockchip_pcie_link_up() function, leading to code duplication. So switch them to use rockchip_pcie_link_up() function. Also, use the FIELD_GET() macro to simplify the link up check in rockchip_pcie_link_up(). Signed-off-by: Hans Zhang <[email protected]> [mani: subject and description rewording] Signed-off-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent ae8ed2b commit 5e5a3bf

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

drivers/pci/controller/dwc/pcie-dw-rockchip.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Author: Simon Xue <[email protected]>
99
*/
1010

11+
#include <linux/bitfield.h>
1112
#include <linux/clk.h>
1213
#include <linux/gpio/consumer.h>
1314
#include <linux/irqchip/chained_irq.h>
@@ -60,9 +61,8 @@
6061

6162
/* LTSSM Status Register */
6263
#define PCIE_CLIENT_LTSSM_STATUS 0x300
63-
#define PCIE_SMLH_LINKUP BIT(16)
64-
#define PCIE_RDLH_LINKUP BIT(17)
65-
#define PCIE_LINKUP (PCIE_SMLH_LINKUP | PCIE_RDLH_LINKUP)
64+
#define PCIE_LINKUP 0x3
65+
#define PCIE_LINKUP_MASK GENMASK(17, 16)
6666
#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
6767

6868
struct rockchip_pcie {
@@ -188,10 +188,7 @@ static int rockchip_pcie_link_up(struct dw_pcie *pci)
188188
struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
189189
u32 val = rockchip_pcie_get_ltssm(rockchip);
190190

191-
if ((val & PCIE_LINKUP) == PCIE_LINKUP)
192-
return 1;
193-
194-
return 0;
191+
return FIELD_GET(PCIE_LINKUP_MASK, val) == PCIE_LINKUP;
195192
}
196193

197194
static void rockchip_pcie_enable_l0s(struct dw_pcie *pci)
@@ -450,7 +447,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
450447
struct dw_pcie *pci = &rockchip->pci;
451448
struct dw_pcie_rp *pp = &pci->pp;
452449
struct device *dev = pci->dev;
453-
u32 reg, val;
450+
u32 reg;
454451

455452
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
456453
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -459,8 +456,7 @@ static irqreturn_t rockchip_pcie_rc_sys_irq_thread(int irq, void *arg)
459456
dev_dbg(dev, "LTSSM_STATUS: %#x\n", rockchip_pcie_get_ltssm(rockchip));
460457

461458
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
462-
val = rockchip_pcie_get_ltssm(rockchip);
463-
if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
459+
if (rockchip_pcie_link_up(pci)) {
464460
dev_dbg(dev, "Received Link up event. Starting enumeration!\n");
465461
/* Rescan the bus to enumerate endpoint devices */
466462
pci_lock_rescan_remove();
@@ -477,7 +473,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
477473
struct rockchip_pcie *rockchip = arg;
478474
struct dw_pcie *pci = &rockchip->pci;
479475
struct device *dev = pci->dev;
480-
u32 reg, val;
476+
u32 reg;
481477

482478
reg = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_INTR_STATUS_MISC);
483479
rockchip_pcie_writel_apb(rockchip, reg, PCIE_CLIENT_INTR_STATUS_MISC);
@@ -491,8 +487,7 @@ static irqreturn_t rockchip_pcie_ep_sys_irq_thread(int irq, void *arg)
491487
}
492488

493489
if (reg & PCIE_RDLH_LINK_UP_CHGED) {
494-
val = rockchip_pcie_get_ltssm(rockchip);
495-
if ((val & PCIE_LINKUP) == PCIE_LINKUP) {
490+
if (rockchip_pcie_link_up(pci)) {
496491
dev_dbg(dev, "link up\n");
497492
dw_pcie_ep_linkup(&pci->ep);
498493
}

0 commit comments

Comments
 (0)