Commit 024979b6 authored by Brent Lu's avatar Brent Lu Committed by Mark Brown

ASoC: Intel: sof_rt1308: move rt1308 code to common module

Move the code related to rt1308 dai link to the realtek common module.
It creates a clean base to add more amplifier support to this machine
driver in the future.
Reviewed-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: default avatarBrent Lu <brent.lu@intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20220301194903.60859-6-pierre-louis.bossart@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent e1d5e133
...@@ -609,6 +609,7 @@ config SND_SOC_INTEL_SOF_RT1308_MACH ...@@ -609,6 +609,7 @@ config SND_SOC_INTEL_SOF_RT1308_MACH
depends on MFD_INTEL_LPSS || COMPILE_TEST depends on MFD_INTEL_LPSS || COMPILE_TEST
select SND_SOC_RT1308 select SND_SOC_RT1308
select SND_SOC_DMIC select SND_SOC_DMIC
select SND_SOC_INTEL_SOF_REALTEK_COMMON
help help
This adds support for ASoC machine driver for Tigerlake platforms This adds support for ASoC machine driver for Tigerlake platforms
with RT1308 I2S audio codec. with RT1308 I2S audio codec.
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#include <sound/soc-acpi.h> #include <sound/soc-acpi.h>
#include <sound/soc-dai.h> #include <sound/soc-dai.h>
#include <sound/soc-dapm.h> #include <sound/soc-dapm.h>
#include <sound/sof.h>
#include <uapi/sound/asound.h> #include <uapi/sound/asound.h>
#include "../../codecs/rt1011.h" #include "../../codecs/rt1011.h"
#include "../../codecs/rt1015.h" #include "../../codecs/rt1015.h"
#include "../../codecs/rt1308.h"
#include "sof_realtek_common.h" #include "sof_realtek_common.h"
/* /*
...@@ -361,5 +363,101 @@ void sof_rt1015_dai_link(struct snd_soc_dai_link *link, unsigned int fs) ...@@ -361,5 +363,101 @@ void sof_rt1015_dai_link(struct snd_soc_dai_link *link, unsigned int fs)
} }
EXPORT_SYMBOL_NS(sof_rt1015_dai_link, SND_SOC_INTEL_SOF_REALTEK_COMMON); EXPORT_SYMBOL_NS(sof_rt1015_dai_link, SND_SOC_INTEL_SOF_REALTEK_COMMON);
/*
* RT1308 audio amplifier
*/
static const struct snd_kcontrol_new rt1308_kcontrols[] = {
SOC_DAPM_PIN_SWITCH("Speakers"),
};
static const struct snd_soc_dapm_widget rt1308_dapm_widgets[] = {
SND_SOC_DAPM_SPK("Speakers", NULL),
};
static const struct snd_soc_dapm_route rt1308_dapm_routes[] = {
/* speaker */
{"Speakers", NULL, "SPOL"},
{"Speakers", NULL, "SPOR"},
};
static struct snd_soc_dai_link_component rt1308_components[] = {
{
.name = RT1308_DEV0_NAME,
.dai_name = RT1308_CODEC_DAI,
}
};
static int rt1308_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
int ret;
ret = snd_soc_dapm_new_controls(&card->dapm, rt1308_dapm_widgets,
ARRAY_SIZE(rt1308_dapm_widgets));
if (ret) {
dev_err(rtd->dev, "fail to add dapm controls, ret %d\n", ret);
return ret;
}
ret = snd_soc_add_card_controls(card, rt1308_kcontrols,
ARRAY_SIZE(rt1308_kcontrols));
if (ret) {
dev_err(rtd->dev, "fail to add card controls, ret %d\n", ret);
return ret;
}
ret = snd_soc_dapm_add_routes(&card->dapm, rt1308_dapm_routes,
ARRAY_SIZE(rt1308_dapm_routes));
if (ret)
dev_err(rtd->dev, "fail to add dapm routes, ret %d\n", ret);
return ret;
}
static int 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 const struct snd_soc_ops rt1308_ops = {
.hw_params = rt1308_hw_params,
};
void sof_rt1308_dai_link(struct snd_soc_dai_link *link)
{
link->codecs = rt1308_components;
link->num_codecs = ARRAY_SIZE(rt1308_components);
link->init = rt1308_init;
link->ops = &rt1308_ops;
}
EXPORT_SYMBOL_NS(sof_rt1308_dai_link, SND_SOC_INTEL_SOF_REALTEK_COMMON);
MODULE_DESCRIPTION("ASoC Intel SOF Realtek helpers"); MODULE_DESCRIPTION("ASoC Intel SOF Realtek helpers");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -35,4 +35,8 @@ void sof_rt1015p_codec_conf(struct snd_soc_card *card); ...@@ -35,4 +35,8 @@ void sof_rt1015p_codec_conf(struct snd_soc_card *card);
void sof_rt1015_dai_link(struct snd_soc_dai_link *link, unsigned int fs); void sof_rt1015_dai_link(struct snd_soc_dai_link *link, unsigned int fs);
void sof_rt1015_codec_conf(struct snd_soc_card *card); void sof_rt1015_codec_conf(struct snd_soc_card *card);
#define RT1308_CODEC_DAI "rt1308-aif"
#define RT1308_DEV0_NAME "i2c-10EC1308:00"
void sof_rt1308_dai_link(struct snd_soc_dai_link *link);
#endif /* __SOF_REALTEK_COMMON_H */ #endif /* __SOF_REALTEK_COMMON_H */
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <sound/pcm.h> #include <sound/pcm.h>
#include <sound/pcm_params.h> #include <sound/pcm_params.h>
#include <sound/sof.h> #include <sound/sof.h>
#include "../../codecs/rt1308.h" #include "sof_realtek_common.h"
#define SOF_RT1308_SSP_CODEC(quirk) ((quirk) & GENMASK(3, 0)) #define SOF_RT1308_SSP_CODEC(quirk) ((quirk) & GENMASK(3, 0))
#define SOF_RT1308_SSP_CODEC_MASK (GENMASK(3, 0)) #define SOF_RT1308_SSP_CODEC_MASK (GENMASK(3, 0))
...@@ -38,22 +38,16 @@ ...@@ -38,22 +38,16 @@
#define SOF_HDMI_CAPTURE_2_SSP(quirk) \ #define SOF_HDMI_CAPTURE_2_SSP(quirk) \
(((quirk) << SOF_HDMI_CAPTURE_2_SSP_SHIFT) & SOF_HDMI_CAPTURE_2_SSP_MASK) (((quirk) << SOF_HDMI_CAPTURE_2_SSP_SHIFT) & SOF_HDMI_CAPTURE_2_SSP_MASK)
#define SOF_RT1308_SPEAKER_AMP_PRESENT BIT(13)
/* Default: SSP2 */ /* Default: SSP2 */
static unsigned long sof_rt1308_quirk = SOF_RT1308_SSP_CODEC(2); static unsigned long sof_rt1308_quirk = SOF_RT1308_SSP_CODEC(2);
static const struct snd_soc_dapm_widget sof_rt1308_dapm_widgets[] = { static const struct snd_soc_dapm_widget sof_rt1308_dapm_widgets[] = {
SND_SOC_DAPM_SPK("Speakers", NULL),
SND_SOC_DAPM_MIC("SoC DMIC", 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[] = { static const struct snd_soc_dapm_route sof_rt1308_dapm_routes[] = {
{ "Speakers", NULL, "SPOL" },
{ "Speakers", NULL, "SPOR" },
/* digital mics */ /* digital mics */
{"DMic", NULL, "SoC DMIC"}, {"DMic", NULL, "SoC DMIC"},
}; };
...@@ -61,8 +55,6 @@ static const struct snd_soc_dapm_route sof_rt1308_dapm_routes[] = { ...@@ -61,8 +55,6 @@ static const struct snd_soc_dapm_route sof_rt1308_dapm_routes[] = {
static struct snd_soc_card sof_rt1308_card = { static struct snd_soc_card sof_rt1308_card = {
.name = "rt1308", .name = "rt1308",
.owner = THIS_MODULE, .owner = THIS_MODULE,
.controls = sof_rt1308_controls,
.num_controls = ARRAY_SIZE(sof_rt1308_controls),
.dapm_widgets = sof_rt1308_dapm_widgets, .dapm_widgets = sof_rt1308_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(sof_rt1308_dapm_widgets), .num_dapm_widgets = ARRAY_SIZE(sof_rt1308_dapm_widgets),
.dapm_routes = sof_rt1308_dapm_routes, .dapm_routes = sof_rt1308_dapm_routes,
...@@ -70,37 +62,6 @@ static struct snd_soc_card sof_rt1308_card = { ...@@ -70,37 +62,6 @@ static struct snd_soc_card sof_rt1308_card = {
.fully_routed = true, .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[] = { static struct snd_soc_dai_link_component platform_component[] = {
{ {
/* name might be overridden during probe */ /* name might be overridden during probe */
...@@ -108,13 +69,6 @@ static struct snd_soc_dai_link_component platform_component[] = { ...@@ -108,13 +69,6 @@ static struct snd_soc_dai_link_component platform_component[] = {
} }
}; };
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[] = { static struct snd_soc_dai_link_component dmic_component[] = {
{ {
.name = "dmic-codec", .name = "dmic-codec",
...@@ -129,11 +83,6 @@ static struct snd_soc_dai_link_component dummy_component[] = { ...@@ -129,11 +83,6 @@ static struct snd_soc_dai_link_component dummy_component[] = {
} }
}; };
/* 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, static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
int ssp_codec, int ssp_codec,
int dmic_be_num) int dmic_be_num)
...@@ -186,11 +135,11 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, ...@@ -186,11 +135,11 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
return NULL; return NULL;
links[id].id = id; links[id].id = id;
links[id].codecs = rt1308_component; if (sof_rt1308_quirk & SOF_RT1308_SPEAKER_AMP_PRESENT) {
links[id].num_codecs = ARRAY_SIZE(rt1308_component); sof_rt1308_dai_link(&links[id]);
}
links[id].platforms = platform_component; links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component); links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].ops = &sof_rt1308_ops;
links[id].dpcm_playback = 1; links[id].dpcm_playback = 1;
links[id].no_pcm = 1; links[id].no_pcm = 1;
links[id].cpus = &cpus[id]; links[id].cpus = &cpus[id];
...@@ -284,7 +233,8 @@ static const struct platform_device_id board_ids[] = { ...@@ -284,7 +233,8 @@ static const struct platform_device_id board_ids[] = {
SOF_NO_OF_HDMI_CAPTURE_SSP(2) | SOF_NO_OF_HDMI_CAPTURE_SSP(2) |
SOF_HDMI_CAPTURE_1_SSP(1) | SOF_HDMI_CAPTURE_1_SSP(1) |
SOF_HDMI_CAPTURE_2_SSP(5) | SOF_HDMI_CAPTURE_2_SSP(5) |
SOF_SSP_HDMI_CAPTURE_PRESENT), SOF_SSP_HDMI_CAPTURE_PRESENT |
SOF_RT1308_SPEAKER_AMP_PRESENT),
}, },
{ } { }
}; };
...@@ -301,5 +251,7 @@ static struct platform_driver sof_rt1308_driver = { ...@@ -301,5 +251,7 @@ static struct platform_driver sof_rt1308_driver = {
module_platform_driver(sof_rt1308_driver); module_platform_driver(sof_rt1308_driver);
MODULE_DESCRIPTION("ASoC Intel(R) SOF + RT1308 Machine driver"); MODULE_DESCRIPTION("ASoC Intel(R) SOF + RT1308 Machine driver");
MODULE_AUTHOR("balamurugan.c <balamurugan.c@intel.com>");
MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:sof_rt1308"); MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON);
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