Skip to content

Commit 9e6f395

Browse files
jbrun3tbroonie
authored andcommitted
ASoC: meson: axg-fifo: use FIELD helpers
Use FIELD_GET() and FIELD_PREP() helpers instead of doing it manually. Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> Link: https://msgid.link/r/20240227150826.573581-1-jbrunet@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent cb9d8a2 commit 9e6f395

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

sound/soc/meson/axg-fifo.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Copyright (c) 2018 BayLibre, SAS.
44
// Author: Jerome Brunet <jbrunet@baylibre.com>
55

6+
#include <linux/bitfield.h>
67
#include <linux/clk.h>
78
#include <linux/of_irq.h>
89
#include <linux/of_platform.h>
@@ -145,8 +146,8 @@ int axg_fifo_pcm_hw_params(struct snd_soc_component *component,
145146
/* Enable irq if necessary */
146147
irq_en = runtime->no_period_wakeup ? 0 : FIFO_INT_COUNT_REPEAT;
147148
regmap_update_bits(fifo->map, FIFO_CTRL0,
148-
CTRL0_INT_EN(FIFO_INT_COUNT_REPEAT),
149-
CTRL0_INT_EN(irq_en));
149+
CTRL0_INT_EN,
150+
FIELD_PREP(CTRL0_INT_EN, irq_en));
150151

151152
return 0;
152153
}
@@ -176,9 +177,9 @@ int axg_fifo_pcm_hw_free(struct snd_soc_component *component,
176177
{
177178
struct axg_fifo *fifo = axg_fifo_data(ss);
178179

179-
/* Disable the block count irq */
180+
/* Disable irqs */
180181
regmap_update_bits(fifo->map, FIFO_CTRL0,
181-
CTRL0_INT_EN(FIFO_INT_COUNT_REPEAT), 0);
182+
CTRL0_INT_EN, 0);
182183

183184
return 0;
184185
}
@@ -187,13 +188,13 @@ EXPORT_SYMBOL_GPL(axg_fifo_pcm_hw_free);
187188
static void axg_fifo_ack_irq(struct axg_fifo *fifo, u8 mask)
188189
{
189190
regmap_update_bits(fifo->map, FIFO_CTRL1,
190-
CTRL1_INT_CLR(FIFO_INT_MASK),
191-
CTRL1_INT_CLR(mask));
191+
CTRL1_INT_CLR,
192+
FIELD_PREP(CTRL1_INT_CLR, mask));
192193

193194
/* Clear must also be cleared */
194195
regmap_update_bits(fifo->map, FIFO_CTRL1,
195-
CTRL1_INT_CLR(FIFO_INT_MASK),
196-
0);
196+
CTRL1_INT_CLR,
197+
FIELD_PREP(CTRL1_INT_CLR, 0));
197198
}
198199

199200
static irqreturn_t axg_fifo_pcm_irq_block(int irq, void *dev_id)
@@ -204,7 +205,7 @@ static irqreturn_t axg_fifo_pcm_irq_block(int irq, void *dev_id)
204205

205206
regmap_read(fifo->map, FIFO_STATUS1, &status);
206207

207-
status = STATUS1_INT_STS(status) & FIFO_INT_MASK;
208+
status = FIELD_GET(STATUS1_INT_STS, status);
208209
if (status & FIFO_INT_COUNT_REPEAT)
209210
snd_pcm_period_elapsed(ss);
210211
else
@@ -254,15 +255,15 @@ int axg_fifo_pcm_open(struct snd_soc_component *component,
254255

255256
/* Setup status2 so it reports the memory pointer */
256257
regmap_update_bits(fifo->map, FIFO_CTRL1,
257-
CTRL1_STATUS2_SEL_MASK,
258-
CTRL1_STATUS2_SEL(STATUS2_SEL_DDR_READ));
258+
CTRL1_STATUS2_SEL,
259+
FIELD_PREP(CTRL1_STATUS2_SEL, STATUS2_SEL_DDR_READ));
259260

260261
/* Make sure the dma is initially disabled */
261262
__dma_enable(fifo, false);
262263

263264
/* Disable irqs until params are ready */
264265
regmap_update_bits(fifo->map, FIFO_CTRL0,
265-
CTRL0_INT_EN(FIFO_INT_MASK), 0);
266+
CTRL0_INT_EN, 0);
266267

267268
/* Clear any pending interrupt */
268269
axg_fifo_ack_irq(fifo, FIFO_INT_MASK);

sound/soc/meson/axg-fifo.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,19 @@ struct snd_soc_pcm_runtime;
4040

