aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c')
-rw-r--r--sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c213
1 files changed, 197 insertions, 16 deletions
diff --git a/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c
index 387f25cad809..cfca6bdee834 100644
--- a/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c
@@ -18,6 +18,8 @@
#include "../../codecs/da7219.h"
#include "../../codecs/mt6358.h"
#include "../common/mtk-afe-platform-driver.h"
+#include "../common/mtk-dsp-sof-common.h"
+#include "../common/mtk-soc-card.h"
#include "mt8186-afe-common.h"
#include "mt8186-afe-clk.h"
#include "mt8186-afe-gpio.h"
@@ -26,10 +28,27 @@
#define DA7219_CODEC_DAI "da7219-hifi"
#define DA7219_DEV_NAME "da7219.5-001a"
+#define SOF_DMA_DL1 "SOF_DMA_DL1"
+#define SOF_DMA_DL2 "SOF_DMA_DL2"
+#define SOF_DMA_UL1 "SOF_DMA_UL1"
+#define SOF_DMA_UL2 "SOF_DMA_UL2"
+
struct mt8186_mt6366_da7219_max98357_priv {
struct snd_soc_jack headset_jack, hdmi_jack;
};
+/* Headset jack detection DAPM pins */
+static struct snd_soc_jack_pin mt8186_jack_pins[] = {
+ {
+ .pin = "Headphones",
+ .mask = SND_JACK_HEADPHONE,
+ },
+ {
+ .pin = "Headset Mic",
+ .mask = SND_JACK_MICROPHONE,
+ },
+};
+
static struct snd_soc_codec_conf mt8186_mt6366_da7219_max98357_codec_conf[] = {
{
.dlc = COMP_CODEC_CONF("mt6358-sound"),
@@ -47,19 +66,30 @@ static struct snd_soc_codec_conf mt8186_mt6366_da7219_max98357_codec_conf[] = {
static int mt8186_da7219_init(struct snd_soc_pcm_runtime *rtd)
{
- struct mt8186_mt6366_da7219_max98357_priv *priv =
+ struct snd_soc_component *cmpnt_afe =
+ snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+ struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
+ struct mtk_soc_card_data *soc_card_data =
snd_soc_card_get_drvdata(rtd->card);
+ struct mt8186_mt6366_da7219_max98357_priv *priv = soc_card_data->mach_priv;
struct snd_soc_jack *jack = &priv->headset_jack;
struct snd_soc_component *cmpnt_codec =
asoc_rtd_to_codec(rtd, 0)->component;
int ret;
+ ret = mt8186_dai_i2s_set_share(afe, "I2S1", "I2S0");
+ if (ret) {
+ dev_err(rtd->dev, "Failed to set up shared clocks\n");
+ return ret;
+ }
+
/* Enable Headset and 4 Buttons Jack detection */
- ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
+ 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 | SND_JACK_LINEOUT,
- jack);
+ jack, mt8186_jack_pins,
+ ARRAY_SIZE(mt8186_jack_pins));
if (ret) {
dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
return ret;
@@ -152,12 +182,22 @@ static const struct snd_soc_ops mt8186_da7219_i2s_ops = {
static int mt8186_mt6366_da7219_max98357_hdmi_init(struct snd_soc_pcm_runtime *rtd)
{
+ struct snd_soc_component *cmpnt_afe =
+ snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+ struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
struct snd_soc_component *cmpnt_codec =
asoc_rtd_to_codec(rtd, 0)->component;
- struct mt8186_mt6366_da7219_max98357_priv *priv =
+ struct mtk_soc_card_data *soc_card_data =
snd_soc_card_get_drvdata(rtd->card);
+ struct mt8186_mt6366_da7219_max98357_priv *priv = soc_card_data->mach_priv;
int ret;
+ ret = mt8186_dai_i2s_set_share(afe, "I2S3", "I2S2");
+ if (ret) {
+ dev_err(rtd->dev, "Failed to set up shared clocks\n");
+ return ret;
+ }
+
ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, &priv->hdmi_jack);
if (ret) {
dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
@@ -201,6 +241,24 @@ static int mt8186_anx7625_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE);
}
+/* fixup the BE DAI link to match any values from topology */
+static int mt8186_sof_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
+ struct snd_pcm_hw_params *params)
+{
+ int ret;
+
+ ret = mtk_sof_dai_link_fixup(rtd, params);
+
+ if (!strcmp(rtd->dai_link->name, "I2S0") ||
+ !strcmp(rtd->dai_link->name, "I2S1") ||
+ !strcmp(rtd->dai_link->name, "I2S2"))
+ mt8186_i2s_hw_params_fixup(rtd, params);
+ else if (!strcmp(rtd->dai_link->name, "I2S3"))
+ mt8186_anx7625_i2s_hw_params_fixup(rtd, params);
+
+ return ret;
+}
+
static int mt8186_mt6366_da7219_max98357_playback_startup(struct snd_pcm_substream *substream)
{
static const unsigned int rates[] = {
@@ -474,6 +532,33 @@ SND_SOC_DAILINK_DEFS(hostless_src_aaudio,
DAILINK_COMP_ARRAY(COMP_CPU("Hostless SRC AAudio DAI")),
DAILINK_COMP_ARRAY(COMP_DUMMY()),
DAILINK_COMP_ARRAY(COMP_EMPTY()));
+SND_SOC_DAILINK_DEFS(AFE_SOF_DL1,
+ DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL1")),
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+SND_SOC_DAILINK_DEFS(AFE_SOF_DL2,
+ DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+SND_SOC_DAILINK_DEFS(AFE_SOF_UL1,
+ DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL1")),
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+SND_SOC_DAILINK_DEFS(AFE_SOF_UL2,
+ DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL2")),
+ DAILINK_COMP_ARRAY(COMP_DUMMY()),
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+static const struct sof_conn_stream g_sof_conn_streams[] = {
+ { "I2S1", "AFE_SOF_DL1", SOF_DMA_DL1, SNDRV_PCM_STREAM_PLAYBACK},
+ { "I2S3", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK},
+ { "Primary Codec", "AFE_SOF_UL1", SOF_DMA_UL1, SNDRV_PCM_STREAM_CAPTURE},
+ { "I2S0", "AFE_SOF_UL2", SOF_DMA_UL2, SNDRV_PCM_STREAM_CAPTURE},
+};
+
static struct snd_soc_dai_link mt8186_mt6366_da7219_max98357_dai_links[] = {
/* Front End DAI links */
{
@@ -848,30 +933,75 @@ static struct snd_soc_dai_link mt8186_mt6366_da7219_max98357_dai_links[] = {
.ignore_suspend = 1,
SND_SOC_DAILINK_REG(hostless_ul6),
},
+ /* SOF BE */
+ {
+ .name = "AFE_SOF_DL1",
+ .no_pcm = 1,
+ .dpcm_playback = 1,
+ SND_SOC_DAILINK_REG(AFE_SOF_DL1),
+ },
+ {
+ .name = "AFE_SOF_DL2",
+ .no_pcm = 1,
+ .dpcm_playback = 1,
+ SND_SOC_DAILINK_REG(AFE_SOF_DL2),
+ },
+ {
+ .name = "AFE_SOF_UL1",
+ .no_pcm = 1,
+ .dpcm_capture = 1,
+ SND_SOC_DAILINK_REG(AFE_SOF_UL1),
+ },
+ {
+ .name = "AFE_SOF_UL2",
+ .no_pcm = 1,
+ .dpcm_capture = 1,
+ SND_SOC_DAILINK_REG(AFE_SOF_UL2),
+ },
};
static const struct snd_soc_dapm_widget
mt8186_mt6366_da7219_max98357_widgets[] = {
SND_SOC_DAPM_SPK("Speakers", NULL),
+ SND_SOC_DAPM_HP("Headphones", NULL),
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_OUTPUT("HDMI1"),
+ SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0),
+ SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
+ SND_SOC_DAPM_MIXER(SOF_DMA_UL1, SND_SOC_NOPM, 0, 0, NULL, 0),
+ SND_SOC_DAPM_MIXER(SOF_DMA_UL2, SND_SOC_NOPM, 0, 0, NULL, 0),
};
static const struct snd_soc_dapm_route
mt8186_mt6366_da7219_max98357_routes[] = {
/* SPK */
{ "Speakers", NULL, "Speaker"},
+ /* Headset */
+ { "Headphones", NULL, "HPL" },
+ { "Headphones", NULL, "HPR" },
+ { "MIC", NULL, "Headset Mic" },
/* HDMI */
{ "HDMI1", NULL, "TX"},
+ /* SOF Uplink */
+ {SOF_DMA_UL1, NULL, "UL1_CH1"},
+ {SOF_DMA_UL1, NULL, "UL1_CH2"},
+ {SOF_DMA_UL2, NULL, "UL2_CH1"},
+ {SOF_DMA_UL2, NULL, "UL2_CH2"},
+ /* SOF Downlink */
+ {"DSP_DL1_VIRT", NULL, SOF_DMA_DL1},
+ {"DSP_DL2_VIRT", NULL, SOF_DMA_DL2},
};
static const struct snd_kcontrol_new
mt8186_mt6366_da7219_max98357_controls[] = {
SOC_DAPM_PIN_SWITCH("Speakers"),
+ SOC_DAPM_PIN_SWITCH("Headphones"),
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
SOC_DAPM_PIN_SWITCH("HDMI1"),
};
static struct snd_soc_card mt8186_mt6366_da7219_max98357_soc_card = {
- .name = "mt8186_mt6366_da7219_max98357",
+ .name = "mt8186_da7219_max98357",
.owner = THIS_MODULE,
.dai_link = mt8186_mt6366_da7219_max98357_dai_links,
.num_links = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_dai_links),
@@ -889,8 +1019,10 @@ static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev)
{
struct snd_soc_card *card;
struct snd_soc_dai_link *dai_link;
- struct mt8186_mt6366_da7219_max98357_priv *priv;
- struct device_node *platform_node, *headset_codec, *playback_codec;
+ struct mtk_soc_card_data *soc_card_data;
+ struct mt8186_mt6366_da7219_max98357_priv *mach_priv;
+ struct device_node *platform_node, *headset_codec, *playback_codec, *adsp_node;
+ int sof_on = 0;
int ret, i;
card = (struct snd_soc_card *)device_get_match_data(&pdev->dev);
@@ -898,11 +1030,60 @@ static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev)
return -EINVAL;
card->dev = &pdev->dev;
+ soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KERNEL);
+ if (!soc_card_data)
+ return -ENOMEM;
+ mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL);
+ if (!mach_priv)
+ return -ENOMEM;
+
+ soc_card_data->mach_priv = mach_priv;
+
+ adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0);
+ if (adsp_node) {
+ struct mtk_sof_priv *sof_priv;
+
+ sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL);
+ if (!sof_priv) {
+ ret = -ENOMEM;
+ goto err_adsp_node;
+ }
+ sof_priv->conn_streams = g_sof_conn_streams;
+ sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams);
+ sof_priv->sof_dai_link_fixup = mt8186_sof_dai_link_fixup;
+ soc_card_data->sof_priv = sof_priv;
+ card->probe = mtk_sof_card_probe;
+ card->late_probe = mtk_sof_card_late_probe;
+ if (!card->topology_shortname_created) {
+ snprintf(card->topology_shortname, 32, "sof-%s", card->name);
+ card->topology_shortname_created = true;
+ }
+ card->name = card->topology_shortname;
+ sof_on = 1;
+ } else {
+ dev_info(&pdev->dev, "Probe without adsp\n");
+ }
+
+ if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) {
+ ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node,
+ "mediatek,dai-link",
+ mt8186_mt6366_da7219_max98357_dai_links,
+ ARRAY_SIZE(mt8186_mt6366_da7219_max98357_dai_links));
+ if (ret) {
+ dev_dbg(&pdev->dev, "Parse dai-link fail\n");
+ goto err_adsp_node;
+ }
+ } else {
+ if (!sof_on)
+ card->num_links = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_dai_links)
+ - ARRAY_SIZE(g_sof_conn_streams);
+ }
+
platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
if (!platform_node) {
ret = -EINVAL;
dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n");
- return ret;
+ goto err_platform_node;
}
playback_codec = of_get_child_by_name(pdev->dev.of_node, "playback-codecs");
@@ -941,17 +1122,14 @@ static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev)
goto err_probe;
}
- if (!dai_link->platforms->name)
- dai_link->platforms->of_node = platform_node;
- }
+ if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on)
+ dai_link->platforms->of_node = adsp_node;
- priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
- if (!priv) {
- ret = -ENOMEM;
- goto err_probe;
+ if (!dai_link->platforms->name && !dai_link->platforms->of_node)
+ dai_link->platforms->of_node = platform_node;
}
- snd_soc_card_set_drvdata(card, priv);
+ snd_soc_card_set_drvdata(card, soc_card_data);
ret = mt8186_afe_gpio_init(&pdev->dev);
if (ret) {
@@ -969,6 +1147,9 @@ err_headset_codec:
of_node_put(playback_codec);
err_playback_codec:
of_node_put(platform_node);
+err_platform_node:
+err_adsp_node:
+ of_node_put(adsp_node);
return ret;
}