mt8195-mt6359.c (3a0323c26c6720447fd5eff6495c1aea514b77d5) mt8195-mt6359.c (86a6b9c9dffff1bd653d582cfc5138da75e5f7b0)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * mt8195-mt6359.c --
4 * MT8195-MT6359 ALSA SoC machine driver code
5 *
6 * Copyright (c) 2022 MediaTek Inc.
7 * Author: Trevor Wu <trevor.wu@mediatek.com>
8 * YC Hung <yc.hung@mediatek.com>

--- 11 unchanged lines hidden (view full) ---

20#include "../../codecs/rt1011.h"
21#include "../../codecs/rt5682.h"
22#include "../common/mtk-afe-platform-driver.h"
23#include "mt8195-afe-clk.h"
24#include "mt8195-afe-common.h"
25
26#define RT1011_SPEAKER_AMP_PRESENT BIT(0)
27#define RT1019_SPEAKER_AMP_PRESENT BIT(1)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * mt8195-mt6359.c --
4 * MT8195-MT6359 ALSA SoC machine driver code
5 *
6 * Copyright (c) 2022 MediaTek Inc.
7 * Author: Trevor Wu <trevor.wu@mediatek.com>
8 * YC Hung <yc.hung@mediatek.com>

--- 11 unchanged lines hidden (view full) ---

20#include "../../codecs/rt1011.h"
21#include "../../codecs/rt5682.h"
22#include "../common/mtk-afe-platform-driver.h"
23#include "mt8195-afe-clk.h"
24#include "mt8195-afe-common.h"
25
26#define RT1011_SPEAKER_AMP_PRESENT BIT(0)
27#define RT1019_SPEAKER_AMP_PRESENT BIT(1)
28#define MAX98390_SPEAKER_AMP_PRESENT BIT(2)
28
29#define RT1011_CODEC_DAI "rt1011-aif"
30#define RT1011_DEV0_NAME "rt1011.2-0038"
31#define RT1011_DEV1_NAME "rt1011.2-0039"
32
33#define RT1019_CODEC_DAI "HiFi"
34#define RT1019_DEV0_NAME "rt1019p"
35
29
30#define RT1011_CODEC_DAI "rt1011-aif"
31#define RT1011_DEV0_NAME "rt1011.2-0038"
32#define RT1011_DEV1_NAME "rt1011.2-0039"
33
34#define RT1019_CODEC_DAI "HiFi"
35#define RT1019_DEV0_NAME "rt1019p"
36
37#define MAX98390_CODEC_DAI "max98390-aif1"
38#define MAX98390_DEV0_NAME "max98390.2-0038" /* right */
39#define MAX98390_DEV1_NAME "max98390.2-0039" /* left */
40
36#define RT5682_CODEC_DAI "rt5682-aif1"
37#define RT5682_DEV0_NAME "rt5682.2-001a"
38
39#define RT5682S_CODEC_DAI "rt5682s-aif1"
40#define RT5682S_DEV0_NAME "rt5682s.2-001a"
41
42#define SOF_DMA_DL2 "SOF_DMA_DL2"
43#define SOF_DMA_DL3 "SOF_DMA_DL3"

--- 72 unchanged lines hidden (view full) ---

116 { "Left Spk", NULL, "Left SPO" },
117 { "Right Spk", NULL, "Right SPO" },
118};
119
120static const struct snd_soc_dapm_route mt8195_rt1019_routes[] = {
121 { "Ext Spk", NULL, "Speaker" },
122};
123
41#define RT5682_CODEC_DAI "rt5682-aif1"
42#define RT5682_DEV0_NAME "rt5682.2-001a"
43
44#define RT5682S_CODEC_DAI "rt5682s-aif1"
45#define RT5682S_DEV0_NAME "rt5682s.2-001a"
46
47#define SOF_DMA_DL2 "SOF_DMA_DL2"
48#define SOF_DMA_DL3 "SOF_DMA_DL3"

--- 72 unchanged lines hidden (view full) ---

