1f40ed2e8SPierre-Louis Bossart // SPDX-License-Identifier: GPL-2.0 2f40ed2e8SPierre-Louis Bossart // Copyright(c) 2018-2020 Intel Corporation. 3f40ed2e8SPierre-Louis Bossart 4f40ed2e8SPierre-Louis Bossart /* 5f40ed2e8SPierre-Louis Bossart * Intel SOF Machine Driver for Intel platforms with TI PCM512x codec, 6f40ed2e8SPierre-Louis Bossart * e.g. Up or Up2 with Hifiberry DAC+ HAT 7f40ed2e8SPierre-Louis Bossart */ 8f40ed2e8SPierre-Louis Bossart #include <linux/clk.h> 9f40ed2e8SPierre-Louis Bossart #include <linux/dmi.h> 10f40ed2e8SPierre-Louis Bossart #include <linux/i2c.h> 11f40ed2e8SPierre-Louis Bossart #include <linux/input.h> 12f40ed2e8SPierre-Louis Bossart #include <linux/module.h> 13f40ed2e8SPierre-Louis Bossart #include <linux/platform_device.h> 14f40ed2e8SPierre-Louis Bossart #include <linux/types.h> 15f40ed2e8SPierre-Louis Bossart #include <sound/core.h> 16f40ed2e8SPierre-Louis Bossart #include <sound/jack.h> 17f40ed2e8SPierre-Louis Bossart #include <sound/pcm.h> 18f40ed2e8SPierre-Louis Bossart #include <sound/pcm_params.h> 19f40ed2e8SPierre-Louis Bossart #include <sound/soc.h> 20f40ed2e8SPierre-Louis Bossart #include <sound/soc-acpi.h> 21f40ed2e8SPierre-Louis Bossart #include "../../codecs/pcm512x.h" 22f40ed2e8SPierre-Louis Bossart #include "../common/soc-intel-quirks.h" 23f40ed2e8SPierre-Louis Bossart #include "hda_dsp_common.h" 24f40ed2e8SPierre-Louis Bossart 25f40ed2e8SPierre-Louis Bossart #define NAME_SIZE 32 26f40ed2e8SPierre-Louis Bossart 27f40ed2e8SPierre-Louis Bossart #define SOF_PCM512X_SSP_CODEC(quirk) ((quirk) & GENMASK(3, 0)) 28f40ed2e8SPierre-Louis Bossart #define SOF_PCM512X_SSP_CODEC_MASK (GENMASK(3, 0)) 29f40ed2e8SPierre-Louis Bossart 30*15a5a895SKai Vehmanen #define IDISP_CODEC_MASK 0x4 31*15a5a895SKai Vehmanen 32f40ed2e8SPierre-Louis Bossart /* Default: SSP5 */ 33f40ed2e8SPierre-Louis Bossart static unsigned long sof_pcm512x_quirk = SOF_PCM512X_SSP_CODEC(5); 34f40ed2e8SPierre-Louis Bossart 35f40ed2e8SPierre-Louis Bossart static bool is_legacy_cpu; 36f40ed2e8SPierre-Louis Bossart 37f40ed2e8SPierre-Louis Bossart struct sof_hdmi_pcm { 38f40ed2e8SPierre-Louis Bossart struct list_head head; 39f40ed2e8SPierre-Louis Bossart struct snd_soc_dai *codec_dai; 40f40ed2e8SPierre-Louis Bossart int device; 41f40ed2e8SPierre-Louis Bossart }; 42f40ed2e8SPierre-Louis Bossart 43f40ed2e8SPierre-Louis Bossart struct sof_card_private { 44f40ed2e8SPierre-Louis Bossart struct list_head hdmi_pcm_list; 45*15a5a895SKai Vehmanen bool idisp_codec; 46f40ed2e8SPierre-Louis Bossart }; 47f40ed2e8SPierre-Louis Bossart 48f40ed2e8SPierre-Louis Bossart static int sof_pcm512x_quirk_cb(const struct dmi_system_id *id) 49f40ed2e8SPierre-Louis Bossart { 50f40ed2e8SPierre-Louis Bossart sof_pcm512x_quirk = (unsigned long)id->driver_data; 51f40ed2e8SPierre-Louis Bossart return 1; 52f40ed2e8SPierre-Louis Bossart } 53f40ed2e8SPierre-Louis Bossart 54f40ed2e8SPierre-Louis Bossart static const struct dmi_system_id sof_pcm512x_quirk_table[] = { 55f40ed2e8SPierre-Louis Bossart { 56f40ed2e8SPierre-Louis Bossart .callback = sof_pcm512x_quirk_cb, 57f40ed2e8SPierre-Louis Bossart .matches = { 58f40ed2e8SPierre-Louis Bossart DMI_MATCH(DMI_SYS_VENDOR, "AAEON"), 59f40ed2e8SPierre-Louis Bossart DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"), 60f40ed2e8SPierre-Louis Bossart }, 61f40ed2e8SPierre-Louis Bossart .driver_data = (void *)(SOF_PCM512X_SSP_CODEC(2)), 62f40ed2e8SPierre-Louis Bossart }, 63f40ed2e8SPierre-Louis Bossart {} 64f40ed2e8SPierre-Louis Bossart }; 65f40ed2e8SPierre-Louis Bossart 66f40ed2e8SPierre-Louis Bossart static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd) 67f40ed2e8SPierre-Louis Bossart { 68f40ed2e8SPierre-Louis Bossart struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card); 69f40ed2e8SPierre-Louis Bossart struct snd_soc_dai *dai = rtd->codec_dai; 70f40ed2e8SPierre-Louis Bossart struct sof_hdmi_pcm *pcm; 71f40ed2e8SPierre-Louis Bossart 72f40ed2e8SPierre-Louis Bossart pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); 73f40ed2e8SPierre-Louis Bossart if (!pcm) 74f40ed2e8SPierre-Louis Bossart return -ENOMEM; 75f40ed2e8SPierre-Louis Bossart 76f40ed2e8SPierre-Louis Bossart /* dai_link id is 1:1 mapped to the PCM device */ 77f40ed2e8SPierre-Louis Bossart pcm->device = rtd->dai_link->id; 78f40ed2e8SPierre-Louis Bossart pcm->codec_dai = dai; 79f40ed2e8SPierre-Louis Bossart 80f40ed2e8SPierre-Louis Bossart list_add_tail(&pcm->head, &ctx->hdmi_pcm_list); 81f40ed2e8SPierre-Louis Bossart 82f40ed2e8SPierre-Louis Bossart return 0; 83f40ed2e8SPierre-Louis Bossart } 84f40ed2e8SPierre-Louis Bossart 85f40ed2e8SPierre-Louis Bossart static int sof_pcm512x_codec_init(struct snd_soc_pcm_runtime *rtd) 86f40ed2e8SPierre-Louis Bossart { 87f40ed2e8SPierre-Louis Bossart struct snd_soc_component *codec = rtd->codec_dai->component; 88f40ed2e8SPierre-Louis Bossart 89f40ed2e8SPierre-Louis Bossart snd_soc_component_update_bits(codec, PCM512x_GPIO_EN, 0x08, 0x08); 90f40ed2e8SPierre-Louis Bossart snd_soc_component_update_bits(codec, PCM512x_GPIO_OUTPUT_4, 0x0f, 0x02); 91f40ed2e8SPierre-Louis Bossart snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1, 92f40ed2e8SPierre-Louis Bossart 0x08, 0x08); 93f40ed2e8SPierre-Louis Bossart 94f40ed2e8SPierre-Louis Bossart return 0; 95f40ed2e8SPierre-Louis Bossart } 96f40ed2e8SPierre-Louis Bossart 97f40ed2e8SPierre-Louis Bossart static int aif1_startup(struct snd_pcm_substream *substream) 98f40ed2e8SPierre-Louis Bossart { 99f40ed2e8SPierre-Louis Bossart struct snd_soc_pcm_runtime *rtd = substream->private_data; 100f40ed2e8SPierre-Louis Bossart struct snd_soc_component *codec = rtd->codec_dai->component; 101f40ed2e8SPierre-Louis Bossart 102f40ed2e8SPierre-Louis Bossart snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1, 103f40ed2e8SPierre-Louis Bossart 0x08, 0x08); 104f40ed2e8SPierre-Louis Bossart 105f40ed2e8SPierre-Louis Bossart return 0; 106f40ed2e8SPierre-Louis Bossart } 107f40ed2e8SPierre-Louis Bossart 108f40ed2e8SPierre-Louis Bossart static void aif1_shutdown(struct snd_pcm_substream *substream) 109f40ed2e8SPierre-Louis Bossart { 110f40ed2e8SPierre-Louis Bossart struct snd_soc_pcm_runtime *rtd = substream->private_data; 111f40ed2e8SPierre-Louis Bossart struct snd_soc_component *codec = rtd->codec_dai->component; 112f40ed2e8SPierre-Louis Bossart 113f40ed2e8SPierre-Louis Bossart snd_soc_component_update_bits(codec, PCM512x_GPIO_CONTROL_1, 114f40ed2e8SPierre-Louis Bossart 0x08, 0x00); 115f40ed2e8SPierre-Louis Bossart } 116f40ed2e8SPierre-Louis Bossart 117f40ed2e8SPierre-Louis Bossart static const struct snd_soc_ops sof_pcm512x_ops = { 118f40ed2e8SPierre-Louis Bossart .startup = aif1_startup, 119f40ed2e8SPierre-Louis Bossart .shutdown = aif1_shutdown, 120f40ed2e8SPierre-Louis Bossart }; 121f40ed2e8SPierre-Louis Bossart 122f40ed2e8SPierre-Louis Bossart static struct snd_soc_dai_link_component platform_component[] = { 123f40ed2e8SPierre-Louis Bossart { 124f40ed2e8SPierre-Louis Bossart /* name might be overridden during probe */ 125f40ed2e8SPierre-Louis Bossart .name = "0000:00:1f.3" 126f40ed2e8SPierre-Louis Bossart } 127f40ed2e8SPierre-Louis Bossart }; 128f40ed2e8SPierre-Louis Bossart 129f40ed2e8SPierre-Louis Bossart #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) 130f40ed2e8SPierre-Louis Bossart static int sof_card_late_probe(struct snd_soc_card *card) 131f40ed2e8SPierre-Louis Bossart { 132f40ed2e8SPierre-Louis Bossart struct sof_card_private *ctx = snd_soc_card_get_drvdata(card); 133f40ed2e8SPierre-Louis Bossart struct sof_hdmi_pcm *pcm; 134f40ed2e8SPierre-Louis Bossart 135f40ed2e8SPierre-Louis Bossart /* HDMI is not supported by SOF on Baytrail/CherryTrail */ 136f40ed2e8SPierre-Louis Bossart if (is_legacy_cpu) 137f40ed2e8SPierre-Louis Bossart return 0; 138f40ed2e8SPierre-Louis Bossart 139f40ed2e8SPierre-Louis Bossart if (list_empty(&ctx->hdmi_pcm_list)) 140f40ed2e8SPierre-Louis Bossart return -EINVAL; 141f40ed2e8SPierre-Louis Bossart 142*15a5a895SKai Vehmanen if (!ctx->idisp_codec) 143*15a5a895SKai Vehmanen return 0; 144*15a5a895SKai Vehmanen 145f40ed2e8SPierre-Louis Bossart pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm, head); 146f40ed2e8SPierre-Louis Bossart 147f40ed2e8SPierre-Louis Bossart return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component); 148f40ed2e8SPierre-Louis Bossart } 149f40ed2e8SPierre-Louis Bossart #else 150f40ed2e8SPierre-Louis Bossart static int sof_card_late_probe(struct snd_soc_card *card) 151f40ed2e8SPierre-Louis Bossart { 152f40ed2e8SPierre-Louis Bossart return 0; 153f40ed2e8SPierre-Louis Bossart } 154f40ed2e8SPierre-Louis Bossart #endif 155f40ed2e8SPierre-Louis Bossart 156f40ed2e8SPierre-Louis Bossart static const struct snd_kcontrol_new sof_controls[] = { 157f40ed2e8SPierre-Louis Bossart SOC_DAPM_PIN_SWITCH("Ext Spk"), 158f40ed2e8SPierre-Louis Bossart }; 159f40ed2e8SPierre-Louis Bossart 160f40ed2e8SPierre-Louis Bossart static const struct snd_soc_dapm_widget sof_widgets[] = { 161f40ed2e8SPierre-Louis Bossart SND_SOC_DAPM_SPK("Ext Spk", NULL), 162f40ed2e8SPierre-Louis Bossart }; 163f40ed2e8SPierre-Louis Bossart 164f40ed2e8SPierre-Louis Bossart static const struct snd_soc_dapm_widget dmic_widgets[] = { 165f40ed2e8SPierre-Louis Bossart SND_SOC_DAPM_MIC("SoC DMIC", NULL), 166f40ed2e8SPierre-Louis Bossart }; 167f40ed2e8SPierre-Louis Bossart 168f40ed2e8SPierre-Louis Bossart static const struct snd_soc_dapm_route sof_map[] = { 169f40ed2e8SPierre-Louis Bossart /* Speaker */ 170f40ed2e8SPierre-Louis Bossart {"Ext Spk", NULL, "OUTR"}, 171f40ed2e8SPierre-Louis Bossart {"Ext Spk", NULL, "OUTL"}, 172f40ed2e8SPierre-Louis Bossart }; 173f40ed2e8SPierre-Louis Bossart 174f40ed2e8SPierre-Louis Bossart static const struct snd_soc_dapm_route dmic_map[] = { 175f40ed2e8SPierre-Louis Bossart /* digital mics */ 176f40ed2e8SPierre-Louis Bossart {"DMic", NULL, "SoC DMIC"}, 177f40ed2e8SPierre-Louis Bossart }; 178f40ed2e8SPierre-Louis Bossart 179f40ed2e8SPierre-Louis Bossart static int dmic_init(struct snd_soc_pcm_runtime *rtd) 180f40ed2e8SPierre-Louis Bossart { 181f40ed2e8SPierre-Louis Bossart struct snd_soc_card *card = rtd->card; 182f40ed2e8SPierre-Louis Bossart int ret; 183f40ed2e8SPierre-Louis Bossart 184f40ed2e8SPierre-Louis Bossart ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets, 185f40ed2e8SPierre-Louis Bossart ARRAY_SIZE(dmic_widgets)); 186f40ed2e8SPierre-Louis Bossart if (ret) { 187f40ed2e8SPierre-Louis Bossart dev_err(card->dev, "DMic widget addition failed: %d\n", ret); 188f40ed2e8SPierre-Louis Bossart /* Don't need to add routes if widget addition failed */ 189f40ed2e8SPierre-Louis Bossart return ret; 190f40ed2e8SPierre-Louis Bossart } 191f40ed2e8SPierre-Louis Bossart 192f40ed2e8SPierre-Louis Bossart ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map, 193f40ed2e8SPierre-Louis Bossart ARRAY_SIZE(dmic_map)); 194f40ed2e8SPierre-Louis Bossart 195f40ed2e8SPierre-Louis Bossart if (ret) 196f40ed2e8SPierre-Louis Bossart dev_err(card->dev, "DMic map addition failed: %d\n", ret); 197f40ed2e8SPierre-Louis Bossart 198f40ed2e8SPierre-Louis Bossart return ret; 199f40ed2e8SPierre-Louis Bossart } 200f40ed2e8SPierre-Louis Bossart 201f40ed2e8SPierre-Louis Bossart /* sof audio machine driver for pcm512x codec */ 202f40ed2e8SPierre-Louis Bossart static struct snd_soc_card sof_audio_card_pcm512x = { 203f40ed2e8SPierre-Louis Bossart .name = "pcm512x", 204f40ed2e8SPierre-Louis Bossart .owner = THIS_MODULE, 205f40ed2e8SPierre-Louis Bossart .controls = sof_controls, 206f40ed2e8SPierre-Louis Bossart .num_controls = ARRAY_SIZE(sof_controls), 207f40ed2e8SPierre-Louis Bossart .dapm_widgets = sof_widgets, 208f40ed2e8SPierre-Louis Bossart .num_dapm_widgets = ARRAY_SIZE(sof_widgets), 209f40ed2e8SPierre-Louis Bossart .dapm_routes = sof_map, 210f40ed2e8SPierre-Louis Bossart .num_dapm_routes = ARRAY_SIZE(sof_map), 211f40ed2e8SPierre-Louis Bossart .fully_routed = true, 212f40ed2e8SPierre-Louis Bossart .late_probe = sof_card_late_probe, 213f40ed2e8SPierre-Louis Bossart }; 214f40ed2e8SPierre-Louis Bossart 215f40ed2e8SPierre-Louis Bossart SND_SOC_DAILINK_DEF(pcm512x_component, 216f40ed2e8SPierre-Louis Bossart DAILINK_COMP_ARRAY(COMP_CODEC("i2c-104C5122:00", "pcm512x-hifi"))); 217f40ed2e8SPierre-Louis Bossart SND_SOC_DAILINK_DEF(dmic_component, 218f40ed2e8SPierre-Louis Bossart DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi"))); 219f40ed2e8SPierre-Louis Bossart 220f40ed2e8SPierre-Louis Bossart static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, 221f40ed2e8SPierre-Louis Bossart int ssp_codec, 222f40ed2e8SPierre-Louis Bossart int dmic_be_num, 223*15a5a895SKai Vehmanen int hdmi_num, 224*15a5a895SKai Vehmanen bool idisp_codec) 225f40ed2e8SPierre-Louis Bossart { 226f40ed2e8SPierre-Louis Bossart struct snd_soc_dai_link_component *idisp_components; 227f40ed2e8SPierre-Louis Bossart struct snd_soc_dai_link_component *cpus; 228f40ed2e8SPierre-Louis Bossart struct snd_soc_dai_link *links; 229f40ed2e8SPierre-Louis Bossart int i, id = 0; 230f40ed2e8SPierre-Louis Bossart 231f40ed2e8SPierre-Louis Bossart links = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links, 232f40ed2e8SPierre-Louis Bossart sizeof(struct snd_soc_dai_link), GFP_KERNEL); 233f40ed2e8SPierre-Louis Bossart cpus = devm_kcalloc(dev, sof_audio_card_pcm512x.num_links, 234f40ed2e8SPierre-Louis Bossart sizeof(struct snd_soc_dai_link_component), GFP_KERNEL); 235f40ed2e8SPierre-Louis Bossart if (!links || !cpus) 236f40ed2e8SPierre-Louis Bossart goto devm_err; 237f40ed2e8SPierre-Louis Bossart 238f40ed2e8SPierre-Louis Bossart /* codec SSP */ 239f40ed2e8SPierre-Louis Bossart links[id].name = devm_kasprintf(dev, GFP_KERNEL, 240f40ed2e8SPierre-Louis Bossart "SSP%d-Codec", ssp_codec); 241f40ed2e8SPierre-Louis Bossart if (!links[id].name) 242f40ed2e8SPierre-Louis Bossart goto devm_err; 243f40ed2e8SPierre-Louis Bossart 244f40ed2e8SPierre-Louis Bossart links[id].id = id; 245f40ed2e8SPierre-Louis Bossart links[id].codecs = pcm512x_component; 246f40ed2e8SPierre-Louis Bossart links[id].num_codecs = ARRAY_SIZE(pcm512x_component); 247f40ed2e8SPierre-Louis Bossart links[id].platforms = platform_component; 248f40ed2e8SPierre-Louis Bossart links[id].num_platforms = ARRAY_SIZE(platform_component); 249f40ed2e8SPierre-Louis Bossart links[id].init = sof_pcm512x_codec_init; 250f40ed2e8SPierre-Louis Bossart links[id].ops = &sof_pcm512x_ops; 251f40ed2e8SPierre-Louis Bossart links[id].nonatomic = true; 252f40ed2e8SPierre-Louis Bossart links[id].dpcm_playback = 1; 253f40ed2e8SPierre-Louis Bossart /* 254f40ed2e8SPierre-Louis Bossart * capture only supported with specific versions of the Hifiberry DAC+ 255f40ed2e8SPierre-Louis Bossart * links[id].dpcm_capture = 1; 256f40ed2e8SPierre-Louis Bossart */ 257f40ed2e8SPierre-Louis Bossart links[id].no_pcm = 1; 258f40ed2e8SPierre-Louis Bossart links[id].cpus = &cpus[id]; 259f40ed2e8SPierre-Louis Bossart links[id].num_cpus = 1; 260f40ed2e8SPierre-Louis Bossart if (is_legacy_cpu) { 261f40ed2e8SPierre-Louis Bossart links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, 262f40ed2e8SPierre-Louis Bossart "ssp%d-port", 263f40ed2e8SPierre-Louis Bossart ssp_codec); 264f40ed2e8SPierre-Louis Bossart if (!links[id].cpus->dai_name) 265f40ed2e8SPierre-Louis Bossart goto devm_err; 266f40ed2e8SPierre-Louis Bossart } else { 267f40ed2e8SPierre-Louis Bossart links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, 268f40ed2e8SPierre-Louis Bossart "SSP%d Pin", 269f40ed2e8SPierre-Louis Bossart ssp_codec); 270f40ed2e8SPierre-Louis Bossart if (!links[id].cpus->dai_name) 271f40ed2e8SPierre-Louis Bossart goto devm_err; 272f40ed2e8SPierre-Louis Bossart } 273f40ed2e8SPierre-Louis Bossart id++; 274f40ed2e8SPierre-Louis Bossart 275f40ed2e8SPierre-Louis Bossart /* dmic */ 276f40ed2e8SPierre-Louis Bossart if (dmic_be_num > 0) { 277f40ed2e8SPierre-Louis Bossart /* at least we have dmic01 */ 278f40ed2e8SPierre-Louis Bossart links[id].name = "dmic01"; 279f40ed2e8SPierre-Louis Bossart links[id].cpus = &cpus[id]; 280f40ed2e8SPierre-Louis Bossart links[id].cpus->dai_name = "DMIC01 Pin"; 281f40ed2e8SPierre-Louis Bossart links[id].init = dmic_init; 282f40ed2e8SPierre-Louis Bossart if (dmic_be_num > 1) { 283f40ed2e8SPierre-Louis Bossart /* set up 2 BE links at most */ 284f40ed2e8SPierre-Louis Bossart links[id + 1].name = "dmic16k"; 285f40ed2e8SPierre-Louis Bossart links[id + 1].cpus = &cpus[id + 1]; 286f40ed2e8SPierre-Louis Bossart links[id + 1].cpus->dai_name = "DMIC16k Pin"; 287f40ed2e8SPierre-Louis Bossart dmic_be_num = 2; 288f40ed2e8SPierre-Louis Bossart } 289f40ed2e8SPierre-Louis Bossart } 290f40ed2e8SPierre-Louis Bossart 291f40ed2e8SPierre-Louis Bossart for (i = 0; i < dmic_be_num; i++) { 292f40ed2e8SPierre-Louis Bossart links[id].id = id; 293f40ed2e8SPierre-Louis Bossart links[id].num_cpus = 1; 294f40ed2e8SPierre-Louis Bossart links[id].codecs = dmic_component; 295f40ed2e8SPierre-Louis Bossart links[id].num_codecs = ARRAY_SIZE(dmic_component); 296f40ed2e8SPierre-Louis Bossart links[id].platforms = platform_component; 297f40ed2e8SPierre-Louis Bossart links[id].num_platforms = ARRAY_SIZE(platform_component); 298f40ed2e8SPierre-Louis Bossart links[id].ignore_suspend = 1; 299f40ed2e8SPierre-Louis Bossart links[id].dpcm_capture = 1; 300f40ed2e8SPierre-Louis Bossart links[id].no_pcm = 1; 301f40ed2e8SPierre-Louis Bossart id++; 302f40ed2e8SPierre-Louis Bossart } 303f40ed2e8SPierre-Louis Bossart 304f40ed2e8SPierre-Louis Bossart /* HDMI */ 305f40ed2e8SPierre-Louis Bossart if (hdmi_num > 0) { 306f40ed2e8SPierre-Louis Bossart idisp_components = devm_kcalloc(dev, hdmi_num, 307f40ed2e8SPierre-Louis Bossart sizeof(struct snd_soc_dai_link_component), 308f40ed2e8SPierre-Louis Bossart GFP_KERNEL); 309f40ed2e8SPierre-Louis Bossart if (!idisp_components) 310f40ed2e8SPierre-Louis Bossart goto devm_err; 311f40ed2e8SPierre-Louis Bossart } 312f40ed2e8SPierre-Louis Bossart for (i = 1; i <= hdmi_num; i++) { 313f40ed2e8SPierre-Louis Bossart links[id].name = devm_kasprintf(dev, GFP_KERNEL, 314f40ed2e8SPierre-Louis Bossart "iDisp%d", i); 315f40ed2e8SPierre-Louis Bossart if (!links[id].name) 316f40ed2e8SPierre-Louis Bossart goto devm_err; 317f40ed2e8SPierre-Louis Bossart 318f40ed2e8SPierre-Louis Bossart links[id].id = id; 319f40ed2e8SPierre-Louis Bossart links[id].cpus = &cpus[id]; 320f40ed2e8SPierre-Louis Bossart links[id].num_cpus = 1; 321f40ed2e8SPierre-Louis Bossart links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, 322f40ed2e8SPierre-Louis Bossart "iDisp%d Pin", i); 323f40ed2e8SPierre-Louis Bossart if (!links[id].cpus->dai_name) 324f40ed2e8SPierre-Louis Bossart goto devm_err; 325f40ed2e8SPierre-Louis Bossart 326*15a5a895SKai Vehmanen /* 327*15a5a895SKai Vehmanen * topology cannot be loaded if codec is missing, so 328*15a5a895SKai Vehmanen * use the dummy codec if needed 329*15a5a895SKai Vehmanen */ 330*15a5a895SKai Vehmanen if (idisp_codec) { 331f40ed2e8SPierre-Louis Bossart idisp_components[i - 1].name = "ehdaudio0D2"; 332*15a5a895SKai Vehmanen idisp_components[i - 1].dai_name = 333*15a5a895SKai Vehmanen devm_kasprintf(dev, GFP_KERNEL, 334*15a5a895SKai Vehmanen "intel-hdmi-hifi%d", i); 335*15a5a895SKai Vehmanen } else { 336*15a5a895SKai Vehmanen idisp_components[i - 1].name = "snd-soc-dummy"; 337*15a5a895SKai Vehmanen idisp_components[i - 1].dai_name = "snd-soc-dummy-dai"; 338*15a5a895SKai Vehmanen } 339f40ed2e8SPierre-Louis Bossart if (!idisp_components[i - 1].dai_name) 340f40ed2e8SPierre-Louis Bossart goto devm_err; 341f40ed2e8SPierre-Louis Bossart 342f40ed2e8SPierre-Louis Bossart links[id].codecs = &idisp_components[i - 1]; 343f40ed2e8SPierre-Louis Bossart links[id].num_codecs = 1; 344f40ed2e8SPierre-Louis Bossart links[id].platforms = platform_component; 345f40ed2e8SPierre-Louis Bossart links[id].num_platforms = ARRAY_SIZE(platform_component); 346f40ed2e8SPierre-Louis Bossart links[id].init = sof_hdmi_init; 347f40ed2e8SPierre-Louis Bossart links[id].dpcm_playback = 1; 348f40ed2e8SPierre-Louis Bossart links[id].no_pcm = 1; 349f40ed2e8SPierre-Louis Bossart id++; 350f40ed2e8SPierre-Louis Bossart } 351f40ed2e8SPierre-Louis Bossart 352f40ed2e8SPierre-Louis Bossart return links; 353f40ed2e8SPierre-Louis Bossart devm_err: 354f40ed2e8SPierre-Louis Bossart return NULL; 355f40ed2e8SPierre-Louis Bossart } 356f40ed2e8SPierre-Louis Bossart 357f40ed2e8SPierre-Louis Bossart static int sof_audio_probe(struct platform_device *pdev) 358f40ed2e8SPierre-Louis Bossart { 359*15a5a895SKai Vehmanen struct snd_soc_acpi_mach *mach = pdev->dev.platform_data; 360f40ed2e8SPierre-Louis Bossart struct snd_soc_dai_link *dai_links; 361f40ed2e8SPierre-Louis Bossart struct sof_card_private *ctx; 362f40ed2e8SPierre-Louis Bossart int dmic_be_num, hdmi_num; 363f40ed2e8SPierre-Louis Bossart int ret, ssp_codec; 364f40ed2e8SPierre-Louis Bossart 365f40ed2e8SPierre-Louis Bossart ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 366f40ed2e8SPierre-Louis Bossart if (!ctx) 367f40ed2e8SPierre-Louis Bossart return -ENOMEM; 368f40ed2e8SPierre-Louis Bossart 369f40ed2e8SPierre-Louis Bossart hdmi_num = 0; 370f40ed2e8SPierre-Louis Bossart if (soc_intel_is_byt() || soc_intel_is_cht()) { 371f40ed2e8SPierre-Louis Bossart is_legacy_cpu = true; 372f40ed2e8SPierre-Louis Bossart dmic_be_num = 0; 373f40ed2e8SPierre-Louis Bossart /* default quirk for legacy cpu */ 374f40ed2e8SPierre-Louis Bossart sof_pcm512x_quirk = SOF_PCM512X_SSP_CODEC(2); 375f40ed2e8SPierre-Louis Bossart } else { 376f40ed2e8SPierre-Louis Bossart dmic_be_num = 2; 377f40ed2e8SPierre-Louis Bossart #if IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI) 378*15a5a895SKai Vehmanen if (mach->mach_params.common_hdmi_codec_drv && 379*15a5a895SKai Vehmanen (mach->mach_params.codec_mask & IDISP_CODEC_MASK)) 380*15a5a895SKai Vehmanen ctx->idisp_codec = true; 381*15a5a895SKai Vehmanen 382*15a5a895SKai Vehmanen /* links are always present in topology */ 383f40ed2e8SPierre-Louis Bossart hdmi_num = 3; 384f40ed2e8SPierre-Louis Bossart #endif 385f40ed2e8SPierre-Louis Bossart } 386f40ed2e8SPierre-Louis Bossart 387f40ed2e8SPierre-Louis Bossart dmi_check_system(sof_pcm512x_quirk_table); 388f40ed2e8SPierre-Louis Bossart 389f40ed2e8SPierre-Louis Bossart dev_dbg(&pdev->dev, "sof_pcm512x_quirk = %lx\n", sof_pcm512x_quirk); 390f40ed2e8SPierre-Louis Bossart 391f40ed2e8SPierre-Louis Bossart ssp_codec = sof_pcm512x_quirk & SOF_PCM512X_SSP_CODEC_MASK; 392f40ed2e8SPierre-Louis Bossart 393f40ed2e8SPierre-Louis Bossart /* compute number of dai links */ 394f40ed2e8SPierre-Louis Bossart sof_audio_card_pcm512x.num_links = 1 + dmic_be_num + hdmi_num; 395f40ed2e8SPierre-Louis Bossart 396f40ed2e8SPierre-Louis Bossart dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, 397*15a5a895SKai Vehmanen dmic_be_num, hdmi_num, 398*15a5a895SKai Vehmanen ctx->idisp_codec); 399f40ed2e8SPierre-Louis Bossart if (!dai_links) 400f40ed2e8SPierre-Louis Bossart return -ENOMEM; 401f40ed2e8SPierre-Louis Bossart 402f40ed2e8SPierre-Louis Bossart sof_audio_card_pcm512x.dai_link = dai_links; 403f40ed2e8SPierre-Louis Bossart 404f40ed2e8SPierre-Louis Bossart INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 405f40ed2e8SPierre-Louis Bossart 406f40ed2e8SPierre-Louis Bossart sof_audio_card_pcm512x.dev = &pdev->dev; 407f40ed2e8SPierre-Louis Bossart 408f40ed2e8SPierre-Louis Bossart /* set platform name for each dailink */ 409f40ed2e8SPierre-Louis Bossart ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_pcm512x, 410f40ed2e8SPierre-Louis Bossart mach->mach_params.platform); 411f40ed2e8SPierre-Louis Bossart if (ret) 412f40ed2e8SPierre-Louis Bossart return ret; 413f40ed2e8SPierre-Louis Bossart 414f40ed2e8SPierre-Louis Bossart snd_soc_card_set_drvdata(&sof_audio_card_pcm512x, ctx); 415f40ed2e8SPierre-Louis Bossart 416f40ed2e8SPierre-Louis Bossart return devm_snd_soc_register_card(&pdev->dev, 417f40ed2e8SPierre-Louis Bossart &sof_audio_card_pcm512x); 418f40ed2e8SPierre-Louis Bossart } 419f40ed2e8SPierre-Louis Bossart 420f40ed2e8SPierre-Louis Bossart static int sof_pcm512x_remove(struct platform_device *pdev) 421f40ed2e8SPierre-Louis Bossart { 422f40ed2e8SPierre-Louis Bossart struct snd_soc_card *card = platform_get_drvdata(pdev); 423f40ed2e8SPierre-Louis Bossart struct snd_soc_component *component = NULL; 424f40ed2e8SPierre-Louis Bossart 425f40ed2e8SPierre-Louis Bossart for_each_card_components(card, component) { 426f40ed2e8SPierre-Louis Bossart if (!strcmp(component->name, pcm512x_component[0].name)) { 427f40ed2e8SPierre-Louis Bossart snd_soc_component_set_jack(component, NULL, NULL); 428f40ed2e8SPierre-Louis Bossart break; 429f40ed2e8SPierre-Louis Bossart } 430f40ed2e8SPierre-Louis Bossart } 431f40ed2e8SPierre-Louis Bossart 432f40ed2e8SPierre-Louis Bossart return 0; 433f40ed2e8SPierre-Louis Bossart } 434f40ed2e8SPierre-Louis Bossart 435f40ed2e8SPierre-Louis Bossart static struct platform_driver sof_audio = { 436f40ed2e8SPierre-Louis Bossart .probe = sof_audio_probe, 437f40ed2e8SPierre-Louis Bossart .remove = sof_pcm512x_remove, 438f40ed2e8SPierre-Louis Bossart .driver = { 439f40ed2e8SPierre-Louis Bossart .name = "sof_pcm512x", 440f40ed2e8SPierre-Louis Bossart .pm = &snd_soc_pm_ops, 441f40ed2e8SPierre-Louis Bossart }, 442f40ed2e8SPierre-Louis Bossart }; 443f40ed2e8SPierre-Louis Bossart module_platform_driver(sof_audio) 444f40ed2e8SPierre-Louis Bossart 445f40ed2e8SPierre-Louis Bossart MODULE_DESCRIPTION("ASoC Intel(R) SOF + PCM512x Machine driver"); 446f40ed2e8SPierre-Louis Bossart MODULE_AUTHOR("Pierre-Louis Bossart"); 447f40ed2e8SPierre-Louis Bossart MODULE_LICENSE("GPL v2"); 448f40ed2e8SPierre-Louis Bossart MODULE_ALIAS("platform:sof_pcm512x"); 449