blob: 42c5835ba92f8e92ec8a9fab47a962b13abd91ed [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.
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00006 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
Liam Girdwood0664d882006-12-18 14:39:02 +01008 *
Liam Girdwoodd3311242008-10-12 13:17:36 +01009 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Liam Girdwood0664d882006-12-18 14:39:02 +010010 * with code, comments and ideas from :-
11 * Richard Purdie <richard@openedhand.com>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020012 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
Frank Mandarinodb2a4162006-10-06 18:31:09 +020018 * TODO:
19 * o Add hw rules to enforce rates, etc.
20 * o More testing with other codecs/machines.
21 * o Add more codecs and platforms to ensure good API coverage.
22 * o Support TDM on PCM and I2S
23 */
24
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/pm.h>
30#include <linux/bitops.h>
Troy Kisky12ef1932008-10-13 17:42:14 -070031#include <linux/debugfs.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020032#include <linux/platform_device.h>
Markus Pargmann741a5092013-08-19 17:05:55 +020033#include <linux/pinctrl/consumer.h>
Mark Brownf0e8ed82011-09-20 11:41:54 +010034#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Stephen Warrenbec4fa02011-12-12 15:55:34 -070036#include <linux/of.h>
Markus Pargmann741a5092013-08-19 17:05:55 +020037#include <linux/gpio.h>
38#include <linux/of_gpio.h>
Marek Vasut474828a2009-07-22 13:01:03 +020039#include <sound/ac97_codec.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020040#include <sound/core.h>
Mark Brown3028eb82010-12-05 12:22:46 +000041#include <sound/jack.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020042#include <sound/pcm.h>
43#include <sound/pcm_params.h>
44#include <sound/soc.h>
Liam Girdwood01d75842012-04-25 12:12:49 +010045#include <sound/soc-dpcm.h>
Frank Mandarinodb2a4162006-10-06 18:31:09 +020046#include <sound/initval.h>
47
Mark Browna8b1d342010-11-03 18:05:58 -040048#define CREATE_TRACE_POINTS
49#include <trace/events/asoc.h>
50
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000051#define NAME_SIZE 32
52
Mark Brown384c89e2008-12-03 17:34:03 +000053#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +000054struct dentry *snd_soc_debugfs_root;
55EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
Mark Brown384c89e2008-12-03 17:34:03 +000056#endif
57
Mark Brownc5af3a22008-11-28 13:29:45 +000058static DEFINE_MUTEX(client_mutex);
Mark Brown12a48a8c2008-12-03 19:40:30 +000059static LIST_HEAD(platform_list);
Mark Brown0d0cf002008-12-10 14:32:45 +000060static LIST_HEAD(codec_list);
Kuninori Morimoto030e79f2013-03-11 18:27:21 -070061static LIST_HEAD(component_list);
Mark Brownc5af3a22008-11-28 13:29:45 +000062
Frank Mandarinodb2a4162006-10-06 18:31:09 +020063/*
64 * This is a timeout to do a DAPM powerdown after a stream is closed().
65 * It can be used to eliminate pops between different playback streams, e.g.
66 * between two audio tracks.
67 */
68static int pmdown_time = 5000;
69module_param(pmdown_time, int, 0);
70MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
71
Markus Pargmann741a5092013-08-19 17:05:55 +020072struct snd_ac97_reset_cfg {
73 struct pinctrl *pctl;
74 struct pinctrl_state *pstate_reset;
75 struct pinctrl_state *pstate_warm_reset;
76 struct pinctrl_state *pstate_run;
77 int gpio_sdata;
78 int gpio_sync;
79 int gpio_reset;
80};
81
Dimitris Papastamos2bc9a812011-02-01 12:24:08 +000082/* returns the minimum number of bytes needed to represent
83 * a particular given value */
84static int min_bytes_needed(unsigned long val)
85{
86 int c = 0;
87 int i;
88
89 for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
90 if (val & (1UL << i))
91 break;
92 c = (sizeof val * 8) - c;
93 if (!c || (c % 8))
94 c = (c + 8) / 8;
95 else
96 c /= 8;
97 return c;
98}
99
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000100/* fill buf which is 'len' bytes with a formatted
101 * string of the form 'reg: value\n' */
102static int format_register_str(struct snd_soc_codec *codec,
103 unsigned int reg, char *buf, size_t len)
Mark Brown2624d5f2009-11-03 21:56:13 +0000104{
Stephen Warren00b317a2011-04-01 14:50:44 -0600105 int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
106 int regsize = codec->driver->reg_word_size * 2;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000107 int ret;
108 char tmpbuf[len + 1];
109 char regbuf[regsize + 1];
110
111 /* since tmpbuf is allocated on the stack, warn the callers if they
112 * try to abuse this function */
113 WARN_ON(len > 63);
114
115 /* +2 for ': ' and + 1 for '\n' */
116 if (wordsize + regsize + 2 + 1 != len)
117 return -EINVAL;
118
Mark Brown25032c12011-08-01 13:52:48 +0900119 ret = snd_soc_read(codec, reg);
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000120 if (ret < 0) {
121 memset(regbuf, 'X', regsize);
122 regbuf[regsize] = '\0';
123 } else {
124 snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
125 }
126
127 /* prepare the buffer */
128 snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
129 /* copy it back to the caller without the '\0' */
130 memcpy(buf, tmpbuf, len);
131
132 return 0;
133}
134
135/* codec register dump */
136static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
137 size_t count, loff_t pos)
138{
139 int i, step = 1;
Dimitris Papastamos2bc9a812011-02-01 12:24:08 +0000140 int wordsize, regsize;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000141 int len;
142 size_t total = 0;
143 loff_t p = 0;
Dimitris Papastamos2bc9a812011-02-01 12:24:08 +0000144
Stephen Warren00b317a2011-04-01 14:50:44 -0600145 wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
146 regsize = codec->driver->reg_word_size * 2;
Mark Brown2624d5f2009-11-03 21:56:13 +0000147
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000148 len = wordsize + regsize + 2 + 1;
149
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000150 if (!codec->driver->reg_cache_size)
Mark Brown2624d5f2009-11-03 21:56:13 +0000151 return 0;
152
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000153 if (codec->driver->reg_cache_step)
154 step = codec->driver->reg_cache_step;
Mark Brown2624d5f2009-11-03 21:56:13 +0000155
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000156 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
Lars-Peter Clausenb92d1502011-08-27 18:24:14 +0200157 if (!snd_soc_codec_readable_register(codec, i))
Mark Brown2624d5f2009-11-03 21:56:13 +0000158 continue;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000159 if (codec->driver->display_register) {
160 count += codec->driver->display_register(codec, buf + count,
Mark Brown2624d5f2009-11-03 21:56:13 +0000161 PAGE_SIZE - count, i);
Mark Brown5164d742010-07-14 16:14:33 +0100162 } else {
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000163 /* only support larger than PAGE_SIZE bytes debugfs
164 * entries for the default case */
165 if (p >= pos) {
166 if (total + len >= count - 1)
167 break;
168 format_register_str(codec, i, buf + total, len);
169 total += len;
170 }
171 p += len;
Mark Brown5164d742010-07-14 16:14:33 +0100172 }
Mark Brown2624d5f2009-11-03 21:56:13 +0000173 }
174
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000175 total = min(total, count - 1);
Mark Brown2624d5f2009-11-03 21:56:13 +0000176
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000177 return total;
Mark Brown2624d5f2009-11-03 21:56:13 +0000178}
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000179
Mark Brown2624d5f2009-11-03 21:56:13 +0000180static ssize_t codec_reg_show(struct device *dev,
181 struct device_attribute *attr, char *buf)
182{
Mark Brown36ae1a92012-01-06 17:12:45 -0800183 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000184
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000185 return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
Mark Brown2624d5f2009-11-03 21:56:13 +0000186}
187
188static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
189
Mark Browndbe21402010-02-12 11:37:24 +0000190static ssize_t pmdown_time_show(struct device *dev,
191 struct device_attribute *attr, char *buf)
192{
Mark Brown36ae1a92012-01-06 17:12:45 -0800193 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
Mark Browndbe21402010-02-12 11:37:24 +0000194
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000195 return sprintf(buf, "%ld\n", rtd->pmdown_time);
Mark Browndbe21402010-02-12 11:37:24 +0000196}
197
198static ssize_t pmdown_time_set(struct device *dev,
199 struct device_attribute *attr,
200 const char *buf, size_t count)
201{
Mark Brown36ae1a92012-01-06 17:12:45 -0800202 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
Mark Brownc593b522010-10-27 20:11:17 -0700203 int ret;
Mark Browndbe21402010-02-12 11:37:24 +0000204
Jingoo Hanb785a492013-07-19 16:24:59 +0900205 ret = kstrtol(buf, 10, &rtd->pmdown_time);
Mark Brownc593b522010-10-27 20:11:17 -0700206 if (ret)
207 return ret;
Mark Browndbe21402010-02-12 11:37:24 +0000208
209 return count;
210}
211
212static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
213
Mark Brown2624d5f2009-11-03 21:56:13 +0000214#ifdef CONFIG_DEBUG_FS
Mark Brown2624d5f2009-11-03 21:56:13 +0000215static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000216 size_t count, loff_t *ppos)
Mark Brown2624d5f2009-11-03 21:56:13 +0000217{
218 ssize_t ret;
219 struct snd_soc_codec *codec = file->private_data;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000220 char *buf;
221
222 if (*ppos < 0 || !count)
223 return -EINVAL;
224
225 buf = kmalloc(count, GFP_KERNEL);
Mark Brown2624d5f2009-11-03 21:56:13 +0000226 if (!buf)
227 return -ENOMEM;
Dimitris Papastamos13fd1792011-02-02 13:58:58 +0000228
229 ret = soc_codec_reg_show(codec, buf, count, *ppos);
230 if (ret >= 0) {
231 if (copy_to_user(user_buf, buf, ret)) {
232 kfree(buf);
233 return -EFAULT;
234 }
235 *ppos += ret;
236 }
237
Mark Brown2624d5f2009-11-03 21:56:13 +0000238 kfree(buf);
239 return ret;
240}
241
242static ssize_t codec_reg_write_file(struct file *file,
243 const char __user *user_buf, size_t count, loff_t *ppos)
244{
245 char buf[32];
Stephen Boyd34e268d2011-05-12 16:50:10 -0700246 size_t buf_size;
Mark Brown2624d5f2009-11-03 21:56:13 +0000247 char *start = buf;
248 unsigned long reg, value;
Mark Brown2624d5f2009-11-03 21:56:13 +0000249 struct snd_soc_codec *codec = file->private_data;
Jingoo Hanb785a492013-07-19 16:24:59 +0900250 int ret;
Mark Brown2624d5f2009-11-03 21:56:13 +0000251
252 buf_size = min(count, (sizeof(buf)-1));
253 if (copy_from_user(buf, user_buf, buf_size))
254 return -EFAULT;
255 buf[buf_size] = 0;
256
Mark Brown2624d5f2009-11-03 21:56:13 +0000257 while (*start == ' ')
258 start++;
259 reg = simple_strtoul(start, &start, 16);
Mark Brown2624d5f2009-11-03 21:56:13 +0000260 while (*start == ' ')
261 start++;
Jingoo Hanb785a492013-07-19 16:24:59 +0900262 ret = kstrtoul(start, 16, &value);
263 if (ret)
264 return ret;
Mark Brown0d51a9c2011-01-06 16:04:57 +0000265
266 /* Userspace has been fiddling around behind the kernel's back */
Rusty Russell373d4d02013-01-21 17:17:39 +1030267 add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE);
Mark Brown0d51a9c2011-01-06 16:04:57 +0000268
Dimitris Papastamose4f078d2010-12-07 16:30:38 +0000269 snd_soc_write(codec, reg, value);
Mark Brown2624d5f2009-11-03 21:56:13 +0000270 return buf_size;
271}
272
273static const struct file_operations codec_reg_fops = {
Stephen Boyd234e3402012-04-05 14:25:11 -0700274 .open = simple_open,
Mark Brown2624d5f2009-11-03 21:56:13 +0000275 .read = codec_reg_read_file,
276 .write = codec_reg_write_file,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200277 .llseek = default_llseek,
Mark Brown2624d5f2009-11-03 21:56:13 +0000278};
279
280static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
281{
Jarkko Nikulad6ce4cf2010-11-05 20:35:20 +0200282 struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
283
284 codec->debugfs_codec_root = debugfs_create_dir(codec->name,
285 debugfs_card_root);
Mark Brown2624d5f2009-11-03 21:56:13 +0000286 if (!codec->debugfs_codec_root) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +0200287 dev_warn(codec->dev,
288 "ASoC: Failed to create codec debugfs directory\n");
Mark Brown2624d5f2009-11-03 21:56:13 +0000289 return;
290 }
291
Mark Brownaaee8ef2011-01-26 20:53:50 +0000292 debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
293 &codec->cache_sync);
294 debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
295 &codec->cache_only);
296
Mark Brown2624d5f2009-11-03 21:56:13 +0000297 codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
298 codec->debugfs_codec_root,
299 codec, &codec_reg_fops);
300 if (!codec->debugfs_reg)
Michał Mirosław10e8aa92013-05-04 22:21:38 +0200301 dev_warn(codec->dev,
302 "ASoC: Failed to create codec register debugfs file\n");
Mark Brown2624d5f2009-11-03 21:56:13 +0000303
Lars-Peter Clausen8eecaf62011-04-30 19:45:48 +0200304 snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
Mark Brown2624d5f2009-11-03 21:56:13 +0000305}
306
307static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
308{
309 debugfs_remove_recursive(codec->debugfs_codec_root);
310}
311
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +0000312static void soc_init_platform_debugfs(struct snd_soc_platform *platform)
313{
314 struct dentry *debugfs_card_root = platform->card->debugfs_card_root;
315
316 platform->debugfs_platform_root = debugfs_create_dir(platform->name,
317 debugfs_card_root);
318 if (!platform->debugfs_platform_root) {
319 dev_warn(platform->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000320 "ASoC: Failed to create platform debugfs directory\n");
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +0000321 return;
322 }
323
324 snd_soc_dapm_debugfs_init(&platform->dapm,
325 platform->debugfs_platform_root);
326}
327
328static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
329{
330 debugfs_remove_recursive(platform->debugfs_platform_root);
331}
332
Mark Brownc3c5a192010-09-15 18:15:14 +0100333static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
334 size_t count, loff_t *ppos)
335{
336 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100337 ssize_t len, ret = 0;
Mark Brownc3c5a192010-09-15 18:15:14 +0100338 struct snd_soc_codec *codec;
339
340 if (!buf)
341 return -ENOMEM;
342
Mark Brown2b194f9d2010-10-13 10:52:16 +0100343 list_for_each_entry(codec, &codec_list, list) {
344 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
345 codec->name);
346 if (len >= 0)
347 ret += len;
348 if (ret > PAGE_SIZE) {
349 ret = PAGE_SIZE;
350 break;
351 }
352 }
Mark Brownc3c5a192010-09-15 18:15:14 +0100353
354 if (ret >= 0)
355 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
356
357 kfree(buf);
358
359 return ret;
360}
361
362static const struct file_operations codec_list_fops = {
363 .read = codec_list_read_file,
364 .llseek = default_llseek,/* read accesses f_pos */
365};
366
Mark Brownf3208782010-09-15 18:19:07 +0100367static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
368 size_t count, loff_t *ppos)
369{
370 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100371 ssize_t len, ret = 0;
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100372 struct snd_soc_component *component;
Mark Brownf3208782010-09-15 18:19:07 +0100373 struct snd_soc_dai *dai;
374
375 if (!buf)
376 return -ENOMEM;
377
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100378 list_for_each_entry(component, &component_list, list) {
379 list_for_each_entry(dai, &component->dai_list, list) {
380 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
381 dai->name);
382 if (len >= 0)
383 ret += len;
384 if (ret > PAGE_SIZE) {
385 ret = PAGE_SIZE;
386 break;
387 }
Mark Brown2b194f9d2010-10-13 10:52:16 +0100388 }
389 }
Mark Brownf3208782010-09-15 18:19:07 +0100390
Mark Brown2b194f9d2010-10-13 10:52:16 +0100391 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
Mark Brownf3208782010-09-15 18:19:07 +0100392
393 kfree(buf);
394
395 return ret;
396}
397
398static const struct file_operations dai_list_fops = {
399 .read = dai_list_read_file,
400 .llseek = default_llseek,/* read accesses f_pos */
401};
402
Mark Brown19c7ac22010-09-15 18:22:40 +0100403static ssize_t platform_list_read_file(struct file *file,
404 char __user *user_buf,
405 size_t count, loff_t *ppos)
406{
407 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
Mark Brown2b194f9d2010-10-13 10:52:16 +0100408 ssize_t len, ret = 0;
Mark Brown19c7ac22010-09-15 18:22:40 +0100409 struct snd_soc_platform *platform;
410
411 if (!buf)
412 return -ENOMEM;
413
Mark Brown2b194f9d2010-10-13 10:52:16 +0100414 list_for_each_entry(platform, &platform_list, list) {
415 len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
416 platform->name);
417 if (len >= 0)
418 ret += len;
419 if (ret > PAGE_SIZE) {
420 ret = PAGE_SIZE;
421 break;
422 }
423 }
Mark Brown19c7ac22010-09-15 18:22:40 +0100424
Mark Brown2b194f9d2010-10-13 10:52:16 +0100425 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
Mark Brown19c7ac22010-09-15 18:22:40 +0100426
427 kfree(buf);
428
429 return ret;
430}
431
432static const struct file_operations platform_list_fops = {
433 .read = platform_list_read_file,
434 .llseek = default_llseek,/* read accesses f_pos */
435};
436
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200437static void soc_init_card_debugfs(struct snd_soc_card *card)
438{
439 card->debugfs_card_root = debugfs_create_dir(card->name,
Mark Brown8a9dab12011-01-10 22:25:21 +0000440 snd_soc_debugfs_root);
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200441 if (!card->debugfs_card_root) {
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200442 dev_warn(card->dev,
Lothar Waßmann7c08be82011-12-09 14:16:29 +0100443 "ASoC: Failed to create card debugfs directory\n");
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200444 return;
445 }
446
447 card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
448 card->debugfs_card_root,
449 &card->pop_time);
450 if (!card->debugfs_pop_time)
451 dev_warn(card->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000452 "ASoC: Failed to create pop time debugfs file\n");
Jarkko Nikulaa6052152010-11-05 20:35:19 +0200453}
454
455static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
456{
457 debugfs_remove_recursive(card->debugfs_card_root);
458}
459
Mark Brown2624d5f2009-11-03 21:56:13 +0000460#else
461
462static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
463{
464}
465
466static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
467{
468}
Axel Linb95fccb2010-11-09 17:06:44 +0800469
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +0000470static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform)
471{
472}
473
474static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform)
475{
476}
477
Axel Linb95fccb2010-11-09 17:06:44 +0800478static inline void soc_init_card_debugfs(struct snd_soc_card *card)
479{
480}
481
482static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
483{
484}
Mark Brown2624d5f2009-11-03 21:56:13 +0000485#endif
486
Liam Girdwood47c88ff2012-04-25 12:12:53 +0100487struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
488 const char *dai_link, int stream)
489{
490 int i;
491
492 for (i = 0; i < card->num_links; i++) {
493 if (card->rtd[i].dai_link->no_pcm &&
494 !strcmp(card->rtd[i].dai_link->name, dai_link))
495 return card->rtd[i].pcm->streams[stream].substream;
496 }
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000497 dev_dbg(card->dev, "ASoC: failed to find dai link %s\n", dai_link);
Liam Girdwood47c88ff2012-04-25 12:12:53 +0100498 return NULL;
499}
500EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
501
502struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
503 const char *dai_link)
504{
505 int i;
506
507 for (i = 0; i < card->num_links; i++) {
508 if (!strcmp(card->rtd[i].dai_link->name, dai_link))
509 return &card->rtd[i];
510 }
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000511 dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link);
Liam Girdwood47c88ff2012-04-25 12:12:53 +0100512 return NULL;
513}
514EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
515
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200516#ifdef CONFIG_SND_SOC_AC97_BUS
517/* unregister ac97 codec */
518static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
519{
520 if (codec->ac97->dev.bus)
521 device_unregister(&codec->ac97->dev);
522 return 0;
523}
524
525/* stop no dev release warning */
526static void soc_ac97_device_release(struct device *dev){}
527
528/* register ac97 codec to bus */
529static int soc_ac97_dev_register(struct snd_soc_codec *codec)
530{
531 int err;
532
533 codec->ac97->dev.bus = &ac97_bus_type;
Mark Brown4ac5c612009-04-01 19:35:01 +0100534 codec->ac97->dev.parent = codec->card->dev;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200535 codec->ac97->dev.release = soc_ac97_device_release;
536
Kay Sieversbb072bf2008-11-02 03:50:35 +0100537 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000538 codec->card->snd_card->number, 0, codec->name);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200539 err = device_register(&codec->ac97->dev);
540 if (err < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000541 dev_err(codec->dev, "ASoC: Can't register ac97 bus\n");
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200542 codec->ac97->dev.bus = NULL;
543 return err;
544 }
545 return 0;
546}
547#endif
548
Richard Fitzgerald9d58a072013-08-05 13:17:28 +0100549static void codec2codec_close_delayed_work(struct work_struct *work)
550{
551 /* Currently nothing to do for c2c links
552 * Since c2c links are internal nodes in the DAPM graph and
553 * don't interface with the outside world or application layer
554 * we don't have to do any special handling on close.
555 */
556}
557
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000558#ifdef CONFIG_PM_SLEEP
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200559/* powers down audio subsystem for suspend */
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000560int snd_soc_suspend(struct device *dev)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200561{
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000562 struct snd_soc_card *card = dev_get_drvdata(dev);
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200563 struct snd_soc_codec *codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200564 int i;
565
Daniel Macke3509ff2009-06-03 17:44:49 +0200566 /* If the initialization of this soc device failed, there is no codec
567 * associated with it. Just bail out in this case.
568 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000569 if (list_empty(&card->codec_dev_list))
Daniel Macke3509ff2009-06-03 17:44:49 +0200570 return 0;
571
Andy Green6ed25972008-06-13 16:24:05 +0100572 /* Due to the resume being scheduled into a workqueue we could
573 * suspend before that's finished - wait for it to complete.
574 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000575 snd_power_lock(card->snd_card);
576 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
577 snd_power_unlock(card->snd_card);
Andy Green6ed25972008-06-13 16:24:05 +0100578
579 /* we're going to block userspace touching us until resume completes */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000580 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
Andy Green6ed25972008-06-13 16:24:05 +0100581
Mark Browna00f90f2010-12-02 16:24:24 +0000582 /* mute any active DACs */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000583 for (i = 0; i < card->num_rtd; i++) {
584 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
585 struct snd_soc_dai_driver *drv = dai->driver;
Mark Brown3efab7d2010-05-09 13:25:43 +0100586
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000587 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100588 continue;
589
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000590 if (drv->ops->digital_mute && dai->playback_active)
591 drv->ops->digital_mute(dai, 1);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200592 }
593
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100594 /* suspend all pcms */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000595 for (i = 0; i < card->num_rtd; i++) {
596 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100597 continue;
598
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000599 snd_pcm_suspend_all(card->rtd[i].pcm);
Mark Brown3efab7d2010-05-09 13:25:43 +0100600 }
Liam Girdwood4ccab3e2008-01-10 14:39:01 +0100601
Mark Brown87506542008-11-18 20:50:34 +0000602 if (card->suspend_pre)
Mark Brown70b2ac12011-01-26 14:05:25 +0000603 card->suspend_pre(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200604
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000605 for (i = 0; i < card->num_rtd; i++) {
606 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
607 struct snd_soc_platform *platform = card->rtd[i].platform;
Mark Brown3efab7d2010-05-09 13:25:43 +0100608
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000609 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100610 continue;
611
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000612 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
613 cpu_dai->driver->suspend(cpu_dai);
614 if (platform->driver->suspend && !platform->suspended) {
615 platform->driver->suspend(cpu_dai);
616 platform->suspended = 1;
Mark Brown1547aba2010-05-07 21:11:40 +0100617 }
618 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200619
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000620 /* close any waiting streams and save state */
621 for (i = 0; i < card->num_rtd; i++) {
Tejun Heo43829732012-08-20 14:51:24 -0700622 flush_delayed_work(&card->rtd[i].delayed_work);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200623 card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000624 }
Mark Brown3efab7d2010-05-09 13:25:43 +0100625
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000626 for (i = 0; i < card->num_rtd; i++) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000627
628 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100629 continue;
630
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800631 snd_soc_dapm_stream_event(&card->rtd[i],
632 SNDRV_PCM_STREAM_PLAYBACK,
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800633 SND_SOC_DAPM_STREAM_SUSPEND);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000634
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800635 snd_soc_dapm_stream_event(&card->rtd[i],
636 SNDRV_PCM_STREAM_CAPTURE,
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800637 SND_SOC_DAPM_STREAM_SUSPEND);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000638 }
639
Mark Browne2d32ff2012-08-31 17:38:32 -0700640 /* Recheck all analogue paths too */
641 dapm_mark_io_dirty(&card->dapm);
642 snd_soc_dapm_sync(&card->dapm);
643
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000644 /* suspend all CODECs */
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200645 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000646 /* If there are paths active then the CODEC will be held with
647 * bias _ON and should not be suspended. */
648 if (!codec->suspended && codec->driver->suspend) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200649 switch (codec->dapm.bias_level) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000650 case SND_SOC_BIAS_STANDBY:
Mark Brown125a25d2012-01-31 15:49:10 +0000651 /*
652 * If the CODEC is capable of idle
653 * bias off then being in STANDBY
654 * means it's doing something,
655 * otherwise fall through.
656 */
657 if (codec->dapm.idle_bias_off) {
658 dev_dbg(codec->dev,
Michał Mirosław10e8aa92013-05-04 22:21:38 +0200659 "ASoC: idle_bias_off CODEC on over suspend\n");
Mark Brown125a25d2012-01-31 15:49:10 +0000660 break;
661 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000662 case SND_SOC_BIAS_OFF:
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +0100663 codec->driver->suspend(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000664 codec->suspended = 1;
Mark Brown7be4ba22011-07-18 13:17:13 +0900665 codec->cache_sync = 1;
Mark Brownda8b8e02012-09-12 12:21:52 +0800666 if (codec->using_regmap)
667 regcache_mark_dirty(codec->control_data);
Nicolin Chen988e8cc2013-11-04 14:57:31 +0800668 /* deactivate pins to sleep state */
669 pinctrl_pm_select_sleep_state(codec->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000670 break;
671 default:
Michał Mirosław10e8aa92013-05-04 22:21:38 +0200672 dev_dbg(codec->dev,
673 "ASoC: CODEC is on over suspend\n");
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000674 break;
675 }
676 }
677 }
678
679 for (i = 0; i < card->num_rtd; i++) {
680 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
681
682 if (card->rtd[i].dai_link->ignore_suspend)
683 continue;
684
685 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
686 cpu_dai->driver->suspend(cpu_dai);
Nicolin Chen988e8cc2013-11-04 14:57:31 +0800687
688 /* deactivate pins to sleep state */
689 pinctrl_pm_select_sleep_state(cpu_dai->dev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200690 }
691
Mark Brown87506542008-11-18 20:50:34 +0000692 if (card->suspend_post)
Mark Brown70b2ac12011-01-26 14:05:25 +0000693 card->suspend_post(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200694
695 return 0;
696}
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000697EXPORT_SYMBOL_GPL(snd_soc_suspend);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200698
Andy Green6ed25972008-06-13 16:24:05 +0100699/* deferred resume work, so resume can complete before we finished
700 * setting our codec back up, which can be very slow on I2C
701 */
702static void soc_resume_deferred(struct work_struct *work)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200703{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000704 struct snd_soc_card *card =
705 container_of(work, struct snd_soc_card, deferred_resume_work);
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200706 struct snd_soc_codec *codec;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200707 int i;
708
Andy Green6ed25972008-06-13 16:24:05 +0100709 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
710 * so userspace apps are blocked from touching us
711 */
712
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000713 dev_dbg(card->dev, "ASoC: starting resume work\n");
Andy Green6ed25972008-06-13 16:24:05 +0100714
Mark Brown99497882010-05-07 20:24:05 +0100715 /* Bring us up into D2 so that DAPM starts enabling things */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000716 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
Mark Brown99497882010-05-07 20:24:05 +0100717
Mark Brown87506542008-11-18 20:50:34 +0000718 if (card->resume_pre)
Mark Brown70b2ac12011-01-26 14:05:25 +0000719 card->resume_pre(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200720
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000721 /* resume AC97 DAIs */
722 for (i = 0; i < card->num_rtd; i++) {
723 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
Mark Brown3efab7d2010-05-09 13:25:43 +0100724
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000725 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100726 continue;
727
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000728 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
729 cpu_dai->driver->resume(cpu_dai);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200730 }
731
Jarkko Nikula2eea3922010-11-25 17:47:38 +0200732 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000733 /* If the CODEC was idle over suspend then it will have been
734 * left with bias OFF or STANDBY and suspended so we must now
735 * resume. Otherwise the suspend was suppressed.
736 */
737 if (codec->driver->resume && codec->suspended) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200738 switch (codec->dapm.bias_level) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000739 case SND_SOC_BIAS_STANDBY:
740 case SND_SOC_BIAS_OFF:
741 codec->driver->resume(codec);
742 codec->suspended = 0;
743 break;
744 default:
Michał Mirosław10e8aa92013-05-04 22:21:38 +0200745 dev_dbg(codec->dev,
746 "ASoC: CODEC was on over suspend\n");
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000747 break;
748 }
Mark Brown1547aba2010-05-07 21:11:40 +0100749 }
750 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200751
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000752 for (i = 0; i < card->num_rtd; i++) {
Mark Brown3efab7d2010-05-09 13:25:43 +0100753
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000754 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100755 continue;
756
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800757 snd_soc_dapm_stream_event(&card->rtd[i],
Liam Girdwoodd9b09512012-03-07 16:32:59 +0000758 SNDRV_PCM_STREAM_PLAYBACK,
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800759 SND_SOC_DAPM_STREAM_RESUME);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000760
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800761 snd_soc_dapm_stream_event(&card->rtd[i],
Liam Girdwoodd9b09512012-03-07 16:32:59 +0000762 SNDRV_PCM_STREAM_CAPTURE,
Mark Brown7bd3a6f2012-02-16 15:03:27 -0800763 SND_SOC_DAPM_STREAM_RESUME);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200764 }
765
Mark Brown3ff3f642008-05-19 12:32:25 +0200766 /* unmute any active DACs */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000767 for (i = 0; i < card->num_rtd; i++) {
768 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
769 struct snd_soc_dai_driver *drv = dai->driver;
Mark Brown3efab7d2010-05-09 13:25:43 +0100770
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000771 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100772 continue;
773
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000774 if (drv->ops->digital_mute && dai->playback_active)
775 drv->ops->digital_mute(dai, 0);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200776 }
777
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000778 for (i = 0; i < card->num_rtd; i++) {
779 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
780 struct snd_soc_platform *platform = card->rtd[i].platform;
Mark Brown3efab7d2010-05-09 13:25:43 +0100781
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000782 if (card->rtd[i].dai_link->ignore_suspend)
Mark Brown3efab7d2010-05-09 13:25:43 +0100783 continue;
784
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000785 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
786 cpu_dai->driver->resume(cpu_dai);
787 if (platform->driver->resume && platform->suspended) {
788 platform->driver->resume(cpu_dai);
789 platform->suspended = 0;
790 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200791 }
792
Mark Brown87506542008-11-18 20:50:34 +0000793 if (card->resume_post)
Mark Brown70b2ac12011-01-26 14:05:25 +0000794 card->resume_post(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200795
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000796 dev_dbg(card->dev, "ASoC: resume work completed\n");
Andy Green6ed25972008-06-13 16:24:05 +0100797
798 /* userspace can access us now we are back as we were before */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000799 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
Mark Browne2d32ff2012-08-31 17:38:32 -0700800
801 /* Recheck all analogue paths too */
802 dapm_mark_io_dirty(&card->dapm);
803 snd_soc_dapm_sync(&card->dapm);
Andy Green6ed25972008-06-13 16:24:05 +0100804}
805
806/* powers up audio subsystem after a suspend */
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000807int snd_soc_resume(struct device *dev)
Andy Green6ed25972008-06-13 16:24:05 +0100808{
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000809 struct snd_soc_card *card = dev_get_drvdata(dev);
Stephen Warren82e14e82011-05-25 14:06:41 -0600810 int i, ac97_control = 0;
Peter Ujfalusib9dd94a2010-02-22 13:27:13 +0200811
Eric Miao5ff1ddf2011-11-23 22:37:00 +0800812 /* If the initialization of this soc device failed, there is no codec
813 * associated with it. Just bail out in this case.
814 */
815 if (list_empty(&card->codec_dev_list))
816 return 0;
817
Nicolin Chen988e8cc2013-11-04 14:57:31 +0800818 /* activate pins from sleep state */
819 for (i = 0; i < card->num_rtd; i++) {
820 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
821 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
822 if (cpu_dai->active)
823 pinctrl_pm_select_default_state(cpu_dai->dev);
824 if (codec_dai->active)
825 pinctrl_pm_select_default_state(codec_dai->dev);
826 }
827
Mark Brown64ab9ba2009-03-31 11:27:03 +0100828 /* AC97 devices might have other drivers hanging off them so
829 * need to resume immediately. Other drivers don't have that
830 * problem and may take a substantial amount of time to resume
831 * due to I/O costs and anti-pop so handle them out of line.
832 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000833 for (i = 0; i < card->num_rtd; i++) {
834 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
Stephen Warren82e14e82011-05-25 14:06:41 -0600835 ac97_control |= cpu_dai->driver->ac97_control;
836 }
837 if (ac97_control) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000838 dev_dbg(dev, "ASoC: Resuming AC97 immediately\n");
Stephen Warren82e14e82011-05-25 14:06:41 -0600839 soc_resume_deferred(&card->deferred_resume_work);
840 } else {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000841 dev_dbg(dev, "ASoC: Scheduling resume work\n");
Stephen Warren82e14e82011-05-25 14:06:41 -0600842 if (!schedule_work(&card->deferred_resume_work))
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000843 dev_err(dev, "ASoC: resume work item may be lost\n");
Mark Brown64ab9ba2009-03-31 11:27:03 +0100844 }
Andy Green6ed25972008-06-13 16:24:05 +0100845
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200846 return 0;
847}
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000848EXPORT_SYMBOL_GPL(snd_soc_resume);
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200849#else
Mark Brown6f8ab4a2011-01-26 14:59:27 +0000850#define snd_soc_suspend NULL
851#define snd_soc_resume NULL
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200852#endif
853
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100854static const struct snd_soc_dai_ops null_dai_ops = {
Barry Song02a06d32009-10-16 18:13:38 +0800855};
856
Misael Lopez Cruz12023a92014-03-21 16:27:25 +0100857static struct snd_soc_codec *soc_find_codec(const struct device_node *codec_of_node,
858 const char *codec_name)
859{
860 struct snd_soc_codec *codec;
861
862 list_for_each_entry(codec, &codec_list, list) {
863 if (codec_of_node) {
864 if (codec->dev->of_node != codec_of_node)
865 continue;
866 } else {
867 if (strcmp(codec->name, codec_name))
868 continue;
869 }
870
871 return codec;
872 }
873
874 return NULL;
875}
876
877static struct snd_soc_dai *soc_find_codec_dai(struct snd_soc_codec *codec,
878 const char *codec_dai_name)
879{
880 struct snd_soc_dai *codec_dai;
881
882 list_for_each_entry(codec_dai, &codec->component.dai_list, list) {
883 if (!strcmp(codec_dai->name, codec_dai_name)) {
884 return codec_dai;
885 }
886 }
887
888 return NULL;
889}
890
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000891static int soc_bind_dai_link(struct snd_soc_card *card, int num)
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200892{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000893 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
894 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100895 struct snd_soc_component *component;
Mark Brown435c5e22008-12-04 15:32:53 +0000896 struct snd_soc_platform *platform;
Misael Lopez Cruz12023a92014-03-21 16:27:25 +0100897 struct snd_soc_dai *cpu_dai;
Mark Brown848dd8b2011-04-27 18:16:32 +0100898 const char *platform_name;
Frank Mandarinodb2a4162006-10-06 18:31:09 +0200899
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000900 dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
Mark Brown63084192008-12-02 15:08:03 +0000901
Mark Brownb19e6e72012-03-14 21:18:39 +0000902 /* Find CPU DAI from registered DAIs*/
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100903 list_for_each_entry(component, &component_list, list) {
Stephen Warrenbc926572012-05-25 18:22:11 -0600904 if (dai_link->cpu_of_node &&
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100905 component->dev->of_node != dai_link->cpu_of_node)
Stephen Warrenbc926572012-05-25 18:22:11 -0600906 continue;
907 if (dai_link->cpu_name &&
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100908 strcmp(dev_name(component->dev), dai_link->cpu_name))
Stephen Warrenbc926572012-05-25 18:22:11 -0600909 continue;
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100910 list_for_each_entry(cpu_dai, &component->dai_list, list) {
911 if (dai_link->cpu_dai_name &&
912 strcmp(cpu_dai->name, dai_link->cpu_dai_name))
913 continue;
Stephen Warren2610ab72011-12-07 13:58:27 -0700914
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +0100915 rtd->cpu_dai = cpu_dai;
916 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000917 }
Mark Brownb19e6e72012-03-14 21:18:39 +0000918
919 if (!rtd->cpu_dai) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000920 dev_err(card->dev, "ASoC: CPU DAI %s not registered\n",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000921 dai_link->cpu_dai_name);
Mark Brownb19e6e72012-03-14 21:18:39 +0000922 return -EPROBE_DEFER;
Mark Brownc5af3a22008-11-28 13:29:45 +0000923 }
924
Misael Lopez Cruz12023a92014-03-21 16:27:25 +0100925 /* Find CODEC from registered list */
926 rtd->codec = soc_find_codec(dai_link->codec_of_node,
927 dai_link->codec_name);
Mark Brownb19e6e72012-03-14 21:18:39 +0000928 if (!rtd->codec) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000929 dev_err(card->dev, "ASoC: CODEC %s not registered\n",
Mark Brownb19e6e72012-03-14 21:18:39 +0000930 dai_link->codec_name);
931 return -EPROBE_DEFER;
932 }
Mark Brown848dd8b2011-04-27 18:16:32 +0100933
Misael Lopez Cruz12023a92014-03-21 16:27:25 +0100934 /* Find CODEC DAI from registered list */
935 rtd->codec_dai = soc_find_codec_dai(rtd->codec,
936 dai_link->codec_dai_name);
937 if (!rtd->codec_dai) {
938 dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
939 dai_link->codec_dai_name);
940 return -EPROBE_DEFER;
941 }
942
Mark Brown848dd8b2011-04-27 18:16:32 +0100943 /* if there's no platform we match on the empty platform */
944 platform_name = dai_link->platform_name;
Stephen Warren5a504962011-12-21 10:40:59 -0700945 if (!platform_name && !dai_link->platform_of_node)
Mark Brown848dd8b2011-04-27 18:16:32 +0100946 platform_name = "snd-soc-dummy";
947
Mark Brownb19e6e72012-03-14 21:18:39 +0000948 /* find one from the set of registered platforms */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000949 list_for_each_entry(platform, &platform_list, list) {
Stephen Warren5a504962011-12-21 10:40:59 -0700950 if (dai_link->platform_of_node) {
951 if (platform->dev->of_node !=
952 dai_link->platform_of_node)
953 continue;
954 } else {
955 if (strcmp(platform->name, platform_name))
956 continue;
957 }
Stephen Warren2610ab72011-12-07 13:58:27 -0700958
959 rtd->platform = platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000960 }
Mark Brownb19e6e72012-03-14 21:18:39 +0000961 if (!rtd->platform) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000962 dev_err(card->dev, "ASoC: platform %s not registered\n",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000963 dai_link->platform_name);
Mark Brownb19e6e72012-03-14 21:18:39 +0000964 return -EPROBE_DEFER;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000965 }
Mark Brownb19e6e72012-03-14 21:18:39 +0000966
967 card->num_rtd++;
968
969 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000970}
971
Stephen Warrend12cd192012-06-08 12:34:22 -0600972static int soc_remove_platform(struct snd_soc_platform *platform)
973{
974 int ret;
975
976 if (platform->driver->remove) {
977 ret = platform->driver->remove(platform);
978 if (ret < 0)
Liam Girdwoodf110bfc2012-11-19 14:47:09 +0000979 dev_err(platform->dev, "ASoC: failed to remove %d\n",
980 ret);
Stephen Warrend12cd192012-06-08 12:34:22 -0600981 }
982
983 /* Make sure all DAPM widgets are freed */
984 snd_soc_dapm_free(&platform->dapm);
985
986 soc_cleanup_platform_debugfs(platform);
987 platform->probed = 0;
988 list_del(&platform->card_list);
989 module_put(platform->dev->driver->owner);
990
991 return 0;
992}
993
Jarkko Nikula589c3562010-12-06 16:27:07 +0200994static void soc_remove_codec(struct snd_soc_codec *codec)
995{
996 int err;
997
998 if (codec->driver->remove) {
999 err = codec->driver->remove(codec);
1000 if (err < 0)
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001001 dev_err(codec->dev, "ASoC: failed to remove %d\n", err);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001002 }
1003
1004 /* Make sure all DAPM widgets are freed */
1005 snd_soc_dapm_free(&codec->dapm);
1006
1007 soc_cleanup_codec_debugfs(codec);
1008 codec->probed = 0;
1009 list_del(&codec->card_list);
1010 module_put(codec->dev->driver->owner);
1011}
1012
Misael Lopez Cruzb0aa88a2014-03-21 16:27:26 +01001013static void soc_remove_codec_dai(struct snd_soc_dai *codec_dai, int order)
1014{
1015 int err;
1016
1017 if (codec_dai && codec_dai->probed &&
1018 codec_dai->driver->remove_order == order) {
1019 if (codec_dai->driver->remove) {
1020 err = codec_dai->driver->remove(codec_dai);
1021 if (err < 0)
1022 dev_err(codec_dai->dev,
1023 "ASoC: failed to remove %s: %d\n",
1024 codec_dai->name, err);
1025 }
1026 codec_dai->probed = 0;
1027 list_del(&codec_dai->card_list);
1028 }
1029}
1030
Stephen Warren62ae68f2012-06-08 12:34:23 -06001031static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001032{
1033 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001034 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1035 int err;
1036
1037 /* unregister the rtd device */
1038 if (rtd->dev_registered) {
Mark Brown36ae1a92012-01-06 17:12:45 -08001039 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
1040 device_remove_file(rtd->dev, &dev_attr_codec_reg);
1041 device_unregister(rtd->dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001042 rtd->dev_registered = 0;
1043 }
1044
1045 /* remove the CODEC DAI */
Misael Lopez Cruzb0aa88a2014-03-21 16:27:26 +01001046 soc_remove_codec_dai(codec_dai, order);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001047
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001048 /* remove the cpu_dai */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001049 if (cpu_dai && cpu_dai->probed &&
1050 cpu_dai->driver->remove_order == order) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001051 if (cpu_dai->driver->remove) {
1052 err = cpu_dai->driver->remove(cpu_dai);
1053 if (err < 0)
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001054 dev_err(cpu_dai->dev,
1055 "ASoC: failed to remove %s: %d\n",
1056 cpu_dai->name, err);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001057 }
1058 cpu_dai->probed = 0;
1059 list_del(&cpu_dai->card_list);
Stephen Warrena9db7db2012-06-08 12:34:20 -06001060
Stephen Warren18d75642012-06-08 12:34:21 -06001061 if (!cpu_dai->codec) {
1062 snd_soc_dapm_free(&cpu_dai->dapm);
Stephen Warrena9db7db2012-06-08 12:34:20 -06001063 module_put(cpu_dai->dev->driver->owner);
Stephen Warren18d75642012-06-08 12:34:21 -06001064 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001065 }
1066}
1067
Stephen Warren62ae68f2012-06-08 12:34:23 -06001068static void soc_remove_link_components(struct snd_soc_card *card, int num,
1069 int order)
1070{
1071 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1072 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1073 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1074 struct snd_soc_platform *platform = rtd->platform;
1075 struct snd_soc_codec *codec;
1076
1077 /* remove the platform */
1078 if (platform && platform->probed &&
1079 platform->driver->remove_order == order) {
1080 soc_remove_platform(platform);
1081 }
1082
1083 /* remove the CODEC-side CODEC */
1084 if (codec_dai) {
1085 codec = codec_dai->codec;
1086 if (codec && codec->probed &&
1087 codec->driver->remove_order == order)
1088 soc_remove_codec(codec);
1089 }
1090
1091 /* remove any CPU-side CODEC */
1092 if (cpu_dai) {
1093 codec = cpu_dai->codec;
1094 if (codec && codec->probed &&
1095 codec->driver->remove_order == order)
1096 soc_remove_codec(codec);
1097 }
1098}
1099
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001100static void soc_remove_dai_links(struct snd_soc_card *card)
1101{
Liam Girdwood0168bf02011-06-07 16:08:05 +01001102 int dai, order;
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001103
Liam Girdwood0168bf02011-06-07 16:08:05 +01001104 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1105 order++) {
1106 for (dai = 0; dai < card->num_rtd; dai++)
Stephen Warren62ae68f2012-06-08 12:34:23 -06001107 soc_remove_link_dais(card, dai, order);
Liam Girdwood0168bf02011-06-07 16:08:05 +01001108 }
Stephen Warren62ae68f2012-06-08 12:34:23 -06001109
1110 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1111 order++) {
1112 for (dai = 0; dai < card->num_rtd; dai++)
1113 soc_remove_link_components(card, dai, order);
1114 }
1115
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001116 card->num_rtd = 0;
1117}
1118
Jarkko Nikulaead9b912010-11-13 20:40:44 +02001119static void soc_set_name_prefix(struct snd_soc_card *card,
1120 struct snd_soc_codec *codec)
1121{
1122 int i;
1123
Dimitris Papastamosff819b82010-12-02 14:53:03 +00001124 if (card->codec_conf == NULL)
Jarkko Nikulaead9b912010-11-13 20:40:44 +02001125 return;
1126
Dimitris Papastamosff819b82010-12-02 14:53:03 +00001127 for (i = 0; i < card->num_configs; i++) {
1128 struct snd_soc_codec_conf *map = &card->codec_conf[i];
Jarkko Nikulaead9b912010-11-13 20:40:44 +02001129 if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1130 codec->name_prefix = map->name_prefix;
1131 break;
1132 }
1133 }
1134}
1135
Jarkko Nikula589c3562010-12-06 16:27:07 +02001136static int soc_probe_codec(struct snd_soc_card *card,
1137 struct snd_soc_codec *codec)
1138{
1139 int ret = 0;
Mark Brown89b95ac02011-03-07 16:38:44 +00001140 const struct snd_soc_codec_driver *driver = codec->driver;
Mark Brown888df392012-02-16 19:37:51 -08001141 struct snd_soc_dai *dai;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001142
1143 codec->card = card;
1144 codec->dapm.card = card;
1145 soc_set_name_prefix(card, codec);
1146
Jarkko Nikula70d29332011-01-27 16:24:22 +02001147 if (!try_module_get(codec->dev->driver->owner))
1148 return -ENODEV;
1149
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001150 soc_init_codec_debugfs(codec);
1151
Lars-Peter Clausen77530152011-05-05 16:59:09 +02001152 if (driver->dapm_widgets)
1153 snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
1154 driver->num_dapm_widgets);
1155
Mark Brown888df392012-02-16 19:37:51 -08001156 /* Create DAPM widgets for each DAI stream */
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +01001157 list_for_each_entry(dai, &codec->component.dai_list, list)
Mark Brown888df392012-02-16 19:37:51 -08001158 snd_soc_dapm_new_dai_widgets(&codec->dapm, dai);
Mark Brown888df392012-02-16 19:37:51 -08001159
Mark Brown33c5f962011-08-22 18:40:30 +01001160 codec->dapm.idle_bias_off = driver->idle_bias_off;
1161
Xiubo Lia32c17b2014-03-11 12:43:22 +08001162 if (!codec->write && dev_get_regmap(codec->dev, NULL)) {
1163 /* Set the default I/O up try regmap */
1164 ret = snd_soc_codec_set_cache_io(codec, NULL);
1165 if (ret < 0) {
1166 dev_err(codec->dev,
1167 "Failed to set cache I/O: %d\n", ret);
1168 goto err_probe;
1169 }
1170 }
Xiubo Life2265e2014-02-27 17:49:52 +08001171
Mark Brown89b95ac02011-03-07 16:38:44 +00001172 if (driver->probe) {
1173 ret = driver->probe(codec);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001174 if (ret < 0) {
1175 dev_err(codec->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001176 "ASoC: failed to probe CODEC %d\n", ret);
Jarkko Nikula70d29332011-01-27 16:24:22 +02001177 goto err_probe;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001178 }
Chuansheng Liuff541f42012-12-21 18:17:12 +08001179 WARN(codec->dapm.idle_bias_off &&
1180 codec->dapm.bias_level != SND_SOC_BIAS_OFF,
Michał Mirosław10e8aa92013-05-04 22:21:38 +02001181 "codec %s can not start from non-off bias with idle_bias_off==1\n",
1182 codec->name);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001183 }
1184
Mark Brownb7af1da2011-04-07 19:18:44 +09001185 if (driver->controls)
Liam Girdwood022658b2012-02-03 17:43:09 +00001186 snd_soc_add_codec_controls(codec, driver->controls,
Mark Brownb7af1da2011-04-07 19:18:44 +09001187 driver->num_controls);
Mark Brown89b95ac02011-03-07 16:38:44 +00001188 if (driver->dapm_routes)
1189 snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
1190 driver->num_dapm_routes);
1191
Jarkko Nikula589c3562010-12-06 16:27:07 +02001192 /* mark codec as probed and add to card codec list */
1193 codec->probed = 1;
1194 list_add(&codec->card_list, &card->codec_dev_list);
Jarkko Nikula7be31be82010-12-14 12:18:32 +02001195 list_add(&codec->dapm.list, &card->dapm_list);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001196
Jarkko Nikula70d29332011-01-27 16:24:22 +02001197 return 0;
1198
1199err_probe:
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001200 soc_cleanup_codec_debugfs(codec);
Jarkko Nikula70d29332011-01-27 16:24:22 +02001201 module_put(codec->dev->driver->owner);
1202
Jarkko Nikula589c3562010-12-06 16:27:07 +02001203 return ret;
1204}
1205
Liam Girdwood956245e2011-07-01 16:54:08 +01001206static int soc_probe_platform(struct snd_soc_card *card,
1207 struct snd_soc_platform *platform)
1208{
1209 int ret = 0;
1210 const struct snd_soc_platform_driver *driver = platform->driver;
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +01001211 struct snd_soc_component *component;
Liam Girdwoodbe09ad92012-03-07 11:47:41 +00001212 struct snd_soc_dai *dai;
Liam Girdwood956245e2011-07-01 16:54:08 +01001213
1214 platform->card = card;
Liam Girdwoodb7950642011-07-04 22:10:52 +01001215 platform->dapm.card = card;
Liam Girdwood956245e2011-07-01 16:54:08 +01001216
1217 if (!try_module_get(platform->dev->driver->owner))
1218 return -ENODEV;
1219
Sebastien Guiriec731f1ab2012-02-15 15:25:31 +00001220 soc_init_platform_debugfs(platform);
1221
Liam Girdwoodcb2cf612011-07-04 22:10:53 +01001222 if (driver->dapm_widgets)
1223 snd_soc_dapm_new_controls(&platform->dapm,
1224 driver->dapm_widgets, driver->num_dapm_widgets);
1225
Liam Girdwoodbe09ad92012-03-07 11:47:41 +00001226 /* Create DAPM widgets for each DAI stream */
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +01001227 list_for_each_entry(component, &component_list, list) {
1228 if (component->dev != platform->dev)
Liam Girdwoodbe09ad92012-03-07 11:47:41 +00001229 continue;
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +01001230 list_for_each_entry(dai, &component->dai_list, list)
1231 snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
Liam Girdwoodbe09ad92012-03-07 11:47:41 +00001232 }
1233
Stephen Warren3fec6b62012-04-05 12:28:01 -06001234 platform->dapm.idle_bias_off = 1;
1235
Liam Girdwood956245e2011-07-01 16:54:08 +01001236 if (driver->probe) {
1237 ret = driver->probe(platform);
1238 if (ret < 0) {
1239 dev_err(platform->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001240 "ASoC: failed to probe platform %d\n", ret);
Liam Girdwood956245e2011-07-01 16:54:08 +01001241 goto err_probe;
1242 }
1243 }
1244
Liam Girdwoodcb2cf612011-07-04 22:10:53 +01001245 if (driver->controls)
1246 snd_soc_add_platform_controls(platform, driver->controls,
1247 driver->num_controls);
1248 if (driver->dapm_routes)
1249 snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
1250 driver->num_dapm_routes);
1251
Liam Girdwood956245e2011-07-01 16:54:08 +01001252 /* mark platform as probed and add to card platform list */
1253 platform->probed = 1;
1254 list_add(&platform->card_list, &card->platform_dev_list);
Liam Girdwoodb7950642011-07-04 22:10:52 +01001255 list_add(&platform->dapm.list, &card->dapm_list);
Liam Girdwood956245e2011-07-01 16:54:08 +01001256
1257 return 0;
1258
1259err_probe:
Liam Girdwood02db1102012-03-02 16:13:44 +00001260 soc_cleanup_platform_debugfs(platform);
Liam Girdwood956245e2011-07-01 16:54:08 +01001261 module_put(platform->dev->driver->owner);
1262
1263 return ret;
1264}
1265
Mark Brown36ae1a92012-01-06 17:12:45 -08001266static void rtd_release(struct device *dev)
1267{
1268 kfree(dev);
1269}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001270
Jarkko Nikula589c3562010-12-06 16:27:07 +02001271static int soc_post_component_init(struct snd_soc_card *card,
1272 struct snd_soc_codec *codec,
1273 int num, int dailess)
1274{
1275 struct snd_soc_dai_link *dai_link = NULL;
1276 struct snd_soc_aux_dev *aux_dev = NULL;
1277 struct snd_soc_pcm_runtime *rtd;
Lars-Peter Clausen6479f15ad2014-03-12 15:27:40 +01001278 const char *name;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001279 int ret = 0;
1280
1281 if (!dailess) {
1282 dai_link = &card->dai_link[num];
1283 rtd = &card->rtd[num];
1284 name = dai_link->name;
1285 } else {
1286 aux_dev = &card->aux_dev[num];
1287 rtd = &card->rtd_aux[num];
1288 name = aux_dev->name;
1289 }
Janusz Krzysztofik0962bb22011-02-02 21:11:41 +01001290 rtd->card = card;
Jarkko Nikula589c3562010-12-06 16:27:07 +02001291
Jarkko Nikula589c3562010-12-06 16:27:07 +02001292 /* do machine specific initialization */
1293 if (!dailess && dai_link->init)
1294 ret = dai_link->init(rtd);
1295 else if (dailess && aux_dev->init)
1296 ret = aux_dev->init(&codec->dapm);
1297 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001298 dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001299 return ret;
1300 }
Jarkko Nikula589c3562010-12-06 16:27:07 +02001301
Jarkko Nikula589c3562010-12-06 16:27:07 +02001302 /* register the rtd device */
1303 rtd->codec = codec;
Mark Brown36ae1a92012-01-06 17:12:45 -08001304
1305 rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1306 if (!rtd->dev)
1307 return -ENOMEM;
1308 device_initialize(rtd->dev);
1309 rtd->dev->parent = card->dev;
1310 rtd->dev->release = rtd_release;
1311 rtd->dev->init_name = name;
1312 dev_set_drvdata(rtd->dev, rtd);
Liam Girdwoodb8c0dab2011-06-09 17:04:39 +01001313 mutex_init(&rtd->pcm_mutex);
Liam Girdwood01d75842012-04-25 12:12:49 +01001314 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
1315 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
1316 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
1317 INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
Mark Brown36ae1a92012-01-06 17:12:45 -08001318 ret = device_add(rtd->dev);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001319 if (ret < 0) {
Chuansheng Liu865df9c2012-12-26 00:56:05 +08001320 /* calling put_device() here to free the rtd->dev */
1321 put_device(rtd->dev);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001322 dev_err(card->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001323 "ASoC: failed to register runtime device: %d\n", ret);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001324 return ret;
1325 }
1326 rtd->dev_registered = 1;
1327
1328 /* add DAPM sysfs entries for this codec */
Mark Brown36ae1a92012-01-06 17:12:45 -08001329 ret = snd_soc_dapm_sys_add(rtd->dev);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001330 if (ret < 0)
1331 dev_err(codec->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001332 "ASoC: failed to add codec dapm sysfs entries: %d\n", ret);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001333
1334 /* add codec sysfs entries */
Mark Brown36ae1a92012-01-06 17:12:45 -08001335 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001336 if (ret < 0)
1337 dev_err(codec->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001338 "ASoC: failed to add codec sysfs files: %d\n", ret);
Jarkko Nikula589c3562010-12-06 16:27:07 +02001339
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01001340#ifdef CONFIG_DEBUG_FS
1341 /* add DPCM sysfs entries */
Liam Girdwoodcd0f8912012-04-30 11:05:30 +01001342 if (!dailess && !dai_link->dynamic)
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01001343 goto out;
1344
1345 ret = soc_dpcm_debugfs_add(rtd);
1346 if (ret < 0)
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001347 dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret);
Liam Girdwoodf86dcef2012-04-25 12:12:50 +01001348
1349out:
1350#endif
Jarkko Nikula589c3562010-12-06 16:27:07 +02001351 return 0;
1352}
1353
Stephen Warren62ae68f2012-06-08 12:34:23 -06001354static int soc_probe_link_components(struct snd_soc_card *card, int num,
1355 int order)
1356{
1357 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1358 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1359 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1360 struct snd_soc_platform *platform = rtd->platform;
1361 int ret;
1362
1363 /* probe the CPU-side component, if it is a CODEC */
1364 if (cpu_dai->codec &&
1365 !cpu_dai->codec->probed &&
1366 cpu_dai->codec->driver->probe_order == order) {
1367 ret = soc_probe_codec(card, cpu_dai->codec);
1368 if (ret < 0)
1369 return ret;
1370 }
1371
1372 /* probe the CODEC-side component */
1373 if (!codec_dai->codec->probed &&
1374 codec_dai->codec->driver->probe_order == order) {
1375 ret = soc_probe_codec(card, codec_dai->codec);
1376 if (ret < 0)
1377 return ret;
1378 }
1379
1380 /* probe the platform */
1381 if (!platform->probed &&
1382 platform->driver->probe_order == order) {
1383 ret = soc_probe_platform(card, platform);
1384 if (ret < 0)
1385 return ret;
1386 }
1387
1388 return 0;
1389}
1390
Misael Lopez Cruzb0aa88a2014-03-21 16:27:26 +01001391static int soc_probe_codec_dai(struct snd_soc_card *card,
1392 struct snd_soc_dai *codec_dai,
1393 int order)
1394{
1395 int ret;
1396
1397 if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
1398 if (codec_dai->driver->probe) {
1399 ret = codec_dai->driver->probe(codec_dai);
1400 if (ret < 0) {
1401 dev_err(codec_dai->dev,
1402 "ASoC: failed to probe CODEC DAI %s: %d\n",
1403 codec_dai->name, ret);
1404 return ret;
1405 }
1406 }
1407
1408 /* mark codec_dai as probed and add to card dai list */
1409 codec_dai->probed = 1;
1410 list_add(&codec_dai->card_list, &card->dai_dev_list);
1411 }
1412
1413 return 0;
1414}
1415
Misael Lopez Cruz2436a722014-03-21 16:27:27 +01001416static int soc_link_dai_widgets(struct snd_soc_card *card,
1417 struct snd_soc_dai_link *dai_link,
1418 struct snd_soc_dai *cpu_dai,
1419 struct snd_soc_dai *codec_dai)
1420{
1421 struct snd_soc_dapm_widget *play_w, *capture_w;
1422 int ret;
1423
1424 /* link the DAI widgets */
1425 play_w = codec_dai->playback_widget;
1426 capture_w = cpu_dai->capture_widget;
1427 if (play_w && capture_w) {
1428 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1429 capture_w, play_w);
1430 if (ret != 0) {
1431 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1432 play_w->name, capture_w->name, ret);
1433 return ret;
1434 }
1435 }
1436
1437 play_w = cpu_dai->playback_widget;
1438 capture_w = codec_dai->capture_widget;
1439 if (play_w && capture_w) {
1440 ret = snd_soc_dapm_new_pcm(card, dai_link->params,
1441 capture_w, play_w);
1442 if (ret != 0) {
1443 dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n",
1444 play_w->name, capture_w->name, ret);
1445 return ret;
1446 }
1447 }
1448
1449 return 0;
1450}
1451
Stephen Warren62ae68f2012-06-08 12:34:23 -06001452static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001453{
1454 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1455 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1456 struct snd_soc_codec *codec = rtd->codec;
1457 struct snd_soc_platform *platform = rtd->platform;
Mark Brownc74184e2012-04-04 22:12:09 +01001458 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1459 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001460 int ret;
1461
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001462 dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
Liam Girdwood0168bf02011-06-07 16:08:05 +01001463 card->name, num, order);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001464
1465 /* config components */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001466 cpu_dai->platform = platform;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001467 codec_dai->card = card;
1468 cpu_dai->card = card;
1469
1470 /* set default power off timeout */
1471 rtd->pmdown_time = pmdown_time;
1472
1473 /* probe the cpu_dai */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001474 if (!cpu_dai->probed &&
1475 cpu_dai->driver->probe_order == order) {
Stephen Warrena9db7db2012-06-08 12:34:20 -06001476 if (!cpu_dai->codec) {
1477 cpu_dai->dapm.card = card;
1478 if (!try_module_get(cpu_dai->dev->driver->owner))
1479 return -ENODEV;
Liam Girdwood61b61e32011-05-24 13:57:43 +01001480
Stephen Warren18d75642012-06-08 12:34:21 -06001481 list_add(&cpu_dai->dapm.list, &card->dapm_list);
Stephen Warrena9db7db2012-06-08 12:34:20 -06001482 }
Liam Girdwoodbe09ad92012-03-07 11:47:41 +00001483
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001484 if (cpu_dai->driver->probe) {
1485 ret = cpu_dai->driver->probe(cpu_dai);
1486 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001487 dev_err(cpu_dai->dev,
1488 "ASoC: failed to probe CPU DAI %s: %d\n",
1489 cpu_dai->name, ret);
Liam Girdwood61b61e32011-05-24 13:57:43 +01001490 module_put(cpu_dai->dev->driver->owner);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001491 return ret;
1492 }
1493 }
1494 cpu_dai->probed = 1;
Wolfram Sang1c8371d2011-07-17 18:00:26 +02001495 /* mark cpu_dai as probed and add to card dai list */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001496 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1497 }
1498
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001499 /* probe the CODEC DAI */
Misael Lopez Cruzb0aa88a2014-03-21 16:27:26 +01001500 ret = soc_probe_codec_dai(card, codec_dai, order);
1501 if (ret)
1502 return ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001503
Liam Girdwood0168bf02011-06-07 16:08:05 +01001504 /* complete DAI probe during last probe */
1505 if (order != SND_SOC_COMP_ORDER_LAST)
1506 return 0;
1507
Jarkko Nikula589c3562010-12-06 16:27:07 +02001508 ret = soc_post_component_init(card, codec, num, 0);
1509 if (ret)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001510 return ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001511
Mark Brown36ae1a92012-01-06 17:12:45 -08001512 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001513 if (ret < 0)
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001514 dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
1515 ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001516
Namarta Kohli1245b702012-08-16 17:10:41 +05301517 if (cpu_dai->driver->compress_dai) {
1518 /*create compress_device"*/
1519 ret = soc_new_compress(rtd, num);
Mark Brownc74184e2012-04-04 22:12:09 +01001520 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001521 dev_err(card->dev, "ASoC: can't create compress %s\n",
Namarta Kohli1245b702012-08-16 17:10:41 +05301522 dai_link->stream_name);
Mark Brownc74184e2012-04-04 22:12:09 +01001523 return ret;
1524 }
1525 } else {
Namarta Kohli1245b702012-08-16 17:10:41 +05301526
1527 if (!dai_link->params) {
1528 /* create the pcm */
1529 ret = soc_new_pcm(rtd, num);
1530 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001531 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
Namarta Kohli1245b702012-08-16 17:10:41 +05301532 dai_link->stream_name, ret);
Mark Brownc74184e2012-04-04 22:12:09 +01001533 return ret;
1534 }
Namarta Kohli1245b702012-08-16 17:10:41 +05301535 } else {
Richard Fitzgerald9d58a072013-08-05 13:17:28 +01001536 INIT_DELAYED_WORK(&rtd->delayed_work,
1537 codec2codec_close_delayed_work);
1538
Namarta Kohli1245b702012-08-16 17:10:41 +05301539 /* link the DAI widgets */
Misael Lopez Cruz2436a722014-03-21 16:27:27 +01001540 ret = soc_link_dai_widgets(card, dai_link,
1541 cpu_dai, codec_dai);
1542 if (ret)
1543 return ret;
Mark Brownc74184e2012-04-04 22:12:09 +01001544 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001545 }
1546
1547 /* add platform data for AC97 devices */
1548 if (rtd->codec_dai->driver->ac97_control)
1549 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1550
1551 return 0;
1552}
1553
1554#ifdef CONFIG_SND_SOC_AC97_BUS
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001555static int soc_register_ac97_codec(struct snd_soc_codec *codec,
1556 struct snd_soc_dai *codec_dai)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001557{
1558 int ret;
1559
1560 /* Only instantiate AC97 if not already done by the adaptor
1561 * for the generic AC97 subsystem.
1562 */
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001563 if (codec_dai->driver->ac97_control && !codec->ac97_registered) {
Mika Westerberg0562f782010-10-13 11:30:32 +03001564 /*
1565 * It is possible that the AC97 device is already registered to
1566 * the device subsystem. This happens when the device is created
1567 * via snd_ac97_mixer(). Currently only SoC codec that does so
1568 * is the generic AC97 glue but others migh emerge.
1569 *
1570 * In those cases we don't try to register the device again.
1571 */
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001572 if (!codec->ac97_created)
Mika Westerberg0562f782010-10-13 11:30:32 +03001573 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001574
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001575 ret = soc_ac97_dev_register(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001576 if (ret < 0) {
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001577 dev_err(codec->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001578 "ASoC: AC97 device register failed: %d\n", ret);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001579 return ret;
1580 }
1581
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001582 codec->ac97_registered = 1;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001583 }
1584 return 0;
1585}
1586
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001587static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1588{
1589 return soc_register_ac97_codec(rtd->codec, rtd->codec_dai);
1590}
1591
1592static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001593{
1594 if (codec->ac97_registered) {
1595 soc_ac97_dev_unregister(codec);
1596 codec->ac97_registered = 0;
1597 }
1598}
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001599
1600static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1601{
1602 soc_unregister_ac97_codec(rtd->codec);
1603}
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001604#endif
1605
Mark Brownb19e6e72012-03-14 21:18:39 +00001606static int soc_check_aux_dev(struct snd_soc_card *card, int num)
1607{
1608 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1609 struct snd_soc_codec *codec;
1610
1611 /* find CODEC from registered CODECs*/
1612 list_for_each_entry(codec, &codec_list, list) {
1613 if (!strcmp(codec->name, aux_dev->codec_name))
1614 return 0;
1615 }
1616
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001617 dev_err(card->dev, "ASoC: %s not registered\n", aux_dev->codec_name);
Mark Brownfb099cb2012-08-09 18:44:37 +01001618
Mark Brownb19e6e72012-03-14 21:18:39 +00001619 return -EPROBE_DEFER;
1620}
1621
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001622static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1623{
1624 struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001625 struct snd_soc_codec *codec;
Jarkko Nikula676ad982010-12-03 09:18:22 +02001626 int ret = -ENODEV;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001627
1628 /* find CODEC from registered CODECs*/
1629 list_for_each_entry(codec, &codec_list, list) {
1630 if (!strcmp(codec->name, aux_dev->codec_name)) {
1631 if (codec->probed) {
1632 dev_err(codec->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001633 "ASoC: codec already probed");
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001634 ret = -EBUSY;
1635 goto out;
1636 }
Jarkko Nikula676ad982010-12-03 09:18:22 +02001637 goto found;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001638 }
1639 }
Jarkko Nikula676ad982010-12-03 09:18:22 +02001640 /* codec not found */
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001641 dev_err(card->dev, "ASoC: codec %s not found", aux_dev->codec_name);
Mark Brownb19e6e72012-03-14 21:18:39 +00001642 return -EPROBE_DEFER;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001643
Jarkko Nikula676ad982010-12-03 09:18:22 +02001644found:
Jarkko Nikula589c3562010-12-06 16:27:07 +02001645 ret = soc_probe_codec(card, codec);
1646 if (ret < 0)
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001647 return ret;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001648
Jarkko Nikula589c3562010-12-06 16:27:07 +02001649 ret = soc_post_component_init(card, codec, num, 1);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001650
1651out:
1652 return ret;
1653}
1654
1655static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1656{
1657 struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1658 struct snd_soc_codec *codec = rtd->codec;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001659
1660 /* unregister the rtd device */
1661 if (rtd->dev_registered) {
Mark Brown36ae1a92012-01-06 17:12:45 -08001662 device_remove_file(rtd->dev, &dev_attr_codec_reg);
Chuansheng Liud3bf1562012-12-26 00:57:32 +08001663 device_unregister(rtd->dev);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001664 rtd->dev_registered = 0;
1665 }
1666
Jarkko Nikula589c3562010-12-06 16:27:07 +02001667 if (codec && codec->probed)
1668 soc_remove_codec(codec);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001669}
1670
Lars-Peter Clausenf90fb3f2013-08-31 20:31:15 +02001671static int snd_soc_init_codec_cache(struct snd_soc_codec *codec)
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001672{
1673 int ret;
1674
1675 if (codec->cache_init)
1676 return 0;
1677
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001678 ret = snd_soc_cache_init(codec);
1679 if (ret < 0) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02001680 dev_err(codec->dev,
1681 "ASoC: Failed to set cache compression type: %d\n",
1682 ret);
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001683 return ret;
1684 }
1685 codec->cache_init = 1;
1686 return 0;
1687}
1688
Mark Brownb19e6e72012-03-14 21:18:39 +00001689static int snd_soc_instantiate_card(struct snd_soc_card *card)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001690{
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001691 struct snd_soc_codec *codec;
Mark Brown75d9ac42011-09-27 16:41:01 +01001692 struct snd_soc_dai_link *dai_link;
Mark Brownf04209a2012-04-09 16:29:21 +01001693 int ret, i, order, dai_fmt;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001694
Liam Girdwood01b9d992012-03-07 10:38:25 +00001695 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001696
Mark Brownb19e6e72012-03-14 21:18:39 +00001697 /* bind DAIs */
1698 for (i = 0; i < card->num_links; i++) {
1699 ret = soc_bind_dai_link(card, i);
1700 if (ret != 0)
1701 goto base_error;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001702 }
1703
Mark Brownb19e6e72012-03-14 21:18:39 +00001704 /* check aux_devs too */
1705 for (i = 0; i < card->num_aux_devs; i++) {
1706 ret = soc_check_aux_dev(card, i);
1707 if (ret != 0)
1708 goto base_error;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001709 }
1710
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001711 /* initialize the register cache for each available codec */
1712 list_for_each_entry(codec, &codec_list, list) {
1713 if (codec->cache_init)
1714 continue;
Lars-Peter Clausenf90fb3f2013-08-31 20:31:15 +02001715 ret = snd_soc_init_codec_cache(codec);
Mark Brownb19e6e72012-03-14 21:18:39 +00001716 if (ret < 0)
1717 goto base_error;
Dimitris Papastamosfdf0f542010-12-02 16:11:06 +00001718 }
1719
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001720 /* card bind complete so register a sound card */
Takashi Iwai102b5a82014-01-29 14:42:55 +01001721 ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001722 card->owner, 0, &card->snd_card);
1723 if (ret < 0) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02001724 dev_err(card->dev,
1725 "ASoC: can't create sound card for card %s: %d\n",
1726 card->name, ret);
Mark Brownb19e6e72012-03-14 21:18:39 +00001727 goto base_error;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001728 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001729
Mark Browne37a4972011-03-02 18:21:57 +00001730 card->dapm.bias_level = SND_SOC_BIAS_OFF;
1731 card->dapm.dev = card->dev;
1732 card->dapm.card = card;
1733 list_add(&card->dapm.list, &card->dapm_list);
1734
Lars-Peter Clausend5d1e0b2011-04-30 19:45:49 +02001735#ifdef CONFIG_DEBUG_FS
1736 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
1737#endif
1738
Mark Brown88ee1c62011-02-02 10:43:26 +00001739#ifdef CONFIG_PM_SLEEP
Andy Green6ed25972008-06-13 16:24:05 +01001740 /* deferred resume work */
Mark Brown63084192008-12-02 15:08:03 +00001741 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
Randy Dunlap1301a962008-06-17 19:19:34 +01001742#endif
Andy Green6ed25972008-06-13 16:24:05 +01001743
Mark Brown9a841eb2011-04-12 17:51:37 -07001744 if (card->dapm_widgets)
1745 snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
1746 card->num_dapm_widgets);
1747
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001748 /* initialise the sound card only once */
1749 if (card->probe) {
Mark Browne7361ec2011-01-26 14:17:20 +00001750 ret = card->probe(card);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001751 if (ret < 0)
1752 goto card_probe_error;
1753 }
1754
Stephen Warren62ae68f2012-06-08 12:34:23 -06001755 /* probe all components used by DAI links on this card */
Liam Girdwood0168bf02011-06-07 16:08:05 +01001756 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1757 order++) {
1758 for (i = 0; i < card->num_links; i++) {
Stephen Warren62ae68f2012-06-08 12:34:23 -06001759 ret = soc_probe_link_components(card, i, order);
Liam Girdwood0168bf02011-06-07 16:08:05 +01001760 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001761 dev_err(card->dev,
1762 "ASoC: failed to instantiate card %d\n",
1763 ret);
Stephen Warren62ae68f2012-06-08 12:34:23 -06001764 goto probe_dai_err;
1765 }
1766 }
1767 }
1768
1769 /* probe all DAI links on this card */
1770 for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
1771 order++) {
1772 for (i = 0; i < card->num_links; i++) {
1773 ret = soc_probe_link_dais(card, i, order);
1774 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001775 dev_err(card->dev,
1776 "ASoC: failed to instantiate card %d\n",
1777 ret);
Liam Girdwood0168bf02011-06-07 16:08:05 +01001778 goto probe_dai_err;
1779 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001780 }
1781 }
1782
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001783 for (i = 0; i < card->num_aux_devs; i++) {
1784 ret = soc_probe_aux_dev(card, i);
1785 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001786 dev_err(card->dev,
1787 "ASoC: failed to add auxiliary devices %d\n",
1788 ret);
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001789 goto probe_aux_dev_err;
1790 }
1791 }
1792
Mark Brown888df392012-02-16 19:37:51 -08001793 snd_soc_dapm_link_dai_widgets(card);
Liam Girdwoodb893ea52014-01-08 10:40:19 +00001794 snd_soc_dapm_connect_dai_link_widgets(card);
Mark Brown888df392012-02-16 19:37:51 -08001795
Mark Brownb7af1da2011-04-07 19:18:44 +09001796 if (card->controls)
Liam Girdwood022658b2012-02-03 17:43:09 +00001797 snd_soc_add_card_controls(card, card->controls, card->num_controls);
Mark Brownb7af1da2011-04-07 19:18:44 +09001798
Mark Brownb8ad29d2011-03-02 18:35:51 +00001799 if (card->dapm_routes)
1800 snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1801 card->num_dapm_routes);
1802
Mark Brown75d9ac42011-09-27 16:41:01 +01001803 for (i = 0; i < card->num_links; i++) {
1804 dai_link = &card->dai_link[i];
Mark Brownf04209a2012-04-09 16:29:21 +01001805 dai_fmt = dai_link->dai_fmt;
Mark Brown75d9ac42011-09-27 16:41:01 +01001806
Mark Brownf04209a2012-04-09 16:29:21 +01001807 if (dai_fmt) {
Mark Brown75d9ac42011-09-27 16:41:01 +01001808 ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
Mark Brownf04209a2012-04-09 16:29:21 +01001809 dai_fmt);
Shawn Guo5e4ba562012-03-09 00:59:40 +08001810 if (ret != 0 && ret != -ENOTSUPP)
Mark Brown75d9ac42011-09-27 16:41:01 +01001811 dev_warn(card->rtd[i].codec_dai->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001812 "ASoC: Failed to set DAI format: %d\n",
Mark Brown75d9ac42011-09-27 16:41:01 +01001813 ret);
Mark Brownf04209a2012-04-09 16:29:21 +01001814 }
1815
1816 /* If this is a regular CPU link there will be a platform */
Stephen Warrenfe33d4c2012-05-14 14:47:22 -06001817 if (dai_fmt &&
1818 (dai_link->platform_name || dai_link->platform_of_node)) {
Mark Brownf04209a2012-04-09 16:29:21 +01001819 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1820 dai_fmt);
1821 if (ret != 0 && ret != -ENOTSUPP)
1822 dev_warn(card->rtd[i].cpu_dai->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001823 "ASoC: Failed to set DAI format: %d\n",
Mark Brownf04209a2012-04-09 16:29:21 +01001824 ret);
1825 } else if (dai_fmt) {
1826 /* Flip the polarity for the "CPU" end */
1827 dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
1828 switch (dai_link->dai_fmt &
1829 SND_SOC_DAIFMT_MASTER_MASK) {
1830 case SND_SOC_DAIFMT_CBM_CFM:
1831 dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1832 break;
1833 case SND_SOC_DAIFMT_CBM_CFS:
1834 dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1835 break;
1836 case SND_SOC_DAIFMT_CBS_CFM:
1837 dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1838 break;
1839 case SND_SOC_DAIFMT_CBS_CFS:
1840 dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1841 break;
1842 }
Mark Brown75d9ac42011-09-27 16:41:01 +01001843
1844 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
Mark Brownf04209a2012-04-09 16:29:21 +01001845 dai_fmt);
Shawn Guo5e4ba562012-03-09 00:59:40 +08001846 if (ret != 0 && ret != -ENOTSUPP)
Mark Brown75d9ac42011-09-27 16:41:01 +01001847 dev_warn(card->rtd[i].cpu_dai->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001848 "ASoC: Failed to set DAI format: %d\n",
Mark Brown75d9ac42011-09-27 16:41:01 +01001849 ret);
1850 }
1851 }
1852
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001853 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001854 "%s", card->name);
Liam Girdwood22de71b2011-05-12 16:14:04 +01001855 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1856 "%s", card->long_name ? card->long_name : card->name);
Mark Brownf0e8ed82011-09-20 11:41:54 +01001857 snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
1858 "%s", card->driver_name ? card->driver_name : card->name);
1859 for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
1860 switch (card->snd_card->driver[i]) {
1861 case '_':
1862 case '-':
1863 case '\0':
1864 break;
1865 default:
1866 if (!isalnum(card->snd_card->driver[i]))
1867 card->snd_card->driver[i] = '_';
1868 break;
1869 }
1870 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001871
Mark Brown28e9ad92011-03-02 18:36:34 +00001872 if (card->late_probe) {
1873 ret = card->late_probe(card);
1874 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001875 dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n",
Mark Brown28e9ad92011-03-02 18:36:34 +00001876 card->name, ret);
1877 goto probe_aux_dev_err;
1878 }
1879 }
1880
Stephen Warren16332812011-11-23 12:42:04 -07001881 if (card->fully_routed)
Mark Brownb05d8dc2011-11-27 19:38:34 +00001882 list_for_each_entry(codec, &card->codec_dev_list, card_list)
Stephen Warren16332812011-11-23 12:42:04 -07001883 snd_soc_dapm_auto_nc_codec_pins(codec);
1884
Lars-Peter Clausen824ef822013-08-27 15:51:01 +02001885 snd_soc_dapm_new_widgets(card);
Lars-Peter Clausen8c193b82013-08-27 15:51:00 +02001886
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001887 ret = snd_card_register(card->snd_card);
1888 if (ret < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001889 dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
1890 ret);
Axel Lin6b3ed782010-12-07 16:12:29 +08001891 goto probe_aux_dev_err;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001892 }
1893
1894#ifdef CONFIG_SND_SOC_AC97_BUS
1895 /* register any AC97 codecs */
1896 for (i = 0; i < card->num_rtd; i++) {
Axel Lin6b3ed782010-12-07 16:12:29 +08001897 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1898 if (ret < 0) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02001899 dev_err(card->dev,
1900 "ASoC: failed to register AC97: %d\n", ret);
Axel Lin6b3ed782010-12-07 16:12:29 +08001901 while (--i >= 0)
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01001902 soc_unregister_ac97_dai_link(&card->rtd[i]);
Axel Lin6b3ed782010-12-07 16:12:29 +08001903 goto probe_aux_dev_err;
Mark Brownfe3e78e2009-11-03 22:13:13 +00001904 }
Axel Lin6b3ed782010-12-07 16:12:29 +08001905 }
Mark Brownfe3e78e2009-11-03 22:13:13 +00001906#endif
1907
Mark Brown435c5e22008-12-04 15:32:53 +00001908 card->instantiated = 1;
Mark Brown4f4c0072011-10-07 14:29:19 +01001909 snd_soc_dapm_sync(&card->dapm);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001910 mutex_unlock(&card->mutex);
Mark Brownb19e6e72012-03-14 21:18:39 +00001911
1912 return 0;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001913
Jarkko Nikula2eea3922010-11-25 17:47:38 +02001914probe_aux_dev_err:
1915 for (i = 0; i < card->num_aux_devs; i++)
1916 soc_remove_aux_dev(card, i);
1917
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001918probe_dai_err:
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001919 soc_remove_dai_links(card);
Mark Brownfe3e78e2009-11-03 22:13:13 +00001920
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001921card_probe_error:
Mark Brown87506542008-11-18 20:50:34 +00001922 if (card->remove)
Mark Browne7361ec2011-01-26 14:17:20 +00001923 card->remove(card);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001924
1925 snd_card_free(card->snd_card);
1926
Mark Brownb19e6e72012-03-14 21:18:39 +00001927base_error:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001928 mutex_unlock(&card->mutex);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001929
Mark Brownb19e6e72012-03-14 21:18:39 +00001930 return ret;
Mark Brown435c5e22008-12-04 15:32:53 +00001931}
1932
1933/* probes a new socdev */
1934static int soc_probe(struct platform_device *pdev)
1935{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001936 struct snd_soc_card *card = platform_get_drvdata(pdev);
Mark Brown435c5e22008-12-04 15:32:53 +00001937
Vinod Koul70a7ca32011-01-14 19:22:48 +05301938 /*
1939 * no card, so machine driver should be registering card
1940 * we should not be here in that case so ret error
1941 */
1942 if (!card)
1943 return -EINVAL;
1944
Mark Brownfe4085e2012-03-02 13:07:41 +00001945 dev_warn(&pdev->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00001946 "ASoC: machine %s should use snd_soc_register_card()\n",
Mark Brownfe4085e2012-03-02 13:07:41 +00001947 card->name);
1948
Mark Brown435c5e22008-12-04 15:32:53 +00001949 /* Bodge while we unpick instantiation */
1950 card->dev = &pdev->dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001951
Mark Brown28d528c2012-08-09 18:45:23 +01001952 return snd_soc_register_card(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001953}
1954
Vinod Koulb0e26482011-01-13 22:48:02 +05301955static int soc_cleanup_card_resources(struct snd_soc_card *card)
1956{
Vinod Koulb0e26482011-01-13 22:48:02 +05301957 int i;
1958
1959 /* make sure any delayed work runs */
1960 for (i = 0; i < card->num_rtd; i++) {
1961 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
Tejun Heo43829732012-08-20 14:51:24 -07001962 flush_delayed_work(&rtd->delayed_work);
Vinod Koulb0e26482011-01-13 22:48:02 +05301963 }
1964
1965 /* remove auxiliary devices */
1966 for (i = 0; i < card->num_aux_devs; i++)
1967 soc_remove_aux_dev(card, i);
1968
1969 /* remove and free each DAI */
Kuninori Morimoto0671fd82011-04-08 14:50:44 +09001970 soc_remove_dai_links(card);
Vinod Koulb0e26482011-01-13 22:48:02 +05301971
1972 soc_cleanup_card_debugfs(card);
1973
1974 /* remove the card */
1975 if (card->remove)
Mark Browne7361ec2011-01-26 14:17:20 +00001976 card->remove(card);
Vinod Koulb0e26482011-01-13 22:48:02 +05301977
Lars-Peter Clausen0aaae522011-04-30 19:45:47 +02001978 snd_soc_dapm_free(&card->dapm);
1979
Vinod Koulb0e26482011-01-13 22:48:02 +05301980 snd_card_free(card->snd_card);
1981 return 0;
1982
1983}
1984
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001985/* removes a socdev */
1986static int soc_remove(struct platform_device *pdev)
1987{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001988 struct snd_soc_card *card = platform_get_drvdata(pdev);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001989
Mark Brownc5af3a22008-11-28 13:29:45 +00001990 snd_soc_unregister_card(card);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02001991 return 0;
1992}
1993
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001994int snd_soc_poweroff(struct device *dev)
Mark Brown51737472009-06-22 13:16:51 +01001995{
Mark Brown6f8ab4a2011-01-26 14:59:27 +00001996 struct snd_soc_card *card = dev_get_drvdata(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001997 int i;
Mark Brown51737472009-06-22 13:16:51 +01001998
1999 if (!card->instantiated)
Mark Brown416356f2009-06-30 19:05:15 +01002000 return 0;
Mark Brown51737472009-06-22 13:16:51 +01002001
2002 /* Flush out pmdown_time work - we actually do want to run it
2003 * now, we're shutting down so no imminent restart. */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002004 for (i = 0; i < card->num_rtd; i++) {
2005 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
Tejun Heo43829732012-08-20 14:51:24 -07002006 flush_delayed_work(&rtd->delayed_work);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002007 }
Mark Brown51737472009-06-22 13:16:51 +01002008
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002009 snd_soc_dapm_shutdown(card);
Mark Brown416356f2009-06-30 19:05:15 +01002010
Nicolin Chen988e8cc2013-11-04 14:57:31 +08002011 /* deactivate pins to sleep state */
2012 for (i = 0; i < card->num_rtd; i++) {
2013 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
2014 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
2015 pinctrl_pm_select_sleep_state(codec_dai->dev);
2016 pinctrl_pm_select_sleep_state(cpu_dai->dev);
2017 }
2018
Mark Brown416356f2009-06-30 19:05:15 +01002019 return 0;
Mark Brown51737472009-06-22 13:16:51 +01002020}
Mark Brown6f8ab4a2011-01-26 14:59:27 +00002021EXPORT_SYMBOL_GPL(snd_soc_poweroff);
Mark Brown51737472009-06-22 13:16:51 +01002022
Mark Brown6f8ab4a2011-01-26 14:59:27 +00002023const struct dev_pm_ops snd_soc_pm_ops = {
Viresh Kumarb1dd5892012-02-24 16:25:49 +05302024 .suspend = snd_soc_suspend,
2025 .resume = snd_soc_resume,
2026 .freeze = snd_soc_suspend,
2027 .thaw = snd_soc_resume,
Mark Brown6f8ab4a2011-01-26 14:59:27 +00002028 .poweroff = snd_soc_poweroff,
Viresh Kumarb1dd5892012-02-24 16:25:49 +05302029 .restore = snd_soc_resume,
Mark Brown416356f2009-06-30 19:05:15 +01002030};
Stephen Warrendeb26072011-04-05 19:35:30 -06002031EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
Mark Brown416356f2009-06-30 19:05:15 +01002032
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002033/* ASoC platform driver */
2034static struct platform_driver soc_driver = {
2035 .driver = {
2036 .name = "soc-audio",
Kay Sievers8b45a202008-04-14 13:33:36 +02002037 .owner = THIS_MODULE,
Mark Brown6f8ab4a2011-01-26 14:59:27 +00002038 .pm = &snd_soc_pm_ops,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002039 },
2040 .probe = soc_probe,
2041 .remove = soc_remove,
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002042};
2043
Mark Brown096e49d2009-07-05 15:12:22 +01002044/**
2045 * snd_soc_codec_volatile_register: Report if a register is volatile.
2046 *
2047 * @codec: CODEC to query.
2048 * @reg: Register to query.
2049 *
2050 * Boolean function indiciating if a CODEC register is volatile.
2051 */
Mark Brown181e0552011-01-24 14:05:25 +00002052int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
2053 unsigned int reg)
Mark Brown096e49d2009-07-05 15:12:22 +01002054{
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00002055 if (codec->volatile_register)
2056 return codec->volatile_register(codec, reg);
Mark Brown096e49d2009-07-05 15:12:22 +01002057 else
2058 return 0;
2059}
2060EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
2061
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002062/**
Dimitris Papastamos239c9702011-03-24 13:45:18 +00002063 * snd_soc_codec_readable_register: Report if a register is readable.
2064 *
2065 * @codec: CODEC to query.
2066 * @reg: Register to query.
2067 *
2068 * Boolean function indicating if a CODEC register is readable.
2069 */
2070int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
2071 unsigned int reg)
2072{
2073 if (codec->readable_register)
2074 return codec->readable_register(codec, reg);
2075 else
Lars-Peter Clausen63fa0a22011-08-27 18:24:12 +02002076 return 1;
Dimitris Papastamos239c9702011-03-24 13:45:18 +00002077}
2078EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
2079
2080/**
2081 * snd_soc_codec_writable_register: Report if a register is writable.
2082 *
2083 * @codec: CODEC to query.
2084 * @reg: Register to query.
2085 *
2086 * Boolean function indicating if a CODEC register is writable.
2087 */
2088int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
2089 unsigned int reg)
2090{
2091 if (codec->writable_register)
2092 return codec->writable_register(codec, reg);
2093 else
Lars-Peter Clausen63fa0a22011-08-27 18:24:12 +02002094 return 1;
Dimitris Papastamos239c9702011-03-24 13:45:18 +00002095}
2096EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
2097
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01002098int snd_soc_platform_read(struct snd_soc_platform *platform,
2099 unsigned int reg)
2100{
2101 unsigned int ret;
2102
2103 if (!platform->driver->read) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00002104 dev_err(platform->dev, "ASoC: platform has no read back\n");
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01002105 return -1;
2106 }
2107
2108 ret = platform->driver->read(platform, reg);
2109 dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
Liam Girdwooda82ce2a2011-07-04 22:10:50 +01002110 trace_snd_soc_preg_read(platform, reg, ret);
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01002111
2112 return ret;
2113}
2114EXPORT_SYMBOL_GPL(snd_soc_platform_read);
2115
2116int snd_soc_platform_write(struct snd_soc_platform *platform,
2117 unsigned int reg, unsigned int val)
2118{
2119 if (!platform->driver->write) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00002120 dev_err(platform->dev, "ASoC: platform has no write back\n");
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01002121 return -1;
2122 }
2123
2124 dev_dbg(platform->dev, "write %x = %x\n", reg, val);
Liam Girdwooda82ce2a2011-07-04 22:10:50 +01002125 trace_snd_soc_preg_write(platform, reg, val);
Liam Girdwoodf1442bc2011-07-04 11:10:15 +01002126 return platform->driver->write(platform, reg, val);
2127}
2128EXPORT_SYMBOL_GPL(snd_soc_platform_write);
2129
Dimitris Papastamos239c9702011-03-24 13:45:18 +00002130/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002131 * snd_soc_new_ac97_codec - initailise AC97 device
2132 * @codec: audio codec
2133 * @ops: AC97 bus operations
2134 * @num: AC97 codec number
2135 *
2136 * Initialises AC97 codec resources for use by ad-hoc devices only.
2137 */
2138int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
2139 struct snd_ac97_bus_ops *ops, int num)
2140{
2141 mutex_lock(&codec->mutex);
2142
2143 codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
2144 if (codec->ac97 == NULL) {
2145 mutex_unlock(&codec->mutex);
2146 return -ENOMEM;
2147 }
2148
2149 codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
2150 if (codec->ac97->bus == NULL) {
2151 kfree(codec->ac97);
2152 codec->ac97 = NULL;
2153 mutex_unlock(&codec->mutex);
2154 return -ENOMEM;
2155 }
2156
2157 codec->ac97->bus->ops = ops;
2158 codec->ac97->num = num;
Mika Westerberg0562f782010-10-13 11:30:32 +03002159
2160 /*
2161 * Mark the AC97 device to be created by us. This way we ensure that the
2162 * device will be registered with the device subsystem later on.
2163 */
2164 codec->ac97_created = 1;
2165
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002166 mutex_unlock(&codec->mutex);
2167 return 0;
2168}
2169EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
2170
Markus Pargmann741a5092013-08-19 17:05:55 +02002171static struct snd_ac97_reset_cfg snd_ac97_rst_cfg;
2172
2173static void snd_soc_ac97_warm_reset(struct snd_ac97 *ac97)
2174{
2175 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
2176
2177 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_warm_reset);
2178
2179 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 1);
2180
2181 udelay(10);
2182
2183 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
2184
2185 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
2186 msleep(2);
2187}
2188
2189static void snd_soc_ac97_reset(struct snd_ac97 *ac97)
2190{
2191 struct pinctrl *pctl = snd_ac97_rst_cfg.pctl;
2192
2193 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_reset);
2194
2195 gpio_direction_output(snd_ac97_rst_cfg.gpio_sync, 0);
2196 gpio_direction_output(snd_ac97_rst_cfg.gpio_sdata, 0);
2197 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 0);
2198
2199 udelay(10);
2200
2201 gpio_direction_output(snd_ac97_rst_cfg.gpio_reset, 1);
2202
2203 pinctrl_select_state(pctl, snd_ac97_rst_cfg.pstate_run);
2204 msleep(2);
2205}
2206
2207static int snd_soc_ac97_parse_pinctl(struct device *dev,
2208 struct snd_ac97_reset_cfg *cfg)
2209{
2210 struct pinctrl *p;
2211 struct pinctrl_state *state;
2212 int gpio;
2213 int ret;
2214
2215 p = devm_pinctrl_get(dev);
2216 if (IS_ERR(p)) {
2217 dev_err(dev, "Failed to get pinctrl\n");
2218 return PTR_RET(p);
2219 }
2220 cfg->pctl = p;
2221
2222 state = pinctrl_lookup_state(p, "ac97-reset");
2223 if (IS_ERR(state)) {
2224 dev_err(dev, "Can't find pinctrl state ac97-reset\n");
2225 return PTR_RET(state);
2226 }
2227 cfg->pstate_reset = state;
2228
2229 state = pinctrl_lookup_state(p, "ac97-warm-reset");
2230 if (IS_ERR(state)) {
2231 dev_err(dev, "Can't find pinctrl state ac97-warm-reset\n");
2232 return PTR_RET(state);
2233 }
2234 cfg->pstate_warm_reset = state;
2235
2236 state = pinctrl_lookup_state(p, "ac97-running");
2237 if (IS_ERR(state)) {
2238 dev_err(dev, "Can't find pinctrl state ac97-running\n");
2239 return PTR_RET(state);
2240 }
2241 cfg->pstate_run = state;
2242
2243 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 0);
2244 if (gpio < 0) {
2245 dev_err(dev, "Can't find ac97-sync gpio\n");
2246 return gpio;
2247 }
2248 ret = devm_gpio_request(dev, gpio, "AC97 link sync");
2249 if (ret) {
2250 dev_err(dev, "Failed requesting ac97-sync gpio\n");
2251 return ret;
2252 }
2253 cfg->gpio_sync = gpio;
2254
2255 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 1);
2256 if (gpio < 0) {
2257 dev_err(dev, "Can't find ac97-sdata gpio %d\n", gpio);
2258 return gpio;
2259 }
2260 ret = devm_gpio_request(dev, gpio, "AC97 link sdata");
2261 if (ret) {
2262 dev_err(dev, "Failed requesting ac97-sdata gpio\n");
2263 return ret;
2264 }
2265 cfg->gpio_sdata = gpio;
2266
2267 gpio = of_get_named_gpio(dev->of_node, "ac97-gpios", 2);
2268 if (gpio < 0) {
2269 dev_err(dev, "Can't find ac97-reset gpio\n");
2270 return gpio;
2271 }
2272 ret = devm_gpio_request(dev, gpio, "AC97 link reset");
2273 if (ret) {
2274 dev_err(dev, "Failed requesting ac97-reset gpio\n");
2275 return ret;
2276 }
2277 cfg->gpio_reset = gpio;
2278
2279 return 0;
2280}
2281
Mark Brownb047e1c2013-06-26 12:45:59 +01002282struct snd_ac97_bus_ops *soc_ac97_ops;
Kevin Hilmanf74b5e22013-06-28 11:17:49 -07002283EXPORT_SYMBOL_GPL(soc_ac97_ops);
Mark Brownb047e1c2013-06-26 12:45:59 +01002284
2285int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops)
2286{
2287 if (ops == soc_ac97_ops)
2288 return 0;
2289
2290 if (soc_ac97_ops && ops)
2291 return -EBUSY;
2292
2293 soc_ac97_ops = ops;
2294
2295 return 0;
2296}
2297EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops);
2298
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002299/**
Markus Pargmann741a5092013-08-19 17:05:55 +02002300 * snd_soc_set_ac97_ops_of_reset - Set ac97 ops with generic ac97 reset functions
2301 *
2302 * This function sets the reset and warm_reset properties of ops and parses
2303 * the device node of pdev to get pinctrl states and gpio numbers to use.
2304 */
2305int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
2306 struct platform_device *pdev)
2307{
2308 struct device *dev = &pdev->dev;
2309 struct snd_ac97_reset_cfg cfg;
2310 int ret;
2311
2312 ret = snd_soc_ac97_parse_pinctl(dev, &cfg);
2313 if (ret)
2314 return ret;
2315
2316 ret = snd_soc_set_ac97_ops(ops);
2317 if (ret)
2318 return ret;
2319
2320 ops->warm_reset = snd_soc_ac97_warm_reset;
2321 ops->reset = snd_soc_ac97_reset;
2322
2323 snd_ac97_rst_cfg = cfg;
2324 return 0;
2325}
2326EXPORT_SYMBOL_GPL(snd_soc_set_ac97_ops_of_reset);
2327
2328/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002329 * snd_soc_free_ac97_codec - free AC97 codec device
2330 * @codec: audio codec
2331 *
2332 * Frees AC97 codec device resources.
2333 */
2334void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
2335{
2336 mutex_lock(&codec->mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002337#ifdef CONFIG_SND_SOC_AC97_BUS
Misael Lopez Cruz02c9c7b2014-03-21 16:27:28 +01002338 soc_unregister_ac97_codec(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002339#endif
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002340 kfree(codec->ac97->bus);
2341 kfree(codec->ac97);
2342 codec->ac97 = NULL;
Mika Westerberg0562f782010-10-13 11:30:32 +03002343 codec->ac97_created = 0;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002344 mutex_unlock(&codec->mutex);
2345}
2346EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
2347
Mark Brownc3753702010-11-01 15:41:57 -04002348unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
2349{
2350 unsigned int ret;
2351
Mark Brownc3acec22010-12-02 16:15:29 +00002352 ret = codec->read(codec, reg);
Mark Brownc3753702010-11-01 15:41:57 -04002353 dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
Mark Browna8b1d342010-11-03 18:05:58 -04002354 trace_snd_soc_reg_read(codec, reg, ret);
Mark Brownc3753702010-11-01 15:41:57 -04002355
2356 return ret;
2357}
2358EXPORT_SYMBOL_GPL(snd_soc_read);
2359
2360unsigned int snd_soc_write(struct snd_soc_codec *codec,
2361 unsigned int reg, unsigned int val)
2362{
2363 dev_dbg(codec->dev, "write %x = %x\n", reg, val);
Mark Browna8b1d342010-11-03 18:05:58 -04002364 trace_snd_soc_reg_write(codec, reg, val);
Mark Brownc3acec22010-12-02 16:15:29 +00002365 return codec->write(codec, reg, val);
Mark Brownc3753702010-11-01 15:41:57 -04002366}
2367EXPORT_SYMBOL_GPL(snd_soc_write);
2368
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002369/**
2370 * snd_soc_update_bits - update codec register bits
2371 * @codec: audio codec
2372 * @reg: codec register
2373 * @mask: register mask
2374 * @value: new value
2375 *
2376 * Writes new register value.
2377 *
Timur Tabi180c3292011-01-10 15:58:13 -06002378 * Returns 1 for change, 0 for no change, or negative error code.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002379 */
2380int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002381 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002382{
Mark Brown8a713da2011-12-03 12:33:55 +00002383 bool change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002384 unsigned int old, new;
Timur Tabi180c3292011-01-10 15:58:13 -06002385 int ret;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002386
Mark Brown8a713da2011-12-03 12:33:55 +00002387 if (codec->using_regmap) {
2388 ret = regmap_update_bits_check(codec->control_data, reg,
2389 mask, value, &change);
2390 } else {
2391 ret = snd_soc_read(codec, reg);
Timur Tabi180c3292011-01-10 15:58:13 -06002392 if (ret < 0)
2393 return ret;
Mark Brown8a713da2011-12-03 12:33:55 +00002394
2395 old = ret;
2396 new = (old & ~mask) | (value & mask);
2397 change = old != new;
2398 if (change)
2399 ret = snd_soc_write(codec, reg, new);
Timur Tabi180c3292011-01-10 15:58:13 -06002400 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002401
Mark Brown8a713da2011-12-03 12:33:55 +00002402 if (ret < 0)
2403 return ret;
2404
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002405 return change;
2406}
2407EXPORT_SYMBOL_GPL(snd_soc_update_bits);
2408
2409/**
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002410 * snd_soc_update_bits_locked - update codec register bits
2411 * @codec: audio codec
2412 * @reg: codec register
2413 * @mask: register mask
2414 * @value: new value
2415 *
2416 * Writes new register value, and takes the codec mutex.
2417 *
2418 * Returns 1 for change else 0.
2419 */
Mark Browndd1b3d52009-12-04 14:22:03 +00002420int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
2421 unsigned short reg, unsigned int mask,
2422 unsigned int value)
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002423{
2424 int change;
2425
2426 mutex_lock(&codec->mutex);
2427 change = snd_soc_update_bits(codec, reg, mask, value);
2428 mutex_unlock(&codec->mutex);
2429
2430 return change;
2431}
Mark Browndd1b3d52009-12-04 14:22:03 +00002432EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002433
2434/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002435 * snd_soc_test_bits - test register for change
2436 * @codec: audio codec
2437 * @reg: codec register
2438 * @mask: register mask
2439 * @value: new value
2440 *
2441 * Tests a register with a new value and checks if the new value is
2442 * different from the old value.
2443 *
2444 * Returns 1 for change else 0.
2445 */
2446int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002447 unsigned int mask, unsigned int value)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002448{
2449 int change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002450 unsigned int old, new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002451
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002452 old = snd_soc_read(codec, reg);
2453 new = (old & ~mask) | value;
2454 change = old != new;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002455
2456 return change;
2457}
2458EXPORT_SYMBOL_GPL(snd_soc_test_bits);
2459
2460/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002461 * snd_soc_cnew - create new control
2462 * @_template: control template
2463 * @data: control private data
Mark Brownac11a2b2009-01-01 12:18:17 +00002464 * @long_name: control long name
Mark Brownefb7ac32011-03-08 17:23:24 +00002465 * @prefix: control name prefix
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002466 *
2467 * Create a new mixer control from a template control.
2468 *
2469 * Returns 0 for success, else error.
2470 */
2471struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
Mark Brown30565572012-02-16 17:07:42 -08002472 void *data, const char *long_name,
Mark Brownefb7ac32011-03-08 17:23:24 +00002473 const char *prefix)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002474{
2475 struct snd_kcontrol_new template;
Mark Brownefb7ac32011-03-08 17:23:24 +00002476 struct snd_kcontrol *kcontrol;
2477 char *name = NULL;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002478
2479 memcpy(&template, _template, sizeof(template));
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002480 template.index = 0;
2481
Mark Brownefb7ac32011-03-08 17:23:24 +00002482 if (!long_name)
2483 long_name = template.name;
2484
2485 if (prefix) {
Lars-Peter Clausen2b581072013-05-14 11:05:32 +02002486 name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
Mark Brownefb7ac32011-03-08 17:23:24 +00002487 if (!name)
2488 return NULL;
2489
Mark Brownefb7ac32011-03-08 17:23:24 +00002490 template.name = name;
2491 } else {
2492 template.name = long_name;
2493 }
2494
2495 kcontrol = snd_ctl_new1(&template, data);
2496
2497 kfree(name);
2498
2499 return kcontrol;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002500}
2501EXPORT_SYMBOL_GPL(snd_soc_cnew);
2502
Liam Girdwood022658b2012-02-03 17:43:09 +00002503static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2504 const struct snd_kcontrol_new *controls, int num_controls,
2505 const char *prefix, void *data)
2506{
2507 int err, i;
2508
2509 for (i = 0; i < num_controls; i++) {
2510 const struct snd_kcontrol_new *control = &controls[i];
2511 err = snd_ctl_add(card, snd_soc_cnew(control, data,
2512 control->name, prefix));
2513 if (err < 0) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00002514 dev_err(dev, "ASoC: Failed to add %s: %d\n",
2515 control->name, err);
Liam Girdwood022658b2012-02-03 17:43:09 +00002516 return err;
2517 }
2518 }
2519
2520 return 0;
2521}
2522
Dimitris Papastamos4fefd692013-07-29 13:51:58 +01002523struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
2524 const char *name)
2525{
2526 struct snd_card *card = soc_card->snd_card;
2527 struct snd_kcontrol *kctl;
2528
2529 if (unlikely(!name))
2530 return NULL;
2531
2532 list_for_each_entry(kctl, &card->controls, list)
2533 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
2534 return kctl;
2535 return NULL;
2536}
2537EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
2538
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002539/**
Liam Girdwood022658b2012-02-03 17:43:09 +00002540 * snd_soc_add_codec_controls - add an array of controls to a codec.
2541 * Convenience function to add a list of controls. Many codecs were
Ian Molton3e8e1952009-01-09 00:23:21 +00002542 * duplicating this code.
2543 *
2544 * @codec: codec to add controls to
2545 * @controls: array of controls to add
2546 * @num_controls: number of elements in the array
2547 *
2548 * Return 0 for success, else error.
2549 */
Liam Girdwood022658b2012-02-03 17:43:09 +00002550int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
Ian Molton3e8e1952009-01-09 00:23:21 +00002551 const struct snd_kcontrol_new *controls, int num_controls)
2552{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002553 struct snd_card *card = codec->card->snd_card;
Ian Molton3e8e1952009-01-09 00:23:21 +00002554
Liam Girdwood022658b2012-02-03 17:43:09 +00002555 return snd_soc_add_controls(card, codec->dev, controls, num_controls,
2556 codec->name_prefix, codec);
Ian Molton3e8e1952009-01-09 00:23:21 +00002557}
Liam Girdwood022658b2012-02-03 17:43:09 +00002558EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
Ian Molton3e8e1952009-01-09 00:23:21 +00002559
2560/**
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002561 * snd_soc_add_platform_controls - add an array of controls to a platform.
Liam Girdwood022658b2012-02-03 17:43:09 +00002562 * Convenience function to add a list of controls.
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002563 *
2564 * @platform: platform to add controls to
2565 * @controls: array of controls to add
2566 * @num_controls: number of elements in the array
2567 *
2568 * Return 0 for success, else error.
2569 */
2570int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
2571 const struct snd_kcontrol_new *controls, int num_controls)
2572{
2573 struct snd_card *card = platform->card->snd_card;
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002574
Liam Girdwood022658b2012-02-03 17:43:09 +00002575 return snd_soc_add_controls(card, platform->dev, controls, num_controls,
2576 NULL, platform);
Liam Girdwooda491a5c2011-07-04 22:10:51 +01002577}
2578EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
2579
2580/**
Liam Girdwood022658b2012-02-03 17:43:09 +00002581 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2582 * Convenience function to add a list of controls.
2583 *
2584 * @soc_card: SoC card to add controls to
2585 * @controls: array of controls to add
2586 * @num_controls: number of elements in the array
2587 *
2588 * Return 0 for success, else error.
2589 */
2590int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2591 const struct snd_kcontrol_new *controls, int num_controls)
2592{
2593 struct snd_card *card = soc_card->snd_card;
2594
2595 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2596 NULL, soc_card);
2597}
2598EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2599
2600/**
2601 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2602 * Convienience function to add a list of controls.
2603 *
2604 * @dai: DAI to add controls to
2605 * @controls: array of controls to add
2606 * @num_controls: number of elements in the array
2607 *
2608 * Return 0 for success, else error.
2609 */
2610int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2611 const struct snd_kcontrol_new *controls, int num_controls)
2612{
2613 struct snd_card *card = dai->card->snd_card;
2614
2615 return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2616 NULL, dai);
2617}
2618EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2619
2620/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002621 * snd_soc_info_enum_double - enumerated double mixer info callback
2622 * @kcontrol: mixer control
2623 * @uinfo: control element information
2624 *
2625 * Callback to provide information about a double enumerated
2626 * mixer control.
2627 *
2628 * Returns 0 for success.
2629 */
2630int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2631 struct snd_ctl_elem_info *uinfo)
2632{
2633 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2634
2635 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2636 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
Takashi Iwai9a8d38d2014-02-18 08:11:42 +01002637 uinfo->value.enumerated.items = e->items;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002638
Takashi Iwai9a8d38d2014-02-18 08:11:42 +01002639 if (uinfo->value.enumerated.item >= e->items)
2640 uinfo->value.enumerated.item = e->items - 1;
Takashi Iwaia19685c2013-10-28 14:21:46 +01002641 strlcpy(uinfo->value.enumerated.name,
2642 e->texts[uinfo->value.enumerated.item],
2643 sizeof(uinfo->value.enumerated.name));
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002644 return 0;
2645}
2646EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
2647
2648/**
2649 * snd_soc_get_enum_double - enumerated double mixer get callback
2650 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002651 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002652 *
2653 * Callback to get the value of a double enumerated mixer.
2654 *
2655 * Returns 0 for success.
2656 */
2657int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
2658 struct snd_ctl_elem_value *ucontrol)
2659{
2660 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2661 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Lars-Peter Clausen29ae2fa2014-02-28 08:31:03 +01002662 unsigned int val, item;
2663 unsigned int reg_val;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002664
Lars-Peter Clausen29ae2fa2014-02-28 08:31:03 +01002665 reg_val = snd_soc_read(codec, e->reg);
2666 val = (reg_val >> e->shift_l) & e->mask;
2667 item = snd_soc_enum_val_to_item(e, val);
2668 ucontrol->value.enumerated.item[0] = item;
2669 if (e->shift_l != e->shift_r) {
2670 val = (reg_val >> e->shift_l) & e->mask;
2671 item = snd_soc_enum_val_to_item(e, val);
2672 ucontrol->value.enumerated.item[1] = item;
2673 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002674
2675 return 0;
2676}
2677EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
2678
2679/**
2680 * snd_soc_put_enum_double - enumerated double mixer put callback
2681 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002682 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002683 *
2684 * Callback to set the value of a double enumerated mixer.
2685 *
2686 * Returns 0 for success.
2687 */
2688int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2689 struct snd_ctl_elem_value *ucontrol)
2690{
2691 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2692 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Lars-Peter Clausen29ae2fa2014-02-28 08:31:03 +01002693 unsigned int *item = ucontrol->value.enumerated.item;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002694 unsigned int val;
Lars-Peter Clausen86767b72012-09-14 13:57:27 +02002695 unsigned int mask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002696
Lars-Peter Clausen29ae2fa2014-02-28 08:31:03 +01002697 if (item[0] >= e->items)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002698 return -EINVAL;
Lars-Peter Clausen29ae2fa2014-02-28 08:31:03 +01002699 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l;
Lars-Peter Clausen86767b72012-09-14 13:57:27 +02002700 mask = e->mask << e->shift_l;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002701 if (e->shift_l != e->shift_r) {
Lars-Peter Clausen29ae2fa2014-02-28 08:31:03 +01002702 if (item[1] >= e->items)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002703 return -EINVAL;
Lars-Peter Clausen29ae2fa2014-02-28 08:31:03 +01002704 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r;
Lars-Peter Clausen86767b72012-09-14 13:57:27 +02002705 mask |= e->mask << e->shift_r;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002706 }
2707
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002708 return snd_soc_update_bits_locked(codec, e->reg, mask, val);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002709}
2710EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
2711
2712/**
Markus Pargmannf227b882014-01-16 16:02:10 +01002713 * snd_soc_read_signed - Read a codec register and interprete as signed value
2714 * @codec: codec
2715 * @reg: Register to read
2716 * @mask: Mask to use after shifting the register value
2717 * @shift: Right shift of register value
2718 * @sign_bit: Bit that describes if a number is negative or not.
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002719 *
Markus Pargmannf227b882014-01-16 16:02:10 +01002720 * This functions reads a codec register. The register value is shifted right
2721 * by 'shift' bits and masked with the given 'mask'. Afterwards it translates
2722 * the given registervalue into a signed integer if sign_bit is non-zero.
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002723 *
Markus Pargmannf227b882014-01-16 16:02:10 +01002724 * Returns the register value as signed int.
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002725 */
Markus Pargmannf227b882014-01-16 16:02:10 +01002726static int snd_soc_read_signed(struct snd_soc_codec *codec, unsigned int reg,
2727 unsigned int mask, unsigned int shift, unsigned int sign_bit)
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002728{
Markus Pargmannf227b882014-01-16 16:02:10 +01002729 int ret;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03002730 unsigned int val;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002731
Markus Pargmannf227b882014-01-16 16:02:10 +01002732 val = (snd_soc_read(codec, reg) >> shift) & mask;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002733
Markus Pargmannf227b882014-01-16 16:02:10 +01002734 if (!sign_bit)
2735 return val;
2736
2737 /* non-negative number */
2738 if (!(val & BIT(sign_bit)))
2739 return val;
2740
2741 ret = val;
2742
2743 /*
2744 * The register most probably does not contain a full-sized int.
2745 * Instead we have an arbitrary number of bits in a signed
2746 * representation which has to be translated into a full-sized int.
2747 * This is done by filling up all bits above the sign-bit.
2748 */
2749 ret |= ~((int)(BIT(sign_bit) - 1));
2750
2751 return ret;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002752}
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02002753
2754/**
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002755 * snd_soc_info_volsw - single mixer info callback
2756 * @kcontrol: mixer control
2757 * @uinfo: control element information
2758 *
Peter Ujfalusie8f5a102011-10-05 10:29:23 +03002759 * Callback to provide information about a single mixer control, or a double
2760 * mixer control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002761 *
2762 * Returns 0 for success.
2763 */
2764int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
2765 struct snd_ctl_elem_info *uinfo)
2766{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002767 struct soc_mixer_control *mc =
2768 (struct soc_mixer_control *)kcontrol->private_value;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002769 int platform_max;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002770
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002771 if (!mc->platform_max)
2772 mc->platform_max = mc->max;
2773 platform_max = mc->platform_max;
2774
2775 if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002776 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2777 else
2778 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2779
Peter Ujfalusie8f5a102011-10-05 10:29:23 +03002780 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002781 uinfo->value.integer.min = 0;
Markus Pargmannf227b882014-01-16 16:02:10 +01002782 uinfo->value.integer.max = platform_max - mc->min;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002783 return 0;
2784}
2785EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
2786
2787/**
2788 * snd_soc_get_volsw - single mixer get callback
2789 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002790 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002791 *
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002792 * Callback to get the value of a single mixer control, or a double mixer
2793 * control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002794 *
2795 * Returns 0 for success.
2796 */
2797int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
2798 struct snd_ctl_elem_value *ucontrol)
2799{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002800 struct soc_mixer_control *mc =
2801 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002802 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002803 unsigned int reg = mc->reg;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002804 unsigned int reg2 = mc->rreg;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002805 unsigned int shift = mc->shift;
2806 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002807 int max = mc->max;
Markus Pargmannf227b882014-01-16 16:02:10 +01002808 int min = mc->min;
2809 int sign_bit = mc->sign_bit;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002810 unsigned int mask = (1 << fls(max)) - 1;
2811 unsigned int invert = mc->invert;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002812
Markus Pargmannf227b882014-01-16 16:02:10 +01002813 if (sign_bit)
2814 mask = BIT(sign_bit + 1) - 1;
2815
2816 ucontrol->value.integer.value[0] = snd_soc_read_signed(codec, reg, mask,
2817 shift, sign_bit) - min;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002818 if (invert)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002819 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002820 max - ucontrol->value.integer.value[0];
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002821
2822 if (snd_soc_volsw_is_stereo(mc)) {
2823 if (reg == reg2)
2824 ucontrol->value.integer.value[1] =
Markus Pargmannf227b882014-01-16 16:02:10 +01002825 snd_soc_read_signed(codec, reg, mask, rshift,
2826 sign_bit) - min;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002827 else
2828 ucontrol->value.integer.value[1] =
Markus Pargmannf227b882014-01-16 16:02:10 +01002829 snd_soc_read_signed(codec, reg2, mask, shift,
2830 sign_bit) - min;
Peter Ujfalusif7915d92011-10-05 10:29:24 +03002831 if (invert)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002832 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002833 max - ucontrol->value.integer.value[1];
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002834 }
2835
2836 return 0;
2837}
2838EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
2839
2840/**
2841 * snd_soc_put_volsw - single mixer put callback
2842 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00002843 * @ucontrol: control element information
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002844 *
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002845 * Callback to set the value of a single mixer control, or a double mixer
2846 * control that spans 2 registers.
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002847 *
2848 * Returns 0 for success.
2849 */
2850int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
2851 struct snd_ctl_elem_value *ucontrol)
2852{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002853 struct soc_mixer_control *mc =
2854 (struct soc_mixer_control *)kcontrol->private_value;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002855 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002856 unsigned int reg = mc->reg;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002857 unsigned int reg2 = mc->rreg;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002858 unsigned int shift = mc->shift;
2859 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002860 int max = mc->max;
Markus Pargmannf227b882014-01-16 16:02:10 +01002861 int min = mc->min;
2862 unsigned int sign_bit = mc->sign_bit;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04002863 unsigned int mask = (1 << fls(max)) - 1;
2864 unsigned int invert = mc->invert;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002865 int err;
Nenghua Cao939d9f12014-03-03 19:08:23 +08002866 bool type_2r = false;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002867 unsigned int val2 = 0;
2868 unsigned int val, val_mask;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002869
Markus Pargmannf227b882014-01-16 16:02:10 +01002870 if (sign_bit)
2871 mask = BIT(sign_bit + 1) - 1;
2872
2873 val = ((ucontrol->value.integer.value[0] + min) & mask);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002874 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002875 val = max - val;
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002876 val_mask = mask << shift;
2877 val = val << shift;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002878 if (snd_soc_volsw_is_stereo(mc)) {
Markus Pargmannf227b882014-01-16 16:02:10 +01002879 val2 = ((ucontrol->value.integer.value[1] + min) & mask);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002880 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01002881 val2 = max - val2;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002882 if (reg == reg2) {
2883 val_mask |= mask << rshift;
2884 val |= val2 << rshift;
2885 } else {
2886 val2 = val2 << shift;
Nenghua Cao939d9f12014-03-03 19:08:23 +08002887 type_2r = true;
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002888 }
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002889 }
Eero Nurkkala6c508c62009-10-30 13:34:03 +02002890 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
Mark Brown3ff3f642008-05-19 12:32:25 +02002891 if (err < 0)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002892 return err;
2893
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002894 if (type_2r)
2895 err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
2896
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002897 return err;
2898}
Peter Ujfalusi974815b2011-10-05 10:29:25 +03002899EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02002900
Mark Browne13ac2e2008-05-28 17:58:05 +01002901/**
Brian Austin1d99f242012-03-30 10:43:55 -05002902 * snd_soc_get_volsw_sx - single mixer get callback
2903 * @kcontrol: mixer control
2904 * @ucontrol: control element information
2905 *
2906 * Callback to get the value of a single mixer control, or a double mixer
2907 * control that spans 2 registers.
2908 *
2909 * Returns 0 for success.
2910 */
2911int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
2912 struct snd_ctl_elem_value *ucontrol)
2913{
2914 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2915 struct soc_mixer_control *mc =
2916 (struct soc_mixer_control *)kcontrol->private_value;
2917
2918 unsigned int reg = mc->reg;
2919 unsigned int reg2 = mc->rreg;
2920 unsigned int shift = mc->shift;
2921 unsigned int rshift = mc->rshift;
2922 int max = mc->max;
2923 int min = mc->min;
2924 int mask = (1 << (fls(min + max) - 1)) - 1;
2925
2926 ucontrol->value.integer.value[0] =
2927 ((snd_soc_read(codec, reg) >> shift) - min) & mask;
2928
2929 if (snd_soc_volsw_is_stereo(mc))
2930 ucontrol->value.integer.value[1] =
2931 ((snd_soc_read(codec, reg2) >> rshift) - min) & mask;
2932
2933 return 0;
2934}
2935EXPORT_SYMBOL_GPL(snd_soc_get_volsw_sx);
2936
2937/**
2938 * snd_soc_put_volsw_sx - double mixer set callback
2939 * @kcontrol: mixer control
2940 * @uinfo: control element information
2941 *
2942 * Callback to set the value of a double mixer control that spans 2 registers.
2943 *
2944 * Returns 0 for success.
2945 */
2946int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
2947 struct snd_ctl_elem_value *ucontrol)
2948{
2949 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2950 struct soc_mixer_control *mc =
2951 (struct soc_mixer_control *)kcontrol->private_value;
2952
2953 unsigned int reg = mc->reg;
2954 unsigned int reg2 = mc->rreg;
2955 unsigned int shift = mc->shift;
2956 unsigned int rshift = mc->rshift;
2957 int max = mc->max;
2958 int min = mc->min;
2959 int mask = (1 << (fls(min + max) - 1)) - 1;
Brian Austin27f1d752012-04-03 11:33:50 -05002960 int err = 0;
Brian Austin1d99f242012-03-30 10:43:55 -05002961 unsigned short val, val_mask, val2 = 0;
2962
2963 val_mask = mask << shift;
2964 val = (ucontrol->value.integer.value[0] + min) & mask;
2965 val = val << shift;
2966
Mukund Navadad0558522012-11-09 11:53:40 +05302967 err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
2968 if (err < 0)
2969 return err;
Brian Austin1d99f242012-03-30 10:43:55 -05002970
2971 if (snd_soc_volsw_is_stereo(mc)) {
2972 val_mask = mask << rshift;
2973 val2 = (ucontrol->value.integer.value[1] + min) & mask;
2974 val2 = val2 << rshift;
2975
2976 if (snd_soc_update_bits_locked(codec, reg2, val_mask, val2))
2977 return err;
2978 }
2979 return 0;
2980}
2981EXPORT_SYMBOL_GPL(snd_soc_put_volsw_sx);
2982
2983/**
Mark Browne13ac2e2008-05-28 17:58:05 +01002984 * snd_soc_info_volsw_s8 - signed mixer info callback
2985 * @kcontrol: mixer control
2986 * @uinfo: control element information
2987 *
2988 * Callback to provide information about a signed mixer control.
2989 *
2990 * Returns 0 for success.
2991 */
2992int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
2993 struct snd_ctl_elem_info *uinfo)
2994{
Jon Smirl4eaa9812008-07-29 11:42:26 +01002995 struct soc_mixer_control *mc =
2996 (struct soc_mixer_control *)kcontrol->private_value;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03002997 int platform_max;
Jon Smirl4eaa9812008-07-29 11:42:26 +01002998 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01002999
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03003000 if (!mc->platform_max)
3001 mc->platform_max = mc->max;
3002 platform_max = mc->platform_max;
3003
Mark Browne13ac2e2008-05-28 17:58:05 +01003004 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3005 uinfo->count = 2;
3006 uinfo->value.integer.min = 0;
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03003007 uinfo->value.integer.max = platform_max - min;
Mark Browne13ac2e2008-05-28 17:58:05 +01003008 return 0;
3009}
3010EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
3011
3012/**
3013 * snd_soc_get_volsw_s8 - signed mixer get callback
3014 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00003015 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01003016 *
3017 * Callback to get the value of a signed mixer control.
3018 *
3019 * Returns 0 for success.
3020 */
3021int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
3022 struct snd_ctl_elem_value *ucontrol)
3023{
Jon Smirl4eaa9812008-07-29 11:42:26 +01003024 struct soc_mixer_control *mc =
3025 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01003026 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04003027 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01003028 int min = mc->min;
Mark Browne13ac2e2008-05-28 17:58:05 +01003029 int val = snd_soc_read(codec, reg);
3030
3031 ucontrol->value.integer.value[0] =
3032 ((signed char)(val & 0xff))-min;
3033 ucontrol->value.integer.value[1] =
3034 ((signed char)((val >> 8) & 0xff))-min;
3035 return 0;
3036}
3037EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
3038
3039/**
3040 * snd_soc_put_volsw_sgn - signed mixer put callback
3041 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00003042 * @ucontrol: control element information
Mark Browne13ac2e2008-05-28 17:58:05 +01003043 *
3044 * Callback to set the value of a signed mixer control.
3045 *
3046 * Returns 0 for success.
3047 */
3048int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
3049 struct snd_ctl_elem_value *ucontrol)
3050{
Jon Smirl4eaa9812008-07-29 11:42:26 +01003051 struct soc_mixer_control *mc =
3052 (struct soc_mixer_control *)kcontrol->private_value;
Mark Browne13ac2e2008-05-28 17:58:05 +01003053 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Jon Smirl815ecf8d2008-07-29 10:22:24 -04003054 unsigned int reg = mc->reg;
Jon Smirl4eaa9812008-07-29 11:42:26 +01003055 int min = mc->min;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03003056 unsigned int val;
Mark Browne13ac2e2008-05-28 17:58:05 +01003057
3058 val = (ucontrol->value.integer.value[0]+min) & 0xff;
3059 val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
3060
Eero Nurkkala6c508c62009-10-30 13:34:03 +02003061 return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
Mark Browne13ac2e2008-05-28 17:58:05 +01003062}
3063EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
3064
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003065/**
Adam Thomson6c9d8cf2012-05-31 15:18:01 +01003066 * snd_soc_info_volsw_range - single mixer info callback with range.
3067 * @kcontrol: mixer control
3068 * @uinfo: control element information
3069 *
3070 * Callback to provide information, within a range, about a single
3071 * mixer control.
3072 *
3073 * returns 0 for success.
3074 */
3075int snd_soc_info_volsw_range(struct snd_kcontrol *kcontrol,
3076 struct snd_ctl_elem_info *uinfo)
3077{
3078 struct soc_mixer_control *mc =
3079 (struct soc_mixer_control *)kcontrol->private_value;
3080 int platform_max;
3081 int min = mc->min;
3082
3083 if (!mc->platform_max)
3084 mc->platform_max = mc->max;
3085 platform_max = mc->platform_max;
3086
3087 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
Mark Brown9bde4f02012-12-19 16:05:00 +00003088 uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
Adam Thomson6c9d8cf2012-05-31 15:18:01 +01003089 uinfo->value.integer.min = 0;
3090 uinfo->value.integer.max = platform_max - min;
3091
3092 return 0;
3093}
3094EXPORT_SYMBOL_GPL(snd_soc_info_volsw_range);
3095
3096/**
3097 * snd_soc_put_volsw_range - single mixer put value callback with range.
3098 * @kcontrol: mixer control
3099 * @ucontrol: control element information
3100 *
3101 * Callback to set the value, within a range, for a single mixer control.
3102 *
3103 * Returns 0 for success.
3104 */
3105int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
3106 struct snd_ctl_elem_value *ucontrol)
3107{
3108 struct soc_mixer_control *mc =
3109 (struct soc_mixer_control *)kcontrol->private_value;
3110 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3111 unsigned int reg = mc->reg;
Mark Brown9bde4f02012-12-19 16:05:00 +00003112 unsigned int rreg = mc->rreg;
Adam Thomson6c9d8cf2012-05-31 15:18:01 +01003113 unsigned int shift = mc->shift;
3114 int min = mc->min;
3115 int max = mc->max;
3116 unsigned int mask = (1 << fls(max)) - 1;
3117 unsigned int invert = mc->invert;
3118 unsigned int val, val_mask;
Mark Brown9bde4f02012-12-19 16:05:00 +00003119 int ret;
Adam Thomson6c9d8cf2012-05-31 15:18:01 +01003120
3121 val = ((ucontrol->value.integer.value[0] + min) & mask);
3122 if (invert)
3123 val = max - val;
3124 val_mask = mask << shift;
3125 val = val << shift;
3126
Mark Brown9bde4f02012-12-19 16:05:00 +00003127 ret = snd_soc_update_bits_locked(codec, reg, val_mask, val);
Joonyoung Shim0eaa6cc2013-03-26 14:41:05 +09003128 if (ret < 0)
Mark Brown9bde4f02012-12-19 16:05:00 +00003129 return ret;
3130
3131 if (snd_soc_volsw_is_stereo(mc)) {
3132 val = ((ucontrol->value.integer.value[1] + min) & mask);
3133 if (invert)
3134 val = max - val;
3135 val_mask = mask << shift;
3136 val = val << shift;
3137
3138 ret = snd_soc_update_bits_locked(codec, rreg, val_mask, val);
3139 }
3140
3141 return ret;
Adam Thomson6c9d8cf2012-05-31 15:18:01 +01003142}
3143EXPORT_SYMBOL_GPL(snd_soc_put_volsw_range);
3144
3145/**
3146 * snd_soc_get_volsw_range - single mixer get callback with range
3147 * @kcontrol: mixer control
3148 * @ucontrol: control element information
3149 *
3150 * Callback to get the value, within a range, of a single mixer control.
3151 *
3152 * Returns 0 for success.
3153 */
3154int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
3155 struct snd_ctl_elem_value *ucontrol)
3156{
3157 struct soc_mixer_control *mc =
3158 (struct soc_mixer_control *)kcontrol->private_value;
3159 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3160 unsigned int reg = mc->reg;
Mark Brown9bde4f02012-12-19 16:05:00 +00003161 unsigned int rreg = mc->rreg;
Adam Thomson6c9d8cf2012-05-31 15:18:01 +01003162 unsigned int shift = mc->shift;
3163 int min = mc->min;
3164 int max = mc->max;
3165 unsigned int mask = (1 << fls(max)) - 1;
3166 unsigned int invert = mc->invert;
3167
3168 ucontrol->value.integer.value[0] =
3169 (snd_soc_read(codec, reg) >> shift) & mask;
3170 if (invert)
3171 ucontrol->value.integer.value[0] =
3172 max - ucontrol->value.integer.value[0];
3173 ucontrol->value.integer.value[0] =
3174 ucontrol->value.integer.value[0] - min;
3175
Mark Brown9bde4f02012-12-19 16:05:00 +00003176 if (snd_soc_volsw_is_stereo(mc)) {
3177 ucontrol->value.integer.value[1] =
3178 (snd_soc_read(codec, rreg) >> shift) & mask;
3179 if (invert)
3180 ucontrol->value.integer.value[1] =
3181 max - ucontrol->value.integer.value[1];
3182 ucontrol->value.integer.value[1] =
3183 ucontrol->value.integer.value[1] - min;
3184 }
3185
Adam Thomson6c9d8cf2012-05-31 15:18:01 +01003186 return 0;
3187}
3188EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
3189
3190/**
Peter Ujfalusi637d3842010-05-07 14:05:49 +03003191 * snd_soc_limit_volume - Set new limit to an existing volume control.
3192 *
3193 * @codec: where to look for the control
3194 * @name: Name of the control
3195 * @max: new maximum limit
3196 *
3197 * Return 0 for success, else error.
3198 */
3199int snd_soc_limit_volume(struct snd_soc_codec *codec,
3200 const char *name, int max)
3201{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003202 struct snd_card *card = codec->card->snd_card;
Peter Ujfalusi637d3842010-05-07 14:05:49 +03003203 struct snd_kcontrol *kctl;
3204 struct soc_mixer_control *mc;
3205 int found = 0;
3206 int ret = -EINVAL;
3207
3208 /* Sanity check for name and max */
3209 if (unlikely(!name || max <= 0))
3210 return -EINVAL;
3211
3212 list_for_each_entry(kctl, &card->controls, list) {
3213 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
3214 found = 1;
3215 break;
3216 }
3217 }
3218 if (found) {
3219 mc = (struct soc_mixer_control *)kctl->private_value;
3220 if (max <= mc->max) {
Peter Ujfalusid11bb4a2010-05-10 14:39:24 +03003221 mc->platform_max = max;
Peter Ujfalusi637d3842010-05-07 14:05:49 +03003222 ret = 0;
3223 }
3224 }
3225 return ret;
3226}
3227EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
3228
Mark Brown71d08512011-10-10 18:31:26 +01003229int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
3230 struct snd_ctl_elem_info *uinfo)
3231{
3232 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3233 struct soc_bytes *params = (void *)kcontrol->private_value;
3234
3235 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
3236 uinfo->count = params->num_regs * codec->val_bytes;
3237
3238 return 0;
3239}
3240EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
3241
3242int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
3243 struct snd_ctl_elem_value *ucontrol)
3244{
3245 struct soc_bytes *params = (void *)kcontrol->private_value;
3246 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3247 int ret;
3248
3249 if (codec->using_regmap)
3250 ret = regmap_raw_read(codec->control_data, params->base,
3251 ucontrol->value.bytes.data,
3252 params->num_regs * codec->val_bytes);
3253 else
3254 ret = -EINVAL;
3255
Mark Brownf831b052012-02-17 16:20:33 -08003256 /* Hide any masked bytes to ensure consistent data reporting */
3257 if (ret == 0 && params->mask) {
3258 switch (codec->val_bytes) {
3259 case 1:
3260 ucontrol->value.bytes.data[0] &= ~params->mask;
3261 break;
3262 case 2:
3263 ((u16 *)(&ucontrol->value.bytes.data))[0]
Charles Keepax8f1ec932013-11-29 13:33:11 +00003264 &= cpu_to_be16(~params->mask);
Mark Brownf831b052012-02-17 16:20:33 -08003265 break;
3266 case 4:
3267 ((u32 *)(&ucontrol->value.bytes.data))[0]
Charles Keepax8f1ec932013-11-29 13:33:11 +00003268 &= cpu_to_be32(~params->mask);
Mark Brownf831b052012-02-17 16:20:33 -08003269 break;
3270 default:
3271 return -EINVAL;
3272 }
3273 }
3274
Mark Brown71d08512011-10-10 18:31:26 +01003275 return ret;
3276}
3277EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
3278
3279int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
3280 struct snd_ctl_elem_value *ucontrol)
3281{
3282 struct soc_bytes *params = (void *)kcontrol->private_value;
3283 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownf831b052012-02-17 16:20:33 -08003284 int ret, len;
Nenghua Caoa1a564e2014-02-19 18:44:58 +08003285 unsigned int val, mask;
Mark Brownf831b052012-02-17 16:20:33 -08003286 void *data;
Mark Brown71d08512011-10-10 18:31:26 +01003287
Mark Brownf831b052012-02-17 16:20:33 -08003288 if (!codec->using_regmap)
3289 return -EINVAL;
3290
Mark Brownf831b052012-02-17 16:20:33 -08003291 len = params->num_regs * codec->val_bytes;
3292
Mark Brownb5a8fe42013-01-20 21:42:22 +09003293 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
3294 if (!data)
3295 return -ENOMEM;
3296
Mark Brownf831b052012-02-17 16:20:33 -08003297 /*
3298 * If we've got a mask then we need to preserve the register
3299 * bits. We shouldn't modify the incoming data so take a
3300 * copy.
3301 */
3302 if (params->mask) {
3303 ret = regmap_read(codec->control_data, params->base, &val);
3304 if (ret != 0)
Wei Yongjune8b18ad2013-03-12 00:35:14 +08003305 goto out;
Mark Brownf831b052012-02-17 16:20:33 -08003306
3307 val &= params->mask;
3308
Mark Brownf831b052012-02-17 16:20:33 -08003309 switch (codec->val_bytes) {
3310 case 1:
3311 ((u8 *)data)[0] &= ~params->mask;
3312 ((u8 *)data)[0] |= val;
3313 break;
3314 case 2:
Nenghua Caoa1a564e2014-02-19 18:44:58 +08003315 mask = ~params->mask;
3316 ret = regmap_parse_val(codec->control_data,
3317 &mask, &mask);
3318 if (ret != 0)
3319 goto out;
3320
3321 ((u16 *)data)[0] &= mask;
3322
3323 ret = regmap_parse_val(codec->control_data,
3324 &val, &val);
3325 if (ret != 0)
3326 goto out;
3327
3328 ((u16 *)data)[0] |= val;
Mark Brownf831b052012-02-17 16:20:33 -08003329 break;
3330 case 4:
Nenghua Caoa1a564e2014-02-19 18:44:58 +08003331 mask = ~params->mask;
3332 ret = regmap_parse_val(codec->control_data,
3333 &mask, &mask);
3334 if (ret != 0)
3335 goto out;
3336
3337 ((u32 *)data)[0] &= mask;
3338
3339 ret = regmap_parse_val(codec->control_data,
3340 &val, &val);
3341 if (ret != 0)
3342 goto out;
3343
3344 ((u32 *)data)[0] |= val;
Mark Brownf831b052012-02-17 16:20:33 -08003345 break;
3346 default:
Wei Yongjune8b18ad2013-03-12 00:35:14 +08003347 ret = -EINVAL;
3348 goto out;
Mark Brownf831b052012-02-17 16:20:33 -08003349 }
3350 }
3351
3352 ret = regmap_raw_write(codec->control_data, params->base,
3353 data, len);
3354
Wei Yongjune8b18ad2013-03-12 00:35:14 +08003355out:
Mark Brownb5a8fe42013-01-20 21:42:22 +09003356 kfree(data);
Mark Brown71d08512011-10-10 18:31:26 +01003357
3358 return ret;
3359}
3360EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
3361
apatard@mandriva.comb6f4bb32010-05-15 17:30:01 +02003362/**
Kristoffer KARLSSON4183eed22012-04-20 11:32:13 +02003363 * snd_soc_info_xr_sx - signed multi register info callback
3364 * @kcontrol: mreg control
3365 * @uinfo: control element information
3366 *
3367 * Callback to provide information of a control that can
3368 * span multiple codec registers which together
3369 * forms a single signed value in a MSB/LSB manner.
3370 *
3371 * Returns 0 for success.
3372 */
3373int snd_soc_info_xr_sx(struct snd_kcontrol *kcontrol,
3374 struct snd_ctl_elem_info *uinfo)
3375{
3376 struct soc_mreg_control *mc =
3377 (struct soc_mreg_control *)kcontrol->private_value;
3378 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3379 uinfo->count = 1;
3380 uinfo->value.integer.min = mc->min;
3381 uinfo->value.integer.max = mc->max;
3382
3383 return 0;
3384}
3385EXPORT_SYMBOL_GPL(snd_soc_info_xr_sx);
3386
3387/**
3388 * snd_soc_get_xr_sx - signed multi register get callback
3389 * @kcontrol: mreg control
3390 * @ucontrol: control element information
3391 *
3392 * Callback to get the value of a control that can span
3393 * multiple codec registers which together forms a single
3394 * signed value in a MSB/LSB manner. The control supports
3395 * specifying total no of bits used to allow for bitfields
3396 * across the multiple codec registers.
3397 *
3398 * Returns 0 for success.
3399 */
3400int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
3401 struct snd_ctl_elem_value *ucontrol)
3402{
3403 struct soc_mreg_control *mc =
3404 (struct soc_mreg_control *)kcontrol->private_value;
3405 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3406 unsigned int regbase = mc->regbase;
3407 unsigned int regcount = mc->regcount;
3408 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3409 unsigned int regwmask = (1<<regwshift)-1;
3410 unsigned int invert = mc->invert;
3411 unsigned long mask = (1UL<<mc->nbits)-1;
3412 long min = mc->min;
3413 long max = mc->max;
3414 long val = 0;
3415 unsigned long regval;
3416 unsigned int i;
3417
3418 for (i = 0; i < regcount; i++) {
3419 regval = snd_soc_read(codec, regbase+i) & regwmask;
3420 val |= regval << (regwshift*(regcount-i-1));
3421 }
3422 val &= mask;
3423 if (min < 0 && val > max)
3424 val |= ~mask;
3425 if (invert)
3426 val = max - val;
3427 ucontrol->value.integer.value[0] = val;
3428
3429 return 0;
3430}
3431EXPORT_SYMBOL_GPL(snd_soc_get_xr_sx);
3432
3433/**
3434 * snd_soc_put_xr_sx - signed multi register get callback
3435 * @kcontrol: mreg control
3436 * @ucontrol: control element information
3437 *
3438 * Callback to set the value of a control that can span
3439 * multiple codec registers which together forms a single
3440 * signed value in a MSB/LSB manner. The control supports
3441 * specifying total no of bits used to allow for bitfields
3442 * across the multiple codec registers.
3443 *
3444 * Returns 0 for success.
3445 */
3446int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
3447 struct snd_ctl_elem_value *ucontrol)
3448{
3449 struct soc_mreg_control *mc =
3450 (struct soc_mreg_control *)kcontrol->private_value;
3451 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3452 unsigned int regbase = mc->regbase;
3453 unsigned int regcount = mc->regcount;
3454 unsigned int regwshift = codec->driver->reg_word_size * BITS_PER_BYTE;
3455 unsigned int regwmask = (1<<regwshift)-1;
3456 unsigned int invert = mc->invert;
3457 unsigned long mask = (1UL<<mc->nbits)-1;
Kristoffer KARLSSON4183eed22012-04-20 11:32:13 +02003458 long max = mc->max;
3459 long val = ucontrol->value.integer.value[0];
3460 unsigned int i, regval, regmask;
3461 int err;
3462
3463 if (invert)
3464 val = max - val;
3465 val &= mask;
3466 for (i = 0; i < regcount; i++) {
3467 regval = (val >> (regwshift*(regcount-i-1))) & regwmask;
3468 regmask = (mask >> (regwshift*(regcount-i-1))) & regwmask;
3469 err = snd_soc_update_bits_locked(codec, regbase+i,
3470 regmask, regval);
3471 if (err < 0)
3472 return err;
3473 }
3474
3475 return 0;
3476}
3477EXPORT_SYMBOL_GPL(snd_soc_put_xr_sx);
3478
3479/**
Kristoffer KARLSSONdd7b10b2012-04-20 11:32:44 +02003480 * snd_soc_get_strobe - strobe get callback
3481 * @kcontrol: mixer control
3482 * @ucontrol: control element information
3483 *
3484 * Callback get the value of a strobe mixer control.
3485 *
3486 * Returns 0 for success.
3487 */
3488int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
3489 struct snd_ctl_elem_value *ucontrol)
3490{
3491 struct soc_mixer_control *mc =
3492 (struct soc_mixer_control *)kcontrol->private_value;
3493 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3494 unsigned int reg = mc->reg;
3495 unsigned int shift = mc->shift;
3496 unsigned int mask = 1 << shift;
3497 unsigned int invert = mc->invert != 0;
3498 unsigned int val = snd_soc_read(codec, reg) & mask;
3499
3500 if (shift != 0 && val != 0)
3501 val = val >> shift;
3502 ucontrol->value.enumerated.item[0] = val ^ invert;
3503
3504 return 0;
3505}
3506EXPORT_SYMBOL_GPL(snd_soc_get_strobe);
3507
3508/**
3509 * snd_soc_put_strobe - strobe put callback
3510 * @kcontrol: mixer control
3511 * @ucontrol: control element information
3512 *
3513 * Callback strobe a register bit to high then low (or the inverse)
3514 * in one pass of a single mixer enum control.
3515 *
3516 * Returns 1 for success.
3517 */
3518int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
3519 struct snd_ctl_elem_value *ucontrol)
3520{
3521 struct soc_mixer_control *mc =
3522 (struct soc_mixer_control *)kcontrol->private_value;
3523 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
3524 unsigned int reg = mc->reg;
3525 unsigned int shift = mc->shift;
3526 unsigned int mask = 1 << shift;
3527 unsigned int invert = mc->invert != 0;
3528 unsigned int strobe = ucontrol->value.enumerated.item[0] != 0;
3529 unsigned int val1 = (strobe ^ invert) ? mask : 0;
3530 unsigned int val2 = (strobe ^ invert) ? 0 : mask;
3531 int err;
3532
3533 err = snd_soc_update_bits_locked(codec, reg, mask, val1);
3534 if (err < 0)
3535 return err;
3536
3537 err = snd_soc_update_bits_locked(codec, reg, mask, val2);
3538 return err;
3539}
3540EXPORT_SYMBOL_GPL(snd_soc_put_strobe);
3541
3542/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003543 * snd_soc_dai_set_sysclk - configure DAI system or master clock.
3544 * @dai: DAI
3545 * @clk_id: DAI specific clock ID
3546 * @freq: new clock frequency in Hz
3547 * @dir: new clock direction - input/output.
3548 *
3549 * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
3550 */
3551int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
3552 unsigned int freq, int dir)
3553{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003554 if (dai->driver && dai->driver->ops->set_sysclk)
3555 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
Mark Brownec4ee522011-03-07 20:58:11 +00003556 else if (dai->codec && dai->codec->driver->set_sysclk)
Mark Brownda1c6ea2011-08-24 20:09:01 +01003557 return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0,
Mark Brownec4ee522011-03-07 20:58:11 +00003558 freq, dir);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003559 else
Mark Brown1104a9c2014-01-15 19:04:19 +00003560 return -ENOTSUPP;
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003561}
3562EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
3563
3564/**
Mark Brownec4ee522011-03-07 20:58:11 +00003565 * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
3566 * @codec: CODEC
3567 * @clk_id: DAI specific clock ID
Mark Brownda1c6ea2011-08-24 20:09:01 +01003568 * @source: Source for the clock
Mark Brownec4ee522011-03-07 20:58:11 +00003569 * @freq: new clock frequency in Hz
3570 * @dir: new clock direction - input/output.
3571 *
3572 * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
3573 */
3574int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
Mark Brownda1c6ea2011-08-24 20:09:01 +01003575 int source, unsigned int freq, int dir)
Mark Brownec4ee522011-03-07 20:58:11 +00003576{
3577 if (codec->driver->set_sysclk)
Mark Brownda1c6ea2011-08-24 20:09:01 +01003578 return codec->driver->set_sysclk(codec, clk_id, source,
3579 freq, dir);
Mark Brownec4ee522011-03-07 20:58:11 +00003580 else
Mark Brown1104a9c2014-01-15 19:04:19 +00003581 return -ENOTSUPP;
Mark Brownec4ee522011-03-07 20:58:11 +00003582}
3583EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
3584
3585/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003586 * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
3587 * @dai: DAI
Mark Brownac11a2b2009-01-01 12:18:17 +00003588 * @div_id: DAI specific clock divider ID
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003589 * @div: new clock divisor.
3590 *
3591 * Configures the clock dividers. This is used to derive the best DAI bit and
3592 * frame clocks from the system or master clock. It's best to set the DAI bit
3593 * and frame clocks as low as possible to save system power.
3594 */
3595int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
3596 int div_id, int div)
3597{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003598 if (dai->driver && dai->driver->ops->set_clkdiv)
3599 return dai->driver->ops->set_clkdiv(dai, div_id, div);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003600 else
3601 return -EINVAL;
3602}
3603EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
3604
3605/**
3606 * snd_soc_dai_set_pll - configure DAI PLL.
3607 * @dai: DAI
3608 * @pll_id: DAI specific PLL ID
Mark Brown85488032009-09-05 18:52:16 +01003609 * @source: DAI specific source for the PLL
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003610 * @freq_in: PLL input clock frequency in Hz
3611 * @freq_out: requested PLL output clock frequency in Hz
3612 *
3613 * Configures and enables PLL to generate output clock based on input clock.
3614 */
Mark Brown85488032009-09-05 18:52:16 +01003615int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
3616 unsigned int freq_in, unsigned int freq_out)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003617{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003618 if (dai->driver && dai->driver->ops->set_pll)
3619 return dai->driver->ops->set_pll(dai, pll_id, source,
Mark Brown85488032009-09-05 18:52:16 +01003620 freq_in, freq_out);
Mark Brownec4ee522011-03-07 20:58:11 +00003621 else if (dai->codec && dai->codec->driver->set_pll)
3622 return dai->codec->driver->set_pll(dai->codec, pll_id, source,
3623 freq_in, freq_out);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003624 else
3625 return -EINVAL;
3626}
3627EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
3628
Mark Brownec4ee522011-03-07 20:58:11 +00003629/*
3630 * snd_soc_codec_set_pll - configure codec PLL.
3631 * @codec: CODEC
3632 * @pll_id: DAI specific PLL ID
3633 * @source: DAI specific source for the PLL
3634 * @freq_in: PLL input clock frequency in Hz
3635 * @freq_out: requested PLL output clock frequency in Hz
3636 *
3637 * Configures and enables PLL to generate output clock based on input clock.
3638 */
3639int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
3640 unsigned int freq_in, unsigned int freq_out)
3641{
3642 if (codec->driver->set_pll)
3643 return codec->driver->set_pll(codec, pll_id, source,
3644 freq_in, freq_out);
3645 else
3646 return -EINVAL;
3647}
3648EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
3649
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003650/**
Liam Girdwoode54cf762013-09-16 13:01:46 +01003651 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
3652 * @dai: DAI
3653 * @ratio Ratio of BCLK to Sample rate.
3654 *
3655 * Configures the DAI for a preset BCLK to sample rate ratio.
3656 */
3657int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
3658{
3659 if (dai->driver && dai->driver->ops->set_bclk_ratio)
3660 return dai->driver->ops->set_bclk_ratio(dai, ratio);
3661 else
3662 return -EINVAL;
3663}
3664EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
3665
3666/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003667 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
3668 * @dai: DAI
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003669 * @fmt: SND_SOC_DAIFMT_ format value.
3670 *
3671 * Configures the DAI hardware format and clocking.
3672 */
3673int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3674{
Shawn Guo5e4ba562012-03-09 00:59:40 +08003675 if (dai->driver == NULL)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003676 return -EINVAL;
Shawn Guo5e4ba562012-03-09 00:59:40 +08003677 if (dai->driver->ops->set_fmt == NULL)
3678 return -ENOTSUPP;
3679 return dai->driver->ops->set_fmt(dai, fmt);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003680}
3681EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
3682
3683/**
Xiubo Lie5c21512014-03-21 14:17:12 +08003684 * snd_soc_xlate_tdm_slot - generate tx/rx slot mask.
Xiubo Li89c67852014-02-14 09:34:35 +08003685 * @slots: Number of slots in use.
3686 * @tx_mask: bitmask representing active TX slots.
3687 * @rx_mask: bitmask representing active RX slots.
3688 *
3689 * Generates the TDM tx and rx slot default masks for DAI.
3690 */
Xiubo Lie5c21512014-03-21 14:17:12 +08003691static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
Xiubo Li89c67852014-02-14 09:34:35 +08003692 unsigned int *tx_mask,
3693 unsigned int *rx_mask)
3694{
3695 if (*tx_mask || *rx_mask)
3696 return 0;
3697
3698 if (!slots)
3699 return -EINVAL;
3700
3701 *tx_mask = (1 << slots) - 1;
3702 *rx_mask = (1 << slots) - 1;
3703
3704 return 0;
3705}
3706
3707/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003708 * snd_soc_dai_set_tdm_slot - configure DAI TDM.
3709 * @dai: DAI
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03003710 * @tx_mask: bitmask representing active TX slots.
3711 * @rx_mask: bitmask representing active RX slots.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003712 * @slots: Number of slots in use.
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03003713 * @slot_width: Width in bits for each slot.
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003714 *
3715 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
3716 * specific.
3717 */
3718int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03003719 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003720{
Xiubo Lie5c21512014-03-21 14:17:12 +08003721 if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask)
3722 dai->driver->ops->xlate_tdm_slot_mask(slots,
Xiubo Li89c67852014-02-14 09:34:35 +08003723 &tx_mask, &rx_mask);
3724 else
Xiubo Lie5c21512014-03-21 14:17:12 +08003725 snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
Xiubo Li89c67852014-02-14 09:34:35 +08003726
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003727 if (dai->driver && dai->driver->ops->set_tdm_slot)
3728 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
Daniel Ribeiroa5479e32009-06-15 21:44:31 -03003729 slots, slot_width);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003730 else
Xiubo Lib2cbb6e2014-01-23 13:02:47 +08003731 return -ENOTSUPP;
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003732}
3733EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
3734
3735/**
Barry Song472df3c2009-09-12 01:16:29 +08003736 * snd_soc_dai_set_channel_map - configure DAI audio channel map
3737 * @dai: DAI
3738 * @tx_num: how many TX channels
3739 * @tx_slot: pointer to an array which imply the TX slot number channel
3740 * 0~num-1 uses
3741 * @rx_num: how many RX channels
3742 * @rx_slot: pointer to an array which imply the RX slot number channel
3743 * 0~num-1 uses
3744 *
3745 * configure the relationship between channel number and TDM slot number.
3746 */
3747int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
3748 unsigned int tx_num, unsigned int *tx_slot,
3749 unsigned int rx_num, unsigned int *rx_slot)
3750{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003751 if (dai->driver && dai->driver->ops->set_channel_map)
3752 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
Barry Song472df3c2009-09-12 01:16:29 +08003753 rx_num, rx_slot);
3754 else
3755 return -EINVAL;
3756}
3757EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
3758
3759/**
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003760 * snd_soc_dai_set_tristate - configure DAI system or master clock.
3761 * @dai: DAI
3762 * @tristate: tristate enable
3763 *
3764 * Tristates the DAI so that others can use it.
3765 */
3766int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
3767{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003768 if (dai->driver && dai->driver->ops->set_tristate)
3769 return dai->driver->ops->set_tristate(dai, tristate);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003770 else
3771 return -EINVAL;
3772}
3773EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
3774
3775/**
3776 * snd_soc_dai_digital_mute - configure DAI system or master clock.
3777 * @dai: DAI
3778 * @mute: mute enable
Mark Brownda183962013-02-06 15:44:07 +00003779 * @direction: stream to mute
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003780 *
3781 * Mutes the DAI DAC.
3782 */
Mark Brownda183962013-02-06 15:44:07 +00003783int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
3784 int direction)
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003785{
Mark Brownda183962013-02-06 15:44:07 +00003786 if (!dai->driver)
3787 return -ENOTSUPP;
3788
3789 if (dai->driver->ops->mute_stream)
3790 return dai->driver->ops->mute_stream(dai, mute, direction);
3791 else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
3792 dai->driver->ops->digital_mute)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003793 return dai->driver->ops->digital_mute(dai, mute);
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003794 else
Mark Brown04570c62012-04-13 19:16:03 +01003795 return -ENOTSUPP;
Liam Girdwood8c6529d2008-07-08 13:19:13 +01003796}
3797EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
3798
Mark Brownc5af3a22008-11-28 13:29:45 +00003799/**
3800 * snd_soc_register_card - Register a card with the ASoC core
3801 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003802 * @card: Card to register
Mark Brownc5af3a22008-11-28 13:29:45 +00003803 *
Mark Brownc5af3a22008-11-28 13:29:45 +00003804 */
Vinod Koul70a7ca32011-01-14 19:22:48 +05303805int snd_soc_register_card(struct snd_soc_card *card)
Mark Brownc5af3a22008-11-28 13:29:45 +00003806{
Mark Brownb19e6e72012-03-14 21:18:39 +00003807 int i, ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003808
Mark Brownc5af3a22008-11-28 13:29:45 +00003809 if (!card->name || !card->dev)
3810 return -EINVAL;
3811
Stephen Warren5a504962011-12-21 10:40:59 -07003812 for (i = 0; i < card->num_links; i++) {
3813 struct snd_soc_dai_link *link = &card->dai_link[i];
3814
3815 /*
3816 * Codec must be specified by 1 of name or OF node,
3817 * not both or neither.
3818 */
3819 if (!!link->codec_name == !!link->codec_of_node) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02003820 dev_err(card->dev,
3821 "ASoC: Neither/both codec name/of_node are set for %s\n",
3822 link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07003823 return -EINVAL;
3824 }
Stephen Warrenbc926572012-05-25 18:22:11 -06003825 /* Codec DAI name must be specified */
3826 if (!link->codec_dai_name) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02003827 dev_err(card->dev,
3828 "ASoC: codec_dai_name not set for %s\n",
3829 link->name);
Stephen Warrenbc926572012-05-25 18:22:11 -06003830 return -EINVAL;
3831 }
Stephen Warren5a504962011-12-21 10:40:59 -07003832
3833 /*
3834 * Platform may be specified by either name or OF node, but
3835 * can be left unspecified, and a dummy platform will be used.
3836 */
3837 if (link->platform_name && link->platform_of_node) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02003838 dev_err(card->dev,
3839 "ASoC: Both platform name/of_node are set for %s\n",
3840 link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07003841 return -EINVAL;
3842 }
3843
3844 /*
Stephen Warrenbc926572012-05-25 18:22:11 -06003845 * CPU device may be specified by either name or OF node, but
3846 * can be left unspecified, and will be matched based on DAI
3847 * name alone..
Stephen Warren5a504962011-12-21 10:40:59 -07003848 */
Stephen Warrenbc926572012-05-25 18:22:11 -06003849 if (link->cpu_name && link->cpu_of_node) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02003850 dev_err(card->dev,
3851 "ASoC: Neither/both cpu name/of_node are set for %s\n",
3852 link->name);
Stephen Warrenbc926572012-05-25 18:22:11 -06003853 return -EINVAL;
3854 }
3855 /*
3856 * At least one of CPU DAI name or CPU device name/node must be
3857 * specified
3858 */
3859 if (!link->cpu_dai_name &&
3860 !(link->cpu_name || link->cpu_of_node)) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02003861 dev_err(card->dev,
3862 "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
3863 link->name);
Stephen Warren5a504962011-12-21 10:40:59 -07003864 return -EINVAL;
3865 }
3866 }
3867
Mark Browned77cc12011-05-03 18:25:34 +01003868 dev_set_drvdata(card->dev, card);
3869
Stephen Warren111c6412011-01-28 14:26:35 -07003870 snd_soc_initialize_card_lists(card);
3871
Vinod Koul150dd2f2011-01-13 22:48:32 +05303872 soc_init_card_debugfs(card);
3873
Mark Brown181a6892012-03-14 20:18:49 +00003874 card->rtd = devm_kzalloc(card->dev,
3875 sizeof(struct snd_soc_pcm_runtime) *
3876 (card->num_links + card->num_aux_devs),
3877 GFP_KERNEL);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003878 if (card->rtd == NULL)
3879 return -ENOMEM;
Liam Girdwooda7dbb602012-04-17 18:00:11 +01003880 card->num_rtd = 0;
Jarkko Nikula2eea3922010-11-25 17:47:38 +02003881 card->rtd_aux = &card->rtd[card->num_links];
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003882
3883 for (i = 0; i < card->num_links; i++)
3884 card->rtd[i].dai_link = &card->dai_link[i];
3885
Mark Brownc5af3a22008-11-28 13:29:45 +00003886 INIT_LIST_HEAD(&card->list);
Mark Browndb432b42011-10-03 21:06:40 +01003887 INIT_LIST_HEAD(&card->dapm_dirty);
Mark Brownc5af3a22008-11-28 13:29:45 +00003888 card->instantiated = 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003889 mutex_init(&card->mutex);
Liam Girdwooda73fb2d2012-03-07 10:38:26 +00003890 mutex_init(&card->dapm_mutex);
Mark Brownc5af3a22008-11-28 13:29:45 +00003891
Mark Brownb19e6e72012-03-14 21:18:39 +00003892 ret = snd_soc_instantiate_card(card);
3893 if (ret != 0)
3894 soc_cleanup_card_debugfs(card);
Mark Brownc5af3a22008-11-28 13:29:45 +00003895
Nicolin Chen988e8cc2013-11-04 14:57:31 +08003896 /* deactivate pins to sleep state */
3897 for (i = 0; i < card->num_rtd; i++) {
3898 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
3899 struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
3900 if (!codec_dai->active)
3901 pinctrl_pm_select_sleep_state(codec_dai->dev);
3902 if (!cpu_dai->active)
3903 pinctrl_pm_select_sleep_state(cpu_dai->dev);
3904 }
3905
Mark Brownb19e6e72012-03-14 21:18:39 +00003906 return ret;
Mark Brownc5af3a22008-11-28 13:29:45 +00003907}
Vinod Koul70a7ca32011-01-14 19:22:48 +05303908EXPORT_SYMBOL_GPL(snd_soc_register_card);
Mark Brownc5af3a22008-11-28 13:29:45 +00003909
3910/**
3911 * snd_soc_unregister_card - Unregister a card with the ASoC core
3912 *
Mark Brownac11a2b2009-01-01 12:18:17 +00003913 * @card: Card to unregister
Mark Brownc5af3a22008-11-28 13:29:45 +00003914 *
Mark Brownc5af3a22008-11-28 13:29:45 +00003915 */
Vinod Koul70a7ca32011-01-14 19:22:48 +05303916int snd_soc_unregister_card(struct snd_soc_card *card)
Mark Brownc5af3a22008-11-28 13:29:45 +00003917{
Vinod Koulb0e26482011-01-13 22:48:02 +05303918 if (card->instantiated)
3919 soc_cleanup_card_resources(card);
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00003920 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
Mark Brownc5af3a22008-11-28 13:29:45 +00003921
3922 return 0;
3923}
Vinod Koul70a7ca32011-01-14 19:22:48 +05303924EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
Mark Brownc5af3a22008-11-28 13:29:45 +00003925
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003926/*
3927 * Simplify DAI link configuration by removing ".-1" from device names
3928 * and sanitizing names.
3929 */
Dimitris Papastamos0b9a2142010-12-06 15:49:20 +00003930static char *fmt_single_name(struct device *dev, int *id)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003931{
3932 char *found, name[NAME_SIZE];
3933 int id1, id2;
3934
3935 if (dev_name(dev) == NULL)
3936 return NULL;
3937
Dimitris Papastamos58818a72010-12-06 15:42:17 +00003938 strlcpy(name, dev_name(dev), NAME_SIZE);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003939
3940 /* are we a "%s.%d" name (platform and SPI components) */
3941 found = strstr(name, dev->driver->name);
3942 if (found) {
3943 /* get ID */
3944 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
3945
3946 /* discard ID from name if ID == -1 */
3947 if (*id == -1)
3948 found[strlen(dev->driver->name)] = '\0';
3949 }
3950
3951 } else {
3952 /* I2C component devices are named "bus-addr" */
3953 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
3954 char tmp[NAME_SIZE];
3955
3956 /* create unique ID number from I2C addr and bus */
Jarkko Nikula05899442010-10-19 11:10:45 +03003957 *id = ((id1 & 0xffff) << 16) + id2;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003958
3959 /* sanitize component name for DAI link creation */
3960 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
Dimitris Papastamos58818a72010-12-06 15:42:17 +00003961 strlcpy(name, tmp, NAME_SIZE);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003962 } else
3963 *id = 0;
3964 }
3965
3966 return kstrdup(name, GFP_KERNEL);
3967}
3968
3969/*
3970 * Simplify DAI link naming for single devices with multiple DAIs by removing
3971 * any ".-1" and using the DAI name (instead of device name).
3972 */
3973static inline char *fmt_multiple_name(struct device *dev,
3974 struct snd_soc_dai_driver *dai_drv)
3975{
3976 if (dai_drv->name == NULL) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02003977 dev_err(dev,
3978 "ASoC: error - multiple DAI %s registered with no name\n",
3979 dev_name(dev));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00003980 return NULL;
3981 }
3982
3983 return kstrdup(dai_drv->name, GFP_KERNEL);
3984}
3985
Mark Brown91151712008-11-30 23:31:24 +00003986/**
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01003987 * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
Mark Brown91151712008-11-30 23:31:24 +00003988 *
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01003989 * @component: The component for which the DAIs should be unregistered
Mark Brown91151712008-11-30 23:31:24 +00003990 */
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01003991static void snd_soc_unregister_dais(struct snd_soc_component *component)
Mark Brown91151712008-11-30 23:31:24 +00003992{
Lars-Peter Clausen5c1d5f02014-03-12 08:34:39 +01003993 struct snd_soc_dai *dai, *_dai;
Mark Brown91151712008-11-30 23:31:24 +00003994
Lars-Peter Clausen5c1d5f02014-03-12 08:34:39 +01003995 list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01003996 dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
3997 dai->name);
Lars-Peter Clausen5c1d5f02014-03-12 08:34:39 +01003998 list_del(&dai->list);
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01003999 kfree(dai->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004000 kfree(dai);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004001 }
Mark Brown91151712008-11-30 23:31:24 +00004002}
Mark Brown91151712008-11-30 23:31:24 +00004003
4004/**
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004005 * snd_soc_register_dais - Register a DAI with the ASoC core
Mark Brown91151712008-11-30 23:31:24 +00004006 *
Lars-Peter Clausen6106d122014-03-05 13:17:46 +01004007 * @component: The component the DAIs are registered for
Lars-Peter Clausen6cc240f2014-03-09 17:41:46 +01004008 * @codec: The CODEC that the DAIs are registered for, NULL if the component is
4009 * not a CODEC.
Lars-Peter Clausen6106d122014-03-05 13:17:46 +01004010 * @dai_drv: DAI driver to use for the DAIs
Mark Brownac11a2b2009-01-01 12:18:17 +00004011 * @count: Number of DAIs
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004012 * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the
4013 * parent's name.
Mark Brown91151712008-11-30 23:31:24 +00004014 */
Lars-Peter Clausen6106d122014-03-05 13:17:46 +01004015static int snd_soc_register_dais(struct snd_soc_component *component,
Lars-Peter Clausen6cc240f2014-03-09 17:41:46 +01004016 struct snd_soc_codec *codec, struct snd_soc_dai_driver *dai_drv,
4017 size_t count, bool legacy_dai_naming)
Mark Brown91151712008-11-30 23:31:24 +00004018{
Lars-Peter Clausen6106d122014-03-05 13:17:46 +01004019 struct device *dev = component->dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004020 struct snd_soc_dai *dai;
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004021 unsigned int i;
4022 int ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004023
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00004024 dev_dbg(dev, "ASoC: dai register %s #%Zu\n", dev_name(dev), count);
Mark Brown91151712008-11-30 23:31:24 +00004025
4026 for (i = 0; i < count; i++) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004027
4028 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
Axel Linc46e0072010-11-03 15:04:45 +08004029 if (dai == NULL) {
4030 ret = -ENOMEM;
4031 goto err;
4032 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004033
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004034 /*
4035 * Back in the old days when we still had component-less DAIs,
4036 * instead of having a static name, component-less DAIs would
4037 * inherit the name of the parent device so it is possible to
4038 * register multiple instances of the DAI. We still need to keep
4039 * the same naming style even though those DAIs are not
4040 * component-less anymore.
4041 */
4042 if (count == 1 && legacy_dai_naming) {
4043 dai->name = fmt_single_name(dev, &dai->id);
4044 } else {
4045 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
4046 if (dai_drv[i].id)
4047 dai->id = dai_drv[i].id;
4048 else
4049 dai->id = i;
4050 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004051 if (dai->name == NULL) {
4052 kfree(dai);
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004053 ret = -ENOMEM;
Mark Brown91151712008-11-30 23:31:24 +00004054 goto err;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004055 }
4056
Lars-Peter Clausen6106d122014-03-05 13:17:46 +01004057 dai->component = component;
Lars-Peter Clausen6cc240f2014-03-09 17:41:46 +01004058 dai->codec = codec;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004059 dai->dev = dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004060 dai->driver = &dai_drv[i];
Liam Girdwoodbe09ad92012-03-07 11:47:41 +00004061 dai->dapm.dev = dev;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004062 if (!dai->driver->ops)
4063 dai->driver->ops = &null_dai_ops;
4064
Peter Ujfalusi5f800082012-08-07 10:24:13 +03004065 if (!dai->codec)
4066 dai->dapm.idle_bias_off = 1;
4067
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +01004068 list_add(&dai->list, &component->dai_list);
Mark Brown054880f2012-04-09 17:29:19 +01004069
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004070 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
Mark Brown91151712008-11-30 23:31:24 +00004071 }
4072
4073 return 0;
4074
4075err:
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004076 snd_soc_unregister_dais(component);
Mark Brown91151712008-11-30 23:31:24 +00004077
4078 return ret;
4079}
Mark Brown91151712008-11-30 23:31:24 +00004080
4081/**
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004082 * snd_soc_register_component - Register a component with the ASoC core
4083 *
4084 */
4085static int
4086__snd_soc_register_component(struct device *dev,
4087 struct snd_soc_component *cmpnt,
4088 const struct snd_soc_component_driver *cmpnt_drv,
Lars-Peter Clausen6cc240f2014-03-09 17:41:46 +01004089 struct snd_soc_codec *codec,
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004090 struct snd_soc_dai_driver *dai_drv,
4091 int num_dai, bool allow_single_dai)
4092{
4093 int ret;
4094
4095 dev_dbg(dev, "component register %s\n", dev_name(dev));
4096
4097 if (!cmpnt) {
4098 dev_err(dev, "ASoC: Failed to connecting component\n");
4099 return -ENOMEM;
4100 }
4101
4102 cmpnt->name = fmt_single_name(dev, &cmpnt->id);
4103 if (!cmpnt->name) {
4104 dev_err(dev, "ASoC: Failed to simplifying name\n");
4105 return -ENOMEM;
4106 }
4107
4108 cmpnt->dev = dev;
4109 cmpnt->driver = cmpnt_drv;
Kuninori Morimoto6833c452013-10-16 22:05:26 -07004110 cmpnt->dai_drv = dai_drv;
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004111 cmpnt->num_dai = num_dai;
Lars-Peter Clausen1438c2f2014-03-09 17:41:47 +01004112 INIT_LIST_HEAD(&cmpnt->dai_list);
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004113
Lars-Peter Clausen6cc240f2014-03-09 17:41:46 +01004114 ret = snd_soc_register_dais(cmpnt, codec, dai_drv, num_dai,
4115 allow_single_dai);
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004116 if (ret < 0) {
4117 dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret);
4118 goto error_component_name;
4119 }
4120
4121 mutex_lock(&client_mutex);
4122 list_add(&cmpnt->list, &component_list);
4123 mutex_unlock(&client_mutex);
4124
4125 dev_dbg(cmpnt->dev, "ASoC: Registered component '%s'\n", cmpnt->name);
4126
4127 return ret;
4128
4129error_component_name:
4130 kfree(cmpnt->name);
4131
4132 return ret;
4133}
4134
4135int snd_soc_register_component(struct device *dev,
4136 const struct snd_soc_component_driver *cmpnt_drv,
4137 struct snd_soc_dai_driver *dai_drv,
4138 int num_dai)
4139{
4140 struct snd_soc_component *cmpnt;
4141
4142 cmpnt = devm_kzalloc(dev, sizeof(*cmpnt), GFP_KERNEL);
4143 if (!cmpnt) {
4144 dev_err(dev, "ASoC: Failed to allocate memory\n");
4145 return -ENOMEM;
4146 }
4147
Lars-Peter Clausen3d594002014-03-05 13:17:48 +01004148 cmpnt->ignore_pmdown_time = true;
4149
Lars-Peter Clausen6cc240f2014-03-09 17:41:46 +01004150 return __snd_soc_register_component(dev, cmpnt, cmpnt_drv, NULL,
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004151 dai_drv, num_dai, true);
4152}
4153EXPORT_SYMBOL_GPL(snd_soc_register_component);
4154
4155/**
4156 * snd_soc_unregister_component - Unregister a component from the ASoC core
4157 *
4158 */
4159void snd_soc_unregister_component(struct device *dev)
4160{
4161 struct snd_soc_component *cmpnt;
4162
4163 list_for_each_entry(cmpnt, &component_list, list) {
4164 if (dev == cmpnt->dev)
4165 goto found;
4166 }
4167 return;
4168
4169found:
Lars-Peter Clausen32c9ba52014-03-09 17:41:45 +01004170 snd_soc_unregister_dais(cmpnt);
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004171
4172 mutex_lock(&client_mutex);
4173 list_del(&cmpnt->list);
4174 mutex_unlock(&client_mutex);
4175
4176 dev_dbg(dev, "ASoC: Unregistered component '%s'\n", cmpnt->name);
4177 kfree(cmpnt->name);
4178}
4179EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
4180
4181/**
Lars-Peter Clausen71a45cd2013-04-15 19:19:49 +02004182 * snd_soc_add_platform - Add a platform to the ASoC core
4183 * @dev: The parent device for the platform
4184 * @platform: The platform to add
4185 * @platform_driver: The driver for the platform
Mark Brown12a48a8c2008-12-03 19:40:30 +00004186 */
Lars-Peter Clausen71a45cd2013-04-15 19:19:49 +02004187int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
Lars-Peter Clausend79e57d2013-03-27 12:02:22 +01004188 const struct snd_soc_platform_driver *platform_drv)
Mark Brown12a48a8c2008-12-03 19:40:30 +00004189{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004190 /* create platform component name */
4191 platform->name = fmt_single_name(dev, &platform->id);
Dan Carpenterb5c745f2013-07-22 09:56:54 +03004192 if (platform->name == NULL)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004193 return -ENOMEM;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004194
4195 platform->dev = dev;
4196 platform->driver = platform_drv;
Liam Girdwoodb7950642011-07-04 22:10:52 +01004197 platform->dapm.dev = dev;
4198 platform->dapm.platform = platform;
Liam Girdwood64a648c2011-07-25 11:15:15 +01004199 platform->dapm.stream_event = platform_drv->stream_event;
Liam Girdwoodcc22d372012-03-06 18:16:18 +00004200 mutex_init(&platform->mutex);
Mark Brown12a48a8c2008-12-03 19:40:30 +00004201
4202 mutex_lock(&client_mutex);
4203 list_add(&platform->list, &platform_list);
4204 mutex_unlock(&client_mutex);
4205
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00004206 dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name);
Mark Brown12a48a8c2008-12-03 19:40:30 +00004207
4208 return 0;
4209}
Lars-Peter Clausen71a45cd2013-04-15 19:19:49 +02004210EXPORT_SYMBOL_GPL(snd_soc_add_platform);
4211
4212/**
4213 * snd_soc_register_platform - Register a platform with the ASoC core
4214 *
4215 * @platform: platform to register
4216 */
4217int snd_soc_register_platform(struct device *dev,
4218 const struct snd_soc_platform_driver *platform_drv)
4219{
4220 struct snd_soc_platform *platform;
4221 int ret;
4222
4223 dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev));
4224
4225 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
4226 if (platform == NULL)
4227 return -ENOMEM;
4228
4229 ret = snd_soc_add_platform(dev, platform, platform_drv);
4230 if (ret)
4231 kfree(platform);
4232
4233 return ret;
4234}
Mark Brown12a48a8c2008-12-03 19:40:30 +00004235EXPORT_SYMBOL_GPL(snd_soc_register_platform);
4236
4237/**
Lars-Peter Clausen71a45cd2013-04-15 19:19:49 +02004238 * snd_soc_remove_platform - Remove a platform from the ASoC core
4239 * @platform: the platform to remove
4240 */
4241void snd_soc_remove_platform(struct snd_soc_platform *platform)
4242{
4243 mutex_lock(&client_mutex);
4244 list_del(&platform->list);
4245 mutex_unlock(&client_mutex);
4246
4247 dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n",
4248 platform->name);
4249 kfree(platform->name);
4250}
4251EXPORT_SYMBOL_GPL(snd_soc_remove_platform);
4252
4253struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev)
4254{
4255 struct snd_soc_platform *platform;
4256
4257 list_for_each_entry(platform, &platform_list, list) {
4258 if (dev == platform->dev)
4259 return platform;
4260 }
4261
4262 return NULL;
4263}
4264EXPORT_SYMBOL_GPL(snd_soc_lookup_platform);
4265
4266/**
Mark Brown12a48a8c2008-12-03 19:40:30 +00004267 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
4268 *
Mark Brownac11a2b2009-01-01 12:18:17 +00004269 * @platform: platform to unregister
Mark Brown12a48a8c2008-12-03 19:40:30 +00004270 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004271void snd_soc_unregister_platform(struct device *dev)
Mark Brown12a48a8c2008-12-03 19:40:30 +00004272{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004273 struct snd_soc_platform *platform;
4274
Lars-Peter Clausen71a45cd2013-04-15 19:19:49 +02004275 platform = snd_soc_lookup_platform(dev);
4276 if (!platform)
4277 return;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004278
Lars-Peter Clausen71a45cd2013-04-15 19:19:49 +02004279 snd_soc_remove_platform(platform);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004280 kfree(platform);
Mark Brown12a48a8c2008-12-03 19:40:30 +00004281}
4282EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
4283
Mark Brown151ab222009-05-09 16:22:58 +01004284static u64 codec_format_map[] = {
4285 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
4286 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
4287 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
4288 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
4289 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
4290 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
4291 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
4292 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
4293 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
4294 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
4295 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
4296 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
4297 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
4298 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
4299 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
4300 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
4301};
4302
4303/* Fix up the DAI formats for endianness: codecs don't actually see
4304 * the endianness of the data but we're using the CPU format
4305 * definitions which do need to include endianness so we ensure that
4306 * codec DAIs always have both big and little endian variants set.
4307 */
4308static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
4309{
4310 int i;
4311
4312 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
4313 if (stream->formats & codec_format_map[i])
4314 stream->formats |= codec_format_map[i];
4315}
4316
Mark Brown0d0cf002008-12-10 14:32:45 +00004317/**
4318 * snd_soc_register_codec - Register a codec with the ASoC core
4319 *
Mark Brownac11a2b2009-01-01 12:18:17 +00004320 * @codec: codec to register
Mark Brown0d0cf002008-12-10 14:32:45 +00004321 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004322int snd_soc_register_codec(struct device *dev,
Mark Brown001ae4c2010-12-02 16:21:08 +00004323 const struct snd_soc_codec_driver *codec_drv,
4324 struct snd_soc_dai_driver *dai_drv,
4325 int num_dai)
Mark Brown0d0cf002008-12-10 14:32:45 +00004326{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004327 struct snd_soc_codec *codec;
4328 int ret, i;
Mark Brown151ab222009-05-09 16:22:58 +01004329
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004330 dev_dbg(dev, "codec register %s\n", dev_name(dev));
Mark Brown0d0cf002008-12-10 14:32:45 +00004331
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004332 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
4333 if (codec == NULL)
4334 return -ENOMEM;
Mark Brown0d0cf002008-12-10 14:32:45 +00004335
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004336 /* create CODEC component name */
4337 codec->name = fmt_single_name(dev, &codec->id);
4338 if (codec->name == NULL) {
Kuninori Morimotof790b942013-02-25 00:40:09 -08004339 ret = -ENOMEM;
4340 goto fail_codec;
Mark Brown151ab222009-05-09 16:22:58 +01004341 }
4342
Mark Brownc3acec22010-12-02 16:15:29 +00004343 codec->write = codec_drv->write;
4344 codec->read = codec_drv->read;
Dimitris Papastamos1500b7b2011-01-13 12:20:38 +00004345 codec->volatile_register = codec_drv->volatile_register;
4346 codec->readable_register = codec_drv->readable_register;
Dimitris Papastamos80204542011-03-24 13:45:17 +00004347 codec->writable_register = codec_drv->writable_register;
Lars-Peter Clausen3d594002014-03-05 13:17:48 +01004348 codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02004349 codec->dapm.bias_level = SND_SOC_BIAS_OFF;
4350 codec->dapm.dev = dev;
4351 codec->dapm.codec = codec;
Mark Brown474b62d2011-01-18 16:14:44 +00004352 codec->dapm.seq_notifier = codec_drv->seq_notifier;
Liam Girdwood64a648c2011-07-25 11:15:15 +01004353 codec->dapm.stream_event = codec_drv->stream_event;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004354 codec->dev = dev;
4355 codec->driver = codec_drv;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004356 codec->num_dai = num_dai;
4357 mutex_init(&codec->mutex);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004358
4359 for (i = 0; i < num_dai; i++) {
4360 fixup_codec_formats(&dai_drv[i].playback);
4361 fixup_codec_formats(&dai_drv[i].capture);
4362 }
4363
Mark Brown054880f2012-04-09 17:29:19 +01004364 mutex_lock(&client_mutex);
4365 list_add(&codec->list, &codec_list);
4366 mutex_unlock(&client_mutex);
4367
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004368 /* register component */
4369 ret = __snd_soc_register_component(dev, &codec->component,
4370 &codec_drv->component_driver,
Lars-Peter Clausen6cc240f2014-03-09 17:41:46 +01004371 codec, dai_drv, num_dai, false);
Kuninori Morimoto5acd7df2013-02-25 00:40:40 -08004372 if (ret < 0) {
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004373 dev_err(codec->dev, "ASoC: Failed to regster component: %d\n", ret);
Kuninori Morimoto5acd7df2013-02-25 00:40:40 -08004374 goto fail_codec_name;
Mark Brown26b01cc2010-08-18 20:20:55 +01004375 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004376
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00004377 dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name);
Mark Brown0d0cf002008-12-10 14:32:45 +00004378 return 0;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004379
Kuninori Morimotof790b942013-02-25 00:40:09 -08004380fail_codec_name:
Kuninori Morimotoe1328a82013-03-07 17:42:33 -08004381 mutex_lock(&client_mutex);
4382 list_del(&codec->list);
4383 mutex_unlock(&client_mutex);
4384
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004385 kfree(codec->name);
Kuninori Morimotof790b942013-02-25 00:40:09 -08004386fail_codec:
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004387 kfree(codec);
4388 return ret;
Mark Brown0d0cf002008-12-10 14:32:45 +00004389}
4390EXPORT_SYMBOL_GPL(snd_soc_register_codec);
4391
4392/**
4393 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
4394 *
Mark Brownac11a2b2009-01-01 12:18:17 +00004395 * @codec: codec to unregister
Mark Brown0d0cf002008-12-10 14:32:45 +00004396 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004397void snd_soc_unregister_codec(struct device *dev)
Mark Brown0d0cf002008-12-10 14:32:45 +00004398{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004399 struct snd_soc_codec *codec;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004400
4401 list_for_each_entry(codec, &codec_list, list) {
4402 if (dev == codec->dev)
4403 goto found;
4404 }
4405 return;
4406
4407found:
Kuninori Morimotod191bd82013-09-04 19:39:03 -07004408 snd_soc_unregister_component(dev);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004409
Mark Brown0d0cf002008-12-10 14:32:45 +00004410 mutex_lock(&client_mutex);
4411 list_del(&codec->list);
4412 mutex_unlock(&client_mutex);
4413
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00004414 dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004415
Dimitris Papastamos7a30a3d2010-11-11 10:04:57 +00004416 snd_soc_cache_exit(codec);
Dimitris Papastamos1aafcd42010-10-21 13:19:45 +01004417 kfree(codec->name);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00004418 kfree(codec);
Mark Brown0d0cf002008-12-10 14:32:45 +00004419}
4420EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
4421
Stephen Warrenbec4fa02011-12-12 15:55:34 -07004422/* Retrieve a card's name from device tree */
4423int snd_soc_of_parse_card_name(struct snd_soc_card *card,
4424 const char *propname)
4425{
4426 struct device_node *np = card->dev->of_node;
4427 int ret;
4428
4429 ret = of_property_read_string_index(np, propname, 0, &card->name);
4430 /*
4431 * EINVAL means the property does not exist. This is fine providing
4432 * card->name was previously set, which is checked later in
4433 * snd_soc_register_card.
4434 */
4435 if (ret < 0 && ret != -EINVAL) {
4436 dev_err(card->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00004437 "ASoC: Property '%s' could not be read: %d\n",
Stephen Warrenbec4fa02011-12-12 15:55:34 -07004438 propname, ret);
4439 return ret;
4440 }
4441
4442 return 0;
4443}
4444EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
4445
Xiubo Li9a6d4862014-02-08 15:59:52 +08004446static const struct snd_soc_dapm_widget simple_widgets[] = {
4447 SND_SOC_DAPM_MIC("Microphone", NULL),
4448 SND_SOC_DAPM_LINE("Line", NULL),
4449 SND_SOC_DAPM_HP("Headphone", NULL),
4450 SND_SOC_DAPM_SPK("Speaker", NULL),
4451};
4452
4453int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
4454 const char *propname)
4455{
4456 struct device_node *np = card->dev->of_node;
4457 struct snd_soc_dapm_widget *widgets;
4458 const char *template, *wname;
4459 int i, j, num_widgets, ret;
4460
4461 num_widgets = of_property_count_strings(np, propname);
4462 if (num_widgets < 0) {
4463 dev_err(card->dev,
4464 "ASoC: Property '%s' does not exist\n", propname);
4465 return -EINVAL;
4466 }
4467 if (num_widgets & 1) {
4468 dev_err(card->dev,
4469 "ASoC: Property '%s' length is not even\n", propname);
4470 return -EINVAL;
4471 }
4472
4473 num_widgets /= 2;
4474 if (!num_widgets) {
4475 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
4476 propname);
4477 return -EINVAL;
4478 }
4479
4480 widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
4481 GFP_KERNEL);
4482 if (!widgets) {
4483 dev_err(card->dev,
4484 "ASoC: Could not allocate memory for widgets\n");
4485 return -ENOMEM;
4486 }
4487
4488 for (i = 0; i < num_widgets; i++) {
4489 ret = of_property_read_string_index(np, propname,
4490 2 * i, &template);
4491 if (ret) {
4492 dev_err(card->dev,
4493 "ASoC: Property '%s' index %d read error:%d\n",
4494 propname, 2 * i, ret);
4495 return -EINVAL;
4496 }
4497
4498 for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
4499 if (!strncmp(template, simple_widgets[j].name,
4500 strlen(simple_widgets[j].name))) {
4501 widgets[i] = simple_widgets[j];
4502 break;
4503 }
4504 }
4505
4506 if (j >= ARRAY_SIZE(simple_widgets)) {
4507 dev_err(card->dev,
4508 "ASoC: DAPM widget '%s' is not supported\n",
4509 template);
4510 return -EINVAL;
4511 }
4512
4513 ret = of_property_read_string_index(np, propname,
4514 (2 * i) + 1,
4515 &wname);
4516 if (ret) {
4517 dev_err(card->dev,
4518 "ASoC: Property '%s' index %d read error:%d\n",
4519 propname, (2 * i) + 1, ret);
4520 return -EINVAL;
4521 }
4522
4523 widgets[i].name = wname;
4524 }
4525
4526 card->dapm_widgets = widgets;
4527 card->num_dapm_widgets = num_widgets;
4528
4529 return 0;
4530}
4531EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
4532
Xiubo Li89c67852014-02-14 09:34:35 +08004533int snd_soc_of_parse_tdm_slot(struct device_node *np,
4534 unsigned int *slots,
4535 unsigned int *slot_width)
4536{
4537 u32 val;
4538 int ret;
4539
4540 if (of_property_read_bool(np, "dai-tdm-slot-num")) {
4541 ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
4542 if (ret)
4543 return ret;
4544
4545 if (slots)
4546 *slots = val;
4547 }
4548
4549 if (of_property_read_bool(np, "dai-tdm-slot-width")) {
4550 ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
4551 if (ret)
4552 return ret;
4553
4554 if (slot_width)
4555 *slot_width = val;
4556 }
4557
4558 return 0;
4559}
4560EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
4561
Stephen Warrena4a54dd2011-12-12 15:55:35 -07004562int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
4563 const char *propname)
4564{
4565 struct device_node *np = card->dev->of_node;
4566 int num_routes;
4567 struct snd_soc_dapm_route *routes;
4568 int i, ret;
4569
4570 num_routes = of_property_count_strings(np, propname);
Richard Zhaoc34ce322012-04-24 15:24:43 +08004571 if (num_routes < 0 || num_routes & 1) {
Michał Mirosław10e8aa92013-05-04 22:21:38 +02004572 dev_err(card->dev,
4573 "ASoC: Property '%s' does not exist or its length is not even\n",
4574 propname);
Stephen Warrena4a54dd2011-12-12 15:55:35 -07004575 return -EINVAL;
4576 }
4577 num_routes /= 2;
4578 if (!num_routes) {
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00004579 dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
Stephen Warrena4a54dd2011-12-12 15:55:35 -07004580 propname);
4581 return -EINVAL;
4582 }
4583
4584 routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes),
4585 GFP_KERNEL);
4586 if (!routes) {
4587 dev_err(card->dev,
Liam Girdwoodf110bfc2012-11-19 14:47:09 +00004588 "ASoC: Could not allocate DAPM route table\n");
Stephen Warrena4a54dd2011-12-12 15:55:35 -07004589 return -EINVAL;
4590 }
4591
4592 for (i = 0; i < num_routes; i++) {
4593 ret = of_property_read_string_index(np, propname,
4594 2 * i, &routes[i].sink);
4595 if (ret) {
Mark Brownc871bd02012-12-10 16:19:52 +09004596 dev_err(card->dev,
4597 "ASoC: Property '%s' index %d could not be read: %d\n",
4598 propname, 2 * i, ret);
Stephen Warrena4a54dd2011-12-12 15:55:35 -07004599 return -EINVAL;
4600 }
4601 ret = of_property_read_string_index(np, propname,
4602 (2 * i) + 1, &routes[i].source);
4603 if (ret) {
4604 dev_err(card->dev,
Mark Brownc871bd02012-12-10 16:19:52 +09004605 "ASoC: Property '%s' index %d could not be read: %d\n",
4606 propname, (2 * i) + 1, ret);
Stephen Warrena4a54dd2011-12-12 15:55:35 -07004607 return -EINVAL;
4608 }
4609 }
4610
4611 card->num_dapm_routes = num_routes;
4612 card->dapm_routes = routes;
4613
4614 return 0;
4615}
4616EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
4617
Kuninori Morimotoa7930ed2013-01-14 18:36:04 -08004618unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
4619 const char *prefix)
4620{
4621 int ret, i;
4622 char prop[128];
4623 unsigned int format = 0;
4624 int bit, frame;
4625 const char *str;
4626 struct {
4627 char *name;
4628 unsigned int val;
4629 } of_fmt_table[] = {
4630 { "i2s", SND_SOC_DAIFMT_I2S },
4631 { "right_j", SND_SOC_DAIFMT_RIGHT_J },
4632 { "left_j", SND_SOC_DAIFMT_LEFT_J },
4633 { "dsp_a", SND_SOC_DAIFMT_DSP_A },
4634 { "dsp_b", SND_SOC_DAIFMT_DSP_B },
4635 { "ac97", SND_SOC_DAIFMT_AC97 },
4636 { "pdm", SND_SOC_DAIFMT_PDM},
4637 { "msb", SND_SOC_DAIFMT_MSB },
4638 { "lsb", SND_SOC_DAIFMT_LSB },
Kuninori Morimotoa7930ed2013-01-14 18:36:04 -08004639 };
4640
4641 if (!prefix)
4642 prefix = "";
4643
4644 /*
4645 * check "[prefix]format = xxx"
4646 * SND_SOC_DAIFMT_FORMAT_MASK area
4647 */
4648 snprintf(prop, sizeof(prop), "%sformat", prefix);
4649 ret = of_property_read_string(np, prop, &str);
4650 if (ret == 0) {
4651 for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
4652 if (strcmp(str, of_fmt_table[i].name) == 0) {
4653 format |= of_fmt_table[i].val;
4654 break;
4655 }
4656 }
4657 }
4658
4659 /*
Kuninori Morimoto8c2d6a92013-01-29 21:03:36 -08004660 * check "[prefix]continuous-clock"
Kuninori Morimotoa7930ed2013-01-14 18:36:04 -08004661 * SND_SOC_DAIFMT_CLOCK_MASK area
4662 */
Kuninori Morimoto8c2d6a92013-01-29 21:03:36 -08004663 snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
4664 if (of_get_property(np, prop, NULL))
4665 format |= SND_SOC_DAIFMT_CONT;
4666 else
4667 format |= SND_SOC_DAIFMT_GATED;
Kuninori Morimotoa7930ed2013-01-14 18:36:04 -08004668
4669 /*
4670 * check "[prefix]bitclock-inversion"
4671 * check "[prefix]frame-inversion"
4672 * SND_SOC_DAIFMT_INV_MASK area
4673 */
4674 snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
4675 bit = !!of_get_property(np, prop, NULL);
4676
4677 snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
4678 frame = !!of_get_property(np, prop, NULL);
4679
4680 switch ((bit << 4) + frame) {
4681 case 0x11:
4682 format |= SND_SOC_DAIFMT_IB_IF;
4683 break;
4684 case 0x10:
4685 format |= SND_SOC_DAIFMT_IB_NF;
4686 break;
4687 case 0x01:
4688 format |= SND_SOC_DAIFMT_NB_IF;
4689 break;
4690 default:
4691 /* SND_SOC_DAIFMT_NB_NF is default */
4692 break;
4693 }
4694
4695 /*
4696 * check "[prefix]bitclock-master"
4697 * check "[prefix]frame-master"
4698 * SND_SOC_DAIFMT_MASTER_MASK area
4699 */
4700 snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
4701 bit = !!of_get_property(np, prop, NULL);
4702
4703 snprintf(prop, sizeof(prop), "%sframe-master", prefix);
4704 frame = !!of_get_property(np, prop, NULL);
4705
4706 switch ((bit << 4) + frame) {
4707 case 0x11:
4708 format |= SND_SOC_DAIFMT_CBM_CFM;
4709 break;
4710 case 0x10:
4711 format |= SND_SOC_DAIFMT_CBM_CFS;
4712 break;
4713 case 0x01:
4714 format |= SND_SOC_DAIFMT_CBS_CFM;
4715 break;
4716 default:
4717 format |= SND_SOC_DAIFMT_CBS_CFS;
4718 break;
4719 }
4720
4721 return format;
4722}
4723EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
4724
Kuninori Morimotocb470082013-09-10 17:39:56 -07004725int snd_soc_of_get_dai_name(struct device_node *of_node,
4726 const char **dai_name)
4727{
4728 struct snd_soc_component *pos;
4729 struct of_phandle_args args;
4730 int ret;
4731
4732 ret = of_parse_phandle_with_args(of_node, "sound-dai",
4733 "#sound-dai-cells", 0, &args);
4734 if (ret)
4735 return ret;
4736
4737 ret = -EPROBE_DEFER;
4738
4739 mutex_lock(&client_mutex);
4740 list_for_each_entry(pos, &component_list, list) {
4741 if (pos->dev->of_node != args.np)
4742 continue;
4743
Kuninori Morimoto6833c452013-10-16 22:05:26 -07004744 if (pos->driver->of_xlate_dai_name) {
4745 ret = pos->driver->of_xlate_dai_name(pos, &args, dai_name);
4746 } else {
4747 int id = -1;
4748
4749 switch (args.args_count) {
4750 case 0:
4751 id = 0; /* same as dai_drv[0] */
4752 break;
4753 case 1:
4754 id = args.args[0];
4755 break;
4756 default:
4757 /* not supported */
4758 break;
4759 }
4760
4761 if (id < 0 || id >= pos->num_dai) {
4762 ret = -EINVAL;
Xiubo Lie41975e2013-12-20 14:39:51 +08004763 break;
Kuninori Morimoto6833c452013-10-16 22:05:26 -07004764 }
Xiubo Lie41975e2013-12-20 14:39:51 +08004765
4766 ret = 0;
4767
4768 *dai_name = pos->dai_drv[id].name;
4769 if (!*dai_name)
4770 *dai_name = pos->name;
Kuninori Morimotocb470082013-09-10 17:39:56 -07004771 }
4772
Kuninori Morimotocb470082013-09-10 17:39:56 -07004773 break;
4774 }
4775 mutex_unlock(&client_mutex);
4776
4777 of_node_put(args.np);
4778
4779 return ret;
4780}
4781EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
4782
Takashi Iwaic9b3a402008-12-10 07:47:22 +01004783static int __init snd_soc_init(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02004784{
Mark Brown384c89e2008-12-03 17:34:03 +00004785#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +00004786 snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
4787 if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) {
Fabio Estevam0837fc62012-02-17 19:40:38 -02004788 pr_warn("ASoC: Failed to create debugfs directory\n");
Mark Brown8a9dab12011-01-10 22:25:21 +00004789 snd_soc_debugfs_root = NULL;
Mark Brown384c89e2008-12-03 17:34:03 +00004790 }
Mark Brownc3c5a192010-09-15 18:15:14 +01004791
Mark Brown8a9dab12011-01-10 22:25:21 +00004792 if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL,
Mark Brownc3c5a192010-09-15 18:15:14 +01004793 &codec_list_fops))
4794 pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
4795
Mark Brown8a9dab12011-01-10 22:25:21 +00004796 if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
Mark Brownf3208782010-09-15 18:19:07 +01004797 &dai_list_fops))
4798 pr_warn("ASoC: Failed to create DAI list debugfs file\n");
Mark Brown19c7ac22010-09-15 18:22:40 +01004799
Mark Brown8a9dab12011-01-10 22:25:21 +00004800 if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL,
Mark Brown19c7ac22010-09-15 18:22:40 +01004801 &platform_list_fops))
4802 pr_warn("ASoC: Failed to create platform list debugfs file\n");
Mark Brown384c89e2008-12-03 17:34:03 +00004803#endif
4804
Mark Brownfb257892011-04-28 10:57:54 +01004805 snd_soc_util_init();
4806
Frank Mandarinodb2a4162006-10-06 18:31:09 +02004807 return platform_driver_register(&soc_driver);
4808}
Mark Brown4abe8e12010-10-12 17:41:03 +01004809module_init(snd_soc_init);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02004810
Mark Brown7d8c16a2008-11-30 22:11:24 +00004811static void __exit snd_soc_exit(void)
Frank Mandarinodb2a4162006-10-06 18:31:09 +02004812{
Mark Brownfb257892011-04-28 10:57:54 +01004813 snd_soc_util_exit();
4814
Mark Brown384c89e2008-12-03 17:34:03 +00004815#ifdef CONFIG_DEBUG_FS
Mark Brown8a9dab12011-01-10 22:25:21 +00004816 debugfs_remove_recursive(snd_soc_debugfs_root);
Mark Brown384c89e2008-12-03 17:34:03 +00004817#endif
Mark Brown3ff3f642008-05-19 12:32:25 +02004818 platform_driver_unregister(&soc_driver);
Frank Mandarinodb2a4162006-10-06 18:31:09 +02004819}
Frank Mandarinodb2a4162006-10-06 18:31:09 +02004820module_exit(snd_soc_exit);
4821
4822/* Module information */
Liam Girdwoodd3311242008-10-12 13:17:36 +01004823MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
Frank Mandarinodb2a4162006-10-06 18:31:09 +02004824MODULE_DESCRIPTION("ALSA SoC Core");
4825MODULE_LICENSE("GPL");
Kay Sievers8b45a202008-04-14 13:33:36 +02004826MODULE_ALIAS("platform:soc-audio");