aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2010-08-20 12:19:27 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-08-20 12:19:27 -0400
commitbf557a50f59fc62dfd89fa5bf08c6f5d96fb2f45 (patch)
tree81a2cd45044970ccceec9ae4e1547e8f5dee850d /sound
parent26b01ccdc8ded270a1a65721b99acacf0c44e088 (diff)
parent3fabe089ad8b8f238bc9de3e7586ae8d2a81f57c (diff)
Merge branch 'for-2.6.37' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/asoc-2.6 into for-2.6.37
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/wl1273.c525
-rw-r--r--sound/soc/codecs/wl1273.h101
-rw-r--r--sound/soc/fsl/fsl_dma.c67
-rw-r--r--sound/soc/fsl/fsl_ssi.c25
4 files changed, 699 insertions, 19 deletions
diff --git a/sound/soc/codecs/wl1273.c b/sound/soc/codecs/wl1273.c
new file mode 100644
index 000000000000..0cd590970883
--- /dev/null
+++ b/sound/soc/codecs/wl1273.c
@@ -0,0 +1,525 @@
1/*
2 * ALSA SoC WL1273 codec driver
3 *
4 * Author: Matti Aaltonen, <matti.j.aaltonen@nokia.com>
5 *
6 * Copyright: (C) 2010 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/mfd/wl1273-core.h>
25#include <linux/slab.h>
26#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc-dai.h>
29#include <sound/soc-dapm.h>
30#include <sound/initval.h>
31
32#include "wl1273.h"
33
34enum wl1273_mode { WL1273_MODE_BT, WL1273_MODE_FM_RX, WL1273_MODE_FM_TX };
35
36/* codec private data */
37struct wl1273_priv {
38 enum wl1273_mode mode;
39 struct wl1273_core *core;
40 unsigned int channels;
41};
42
43static int snd_wl1273_fm_set_i2s_mode(struct wl1273_core *core,
44 int rate, int width)
45{
46 struct device *dev = &core->i2c_dev->dev;
47 int r = 0;
48 u16 mode;
49
50 dev_dbg(dev, "rate: %d\n", rate);
51 dev_dbg(dev, "width: %d\n", width);
52
53 mutex_lock(&core->lock);
54
55 mode = core->i2s_mode & ~WL1273_IS2_WIDTH & ~WL1273_IS2_RATE;
56
57 switch (rate) {
58 case 48000:
59 mode |= WL1273_IS2_RATE_48K;
60 break;
61 case 44100:
62 mode |= WL1273_IS2_RATE_44_1K;
63 break;
64 case 32000:
65 mode |= WL1273_IS2_RATE_32K;
66 break;
67 case 22050:
68 mode |= WL1273_IS2_RATE_22_05K;
69 break;
70 case 16000:
71 mode |= WL1273_IS2_RATE_16K;
72 break;
73 case 12000:
74 mode |= WL1273_IS2_RATE_12K;
75 break;
76 case 11025:
77 mode |= WL1273_IS2_RATE_11_025;
78 break;
79 case 8000:
80 mode |= WL1273_IS2_RATE_8K;
81 break;
82 default:
83 dev_err(dev, "Sampling rate: %d not supported\n", rate);
84 r = -EINVAL;
85 goto out;
86 }
87
88 switch (width) {
89 case 16:
90 mode |= WL1273_IS2_WIDTH_32;
91 break;
92 case 20:
93 mode |= WL1273_IS2_WIDTH_40;
94 break;
95 case 24:
96 mode |= WL1273_IS2_WIDTH_48;
97 break;
98 case 25:
99 mode |= WL1273_IS2_WIDTH_50;
100 break;
101 case 30:
102 mode |= WL1273_IS2_WIDTH_60;
103 break;
104 case 32:
105 mode |= WL1273_IS2_WIDTH_64;
106 break;
107 case 40:
108 mode |= WL1273_IS2_WIDTH_80;
109 break;
110 case 48:
111 mode |= WL1273_IS2_WIDTH_96;
112 break;
113 case 64:
114 mode |= WL1273_IS2_WIDTH_128;
115 break;
116 default:
117 dev_err(dev, "Data width: %d not supported\n", width);
118 r = -EINVAL;
119 goto out;
120 }
121
122 dev_dbg(dev, "WL1273_I2S_DEF_MODE: 0x%04x\n", WL1273_I2S_DEF_MODE);
123 dev_dbg(dev, "core->i2s_mode: 0x%04x\n", core->i2s_mode);
124 dev_dbg(dev, "mode: 0x%04x\n", mode);
125
126 if (core->i2s_mode != mode) {
127 r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET, mode);
128 if (r)
129 goto out;
130
131 core->i2s_mode = mode;
132 r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE,
133 WL1273_AUDIO_ENABLE_I2S);
134 if (r)
135 goto out;
136 }
137out:
138 mutex_unlock(&core->lock);
139
140 return r;
141}
142
143static int snd_wl1273_fm_set_channel_number(struct wl1273_core *core,
144 int channel_number)
145{
146 struct i2c_client *client = core->i2c_dev;
147 struct device *dev = &client->dev;
148 int r = 0;
149
150 dev_dbg(dev, "%s\n", __func__);
151
152 mutex_lock(&core->lock);
153
154 if (core->channel_number == channel_number)
155 goto out;
156
157 if (channel_number == 1 && core->mode == WL1273_MODE_RX)
158 r = wl1273_fm_write_cmd(core, WL1273_MOST_MODE_SET,
159 WL1273_RX_MONO);
160 else if (channel_number == 1 && core->mode == WL1273_MODE_TX)
161 r = wl1273_fm_write_cmd(core, WL1273_MONO_SET,
162 WL1273_TX_MONO);
163 else if (channel_number == 2 && core->mode == WL1273_MODE_RX)
164 r = wl1273_fm_write_cmd(core, WL1273_MOST_MODE_SET,
165 WL1273_RX_STEREO);
166 else if (channel_number == 2 && core->mode == WL1273_MODE_TX)
167 r = wl1273_fm_write_cmd(core, WL1273_MONO_SET,
168 WL1273_TX_STEREO);
169 else
170 r = -EINVAL;
171out:
172 mutex_unlock(&core->lock);
173
174 return r;
175}
176
177static int snd_wl1273_get_audio_route(struct snd_kcontrol *kcontrol,
178 struct snd_ctl_elem_value *ucontrol)
179{
180 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
181 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
182
183 ucontrol->value.integer.value[0] = wl1273->mode;
184
185 return 0;
186}
187
188static const char *wl1273_audio_route[] = { "Bt", "FmRx", "FmTx" };
189
190static int snd_wl1273_set_audio_route(struct snd_kcontrol *kcontrol,
191 struct snd_ctl_elem_value *ucontrol)
192{
193 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
194 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
195
196 /* Do not allow changes while stream is running */
197 if (codec->active)
198 return -EPERM;
199
200 if (ucontrol->value.integer.value[0] < 0 ||
201 ucontrol->value.integer.value[0] >= ARRAY_SIZE(wl1273_audio_route))
202 return -EINVAL;
203
204 wl1273->mode = ucontrol->value.integer.value[0];
205
206 return 1;
207}
208
209static const struct soc_enum wl1273_enum =
210 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wl1273_audio_route), wl1273_audio_route);
211
212static int snd_wl1273_fm_audio_get(struct snd_kcontrol *kcontrol,
213 struct snd_ctl_elem_value *ucontrol)
214{
215 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
216 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
217
218 dev_dbg(codec->dev, "%s: enter.\n", __func__);
219
220 ucontrol->value.integer.value[0] = wl1273->core->audio_mode;
221
222 return 0;
223}
224
225static int snd_wl1273_fm_audio_put(struct snd_kcontrol *kcontrol,
226 struct snd_ctl_elem_value *ucontrol)
227{
228 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
229 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
230 int val, r = 0;
231
232 dev_dbg(codec->dev, "%s: enter.\n", __func__);
233
234 val = ucontrol->value.integer.value[0];
235 if (wl1273->core->audio_mode == val)
236 return 0;
237
238 r = wl1273_fm_set_audio(wl1273->core, val);
239 if (r < 0)
240 return r;
241
242 return 1;
243}
244
245static const char *wl1273_audio_strings[] = { "Digital", "Analog" };
246
247static const struct soc_enum wl1273_audio_enum =
248 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(wl1273_audio_strings),
249 wl1273_audio_strings);
250
251static int snd_wl1273_fm_volume_get(struct snd_kcontrol *kcontrol,
252 struct snd_ctl_elem_value *ucontrol)
253{
254 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
255 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
256
257 dev_dbg(codec->dev, "%s: enter.\n", __func__);
258
259 ucontrol->value.integer.value[0] = wl1273->core->volume;
260
261 return 0;
262}
263
264static int snd_wl1273_fm_volume_put(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_value *ucontrol)
266{
267 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
268 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
269 int r;
270
271 dev_dbg(codec->dev, "%s: enter.\n", __func__);
272
273 r = wl1273_fm_set_volume(wl1273->core,
274 ucontrol->value.integer.value[0]);
275 if (r)
276 return r;
277
278 return 1;
279}
280
281static const struct snd_kcontrol_new wl1273_controls[] = {
282 SOC_ENUM_EXT("Codec Mode", wl1273_enum,
283 snd_wl1273_get_audio_route, snd_wl1273_set_audio_route),
284 SOC_ENUM_EXT("Audio Switch", wl1273_audio_enum,
285 snd_wl1273_fm_audio_get, snd_wl1273_fm_audio_put),
286 SOC_SINGLE_EXT("Volume", 0, 0, WL1273_MAX_VOLUME, 0,
287 snd_wl1273_fm_volume_get, snd_wl1273_fm_volume_put),
288};
289
290static int wl1273_startup(struct snd_pcm_substream *substream,
291 struct snd_soc_dai *dai)
292{
293 struct snd_soc_pcm_runtime *rtd = substream->private_data;
294 struct snd_soc_codec *codec = rtd->codec;
295 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
296
297 switch (wl1273->mode) {
298 case WL1273_MODE_BT:
299 snd_pcm_hw_constraint_minmax(substream->runtime,
300 SNDRV_PCM_HW_PARAM_RATE,
301 8000, 8000);
302 snd_pcm_hw_constraint_minmax(substream->runtime,
303 SNDRV_PCM_HW_PARAM_CHANNELS, 1, 1);
304 break;
305 case WL1273_MODE_FM_RX:
306 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
307 pr_err("Cannot play in RX mode.\n");
308 return -EINVAL;
309 }
310 break;
311 case WL1273_MODE_FM_TX:
312 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
313 pr_err("Cannot capture in TX mode.\n");
314 return -EINVAL;
315 }
316 break;
317 default:
318 return -EINVAL;
319 break;
320 }
321
322 return 0;
323}
324
325static int wl1273_hw_params(struct snd_pcm_substream *substream,
326 struct snd_pcm_hw_params *params,
327 struct snd_soc_dai *dai)
328{
329 struct snd_soc_pcm_runtime *rtd = substream->private_data;
330 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(rtd->codec);
331 struct wl1273_core *core = wl1273->core;
332 unsigned int rate, width, r;
333
334 if (params_format(params) != SNDRV_PCM_FORMAT_S16_LE) {
335 pr_err("Only SNDRV_PCM_FORMAT_S16_LE supported.\n");
336 return -EINVAL;
337 }
338
339 rate = params_rate(params);
340 width = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min;
341
342 if (wl1273->mode == WL1273_MODE_BT) {
343 if (rate != 8000) {
344 pr_err("Rate %d not supported.\n", params_rate(params));
345 return -EINVAL;
346 }
347
348 if (params_channels(params) != 1) {
349 pr_err("Only mono supported.\n");
350 return -EINVAL;
351 }
352
353 return 0;
354 }
355
356 if (wl1273->mode == WL1273_MODE_FM_TX &&
357 substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
358 pr_err("Only playback supported with TX.\n");
359 return -EINVAL;
360 }
361
362 if (wl1273->mode == WL1273_MODE_FM_RX &&
363 substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
364 pr_err("Only capture supported with RX.\n");
365 return -EINVAL;
366 }
367
368 if (wl1273->mode != WL1273_MODE_FM_RX &&
369 wl1273->mode != WL1273_MODE_FM_TX) {
370 pr_err("Unexpected mode: %d.\n", wl1273->mode);
371 return -EINVAL;
372 }
373
374 r = snd_wl1273_fm_set_i2s_mode(core, rate, width);
375 if (r)
376 return r;
377
378 wl1273->channels = params_channels(params);
379 r = snd_wl1273_fm_set_channel_number(core, wl1273->channels);
380 if (r)
381 return r;
382
383 return 0;
384}
385
386static struct snd_soc_dai_ops wl1273_dai_ops = {
387 .startup = wl1273_startup,
388 .hw_params = wl1273_hw_params,
389};
390
391static struct snd_soc_dai_driver wl1273_dai = {
392 .name = "wl1273-fm",
393 .playback = {
394 .stream_name = "Playback",
395 .channels_min = 1,
396 .channels_max = 2,
397 .rates = SNDRV_PCM_RATE_8000_48000,
398 .formats = SNDRV_PCM_FMTBIT_S16_LE},
399 .capture = {
400 .stream_name = "Capture",
401 .channels_min = 1,
402 .channels_max = 2,
403 .rates = SNDRV_PCM_RATE_8000_48000,
404 .formats = SNDRV_PCM_FMTBIT_S16_LE},
405 .ops = &wl1273_dai_ops,
406};
407
408/* Audio interface format for the soc_card driver */
409int wl1273_get_format(struct snd_soc_codec *codec, unsigned int *fmt)
410{
411 struct wl1273_priv *wl1273;
412
413 if (codec == NULL || fmt == NULL)
414 return -EINVAL;
415
416 wl1273 = snd_soc_codec_get_drvdata(codec);
417
418 switch (wl1273->mode) {
419 case WL1273_MODE_FM_RX:
420 case WL1273_MODE_FM_TX:
421 *fmt = SND_SOC_DAIFMT_I2S |
422 SND_SOC_DAIFMT_NB_NF |
423 SND_SOC_DAIFMT_CBM_CFM;
424
425 break;
426 case WL1273_MODE_BT:
427 *fmt = SND_SOC_DAIFMT_DSP_A |
428 SND_SOC_DAIFMT_IB_NF |
429 SND_SOC_DAIFMT_CBM_CFM;
430
431 break;
432 default:
433 return -EINVAL;
434 }
435
436 return 0;
437}
438EXPORT_SYMBOL_GPL(wl1273_get_format);
439
440static int wl1273_probe(struct snd_soc_codec *codec)
441{
442 struct wl1273_core **core = codec->dev->platform_data;
443 struct wl1273_priv *wl1273;
444 int r;
445
446 dev_dbg(codec->dev, "%s.\n", __func__);
447
448 if (!core) {
449 dev_err(codec->dev, "Platform data is missing.\n");
450 return -EINVAL;
451 }
452
453 wl1273 = kzalloc(sizeof(struct wl1273_priv), GFP_KERNEL);
454 if (wl1273 == NULL) {
455 dev_err(codec->dev, "Cannot allocate memory.\n");
456 return -ENOMEM;
457 }
458
459 wl1273->mode = WL1273_MODE_BT;
460 wl1273->core = *core;
461
462 snd_soc_codec_set_drvdata(codec, wl1273);
463 mutex_init(&codec->mutex);
464
465 r = snd_soc_add_controls(codec, wl1273_controls,
466 ARRAY_SIZE(wl1273_controls));
467 if (r)
468 kfree(wl1273);
469
470 return r;
471}
472
473static int wl1273_remove(struct snd_soc_codec *codec)
474{
475 struct wl1273_priv *wl1273 = snd_soc_codec_get_drvdata(codec);
476
477 dev_dbg(codec->dev, "%s\n", __func__);
478 kfree(wl1273);
479
480 return 0;
481}
482
483static struct snd_soc_codec_driver soc_codec_dev_wl1273 = {
484 .probe = wl1273_probe,
485 .remove = wl1273_remove,
486};
487
488static int __devinit wl1273_platform_probe(struct platform_device *pdev)
489{
490 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wl1273,
491 &wl1273_dai, 1);
492}
493
494static int __devexit wl1273_platform_remove(struct platform_device *pdev)
495{
496 snd_soc_unregister_codec(&pdev->dev);
497 return 0;
498}
499
500MODULE_ALIAS("platform:wl1273-codec");
501
502static struct platform_driver wl1273_platform_driver = {
503 .driver = {
504 .name = "wl1273-codec",
505 .owner = THIS_MODULE,
506 },
507 .probe = wl1273_platform_probe,
508 .remove = __devexit_p(wl1273_platform_remove),
509};
510
511static int __init wl1273_init(void)
512{
513 return platform_driver_register(&wl1273_platform_driver);
514}
515module_init(wl1273_init);
516
517static void __exit wl1273_exit(void)
518{
519 platform_driver_unregister(&wl1273_platform_driver);
520}
521module_exit(wl1273_exit);
522
523MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>");
524MODULE_DESCRIPTION("ASoC WL1273 codec driver");
525MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wl1273.h b/sound/soc/codecs/wl1273.h
new file mode 100644
index 000000000000..14ed027fdcfc
--- /dev/null
+++ b/sound/soc/codecs/wl1273.h
@@ -0,0 +1,101 @@
1/*
2 * sound/soc/codec/wl1273.h
3 *
4 * ALSA SoC WL1273 codec driver
5 *
6 * Copyright (C) Nokia Corporation
7 * Author: Matti Aaltonen <matti.j.aaltonen@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1273_CODEC_H__
26#define __WL1273_CODEC_H__
27
28/* I2S protocol, left channel first, data width 16 bits */
29#define WL1273_PCM_DEF_MODE 0x00
30
31/* Rx */
32#define WL1273_AUDIO_ENABLE_I2S (1 << 0)
33#define WL1273_AUDIO_ENABLE_ANALOG (1 << 1)
34
35/* Tx */
36#define WL1273_AUDIO_IO_SET_ANALOG 0
37#define WL1273_AUDIO_IO_SET_I2S 1
38
39#define WL1273_POWER_SET_OFF 0
40#define WL1273_POWER_SET_FM (1 << 0)
41#define WL1273_POWER_SET_RDS (1 << 1)
42#define WL1273_POWER_SET_RETENTION (1 << 4)
43
44#define WL1273_PUPD_SET_OFF 0x00
45#define WL1273_PUPD_SET_ON 0x01
46#define WL1273_PUPD_SET_RETENTION 0x10
47
48/* I2S mode */
49#define WL1273_IS2_WIDTH_32 0x0
50#define WL1273_IS2_WIDTH_40 0x1
51#define WL1273_IS2_WIDTH_22_23 0x2
52#define WL1273_IS2_WIDTH_23_22 0x3
53#define WL1273_IS2_WIDTH_48 0x4
54#define WL1273_IS2_WIDTH_50 0x5
55#define WL1273_IS2_WIDTH_60 0x6
56#define WL1273_IS2_WIDTH_64 0x7
57#define WL1273_IS2_WIDTH_80 0x8
58#define WL1273_IS2_WIDTH_96 0x9
59#define WL1273_IS2_WIDTH_128 0xa
60#define WL1273_IS2_WIDTH 0xf
61
62#define WL1273_IS2_FORMAT_STD (0x0 << 4)
63#define WL1273_IS2_FORMAT_LEFT (0x1 << 4)
64#define WL1273_IS2_FORMAT_RIGHT (0x2 << 4)
65#define WL1273_IS2_FORMAT_USER (0x3 << 4)
66
67#define WL1273_IS2_MASTER (0x0 << 6)
68#define WL1273_IS2_SLAVEW (0x1 << 6)
69
70#define WL1273_IS2_TRI_AFTER_SENDING (0x0 << 7)
71#define WL1273_IS2_TRI_ALWAYS_ACTIVE (0x1 << 7)
72
73#define WL1273_IS2_SDOWS_RR (0x0 << 8)
74#define WL1273_IS2_SDOWS_RF (0x1 << 8)
75#define WL1273_IS2_SDOWS_FR (0x2 << 8)
76#define WL1273_IS2_SDOWS_FF (0x3 << 8)
77
78#define WL1273_IS2_TRI_OPT (0x0 << 10)
79#define WL1273_IS2_TRI_ALWAYS (0x1 << 10)
80
81#define WL1273_IS2_RATE_48K (0x0 << 12)
82#define WL1273_IS2_RATE_44_1K (0x1 << 12)
83#define WL1273_IS2_RATE_32K (0x2 << 12)
84#define WL1273_IS2_RATE_22_05K (0x4 << 12)
85#define WL1273_IS2_RATE_16K (0x5 << 12)
86#define WL1273_IS2_RATE_12K (0x8 << 12)
87#define WL1273_IS2_RATE_11_025 (0x9 << 12)
88#define WL1273_IS2_RATE_8K (0xa << 12)
89#define WL1273_IS2_RATE (0xf << 12)
90
91#define WL1273_I2S_DEF_MODE (WL1273_IS2_WIDTH_32 | \
92 WL1273_IS2_FORMAT_STD | \
93 WL1273_IS2_MASTER | \
94 WL1273_IS2_TRI_AFTER_SENDING | \
95 WL1273_IS2_SDOWS_RR | \
96 WL1273_IS2_TRI_OPT | \
97 WL1273_IS2_RATE_48K)
98
99int wl1273_get_format(struct snd_soc_codec *codec, unsigned int *fmt);
100
101#endif /* End of __WL1273_CODEC_H__ */
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 5a6f56d63756..f039e8db0765 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -60,6 +60,7 @@ struct dma_object {
60 struct snd_soc_platform_driver dai; 60 struct snd_soc_platform_driver dai;
61 dma_addr_t ssi_stx_phys; 61 dma_addr_t ssi_stx_phys;
62 dma_addr_t ssi_srx_phys; 62 dma_addr_t ssi_srx_phys;
63 unsigned int ssi_fifo_depth;
63 struct ccsr_dma_channel __iomem *channel; 64 struct ccsr_dma_channel __iomem *channel;
64 unsigned int irq; 65 unsigned int irq;
65 bool assigned; 66 bool assigned;
@@ -99,6 +100,7 @@ struct fsl_dma_private {
99 unsigned int irq; 100 unsigned int irq;
100 struct snd_pcm_substream *substream; 101 struct snd_pcm_substream *substream;
101 dma_addr_t ssi_sxx_phys; 102 dma_addr_t ssi_sxx_phys;
103 unsigned int ssi_fifo_depth;
102 dma_addr_t ld_buf_phys; 104 dma_addr_t ld_buf_phys;
103 unsigned int current_link; 105 unsigned int current_link;
104 dma_addr_t dma_buf_phys; 106 dma_addr_t dma_buf_phys;
@@ -439,6 +441,7 @@ static int fsl_dma_open(struct snd_pcm_substream *substream)
439 else 441 else
440 dma_private->ssi_sxx_phys = dma->ssi_srx_phys; 442 dma_private->ssi_sxx_phys = dma->ssi_srx_phys;
441 443
444 dma_private->ssi_fifo_depth = dma->ssi_fifo_depth;
442 dma_private->dma_channel = dma->channel; 445 dma_private->dma_channel = dma->channel;
443 dma_private->irq = dma->irq; 446 dma_private->irq = dma->irq;
444 dma_private->substream = substream; 447 dma_private->substream = substream;
@@ -552,11 +555,11 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream,
552 struct device *dev = rtd->platform->dev; 555 struct device *dev = rtd->platform->dev;
553 556
554 /* Number of bits per sample */ 557 /* Number of bits per sample */
555 unsigned int sample_size = 558 unsigned int sample_bits =
556 snd_pcm_format_physical_width(params_format(hw_params)); 559 snd_pcm_format_physical_width(params_format(hw_params));
557 560
558 /* Number of bytes per frame */ 561 /* Number of bytes per frame */
559 unsigned int frame_size = 2 * (sample_size / 8); 562 unsigned int sample_bytes = sample_bits / 8;
560 563
561 /* Bus address of SSI STX register */ 564 /* Bus address of SSI STX register */
562 dma_addr_t ssi_sxx_phys = dma_private->ssi_sxx_phys; 565 dma_addr_t ssi_sxx_phys = dma_private->ssi_sxx_phys;
@@ -596,7 +599,7 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream,
596 * that offset here. While we're at it, also tell the DMA controller 599 * that offset here. While we're at it, also tell the DMA controller
597 * how much data to transfer per sample. 600 * how much data to transfer per sample.
598 */ 601 */
599 switch (sample_size) { 602 switch (sample_bits) {
600 case 8: 603 case 8:
601 mr |= CCSR_DMA_MR_DAHTS_1 | CCSR_DMA_MR_SAHTS_1; 604 mr |= CCSR_DMA_MR_DAHTS_1 | CCSR_DMA_MR_SAHTS_1;
602 ssi_sxx_phys += 3; 605 ssi_sxx_phys += 3;
@@ -610,22 +613,42 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream,
610 break; 613 break;
611 default: 614 default:
612 /* We should never get here */ 615 /* We should never get here */
613 dev_err(dev, "unsupported sample size %u\n", sample_size); 616 dev_err(dev, "unsupported sample size %u\n", sample_bits);
614 return -EINVAL; 617 return -EINVAL;
615 } 618 }
616 619
617 /* 620 /*
618 * BWC should always be a multiple of the frame size. BWC determines 621 * BWC determines how many bytes are sent/received before the DMA
619 * how many bytes are sent/received before the DMA controller checks the 622 * controller checks the SSI to see if it needs to stop. BWC should
620 * SSI to see if it needs to stop. For playback, the transmit FIFO can 623 * always be a multiple of the frame size, so that we always transmit
621 * hold three frames, so we want to send two frames at a time. For 624 * whole frames. Each frame occupies two slots in the FIFO. The
622 * capture, the receive FIFO is triggered when it contains one frame, so 625 * parameter for CCSR_DMA_MR_BWC() is rounded down the next power of two
623 * we want to receive one frame at a time. 626 * (MR[BWC] can only represent even powers of two).
627 *
628 * To simplify the process, we set BWC to the largest value that is
629 * less than or equal to the FIFO watermark. For playback, this ensures
630 * that we transfer the maximum amount without overrunning the FIFO.
631 * For capture, this ensures that we transfer the maximum amount without
632 * underrunning the FIFO.
633 *
634 * f = SSI FIFO depth
635 * w = SSI watermark value (which equals f - 2)
636 * b = DMA bandwidth count (in bytes)
637 * s = sample size (in bytes, which equals frame_size * 2)
638 *
639 * For playback, we never transmit more than the transmit FIFO
640 * watermark, otherwise we might write more data than the FIFO can hold.
641 * The watermark is equal to the FIFO depth minus two.
642 *
643 * For capture, two equations must hold:
644 * w > f - (b / s)
645 * w >= b / s
646 *
647 * So, b > 2 * s, but b must also be <= s * w. To simplify, we set
648 * b = s * w, which is equal to
649 * (dma_private->ssi_fifo_depth - 2) * sample_bytes.
624 */ 650 */
625 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 651 mr |= CCSR_DMA_MR_BWC((dma_private->ssi_fifo_depth - 2) * sample_bytes);
626 mr |= CCSR_DMA_MR_BWC(2 * frame_size);
627 else
628 mr |= CCSR_DMA_MR_BWC(frame_size);
629 652
630 out_be32(&dma_channel->mr, mr); 653 out_be32(&dma_channel->mr, mr);
631 654
@@ -879,6 +902,7 @@ static int __devinit fsl_soc_dma_probe(struct of_device *of_dev,
879 struct device_node *np = of_dev->dev.of_node; 902 struct device_node *np = of_dev->dev.of_node;
880 struct device_node *ssi_np; 903 struct device_node *ssi_np;
881 struct resource res; 904 struct resource res;
905 const uint32_t *iprop;
882 int ret; 906 int ret;
883 907
884 /* Find the SSI node that points to us. */ 908 /* Find the SSI node that points to us. */
@@ -889,15 +913,17 @@ static int __devinit fsl_soc_dma_probe(struct of_device *of_dev,
889 } 913 }
890 914
891 ret = of_address_to_resource(ssi_np, 0, &res); 915 ret = of_address_to_resource(ssi_np, 0, &res);
892 of_node_put(ssi_np);
893 if (ret) { 916 if (ret) {
894 dev_err(&of_dev->dev, "could not determine device resources\n"); 917 dev_err(&of_dev->dev, "could not determine resources for %s\n",
918 ssi_np->full_name);
919 of_node_put(ssi_np);
895 return ret; 920 return ret;
896 } 921 }
897 922
898 dma = kzalloc(sizeof(*dma) + strlen(np->full_name), GFP_KERNEL); 923 dma = kzalloc(sizeof(*dma) + strlen(np->full_name), GFP_KERNEL);
899 if (!dma) { 924 if (!dma) {
900 dev_err(&of_dev->dev, "could not allocate dma object\n"); 925 dev_err(&of_dev->dev, "could not allocate dma object\n");
926 of_node_put(ssi_np);
901 return -ENOMEM; 927 return -ENOMEM;
902 } 928 }
903 929
@@ -910,6 +936,15 @@ static int __devinit fsl_soc_dma_probe(struct of_device *of_dev,
910 dma->ssi_stx_phys = res.start + offsetof(struct ccsr_ssi, stx0); 936 dma->ssi_stx_phys = res.start + offsetof(struct ccsr_ssi, stx0);
911 dma->ssi_srx_phys = res.start + offsetof(struct ccsr_ssi, srx0); 937 dma->ssi_srx_phys = res.start + offsetof(struct ccsr_ssi, srx0);
912 938
939 iprop = of_get_property(ssi_np, "fsl,fifo-depth", NULL);
940 if (iprop)
941 dma->ssi_fifo_depth = *iprop;
942 else
943 /* Older 8610 DTs didn't have the fifo-depth property */
944 dma->ssi_fifo_depth = 8;
945
946 of_node_put(ssi_np);
947
913 ret = snd_soc_register_platform(&of_dev->dev, &dma->dai); 948 ret = snd_soc_register_platform(&of_dev->dev, &dma->dai);
914 if (ret) { 949 if (ret) {
915 dev_err(&of_dev->dev, "could not register platform\n"); 950 dev_err(&of_dev->dev, "could not register platform\n");
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 7939c337ed9d..d1c855ade8fb 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -93,6 +93,7 @@ struct fsl_ssi_private {
93 unsigned int playback; 93 unsigned int playback;
94 unsigned int capture; 94 unsigned int capture;
95 int asynchronous; 95 int asynchronous;
96 unsigned int fifo_depth;
96 struct snd_soc_dai_driver cpu_dai_drv; 97 struct snd_soc_dai_driver cpu_dai_drv;
97 struct device_attribute dev_attr; 98 struct device_attribute dev_attr;
98 struct platform_device *pdev; 99 struct platform_device *pdev;
@@ -337,11 +338,20 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
337 338
338 /* 339 /*
339 * Set the watermark for transmit FIFI 0 and receive FIFO 0. We 340 * Set the watermark for transmit FIFI 0 and receive FIFO 0. We
340 * don't use FIFO 1. Since the SSI only supports stereo, the 341 * don't use FIFO 1. We program the transmit water to signal a
341 * watermark should never be an odd number. 342 * DMA transfer if there are only two (or fewer) elements left
343 * in the FIFO. Two elements equals one frame (left channel,
344 * right channel). This value, however, depends on the depth of
345 * the transmit buffer.
346 *
347 * We program the receive FIFO to notify us if at least two
348 * elements (one frame) have been written to the FIFO. We could
349 * make this value larger (and maybe we should), but this way
350 * data will be written to memory as soon as it's available.
342 */ 351 */
343 out_be32(&ssi->sfcsr, 352 out_be32(&ssi->sfcsr,
344 CCSR_SSI_SFCSR_TFWM0(6) | CCSR_SSI_SFCSR_RFWM0(2)); 353 CCSR_SSI_SFCSR_TFWM0(ssi_private->fifo_depth - 2) |
354 CCSR_SSI_SFCSR_RFWM0(ssi_private->fifo_depth - 2));
345 355
346 /* 356 /*
347 * We keep the SSI disabled because if we enable it, then the 357 * We keep the SSI disabled because if we enable it, then the
@@ -622,6 +632,7 @@ static int __devinit fsl_ssi_probe(struct of_device *of_dev,
622 struct device_attribute *dev_attr = NULL; 632 struct device_attribute *dev_attr = NULL;
623 struct device_node *np = of_dev->dev.of_node; 633 struct device_node *np = of_dev->dev.of_node;
624 const char *p, *sprop; 634 const char *p, *sprop;
635 const uint32_t *iprop;
625 struct resource res; 636 struct resource res;
626 char name[64]; 637 char name[64];
627 638
@@ -678,6 +689,14 @@ static int __devinit fsl_ssi_probe(struct of_device *of_dev,
678 else 689 else
679 ssi_private->cpu_dai_drv.symmetric_rates = 1; 690 ssi_private->cpu_dai_drv.symmetric_rates = 1;
680 691
692 /* Determine the FIFO depth. */
693 iprop = of_get_property(np, "fsl,fifo-depth", NULL);
694 if (iprop)
695 ssi_private->fifo_depth = *iprop;
696 else
697 /* Older 8610 DTs didn't have the fifo-depth property */
698 ssi_private->fifo_depth = 8;
699
681 /* Initialize the the device_attribute structure */ 700 /* Initialize the the device_attribute structure */
682 dev_attr = &ssi_private->dev_attr; 701 dev_attr = &ssi_private->dev_attr;
683 dev_attr->attr.name = "statistics"; 702 dev_attr->attr.name = "statistics";