1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright(c) 2015-18 Intel Corporation. 3 4 /* 5 * Machine Driver for SKL+ platforms with DSP and iDisp, HDA Codecs 6 */ 7 8 #include <linux/module.h> 9 #include <linux/platform_device.h> 10 #include <sound/core.h> 11 #include <sound/jack.h> 12 #include <sound/pcm.h> 13 #include <sound/pcm_params.h> 14 #include <sound/soc.h> 15 #include <sound/soc-acpi.h> 16 #include "../../codecs/hdac_hdmi.h" 17 #include "skl_hda_dsp_common.h" 18 19 static const struct snd_soc_dapm_widget skl_hda_widgets[] = { 20 SND_SOC_DAPM_HP("Analog Out", NULL), 21 SND_SOC_DAPM_MIC("Analog In", NULL), 22 SND_SOC_DAPM_HP("Alt Analog Out", NULL), 23 SND_SOC_DAPM_MIC("Alt Analog In", NULL), 24 SND_SOC_DAPM_SPK("Digital Out", NULL), 25 SND_SOC_DAPM_MIC("Digital In", NULL), 26 }; 27 28 static const struct snd_soc_dapm_route skl_hda_map[] = { 29 { "hifi3", NULL, "iDisp3 Tx"}, 30 { "iDisp3 Tx", NULL, "iDisp3_out"}, 31 { "hifi2", NULL, "iDisp2 Tx"}, 32 { "iDisp2 Tx", NULL, "iDisp2_out"}, 33 { "hifi1", NULL, "iDisp1 Tx"}, 34 { "iDisp1 Tx", NULL, "iDisp1_out"}, 35 36 { "Analog Out", NULL, "Codec Output Pin1" }, 37 { "Digital Out", NULL, "Codec Output Pin2" }, 38 { "Alt Analog Out", NULL, "Codec Output Pin3" }, 39 40 { "Codec Input Pin1", NULL, "Analog In" }, 41 { "Codec Input Pin2", NULL, "Digital In" }, 42 { "Codec Input Pin3", NULL, "Alt Analog In" }, 43 44 /* CODEC BE connections */ 45 { "Analog Codec Playback", NULL, "Analog CPU Playback" }, 46 { "Analog CPU Playback", NULL, "codec0_out" }, 47 { "Digital Codec Playback", NULL, "Digital CPU Playback" }, 48 { "Digital CPU Playback", NULL, "codec1_out" }, 49 { "Alt Analog Codec Playback", NULL, "Alt Analog CPU Playback" }, 50 { "Alt Analog CPU Playback", NULL, "codec2_out" }, 51 52 { "codec0_in", NULL, "Analog CPU Capture" }, 53 { "Analog CPU Capture", NULL, "Analog Codec Capture" }, 54 { "codec1_in", NULL, "Digital CPU Capture" }, 55 { "Digital CPU Capture", NULL, "Digital Codec Capture" }, 56 { "codec2_in", NULL, "Alt Analog CPU Capture" }, 57 { "Alt Analog CPU Capture", NULL, "Alt Analog Codec Capture" }, 58 }; 59 60 static int skl_hda_card_late_probe(struct snd_soc_card *card) 61 { 62 return skl_hda_hdmi_jack_init(card); 63 } 64 65 static int 66 skl_hda_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *link) 67 { 68 struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card); 69 int ret = 0; 70 71 dev_dbg(card->dev, "%s: dai link name - %s\n", __func__, link->name); 72 link->platform_name = ctx->platform_name; 73 link->nonatomic = 1; 74 75 if (strstr(link->name, "HDMI")) { 76 ret = skl_hda_hdmi_add_pcm(card, ctx->pcm_count); 77 78 if (ret < 0) 79 return ret; 80 81 ctx->dai_index++; 82 } 83 84 ctx->pcm_count++; 85 return ret; 86 } 87 88 static struct snd_soc_card hda_soc_card = { 89 .name = "skl_hda_card", 90 .owner = THIS_MODULE, 91 .dai_link = skl_hda_be_dai_links, 92 .dapm_widgets = skl_hda_widgets, 93 .dapm_routes = skl_hda_map, 94 .add_dai_link = skl_hda_add_dai_link, 95 .fully_routed = true, 96 .late_probe = skl_hda_card_late_probe, 97 }; 98 99 #define IDISP_DAI_COUNT 3 100 /* there are two routes per iDisp output */ 101 #define IDISP_ROUTE_COUNT (IDISP_DAI_COUNT * 2) 102 #define IDISP_CODEC_MASK 0x4 103 104 static int skl_hda_fill_card_info(struct snd_soc_acpi_mach_params *mach_params) 105 { 106 struct snd_soc_card *card = &hda_soc_card; 107 struct snd_soc_dai_link *dai_link; 108 u32 codec_count, codec_mask; 109 int i, num_links, num_route; 110 111 codec_mask = mach_params->codec_mask; 112 codec_count = hweight_long(codec_mask); 113 114 if (codec_count == 1 && codec_mask & IDISP_CODEC_MASK) { 115 num_links = IDISP_DAI_COUNT; 116 num_route = IDISP_ROUTE_COUNT; 117 } else if (codec_count == 2 && codec_mask & IDISP_CODEC_MASK) { 118 num_links = ARRAY_SIZE(skl_hda_be_dai_links); 119 num_route = ARRAY_SIZE(skl_hda_map), 120 card->dapm_widgets = skl_hda_widgets; 121 card->num_dapm_widgets = ARRAY_SIZE(skl_hda_widgets); 122 } else { 123 return -EINVAL; 124 } 125 126 card->num_links = num_links; 127 card->num_dapm_routes = num_route; 128 129 for_each_card_prelinks(card, i, dai_link) 130 dai_link->platform_name = mach_params->platform; 131 132 return 0; 133 } 134 135 static int skl_hda_audio_probe(struct platform_device *pdev) 136 { 137 struct snd_soc_acpi_mach *mach; 138 struct skl_hda_private *ctx; 139 int ret; 140 141 dev_dbg(&pdev->dev, "%s: entry\n", __func__); 142 143 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 144 if (!ctx) 145 return -ENOMEM; 146 147 INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 148 149 mach = (&pdev->dev)->platform_data; 150 if (!mach) 151 return -EINVAL; 152 153 ret = skl_hda_fill_card_info(&mach->mach_params); 154 if (ret < 0) { 155 dev_err(&pdev->dev, "Unsupported HDAudio/iDisp configuration found\n"); 156 return ret; 157 } 158 159 ctx->pcm_count = hda_soc_card.num_links; 160 ctx->dai_index = 1; /* hdmi codec dai name starts from index 1 */ 161 ctx->platform_name = mach->mach_params.platform; 162 163 hda_soc_card.dev = &pdev->dev; 164 snd_soc_card_set_drvdata(&hda_soc_card, ctx); 165 166 return devm_snd_soc_register_card(&pdev->dev, &hda_soc_card); 167 } 168 169 static struct platform_driver skl_hda_audio = { 170 .probe = skl_hda_audio_probe, 171 .driver = { 172 .name = "skl_hda_dsp_generic", 173 .pm = &snd_soc_pm_ops, 174 }, 175 }; 176 177 module_platform_driver(skl_hda_audio) 178 179 /* Module information */ 180 MODULE_DESCRIPTION("SKL/KBL/BXT/APL HDA Generic Machine driver"); 181 MODULE_AUTHOR("Rakesh Ughreja <rakesh.a.ughreja@intel.com>"); 182 MODULE_LICENSE("GPL v2"); 183 MODULE_ALIAS("platform:skl_hda_dsp_generic"); 184