From: Brent Lu <brent.lu@xxxxxxxxx> 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: Bard Liao <yung-chuan.liao@xxxxxxxxxxxxxxx> Signed-off-by: Brent Lu <brent.lu@xxxxxxxxx> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@xxxxxxxxxxxxxxx> --- sound/soc/intel/boards/Kconfig | 1 + sound/soc/intel/boards/sof_realtek_common.c | 98 +++++++++++++++++++++ sound/soc/intel/boards/sof_realtek_common.h | 4 + sound/soc/intel/boards/sof_rt1308.c | 70 +++------------ 4 files changed, 114 insertions(+), 59 deletions(-) diff --git a/sound/soc/intel/boards/Kconfig b/sound/soc/intel/boards/Kconfig index cdf94b09c372..d96ebc335249 100644 --- a/sound/soc/intel/boards/Kconfig +++ b/sound/soc/intel/boards/Kconfig @@ -609,6 +609,7 @@ config SND_SOC_INTEL_SOF_RT1308_MACH depends on MFD_INTEL_LPSS || COMPILE_TEST select SND_SOC_RT1308 select SND_SOC_DMIC + select SND_SOC_INTEL_SOF_REALTEK_COMMON help This adds support for ASoC machine driver for Tigerlake platforms with RT1308 I2S audio codec. diff --git a/sound/soc/intel/boards/sof_realtek_common.c b/sound/soc/intel/boards/sof_realtek_common.c index 669e44c73c17..a2bcbeee0216 100644 --- a/sound/soc/intel/boards/sof_realtek_common.c +++ b/sound/soc/intel/boards/sof_realtek_common.c @@ -10,9 +10,11 @@ #include <sound/soc-acpi.h> #include <sound/soc-dai.h> #include <sound/soc-dapm.h> +#include <sound/sof.h> #include <uapi/sound/asound.h> #include "../../codecs/rt1011.h" #include "../../codecs/rt1015.h" +#include "../../codecs/rt1308.h" #include "sof_realtek_common.h" /* @@ -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); +/* + * 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_LICENSE("GPL"); diff --git a/sound/soc/intel/boards/sof_realtek_common.h b/sound/soc/intel/boards/sof_realtek_common.h index 228ac9c08430..e0a5518e8dd2 100644 --- a/sound/soc/intel/boards/sof_realtek_common.h +++ b/sound/soc/intel/boards/sof_realtek_common.h @@ -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_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 */ diff --git a/sound/soc/intel/boards/sof_rt1308.c b/sound/soc/intel/boards/sof_rt1308.c index 7e33c49b3531..971ab53236a5 100644 --- a/sound/soc/intel/boards/sof_rt1308.c +++ b/sound/soc/intel/boards/sof_rt1308.c @@ -16,7 +16,7 @@ #include <sound/pcm.h> #include <sound/pcm_params.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_MASK (GENMASK(3, 0)) @@ -38,22 +38,16 @@ #define SOF_HDMI_CAPTURE_2_SSP(quirk) \ (((quirk) << SOF_HDMI_CAPTURE_2_SSP_SHIFT) & SOF_HDMI_CAPTURE_2_SSP_MASK) +#define SOF_RT1308_SPEAKER_AMP_PRESENT BIT(13) + /* 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"}, }; @@ -61,8 +55,6 @@ static const struct snd_soc_dapm_route sof_rt1308_dapm_routes[] = { 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, @@ -70,37 +62,6 @@ static struct snd_soc_card sof_rt1308_card = { .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 */ @@ -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[] = { { .name = "dmic-codec", @@ -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, int ssp_codec, int dmic_be_num) @@ -186,11 +135,11 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, return NULL; links[id].id = id; - links[id].codecs = rt1308_component; - links[id].num_codecs = ARRAY_SIZE(rt1308_component); + if (sof_rt1308_quirk & SOF_RT1308_SPEAKER_AMP_PRESENT) { + sof_rt1308_dai_link(&links[id]); + } 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]; @@ -284,7 +233,8 @@ static const struct platform_device_id board_ids[] = { SOF_NO_OF_HDMI_CAPTURE_SSP(2) | SOF_HDMI_CAPTURE_1_SSP(1) | 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 = { module_platform_driver(sof_rt1308_driver); MODULE_DESCRIPTION("ASoC Intel(R) SOF + RT1308 Machine driver"); +MODULE_AUTHOR("balamurugan.c <balamurugan.c@xxxxxxxxx>"); +MODULE_AUTHOR("Brent Lu <brent.lu@xxxxxxxxx>"); MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:sof_rt1308"); +MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_REALTEK_COMMON); -- 2.25.1