Skip to content

Commit 1fd6fe8

Browse files
fancervinodkoul
authored andcommitted
dmaengine: dw: Simplify prepare CTL_LO methods
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>
1 parent d04b21b commit 1fd6fe8

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

drivers/dma/dw/dw.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,21 @@ static size_t dw_dma_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
6767
static u32 dw_dma_prepare_ctllo(struct dw_dma_chan *dwc)
6868
{
6969
struct dma_slave_config *sconfig = &dwc->dma_sconfig;
70-
u8 smsize = (dwc->direction == DMA_DEV_TO_MEM) ? sconfig->src_maxburst : 0;
71-
u8 dmsize = (dwc->direction == DMA_MEM_TO_DEV) ? sconfig->dst_maxburst : 0;
72-
u8 p_master = dwc->dws.p_master;
73-
u8 m_master = dwc->dws.m_master;
74-
u8 dms = (dwc->direction == DMA_MEM_TO_DEV) ? p_master : m_master;
75-
u8 sms = (dwc->direction == DMA_DEV_TO_MEM) ? p_master : m_master;
70+
u8 smsize = 0, dmsize = 0;
71+
u8 sms, dms;
72+
73+
if (dwc->direction == DMA_MEM_TO_DEV) {
74+
sms = dwc->dws.m_master;
75+
dms = dwc->dws.p_master;
76+
dmsize = sconfig->dst_maxburst;
77+
} else if (dwc->direction == DMA_DEV_TO_MEM) {
78+
sms = dwc->dws.p_master;
79+
dms = dwc->dws.m_master;
80+
smsize = sconfig->src_maxburst;
81+
} else /* DMA_MEM_TO_MEM */ {
82+
sms = dwc->dws.m_master;
83+
dms = dwc->dws.m_master;
84+
}
7685

7786
return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN |
7887
DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize) |

drivers/dma/dw/idma32.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,12 @@ static size_t idma32_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
202202
static u32 idma32_prepare_ctllo(struct dw_dma_chan *dwc)
203203
{
204204
struct dma_slave_config *sconfig = &dwc->dma_sconfig;
205-
u8 smsize = (dwc->direction == DMA_DEV_TO_MEM) ? sconfig->src_maxburst : 0;
206-
u8 dmsize = (dwc->direction == DMA_MEM_TO_DEV) ? sconfig->dst_maxburst : 0;
205+
u8 smsize = 0, dmsize = 0;
206+
207+
if (dwc->direction == DMA_MEM_TO_DEV)
208+
dmsize = sconfig->dst_maxburst;
209+
else if (dwc->direction == DMA_DEV_TO_MEM)
210+
smsize = sconfig->src_maxburst;
207211

208212
return DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN |
209213
DWC_CTLL_DST_MSIZE(dmsize) | DWC_CTLL_SRC_MSIZE(smsize);

0 commit comments

Comments
 (0)