2010-03-11 15:32:59 +00:00
|
|
|
/*
|
|
|
|
* ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Texas Instruments, Inc
|
|
|
|
*
|
|
|
|
* Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#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 17:52:29 +00:00
|
|
|
#include <linux/slab.h>
|
2010-03-11 15:32:59 +00:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/mfd/davinci_voicecodec.h>
|
2010-03-17 20:15:21 +00:00
|
|
|
#include <linux/spi/spi.h>
|
2010-03-11 15:32:59 +00: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),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cq93vc_mute(struct snd_soc_dai *dai, int mute)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
2013-08-31 12:38:16 +00:00
|
|
|
u8 reg;
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
if (mute)
|
2013-08-31 12:38:16 +00:00
|
|
|
reg = DAVINCI_VC_REG09_MUTE;
|
2010-03-11 15:32:59 +00:00
|
|
|
else
|
2013-08-31 12:38:16 +00:00
|
|
|
reg = 0;
|
|
|
|
|
|
|
|
snd_soc_update_bits(codec, DAVINCI_VC_REG09, DAVINCI_VC_REG09_MUTE,
|
|
|
|
reg);
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2013-08-31 12:51:38 +00:00
|
|
|
struct davinci_vc *davinci_vc = codec->dev->platform_data;
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
switch (freq) {
|
|
|
|
case 22579200:
|
|
|
|
case 27000000:
|
|
|
|
case 33868800:
|
|
|
|
davinci_vc->cq93vc.sysclk = freq;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
|
|
|
|
enum snd_soc_bias_level level)
|
|
|
|
{
|
|
|
|
switch (level) {
|
|
|
|
case SND_SOC_BIAS_ON:
|
2013-08-31 12:38:16 +00:00
|
|
|
snd_soc_write(codec, DAVINCI_VC_REG12,
|
2010-03-11 15:32:59 +00:00
|
|
|
DAVINCI_VC_REG12_POWER_ALL_ON);
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_PREPARE:
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_STANDBY:
|
2013-08-31 12:38:16 +00:00
|
|
|
snd_soc_write(codec, DAVINCI_VC_REG12,
|
2010-03-11 15:32:59 +00:00
|
|
|
DAVINCI_VC_REG12_POWER_ALL_OFF);
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_OFF:
|
|
|
|
/* force all power off */
|
2013-08-31 12:38:16 +00:00
|
|
|
snd_soc_write(codec, DAVINCI_VC_REG12,
|
2010-03-11 15:32:59 +00:00
|
|
|
DAVINCI_VC_REG12_POWER_ALL_OFF);
|
|
|
|
break;
|
|
|
|
}
|
2010-11-05 13:53:46 +00:00
|
|
|
codec->dapm.bias_level = level;
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
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 10:40:40 +00:00
|
|
|
static const struct snd_soc_dai_ops cq93vc_dai_ops = {
|
2010-03-11 15:32:59 +00:00
|
|
|
.digital_mute = cq93vc_mute,
|
|
|
|
.set_sysclk = cq93vc_set_dai_sysclk,
|
|
|
|
};
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static struct snd_soc_dai_driver cq93vc_dai = {
|
|
|
|
.name = "cq93vc-hifi",
|
2010-03-11 15:32:59 +00: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,
|
|
|
|
};
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cq93vc_resume(struct snd_soc_codec *codec)
|
2010-03-11 15:32:59 +00:00
|
|
|
{
|
2010-05-07 19:30:00 +00:00
|
|
|
cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cq93vc_probe(struct snd_soc_codec *codec)
|
2010-03-11 15:32:59 +00:00
|
|
|
{
|
2011-04-06 14:39:45 +00:00
|
|
|
struct davinci_vc *davinci_vc = codec->dev->platform_data;
|
2010-03-17 20:15:21 +00:00
|
|
|
|
|
|
|
davinci_vc->cq93vc.codec = codec;
|
2013-08-31 12:52:41 +00:00
|
|
|
codec->control_data = davinci_vc->regmap;
|
|
|
|
|
|
|
|
snd_soc_codec_set_cache_io(codec, 32, 32, SND_SOC_REGMAP);
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
/* Off, with power on */
|
|
|
|
cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cq93vc_remove(struct snd_soc_codec *codec)
|
2010-03-11 15:32:59 +00:00
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
cq93vc_set_bias_level(codec, SND_SOC_BIAS_OFF);
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static struct snd_soc_codec_driver soc_codec_dev_cq93vc = {
|
|
|
|
.set_bias_level = cq93vc_set_bias_level,
|
2010-03-11 15:32:59 +00:00
|
|
|
.probe = cq93vc_probe,
|
|
|
|
.remove = cq93vc_remove,
|
|
|
|
.resume = cq93vc_resume,
|
2013-08-31 12:46:05 +00:00
|
|
|
.controls = cq93vc_snd_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(cq93vc_snd_controls),
|
2010-03-11 15:32:59 +00:00
|
|
|
};
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cq93vc_platform_probe(struct platform_device *pdev)
|
2010-03-11 15:32:59 +00:00
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
return snd_soc_register_codec(&pdev->dev,
|
|
|
|
&soc_codec_dev_cq93vc, &cq93vc_dai, 1);
|
2010-03-11 15:32:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cq93vc_platform_remove(struct platform_device *pdev)
|
2010-03-11 15:32:59 +00:00
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
snd_soc_unregister_codec(&pdev->dev);
|
2010-03-11 15:32:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver cq93vc_codec_driver = {
|
|
|
|
.driver = {
|
2010-03-17 20:15:21 +00:00
|
|
|
.name = "cq93vc-codec",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
|
|
|
|
.probe = cq93vc_platform_probe,
|
2012-12-07 14:26:37 +00:00
|
|
|
.remove = cq93vc_platform_remove,
|
2010-03-11 15:32:59 +00:00
|
|
|
};
|
|
|
|
|
2011-11-23 22:52:08 +00:00
|
|
|
module_platform_driver(cq93vc_codec_driver);
|
2010-03-11 15:32:59 +00:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver");
|
|
|
|
MODULE_AUTHOR("Miguel Aguilar");
|
|
|
|
MODULE_LICENSE("GPL");
|