#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/dmi.h>
#include <sound/core.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/sof.h>
#include <sound/rt5682.h>
#include <sound/rt5682s.h>
#include <sound/soc-acpi.h>
#include "../../codecs/rt5682.h"
#include "../../codecs/rt5682s.h"
#include "../../codecs/rt5645.h"
#include "../common/soc-intel-quirks.h"
#include "sof_board_helpers.h"
#include "sof_maxim_common.h"
#include "sof_realtek_common.h"
#define SOF_RT5682_MCLK_EN …
static unsigned long sof_rt5682_quirk = …;
static int sof_rt5682_quirk_cb(const struct dmi_system_id *id)
{ … }
static const struct dmi_system_id sof_rt5682_quirk_table[] = …;
static struct snd_soc_jack_pin jack_pins[] = …;
static int sof_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
{
struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
struct snd_soc_jack *jack = &ctx->headset_jack;
int extra_jack_data;
int ret, mclk_freq;
if (ctx->rt5682.mclk_en) {
mclk_freq = sof_dai_get_mclk(rtd);
if (mclk_freq <= 0) {
dev_err(rtd->dev, "invalid mclk freq %d\n", mclk_freq);
return -EINVAL;
}
if (mclk_freq == 24000000) {
dev_info(rtd->dev, "enable ASRC\n");
switch (ctx->codec_type) {
case CODEC_RT5650:
rt5645_sel_asrc_clk_src(component,
RT5645_DA_STEREO_FILTER |
RT5645_AD_STEREO_FILTER,
RT5645_CLK_SEL_I2S1_ASRC);
rt5645_sel_asrc_clk_src(component,
RT5645_DA_MONO_L_FILTER |
RT5645_DA_MONO_R_FILTER,
RT5645_CLK_SEL_I2S2_ASRC);
break;
case CODEC_RT5682:
rt5682_sel_asrc_clk_src(component,
RT5682_DA_STEREO1_FILTER |
RT5682_AD_STEREO1_FILTER,
RT5682_CLK_SEL_I2S1_ASRC);
break;
case CODEC_RT5682S:
rt5682s_sel_asrc_clk_src(component,
RT5682S_DA_STEREO1_FILTER |
RT5682S_AD_STEREO1_FILTER,
RT5682S_CLK_SEL_I2S1_ASRC);
break;
default:
dev_err(rtd->dev, "invalid codec type %d\n",
ctx->codec_type);
return -EINVAL;
}
}
if (ctx->rt5682.is_legacy_cpu) {
ret = clk_prepare_enable(ctx->rt5682.mclk);
if (!ret)
clk_disable_unprepare(ctx->rt5682.mclk);
ret = clk_set_rate(ctx->rt5682.mclk, 19200000);
if (ret)
dev_err(rtd->dev, "unable to set MCLK rate\n");
}
}
ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
SND_JACK_HEADSET | SND_JACK_BTN_0 |
SND_JACK_BTN_1 | SND_JACK_BTN_2 |
SND_JACK_BTN_3,
jack,
jack_pins,
ARRAY_SIZE(jack_pins));
if (ret) {
dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
return ret;
}
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
if (ctx->codec_type == CODEC_RT5650) {
extra_jack_data = SND_JACK_MICROPHONE | SND_JACK_BTN_0;
ret = snd_soc_component_set_jack(component, jack, &extra_jack_data);
} else
ret = snd_soc_component_set_jack(component, jack, NULL);
if (ret) {
dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
return ret;
}
return ret;
};
static void sof_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
{ … }
static int sof_rt5682_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{ … }
static const struct snd_soc_ops sof_rt5682_ops = …;
static int sof_card_late_probe(struct snd_soc_card *card)
{ … }
static const struct snd_kcontrol_new sof_controls[] = …;
static const struct snd_soc_dapm_widget sof_widgets[] = …;
static const struct snd_soc_dapm_route sof_map[] = …;
static const struct snd_kcontrol_new rt5650_spk_kcontrols[] = …;
static const struct snd_soc_dapm_widget rt5650_spk_widgets[] = …;
static const struct snd_soc_dapm_route rt5650_spk_dapm_routes[] = …;
static int rt5650_spk_init(struct snd_soc_pcm_runtime *rtd)
{ … }
static struct snd_soc_card sof_audio_card_rt5682 = …;
static struct snd_soc_dai_link_component rt5682_component[] = …;
static struct snd_soc_dai_link_component rt5682s_component[] = …;
static struct snd_soc_dai_link_component rt5650_components[] = …;
static int
sof_card_dai_links_create(struct device *dev, struct snd_soc_card *card,
struct sof_card_private *ctx)
{ … }
#define GLK_LINK_ORDER …
static int sof_audio_probe(struct platform_device *pdev)
{ … }
static const struct platform_device_id board_ids[] = …;
MODULE_DEVICE_TABLE(platform, board_ids);
static struct platform_driver sof_audio = …;
module_platform_driver(…) …
MODULE_DESCRIPTION(…) …;
MODULE_AUTHOR(…) …;
MODULE_AUTHOR(…) …;
MODULE_AUTHOR(…) …;
MODULE_AUTHOR(…) …;
MODULE_LICENSE(…) …;
MODULE_IMPORT_NS(…);
MODULE_IMPORT_NS(…);
MODULE_IMPORT_NS(…);