2019-05-27 09:55:05 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2010-03-11 18:32:59 +03:00
/*
* ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
*
* Copyright ( C ) 2010 Texas Instruments , Inc
*
* Author : Miguel Aguilar < miguel . aguilar @ ridgerun . com >
*/
# include <linux/module.h>
# include <linux/moduleparam.h>
# include <linux/init.h>
# include <linux/io.h>
# include <linux/delay.h>
# include <linux/pm.h>
# include <linux/platform_device.h>
# include <linux/device.h>
2010-03-29 21:52:29 +04:00
# include <linux/slab.h>
2010-03-11 18:32:59 +03:00
# include <linux/clk.h>
# include <linux/mfd/davinci_voicecodec.h>
2010-03-17 23:15:21 +03:00
# include <linux/spi/spi.h>
2010-03-11 18:32:59 +03:00
# include <sound/core.h>
# include <sound/pcm.h>
# include <sound/pcm_params.h>
# include <sound/soc.h>
# include <sound/initval.h>
static const struct snd_kcontrol_new cq93vc_snd_controls [ ] = {
SOC_SINGLE ( " PGA Capture Volume " , DAVINCI_VC_REG05 , 0 , 0x03 , 0 ) ,
SOC_SINGLE ( " Mono DAC Playback Volume " , DAVINCI_VC_REG09 , 0 , 0x3f , 0 ) ,
} ;
2020-07-09 04:56:20 +03:00
static int cq93vc_mute ( struct snd_soc_dai * dai , int mute , int direction )
2010-03-11 18:32:59 +03:00
{
2018-01-29 07:42:49 +03:00
struct snd_soc_component * component = dai - > component ;
2013-08-31 16:38:16 +04:00
u8 reg ;
2010-03-11 18:32:59 +03:00
if ( mute )
2013-08-31 16:38:16 +04:00
reg = DAVINCI_VC_REG09_MUTE ;
2010-03-11 18:32:59 +03:00
else
2013-08-31 16:38:16 +04:00
reg = 0 ;
2018-01-29 07:42:49 +03:00
snd_soc_component_update_bits ( component , DAVINCI_VC_REG09 , DAVINCI_VC_REG09_MUTE ,
2013-08-31 16:38:16 +04:00
reg ) ;
2010-03-11 18:32:59 +03:00
return 0 ;
}
static int cq93vc_set_dai_sysclk ( struct snd_soc_dai * codec_dai ,
int clk_id , unsigned int freq , int dir )
{
switch ( freq ) {
case 22579200 :
case 27000000 :
case 33868800 :
return 0 ;
}
return - EINVAL ;
}
2018-01-29 07:42:49 +03:00
static int cq93vc_set_bias_level ( struct snd_soc_component * component ,
2010-03-11 18:32:59 +03:00
enum snd_soc_bias_level level )
{
switch ( level ) {
case SND_SOC_BIAS_ON :
2018-01-29 07:42:49 +03:00
snd_soc_component_write ( component , DAVINCI_VC_REG12 ,
2010-03-11 18:32:59 +03:00
DAVINCI_VC_REG12_POWER_ALL_ON ) ;
break ;
case SND_SOC_BIAS_PREPARE :
break ;
case SND_SOC_BIAS_STANDBY :
2018-01-29 07:42:49 +03:00
snd_soc_component_write ( component , DAVINCI_VC_REG12 ,
2010-03-11 18:32:59 +03:00
DAVINCI_VC_REG12_POWER_ALL_OFF ) ;
break ;
case SND_SOC_BIAS_OFF :
/* force all power off */
2018-01-29 07:42:49 +03:00
snd_soc_component_write ( component , DAVINCI_VC_REG12 ,
2010-03-11 18:32:59 +03:00
DAVINCI_VC_REG12_POWER_ALL_OFF ) ;
break ;
}
return 0 ;
}
# define CQ93VC_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
# define CQ93VC_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
2011-11-23 14:40:40 +04:00
static const struct snd_soc_dai_ops cq93vc_dai_ops = {
2020-07-09 04:56:20 +03:00
. mute_stream = cq93vc_mute ,
2010-03-11 18:32:59 +03:00
. set_sysclk = cq93vc_set_dai_sysclk ,
2020-07-09 04:56:20 +03:00
. no_capture_mute = 1 ,
2010-03-11 18:32:59 +03:00
} ;
2010-03-17 23:15:21 +03:00
static struct snd_soc_dai_driver cq93vc_dai = {
. name = " cq93vc-hifi " ,
2010-03-11 18:32:59 +03:00
. playback = {
. stream_name = " Playback " ,
. channels_min = 1 ,
. channels_max = 2 ,
. rates = CQ93VC_RATES ,
. formats = CQ93VC_FORMATS , } ,
. capture = {
. stream_name = " Capture " ,
. channels_min = 1 ,
. channels_max = 2 ,
. rates = CQ93VC_RATES ,
. formats = CQ93VC_FORMATS , } ,
. ops = & cq93vc_dai_ops ,
} ;
2017-11-28 09:05:46 +03:00
static int cq93vc_probe ( struct snd_soc_component * component )
2014-03-26 09:40:25 +04:00
{
2017-11-28 09:05:46 +03:00
struct davinci_vc * davinci_vc = component - > dev - > platform_data ;
2014-03-26 09:40:25 +04:00
2017-11-28 09:05:46 +03:00
snd_soc_component_init_regmap ( component , davinci_vc - > regmap ) ;
return 0 ;
2014-03-26 09:40:25 +04:00
}
2018-01-29 07:42:49 +03:00
static const struct snd_soc_component_driver soc_component_dev_cq93vc = {
. set_bias_level = cq93vc_set_bias_level ,
. probe = cq93vc_probe ,
. controls = cq93vc_snd_controls ,
. num_controls = ARRAY_SIZE ( cq93vc_snd_controls ) ,
. idle_bias_on = 1 ,
. use_pmdown_time = 1 ,
. endianness = 1 ,
. non_legacy_dai_naming = 1 ,
2010-03-11 18:32:59 +03:00
} ;
2010-03-17 23:15:21 +03:00
static int cq93vc_platform_probe ( struct platform_device * pdev )
2010-03-11 18:32:59 +03:00
{
2018-01-29 07:42:49 +03:00
return devm_snd_soc_register_component ( & pdev - > dev ,
& soc_component_dev_cq93vc , & cq93vc_dai , 1 ) ;
2010-03-11 18:32:59 +03:00
}
2010-03-17 23:15:21 +03:00
static int cq93vc_platform_remove ( struct platform_device * pdev )
2010-03-11 18:32:59 +03:00
{
return 0 ;
}
static struct platform_driver cq93vc_codec_driver = {
. driver = {
2010-03-17 23:15:21 +03:00
. name = " cq93vc-codec " ,
} ,
. probe = cq93vc_platform_probe ,
2012-12-07 18:26:37 +04:00
. remove = cq93vc_platform_remove ,
2010-03-11 18:32:59 +03:00
} ;
2011-11-24 02:52:08 +04:00
module_platform_driver ( cq93vc_codec_driver ) ;
2010-03-11 18:32:59 +03:00
MODULE_DESCRIPTION ( " Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver " ) ;
MODULE_AUTHOR ( " Miguel Aguilar " ) ;
MODULE_LICENSE ( " GPL " ) ;