[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250611163131.860729-1-18255117159@163.com>
Date: Thu, 12 Jun 2025 00:31:31 +0800
From: Hans Zhang <18255117159@....com>
To: lpieralisi@...nel.org,
bhelgaas@...gle.com,
mani@...nel.org,
kwilczynski@...nel.org
Cc: robh@...nel.org,
jingoohan1@...il.com,
linux-pci@...r.kernel.org,
linux-kernel@...r.kernel.org,
Hans Zhang <18255117159@....com>
Subject: [PATCH 05/13] PCI: dwc: Refactor meson to use dw_pcie_clear_and_set_dword()
Meson PCIe driver implements payload size configuration through manual
register manipulation. The current code reads device control registers,
modifies specific bitfields for maximum payload and read request sizes,
then writes back the updated values. This pattern repeats twice with
similar logic but different bit masks.
Replace explicit bit manipulation with dw_pcie_clear_and_set_dword() for
payload and read request size configuration. The helper consolidates
read-clear-set-write operations into a single call, eliminating redundant
register read operations and local variable usage.
This refactoring reduces code duplication in size configuration logic
and improves maintainability. By using the DesignWare helper, the driver
aligns with standard PCIe controller programming patterns and simplifies
future updates to device capability settings.
Signed-off-by: Hans Zhang <18255117159@....com>
---
drivers/pci/controller/dwc/pci-meson.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
index 787469d1b396..cd6280a8e619 100644
--- a/drivers/pci/controller/dwc/pci-meson.c
+++ b/drivers/pci/controller/dwc/pci-meson.c
@@ -264,33 +264,27 @@ static int meson_size_to_payload(struct meson_pcie *mp, int size)
static void meson_set_max_payload(struct meson_pcie *mp, int size)
{
struct dw_pcie *pci = &mp->pci;
- u32 val;
u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
int max_payload_size = meson_size_to_payload(mp, size);
- val = dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL);
- val &= ~PCI_EXP_DEVCTL_PAYLOAD;
- dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val);
+ dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL,
+ PCI_EXP_DEVCTL_PAYLOAD, 0);
- val = dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL);
- val |= PCIE_CAP_MAX_PAYLOAD_SIZE(max_payload_size);
- dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val);
+ dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL, 0,
+ PCIE_CAP_MAX_PAYLOAD_SIZE(max_payload_size));
}
static void meson_set_max_rd_req_size(struct meson_pcie *mp, int size)
{
struct dw_pcie *pci = &mp->pci;
- u32 val;
u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
int max_rd_req_size = meson_size_to_payload(mp, size);
- val = dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL);
- val &= ~PCI_EXP_DEVCTL_READRQ;
- dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val);
+ dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL,
+ PCI_EXP_DEVCTL_READRQ, 0);
- val = dw_pcie_readl_dbi(pci, offset + PCI_EXP_DEVCTL);
- val |= PCIE_CAP_MAX_READ_REQ_SIZE(max_rd_req_size);
- dw_pcie_writel_dbi(pci, offset + PCI_EXP_DEVCTL, val);
+ dw_pcie_clear_and_set_dword(pci, offset + PCI_EXP_DEVCTL, 0,
+ PCIE_CAP_MAX_READ_REQ_SIZE(max_rd_req_size));
}
static int meson_pcie_start_link(struct dw_pcie *pci)
--
2.25.1
Powered by blists - more mailing lists