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