Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: hdmi-codec: Add iec958 controls

The IEC958 status bits can be exposed and modified by the userspace
through dedicated ALSA controls.

This patch implements those controls for the hdmi-codec driver. It
relies on a default value being setup at probe time that can later be
overridden by the control put.

The hw_params callback is then called with a buffer filled with the
proper bits for the current parameters being passed on so the underlying
driver can just reuse those bits as is.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210525132354.297468-5-maxime@cerno.tech

+64 -2
+64 -2
sound/soc/codecs/hdmi-codec.c
··· 277 277 bool busy; 278 278 struct snd_soc_jack *jack; 279 279 unsigned int jack_status; 280 + u8 iec_status[5]; 280 281 }; 281 282 282 283 static const struct snd_soc_dapm_widget hdmi_widgets[] = { ··· 386 385 return 0; 387 386 } 388 387 388 + static int hdmi_codec_iec958_info(struct snd_kcontrol *kcontrol, 389 + struct snd_ctl_elem_info *uinfo) 390 + { 391 + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 392 + uinfo->count = 1; 393 + return 0; 394 + } 395 + 396 + static int hdmi_codec_iec958_default_get(struct snd_kcontrol *kcontrol, 397 + struct snd_ctl_elem_value *ucontrol) 398 + { 399 + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 400 + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); 401 + 402 + memcpy(ucontrol->value.iec958.status, hcp->iec_status, 403 + sizeof(hcp->iec_status)); 404 + 405 + return 0; 406 + } 407 + 408 + static int hdmi_codec_iec958_default_put(struct snd_kcontrol *kcontrol, 409 + struct snd_ctl_elem_value *ucontrol) 410 + { 411 + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); 412 + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); 413 + 414 + memcpy(hcp->iec_status, ucontrol->value.iec958.status, 415 + sizeof(hcp->iec_status)); 416 + 417 + return 0; 418 + } 419 + 420 + static int hdmi_codec_iec958_mask_get(struct snd_kcontrol *kcontrol, 421 + struct snd_ctl_elem_value *ucontrol) 422 + { 423 + memset(ucontrol->value.iec958.status, 0xff, 424 + sizeof_field(struct hdmi_codec_priv, iec_status)); 425 + 426 + return 0; 427 + } 428 + 389 429 static int hdmi_codec_startup(struct snd_pcm_substream *substream, 390 430 struct snd_soc_dai *dai) 391 431 { ··· 501 459 params_width(params), params_rate(params), 502 460 params_channels(params)); 503 461 504 - ret = snd_pcm_create_iec958_consumer_hw_params(params, hp.iec.status, 505 - sizeof(hp.iec.status)); 462 + memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); 463 + ret = snd_pcm_fill_iec958_consumer_hw_params(params, hp.iec.status, 464 + sizeof(hp.iec.status)); 506 465 if (ret < 0) { 507 466 dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", 508 467 ret); ··· 664 621 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE) 665 622 666 623 struct snd_kcontrol_new hdmi_codec_controls[] = { 624 + { 625 + .access = SNDRV_CTL_ELEM_ACCESS_READ, 626 + .iface = SNDRV_CTL_ELEM_IFACE_PCM, 627 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), 628 + .info = hdmi_codec_iec958_info, 629 + .get = hdmi_codec_iec958_mask_get, 630 + }, 631 + { 632 + .iface = SNDRV_CTL_ELEM_IFACE_PCM, 633 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), 634 + .info = hdmi_codec_iec958_info, 635 + .get = hdmi_codec_iec958_default_get, 636 + .put = hdmi_codec_iec958_default_put, 637 + }, 667 638 { 668 639 .access = (SNDRV_CTL_ELEM_ACCESS_READ | 669 640 SNDRV_CTL_ELEM_ACCESS_VOLATILE), ··· 929 872 930 873 hcp->hcd = *hcd; 931 874 mutex_init(&hcp->lock); 875 + 876 + ret = snd_pcm_create_iec958_consumer_default(hcp->iec_status, 877 + sizeof(hcp->iec_status)); 878 + if (ret < 0) 879 + return ret; 932 880 933 881 daidrv = devm_kcalloc(dev, dai_count, sizeof(*daidrv), GFP_KERNEL); 934 882 if (!daidrv)