0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/platform_device.h>
0010 #include <sound/core.h>
0011 #include <sound/jack.h>
0012 #include <sound/pcm.h>
0013 #include <sound/pcm_params.h>
0014 #include <sound/soc.h>
0015 #include <sound/soc-acpi.h>
0016 #include "../../codecs/hdac_hdmi.h"
0017 #include "skl_hda_dsp_common.h"
0018
0019 static const struct snd_soc_dapm_widget skl_hda_widgets[] = {
0020 SND_SOC_DAPM_HP("Analog Out", NULL),
0021 SND_SOC_DAPM_MIC("Analog In", NULL),
0022 SND_SOC_DAPM_HP("Alt Analog Out", NULL),
0023 SND_SOC_DAPM_MIC("Alt Analog In", NULL),
0024 SND_SOC_DAPM_SPK("Digital Out", NULL),
0025 SND_SOC_DAPM_MIC("Digital In", NULL),
0026 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
0027 };
0028
0029 static const struct snd_soc_dapm_route skl_hda_map[] = {
0030 { "hifi3", NULL, "iDisp3 Tx"},
0031 { "iDisp3 Tx", NULL, "iDisp3_out"},
0032 { "hifi2", NULL, "iDisp2 Tx"},
0033 { "iDisp2 Tx", NULL, "iDisp2_out"},
0034 { "hifi1", NULL, "iDisp1 Tx"},
0035 { "iDisp1 Tx", NULL, "iDisp1_out"},
0036
0037 { "Analog Out", NULL, "Codec Output Pin1" },
0038 { "Digital Out", NULL, "Codec Output Pin2" },
0039 { "Alt Analog Out", NULL, "Codec Output Pin3" },
0040
0041 { "Codec Input Pin1", NULL, "Analog In" },
0042 { "Codec Input Pin2", NULL, "Digital In" },
0043 { "Codec Input Pin3", NULL, "Alt Analog In" },
0044
0045
0046 {"DMic", NULL, "SoC DMIC"},
0047
0048
0049 { "Analog Codec Playback", NULL, "Analog CPU Playback" },
0050 { "Analog CPU Playback", NULL, "codec0_out" },
0051 { "Digital Codec Playback", NULL, "Digital CPU Playback" },
0052 { "Digital CPU Playback", NULL, "codec1_out" },
0053 { "Alt Analog Codec Playback", NULL, "Alt Analog CPU Playback" },
0054 { "Alt Analog CPU Playback", NULL, "codec2_out" },
0055
0056 { "codec0_in", NULL, "Analog CPU Capture" },
0057 { "Analog CPU Capture", NULL, "Analog Codec Capture" },
0058 { "codec1_in", NULL, "Digital CPU Capture" },
0059 { "Digital CPU Capture", NULL, "Digital Codec Capture" },
0060 { "codec2_in", NULL, "Alt Analog CPU Capture" },
0061 { "Alt Analog CPU Capture", NULL, "Alt Analog Codec Capture" },
0062 };
0063
0064 SND_SOC_DAILINK_DEF(dummy_codec,
0065 DAILINK_COMP_ARRAY(COMP_CODEC("snd-soc-dummy", "snd-soc-dummy-dai")));
0066
0067 static int skl_hda_card_late_probe(struct snd_soc_card *card)
0068 {
0069 return skl_hda_hdmi_jack_init(card);
0070 }
0071
0072 static int
0073 skl_hda_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *link)
0074 {
0075 struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
0076 int ret = 0;
0077
0078 dev_dbg(card->dev, "dai link name - %s\n", link->name);
0079 link->platforms->name = ctx->platform_name;
0080 link->nonatomic = 1;
0081
0082 if (!ctx->idisp_codec)
0083 return 0;
0084
0085 if (strstr(link->name, "HDMI")) {
0086 ret = skl_hda_hdmi_add_pcm(card, ctx->pcm_count);
0087
0088 if (ret < 0)
0089 return ret;
0090
0091 ctx->dai_index++;
0092 }
0093
0094 ctx->pcm_count++;
0095 return ret;
0096 }
0097
0098 static struct snd_soc_card hda_soc_card = {
0099 .name = "hda-dsp",
0100 .owner = THIS_MODULE,
0101 .dai_link = skl_hda_be_dai_links,
0102 .dapm_widgets = skl_hda_widgets,
0103 .dapm_routes = skl_hda_map,
0104 .add_dai_link = skl_hda_add_dai_link,
0105 .fully_routed = true,
0106 .late_probe = skl_hda_card_late_probe,
0107 };
0108
0109 static char hda_soc_components[30];
0110
0111 #define IDISP_DAI_COUNT 3
0112 #define HDAC_DAI_COUNT 2
0113 #define DMIC_DAI_COUNT 2
0114
0115
0116 #define IDISP_ROUTE_COUNT (IDISP_DAI_COUNT * 2)
0117 #define IDISP_CODEC_MASK 0x4
0118
0119 #define HDA_CODEC_AUTOSUSPEND_DELAY_MS 1000
0120
0121 static int skl_hda_fill_card_info(struct snd_soc_acpi_mach_params *mach_params)
0122 {
0123 struct snd_soc_card *card = &hda_soc_card;
0124 struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
0125 struct snd_soc_dai_link *dai_link;
0126 u32 codec_count, codec_mask;
0127 int i, num_links, num_route;
0128
0129 codec_mask = mach_params->codec_mask;
0130 codec_count = hweight_long(codec_mask);
0131 ctx->idisp_codec = !!(codec_mask & IDISP_CODEC_MASK);
0132
0133 if (!codec_count || codec_count > 2 ||
0134 (codec_count == 2 && !ctx->idisp_codec))
0135 return -EINVAL;
0136
0137 if (codec_mask == IDISP_CODEC_MASK) {
0138
0139 num_links = IDISP_DAI_COUNT + DMIC_DAI_COUNT;
0140 num_route = IDISP_ROUTE_COUNT;
0141
0142
0143
0144
0145
0146
0147
0148 for (i = 0; i < DMIC_DAI_COUNT; i++) {
0149 skl_hda_be_dai_links[IDISP_DAI_COUNT + i] =
0150 skl_hda_be_dai_links[IDISP_DAI_COUNT +
0151 HDAC_DAI_COUNT + i];
0152 }
0153 } else {
0154
0155 num_links = ARRAY_SIZE(skl_hda_be_dai_links);
0156 num_route = ARRAY_SIZE(skl_hda_map);
0157 card->dapm_widgets = skl_hda_widgets;
0158 card->num_dapm_widgets = ARRAY_SIZE(skl_hda_widgets);
0159 if (!ctx->idisp_codec) {
0160 for (i = 0; i < IDISP_DAI_COUNT; i++) {
0161 skl_hda_be_dai_links[i].codecs = dummy_codec;
0162 skl_hda_be_dai_links[i].num_codecs =
0163 ARRAY_SIZE(dummy_codec);
0164 }
0165 }
0166 }
0167
0168 card->num_links = num_links;
0169 card->num_dapm_routes = num_route;
0170
0171 for_each_card_prelinks(card, i, dai_link)
0172 dai_link->platforms->name = mach_params->platform;
0173
0174 return 0;
0175 }
0176
0177 static void skl_set_hda_codec_autosuspend_delay(struct snd_soc_card *card)
0178 {
0179 struct snd_soc_pcm_runtime *rtd;
0180 struct hdac_hda_priv *hda_pvt;
0181 struct snd_soc_dai *dai;
0182
0183 for_each_card_rtds(card, rtd) {
0184 if (!strstr(rtd->dai_link->codecs->name, "ehdaudio0D0"))
0185 continue;
0186 dai = asoc_rtd_to_codec(rtd, 0);
0187 hda_pvt = snd_soc_component_get_drvdata(dai->component);
0188 if (hda_pvt) {
0189
0190
0191
0192
0193 snd_hda_set_power_save(hda_pvt->codec.bus,
0194 HDA_CODEC_AUTOSUSPEND_DELAY_MS);
0195 break;
0196 }
0197 }
0198 }
0199
0200 static int skl_hda_audio_probe(struct platform_device *pdev)
0201 {
0202 struct snd_soc_acpi_mach *mach;
0203 struct skl_hda_private *ctx;
0204 int ret;
0205
0206 dev_dbg(&pdev->dev, "entry\n");
0207
0208 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
0209 if (!ctx)
0210 return -ENOMEM;
0211
0212 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
0213
0214 mach = pdev->dev.platform_data;
0215 if (!mach)
0216 return -EINVAL;
0217
0218 snd_soc_card_set_drvdata(&hda_soc_card, ctx);
0219
0220 ret = skl_hda_fill_card_info(&mach->mach_params);
0221 if (ret < 0) {
0222 dev_err(&pdev->dev, "Unsupported HDAudio/iDisp configuration found\n");
0223 return ret;
0224 }
0225
0226 ctx->pcm_count = hda_soc_card.num_links;
0227 ctx->dai_index = 1;
0228 ctx->platform_name = mach->mach_params.platform;
0229 ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
0230
0231 hda_soc_card.dev = &pdev->dev;
0232
0233 if (mach->mach_params.dmic_num > 0) {
0234 snprintf(hda_soc_components, sizeof(hda_soc_components),
0235 "cfg-dmics:%d", mach->mach_params.dmic_num);
0236 hda_soc_card.components = hda_soc_components;
0237 }
0238
0239 ret = devm_snd_soc_register_card(&pdev->dev, &hda_soc_card);
0240 if (!ret)
0241 skl_set_hda_codec_autosuspend_delay(&hda_soc_card);
0242
0243 return ret;
0244 }
0245
0246 static struct platform_driver skl_hda_audio = {
0247 .probe = skl_hda_audio_probe,
0248 .driver = {
0249 .name = "skl_hda_dsp_generic",
0250 .pm = &snd_soc_pm_ops,
0251 },
0252 };
0253
0254 module_platform_driver(skl_hda_audio)
0255
0256
0257 MODULE_DESCRIPTION("SKL/KBL/BXT/APL HDA Generic Machine driver");
0258 MODULE_AUTHOR("Rakesh Ughreja <rakesh.a.ughreja@intel.com>");
0259 MODULE_LICENSE("GPL v2");
0260 MODULE_ALIAS("platform:skl_hda_dsp_generic");
0261 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);