diff options
Diffstat (limited to 'sound/soc/davinci')
-rw-r--r-- | sound/soc/davinci/Kconfig | 10 | ||||
-rw-r--r-- | sound/soc/davinci/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-evm.c | 14 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-i2s.c | 257 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-pcm.c | 30 | ||||
-rw-r--r-- | sound/soc/davinci/davinci-sffsdr.c | 157 |
6 files changed, 388 insertions, 82 deletions
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig index 8f7e33834902..b502741692d6 100644 --- a/sound/soc/davinci/Kconfig +++ b/sound/soc/davinci/Kconfig | |||
@@ -17,3 +17,13 @@ config SND_DAVINCI_SOC_EVM | |||
17 | help | 17 | help |
18 | Say Y if you want to add support for SoC audio on TI | 18 | Say Y if you want to add support for SoC audio on TI |
19 | DaVinci EVM platform. | 19 | DaVinci EVM platform. |
20 | |||
21 | config SND_DAVINCI_SOC_SFFSDR | ||
22 | tristate "SoC Audio support for SFFSDR" | ||
23 | depends on SND_DAVINCI_SOC && MACH_DAVINCI_SFFSDR | ||
24 | select SND_DAVINCI_SOC_I2S | ||
25 | select SND_SOC_PCM3008 | ||
26 | select SFFSDR_FPGA | ||
27 | help | ||
28 | Say Y if you want to add support for SoC audio on | ||
29 | Lyrtech SFFSDR board. | ||
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile index ca772e5b4637..ca8bae1fc3f6 100644 --- a/sound/soc/davinci/Makefile +++ b/sound/soc/davinci/Makefile | |||
@@ -7,5 +7,7 @@ obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o | |||
7 | 7 | ||
8 | # DAVINCI Machine Support | 8 | # DAVINCI Machine Support |
9 | snd-soc-evm-objs := davinci-evm.o | 9 | snd-soc-evm-objs := davinci-evm.o |
10 | snd-soc-sffsdr-objs := davinci-sffsdr.o | ||
10 | 11 | ||
11 | obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o | 12 | obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o |
13 | obj-$(CONFIG_SND_DAVINCI_SOC_SFFSDR) += snd-soc-sffsdr.o | ||
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c index 9e6062cd6b59..01b948bb55a1 100644 --- a/sound/soc/davinci/davinci-evm.c +++ b/sound/soc/davinci/davinci-evm.c | |||
@@ -28,6 +28,8 @@ | |||
28 | 28 | ||
29 | #define EVM_CODEC_CLOCK 22579200 | 29 | #define EVM_CODEC_CLOCK 22579200 |
30 | 30 | ||
31 | #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \ | ||
32 | SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF) | ||
31 | static int evm_hw_params(struct snd_pcm_substream *substream, | 33 | static int evm_hw_params(struct snd_pcm_substream *substream, |
32 | struct snd_pcm_hw_params *params) | 34 | struct snd_pcm_hw_params *params) |
33 | { | 35 | { |
@@ -37,14 +39,12 @@ static int evm_hw_params(struct snd_pcm_substream *substream, | |||
37 | int ret = 0; | 39 | int ret = 0; |
38 | 40 | ||
39 | /* set codec DAI configuration */ | 41 | /* set codec DAI configuration */ |
40 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | 42 | ret = snd_soc_dai_set_fmt(codec_dai, AUDIO_FORMAT); |
41 | SND_SOC_DAIFMT_CBM_CFM); | ||
42 | if (ret < 0) | 43 | if (ret < 0) |
43 | return ret; | 44 | return ret; |
44 | 45 | ||
45 | /* set cpu DAI configuration */ | 46 | /* set cpu DAI configuration */ |
46 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM | | 47 | ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT); |
47 | SND_SOC_DAIFMT_IB_NF); | ||
48 | if (ret < 0) | 48 | if (ret < 0) |
49 | return ret; | 49 | return ret; |
50 | 50 | ||
@@ -128,8 +128,9 @@ static struct snd_soc_dai_link evm_dai = { | |||
128 | }; | 128 | }; |
129 | 129 | ||
130 | /* davinci-evm audio machine driver */ | 130 | /* davinci-evm audio machine driver */ |
131 | static struct snd_soc_machine snd_soc_machine_evm = { | 131 | static struct snd_soc_card snd_soc_card_evm = { |
132 | .name = "DaVinci EVM", | 132 | .name = "DaVinci EVM", |
133 | .platform = &davinci_soc_platform, | ||
133 | .dai_link = &evm_dai, | 134 | .dai_link = &evm_dai, |
134 | .num_links = 1, | 135 | .num_links = 1, |
135 | }; | 136 | }; |
@@ -142,8 +143,7 @@ static struct aic3x_setup_data evm_aic3x_setup = { | |||
142 | 143 | ||
143 | /* evm audio subsystem */ | 144 | /* evm audio subsystem */ |
144 | static struct snd_soc_device evm_snd_devdata = { | 145 | static struct snd_soc_device evm_snd_devdata = { |
145 | .machine = &snd_soc_machine_evm, | 146 | .card = &snd_soc_card_evm, |
146 | .platform = &davinci_soc_platform, | ||
147 | .codec_dev = &soc_codec_dev_aic3x, | 147 | .codec_dev = &soc_codec_dev_aic3x, |
148 | .codec_data = &evm_aic3x_setup, | 148 | .codec_data = &evm_aic3x_setup, |
149 | }; | 149 | }; |
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c index abb5fedb0b1e..0fee779e3c76 100644 --- a/sound/soc/davinci/davinci-i2s.c +++ b/sound/soc/davinci/davinci-i2s.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #define DAVINCI_MCBSP_PCR_CLKXP (1 << 1) | 59 | #define DAVINCI_MCBSP_PCR_CLKXP (1 << 1) |
60 | #define DAVINCI_MCBSP_PCR_FSRP (1 << 2) | 60 | #define DAVINCI_MCBSP_PCR_FSRP (1 << 2) |
61 | #define DAVINCI_MCBSP_PCR_FSXP (1 << 3) | 61 | #define DAVINCI_MCBSP_PCR_FSXP (1 << 3) |
62 | #define DAVINCI_MCBSP_PCR_SCLKME (1 << 7) | ||
62 | #define DAVINCI_MCBSP_PCR_CLKRM (1 << 8) | 63 | #define DAVINCI_MCBSP_PCR_CLKRM (1 << 8) |
63 | #define DAVINCI_MCBSP_PCR_CLKXM (1 << 9) | 64 | #define DAVINCI_MCBSP_PCR_CLKXM (1 << 9) |
64 | #define DAVINCI_MCBSP_PCR_FSRM (1 << 10) | 65 | #define DAVINCI_MCBSP_PCR_FSRM (1 << 10) |
@@ -110,16 +111,59 @@ static void davinci_mcbsp_start(struct snd_pcm_substream *substream) | |||
110 | { | 111 | { |
111 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 112 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
112 | struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data; | 113 | struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data; |
114 | struct snd_soc_device *socdev = rtd->socdev; | ||
115 | struct snd_soc_platform *platform = socdev->card->platform; | ||
113 | u32 w; | 116 | u32 w; |
117 | int ret; | ||
114 | 118 | ||
115 | /* Start the sample generator and enable transmitter/receiver */ | 119 | /* Start the sample generator and enable transmitter/receiver */ |
116 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | 120 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
117 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST, 1); | 121 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST, 1); |
118 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | 122 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); |
123 | |||
124 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
125 | /* Stop the DMA to avoid data loss */ | ||
126 | /* while the transmitter is out of reset to handle XSYNCERR */ | ||
127 | if (platform->pcm_ops->trigger) { | ||
128 | ret = platform->pcm_ops->trigger(substream, | ||
129 | SNDRV_PCM_TRIGGER_STOP); | ||
130 | if (ret < 0) | ||
131 | printk(KERN_DEBUG "Playback DMA stop failed\n"); | ||
132 | } | ||
133 | |||
134 | /* Enable the transmitter */ | ||
135 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | ||
119 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 1); | 136 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 1); |
120 | else | 137 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); |
138 | |||
139 | /* wait for any unexpected frame sync error to occur */ | ||
140 | udelay(100); | ||
141 | |||
142 | /* Disable the transmitter to clear any outstanding XSYNCERR */ | ||
143 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | ||
144 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 0); | ||
145 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); | ||
146 | |||
147 | /* Restart the DMA */ | ||
148 | if (platform->pcm_ops->trigger) { | ||
149 | ret = platform->pcm_ops->trigger(substream, | ||
150 | SNDRV_PCM_TRIGGER_START); | ||
151 | if (ret < 0) | ||
152 | printk(KERN_DEBUG "Playback DMA start failed\n"); | ||
153 | } | ||
154 | /* Enable the transmitter */ | ||
155 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | ||
156 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 1); | ||
157 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); | ||
158 | |||
159 | } else { | ||
160 | |||
161 | /* Enable the reciever */ | ||
162 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | ||
121 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 1); | 163 | MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 1); |
122 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); | 164 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); |
165 | } | ||
166 | |||
123 | 167 | ||
124 | /* Start frame sync */ | 168 | /* Start frame sync */ |
125 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | 169 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
@@ -144,7 +188,8 @@ static void davinci_mcbsp_stop(struct snd_pcm_substream *substream) | |||
144 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); | 188 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); |
145 | } | 189 | } |
146 | 190 | ||
147 | static int davinci_i2s_startup(struct snd_pcm_substream *substream) | 191 | static int davinci_i2s_startup(struct snd_pcm_substream *substream, |
192 | struct snd_soc_dai *dai) | ||
148 | { | 193 | { |
149 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 194 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
150 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | 195 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
@@ -155,61 +200,138 @@ static int davinci_i2s_startup(struct snd_pcm_substream *substream) | |||
155 | return 0; | 200 | return 0; |
156 | } | 201 | } |
157 | 202 | ||
203 | #define DEFAULT_BITPERSAMPLE 16 | ||
204 | |||
158 | static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, | 205 | static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
159 | unsigned int fmt) | 206 | unsigned int fmt) |
160 | { | 207 | { |
161 | struct davinci_mcbsp_dev *dev = cpu_dai->private_data; | 208 | struct davinci_mcbsp_dev *dev = cpu_dai->private_data; |
162 | u32 w; | 209 | unsigned int pcr; |
210 | unsigned int srgr; | ||
211 | unsigned int rcr; | ||
212 | unsigned int xcr; | ||
213 | srgr = DAVINCI_MCBSP_SRGR_FSGM | | ||
214 | DAVINCI_MCBSP_SRGR_FPER(DEFAULT_BITPERSAMPLE * 2 - 1) | | ||
215 | DAVINCI_MCBSP_SRGR_FWID(DEFAULT_BITPERSAMPLE - 1); | ||
163 | 216 | ||
164 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | 217 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
165 | case SND_SOC_DAIFMT_CBS_CFS: | 218 | case SND_SOC_DAIFMT_CBS_CFS: |
166 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, | 219 | /* cpu is master */ |
167 | DAVINCI_MCBSP_PCR_FSXM | | 220 | pcr = DAVINCI_MCBSP_PCR_FSXM | |
168 | DAVINCI_MCBSP_PCR_FSRM | | 221 | DAVINCI_MCBSP_PCR_FSRM | |
169 | DAVINCI_MCBSP_PCR_CLKXM | | 222 | DAVINCI_MCBSP_PCR_CLKXM | |
170 | DAVINCI_MCBSP_PCR_CLKRM); | 223 | DAVINCI_MCBSP_PCR_CLKRM; |
171 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, | 224 | break; |
172 | DAVINCI_MCBSP_SRGR_FSGM); | 225 | case SND_SOC_DAIFMT_CBM_CFS: |
226 | /* McBSP CLKR pin is the input for the Sample Rate Generator. | ||
227 | * McBSP FSR and FSX are driven by the Sample Rate Generator. */ | ||
228 | pcr = DAVINCI_MCBSP_PCR_SCLKME | | ||
229 | DAVINCI_MCBSP_PCR_FSXM | | ||
230 | DAVINCI_MCBSP_PCR_FSRM; | ||
173 | break; | 231 | break; |
174 | case SND_SOC_DAIFMT_CBM_CFM: | 232 | case SND_SOC_DAIFMT_CBM_CFM: |
175 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, 0); | 233 | /* codec is master */ |
234 | pcr = 0; | ||
176 | break; | 235 | break; |
177 | default: | 236 | default: |
237 | printk(KERN_ERR "%s:bad master\n", __func__); | ||
178 | return -EINVAL; | 238 | return -EINVAL; |
179 | } | 239 | } |
180 | 240 | ||
181 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | 241 | rcr = DAVINCI_MCBSP_RCR_RFRLEN1(1); |
182 | case SND_SOC_DAIFMT_IB_NF: | 242 | xcr = DAVINCI_MCBSP_XCR_XFIG | DAVINCI_MCBSP_XCR_XFRLEN1(1); |
183 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG); | 243 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
184 | MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP | | 244 | case SND_SOC_DAIFMT_DSP_B: |
185 | DAVINCI_MCBSP_PCR_CLKRP, 1); | ||
186 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w); | ||
187 | break; | 245 | break; |
188 | case SND_SOC_DAIFMT_NB_IF: | 246 | case SND_SOC_DAIFMT_I2S: |
189 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG); | 247 | /* Davinci doesn't support TRUE I2S, but some codecs will have |
190 | MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_FSXP | | 248 | * the left and right channels contiguous. This allows |
191 | DAVINCI_MCBSP_PCR_FSRP, 1); | 249 | * dsp_a mode to be used with an inverted normal frame clk. |
192 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w); | 250 | * If your codec is master and does not have contiguous |
251 | * channels, then you will have sound on only one channel. | ||
252 | * Try using a different mode, or codec as slave. | ||
253 | * | ||
254 | * The TLV320AIC33 is an example of a codec where this works. | ||
255 | * It has a variable bit clock frequency allowing it to have | ||
256 | * valid data on every bit clock. | ||
257 | * | ||
258 | * The TLV320AIC23 is an example of a codec where this does not | ||
259 | * work. It has a fixed bit clock frequency with progressively | ||
260 | * more empty bit clock slots between channels as the sample | ||
261 | * rate is lowered. | ||
262 | */ | ||
263 | fmt ^= SND_SOC_DAIFMT_NB_IF; | ||
264 | case SND_SOC_DAIFMT_DSP_A: | ||
265 | rcr |= DAVINCI_MCBSP_RCR_RDATDLY(1); | ||
266 | xcr |= DAVINCI_MCBSP_XCR_XDATDLY(1); | ||
267 | break; | ||
268 | default: | ||
269 | printk(KERN_ERR "%s:bad format\n", __func__); | ||
270 | return -EINVAL; | ||
271 | } | ||
272 | |||
273 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
274 | case SND_SOC_DAIFMT_NB_NF: | ||
275 | /* CLKRP Receive clock polarity, | ||
276 | * 1 - sampled on rising edge of CLKR | ||
277 | * valid on rising edge | ||
278 | * CLKXP Transmit clock polarity, | ||
279 | * 1 - clocked on falling edge of CLKX | ||
280 | * valid on rising edge | ||
281 | * FSRP Receive frame sync pol, 0 - active high | ||
282 | * FSXP Transmit frame sync pol, 0 - active high | ||
283 | */ | ||
284 | pcr |= (DAVINCI_MCBSP_PCR_CLKXP | DAVINCI_MCBSP_PCR_CLKRP); | ||
193 | break; | 285 | break; |
194 | case SND_SOC_DAIFMT_IB_IF: | 286 | case SND_SOC_DAIFMT_IB_IF: |
195 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG); | 287 | /* CLKRP Receive clock polarity, |
196 | MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP | | 288 | * 0 - sampled on falling edge of CLKR |
197 | DAVINCI_MCBSP_PCR_CLKRP | | 289 | * valid on falling edge |
198 | DAVINCI_MCBSP_PCR_FSXP | | 290 | * CLKXP Transmit clock polarity, |
199 | DAVINCI_MCBSP_PCR_FSRP, 1); | 291 | * 0 - clocked on rising edge of CLKX |
200 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w); | 292 | * valid on falling edge |
293 | * FSRP Receive frame sync pol, 1 - active low | ||
294 | * FSXP Transmit frame sync pol, 1 - active low | ||
295 | */ | ||
296 | pcr |= (DAVINCI_MCBSP_PCR_FSXP | DAVINCI_MCBSP_PCR_FSRP); | ||
201 | break; | 297 | break; |
202 | case SND_SOC_DAIFMT_NB_NF: | 298 | case SND_SOC_DAIFMT_NB_IF: |
299 | /* CLKRP Receive clock polarity, | ||
300 | * 1 - sampled on rising edge of CLKR | ||
301 | * valid on rising edge | ||
302 | * CLKXP Transmit clock polarity, | ||
303 | * 1 - clocked on falling edge of CLKX | ||
304 | * valid on rising edge | ||
305 | * FSRP Receive frame sync pol, 1 - active low | ||
306 | * FSXP Transmit frame sync pol, 1 - active low | ||
307 | */ | ||
308 | pcr |= (DAVINCI_MCBSP_PCR_CLKXP | DAVINCI_MCBSP_PCR_CLKRP | | ||
309 | DAVINCI_MCBSP_PCR_FSXP | DAVINCI_MCBSP_PCR_FSRP); | ||
310 | break; | ||
311 | case SND_SOC_DAIFMT_IB_NF: | ||
312 | /* CLKRP Receive clock polarity, | ||
313 | * 0 - sampled on falling edge of CLKR | ||
314 | * valid on falling edge | ||
315 | * CLKXP Transmit clock polarity, | ||
316 | * 0 - clocked on rising edge of CLKX | ||
317 | * valid on falling edge | ||
318 | * FSRP Receive frame sync pol, 0 - active high | ||
319 | * FSXP Transmit frame sync pol, 0 - active high | ||
320 | */ | ||
203 | break; | 321 | break; |
204 | default: | 322 | default: |
205 | return -EINVAL; | 323 | return -EINVAL; |
206 | } | 324 | } |
207 | 325 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, srgr); | |
326 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, pcr); | ||
327 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, rcr); | ||
328 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, xcr); | ||
208 | return 0; | 329 | return 0; |
209 | } | 330 | } |
210 | 331 | ||
211 | static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, | 332 | static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, |
212 | struct snd_pcm_hw_params *params) | 333 | struct snd_pcm_hw_params *params, |
334 | struct snd_soc_dai *dai) | ||
213 | { | 335 | { |
214 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | 336 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
215 | struct davinci_pcm_dma_params *dma_params = rtd->dai->cpu_dai->dma_data; | 337 | struct davinci_pcm_dma_params *dma_params = rtd->dai->cpu_dai->dma_data; |
@@ -219,25 +341,20 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, | |||
219 | u32 w; | 341 | u32 w; |
220 | 342 | ||
221 | /* general line settings */ | 343 | /* general line settings */ |
222 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, | 344 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
223 | DAVINCI_MCBSP_SPCR_RINTM(3) | | 345 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
224 | DAVINCI_MCBSP_SPCR_XINTM(3) | | 346 | w |= DAVINCI_MCBSP_SPCR_RINTM(3) | DAVINCI_MCBSP_SPCR_FREE; |
225 | DAVINCI_MCBSP_SPCR_FREE); | 347 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); |
226 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, | 348 | } else { |
227 | DAVINCI_MCBSP_RCR_RFRLEN1(1) | | 349 | w |= DAVINCI_MCBSP_SPCR_XINTM(3) | DAVINCI_MCBSP_SPCR_FREE; |
228 | DAVINCI_MCBSP_RCR_RDATDLY(1)); | 350 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w); |
229 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, | 351 | } |
230 | DAVINCI_MCBSP_XCR_XFRLEN1(1) | | ||
231 | DAVINCI_MCBSP_XCR_XDATDLY(1) | | ||
232 | DAVINCI_MCBSP_XCR_XFIG); | ||
233 | 352 | ||
234 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); | 353 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); |
235 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG); | 354 | w = DAVINCI_MCBSP_SRGR_FSGM; |
236 | MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FWID(snd_interval_value(i) - 1), 1); | 355 | MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FWID(snd_interval_value(i) - 1), 1); |
237 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w); | ||
238 | 356 | ||
239 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_FRAME_BITS); | 357 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_FRAME_BITS); |
240 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG); | ||
241 | MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FPER(snd_interval_value(i) - 1), 1); | 358 | MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FPER(snd_interval_value(i) - 1), 1); |
242 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w); | 359 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w); |
243 | 360 | ||
@@ -260,20 +377,24 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, | |||
260 | return -EINVAL; | 377 | return -EINVAL; |
261 | } | 378 | } |
262 | 379 | ||
263 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_RCR_REG); | 380 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
264 | MOD_REG_BIT(w, DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) | | 381 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_RCR_REG); |
265 | DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length), 1); | 382 | MOD_REG_BIT(w, DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) | |
266 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, w); | 383 | DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length), 1); |
384 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, w); | ||
267 | 385 | ||
268 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_XCR_REG); | 386 | } else { |
269 | MOD_REG_BIT(w, DAVINCI_MCBSP_XCR_XWDLEN1(mcbsp_word_length) | | 387 | w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_XCR_REG); |
270 | DAVINCI_MCBSP_XCR_XWDLEN2(mcbsp_word_length), 1); | 388 | MOD_REG_BIT(w, DAVINCI_MCBSP_XCR_XWDLEN1(mcbsp_word_length) | |
271 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, w); | 389 | DAVINCI_MCBSP_XCR_XWDLEN2(mcbsp_word_length), 1); |
390 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, w); | ||
272 | 391 | ||
392 | } | ||
273 | return 0; | 393 | return 0; |
274 | } | 394 | } |
275 | 395 | ||
276 | static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd) | 396 | static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
397 | struct snd_soc_dai *dai) | ||
277 | { | 398 | { |
278 | int ret = 0; | 399 | int ret = 0; |
279 | 400 | ||
@@ -299,8 +420,8 @@ static int davinci_i2s_probe(struct platform_device *pdev, | |||
299 | struct snd_soc_dai *dai) | 420 | struct snd_soc_dai *dai) |
300 | { | 421 | { |
301 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 422 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
302 | struct snd_soc_machine *machine = socdev->machine; | 423 | struct snd_soc_card *card = socdev->card; |
303 | struct snd_soc_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai; | 424 | struct snd_soc_dai *cpu_dai = card->dai_link[pdev->id].cpu_dai; |
304 | struct davinci_mcbsp_dev *dev; | 425 | struct davinci_mcbsp_dev *dev; |
305 | struct resource *mem, *ioarea; | 426 | struct resource *mem, *ioarea; |
306 | struct evm_snd_platform_data *pdata; | 427 | struct evm_snd_platform_data *pdata; |
@@ -361,8 +482,8 @@ static void davinci_i2s_remove(struct platform_device *pdev, | |||
361 | struct snd_soc_dai *dai) | 482 | struct snd_soc_dai *dai) |
362 | { | 483 | { |
363 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); | 484 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
364 | struct snd_soc_machine *machine = socdev->machine; | 485 | struct snd_soc_card *card = socdev->card; |
365 | struct snd_soc_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai; | 486 | struct snd_soc_dai *cpu_dai = card->dai_link[pdev->id].cpu_dai; |
366 | struct davinci_mcbsp_dev *dev = cpu_dai->private_data; | 487 | struct davinci_mcbsp_dev *dev = cpu_dai->private_data; |
367 | struct resource *mem; | 488 | struct resource *mem; |
368 | 489 | ||
@@ -381,7 +502,6 @@ static void davinci_i2s_remove(struct platform_device *pdev, | |||
381 | struct snd_soc_dai davinci_i2s_dai = { | 502 | struct snd_soc_dai davinci_i2s_dai = { |
382 | .name = "davinci-i2s", | 503 | .name = "davinci-i2s", |
383 | .id = 0, | 504 | .id = 0, |
384 | .type = SND_SOC_DAI_I2S, | ||
385 | .probe = davinci_i2s_probe, | 505 | .probe = davinci_i2s_probe, |
386 | .remove = davinci_i2s_remove, | 506 | .remove = davinci_i2s_remove, |
387 | .playback = { | 507 | .playback = { |
@@ -397,13 +517,24 @@ struct snd_soc_dai davinci_i2s_dai = { | |||
397 | .ops = { | 517 | .ops = { |
398 | .startup = davinci_i2s_startup, | 518 | .startup = davinci_i2s_startup, |
399 | .trigger = davinci_i2s_trigger, | 519 | .trigger = davinci_i2s_trigger, |
400 | .hw_params = davinci_i2s_hw_params,}, | 520 | .hw_params = davinci_i2s_hw_params, |
401 | .dai_ops = { | ||
402 | .set_fmt = davinci_i2s_set_dai_fmt, | 521 | .set_fmt = davinci_i2s_set_dai_fmt, |
403 | }, | 522 | }, |
404 | }; | 523 | }; |
405 | EXPORT_SYMBOL_GPL(davinci_i2s_dai); | 524 | EXPORT_SYMBOL_GPL(davinci_i2s_dai); |
406 | 525 | ||
526 | static int __init davinci_i2s_init(void) | ||
527 | { | ||
528 | return snd_soc_register_dai(&davinci_i2s_dai); | ||
529 | } | ||
530 | module_init(davinci_i2s_init); | ||
531 | |||
532 | static void __exit davinci_i2s_exit(void) | ||
533 | { | ||
534 | snd_soc_unregister_dai(&davinci_i2s_dai); | ||
535 | } | ||
536 | module_exit(davinci_i2s_exit); | ||
537 | |||
407 | MODULE_AUTHOR("Vladimir Barinov"); | 538 | MODULE_AUTHOR("Vladimir Barinov"); |
408 | MODULE_DESCRIPTION("TI DAVINCI I2S (McBSP) SoC Interface"); | 539 | MODULE_DESCRIPTION("TI DAVINCI I2S (McBSP) SoC Interface"); |
409 | MODULE_LICENSE("GPL"); | 540 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c index 76feaa657375..74abc9b4f1cc 100644 --- a/sound/soc/davinci/davinci-pcm.c +++ b/sound/soc/davinci/davinci-pcm.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/dma-mapping.h> | 16 | #include <linux/dma-mapping.h> |
17 | #include <linux/kernel.h> | ||
17 | 18 | ||
18 | #include <sound/core.h> | 19 | #include <sound/core.h> |
19 | #include <sound/pcm.h> | 20 | #include <sound/pcm.h> |
@@ -24,13 +25,6 @@ | |||
24 | 25 | ||
25 | #include "davinci-pcm.h" | 26 | #include "davinci-pcm.h" |
26 | 27 | ||
27 | #define DAVINCI_PCM_DEBUG 0 | ||
28 | #if DAVINCI_PCM_DEBUG | ||
29 | #define DPRINTK(x...) printk(KERN_DEBUG x) | ||
30 | #else | ||
31 | #define DPRINTK(x...) | ||
32 | #endif | ||
33 | |||
34 | static struct snd_pcm_hardware davinci_pcm_hardware = { | 28 | static struct snd_pcm_hardware davinci_pcm_hardware = { |
35 | .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | | 29 | .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
36 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | | 30 | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | |
@@ -78,8 +72,8 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream) | |||
78 | dma_offset = prtd->period * period_size; | 72 | dma_offset = prtd->period * period_size; |
79 | dma_pos = runtime->dma_addr + dma_offset; | 73 | dma_pos = runtime->dma_addr + dma_offset; |
80 | 74 | ||
81 | DPRINTK("audio_set_dma_params_play channel = %d dma_ptr = %x " | 75 | pr_debug("davinci_pcm: audio_set_dma_params_play channel = %d " |
82 | "period_size=%x\n", lch, dma_pos, period_size); | 76 | "dma_ptr = %x period_size=%x\n", lch, dma_pos, period_size); |
83 | 77 | ||
84 | data_type = prtd->params->data_type; | 78 | data_type = prtd->params->data_type; |
85 | count = period_size / data_type; | 79 | count = period_size / data_type; |
@@ -112,7 +106,7 @@ static void davinci_pcm_dma_irq(int lch, u16 ch_status, void *data) | |||
112 | struct snd_pcm_substream *substream = data; | 106 | struct snd_pcm_substream *substream = data; |
113 | struct davinci_runtime_data *prtd = substream->runtime->private_data; | 107 | struct davinci_runtime_data *prtd = substream->runtime->private_data; |
114 | 108 | ||
115 | DPRINTK("lch=%d, status=0x%x\n", lch, ch_status); | 109 | pr_debug("davinci_pcm: lch=%d, status=0x%x\n", lch, ch_status); |
116 | 110 | ||
117 | if (unlikely(ch_status != DMA_COMPLETE)) | 111 | if (unlikely(ch_status != DMA_COMPLETE)) |
118 | return; | 112 | return; |
@@ -316,8 +310,8 @@ static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) | |||
316 | buf->area = dma_alloc_writecombine(pcm->card->dev, size, | 310 | buf->area = dma_alloc_writecombine(pcm->card->dev, size, |
317 | &buf->addr, GFP_KERNEL); | 311 | &buf->addr, GFP_KERNEL); |
318 | 312 | ||
319 | DPRINTK("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n", | 313 | pr_debug("davinci_pcm: preallocate_dma_buffer: area=%p, addr=%p, " |
320 | (void *) buf->area, (void *) buf->addr, size); | 314 | "size=%d\n", (void *) buf->area, (void *) buf->addr, size); |
321 | 315 | ||
322 | if (!buf->area) | 316 | if (!buf->area) |
323 | return -ENOMEM; | 317 | return -ENOMEM; |
@@ -384,6 +378,18 @@ struct snd_soc_platform davinci_soc_platform = { | |||
384 | }; | 378 | }; |
385 | EXPORT_SYMBOL_GPL(davinci_soc_platform); | 379 | EXPORT_SYMBOL_GPL(davinci_soc_platform); |
386 | 380 | ||
381 | static int __init davinci_soc_platform_init(void) | ||
382 | { | ||
383 | return snd_soc_register_platform(&davinci_soc_platform); | ||
384 | } | ||
385 | module_init(davinci_soc_platform_init); | ||
386 | |||
387 | static void __exit davinci_soc_platform_exit(void) | ||
388 | { | ||
389 | snd_soc_unregister_platform(&davinci_soc_platform); | ||
390 | } | ||
391 | module_exit(davinci_soc_platform_exit); | ||
392 | |||
387 | MODULE_AUTHOR("Vladimir Barinov"); | 393 | MODULE_AUTHOR("Vladimir Barinov"); |
388 | MODULE_DESCRIPTION("TI DAVINCI PCM DMA module"); | 394 | MODULE_DESCRIPTION("TI DAVINCI PCM DMA module"); |
389 | MODULE_LICENSE("GPL"); | 395 | MODULE_LICENSE("GPL"); |
diff --git a/sound/soc/davinci/davinci-sffsdr.c b/sound/soc/davinci/davinci-sffsdr.c new file mode 100644 index 000000000000..f67579d52765 --- /dev/null +++ b/sound/soc/davinci/davinci-sffsdr.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * ASoC driver for Lyrtech SFFSDR board. | ||
3 | * | ||
4 | * Author: Hugo Villeneuve | ||
5 | * Copyright (C) 2008 Lyrtech inc | ||
6 | * | ||
7 | * Based on ASoC driver for TI DAVINCI EVM platform, original copyright follow: | ||
8 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/moduleparam.h> | ||
17 | #include <linux/timer.h> | ||
18 | #include <linux/interrupt.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/gpio.h> | ||
21 | #include <sound/core.h> | ||
22 | #include <sound/pcm.h> | ||
23 | #include <sound/soc.h> | ||
24 | #include <sound/soc-dapm.h> | ||
25 | |||
26 | #include <asm/dma.h> | ||
27 | #include <asm/plat-sffsdr/sffsdr-fpga.h> | ||
28 | |||
29 | #include <mach/mcbsp.h> | ||
30 | #include <mach/edma.h> | ||
31 | |||
32 | #include "../codecs/pcm3008.h" | ||
33 | #include "davinci-pcm.h" | ||
34 | #include "davinci-i2s.h" | ||
35 | |||
36 | static int sffsdr_hw_params(struct snd_pcm_substream *substream, | ||
37 | struct snd_pcm_hw_params *params, | ||
38 | struct snd_soc_dai *dai) | ||
39 | { | ||
40 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
41 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | ||
42 | int fs; | ||
43 | int ret = 0; | ||
44 | |||
45 | /* Set cpu DAI configuration: | ||
46 | * CLKX and CLKR are the inputs for the Sample Rate Generator. | ||
47 | * FSX and FSR are outputs, driven by the sample Rate Generator. */ | ||
48 | ret = snd_soc_dai_set_fmt(cpu_dai, | ||
49 | SND_SOC_DAIFMT_RIGHT_J | | ||
50 | SND_SOC_DAIFMT_CBM_CFS | | ||
51 | SND_SOC_DAIFMT_IB_NF); | ||
52 | if (ret < 0) | ||
53 | return ret; | ||
54 | |||
55 | /* Fsref can be 32000, 44100 or 48000. */ | ||
56 | fs = params_rate(params); | ||
57 | |||
58 | pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs); | ||
59 | |||
60 | return sffsdr_fpga_set_codec_fs(fs); | ||
61 | } | ||
62 | |||
63 | static struct snd_soc_ops sffsdr_ops = { | ||
64 | .hw_params = sffsdr_hw_params, | ||
65 | }; | ||
66 | |||
67 | /* davinci-sffsdr digital audio interface glue - connects codec <--> CPU */ | ||
68 | static struct snd_soc_dai_link sffsdr_dai = { | ||
69 | .name = "PCM3008", /* Codec name */ | ||
70 | .stream_name = "PCM3008 HiFi", | ||
71 | .cpu_dai = &davinci_i2s_dai, | ||
72 | .codec_dai = &pcm3008_dai, | ||
73 | .ops = &sffsdr_ops, | ||
74 | }; | ||
75 | |||
76 | /* davinci-sffsdr audio machine driver */ | ||
77 | static struct snd_soc_card snd_soc_sffsdr = { | ||
78 | .name = "DaVinci SFFSDR", | ||
79 | .platform = &davinci_soc_platform, | ||
80 | .dai_link = &sffsdr_dai, | ||
81 | .num_links = 1, | ||
82 | }; | ||
83 | |||
84 | /* sffsdr audio private data */ | ||
85 | static struct pcm3008_setup_data sffsdr_pcm3008_setup = { | ||
86 | .dem0_pin = GPIO(45), | ||
87 | .dem1_pin = GPIO(46), | ||
88 | .pdad_pin = GPIO(47), | ||
89 | .pdda_pin = GPIO(38), | ||
90 | }; | ||
91 | |||
92 | /* sffsdr audio subsystem */ | ||
93 | static struct snd_soc_device sffsdr_snd_devdata = { | ||
94 | .card = &snd_soc_sffsdr, | ||
95 | .codec_dev = &soc_codec_dev_pcm3008, | ||
96 | .codec_data = &sffsdr_pcm3008_setup, | ||
97 | }; | ||
98 | |||
99 | static struct resource sffsdr_snd_resources[] = { | ||
100 | { | ||
101 | .start = DAVINCI_MCBSP_BASE, | ||
102 | .end = DAVINCI_MCBSP_BASE + SZ_8K - 1, | ||
103 | .flags = IORESOURCE_MEM, | ||
104 | }, | ||
105 | }; | ||
106 | |||
107 | static struct evm_snd_platform_data sffsdr_snd_data = { | ||
108 | .tx_dma_ch = DAVINCI_DMA_MCBSP_TX, | ||
109 | .rx_dma_ch = DAVINCI_DMA_MCBSP_RX, | ||
110 | }; | ||
111 | |||
112 | static struct platform_device *sffsdr_snd_device; | ||
113 | |||
114 | static int __init sffsdr_init(void) | ||
115 | { | ||
116 | int ret; | ||
117 | |||
118 | sffsdr_snd_device = platform_device_alloc("soc-audio", 0); | ||
119 | if (!sffsdr_snd_device) { | ||
120 | printk(KERN_ERR "platform device allocation failed\n"); | ||
121 | return -ENOMEM; | ||
122 | } | ||
123 | |||
124 | platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata); | ||
125 | sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev; | ||
126 | sffsdr_snd_device->dev.platform_data = &sffsdr_snd_data; | ||
127 | |||
128 | ret = platform_device_add_resources(sffsdr_snd_device, | ||
129 | sffsdr_snd_resources, | ||
130 | ARRAY_SIZE(sffsdr_snd_resources)); | ||
131 | if (ret) { | ||
132 | printk(KERN_ERR "platform device add ressources failed\n"); | ||
133 | goto error; | ||
134 | } | ||
135 | |||
136 | ret = platform_device_add(sffsdr_snd_device); | ||
137 | if (ret) | ||
138 | goto error; | ||
139 | |||
140 | return ret; | ||
141 | |||
142 | error: | ||
143 | platform_device_put(sffsdr_snd_device); | ||
144 | return ret; | ||
145 | } | ||
146 | |||
147 | static void __exit sffsdr_exit(void) | ||
148 | { | ||
149 | platform_device_unregister(sffsdr_snd_device); | ||
150 | } | ||
151 | |||
152 | module_init(sffsdr_init); | ||
153 | module_exit(sffsdr_exit); | ||
154 | |||
155 | MODULE_AUTHOR("Hugo Villeneuve"); | ||
156 | MODULE_DESCRIPTION("Lyrtech SFFSDR ASoC driver"); | ||
157 | MODULE_LICENSE("GPL"); | ||