bcm27xx: add kernel 5.10 support
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.10 / 950-0634-ASoC-hdmi-codec-Add-iec958-controls.patch
1 From 011a6244136c86e03c77866d6ef9b8eac65fc575 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Wed, 28 Apr 2021 15:29:51 +0200
4 Subject: [PATCH] ASoC: hdmi-codec: Add iec958 controls
5
6 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
7 ---
8 sound/soc/codecs/hdmi-codec.c | 66 +++++++++++++++++++++++++++++++++--
9 1 file changed, 64 insertions(+), 2 deletions(-)
10
11 --- a/sound/soc/codecs/hdmi-codec.c
12 +++ b/sound/soc/codecs/hdmi-codec.c
13 @@ -278,6 +278,7 @@ struct hdmi_codec_priv {
14 bool busy;
15 struct snd_soc_jack *jack;
16 unsigned int jack_status;
17 + u8 iec_status[5];
18 };
19
20 static const struct snd_soc_dapm_widget hdmi_widgets[] = {
21 @@ -385,6 +386,47 @@ static int hdmi_codec_chmap_ctl_get(stru
22 return 0;
23 }
24
25 +static int hdmi_codec_iec958_info(struct snd_kcontrol *kcontrol,
26 + struct snd_ctl_elem_info *uinfo)
27 +{
28 + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
29 + uinfo->count = 1;
30 + return 0;
31 +}
32 +
33 +static int hdmi_codec_iec958_default_get(struct snd_kcontrol *kcontrol,
34 + struct snd_ctl_elem_value *ucontrol)
35 +{
36 + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
37 + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
38 +
39 + memcpy(ucontrol->value.iec958.status, hcp->iec_status,
40 + sizeof(hcp->iec_status));
41 +
42 + return 0;
43 +}
44 +
45 +static int hdmi_codec_iec958_default_put(struct snd_kcontrol *kcontrol,
46 + struct snd_ctl_elem_value *ucontrol)
47 +{
48 + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
49 + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
50 +
51 + memcpy(hcp->iec_status, ucontrol->value.iec958.status,
52 + sizeof(hcp->iec_status));
53 +
54 + return 0;
55 +}
56 +
57 +static int hdmi_codec_iec958_mask_get(struct snd_kcontrol *kcontrol,
58 + struct snd_ctl_elem_value *ucontrol)
59 +{
60 + memset(ucontrol->value.iec958.status, 0xff,
61 + sizeof_field(struct hdmi_codec_priv, iec_status));
62 +
63 + return 0;
64 +}
65 +
66 static int hdmi_codec_startup(struct snd_pcm_substream *substream,
67 struct snd_soc_dai *dai)
68 {
69 @@ -458,8 +500,9 @@ static int hdmi_codec_hw_params(struct s
70 params_width(params), params_rate(params),
71 params_channels(params));
72
73 - ret = snd_pcm_create_iec958_consumer_hw_params(params, hp.iec.status,
74 - sizeof(hp.iec.status));
75 + memcpy(hp.iec.status, hcp->iec_status, sizeof(hp->iec_status));
76 + ret = snd_pcm_fill_iec958_consumer_hw_params(params, hp.iec.status,
77 + sizeof(hp.iec.status));
78 if (ret < 0) {
79 dev_err(dai->dev, "Creating IEC958 channel status failed %d\n",
80 ret);
81 @@ -621,6 +664,20 @@ static const struct snd_soc_dai_ops hdmi
82
83 struct snd_kcontrol_new hdmi_codec_controls[] = {
84 {
85 + .access = SNDRV_CTL_ELEM_ACCESS_READ,
86 + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
87 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
88 + .info = hdmi_codec_iec958_info,
89 + .get = hdmi_codec_iec958_mask_get,
90 + },
91 + {
92 + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
93 + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
94 + .info = hdmi_codec_iec958_info,
95 + .get = hdmi_codec_iec958_default_get,
96 + .put = hdmi_codec_iec958_default_put,
97 + },
98 + {
99 .access = (SNDRV_CTL_ELEM_ACCESS_READ |
100 SNDRV_CTL_ELEM_ACCESS_VOLATILE),
101 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
102 @@ -845,6 +902,11 @@ static int hdmi_codec_probe(struct platf
103 hcp->hcd = *hcd;
104 mutex_init(&hcp->lock);
105
106 + ret = snd_pcm_create_iec958_consumer_default(hcp->iec_status,
107 + sizeof(hcp->iec_status));
108 + if (ret < 0)
109 + return ret;
110 +
111 daidrv = devm_kcalloc(dev, dai_count, sizeof(*daidrv), GFP_KERNEL);
112 if (!daidrv)
113 return -ENOMEM;