18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Intel Haswell Lynxpoint SST Audio
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2013, Intel Corporation. All rights reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/module.h>
98c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
108c2ecf20Sopenharmony_ci#include <sound/core.h>
118c2ecf20Sopenharmony_ci#include <sound/pcm.h>
128c2ecf20Sopenharmony_ci#include <sound/soc.h>
138c2ecf20Sopenharmony_ci#include <sound/soc-acpi.h>
148c2ecf20Sopenharmony_ci#include <sound/pcm_params.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "../../codecs/rt5640.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* Haswell ULT platforms have a Headphone and Mic jack */
198c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget haswell_widgets[] = {
208c2ecf20Sopenharmony_ci	SND_SOC_DAPM_HP("Headphones", NULL),
218c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIC("Mic", NULL),
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route haswell_rt5640_map[] = {
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	{"Headphones", NULL, "HPOR"},
278c2ecf20Sopenharmony_ci	{"Headphones", NULL, "HPOL"},
288c2ecf20Sopenharmony_ci	{"IN2P", NULL, "Mic"},
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	/* CODEC BE connections */
318c2ecf20Sopenharmony_ci	{"SSP0 CODEC IN", NULL, "AIF1 Capture"},
328c2ecf20Sopenharmony_ci	{"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic int haswell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
368c2ecf20Sopenharmony_ci			struct snd_pcm_hw_params *params)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	struct snd_interval *rate = hw_param_interval(params,
398c2ecf20Sopenharmony_ci			SNDRV_PCM_HW_PARAM_RATE);
408c2ecf20Sopenharmony_ci	struct snd_interval *channels = hw_param_interval(params,
418c2ecf20Sopenharmony_ci						SNDRV_PCM_HW_PARAM_CHANNELS);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	/* The ADSP will covert the FE rate to 48k, stereo */
448c2ecf20Sopenharmony_ci	rate->min = rate->max = 48000;
458c2ecf20Sopenharmony_ci	channels->min = channels->max = 2;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	/* set SSP0 to 16 bit */
488c2ecf20Sopenharmony_ci	params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
498c2ecf20Sopenharmony_ci	return 0;
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic int haswell_rt5640_hw_params(struct snd_pcm_substream *substream,
538c2ecf20Sopenharmony_ci	struct snd_pcm_hw_params *params)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
568c2ecf20Sopenharmony_ci	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
578c2ecf20Sopenharmony_ci	int ret;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000,
608c2ecf20Sopenharmony_ci		SND_SOC_CLOCK_IN);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	if (ret < 0) {
638c2ecf20Sopenharmony_ci		dev_err(rtd->dev, "can't set codec sysclk configuration\n");
648c2ecf20Sopenharmony_ci		return ret;
658c2ecf20Sopenharmony_ci	}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	/* set correct codec filter for DAI format and clock config */
688c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(codec_dai->component, 0x83, 0xffff, 0x8000);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	return ret;
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic const struct snd_soc_ops haswell_rt5640_ops = {
748c2ecf20Sopenharmony_ci	.hw_params = haswell_rt5640_hw_params,
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(dummy,
788c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_DUMMY()));
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(system,
818c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CPU("System Pin")));
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(offload0,
848c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CPU("Offload0 Pin")));
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(offload1,
878c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CPU("Offload1 Pin")));
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(loopback,
908c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CPU("Loopback Pin")));
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(codec,
938c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-INT33CA:00", "rt5640-aif1")));
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(platform,
968c2ecf20Sopenharmony_ci	DAILINK_COMP_ARRAY(COMP_PLATFORM("haswell-pcm-audio")));
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEF(ssp0_port,
998c2ecf20Sopenharmony_ci	    DAILINK_COMP_ARRAY(COMP_CPU("ssp0-port")));
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cistatic struct snd_soc_dai_link haswell_rt5640_dais[] = {
1028c2ecf20Sopenharmony_ci	/* Front End DAI links */
1038c2ecf20Sopenharmony_ci	{
1048c2ecf20Sopenharmony_ci		.name = "System",
1058c2ecf20Sopenharmony_ci		.stream_name = "System Playback/Capture",
1068c2ecf20Sopenharmony_ci		.nonatomic = 1,
1078c2ecf20Sopenharmony_ci		.dynamic = 1,
1088c2ecf20Sopenharmony_ci		.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1098c2ecf20Sopenharmony_ci		.dpcm_playback = 1,
1108c2ecf20Sopenharmony_ci		.dpcm_capture = 1,
1118c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(system, dummy, platform),
1128c2ecf20Sopenharmony_ci	},
1138c2ecf20Sopenharmony_ci	{
1148c2ecf20Sopenharmony_ci		.name = "Offload0",
1158c2ecf20Sopenharmony_ci		.stream_name = "Offload0 Playback",
1168c2ecf20Sopenharmony_ci		.nonatomic = 1,
1178c2ecf20Sopenharmony_ci		.dynamic = 1,
1188c2ecf20Sopenharmony_ci		.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1198c2ecf20Sopenharmony_ci		.dpcm_playback = 1,
1208c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(offload0, dummy, platform),
1218c2ecf20Sopenharmony_ci	},
1228c2ecf20Sopenharmony_ci	{
1238c2ecf20Sopenharmony_ci		.name = "Offload1",
1248c2ecf20Sopenharmony_ci		.stream_name = "Offload1 Playback",
1258c2ecf20Sopenharmony_ci		.nonatomic = 1,
1268c2ecf20Sopenharmony_ci		.dynamic = 1,
1278c2ecf20Sopenharmony_ci		.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1288c2ecf20Sopenharmony_ci		.dpcm_playback = 1,
1298c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(offload1, dummy, platform),
1308c2ecf20Sopenharmony_ci	},
1318c2ecf20Sopenharmony_ci	{
1328c2ecf20Sopenharmony_ci		.name = "Loopback",
1338c2ecf20Sopenharmony_ci		.stream_name = "Loopback",
1348c2ecf20Sopenharmony_ci		.nonatomic = 1,
1358c2ecf20Sopenharmony_ci		.dynamic = 1,
1368c2ecf20Sopenharmony_ci		.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
1378c2ecf20Sopenharmony_ci		.dpcm_capture = 1,
1388c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(loopback, dummy, platform),
1398c2ecf20Sopenharmony_ci	},
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	/* Back End DAI links */
1428c2ecf20Sopenharmony_ci	{
1438c2ecf20Sopenharmony_ci		/* SSP0 - Codec */
1448c2ecf20Sopenharmony_ci		.name = "Codec",
1458c2ecf20Sopenharmony_ci		.id = 0,
1468c2ecf20Sopenharmony_ci		.no_pcm = 1,
1478c2ecf20Sopenharmony_ci		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
1488c2ecf20Sopenharmony_ci			SND_SOC_DAIFMT_CBS_CFS,
1498c2ecf20Sopenharmony_ci		.ignore_pmdown_time = 1,
1508c2ecf20Sopenharmony_ci		.be_hw_params_fixup = haswell_ssp0_fixup,
1518c2ecf20Sopenharmony_ci		.ops = &haswell_rt5640_ops,
1528c2ecf20Sopenharmony_ci		.dpcm_playback = 1,
1538c2ecf20Sopenharmony_ci		.dpcm_capture = 1,
1548c2ecf20Sopenharmony_ci		SND_SOC_DAILINK_REG(ssp0_port, codec, platform),
1558c2ecf20Sopenharmony_ci	},
1568c2ecf20Sopenharmony_ci};
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/* audio machine driver for Haswell Lynxpoint DSP + RT5640 */
1598c2ecf20Sopenharmony_cistatic struct snd_soc_card haswell_rt5640 = {
1608c2ecf20Sopenharmony_ci	.name = "haswell-rt5640",
1618c2ecf20Sopenharmony_ci	.owner = THIS_MODULE,
1628c2ecf20Sopenharmony_ci	.dai_link = haswell_rt5640_dais,
1638c2ecf20Sopenharmony_ci	.num_links = ARRAY_SIZE(haswell_rt5640_dais),
1648c2ecf20Sopenharmony_ci	.dapm_widgets = haswell_widgets,
1658c2ecf20Sopenharmony_ci	.num_dapm_widgets = ARRAY_SIZE(haswell_widgets),
1668c2ecf20Sopenharmony_ci	.dapm_routes = haswell_rt5640_map,
1678c2ecf20Sopenharmony_ci	.num_dapm_routes = ARRAY_SIZE(haswell_rt5640_map),
1688c2ecf20Sopenharmony_ci	.fully_routed = true,
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistatic int haswell_audio_probe(struct platform_device *pdev)
1728c2ecf20Sopenharmony_ci{
1738c2ecf20Sopenharmony_ci	struct snd_soc_acpi_mach *mach;
1748c2ecf20Sopenharmony_ci	int ret;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	haswell_rt5640.dev = &pdev->dev;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	/* override plaform name, if required */
1798c2ecf20Sopenharmony_ci	mach = pdev->dev.platform_data;
1808c2ecf20Sopenharmony_ci	ret = snd_soc_fixup_dai_links_platform_name(&haswell_rt5640,
1818c2ecf20Sopenharmony_ci						    mach->mach_params.platform);
1828c2ecf20Sopenharmony_ci	if (ret)
1838c2ecf20Sopenharmony_ci		return ret;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	return devm_snd_soc_register_card(&pdev->dev, &haswell_rt5640);
1868c2ecf20Sopenharmony_ci}
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistatic struct platform_driver haswell_audio = {
1898c2ecf20Sopenharmony_ci	.probe = haswell_audio_probe,
1908c2ecf20Sopenharmony_ci	.driver = {
1918c2ecf20Sopenharmony_ci		.name = "haswell-audio",
1928c2ecf20Sopenharmony_ci		.pm = &snd_soc_pm_ops,
1938c2ecf20Sopenharmony_ci	},
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cimodule_platform_driver(haswell_audio)
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/* Module information */
1998c2ecf20Sopenharmony_ciMODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
2008c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint");
2018c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
2028c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:haswell-audio");
203