aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc
diff options
context:
space:
mode:
authorHugo Villeneuve <hugo@hugovil.com>2008-11-19 01:37:31 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2008-11-19 08:16:38 -0500
commit1c0090c280da18f79e3e94168b5f3bfe4eb5f1c8 (patch)
tree0e81a01eccca0060c964fa0646ac6792f98f3213 /sound/soc
parentca3ea02e90d63a6a91c1c2a445d6d71f9031a44a (diff)
ASoC: Add PCM3008 ALSA SoC driver
The PCM3008 is a 16-bit stereo audio codec. It accepts left-justified format for ADC, and right-justified format for DAC. Independent power-down modes for ADC and DAC are provided, as well as a digital de-emphasis filter (4 modes). [Merged Makefile & Kconfig, changed asm/gpio.h to linux/gpio.h -- broonie] Signed-off-by: Hugo Villeneuve <hugo@hugovil.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc')
-rw-r--r--sound/soc/codecs/Kconfig4
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/pcm3008.c201
-rw-r--r--sound/soc/codecs/pcm3008.h25
4 files changed, 232 insertions, 0 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 04f49f5c3c3d..bf68052d6924 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -5,6 +5,7 @@ config SND_SOC_ALL_CODECS
5 select SND_SOC_AD73311 if I2C 5 select SND_SOC_AD73311 if I2C
6 select SND_SOC_AK4535 if I2C 6 select SND_SOC_AK4535 if I2C
7 select SND_SOC_CS4270 if I2C 7 select SND_SOC_CS4270 if I2C
8 select SND_SOC_PCM3008
8 select SND_SOC_SSM2602 if I2C 9 select SND_SOC_SSM2602 if I2C
9 select SND_SOC_TLV320AIC23 if I2C 10 select SND_SOC_TLV320AIC23 if I2C
10 select SND_SOC_TLV320AIC26 if SPI_MASTER 11 select SND_SOC_TLV320AIC26 if SPI_MASTER
@@ -70,6 +71,9 @@ config SND_SOC_CS4270_VD33_ERRATA
70config SND_SOC_L3 71config SND_SOC_L3
71 tristate 72 tristate
72 73
74config SND_SOC_PCM3008
75 tristate
76
73config SND_SOC_SSM2602 77config SND_SOC_SSM2602
74 tristate 78 tristate
75 79
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index de6572356d1b..9a20fddd09c7 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -4,6 +4,7 @@ snd-soc-ad73311-objs := ad73311.o
4snd-soc-ak4535-objs := ak4535.o 4snd-soc-ak4535-objs := ak4535.o
5snd-soc-cs4270-objs := cs4270.o 5snd-soc-cs4270-objs := cs4270.o
6snd-soc-l3-objs := l3.o 6snd-soc-l3-objs := l3.o
7snd-soc-pcm3008-objs := pcm3008.o
7snd-soc-ssm2602-objs := ssm2602.o 8snd-soc-ssm2602-objs := ssm2602.o
8snd-soc-tlv320aic23-objs := tlv320aic23.o 9snd-soc-tlv320aic23-objs := tlv320aic23.o
9snd-soc-tlv320aic26-objs := tlv320aic26.o 10snd-soc-tlv320aic26-objs := tlv320aic26.o
@@ -30,6 +31,7 @@ obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
30obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o 31obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
31obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 32obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
32obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o 33obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
34obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
33obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o 35obj-$(CONFIG_SND_SOC_SSM2602) += snd-soc-ssm2602.o
34obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o 36obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o
35obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o 37obj-$(CONFIG_SND_SOC_TLV320AIC26) += snd-soc-tlv320aic26.o
diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c
new file mode 100644
index 000000000000..2b26e1d80c8d
--- /dev/null
+++ b/sound/soc/codecs/pcm3008.c
@@ -0,0 +1,201 @@
1/*
2 * ALSA Soc PCM3008 codec support
3 *
4 * Author: Hugo Villeneuve
5 * Copyright (C) 2008 Lyrtech inc
6 *
7 * Based on AC97 Soc codec, original copyright follow:
8 * Copyright 2005 Wolfson Microelectronics PLC.
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 * Generic PCM3008 support.
16 */
17
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/device.h>
21#include <linux/gpio.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/initval.h>
25#include <sound/soc.h>
26
27#include "pcm3008.h"
28
29#define PCM3008_VERSION "0.2"
30
31#define PCM3008_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
32 SNDRV_PCM_RATE_48000)
33
34struct snd_soc_dai pcm3008_dai = {
35 .name = "PCM3008 HiFi",
36 .type = SND_SOC_DAI_I2S,
37 .playback = {
38 .stream_name = "PCM3008 Playback",
39 .channels_min = 1,
40 .channels_max = 2,
41 .rates = PCM3008_RATES,
42 .formats = SNDRV_PCM_FMTBIT_S16_LE,
43 },
44 .capture = {
45 .stream_name = "PCM3008 Capture",
46 .channels_min = 1,
47 .channels_max = 2,
48 .rates = PCM3008_RATES,
49 .formats = SNDRV_PCM_FMTBIT_S16_LE,
50 },
51};
52EXPORT_SYMBOL_GPL(pcm3008_dai);
53
54static void pcm3008_gpio_free(struct pcm3008_setup_data *setup)
55{
56 gpio_free(setup->dem0_pin);
57 gpio_free(setup->dem1_pin);
58 gpio_free(setup->pdad_pin);
59 gpio_free(setup->pdda_pin);
60}
61
62static int pcm3008_soc_probe(struct platform_device *pdev)
63{
64 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
65 struct snd_soc_codec *codec;
66 struct pcm3008_setup_data *setup = socdev->codec_data;
67 int ret = 0;
68
69 printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION);
70
71 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
72 if (!socdev->codec)
73 return -ENOMEM;
74
75 codec = socdev->codec;
76 mutex_init(&codec->mutex);
77
78 codec->name = "PCM3008";
79 codec->owner = THIS_MODULE;
80 codec->dai = &pcm3008_dai;
81 codec->num_dai = 1;
82 codec->write = NULL;
83 codec->read = NULL;
84 INIT_LIST_HEAD(&codec->dapm_widgets);
85 INIT_LIST_HEAD(&codec->dapm_paths);
86
87 /* Register PCMs. */
88 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
89 if (ret < 0) {
90 printk(KERN_ERR "pcm3008: failed to create pcms\n");
91 goto pcm_err;
92 }
93
94 /* Register Card. */
95 ret = snd_soc_register_card(socdev);
96 if (ret < 0) {
97 printk(KERN_ERR "pcm3008: failed to register card\n");
98 goto card_err;
99 }
100
101 /* DEM1 DEM0 DE-EMPHASIS_MODE
102 * Low Low De-emphasis 44.1 kHz ON
103 * Low High De-emphasis OFF
104 * High Low De-emphasis 48 kHz ON
105 * High High De-emphasis 32 kHz ON
106 */
107
108 /* Configure DEM0 GPIO (turning OFF DAC De-emphasis). */
109 ret = gpio_request(setup->dem0_pin, "codec_dem0");
110 if (ret == 0)
111 ret = gpio_direction_output(setup->dem0_pin, 1);
112 if (ret != 0)
113 goto gpio_err;
114
115 /* Configure DEM1 GPIO (turning OFF DAC De-emphasis). */
116 ret = gpio_request(setup->dem1_pin, "codec_dem1");
117 if (ret == 0)
118 ret = gpio_direction_output(setup->dem1_pin, 0);
119 if (ret != 0)
120 goto gpio_err;
121
122 /* Configure PDAD GPIO. */
123 ret = gpio_request(setup->pdad_pin, "codec_pdad");
124 if (ret == 0)
125 ret = gpio_direction_output(setup->pdad_pin, 1);
126 if (ret != 0)
127 goto gpio_err;
128
129 /* Configure PDDA GPIO. */
130 ret = gpio_request(setup->pdda_pin, "codec_pdda");
131 if (ret == 0)
132 ret = gpio_direction_output(setup->pdda_pin, 1);
133 if (ret != 0)
134 goto gpio_err;
135
136 return ret;
137
138gpio_err:
139 pcm3008_gpio_free(setup);
140card_err:
141 snd_soc_free_pcms(socdev);
142pcm_err:
143 kfree(socdev->codec);
144
145 return ret;
146}
147
148static int pcm3008_soc_remove(struct platform_device *pdev)
149{
150 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
151 struct snd_soc_codec *codec = socdev->codec;
152 struct pcm3008_setup_data *setup = socdev->codec_data;
153
154 if (!codec)
155 return 0;
156
157 pcm3008_gpio_free(setup);
158 snd_soc_free_pcms(socdev);
159 kfree(socdev->codec);
160
161 return 0;
162}
163
164#ifdef CONFIG_PM
165static int pcm3008_soc_suspend(struct platform_device *pdev, pm_message_t msg)
166{
167 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
168 struct pcm3008_setup_data *setup = socdev->codec_data;
169
170 gpio_set_value(setup->pdad_pin, 0);
171 gpio_set_value(setup->pdda_pin, 0);
172
173 return 0;
174}
175
176static int pcm3008_soc_resume(struct platform_device *pdev)
177{
178 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
179 struct pcm3008_setup_data *setup = socdev->codec_data;
180
181 gpio_set_value(setup->pdad_pin, 1);
182 gpio_set_value(setup->pdda_pin, 1);
183
184 return 0;
185}
186#else
187#define pcm3008_soc_suspend NULL
188#define pcm3008_soc_resume NULL
189#endif
190
191struct snd_soc_codec_device soc_codec_dev_pcm3008 = {
192 .probe = pcm3008_soc_probe,
193 .remove = pcm3008_soc_remove,
194 .suspend = pcm3008_soc_suspend,
195 .resume = pcm3008_soc_resume,
196};
197EXPORT_SYMBOL_GPL(soc_codec_dev_pcm3008);
198
199MODULE_DESCRIPTION("Soc PCM3008 driver");
200MODULE_AUTHOR("Hugo Villeneuve");
201MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/pcm3008.h b/sound/soc/codecs/pcm3008.h
new file mode 100644
index 000000000000..d04e87d3c060
--- /dev/null
+++ b/sound/soc/codecs/pcm3008.h
@@ -0,0 +1,25 @@
1/*
2 * PCM3008 ALSA SoC Layer
3 *
4 * Author: Hugo Villeneuve
5 * Copyright (C) 2008 Lyrtech inc
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef __LINUX_SND_SOC_PCM3008_H
13#define __LINUX_SND_SOC_PCM3008_H
14
15struct pcm3008_setup_data {
16 unsigned dem0_pin;
17 unsigned dem1_pin;
18 unsigned pdad_pin;
19 unsigned pdda_pin;
20};
21
22extern struct snd_soc_codec_device soc_codec_dev_pcm3008;
23extern struct snd_soc_dai pcm3008_dai;
24
25#endif