]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
dmaengine: dw: Simplify prepare CTL_LO methods
authorSerge Semin <fancer.lancer@gmail.com>
Fri, 2 Aug 2024 07:50:48 +0000 (10:50 +0300)
committerVinod Koul <vkoul@kernel.org>
Mon, 5 Aug 2024 16:37:47 +0000 (22:07 +0530)
Currently the CTL LO fields are calculated on the platform-specific basis.
It's implemented by means of the prepare_ctllo() callbacks using the
ternary operator within the local variables init block at the beginning of
the block scope. The functions code currently is relatively hard to
comprehend and isn't that optimal since implies four conditional
statements executed and two additional local variables defined. Let's
simplify the DW AHB DMA prepare_ctllo() method by unrolling the ternary
operators into the normal if-else statement, dropping redundant
master-interface ID variables and initializing the local variables based
on the singly evaluated DMA-transfer direction check. Thus the method will
look much more readable since now the fields content can be easily
inferred right from the if-else branch. Provide the same update in the
Intel DMA32 core driver for the sake of the driver code unification.

Note besides of the effects described above this update is basically a
preparation before dropping the max burst encoding callback. The dropping
will require to call the burst fields calculation methods right in the
prepare_ctllo() callbacks. It would have made the later functions code
even more complex should they were left in the original state.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
Acked-by: Andy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/20240802075100.6475-4-fancer.lancer@gmail.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/dw/dw.c
drivers/dma/dw/idma32.c

index a4862263ff14df9c6505fabc160b08901df66f5c..e3d2cc3ea68c0a8ed0520ba980081811f7852f07 100644 (file)
@@ -67,12 +67,21 @@ static size_t dw_dma_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
 static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc)
 {
        struct dma_slave_config *sconfig = &dwc->dma_sconfig;
-       u8 smsize = (dwc->direction == DMA_DEV_TO_MEM) ? sconfig->src_maxburst : 0;
-       u8 dmsize = (dwc->direction == DMA_MEM_TO_DEV) ? sconfig->dst_maxburst : 0;
-       u8 p_master = dwc->dws.p_master;
-       u8 m_master = dwc->dws.m_master;
-       u8 dms = (dwc->direction == DMA_MEM_TO_DEV) ? p_master : m_master;
-       u8 sms = (dwc->direction == DMA_DEV_TO_MEM) ? p_master : m_master;
+       u8 smsize = 0, dmsize = 0;
+       u8 sms, dms;
+
+       if (dwc->direction == DMA_MEM_TO_DEV) {
+               sms = dwc->dws.m_master;
+               dms = dwc->dws.p_master;
+               dmsize = sconfig->dst_maxburst;
+       } else if (dwc->direction == DMA_DEV_TO_MEM) {
+               sms = dwc->dws.p_master;
+               dms = dwc->dws.m_master;
+               smsize = sconfig->src_maxburst;
+       } else /* DMA_MEM_TO_MEM */ {
+               sms = dwc->dws.m_master;
+               dms = dwc->dws.m_master;
+       }
 
        return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN |
               DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize) |
index 58f4078d83feca8f6f1389e459c266ed4149cefb..e0c31f77cd0f2752311a1b95d7aa024290d34c50 100644 (file)
@@ -202,8 +202,12 @@ static size_t idma32_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
 static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc)
 {
        struct dma_slave_config *sconfig = &dwc->dma_sconfig;
-       u8 smsize = (dwc->direction == DMA_DEV_TO_MEM) ? sconfig->src_maxburst : 0;
-       u8 dmsize = (dwc->direction == DMA_MEM_TO_DEV) ? sconfig->dst_maxburst : 0;
+       u8 smsize = 0, dmsize = 0;
+
+       if (dwc->direction == DMA_MEM_TO_DEV)
+               dmsize = sconfig->dst_maxburst;
+       else if (dwc->direction == DMA_DEV_TO_MEM)
+               smsize = sconfig->src_maxburst;
 
        return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN |
               DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize);