18b99e24dSCezary Rojewski // SPDX-License-Identifier: GPL-2.0-only 28b99e24dSCezary Rojewski /* 38b99e24dSCezary Rojewski * Intel Haswell Lynxpoint SST Audio 48b99e24dSCezary Rojewski * 58b99e24dSCezary Rojewski * Copyright (C) 2013, Intel Corporation. All rights reserved. 68b99e24dSCezary Rojewski */ 78b99e24dSCezary Rojewski 88b99e24dSCezary Rojewski #include <linux/module.h> 98b99e24dSCezary Rojewski #include <linux/platform_device.h> 108b99e24dSCezary Rojewski #include <sound/core.h> 118b99e24dSCezary Rojewski #include <sound/pcm.h> 12*5b66dde4SCezary Rojewski #include <sound/pcm_params.h> 138b99e24dSCezary Rojewski #include <sound/soc.h> 148b99e24dSCezary Rojewski #include <sound/soc-acpi.h> 158b99e24dSCezary Rojewski #include "../../codecs/rt5640.h" 168b99e24dSCezary Rojewski 178b99e24dSCezary Rojewski /* Haswell ULT platforms have a Headphone and Mic jack */ 18675002b6SCezary Rojewski static const struct snd_soc_dapm_widget card_widgets[] = { 198b99e24dSCezary Rojewski SND_SOC_DAPM_HP("Headphones", NULL), 208b99e24dSCezary Rojewski SND_SOC_DAPM_MIC("Mic", NULL), 218b99e24dSCezary Rojewski }; 228b99e24dSCezary Rojewski 23675002b6SCezary Rojewski static const struct snd_soc_dapm_route card_routes[] = { 248b99e24dSCezary Rojewski {"Headphones", NULL, "HPOR"}, 258b99e24dSCezary Rojewski {"Headphones", NULL, "HPOL"}, 268b99e24dSCezary Rojewski {"IN2P", NULL, "Mic"}, 278b99e24dSCezary Rojewski 288b99e24dSCezary Rojewski /* CODEC BE connections */ 298b99e24dSCezary Rojewski {"SSP0 CODEC IN", NULL, "AIF1 Capture"}, 308b99e24dSCezary Rojewski {"AIF1 Playback", NULL, "SSP0 CODEC OUT"}, 318b99e24dSCezary Rojewski }; 328b99e24dSCezary Rojewski 33675002b6SCezary Rojewski static int codec_link_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 348b99e24dSCezary Rojewski struct snd_pcm_hw_params *params) 358b99e24dSCezary Rojewski { 36*5b66dde4SCezary Rojewski struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 37*5b66dde4SCezary Rojewski struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 388b99e24dSCezary Rojewski 398b99e24dSCezary Rojewski /* The ADSP will covert the FE rate to 48k, stereo */ 408b99e24dSCezary Rojewski rate->min = rate->max = 48000; 418b99e24dSCezary Rojewski channels->min = channels->max = 2; 428b99e24dSCezary Rojewski /* set SSP0 to 16 bit */ 438b99e24dSCezary Rojewski params_set_format(params, SNDRV_PCM_FORMAT_S16_LE); 44*5b66dde4SCezary Rojewski 458b99e24dSCezary Rojewski return 0; 468b99e24dSCezary Rojewski } 478b99e24dSCezary Rojewski 48675002b6SCezary Rojewski static int codec_link_hw_params(struct snd_pcm_substream *substream, 498b99e24dSCezary Rojewski struct snd_pcm_hw_params *params) 508b99e24dSCezary Rojewski { 518b99e24dSCezary Rojewski struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 528b99e24dSCezary Rojewski struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 538b99e24dSCezary Rojewski int ret; 548b99e24dSCezary Rojewski 55*5b66dde4SCezary Rojewski ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000, SND_SOC_CLOCK_IN); 568b99e24dSCezary Rojewski if (ret < 0) { 578b99e24dSCezary Rojewski dev_err(rtd->dev, "can't set codec sysclk configuration\n"); 588b99e24dSCezary Rojewski return ret; 598b99e24dSCezary Rojewski } 608b99e24dSCezary Rojewski 618b99e24dSCezary Rojewski /* set correct codec filter for DAI format and clock config */ 628b99e24dSCezary Rojewski snd_soc_component_update_bits(codec_dai->component, 0x83, 0xffff, 0x8000); 638b99e24dSCezary Rojewski 648b99e24dSCezary Rojewski return ret; 658b99e24dSCezary Rojewski } 668b99e24dSCezary Rojewski 67675002b6SCezary Rojewski static const struct snd_soc_ops codec_link_ops = { 68675002b6SCezary Rojewski .hw_params = codec_link_hw_params, 698b99e24dSCezary Rojewski }; 708b99e24dSCezary Rojewski 71*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(system, DAILINK_COMP_ARRAY(COMP_CPU("System Pin"))); 72*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(offload0, DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin"))); 73*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(offload1, DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin"))); 74*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(loopback, DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin"))); 758b99e24dSCezary Rojewski 76*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(dummy, DAILINK_COMP_ARRAY(COMP_DUMMY())); 77*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(codec, DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT33CA:00", "rt5640-aif1"))); 78*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio"))); 79*5b66dde4SCezary Rojewski SND_SOC_DAILINK_DEF(ssp0_port, DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port"))); 808b99e24dSCezary Rojewski 81675002b6SCezary Rojewski static struct snd_soc_dai_link card_dai_links[] = { 828b99e24dSCezary Rojewski /* Front End DAI links */ 838b99e24dSCezary Rojewski { 848b99e24dSCezary Rojewski .name = "System", 858b99e24dSCezary Rojewski .stream_name = "System Playback/Capture", 868b99e24dSCezary Rojewski .nonatomic = 1, 878b99e24dSCezary Rojewski .dynamic = 1, 888b99e24dSCezary Rojewski .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 898b99e24dSCezary Rojewski .dpcm_playback = 1, 908b99e24dSCezary Rojewski .dpcm_capture = 1, 918b99e24dSCezary Rojewski SND_SOC_DAILINK_REG(system, dummy, platform), 928b99e24dSCezary Rojewski }, 938b99e24dSCezary Rojewski { 948b99e24dSCezary Rojewski .name = "Offload0", 958b99e24dSCezary Rojewski .stream_name = "Offload0 Playback", 968b99e24dSCezary Rojewski .nonatomic = 1, 978b99e24dSCezary Rojewski .dynamic = 1, 988b99e24dSCezary Rojewski .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 998b99e24dSCezary Rojewski .dpcm_playback = 1, 1008b99e24dSCezary Rojewski SND_SOC_DAILINK_REG(offload0, dummy, platform), 1018b99e24dSCezary Rojewski }, 1028b99e24dSCezary Rojewski { 1038b99e24dSCezary Rojewski .name = "Offload1", 1048b99e24dSCezary Rojewski .stream_name = "Offload1 Playback", 1058b99e24dSCezary Rojewski .nonatomic = 1, 1068b99e24dSCezary Rojewski .dynamic = 1, 1078b99e24dSCezary Rojewski .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 1088b99e24dSCezary Rojewski .dpcm_playback = 1, 1098b99e24dSCezary Rojewski SND_SOC_DAILINK_REG(offload1, dummy, platform), 1108b99e24dSCezary Rojewski }, 1118b99e24dSCezary Rojewski { 1128b99e24dSCezary Rojewski .name = "Loopback", 1138b99e24dSCezary Rojewski .stream_name = "Loopback", 1148b99e24dSCezary Rojewski .nonatomic = 1, 1158b99e24dSCezary Rojewski .dynamic = 1, 1168b99e24dSCezary Rojewski .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 1178b99e24dSCezary Rojewski .dpcm_capture = 1, 1188b99e24dSCezary Rojewski SND_SOC_DAILINK_REG(loopback, dummy, platform), 1198b99e24dSCezary Rojewski }, 1208b99e24dSCezary Rojewski /* Back End DAI links */ 1218b99e24dSCezary Rojewski { 1228b99e24dSCezary Rojewski /* SSP0 - Codec */ 1238b99e24dSCezary Rojewski .name = "Codec", 1248b99e24dSCezary Rojewski .id = 0, 1258b99e24dSCezary Rojewski .no_pcm = 1, 126*5b66dde4SCezary Rojewski .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC, 1278b99e24dSCezary Rojewski .ignore_pmdown_time = 1, 128675002b6SCezary Rojewski .be_hw_params_fixup = codec_link_hw_params_fixup, 129675002b6SCezary Rojewski .ops = &codec_link_ops, 1308b99e24dSCezary Rojewski .dpcm_playback = 1, 1318b99e24dSCezary Rojewski .dpcm_capture = 1, 1328b99e24dSCezary Rojewski SND_SOC_DAILINK_REG(ssp0_port, codec, platform), 1338b99e24dSCezary Rojewski }, 1348b99e24dSCezary Rojewski }; 1358b99e24dSCezary Rojewski 1368b99e24dSCezary Rojewski /* audio machine driver for Haswell Lynxpoint DSP + RT5640 */ 137675002b6SCezary Rojewski static struct snd_soc_card hsw_rt5640_card = { 1388b99e24dSCezary Rojewski .name = "haswell-rt5640", 1398b99e24dSCezary Rojewski .owner = THIS_MODULE, 140675002b6SCezary Rojewski .dai_link = card_dai_links, 141675002b6SCezary Rojewski .num_links = ARRAY_SIZE(card_dai_links), 142675002b6SCezary Rojewski .dapm_widgets = card_widgets, 143675002b6SCezary Rojewski .num_dapm_widgets = ARRAY_SIZE(card_widgets), 144675002b6SCezary Rojewski .dapm_routes = card_routes, 145675002b6SCezary Rojewski .num_dapm_routes = ARRAY_SIZE(card_routes), 1468b99e24dSCezary Rojewski .fully_routed = true, 1478b99e24dSCezary Rojewski }; 1488b99e24dSCezary Rojewski 149675002b6SCezary Rojewski static int hsw_rt5640_probe(struct platform_device *pdev) 1508b99e24dSCezary Rojewski { 1518b99e24dSCezary Rojewski struct snd_soc_acpi_mach *mach; 1528b99e24dSCezary Rojewski int ret; 1538b99e24dSCezary Rojewski 154675002b6SCezary Rojewski hsw_rt5640_card.dev = &pdev->dev; 1558b99e24dSCezary Rojewski /* override platform name, if required */ 1568b99e24dSCezary Rojewski mach = pdev->dev.platform_data; 157*5b66dde4SCezary Rojewski 158*5b66dde4SCezary Rojewski ret = snd_soc_fixup_dai_links_platform_name(&hsw_rt5640_card, mach->mach_params.platform); 1598b99e24dSCezary Rojewski if (ret) 1608b99e24dSCezary Rojewski return ret; 1618b99e24dSCezary Rojewski 162675002b6SCezary Rojewski return devm_snd_soc_register_card(&pdev->dev, &hsw_rt5640_card); 1638b99e24dSCezary Rojewski } 1648b99e24dSCezary Rojewski 165675002b6SCezary Rojewski static struct platform_driver hsw_rt5640_driver = { 166675002b6SCezary Rojewski .probe = hsw_rt5640_probe, 1678b99e24dSCezary Rojewski .driver = { 168a69615e8SCezary Rojewski .name = "hsw_rt5640", 1698b99e24dSCezary Rojewski .pm = &snd_soc_pm_ops, 1708b99e24dSCezary Rojewski }, 1718b99e24dSCezary Rojewski }; 1728b99e24dSCezary Rojewski 173675002b6SCezary Rojewski module_platform_driver(hsw_rt5640_driver) 1748b99e24dSCezary Rojewski 1758b99e24dSCezary Rojewski /* Module information */ 1768b99e24dSCezary Rojewski MODULE_AUTHOR("Liam Girdwood, Xingchao Wang"); 1778b99e24dSCezary Rojewski MODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint"); 1788b99e24dSCezary Rojewski MODULE_LICENSE("GPL v2"); 179a69615e8SCezary Rojewski MODULE_ALIAS("platform:hsw_rt5640"); 180