2018-04-27 04:54:44 +03:00
// SPDX-License-Identifier: GPL-2.0
//
// mt6797-mt6351.c -- MT6797 MT6351 ALSA SoC machine driver
//
// Copyright (c) 2018 MediaTek Inc.
// Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
2018-04-25 10:25:21 +03:00
# include <linux/module.h>
# include <sound/soc.h>
# include "mt6797-afe-common.h"
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_DEFS ( playback_1 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " DL1 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( playback_2 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " DL2 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( playback_3 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " DL3 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( capture_1 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " UL1 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( capture_2 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " UL2 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( capture_3 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " UL3 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( capture_mono_1 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " UL_MONO_1 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( hostless_lpbk ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " Hostless LPBK DAI " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( hostless_speech ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " Hostless Speech DAI " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( primary_codec ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " ADDA " ) ) ,
DAILINK_COMP_ARRAY ( COMP_CODEC ( NULL , " mt6351-snd-codec-aif1 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( pcm1 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " PCM 1 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
SND_SOC_DAILINK_DEFS ( pcm2 ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " PCM 2 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ,
DAILINK_COMP_ARRAY ( COMP_EMPTY ( ) ) ) ;
2018-04-25 10:25:21 +03:00
static struct snd_soc_dai_link mt6797_mt6351_dai_links [ ] = {
/* FE */
{
. name = " Playback_1 " ,
. stream_name = " Playback_1 " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_playback = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( playback_1 ) ,
2018-04-25 10:25:21 +03:00
} ,
{
. name = " Playback_2 " ,
. stream_name = " Playback_2 " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_playback = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( playback_2 ) ,
2018-04-25 10:25:21 +03:00
} ,
{
. name = " Playback_3 " ,
. stream_name = " Playback_3 " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_playback = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( playback_3 ) ,
2018-04-25 10:25:21 +03:00
} ,
{
. name = " Capture_1 " ,
. stream_name = " Capture_1 " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_capture = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( capture_1 ) ,
2018-04-25 10:25:21 +03:00
} ,
{
. name = " Capture_2 " ,
. stream_name = " Capture_2 " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_capture = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( capture_2 ) ,
2018-04-25 10:25:21 +03:00
} ,
{
. name = " Capture_3 " ,
. stream_name = " Capture_3 " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_capture = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( capture_3 ) ,
2018-04-25 10:25:21 +03:00
} ,
{
. name = " Capture_Mono_1 " ,
. stream_name = " Capture_Mono_1 " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_capture = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( capture_mono_1 ) ,
2018-04-25 10:25:21 +03:00
} ,
2018-05-31 04:26:21 +03:00
{
. name = " Hostless_LPBK " ,
. stream_name = " Hostless_LPBK " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_playback = 1 ,
. dpcm_capture = 1 ,
. ignore_suspend = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( hostless_lpbk ) ,
2018-05-31 04:26:21 +03:00
} ,
{
. name = " Hostless_Speech " ,
. stream_name = " Hostless_Speech " ,
. trigger = { SND_SOC_DPCM_TRIGGER_PRE ,
SND_SOC_DPCM_TRIGGER_PRE } ,
. dynamic = 1 ,
. dpcm_playback = 1 ,
. dpcm_capture = 1 ,
. ignore_suspend = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( hostless_speech ) ,
2018-05-31 04:26:21 +03:00
} ,
2018-04-25 10:25:21 +03:00
/* BE */
{
. name = " Primary Codec " ,
. no_pcm = 1 ,
. dpcm_playback = 1 ,
. dpcm_capture = 1 ,
. ignore_suspend = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( primary_codec ) ,
2018-04-25 10:25:21 +03:00
} ,
2018-05-31 04:26:21 +03:00
{
. name = " PCM 1 " ,
. no_pcm = 1 ,
. dpcm_playback = 1 ,
. dpcm_capture = 1 ,
. ignore_suspend = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( pcm1 ) ,
2018-05-31 04:26:21 +03:00
} ,
{
. name = " PCM 2 " ,
. no_pcm = 1 ,
. dpcm_playback = 1 ,
. dpcm_capture = 1 ,
. ignore_suspend = 1 ,
2019-06-06 07:07:49 +03:00
SND_SOC_DAILINK_REG ( pcm2 ) ,
2018-05-31 04:26:21 +03:00
} ,
2018-04-25 10:25:21 +03:00
} ;
static struct snd_soc_card mt6797_mt6351_card = {
. name = " mt6797-mt6351 " ,
. owner = THIS_MODULE ,
. dai_link = mt6797_mt6351_dai_links ,
. num_links = ARRAY_SIZE ( mt6797_mt6351_dai_links ) ,
} ;
static int mt6797_mt6351_dev_probe ( struct platform_device * pdev )
{
struct snd_soc_card * card = & mt6797_mt6351_card ;
struct device_node * platform_node , * codec_node ;
2018-09-18 04:28:49 +03:00
struct snd_soc_dai_link * dai_link ;
2018-04-25 10:25:21 +03:00
int ret , i ;
card - > dev = & pdev - > dev ;
platform_node = of_parse_phandle ( pdev - > dev . of_node ,
" mediatek,platform " , 0 ) ;
if ( ! platform_node ) {
dev_err ( & pdev - > dev , " Property 'platform' missing or invalid \n " ) ;
return - EINVAL ;
}
2018-09-18 04:28:49 +03:00
for_each_card_prelinks ( card , i , dai_link ) {
2019-06-06 07:07:49 +03:00
if ( dai_link - > platforms - > name )
2018-04-25 10:25:21 +03:00
continue ;
2019-06-06 07:07:49 +03:00
dai_link - > platforms - > of_node = platform_node ;
2018-04-25 10:25:21 +03:00
}
codec_node = of_parse_phandle ( pdev - > dev . of_node ,
" mediatek,audio-codec " , 0 ) ;
if ( ! codec_node ) {
dev_err ( & pdev - > dev ,
" Property 'audio-codec' missing or invalid \n " ) ;
2022-06-03 11:34:15 +03:00
ret = - EINVAL ;
goto put_platform_node ;
2018-04-25 10:25:21 +03:00
}
2018-09-18 04:28:49 +03:00
for_each_card_prelinks ( card , i , dai_link ) {
2019-06-06 07:07:49 +03:00
if ( dai_link - > codecs - > name )
2018-04-25 10:25:21 +03:00
continue ;
2019-06-06 07:07:49 +03:00
dai_link - > codecs - > of_node = codec_node ;
2018-04-25 10:25:21 +03:00
}
ret = devm_snd_soc_register_card ( & pdev - > dev , card ) ;
if ( ret )
dev_err ( & pdev - > dev , " %s snd_soc_register_card fail %d \n " ,
__func__ , ret ) ;
2022-06-03 11:34:15 +03:00
of_node_put ( codec_node ) ;
put_platform_node :
of_node_put ( platform_node ) ;
2018-04-25 10:25:21 +03:00
return ret ;
}
# ifdef CONFIG_OF
static const struct of_device_id mt6797_mt6351_dt_match [ ] = {
{ . compatible = " mediatek,mt6797-mt6351-sound " , } ,
{ }
} ;
# endif
static struct platform_driver mt6797_mt6351_driver = {
. driver = {
. name = " mt6797-mt6351 " ,
# ifdef CONFIG_OF
. of_match_table = mt6797_mt6351_dt_match ,
# endif
} ,
. probe = mt6797_mt6351_dev_probe ,
} ;
module_platform_driver ( mt6797_mt6351_driver ) ;
/* Module information */
MODULE_DESCRIPTION ( " MT6797 MT6351 ALSA SoC machine driver " ) ;
MODULE_AUTHOR ( " KaiChieh Chuang <kaichieh.chuang@mediatek.com> " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;
MODULE_ALIAS ( " mt6797 mt6351 soc card " ) ;