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