Skip to content

Commit fc408ab

Browse files
committed
ASoC: don't use array if single pattern
Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> says: Current ASoC supports snd_soc_daifmt_parse_format() which can specify DAI format by "dai-format" property from DT. But strictly speaking, it is SW settings, so doesn't match to DT's policy. Current ASoC is supporting auto format select via snd_soc_dai_ops :: .auto_selectable_formats. But the user is very few today. DT doesn't need to specify the DAI format via "dai-format", if both CPU and Codec drivers were supporting .auto_selectable_formats. It will be automatically selected from .auto_selectable_formats. But, I noticed that current auto format select method can't handle all cases. For example, current .auto_selectable_formats is like below static u64 xxx_auto_formats[] = { (A) /* First Priority */ SND_SOC_POSSIBLE_DAIFMT_I2S | SND_SOC_POSSIBLE_DAIFMT_LEFT_J | SND_SOC_POSSIBLE_DAIFMT_NB_NF | SND_SOC_POSSIBLE_DAIFMT_NB_IF | (x) SND_SOC_POSSIBLE_DAIFMT_IB_NF | SND_SOC_POSSIBLE_DAIFMT_IB_IF, (x) /* Second Priority */ (B) SND_SOC_POSSIBLE_DAIFMT_DSP_A | (y) SND_SOC_POSSIBLE_DAIFMT_DSP_B, (y) }; It try to find DAI format from (A) first, and next it will use (A | B). But it can't handle the format if some format were independent. For example, DSP_x (y) can't use with xB_IF (x), etc. So, I would like to update the method. New method doesn't use OR. It try to find DAI format from (a), next it will use (b). static u64 xxx_auto_formats[] = { (a) /* First Priority */ SND_SOC_POSSIBLE_DAIFMT_I2S | SND_SOC_POSSIBLE_DAIFMT_LEFT_J | SND_SOC_POSSIBLE_DAIFMT_NB_NF | SND_SOC_POSSIBLE_DAIFMT_NB_IF | SND_SOC_POSSIBLE_DAIFMT_IB_NF | SND_SOC_POSSIBLE_DAIFMT_IB_IF, /* Second Priority */ (b) SND_SOC_POSSIBLE_DAIFMT_DSP_A | SND_SOC_POSSIBLE_DAIFMT_DSP_B | SND_SOC_POSSIBLE_DAIFMT_NB_NF | SND_SOC_POSSIBLE_DAIFMT_IB_NF, }; Switch old method to new method, Current auto select user need to update .auto_selectable_formats. Fortunately, current few users doesn't have above limitation. update (A)(B) to (a)(b) style is possible. a = A b = A | B I would like to update method, and add .auto_selectable_formats support on all drivers. One note is that auto select might not find best format on some CPU/Codec combination. So "dai-format" is necessary anyway. And, there haven't been any big problems on .auto_selectable_formats, because there were few users. But if all drivers try to use this, it cannot be denied that they may encounter unknown problems... In such case, "dai-format" can help, though. Link: https://patch.msgid.link/87v7bs36m0.wl-kuninori.morimoto.gx@renesas.com
2 parents 69b4141 + 442cfd5 commit fc408ab

16 files changed

Lines changed: 201 additions & 281 deletions

File tree

include/sound/soc-dai.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ struct clk;
8181
/*
8282
* define GATED -> CONT. GATED will be selected if both are selected.
8383
* see
84-
* snd_soc_runtime_get_dai_fmt()
84+
* soc_dai_convert_possiblefmt_to_daifmt()
8585
*/
8686
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT 16
87-
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_MASK (0xFFFF << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
87+
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_MASK (0xFFFFULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
8888
#define SND_SOC_POSSIBLE_DAIFMT_GATED (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
8989
#define SND_SOC_POSSIBLE_DAIFMT_CONT (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_SHIFT)
9090

@@ -140,14 +140,6 @@ struct clk;
140140
#define SND_SOC_DAIFMT_BP_FC SND_SOC_DAIFMT_CBP_CFC
141141
#define SND_SOC_DAIFMT_BC_FC SND_SOC_DAIFMT_CBC_CFC
142142

143-
/* Describes the possible PCM format */
144-
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT 48
145-
#define SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_MASK (0xFFFFULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
146-
#define SND_SOC_POSSIBLE_DAIFMT_CBP_CFP (0x1ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
147-
#define SND_SOC_POSSIBLE_DAIFMT_CBC_CFP (0x2ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
148-
#define SND_SOC_POSSIBLE_DAIFMT_CBP_CFC (0x4ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
149-
#define SND_SOC_POSSIBLE_DAIFMT_CBC_CFC (0x8ULL << SND_SOC_POSSIBLE_DAIFMT_CLOCK_PROVIDER_SHIFT)
150-
151143
#define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
152144
#define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
153145
#define SND_SOC_DAIFMT_INV_MASK 0x0f00
@@ -192,8 +184,7 @@ int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio);
192184
void snd_soc_dai_set_bclk_clk(struct snd_soc_dai *dai, struct clk *bclk);
193185

194186
/* Digital Audio interface formatting */
195-
int snd_soc_dai_get_fmt_max_priority(const struct snd_soc_pcm_runtime *rtd);
196-
u64 snd_soc_dai_get_fmt(const struct snd_soc_dai *dai, int priority);
187+
unsigned int snd_soc_dai_auto_select_format(const struct snd_soc_pcm_runtime *rtd);
197188
int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt);
198189

