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