Commit da793fb0 authored by balamurugan.c's avatar balamurugan.c Committed by Mark Brown

ASoC: Intel: add RT1308 I2S machine driver and HDMI-in capture via I2S support.

Adding separate I2S machine driver for RT1308.

Adding support for HDMI-In capture via I2S in slave mode configuration.
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: default avatarbalamurugan.c <balamurugan.c@intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20220301194903.60859-4-pierre-louis.bossart@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent f1eebb3b
......@@ -599,6 +599,18 @@ config SND_SOC_INTEL_SOF_DA7219_MAX98373_MACH
endif ## SND_SOC_SOF_JASPERLAKE
config SND_SOC_INTEL_SOF_RT1308_MACH
tristate "SOF with RT1308 in I2S Mode"
depends on I2C && ACPI && GPIOLIB
depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_RT1308
select SND_SOC_DMIC
help
This adds support for ASoC machine driver for Tigerlake platforms
with RT1308 I2S audio codec.
Say Y if you have such a device.
If unsure select "N".
if SND_SOC_SOF_ELKHARTLAKE
config SND_SOC_INTEL_EHL_RT5660_MACH
......
......@@ -35,6 +35,7 @@ snd-skl_nau88l25_max98357a-objs := skl_nau88l25_max98357a.o
snd-soc-skl_nau88l25_ssm4567-objs := skl_nau88l25_ssm4567.o
snd-soc-sof_da7219_max98373-objs := sof_da7219_max98373.o
snd-soc-ehl-rt5660-objs := ehl_rt5660.o
snd-soc-sof-rt1308-objs := sof_rt1308.o
snd-soc-sof-sdw-objs += sof_sdw.o \
sof_sdw_max98373.o \
sof_sdw_rt1308.o sof_sdw_rt1316.o \
......@@ -79,6 +80,7 @@ obj-$(CONFIG_SND_SOC_INTEL_SKL_HDA_DSP_GENERIC_MACH) += snd-soc-skl_hda_dsp.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_DA7219_MAX98373_MACH) += snd-soc-sof_da7219_max98373.o
obj-$(CONFIG_SND_SOC_INTEL_EHL_RT5660_MACH) += snd-soc-ehl-rt5660.o
obj-$(CONFIG_SND_SOC_INTEL_SOUNDWIRE_SOF_MACH) += snd-soc-sof-sdw.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_RT1308_MACH) += snd-soc-sof-rt1308.o
# common modules
snd-soc-intel-hda-dsp-common-objs := hda_dsp_common.o
......
// SPDX-License-Identifier: GPL-2.0-only
//
// Copyright(c) 2022 Intel Corporation. All rights reserved.
/*
* sof_rt1308.c - ASoc Machine driver for Intel platforms
* with RT1308 codec.
*/
#include <linux/acpi.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/sof.h>
#include "../../codecs/rt1308.h"
#define SOF_RT1308_SSP_CODEC(quirk) ((quirk) & GENMASK(3, 0))
#define SOF_RT1308_SSP_CODEC_MASK (GENMASK(3, 0))
/* HDMI capture*/
#define SOF_SSP_HDMI_CAPTURE_PRESENT BIT(4)
#define SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT 5
#define SOF_NO_OF_HDMI_CAPTURE_SSP_MASK (GENMASK(6, 5))
#define SOF_NO_OF_HDMI_CAPTURE_SSP(quirk) \
(((quirk) << SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT) & SOF_NO_OF_HDMI_CAPTURE_SSP_MASK)
#define SOF_HDMI_CAPTURE_1_SSP_SHIFT 7
#define SOF_HDMI_CAPTURE_1_SSP_MASK (GENMASK(9, 7))
#define SOF_HDMI_CAPTURE_1_SSP(quirk) \
(((quirk) << SOF_HDMI_CAPTURE_1_SSP_SHIFT) & SOF_HDMI_CAPTURE_1_SSP_MASK)
#define SOF_HDMI_CAPTURE_2_SSP_SHIFT 10
#define SOF_HDMI_CAPTURE_2_SSP_MASK (GENMASK(12, 10))
#define SOF_HDMI_CAPTURE_2_SSP(quirk) \
(((quirk) << SOF_HDMI_CAPTURE_2_SSP_SHIFT) & SOF_HDMI_CAPTURE_2_SSP_MASK)
/* Default: SSP2 */
static unsigned long sof_rt1308_quirk = SOF_RT1308_SSP_CODEC(2);
static const struct snd_soc_dapm_widget sof_rt1308_dapm_widgets[] = {
SND_SOC_DAPM_SPK("Speakers", NULL),
SND_SOC_DAPM_MIC("SoC DMIC", NULL),
};
static const struct snd_kcontrol_new sof_rt1308_controls[] = {
SOC_DAPM_PIN_SWITCH("Speakers"),
};
static const struct snd_soc_dapm_route sof_rt1308_dapm_routes[] = {
{ "Speakers", NULL, "SPOL" },
{ "Speakers", NULL, "SPOR" },
/* digital mics */
{"DMic", NULL, "SoC DMIC"},
};
static struct snd_soc_card sof_rt1308_card = {
.name = "rt1308",
.owner = THIS_MODULE,
.controls = sof_rt1308_controls,
.num_controls = ARRAY_SIZE(sof_rt1308_controls),
.dapm_widgets = sof_rt1308_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(sof_rt1308_dapm_widgets),
.dapm_routes = sof_rt1308_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(sof_rt1308_dapm_routes),
.fully_routed = true,
};
static int sof_rt1308_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct snd_soc_card *card = rtd->card;
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
int clk_id, clk_freq, pll_out;
int ret;
clk_id = RT1308_PLL_S_MCLK;
/* get the tplg configured mclk. */
clk_freq = sof_dai_get_mclk(rtd);
pll_out = params_rate(params) * 512;
/* Set rt1308 pll */
ret = snd_soc_dai_set_pll(codec_dai, 0, clk_id, clk_freq, pll_out);
if (ret < 0) {
dev_err(card->dev, "Failed to set RT1308 PLL: %d\n", ret);
return ret;
}
/* Set rt1308 sysclk */
ret = snd_soc_dai_set_sysclk(codec_dai, RT1308_FS_SYS_S_PLL, pll_out,
SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(card->dev, "Failed to set RT1308 SYSCLK: %d\n", ret);
return ret;
}
static struct snd_soc_dai_link_component platform_component[] = {
{
/* name might be overridden during probe */
.name = "0000:00:1f.3"
}
};
static struct snd_soc_dai_link_component rt1308_component[] = {
{
.name = "i2c-10EC1308:00",
.dai_name = "rt1308-aif",
}
};
static struct snd_soc_dai_link_component dmic_component[] = {
{
.name = "dmic-codec",
.dai_name = "dmic-hifi",
}
};
static struct snd_soc_dai_link_component dummy_component[] = {
{
.name = "snd-soc-dummy",
.dai_name = "snd-soc-dummy-dai",
}
};
/* machine stream operations */
static const struct snd_soc_ops sof_rt1308_ops = {
.hw_params = sof_rt1308_hw_params,
};
static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
int ssp_codec,
int dmic_be_num)
{
struct snd_soc_dai_link_component *cpus;
struct snd_soc_dai_link *links;
int i, id = 0;
links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) *
sof_rt1308_card.num_links, GFP_KERNEL);
cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component) *
sof_rt1308_card.num_links, GFP_KERNEL);
if (!links || !cpus)
return NULL;
/* HDMI-In SSP */
if (sof_rt1308_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT) {
int num_of_hdmi_ssp = (sof_rt1308_quirk & SOF_NO_OF_HDMI_CAPTURE_SSP_MASK) >>
SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT;
for (i = 1; i <= num_of_hdmi_ssp; i++) {
int port = (i == 1 ? (sof_rt1308_quirk & SOF_HDMI_CAPTURE_1_SSP_MASK) >>
SOF_HDMI_CAPTURE_1_SSP_SHIFT :
(sof_rt1308_quirk & SOF_HDMI_CAPTURE_2_SSP_MASK) >>
SOF_HDMI_CAPTURE_2_SSP_SHIFT);
links[id].cpus = &cpus[id];
links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d Pin", port);
if (!links[id].cpus->dai_name)
return NULL;
links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-HDMI", port);
if (!links[id].name)
return NULL;
links[id].id = id;
links[id].codecs = dummy_component;
links[id].num_codecs = ARRAY_SIZE(dummy_component);
links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].dpcm_capture = 1;
links[id].no_pcm = 1;
links[id].num_cpus = 1;
id++;
}
}
/* codec SSP */
links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_codec);
if (!links[id].name)
return NULL;
links[id].id = id;
links[id].codecs = rt1308_component;
links[id].num_codecs = ARRAY_SIZE(rt1308_component);
links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].ops = &sof_rt1308_ops;
links[id].dpcm_playback = 1;
links[id].no_pcm = 1;
links[id].cpus = &cpus[id];
links[id].num_cpus = 1;
links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_codec);
if (!links[id].cpus->dai_name)
return NULL;
id++;
/* dmic */
if (dmic_be_num > 0) {
/* at least we have dmic01 */
links[id].name = "dmic01";
links[id].cpus = &cpus[id];
links[id].cpus->dai_name = "DMIC01 Pin";
if (dmic_be_num > 1) {
/* set up 2 BE links at most */
links[id + 1].name = "dmic16k";
links[id + 1].cpus = &cpus[id + 1];
links[id + 1].cpus->dai_name = "DMIC16k Pin";
dmic_be_num = 2;
}
}
for (i = 0; i < dmic_be_num; i++) {
links[id].id = id;
links[id].num_cpus = 1;
links[id].codecs = dmic_component;
links[id].num_codecs = ARRAY_SIZE(dmic_component);
links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].ignore_suspend = 1;
links[id].dpcm_capture = 1;
links[id].no_pcm = 1;
id++;
}
return links;
}
static int sof_rt1308_probe(struct platform_device *pdev)
{
struct snd_soc_dai_link *dai_links;
struct snd_soc_acpi_mach *mach;
int dmic_be_num;
int ret, ssp_codec;
if (pdev->id_entry && pdev->id_entry->driver_data)
sof_rt1308_quirk = (unsigned long)pdev->id_entry->driver_data;
mach = pdev->dev.platform_data;
dmic_be_num = mach->mach_params.dmic_num;
ssp_codec = sof_rt1308_quirk & SOF_RT1308_SSP_CODEC_MASK;
/* set number of dai links */
sof_rt1308_card.num_links = 1 + dmic_be_num;
if (sof_rt1308_quirk & SOF_SSP_HDMI_CAPTURE_PRESENT)
sof_rt1308_card.num_links += (sof_rt1308_quirk & SOF_NO_OF_HDMI_CAPTURE_SSP_MASK) >>
SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT;
dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, dmic_be_num);
if (!dai_links)
return -ENOMEM;
sof_rt1308_card.dai_link = dai_links;
sof_rt1308_card.dev = &pdev->dev;
/* set platform name for each dailink */
ret = snd_soc_fixup_dai_links_platform_name(&sof_rt1308_card,
mach->mach_params.platform);
if (ret)
return ret;
snd_soc_card_set_drvdata(&sof_rt1308_card, NULL);
return devm_snd_soc_register_card(&pdev->dev, &sof_rt1308_card);
}
static const struct platform_device_id board_ids[] = {
{
.name = "sof_rt1308",
},
{
.name = "tgl_rt1308_hdmi_ssp",
.driver_data = (kernel_ulong_t)(SOF_RT1308_SSP_CODEC(2) |
SOF_NO_OF_HDMI_CAPTURE_SSP(2) |
SOF_HDMI_CAPTURE_1_SSP(1) |
SOF_HDMI_CAPTURE_2_SSP(5) |
SOF_SSP_HDMI_CAPTURE_PRESENT),
},
{ }
};
MODULE_DEVICE_TABLE(platform, board_ids);
static struct platform_driver sof_rt1308_driver = {
.probe = sof_rt1308_probe,
.driver = {
.name = "sof_rt1308",
.pm = &snd_soc_pm_ops,
},
.id_table = board_ids,
};
module_platform_driver(sof_rt1308_driver);
MODULE_DESCRIPTION("ASoC Intel(R) SOF + RT1308 Machine driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:sof_rt1308");
......@@ -363,6 +363,11 @@ static const struct snd_soc_acpi_codecs tgl_rt5682_rt5682s_hp = {
.codecs = {"10EC5682", "RTL5682"},
};
static const struct snd_soc_acpi_codecs tgl_lt6911_hdmi = {
.num_codecs = 1,
.codecs = {"INTC10B0"}
};
struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_machines[] = {
{
.comp_ids = &tgl_rt5682_rt5682s_hp,
......@@ -390,6 +395,13 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_machines[] = {
.drv_name = "sof-essx8336",
.sof_tplg_filename = "sof-tgl-es8336.tplg",
},
{
.id = "10EC1308",
.drv_name = "tgl_rt1308_hdmi_ssp",
.machine_quirk = snd_soc_acpi_codec_list,
.quirk_data = &tgl_lt6911_hdmi,
.sof_tplg_filename = "sof-tgl-rt1308-ssp2-hdmi-ssp15.tplg"
},
{},
};
EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_tgl_machines);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment