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