>From ca70e7dd9b84c9dd01124a13f624441c01f7c09d Mon Sep 17 00:00:00 2001 From: Serge Semin Date: Fri, 2 Feb 2024 18:18:39 +0300 Subject: [PATCH 2/5] PCI: dwc: Split up eDMA parameters auto-detection procedure It turns out the DW HDMA controller parameters can't be auto-detected in the same way as it's done for DW eDMA: HDMA has only the unrolled CSRs mapping and has no way to find out the amount of the channels. For that case the best choice would be to have the HDMA controller parameters pre-defined by the platform drivers and to convert the implemented auto-detection procedure to being optionally executed if no DMA-controller parameters specified. As a preparation step before that let's split the eDMA auto-detection into three stages: 1. initialize DW eDMA data, 2. auto-detect the CSRs mapping format, 3. auto-detect the amount of channels. Note this commit doesn't imply the eDMA detection procedure semantics change. Signed-off-by: Serge Semin --- drivers/pci/controller/dwc/pcie-designware.c | 33 +++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c index 454ea32ee70b..149c7a2a12f2 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c @@ -878,7 +878,17 @@ static struct dw_edma_plat_ops dw_pcie_edma_ops = { .irq_vector = dw_pcie_edma_irq_vector, }; -static int dw_pcie_edma_find_chip(struct dw_pcie *pci) +static void dw_pcie_edma_init_data(struct dw_pcie *pci) +{ + pci->edma.dev = pci->dev; + + if (!pci->edma.ops) + pci->edma.ops = &dw_pcie_edma_ops; + + pci->edma.flags |= DW_EDMA_CHIP_LOCAL; +} + +static int dw_pcie_edma_find_mf(struct dw_pcie *pci) { u32 val; @@ -900,8 +910,6 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) if (val == 0xFFFFFFFF && pci->edma.reg_base) { pci->edma.mf = EDMA_MF_EDMA_UNROLL; - - val = dw_pcie_readl_dma(pci, PCIE_DMA_CTRL); } else if (val != 0xFFFFFFFF) { pci->edma.mf = EDMA_MF_EDMA_LEGACY; @@ -910,12 +918,14 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) return -ENODEV; } - pci->edma.dev = pci->dev; + return 0; +} - if (!pci->edma.ops) - pci->edma.ops = &dw_pcie_edma_ops; +static int dw_pcie_edma_find_chan(struct dw_pcie *pci) +{ + u32 val; - pci->edma.flags |= DW_EDMA_CHIP_LOCAL; + val = dw_pcie_readl_dma(pci, PCIE_DMA_CTRL); pci->edma.ll_wr_cnt = FIELD_GET(PCIE_DMA_NUM_WR_CHAN, val); pci->edma.ll_rd_cnt = FIELD_GET(PCIE_DMA_NUM_RD_CHAN, val); @@ -992,8 +1002,15 @@ int dw_pcie_edma_detect(struct dw_pcie *pci) { int ret; + dw_pcie_edma_init_data(pci); + /* Don't fail if no eDMA was found (for the backward compatibility) */ - ret = dw_pcie_edma_find_chip(pci); + ret = dw_pcie_edma_find_mf(pci); + if (ret) + return 0; + + /* Don't fail if no valid channels detected (for the backward compatibility) */ + ret = dw_pcie_edma_find_chan(pci); if (ret) return 0; -- 2.43.0