ASoC: add dialog da9034 (aka micco) audio codec support
Subsystems (3)
PATCH 2/4 ASoC: add dialog da9034 (aka micco) audio codec support
--- sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/da9034-audio.c | 696 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 702 insertions(+), 0 deletions(-) create mode 100644 sound/soc/codecs/da9034-audio.c
sound/soc/codecs/Kconfig +4 -0
@@ -42,6 +42,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_WM9705 if SND_SOC_AC97_BUS select SND_SOC_WM9712 if SND_SOC_AC97_BUS select SND_SOC_WM9713 if SND_SOC_AC97_BUS + select SND_SOC_DA9034 if PMIC_DA903X help Normally ASoC codec drivers are only built if a machine driver which uses them is also built since they are only usable with a machine
@@ -160,3 +161,6 @@ config SND_SOC_WM9712 config SND_SOC_WM9713 tristate + +config SND_SOC_DA9034 + tristate
sound/soc/codecs/Makefile +2 -0
@@ -30,6 +30,7 @@ snd-soc-wm8990-objs := wm8990.o snd-soc-wm9705-objs := wm9705.o snd-soc-wm9712-objs := wm9712.o snd-soc-wm9713-objs := wm9713.o +snd-soc-da9034-objs := da9034-audio.o obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o
@@ -64,3 +65,4 @@ obj-$(CONFIG_SND_SOC_WM8991) += snd-soc-wm8991.o obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o +obj-$(CONFIG_SND_SOC_DA9034) += snd-soc-da9034.o
sound/soc/codecs/da9034-audio.c new file +408 -0
408 lines not on this page · raw message
unsigned int fmt)
+{
+ switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+ case SND_SOC_DAIFMT_DSP_A:
+ break;
+ default:
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static int da9034_voice_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct snd_soc_device *socdev = rtd->socdev;
+ struct snd_soc_codec *codec = socdev->card->codec;
+ uint8_t val;
+
+ da903x_read(codec->dev, DA9034_VOICE_ADC, &val);
+
+ val |= 0x18;
+
+ switch ((params_rate(params))) {
+ case 8000: break;
+ case 16000: val |= 0x01 << 3; break;
+ case 32000: val |= 0x02 << 3; break;
+ default:
+ return -EINVAL;
+ }
+
+ return da903x_write(codec->dev, DA9034_VOICE_ADC, val);
+}
+
+#define DA9034_HIFI_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
+ SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
+ SNDRV_PCM_RATE_48000)
+
+#define DA9034_VOICE_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
+ SNDRV_PCM_RATE_32000)
+
+#define DA9034_PCM_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
+
+static struct snd_soc_dai_ops da9034_dai_ops_hifi = {
+ .hw_params = da9034_hifi_hw_params,
+ .set_fmt = da9034_hifi_set_fmt,
+};
+
+static struct snd_soc_dai_ops da9034_dai_ops_voice = {
+ .hw_params = da9034_voice_hw_params,
+ .set_fmt = da9034_voice_set_fmt,
+};
+
+struct snd_soc_dai da9034_dais[] = {
+ [0] = {
+ .name = "I2S HiFi",
+ .playback = {
+ .stream_name = "HiFi Playback",
+ .channels_min = 2,
+ .channels_max = 2,
+ .rates = DA9034_HIFI_RATES,
+ .formats = DA9034_PCM_FORMATS,
+ },
+ .ops = &da9034_dai_ops_hifi,
+ },
+ [1] = {
+ .name = "PCM Voice",
+ .playback = {
+ .stream_name = "Voice Playback",
+ .channels_min = 1,
+ .channels_max = 1,
+ .rates = DA9034_VOICE_RATES,
+ .formats = DA9034_PCM_FORMATS,
+ },
+ .capture = {
+ .stream_name = "Voice Capture",
+ .channels_min = 1,
+ .channels_max = 1,
+ .rates = DA9034_VOICE_RATES,
+ .formats = DA9034_PCM_FORMATS,
+ },
+ .ops = &da9034_dai_ops_voice,
+ },
+};
+EXPORT_SYMBOL_GPL(da9034_dais);
+
+#ifdef CONFIG_DEBUG_FS
+static struct {
+ const char *reg_name;
+ int reg_addr;
+} da9034_regs[] = {
+ { "MUX_MONO", 0x70 },
+ { "MUX_BEAR", 0x71 },
+ { "MUX_LINE", 0x72 },
+ { "MUX_STEREO_CH1", 0x73 },
+ { "MUX_STEREO_CH2", 0x74 },
+ { "AUDIO_LINE_AMP", 0x75 },
+ { "STEREO_AMP_CH1", 0x76 },
+ { "STEREO_AMP_CH2", 0x77 },
+ { "STEREO_DAC", 0x78 },
+ { "MONO_VOL", 0x79 },
+ { "BEAR_VOL", 0x7a },
+ { "I2S_CONTROL", 0x7b },
+ { "TX_PGA", 0x7c },
+ { "MIC_AMP", 0x7d },
+ { "TX_PGA_MUX", 0x7e },
+ { "VOICE_ADC", 0x7f },
+ { "VOICE_DAC", 0x80 },
+ { "SIDE_TONE", 0x81 },
+ { "PGA_AUXI12", 0x82 },
+ { "PGA_AUXI3", 0x83 },
+ { "PGA_DACS", 0x84 },
+};
+
+static int da9034_debugfs_show(struct seq_file *s, void *data) +{
+ struct snd_soc_codec *codec = data;
+ struct device *dev = codec->dev;
+ uint8_t v;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(da9034_regs); i++) {
+ da903x_read(codec->dev, da9034_regs[i].reg_addr, &v);
+ seq_printf(s, "%20s: 0x%02x\n", da9034_regs[i].reg_name, v);
+ }
+ return 0;
+}
+
+static int da9034_debugfs_open(struct inode *inode, struct file *file) +{
+ return single_open(file, da9034_debugfs_show, inode->i_private);
+}
+
+static const struct file_operations da9034_debugfs_ops = {
+ .owner = THIS_MODULE,
+ .open = da9034_debugfs_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static void __init da9034_init_debugfs(struct snd_soc_codec *codec) +{
+ debugfs_create_file("da9034", S_IFREG | S_IRUGO, NULL,
+ codec, da9034_debugfs_ops);
+}
+#else
+static inline void da9034_init_debugfs(struct snd_soc_codec *codec) {} +#endif /* CONFIG_DEBUG_FS */
+
+static struct snd_soc_codec *da9034_codec;
+
+static int da9034_soc_probe(struct platform_device *pdev) +{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ int ret = 0;
+
+ BUG_ON(!da9034_codec);
+
+ socdev->card->codec = da9034_codec;
+ socdev->dev = &pdev->dev;
+
+ ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "failed to create pcms\n");
+ return ret;
+ }
+
+ da9034_add_widgets(da9034_codec);
+
+ ret = snd_soc_init_card(socdev);
+ if (ret < 0)
+ goto reset_err;
+
+ return 0;
+
+reset_err:
+ snd_soc_free_pcms(socdev);
+ socdev->card->codec = NULL;
+ return ret;
+}
+
+static int da9034_soc_remove(struct platform_device *pdev) +{
+ struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+ struct snd_soc_codec *codec = socdev->card->codec;
+
+ if (codec == NULL)
+ return 0;
+
+ snd_soc_dapm_free(socdev);
+ snd_soc_free_pcms(socdev);
+ return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_da9034 = {
+ .probe = da9034_soc_probe,
+ .remove = da9034_soc_remove,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_da9034);
+
+static int __devinit da9034_audio_probe(struct platform_device *pdev) +{
+ struct snd_soc_codec *codec;
+ int ret;
+
+ codec = kzalloc(sizeof(*codec), GFP_KERNEL);
+ if (codec == NULL) {
+ dev_err(&pdev->dev, "failed to allocate codec\n");
+ return -ENOMEM;
+ }
+
+ mutex_init(&codec->mutex);
+ INIT_LIST_HEAD(&codec->dapm_widgets);
+ INIT_LIST_HEAD(&codec->dapm_paths);
+
+ codec->dev = pdev->dev.parent;
+ codec->name = "DA9034";
+ codec->owner = THIS_MODULE;
+ codec->read = da9034_audio_read;
+ codec->write = da9034_audio_write;
+ codec->dai = da9034_dais;
+ codec->num_dai = ARRAY_SIZE(da9034_dais);
+
+ ret = da9034_reset(codec, 0);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "codec reset error\n");
+ goto err_free_codec;
+ }
+
+ ret = snd_soc_register_codec(codec);
+ if (ret)
+ goto err_free_codec;
+
+ ret = snd_soc_register_dais(ARRAY_AND_SIZE(da9034_dais));
+ if (ret)
+ goto err_unregister;
+
+ da9034_init_debugfs(codec);
+ da9034_codec = codec;
+ platform_set_drvdata(pdev, codec);
+
+ dev_info(&pdev->dev, "da9034 (aka micco) audio codec registered\n");
+ return 0;
+
+err_unregister:
+ snd_soc_unregister_codec(codec);
+err_free_codec:
+ kfree(codec);
+ return ret;
+}
+
+static int __devexit da9034_audio_remove(struct platform_device *pdev) +{
+ struct snd_soc_codec *codec = platform_get_drvdata(pdev);
+
+ snd_soc_unregister_dais(ARRAY_AND_SIZE(da9034_dais));
+ snd_soc_unregister_codec(codec);
+ kfree(codec);
+ return 0;
+}
+
+static struct platform_driver da9034_audio_driver = {
+ .driver = {
+ .name = "da9034-audio",
+ .owner = THIS_MODULE,
+ },
+ .probe = da9034_audio_probe,
+ .remove = da9034_audio_remove,
+};
+
+static int da9034_audio_init(void)
+{
+ return platform_driver_register(&da9034_audio_driver);
+}
+module_init(da9034_audio_init);
+
+static void da9034_audio_exit(void)
+{
+ platform_driver_unregister(&da9034_audio_driver);
+}
+module_exit(da9034_audio_exit);
+
+MODULE_DESCRIPTION("ASoC DA9034 Audio Codec Driver"); +MODULE_AUTHOR("Bin Yang <[email protected]>"
+ "Paul Shen <[email protected]>");
+MODULE_LICENSE("GPL");
Signature · 1 line
1.6.0.4
On Wed, Jun 03, 2009 at 08:34:36PM +0800, Eric Miao wrote:
This looks good overall - some comments below, mostly at the style level.
sound/soc/codecs/da9034-audio.c line 2
Quoted 6 lines
index 0000000..159a883
sound/soc/codecs/da9034-audio.c new file +2
-0@@ -0,0 +1,696 @@ +/* +* linux/sound/soc/codecs/micco.c
Make your mind up :)
sound/soc/codecs/da9034-audio.c line 24
Quoted 1 line
sound/soc/codecs/da9034-audio.c new file +1
-0+#include <asm/mach-types.h>
This shouldn't be needed and doesn't appear to be used so should be removed.
sound/soc/codecs/da9034-audio.c line 53
Quoted 6 lines
sound/soc/codecs/da9034-audio.c new file +6
-0+/* NOTE: the ES1 revision of the chip has the following two issues +* regarding audio: +* 1. The MONO and BEAR are incorrectly exchanged +* 2. The Stereo DAC has to be enabled for Voice Codec +*/ +#define DA9034_ERRATA_ES1 1
This should be moved into platform data in order to allow it to be selected based on board type - if this has been fixed in subsequent silicon the workaround won't be appropriate for a lot of systems. Probably a module option would also be good in case a board may have either revision.
sound/soc/codecs/da9034-audio.c line 67
Quoted 3 lines
sound/soc/codecs/da9034-audio.c new file +3
-0+static const struct snd_kcontrol_new da9034_mixer_mono_out_controls[] = { +SOC_DAPM_SINGLE ("AUX1" ,DA9034_MUX_MONO ,0 ,1 ,0 ), +SOC_DAPM_SINGLE ("AUX2" ,DA9034_MUX_MONO ,1 ,1 ,0 ),
These should all be in the form "Foo Switch" - ths applies to most of the controls. Ideally the relevant PGAs should be named in the form "Foo Volume" so that ALSA can present them to the user as a single volume/PGA control.
sound/soc/codecs/da9034-audio.c line 134
Quoted 5 lines
sound/soc/codecs/da9034-audio.c new file +5
-0+static const struct soc_enum da9034_mux_enum[] = { +SOC_VALUE_ENUM_SINGLE (DA9034_TX_PGA_MUX ,0 ,0xff ,7 , + mux_tx_pga_texts, mux_tx_pga_values), +SOC_ENUM_SINGLE (DA9034_MIC_PGA ,4 ,2 , mux_mic_texts), +};
Please move these out of arrays since...
sound/soc/codecs/da9034-audio.c line 192
Quoted 4 lines
sound/soc/codecs/da9034-audio.c new file +4
-0+/* DACs and ADCs */ +#ifdef DA9034_ERRATA_ES1 +SND_SOC_DAPM_DAC ("DAC1" ,"HiFi Playback CH1" ,-1 ,0 ,0 ), + SND_SOC_DAPM_DAC("DAC2", "HiFi Playback CH2", -1, 0, 0),
This should use SND_SOC_NOPM for the invalid register.
sound/soc/codecs/da9034-audio.c line 210
Quoted 2 lines
sound/soc/codecs/da9034-audio.c new file +2
-0+SND_SOC_DAPM_PGA ("LINE_OUT PGA" ,DA9034_AUDIO_LINE_AMP ,4 ,0 , + &pga_ctrls[7], 1),
...these numerical references into the arrays from further down the driver get confusing. I know many of the older drivers do this but I'm trying to avoid adding any new code using this scheme due to the legibility and maintainability issues that result.
sound/soc/codecs/da9034-audio.c line 238
Quoted 3 lines
sound/soc/codecs/da9034-audio.c new file +3
-0+#ifdef DA9034_ERRATA_ES1 + { "BEAR PGA", NULL, "MONO Mixer" }, +#endif
The description of the erratum at the top said this was exchanged with something else, not absent? I'd expect an #else if so...
sound/soc/codecs/da9034-audio.c line 30
Quoted 4 lines
sound/soc/codecs/da9034-audio.c new file +4
-0+#define DA9034_HIFI_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ + SNDRV_PCM_RATE_48000)
This could be SNDRV_PCM_RATE_8000_48000 unless I misread.
sound/soc/codecs/da9034-audio.c line 42
Quoted 12 lines
sound/soc/codecs/da9034-audio.c new file +12
-0+struct snd_soc_dai da9034_dais[] = { + [0 ] = { + .name ="I2S HiFi" , + .playback = { + .stream_name ="HiFi Playback" , + .channels_min =2 , + .channels_max =2 , + .rates =DA9034_HIFI_RATES , + .formats =DA9034_PCM_FORMATS , + }, + .ops = &da9034_dai_ops_hifi, + },
Your hw_params function above sets the rate unconditionally without seperate configuration for playback and capture. This suggests that you should be defining symmetric_rates here in order to stop applications trying to reconfigure the rates with a record while a playback is active (or vice versa).
Quoted 8 lines
sound/soc/codecs/da9034-audio.c new file +8
-0+ [1] = { + .name = "PCM Voice", + .playback = { + .stream_name = "Voice Playback", + .channels_min = 1, + .channels_max = 1, + .rates = DA9034_VOICE_RATES, + .formats = DA9034_PCM_FORMATS,
sound/soc/codecs/da9034-audio.c line 60
Quoted 10 lines
sound/soc/codecs/da9034-audio.c new file +10
-0+ }, + .capture = { + .stream_name = "Voice Capture", + .channels_min = 1, + .channels_max = 1, + .rates = DA9034_VOICE_RATES, + .formats = DA9034_PCM_FORMATS, + }, + .ops = &da9034_dai_ops_voice, + },
Same comment looks like it applies to the voice DAI.
sound/soc/codecs/da9034-audio.c line 61
Quoted 1 line
sound/soc/codecs/da9034-audio.c new file +1
-0+#ifdef CONFIG_DEBUG_FS
Please remove all this code - ASoC already has register dump support via both debugfs and sysfs. It currently uses register numbers rather than names but I wouldn't be averse to patches adding name support.
sound/soc/codecs/da9034-audio.c line 69
Quoted 8 lines
sound/soc/codecs/da9034-audio.c new file +8
-0+static struct snd_soc_codec *da9034_codec; + +static int da9034_soc_probe (struct platform_device *pdev) +{ +struct snd_soc_device *socdev =platform_get_drvdata (pdev); +int ret =0 ; + +BUG_ON (!da9034_codec);
Seems harsh but OK.
sound/soc/codecs/da9034-audio.c line 70
Quoted 1 line
sound/soc/codecs/da9034-audio.c new file +1
-0+dev_info (&pdev->dev,"da9034 (aka micco) audio codec registered\n" );
dev_dbg() if you're going to have this. Might be better to use codec->dev rather than the platform device since other things will use that and it's a bit more friendly.