Skip to content

Commit 2464feb

Browse files
crojewsk-intelbroonie
authored andcommitted
ASoC: Intel: catpt: Simplify procedure of applying user settings
Existing catpt_dai_apply_usettings() applies all the individual control settings but why-what is covered behind if-statements. Refactor the operation into: catpt_apply_controls() |__ catpt_apply_volume() |__ catpt_apply_mute() to make it easy to understand why and what is going on. The update also enlists snd_ctl_find_id_mixer() for the query purpose, removing code duplication. Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com> Link: https://patch.msgid.link/20260309091605.896307-4-cezary.rojewski@intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent d16b942 commit 2464feb

1 file changed

Lines changed: 33 additions & 31 deletions

File tree

  • sound/soc/intel/catpt

sound/soc/intel/catpt/pcm.c

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -359,46 +359,48 @@ struct catpt_control_data {
359359
long volumes[CATPT_CHANNELS_MAX];
360360
};
361361

362-
static int catpt_dai_apply_usettings(struct snd_soc_dai *dai,
363-
struct catpt_stream_runtime *stream)
362+
static int catpt_apply_volume(struct catpt_dev *cdev, struct snd_soc_card *card, const char *name)
364363
{
365-
struct snd_soc_component *component = dai->component;
366-
struct snd_kcontrol *pos;
367-
struct catpt_dev *cdev = dev_get_drvdata(dai->dev);
368-
const char *name;
364+
struct snd_kcontrol *kctl = snd_ctl_find_id_mixer(card->snd_card, name);
365+
struct catpt_control_data *data;
366+
367+
if (!kctl)
368+
return -ENOENT;
369+
data = (struct catpt_control_data *)kctl->private_value;
370+
371+
return catpt_set_dspvol(cdev, data->pin_id, data->volumes);
372+
}
373+
374+
static int catpt_apply_mute(struct catpt_dev *cdev, struct snd_soc_card *card)
375+
{
376+
struct snd_kcontrol *kctl = snd_ctl_find_id_mixer(card->snd_card, "Loopback Mute");
377+
bool mute;
369378
int ret;
370-
u32 id = stream->info.stream_hw_id;
371379

372-
/* only selected streams have individual controls */
373-
switch (id) {
380+
if (!kctl)
381+
return -ENOENT;
382+
mute = *(bool *)kctl->private_value;
383+
384+
ret = catpt_ipc_mute_loopback(cdev, CATPT_PIN_ID_REFERENCE, mute);
385+
return CATPT_IPC_RET(ret);
386+
}
387+
388+
static int catpt_apply_controls(struct catpt_dev *cdev, struct snd_soc_card *card,
389+
struct catpt_stream_runtime *stream)
390+
{
391+
/* Only selected streams have individual controls. */
392+
switch (stream->info.stream_hw_id) {
374393
case CATPT_PIN_ID_OFFLOAD1:
375-
name = "Media0 Playback Volume";
376-
break;
394+
return catpt_apply_volume(cdev, card, "Media0 Playback Volume");
377395
case CATPT_PIN_ID_OFFLOAD2:
378-
name = "Media1 Playback Volume";
379-
break;
396+
return catpt_apply_volume(cdev, card, "Media1 Playback Volume");
380397
case CATPT_PIN_ID_CAPTURE1:
381-
name = "Mic Capture Volume";
382-
break;
398+
return catpt_apply_volume(cdev, card, "Mic Capture Volume");
383399
case CATPT_PIN_ID_REFERENCE:
384-
name = "Loopback Mute";
385-
break;
400+
return catpt_apply_mute(cdev, card);
386401
default:
387402
return 0;
388403
}
389-
390-
list_for_each_entry(pos, &component->card->snd_card->controls, list) {
391-
if (pos->private_data == component &&
392-
!strncmp(name, pos->id.name, sizeof(pos->id.name)))
393-
break;
394-
}
395-
if (list_entry_is_head(pos, &component->card->snd_card->controls, list))
396-
return -ENOENT;
397-
398-
if (stream->template->type != CATPT_STRM_TYPE_LOOPBACK)
399-
return catpt_set_dspvol(cdev, id, (long *)pos->private_value);
400-
ret = catpt_ipc_mute_loopback(cdev, id, *(bool *)pos->private_value);
401-
return CATPT_IPC_RET(ret);
402404
}
403405

404406
static int catpt_dai_hw_params(struct snd_pcm_substream *substream,
@@ -449,7 +451,7 @@ static int catpt_dai_hw_params(struct snd_pcm_substream *substream,
449451

450452
guard(mutex)(&cdev->stream_mutex);
451453

452-
ret = catpt_dai_apply_usettings(dai, stream);
454+
ret = catpt_apply_controls(cdev, dai->component->card, stream);
453455
if (ret) {
454456
catpt_ipc_free_stream(cdev, stream->info.stream_hw_id);
455457
return ret;

0 commit comments

Comments
 (0)