Skip to content

Commit 1e112c3

Browse files
Peter Ujfalusibroonie
authored andcommitted
ASoC: ti: davinci-mcasp: Correct slot_width posed constraint
The slot_width is a property for the bus while the constraint for SNDRV_PCM_HW_PARAM_SAMPLE_BITS is for the in memory format. Applying slot_width constraint to sample_bits works most of the time, but it will blacklist valid formats in some cases. With slot_width 24 we can support S24_3LE and S24_LE formats as they both look the same on the bus, but a a 24 constraint on sample_bits would not allow S24_LE as it is stored in 32bits in memory. Implement a simple hw_rule function to allow all formats which require less or equal number of bits on the bus as slot_width (if configured). Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Link: https://lore.kernel.org/r/20190726064244.3762-2-peter.ujfalusi@ti.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 789e162 commit 1e112c3

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

‎sound/soc/ti/davinci-mcasp.c‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,28 @@ static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
12571257
return ret;
12581258
}
12591259

1260+
static int davinci_mcasp_hw_rule_slot_width(struct snd_pcm_hw_params *params,
1261+
struct snd_pcm_hw_rule *rule)
1262+
{
1263+
struct davinci_mcasp_ruledata *rd = rule->private;
1264+
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1265+
struct snd_mask nfmt;
1266+
int i, slot_width;
1267+
1268+
snd_mask_none(&nfmt);
1269+
slot_width = rd->mcasp->slot_width;
1270+
1271+
for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) {
1272+
if (snd_mask_test(fmt, i)) {
1273+
if (snd_pcm_format_width(i) <= slot_width) {
1274+
snd_mask_set(&nfmt, i);
1275+
}
1276+
}
1277+
}
1278+
1279+
return snd_mask_refine(fmt, &nfmt);
1280+
}
1281+
12601282
static const unsigned int davinci_mcasp_dai_rates[] = {
12611283
8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
12621284
88200, 96000, 176400, 192000,
@@ -1378,7 +1400,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
13781400
struct davinci_mcasp_ruledata *ruledata =
13791401
&mcasp->ruledata[substream->stream];
13801402
u32 max_channels = 0;
1381-
int i, dir;
1403+
int i, dir, ret;
13821404
int tdm_slots = mcasp->tdm_slots;
13831405

13841406
/* Do not allow more then one stream per direction */
@@ -1407,6 +1429,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
14071429
max_channels++;
14081430
}
14091431
ruledata->serializers = max_channels;
1432+
ruledata->mcasp = mcasp;
14101433
max_channels *= tdm_slots;
14111434
/*
14121435
* If the already active stream has less channels than the calculated
@@ -1432,20 +1455,22 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
14321455
0, SNDRV_PCM_HW_PARAM_CHANNELS,
14331456
&mcasp->chconstr[substream->stream]);
14341457

1435-
if (mcasp->slot_width)
1436-
snd_pcm_hw_constraint_minmax(substream->runtime,
1437-
SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
1438-
8, mcasp->slot_width);
1458+
if (mcasp->slot_width) {
1459+
/* Only allow formats require <= slot_width bits on the bus */
1460+
ret = snd_pcm_hw_rule_add(substream->runtime, 0,
1461+
SNDRV_PCM_HW_PARAM_FORMAT,
1462+
davinci_mcasp_hw_rule_slot_width,
1463+
ruledata,
1464+
SNDRV_PCM_HW_PARAM_FORMAT, -1);
1465+
if (ret)
1466+
return ret;
1467+
}
14391468

14401469
/*
14411470
* If we rely on implicit BCLK divider setting we should
14421471
* set constraints based on what we can provide.
14431472
*/
14441473
if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) {
1445-
int ret;
1446-
1447-
ruledata->mcasp = mcasp;
1448-
14491474
ret = snd_pcm_hw_rule_add(substream->runtime, 0,
14501475
SNDRV_PCM_HW_PARAM_RATE,
14511476
davinci_mcasp_hw_rule_rate,

0 commit comments

Comments
 (0)