1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2020 Intel Corporation
3
4 /*
5 * sof_sdw_hdmi - Helpers to handle HDMI from generic machine driver
6 */
7
8 #include <linux/device.h>
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/list.h>
12 #include <sound/soc.h>
13 #include <sound/soc-acpi.h>
14 #include <sound/jack.h>
15 #include "sof_sdw_common.h"
16 #include "../../codecs/hdac_hdmi.h"
17 #include "hda_dsp_common.h"
18
19 static struct snd_soc_jack hdmi[MAX_HDMI_NUM];
20
21 struct hdmi_pcm {
22 struct list_head head;
23 struct snd_soc_dai *codec_dai;
24 int device;
25 };
26
sof_sdw_hdmi_init(struct snd_soc_pcm_runtime * rtd)27 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd)
28 {
29 struct mc_private *ctx = snd_soc_card_get_drvdata(rtd->card);
30 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
31 struct hdmi_pcm *pcm;
32
33 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
34 if (!pcm)
35 return -ENOMEM;
36
37 /* dai_link id is 1:1 mapped to the PCM device */
38 pcm->device = rtd->dai_link->id;
39 pcm->codec_dai = dai;
40
41 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
42
43 return 0;
44 }
45
46 #define NAME_SIZE 32
sof_sdw_hdmi_card_late_probe(struct snd_soc_card * card)47 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card)
48 {
49 struct mc_private *ctx = snd_soc_card_get_drvdata(card);
50 struct hdmi_pcm *pcm;
51 struct snd_soc_component *component = NULL;
52 int err, i = 0;
53 char jack_name[NAME_SIZE];
54
55 if (!ctx->idisp_codec)
56 return 0;
57
58 if (list_empty(&ctx->hdmi_pcm_list))
59 return -EINVAL;
60
61 pcm = list_first_entry(&ctx->hdmi_pcm_list, struct hdmi_pcm,
62 head);
63 component = pcm->codec_dai->component;
64
65 if (ctx->common_hdmi_codec_drv)
66 return hda_dsp_hdmi_build_controls(card, component);
67
68 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
69 component = pcm->codec_dai->component;
70 snprintf(jack_name, sizeof(jack_name),
71 "HDMI/DP, pcm=%d Jack", pcm->device);
72 err = snd_soc_card_jack_new(card, jack_name,
73 SND_JACK_AVOUT, &hdmi[i],
74 NULL, 0);
75
76 if (err)
77 return err;
78
79 err = snd_jack_add_new_kctl(hdmi[i].jack,
80 jack_name, SND_JACK_AVOUT);
81 if (err)
82 dev_warn(component->dev, "failed creating Jack kctl\n");
83
84 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
85 &hdmi[i]);
86 if (err < 0)
87 return err;
88
89 i++;
90 }
91
92 if (!component)
93 return -EINVAL;
94
95 return hdac_hdmi_jack_port_init(component, &card->dapm);
96 }
97