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