199190
int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,

sound/soc/codecs/ak4613.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,6 @@ static int ak4613_dai_trigger(struct snd_pcm_substream *substream, int cmd,
748748
return 0;
749749
}
750750

751-
/*
752-
* Select below from Sound Card, not Auto
753-
* SND_SOC_DAIFMT_CBC_CFC
754-
* SND_SOC_DAIFMT_CBP_CFP
755-
*/
756751
static const u64 ak4613_dai_formats =
757752
SND_SOC_POSSIBLE_DAIFMT_I2S |
758753
SND_SOC_POSSIBLE_DAIFMT_LEFT_J;

sound/soc/codecs/ak4619.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -778,17 +778,13 @@ static int ak4619_dai_startup(struct snd_pcm_substream *substream,
778778
}
779779

780780
static u64 ak4619_dai_formats[] = {
781-
/*
782-
* Select below from Sound Card, not here
783-
* SND_SOC_DAIFMT_CBC_CFC
784-
* SND_SOC_DAIFMT_CBP_CFP
785-
*/
786-
787781
/* First Priority */
788782
SND_SOC_POSSIBLE_DAIFMT_I2S |
789783
SND_SOC_POSSIBLE_DAIFMT_LEFT_J,
790784

791785
/* Second Priority */
786+
SND_SOC_POSSIBLE_DAIFMT_I2S |
787+
SND_SOC_POSSIBLE_DAIFMT_LEFT_J |
792788
SND_SOC_POSSIBLE_DAIFMT_DSP_A |
793789
SND_SOC_POSSIBLE_DAIFMT_DSP_B,
794790
};

sound/soc/codecs/da7213.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,11 +1720,6 @@ static int da7213_set_component_pll(struct snd_soc_component *component,
17201720
return _da7213_set_component_pll(component, pll_id, source, fref, fout);
17211721
}
17221722

1723-
/*
1724-
* Select below from Sound Card, not Auto
1725-
* SND_SOC_DAIFMT_CBC_CFC
1726-
* SND_SOC_DAIFMT_CBP_CFP
1727-
*/
17281723
static const u64 da7213_dai_formats =
17291724
SND_SOC_POSSIBLE_DAIFMT_I2S |
17301725
SND_SOC_POSSIBLE_DAIFMT_LEFT_J |

sound/soc/codecs/framer-codec.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,13 @@ static int framer_dai_startup(struct snd_pcm_substream *substream,
238238
return 0;
239239
}
240240

241-
static const u64 framer_dai_formats[] = {
242-
SND_SOC_POSSIBLE_DAIFMT_DSP_B,
243-
};
241+
static const u64 framer_dai_formats = SND_SOC_POSSIBLE_DAIFMT_DSP_B;
244242

245243
static const struct snd_soc_dai_ops framer_dai_ops = {
246244
.startup = framer_dai_startup,
247245
.set_tdm_slot = framer_dai_set_tdm_slot,
248-
.auto_selectable_formats = framer_dai_formats,
249-
.num_auto_selectable_formats = ARRAY_SIZE(framer_dai_formats),
246+
.auto_selectable_formats = &framer_dai_formats,
247+
.num_auto_selectable_formats = 1,
250248
};
251249

