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