Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * soc-core.c -- ALSA SoC Audio Layer |
| 3 | * |
| 4 | * Copyright 2005 Wolfson Microelectronics PLC. |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 5 | * Copyright 2005 Openedhand Ltd. |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 6 | * Copyright (C) 2010 Slimlogic Ltd. |
| 7 | * Copyright (C) 2010 Texas Instruments Inc. |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 8 | * |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 9 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 10 | * with code, comments and ideas from :- |
| 11 | * Richard Purdie <richard@openedhand.com> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 12 | * |
| 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 Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 18 | * 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 Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Mark Brown | f0e8ed8 | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 33 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 35 | #include <linux/of.h> |
Marek Vasut | 474828a | 2009-07-22 13:01:03 +0200 | [diff] [blame] | 36 | #include <sound/ac97_codec.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 37 | #include <sound/core.h> |
Mark Brown | 3028eb8 | 2010-12-05 12:22:46 +0000 | [diff] [blame] | 38 | #include <sound/jack.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 39 | #include <sound/pcm.h> |
| 40 | #include <sound/pcm_params.h> |
| 41 | #include <sound/soc.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 42 | #include <sound/soc-dpcm.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 43 | #include <sound/initval.h> |
| 44 | |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 45 | #define CREATE_TRACE_POINTS |
| 46 | #include <trace/events/asoc.h> |
| 47 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 48 | #define NAME_SIZE 32 |
| 49 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 50 | static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); |
| 51 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 52 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 53 | struct dentry *snd_soc_debugfs_root; |
| 54 | EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 57 | static DEFINE_MUTEX(client_mutex); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 58 | static LIST_HEAD(dai_list); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 59 | static LIST_HEAD(platform_list); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 60 | static LIST_HEAD(codec_list); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 61 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 62 | int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num); |
| 63 | int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd); |
| 64 | int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute); |
| 65 | int soc_dpcm_be_ac97_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe); |
| 66 | int soc_dpcm_be_ac97_cpu_dai_resume(struct snd_soc_pcm_runtime *fe); |
| 67 | int soc_dpcm_be_cpu_dai_resume(struct snd_soc_pcm_runtime *fe); |
| 68 | int soc_dpcm_be_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe); |
| 69 | int soc_dpcm_be_platform_suspend(struct snd_soc_pcm_runtime *fe); |
| 70 | int soc_dpcm_be_platform_resume(struct snd_soc_pcm_runtime *fe); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 71 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 72 | /* |
| 73 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
| 74 | * It can be used to eliminate pops between different playback streams, e.g. |
| 75 | * between two audio tracks. |
| 76 | */ |
Patrick Lai | 95c1e67 | 2012-04-13 21:52:20 -0700 | [diff] [blame] | 77 | static int pmdown_time; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 78 | module_param(pmdown_time, int, 0); |
| 79 | MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); |
| 80 | |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 81 | /* returns the minimum number of bytes needed to represent |
| 82 | * a particular given value */ |
| 83 | static int min_bytes_needed(unsigned long val) |
| 84 | { |
| 85 | int c = 0; |
| 86 | int i; |
| 87 | |
| 88 | for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c) |
| 89 | if (val & (1UL << i)) |
| 90 | break; |
| 91 | c = (sizeof val * 8) - c; |
| 92 | if (!c || (c % 8)) |
| 93 | c = (c + 8) / 8; |
| 94 | else |
| 95 | c /= 8; |
| 96 | return c; |
| 97 | } |
| 98 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 99 | /* fill buf which is 'len' bytes with a formatted |
| 100 | * string of the form 'reg: value\n' */ |
| 101 | static int format_register_str(struct snd_soc_codec *codec, |
| 102 | unsigned int reg, char *buf, size_t len) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 103 | { |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 104 | int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 105 | int regsize = codec->driver->reg_word_size * 2; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 106 | int ret; |
| 107 | char tmpbuf[len + 1]; |
| 108 | char regbuf[regsize + 1]; |
| 109 | |
| 110 | /* since tmpbuf is allocated on the stack, warn the callers if they |
| 111 | * try to abuse this function */ |
| 112 | WARN_ON(len > 63); |
| 113 | |
| 114 | /* +2 for ': ' and + 1 for '\n' */ |
| 115 | if (wordsize + regsize + 2 + 1 != len) |
| 116 | return -EINVAL; |
| 117 | |
Mark Brown | 25032c1 | 2011-08-01 13:52:48 +0900 | [diff] [blame] | 118 | ret = snd_soc_read(codec, reg); |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 119 | if (ret < 0) { |
| 120 | memset(regbuf, 'X', regsize); |
| 121 | regbuf[regsize] = '\0'; |
| 122 | } else { |
| 123 | snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); |
| 124 | } |
| 125 | |
| 126 | /* prepare the buffer */ |
| 127 | snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); |
| 128 | /* copy it back to the caller without the '\0' */ |
| 129 | memcpy(buf, tmpbuf, len); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | /* codec register dump */ |
| 135 | static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, |
| 136 | size_t count, loff_t pos) |
| 137 | { |
| 138 | int i, step = 1; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 139 | int wordsize, regsize; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 140 | int len; |
| 141 | size_t total = 0; |
| 142 | loff_t p = 0; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 143 | |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 144 | wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 145 | regsize = codec->driver->reg_word_size * 2; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 146 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 147 | len = wordsize + regsize + 2 + 1; |
| 148 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 149 | if (!codec->driver->reg_cache_size) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 150 | return 0; |
| 151 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 152 | if (codec->driver->reg_cache_step) |
| 153 | step = codec->driver->reg_cache_step; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 154 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 155 | for (i = 0; i < codec->driver->reg_cache_size; i += step) { |
Lars-Peter Clausen | b92d150 | 2011-08-27 18:24:14 +0200 | [diff] [blame] | 156 | if (!snd_soc_codec_readable_register(codec, i)) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 157 | continue; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 158 | if (codec->driver->display_register) { |
| 159 | count += codec->driver->display_register(codec, buf + count, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 160 | PAGE_SIZE - count, i); |
Mark Brown | 5164d74 | 2010-07-14 16:14:33 +0100 | [diff] [blame] | 161 | } else { |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 162 | /* only support larger than PAGE_SIZE bytes debugfs |
| 163 | * entries for the default case */ |
| 164 | if (p >= pos) { |
| 165 | if (total + len >= count - 1) |
| 166 | break; |
| 167 | format_register_str(codec, i, buf + total, len); |
| 168 | total += len; |
| 169 | } |
| 170 | p += len; |
Mark Brown | 5164d74 | 2010-07-14 16:14:33 +0100 | [diff] [blame] | 171 | } |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 174 | total = min(total, count - 1); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 175 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 176 | return total; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 177 | } |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 178 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 179 | static ssize_t codec_reg_show(struct device *dev, |
| 180 | struct device_attribute *attr, char *buf) |
| 181 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 182 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 183 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 184 | return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); |
| 188 | |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 189 | static ssize_t pmdown_time_show(struct device *dev, |
| 190 | struct device_attribute *attr, char *buf) |
| 191 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 192 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 193 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 194 | return sprintf(buf, "%ld\n", rtd->pmdown_time); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static ssize_t pmdown_time_set(struct device *dev, |
| 198 | struct device_attribute *attr, |
| 199 | const char *buf, size_t count) |
| 200 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 201 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 202 | int ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 203 | |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 204 | ret = strict_strtol(buf, 10, &rtd->pmdown_time); |
| 205 | if (ret) |
| 206 | return ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 207 | |
| 208 | return count; |
| 209 | } |
| 210 | |
| 211 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); |
| 212 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 213 | #ifdef CONFIG_DEBUG_FS |
| 214 | static int codec_reg_open_file(struct inode *inode, struct file *file) |
| 215 | { |
| 216 | file->private_data = inode->i_private; |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 221 | size_t count, loff_t *ppos) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 222 | { |
| 223 | ssize_t ret; |
| 224 | struct snd_soc_codec *codec = file->private_data; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 225 | char *buf; |
| 226 | |
| 227 | if (*ppos < 0 || !count) |
| 228 | return -EINVAL; |
| 229 | |
| 230 | buf = kmalloc(count, GFP_KERNEL); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 231 | if (!buf) |
| 232 | return -ENOMEM; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 233 | |
| 234 | ret = soc_codec_reg_show(codec, buf, count, *ppos); |
| 235 | if (ret >= 0) { |
| 236 | if (copy_to_user(user_buf, buf, ret)) { |
| 237 | kfree(buf); |
| 238 | return -EFAULT; |
| 239 | } |
| 240 | *ppos += ret; |
| 241 | } |
| 242 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 243 | kfree(buf); |
| 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | static ssize_t codec_reg_write_file(struct file *file, |
| 248 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 249 | { |
| 250 | char buf[32]; |
Stephen Boyd | 34e268d | 2011-05-12 16:50:10 -0700 | [diff] [blame] | 251 | size_t buf_size; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 252 | char *start = buf; |
| 253 | unsigned long reg, value; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 254 | struct snd_soc_codec *codec = file->private_data; |
| 255 | |
| 256 | buf_size = min(count, (sizeof(buf)-1)); |
| 257 | if (copy_from_user(buf, user_buf, buf_size)) |
| 258 | return -EFAULT; |
| 259 | buf[buf_size] = 0; |
| 260 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 261 | while (*start == ' ') |
| 262 | start++; |
| 263 | reg = simple_strtoul(start, &start, 16); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 264 | while (*start == ' ') |
| 265 | start++; |
| 266 | if (strict_strtoul(start, 16, &value)) |
| 267 | return -EINVAL; |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 268 | |
| 269 | /* Userspace has been fiddling around behind the kernel's back */ |
| 270 | add_taint(TAINT_USER); |
| 271 | |
Dimitris Papastamos | e4f078d | 2010-12-07 16:30:38 +0000 | [diff] [blame] | 272 | snd_soc_write(codec, reg, value); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 273 | return buf_size; |
| 274 | } |
| 275 | |
| 276 | static const struct file_operations codec_reg_fops = { |
| 277 | .open = codec_reg_open_file, |
| 278 | .read = codec_reg_read_file, |
| 279 | .write = codec_reg_write_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 280 | .llseek = default_llseek, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | static void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 284 | { |
Jarkko Nikula | d6ce4cf | 2010-11-05 20:35:20 +0200 | [diff] [blame] | 285 | struct dentry *debugfs_card_root = codec->card->debugfs_card_root; |
| 286 | |
| 287 | codec->debugfs_codec_root = debugfs_create_dir(codec->name, |
| 288 | debugfs_card_root); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 289 | if (!codec->debugfs_codec_root) { |
| 290 | printk(KERN_WARNING |
| 291 | "ASoC: Failed to create codec debugfs directory\n"); |
| 292 | return; |
| 293 | } |
| 294 | |
Mark Brown | aaee8ef | 2011-01-26 20:53:50 +0000 | [diff] [blame] | 295 | debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root, |
| 296 | &codec->cache_sync); |
| 297 | debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root, |
| 298 | &codec->cache_only); |
| 299 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 300 | codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, |
| 301 | codec->debugfs_codec_root, |
| 302 | codec, &codec_reg_fops); |
| 303 | if (!codec->debugfs_reg) |
| 304 | printk(KERN_WARNING |
| 305 | "ASoC: Failed to create codec register debugfs file\n"); |
| 306 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 307 | snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 311 | { |
| 312 | debugfs_remove_recursive(codec->debugfs_codec_root); |
| 313 | } |
| 314 | |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 315 | static void soc_init_platform_debugfs(struct snd_soc_platform *platform) |
| 316 | { |
| 317 | struct dentry *debugfs_card_root = platform->card->debugfs_card_root; |
| 318 | |
| 319 | platform->debugfs_platform_root = debugfs_create_dir(platform->name, |
| 320 | debugfs_card_root); |
| 321 | if (!platform->debugfs_platform_root) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 322 | printk(KERN_WARNING |
| 323 | "ASoC: Failed to create platform debugfs directory\n"); |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 324 | return; |
| 325 | } |
| 326 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 327 | snd_soc_dapm_debugfs_init(&platform->dapm, platform->debugfs_platform_root); |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) |
| 331 | { |
| 332 | debugfs_remove_recursive(platform->debugfs_platform_root); |
| 333 | } |
| 334 | |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 335 | static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, |
| 336 | size_t count, loff_t *ppos) |
| 337 | { |
| 338 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 339 | ssize_t len, ret = 0; |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 340 | struct snd_soc_codec *codec; |
| 341 | |
| 342 | if (!buf) |
| 343 | return -ENOMEM; |
| 344 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 345 | list_for_each_entry(codec, &codec_list, list) { |
| 346 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 347 | codec->name); |
| 348 | if (len >= 0) |
| 349 | ret += len; |
| 350 | if (ret > PAGE_SIZE) { |
| 351 | ret = PAGE_SIZE; |
| 352 | break; |
| 353 | } |
| 354 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 355 | |
| 356 | if (ret >= 0) |
| 357 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 358 | |
| 359 | kfree(buf); |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | static const struct file_operations codec_list_fops = { |
| 365 | .read = codec_list_read_file, |
| 366 | .llseek = default_llseek,/* read accesses f_pos */ |
| 367 | }; |
| 368 | |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 369 | static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, |
| 370 | size_t count, loff_t *ppos) |
| 371 | { |
| 372 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 373 | ssize_t len, ret = 0; |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 374 | struct snd_soc_dai *dai; |
| 375 | |
| 376 | if (!buf) |
| 377 | return -ENOMEM; |
| 378 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 379 | list_for_each_entry(dai, &dai_list, list) { |
| 380 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); |
| 381 | if (len >= 0) |
| 382 | ret += len; |
| 383 | if (ret > PAGE_SIZE) { |
| 384 | ret = PAGE_SIZE; |
| 385 | break; |
| 386 | } |
| 387 | } |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 388 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 389 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 390 | |
| 391 | kfree(buf); |
| 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | static const struct file_operations dai_list_fops = { |
| 397 | .read = dai_list_read_file, |
| 398 | .llseek = default_llseek,/* read accesses f_pos */ |
| 399 | }; |
| 400 | |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 401 | static ssize_t platform_list_read_file(struct file *file, |
| 402 | char __user *user_buf, |
| 403 | size_t count, loff_t *ppos) |
| 404 | { |
| 405 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 406 | ssize_t len, ret = 0; |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 407 | struct snd_soc_platform *platform; |
| 408 | |
| 409 | if (!buf) |
| 410 | return -ENOMEM; |
| 411 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 412 | list_for_each_entry(platform, &platform_list, list) { |
| 413 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 414 | platform->name); |
| 415 | if (len >= 0) |
| 416 | ret += len; |
| 417 | if (ret > PAGE_SIZE) { |
| 418 | ret = PAGE_SIZE; |
| 419 | break; |
| 420 | } |
| 421 | } |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 422 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 423 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 424 | |
| 425 | kfree(buf); |
| 426 | |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | static const struct file_operations platform_list_fops = { |
| 431 | .read = platform_list_read_file, |
| 432 | .llseek = default_llseek,/* read accesses f_pos */ |
| 433 | }; |
| 434 | |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 435 | static void soc_init_card_debugfs(struct snd_soc_card *card) |
| 436 | { |
| 437 | card->debugfs_card_root = debugfs_create_dir(card->name, |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 438 | snd_soc_debugfs_root); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 439 | if (!card->debugfs_card_root) { |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 440 | dev_warn(card->dev, |
Lothar Waßmann | 7c08be8 | 2011-12-09 14:16:29 +0100 | [diff] [blame] | 441 | "ASoC: Failed to create card debugfs directory\n"); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 442 | return; |
| 443 | } |
| 444 | |
| 445 | card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, |
| 446 | card->debugfs_card_root, |
| 447 | &card->pop_time); |
| 448 | if (!card->debugfs_pop_time) |
| 449 | dev_warn(card->dev, |
| 450 | "Failed to create pop time debugfs file\n"); |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | static void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 454 | { |
| 455 | debugfs_remove_recursive(card->debugfs_card_root); |
| 456 | } |
| 457 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 458 | #else |
| 459 | |
| 460 | static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 461 | { |
| 462 | } |
| 463 | |
| 464 | static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 465 | { |
| 466 | } |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 467 | |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 468 | static inline void soc_init_platform_debugfs(struct snd_soc_platform *platform) |
| 469 | { |
| 470 | } |
| 471 | |
| 472 | static inline void soc_cleanup_platform_debugfs(struct snd_soc_platform *platform) |
| 473 | { |
| 474 | } |
| 475 | |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 476 | static inline void soc_init_card_debugfs(struct snd_soc_card *card) |
| 477 | { |
| 478 | } |
| 479 | |
| 480 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 481 | { |
| 482 | } |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 483 | #endif |
| 484 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 485 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, |
| 486 | const char *dai_link, int stream) |
| 487 | { |
| 488 | int i; |
| 489 | |
| 490 | for (i = 0; i < card->num_links; i++) { |
| 491 | if (card->rtd[i].dai_link->no_pcm && |
| 492 | !strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 493 | return card->rtd[i].pcm->streams[stream].substream; |
| 494 | } |
| 495 | dev_dbg(card->dev, "failed to find dai link %s\n", dai_link); |
| 496 | return NULL; |
| 497 | } |
| 498 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); |
| 499 | |
| 500 | struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, |
| 501 | const char *dai_link) |
| 502 | { |
| 503 | int i; |
| 504 | |
| 505 | for (i = 0; i < card->num_links; i++) { |
| 506 | if (!strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 507 | return &card->rtd[i]; |
| 508 | } |
| 509 | dev_dbg(card->dev, "failed to find rtd %s\n", dai_link); |
| 510 | return NULL; |
| 511 | } |
| 512 | EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); |
| 513 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 514 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 515 | /* unregister ac97 codec */ |
| 516 | static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) |
| 517 | { |
| 518 | if (codec->ac97->dev.bus) |
| 519 | device_unregister(&codec->ac97->dev); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | /* stop no dev release warning */ |
| 524 | static void soc_ac97_device_release(struct device *dev){} |
| 525 | |
| 526 | /* register ac97 codec to bus */ |
| 527 | static int soc_ac97_dev_register(struct snd_soc_codec *codec) |
| 528 | { |
| 529 | int err; |
| 530 | |
| 531 | codec->ac97->dev.bus = &ac97_bus_type; |
Mark Brown | 4ac5c61 | 2009-04-01 19:35:01 +0100 | [diff] [blame] | 532 | codec->ac97->dev.parent = codec->card->dev; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 533 | codec->ac97->dev.release = soc_ac97_device_release; |
| 534 | |
Kay Sievers | bb072bf | 2008-11-02 03:50:35 +0100 | [diff] [blame] | 535 | dev_set_name(&codec->ac97->dev, "%d-%d:%s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 536 | codec->card->snd_card->number, 0, codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 537 | err = device_register(&codec->ac97->dev); |
| 538 | if (err < 0) { |
| 539 | snd_printk(KERN_ERR "Can't register ac97 bus\n"); |
| 540 | codec->ac97->dev.bus = NULL; |
| 541 | return err; |
| 542 | } |
| 543 | return 0; |
| 544 | } |
| 545 | #endif |
| 546 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 547 | #ifdef CONFIG_PM_SLEEP |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 548 | /* powers down audio subsystem for suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 549 | int snd_soc_suspend(struct device *dev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 550 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 551 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 552 | struct snd_soc_codec *codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 553 | int i; |
| 554 | |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 555 | /* If the initialization of this soc device failed, there is no codec |
| 556 | * associated with it. Just bail out in this case. |
| 557 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 558 | if (list_empty(&card->codec_dev_list)) |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 559 | return 0; |
| 560 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 561 | /* Due to the resume being scheduled into a workqueue we could |
| 562 | * suspend before that's finished - wait for it to complete. |
| 563 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 564 | snd_power_lock(card->snd_card); |
| 565 | snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); |
| 566 | snd_power_unlock(card->snd_card); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 567 | |
| 568 | /* we're going to block userspace touching us until resume completes */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 569 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 570 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 571 | /* mute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 572 | for (i = 0; i < card->num_rtd; i++) { |
| 573 | struct snd_soc_dai *dai = card->rtd[i].codec_dai; |
| 574 | struct snd_soc_dai_driver *drv = dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 575 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 576 | if (card->rtd[i].dai_link->ignore_suspend || |
| 577 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 578 | continue; |
| 579 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 580 | if (card->rtd[i].dai_link->dynamic) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 581 | soc_dpcm_be_digital_mute(&card->rtd[i], 1); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 582 | else { |
| 583 | if (drv->ops->digital_mute && dai->playback_active) |
| 584 | drv->ops->digital_mute(dai, 1); |
| 585 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 588 | /* suspend all pcms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 589 | for (i = 0; i < card->num_rtd; i++) { |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 590 | if (card->rtd[i].dai_link->ignore_suspend || |
| 591 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 592 | continue; |
| 593 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 594 | snd_pcm_suspend_all(card->rtd[i].pcm); |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 595 | } |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 596 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 597 | if (card->suspend_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 598 | card->suspend_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 599 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 600 | for (i = 0; i < card->num_rtd; i++) { |
| 601 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 602 | struct snd_soc_platform *platform = card->rtd[i].platform; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 603 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 604 | if (card->rtd[i].dai_link->ignore_suspend || |
| 605 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 606 | continue; |
| 607 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 608 | if (card->rtd[i].dai_link->dynamic) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 609 | soc_dpcm_be_cpu_dai_suspend(&card->rtd[i]); |
| 610 | soc_dpcm_be_platform_suspend(&card->rtd[i]); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 611 | } else { |
| 612 | 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; |
| 617 | } |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 618 | } |
| 619 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 620 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 621 | /* close any waiting streams and save state */ |
| 622 | for (i = 0; i < card->num_rtd; i++) { |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 623 | flush_delayed_work_sync(&card->rtd[i].delayed_work); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 624 | card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 625 | } |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 626 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 627 | for (i = 0; i < card->num_rtd; i++) { |
| 628 | struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; |
| 629 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 630 | if (card->rtd[i].dai_link->ignore_suspend || |
| 631 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 632 | continue; |
| 633 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 634 | if (driver->playback.stream_name != NULL) |
| 635 | snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, |
| 636 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 637 | |
| 638 | if (driver->capture.stream_name != NULL) |
| 639 | snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, |
| 640 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 641 | } |
| 642 | |
| 643 | /* suspend all CODECs */ |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 644 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 645 | /* If there are paths active then the CODEC will be held with |
| 646 | * bias _ON and should not be suspended. */ |
| 647 | if (!codec->suspended && codec->driver->suspend) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 648 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 649 | case SND_SOC_BIAS_STANDBY: |
| 650 | case SND_SOC_BIAS_OFF: |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 651 | codec->driver->suspend(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 652 | codec->suspended = 1; |
Mark Brown | 7be4ba2 | 2011-07-18 13:17:13 +0900 | [diff] [blame] | 653 | codec->cache_sync = 1; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 654 | break; |
| 655 | default: |
| 656 | dev_dbg(codec->dev, "CODEC is on over suspend\n"); |
| 657 | break; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | for (i = 0; i < card->num_rtd; i++) { |
| 663 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 664 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 665 | if (card->rtd[i].dai_link->ignore_suspend || |
| 666 | card->rtd[i].dai_link->no_pcm) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 667 | continue; |
| 668 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 669 | if (card->rtd[i].dai_link->dynamic) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 670 | soc_dpcm_be_ac97_cpu_dai_suspend(&card->rtd[i]); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 671 | else |
| 672 | if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) |
| 673 | cpu_dai->driver->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 674 | } |
| 675 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 676 | if (card->suspend_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 677 | card->suspend_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 678 | |
| 679 | return 0; |
| 680 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 681 | EXPORT_SYMBOL_GPL(snd_soc_suspend); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 682 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 683 | /* deferred resume work, so resume can complete before we finished |
| 684 | * setting our codec back up, which can be very slow on I2C |
| 685 | */ |
| 686 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 687 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 688 | struct snd_soc_card *card = |
| 689 | container_of(work, struct snd_soc_card, deferred_resume_work); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 690 | struct snd_soc_codec *codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 691 | int i; |
| 692 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 693 | /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
| 694 | * so userspace apps are blocked from touching us |
| 695 | */ |
| 696 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 697 | dev_dbg(card->dev, "starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 698 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 699 | /* Bring us up into D2 so that DAPM starts enabling things */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 700 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 701 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 702 | if (card->resume_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 703 | card->resume_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 704 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 705 | /* resume AC97 DAIs */ |
| 706 | for (i = 0; i < card->num_rtd; i++) { |
| 707 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 708 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 709 | if (card->rtd[i].dai_link->ignore_suspend || |
| 710 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 711 | continue; |
| 712 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 713 | if (card->rtd[i].dai_link->dynamic) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 714 | soc_dpcm_be_ac97_cpu_dai_resume(&card->rtd[i]); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 715 | else |
| 716 | if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) |
| 717 | cpu_dai->driver->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 718 | } |
| 719 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 720 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 721 | /* If the CODEC was idle over suspend then it will have been |
| 722 | * left with bias OFF or STANDBY and suspended so we must now |
| 723 | * resume. Otherwise the suspend was suppressed. |
| 724 | */ |
| 725 | if (codec->driver->resume && codec->suspended) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 726 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 727 | case SND_SOC_BIAS_STANDBY: |
| 728 | case SND_SOC_BIAS_OFF: |
| 729 | codec->driver->resume(codec); |
| 730 | codec->suspended = 0; |
| 731 | break; |
| 732 | default: |
| 733 | dev_dbg(codec->dev, "CODEC was on over suspend\n"); |
| 734 | break; |
| 735 | } |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 736 | } |
| 737 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 738 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 739 | for (i = 0; i < card->num_rtd; i++) { |
| 740 | struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 741 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 742 | if (card->rtd[i].dai_link->ignore_suspend || |
| 743 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 744 | continue; |
| 745 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 746 | if (driver->playback.stream_name != NULL) |
| 747 | snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 748 | SND_SOC_DAPM_STREAM_RESUME); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 749 | |
| 750 | if (driver->capture.stream_name != NULL) |
| 751 | snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 752 | SND_SOC_DAPM_STREAM_RESUME); |
| 753 | } |
| 754 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 755 | /* unmute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 756 | for (i = 0; i < card->num_rtd; i++) { |
| 757 | struct snd_soc_dai *dai = card->rtd[i].codec_dai; |
| 758 | struct snd_soc_dai_driver *drv = dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 759 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 760 | if (card->rtd[i].dai_link->ignore_suspend || |
| 761 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 762 | continue; |
| 763 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 764 | if (card->rtd[i].dai_link->dynamic) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 765 | soc_dpcm_be_digital_mute(&card->rtd[i], 0); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 766 | else { |
| 767 | if (drv->ops->digital_mute && dai->playback_active) |
| 768 | drv->ops->digital_mute(dai, 0); |
| 769 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 770 | } |
| 771 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 772 | for (i = 0; i < card->num_rtd; i++) { |
| 773 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 774 | struct snd_soc_platform *platform = card->rtd[i].platform; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 775 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 776 | if (card->rtd[i].dai_link->ignore_suspend || |
| 777 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 778 | continue; |
| 779 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 780 | if (card->rtd[i].dai_link->dynamic) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 781 | soc_dpcm_be_cpu_dai_resume(&card->rtd[i]); |
| 782 | soc_dpcm_be_platform_resume(&card->rtd[i]); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 783 | } else { |
| 784 | if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) |
| 785 | cpu_dai->driver->resume(cpu_dai); |
| 786 | if (platform->driver->resume && platform->suspended) { |
| 787 | platform->driver->resume(cpu_dai); |
| 788 | platform->suspended = 0; |
| 789 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 790 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 791 | } |
| 792 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 793 | if (card->resume_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 794 | card->resume_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 795 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 796 | dev_dbg(card->dev, "resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 797 | |
| 798 | /* userspace can access us now we are back as we were before */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 799 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /* powers up audio subsystem after a suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 803 | int snd_soc_resume(struct device *dev) |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 804 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 805 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 806 | int i, ac97_control = 0; |
Peter Ujfalusi | b9dd94a | 2010-02-22 13:27:13 +0200 | [diff] [blame] | 807 | |
Eric Miao | 5ff1ddf | 2011-11-23 22:37:00 +0800 | [diff] [blame] | 808 | /* If the initialization of this soc device failed, there is no codec |
| 809 | * associated with it. Just bail out in this case. |
| 810 | */ |
| 811 | if (list_empty(&card->codec_dev_list)) |
| 812 | return 0; |
| 813 | |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 814 | /* AC97 devices might have other drivers hanging off them so |
| 815 | * need to resume immediately. Other drivers don't have that |
| 816 | * problem and may take a substantial amount of time to resume |
| 817 | * due to I/O costs and anti-pop so handle them out of line. |
| 818 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 819 | for (i = 0; i < card->num_rtd; i++) { |
| 820 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 821 | ac97_control |= cpu_dai->driver->ac97_control; |
| 822 | } |
| 823 | if (ac97_control) { |
| 824 | dev_dbg(dev, "Resuming AC97 immediately\n"); |
| 825 | soc_resume_deferred(&card->deferred_resume_work); |
| 826 | } else { |
| 827 | dev_dbg(dev, "Scheduling resume work\n"); |
| 828 | if (!schedule_work(&card->deferred_resume_work)) |
| 829 | dev_err(dev, "resume work item may be lost\n"); |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 830 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 831 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 832 | return 0; |
| 833 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 834 | EXPORT_SYMBOL_GPL(snd_soc_resume); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 835 | #else |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 836 | #define snd_soc_suspend NULL |
| 837 | #define snd_soc_resume NULL |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 838 | #endif |
| 839 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 840 | static const struct snd_soc_dai_ops null_dai_ops = { |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 841 | }; |
| 842 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 843 | static int soc_bind_dai_link(struct snd_soc_card *card, int num) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 844 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 845 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 846 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 847 | struct snd_soc_codec *codec; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 848 | struct snd_soc_platform *platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 849 | struct snd_soc_dai *codec_dai, *cpu_dai; |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 850 | const char *platform_name; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 851 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 852 | dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num); |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 853 | |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 854 | /* Find CPU DAI from registered DAIs*/ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 855 | list_for_each_entry(cpu_dai, &dai_list, list) { |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 856 | if (dai_link->cpu_dai_of_node) { |
| 857 | if (cpu_dai->dev->of_node != dai_link->cpu_dai_of_node) |
| 858 | continue; |
| 859 | } else { |
| 860 | if (strcmp(cpu_dai->name, dai_link->cpu_dai_name)) |
| 861 | continue; |
| 862 | } |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 863 | |
| 864 | rtd->cpu_dai = cpu_dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 865 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 866 | |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 867 | if (!rtd->cpu_dai) { |
| 868 | dev_dbg(card->dev, "CPU DAI %s not registered\n", |
| 869 | dai_link->cpu_dai_name); |
| 870 | return -EPROBE_DEFER; |
| 871 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 874 | /* no, then find CODEC from registered CODECs*/ |
| 875 | list_for_each_entry(codec, &codec_list, list) { |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 876 | if (dai_link->codec_of_node) { |
| 877 | if (codec->dev->of_node != dai_link->codec_of_node) |
| 878 | continue; |
| 879 | } else { |
| 880 | if (strcmp(codec->name, dai_link->codec_name)) |
| 881 | continue; |
| 882 | } |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 883 | |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 884 | rtd->codec = codec; |
| 885 | |
| 886 | /* |
| 887 | * CODEC found, so find CODEC DAI from registered DAIs from |
| 888 | * this CODEC |
| 889 | */ |
| 890 | list_for_each_entry(codec_dai, &dai_list, list) { |
| 891 | if (codec->dev == codec_dai->dev && |
| 892 | !strcmp(codec_dai->name, |
| 893 | dai_link->codec_dai_name)) { |
| 894 | |
| 895 | rtd->codec_dai = codec_dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 896 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 897 | } |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 898 | if (!rtd->codec_dai) { |
| 899 | dev_dbg(card->dev, "CODEC DAI %s not registered\n", |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 900 | dai_link->codec_dai_name); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 901 | return -EPROBE_DEFER; |
| 902 | } |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 903 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 904 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 905 | |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 906 | if (!rtd->codec) { |
| 907 | dev_dbg(card->dev, "CODEC %s not registered\n", |
| 908 | dai_link->codec_name); |
| 909 | return -EPROBE_DEFER; |
| 910 | } |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 911 | |
| 912 | /* if there's no platform we match on the empty platform */ |
| 913 | platform_name = dai_link->platform_name; |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 914 | if (!platform_name && !dai_link->platform_of_node) |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 915 | platform_name = "snd-soc-dummy"; |
| 916 | |
| 917 | /* no, then find one from the set of registered platforms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 918 | list_for_each_entry(platform, &platform_list, list) { |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 919 | if (dai_link->platform_of_node) { |
| 920 | if (platform->dev->of_node != |
| 921 | dai_link->platform_of_node) |
| 922 | continue; |
| 923 | } else { |
| 924 | if (strcmp(platform->name, platform_name)) |
| 925 | continue; |
| 926 | } |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 927 | |
| 928 | rtd->platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 929 | } |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 930 | if (!rtd->platform) { |
| 931 | dev_dbg(card->dev, "platform %s not registered\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 932 | dai_link->platform_name); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 933 | |
| 934 | return -EPROBE_DEFER; |
| 935 | } |
| 936 | card->num_rtd++; |
| 937 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 938 | return 0; |
| 939 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 942 | static void soc_remove_codec(struct snd_soc_codec *codec) |
| 943 | { |
| 944 | int err; |
| 945 | |
| 946 | if (codec->driver->remove) { |
| 947 | err = codec->driver->remove(codec); |
| 948 | if (err < 0) |
| 949 | dev_err(codec->dev, |
| 950 | "asoc: failed to remove %s: %d\n", |
| 951 | codec->name, err); |
| 952 | } |
| 953 | |
| 954 | /* Make sure all DAPM widgets are freed */ |
| 955 | snd_soc_dapm_free(&codec->dapm); |
| 956 | |
| 957 | soc_cleanup_codec_debugfs(codec); |
| 958 | codec->probed = 0; |
| 959 | list_del(&codec->card_list); |
| 960 | module_put(codec->dev->driver->owner); |
| 961 | } |
| 962 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 963 | static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 964 | { |
| 965 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 966 | struct snd_soc_codec *codec = rtd->codec; |
| 967 | struct snd_soc_platform *platform = rtd->platform; |
| 968 | struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; |
| 969 | int err; |
| 970 | |
| 971 | /* unregister the rtd device */ |
| 972 | if (rtd->dev_registered) { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 973 | device_remove_file(rtd->dev, &dev_attr_pmdown_time); |
| 974 | device_remove_file(rtd->dev, &dev_attr_codec_reg); |
| 975 | device_unregister(rtd->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 976 | rtd->dev_registered = 0; |
| 977 | } |
| 978 | |
| 979 | /* remove the CODEC DAI */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 980 | if (codec_dai && codec_dai->probed && |
| 981 | codec_dai->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 982 | if (codec_dai->driver->remove) { |
| 983 | err = codec_dai->driver->remove(codec_dai); |
| 984 | if (err < 0) |
| 985 | printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name); |
| 986 | } |
| 987 | codec_dai->probed = 0; |
| 988 | list_del(&codec_dai->card_list); |
| 989 | } |
| 990 | |
| 991 | /* remove the platform */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 992 | if (platform && platform->probed && |
| 993 | platform->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 994 | if (platform->driver->remove) { |
| 995 | err = platform->driver->remove(platform); |
| 996 | if (err < 0) |
| 997 | printk(KERN_ERR "asoc: failed to remove %s\n", platform->name); |
| 998 | } |
Liam Girdwood | 675c496 | 2012-01-16 15:25:37 +0000 | [diff] [blame] | 999 | /* Make sure all DAPM widgets are freed */ |
| 1000 | snd_soc_dapm_free(&platform->dapm); |
| 1001 | |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 1002 | soc_cleanup_platform_debugfs(platform); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1003 | platform->probed = 0; |
| 1004 | list_del(&platform->card_list); |
| 1005 | module_put(platform->dev->driver->owner); |
| 1006 | } |
| 1007 | |
| 1008 | /* remove the CODEC */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1009 | if (codec && codec->probed && |
| 1010 | codec->driver->remove_order == order) |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1011 | soc_remove_codec(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1012 | |
| 1013 | /* remove the cpu_dai */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1014 | if (cpu_dai && cpu_dai->probed && |
| 1015 | cpu_dai->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1016 | if (cpu_dai->driver->remove) { |
| 1017 | err = cpu_dai->driver->remove(cpu_dai); |
| 1018 | if (err < 0) |
| 1019 | printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name); |
| 1020 | } |
| 1021 | cpu_dai->probed = 0; |
| 1022 | list_del(&cpu_dai->card_list); |
| 1023 | module_put(cpu_dai->dev->driver->owner); |
| 1024 | } |
| 1025 | } |
| 1026 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1027 | static void soc_remove_dai_links(struct snd_soc_card *card) |
| 1028 | { |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1029 | int dai, order; |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1030 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1031 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1032 | order++) { |
| 1033 | for (dai = 0; dai < card->num_rtd; dai++) |
| 1034 | soc_remove_dai_link(card, dai, order); |
| 1035 | } |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1036 | card->num_rtd = 0; |
| 1037 | } |
| 1038 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1039 | static void soc_set_name_prefix(struct snd_soc_card *card, |
| 1040 | struct snd_soc_codec *codec) |
| 1041 | { |
| 1042 | int i; |
| 1043 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1044 | if (card->codec_conf == NULL) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1045 | return; |
| 1046 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1047 | for (i = 0; i < card->num_configs; i++) { |
| 1048 | struct snd_soc_codec_conf *map = &card->codec_conf[i]; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1049 | if (map->dev_name && !strcmp(codec->name, map->dev_name)) { |
| 1050 | codec->name_prefix = map->name_prefix; |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1056 | static int soc_probe_codec(struct snd_soc_card *card, |
| 1057 | struct snd_soc_codec *codec) |
| 1058 | { |
| 1059 | int ret = 0; |
Mark Brown | 89b95ac | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1060 | const struct snd_soc_codec_driver *driver = codec->driver; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1061 | |
| 1062 | codec->card = card; |
| 1063 | codec->dapm.card = card; |
| 1064 | soc_set_name_prefix(card, codec); |
| 1065 | |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1066 | if (!try_module_get(codec->dev->driver->owner)) |
| 1067 | return -ENODEV; |
| 1068 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1069 | soc_init_codec_debugfs(codec); |
| 1070 | |
Lars-Peter Clausen | 7753015 | 2011-05-05 16:59:09 +0200 | [diff] [blame] | 1071 | if (driver->dapm_widgets) |
| 1072 | snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets, |
| 1073 | driver->num_dapm_widgets); |
| 1074 | |
Mark Brown | 33c5f96 | 2011-08-22 18:40:30 +0100 | [diff] [blame] | 1075 | codec->dapm.idle_bias_off = driver->idle_bias_off; |
| 1076 | |
Mark Brown | 89b95ac | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1077 | if (driver->probe) { |
| 1078 | ret = driver->probe(codec); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1079 | if (ret < 0) { |
| 1080 | dev_err(codec->dev, |
| 1081 | "asoc: failed to probe CODEC %s: %d\n", |
| 1082 | codec->name, ret); |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1083 | goto err_probe; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1087 | if (driver->controls) |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1088 | snd_soc_add_codec_controls(codec, driver->controls, |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1089 | driver->num_controls); |
Mark Brown | 89b95ac | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1090 | if (driver->dapm_routes) |
| 1091 | snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, |
| 1092 | driver->num_dapm_routes); |
| 1093 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1094 | /* mark codec as probed and add to card codec list */ |
| 1095 | codec->probed = 1; |
| 1096 | list_add(&codec->card_list, &card->codec_dev_list); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1097 | list_add(&codec->dapm.list, &card->dapm_list); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1098 | |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1099 | return 0; |
| 1100 | |
| 1101 | err_probe: |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1102 | soc_cleanup_codec_debugfs(codec); |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1103 | module_put(codec->dev->driver->owner); |
| 1104 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1105 | return ret; |
| 1106 | } |
| 1107 | |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1108 | static int soc_probe_platform(struct snd_soc_card *card, |
| 1109 | struct snd_soc_platform *platform) |
| 1110 | { |
| 1111 | int ret = 0; |
| 1112 | const struct snd_soc_platform_driver *driver = platform->driver; |
| 1113 | |
| 1114 | platform->card = card; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 1115 | platform->dapm.card = card; |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1116 | |
| 1117 | if (!try_module_get(platform->dev->driver->owner)) |
| 1118 | return -ENODEV; |
| 1119 | |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 1120 | soc_init_platform_debugfs(platform); |
| 1121 | |
Liam Girdwood | cb2cf61 | 2011-07-04 22:10:53 +0100 | [diff] [blame] | 1122 | if (driver->dapm_widgets) |
| 1123 | snd_soc_dapm_new_controls(&platform->dapm, |
| 1124 | driver->dapm_widgets, driver->num_dapm_widgets); |
| 1125 | |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1126 | if (driver->probe) { |
| 1127 | ret = driver->probe(platform); |
| 1128 | if (ret < 0) { |
| 1129 | dev_err(platform->dev, |
| 1130 | "asoc: failed to probe platform %s: %d\n", |
| 1131 | platform->name, ret); |
| 1132 | goto err_probe; |
| 1133 | } |
| 1134 | } |
| 1135 | |
Liam Girdwood | cb2cf61 | 2011-07-04 22:10:53 +0100 | [diff] [blame] | 1136 | if (driver->controls) |
| 1137 | snd_soc_add_platform_controls(platform, driver->controls, |
| 1138 | driver->num_controls); |
| 1139 | if (driver->dapm_routes) |
| 1140 | snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes, |
| 1141 | driver->num_dapm_routes); |
| 1142 | |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1143 | /* mark platform as probed and add to card platform list */ |
| 1144 | platform->probed = 1; |
| 1145 | list_add(&platform->card_list, &card->platform_dev_list); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 1146 | list_add(&platform->dapm.list, &card->dapm_list); |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1147 | |
| 1148 | return 0; |
| 1149 | |
| 1150 | err_probe: |
| 1151 | module_put(platform->dev->driver->owner); |
| 1152 | |
| 1153 | return ret; |
| 1154 | } |
| 1155 | |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1156 | static void rtd_release(struct device *dev) |
| 1157 | { |
| 1158 | kfree(dev); |
| 1159 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1160 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1161 | static int soc_post_component_init(struct snd_soc_card *card, |
| 1162 | struct snd_soc_codec *codec, |
| 1163 | int num, int dailess) |
| 1164 | { |
| 1165 | struct snd_soc_dai_link *dai_link = NULL; |
| 1166 | struct snd_soc_aux_dev *aux_dev = NULL; |
| 1167 | struct snd_soc_pcm_runtime *rtd; |
| 1168 | const char *temp, *name; |
| 1169 | int ret = 0; |
| 1170 | |
| 1171 | if (!dailess) { |
| 1172 | dai_link = &card->dai_link[num]; |
| 1173 | rtd = &card->rtd[num]; |
| 1174 | name = dai_link->name; |
| 1175 | } else { |
| 1176 | aux_dev = &card->aux_dev[num]; |
| 1177 | rtd = &card->rtd_aux[num]; |
| 1178 | name = aux_dev->name; |
| 1179 | } |
Janusz Krzysztofik | 0962bb2 | 2011-02-02 21:11:41 +0100 | [diff] [blame] | 1180 | rtd->card = card; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1181 | |
Mark Brown | 4b1cfcb | 2011-10-18 00:11:49 +0100 | [diff] [blame] | 1182 | /* Make sure all DAPM widgets are instantiated */ |
| 1183 | snd_soc_dapm_new_widgets(&codec->dapm); |
| 1184 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1185 | /* machine controls, routes and widgets are not prefixed */ |
| 1186 | temp = codec->name_prefix; |
| 1187 | codec->name_prefix = NULL; |
| 1188 | |
| 1189 | /* do machine specific initialization */ |
| 1190 | if (!dailess && dai_link->init) |
| 1191 | ret = dai_link->init(rtd); |
| 1192 | else if (dailess && aux_dev->init) |
| 1193 | ret = aux_dev->init(&codec->dapm); |
| 1194 | if (ret < 0) { |
| 1195 | dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret); |
| 1196 | return ret; |
| 1197 | } |
| 1198 | codec->name_prefix = temp; |
| 1199 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1200 | /* register the rtd device */ |
| 1201 | rtd->codec = codec; |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1202 | |
| 1203 | rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 1204 | if (!rtd->dev) |
| 1205 | return -ENOMEM; |
| 1206 | device_initialize(rtd->dev); |
| 1207 | rtd->dev->parent = card->dev; |
| 1208 | rtd->dev->release = rtd_release; |
| 1209 | rtd->dev->init_name = name; |
| 1210 | dev_set_drvdata(rtd->dev, rtd); |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1211 | mutex_init(&rtd->pcm_mutex); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1212 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); |
| 1213 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); |
| 1214 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); |
| 1215 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1216 | ret = device_add(rtd->dev); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1217 | if (ret < 0) { |
| 1218 | dev_err(card->dev, |
| 1219 | "asoc: failed to register runtime device: %d\n", ret); |
| 1220 | return ret; |
| 1221 | } |
| 1222 | rtd->dev_registered = 1; |
| 1223 | |
| 1224 | /* add DAPM sysfs entries for this codec */ |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1225 | ret = snd_soc_dapm_sys_add(rtd->dev); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1226 | if (ret < 0) |
| 1227 | dev_err(codec->dev, |
| 1228 | "asoc: failed to add codec dapm sysfs entries: %d\n", |
| 1229 | ret); |
| 1230 | |
| 1231 | /* add codec sysfs entries */ |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1232 | ret = device_create_file(rtd->dev, &dev_attr_codec_reg); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1233 | if (ret < 0) |
| 1234 | dev_err(codec->dev, |
| 1235 | "asoc: failed to add codec sysfs files: %d\n", ret); |
| 1236 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1237 | #ifdef CONFIG_DEBUG_FS |
| 1238 | /* add DSP sysfs entries */ |
| 1239 | if (!dai_link->dynamic) |
| 1240 | goto out; |
| 1241 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1242 | ret = soc_dpcm_debugfs_add(rtd); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1243 | if (ret < 0) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1244 | dev_err(rtd->dev, "asoc: failed to add dpcm sysfs entries: %d\n", ret); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1245 | |
| 1246 | out: |
| 1247 | #endif |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1248 | return 0; |
| 1249 | } |
| 1250 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1251 | static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1252 | { |
| 1253 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 1254 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 1255 | struct snd_soc_codec *codec = rtd->codec; |
| 1256 | struct snd_soc_platform *platform = rtd->platform; |
| 1257 | struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; |
| 1258 | int ret; |
| 1259 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1260 | dev_dbg(card->dev, "probe %s dai link %d late %d\n", |
| 1261 | card->name, num, order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1262 | |
| 1263 | /* config components */ |
| 1264 | codec_dai->codec = codec; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1265 | cpu_dai->platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1266 | codec_dai->card = card; |
| 1267 | cpu_dai->card = card; |
| 1268 | |
| 1269 | /* set default power off timeout */ |
| 1270 | rtd->pmdown_time = pmdown_time; |
| 1271 | |
| 1272 | /* probe the cpu_dai */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1273 | if (!cpu_dai->probed && |
| 1274 | cpu_dai->driver->probe_order == order) { |
Liam Girdwood | 61b61e3 | 2011-05-24 13:57:43 +0100 | [diff] [blame] | 1275 | if (!try_module_get(cpu_dai->dev->driver->owner)) |
| 1276 | return -ENODEV; |
| 1277 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1278 | if (cpu_dai->driver->probe) { |
| 1279 | ret = cpu_dai->driver->probe(cpu_dai); |
| 1280 | if (ret < 0) { |
| 1281 | printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n", |
| 1282 | cpu_dai->name); |
Liam Girdwood | 61b61e3 | 2011-05-24 13:57:43 +0100 | [diff] [blame] | 1283 | module_put(cpu_dai->dev->driver->owner); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1284 | return ret; |
| 1285 | } |
| 1286 | } |
| 1287 | cpu_dai->probed = 1; |
Wolfram Sang | 1c8371d | 2011-07-17 18:00:26 +0200 | [diff] [blame] | 1288 | /* mark cpu_dai as probed and add to card dai list */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1289 | list_add(&cpu_dai->card_list, &card->dai_dev_list); |
| 1290 | } |
| 1291 | |
| 1292 | /* probe the CODEC */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1293 | if (!codec->probed && |
| 1294 | codec->driver->probe_order == order) { |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1295 | ret = soc_probe_codec(card, codec); |
| 1296 | if (ret < 0) |
| 1297 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | /* probe the platform */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1301 | if (!platform->probed && |
| 1302 | platform->driver->probe_order == order) { |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1303 | ret = soc_probe_platform(card, platform); |
| 1304 | if (ret < 0) |
| 1305 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | /* probe the CODEC DAI */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1309 | if (!codec_dai->probed && codec_dai->driver->probe_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1310 | if (codec_dai->driver->probe) { |
| 1311 | ret = codec_dai->driver->probe(codec_dai); |
| 1312 | if (ret < 0) { |
| 1313 | printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n", |
| 1314 | codec_dai->name); |
| 1315 | return ret; |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
Wolfram Sang | 1c8371d | 2011-07-17 18:00:26 +0200 | [diff] [blame] | 1319 | /* mark codec_dai as probed and add to card dai list */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1320 | codec_dai->probed = 1; |
| 1321 | list_add(&codec_dai->card_list, &card->dai_dev_list); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1324 | /* complete DAI probe during last probe */ |
| 1325 | if (order != SND_SOC_COMP_ORDER_LAST) |
| 1326 | return 0; |
| 1327 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1328 | ret = soc_post_component_init(card, codec, num, 0); |
| 1329 | if (ret) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1330 | return ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1331 | |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1332 | ret = device_create_file(rtd->dev, &dev_attr_pmdown_time); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1333 | if (ret < 0) |
| 1334 | printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); |
| 1335 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1336 | /* create the pcm */ |
| 1337 | ret = soc_new_pcm(rtd, num); |
| 1338 | if (ret < 0) { |
| 1339 | printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name); |
| 1340 | return ret; |
| 1341 | } |
| 1342 | |
| 1343 | /* add platform data for AC97 devices */ |
| 1344 | if (rtd->codec_dai->driver->ac97_control) |
| 1345 | snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); |
| 1346 | |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
| 1350 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 1351 | static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) |
| 1352 | { |
| 1353 | int ret; |
| 1354 | |
| 1355 | /* Only instantiate AC97 if not already done by the adaptor |
| 1356 | * for the generic AC97 subsystem. |
| 1357 | */ |
| 1358 | if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 1359 | /* |
| 1360 | * It is possible that the AC97 device is already registered to |
| 1361 | * the device subsystem. This happens when the device is created |
| 1362 | * via snd_ac97_mixer(). Currently only SoC codec that does so |
| 1363 | * is the generic AC97 glue but others migh emerge. |
| 1364 | * |
| 1365 | * In those cases we don't try to register the device again. |
| 1366 | */ |
| 1367 | if (!rtd->codec->ac97_created) |
| 1368 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1369 | |
| 1370 | ret = soc_ac97_dev_register(rtd->codec); |
| 1371 | if (ret < 0) { |
| 1372 | printk(KERN_ERR "asoc: AC97 device register failed\n"); |
| 1373 | return ret; |
| 1374 | } |
| 1375 | |
| 1376 | rtd->codec->ac97_registered = 1; |
| 1377 | } |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
| 1381 | static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) |
| 1382 | { |
| 1383 | if (codec->ac97_registered) { |
| 1384 | soc_ac97_dev_unregister(codec); |
| 1385 | codec->ac97_registered = 0; |
| 1386 | } |
| 1387 | } |
| 1388 | #endif |
| 1389 | |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1390 | static int soc_check_aux_dev(struct snd_soc_card *card, int num) |
| 1391 | { |
| 1392 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
| 1393 | struct snd_soc_codec *codec; |
| 1394 | |
| 1395 | /* find CODEC from registered CODECs*/ |
| 1396 | list_for_each_entry(codec, &codec_list, list) { |
| 1397 | if (!strcmp(codec->name, aux_dev->codec_name)) |
| 1398 | return 0; |
| 1399 | } |
| 1400 | |
| 1401 | return -EPROBE_DEFER; |
| 1402 | } |
| 1403 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1404 | static int soc_probe_aux_dev(struct snd_soc_card *card, int num) |
| 1405 | { |
| 1406 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1407 | struct snd_soc_codec *codec; |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1408 | int ret = -ENODEV; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1409 | |
| 1410 | /* find CODEC from registered CODECs*/ |
| 1411 | list_for_each_entry(codec, &codec_list, list) { |
| 1412 | if (!strcmp(codec->name, aux_dev->codec_name)) { |
| 1413 | if (codec->probed) { |
| 1414 | dev_err(codec->dev, |
| 1415 | "asoc: codec already probed"); |
| 1416 | ret = -EBUSY; |
| 1417 | goto out; |
| 1418 | } |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1419 | goto found; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1420 | } |
| 1421 | } |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1422 | /* codec not found */ |
| 1423 | dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1424 | return -EPROBE_DEFER; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1425 | |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1426 | found: |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1427 | ret = soc_probe_codec(card, codec); |
| 1428 | if (ret < 0) |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1429 | return ret; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1430 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1431 | ret = soc_post_component_init(card, codec, num, 1); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1432 | |
| 1433 | out: |
| 1434 | return ret; |
| 1435 | } |
| 1436 | |
| 1437 | static void soc_remove_aux_dev(struct snd_soc_card *card, int num) |
| 1438 | { |
| 1439 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
| 1440 | struct snd_soc_codec *codec = rtd->codec; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1441 | |
| 1442 | /* unregister the rtd device */ |
| 1443 | if (rtd->dev_registered) { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1444 | device_remove_file(rtd->dev, &dev_attr_codec_reg); |
| 1445 | device_del(rtd->dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1446 | rtd->dev_registered = 0; |
| 1447 | } |
| 1448 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1449 | if (codec && codec->probed) |
| 1450 | soc_remove_codec(codec); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1451 | } |
| 1452 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1453 | static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, |
| 1454 | enum snd_soc_compress_type compress_type) |
| 1455 | { |
| 1456 | int ret; |
| 1457 | |
| 1458 | if (codec->cache_init) |
| 1459 | return 0; |
| 1460 | |
| 1461 | /* override the compress_type if necessary */ |
| 1462 | if (compress_type && codec->compress_type != compress_type) |
| 1463 | codec->compress_type = compress_type; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1464 | ret = snd_soc_cache_init(codec); |
| 1465 | if (ret < 0) { |
| 1466 | dev_err(codec->dev, "Failed to set cache compression type: %d\n", |
| 1467 | ret); |
| 1468 | return ret; |
| 1469 | } |
| 1470 | codec->cache_init = 1; |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1474 | static void soc_init_dai_aif_channel_map(struct snd_soc_card *card, |
| 1475 | struct snd_soc_dai *dai, int stream) |
| 1476 | { |
| 1477 | struct snd_soc_dapm_widget *w = NULL; |
| 1478 | const char *aif_name; |
| 1479 | |
| 1480 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1481 | aif_name = dai->driver->playback.aif_name; |
| 1482 | else |
| 1483 | aif_name = dai->driver->capture.aif_name; |
| 1484 | |
| 1485 | if (dai->codec) { |
| 1486 | struct snd_soc_codec *codec; |
| 1487 | |
| 1488 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
| 1489 | w = snd_soc_get_codec_widget(card, codec, aif_name); |
| 1490 | if (w) |
| 1491 | break; |
| 1492 | } |
| 1493 | } else if (dai->platform) { |
| 1494 | struct snd_soc_platform *platform; |
| 1495 | |
| 1496 | list_for_each_entry(platform, &card->platform_dev_list, card_list) { |
| 1497 | w = snd_soc_get_platform_widget(card, platform, aif_name); |
| 1498 | if (w) |
| 1499 | break; |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | if (w) { |
| 1504 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1505 | dai->playback_aif = w; |
| 1506 | else |
| 1507 | dai->capture_aif = w; |
| 1508 | } else |
| 1509 | dev_err(dai->dev, "unable to find %s DAI AIF %s\n", |
| 1510 | stream ? "capture" : "playback", aif_name); |
| 1511 | |
| 1512 | dai->channel_map_instanciated = 1; |
| 1513 | } |
| 1514 | |
| 1515 | static int soc_is_dai_pcm(struct snd_soc_card *card, struct snd_soc_dai *dai) |
| 1516 | { |
| 1517 | int i; |
| 1518 | |
| 1519 | for (i = 0; i < card->num_rtd; i++) { |
| 1520 | if (card->rtd[i].cpu_dai == dai && !card->rtd[i].dai_link->no_pcm) |
| 1521 | return 1; |
| 1522 | } |
| 1523 | return 0; |
| 1524 | } |
| 1525 | |
| 1526 | static void soc_init_card_aif_channel_map(struct snd_soc_card *card) |
| 1527 | { |
| 1528 | struct snd_soc_dai *dai; |
| 1529 | |
| 1530 | list_for_each_entry(dai, &card->dai_dev_list, card_list) { |
| 1531 | |
| 1532 | /* only process DAIs that use the new API until |
| 1533 | * the old "stream name" API is fully deprecated */ |
| 1534 | if (!dai->driver->playback.aif_name && !dai->driver->capture.aif_name) |
| 1535 | continue; |
| 1536 | |
| 1537 | /* channels are only mapped from PCM DAIs */ |
| 1538 | if (!soc_is_dai_pcm(card, dai)) |
| 1539 | continue; |
| 1540 | |
| 1541 | /* skip if already instanciated */ |
| 1542 | if (dai->channel_map_instanciated) |
| 1543 | continue; |
| 1544 | |
| 1545 | /* create unique channels masks for each DAI in the sound card */ |
| 1546 | dai->playback_channel_map = |
| 1547 | ((1 << dai->driver->playback.channels_max) - 1) |
| 1548 | << card->num_playback_channels; |
| 1549 | card->num_playback_channels += dai->driver->playback.channels_max; |
| 1550 | |
| 1551 | dai->capture_channel_map = |
| 1552 | ((1 << dai->driver->capture.channels_max) - 1) |
| 1553 | << card->num_capture_channels; |
| 1554 | card->num_capture_channels += dai->driver->capture.channels_max; |
| 1555 | |
| 1556 | if (dai->driver->playback.channels_max) |
| 1557 | soc_init_dai_aif_channel_map(card, dai, SNDRV_PCM_STREAM_PLAYBACK); |
| 1558 | if (dai->driver->capture.channels_max) |
| 1559 | soc_init_dai_aif_channel_map(card, dai, SNDRV_PCM_STREAM_CAPTURE); |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1564 | static int snd_soc_instantiate_card(struct snd_soc_card *card) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1565 | { |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1566 | struct snd_soc_codec *codec; |
| 1567 | struct snd_soc_codec_conf *codec_conf; |
| 1568 | enum snd_soc_compress_type compress_type; |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1569 | struct snd_soc_dai_link *dai_link; |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1570 | int ret, i, order; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1571 | |
| 1572 | mutex_lock(&card->mutex); |
| 1573 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1574 | |
| 1575 | /* bind DAIs */ |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1576 | for (i = 0; i < card->num_links; i++) { |
| 1577 | ret = soc_bind_dai_link(card, i); |
| 1578 | if (ret != 0) |
| 1579 | goto base_error; |
| 1580 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1581 | |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1582 | /* check aux_devs too */ |
| 1583 | for (i = 0; i < card->num_aux_devs; i++) { |
| 1584 | ret = soc_check_aux_dev(card, i); |
| 1585 | if (ret != 0) |
| 1586 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1589 | /* initialize the register cache for each available codec */ |
| 1590 | list_for_each_entry(codec, &codec_list, list) { |
| 1591 | if (codec->cache_init) |
| 1592 | continue; |
Dimitris Papastamos | 861f2fa | 2011-01-11 11:43:51 +0000 | [diff] [blame] | 1593 | /* by default we don't override the compress_type */ |
| 1594 | compress_type = 0; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1595 | /* check to see if we need to override the compress_type */ |
| 1596 | for (i = 0; i < card->num_configs; ++i) { |
| 1597 | codec_conf = &card->codec_conf[i]; |
| 1598 | if (!strcmp(codec->name, codec_conf->dev_name)) { |
| 1599 | compress_type = codec_conf->compress_type; |
| 1600 | if (compress_type && compress_type |
| 1601 | != codec->compress_type) |
| 1602 | break; |
| 1603 | } |
| 1604 | } |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1605 | ret = snd_soc_init_codec_cache(codec, compress_type); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1606 | if (ret < 0) |
| 1607 | goto base_error; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1610 | /* card bind complete so register a sound card */ |
| 1611 | ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
| 1612 | card->owner, 0, &card->snd_card); |
| 1613 | if (ret < 0) { |
| 1614 | printk(KERN_ERR "asoc: can't create sound card for card %s\n", |
| 1615 | card->name); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1616 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1617 | } |
| 1618 | card->snd_card->dev = card->dev; |
| 1619 | |
Mark Brown | e37a497 | 2011-03-02 18:21:57 +0000 | [diff] [blame] | 1620 | card->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 1621 | card->dapm.dev = card->dev; |
| 1622 | card->dapm.card = card; |
| 1623 | list_add(&card->dapm.list, &card->dapm_list); |
| 1624 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1625 | #ifdef CONFIG_DEBUG_FS |
| 1626 | snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); |
| 1627 | #endif |
| 1628 | |
Mark Brown | 88ee1c6 | 2011-02-02 10:43:26 +0000 | [diff] [blame] | 1629 | #ifdef CONFIG_PM_SLEEP |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1630 | /* deferred resume work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1631 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 1632 | #endif |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1633 | |
Mark Brown | 9a841eb | 2011-04-12 17:51:37 -0700 | [diff] [blame] | 1634 | if (card->dapm_widgets) |
| 1635 | snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, |
| 1636 | card->num_dapm_widgets); |
| 1637 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1638 | /* initialise the sound card only once */ |
| 1639 | if (card->probe) { |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1640 | ret = card->probe(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1641 | if (ret < 0) |
| 1642 | goto card_probe_error; |
| 1643 | } |
| 1644 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1645 | /* early DAI link probe */ |
| 1646 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1647 | order++) { |
| 1648 | for (i = 0; i < card->num_links; i++) { |
| 1649 | ret = soc_probe_dai_link(card, i, order); |
| 1650 | if (ret < 0) { |
| 1651 | pr_err("asoc: failed to instantiate card %s: %d\n", |
Mark Brown | 321de0d | 2010-09-21 15:09:37 +0100 | [diff] [blame] | 1652 | card->name, ret); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1653 | goto probe_dai_err; |
| 1654 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1658 | for (i = 0; i < card->num_aux_devs; i++) { |
| 1659 | ret = soc_probe_aux_dev(card, i); |
| 1660 | if (ret < 0) { |
| 1661 | pr_err("asoc: failed to add auxiliary devices %s: %d\n", |
| 1662 | card->name, ret); |
| 1663 | goto probe_aux_dev_err; |
| 1664 | } |
| 1665 | } |
| 1666 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1667 | if (card->controls) |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1668 | snd_soc_add_card_controls(card, card->controls, card->num_controls); |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1669 | |
Mark Brown | b8ad29d | 2011-03-02 18:35:51 +0000 | [diff] [blame] | 1670 | if (card->dapm_routes) |
| 1671 | snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, |
| 1672 | card->num_dapm_routes); |
| 1673 | |
Mark Brown | b90d2f9 | 2011-10-10 13:38:06 +0100 | [diff] [blame] | 1674 | snd_soc_dapm_new_widgets(&card->dapm); |
| 1675 | |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1676 | for (i = 0; i < card->num_links; i++) { |
| 1677 | dai_link = &card->dai_link[i]; |
| 1678 | |
| 1679 | if (dai_link->dai_fmt) { |
| 1680 | ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, |
| 1681 | dai_link->dai_fmt); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1682 | if (ret != 0) |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1683 | dev_warn(card->rtd[i].codec_dai->dev, |
| 1684 | "Failed to set DAI format: %d\n", |
| 1685 | ret); |
| 1686 | |
| 1687 | ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai, |
| 1688 | dai_link->dai_fmt); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1689 | if (ret != 0) |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1690 | dev_warn(card->rtd[i].cpu_dai->dev, |
| 1691 | "Failed to set DAI format: %d\n", |
| 1692 | ret); |
| 1693 | } |
| 1694 | } |
| 1695 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1696 | snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1697 | "%s", card->name); |
Liam Girdwood | 22de71b | 2011-05-12 16:14:04 +0100 | [diff] [blame] | 1698 | snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), |
| 1699 | "%s", card->long_name ? card->long_name : card->name); |
Mark Brown | f0e8ed8 | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 1700 | snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), |
| 1701 | "%s", card->driver_name ? card->driver_name : card->name); |
| 1702 | for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { |
| 1703 | switch (card->snd_card->driver[i]) { |
| 1704 | case '_': |
| 1705 | case '-': |
| 1706 | case '\0': |
| 1707 | break; |
| 1708 | default: |
| 1709 | if (!isalnum(card->snd_card->driver[i])) |
| 1710 | card->snd_card->driver[i] = '_'; |
| 1711 | break; |
| 1712 | } |
| 1713 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1714 | |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 1715 | if (card->late_probe) { |
| 1716 | ret = card->late_probe(card); |
| 1717 | if (ret < 0) { |
| 1718 | dev_err(card->dev, "%s late_probe() failed: %d\n", |
| 1719 | card->name, ret); |
| 1720 | goto probe_aux_dev_err; |
| 1721 | } |
| 1722 | } |
| 1723 | |
Mark Brown | 2dc0021 | 2011-10-08 13:59:44 +0100 | [diff] [blame] | 1724 | snd_soc_dapm_new_widgets(&card->dapm); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1725 | soc_init_card_aif_channel_map(card); |
Mark Brown | 2dc0021 | 2011-10-08 13:59:44 +0100 | [diff] [blame] | 1726 | |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 1727 | if (card->fully_routed) |
Mark Brown | b05d8dc | 2011-11-27 19:38:34 +0000 | [diff] [blame] | 1728 | list_for_each_entry(codec, &card->codec_dev_list, card_list) |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 1729 | snd_soc_dapm_auto_nc_codec_pins(codec); |
| 1730 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1731 | ret = snd_card_register(card->snd_card); |
| 1732 | if (ret < 0) { |
| 1733 | printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1734 | goto probe_aux_dev_err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 1738 | /* register any AC97 codecs */ |
| 1739 | for (i = 0; i < card->num_rtd; i++) { |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1740 | ret = soc_register_ac97_dai_link(&card->rtd[i]); |
| 1741 | if (ret < 0) { |
| 1742 | printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name); |
| 1743 | while (--i >= 0) |
Mark Brown | 7d8316d | 2010-12-13 17:03:27 +0000 | [diff] [blame] | 1744 | soc_unregister_ac97_dai_link(card->rtd[i].codec); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1745 | goto probe_aux_dev_err; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1746 | } |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1747 | } |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1748 | #endif |
| 1749 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1750 | card->instantiated = 1; |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 1751 | snd_soc_dapm_sync(&card->dapm); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1752 | mutex_unlock(&card->mutex); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1753 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1754 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1755 | probe_aux_dev_err: |
| 1756 | for (i = 0; i < card->num_aux_devs; i++) |
| 1757 | soc_remove_aux_dev(card, i); |
| 1758 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1759 | probe_dai_err: |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1760 | soc_remove_dai_links(card); |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1761 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1762 | card_probe_error: |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1763 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1764 | card->remove(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1765 | |
| 1766 | snd_card_free(card->snd_card); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1767 | base_error: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1768 | mutex_unlock(&card->mutex); |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1769 | return ret; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | /* probes a new socdev */ |
| 1773 | static int soc_probe(struct platform_device *pdev) |
| 1774 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1775 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1776 | int ret = 0; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1777 | |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 1778 | /* |
| 1779 | * no card, so machine driver should be registering card |
| 1780 | * we should not be here in that case so ret error |
| 1781 | */ |
| 1782 | if (!card) |
| 1783 | return -EINVAL; |
| 1784 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1785 | /* Bodge while we unpick instantiation */ |
| 1786 | card->dev = &pdev->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1787 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1788 | ret = snd_soc_register_card(card); |
| 1789 | if (ret != 0) { |
| 1790 | dev_err(&pdev->dev, "Failed to register card\n"); |
| 1791 | return ret; |
| 1792 | } |
| 1793 | |
| 1794 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1795 | } |
| 1796 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1797 | static int soc_cleanup_card_resources(struct snd_soc_card *card) |
| 1798 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1799 | int i; |
| 1800 | |
| 1801 | /* make sure any delayed work runs */ |
| 1802 | for (i = 0; i < card->num_rtd; i++) { |
| 1803 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 1804 | flush_delayed_work_sync(&rtd->delayed_work); |
| 1805 | } |
| 1806 | |
| 1807 | /* remove auxiliary devices */ |
| 1808 | for (i = 0; i < card->num_aux_devs; i++) |
| 1809 | soc_remove_aux_dev(card, i); |
| 1810 | |
| 1811 | /* remove and free each DAI */ |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1812 | soc_remove_dai_links(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1813 | |
| 1814 | soc_cleanup_card_debugfs(card); |
| 1815 | |
| 1816 | /* remove the card */ |
| 1817 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1818 | card->remove(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1819 | |
Lars-Peter Clausen | 0aaae52 | 2011-04-30 19:45:47 +0200 | [diff] [blame] | 1820 | snd_soc_dapm_free(&card->dapm); |
| 1821 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1822 | kfree(card->rtd); |
| 1823 | snd_card_free(card->snd_card); |
| 1824 | return 0; |
| 1825 | |
| 1826 | } |
| 1827 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1828 | /* removes a socdev */ |
| 1829 | static int soc_remove(struct platform_device *pdev) |
| 1830 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1831 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1832 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1833 | snd_soc_unregister_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1834 | return 0; |
| 1835 | } |
| 1836 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1837 | int snd_soc_poweroff(struct device *dev) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1838 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1839 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1840 | int i; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1841 | |
| 1842 | if (!card->instantiated) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1843 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1844 | |
| 1845 | /* Flush out pmdown_time work - we actually do want to run it |
| 1846 | * now, we're shutting down so no imminent restart. */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1847 | for (i = 0; i < card->num_rtd; i++) { |
| 1848 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 1849 | flush_delayed_work_sync(&rtd->delayed_work); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1850 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1851 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1852 | snd_soc_dapm_shutdown(card); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1853 | |
| 1854 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1855 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1856 | EXPORT_SYMBOL_GPL(snd_soc_poweroff); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1857 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1858 | const struct dev_pm_ops snd_soc_pm_ops = { |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 1859 | .suspend = snd_soc_suspend, |
| 1860 | .resume = snd_soc_resume, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1861 | .poweroff = snd_soc_poweroff, |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1862 | }; |
Stephen Warren | deb2607 | 2011-04-05 19:35:30 -0600 | [diff] [blame] | 1863 | EXPORT_SYMBOL_GPL(snd_soc_pm_ops); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1864 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1865 | /* ASoC platform driver */ |
| 1866 | static struct platform_driver soc_driver = { |
| 1867 | .driver = { |
| 1868 | .name = "soc-audio", |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 1869 | .owner = THIS_MODULE, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1870 | .pm = &snd_soc_pm_ops, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1871 | }, |
| 1872 | .probe = soc_probe, |
| 1873 | .remove = soc_remove, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1874 | }; |
| 1875 | |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1876 | /** |
| 1877 | * snd_soc_codec_volatile_register: Report if a register is volatile. |
| 1878 | * |
| 1879 | * @codec: CODEC to query. |
| 1880 | * @reg: Register to query. |
| 1881 | * |
| 1882 | * Boolean function indiciating if a CODEC register is volatile. |
| 1883 | */ |
Mark Brown | 181e055 | 2011-01-24 14:05:25 +0000 | [diff] [blame] | 1884 | int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, |
| 1885 | unsigned int reg) |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1886 | { |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 1887 | if (codec->volatile_register) |
| 1888 | return codec->volatile_register(codec, reg); |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1889 | else |
| 1890 | return 0; |
| 1891 | } |
| 1892 | EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); |
| 1893 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1894 | /** |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 1895 | * snd_soc_codec_readable_register: Report if a register is readable. |
| 1896 | * |
| 1897 | * @codec: CODEC to query. |
| 1898 | * @reg: Register to query. |
| 1899 | * |
| 1900 | * Boolean function indicating if a CODEC register is readable. |
| 1901 | */ |
| 1902 | int snd_soc_codec_readable_register(struct snd_soc_codec *codec, |
| 1903 | unsigned int reg) |
| 1904 | { |
| 1905 | if (codec->readable_register) |
| 1906 | return codec->readable_register(codec, reg); |
| 1907 | else |
Lars-Peter Clausen | 63fa0a2 | 2011-08-27 18:24:12 +0200 | [diff] [blame] | 1908 | return 1; |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 1909 | } |
| 1910 | EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register); |
| 1911 | |
| 1912 | /** |
| 1913 | * snd_soc_codec_writable_register: Report if a register is writable. |
| 1914 | * |
| 1915 | * @codec: CODEC to query. |
| 1916 | * @reg: Register to query. |
| 1917 | * |
| 1918 | * Boolean function indicating if a CODEC register is writable. |
| 1919 | */ |
| 1920 | int snd_soc_codec_writable_register(struct snd_soc_codec *codec, |
| 1921 | unsigned int reg) |
| 1922 | { |
| 1923 | if (codec->writable_register) |
| 1924 | return codec->writable_register(codec, reg); |
| 1925 | else |
Lars-Peter Clausen | 63fa0a2 | 2011-08-27 18:24:12 +0200 | [diff] [blame] | 1926 | return 1; |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 1927 | } |
| 1928 | EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register); |
| 1929 | |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 1930 | int snd_soc_platform_read(struct snd_soc_platform *platform, |
| 1931 | unsigned int reg) |
| 1932 | { |
| 1933 | unsigned int ret; |
| 1934 | |
| 1935 | if (!platform->driver->read) { |
| 1936 | dev_err(platform->dev, "platform has no read back\n"); |
| 1937 | return -1; |
| 1938 | } |
| 1939 | |
| 1940 | ret = platform->driver->read(platform, reg); |
| 1941 | dev_dbg(platform->dev, "read %x => %x\n", reg, ret); |
Liam Girdwood | a82ce2a | 2011-07-04 22:10:50 +0100 | [diff] [blame] | 1942 | trace_snd_soc_preg_read(platform, reg, ret); |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 1943 | |
| 1944 | return ret; |
| 1945 | } |
| 1946 | EXPORT_SYMBOL_GPL(snd_soc_platform_read); |
| 1947 | |
| 1948 | int snd_soc_platform_write(struct snd_soc_platform *platform, |
| 1949 | unsigned int reg, unsigned int val) |
| 1950 | { |
| 1951 | if (!platform->driver->write) { |
| 1952 | dev_err(platform->dev, "platform has no write back\n"); |
| 1953 | return -1; |
| 1954 | } |
| 1955 | |
| 1956 | dev_dbg(platform->dev, "write %x = %x\n", reg, val); |
Liam Girdwood | a82ce2a | 2011-07-04 22:10:50 +0100 | [diff] [blame] | 1957 | trace_snd_soc_preg_write(platform, reg, val); |
Liam Girdwood | f1442bc | 2011-07-04 11:10:15 +0100 | [diff] [blame] | 1958 | return platform->driver->write(platform, reg, val); |
| 1959 | } |
| 1960 | EXPORT_SYMBOL_GPL(snd_soc_platform_write); |
| 1961 | |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 1962 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1963 | * snd_soc_new_ac97_codec - initailise AC97 device |
| 1964 | * @codec: audio codec |
| 1965 | * @ops: AC97 bus operations |
| 1966 | * @num: AC97 codec number |
| 1967 | * |
| 1968 | * Initialises AC97 codec resources for use by ad-hoc devices only. |
| 1969 | */ |
| 1970 | int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, |
| 1971 | struct snd_ac97_bus_ops *ops, int num) |
| 1972 | { |
| 1973 | mutex_lock(&codec->mutex); |
| 1974 | |
| 1975 | codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); |
| 1976 | if (codec->ac97 == NULL) { |
| 1977 | mutex_unlock(&codec->mutex); |
| 1978 | return -ENOMEM; |
| 1979 | } |
| 1980 | |
| 1981 | codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); |
| 1982 | if (codec->ac97->bus == NULL) { |
| 1983 | kfree(codec->ac97); |
| 1984 | codec->ac97 = NULL; |
| 1985 | mutex_unlock(&codec->mutex); |
| 1986 | return -ENOMEM; |
| 1987 | } |
| 1988 | |
| 1989 | codec->ac97->bus->ops = ops; |
| 1990 | codec->ac97->num = num; |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 1991 | |
| 1992 | /* |
| 1993 | * Mark the AC97 device to be created by us. This way we ensure that the |
| 1994 | * device will be registered with the device subsystem later on. |
| 1995 | */ |
| 1996 | codec->ac97_created = 1; |
| 1997 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1998 | mutex_unlock(&codec->mutex); |
| 1999 | return 0; |
| 2000 | } |
| 2001 | EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); |
| 2002 | |
| 2003 | /** |
| 2004 | * snd_soc_free_ac97_codec - free AC97 codec device |
| 2005 | * @codec: audio codec |
| 2006 | * |
| 2007 | * Frees AC97 codec device resources. |
| 2008 | */ |
| 2009 | void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) |
| 2010 | { |
| 2011 | mutex_lock(&codec->mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2012 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 2013 | soc_unregister_ac97_dai_link(codec); |
| 2014 | #endif |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2015 | kfree(codec->ac97->bus); |
| 2016 | kfree(codec->ac97); |
| 2017 | codec->ac97 = NULL; |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 2018 | codec->ac97_created = 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2019 | mutex_unlock(&codec->mutex); |
| 2020 | } |
| 2021 | EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); |
| 2022 | |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2023 | unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg) |
| 2024 | { |
| 2025 | unsigned int ret; |
| 2026 | |
Joonwoo Park | 6fb6439 | 2013-08-07 18:59:09 -0700 | [diff] [blame] | 2027 | if (unlikely(!snd_card_is_online_state(codec->card->snd_card))) { |
| 2028 | dev_err(codec->dev, "read 0x%02x while offline\n", reg); |
| 2029 | return -ENODEV; |
| 2030 | } |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 2031 | ret = codec->read(codec, reg); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2032 | dev_dbg(codec->dev, "read %x => %x\n", reg, ret); |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 2033 | trace_snd_soc_reg_read(codec, reg, ret); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2034 | |
| 2035 | return ret; |
| 2036 | } |
| 2037 | EXPORT_SYMBOL_GPL(snd_soc_read); |
| 2038 | |
| 2039 | unsigned int snd_soc_write(struct snd_soc_codec *codec, |
| 2040 | unsigned int reg, unsigned int val) |
| 2041 | { |
Joonwoo Park | 6fb6439 | 2013-08-07 18:59:09 -0700 | [diff] [blame] | 2042 | if (unlikely(!snd_card_is_online_state(codec->card->snd_card))) { |
| 2043 | dev_err(codec->dev, "write 0x%02x while offline\n", reg); |
| 2044 | return -ENODEV; |
| 2045 | } |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2046 | dev_dbg(codec->dev, "write %x = %x\n", reg, val); |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 2047 | trace_snd_soc_reg_write(codec, reg, val); |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 2048 | return codec->write(codec, reg, val); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2049 | } |
| 2050 | EXPORT_SYMBOL_GPL(snd_soc_write); |
| 2051 | |
Dimitris Papastamos | 5fb609d | 2011-03-22 10:37:03 +0000 | [diff] [blame] | 2052 | unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec, |
| 2053 | unsigned int reg, const void *data, size_t len) |
| 2054 | { |
| 2055 | return codec->bulk_write_raw(codec, reg, data, len); |
| 2056 | } |
| 2057 | EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw); |
| 2058 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2059 | /** |
| 2060 | * snd_soc_update_bits - update codec register bits |
| 2061 | * @codec: audio codec |
| 2062 | * @reg: codec register |
| 2063 | * @mask: register mask |
| 2064 | * @value: new value |
| 2065 | * |
| 2066 | * Writes new register value. |
| 2067 | * |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2068 | * Returns 1 for change, 0 for no change, or negative error code. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2069 | */ |
| 2070 | int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2071 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2072 | { |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2073 | bool change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2074 | unsigned int old, new; |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2075 | int ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2076 | |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2077 | if (codec->using_regmap) { |
| 2078 | ret = regmap_update_bits_check(codec->control_data, reg, |
| 2079 | mask, value, &change); |
| 2080 | } else { |
| 2081 | ret = snd_soc_read(codec, reg); |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2082 | if (ret < 0) |
| 2083 | return ret; |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2084 | |
| 2085 | old = ret; |
| 2086 | new = (old & ~mask) | (value & mask); |
| 2087 | change = old != new; |
| 2088 | if (change) |
| 2089 | ret = snd_soc_write(codec, reg, new); |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2090 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2091 | |
Mark Brown | 8a713da | 2011-12-03 12:33:55 +0000 | [diff] [blame] | 2092 | if (ret < 0) |
| 2093 | return ret; |
| 2094 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2095 | return change; |
| 2096 | } |
| 2097 | EXPORT_SYMBOL_GPL(snd_soc_update_bits); |
| 2098 | |
| 2099 | /** |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2100 | * snd_soc_update_bits_locked - update codec register bits |
| 2101 | * @codec: audio codec |
| 2102 | * @reg: codec register |
| 2103 | * @mask: register mask |
| 2104 | * @value: new value |
| 2105 | * |
| 2106 | * Writes new register value, and takes the codec mutex. |
| 2107 | * |
| 2108 | * Returns 1 for change else 0. |
| 2109 | */ |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 2110 | int snd_soc_update_bits_locked(struct snd_soc_codec *codec, |
| 2111 | unsigned short reg, unsigned int mask, |
| 2112 | unsigned int value) |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2113 | { |
| 2114 | int change; |
| 2115 | |
| 2116 | mutex_lock(&codec->mutex); |
| 2117 | change = snd_soc_update_bits(codec, reg, mask, value); |
| 2118 | mutex_unlock(&codec->mutex); |
| 2119 | |
| 2120 | return change; |
| 2121 | } |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 2122 | EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2123 | |
| 2124 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2125 | * snd_soc_test_bits - test register for change |
| 2126 | * @codec: audio codec |
| 2127 | * @reg: codec register |
| 2128 | * @mask: register mask |
| 2129 | * @value: new value |
| 2130 | * |
| 2131 | * Tests a register with a new value and checks if the new value is |
| 2132 | * different from the old value. |
| 2133 | * |
| 2134 | * Returns 1 for change else 0. |
| 2135 | */ |
| 2136 | int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2137 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2138 | { |
| 2139 | int change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2140 | unsigned int old, new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2141 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2142 | old = snd_soc_read(codec, reg); |
| 2143 | new = (old & ~mask) | value; |
| 2144 | change = old != new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2145 | |
| 2146 | return change; |
| 2147 | } |
| 2148 | EXPORT_SYMBOL_GPL(snd_soc_test_bits); |
| 2149 | |
| 2150 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2151 | * snd_soc_set_runtime_hwparams - set the runtime hardware parameters |
| 2152 | * @substream: the pcm substream |
| 2153 | * @hw: the hardware parameters |
| 2154 | * |
| 2155 | * Sets the substream runtime hardware parameters. |
| 2156 | */ |
| 2157 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, |
| 2158 | const struct snd_pcm_hardware *hw) |
| 2159 | { |
| 2160 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2161 | if (!runtime) |
| 2162 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2163 | runtime->hw.info = hw->info; |
| 2164 | runtime->hw.formats = hw->formats; |
| 2165 | runtime->hw.period_bytes_min = hw->period_bytes_min; |
| 2166 | runtime->hw.period_bytes_max = hw->period_bytes_max; |
| 2167 | runtime->hw.periods_min = hw->periods_min; |
| 2168 | runtime->hw.periods_max = hw->periods_max; |
| 2169 | runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; |
| 2170 | runtime->hw.fifo_size = hw->fifo_size; |
| 2171 | return 0; |
| 2172 | } |
| 2173 | EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); |
| 2174 | |
| 2175 | /** |
| 2176 | * snd_soc_cnew - create new control |
| 2177 | * @_template: control template |
| 2178 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2179 | * @long_name: control long name |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2180 | * @prefix: control name prefix |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2181 | * |
| 2182 | * Create a new mixer control from a template control. |
| 2183 | * |
| 2184 | * Returns 0 for success, else error. |
| 2185 | */ |
| 2186 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2187 | void *data, char *long_name, |
| 2188 | const char *prefix) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2189 | { |
| 2190 | struct snd_kcontrol_new template; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2191 | struct snd_kcontrol *kcontrol; |
| 2192 | char *name = NULL; |
| 2193 | int name_len; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2194 | |
| 2195 | memcpy(&template, _template, sizeof(template)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2196 | template.index = 0; |
| 2197 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2198 | if (!long_name) |
| 2199 | long_name = template.name; |
| 2200 | |
| 2201 | if (prefix) { |
| 2202 | name_len = strlen(long_name) + strlen(prefix) + 2; |
Axel Lin | 57cf9d4 | 2011-08-20 11:03:44 +0800 | [diff] [blame] | 2203 | name = kmalloc(name_len, GFP_KERNEL); |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2204 | if (!name) |
| 2205 | return NULL; |
| 2206 | |
| 2207 | snprintf(name, name_len, "%s %s", prefix, long_name); |
| 2208 | |
| 2209 | template.name = name; |
| 2210 | } else { |
| 2211 | template.name = long_name; |
| 2212 | } |
| 2213 | |
| 2214 | kcontrol = snd_ctl_new1(&template, data); |
| 2215 | |
| 2216 | kfree(name); |
| 2217 | |
| 2218 | return kcontrol; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2219 | } |
| 2220 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 2221 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2222 | static int snd_soc_add_controls(struct snd_card *card, struct device *dev, |
| 2223 | const struct snd_kcontrol_new *controls, int num_controls, |
| 2224 | const char *prefix, void *data) |
| 2225 | { |
| 2226 | int err, i; |
| 2227 | |
| 2228 | for (i = 0; i < num_controls; i++) { |
| 2229 | const struct snd_kcontrol_new *control = &controls[i]; |
| 2230 | err = snd_ctl_add(card, snd_soc_cnew(control, data, |
| 2231 | control->name, prefix)); |
| 2232 | if (err < 0) { |
| 2233 | dev_err(dev, "Failed to add %s: %d\n", control->name, err); |
| 2234 | return err; |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | return 0; |
| 2239 | } |
| 2240 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2241 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2242 | * snd_soc_add_codec_controls - add an array of controls to a codec. |
| 2243 | * Convenience function to add a list of controls. Many codecs were |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2244 | * duplicating this code. |
| 2245 | * |
| 2246 | * @codec: codec to add controls to |
| 2247 | * @controls: array of controls to add |
| 2248 | * @num_controls: number of elements in the array |
| 2249 | * |
| 2250 | * Return 0 for success, else error. |
| 2251 | */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2252 | int snd_soc_add_codec_controls(struct snd_soc_codec *codec, |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2253 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2254 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2255 | struct snd_card *card = codec->card->snd_card; |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2256 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2257 | return snd_soc_add_controls(card, codec->dev, controls, num_controls, |
| 2258 | codec->name_prefix, codec); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2259 | } |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2260 | EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2261 | |
| 2262 | /** |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2263 | * snd_soc_add_platform_controls - add an array of controls to a platform. |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2264 | * Convenience function to add a list of controls. |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2265 | * |
| 2266 | * @platform: platform to add controls to |
| 2267 | * @controls: array of controls to add |
| 2268 | * @num_controls: number of elements in the array |
| 2269 | * |
| 2270 | * Return 0 for success, else error. |
| 2271 | */ |
| 2272 | int snd_soc_add_platform_controls(struct snd_soc_platform *platform, |
| 2273 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2274 | { |
| 2275 | struct snd_card *card = platform->card->snd_card; |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2276 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2277 | return snd_soc_add_controls(card, platform->dev, controls, num_controls, |
| 2278 | NULL, platform); |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 2279 | } |
| 2280 | EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); |
| 2281 | |
| 2282 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2283 | * snd_soc_add_card_controls - add an array of controls to a SoC card. |
| 2284 | * Convenience function to add a list of controls. |
| 2285 | * |
| 2286 | * @soc_card: SoC card to add controls to |
| 2287 | * @controls: array of controls to add |
| 2288 | * @num_controls: number of elements in the array |
| 2289 | * |
| 2290 | * Return 0 for success, else error. |
| 2291 | */ |
| 2292 | int snd_soc_add_card_controls(struct snd_soc_card *soc_card, |
| 2293 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2294 | { |
| 2295 | struct snd_card *card = soc_card->snd_card; |
| 2296 | |
| 2297 | return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, |
| 2298 | NULL, soc_card); |
| 2299 | } |
| 2300 | EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); |
| 2301 | |
| 2302 | /** |
| 2303 | * snd_soc_add_dai_controls - add an array of controls to a DAI. |
| 2304 | * Convienience function to add a list of controls. |
| 2305 | * |
| 2306 | * @dai: DAI to add controls to |
| 2307 | * @controls: array of controls to add |
| 2308 | * @num_controls: number of elements in the array |
| 2309 | * |
| 2310 | * Return 0 for success, else error. |
| 2311 | */ |
| 2312 | int snd_soc_add_dai_controls(struct snd_soc_dai *dai, |
| 2313 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2314 | { |
| 2315 | struct snd_card *card = dai->card->snd_card; |
| 2316 | |
| 2317 | return snd_soc_add_controls(card, dai->dev, controls, num_controls, |
| 2318 | NULL, dai); |
| 2319 | } |
| 2320 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); |
| 2321 | |
| 2322 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2323 | * snd_soc_info_enum_double - enumerated double mixer info callback |
| 2324 | * @kcontrol: mixer control |
| 2325 | * @uinfo: control element information |
| 2326 | * |
| 2327 | * Callback to provide information about a double enumerated |
| 2328 | * mixer control. |
| 2329 | * |
| 2330 | * Returns 0 for success. |
| 2331 | */ |
| 2332 | int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, |
| 2333 | struct snd_ctl_elem_info *uinfo) |
| 2334 | { |
| 2335 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2336 | |
| 2337 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2338 | uinfo->count = e->shift_l == e->shift_r ? 1 : 2; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2339 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2340 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2341 | if (uinfo->value.enumerated.item > e->max - 1) |
| 2342 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2343 | strcpy(uinfo->value.enumerated.name, |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame] | 2344 | snd_soc_get_enum_text(e, uinfo->value.enumerated.item)); |
| 2345 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2346 | return 0; |
| 2347 | } |
| 2348 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); |
| 2349 | |
| 2350 | /** |
| 2351 | * snd_soc_get_enum_double - enumerated double mixer get callback |
| 2352 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2353 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2354 | * |
| 2355 | * Callback to get the value of a double enumerated mixer. |
| 2356 | * |
| 2357 | * Returns 0 for success. |
| 2358 | */ |
| 2359 | int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2360 | struct snd_ctl_elem_value *ucontrol) |
| 2361 | { |
| 2362 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2363 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2364 | unsigned int val, bitmask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2365 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2366 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2367 | ; |
| 2368 | val = snd_soc_read(codec, e->reg); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2369 | ucontrol->value.enumerated.item[0] |
| 2370 | = (val >> e->shift_l) & (bitmask - 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2371 | if (e->shift_l != e->shift_r) |
| 2372 | ucontrol->value.enumerated.item[1] = |
| 2373 | (val >> e->shift_r) & (bitmask - 1); |
| 2374 | |
| 2375 | return 0; |
| 2376 | } |
| 2377 | EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); |
| 2378 | |
| 2379 | /** |
| 2380 | * snd_soc_put_enum_double - enumerated double mixer put callback |
| 2381 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2382 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2383 | * |
| 2384 | * Callback to set the value of a double enumerated mixer. |
| 2385 | * |
| 2386 | * Returns 0 for success. |
| 2387 | */ |
| 2388 | int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2389 | struct snd_ctl_elem_value *ucontrol) |
| 2390 | { |
| 2391 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2392 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2393 | unsigned int val; |
| 2394 | unsigned int mask, bitmask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2395 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2396 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2397 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2398 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2399 | return -EINVAL; |
| 2400 | val = ucontrol->value.enumerated.item[0] << e->shift_l; |
| 2401 | mask = (bitmask - 1) << e->shift_l; |
| 2402 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2403 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2404 | return -EINVAL; |
| 2405 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 2406 | mask |= (bitmask - 1) << e->shift_r; |
| 2407 | } |
| 2408 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2409 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2410 | } |
| 2411 | EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); |
| 2412 | |
| 2413 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2414 | * snd_soc_get_value_enum_double - semi enumerated double mixer get callback |
| 2415 | * @kcontrol: mixer control |
| 2416 | * @ucontrol: control element information |
| 2417 | * |
| 2418 | * Callback to get the value of a double semi enumerated mixer. |
| 2419 | * |
| 2420 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2421 | * used for handling bitfield coded enumeration for example. |
| 2422 | * |
| 2423 | * Returns 0 for success. |
| 2424 | */ |
| 2425 | int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2426 | struct snd_ctl_elem_value *ucontrol) |
| 2427 | { |
| 2428 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2429 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2430 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2431 | |
| 2432 | reg_val = snd_soc_read(codec, e->reg); |
| 2433 | val = (reg_val >> e->shift_l) & e->mask; |
| 2434 | for (mux = 0; mux < e->max; mux++) { |
| 2435 | if (val == e->values[mux]) |
| 2436 | break; |
| 2437 | } |
| 2438 | ucontrol->value.enumerated.item[0] = mux; |
| 2439 | if (e->shift_l != e->shift_r) { |
| 2440 | val = (reg_val >> e->shift_r) & e->mask; |
| 2441 | for (mux = 0; mux < e->max; mux++) { |
| 2442 | if (val == e->values[mux]) |
| 2443 | break; |
| 2444 | } |
| 2445 | ucontrol->value.enumerated.item[1] = mux; |
| 2446 | } |
| 2447 | |
| 2448 | return 0; |
| 2449 | } |
| 2450 | EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); |
| 2451 | |
| 2452 | /** |
| 2453 | * snd_soc_put_value_enum_double - semi enumerated double mixer put callback |
| 2454 | * @kcontrol: mixer control |
| 2455 | * @ucontrol: control element information |
| 2456 | * |
| 2457 | * Callback to set the value of a double semi enumerated mixer. |
| 2458 | * |
| 2459 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2460 | * used for handling bitfield coded enumeration for example. |
| 2461 | * |
| 2462 | * Returns 0 for success. |
| 2463 | */ |
| 2464 | int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2465 | struct snd_ctl_elem_value *ucontrol) |
| 2466 | { |
| 2467 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2468 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2469 | unsigned int val; |
| 2470 | unsigned int mask; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2471 | |
| 2472 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2473 | return -EINVAL; |
| 2474 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2475 | mask = e->mask << e->shift_l; |
| 2476 | if (e->shift_l != e->shift_r) { |
| 2477 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2478 | return -EINVAL; |
| 2479 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2480 | mask |= e->mask << e->shift_r; |
| 2481 | } |
| 2482 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2483 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2484 | } |
| 2485 | EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); |
| 2486 | |
| 2487 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2488 | * snd_soc_info_enum_ext - external enumerated single mixer info callback |
| 2489 | * @kcontrol: mixer control |
| 2490 | * @uinfo: control element information |
| 2491 | * |
| 2492 | * Callback to provide information about an external enumerated |
| 2493 | * single mixer. |
| 2494 | * |
| 2495 | * Returns 0 for success. |
| 2496 | */ |
| 2497 | int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, |
| 2498 | struct snd_ctl_elem_info *uinfo) |
| 2499 | { |
| 2500 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2501 | |
| 2502 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2503 | uinfo->count = 1; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2504 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2505 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2506 | if (uinfo->value.enumerated.item > e->max - 1) |
| 2507 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2508 | strcpy(uinfo->value.enumerated.name, |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame] | 2509 | snd_soc_get_enum_text(e, uinfo->value.enumerated.item)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2510 | return 0; |
| 2511 | } |
| 2512 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); |
| 2513 | |
| 2514 | /** |
| 2515 | * snd_soc_info_volsw_ext - external single mixer info callback |
| 2516 | * @kcontrol: mixer control |
| 2517 | * @uinfo: control element information |
| 2518 | * |
| 2519 | * Callback to provide information about a single external mixer control. |
| 2520 | * |
| 2521 | * Returns 0 for success. |
| 2522 | */ |
| 2523 | int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, |
| 2524 | struct snd_ctl_elem_info *uinfo) |
| 2525 | { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2526 | int max = kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2527 | |
Mark Brown | fd5dfad | 2009-04-15 21:37:46 +0100 | [diff] [blame] | 2528 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2529 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2530 | else |
| 2531 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2532 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2533 | uinfo->count = 1; |
| 2534 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2535 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2536 | return 0; |
| 2537 | } |
| 2538 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); |
| 2539 | |
| 2540 | /** |
Ben Romberger | 8f1dc4c | 2011-09-22 13:51:35 -0700 | [diff] [blame] | 2541 | * snd_soc_info_multi_ext - external single mixer info callback |
| 2542 | * @kcontrol: mixer control |
| 2543 | * @uinfo: control element information |
| 2544 | * |
| 2545 | * Callback to provide information about a single external mixer control. |
| 2546 | * that accepts multiple input. |
| 2547 | * |
| 2548 | * Returns 0 for success. |
| 2549 | */ |
| 2550 | int snd_soc_info_multi_ext(struct snd_kcontrol *kcontrol, |
| 2551 | struct snd_ctl_elem_info *uinfo) |
| 2552 | { |
| 2553 | struct soc_multi_mixer_control *mc = |
| 2554 | (struct soc_multi_mixer_control *)kcontrol->private_value; |
| 2555 | int platform_max; |
| 2556 | |
| 2557 | if (!mc->platform_max) |
| 2558 | mc->platform_max = mc->max; |
| 2559 | platform_max = mc->platform_max; |
| 2560 | |
| 2561 | if (platform_max == 1 && !strnstr(kcontrol->id.name, " Volume", 30)) |
| 2562 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2563 | else |
| 2564 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2565 | |
| 2566 | uinfo->count = mc->count; |
| 2567 | uinfo->value.integer.min = 0; |
| 2568 | uinfo->value.integer.max = platform_max; |
| 2569 | return 0; |
| 2570 | } |
| 2571 | EXPORT_SYMBOL_GPL(snd_soc_info_multi_ext); |
| 2572 | |
| 2573 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2574 | * snd_soc_info_volsw - single mixer info callback |
| 2575 | * @kcontrol: mixer control |
| 2576 | * @uinfo: control element information |
| 2577 | * |
Peter Ujfalusi | e8f5a10 | 2011-10-05 10:29:23 +0300 | [diff] [blame] | 2578 | * Callback to provide information about a single mixer control, or a double |
| 2579 | * mixer control that spans 2 registers. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2580 | * |
| 2581 | * Returns 0 for success. |
| 2582 | */ |
| 2583 | int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, |
| 2584 | struct snd_ctl_elem_info *uinfo) |
| 2585 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2586 | struct soc_mixer_control *mc = |
| 2587 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2588 | int platform_max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2589 | |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2590 | if (!mc->platform_max) |
| 2591 | mc->platform_max = mc->max; |
| 2592 | platform_max = mc->platform_max; |
| 2593 | |
| 2594 | if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2595 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2596 | else |
| 2597 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2598 | |
Peter Ujfalusi | e8f5a10 | 2011-10-05 10:29:23 +0300 | [diff] [blame] | 2599 | uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2600 | uinfo->value.integer.min = 0; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2601 | uinfo->value.integer.max = platform_max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2602 | return 0; |
| 2603 | } |
| 2604 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw); |
| 2605 | |
| 2606 | /** |
| 2607 | * snd_soc_get_volsw - single mixer get callback |
| 2608 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2609 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2610 | * |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2611 | * Callback to get the value of a single mixer control, or a double mixer |
| 2612 | * control that spans 2 registers. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2613 | * |
| 2614 | * Returns 0 for success. |
| 2615 | */ |
| 2616 | int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, |
| 2617 | struct snd_ctl_elem_value *ucontrol) |
| 2618 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2619 | struct soc_mixer_control *mc = |
| 2620 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2621 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2622 | unsigned int reg = mc->reg; |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2623 | unsigned int reg2 = mc->rreg; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2624 | unsigned int shift = mc->shift; |
| 2625 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2626 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2627 | unsigned int mask = (1 << fls(max)) - 1; |
| 2628 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2629 | |
| 2630 | ucontrol->value.integer.value[0] = |
| 2631 | (snd_soc_read(codec, reg) >> shift) & mask; |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2632 | if (invert) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2633 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2634 | max - ucontrol->value.integer.value[0]; |
Peter Ujfalusi | f7915d9 | 2011-10-05 10:29:24 +0300 | [diff] [blame] | 2635 | |
| 2636 | if (snd_soc_volsw_is_stereo(mc)) { |
| 2637 | if (reg == reg2) |
| 2638 | ucontrol->value.integer.value[1] = |
| 2639 | (snd_soc_read(codec, reg) >> rshift) & mask; |
| 2640 | else |
| 2641 | ucontrol->value.integer.value[1] = |
| 2642 | (snd_soc_read(codec, reg2) >> shift) & mask; |
| 2643 | if (invert) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2644 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2645 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | return 0; |
| 2649 | } |
| 2650 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw); |
| 2651 | |
| 2652 | /** |
| 2653 | * snd_soc_put_volsw - single mixer put callback |
| 2654 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2655 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2656 | * |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2657 | * Callback to set the value of a single mixer control, or a double mixer |
| 2658 | * control that spans 2 registers. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2659 | * |
| 2660 | * Returns 0 for success. |
| 2661 | */ |
| 2662 | int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, |
| 2663 | struct snd_ctl_elem_value *ucontrol) |
| 2664 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2665 | struct soc_mixer_control *mc = |
| 2666 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2667 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2668 | unsigned int reg = mc->reg; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2669 | unsigned int reg2 = mc->rreg; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2670 | unsigned int shift = mc->shift; |
| 2671 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2672 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2673 | unsigned int mask = (1 << fls(max)) - 1; |
| 2674 | unsigned int invert = mc->invert; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2675 | int err; |
| 2676 | bool type_2r = 0; |
| 2677 | unsigned int val2 = 0; |
| 2678 | unsigned int val, val_mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2679 | |
| 2680 | val = (ucontrol->value.integer.value[0] & mask); |
| 2681 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2682 | val = max - val; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2683 | val_mask = mask << shift; |
| 2684 | val = val << shift; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2685 | if (snd_soc_volsw_is_stereo(mc)) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2686 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 2687 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2688 | val2 = max - val2; |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2689 | if (reg == reg2) { |
| 2690 | val_mask |= mask << rshift; |
| 2691 | val |= val2 << rshift; |
| 2692 | } else { |
| 2693 | val2 = val2 << shift; |
| 2694 | type_2r = 1; |
| 2695 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2696 | } |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2697 | err = snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2698 | if (err < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2699 | return err; |
| 2700 | |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2701 | if (type_2r) |
| 2702 | err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); |
| 2703 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2704 | return err; |
| 2705 | } |
Peter Ujfalusi | 974815b | 2011-10-05 10:29:25 +0300 | [diff] [blame] | 2706 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2707 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2708 | /** |
| 2709 | * snd_soc_info_volsw_s8 - signed mixer info callback |
| 2710 | * @kcontrol: mixer control |
| 2711 | * @uinfo: control element information |
| 2712 | * |
| 2713 | * Callback to provide information about a signed mixer control. |
| 2714 | * |
| 2715 | * Returns 0 for success. |
| 2716 | */ |
| 2717 | int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2718 | struct snd_ctl_elem_info *uinfo) |
| 2719 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2720 | struct soc_mixer_control *mc = |
| 2721 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2722 | int platform_max; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2723 | int min = mc->min; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2724 | unsigned int shift = mc->shift; |
| 2725 | unsigned int rshift = mc->rshift; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2726 | |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2727 | if (!mc->platform_max) |
| 2728 | mc->platform_max = mc->max; |
| 2729 | platform_max = mc->platform_max; |
| 2730 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2731 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2732 | uinfo->count = shift == rshift ? 1 : 2; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2733 | uinfo->value.integer.min = 0; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2734 | uinfo->value.integer.max = platform_max - min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2735 | return 0; |
| 2736 | } |
| 2737 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); |
| 2738 | |
| 2739 | /** |
| 2740 | * snd_soc_get_volsw_s8 - signed mixer get callback |
| 2741 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2742 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2743 | * |
| 2744 | * Callback to get the value of a signed mixer control. |
| 2745 | * |
| 2746 | * Returns 0 for success. |
| 2747 | */ |
| 2748 | int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2749 | struct snd_ctl_elem_value *ucontrol) |
| 2750 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2751 | struct soc_mixer_control *mc = |
| 2752 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2753 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2754 | unsigned int reg = mc->reg; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2755 | unsigned int shift = mc->shift; |
| 2756 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2757 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2758 | int val = snd_soc_read(codec, reg); |
| 2759 | |
| 2760 | ucontrol->value.integer.value[0] = |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2761 | ((signed char)((val >> shift) & 0xff))-min; |
| 2762 | if (shift != rshift) |
| 2763 | ucontrol->value.integer.value[1] = |
| 2764 | ((signed char)((val >> rshift) & 0xff))-min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2765 | return 0; |
| 2766 | } |
| 2767 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); |
| 2768 | |
| 2769 | /** |
| 2770 | * snd_soc_put_volsw_sgn - signed mixer put callback |
| 2771 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2772 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2773 | * |
| 2774 | * Callback to set the value of a signed mixer control. |
| 2775 | * |
| 2776 | * Returns 0 for success. |
| 2777 | */ |
| 2778 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2779 | struct snd_ctl_elem_value *ucontrol) |
| 2780 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2781 | struct soc_mixer_control *mc = |
| 2782 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2783 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2784 | unsigned int reg = mc->reg; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2785 | unsigned int shift = mc->shift; |
| 2786 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2787 | int min = mc->min; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2788 | unsigned int val, val2, val_mask; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2789 | |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2790 | val = ((ucontrol->value.integer.value[0]+min) & 0xff) << shift; |
| 2791 | val_mask = 0xff << shift; |
| 2792 | if (shift != rshift) { |
| 2793 | val2 = (ucontrol->value.integer.value[1]+min) & 0xff; |
| 2794 | val |= val2 << rshift; |
| 2795 | val_mask |= 0xff << rshift; |
| 2796 | } |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2797 | |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 2798 | return snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2799 | } |
| 2800 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); |
| 2801 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2802 | /** |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 2803 | * snd_soc_limit_volume - Set new limit to an existing volume control. |
| 2804 | * |
| 2805 | * @codec: where to look for the control |
| 2806 | * @name: Name of the control |
| 2807 | * @max: new maximum limit |
| 2808 | * |
| 2809 | * Return 0 for success, else error. |
| 2810 | */ |
| 2811 | int snd_soc_limit_volume(struct snd_soc_codec *codec, |
| 2812 | const char *name, int max) |
| 2813 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2814 | struct snd_card *card = codec->card->snd_card; |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 2815 | struct snd_kcontrol *kctl; |
| 2816 | struct soc_mixer_control *mc; |
| 2817 | int found = 0; |
| 2818 | int ret = -EINVAL; |
| 2819 | |
| 2820 | /* Sanity check for name and max */ |
| 2821 | if (unlikely(!name || max <= 0)) |
| 2822 | return -EINVAL; |
| 2823 | |
| 2824 | list_for_each_entry(kctl, &card->controls, list) { |
| 2825 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { |
| 2826 | found = 1; |
| 2827 | break; |
| 2828 | } |
| 2829 | } |
| 2830 | if (found) { |
| 2831 | mc = (struct soc_mixer_control *)kctl->private_value; |
| 2832 | if (max <= mc->max) { |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 2833 | mc->platform_max = max; |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 2834 | ret = 0; |
| 2835 | } |
| 2836 | } |
| 2837 | return ret; |
| 2838 | } |
| 2839 | EXPORT_SYMBOL_GPL(snd_soc_limit_volume); |
| 2840 | |
| 2841 | /** |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 2842 | * snd_soc_info_volsw_2r_sx - double with tlv and variable data size |
| 2843 | * mixer info callback |
| 2844 | * @kcontrol: mixer control |
| 2845 | * @uinfo: control element information |
| 2846 | * |
| 2847 | * Returns 0 for success. |
| 2848 | */ |
| 2849 | int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol, |
| 2850 | struct snd_ctl_elem_info *uinfo) |
| 2851 | { |
| 2852 | struct soc_mixer_control *mc = |
| 2853 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2854 | int max = mc->max; |
| 2855 | int min = mc->min; |
| 2856 | |
| 2857 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2858 | uinfo->count = 2; |
| 2859 | uinfo->value.integer.min = 0; |
| 2860 | uinfo->value.integer.max = max-min; |
| 2861 | |
| 2862 | return 0; |
| 2863 | } |
| 2864 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx); |
| 2865 | |
| 2866 | /** |
| 2867 | * snd_soc_get_volsw_2r_sx - double with tlv and variable data size |
| 2868 | * mixer get callback |
| 2869 | * @kcontrol: mixer control |
| 2870 | * @uinfo: control element information |
| 2871 | * |
| 2872 | * Returns 0 for success. |
| 2873 | */ |
| 2874 | int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, |
| 2875 | struct snd_ctl_elem_value *ucontrol) |
| 2876 | { |
| 2877 | struct soc_mixer_control *mc = |
| 2878 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2879 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2880 | unsigned int mask = (1<<mc->shift)-1; |
| 2881 | int min = mc->min; |
| 2882 | int val = snd_soc_read(codec, mc->reg) & mask; |
| 2883 | int valr = snd_soc_read(codec, mc->rreg) & mask; |
| 2884 | |
Stuart Longland | 20630c7 | 2010-06-18 12:56:10 +1000 | [diff] [blame] | 2885 | ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; |
| 2886 | ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 2887 | return 0; |
| 2888 | } |
| 2889 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); |
| 2890 | |
| 2891 | /** |
| 2892 | * snd_soc_put_volsw_2r_sx - double with tlv and variable data size |
| 2893 | * mixer put callback |
| 2894 | * @kcontrol: mixer control |
| 2895 | * @uinfo: control element information |
| 2896 | * |
| 2897 | * Returns 0 for success. |
| 2898 | */ |
| 2899 | int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol, |
| 2900 | struct snd_ctl_elem_value *ucontrol) |
| 2901 | { |
| 2902 | struct soc_mixer_control *mc = |
| 2903 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2904 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2905 | unsigned int mask = (1<<mc->shift)-1; |
| 2906 | int min = mc->min; |
| 2907 | int ret; |
| 2908 | unsigned int val, valr, oval, ovalr; |
| 2909 | |
| 2910 | val = ((ucontrol->value.integer.value[0]+min) & 0xff); |
| 2911 | val &= mask; |
| 2912 | valr = ((ucontrol->value.integer.value[1]+min) & 0xff); |
| 2913 | valr &= mask; |
| 2914 | |
| 2915 | oval = snd_soc_read(codec, mc->reg) & mask; |
| 2916 | ovalr = snd_soc_read(codec, mc->rreg) & mask; |
| 2917 | |
| 2918 | ret = 0; |
| 2919 | if (oval != val) { |
| 2920 | ret = snd_soc_write(codec, mc->reg, val); |
| 2921 | if (ret < 0) |
Mark Brown | f1df5ae | 2010-06-15 15:14:31 +0100 | [diff] [blame] | 2922 | return ret; |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 2923 | } |
| 2924 | if (ovalr != valr) { |
| 2925 | ret = snd_soc_write(codec, mc->rreg, valr); |
| 2926 | if (ret < 0) |
Mark Brown | f1df5ae | 2010-06-15 15:14:31 +0100 | [diff] [blame] | 2927 | return ret; |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | return 0; |
| 2931 | } |
| 2932 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx); |
| 2933 | |
| 2934 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2935 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
| 2936 | * @dai: DAI |
| 2937 | * @clk_id: DAI specific clock ID |
| 2938 | * @freq: new clock frequency in Hz |
| 2939 | * @dir: new clock direction - input/output. |
| 2940 | * |
| 2941 | * Configures the DAI master (MCLK) or system (SYSCLK) clocking. |
| 2942 | */ |
| 2943 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 2944 | unsigned int freq, int dir) |
| 2945 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2946 | if (dai->driver && dai->driver->ops->set_sysclk) |
| 2947 | return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2948 | else if (dai->codec && dai->codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2949 | return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2950 | freq, dir); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2951 | else |
| 2952 | return -EINVAL; |
| 2953 | } |
| 2954 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); |
| 2955 | |
| 2956 | /** |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2957 | * snd_soc_codec_set_sysclk - configure CODEC system or master clock. |
| 2958 | * @codec: CODEC |
| 2959 | * @clk_id: DAI specific clock ID |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2960 | * @source: Source for the clock |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2961 | * @freq: new clock frequency in Hz |
| 2962 | * @dir: new clock direction - input/output. |
| 2963 | * |
| 2964 | * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. |
| 2965 | */ |
| 2966 | int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2967 | int source, unsigned int freq, int dir) |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2968 | { |
| 2969 | if (codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2970 | return codec->driver->set_sysclk(codec, clk_id, source, |
| 2971 | freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2972 | else |
| 2973 | return -EINVAL; |
| 2974 | } |
| 2975 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); |
| 2976 | |
| 2977 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2978 | * snd_soc_dai_set_clkdiv - configure DAI clock dividers. |
| 2979 | * @dai: DAI |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2980 | * @div_id: DAI specific clock divider ID |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2981 | * @div: new clock divisor. |
| 2982 | * |
| 2983 | * Configures the clock dividers. This is used to derive the best DAI bit and |
| 2984 | * frame clocks from the system or master clock. It's best to set the DAI bit |
| 2985 | * and frame clocks as low as possible to save system power. |
| 2986 | */ |
| 2987 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 2988 | int div_id, int div) |
| 2989 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2990 | if (dai->driver && dai->driver->ops->set_clkdiv) |
| 2991 | return dai->driver->ops->set_clkdiv(dai, div_id, div); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2992 | else |
| 2993 | return -EINVAL; |
| 2994 | } |
| 2995 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); |
| 2996 | |
| 2997 | /** |
| 2998 | * snd_soc_dai_set_pll - configure DAI PLL. |
| 2999 | * @dai: DAI |
| 3000 | * @pll_id: DAI specific PLL ID |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3001 | * @source: DAI specific source for the PLL |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3002 | * @freq_in: PLL input clock frequency in Hz |
| 3003 | * @freq_out: requested PLL output clock frequency in Hz |
| 3004 | * |
| 3005 | * Configures and enables PLL to generate output clock based on input clock. |
| 3006 | */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3007 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, |
| 3008 | unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3009 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3010 | if (dai->driver && dai->driver->ops->set_pll) |
| 3011 | return dai->driver->ops->set_pll(dai, pll_id, source, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3012 | freq_in, freq_out); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3013 | else if (dai->codec && dai->codec->driver->set_pll) |
| 3014 | return dai->codec->driver->set_pll(dai->codec, pll_id, source, |
| 3015 | freq_in, freq_out); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3016 | else |
| 3017 | return -EINVAL; |
| 3018 | } |
| 3019 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); |
| 3020 | |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3021 | /* |
| 3022 | * snd_soc_codec_set_pll - configure codec PLL. |
| 3023 | * @codec: CODEC |
| 3024 | * @pll_id: DAI specific PLL ID |
| 3025 | * @source: DAI specific source for the PLL |
| 3026 | * @freq_in: PLL input clock frequency in Hz |
| 3027 | * @freq_out: requested PLL output clock frequency in Hz |
| 3028 | * |
| 3029 | * Configures and enables PLL to generate output clock based on input clock. |
| 3030 | */ |
| 3031 | int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, |
| 3032 | unsigned int freq_in, unsigned int freq_out) |
| 3033 | { |
| 3034 | if (codec->driver->set_pll) |
| 3035 | return codec->driver->set_pll(codec, pll_id, source, |
| 3036 | freq_in, freq_out); |
| 3037 | else |
| 3038 | return -EINVAL; |
| 3039 | } |
| 3040 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); |
| 3041 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3042 | /** |
| 3043 | * snd_soc_dai_set_fmt - configure DAI hardware audio format. |
| 3044 | * @dai: DAI |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3045 | * @fmt: SND_SOC_DAIFMT_ format value. |
| 3046 | * |
| 3047 | * Configures the DAI hardware format and clocking. |
| 3048 | */ |
| 3049 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 3050 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3051 | if (dai->driver && dai->driver->ops->set_fmt) |
| 3052 | return dai->driver->ops->set_fmt(dai, fmt); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3053 | else |
| 3054 | return -EINVAL; |
| 3055 | } |
| 3056 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); |
| 3057 | |
| 3058 | /** |
| 3059 | * snd_soc_dai_set_tdm_slot - configure DAI TDM. |
| 3060 | * @dai: DAI |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3061 | * @tx_mask: bitmask representing active TX slots. |
| 3062 | * @rx_mask: bitmask representing active RX slots. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3063 | * @slots: Number of slots in use. |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3064 | * @slot_width: Width in bits for each slot. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3065 | * |
| 3066 | * Configures a DAI for TDM operation. Both mask and slots are codec and DAI |
| 3067 | * specific. |
| 3068 | */ |
| 3069 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3070 | unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3071 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3072 | if (dai->driver && dai->driver->ops->set_tdm_slot) |
| 3073 | return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3074 | slots, slot_width); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3075 | else |
| 3076 | return -EINVAL; |
| 3077 | } |
| 3078 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); |
| 3079 | |
| 3080 | /** |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 3081 | * snd_soc_dai_set_channel_map - configure DAI audio channel map |
| 3082 | * @dai: DAI |
| 3083 | * @tx_num: how many TX channels |
| 3084 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 3085 | * 0~num-1 uses |
| 3086 | * @rx_num: how many RX channels |
| 3087 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 3088 | * 0~num-1 uses |
| 3089 | * |
| 3090 | * configure the relationship between channel number and TDM slot number. |
| 3091 | */ |
| 3092 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 3093 | unsigned int tx_num, unsigned int *tx_slot, |
| 3094 | unsigned int rx_num, unsigned int *rx_slot) |
| 3095 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3096 | if (dai->driver && dai->driver->ops->set_channel_map) |
| 3097 | return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 3098 | rx_num, rx_slot); |
| 3099 | else |
| 3100 | return -EINVAL; |
| 3101 | } |
| 3102 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); |
| 3103 | |
| 3104 | /** |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3105 | * snd_soc_dai_get_channel_map - configure DAI audio channel map |
| 3106 | * @dai: DAI |
| 3107 | * @tx_num: how many TX channels |
| 3108 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 3109 | * 0~num-1 uses |
| 3110 | * @rx_num: how many RX channels |
| 3111 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 3112 | * 0~num-1 uses |
| 3113 | * |
| 3114 | * configure the relationship between channel number and TDM slot number. |
| 3115 | */ |
| 3116 | int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai, |
| 3117 | unsigned int *tx_num, unsigned int *tx_slot, |
| 3118 | unsigned int *rx_num, unsigned int *rx_slot) |
| 3119 | { |
| 3120 | if (dai->driver && dai->driver->ops->get_channel_map) |
| 3121 | return dai->driver->ops->get_channel_map(dai, tx_num, tx_slot, |
| 3122 | rx_num, rx_slot); |
| 3123 | else |
| 3124 | return -EINVAL; |
| 3125 | } |
| 3126 | EXPORT_SYMBOL_GPL(snd_soc_dai_get_channel_map); |
| 3127 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3128 | * snd_soc_dai_set_tristate - configure DAI system or master clock. |
| 3129 | * @dai: DAI |
| 3130 | * @tristate: tristate enable |
| 3131 | * |
| 3132 | * Tristates the DAI so that others can use it. |
| 3133 | */ |
| 3134 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
| 3135 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3136 | if (dai->driver && dai->driver->ops->set_tristate) |
| 3137 | return dai->driver->ops->set_tristate(dai, tristate); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3138 | else |
| 3139 | return -EINVAL; |
| 3140 | } |
| 3141 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); |
| 3142 | |
| 3143 | /** |
| 3144 | * snd_soc_dai_digital_mute - configure DAI system or master clock. |
| 3145 | * @dai: DAI |
| 3146 | * @mute: mute enable |
| 3147 | * |
| 3148 | * Mutes the DAI DAC. |
| 3149 | */ |
| 3150 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) |
| 3151 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3152 | if (dai->driver && dai->driver->ops->digital_mute) |
| 3153 | return dai->driver->ops->digital_mute(dai, mute); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3154 | else |
| 3155 | return -EINVAL; |
| 3156 | } |
| 3157 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
| 3158 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3159 | /** |
| 3160 | * snd_soc_register_card - Register a card with the ASoC core |
| 3161 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3162 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3163 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3164 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3165 | int snd_soc_register_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3166 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3167 | int i; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 3168 | int ret = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3169 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3170 | if (!card->name || !card->dev) |
| 3171 | return -EINVAL; |
| 3172 | |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3173 | for (i = 0; i < card->num_links; i++) { |
| 3174 | struct snd_soc_dai_link *link = &card->dai_link[i]; |
| 3175 | |
| 3176 | /* |
| 3177 | * Codec must be specified by 1 of name or OF node, |
| 3178 | * not both or neither. |
| 3179 | */ |
| 3180 | if (!!link->codec_name == !!link->codec_of_node) { |
| 3181 | dev_err(card->dev, |
Liam Girdwood | 3b09bb8 | 2012-01-09 12:09:29 +0000 | [diff] [blame] | 3182 | "Neither/both codec name/of_node are set for %s\n", |
| 3183 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3184 | return -EINVAL; |
| 3185 | } |
| 3186 | |
| 3187 | /* |
| 3188 | * Platform may be specified by either name or OF node, but |
| 3189 | * can be left unspecified, and a dummy platform will be used. |
| 3190 | */ |
| 3191 | if (link->platform_name && link->platform_of_node) { |
| 3192 | dev_err(card->dev, |
Liam Girdwood | 3b09bb8 | 2012-01-09 12:09:29 +0000 | [diff] [blame] | 3193 | "Both platform name/of_node are set for %s\n", link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3194 | return -EINVAL; |
| 3195 | } |
| 3196 | |
| 3197 | /* |
| 3198 | * CPU DAI must be specified by 1 of name or OF node, |
| 3199 | * not both or neither. |
| 3200 | */ |
| 3201 | if (!!link->cpu_dai_name == !!link->cpu_dai_of_node) { |
| 3202 | dev_err(card->dev, |
Liam Girdwood | 3b09bb8 | 2012-01-09 12:09:29 +0000 | [diff] [blame] | 3203 | "Neither/both cpu_dai name/of_node are set for %s\n", |
| 3204 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 3205 | return -EINVAL; |
| 3206 | } |
| 3207 | } |
| 3208 | |
Mark Brown | ed77cc1 | 2011-05-03 18:25:34 +0100 | [diff] [blame] | 3209 | dev_set_drvdata(card->dev, card); |
| 3210 | |
Stephen Warren | 111c641 | 2011-01-28 14:26:35 -0700 | [diff] [blame] | 3211 | snd_soc_initialize_card_lists(card); |
| 3212 | |
Vinod Koul | 150dd2f | 2011-01-13 22:48:32 +0530 | [diff] [blame] | 3213 | soc_init_card_debugfs(card); |
| 3214 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 3215 | card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) * |
| 3216 | (card->num_links + card->num_aux_devs), |
| 3217 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3218 | if (card->rtd == NULL) |
| 3219 | return -ENOMEM; |
Liam Girdwood | a7dbb60 | 2012-04-17 18:00:11 +0100 | [diff] [blame] | 3220 | card->num_rtd = 0; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 3221 | card->rtd_aux = &card->rtd[card->num_links]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3222 | |
| 3223 | for (i = 0; i < card->num_links; i++) |
| 3224 | card->rtd[i].dai_link = &card->dai_link[i]; |
| 3225 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3226 | INIT_LIST_HEAD(&card->list); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 3227 | INIT_LIST_HEAD(&card->dapm_dirty); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3228 | card->instantiated = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3229 | mutex_init(&card->mutex); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3230 | mutex_init(&card->dpcm_mutex); |
Sriranjan Srikantam | fd7f1ad | 2012-08-14 17:42:06 -0700 | [diff] [blame] | 3231 | mutex_init(&card->dapm_power_mutex); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3232 | |
Mark Brown | 87ba7da | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 3233 | ret = snd_soc_instantiate_card(card); |
| 3234 | if (ret != 0) |
| 3235 | soc_cleanup_card_debugfs(card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3236 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3237 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 3238 | return ret; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3239 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3240 | EXPORT_SYMBOL_GPL(snd_soc_register_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3241 | |
| 3242 | /** |
| 3243 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 3244 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3245 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3246 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3247 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3248 | int snd_soc_unregister_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3249 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 3250 | if (card->instantiated) |
| 3251 | soc_cleanup_card_resources(card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3252 | dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); |
| 3253 | |
| 3254 | return 0; |
| 3255 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3256 | EXPORT_SYMBOL_GPL(snd_soc_unregister_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3257 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3258 | /* |
| 3259 | * Simplify DAI link configuration by removing ".-1" from device names |
| 3260 | * and sanitizing names. |
| 3261 | */ |
Dimitris Papastamos | 0b9a214 | 2010-12-06 15:49:20 +0000 | [diff] [blame] | 3262 | static char *fmt_single_name(struct device *dev, int *id) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3263 | { |
| 3264 | char *found, name[NAME_SIZE]; |
| 3265 | int id1, id2; |
| 3266 | |
| 3267 | if (dev_name(dev) == NULL) |
| 3268 | return NULL; |
| 3269 | |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 3270 | strlcpy(name, dev_name(dev), NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3271 | |
| 3272 | /* are we a "%s.%d" name (platform and SPI components) */ |
| 3273 | found = strstr(name, dev->driver->name); |
| 3274 | if (found) { |
| 3275 | /* get ID */ |
| 3276 | if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { |
| 3277 | |
| 3278 | /* discard ID from name if ID == -1 */ |
| 3279 | if (*id == -1) |
| 3280 | found[strlen(dev->driver->name)] = '\0'; |
| 3281 | } |
| 3282 | |
| 3283 | } else { |
| 3284 | /* I2C component devices are named "bus-addr" */ |
| 3285 | if (sscanf(name, "%x-%x", &id1, &id2) == 2) { |
| 3286 | char tmp[NAME_SIZE]; |
| 3287 | |
| 3288 | /* create unique ID number from I2C addr and bus */ |
Jarkko Nikula | 0589944 | 2010-10-19 11:10:45 +0300 | [diff] [blame] | 3289 | *id = ((id1 & 0xffff) << 16) + id2; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3290 | |
| 3291 | /* sanitize component name for DAI link creation */ |
| 3292 | snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 3293 | strlcpy(name, tmp, NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3294 | } else |
| 3295 | *id = 0; |
| 3296 | } |
| 3297 | |
| 3298 | return kstrdup(name, GFP_KERNEL); |
| 3299 | } |
| 3300 | |
| 3301 | /* |
| 3302 | * Simplify DAI link naming for single devices with multiple DAIs by removing |
| 3303 | * any ".-1" and using the DAI name (instead of device name). |
| 3304 | */ |
| 3305 | static inline char *fmt_multiple_name(struct device *dev, |
| 3306 | struct snd_soc_dai_driver *dai_drv) |
| 3307 | { |
| 3308 | if (dai_drv->name == NULL) { |
| 3309 | printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n", |
| 3310 | dev_name(dev)); |
| 3311 | return NULL; |
| 3312 | } |
| 3313 | |
| 3314 | return kstrdup(dai_drv->name, GFP_KERNEL); |
| 3315 | } |
| 3316 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3317 | /** |
| 3318 | * snd_soc_register_dai - Register a DAI with the ASoC core |
| 3319 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3320 | * @dai: DAI to register |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3321 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3322 | int snd_soc_register_dai(struct device *dev, |
| 3323 | struct snd_soc_dai_driver *dai_drv) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3324 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3325 | struct snd_soc_dai *dai; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3326 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3327 | dev_dbg(dev, "dai register %s\n", dev_name(dev)); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3328 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3329 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
| 3330 | if (dai == NULL) |
Lu Guanqun | a739362 | 2011-04-20 16:00:51 +0800 | [diff] [blame] | 3331 | return -ENOMEM; |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 3332 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3333 | /* create DAI component name */ |
| 3334 | dai->name = fmt_single_name(dev, &dai->id); |
| 3335 | if (dai->name == NULL) { |
| 3336 | kfree(dai); |
| 3337 | return -ENOMEM; |
| 3338 | } |
| 3339 | |
| 3340 | dai->dev = dev; |
| 3341 | dai->driver = dai_drv; |
| 3342 | if (!dai->driver->ops) |
| 3343 | dai->driver->ops = &null_dai_ops; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3344 | |
| 3345 | mutex_lock(&client_mutex); |
| 3346 | list_add(&dai->list, &dai_list); |
| 3347 | mutex_unlock(&client_mutex); |
| 3348 | |
| 3349 | pr_debug("Registered DAI '%s'\n", dai->name); |
| 3350 | |
| 3351 | return 0; |
| 3352 | } |
| 3353 | EXPORT_SYMBOL_GPL(snd_soc_register_dai); |
| 3354 | |
| 3355 | /** |
| 3356 | * snd_soc_unregister_dai - Unregister a DAI from the ASoC core |
| 3357 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3358 | * @dai: DAI to unregister |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3359 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3360 | void snd_soc_unregister_dai(struct device *dev) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3361 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3362 | struct snd_soc_dai *dai; |
| 3363 | |
| 3364 | list_for_each_entry(dai, &dai_list, list) { |
| 3365 | if (dev == dai->dev) |
| 3366 | goto found; |
| 3367 | } |
| 3368 | return; |
| 3369 | |
| 3370 | found: |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3371 | mutex_lock(&client_mutex); |
| 3372 | list_del(&dai->list); |
| 3373 | mutex_unlock(&client_mutex); |
| 3374 | |
| 3375 | pr_debug("Unregistered DAI '%s'\n", dai->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3376 | kfree(dai->name); |
| 3377 | kfree(dai); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3378 | } |
| 3379 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); |
| 3380 | |
| 3381 | /** |
| 3382 | * snd_soc_register_dais - Register multiple DAIs with the ASoC core |
| 3383 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3384 | * @dai: Array of DAIs to register |
| 3385 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3386 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3387 | int snd_soc_register_dais(struct device *dev, |
| 3388 | struct snd_soc_dai_driver *dai_drv, size_t count) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3389 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3390 | struct snd_soc_dai *dai; |
| 3391 | int i, ret = 0; |
| 3392 | |
Liam Girdwood | 720ffa4 | 2010-08-18 00:30:30 +0100 | [diff] [blame] | 3393 | dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3394 | |
| 3395 | for (i = 0; i < count; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3396 | |
| 3397 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
Axel Lin | c46e007 | 2010-11-03 15:04:45 +0800 | [diff] [blame] | 3398 | if (dai == NULL) { |
| 3399 | ret = -ENOMEM; |
| 3400 | goto err; |
| 3401 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3402 | |
| 3403 | /* create DAI component name */ |
| 3404 | dai->name = fmt_multiple_name(dev, &dai_drv[i]); |
| 3405 | if (dai->name == NULL) { |
| 3406 | kfree(dai); |
| 3407 | ret = -EINVAL; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3408 | goto err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | dai->dev = dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3412 | dai->driver = &dai_drv[i]; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3413 | |
Mark Brown | 0f9141c | 2010-10-12 15:43:21 +0100 | [diff] [blame] | 3414 | if (dai->driver->id) |
| 3415 | dai->id = dai->driver->id; |
| 3416 | else |
| 3417 | dai->id = i; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3418 | if (!dai->driver->ops) |
| 3419 | dai->driver->ops = &null_dai_ops; |
| 3420 | |
| 3421 | mutex_lock(&client_mutex); |
| 3422 | list_add(&dai->list, &dai_list); |
| 3423 | mutex_unlock(&client_mutex); |
| 3424 | |
| 3425 | pr_debug("Registered DAI '%s'\n", dai->name); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3426 | } |
| 3427 | |
| 3428 | return 0; |
| 3429 | |
| 3430 | err: |
| 3431 | for (i--; i >= 0; i--) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3432 | snd_soc_unregister_dai(dev); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3433 | |
| 3434 | return ret; |
| 3435 | } |
| 3436 | EXPORT_SYMBOL_GPL(snd_soc_register_dais); |
| 3437 | |
| 3438 | /** |
| 3439 | * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core |
| 3440 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3441 | * @dai: Array of DAIs to unregister |
| 3442 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3443 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3444 | void snd_soc_unregister_dais(struct device *dev, size_t count) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3445 | { |
| 3446 | int i; |
| 3447 | |
| 3448 | for (i = 0; i < count; i++) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3449 | snd_soc_unregister_dai(dev); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3450 | } |
| 3451 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); |
| 3452 | |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3453 | /** |
| 3454 | * snd_soc_register_platform - Register a platform with the ASoC core |
| 3455 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3456 | * @platform: platform to register |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3457 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3458 | int snd_soc_register_platform(struct device *dev, |
| 3459 | struct snd_soc_platform_driver *platform_drv) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3460 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3461 | struct snd_soc_platform *platform; |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3462 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3463 | dev_dbg(dev, "platform register %s\n", dev_name(dev)); |
| 3464 | |
| 3465 | platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); |
| 3466 | if (platform == NULL) |
Lu Guanqun | a739362 | 2011-04-20 16:00:51 +0800 | [diff] [blame] | 3467 | return -ENOMEM; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3468 | |
| 3469 | /* create platform component name */ |
| 3470 | platform->name = fmt_single_name(dev, &platform->id); |
| 3471 | if (platform->name == NULL) { |
| 3472 | kfree(platform); |
| 3473 | return -ENOMEM; |
| 3474 | } |
| 3475 | |
| 3476 | platform->dev = dev; |
| 3477 | platform->driver = platform_drv; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 3478 | platform->dapm.dev = dev; |
| 3479 | platform->dapm.platform = platform; |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 3480 | platform->dapm.stream_event = platform_drv->stream_event; |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3481 | |
| 3482 | mutex_lock(&client_mutex); |
| 3483 | list_add(&platform->list, &platform_list); |
| 3484 | mutex_unlock(&client_mutex); |
| 3485 | |
| 3486 | pr_debug("Registered platform '%s'\n", platform->name); |
| 3487 | |
| 3488 | return 0; |
| 3489 | } |
| 3490 | EXPORT_SYMBOL_GPL(snd_soc_register_platform); |
| 3491 | |
| 3492 | /** |
| 3493 | * snd_soc_unregister_platform - Unregister a platform from the ASoC core |
| 3494 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3495 | * @platform: platform to unregister |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3496 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3497 | void snd_soc_unregister_platform(struct device *dev) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3498 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3499 | struct snd_soc_platform *platform; |
| 3500 | |
| 3501 | list_for_each_entry(platform, &platform_list, list) { |
| 3502 | if (dev == platform->dev) |
| 3503 | goto found; |
| 3504 | } |
| 3505 | return; |
| 3506 | |
| 3507 | found: |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3508 | mutex_lock(&client_mutex); |
| 3509 | list_del(&platform->list); |
| 3510 | mutex_unlock(&client_mutex); |
| 3511 | |
| 3512 | pr_debug("Unregistered platform '%s'\n", platform->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3513 | kfree(platform->name); |
| 3514 | kfree(platform); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 3515 | } |
| 3516 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
| 3517 | |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 3518 | static u64 codec_format_map[] = { |
| 3519 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, |
| 3520 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, |
| 3521 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, |
| 3522 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, |
| 3523 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, |
| 3524 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, |
| 3525 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 3526 | SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 3527 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, |
| 3528 | SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, |
| 3529 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, |
| 3530 | SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, |
| 3531 | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, |
| 3532 | SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, |
| 3533 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE |
| 3534 | | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, |
| 3535 | }; |
| 3536 | |
| 3537 | /* Fix up the DAI formats for endianness: codecs don't actually see |
| 3538 | * the endianness of the data but we're using the CPU format |
| 3539 | * definitions which do need to include endianness so we ensure that |
| 3540 | * codec DAIs always have both big and little endian variants set. |
| 3541 | */ |
| 3542 | static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) |
| 3543 | { |
| 3544 | int i; |
| 3545 | |
| 3546 | for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) |
| 3547 | if (stream->formats & codec_format_map[i]) |
| 3548 | stream->formats |= codec_format_map[i]; |
| 3549 | } |
| 3550 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3551 | /** |
Joonwoo Park | 6fb6439 | 2013-08-07 18:59:09 -0700 | [diff] [blame] | 3552 | * snd_soc_card_change_online_state - Mark if soc card is online/offline |
| 3553 | * |
| 3554 | * @soc_card : soc_card to mark |
| 3555 | */ |
| 3556 | void snd_soc_card_change_online_state(struct snd_soc_card *soc_card, int online) |
| 3557 | { |
| 3558 | snd_card_change_online_state(soc_card->snd_card, online); |
| 3559 | } |
| 3560 | EXPORT_SYMBOL(snd_soc_card_change_online_state); |
| 3561 | |
| 3562 | /** |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3563 | * snd_soc_register_codec - Register a codec with the ASoC core |
| 3564 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3565 | * @codec: codec to register |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3566 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3567 | int snd_soc_register_codec(struct device *dev, |
Mark Brown | 001ae4c | 2010-12-02 16:21:08 +0000 | [diff] [blame] | 3568 | const struct snd_soc_codec_driver *codec_drv, |
| 3569 | struct snd_soc_dai_driver *dai_drv, |
| 3570 | int num_dai) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3571 | { |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 3572 | size_t reg_size; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3573 | struct snd_soc_codec *codec; |
| 3574 | int ret, i; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 3575 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3576 | dev_dbg(dev, "codec register %s\n", dev_name(dev)); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3577 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3578 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 3579 | if (codec == NULL) |
| 3580 | return -ENOMEM; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3581 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3582 | /* create CODEC component name */ |
| 3583 | codec->name = fmt_single_name(dev, &codec->id); |
| 3584 | if (codec->name == NULL) { |
| 3585 | kfree(codec); |
| 3586 | return -ENOMEM; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 3587 | } |
| 3588 | |
Dimitris Papastamos | 23bbce3 | 2010-12-02 14:53:01 +0000 | [diff] [blame] | 3589 | if (codec_drv->compress_type) |
| 3590 | codec->compress_type = codec_drv->compress_type; |
| 3591 | else |
| 3592 | codec->compress_type = SND_SOC_FLAT_COMPRESSION; |
| 3593 | |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 3594 | codec->write = codec_drv->write; |
| 3595 | codec->read = codec_drv->read; |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 3596 | codec->volatile_register = codec_drv->volatile_register; |
| 3597 | codec->readable_register = codec_drv->readable_register; |
Dimitris Papastamos | 8020454 | 2011-03-24 13:45:17 +0000 | [diff] [blame] | 3598 | codec->writable_register = codec_drv->writable_register; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3599 | codec->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 3600 | codec->dapm.dev = dev; |
| 3601 | codec->dapm.codec = codec; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 3602 | codec->dapm.seq_notifier = codec_drv->seq_notifier; |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 3603 | codec->dapm.stream_event = codec_drv->stream_event; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3604 | codec->dev = dev; |
| 3605 | codec->driver = codec_drv; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3606 | codec->num_dai = num_dai; |
| 3607 | mutex_init(&codec->mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3608 | |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 3609 | /* allocate CODEC register cache */ |
| 3610 | if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 3611 | reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; |
Dimitris Papastamos | aea170a | 2011-01-12 10:38:58 +0000 | [diff] [blame] | 3612 | codec->reg_size = reg_size; |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 3613 | /* it is necessary to make a copy of the default register cache |
| 3614 | * because in the case of using a compression type that requires |
| 3615 | * the default register cache to be marked as __devinitconst the |
| 3616 | * kernel might have freed the array by the time we initialize |
| 3617 | * the cache. |
| 3618 | */ |
Dimitris Papastamos | 2aa8632 | 2011-01-10 10:10:56 +0000 | [diff] [blame] | 3619 | if (codec_drv->reg_cache_default) { |
| 3620 | codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default, |
| 3621 | reg_size, GFP_KERNEL); |
| 3622 | if (!codec->reg_def_copy) { |
| 3623 | ret = -ENOMEM; |
| 3624 | goto fail; |
| 3625 | } |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 3629 | if (codec_drv->reg_access_size && codec_drv->reg_access_default) { |
| 3630 | if (!codec->volatile_register) |
| 3631 | codec->volatile_register = snd_soc_default_volatile_register; |
| 3632 | if (!codec->readable_register) |
| 3633 | codec->readable_register = snd_soc_default_readable_register; |
Dimitris Papastamos | 8020454 | 2011-03-24 13:45:17 +0000 | [diff] [blame] | 3634 | if (!codec->writable_register) |
| 3635 | codec->writable_register = snd_soc_default_writable_register; |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3638 | for (i = 0; i < num_dai; i++) { |
| 3639 | fixup_codec_formats(&dai_drv[i].playback); |
| 3640 | fixup_codec_formats(&dai_drv[i].capture); |
| 3641 | } |
| 3642 | |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 3643 | /* register any DAIs */ |
| 3644 | if (num_dai) { |
| 3645 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); |
| 3646 | if (ret < 0) |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 3647 | goto fail; |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 3648 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3649 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3650 | mutex_lock(&client_mutex); |
| 3651 | list_add(&codec->list, &codec_list); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3652 | mutex_unlock(&client_mutex); |
| 3653 | |
| 3654 | pr_debug("Registered codec '%s'\n", codec->name); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3655 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3656 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 3657 | fail: |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 3658 | kfree(codec->reg_def_copy); |
| 3659 | codec->reg_def_copy = NULL; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3660 | kfree(codec->name); |
| 3661 | kfree(codec); |
| 3662 | return ret; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3663 | } |
| 3664 | EXPORT_SYMBOL_GPL(snd_soc_register_codec); |
| 3665 | |
| 3666 | /** |
| 3667 | * snd_soc_unregister_codec - Unregister a codec from the ASoC core |
| 3668 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3669 | * @codec: codec to unregister |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3670 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3671 | void snd_soc_unregister_codec(struct device *dev) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3672 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3673 | struct snd_soc_codec *codec; |
| 3674 | int i; |
| 3675 | |
| 3676 | list_for_each_entry(codec, &codec_list, list) { |
| 3677 | if (dev == codec->dev) |
| 3678 | goto found; |
| 3679 | } |
| 3680 | return; |
| 3681 | |
| 3682 | found: |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 3683 | if (codec->num_dai) |
| 3684 | for (i = 0; i < codec->num_dai; i++) |
| 3685 | snd_soc_unregister_dai(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3686 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3687 | mutex_lock(&client_mutex); |
| 3688 | list_del(&codec->list); |
| 3689 | mutex_unlock(&client_mutex); |
| 3690 | |
| 3691 | pr_debug("Unregistered codec '%s'\n", codec->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3692 | |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 3693 | snd_soc_cache_exit(codec); |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 3694 | kfree(codec->reg_def_copy); |
Dimitris Papastamos | 1aafcd4 | 2010-10-21 13:19:45 +0100 | [diff] [blame] | 3695 | kfree(codec->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3696 | kfree(codec); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3697 | } |
| 3698 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
| 3699 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3700 | /* Retrieve a card's name from device tree */ |
| 3701 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, |
| 3702 | const char *propname) |
| 3703 | { |
| 3704 | struct device_node *np = card->dev->of_node; |
| 3705 | int ret; |
| 3706 | |
| 3707 | ret = of_property_read_string_index(np, propname, 0, &card->name); |
| 3708 | /* |
| 3709 | * EINVAL means the property does not exist. This is fine providing |
| 3710 | * card->name was previously set, which is checked later in |
| 3711 | * snd_soc_register_card. |
| 3712 | */ |
| 3713 | if (ret < 0 && ret != -EINVAL) { |
| 3714 | dev_err(card->dev, |
| 3715 | "Property '%s' could not be read: %d\n", |
| 3716 | propname, ret); |
| 3717 | return ret; |
| 3718 | } |
| 3719 | |
| 3720 | return 0; |
| 3721 | } |
| 3722 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); |
| 3723 | |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3724 | int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, |
| 3725 | const char *propname) |
| 3726 | { |
| 3727 | struct device_node *np = card->dev->of_node; |
| 3728 | int num_routes; |
| 3729 | struct snd_soc_dapm_route *routes; |
| 3730 | int i, ret; |
| 3731 | |
| 3732 | num_routes = of_property_count_strings(np, propname); |
Richard Zhao | c34ce32 | 2012-04-24 15:24:43 +0800 | [diff] [blame] | 3733 | if (num_routes < 0 || num_routes & 1) { |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3734 | dev_err(card->dev, |
Richard Zhao | c34ce32 | 2012-04-24 15:24:43 +0800 | [diff] [blame] | 3735 | "Property '%s' does not exist or its length is not even\n", |
| 3736 | propname); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3737 | return -EINVAL; |
| 3738 | } |
| 3739 | num_routes /= 2; |
| 3740 | if (!num_routes) { |
| 3741 | dev_err(card->dev, |
| 3742 | "Property '%s's length is zero\n", |
| 3743 | propname); |
| 3744 | return -EINVAL; |
| 3745 | } |
| 3746 | |
| 3747 | routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), |
| 3748 | GFP_KERNEL); |
| 3749 | if (!routes) { |
| 3750 | dev_err(card->dev, |
| 3751 | "Could not allocate DAPM route table\n"); |
| 3752 | return -EINVAL; |
| 3753 | } |
| 3754 | |
| 3755 | for (i = 0; i < num_routes; i++) { |
| 3756 | ret = of_property_read_string_index(np, propname, |
| 3757 | 2 * i, &routes[i].sink); |
| 3758 | if (ret) { |
| 3759 | dev_err(card->dev, |
| 3760 | "Property '%s' index %d could not be read: %d\n", |
| 3761 | propname, 2 * i, ret); |
| 3762 | return -EINVAL; |
| 3763 | } |
| 3764 | ret = of_property_read_string_index(np, propname, |
| 3765 | (2 * i) + 1, &routes[i].source); |
| 3766 | if (ret) { |
| 3767 | dev_err(card->dev, |
| 3768 | "Property '%s' index %d could not be read: %d\n", |
| 3769 | propname, (2 * i) + 1, ret); |
| 3770 | return -EINVAL; |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | card->num_dapm_routes = num_routes; |
| 3775 | card->dapm_routes = routes; |
| 3776 | |
| 3777 | return 0; |
| 3778 | } |
| 3779 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); |
| 3780 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 3781 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3782 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3783 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3784 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); |
| 3785 | if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3786 | printk(KERN_WARNING |
| 3787 | "ASoC: Failed to create debugfs directory\n"); |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3788 | snd_soc_debugfs_root = NULL; |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3789 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 3790 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3791 | if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 3792 | &codec_list_fops)) |
| 3793 | pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); |
| 3794 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3795 | if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 3796 | &dai_list_fops)) |
| 3797 | pr_warn("ASoC: Failed to create DAI list debugfs file\n"); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 3798 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3799 | if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 3800 | &platform_list_fops)) |
| 3801 | pr_warn("ASoC: Failed to create platform list debugfs file\n"); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3802 | #endif |
| 3803 | |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3804 | snd_soc_util_init(); |
| 3805 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3806 | return platform_driver_register(&soc_driver); |
| 3807 | } |
Mark Brown | 4abe8e1 | 2010-10-12 17:41:03 +0100 | [diff] [blame] | 3808 | module_init(snd_soc_init); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3809 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 3810 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3811 | { |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3812 | snd_soc_util_exit(); |
| 3813 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3814 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 3815 | debugfs_remove_recursive(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3816 | #endif |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 3817 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3818 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3819 | module_exit(snd_soc_exit); |
| 3820 | |
| 3821 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 3822 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3823 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 3824 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 3825 | MODULE_ALIAS("platform:soc-audio"); |