252250
static struct snd_soc_dai_driver framer_dai_driver = {

sound/soc/codecs/idt821034.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,18 +860,17 @@ static int idt821034_dai_startup(struct snd_pcm_substream *substream,
860860
return 0;
861861
}
862862

863-
static const u64 idt821034_dai_formats[] = {
863+
static const u64 idt821034_dai_formats =
864864
SND_SOC_POSSIBLE_DAIFMT_DSP_A |
865-
SND_SOC_POSSIBLE_DAIFMT_DSP_B,
866-
};
865+
SND_SOC_POSSIBLE_DAIFMT_DSP_B;
867866

868867
static const struct snd_soc_dai_ops idt821034_dai_ops = {
869868
.startup = idt821034_dai_startup,
870869
.hw_params = idt821034_dai_hw_params,
871870
.set_tdm_slot = idt821034_dai_set_tdm_slot,
872871
.set_fmt = idt821034_dai_set_fmt,
873-
.auto_selectable_formats = idt821034_dai_formats,
874-
.num_auto_selectable_formats = ARRAY_SIZE(idt821034_dai_formats),
872+
.auto_selectable_formats = &idt821034_dai_formats,
873+
.num_auto_selectable_formats = 1,
875874
};
876875

877876
static struct snd_soc_dai_driver idt821034_dai_driver = {

sound/soc/codecs/pcm3168a.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,6 @@ static int pcm3168a_hw_params(struct snd_pcm_substream *substream,
563563
}
564564

565565
static const u64 pcm3168a_dai_formats[] = {
566-
/*
567-
* Select below from Sound Card, not here
568-
* SND_SOC_DAIFMT_CBC_CFC
569-
* SND_SOC_DAIFMT_CBP_CFP
570-
*/
571-
572566
/*
573567
* First Priority
574568
*/
@@ -581,6 +575,8 @@ static const u64 pcm3168a_dai_formats[] = {
581575
* see
582576
* pcm3168a_hw_params()
583577
*/
578+
SND_SOC_POSSIBLE_DAIFMT_I2S |
579+
SND_SOC_POSSIBLE_DAIFMT_LEFT_J |
584580
SND_SOC_POSSIBLE_DAIFMT_RIGHT_J |
585581
SND_SOC_POSSIBLE_DAIFMT_DSP_A |
586582
SND_SOC_POSSIBLE_DAIFMT_DSP_B,

sound/soc/codecs/peb2466.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,18 +817,17 @@ static int peb2466_dai_startup(struct snd_pcm_substream *substream,
817817
&peb2466_sample_bits_constr);
818818
}
819819

820-
static const u64 peb2466_dai_formats[] = {
820+
static const u64 peb2466_dai_formats =
821821
SND_SOC_POSSIBLE_DAIFMT_DSP_A |
822-
SND_SOC_POSSIBLE_DAIFMT_DSP_B,
823-
};
822+
SND_SOC_POSSIBLE_DAIFMT_DSP_B;
824823

825824
static const struct snd_soc_dai_ops peb2466_dai_ops = {
826825
.startup = peb2466_dai_startup,
827826
.hw_params = peb2466_dai_hw_params,
828827
.set_tdm_slot = peb2466_dai_set_tdm_slot,
829828
.set_fmt = peb2466_dai_set_fmt,
830-
.auto_selectable_formats = peb2466_dai_formats,
831-
.num_auto_selectable_formats = ARRAY_SIZE(peb2466_dai_formats),
829+
.auto_selectable_formats = &peb2466_dai_formats,
830+
.num_auto_selectable_formats = 1,
832831
};
833832

834833
static struct snd_soc_dai_driver peb2466_dai_driver = {

sound/soc/generic/audio-graph-card2.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,18 @@ static void graph_link_init(struct simple_util_priv *priv,
778778
graph_parse_daifmt(ports_cpu, &daifmt);
779779
graph_parse_daifmt(ports_codec, &daifmt);
780780
graph_parse_daifmt(lnk, &daifmt);
781+
if (daifmt) {
782+
struct device *dev = simple_priv_to_dev(priv);
783+
784+
/*
785+
* Recommend to use Auto Select by using .auto_selectable_formats.
786+
* linux/sound/soc/renesas/rcar/core.c can be good sample for it.
787+
*
788+
* One note is that Audio Graph Card2 still keeps compatible to set
789+
* DAI format via DT.
790+
*/
791+
dev_warn_once(dev, "use .auto_selectable_formats on each corresponding CPU/Codec driver");
792+
}
781793

782794
graph_util_parse_link_direction(lnk, &playback_only, &capture_only);
783795
graph_util_parse_link_direction(ports_cpu, &playback_only, &capture_only);

sound/soc/generic/test-component.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ static int test_dai_trigger(struct snd_pcm_substream *substream, int cmd, struct
191191
}
192192

193193
static const u64 test_dai_formats =
194-
/*
195-
* Select below from Sound Card, not auto
196-
* SND_SOC_POSSIBLE_DAIFMT_BP_FP
197-
* SND_SOC_POSSIBLE_DAIFMT_BC_FP
198-
* SND_SOC_POSSIBLE_DAIFMT_BP_FC
199-
* SND_SOC_POSSIBLE_DAIFMT_BC_FC
200-
*/
201194
SND_SOC_POSSIBLE_DAIFMT_I2S |
202195
SND_SOC_POSSIBLE_DAIFMT_RIGHT_J |
203196
SND_SOC_POSSIBLE_DAIFMT_LEFT_J |

0 commit comments

Comments
 (0)