Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dmaengine: stm32-dma: use bitfield helpers

Use the FIELD_{GET,PREP}() helpers, instead of defining custom macros
implementing the same operations.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Link: https://lore.kernel.org/r/20220829154646.29867-3-amelie.delaunay@foss.st.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Amelie Delaunay and committed by
Vinod Koul
1c32d6c3 4dc36a53

+25 -35
+25 -35
drivers/dma/stm32-dma.c
··· 9 9 * Pierre-Yves Mordret <pierre-yves.mordret@st.com> 10 10 */ 11 11 12 + #include <linux/bitfield.h> 12 13 #include <linux/clk.h> 13 14 #include <linux/delay.h> 14 15 #include <linux/dmaengine.h> ··· 55 54 56 55 /* DMA Stream x Configuration Register */ 57 56 #define STM32_DMA_SCR(x) (0x0010 + 0x18 * (x)) /* x = 0..7 */ 58 - #define STM32_DMA_SCR_REQ(n) ((n & 0x7) << 25) 57 + #define STM32_DMA_SCR_REQ_MASK GENMASK(27, 25) 59 58 #define STM32_DMA_SCR_MBURST_MASK GENMASK(24, 23) 60 - #define STM32_DMA_SCR_MBURST(n) ((n & 0x3) << 23) 61 59 #define STM32_DMA_SCR_PBURST_MASK GENMASK(22, 21) 62 - #define STM32_DMA_SCR_PBURST(n) ((n & 0x3) << 21) 63 60 #define STM32_DMA_SCR_PL_MASK GENMASK(17, 16) 64 - #define STM32_DMA_SCR_PL(n) ((n & 0x3) << 16) 65 61 #define STM32_DMA_SCR_MSIZE_MASK GENMASK(14, 13) 66 - #define STM32_DMA_SCR_MSIZE(n) ((n & 0x3) << 13) 67 62 #define STM32_DMA_SCR_PSIZE_MASK GENMASK(12, 11) 68 - #define STM32_DMA_SCR_PSIZE(n) ((n & 0x3) << 11) 69 - #define STM32_DMA_SCR_PSIZE_GET(n) ((n & STM32_DMA_SCR_PSIZE_MASK) >> 11) 70 63 #define STM32_DMA_SCR_DIR_MASK GENMASK(7, 6) 71 - #define STM32_DMA_SCR_DIR(n) ((n & 0x3) << 6) 72 64 #define STM32_DMA_SCR_TRBUFF BIT(20) /* Bufferable transfer for USART/UART */ 73 65 #define STM32_DMA_SCR_CT BIT(19) /* Target in double buffer */ 74 66 #define STM32_DMA_SCR_DBM BIT(18) /* Double Buffer Mode */ ··· 98 104 /* DMA stream x FIFO control register */ 99 105 #define STM32_DMA_SFCR(x) (0x0024 + 0x18 * (x)) 100 106 #define STM32_DMA_SFCR_FTH_MASK GENMASK(1, 0) 101 - #define STM32_DMA_SFCR_FTH(n) (n & STM32_DMA_SFCR_FTH_MASK) 102 107 #define STM32_DMA_SFCR_FEIE BIT(7) /* FIFO error interrupt enable */ 103 108 #define STM32_DMA_SFCR_DMDIS BIT(2) /* Direct mode disable */ 104 109 #define STM32_DMA_SFCR_MASK (STM32_DMA_SFCR_FEIE \ ··· 138 145 139 146 /* DMA Features */ 140 147 #define STM32_DMA_THRESHOLD_FTR_MASK GENMASK(1, 0) 141 - #define STM32_DMA_THRESHOLD_FTR_GET(n) ((n) & STM32_DMA_THRESHOLD_FTR_MASK) 142 148 #define STM32_DMA_DIRECT_MODE_MASK BIT(2) 143 - #define STM32_DMA_DIRECT_MODE_GET(n) (((n) & STM32_DMA_DIRECT_MODE_MASK) >> 2) 144 149 #define STM32_DMA_ALT_ACK_MODE_MASK BIT(4) 145 - #define STM32_DMA_ALT_ACK_MODE_GET(n) (((n) & STM32_DMA_ALT_ACK_MODE_MASK) >> 4) 146 150 147 151 enum stm32_dma_width { 148 152 STM32_DMA_BYTE, ··· 846 856 sg_req = &chan->desc->sg_req[chan->next_sg - 1]; 847 857 848 858 ndtr = sg_req->chan_reg.dma_sndtr; 849 - offset = (ndtr - chan_reg.dma_sndtr) << STM32_DMA_SCR_PSIZE_GET(chan_reg.dma_scr); 859 + offset = (ndtr - chan_reg.dma_sndtr); 860 + offset <<= FIELD_GET(STM32_DMA_SCR_PSIZE_MASK, chan_reg.dma_scr); 850 861 spar = sg_req->chan_reg.dma_spar; 851 862 sm0ar = sg_req->chan_reg.dma_sm0ar; 852 863 sm1ar = sg_req->chan_reg.dma_sm1ar; ··· 959 968 if (src_burst_size < 0) 960 969 return src_burst_size; 961 970 962 - dma_scr = STM32_DMA_SCR_DIR(STM32_DMA_MEM_TO_DEV) | 963 - STM32_DMA_SCR_PSIZE(dst_bus_width) | 964 - STM32_DMA_SCR_MSIZE(src_bus_width) | 965 - STM32_DMA_SCR_PBURST(dst_burst_size) | 966 - STM32_DMA_SCR_MBURST(src_burst_size); 971 + dma_scr = FIELD_PREP(STM32_DMA_SCR_DIR_MASK, STM32_DMA_MEM_TO_DEV) | 972 + FIELD_PREP(STM32_DMA_SCR_PSIZE_MASK, dst_bus_width) | 973 + FIELD_PREP(STM32_DMA_SCR_MSIZE_MASK, src_bus_width) | 974 + FIELD_PREP(STM32_DMA_SCR_PBURST_MASK, dst_burst_size) | 975 + FIELD_PREP(STM32_DMA_SCR_MBURST_MASK, src_burst_size); 967 976 968 977 /* Set FIFO threshold */ 969 978 chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK; 970 979 if (fifoth != STM32_DMA_FIFO_THRESHOLD_NONE) 971 - chan->chan_reg.dma_sfcr |= STM32_DMA_SFCR_FTH(fifoth); 980 + chan->chan_reg.dma_sfcr |= FIELD_PREP(STM32_DMA_SFCR_FTH_MASK, fifoth); 972 981 973 982 /* Set peripheral address */ 974 983 chan->chan_reg.dma_spar = chan->dma_sconfig.dst_addr; ··· 1016 1025 if (dst_burst_size < 0) 1017 1026 return dst_burst_size; 1018 1027 1019 - dma_scr = STM32_DMA_SCR_DIR(STM32_DMA_DEV_TO_MEM) | 1020 - STM32_DMA_SCR_PSIZE(src_bus_width) | 1021 - STM32_DMA_SCR_MSIZE(dst_bus_width) | 1022 - STM32_DMA_SCR_PBURST(src_burst_size) | 1023 - STM32_DMA_SCR_MBURST(dst_burst_size); 1028 + dma_scr = FIELD_PREP(STM32_DMA_SCR_DIR_MASK, STM32_DMA_DEV_TO_MEM) | 1029 + FIELD_PREP(STM32_DMA_SCR_PSIZE_MASK, src_bus_width) | 1030 + FIELD_PREP(STM32_DMA_SCR_MSIZE_MASK, dst_bus_width) | 1031 + FIELD_PREP(STM32_DMA_SCR_PBURST_MASK, src_burst_size) | 1032 + FIELD_PREP(STM32_DMA_SCR_MBURST_MASK, dst_burst_size); 1024 1033 1025 1034 /* Set FIFO threshold */ 1026 1035 chan->chan_reg.dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK; 1027 1036 if (fifoth != STM32_DMA_FIFO_THRESHOLD_NONE) 1028 - chan->chan_reg.dma_sfcr |= STM32_DMA_SFCR_FTH(fifoth); 1037 + chan->chan_reg.dma_sfcr |= FIELD_PREP(STM32_DMA_SFCR_FTH_MASK, fifoth); 1029 1038 1030 1039 /* Set peripheral address */ 1031 1040 chan->chan_reg.dma_spar = chan->dma_sconfig.src_addr; ··· 1233 1242 1234 1243 stm32_dma_clear_reg(&desc->sg_req[i].chan_reg); 1235 1244 desc->sg_req[i].chan_reg.dma_scr = 1236 - STM32_DMA_SCR_DIR(STM32_DMA_MEM_TO_MEM) | 1237 - STM32_DMA_SCR_PBURST(dma_burst) | 1238 - STM32_DMA_SCR_MBURST(dma_burst) | 1245 + FIELD_PREP(STM32_DMA_SCR_DIR_MASK, STM32_DMA_MEM_TO_MEM) | 1246 + FIELD_PREP(STM32_DMA_SCR_PBURST_MASK, dma_burst) | 1247 + FIELD_PREP(STM32_DMA_SCR_MBURST_MASK, dma_burst) | 1239 1248 STM32_DMA_SCR_MINC | 1240 1249 STM32_DMA_SCR_PINC | 1241 1250 STM32_DMA_SCR_TCIE | 1242 1251 STM32_DMA_SCR_TEIE; 1243 1252 desc->sg_req[i].chan_reg.dma_sfcr |= STM32_DMA_SFCR_MASK; 1244 - desc->sg_req[i].chan_reg.dma_sfcr |= 1245 - STM32_DMA_SFCR_FTH(threshold); 1253 + desc->sg_req[i].chan_reg.dma_sfcr |= FIELD_PREP(STM32_DMA_SFCR_FTH_MASK, threshold); 1246 1254 desc->sg_req[i].chan_reg.dma_spar = src + offset; 1247 1255 desc->sg_req[i].chan_reg.dma_sm0ar = dest + offset; 1248 1256 desc->sg_req[i].chan_reg.dma_sndtr = xfer_count; ··· 1260 1270 struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan); 1261 1271 1262 1272 dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id)); 1263 - width = STM32_DMA_SCR_PSIZE_GET(dma_scr); 1273 + width = FIELD_GET(STM32_DMA_SCR_PSIZE_MASK, dma_scr); 1264 1274 ndtr = stm32_dma_read(dmadev, STM32_DMA_SNDTR(chan->id)); 1265 1275 1266 1276 return ndtr << width; ··· 1466 1476 stm32_dma_clear_reg(&chan->chan_reg); 1467 1477 1468 1478 chan->chan_reg.dma_scr = cfg->stream_config & STM32_DMA_SCR_CFG_MASK; 1469 - chan->chan_reg.dma_scr |= STM32_DMA_SCR_REQ(cfg->request_line); 1479 + chan->chan_reg.dma_scr |= FIELD_PREP(STM32_DMA_SCR_REQ_MASK, cfg->request_line); 1470 1480 1471 1481 /* Enable Interrupts */ 1472 1482 chan->chan_reg.dma_scr |= STM32_DMA_SCR_TEIE | STM32_DMA_SCR_TCIE; 1473 1483 1474 - chan->threshold = STM32_DMA_THRESHOLD_FTR_GET(cfg->features); 1475 - if (STM32_DMA_DIRECT_MODE_GET(cfg->features)) 1484 + chan->threshold = FIELD_GET(STM32_DMA_THRESHOLD_FTR_MASK, cfg->features); 1485 + if (FIELD_GET(STM32_DMA_DIRECT_MODE_MASK, cfg->features)) 1476 1486 chan->threshold = STM32_DMA_FIFO_THRESHOLD_NONE; 1477 - if (STM32_DMA_ALT_ACK_MODE_GET(cfg->features)) 1487 + if (FIELD_GET(STM32_DMA_ALT_ACK_MODE_MASK, cfg->features)) 1478 1488 chan->chan_reg.dma_scr |= STM32_DMA_SCR_TRBUFF; 1479 1489 } 1480 1490