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