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