|
10 | 10 | * Inspired by stm32-dma.c and dma-jz4780.c
|
11 | 11 | */
|
12 | 12 |
|
| 13 | +#include <linux/bitfield.h> |
13 | 14 | #include <linux/clk.h>
|
14 | 15 | #include <linux/delay.h>
|
15 | 16 | #include <linux/dmaengine.h>
|
|
32 | 33 |
|
33 | 34 | #include "virt-dma.h"
|
34 | 35 |
|
35 |
| -/* MDMA Generic getter/setter */ |
36 |
| -#define STM32_MDMA_SHIFT(n) (ffs(n) - 1) |
37 |
| -#define STM32_MDMA_SET(n, mask) (((n) << STM32_MDMA_SHIFT(mask)) & \ |
38 |
| - (mask)) |
39 |
| -#define STM32_MDMA_GET(n, mask) (((n) & (mask)) >> \ |
40 |
| - STM32_MDMA_SHIFT(mask)) |
41 |
| - |
42 | 36 | #define STM32_MDMA_GISR0 0x0000 /* MDMA Int Status Reg 1 */
|
43 | 37 | #define STM32_MDMA_GISR1 0x0004 /* MDMA Int Status Reg 2 */
|
44 | 38 |
|
|
80 | 74 | #define STM32_MDMA_CCR_HEX BIT(13)
|
81 | 75 | #define STM32_MDMA_CCR_BEX BIT(12)
|
82 | 76 | #define STM32_MDMA_CCR_PL_MASK GENMASK(7, 6)
|
83 |
| -#define STM32_MDMA_CCR_PL(n) STM32_MDMA_SET(n, \ |
84 |
| - STM32_MDMA_CCR_PL_MASK) |
| 77 | +#define STM32_MDMA_CCR_PL(n) FIELD_PREP(STM32_MDMA_CCR_PL_MASK, (n)) |
85 | 78 | #define STM32_MDMA_CCR_TCIE BIT(5)
|
86 | 79 | #define STM32_MDMA_CCR_BTIE BIT(4)
|
87 | 80 | #define STM32_MDMA_CCR_BRTIE BIT(3)
|
|
99 | 92 | #define STM32_MDMA_CTCR_BWM BIT(31)
|
100 | 93 | #define STM32_MDMA_CTCR_SWRM BIT(30)
|
101 | 94 | #define STM32_MDMA_CTCR_TRGM_MSK GENMASK(29, 28)
|
102 |
| -#define STM32_MDMA_CTCR_TRGM(n) STM32_MDMA_SET((n), \ |
103 |
| - STM32_MDMA_CTCR_TRGM_MSK) |
104 |
| -#define STM32_MDMA_CTCR_TRGM_GET(n) STM32_MDMA_GET((n), \ |
105 |
| - STM32_MDMA_CTCR_TRGM_MSK) |
| 95 | +#define STM32_MDMA_CTCR_TRGM(n) FIELD_PREP(STM32_MDMA_CTCR_TRGM_MSK, (n)) |
| 96 | +#define STM32_MDMA_CTCR_TRGM_GET(n) FIELD_GET(STM32_MDMA_CTCR_TRGM_MSK, (n)) |
106 | 97 | #define STM32_MDMA_CTCR_PAM_MASK GENMASK(27, 26)
|
107 |
| -#define STM32_MDMA_CTCR_PAM(n) STM32_MDMA_SET(n, \ |
108 |
| - STM32_MDMA_CTCR_PAM_MASK) |
| 98 | +#define STM32_MDMA_CTCR_PAM(n) FIELD_PREP(STM32_MDMA_CTCR_PAM_MASK, (n)) |
109 | 99 | #define STM32_MDMA_CTCR_PKE BIT(25)
|
110 | 100 | #define STM32_MDMA_CTCR_TLEN_MSK GENMASK(24, 18)
|
111 |
| -#define STM32_MDMA_CTCR_TLEN(n) STM32_MDMA_SET((n), \ |
112 |
| - STM32_MDMA_CTCR_TLEN_MSK) |
113 |
| -#define STM32_MDMA_CTCR_TLEN_GET(n) STM32_MDMA_GET((n), \ |
114 |
| - STM32_MDMA_CTCR_TLEN_MSK) |
| 101 | +#define STM32_MDMA_CTCR_TLEN(n) FIELD_PREP(STM32_MDMA_CTCR_TLEN_MSK, (n)) |
| 102 | +#define STM32_MDMA_CTCR_TLEN_GET(n) FIELD_GET(STM32_MDMA_CTCR_TLEN_MSK, (n)) |
115 | 103 | #define STM32_MDMA_CTCR_LEN2_MSK GENMASK(25, 18)
|
116 |
| -#define STM32_MDMA_CTCR_LEN2(n) STM32_MDMA_SET((n), \ |
117 |
| - STM32_MDMA_CTCR_LEN2_MSK) |
118 |
| -#define STM32_MDMA_CTCR_LEN2_GET(n) STM32_MDMA_GET((n), \ |
119 |
| - STM32_MDMA_CTCR_LEN2_MSK) |
| 104 | +#define STM32_MDMA_CTCR_LEN2(n) FIELD_PREP(STM32_MDMA_CTCR_LEN2_MSK, (n)) |
| 105 | +#define STM32_MDMA_CTCR_LEN2_GET(n) FIELD_GET(STM32_MDMA_CTCR_LEN2_MSK, (n)) |
120 | 106 | #define STM32_MDMA_CTCR_DBURST_MASK GENMASK(17, 15)
|
121 |
| -#define STM32_MDMA_CTCR_DBURST(n) STM32_MDMA_SET(n, \ |
122 |
| - STM32_MDMA_CTCR_DBURST_MASK) |
| 107 | +#define STM32_MDMA_CTCR_DBURST(n) FIELD_PREP(STM32_MDMA_CTCR_DBURST_MASK, (n)) |
123 | 108 | #define STM32_MDMA_CTCR_SBURST_MASK GENMASK(14, 12)
|
124 |
| -#define STM32_MDMA_CTCR_SBURST(n) STM32_MDMA_SET(n, \ |
125 |
| - STM32_MDMA_CTCR_SBURST_MASK) |
| 109 | +#define STM32_MDMA_CTCR_SBURST(n) FIELD_PREP(STM32_MDMA_CTCR_SBURST_MASK, (n)) |
126 | 110 | #define STM32_MDMA_CTCR_DINCOS_MASK GENMASK(11, 10)
|
127 |
| -#define STM32_MDMA_CTCR_DINCOS(n) STM32_MDMA_SET((n), \ |
128 |
| - STM32_MDMA_CTCR_DINCOS_MASK) |
| 111 | +#define STM32_MDMA_CTCR_DINCOS(n) FIELD_PREP(STM32_MDMA_CTCR_DINCOS_MASK, (n)) |
129 | 112 | #define STM32_MDMA_CTCR_SINCOS_MASK GENMASK(9, 8)
|
130 |
| -#define STM32_MDMA_CTCR_SINCOS(n) STM32_MDMA_SET((n), \ |
131 |
| - STM32_MDMA_CTCR_SINCOS_MASK) |
| 113 | +#define STM32_MDMA_CTCR_SINCOS(n) FIELD_PREP(STM32_MDMA_CTCR_SINCOS_MASK, (n)) |
132 | 114 | #define STM32_MDMA_CTCR_DSIZE_MASK GENMASK(7, 6)
|
133 |
| -#define STM32_MDMA_CTCR_DSIZE(n) STM32_MDMA_SET(n, \ |
134 |
| - STM32_MDMA_CTCR_DSIZE_MASK) |
| 115 | +#define STM32_MDMA_CTCR_DSIZE(n) FIELD_PREP(STM32_MDMA_CTCR_DSIZE_MASK, (n)) |
135 | 116 | #define STM32_MDMA_CTCR_SSIZE_MASK GENMASK(5, 4)
|
136 |
| -#define STM32_MDMA_CTCR_SSIZE(n) STM32_MDMA_SET(n, \ |
137 |
| - STM32_MDMA_CTCR_SSIZE_MASK) |
| 117 | +#define STM32_MDMA_CTCR_SSIZE(n) FIELD_PREP(STM32_MDMA_CTCR_SSIZE_MASK, (n)) |
138 | 118 | #define STM32_MDMA_CTCR_DINC_MASK GENMASK(3, 2)
|
139 |
| -#define STM32_MDMA_CTCR_DINC(n) STM32_MDMA_SET((n), \ |
140 |
| - STM32_MDMA_CTCR_DINC_MASK) |
| 119 | +#define STM32_MDMA_CTCR_DINC(n) FIELD_PREP(STM32_MDMA_CTCR_DINC_MASK, (n)) |
141 | 120 | #define STM32_MDMA_CTCR_SINC_MASK GENMASK(1, 0)
|
142 |
| -#define STM32_MDMA_CTCR_SINC(n) STM32_MDMA_SET((n), \ |
143 |
| - STM32_MDMA_CTCR_SINC_MASK) |
| 121 | +#define STM32_MDMA_CTCR_SINC(n) FIELD_PREP(STM32_MDMA_CTCR_SINC_MASK, (n)) |
144 | 122 | #define STM32_MDMA_CTCR_CFG_MASK (STM32_MDMA_CTCR_SINC_MASK \
|
145 | 123 | | STM32_MDMA_CTCR_DINC_MASK \
|
146 | 124 | | STM32_MDMA_CTCR_SINCOS_MASK \
|
|
151 | 129 | /* MDMA Channel x block number of data register */
|
152 | 130 | #define STM32_MDMA_CBNDTR(x) (0x54 + 0x40 * (x))
|
153 | 131 | #define STM32_MDMA_CBNDTR_BRC_MK GENMASK(31, 20)
|
154 |
| -#define STM32_MDMA_CBNDTR_BRC(n) STM32_MDMA_SET(n, \ |
155 |
| - STM32_MDMA_CBNDTR_BRC_MK) |
156 |
| -#define STM32_MDMA_CBNDTR_BRC_GET(n) STM32_MDMA_GET((n), \ |
157 |
| - STM32_MDMA_CBNDTR_BRC_MK) |
| 132 | +#define STM32_MDMA_CBNDTR_BRC(n) FIELD_PREP(STM32_MDMA_CBNDTR_BRC_MK, (n)) |
| 133 | +#define STM32_MDMA_CBNDTR_BRC_GET(n) FIELD_GET(STM32_MDMA_CBNDTR_BRC_MK, (n)) |
158 | 134 |
|
159 | 135 | #define STM32_MDMA_CBNDTR_BRDUM BIT(19)
|
160 | 136 | #define STM32_MDMA_CBNDTR_BRSUM BIT(18)
|
161 | 137 | #define STM32_MDMA_CBNDTR_BNDT_MASK GENMASK(16, 0)
|
162 |
| -#define STM32_MDMA_CBNDTR_BNDT(n) STM32_MDMA_SET(n, \ |
163 |
| - STM32_MDMA_CBNDTR_BNDT_MASK) |
| 138 | +#define STM32_MDMA_CBNDTR_BNDT(n) FIELD_PREP(STM32_MDMA_CBNDTR_BNDT_MASK, (n)) |
164 | 139 |
|
165 | 140 | /* MDMA Channel x source address register */
|
166 | 141 | #define STM32_MDMA_CSAR(x) (0x58 + 0x40 * (x))
|
|
171 | 146 | /* MDMA Channel x block repeat address update register */
|
172 | 147 | #define STM32_MDMA_CBRUR(x) (0x60 + 0x40 * (x))
|
173 | 148 | #define STM32_MDMA_CBRUR_DUV_MASK GENMASK(31, 16)
|
174 |
| -#define STM32_MDMA_CBRUR_DUV(n) STM32_MDMA_SET(n, \ |
175 |
| - STM32_MDMA_CBRUR_DUV_MASK) |
| 149 | +#define STM32_MDMA_CBRUR_DUV(n) FIELD_PREP(STM32_MDMA_CBRUR_DUV_MASK, (n)) |
176 | 150 | #define STM32_MDMA_CBRUR_SUV_MASK GENMASK(15, 0)
|
177 |
| -#define STM32_MDMA_CBRUR_SUV(n) STM32_MDMA_SET(n, \ |
178 |
| - STM32_MDMA_CBRUR_SUV_MASK) |
| 151 | +#define STM32_MDMA_CBRUR_SUV(n) FIELD_PREP(STM32_MDMA_CBRUR_SUV_MASK, (n)) |
179 | 152 |
|
180 | 153 | /* MDMA Channel x link address register */
|
181 | 154 | #define STM32_MDMA_CLAR(x) (0x64 + 0x40 * (x))
|
|
185 | 158 | #define STM32_MDMA_CTBR_DBUS BIT(17)
|
186 | 159 | #define STM32_MDMA_CTBR_SBUS BIT(16)
|
187 | 160 | #define STM32_MDMA_CTBR_TSEL_MASK GENMASK(7, 0)
|
188 |
| -#define STM32_MDMA_CTBR_TSEL(n) STM32_MDMA_SET(n, \ |
189 |
| - STM32_MDMA_CTBR_TSEL_MASK) |
| 161 | +#define STM32_MDMA_CTBR_TSEL(n) FIELD_PREP(STM32_MDMA_CTBR_TSEL_MASK, (n)) |
190 | 162 |
|
191 | 163 | /* MDMA Channel x mask address register */
|
192 | 164 | #define STM32_MDMA_CMAR(x) (0x70 + 0x40 * (x))
|
|
0 commit comments