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