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