121 { "Left Spk", NULL, "Left SPO" },
122 { "Right Spk", NULL, "Right SPO" },
123};
124
125static const struct snd_soc_dapm_route mt8195_rt1019_routes[] = {
126 { "Ext Spk", NULL, "Speaker" },
127};
128
129static const struct snd_soc_dapm_route mt8195_max98390_routes[] = {
130 { "Left Spk", NULL, "Left BE_OUT" },
131 { "Right Spk", NULL, "Right BE_OUT" },
132};
133
124#define CKSYS_AUD_TOP_CFG 0x032c
125#define CKSYS_AUD_TOP_MON 0x0330
126
127static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
128{
129 struct snd_soc_component *cmpnt_afe =
130 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
131 struct snd_soc_component *cmpnt_codec =

--- 531 unchanged lines hidden (view full) ---

663 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes,
664 ARRAY_SIZE(mt8195_rt1019_routes));
665 if (ret)
666 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
667
668 return ret;
669}
670
134#define CKSYS_AUD_TOP_CFG 0x032c
135#define CKSYS_AUD_TOP_MON 0x0330
136
137static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
138{
139 struct snd_soc_component *cmpnt_afe =
140 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
141 struct snd_soc_component *cmpnt_codec =

--- 531 unchanged lines hidden (view full) ---

673 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes,
674 ARRAY_SIZE(mt8195_rt1019_routes));
675 if (ret)
676 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
677
678 return ret;
679}
680
681static int mt8195_max98390_init(struct snd_soc_pcm_runtime *rtd)
682{
683 struct snd_soc_card *card = rtd->card;
684 int ret;
685
686 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets,
687 ARRAY_SIZE(mt8195_dual_speaker_widgets));
688 if (ret) {
689 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
690 /* Don't need to add routes if widget addition failed */
691 return ret;
692 }
693
694 ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls,
695 ARRAY_SIZE(mt8195_dual_speaker_controls));
696 if (ret) {
697 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
698 return ret;
699 }
700
701 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_max98390_routes,
702 ARRAY_SIZE(mt8195_max98390_routes));
703 if (ret)
704 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
705
706 return ret;
707}
708
671static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
672 struct snd_pcm_hw_params *params)
673{
674 /* fix BE i2s format to S24_LE, clean param mask first */
675 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
676 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
677
678 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);

--- 242 unchanged lines hidden (view full) ---

921 RT1019_CODEC_DAI)));
922
923SND_SOC_DAILINK_DEF(rt1011_comps,
924 DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME,
925 RT1011_CODEC_DAI),
926 COMP_CODEC(RT1011_DEV1_NAME,
927 RT1011_CODEC_DAI)));
928
709static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
710 struct snd_pcm_hw_params *params)
711{
712 /* fix BE i2s format to S24_LE, clean param mask first */
713 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
714 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
715
716 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);

--- 242 unchanged lines hidden (view full) ---

959 RT1019_CODEC_DAI)));
960
961SND_SOC_DAILINK_DEF(rt1011_comps,
962 DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME,
963 RT1011_CODEC_DAI),
964 COMP_CODEC(RT1011_DEV1_NAME,
965 RT1011_CODEC_DAI)));
966
967SND_SOC_DAILINK_DEF(max98390_comps,
968 DAILINK_COMP_ARRAY(COMP_CODEC(MAX98390_DEV0_NAME,
969 MAX98390_CODEC_DAI),
970 COMP_CODEC(MAX98390_DEV1_NAME,
971 MAX98390_CODEC_DAI)));
972
929static const struct sof_conn_stream g_sof_conn_streams[] = {
930 { "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK},
931 { "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3, SNDRV_PCM_STREAM_PLAYBACK},
932 { "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4, SNDRV_PCM_STREAM_CAPTURE},
933 { "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5, SNDRV_PCM_STREAM_CAPTURE},
934};
935
936static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = {

--- 307 unchanged lines hidden (view full) ---

1244 .name_prefix = "Left",
1245 },
1246 {
1247 .dlc = COMP_CODEC_CONF(RT1011_DEV1_NAME),
1248 .name_prefix = "Right",
1249 },
1250};
1251
973static const struct sof_conn_stream g_sof_conn_streams[] = {
974 { "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK},
975 { "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3, SNDRV_PCM_STREAM_PLAYBACK},
976 { "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4, SNDRV_PCM_STREAM_CAPTURE},
977 { "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5, SNDRV_PCM_STREAM_CAPTURE},
978};
979
980static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = {

--- 307 unchanged lines hidden (view full) ---

1288 .name_prefix = "Left",
1289 },
1290 {
1291 .dlc = COMP_CODEC_CONF(RT1011_DEV1_NAME),
1292 .name_prefix = "Right",
1293 },
1294};
1295
1296static struct snd_soc_codec_conf max98390_codec_conf[] = {
1297 {
1298 .dlc = COMP_CODEC_CONF(MAX98390_DEV0_NAME),
1299 .name_prefix = "Right",
1300 },
1301 {
1302 .dlc = COMP_CODEC_CONF(MAX98390_DEV1_NAME),
1303 .name_prefix = "Left",
1304 },
1305};
1306
1252static struct snd_soc_card mt8195_mt6359_soc_card = {
1253 .owner = THIS_MODULE,
1254 .dai_link = mt8195_mt6359_dai_links,
1255 .num_links = ARRAY_SIZE(mt8195_mt6359_dai_links),
1256 .controls = mt8195_mt6359_controls,
1257 .num_controls = ARRAY_SIZE(mt8195_mt6359_controls),
1258 .dapm_widgets = mt8195_mt6359_widgets,
1259 .num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets),

--- 279 unchanged lines hidden (view full) ---

1539 card->codec_conf = rt1011_codec_conf;
1540 card->num_configs = ARRAY_SIZE(rt1011_codec_conf);
1541 break;
1542 case RT1019_SPEAKER_AMP_PRESENT:
1543 dai_link->codecs = rt1019_comps;
1544 dai_link->num_codecs = ARRAY_SIZE(rt1019_comps);
1545 dai_link->init = mt8195_rt1019_init;
1546 break;
1307static struct snd_soc_card mt8195_mt6359_soc_card = {
1308 .owner = THIS_MODULE,
1309 .dai_link = mt8195_mt6359_dai_links,
1310 .num_links = ARRAY_SIZE(mt8195_mt6359_dai_links),
1311 .controls = mt8195_mt6359_controls,
1312 .num_controls = ARRAY_SIZE(mt8195_mt6359_controls),
1313 .dapm_widgets = mt8195_mt6359_widgets,
1314 .num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets),

--- 279 unchanged lines hidden (view full) ---

1594 card->codec_conf = rt1011_codec_conf;
1595 card->num_configs = ARRAY_SIZE(rt1011_codec_conf);
1596 break;
1597 case RT1019_SPEAKER_AMP_PRESENT:
1598 dai_link->codecs = rt1019_comps;
1599 dai_link->num_codecs = ARRAY_SIZE(rt1019_comps);
1600 dai_link->init = mt8195_rt1019_init;
1601 break;
1602 case MAX98390_SPEAKER_AMP_PRESENT:
1603 dai_link->codecs = max98390_comps;
1604 dai_link->num_codecs = ARRAY_SIZE(max98390_comps);
1605 dai_link->init = mt8195_max98390_init;
1606 card->codec_conf = max98390_codec_conf;
1607 card->num_configs = ARRAY_SIZE(max98390_codec_conf);
1608 break;
1547 default:
1548 break;
1549 }
1550 }
1551 }
1552
1553 if (sof_on)
1554 card->late_probe = mt8195_mt6359_card_late_probe;

--- 14 unchanged lines hidden (view full) ---

1569 .quirk = RT1019_SPEAKER_AMP_PRESENT,
1570};
1571
1572static struct mt8195_card_data mt8195_mt6359_rt1011_rt5682_card = {
1573 .name = "mt8195_r1011_5682",
1574 .quirk = RT1011_SPEAKER_AMP_PRESENT,
1575};
1576
1609 default:
1610 break;
1611 }
1612 }
1613 }
1614
1615 if (sof_on)
1616 card->late_probe = mt8195_mt6359_card_late_probe;

