2019-05-30 02:57:50 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2008-12-04 23:39:54 +03:00
/*
* omap3pandora . c - - SoC audio for Pandora Handheld Console
*
* Author : Gražvydas Ignotas < notasas @ gmail . com >
*/
# include <linux/clk.h>
# include <linux/platform_device.h>
# include <linux/gpio.h>
# include <linux/delay.h>
2010-02-05 17:29:53 +03:00
# include <linux/regulator/consumer.h>
2011-07-15 20:38:28 +04:00
# include <linux/module.h>
2008-12-04 23:39:54 +03:00
# include <sound/core.h>
# include <sound/pcm.h>
# include <sound/soc.h>
# include <asm/mach-types.h>
2012-08-24 17:21:06 +04:00
# include <linux/platform_data/asoc-ti-mcbsp.h>
2008-12-04 23:39:54 +03:00
# include "omap-mcbsp.h"
# define OMAP3_PANDORA_DAC_POWER_GPIO 118
# define OMAP3_PANDORA_AMP_POWER_GPIO 14
# define PREFIX "ASoC omap3pandora: "
2010-02-05 17:29:53 +03:00
static struct regulator * omap3pandora_dac_reg ;
2010-06-17 17:45:28 +04:00
static int omap3pandora_hw_params ( struct snd_pcm_substream * substream ,
struct snd_pcm_hw_params * params )
2008-12-04 23:39:54 +03:00
{
2020-07-20 04:17:48 +03:00
struct snd_soc_pcm_runtime * rtd = asoc_substream_to_rtd ( substream ) ;
2020-03-23 08:21:14 +03:00
struct snd_soc_dai * codec_dai = asoc_rtd_to_codec ( rtd , 0 ) ;
struct snd_soc_dai * cpu_dai = asoc_rtd_to_cpu ( rtd , 0 ) ;
2008-12-04 23:39:54 +03:00
int ret ;
/* Set the codec system clock for DAC and ADC */
ret = snd_soc_dai_set_sysclk ( codec_dai , 0 , 26000000 ,
SND_SOC_CLOCK_IN ) ;
if ( ret < 0 ) {
pr_err ( PREFIX " can't set codec system clock \n " ) ;
return ret ;
}
/* Set McBSP clock to external */
2009-11-09 09:44:32 +03:00
ret = snd_soc_dai_set_sysclk ( cpu_dai , OMAP_MCBSP_SYSCLK_CLKS_EXT ,
256 * params_rate ( params ) ,
SND_SOC_CLOCK_IN ) ;
2008-12-04 23:39:54 +03:00
if ( ret < 0 ) {
pr_err ( PREFIX " can't set cpu system clock \n " ) ;
return ret ;
}
ret = snd_soc_dai_set_clkdiv ( cpu_dai , OMAP_MCBSP_CLKGDV , 8 ) ;
if ( ret < 0 ) {
pr_err ( PREFIX " can't set SRG clock divider \n " ) ;
return ret ;
}
return 0 ;
}
2010-02-05 17:29:53 +03:00
static int omap3pandora_dac_event ( struct snd_soc_dapm_widget * w ,
2008-12-04 23:39:54 +03:00
struct snd_kcontrol * k , int event )
{
2013-03-02 11:47:55 +04:00
int ret ;
2010-02-05 17:29:53 +03:00
/*
* The PCM1773 DAC datasheet requires 1 ms delay between switching
* VCC power on / off and / PD pin high / low
*/
2008-12-04 23:39:54 +03:00
if ( SND_SOC_DAPM_EVENT_ON ( event ) ) {
2013-03-02 11:47:55 +04:00
ret = regulator_enable ( omap3pandora_dac_reg ) ;
if ( ret ) {
2013-03-05 18:24:16 +04:00
dev_err ( w - > dapm - > dev , " Failed to power DAC: %d \n " , ret ) ;
2013-03-02 11:47:55 +04:00
return ret ;
}
2010-02-05 17:29:53 +03:00
mdelay ( 1 ) ;
2008-12-04 23:39:54 +03:00
gpio_set_value ( OMAP3_PANDORA_DAC_POWER_GPIO , 1 ) ;
} else {
gpio_set_value ( OMAP3_PANDORA_DAC_POWER_GPIO , 0 ) ;
2010-02-05 17:29:53 +03:00
mdelay ( 1 ) ;
regulator_disable ( omap3pandora_dac_reg ) ;
2008-12-04 23:39:54 +03:00
}
return 0 ;
}
2010-02-05 17:29:53 +03:00
static int omap3pandora_hp_event ( struct snd_soc_dapm_widget * w ,
struct snd_kcontrol * k , int event )
{
if ( SND_SOC_DAPM_EVENT_ON ( event ) )
gpio_set_value ( OMAP3_PANDORA_AMP_POWER_GPIO , 1 ) ;
else
gpio_set_value ( OMAP3_PANDORA_AMP_POWER_GPIO , 0 ) ;
return 0 ;
}
2008-12-04 23:39:54 +03:00
/*
* Audio paths on Pandora board :
*
* | O | - - - > PCM DAC + - > AMP - > Headphone Jack
* | M | A + - - - - - - - - > Line Out
* | A | < ~ ~ clk ~ ~ +
* | P | < - - - TWL4030 < - - - - - - - - - Line In and MICs
*/
2014-03-12 18:27:34 +04:00
static const struct snd_soc_dapm_widget omap3pandora_dapm_widgets [ ] = {
2010-02-05 17:29:53 +03:00
SND_SOC_DAPM_DAC_E ( " PCM DAC " , " HiFi Playback " , SND_SOC_NOPM ,
0 , 0 , omap3pandora_dac_event ,
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ) ,
2008-12-04 23:39:54 +03:00
SND_SOC_DAPM_PGA_E ( " Headphone Amplifier " , SND_SOC_NOPM ,
0 , 0 , NULL , 0 , omap3pandora_hp_event ,
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ) ,
SND_SOC_DAPM_HP ( " Headphone Jack " , NULL ) ,
SND_SOC_DAPM_LINE ( " Line Out " , NULL ) ,
2009-01-31 17:29:24 +03:00
SND_SOC_DAPM_MIC ( " Mic (internal) " , NULL ) ,
2008-12-04 23:39:54 +03:00
SND_SOC_DAPM_MIC ( " Mic (external) " , NULL ) ,
SND_SOC_DAPM_LINE ( " Line In " , NULL ) ,
} ;
2014-03-12 18:27:34 +04:00
static const struct snd_soc_dapm_route omap3pandora_map [ ] = {
2010-02-05 01:55:33 +03:00
{ " PCM DAC " , NULL , " APLL Enable " } ,
2008-12-04 23:39:54 +03:00
{ " Headphone Amplifier " , NULL , " PCM DAC " } ,
{ " Line Out " , NULL , " PCM DAC " } ,
{ " Headphone Jack " , NULL , " Headphone Amplifier " } ,
2009-01-31 17:29:24 +03:00
{ " AUXL " , NULL , " Line In " } ,
{ " AUXR " , NULL , " Line In " } ,
2012-12-31 14:51:45 +04:00
{ " MAINMIC " , NULL , " Mic (internal) " } ,
{ " Mic (internal) " , NULL , " Mic Bias 1 " } ,
2009-01-31 17:29:24 +03:00
2012-12-31 14:51:45 +04:00
{ " SUBMIC " , NULL , " Mic (external) " } ,
{ " Mic (external) " , NULL , " Mic Bias 2 " } ,
2008-12-04 23:39:54 +03:00
} ;
2010-03-17 23:15:21 +03:00
static int omap3pandora_out_init ( struct snd_soc_pcm_runtime * rtd )
2008-12-04 23:39:54 +03:00
{
2015-07-06 16:38:08 +03:00
struct snd_soc_dapm_context * dapm = & rtd - > card - > dapm ;
2008-12-04 23:39:54 +03:00
2009-01-31 17:29:24 +03:00
/* All TWL4030 output pins are floating */
2010-11-05 16:53:46 +03:00
snd_soc_dapm_nc_pin ( dapm , " EARPIECE " ) ;
snd_soc_dapm_nc_pin ( dapm , " PREDRIVEL " ) ;
snd_soc_dapm_nc_pin ( dapm , " PREDRIVER " ) ;
snd_soc_dapm_nc_pin ( dapm , " HSOL " ) ;
snd_soc_dapm_nc_pin ( dapm , " HSOR " ) ;
snd_soc_dapm_nc_pin ( dapm , " CARKITL " ) ;
snd_soc_dapm_nc_pin ( dapm , " CARKITR " ) ;
snd_soc_dapm_nc_pin ( dapm , " HFL " ) ;
snd_soc_dapm_nc_pin ( dapm , " HFR " ) ;
snd_soc_dapm_nc_pin ( dapm , " VIBRA " ) ;
2014-03-12 18:27:34 +04:00
return 0 ;
2008-12-04 23:39:54 +03:00
}
2010-03-17 23:15:21 +03:00
static int omap3pandora_in_init ( struct snd_soc_pcm_runtime * rtd )
2008-12-04 23:39:54 +03:00
{
2015-07-06 16:38:08 +03:00
struct snd_soc_dapm_context * dapm = & rtd - > card - > dapm ;
2008-12-04 23:39:54 +03:00
2009-01-31 17:29:24 +03:00
/* Not comnnected */
2010-11-05 16:53:46 +03:00
snd_soc_dapm_nc_pin ( dapm , " HSMIC " ) ;
snd_soc_dapm_nc_pin ( dapm , " CARKITMIC " ) ;
snd_soc_dapm_nc_pin ( dapm , " DIGIMIC0 " ) ;
snd_soc_dapm_nc_pin ( dapm , " DIGIMIC1 " ) ;
2008-12-23 13:04:48 +03:00
2014-03-12 18:27:34 +04:00
return 0 ;
2008-12-04 23:39:54 +03:00
}
2017-03-18 17:04:11 +03:00
static const struct snd_soc_ops omap3pandora_ops = {
2010-06-17 17:45:28 +04:00
. hw_params = omap3pandora_hw_params ,
2008-12-04 23:39:54 +03:00
} ;
/* Digital audio interface glue - connects codec <--> CPU */
2019-06-06 07:12:52 +03:00
SND_SOC_DAILINK_DEFS ( out ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " omap-mcbsp.2 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_CODEC ( " twl4030-codec " , " twl4030-hifi " ) ) ,
DAILINK_COMP_ARRAY ( COMP_PLATFORM ( " omap-mcbsp.2 " ) ) ) ;
SND_SOC_DAILINK_DEFS ( in ,
DAILINK_COMP_ARRAY ( COMP_CPU ( " omap-mcbsp.4 " ) ) ,
DAILINK_COMP_ARRAY ( COMP_CODEC ( " twl4030-codec " , " twl4030-hifi " ) ) ,
DAILINK_COMP_ARRAY ( COMP_PLATFORM ( " omap-mcbsp.4 " ) ) ) ;
2008-12-04 23:39:54 +03:00
static struct snd_soc_dai_link omap3pandora_dai [ ] = {
{
. name = " PCM1773 " ,
. stream_name = " HiFi Out " ,
2011-09-30 17:07:45 +04:00
. dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS ,
2010-06-17 17:45:28 +04:00
. ops = & omap3pandora_ops ,
2008-12-04 23:39:54 +03:00
. init = omap3pandora_out_init ,
2019-06-06 07:12:52 +03:00
SND_SOC_DAILINK_REG ( out ) ,
2008-12-04 23:39:54 +03:00
} , {
. name = " TWL4030 " ,
. stream_name = " Line/Mic In " ,
2011-09-30 17:07:45 +04:00
. dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBS_CFS ,
2010-06-17 17:45:28 +04:00
. ops = & omap3pandora_ops ,
2008-12-04 23:39:54 +03:00
. init = omap3pandora_in_init ,
2019-06-06 07:12:52 +03:00
SND_SOC_DAILINK_REG ( in ) ,
2008-12-04 23:39:54 +03:00
}
} ;
/* SoC card */
static struct snd_soc_card snd_soc_card_omap3pandora = {
. name = " omap3pandora " ,
2011-12-22 07:08:59 +04:00
. owner = THIS_MODULE ,
2008-12-04 23:39:54 +03:00
. dai_link = omap3pandora_dai ,
. num_links = ARRAY_SIZE ( omap3pandora_dai ) ,
2014-03-12 18:27:34 +04:00
. dapm_widgets = omap3pandora_dapm_widgets ,
. num_dapm_widgets = ARRAY_SIZE ( omap3pandora_dapm_widgets ) ,
. dapm_routes = omap3pandora_map ,
. num_dapm_routes = ARRAY_SIZE ( omap3pandora_map ) ,
2008-12-04 23:39:54 +03:00
} ;
static struct platform_device * omap3pandora_snd_device ;
static int __init omap3pandora_soc_init ( void )
{
int ret ;
2009-01-31 17:29:24 +03:00
if ( ! machine_is_omap3_pandora ( ) )
2008-12-04 23:39:54 +03:00
return - ENODEV ;
2009-01-31 17:29:24 +03:00
2008-12-04 23:39:54 +03:00
pr_info ( " OMAP3 Pandora SoC init \n " ) ;
ret = gpio_request ( OMAP3_PANDORA_DAC_POWER_GPIO , " dac_power " ) ;
if ( ret ) {
pr_err ( PREFIX " Failed to get DAC power GPIO \n " ) ;
return ret ;
}
ret = gpio_direction_output ( OMAP3_PANDORA_DAC_POWER_GPIO , 0 ) ;
if ( ret ) {
pr_err ( PREFIX " Failed to set DAC power GPIO direction \n " ) ;
goto fail0 ;
}
ret = gpio_request ( OMAP3_PANDORA_AMP_POWER_GPIO , " amp_power " ) ;
if ( ret ) {
pr_err ( PREFIX " Failed to get amp power GPIO \n " ) ;
goto fail0 ;
}
ret = gpio_direction_output ( OMAP3_PANDORA_AMP_POWER_GPIO , 0 ) ;
if ( ret ) {
pr_err ( PREFIX " Failed to set amp power GPIO direction \n " ) ;
goto fail1 ;
}
omap3pandora_snd_device = platform_device_alloc ( " soc-audio " , - 1 ) ;
if ( omap3pandora_snd_device = = NULL ) {
pr_err ( PREFIX " Platform device allocation failed \n " ) ;
ret = - ENOMEM ;
goto fail1 ;
}
2010-03-17 23:15:21 +03:00
platform_set_drvdata ( omap3pandora_snd_device , & snd_soc_card_omap3pandora ) ;
2008-12-04 23:39:54 +03:00
ret = platform_device_add ( omap3pandora_snd_device ) ;
if ( ret ) {
pr_err ( PREFIX " Unable to add platform device \n " ) ;
goto fail2 ;
}
2010-02-05 17:29:53 +03:00
omap3pandora_dac_reg = regulator_get ( & omap3pandora_snd_device - > dev , " vcc " ) ;
if ( IS_ERR ( omap3pandora_dac_reg ) ) {
pr_err ( PREFIX " Failed to get DAC regulator from %s: %ld \n " ,
dev_name ( & omap3pandora_snd_device - > dev ) ,
PTR_ERR ( omap3pandora_dac_reg ) ) ;
2010-11-24 10:20:48 +03:00
ret = PTR_ERR ( omap3pandora_dac_reg ) ;
2010-02-05 17:29:53 +03:00
goto fail3 ;
}
2008-12-04 23:39:54 +03:00
return 0 ;
2010-02-05 17:29:53 +03:00
fail3 :
platform_device_del ( omap3pandora_snd_device ) ;
2008-12-04 23:39:54 +03:00
fail2 :
platform_device_put ( omap3pandora_snd_device ) ;
fail1 :
gpio_free ( OMAP3_PANDORA_AMP_POWER_GPIO ) ;
fail0 :
gpio_free ( OMAP3_PANDORA_DAC_POWER_GPIO ) ;
return ret ;
}
module_init ( omap3pandora_soc_init ) ;
static void __exit omap3pandora_soc_exit ( void )
{
2010-02-05 17:29:53 +03:00
regulator_put ( omap3pandora_dac_reg ) ;
2008-12-04 23:39:54 +03:00
platform_device_unregister ( omap3pandora_snd_device ) ;
gpio_free ( OMAP3_PANDORA_AMP_POWER_GPIO ) ;
gpio_free ( OMAP3_PANDORA_DAC_POWER_GPIO ) ;
}
module_exit ( omap3pandora_soc_exit ) ;
MODULE_AUTHOR ( " Grazvydas Ignotas <notasas@gmail.com> " ) ;
MODULE_DESCRIPTION ( " ALSA SoC OMAP3 Pandora " ) ;
MODULE_LICENSE ( " GPL " ) ;