Skip to content

Commit 4b33472

Browse files
author
AngeloGioacchino Del Regno
committed
soc: mediatek: mtk-cmdq: Move mask build and append to function
Move the CMDQ_CODE_MASK packet build and append logic to a new cmdq_pkt_mask() function; this reduces code duplication by 4x. Reviewed-by: Matthias Brugger <[email protected]> Signed-off-by: AngeloGioacchino Del Regno <[email protected]>
1 parent 192514a commit 4b33472

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

drivers/soc/mediatek/mtk-cmdq-helper.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt,
180180
return 0;
181181
}
182182

183+
static int cmdq_pkt_mask(struct cmdq_pkt *pkt, u32 mask)
184+
{
185+
struct cmdq_instruction inst = {
186+
.op = CMDQ_CODE_MASK,
187+
.mask = ~mask
188+
};
189+
return cmdq_pkt_append_command(pkt, inst);
190+
}
191+
183192
int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value)
184193
{
185194
struct cmdq_instruction inst;
@@ -196,14 +205,11 @@ EXPORT_SYMBOL(cmdq_pkt_write);
196205
int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
197206
u16 offset, u32 value, u32 mask)
198207
{
199-
struct cmdq_instruction inst = { {0} };
200208
u16 offset_mask = offset;
201209
int err;
202210

203211
if (mask != 0xffffffff) {
204-
inst.op = CMDQ_CODE_MASK;
205-
inst.mask = ~mask;
206-
err = cmdq_pkt_append_command(pkt, inst);
212+
err = cmdq_pkt_mask(pkt, mask);
207213
if (err < 0)
208214
return err;
209215

@@ -251,9 +257,7 @@ int cmdq_pkt_write_s_mask(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
251257
struct cmdq_instruction inst = {};
252258
int err;
253259

254-
inst.op = CMDQ_CODE_MASK;
255-
inst.mask = ~mask;
256-
err = cmdq_pkt_append_command(pkt, inst);
260+
err = cmdq_pkt_mask(pkt, mask);
257261
if (err < 0)
258262
return err;
259263

@@ -288,9 +292,7 @@ int cmdq_pkt_write_s_mask_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
288292
struct cmdq_instruction inst = {};
289293
int err;
290294

291-
inst.op = CMDQ_CODE_MASK;
292-
inst.mask = ~mask;
293-
err = cmdq_pkt_append_command(pkt, inst);
295+
err = cmdq_pkt_mask(pkt, mask);
294296
if (err < 0)
295297
return err;
296298

@@ -409,12 +411,9 @@ EXPORT_SYMBOL(cmdq_pkt_poll);
409411
int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
410412
u16 offset, u32 value, u32 mask)
411413
{
412-
struct cmdq_instruction inst = { {0} };
413414
int err;
414415

415-
inst.op = CMDQ_CODE_MASK;
416-
inst.mask = ~mask;
417-
err = cmdq_pkt_append_command(pkt, inst);
416+
err = cmdq_pkt_mask(pkt, mask);
418417
if (err < 0)
419418
return err;
420419

@@ -436,9 +435,7 @@ int cmdq_pkt_poll_addr(struct cmdq_pkt *pkt, dma_addr_t addr, u32 value, u32 mas
436435
* which enables use_mask bit.
437436
*/
438437
if (mask != GENMASK(31, 0)) {
439-
inst.op = CMDQ_CODE_MASK;
440-
inst.mask = ~mask;
441-
ret = cmdq_pkt_append_command(pkt, inst);
438+
ret = cmdq_pkt_mask(pkt, mask);
442439
if (ret < 0)
443440
return ret;
444441
use_mask = CMDQ_POLL_ENABLE_MASK;

0 commit comments

Comments
 (0)