blob: 8661e5b4adb1ea6c9f6128d9dafa646a1653e54e [file] [log] [blame]
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001/*
2 * soc-core.c -- ALSA SoC Audio Layer
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
Liam Girdwood0664d882006-12-18 14:39:02 +01005 * Copyright 2005 Openedhand Ltd.
6 *
Liam Girdwoodd3311242008-10-12 13:17:36 +01007 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Liam Girdwood0664d882006-12-18 14:39:02 +01008 * with code, comments and ideas from :-
9 * Richard Purdie <richard@openedhand.com>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020010 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
Frank Mandarinodb2a4162006-10-06 18:31:09 +020016 * TODO:
17 * o Add hw rules to enforce rates, etc.
18 * o More testing with other codecs/machines.
19 * o Add more codecs and platforms to ensure good API coverage.
20 * o Support TDM on PCM and I2S
21 */
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/pm.h>
28#include <linux/bitops.h>
Troy Kisky12ef1932008-10-13 17:42:14 -070029#include <linux/debugfs.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020030#include <linux/platform_device.h>
Marek Vasut474828a2009-07-22 13:01:03 +020031#include <sound/ac97_codec.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020032#include <sound/core.h>
33#include <sound/pcm.h>
34#include <sound/pcm_params.h>
35#include <sound/soc.h>
36#include <sound/soc-dapm.h>
37#include <sound/initval.h>
38
Frank Mandarinodb2a4162006-10-06 18:31:09 +020039static DEFINE_MUTEX(pcm_mutex);
Frank Mandarinodb2a4162006-10-06 18:31:09 +020040static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
41
Mark Brown384c89e2008-12-03 17:34:03 +000042#ifdef CONFIG_DEBUG_FS
43static struct dentry *debugfs_root;
44#endif
45
Mark Brownc5af3a22008-11-28 13:29:45 +000046static DEFINE_MUTEX(client_mutex);
47static LIST_HEAD(card_list);
Mark Brown91151712008-11-30 23:31:24 +000048static LIST_HEAD(dai_list);
Mark Brown12a48a8c2008-12-03 19:40:30 +000049static LIST_HEAD(platform_list);
Mark Brown0d0cf002008-12-10 14:32:45 +000050static LIST_HEAD(codec_list);
Mark Brownc5af3a22008-11-28 13:29:45 +000051
52static int snd_soc_register_card(struct snd_soc_card *card);
53static int snd_soc_unregister_card(struct snd_soc_card *card);
54
Frank Mandarinodb2a4162006-10-06 18:31:09 +020055/*
56 * This is a timeout to do a DAPM powerdown after a stream is closed().
57 * It can be used to eliminate pops between different playback streams, e.g.
58 * between two audio tracks.
59 */
60static int pmdown_time = 5000;
61module_param(pmdown_time, int, 0);
62MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
63
Liam Girdwood965ac422007-01-31 14:14:57 +010064/*
65 * This function forces any delayed work to be queued and run.
66 */
67static int run_delayed_work(struct delayed_work *dwork)
68{
69 int ret;
70
71 /* cancel any work waiting to be queued. */
72 ret = cancel_delayed_work(dwork);
73
74 /* if there was any work waiting then we run it now and
75 * wait for it's completion */
76 if (ret) {
77 schedule_delayed_work(dwork, 0);
78 flush_scheduled_work();
79 }
80 return ret;
81}
82
Mark Brown2624d5f2009-11-03 21:56:13 +000083/* codec register dump */
84static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
85{
86 int i, step = 1, count = 0;
87
88 if (!codec->reg_cache_size)
89 return 0;
90
91 if (codec->reg_cache_step)
92 step = codec->reg_cache_step;
93
94 count += sprintf(buf, "%s registers\n", codec->name);
95 for (i = 0; i < codec->reg_cache_size; i += step) {
96 if (codec->readable_register && !codec->readable_register(i))
97 continue;
98
99 count += sprintf(buf + count, "%2x: ", i);
100 if (count >= PAGE_SIZE - 1)
101 break;
102
103 if (codec->display_register)
104 count += codec->display_register(codec, buf + count,
105 PAGE_SIZE - count, i);
106 else
107 count += snprintf(buf + count, PAGE_SIZE - count,
108 "%4x", codec->read(codec, i));
109
110 if (count >= PAGE_SIZE - 1)
111 break;
112
113 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
114 if (count >= PAGE_SIZE - 1)
115 break;
116 }
117
118 /* Truncate count; min() would cause a warning */
119 if (count >= PAGE_SIZE)
120 count = PAGE_SIZE - 1;
121
122 return count;
123}
124static ssize_t codec_reg_show(struct device *dev,
125 struct device_attribute *attr, char *buf)
126{
127 struct snd_soc_device *devdata = dev_get_drvdata(dev);
128 return soc_codec_reg_show(devdata->card->codec, buf);
129}
130
131static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
132
Mark Browndbe21402010-02-12 11:37:24 +0000133static ssize_t pmdown_time_show(struct device *dev,
134 struct device_attribute *attr, char *buf)
135{
136 struct snd_soc_device *socdev = dev_get_drvdata(dev);
137 struct snd_soc_card *card = socdev->card;
138
Mark Brown6c5f1fe2010-02-17 14:30:44 +0000139 return sprintf(buf, "%ld\n", card->pmdown_time);
Mark Browndbe21402010-02-12 11:37:24 +0000140}
141
142static ssize_t pmdown_time_set(struct device *dev,
143 struct device_attribute *attr,
144 const char *buf, size_t count)
145{
146 struct snd_soc_device *socdev = dev_get_drvdata(dev);
147 struct snd_soc_card *card = socdev->card;
148
149 strict_strtol(buf, 10, &card->pmdown_time);
150
151 return count;
152}
153
154static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
155
Mark Brown2624d5f2009-11-03 21:56:13 +0000156#ifdef CONFIG_DEBUG_FS
157static int codec_reg_open_file(struct inode *inode, struct file *file)
158{
159 file->private_data = inode->i_private;
160 return 0;
161}
162
163static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
164 size_t count, loff_t *ppos)
165{
166 ssize_t ret;
167 struct snd_soc_codec *codec = file->private_data;
168 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
169 if (!buf)
170 return -ENOMEM;
171 ret = soc_codec_reg_show(codec, buf);
172 if (ret >= 0)
173 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
174 kfree(buf);
175 return ret;
176}
177
178static ssize_t codec_reg_write_file(struct file *file,
179 const char __user *user_buf, size_t count, loff_t *ppos)
180{
181 char buf[32];
182 int buf_size;
183 char *start = buf;
184 unsigned long reg, value;
185 int step = 1;
186 struct snd_soc_codec *codec = file->private_data;
187
188 buf_size = min(count, (sizeof(buf)-1));
189 if (copy_from_user(buf, user_buf, buf_size))
190 return -EFAULT;
191 buf[buf_size] = 0;
192
193 if (codec->reg_cache_step)
194 step = codec->reg_cache_step;
195
196 while (*start == ' ')
197 start++;
198 reg = simple_strtoul(start, &start, 16);
199 if ((reg >= codec->reg_cache_size) || (reg % step))
200 return -EINVAL;
201 while (*start == ' ')
202 start++;
203 if (strict_strtoul(start, 16, &value))
204 return -EINVAL;
205 codec->write(codec, reg, value);
206 return buf_size;
207}
208
209static const struct file_operations codec_reg_fops = {
210 .open = codec_reg_open_file,
211 .read = codec_reg_read_file,
212 .write = codec_reg_write_file,
213};
214
215static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
216{
217 char codec_root[128];
218
219 if (codec->dev)
220 snprintf(codec_root, sizeof(codec_root),
221 "%s.%s", codec->name, dev_name(codec->dev));
222 else
223 snprintf(codec_root, sizeof(codec_root),
224 "%s", codec->name);
225
226 codec->debugfs_codec_root = debugfs_create_dir(codec_root,
227 debugfs_root);
228 if (!codec->debugfs_codec_root) {
229 printk(KERN_WARNING
230 "ASoC: Failed to create codec debugfs directory\n");
231 return;
232 }
233
234 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
235 codec->debugfs_codec_root,
236 codec, &codec_reg_fops);
237 if (!codec->debugfs_reg)
238 printk(KERN_WARNING
239 "ASoC: Failed to create codec register debugfs file\n");
240
241 codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744,
242 codec->debugfs_codec_root,
243 &codec->pop_time);
244 if (!codec->debugfs_pop_time)
245 printk(KERN_WARNING
246 "Failed to create pop time debugfs file\n");
247
248 codec->debugfs_dapm = debugfs_create_dir("dapm",
249 codec->debugfs_codec_root);
250 if (!codec->debugfs_dapm)
251 printk(KERN_WARNING
252 "Failed to create DAPM debugfs directory\n");
253
254 snd_soc_dapm_debugfs_init(codec);
255}
256
257static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
258{
259 debugfs_remove_recursive(codec->debugfs_codec_root);
260}
261
262#else
263
264static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
265{
266}
267
268static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
269{
270}
271#endif
272
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200273#ifdef CONFIG_SND_SOC_AC97_BUS
274/* unregister ac97 codec */
275static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
276{
277 if (codec->ac97->dev.bus)
278 device_unregister(&codec->ac97->dev);
279 return 0;
280}
281
282/* stop no dev release warning */
283static void soc_ac97_device_release(struct device *dev){}
284
285/* register ac97 codec to bus */
286static int soc_ac97_dev_register(struct snd_soc_codec *codec)
287{
288 int err;
289
290 codec->ac97->dev.bus = &ac97_bus_type;
Mark Brown4ac5c612009-04-01 19:35:01 +0100291 codec->ac97->dev.parent = codec->card->dev;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200292 codec->ac97->dev.release = soc_ac97_device_release;
293
Kay Sieversbb072bf2008-11-02 03:50:35 +0100294 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
295 codec->card->number, 0, codec->name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200296 err = device_register(&codec->ac97->dev);
297 if (err < 0) {
298 snd_printk(KERN_ERR "Can't register ac97 bus\n");
299 codec->ac97->dev.bus = NULL;
300 return err;
301 }
302 return 0;
303}
304#endif
305
Mark Brown06f409d2009-04-07 18:10:13 +0100306static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
307{
308 struct snd_soc_pcm_runtime *rtd = substream->private_data;
309 struct snd_soc_device *socdev = rtd->socdev;
310 struct snd_soc_card *card = socdev->card;
311 struct snd_soc_dai_link *machine = rtd->dai;
312 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
313 struct snd_soc_dai *codec_dai = machine->codec_dai;
314 int ret;
315
316 if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates ||
317 machine->symmetric_rates) {
Peter Ujfalusi50831452010-03-03 15:08:04 +0200318 dev_dbg(card->dev, "Symmetry forces %dHz rate\n",
Mark Brown06f409d2009-04-07 18:10:13 +0100319 machine->rate);
320
321 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
322 SNDRV_PCM_HW_PARAM_RATE,
323 machine->rate,
324 machine->rate);
325 if (ret < 0) {
326 dev_err(card->dev,
327 "Unable to apply rate symmetry constraint: %d\n", ret);
328 return ret;
329 }
330 }
331
332 return 0;
333}
334
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200335/*
336 * Called by ALSA when a PCM substream is opened, the runtime->hw record is
337 * then initialized and any private data can be allocated. This also calls
338 * startup for the cpu DAI, platform, machine and codec DAI.
339 */
340static int soc_pcm_open(struct snd_pcm_substream *substream)
341{
342 struct snd_soc_pcm_runtime *rtd = substream->private_data;
343 struct snd_soc_device *socdev = rtd->socdev;
Mark Brown87689d52008-12-02 16:01:14 +0000344 struct snd_soc_card *card = socdev->card;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200345 struct snd_pcm_runtime *runtime = substream->runtime;
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100346 struct snd_soc_dai_link *machine = rtd->dai;
Mark Brown87689d52008-12-02 16:01:14 +0000347 struct snd_soc_platform *platform = card->platform;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100348 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
349 struct snd_soc_dai *codec_dai = machine->codec_dai;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200350 int ret = 0;
351
352 mutex_lock(&pcm_mutex);
353
354 /* startup the audio subsystem */
Eric Miao6335d052009-03-03 09:41:00 +0800355 if (cpu_dai->ops->startup) {
356 ret = cpu_dai->ops->startup(substream, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200357 if (ret < 0) {
358 printk(KERN_ERR "asoc: can't open interface %s\n",
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100359 cpu_dai->name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200360 goto out;
361 }
362 }
363
364 if (platform->pcm_ops->open) {
365 ret = platform->pcm_ops->open(substream);
366 if (ret < 0) {
367 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
368 goto platform_err;
369 }
370 }
371
Eric Miao6335d052009-03-03 09:41:00 +0800372 if (codec_dai->ops->startup) {
373 ret = codec_dai->ops->startup(substream, codec_dai);
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100374 if (ret < 0) {
375 printk(KERN_ERR "asoc: can't open codec %s\n",
376 codec_dai->name);
377 goto codec_dai_err;
378 }
379 }
380
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200381 if (machine->ops && machine->ops->startup) {
382 ret = machine->ops->startup(substream);
383 if (ret < 0) {
384 printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
385 goto machine_err;
386 }
387 }
388
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200389 /* Check that the codec and cpu DAI's are compatible */
390 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
391 runtime->hw.rate_min =
Mark Brown3ff3f642008-05-19 12:32:25 +0200392 max(codec_dai->playback.rate_min,
393 cpu_dai->playback.rate_min);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200394 runtime->hw.rate_max =
Mark Brown3ff3f642008-05-19 12:32:25 +0200395 min(codec_dai->playback.rate_max,
396 cpu_dai->playback.rate_max);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200397 runtime->hw.channels_min =
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100398 max(codec_dai->playback.channels_min,
399 cpu_dai->playback.channels_min);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200400 runtime->hw.channels_max =
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100401 min(codec_dai->playback.channels_max,
402 cpu_dai->playback.channels_max);
403 runtime->hw.formats =
404 codec_dai->playback.formats & cpu_dai->playback.formats;
405 runtime->hw.rates =
406 codec_dai->playback.rates & cpu_dai->playback.rates;
Jassi Brard9ad6292010-03-12 13:38:52 +0900407 if (codec_dai->playback.rates
408 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
409 runtime->hw.rates |= cpu_dai->playback.rates;
410 if (cpu_dai->playback.rates
411 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
412 runtime->hw.rates |= codec_dai->playback.rates;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200413 } else {
414 runtime->hw.rate_min =
Mark Brown3ff3f642008-05-19 12:32:25 +0200415 max(codec_dai->capture.rate_min,
416 cpu_dai->capture.rate_min);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200417 runtime->hw.rate_max =
Mark Brown3ff3f642008-05-19 12:32:25 +0200418 min(codec_dai->capture.rate_max,
419 cpu_dai->capture.rate_max);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200420 runtime->hw.channels_min =
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100421 max(codec_dai->capture.channels_min,
422 cpu_dai->capture.channels_min);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200423 runtime->hw.channels_max =
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100424 min(codec_dai->capture.channels_max,
425 cpu_dai->capture.channels_max);
426 runtime->hw.formats =
427 codec_dai->capture.formats & cpu_dai->capture.formats;
428 runtime->hw.rates =
429 codec_dai->capture.rates & cpu_dai->capture.rates;
Jassi Brard9ad6292010-03-12 13:38:52 +0900430 if (codec_dai->capture.rates
431 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
432 runtime->hw.rates |= cpu_dai->capture.rates;
433 if (cpu_dai->capture.rates
434 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
435 runtime->hw.rates |= codec_dai->capture.rates;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200436 }
437
438 snd_pcm_limit_hw_rates(runtime);
439 if (!runtime->hw.rates) {
440 printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100441 codec_dai->name, cpu_dai->name);
Jassi Brarbb1c0472010-02-25 11:24:53 +0900442 goto config_err;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200443 }
444 if (!runtime->hw.formats) {
445 printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100446 codec_dai->name, cpu_dai->name);
Jassi Brarbb1c0472010-02-25 11:24:53 +0900447 goto config_err;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200448 }
449 if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
450 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100451 codec_dai->name, cpu_dai->name);
Jassi Brarbb1c0472010-02-25 11:24:53 +0900452 goto config_err;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200453 }
454
Mark Brown06f409d2009-04-07 18:10:13 +0100455 /* Symmetry only applies if we've already got an active stream. */
456 if (cpu_dai->active || codec_dai->active) {
457 ret = soc_pcm_apply_symmetry(substream);
458 if (ret != 0)
Jassi Brarbb1c0472010-02-25 11:24:53 +0900459 goto config_err;
Mark Brown06f409d2009-04-07 18:10:13 +0100460 }
461
Mark Brownf24368c2008-10-21 21:45:08 +0100462 pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
463 pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
464 pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
465 runtime->hw.channels_max);
466 pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
467 runtime->hw.rate_max);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200468
Jassi Brar14dc5732010-02-26 09:12:32 +0900469 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
470 cpu_dai->playback.active++;
471 codec_dai->playback.active++;
472 } else {
473 cpu_dai->capture.active++;
474 codec_dai->capture.active++;
475 }
476 cpu_dai->active++;
477 codec_dai->active++;
Mark Brown6627a652009-01-23 22:55:23 +0000478 card->codec->active++;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200479 mutex_unlock(&pcm_mutex);
480 return 0;
481
Jassi Brarbb1c0472010-02-25 11:24:53 +0900482config_err:
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200483 if (machine->ops && machine->ops->shutdown)
484 machine->ops->shutdown(substream);
485
Jassi Brarbb1c0472010-02-25 11:24:53 +0900486machine_err:
487 if (codec_dai->ops->shutdown)
488 codec_dai->ops->shutdown(substream, codec_dai);
489
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100490codec_dai_err:
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200491 if (platform->pcm_ops->close)
492 platform->pcm_ops->close(substream);
493
494platform_err:
Eric Miao6335d052009-03-03 09:41:00 +0800495 if (cpu_dai->ops->shutdown)
496 cpu_dai->ops->shutdown(substream, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200497out:
498 mutex_unlock(&pcm_mutex);
499 return ret;
500}
501
502/*
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200503 * Power down the audio subsystem pmdown_time msecs after close is called.
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200504 * This is to ensure there are no pops or clicks in between any music tracks
505 * due to DAPM power cycling.
506 */
Andrew Morton4484bb22006-12-15 09:30:07 +0100507static void close_delayed_work(struct work_struct *work)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200508{
Mark Brown63084192008-12-02 15:08:03 +0000509 struct snd_soc_card *card = container_of(work, struct snd_soc_card,
510 delayed_work.work);
Mark Brown6627a652009-01-23 22:55:23 +0000511 struct snd_soc_codec *codec = card->codec;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100512 struct snd_soc_dai *codec_dai;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200513 int i;
514
515 mutex_lock(&pcm_mutex);
Mark Brown3ff3f642008-05-19 12:32:25 +0200516 for (i = 0; i < codec->num_dai; i++) {
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200517 codec_dai = &codec->dai[i];
518
Mark Brownf24368c2008-10-21 21:45:08 +0100519 pr_debug("pop wq checking: %s status: %s waiting: %s\n",
520 codec_dai->playback.stream_name,
521 codec_dai->playback.active ? "active" : "inactive",
522 codec_dai->pop_wait ? "yes" : "no");
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200523
524 /* are we waiting on this codec DAI stream */
525 if (codec_dai->pop_wait == 1) {
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200526 codec_dai->pop_wait = 0;
Liam Girdwood0b4d2212008-01-10 14:36:20 +0100527 snd_soc_dapm_stream_event(codec,
528 codec_dai->playback.stream_name,
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200529 SND_SOC_DAPM_STREAM_STOP);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200530 }
531 }
532 mutex_unlock(&pcm_mutex);
533}
534
535/*
536 * Called by ALSA when a PCM substream is closed. Private data can be
537 * freed here. The cpu DAI, codec DAI, machine and platform are also
538 * shutdown.
539 */
540static int soc_codec_close(struct snd_pcm_substream *substream)
541{
542 struct snd_soc_pcm_runtime *rtd = substream->private_data;
543 struct snd_soc_device *socdev = rtd->socdev;
Mark Brown63084192008-12-02 15:08:03 +0000544 struct snd_soc_card *card = socdev->card;
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100545 struct snd_soc_dai_link *machine = rtd->dai;
Mark Brown87689d52008-12-02 16:01:14 +0000546 struct snd_soc_platform *platform = card->platform;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100547 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
548 struct snd_soc_dai *codec_dai = machine->codec_dai;
Mark Brown6627a652009-01-23 22:55:23 +0000549 struct snd_soc_codec *codec = card->codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200550
551 mutex_lock(&pcm_mutex);
552
Jassi Brar14dc5732010-02-26 09:12:32 +0900553 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
554 cpu_dai->playback.active--;
555 codec_dai->playback.active--;
556 } else {
557 cpu_dai->capture.active--;
558 codec_dai->capture.active--;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200559 }
Jassi Brar14dc5732010-02-26 09:12:32 +0900560
561 cpu_dai->active--;
562 codec_dai->active--;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200563 codec->active--;
564
Mark Brown6010b2d2008-09-06 18:33:24 +0100565 /* Muting the DAC suppresses artifacts caused during digital
566 * shutdown, for example from stopping clocks.
567 */
568 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
569 snd_soc_dai_digital_mute(codec_dai, 1);
570
Eric Miao6335d052009-03-03 09:41:00 +0800571 if (cpu_dai->ops->shutdown)
572 cpu_dai->ops->shutdown(substream, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200573
Eric Miao6335d052009-03-03 09:41:00 +0800574 if (codec_dai->ops->shutdown)
575 codec_dai->ops->shutdown(substream, codec_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200576
577 if (machine->ops && machine->ops->shutdown)
578 machine->ops->shutdown(substream);
579
580 if (platform->pcm_ops->close)
581 platform->pcm_ops->close(substream);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200582
583 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
584 /* start delayed pop wq here for playback streams */
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100585 codec_dai->pop_wait = 1;
Mark Brown63084192008-12-02 15:08:03 +0000586 schedule_delayed_work(&card->delayed_work,
Mark Brown96dd3622010-02-12 11:05:44 +0000587 msecs_to_jiffies(card->pmdown_time));
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200588 } else {
589 /* capture streams can be powered down now */
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100590 snd_soc_dapm_stream_event(codec,
Liam Girdwood0b4d2212008-01-10 14:36:20 +0100591 codec_dai->capture.stream_name,
592 SND_SOC_DAPM_STREAM_STOP);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200593 }
594
595 mutex_unlock(&pcm_mutex);
596 return 0;
597}
598
599/*
600 * Called by ALSA when the PCM substream is prepared, can set format, sample
601 * rate, etc. This function is non atomic and can be called multiple times,
602 * it can refer to the runtime info.
603 */
604static int soc_pcm_prepare(struct snd_pcm_substream *substream)
605{
606 struct snd_soc_pcm_runtime *rtd = substream->private_data;
607 struct snd_soc_device *socdev = rtd->socdev;
Mark Brown63084192008-12-02 15:08:03 +0000608 struct snd_soc_card *card = socdev->card;
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100609 struct snd_soc_dai_link *machine = rtd->dai;
Mark Brown87689d52008-12-02 16:01:14 +0000610 struct snd_soc_platform *platform = card->platform;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100611 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
612 struct snd_soc_dai *codec_dai = machine->codec_dai;
Mark Brown6627a652009-01-23 22:55:23 +0000613 struct snd_soc_codec *codec = card->codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200614 int ret = 0;
615
616 mutex_lock(&pcm_mutex);
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100617
618 if (machine->ops && machine->ops->prepare) {
619 ret = machine->ops->prepare(substream);
620 if (ret < 0) {
621 printk(KERN_ERR "asoc: machine prepare error\n");
622 goto out;
623 }
624 }
625
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200626 if (platform->pcm_ops->prepare) {
627 ret = platform->pcm_ops->prepare(substream);
Liam Girdwooda71a4682006-10-19 20:35:56 +0200628 if (ret < 0) {
629 printk(KERN_ERR "asoc: platform prepare error\n");
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200630 goto out;
Liam Girdwooda71a4682006-10-19 20:35:56 +0200631 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200632 }
633
Eric Miao6335d052009-03-03 09:41:00 +0800634 if (codec_dai->ops->prepare) {
635 ret = codec_dai->ops->prepare(substream, codec_dai);
Liam Girdwooda71a4682006-10-19 20:35:56 +0200636 if (ret < 0) {
637 printk(KERN_ERR "asoc: codec DAI prepare error\n");
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200638 goto out;
Liam Girdwooda71a4682006-10-19 20:35:56 +0200639 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200640 }
641
Eric Miao6335d052009-03-03 09:41:00 +0800642 if (cpu_dai->ops->prepare) {
643 ret = cpu_dai->ops->prepare(substream, cpu_dai);
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100644 if (ret < 0) {
645 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
646 goto out;
647 }
648 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200649
Mark Brownd45f6212008-10-14 13:58:36 +0100650 /* cancel any delayed stream shutdown that is pending */
651 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
652 codec_dai->pop_wait) {
653 codec_dai->pop_wait = 0;
Mark Brown63084192008-12-02 15:08:03 +0000654 cancel_delayed_work(&card->delayed_work);
Mark Brownd45f6212008-10-14 13:58:36 +0100655 }
656
Mark Brown452c5ea2009-05-17 21:41:23 +0100657 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
658 snd_soc_dapm_stream_event(codec,
659 codec_dai->playback.stream_name,
660 SND_SOC_DAPM_STREAM_START);
661 else
662 snd_soc_dapm_stream_event(codec,
663 codec_dai->capture.stream_name,
664 SND_SOC_DAPM_STREAM_START);
Mark Brownd45f6212008-10-14 13:58:36 +0100665
Mark Brown452c5ea2009-05-17 21:41:23 +0100666 snd_soc_dai_digital_mute(codec_dai, 0);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200667
668out:
669 mutex_unlock(&pcm_mutex);
670 return ret;
671}
672
673/*
674 * Called by ALSA when the hardware params are set by application. This
675 * function can also be called multiple times and can allocate buffers
676 * (using snd_pcm_lib_* ). It's non-atomic.
677 */
678static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
679 struct snd_pcm_hw_params *params)
680{
681 struct snd_soc_pcm_runtime *rtd = substream->private_data;
682 struct snd_soc_device *socdev = rtd->socdev;
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100683 struct snd_soc_dai_link *machine = rtd->dai;
Mark Brown87689d52008-12-02 16:01:14 +0000684 struct snd_soc_card *card = socdev->card;
685 struct snd_soc_platform *platform = card->platform;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100686 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
687 struct snd_soc_dai *codec_dai = machine->codec_dai;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200688 int ret = 0;
689
690 mutex_lock(&pcm_mutex);
691
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100692 if (machine->ops && machine->ops->hw_params) {
693 ret = machine->ops->hw_params(substream, params);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200694 if (ret < 0) {
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100695 printk(KERN_ERR "asoc: machine hw_params failed\n");
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200696 goto out;
697 }
698 }
699
Eric Miao6335d052009-03-03 09:41:00 +0800700 if (codec_dai->ops->hw_params) {
701 ret = codec_dai->ops->hw_params(substream, params, codec_dai);
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100702 if (ret < 0) {
703 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
704 codec_dai->name);
705 goto codec_err;
706 }
707 }
708
Eric Miao6335d052009-03-03 09:41:00 +0800709 if (cpu_dai->ops->hw_params) {
710 ret = cpu_dai->ops->hw_params(substream, params, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200711 if (ret < 0) {
Mark Brown3ff3f642008-05-19 12:32:25 +0200712 printk(KERN_ERR "asoc: interface %s hw params failed\n",
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100713 cpu_dai->name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200714 goto interface_err;
715 }
716 }
717
718 if (platform->pcm_ops->hw_params) {
719 ret = platform->pcm_ops->hw_params(substream, params);
720 if (ret < 0) {
Mark Brown3ff3f642008-05-19 12:32:25 +0200721 printk(KERN_ERR "asoc: platform %s hw params failed\n",
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200722 platform->name);
723 goto platform_err;
724 }
725 }
726
Mark Brown06f409d2009-04-07 18:10:13 +0100727 machine->rate = params_rate(params);
728
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200729out:
730 mutex_unlock(&pcm_mutex);
731 return ret;
732
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200733platform_err:
Eric Miao6335d052009-03-03 09:41:00 +0800734 if (cpu_dai->ops->hw_free)
735 cpu_dai->ops->hw_free(substream, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200736
737interface_err:
Eric Miao6335d052009-03-03 09:41:00 +0800738 if (codec_dai->ops->hw_free)
739 codec_dai->ops->hw_free(substream, codec_dai);
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100740
741codec_err:
Mark Brown3ff3f642008-05-19 12:32:25 +0200742 if (machine->ops && machine->ops->hw_free)
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100743 machine->ops->hw_free(substream);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200744
745 mutex_unlock(&pcm_mutex);
746 return ret;
747}
748
749/*
750 * Free's resources allocated by hw_params, can be called multiple times
751 */
752static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
753{
754 struct snd_soc_pcm_runtime *rtd = substream->private_data;
755 struct snd_soc_device *socdev = rtd->socdev;
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100756 struct snd_soc_dai_link *machine = rtd->dai;
Mark Brown87689d52008-12-02 16:01:14 +0000757 struct snd_soc_card *card = socdev->card;
758 struct snd_soc_platform *platform = card->platform;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100759 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
760 struct snd_soc_dai *codec_dai = machine->codec_dai;
Mark Brown6627a652009-01-23 22:55:23 +0000761 struct snd_soc_codec *codec = card->codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200762
763 mutex_lock(&pcm_mutex);
764
765 /* apply codec digital mute */
Liam Girdwood8c6529d2008-07-08 13:19:13 +0100766 if (!codec->active)
767 snd_soc_dai_digital_mute(codec_dai, 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200768
769 /* free any machine hw params */
770 if (machine->ops && machine->ops->hw_free)
771 machine->ops->hw_free(substream);
772
773 /* free any DMA resources */
774 if (platform->pcm_ops->hw_free)
775 platform->pcm_ops->hw_free(substream);
776
777 /* now free hw params for the DAI's */
Eric Miao6335d052009-03-03 09:41:00 +0800778 if (codec_dai->ops->hw_free)
779 codec_dai->ops->hw_free(substream, codec_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200780
Eric Miao6335d052009-03-03 09:41:00 +0800781 if (cpu_dai->ops->hw_free)
782 cpu_dai->ops->hw_free(substream, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200783
784 mutex_unlock(&pcm_mutex);
785 return 0;
786}
787
788static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
789{
790 struct snd_soc_pcm_runtime *rtd = substream->private_data;
791 struct snd_soc_device *socdev = rtd->socdev;
Mark Brown87689d52008-12-02 16:01:14 +0000792 struct snd_soc_card *card= socdev->card;
Liam Girdwoodcb666e52007-02-02 17:13:49 +0100793 struct snd_soc_dai_link *machine = rtd->dai;
Mark Brown87689d52008-12-02 16:01:14 +0000794 struct snd_soc_platform *platform = card->platform;
Liam Girdwood3c4b2662008-07-07 16:07:17 +0100795 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
796 struct snd_soc_dai *codec_dai = machine->codec_dai;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200797 int ret;
798
Eric Miao6335d052009-03-03 09:41:00 +0800799 if (codec_dai->ops->trigger) {
800 ret = codec_dai->ops->trigger(substream, cmd, codec_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200801 if (ret < 0)
802 return ret;
803 }
804
805 if (platform->pcm_ops->trigger) {
806 ret = platform->pcm_ops->trigger(substream, cmd);
807 if (ret < 0)
808 return ret;
809 }
810
Eric Miao6335d052009-03-03 09:41:00 +0800811 if (cpu_dai->ops->trigger) {
812 ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200813 if (ret < 0)
814 return ret;
815 }
816 return 0;
817}
818
Peter Ujfalusi377b6f62010-03-03 15:08:06 +0200819/*
820 * soc level wrapper for pointer callback
Peter Ujfalusi258020d2010-03-03 15:08:07 +0200821 * If cpu_dai, codec_dai, platform driver has the delay callback, than
822 * the runtime->delay will be updated accordingly.
Peter Ujfalusi377b6f62010-03-03 15:08:06 +0200823 */
824static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
825{
826 struct snd_soc_pcm_runtime *rtd = substream->private_data;
827 struct snd_soc_device *socdev = rtd->socdev;
828 struct snd_soc_card *card = socdev->card;
829 struct snd_soc_platform *platform = card->platform;
Peter Ujfalusi258020d2010-03-03 15:08:07 +0200830 struct snd_soc_dai_link *machine = rtd->dai;
831 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
832 struct snd_soc_dai *codec_dai = machine->codec_dai;
833 struct snd_pcm_runtime *runtime = substream->runtime;
Peter Ujfalusi377b6f62010-03-03 15:08:06 +0200834 snd_pcm_uframes_t offset = 0;
Peter Ujfalusi258020d2010-03-03 15:08:07 +0200835 snd_pcm_sframes_t delay = 0;
Peter Ujfalusi377b6f62010-03-03 15:08:06 +0200836
837 if (platform->pcm_ops->pointer)
838 offset = platform->pcm_ops->pointer(substream);
839
Peter Ujfalusi258020d2010-03-03 15:08:07 +0200840 if (cpu_dai->ops->delay)
841 delay += cpu_dai->ops->delay(substream, cpu_dai);
842
843 if (codec_dai->ops->delay)
844 delay += codec_dai->ops->delay(substream, codec_dai);
845
846 if (platform->delay)
847 delay += platform->delay(substream, codec_dai);
848
849 runtime->delay = delay;
850
Peter Ujfalusi377b6f62010-03-03 15:08:06 +0200851 return offset;
852}
853
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200854/* ASoC PCM operations */
855static struct snd_pcm_ops soc_pcm_ops = {
856 .open = soc_pcm_open,
857 .close = soc_codec_close,
858 .hw_params = soc_pcm_hw_params,
859 .hw_free = soc_pcm_hw_free,
860 .prepare = soc_pcm_prepare,
861 .trigger = soc_pcm_trigger,
Peter Ujfalusi377b6f62010-03-03 15:08:06 +0200862 .pointer = soc_pcm_pointer,
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200863};
864
865#ifdef CONFIG_PM
866/* powers down audio subsystem for suspend */
Mark Brown416356f2009-06-30 19:05:15 +0100867static int soc_suspend(struct device *dev)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200868{
Mark Brown416356f2009-06-30 19:05:15 +0100869 struct platform_device *pdev = to_platform_device(dev);
Mark Brown3ff3f642008-05-19 12:32:25 +0200870 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
Mark Brown87506542008-11-18 20:50:34 +0000871 struct snd_soc_card *card = socdev->card;
Mark Brown87689d52008-12-02 16:01:14 +0000872 struct snd_soc_platform *platform = card->platform;
Mark Brown3ff3f642008-05-19 12:32:25 +0200873 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
Mark Brown6627a652009-01-23 22:55:23 +0000874 struct snd_soc_codec *codec = card->codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200875 int i;
876
Daniel Macke3509ff2009-06-03 17:44:49 +0200877 /* If the initialization of this soc device failed, there is no codec
878 * associated with it. Just bail out in this case.
879 */
880 if (!codec)
881 return 0;
882
Andy Green6ed25972008-06-13 16:24:05 +0100883 /* Due to the resume being scheduled into a workqueue we could
884 * suspend before that's finished - wait for it to complete.
885 */
886 snd_power_lock(codec->card);
887 snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
888 snd_power_unlock(codec->card);
889
890 /* we're going to block userspace touching us until resume completes */
891 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
892
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200893 /* mute any active DAC's */
Mark Browndee89c42008-11-18 22:11:38 +0000894 for (i = 0; i < card->num_links; i++) {
895 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
Eric Miao6335d052009-03-03 09:41:00 +0800896 if (dai->ops->digital_mute && dai->playback.active)
897 dai->ops->digital_mute(dai, 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200898 }
899
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100900 /* suspend all pcms */
Mark Brown87506542008-11-18 20:50:34 +0000901 for (i = 0; i < card->num_links; i++)
902 snd_pcm_suspend_all(card->dai_link[i].pcm);
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100903
Mark Brown87506542008-11-18 20:50:34 +0000904 if (card->suspend_pre)
Mark Brown416356f2009-06-30 19:05:15 +0100905 card->suspend_pre(pdev, PMSG_SUSPEND);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200906
Mark Brown87506542008-11-18 20:50:34 +0000907 for (i = 0; i < card->num_links; i++) {
908 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
Mark Brown3ba9e10a2008-11-24 18:01:05 +0000909 if (cpu_dai->suspend && !cpu_dai->ac97_control)
Mark Browndc7d7b82008-12-03 18:21:52 +0000910 cpu_dai->suspend(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200911 if (platform->suspend)
jassi brard273ebe2010-02-22 15:58:04 +0900912 platform->suspend(&card->dai_link[i]);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200913 }
914
915 /* close any waiting streams and save state */
Mark Brown63084192008-12-02 15:08:03 +0000916 run_delayed_work(&card->delayed_work);
Mark Brown0be98982008-05-19 12:31:28 +0200917 codec->suspend_bias_level = codec->bias_level;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200918
Mark Brown3ff3f642008-05-19 12:32:25 +0200919 for (i = 0; i < codec->num_dai; i++) {
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200920 char *stream = codec->dai[i].playback.stream_name;
921 if (stream != NULL)
922 snd_soc_dapm_stream_event(codec, stream,
923 SND_SOC_DAPM_STREAM_SUSPEND);
924 stream = codec->dai[i].capture.stream_name;
925 if (stream != NULL)
926 snd_soc_dapm_stream_event(codec, stream,
927 SND_SOC_DAPM_STREAM_SUSPEND);
928 }
929
Mark Brown1547aba2010-05-07 21:11:40 +0100930 /* If there are paths active then the CODEC will be held with
931 * bias _ON and should not be suspended. */
932 if (codec_dev->suspend) {
933 switch (codec->bias_level) {
934 case SND_SOC_BIAS_STANDBY:
935 case SND_SOC_BIAS_OFF:
936 codec_dev->suspend(pdev, PMSG_SUSPEND);
937 break;
938 default:
939 dev_dbg(socdev->dev, "CODEC is on over suspend\n");
940 break;
941 }
942 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200943
Mark Brown87506542008-11-18 20:50:34 +0000944 for (i = 0; i < card->num_links; i++) {
945 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
Mark Brown3ba9e10a2008-11-24 18:01:05 +0000946 if (cpu_dai->suspend && cpu_dai->ac97_control)
Mark Browndc7d7b82008-12-03 18:21:52 +0000947 cpu_dai->suspend(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200948 }
949
Mark Brown87506542008-11-18 20:50:34 +0000950 if (card->suspend_post)
Mark Brown416356f2009-06-30 19:05:15 +0100951 card->suspend_post(pdev, PMSG_SUSPEND);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200952
953 return 0;
954}
955
Andy Green6ed25972008-06-13 16:24:05 +0100956/* deferred resume work, so resume can complete before we finished
957 * setting our codec back up, which can be very slow on I2C
958 */
959static void soc_resume_deferred(struct work_struct *work)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200960{
Mark Brown63084192008-12-02 15:08:03 +0000961 struct snd_soc_card *card = container_of(work,
962 struct snd_soc_card,
963 deferred_resume_work);
964 struct snd_soc_device *socdev = card->socdev;
Mark Brown87689d52008-12-02 16:01:14 +0000965 struct snd_soc_platform *platform = card->platform;
Mark Brown3ff3f642008-05-19 12:32:25 +0200966 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
Mark Brown6627a652009-01-23 22:55:23 +0000967 struct snd_soc_codec *codec = card->codec;
Andy Green6ed25972008-06-13 16:24:05 +0100968 struct platform_device *pdev = to_platform_device(socdev->dev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200969 int i;
970
Andy Green6ed25972008-06-13 16:24:05 +0100971 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
972 * so userspace apps are blocked from touching us
973 */
974
Mark Brownfde22f22008-11-24 18:08:18 +0000975 dev_dbg(socdev->dev, "starting resume work\n");
Andy Green6ed25972008-06-13 16:24:05 +0100976
Mark Brown9949788b2010-05-07 20:24:05 +0100977 /* Bring us up into D2 so that DAPM starts enabling things */
978 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D2);
979
Mark Brown87506542008-11-18 20:50:34 +0000980 if (card->resume_pre)
981 card->resume_pre(pdev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200982
Mark Brown87506542008-11-18 20:50:34 +0000983 for (i = 0; i < card->num_links; i++) {
984 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
Mark Brown3ba9e10a2008-11-24 18:01:05 +0000985 if (cpu_dai->resume && cpu_dai->ac97_control)
Mark Browndc7d7b82008-12-03 18:21:52 +0000986 cpu_dai->resume(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200987 }
988
Mark Brown1547aba2010-05-07 21:11:40 +0100989 /* If the CODEC was idle over suspend then it will have been
990 * left with bias OFF or STANDBY and suspended so we must now
991 * resume. Otherwise the suspend was suppressed.
992 */
993 if (codec_dev->resume) {
994 switch (codec->bias_level) {
995 case SND_SOC_BIAS_STANDBY:
996 case SND_SOC_BIAS_OFF:
997 codec_dev->resume(pdev);
998 break;
999 default:
1000 dev_dbg(socdev->dev, "CODEC was on over suspend\n");
1001 break;
1002 }
1003 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001004
Mark Brown3ff3f642008-05-19 12:32:25 +02001005 for (i = 0; i < codec->num_dai; i++) {
1006 char *stream = codec->dai[i].playback.stream_name;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001007 if (stream != NULL)
1008 snd_soc_dapm_stream_event(codec, stream,
1009 SND_SOC_DAPM_STREAM_RESUME);
1010 stream = codec->dai[i].capture.stream_name;
1011 if (stream != NULL)
1012 snd_soc_dapm_stream_event(codec, stream,
1013 SND_SOC_DAPM_STREAM_RESUME);
1014 }
1015
Mark Brown3ff3f642008-05-19 12:32:25 +02001016 /* unmute any active DACs */
Mark Browndee89c42008-11-18 22:11:38 +00001017 for (i = 0; i < card->num_links; i++) {
1018 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
Eric Miao6335d052009-03-03 09:41:00 +08001019 if (dai->ops->digital_mute && dai->playback.active)
1020 dai->ops->digital_mute(dai, 0);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001021 }
1022
Mark Brown87506542008-11-18 20:50:34 +00001023 for (i = 0; i < card->num_links; i++) {
1024 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
Mark Brown3ba9e10a2008-11-24 18:01:05 +00001025 if (cpu_dai->resume && !cpu_dai->ac97_control)
Mark Browndc7d7b82008-12-03 18:21:52 +00001026 cpu_dai->resume(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001027 if (platform->resume)
jassi brard273ebe2010-02-22 15:58:04 +09001028 platform->resume(&card->dai_link[i]);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001029 }
1030
Mark Brown87506542008-11-18 20:50:34 +00001031 if (card->resume_post)
1032 card->resume_post(pdev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001033
Mark Brownfde22f22008-11-24 18:08:18 +00001034 dev_dbg(socdev->dev, "resume work completed\n");
Andy Green6ed25972008-06-13 16:24:05 +01001035
1036 /* userspace can access us now we are back as we were before */
1037 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
1038}
1039
1040/* powers up audio subsystem after a suspend */
Mark Brown416356f2009-06-30 19:05:15 +01001041static int soc_resume(struct device *dev)
Andy Green6ed25972008-06-13 16:24:05 +01001042{
Mark Brown416356f2009-06-30 19:05:15 +01001043 struct platform_device *pdev = to_platform_device(dev);
Andy Green6ed25972008-06-13 16:24:05 +01001044 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
Mark Brown63084192008-12-02 15:08:03 +00001045 struct snd_soc_card *card = socdev->card;
Mark Brown64ab9ba2009-03-31 11:27:03 +01001046 struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai;
Andy Green6ed25972008-06-13 16:24:05 +01001047
Peter Ujfalusib9dd94a2010-02-22 13:27:13 +02001048 /* If the initialization of this soc device failed, there is no codec
1049 * associated with it. Just bail out in this case.
1050 */
1051 if (!card->codec)
1052 return 0;
1053
Mark Brown64ab9ba2009-03-31 11:27:03 +01001054 /* AC97 devices might have other drivers hanging off them so
1055 * need to resume immediately. Other drivers don't have that
1056 * problem and may take a substantial amount of time to resume
1057 * due to I/O costs and anti-pop so handle them out of line.
1058 */
1059 if (cpu_dai->ac97_control) {
1060 dev_dbg(socdev->dev, "Resuming AC97 immediately\n");
1061 soc_resume_deferred(&card->deferred_resume_work);
1062 } else {
1063 dev_dbg(socdev->dev, "Scheduling resume work\n");
1064 if (!schedule_work(&card->deferred_resume_work))
1065 dev_err(socdev->dev, "resume work item may be lost\n");
1066 }
Andy Green6ed25972008-06-13 16:24:05 +01001067
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001068 return 0;
1069}
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001070#else
1071#define soc_suspend NULL
1072#define soc_resume NULL
1073#endif
1074
Barry Song02a06d32009-10-16 18:13:38 +08001075static struct snd_soc_dai_ops null_dai_ops = {
1076};
1077
Mark Brown435c5e22008-12-04 15:32:53 +00001078static void snd_soc_instantiate_card(struct snd_soc_card *card)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001079{
Mark Brown435c5e22008-12-04 15:32:53 +00001080 struct platform_device *pdev = container_of(card->dev,
1081 struct platform_device,
1082 dev);
1083 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
Mark Brownfe3e78e2009-11-03 22:13:13 +00001084 struct snd_soc_codec *codec;
Mark Brown435c5e22008-12-04 15:32:53 +00001085 struct snd_soc_platform *platform;
1086 struct snd_soc_dai *dai;
Mark Brown6b05eda2008-12-08 19:26:48 +00001087 int i, found, ret, ac97;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001088
Mark Brown435c5e22008-12-04 15:32:53 +00001089 if (card->instantiated)
1090 return;
Mark Brown63084192008-12-02 15:08:03 +00001091
Mark Brown435c5e22008-12-04 15:32:53 +00001092 found = 0;
1093 list_for_each_entry(platform, &platform_list, list)
1094 if (card->platform == platform) {
1095 found = 1;
1096 break;
1097 }
1098 if (!found) {
1099 dev_dbg(card->dev, "Platform %s not registered\n",
1100 card->platform->name);
1101 return;
Mark Brownc5af3a22008-11-28 13:29:45 +00001102 }
1103
Mark Brown6b05eda2008-12-08 19:26:48 +00001104 ac97 = 0;
Mark Brown435c5e22008-12-04 15:32:53 +00001105 for (i = 0; i < card->num_links; i++) {
1106 found = 0;
1107 list_for_each_entry(dai, &dai_list, list)
1108 if (card->dai_link[i].cpu_dai == dai) {
1109 found = 1;
1110 break;
1111 }
1112 if (!found) {
1113 dev_dbg(card->dev, "DAI %s not registered\n",
1114 card->dai_link[i].cpu_dai->name);
1115 return;
1116 }
Mark Brown6b05eda2008-12-08 19:26:48 +00001117
1118 if (card->dai_link[i].cpu_dai->ac97_control)
1119 ac97 = 1;
Mark Brown435c5e22008-12-04 15:32:53 +00001120 }
1121
Barry Song02a06d32009-10-16 18:13:38 +08001122 for (i = 0; i < card->num_links; i++) {
1123 if (!card->dai_link[i].codec_dai->ops)
1124 card->dai_link[i].codec_dai->ops = &null_dai_ops;
1125 }
1126
Mark Brown6b05eda2008-12-08 19:26:48 +00001127 /* If we have AC97 in the system then don't wait for the
1128 * codec. This will need revisiting if we have to handle
1129 * systems with mixed AC97 and non-AC97 parts. Only check for
1130 * DAIs currently; we can't do this per link since some AC97
1131 * codecs have non-AC97 DAIs.
1132 */
1133 if (!ac97)
1134 for (i = 0; i < card->num_links; i++) {
1135 found = 0;
1136 list_for_each_entry(dai, &dai_list, list)
1137 if (card->dai_link[i].codec_dai == dai) {
1138 found = 1;
1139 break;
1140 }
1141 if (!found) {
1142 dev_dbg(card->dev, "DAI %s not registered\n",
1143 card->dai_link[i].codec_dai->name);
1144 return;
1145 }
1146 }
1147
Mark Brown435c5e22008-12-04 15:32:53 +00001148 /* Note that we do not current check for codec components */
1149
1150 dev_dbg(card->dev, "All components present, instantiating\n");
1151
1152 /* Found everything, bring it up */
Mark Brown96dd3622010-02-12 11:05:44 +00001153 card->pmdown_time = pmdown_time;
1154
Mark Brown87506542008-11-18 20:50:34 +00001155 if (card->probe) {
1156 ret = card->probe(pdev);
Mark Brown3ff3f642008-05-19 12:32:25 +02001157 if (ret < 0)
Mark Brown435c5e22008-12-04 15:32:53 +00001158 return;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001159 }
1160
Mark Brown87506542008-11-18 20:50:34 +00001161 for (i = 0; i < card->num_links; i++) {
1162 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001163 if (cpu_dai->probe) {
Mark Brownbdb92872008-06-11 13:47:10 +01001164 ret = cpu_dai->probe(pdev, cpu_dai);
Mark Brown3ff3f642008-05-19 12:32:25 +02001165 if (ret < 0)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001166 goto cpu_dai_err;
1167 }
1168 }
1169
1170 if (codec_dev->probe) {
1171 ret = codec_dev->probe(pdev);
Mark Brown3ff3f642008-05-19 12:32:25 +02001172 if (ret < 0)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001173 goto cpu_dai_err;
1174 }
Mark Brownfe3e78e2009-11-03 22:13:13 +00001175 codec = card->codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001176
1177 if (platform->probe) {
1178 ret = platform->probe(pdev);
Mark Brown3ff3f642008-05-19 12:32:25 +02001179 if (ret < 0)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001180 goto platform_err;
1181 }
1182
1183 /* DAPM stream work */
Mark Brown63084192008-12-02 15:08:03 +00001184 INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work);
Randy Dunlap1301a962008-06-17 19:19:34 +01001185#ifdef CONFIG_PM
Andy Green6ed25972008-06-13 16:24:05 +01001186 /* deferred resume work */
Mark Brown63084192008-12-02 15:08:03 +00001187 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
Randy Dunlap1301a962008-06-17 19:19:34 +01001188#endif
Andy Green6ed25972008-06-13 16:24:05 +01001189
Mark Brownfe3e78e2009-11-03 22:13:13 +00001190 for (i = 0; i < card->num_links; i++) {
1191 if (card->dai_link[i].init) {
1192 ret = card->dai_link[i].init(codec);
1193 if (ret < 0) {
1194 printk(KERN_ERR "asoc: failed to init %s\n",
1195 card->dai_link[i].stream_name);
1196 continue;
1197 }
1198 }
Barry Songf7732052009-11-12 12:01:47 +08001199 if (card->dai_link[i].codec_dai->ac97_control)
Mark Brownfe3e78e2009-11-03 22:13:13 +00001200 ac97 = 1;
Mark Brownfe3e78e2009-11-03 22:13:13 +00001201 }
1202
1203 snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1204 "%s", card->name);
1205 snprintf(codec->card->longname, sizeof(codec->card->longname),
1206 "%s (%s)", card->name, codec->name);
1207
1208 /* Make sure all DAPM widgets are instantiated */
1209 snd_soc_dapm_new_widgets(codec);
1210
1211 ret = snd_card_register(codec->card);
1212 if (ret < 0) {
1213 printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1214 codec->name);
1215 goto card_err;
1216 }
1217
1218 mutex_lock(&codec->mutex);
1219#ifdef CONFIG_SND_SOC_AC97_BUS
1220 /* Only instantiate AC97 if not already done by the adaptor
1221 * for the generic AC97 subsystem.
1222 */
1223 if (ac97 && strcmp(codec->name, "AC97") != 0) {
1224 ret = soc_ac97_dev_register(codec);
1225 if (ret < 0) {
1226 printk(KERN_ERR "asoc: AC97 device register failed\n");
1227 snd_card_free(codec->card);
1228 mutex_unlock(&codec->mutex);
1229 goto card_err;
1230 }
1231 }
1232#endif
1233
1234 ret = snd_soc_dapm_sys_add(card->socdev->dev);
1235 if (ret < 0)
1236 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1237
Mark Browndbe21402010-02-12 11:37:24 +00001238 ret = device_create_file(card->socdev->dev, &dev_attr_pmdown_time);
1239 if (ret < 0)
1240 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1241
Mark Brownfe3e78e2009-11-03 22:13:13 +00001242 ret = device_create_file(card->socdev->dev, &dev_attr_codec_reg);
1243 if (ret < 0)
1244 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1245
1246 soc_init_codec_debugfs(codec);
1247 mutex_unlock(&codec->mutex);
1248
Mark Brown435c5e22008-12-04 15:32:53 +00001249 card->instantiated = 1;
1250
1251 return;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001252
Mark Brownfe3e78e2009-11-03 22:13:13 +00001253card_err:
1254 if (platform->remove)
1255 platform->remove(pdev);
1256
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001257platform_err:
1258 if (codec_dev->remove)
1259 codec_dev->remove(pdev);
1260
1261cpu_dai_err:
Liam Girdwood18b9b3d2007-01-30 17:18:45 +01001262 for (i--; i >= 0; i--) {
Mark Brown87506542008-11-18 20:50:34 +00001263 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001264 if (cpu_dai->remove)
Mark Brownbdb92872008-06-11 13:47:10 +01001265 cpu_dai->remove(pdev, cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001266 }
1267
Mark Brown87506542008-11-18 20:50:34 +00001268 if (card->remove)
1269 card->remove(pdev);
Mark Brown435c5e22008-12-04 15:32:53 +00001270}
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001271
Mark Brown435c5e22008-12-04 15:32:53 +00001272/*
1273 * Attempt to initialise any uninitalised cards. Must be called with
1274 * client_mutex.
1275 */
1276static void snd_soc_instantiate_cards(void)
1277{
1278 struct snd_soc_card *card;
1279 list_for_each_entry(card, &card_list, list)
1280 snd_soc_instantiate_card(card);
1281}
1282
1283/* probes a new socdev */
1284static int soc_probe(struct platform_device *pdev)
1285{
1286 int ret = 0;
1287 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1288 struct snd_soc_card *card = socdev->card;
1289
1290 /* Bodge while we push things out of socdev */
1291 card->socdev = socdev;
1292
1293 /* Bodge while we unpick instantiation */
1294 card->dev = &pdev->dev;
1295 ret = snd_soc_register_card(card);
1296 if (ret != 0) {
1297 dev_err(&pdev->dev, "Failed to register card\n");
1298 return ret;
1299 }
1300
1301 return 0;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001302}
1303
1304/* removes a socdev */
1305static int soc_remove(struct platform_device *pdev)
1306{
1307 int i;
1308 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
Mark Brown87506542008-11-18 20:50:34 +00001309 struct snd_soc_card *card = socdev->card;
Mark Brown87689d52008-12-02 16:01:14 +00001310 struct snd_soc_platform *platform = card->platform;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001311 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1312
Guennadi Liakhovetskib2dfa622010-03-18 08:23:33 +01001313 if (card->instantiated) {
1314 run_delayed_work(&card->delayed_work);
Mike Rapoport914dc182009-05-11 13:04:55 +03001315
Guennadi Liakhovetskib2dfa622010-03-18 08:23:33 +01001316 if (platform->remove)
1317 platform->remove(pdev);
Liam Girdwood965ac422007-01-31 14:14:57 +01001318
Guennadi Liakhovetskib2dfa622010-03-18 08:23:33 +01001319 if (codec_dev->remove)
1320 codec_dev->remove(pdev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001321
Guennadi Liakhovetskib2dfa622010-03-18 08:23:33 +01001322 for (i = 0; i < card->num_links; i++) {
1323 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1324 if (cpu_dai->remove)
1325 cpu_dai->remove(pdev, cpu_dai);
1326 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001327
Guennadi Liakhovetskib2dfa622010-03-18 08:23:33 +01001328 if (card->remove)
1329 card->remove(pdev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001330 }
1331
Mark Brownc5af3a22008-11-28 13:29:45 +00001332 snd_soc_unregister_card(card);
1333
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001334 return 0;
1335}
1336
Mark Brown416356f2009-06-30 19:05:15 +01001337static int soc_poweroff(struct device *dev)
Mark Brown51737472009-06-22 13:16:51 +01001338{
Mark Brown416356f2009-06-30 19:05:15 +01001339 struct platform_device *pdev = to_platform_device(dev);
Mark Brown51737472009-06-22 13:16:51 +01001340 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1341 struct snd_soc_card *card = socdev->card;
1342
1343 if (!card->instantiated)
Mark Brown416356f2009-06-30 19:05:15 +01001344 return 0;
Mark Brown51737472009-06-22 13:16:51 +01001345
1346 /* Flush out pmdown_time work - we actually do want to run it
1347 * now, we're shutting down so no imminent restart. */
1348 run_delayed_work(&card->delayed_work);
1349
1350 snd_soc_dapm_shutdown(socdev);
Mark Brown416356f2009-06-30 19:05:15 +01001351
1352 return 0;
Mark Brown51737472009-06-22 13:16:51 +01001353}
1354
Alexey Dobriyan47145212009-12-14 18:00:08 -08001355static const struct dev_pm_ops soc_pm_ops = {
Mark Brown416356f2009-06-30 19:05:15 +01001356 .suspend = soc_suspend,
1357 .resume = soc_resume,
1358 .poweroff = soc_poweroff,
1359};
1360
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001361/* ASoC platform driver */
1362static struct platform_driver soc_driver = {
1363 .driver = {
1364 .name = "soc-audio",
Kay Sievers8b45a202008-04-14 13:33:36 +02001365 .owner = THIS_MODULE,
Mark Brown416356f2009-06-30 19:05:15 +01001366 .pm = &soc_pm_ops,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001367 },
1368 .probe = soc_probe,
1369 .remove = soc_remove,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001370};
1371
1372/* create a new pcm */
1373static int soc_new_pcm(struct snd_soc_device *socdev,
1374 struct snd_soc_dai_link *dai_link, int num)
1375{
Mark Brown87689d52008-12-02 16:01:14 +00001376 struct snd_soc_card *card = socdev->card;
Mark Brown6627a652009-01-23 22:55:23 +00001377 struct snd_soc_codec *codec = card->codec;
Mark Brown87689d52008-12-02 16:01:14 +00001378 struct snd_soc_platform *platform = card->platform;
Liam Girdwood3c4b2662008-07-07 16:07:17 +01001379 struct snd_soc_dai *codec_dai = dai_link->codec_dai;
1380 struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001381 struct snd_soc_pcm_runtime *rtd;
1382 struct snd_pcm *pcm;
1383 char new_name[64];
1384 int ret = 0, playback = 0, capture = 0;
1385
1386 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
1387 if (rtd == NULL)
1388 return -ENOMEM;
Liam Girdwoodcb666e52007-02-02 17:13:49 +01001389
1390 rtd->dai = dai_link;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001391 rtd->socdev = socdev;
Mark Brown6627a652009-01-23 22:55:23 +00001392 codec_dai->codec = card->codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001393
1394 /* check client and interface hw capabilities */
Mark Brown40ca1142009-12-24 13:44:28 +00001395 snprintf(new_name, sizeof(new_name), "%s %s-%d",
1396 dai_link->stream_name, codec_dai->name, num);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001397
1398 if (codec_dai->playback.channels_min)
1399 playback = 1;
1400 if (codec_dai->capture.channels_min)
1401 capture = 1;
1402
1403 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
1404 capture, &pcm);
1405 if (ret < 0) {
Mark Brown3ff3f642008-05-19 12:32:25 +02001406 printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
1407 codec->name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001408 kfree(rtd);
1409 return ret;
1410 }
1411
Liam Girdwood4ccab3e2008-01-10 14:39:01 +01001412 dai_link->pcm = pcm;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001413 pcm->private_data = rtd;
Mark Brown87689d52008-12-02 16:01:14 +00001414 soc_pcm_ops.mmap = platform->pcm_ops->mmap;
Mark Brown87689d52008-12-02 16:01:14 +00001415 soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
1416 soc_pcm_ops.copy = platform->pcm_ops->copy;
1417 soc_pcm_ops.silence = platform->pcm_ops->silence;
1418 soc_pcm_ops.ack = platform->pcm_ops->ack;
1419 soc_pcm_ops.page = platform->pcm_ops->page;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001420
1421 if (playback)
1422 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
1423
1424 if (capture)
1425 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
1426
Mark Brown87689d52008-12-02 16:01:14 +00001427 ret = platform->pcm_new(codec->card, codec_dai, pcm);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001428 if (ret < 0) {
1429 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
1430 kfree(rtd);
1431 return ret;
1432 }
1433
Mark Brown87689d52008-12-02 16:01:14 +00001434 pcm->private_free = platform->pcm_free;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001435 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
1436 cpu_dai->name);
1437 return ret;
1438}
1439
Mark Brown096e49d2009-07-05 15:12:22 +01001440/**
1441 * snd_soc_codec_volatile_register: Report if a register is volatile.
1442 *
1443 * @codec: CODEC to query.
1444 * @reg: Register to query.
1445 *
1446 * Boolean function indiciating if a CODEC register is volatile.
1447 */
1448int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg)
1449{
1450 if (codec->volatile_register)
1451 return codec->volatile_register(reg);
1452 else
1453 return 0;
1454}
1455EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
1456
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001457/**
1458 * snd_soc_new_ac97_codec - initailise AC97 device
1459 * @codec: audio codec
1460 * @ops: AC97 bus operations
1461 * @num: AC97 codec number
1462 *
1463 * Initialises AC97 codec resources for use by ad-hoc devices only.
1464 */
1465int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1466 struct snd_ac97_bus_ops *ops, int num)
1467{
1468 mutex_lock(&codec->mutex);
1469
1470 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
1471 if (codec->ac97 == NULL) {
1472 mutex_unlock(&codec->mutex);
1473 return -ENOMEM;
1474 }
1475
1476 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
1477 if (codec->ac97->bus == NULL) {
1478 kfree(codec->ac97);
1479 codec->ac97 = NULL;
1480 mutex_unlock(&codec->mutex);
1481 return -ENOMEM;
1482 }
1483
1484 codec->ac97->bus->ops = ops;
1485 codec->ac97->num = num;
Mark Brown27186252010-01-28 12:36:29 +00001486 codec->dev = &codec->ac97->dev;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001487 mutex_unlock(&codec->mutex);
1488 return 0;
1489}
1490EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1491
1492/**
1493 * snd_soc_free_ac97_codec - free AC97 codec device
1494 * @codec: audio codec
1495 *
1496 * Frees AC97 codec device resources.
1497 */
1498void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1499{
1500 mutex_lock(&codec->mutex);
1501 kfree(codec->ac97->bus);
1502 kfree(codec->ac97);
1503 codec->ac97 = NULL;
1504 mutex_unlock(&codec->mutex);
1505}
1506EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
1507
1508/**
1509 * snd_soc_update_bits - update codec register bits
1510 * @codec: audio codec
1511 * @reg: codec register
1512 * @mask: register mask
1513 * @value: new value
1514 *
1515 * Writes new register value.
1516 *
1517 * Returns 1 for change else 0.
1518 */
1519int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001520 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001521{
1522 int change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001523 unsigned int old, new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001524
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001525 old = snd_soc_read(codec, reg);
1526 new = (old & ~mask) | value;
1527 change = old != new;
1528 if (change)
1529 snd_soc_write(codec, reg, new);
1530
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001531 return change;
1532}
1533EXPORT_SYMBOL_GPL(snd_soc_update_bits);
1534
1535/**
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001536 * snd_soc_update_bits_locked - update codec register bits
1537 * @codec: audio codec
1538 * @reg: codec register
1539 * @mask: register mask
1540 * @value: new value
1541 *
1542 * Writes new register value, and takes the codec mutex.
1543 *
1544 * Returns 1 for change else 0.
1545 */
Mark Browndd1b3d52009-12-04 14:22:03 +00001546int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
1547 unsigned short reg, unsigned int mask,
1548 unsigned int value)
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001549{
1550 int change;
1551
1552 mutex_lock(&codec->mutex);
1553 change = snd_soc_update_bits(codec, reg, mask, value);
1554 mutex_unlock(&codec->mutex);
1555
1556 return change;
1557}
Mark Browndd1b3d52009-12-04 14:22:03 +00001558EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001559
1560/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001561 * snd_soc_test_bits - test register for change
1562 * @codec: audio codec
1563 * @reg: codec register
1564 * @mask: register mask
1565 * @value: new value
1566 *
1567 * Tests a register with a new value and checks if the new value is
1568 * different from the old value.
1569 *
1570 * Returns 1 for change else 0.
1571 */
1572int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001573 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001574{
1575 int change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001576 unsigned int old, new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001577
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001578 old = snd_soc_read(codec, reg);
1579 new = (old & ~mask) | value;
1580 change = old != new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001581
1582 return change;
1583}
1584EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1585
1586/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001587 * snd_soc_new_pcms - create new sound card and pcms
1588 * @socdev: the SoC audio device
Mark Brownac11a2b2009-01-01 12:18:17 +00001589 * @idx: ALSA card index
1590 * @xid: card identification
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001591 *
1592 * Create a new sound card based upon the codec and interface pcms.
1593 *
1594 * Returns 0 for success, else error.
1595 */
Liam Girdwoodbc7320c2007-02-01 12:26:07 +01001596int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001597{
Mark Brown87506542008-11-18 20:50:34 +00001598 struct snd_soc_card *card = socdev->card;
Mark Brown6627a652009-01-23 22:55:23 +00001599 struct snd_soc_codec *codec = card->codec;
Takashi Iwaibd7dd772008-12-28 16:45:02 +01001600 int ret, i;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001601
1602 mutex_lock(&codec->mutex);
1603
1604 /* register a sound card */
Takashi Iwaibd7dd772008-12-28 16:45:02 +01001605 ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card);
1606 if (ret < 0) {
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001607 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1608 codec->name);
1609 mutex_unlock(&codec->mutex);
Takashi Iwaibd7dd772008-12-28 16:45:02 +01001610 return ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001611 }
1612
Mark Brown452c5ea2009-05-17 21:41:23 +01001613 codec->socdev = socdev;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001614 codec->card->dev = socdev->dev;
1615 codec->card->private_data = codec;
1616 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1617
1618 /* create the pcms */
Mark Brown87506542008-11-18 20:50:34 +00001619 for (i = 0; i < card->num_links; i++) {
1620 ret = soc_new_pcm(socdev, &card->dai_link[i], i);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001621 if (ret < 0) {
1622 printk(KERN_ERR "asoc: can't create pcm %s\n",
Mark Brown87506542008-11-18 20:50:34 +00001623 card->dai_link[i].stream_name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001624 mutex_unlock(&codec->mutex);
1625 return ret;
1626 }
Graham Gowerfb48e3c2010-03-25 10:52:12 +10301627 /* Check for codec->ac97 to handle the ac97.c fun */
1628 if (card->dai_link[i].codec_dai->ac97_control && codec->ac97) {
Barry Songf7732052009-11-12 12:01:47 +08001629 snd_ac97_dev_add_pdata(codec->ac97,
1630 card->dai_link[i].cpu_dai->ac97_pdata);
1631 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001632 }
1633
1634 mutex_unlock(&codec->mutex);
1635 return ret;
1636}
1637EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1638
1639/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001640 * snd_soc_free_pcms - free sound card and pcms
1641 * @socdev: the SoC audio device
1642 *
1643 * Frees sound card and pcms associated with the socdev.
1644 * Also unregister the codec if it is an AC97 device.
1645 */
1646void snd_soc_free_pcms(struct snd_soc_device *socdev)
1647{
Mark Brown6627a652009-01-23 22:55:23 +00001648 struct snd_soc_codec *codec = socdev->card->codec;
Liam Girdwooda68660e2007-05-10 19:27:27 +02001649#ifdef CONFIG_SND_SOC_AC97_BUS
Liam Girdwood3c4b2662008-07-07 16:07:17 +01001650 struct snd_soc_dai *codec_dai;
Liam Girdwooda68660e2007-05-10 19:27:27 +02001651 int i;
1652#endif
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001653
1654 mutex_lock(&codec->mutex);
Mark Brown6627a652009-01-23 22:55:23 +00001655 soc_cleanup_codec_debugfs(codec);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001656#ifdef CONFIG_SND_SOC_AC97_BUS
Mark Brown3ff3f642008-05-19 12:32:25 +02001657 for (i = 0; i < codec->num_dai; i++) {
Liam Girdwooda68660e2007-05-10 19:27:27 +02001658 codec_dai = &codec->dai[i];
Atsushi Nemotod2314e02009-03-16 23:26:20 +09001659 if (codec_dai->ac97_control && codec->ac97 &&
1660 strcmp(codec->name, "AC97") != 0) {
Liam Girdwooda68660e2007-05-10 19:27:27 +02001661 soc_ac97_dev_unregister(codec);
1662 goto free_card;
1663 }
1664 }
1665free_card:
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001666#endif
1667
1668 if (codec->card)
1669 snd_card_free(codec->card);
1670 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1671 mutex_unlock(&codec->mutex);
1672}
1673EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1674
1675/**
1676 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1677 * @substream: the pcm substream
1678 * @hw: the hardware parameters
1679 *
1680 * Sets the substream runtime hardware parameters.
1681 */
1682int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
1683 const struct snd_pcm_hardware *hw)
1684{
1685 struct snd_pcm_runtime *runtime = substream->runtime;
1686 runtime->hw.info = hw->info;
1687 runtime->hw.formats = hw->formats;
1688 runtime->hw.period_bytes_min = hw->period_bytes_min;
1689 runtime->hw.period_bytes_max = hw->period_bytes_max;
1690 runtime->hw.periods_min = hw->periods_min;
1691 runtime->hw.periods_max = hw->periods_max;
1692 runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
1693 runtime->hw.fifo_size = hw->fifo_size;
1694 return 0;
1695}
1696EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
1697
1698/**
1699 * snd_soc_cnew - create new control
1700 * @_template: control template
1701 * @data: control private data
Mark Brownac11a2b2009-01-01 12:18:17 +00001702 * @long_name: control long name
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001703 *
1704 * Create a new mixer control from a template control.
1705 *
1706 * Returns 0 for success, else error.
1707 */
1708struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1709 void *data, char *long_name)
1710{
1711 struct snd_kcontrol_new template;
1712
1713 memcpy(&template, _template, sizeof(template));
1714 if (long_name)
1715 template.name = long_name;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001716 template.index = 0;
1717
1718 return snd_ctl_new1(&template, data);
1719}
1720EXPORT_SYMBOL_GPL(snd_soc_cnew);
1721
1722/**
Ian Molton3e8e1952009-01-09 00:23:21 +00001723 * snd_soc_add_controls - add an array of controls to a codec.
1724 * Convienience function to add a list of controls. Many codecs were
1725 * duplicating this code.
1726 *
1727 * @codec: codec to add controls to
1728 * @controls: array of controls to add
1729 * @num_controls: number of elements in the array
1730 *
1731 * Return 0 for success, else error.
1732 */
1733int snd_soc_add_controls(struct snd_soc_codec *codec,
1734 const struct snd_kcontrol_new *controls, int num_controls)
1735{
1736 struct snd_card *card = codec->card;
1737 int err, i;
1738
1739 for (i = 0; i < num_controls; i++) {
1740 const struct snd_kcontrol_new *control = &controls[i];
1741 err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL));
1742 if (err < 0) {
1743 dev_err(codec->dev, "%s: Failed to add %s\n",
1744 codec->name, control->name);
1745 return err;
1746 }
1747 }
1748
1749 return 0;
1750}
1751EXPORT_SYMBOL_GPL(snd_soc_add_controls);
1752
1753/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001754 * snd_soc_info_enum_double - enumerated double mixer info callback
1755 * @kcontrol: mixer control
1756 * @uinfo: control element information
1757 *
1758 * Callback to provide information about a double enumerated
1759 * mixer control.
1760 *
1761 * Returns 0 for success.
1762 */
1763int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
1764 struct snd_ctl_elem_info *uinfo)
1765{
1766 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1767
1768 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1769 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001770 uinfo->value.enumerated.items = e->max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001771
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001772 if (uinfo->value.enumerated.item > e->max - 1)
1773 uinfo->value.enumerated.item = e->max - 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001774 strcpy(uinfo->value.enumerated.name,
1775 e->texts[uinfo->value.enumerated.item]);
1776 return 0;
1777}
1778EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
1779
1780/**
1781 * snd_soc_get_enum_double - enumerated double mixer get callback
1782 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001783 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001784 *
1785 * Callback to get the value of a double enumerated mixer.
1786 *
1787 * Returns 0 for success.
1788 */
1789int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
1790 struct snd_ctl_elem_value *ucontrol)
1791{
1792 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1793 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001794 unsigned int val, bitmask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001795
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001796 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001797 ;
1798 val = snd_soc_read(codec, e->reg);
Mark Brown3ff3f642008-05-19 12:32:25 +02001799 ucontrol->value.enumerated.item[0]
1800 = (val >> e->shift_l) & (bitmask - 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001801 if (e->shift_l != e->shift_r)
1802 ucontrol->value.enumerated.item[1] =
1803 (val >> e->shift_r) & (bitmask - 1);
1804
1805 return 0;
1806}
1807EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
1808
1809/**
1810 * snd_soc_put_enum_double - enumerated double mixer put callback
1811 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001812 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001813 *
1814 * Callback to set the value of a double enumerated mixer.
1815 *
1816 * Returns 0 for success.
1817 */
1818int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
1819 struct snd_ctl_elem_value *ucontrol)
1820{
1821 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1822 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001823 unsigned int val;
1824 unsigned int mask, bitmask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001825
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001826 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001827 ;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001828 if (ucontrol->value.enumerated.item[0] > e->max - 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001829 return -EINVAL;
1830 val = ucontrol->value.enumerated.item[0] << e->shift_l;
1831 mask = (bitmask - 1) << e->shift_l;
1832 if (e->shift_l != e->shift_r) {
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001833 if (ucontrol->value.enumerated.item[1] > e->max - 1)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001834 return -EINVAL;
1835 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1836 mask |= (bitmask - 1) << e->shift_r;
1837 }
1838
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001839 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001840}
1841EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
1842
1843/**
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001844 * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
1845 * @kcontrol: mixer control
1846 * @ucontrol: control element information
1847 *
1848 * Callback to get the value of a double semi enumerated mixer.
1849 *
1850 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1851 * used for handling bitfield coded enumeration for example.
1852 *
1853 * Returns 0 for success.
1854 */
1855int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
1856 struct snd_ctl_elem_value *ucontrol)
1857{
1858 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02001859 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001860 unsigned int reg_val, val, mux;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001861
1862 reg_val = snd_soc_read(codec, e->reg);
1863 val = (reg_val >> e->shift_l) & e->mask;
1864 for (mux = 0; mux < e->max; mux++) {
1865 if (val == e->values[mux])
1866 break;
1867 }
1868 ucontrol->value.enumerated.item[0] = mux;
1869 if (e->shift_l != e->shift_r) {
1870 val = (reg_val >> e->shift_r) & e->mask;
1871 for (mux = 0; mux < e->max; mux++) {
1872 if (val == e->values[mux])
1873 break;
1874 }
1875 ucontrol->value.enumerated.item[1] = mux;
1876 }
1877
1878 return 0;
1879}
1880EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
1881
1882/**
1883 * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
1884 * @kcontrol: mixer control
1885 * @ucontrol: control element information
1886 *
1887 * Callback to set the value of a double semi enumerated mixer.
1888 *
1889 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1890 * used for handling bitfield coded enumeration for example.
1891 *
1892 * Returns 0 for success.
1893 */
1894int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
1895 struct snd_ctl_elem_value *ucontrol)
1896{
1897 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02001898 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001899 unsigned int val;
1900 unsigned int mask;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001901
1902 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1903 return -EINVAL;
1904 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1905 mask = e->mask << e->shift_l;
1906 if (e->shift_l != e->shift_r) {
1907 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1908 return -EINVAL;
1909 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1910 mask |= e->mask << e->shift_r;
1911 }
1912
Eero Nurkkala6c508c62009-10-30 13:34:03 +02001913 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001914}
1915EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
1916
1917/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001918 * snd_soc_info_enum_ext - external enumerated single mixer info callback
1919 * @kcontrol: mixer control
1920 * @uinfo: control element information
1921 *
1922 * Callback to provide information about an external enumerated
1923 * single mixer.
1924 *
1925 * Returns 0 for success.
1926 */
1927int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
1928 struct snd_ctl_elem_info *uinfo)
1929{
1930 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1931
1932 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1933 uinfo->count = 1;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001934 uinfo->value.enumerated.items = e->max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001935
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001936 if (uinfo->value.enumerated.item > e->max - 1)
1937 uinfo->value.enumerated.item = e->max - 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001938 strcpy(uinfo->value.enumerated.name,
1939 e->texts[uinfo->value.enumerated.item]);
1940 return 0;
1941}
1942EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
1943
1944/**
1945 * snd_soc_info_volsw_ext - external single mixer info callback
1946 * @kcontrol: mixer control
1947 * @uinfo: control element information
1948 *
1949 * Callback to provide information about a single external mixer control.
1950 *
1951 * Returns 0 for success.
1952 */
1953int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
1954 struct snd_ctl_elem_info *uinfo)
1955{
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001956 int max = kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001957
Mark Brownfd5dfad2009-04-15 21:37:46 +01001958 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001959 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1960 else
1961 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1962
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001963 uinfo->count = 1;
1964 uinfo->value.integer.min = 0;
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001965 uinfo->value.integer.max = max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001966 return 0;
1967}
1968EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
1969
1970/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001971 * snd_soc_info_volsw - single mixer info callback
1972 * @kcontrol: mixer control
1973 * @uinfo: control element information
1974 *
1975 * Callback to provide information about a single mixer control.
1976 *
1977 * Returns 0 for success.
1978 */
1979int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
1980 struct snd_ctl_elem_info *uinfo)
1981{
Jon Smirl4eaa9812008-07-29 11:42:26 +01001982 struct soc_mixer_control *mc =
1983 (struct soc_mixer_control *)kcontrol->private_value;
1984 int max = mc->max;
Mark Brown762b8df2008-10-30 12:37:08 +00001985 unsigned int shift = mc->shift;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04001986 unsigned int rshift = mc->rshift;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001987
Mark Brownfd5dfad2009-04-15 21:37:46 +01001988 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001989 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1990 else
1991 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1992
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001993 uinfo->count = shift == rshift ? 1 : 2;
1994 uinfo->value.integer.min = 0;
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001995 uinfo->value.integer.max = max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001996 return 0;
1997}
1998EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
1999
2000/**
2001 * snd_soc_get_volsw - single mixer get callback
2002 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002003 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002004 *
2005 * Callback to get the value of a single mixer control.
2006 *
2007 * Returns 0 for success.
2008 */
2009int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2010 struct snd_ctl_elem_value *ucontrol)
2011{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002012 struct soc_mixer_control *mc =
2013 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002014 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002015 unsigned int reg = mc->reg;
2016 unsigned int shift = mc->shift;
2017 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002018 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002019 unsigned int mask = (1 << fls(max)) - 1;
2020 unsigned int invert = mc->invert;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002021
2022 ucontrol->value.integer.value[0] =
2023 (snd_soc_read(codec, reg) >> shift) & mask;
2024 if (shift != rshift)
2025 ucontrol->value.integer.value[1] =
2026 (snd_soc_read(codec, reg) >> rshift) & mask;
2027 if (invert) {
2028 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002029 max - ucontrol->value.integer.value[0];
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002030 if (shift != rshift)
2031 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002032 max - ucontrol->value.integer.value[1];
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002033 }
2034
2035 return 0;
2036}
2037EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2038
2039/**
2040 * snd_soc_put_volsw - single mixer put callback
2041 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002042 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002043 *
2044 * Callback to set the value of a single mixer control.
2045 *
2046 * Returns 0 for success.
2047 */
2048int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2049 struct snd_ctl_elem_value *ucontrol)
2050{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002051 struct soc_mixer_control *mc =
2052 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002053 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002054 unsigned int reg = mc->reg;
2055 unsigned int shift = mc->shift;
2056 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002057 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002058 unsigned int mask = (1 << fls(max)) - 1;
2059 unsigned int invert = mc->invert;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002060 unsigned int val, val2, val_mask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002061
2062 val = (ucontrol->value.integer.value[0] & mask);
2063 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002064 val = max - val;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002065 val_mask = mask << shift;
2066 val = val << shift;
2067 if (shift != rshift) {
2068 val2 = (ucontrol->value.integer.value[1] & mask);
2069 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002070 val2 = max - val2;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002071 val_mask |= mask << rshift;
2072 val |= val2 << rshift;
2073 }
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002074 return snd_soc_update_bits_locked(codec, reg, val_mask, val);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002075}
2076EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
2077
2078/**
2079 * snd_soc_info_volsw_2r - double mixer info callback
2080 * @kcontrol: mixer control
2081 * @uinfo: control element information
2082 *
2083 * Callback to provide information about a double mixer control that
2084 * spans 2 codec registers.
2085 *
2086 * Returns 0 for success.
2087 */
2088int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
2089 struct snd_ctl_elem_info *uinfo)
2090{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002091 struct soc_mixer_control *mc =
2092 (struct soc_mixer_control *)kcontrol->private_value;
2093 int max = mc->max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002094
Mark Brownfd5dfad2009-04-15 21:37:46 +01002095 if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002096 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2097 else
2098 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2099
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002100 uinfo->count = 2;
2101 uinfo->value.integer.min = 0;
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002102 uinfo->value.integer.max = max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002103 return 0;
2104}
2105EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
2106
2107/**
2108 * snd_soc_get_volsw_2r - double mixer get callback
2109 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002110 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002111 *
2112 * Callback to get the value of a double mixer control that spans 2 registers.
2113 *
2114 * Returns 0 for success.
2115 */
2116int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
2117 struct snd_ctl_elem_value *ucontrol)
2118{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002119 struct soc_mixer_control *mc =
2120 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002121 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002122 unsigned int reg = mc->reg;
2123 unsigned int reg2 = mc->rreg;
2124 unsigned int shift = mc->shift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002125 int max = mc->max;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002126 unsigned int mask = (1 << fls(max)) - 1;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002127 unsigned int invert = mc->invert;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002128
2129 ucontrol->value.integer.value[0] =
2130 (snd_soc_read(codec, reg) >> shift) & mask;
2131 ucontrol->value.integer.value[1] =
2132 (snd_soc_read(codec, reg2) >> shift) & mask;
2133 if (invert) {
2134 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002135 max - ucontrol->value.integer.value[0];
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002136 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002137 max - ucontrol->value.integer.value[1];
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002138 }
2139
2140 return 0;
2141}
2142EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
2143
2144/**
2145 * snd_soc_put_volsw_2r - double mixer set callback
2146 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002147 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002148 *
2149 * Callback to set the value of a double mixer control that spans 2 registers.
2150 *
2151 * Returns 0 for success.
2152 */
2153int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
2154 struct snd_ctl_elem_value *ucontrol)
2155{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002156 struct soc_mixer_control *mc =
2157 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002158 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002159 unsigned int reg = mc->reg;
2160 unsigned int reg2 = mc->rreg;
2161 unsigned int shift = mc->shift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002162 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002163 unsigned int mask = (1 << fls(max)) - 1;
2164 unsigned int invert = mc->invert;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002165 int err;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002166 unsigned int val, val2, val_mask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002167
2168 val_mask = mask << shift;
2169 val = (ucontrol->value.integer.value[0] & mask);
2170 val2 = (ucontrol->value.integer.value[1] & mask);
2171
2172 if (invert) {
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002173 val = max - val;
2174 val2 = max - val2;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002175 }
2176
2177 val = val << shift;
2178 val2 = val2 << shift;
2179
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002180 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
Mark Brown3ff3f642008-05-19 12:32:25 +02002181 if (err < 0)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002182 return err;
2183
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002184 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002185 return err;
2186}
2187EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
2188
Mark Browne13ac2e2008-05-28 17:58:05 +01002189/**
2190 * snd_soc_info_volsw_s8 - signed mixer info callback
2191 * @kcontrol: mixer control
2192 * @uinfo: control element information
2193 *
2194 * Callback to provide information about a signed mixer control.
2195 *
2196 * Returns 0 for success.
2197 */
2198int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2199 struct snd_ctl_elem_info *uinfo)
2200{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002201 struct soc_mixer_control *mc =
2202 (struct soc_mixer_control *)kcontrol->private_value;
2203 int max = mc->max;
2204 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002205
2206 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2207 uinfo->count = 2;
2208 uinfo->value.integer.min = 0;
2209 uinfo->value.integer.max = max-min;
2210 return 0;
2211}
2212EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
2213
2214/**
2215 * snd_soc_get_volsw_s8 - signed mixer get callback
2216 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002217 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01002218 *
2219 * Callback to get the value of a signed mixer control.
2220 *
2221 * Returns 0 for success.
2222 */
2223int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
2224 struct snd_ctl_elem_value *ucontrol)
2225{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002226 struct soc_mixer_control *mc =
2227 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01002228 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002229 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002230 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002231 int val = snd_soc_read(codec, reg);
2232
2233 ucontrol->value.integer.value[0] =
2234 ((signed char)(val & 0xff))-min;
2235 ucontrol->value.integer.value[1] =
2236 ((signed char)((val >> 8) & 0xff))-min;
2237 return 0;
2238}
2239EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
2240
2241/**
2242 * snd_soc_put_volsw_sgn - signed mixer put callback
2243 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002244 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01002245 *
2246 * Callback to set the value of a signed mixer control.
2247 *
2248 * Returns 0 for success.
2249 */
2250int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
2251 struct snd_ctl_elem_value *ucontrol)
2252{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002253 struct soc_mixer_control *mc =
2254 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01002255 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002256 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002257 int min = mc->min;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002258 unsigned int val;
Mark Browne13ac2e2008-05-28 17:58:05 +01002259
2260 val = (ucontrol->value.integer.value[0]+min) & 0xff;
2261 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
2262
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002263 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
Mark Browne13ac2e2008-05-28 17:58:05 +01002264}
2265EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2266
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002267/**
Peter Ujfalusi637d3842010-05-07 14:05:49 +03002268 * snd_soc_limit_volume - Set new limit to an existing volume control.
2269 *
2270 * @codec: where to look for the control
2271 * @name: Name of the control
2272 * @max: new maximum limit
2273 *
2274 * Return 0 for success, else error.
2275 */
2276int snd_soc_limit_volume(struct snd_soc_codec *codec,
2277 const char *name, int max)
2278{
2279 struct snd_card *card = codec->card;
2280 struct snd_kcontrol *kctl;
2281 struct soc_mixer_control *mc;
2282 int found = 0;
2283 int ret = -EINVAL;
2284
2285 /* Sanity check for name and max */
2286 if (unlikely(!name || max <= 0))
2287 return -EINVAL;
2288
2289 list_for_each_entry(kctl, &card->controls, list) {
2290 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
2291 found = 1;
2292 break;
2293 }
2294 }
2295 if (found) {
2296 mc = (struct soc_mixer_control *)kctl->private_value;
2297 if (max <= mc->max) {
2298 mc->max = max;
2299 ret = 0;
2300 }
2301 }
2302 return ret;
2303}
2304EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
2305
2306/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002307 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
2308 * @dai: DAI
2309 * @clk_id: DAI specific clock ID
2310 * @freq: new clock frequency in Hz
2311 * @dir: new clock direction - input/output.
2312 *
2313 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
2314 */
2315int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2316 unsigned int freq, int dir)
2317{
Mark Brown3f1a4d82009-04-15 21:35:26 +01002318 if (dai->ops && dai->ops->set_sysclk)
Eric Miao6335d052009-03-03 09:41:00 +08002319 return dai->ops->set_sysclk(dai, clk_id, freq, dir);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002320 else
2321 return -EINVAL;
2322}
2323EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2324
2325/**
2326 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
2327 * @dai: DAI
Mark Brownac11a2b2009-01-01 12:18:17 +00002328 * @div_id: DAI specific clock divider ID
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002329 * @div: new clock divisor.
2330 *
2331 * Configures the clock dividers. This is used to derive the best DAI bit and
2332 * frame clocks from the system or master clock. It's best to set the DAI bit
2333 * and frame clocks as low as possible to save system power.
2334 */
2335int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2336 int div_id, int div)
2337{
Mark Brown3f1a4d82009-04-15 21:35:26 +01002338 if (dai->ops && dai->ops->set_clkdiv)
Eric Miao6335d052009-03-03 09:41:00 +08002339 return dai->ops->set_clkdiv(dai, div_id, div);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002340 else
2341 return -EINVAL;
2342}
2343EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2344
2345/**
2346 * snd_soc_dai_set_pll - configure DAI PLL.
2347 * @dai: DAI
2348 * @pll_id: DAI specific PLL ID
Mark Brown85488032009-09-05 18:52:16 +01002349 * @source: DAI specific source for the PLL
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002350 * @freq_in: PLL input clock frequency in Hz
2351 * @freq_out: requested PLL output clock frequency in Hz
2352 *
2353 * Configures and enables PLL to generate output clock based on input clock.
2354 */
Mark Brown85488032009-09-05 18:52:16 +01002355int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2356 unsigned int freq_in, unsigned int freq_out)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002357{
Mark Brown3f1a4d82009-04-15 21:35:26 +01002358 if (dai->ops && dai->ops->set_pll)
Mark Brown85488032009-09-05 18:52:16 +01002359 return dai->ops->set_pll(dai, pll_id, source,
2360 freq_in, freq_out);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002361 else
2362 return -EINVAL;
2363}
2364EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2365
2366/**
2367 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2368 * @dai: DAI
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002369 * @fmt: SND_SOC_DAIFMT_ format value.
2370 *
2371 * Configures the DAI hardware format and clocking.
2372 */
2373int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2374{
Mark Brown3f1a4d82009-04-15 21:35:26 +01002375 if (dai->ops && dai->ops->set_fmt)
Eric Miao6335d052009-03-03 09:41:00 +08002376 return dai->ops->set_fmt(dai, fmt);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002377 else
2378 return -EINVAL;
2379}
2380EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2381
2382/**
2383 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
2384 * @dai: DAI
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002385 * @tx_mask: bitmask representing active TX slots.
2386 * @rx_mask: bitmask representing active RX slots.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002387 * @slots: Number of slots in use.
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002388 * @slot_width: Width in bits for each slot.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002389 *
2390 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
2391 * specific.
2392 */
2393int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002394 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002395{
Mark Brown3f1a4d82009-04-15 21:35:26 +01002396 if (dai->ops && dai->ops->set_tdm_slot)
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03002397 return dai->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2398 slots, slot_width);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002399 else
2400 return -EINVAL;
2401}
2402EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2403
2404/**
Barry Song472df3c2009-09-12 01:16:29 +08002405 * snd_soc_dai_set_channel_map - configure DAI audio channel map
2406 * @dai: DAI
2407 * @tx_num: how many TX channels
2408 * @tx_slot: pointer to an array which imply the TX slot number channel
2409 * 0~num-1 uses
2410 * @rx_num: how many RX channels
2411 * @rx_slot: pointer to an array which imply the RX slot number channel
2412 * 0~num-1 uses
2413 *
2414 * configure the relationship between channel number and TDM slot number.
2415 */
2416int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2417 unsigned int tx_num, unsigned int *tx_slot,
2418 unsigned int rx_num, unsigned int *rx_slot)
2419{
2420 if (dai->ops && dai->ops->set_channel_map)
2421 return dai->ops->set_channel_map(dai, tx_num, tx_slot,
2422 rx_num, rx_slot);
2423 else
2424 return -EINVAL;
2425}
2426EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2427
2428/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002429 * snd_soc_dai_set_tristate - configure DAI system or master clock.
2430 * @dai: DAI
2431 * @tristate: tristate enable
2432 *
2433 * Tristates the DAI so that others can use it.
2434 */
2435int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2436{
Mark Brown3f1a4d82009-04-15 21:35:26 +01002437 if (dai->ops && dai->ops->set_tristate)
Eric Miao6335d052009-03-03 09:41:00 +08002438 return dai->ops->set_tristate(dai, tristate);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002439 else
2440 return -EINVAL;
2441}
2442EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2443
2444/**
2445 * snd_soc_dai_digital_mute - configure DAI system or master clock.
2446 * @dai: DAI
2447 * @mute: mute enable
2448 *
2449 * Mutes the DAI DAC.
2450 */
2451int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2452{
Mark Brown3f1a4d82009-04-15 21:35:26 +01002453 if (dai->ops && dai->ops->digital_mute)
Eric Miao6335d052009-03-03 09:41:00 +08002454 return dai->ops->digital_mute(dai, mute);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01002455 else
2456 return -EINVAL;
2457}
2458EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2459
Mark Brownc5af3a22008-11-28 13:29:45 +00002460/**
2461 * snd_soc_register_card - Register a card with the ASoC core
2462 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002463 * @card: Card to register
Mark Brownc5af3a22008-11-28 13:29:45 +00002464 *
2465 * Note that currently this is an internal only function: it will be
2466 * exposed to machine drivers after further backporting of ASoC v2
2467 * registration APIs.
2468 */
2469static int snd_soc_register_card(struct snd_soc_card *card)
2470{
2471 if (!card->name || !card->dev)
2472 return -EINVAL;
2473
2474 INIT_LIST_HEAD(&card->list);
2475 card->instantiated = 0;
2476
2477 mutex_lock(&client_mutex);
2478 list_add(&card->list, &card_list);
Mark Brown435c5e22008-12-04 15:32:53 +00002479 snd_soc_instantiate_cards();
Mark Brownc5af3a22008-11-28 13:29:45 +00002480 mutex_unlock(&client_mutex);
2481
2482 dev_dbg(card->dev, "Registered card '%s'\n", card->name);
2483
2484 return 0;
2485}
2486
2487/**
2488 * snd_soc_unregister_card - Unregister a card with the ASoC core
2489 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002490 * @card: Card to unregister
Mark Brownc5af3a22008-11-28 13:29:45 +00002491 *
2492 * Note that currently this is an internal only function: it will be
2493 * exposed to machine drivers after further backporting of ASoC v2
2494 * registration APIs.
2495 */
2496static int snd_soc_unregister_card(struct snd_soc_card *card)
2497{
2498 mutex_lock(&client_mutex);
2499 list_del(&card->list);
2500 mutex_unlock(&client_mutex);
2501
2502 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2503
2504 return 0;
2505}
2506
Mark Brown91151712008-11-30 23:31:24 +00002507/**
2508 * snd_soc_register_dai - Register a DAI with the ASoC core
2509 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002510 * @dai: DAI to register
Mark Brown91151712008-11-30 23:31:24 +00002511 */
2512int snd_soc_register_dai(struct snd_soc_dai *dai)
2513{
2514 if (!dai->name)
2515 return -EINVAL;
2516
2517 /* The device should become mandatory over time */
2518 if (!dai->dev)
2519 printk(KERN_WARNING "No device for DAI %s\n", dai->name);
2520
Eric Miao6335d052009-03-03 09:41:00 +08002521 if (!dai->ops)
2522 dai->ops = &null_dai_ops;
2523
Mark Brown91151712008-11-30 23:31:24 +00002524 INIT_LIST_HEAD(&dai->list);
2525
2526 mutex_lock(&client_mutex);
2527 list_add(&dai->list, &dai_list);
Mark Brown435c5e22008-12-04 15:32:53 +00002528 snd_soc_instantiate_cards();
Mark Brown91151712008-11-30 23:31:24 +00002529 mutex_unlock(&client_mutex);
2530
2531 pr_debug("Registered DAI '%s'\n", dai->name);
2532
2533 return 0;
2534}
2535EXPORT_SYMBOL_GPL(snd_soc_register_dai);
2536
2537/**
2538 * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
2539 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002540 * @dai: DAI to unregister
Mark Brown91151712008-11-30 23:31:24 +00002541 */
2542void snd_soc_unregister_dai(struct snd_soc_dai *dai)
2543{
2544 mutex_lock(&client_mutex);
2545 list_del(&dai->list);
2546 mutex_unlock(&client_mutex);
2547
2548 pr_debug("Unregistered DAI '%s'\n", dai->name);
2549}
2550EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
2551
2552/**
2553 * snd_soc_register_dais - Register multiple DAIs with the ASoC core
2554 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002555 * @dai: Array of DAIs to register
2556 * @count: Number of DAIs
Mark Brown91151712008-11-30 23:31:24 +00002557 */
2558int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count)
2559{
2560 int i, ret;
2561
2562 for (i = 0; i < count; i++) {
2563 ret = snd_soc_register_dai(&dai[i]);
2564 if (ret != 0)
2565 goto err;
2566 }
2567
2568 return 0;
2569
2570err:
2571 for (i--; i >= 0; i--)
2572 snd_soc_unregister_dai(&dai[i]);
2573
2574 return ret;
2575}
2576EXPORT_SYMBOL_GPL(snd_soc_register_dais);
2577
2578/**
2579 * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
2580 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002581 * @dai: Array of DAIs to unregister
2582 * @count: Number of DAIs
Mark Brown91151712008-11-30 23:31:24 +00002583 */
2584void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count)
2585{
2586 int i;
2587
2588 for (i = 0; i < count; i++)
2589 snd_soc_unregister_dai(&dai[i]);
2590}
2591EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
2592
Mark Brown12a48a8c2008-12-03 19:40:30 +00002593/**
2594 * snd_soc_register_platform - Register a platform with the ASoC core
2595 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002596 * @platform: platform to register
Mark Brown12a48a8c2008-12-03 19:40:30 +00002597 */
2598int snd_soc_register_platform(struct snd_soc_platform *platform)
2599{
2600 if (!platform->name)
2601 return -EINVAL;
2602
2603 INIT_LIST_HEAD(&platform->list);
2604
2605 mutex_lock(&client_mutex);
2606 list_add(&platform->list, &platform_list);
Mark Brown435c5e22008-12-04 15:32:53 +00002607 snd_soc_instantiate_cards();
Mark Brown12a48a8c2008-12-03 19:40:30 +00002608 mutex_unlock(&client_mutex);
2609
2610 pr_debug("Registered platform '%s'\n", platform->name);
2611
2612 return 0;
2613}
2614EXPORT_SYMBOL_GPL(snd_soc_register_platform);
2615
2616/**
2617 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
2618 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002619 * @platform: platform to unregister
Mark Brown12a48a8c2008-12-03 19:40:30 +00002620 */
2621void snd_soc_unregister_platform(struct snd_soc_platform *platform)
2622{
2623 mutex_lock(&client_mutex);
2624 list_del(&platform->list);
2625 mutex_unlock(&client_mutex);
2626
2627 pr_debug("Unregistered platform '%s'\n", platform->name);
2628}
2629EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
2630
Mark Brown151ab222009-05-09 16:22:58 +01002631static u64 codec_format_map[] = {
2632 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
2633 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
2634 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
2635 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
2636 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
2637 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
2638 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
2639 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
2640 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
2641 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
2642 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
2643 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
2644 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
2645 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
2646 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
2647 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
2648};
2649
2650/* Fix up the DAI formats for endianness: codecs don't actually see
2651 * the endianness of the data but we're using the CPU format
2652 * definitions which do need to include endianness so we ensure that
2653 * codec DAIs always have both big and little endian variants set.
2654 */
2655static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
2656{
2657 int i;
2658
2659 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
2660 if (stream->formats & codec_format_map[i])
2661 stream->formats |= codec_format_map[i];
2662}
2663
Mark Brown0d0cf002008-12-10 14:32:45 +00002664/**
2665 * snd_soc_register_codec - Register a codec with the ASoC core
2666 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002667 * @codec: codec to register
Mark Brown0d0cf002008-12-10 14:32:45 +00002668 */
2669int snd_soc_register_codec(struct snd_soc_codec *codec)
2670{
Mark Brown151ab222009-05-09 16:22:58 +01002671 int i;
2672
Mark Brown0d0cf002008-12-10 14:32:45 +00002673 if (!codec->name)
2674 return -EINVAL;
2675
2676 /* The device should become mandatory over time */
2677 if (!codec->dev)
2678 printk(KERN_WARNING "No device for codec %s\n", codec->name);
2679
2680 INIT_LIST_HEAD(&codec->list);
2681
Mark Brown151ab222009-05-09 16:22:58 +01002682 for (i = 0; i < codec->num_dai; i++) {
2683 fixup_codec_formats(&codec->dai[i].playback);
2684 fixup_codec_formats(&codec->dai[i].capture);
2685 }
2686
Mark Brown0d0cf002008-12-10 14:32:45 +00002687 mutex_lock(&client_mutex);
2688 list_add(&codec->list, &codec_list);
2689 snd_soc_instantiate_cards();
2690 mutex_unlock(&client_mutex);
2691
2692 pr_debug("Registered codec '%s'\n", codec->name);
2693
2694 return 0;
2695}
2696EXPORT_SYMBOL_GPL(snd_soc_register_codec);
2697
2698/**
2699 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
2700 *
Mark Brownac11a2b2009-01-01 12:18:17 +00002701 * @codec: codec to unregister
Mark Brown0d0cf002008-12-10 14:32:45 +00002702 */
2703void snd_soc_unregister_codec(struct snd_soc_codec *codec)
2704{
2705 mutex_lock(&client_mutex);
2706 list_del(&codec->list);
2707 mutex_unlock(&client_mutex);
2708
2709 pr_debug("Unregistered codec '%s'\n", codec->name);
2710}
2711EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
2712
Takashi Iwaic9b3a402008-12-10 07:47:22 +01002713static int __init snd_soc_init(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002714{
Mark Brown384c89e2008-12-03 17:34:03 +00002715#ifdef CONFIG_DEBUG_FS
2716 debugfs_root = debugfs_create_dir("asoc", NULL);
2717 if (IS_ERR(debugfs_root) || !debugfs_root) {
2718 printk(KERN_WARNING
2719 "ASoC: Failed to create debugfs directory\n");
2720 debugfs_root = NULL;
2721 }
2722#endif
2723
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002724 return platform_driver_register(&soc_driver);
2725}
2726
Mark Brown7d8c16a2008-11-30 22:11:24 +00002727static void __exit snd_soc_exit(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002728{
Mark Brown384c89e2008-12-03 17:34:03 +00002729#ifdef CONFIG_DEBUG_FS
2730 debugfs_remove_recursive(debugfs_root);
2731#endif
Mark Brown3ff3f642008-05-19 12:32:25 +02002732 platform_driver_unregister(&soc_driver);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002733}
2734
2735module_init(snd_soc_init);
2736module_exit(snd_soc_exit);
2737
2738/* Module information */
Liam Girdwoodd3311242008-10-12 13:17:36 +01002739MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002740MODULE_DESCRIPTION("ALSA SoC Core");
2741MODULE_LICENSE("GPL");
Kay Sievers8b45a202008-04-14 13:33:36 +02002742MODULE_ALIAS("platform:soc-audio");