2019-05-29 17:17:59 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2015-02-05 05:19:32 +03:00
/*
* cht - bsw - rt5645 . c - ASoc Machine driver for Intel Cherryview - based platforms
* Cherrytrail and Braswell , with RT5645 codec .
*
* Copyright ( C ) 2015 Intel Corp
* Author : Fang , Yang A < yang . a . fang @ intel . com >
* N , Harshapriya < harshapriya . n @ intel . com >
* This file is modified from cht_bsw_rt5672 . c
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*/
# include <linux/module.h>
# include <linux/platform_device.h>
2017-10-13 02:37:59 +03:00
# include <linux/acpi.h>
# include <linux/clk.h>
2017-01-26 23:09:43 +03:00
# include <linux/dmi.h>
2015-02-05 05:19:32 +03:00
# include <linux/slab.h>
# include <sound/pcm.h>
# include <sound/pcm_params.h>
# include <sound/soc.h>
# include <sound/jack.h>
2017-10-13 02:49:38 +03:00
# include <sound/soc-acpi.h>
2015-04-02 10:37:02 +03:00
# include "../../codecs/rt5645.h"
2015-04-02 10:37:04 +03:00
# include "../atom/sst-atom-controls.h"
2019-05-30 14:50:11 +03:00
# include "../common/soc-intel-quirks.h"
2015-02-05 05:19:32 +03:00
# define CHT_PLAT_CLK_3_HZ 19200000
2017-01-26 23:09:43 +03:00
# define CHT_CODEC_DAI1 "rt5645-aif1"
# define CHT_CODEC_DAI2 "rt5645-aif2"
2015-02-05 05:19:32 +03:00
2015-04-23 20:23:02 +03:00
struct cht_acpi_card {
char * codec_id ;
int codec_type ;
struct snd_soc_card * soc_card ;
} ;
2015-02-05 05:19:32 +03:00
struct cht_mc_private {
2015-05-06 02:55:34 +03:00
struct snd_soc_jack jack ;
2015-04-23 20:23:02 +03:00
struct cht_acpi_card * acpi_card ;
2018-01-11 22:52:09 +03:00
char codec_name [ SND_ACPI_I2C_ID_LEN ] ;
2017-01-26 23:09:38 +03:00
struct clk * mclk ;
2015-02-05 05:19:32 +03:00
} ;
2017-10-13 02:37:59 +03:00
# define CHT_RT5645_MAP(quirk) ((quirk) & GENMASK(7, 0))
2017-01-26 23:09:43 +03:00
# define CHT_RT5645_SSP2_AIF2 BIT(16) /* default is using AIF1 */
# define CHT_RT5645_SSP0_AIF1 BIT(17)
# define CHT_RT5645_SSP0_AIF2 BIT(18)
2019-09-17 08:49:33 +03:00
# define CHT_RT5645_PMC_PLT_CLK_0 BIT(19)
2017-01-26 23:09:43 +03:00
static unsigned long cht_rt5645_quirk = 0 ;
static void log_quirks ( struct device * dev )
{
if ( cht_rt5645_quirk & CHT_RT5645_SSP2_AIF2 )
dev_info ( dev , " quirk SSP2_AIF2 enabled " ) ;
if ( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF1 )
dev_info ( dev , " quirk SSP0_AIF1 enabled " ) ;
if ( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2 )
dev_info ( dev , " quirk SSP0_AIF2 enabled " ) ;
2019-09-17 08:49:33 +03:00
if ( cht_rt5645_quirk & CHT_RT5645_PMC_PLT_CLK_0 )
dev_info ( dev , " quirk PMC_PLT_CLK_0 enabled " ) ;
2017-01-26 23:09:43 +03:00
}
2015-02-05 05:19:32 +03:00
static int platform_clock_control ( struct snd_soc_dapm_widget * w ,
struct snd_kcontrol * k , int event )
{
struct snd_soc_dapm_context * dapm = w - > dapm ;
struct snd_soc_card * card = dapm - > card ;
struct snd_soc_dai * codec_dai ;
2017-01-26 23:09:38 +03:00
struct cht_mc_private * ctx = snd_soc_card_get_drvdata ( card ) ;
2015-02-05 05:19:32 +03:00
int ret ;
2017-10-13 02:38:03 +03:00
codec_dai = snd_soc_card_get_codec_dai ( card , CHT_CODEC_DAI1 ) ;
if ( ! codec_dai )
codec_dai = snd_soc_card_get_codec_dai ( card , CHT_CODEC_DAI2 ) ;
2015-02-05 05:19:32 +03:00
if ( ! codec_dai ) {
dev_err ( card - > dev , " Codec dai not found; Unable to set platform clock \n " ) ;
return - EIO ;
}
2017-01-26 23:09:38 +03:00
if ( SND_SOC_DAPM_EVENT_ON ( event ) ) {
2017-10-13 02:37:59 +03:00
ret = clk_prepare_enable ( ctx - > mclk ) ;
if ( ret < 0 ) {
dev_err ( card - > dev ,
" could not configure MCLK state " ) ;
return ret ;
2017-01-26 23:09:38 +03:00
}
} else {
/* Set codec sysclk source to its internal clock because codec PLL will
* be off when idle and MCLK will also be off when codec is
* runtime suspended . Codec needs clock for jack detection and button
* press . MCLK is turned off with clock framework or ACPI .
*/
ret = snd_soc_dai_set_sysclk ( codec_dai , RT5645_SCLK_S_RCCLK ,
48000 * 512 , SND_SOC_CLOCK_IN ) ;
if ( ret < 0 ) {
dev_err ( card - > dev , " can't set codec sysclk: %d \n " , ret ) ;
return ret ;
}
2015-02-05 05:19:32 +03:00
2017-10-13 02:37:59 +03:00
clk_disable_unprepare ( ctx - > mclk ) ;
2015-02-05 05:19:32 +03:00
}
return 0 ;
}
static const struct snd_soc_dapm_widget cht_dapm_widgets [ ] = {
SND_SOC_DAPM_HP ( " Headphone " , NULL ) ,
SND_SOC_DAPM_MIC ( " Headset Mic " , NULL ) ,
SND_SOC_DAPM_MIC ( " Int Mic " , NULL ) ,
2018-01-02 21:53:14 +03:00
SND_SOC_DAPM_MIC ( " Int Analog Mic " , NULL ) ,
2015-02-05 05:19:32 +03:00
SND_SOC_DAPM_SPK ( " Ext Spk " , NULL ) ,
SND_SOC_DAPM_SUPPLY ( " Platform Clock " , SND_SOC_NOPM , 0 , 0 ,
2017-01-26 23:09:38 +03:00
platform_clock_control , SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD ) ,
2015-02-05 05:19:32 +03:00
} ;
2015-04-23 20:23:02 +03:00
static const struct snd_soc_dapm_route cht_rt5645_audio_map [ ] = {
2015-02-05 05:19:32 +03:00
{ " IN1P " , NULL , " Headset Mic " } ,
{ " IN1N " , NULL , " Headset Mic " } ,
{ " DMIC L1 " , NULL , " Int Mic " } ,
{ " DMIC R1 " , NULL , " Int Mic " } ,
2018-01-02 21:53:14 +03:00
{ " IN2P " , NULL , " Int Analog Mic " } ,
{ " IN2N " , NULL , " Int Analog Mic " } ,
2015-02-05 05:19:32 +03:00
{ " Headphone " , NULL , " HPOL " } ,
{ " Headphone " , NULL , " HPOR " } ,
{ " Ext Spk " , NULL , " SPOL " } ,
{ " Ext Spk " , NULL , " SPOR " } ,
{ " Headphone " , NULL , " Platform Clock " } ,
{ " Headset Mic " , NULL , " Platform Clock " } ,
{ " Int Mic " , NULL , " Platform Clock " } ,
2018-01-02 21:53:14 +03:00
{ " Int Analog Mic " , NULL , " Platform Clock " } ,
{ " Int Analog Mic " , NULL , " micbias1 " } ,
{ " Int Analog Mic " , NULL , " micbias2 " } ,
2015-02-05 05:19:32 +03:00
{ " Ext Spk " , NULL , " Platform Clock " } ,
} ;
2015-04-23 20:23:02 +03:00
static const struct snd_soc_dapm_route cht_rt5650_audio_map [ ] = {
{ " IN1P " , NULL , " Headset Mic " } ,
{ " IN1N " , NULL , " Headset Mic " } ,
{ " DMIC L2 " , NULL , " Int Mic " } ,
{ " DMIC R2 " , NULL , " Int Mic " } ,
{ " Headphone " , NULL , " HPOL " } ,
{ " Headphone " , NULL , " HPOR " } ,
{ " Ext Spk " , NULL , " SPOL " } ,
{ " Ext Spk " , NULL , " SPOR " } ,
2017-01-26 23:09:43 +03:00
{ " Headphone " , NULL , " Platform Clock " } ,
{ " Headset Mic " , NULL , " Platform Clock " } ,
{ " Int Mic " , NULL , " Platform Clock " } ,
{ " Ext Spk " , NULL , " Platform Clock " } ,
} ;
static const struct snd_soc_dapm_route cht_rt5645_ssp2_aif1_map [ ] = {
2015-04-23 20:23:02 +03:00
{ " AIF1 Playback " , NULL , " ssp2 Tx " } ,
{ " ssp2 Tx " , NULL , " codec_out0 " } ,
{ " ssp2 Tx " , NULL , " codec_out1 " } ,
{ " codec_in0 " , NULL , " ssp2 Rx " } ,
{ " codec_in1 " , NULL , " ssp2 Rx " } ,
{ " ssp2 Rx " , NULL , " AIF1 Capture " } ,
2017-01-26 23:09:43 +03:00
} ;
static const struct snd_soc_dapm_route cht_rt5645_ssp2_aif2_map [ ] = {
{ " AIF2 Playback " , NULL , " ssp2 Tx " } ,
{ " ssp2 Tx " , NULL , " codec_out0 " } ,
{ " ssp2 Tx " , NULL , " codec_out1 " } ,
{ " codec_in0 " , NULL , " ssp2 Rx " } ,
{ " codec_in1 " , NULL , " ssp2 Rx " } ,
{ " ssp2 Rx " , NULL , " AIF2 Capture " } ,
} ;
static const struct snd_soc_dapm_route cht_rt5645_ssp0_aif1_map [ ] = {
{ " AIF1 Playback " , NULL , " ssp0 Tx " } ,
{ " ssp0 Tx " , NULL , " modem_out " } ,
{ " modem_in " , NULL , " ssp0 Rx " } ,
{ " ssp0 Rx " , NULL , " AIF1 Capture " } ,
} ;
static const struct snd_soc_dapm_route cht_rt5645_ssp0_aif2_map [ ] = {
{ " AIF2 Playback " , NULL , " ssp0 Tx " } ,
{ " ssp0 Tx " , NULL , " modem_out " } ,
{ " modem_in " , NULL , " ssp0 Rx " } ,
{ " ssp0 Rx " , NULL , " AIF2 Capture " } ,
2015-04-23 20:23:02 +03:00
} ;
2015-02-05 05:19:32 +03:00
static const struct snd_kcontrol_new cht_mc_controls [ ] = {
SOC_DAPM_PIN_SWITCH ( " Headphone " ) ,
SOC_DAPM_PIN_SWITCH ( " Headset Mic " ) ,
SOC_DAPM_PIN_SWITCH ( " Int Mic " ) ,
2018-01-02 21:53:14 +03:00
SOC_DAPM_PIN_SWITCH ( " Int Analog Mic " ) ,
2015-02-05 05:19:32 +03:00
SOC_DAPM_PIN_SWITCH ( " Ext Spk " ) ,
} ;
2016-02-17 00:27:19 +03:00
static struct snd_soc_jack_pin cht_bsw_jack_pins [ ] = {
{
. pin = " Headphone " ,
. mask = SND_JACK_HEADPHONE ,
} ,
{
. pin = " Headset Mic " ,
. mask = SND_JACK_MICROPHONE ,
} ,
} ;
2015-02-05 05:19:32 +03:00
static int cht_aif1_hw_params ( struct snd_pcm_substream * substream ,
struct snd_pcm_hw_params * params )
{
2023-09-26 09:24:24 +03:00
struct snd_soc_pcm_runtime * rtd = snd_soc_substream_to_rtd ( substream ) ;
struct snd_soc_dai * codec_dai = snd_soc_rtd_to_codec ( rtd , 0 ) ;
2015-02-05 05:19:32 +03:00
int ret ;
/* set codec PLL source to the 19.2MHz platform clock (MCLK) */
ret = snd_soc_dai_set_pll ( codec_dai , 0 , RT5645_PLL1_S_MCLK ,
CHT_PLAT_CLK_3_HZ , params_rate ( params ) * 512 ) ;
if ( ret < 0 ) {
dev_err ( rtd - > dev , " can't set codec pll: %d \n " , ret ) ;
return ret ;
}
ret = snd_soc_dai_set_sysclk ( codec_dai , RT5645_SCLK_S_PLL1 ,
params_rate ( params ) * 512 , SND_SOC_CLOCK_IN ) ;
if ( ret < 0 ) {
dev_err ( rtd - > dev , " can't set codec sysclk: %d \n " , ret ) ;
return ret ;
}
return 0 ;
}
2017-01-26 23:09:43 +03:00
static int cht_rt5645_quirk_cb ( const struct dmi_system_id * id )
{
cht_rt5645_quirk = ( unsigned long ) id - > driver_data ;
return 1 ;
}
static const struct dmi_system_id cht_rt5645_quirk_table [ ] = {
2019-09-17 08:49:33 +03:00
{
/* Strago family Chromebooks */
. callback = cht_rt5645_quirk_cb ,
. matches = {
DMI_MATCH ( DMI_PRODUCT_FAMILY , " Intel_Strago " ) ,
} ,
. driver_data = ( void * ) CHT_RT5645_PMC_PLT_CLK_0 ,
} ,
2017-01-26 23:09:43 +03:00
{
} ,
} ;
2015-02-05 05:19:32 +03:00
static int cht_codec_init ( struct snd_soc_pcm_runtime * runtime )
{
2017-01-26 23:09:43 +03:00
struct snd_soc_card * card = runtime - > card ;
2015-02-05 05:19:32 +03:00
struct cht_mc_private * ctx = snd_soc_card_get_drvdata ( runtime - > card ) ;
2023-09-26 09:24:24 +03:00
struct snd_soc_component * component = snd_soc_rtd_to_codec ( runtime , 0 ) - > component ;
2017-10-13 02:37:59 +03:00
int jack_type ;
int ret ;
2015-02-05 05:19:32 +03:00
2017-01-26 23:09:44 +03:00
if ( ( cht_rt5645_quirk & CHT_RT5645_SSP2_AIF2 ) | |
( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2 ) ) {
/* Select clk_i2s2_asrc as ASRC clock source */
2018-01-29 06:49:31 +03:00
rt5645_sel_asrc_clk_src ( component ,
2017-01-26 23:09:44 +03:00
RT5645_DA_STEREO_FILTER |
RT5645_DA_MONO_L_FILTER |
RT5645_DA_MONO_R_FILTER |
RT5645_AD_STEREO_FILTER ,
RT5645_CLK_SEL_I2S2_ASRC ) ;
} else {
/* Select clk_i2s1_asrc as ASRC clock source */
2018-01-29 06:49:31 +03:00
rt5645_sel_asrc_clk_src ( component ,
2017-01-26 23:09:44 +03:00
RT5645_DA_STEREO_FILTER |
RT5645_DA_MONO_L_FILTER |
RT5645_DA_MONO_R_FILTER |
RT5645_AD_STEREO_FILTER ,
RT5645_CLK_SEL_I2S1_ASRC ) ;
}
2015-02-05 05:19:32 +03:00
2017-01-26 23:09:43 +03:00
if ( cht_rt5645_quirk & CHT_RT5645_SSP2_AIF2 ) {
ret = snd_soc_dapm_add_routes ( & card - > dapm ,
cht_rt5645_ssp2_aif2_map ,
ARRAY_SIZE ( cht_rt5645_ssp2_aif2_map ) ) ;
} else if ( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF1 ) {
ret = snd_soc_dapm_add_routes ( & card - > dapm ,
cht_rt5645_ssp0_aif1_map ,
ARRAY_SIZE ( cht_rt5645_ssp0_aif1_map ) ) ;
} else if ( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2 ) {
ret = snd_soc_dapm_add_routes ( & card - > dapm ,
cht_rt5645_ssp0_aif2_map ,
ARRAY_SIZE ( cht_rt5645_ssp0_aif2_map ) ) ;
} else {
ret = snd_soc_dapm_add_routes ( & card - > dapm ,
cht_rt5645_ssp2_aif1_map ,
ARRAY_SIZE ( cht_rt5645_ssp2_aif1_map ) ) ;
}
if ( ret )
return ret ;
2015-05-06 02:55:34 +03:00
if ( ctx - > acpi_card - > codec_type = = CODEC_TYPE_RT5650 )
jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
SND_JACK_BTN_0 | SND_JACK_BTN_1 |
SND_JACK_BTN_2 | SND_JACK_BTN_3 ;
else
jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE ;
2015-02-05 05:19:32 +03:00
2022-04-08 07:11:14 +03:00
ret = snd_soc_card_jack_new_pins ( runtime - > card , " Headset " , jack_type ,
& ctx - > jack , cht_bsw_jack_pins ,
ARRAY_SIZE ( cht_bsw_jack_pins ) ) ;
2015-02-05 05:19:32 +03:00
if ( ret ) {
2015-05-06 02:55:34 +03:00
dev_err ( runtime - > dev , " Headset jack creation failed %d \n " , ret ) ;
2015-02-05 05:19:32 +03:00
return ret ;
}
2018-01-29 06:49:31 +03:00
rt5645_set_jack_detect ( component , & ctx - > jack , & ctx - > jack , & ctx - > jack ) ;
2015-02-05 05:19:32 +03:00
2017-01-26 23:09:38 +03:00
2017-10-13 02:37:59 +03:00
/*
* The firmware might enable the clock at
* boot ( this information may or may not
* be reflected in the enable clock register ) .
* To change the rate we must disable the clock
* first to cover these cases . Due to common
* clock framework restrictions that do not allow
* to disable a clock that has not been enabled ,
* we need to enable the clock first .
*/
ret = clk_prepare_enable ( ctx - > mclk ) ;
if ( ! ret )
clk_disable_unprepare ( ctx - > mclk ) ;
ret = clk_set_rate ( ctx - > mclk , CHT_PLAT_CLK_3_HZ ) ;
if ( ret )
dev_err ( runtime - > dev , " unable to set MCLK rate \n " ) ;
2017-01-26 23:09:38 +03:00
2015-02-05 05:19:32 +03:00
return ret ;
}
static int cht_codec_fixup ( struct snd_soc_pcm_runtime * rtd ,
struct snd_pcm_hw_params * params )
{
2017-01-26 23:09:43 +03:00
int ret ;
2015-02-05 05:19:32 +03:00
struct snd_interval * rate = hw_param_interval ( params ,
SNDRV_PCM_HW_PARAM_RATE ) ;
struct snd_interval * channels = hw_param_interval ( params ,
SNDRV_PCM_HW_PARAM_CHANNELS ) ;
2022-10-24 22:08:40 +03:00
/* The DSP will convert the FE rate to 48k, stereo, 24bits */
2015-02-05 05:19:32 +03:00
rate - > min = rate - > max = 48000 ;
channels - > min = channels - > max = 2 ;
2017-01-26 23:09:43 +03:00
if ( ( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF1 ) | |
( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2 ) ) {
/* set SSP0 to 16-bit */
params_set_format ( params , SNDRV_PCM_FORMAT_S16_LE ) ;
/*
* Default mode for SSP configuration is TDM 4 slot , override config
* with explicit setting to I2S 2 ch 16 - bit . The word length is set with
* dai_set_tdm_slot ( ) since there is no other API exposed
*/
2023-09-26 09:24:24 +03:00
ret = snd_soc_dai_set_fmt ( snd_soc_rtd_to_cpu ( rtd , 0 ) ,
2017-01-26 23:09:43 +03:00
SND_SOC_DAIFMT_I2S |
2017-01-26 23:09:45 +03:00
SND_SOC_DAIFMT_NB_NF |
2022-05-19 18:42:33 +03:00
SND_SOC_DAIFMT_BP_FP
2017-01-26 23:09:45 +03:00
) ;
if ( ret < 0 ) {
dev_err ( rtd - > dev , " can't set format to I2S, err %d \n " , ret ) ;
return ret ;
}
2023-09-26 09:24:24 +03:00
ret = snd_soc_dai_set_fmt ( snd_soc_rtd_to_codec ( rtd , 0 ) ,
2017-01-26 23:09:45 +03:00
SND_SOC_DAIFMT_I2S |
SND_SOC_DAIFMT_NB_NF |
2022-05-19 18:42:33 +03:00
SND_SOC_DAIFMT_BC_FC
2017-01-26 23:09:43 +03:00
) ;
if ( ret < 0 ) {
dev_err ( rtd - > dev , " can't set format to I2S, err %d \n " , ret ) ;
return ret ;
}
2023-09-26 09:24:24 +03:00
ret = snd_soc_dai_set_tdm_slot ( snd_soc_rtd_to_cpu ( rtd , 0 ) , 0x3 , 0x3 , 2 , 16 ) ;
2017-01-26 23:09:43 +03:00
if ( ret < 0 ) {
dev_err ( rtd - > dev , " can't set I2S config, err %d \n " , ret ) ;
return ret ;
}
} else {
/* set SSP2 to 24-bit */
params_set_format ( params , SNDRV_PCM_FORMAT_S24_LE ) ;
2017-01-26 23:09:45 +03:00
/*
* Default mode for SSP configuration is TDM 4 slot
*/
2023-09-26 09:24:24 +03:00
ret = snd_soc_dai_set_fmt ( snd_soc_rtd_to_codec ( rtd , 0 ) ,
2017-01-26 23:09:45 +03:00
SND_SOC_DAIFMT_DSP_B |
SND_SOC_DAIFMT_IB_NF |
2022-05-19 18:42:33 +03:00
SND_SOC_DAIFMT_BC_FC ) ;
2017-01-26 23:09:45 +03:00
if ( ret < 0 ) {
dev_err ( rtd - > dev , " can't set format to TDM %d \n " , ret ) ;
return ret ;
}
/* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */
2023-09-26 09:24:24 +03:00
ret = snd_soc_dai_set_tdm_slot ( snd_soc_rtd_to_codec ( rtd , 0 ) , 0xF , 0xF , 4 , 24 ) ;
2017-01-26 23:09:45 +03:00
if ( ret < 0 ) {
dev_err ( rtd - > dev , " can't set codec TDM slot %d \n " , ret ) ;
return ret ;
}
2017-01-26 23:09:43 +03:00
}
2015-02-05 05:19:32 +03:00
return 0 ;
}
static int cht_aif1_startup ( struct snd_pcm_substream * substream )
{
2015-10-18 16:39:32 +03:00
return snd_pcm_hw_constraint_single ( substream - > runtime ,
SNDRV_PCM_HW_PARAM_RATE , 48000 ) ;
2015-02-05 05:19:32 +03:00
}
2016-10-15 17:55:49 +03:00
static const struct snd_soc_ops cht_aif1_ops = {
2015-02-05 05:19:32 +03:00
. startup = cht_aif1_startup ,
} ;
2016-10-15 17:55:49 +03:00
static const struct snd_soc_ops cht_be_ssp2_ops = {
2015-02-05 05:19:32 +03:00
. hw_params = cht_aif1_hw_params ,
} ;
2019-06-06 07:20:48 +03:00
SND_SOC_DAILINK_DEF ( dummy ,
DAILINK_COMP_ARRAY ( COMP_DUMMY ( ) ) ) ;
SND_SOC_DAILINK_DEF ( media ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " media-cpu-dai " ) ) ) ;
SND_SOC_DAILINK_DEF ( deepbuffer ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " deepbuffer-cpu-dai " ) ) ) ;
SND_SOC_DAILINK_DEF ( ssp2_port ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " ssp2-port " ) ) ) ;
SND_SOC_DAILINK_DEF ( ssp2_codec ,
DAILINK_COMP_ARRAY ( COMP_CODEC ( " i2c-10EC5645:00 " , " rt5645-aif1 " ) ) ) ;
SND_SOC_DAILINK_DEF ( platform ,
DAILINK_COMP_ARRAY ( COMP_PLATFORM ( " sst-mfld-platform " ) ) ) ;
2015-02-05 05:19:32 +03:00
static struct snd_soc_dai_link cht_dailink [ ] = {
[ MERR_DPCM_AUDIO ] = {
. name = " Audio Port " ,
. stream_name = " Audio " ,
2015-04-23 20:23:02 +03:00
. nonatomic = true ,
2015-02-05 05:19:32 +03:00
. dynamic = 1 ,
. dpcm_playback = 1 ,
. dpcm_capture = 1 ,
. ops = & cht_aif1_ops ,
2019-06-06 07:20:48 +03:00
SND_SOC_DAILINK_REG ( media , dummy , platform ) ,
2015-02-05 05:19:32 +03:00
} ,
2015-12-18 05:35:45 +03:00
[ MERR_DPCM_DEEP_BUFFER ] = {
. name = " Deep-Buffer Audio Port " ,
. stream_name = " Deep-Buffer Audio " ,
. nonatomic = true ,
. dynamic = 1 ,
. dpcm_playback = 1 ,
. ops = & cht_aif1_ops ,
2019-06-06 07:20:48 +03:00
SND_SOC_DAILINK_REG ( deepbuffer , dummy , platform ) ,
2015-12-18 05:35:45 +03:00
} ,
2015-02-05 05:19:32 +03:00
/* CODEC<->CODEC link */
/* back ends */
{
. name = " SSP2-Codec " ,
2017-10-13 02:38:04 +03:00
. id = 0 ,
2015-02-05 05:19:32 +03:00
. no_pcm = 1 ,
. init = cht_codec_init ,
. be_hw_params_fixup = cht_codec_fixup ,
. dpcm_playback = 1 ,
. dpcm_capture = 1 ,
. ops = & cht_be_ssp2_ops ,
2019-06-06 07:20:48 +03:00
SND_SOC_DAILINK_REG ( ssp2_port , ssp2_codec , platform ) ,
2015-02-05 05:19:32 +03:00
} ,
} ;
2020-06-17 19:56:15 +03:00
/* use space before codec name to simplify card ID, and simplify driver name */
2020-11-13 01:38:16 +03:00
# define SOF_CARD_RT5645_NAME "bytcht rt5645" /* card name 'sof-bytcht rt5645' */
# define SOF_CARD_RT5650_NAME "bytcht rt5650" /* card name 'sof-bytcht rt5650' */
# define SOF_DRIVER_NAME "SOF"
2020-06-17 19:56:15 +03:00
# define CARD_RT5645_NAME "chtrt5645"
# define CARD_RT5650_NAME "chtrt5650"
# define DRIVER_NAME NULL /* card name will be used for driver name */
2015-02-05 05:19:32 +03:00
/* SoC card */
2015-04-23 20:23:02 +03:00
static struct snd_soc_card snd_soc_card_chtrt5645 = {
2015-08-21 15:59:21 +03:00
. owner = THIS_MODULE ,
2015-02-05 05:19:32 +03:00
. dai_link = cht_dailink ,
. num_links = ARRAY_SIZE ( cht_dailink ) ,
. dapm_widgets = cht_dapm_widgets ,
. num_dapm_widgets = ARRAY_SIZE ( cht_dapm_widgets ) ,
2015-04-23 20:23:02 +03:00
. dapm_routes = cht_rt5645_audio_map ,
. num_dapm_routes = ARRAY_SIZE ( cht_rt5645_audio_map ) ,
2015-02-05 05:19:32 +03:00
. controls = cht_mc_controls ,
. num_controls = ARRAY_SIZE ( cht_mc_controls ) ,
} ;
2015-04-23 20:23:02 +03:00
static struct snd_soc_card snd_soc_card_chtrt5650 = {
2015-08-21 15:59:21 +03:00
. owner = THIS_MODULE ,
2015-04-23 20:23:02 +03:00
. dai_link = cht_dailink ,
. num_links = ARRAY_SIZE ( cht_dailink ) ,
. dapm_widgets = cht_dapm_widgets ,
. num_dapm_widgets = ARRAY_SIZE ( cht_dapm_widgets ) ,
. dapm_routes = cht_rt5650_audio_map ,
. num_dapm_routes = ARRAY_SIZE ( cht_rt5650_audio_map ) ,
. controls = cht_mc_controls ,
. num_controls = ARRAY_SIZE ( cht_mc_controls ) ,
} ;
static struct cht_acpi_card snd_soc_cards [ ] = {
2016-07-08 13:09:51 +03:00
{ " 10EC5640 " , CODEC_TYPE_RT5645 , & snd_soc_card_chtrt5645 } ,
2015-04-23 20:23:02 +03:00
{ " 10EC5645 " , CODEC_TYPE_RT5645 , & snd_soc_card_chtrt5645 } ,
2017-01-26 23:09:36 +03:00
{ " 10EC5648 " , CODEC_TYPE_RT5645 , & snd_soc_card_chtrt5645 } ,
2017-01-26 23:09:40 +03:00
{ " 10EC3270 " , CODEC_TYPE_RT5645 , & snd_soc_card_chtrt5645 } ,
2015-04-23 20:23:02 +03:00
{ " 10EC5650 " , CODEC_TYPE_RT5650 , & snd_soc_card_chtrt5650 } ,
} ;
2018-01-11 22:52:09 +03:00
static char cht_rt5645_codec_name [ SND_ACPI_I2C_ID_LEN ] ;
2016-07-08 13:09:51 +03:00
2017-01-26 23:09:43 +03:00
struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
u64 aif_value ; /* 1: AIF1, 2: AIF2 */
u64 mclock_value ; /* usually 25MHz (0x17d7940), ignored */
} ;
2015-02-05 05:19:32 +03:00
static int snd_cht_mc_probe ( struct platform_device * pdev )
{
2015-04-23 20:23:02 +03:00
struct snd_soc_card * card = snd_soc_cards [ 0 ] . soc_card ;
2017-10-13 02:49:38 +03:00
struct snd_soc_acpi_mach * mach ;
2019-01-25 23:35:05 +03:00
const char * platform_name ;
2017-10-13 02:37:59 +03:00
struct cht_mc_private * drv ;
2019-03-28 20:17:27 +03:00
struct acpi_device * adev ;
2020-11-13 01:38:16 +03:00
bool sof_parent ;
2017-01-26 23:09:41 +03:00
bool found = false ;
2017-01-26 23:09:43 +03:00
bool is_bytcr = false ;
2017-10-13 02:37:59 +03:00
int dai_index = 0 ;
int ret_val = 0 ;
int i ;
2019-09-17 08:49:33 +03:00
const char * mclk_name ;
2015-02-05 05:19:32 +03:00
2018-04-09 13:48:31 +03:00
drv = devm_kzalloc ( & pdev - > dev , sizeof ( * drv ) , GFP_KERNEL ) ;
2015-02-05 05:19:32 +03:00
if ( ! drv )
return - ENOMEM ;
2020-03-12 22:48:56 +03:00
mach = pdev - > dev . platform_data ;
2017-01-26 23:09:41 +03:00
2015-04-23 20:23:02 +03:00
for ( i = 0 ; i < ARRAY_SIZE ( snd_soc_cards ) ; i + + ) {
2017-01-26 23:09:41 +03:00
if ( acpi_dev_found ( snd_soc_cards [ i ] . codec_id ) & &
( ! strncmp ( snd_soc_cards [ i ] . codec_id , mach - > id , 8 ) ) ) {
2015-04-23 20:23:02 +03:00
dev_dbg ( & pdev - > dev ,
" found codec %s \n " , snd_soc_cards [ i ] . codec_id ) ;
card = snd_soc_cards [ i ] . soc_card ;
drv - > acpi_card = & snd_soc_cards [ i ] ;
2017-01-26 23:09:41 +03:00
found = true ;
2015-04-23 20:23:02 +03:00
break ;
}
}
2017-01-26 23:09:41 +03:00
if ( ! found ) {
dev_err ( & pdev - > dev , " No matching HID found in supported list \n " ) ;
return - ENODEV ;
}
2015-04-23 20:23:02 +03:00
card - > dev = & pdev - > dev ;
2016-11-22 20:11:08 +03:00
sprintf ( drv - > codec_name , " i2c-%s:00 " , drv - > acpi_card - > codec_id ) ;
2016-02-23 11:50:20 +03:00
2015-04-23 20:23:02 +03:00
/* set correct codec name */
2016-02-23 11:50:20 +03:00
for ( i = 0 ; i < ARRAY_SIZE ( cht_dailink ) ; i + + )
2019-06-06 07:20:48 +03:00
if ( ! strcmp ( card - > dai_link [ i ] . codecs - > name ,
" i2c-10EC5645:00 " ) ) {
card - > dai_link [ i ] . codecs - > name = drv - > codec_name ;
2016-07-08 13:09:51 +03:00
dai_index = i ;
}
/* fixup codec name based on HID */
2019-03-28 20:17:27 +03:00
adev = acpi_dev_get_first_match_dev ( mach - > id , NULL , - 1 ) ;
if ( adev ) {
2017-01-26 23:09:43 +03:00
snprintf ( cht_rt5645_codec_name , sizeof ( cht_rt5645_codec_name ) ,
2019-03-28 20:17:27 +03:00
" i2c-%s " , acpi_dev_name ( adev ) ) ;
2019-06-06 07:20:48 +03:00
cht_dailink [ dai_index ] . codecs - > name = cht_rt5645_codec_name ;
2017-01-26 23:09:43 +03:00
}
2023-01-02 23:30:35 +03:00
acpi_dev_put ( adev ) ;
2017-01-26 23:09:43 +03:00
/*
* swap SSP0 if bytcr is detected
* ( will be overridden if DMI quirk is detected )
*/
2019-05-30 14:50:11 +03:00
if ( soc_intel_is_byt ( ) ) {
2018-11-02 00:34:50 +03:00
if ( mach - > mach_params . acpi_ipc_irq_index = = 0 )
2017-01-26 23:09:43 +03:00
is_bytcr = true ;
}
if ( is_bytcr ) {
/*
* Baytrail CR platforms may have CHAN package in BIOS , try
* to find relevant routing quirk based as done on Windows
* platforms . We have to read the information directly from the
* BIOS , at this stage the card is not created and the links
* with the codec driver / pdata are non - existent
*/
2022-05-21 00:17:12 +03:00
struct acpi_chan_package chan_package = { 0 } ;
2017-01-26 23:09:43 +03:00
/* format specified: 2 64-bit integers */
struct acpi_buffer format = { sizeof ( " NN " ) , " NN " } ;
struct acpi_buffer state = { 0 , NULL } ;
2017-10-13 02:49:38 +03:00
struct snd_soc_acpi_package_context pkg_ctx ;
2017-01-26 23:09:43 +03:00
bool pkg_found = false ;
state . length = sizeof ( chan_package ) ;
state . pointer = & chan_package ;
pkg_ctx . name = " CHAN " ;
pkg_ctx . length = 2 ;
pkg_ctx . format = & format ;
pkg_ctx . state = & state ;
pkg_ctx . data_valid = false ;
2017-10-13 02:49:38 +03:00
pkg_found = snd_soc_acpi_find_package_from_hid ( mach - > id ,
& pkg_ctx ) ;
2017-01-26 23:09:43 +03:00
if ( pkg_found ) {
if ( chan_package . aif_value = = 1 ) {
dev_info ( & pdev - > dev , " BIOS Routing: AIF1 connected \n " ) ;
cht_rt5645_quirk | = CHT_RT5645_SSP0_AIF1 ;
} else if ( chan_package . aif_value = = 2 ) {
dev_info ( & pdev - > dev , " BIOS Routing: AIF2 connected \n " ) ;
cht_rt5645_quirk | = CHT_RT5645_SSP0_AIF2 ;
} else {
dev_info ( & pdev - > dev , " BIOS Routing isn't valid, ignored \n " ) ;
pkg_found = false ;
}
}
if ( ! pkg_found ) {
/* no BIOS indications, assume SSP0-AIF2 connection */
cht_rt5645_quirk | = CHT_RT5645_SSP0_AIF2 ;
}
}
/* check quirks before creating card */
dmi_check_system ( cht_rt5645_quirk_table ) ;
log_quirks ( & pdev - > dev ) ;
if ( ( cht_rt5645_quirk & CHT_RT5645_SSP2_AIF2 ) | |
2020-01-15 19:46:19 +03:00
( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2 ) )
cht_dailink [ dai_index ] . codecs - > dai_name = " rt5645-aif2 " ;
2017-01-26 23:09:43 +03:00
if ( ( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF1 ) | |
2020-01-15 19:46:19 +03:00
( cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2 ) )
cht_dailink [ dai_index ] . cpus - > dai_name = " ssp0-port " ;
2016-02-23 11:50:20 +03:00
2022-03-01 22:48:57 +03:00
/* override platform name, if required */
2019-01-25 23:35:05 +03:00
platform_name = mach - > mach_params . platform ;
ret_val = snd_soc_fixup_dai_links_platform_name ( card ,
platform_name ) ;
if ( ret_val )
return ret_val ;
2019-09-17 08:49:33 +03:00
if ( cht_rt5645_quirk & CHT_RT5645_PMC_PLT_CLK_0 )
mclk_name = " pmc_plt_clk_0 " ;
else
mclk_name = " pmc_plt_clk_3 " ;
drv - > mclk = devm_clk_get ( & pdev - > dev , mclk_name ) ;
2017-09-08 20:43:52 +03:00
if ( IS_ERR ( drv - > mclk ) ) {
2019-09-17 08:49:33 +03:00
dev_err ( & pdev - > dev , " Failed to get MCLK from %s: %ld \n " ,
mclk_name , PTR_ERR ( drv - > mclk ) ) ;
2017-09-08 20:43:52 +03:00
return PTR_ERR ( drv - > mclk ) ;
2017-01-26 23:09:38 +03:00
}
2015-04-23 20:23:02 +03:00
snd_soc_card_set_drvdata ( card , drv ) ;
2020-11-13 01:38:16 +03:00
sof_parent = snd_soc_acpi_sof_parent ( & pdev - > dev ) ;
/* set card and driver name */
if ( sof_parent ) {
snd_soc_card_chtrt5645 . name = SOF_CARD_RT5645_NAME ;
snd_soc_card_chtrt5645 . driver_name = SOF_DRIVER_NAME ;
snd_soc_card_chtrt5650 . name = SOF_CARD_RT5650_NAME ;
snd_soc_card_chtrt5650 . driver_name = SOF_DRIVER_NAME ;
} else {
snd_soc_card_chtrt5645 . name = CARD_RT5645_NAME ;
snd_soc_card_chtrt5645 . driver_name = DRIVER_NAME ;
snd_soc_card_chtrt5650 . name = CARD_RT5650_NAME ;
snd_soc_card_chtrt5650 . driver_name = DRIVER_NAME ;
}
2020-11-13 01:38:17 +03:00
/* set pm ops */
if ( sof_parent )
pdev - > dev . driver - > pm = & snd_soc_pm_ops ;
2015-04-23 20:23:02 +03:00
ret_val = devm_snd_soc_register_card ( & pdev - > dev , card ) ;
2015-02-05 05:19:32 +03:00
if ( ret_val ) {
dev_err ( & pdev - > dev ,
" snd_soc_register_card failed %d \n " , ret_val ) ;
return ret_val ;
}
2015-04-23 20:23:02 +03:00
platform_set_drvdata ( pdev , card ) ;
2015-02-05 05:19:32 +03:00
return ret_val ;
}
static struct platform_driver snd_cht_mc_driver = {
. driver = {
. name = " cht-bsw-rt5645 " ,
} ,
. probe = snd_cht_mc_probe ,
} ;
module_platform_driver ( snd_cht_mc_driver )
MODULE_DESCRIPTION ( " ASoC Intel(R) Braswell Machine driver " ) ;
MODULE_AUTHOR ( " Fang, Yang A,N,Harshapriya " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;
MODULE_ALIAS ( " platform:cht-bsw-rt5645 " ) ;