WIP FPC-III support
[linux/fpc-iii.git] / sound / soc / intel / boards / sof_sdw_hdmi.c
blob99b04bb2f3a05d38a018f079dda1e3b1fed2666d
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2020 Intel Corporation
4 /*
5 * sof_sdw_hdmi - Helpers to handle HDMI from generic machine driver
6 */
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"
19 static struct snd_soc_jack hdmi[MAX_HDMI_NUM];
21 struct hdmi_pcm {
22 struct list_head head;
23 struct snd_soc_dai *codec_dai;
24 int device;
27 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd)
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;
33 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
34 if (!pcm)
35 return -ENOMEM;
37 /* dai_link id is 1:1 mapped to the PCM device */
38 pcm->device = rtd->dai_link->id;
39 pcm->codec_dai = dai;
41 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
43 return 0;
46 #define NAME_SIZE 32
47 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card)
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];
55 if (!ctx->idisp_codec)
56 return 0;
58 if (list_empty(&ctx->hdmi_pcm_list))
59 return -EINVAL;
61 pcm = list_first_entry(&ctx->hdmi_pcm_list, struct hdmi_pcm,
62 head);
63 component = pcm->codec_dai->component;
65 if (ctx->common_hdmi_codec_drv)
66 return hda_dsp_hdmi_build_controls(card, component);
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);
76 if (err)
77 return err;
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");
84 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
85 &hdmi[i]);
86 if (err < 0)
87 return err;
89 i++;
92 if (!component)
93 return -EINVAL;
95 return hdac_hdmi_jack_port_init(component, &card->dapm);