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