4141
#define FIFO_CTRL0 0x00
4242
#define CTRL0_DMA_EN BIT(31)
43-
#define CTRL0_INT_EN(x) ((x) << 16)
43+
#define CTRL0_INT_EN GENMASK(23, 16)
4444
#define CTRL0_SEL_MASK GENMASK(2, 0)
4545
#define CTRL0_SEL_SHIFT 0
4646
#define FIFO_CTRL1 0x04
47-
#define CTRL1_INT_CLR(x) ((x) << 0)
48-
#define CTRL1_STATUS2_SEL_MASK GENMASK(11, 8)
49-
#define CTRL1_STATUS2_SEL(x) ((x) << 8)
47+
#define CTRL1_INT_CLR GENMASK(7, 0)
48+
#define CTRL1_STATUS2_SEL GENMASK(11, 8)
5049
#define STATUS2_SEL_DDR_READ 0
51-
#define CTRL1_FRDDR_DEPTH_MASK GENMASK(31, 24)
52-
#define CTRL1_FRDDR_DEPTH(x) ((x) << 24)
50+
#define CTRL1_FRDDR_DEPTH GENMASK(31, 24)
5351
#define FIFO_START_ADDR 0x08
5452
#define FIFO_FINISH_ADDR 0x0c
5553
#define FIFO_INT_ADDR 0x10
5654
#define FIFO_STATUS1 0x14
57-
#define STATUS1_INT_STS(x) ((x) << 0)
55+
#define STATUS1_INT_STS GENMASK(7, 0)
5856
#define FIFO_STATUS2 0x18
5957
#define FIFO_INIT_ADDR 0x24
6058
#define FIFO_CTRL2 0x28

sound/soc/meson/axg-frddr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* This driver implements the frontend playback DAI of AXG and G12A based SoCs
88
*/
99

10+
#include <linux/bitfield.h>
1011
#include <linux/clk.h>
1112
#include <linux/regmap.h>
1213
#include <linux/module.h>
@@ -59,8 +60,8 @@ static int axg_frddr_dai_hw_params(struct snd_pcm_substream *substream,
5960
/* Trim the FIFO depth if the period is small to improve latency */
6061
depth = min(period, fifo->depth);
6162
val = (depth / AXG_FIFO_BURST) - 1;
62-
regmap_update_bits(fifo->map, FIFO_CTRL1, CTRL1_FRDDR_DEPTH_MASK,
63-
CTRL1_FRDDR_DEPTH(val));
63+
regmap_update_bits(fifo->map, FIFO_CTRL1, CTRL1_FRDDR_DEPTH,
64+
FIELD_PREP(CTRL1_FRDDR_DEPTH, val));
6465

6566
return 0;
6667
}

sound/soc/meson/axg-toddr.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/* This driver implements the frontend capture DAI of AXG based SoCs */
77

8+
#include <linux/bitfield.h>
89
#include <linux/clk.h>
910
#include <linux/regmap.h>
1011
#include <linux/module.h>
@@ -19,12 +20,9 @@
1920
#define CTRL0_TODDR_EXT_SIGNED BIT(29)
2021
#define CTRL0_TODDR_PP_MODE BIT(28)
2122
#define CTRL0_TODDR_SYNC_CH BIT(27)
22-
#define CTRL0_TODDR_TYPE_MASK GENMASK(15, 13)
23-
#define CTRL0_TODDR_TYPE(x) ((x) << 13)
24-
#define CTRL0_TODDR_MSB_POS_MASK GENMASK(12, 8)
25-
#define CTRL0_TODDR_MSB_POS(x) ((x) << 8)
26-
#define CTRL0_TODDR_LSB_POS_MASK GENMASK(7, 3)
27-
#define CTRL0_TODDR_LSB_POS(x) ((x) << 3)
23+
#define CTRL0_TODDR_TYPE GENMASK(15, 13)
24+
#define CTRL0_TODDR_MSB_POS GENMASK(12, 8)
25+
#define CTRL0_TODDR_LSB_POS GENMASK(7, 3)
2826
#define CTRL1_TODDR_FORCE_FINISH BIT(25)
2927
#define CTRL1_SEL_SHIFT 28
3028

@@ -76,12 +74,12 @@ static int axg_toddr_dai_hw_params(struct snd_pcm_substream *substream,
7674
width = params_width(params);
7775

7876
regmap_update_bits(fifo->map, FIFO_CTRL0,
79-
CTRL0_TODDR_TYPE_MASK |
80-
CTRL0_TODDR_MSB_POS_MASK |
81-
CTRL0_TODDR_LSB_POS_MASK,
82-
CTRL0_TODDR_TYPE(type) |
83-
CTRL0_TODDR_MSB_POS(TODDR_MSB_POS) |
84-
CTRL0_TODDR_LSB_POS(TODDR_MSB_POS - (width - 1)));
77+
CTRL0_TODDR_TYPE |
78+
CTRL0_TODDR_MSB_POS |
79+
CTRL0_TODDR_LSB_POS,
80+
FIELD_PREP(CTRL0_TODDR_TYPE, type) |
81+
FIELD_PREP(CTRL0_TODDR_MSB_POS, TODDR_MSB_POS) |
82+
FIELD_PREP(CTRL0_TODDR_LSB_POS, TODDR_MSB_POS - (width - 1)));
8583

8684
return 0;
8785
}

0 commit comments

Comments
 (0)