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