Skip to content

Commit 40f74d5

Browse files
saba-kareembroonie
authored andcommitted
ASoC: amd: acp: refactor acp i2s clock generation code
Refactor acp i2s LRCLK,BCLK generation code and move to commnon file. Signed-off-by: Syed Saba Kareem <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 33d120a commit 40f74d5

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

sound/soc/amd/acp/acp-i2s.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,42 @@
2020
#include <sound/soc.h>
2121
#include <sound/soc-dai.h>
2222
#include <linux/dma-mapping.h>
23+
#include <linux/bitfield.h>
2324

2425
#include "amd.h"
2526

2627
#define DRV_NAME "acp_i2s_playcap"
28+
#define I2S_MASTER_MODE_ENABLE 1
29+
#define I2S_MODE_ENABLE 0
30+
#define I2S_FORMAT_MODE GENMASK(1, 1)
31+
#define LRCLK_DIV_FIELD GENMASK(10, 2)
32+
#define BCLK_DIV_FIELD GENMASK(23, 11)
33+
34+
static inline void acp_set_i2s_clk(struct acp_dev_data *adata, int dai_id)
35+
{
36+
u32 i2s_clk_reg, val;
37+
38+
switch (dai_id) {
39+
case I2S_SP_INSTANCE:
40+
i2s_clk_reg = ACP_I2STDM0_MSTRCLKGEN;
41+
break;
42+
case I2S_BT_INSTANCE:
43+
i2s_clk_reg = ACP_I2STDM1_MSTRCLKGEN;
44+
break;
45+
case I2S_HS_INSTANCE:
46+
i2s_clk_reg = ACP_I2STDM2_MSTRCLKGEN;
47+
break;
48+
default:
49+
i2s_clk_reg = ACP_I2STDM0_MSTRCLKGEN;
50+
break;
51+
}
52+
53+
val = I2S_MASTER_MODE_ENABLE;
54+
val |= I2S_MODE_ENABLE & BIT(1);
55+
val |= FIELD_PREP(LRCLK_DIV_FIELD, adata->lrclk_div);
56+
val |= FIELD_PREP(BCLK_DIV_FIELD, adata->bclk_div);
57+
writel(val, adata->acp_base + i2s_clk_reg);
58+
}
2759

2860
static int acp_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
2961
unsigned int fmt)

sound/soc/amd/acp/amd.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,6 @@ struct acp_dev_data {
188188
u32 xfer_rx_resolution[3];
189189
};
190190

191-
union acp_i2stdm_mstrclkgen {
192-
struct {
193-
u32 i2stdm_master_mode : 1;
194-
u32 i2stdm_format_mode : 1;
195-
u32 i2stdm_lrclk_div_val : 9;
196-
u32 i2stdm_bclk_div_val : 11;
197-
u32:10;
198-
} bitfields, bits;
199-
u32 u32_all;
200-
};
201-
202191
extern const struct snd_soc_dai_ops asoc_acp_cpu_dai_ops;
203192
extern const struct snd_soc_dai_ops acp_dmic_dai_ops;
204193

@@ -276,32 +265,4 @@ static inline u64 acp_get_byte_count(struct acp_dev_data *adata, int dai_id, int
276265
POINTER_RETURN_BYTES:
277266
return byte_count;
278267
}
279-
280-
static inline void acp_set_i2s_clk(struct acp_dev_data *adata, int dai_id)
281-
{
282-
union acp_i2stdm_mstrclkgen mclkgen;
283-
u32 master_reg;
284-
285-
switch (dai_id) {
286-
case I2S_SP_INSTANCE:
287-
master_reg = ACP_I2STDM0_MSTRCLKGEN;
288-
break;
289-
case I2S_BT_INSTANCE:
290-
master_reg = ACP_I2STDM1_MSTRCLKGEN;
291-
break;
292-
case I2S_HS_INSTANCE:
293-
master_reg = ACP_I2STDM2_MSTRCLKGEN;
294-
break;
295-
default:
296-
master_reg = ACP_I2STDM0_MSTRCLKGEN;
297-
break;
298-
}
299-
300-
mclkgen.bits.i2stdm_master_mode = 0x1;
301-
mclkgen.bits.i2stdm_format_mode = 0x00;
302-
303-
mclkgen.bits.i2stdm_bclk_div_val = adata->bclk_div;
304-
mclkgen.bits.i2stdm_lrclk_div_val = adata->lrclk_div;
305-
writel(mclkgen.u32_all, adata->acp_base + master_reg);
306-
}
307268
#endif

0 commit comments

Comments
 (0)