--- 14 unchanged lines hidden (view full) ---

1631 .quirk = RT1019_SPEAKER_AMP_PRESENT,
1632};
1633
1634static struct mt8195_card_data mt8195_mt6359_rt1011_rt5682_card = {
1635 .name = "mt8195_r1011_5682",
1636 .quirk = RT1011_SPEAKER_AMP_PRESENT,
1637};
1638
1639static struct mt8195_card_data mt8195_mt6359_max98390_rt5682_card = {
1640 .name = "mt8195_m98390_r5682",
1641 .quirk = MAX98390_SPEAKER_AMP_PRESENT,
1642};
1643
1577#ifdef CONFIG_OF
1578static const struct of_device_id mt8195_mt6359_dt_match[] = {
1579 {
1580 .compatible = "mediatek,mt8195_mt6359_rt1019_rt5682",
1581 .data = &mt8195_mt6359_rt1019_rt5682_card,
1582 },
1583 {
1584 .compatible = "mediatek,mt8195_mt6359_rt1011_rt5682",
1585 .data = &mt8195_mt6359_rt1011_rt5682_card,
1586 },
1644#ifdef CONFIG_OF
1645static const struct of_device_id mt8195_mt6359_dt_match[] = {
1646 {
1647 .compatible = "mediatek,mt8195_mt6359_rt1019_rt5682",
1648 .data = &mt8195_mt6359_rt1019_rt5682_card,
1649 },
1650 {
1651 .compatible = "mediatek,mt8195_mt6359_rt1011_rt5682",
1652 .data = &mt8195_mt6359_rt1011_rt5682_card,
1653 },
1654 {
1655 .compatible = "mediatek,mt8195_mt6359_max98390_rt5682",
1656 .data = &mt8195_mt6359_max98390_rt5682_card,
1657 },
1587};
1588#endif
1589
1590static const struct dev_pm_ops mt8195_mt6359_pm_ops = {
1591 .poweroff = snd_soc_poweroff,
1592 .restore = snd_soc_resume,
1593};
1594

--- 19 unchanged lines hidden ---
1658};
1659#endif
1660
1661static const struct dev_pm_ops mt8195_mt6359_pm_ops = {
1662 .poweroff = snd_soc_poweroff,
1663 .restore = snd_soc_resume,
1664};
1665

--- 19 unchanged lines hidden ---