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