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. |
| 6 | * |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 7 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Liam Girdwood | 0664d88 | 2006-12-18 14:39:02 +0100 | [diff] [blame] | 8 | * with code, comments and ideas from :- |
| 9 | * Richard Purdie <richard@openedhand.com> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
| 15 | * |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 16 | * TODO: |
| 17 | * o Add hw rules to enforce rates, etc. |
| 18 | * o More testing with other codecs/machines. |
| 19 | * o Add more codecs and platforms to ensure good API coverage. |
| 20 | * o Support TDM on PCM and I2S |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/moduleparam.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/pm.h> |
| 28 | #include <linux/bitops.h> |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 29 | #include <linux/debugfs.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
Marek Vasut | 474828a | 2009-07-22 13:01:03 +0200 | [diff] [blame] | 31 | #include <sound/ac97_codec.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 32 | #include <sound/core.h> |
| 33 | #include <sound/pcm.h> |
| 34 | #include <sound/pcm_params.h> |
| 35 | #include <sound/soc.h> |
| 36 | #include <sound/soc-dapm.h> |
| 37 | #include <sound/initval.h> |
| 38 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 39 | static DEFINE_MUTEX(pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 40 | static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); |
| 41 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 42 | #ifdef CONFIG_DEBUG_FS |
| 43 | static struct dentry *debugfs_root; |
| 44 | #endif |
| 45 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 46 | static DEFINE_MUTEX(client_mutex); |
| 47 | static LIST_HEAD(card_list); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 48 | static LIST_HEAD(dai_list); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 49 | static LIST_HEAD(platform_list); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 50 | static LIST_HEAD(codec_list); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 51 | |
| 52 | static int snd_soc_register_card(struct snd_soc_card *card); |
| 53 | static int snd_soc_unregister_card(struct snd_soc_card *card); |
| 54 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 55 | /* |
| 56 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
| 57 | * It can be used to eliminate pops between different playback streams, e.g. |
| 58 | * between two audio tracks. |
| 59 | */ |
| 60 | static int pmdown_time = 5000; |
| 61 | module_param(pmdown_time, int, 0); |
| 62 | MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); |
| 63 | |
Liam Girdwood | 965ac42 | 2007-01-31 14:14:57 +0100 | [diff] [blame] | 64 | /* |
| 65 | * This function forces any delayed work to be queued and run. |
| 66 | */ |
| 67 | static int run_delayed_work(struct delayed_work *dwork) |
| 68 | { |
| 69 | int ret; |
| 70 | |
| 71 | /* cancel any work waiting to be queued. */ |
| 72 | ret = cancel_delayed_work(dwork); |
| 73 | |
| 74 | /* if there was any work waiting then we run it now and |
| 75 | * wait for it's completion */ |
| 76 | if (ret) { |
| 77 | schedule_delayed_work(dwork, 0); |
| 78 | flush_scheduled_work(); |
| 79 | } |
| 80 | return ret; |
| 81 | } |
| 82 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 83 | /* codec register dump */ |
| 84 | static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) |
| 85 | { |
| 86 | int i, step = 1, count = 0; |
| 87 | |
| 88 | if (!codec->reg_cache_size) |
| 89 | return 0; |
| 90 | |
| 91 | if (codec->reg_cache_step) |
| 92 | step = codec->reg_cache_step; |
| 93 | |
| 94 | count += sprintf(buf, "%s registers\n", codec->name); |
| 95 | for (i = 0; i < codec->reg_cache_size; i += step) { |
| 96 | if (codec->readable_register && !codec->readable_register(i)) |
| 97 | continue; |
| 98 | |
| 99 | count += sprintf(buf + count, "%2x: ", i); |
| 100 | if (count >= PAGE_SIZE - 1) |
| 101 | break; |
| 102 | |
| 103 | if (codec->display_register) |
| 104 | count += codec->display_register(codec, buf + count, |
| 105 | PAGE_SIZE - count, i); |
| 106 | else |
| 107 | count += snprintf(buf + count, PAGE_SIZE - count, |
| 108 | "%4x", codec->read(codec, i)); |
| 109 | |
| 110 | if (count >= PAGE_SIZE - 1) |
| 111 | break; |
| 112 | |
| 113 | count += snprintf(buf + count, PAGE_SIZE - count, "\n"); |
| 114 | if (count >= PAGE_SIZE - 1) |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | /* Truncate count; min() would cause a warning */ |
| 119 | if (count >= PAGE_SIZE) |
| 120 | count = PAGE_SIZE - 1; |
| 121 | |
| 122 | return count; |
| 123 | } |
| 124 | static ssize_t codec_reg_show(struct device *dev, |
| 125 | struct device_attribute *attr, char *buf) |
| 126 | { |
| 127 | struct snd_soc_device *devdata = dev_get_drvdata(dev); |
| 128 | return soc_codec_reg_show(devdata->card->codec, buf); |
| 129 | } |
| 130 | |
| 131 | static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); |
| 132 | |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 133 | static ssize_t pmdown_time_show(struct device *dev, |
| 134 | struct device_attribute *attr, char *buf) |
| 135 | { |
| 136 | struct snd_soc_device *socdev = dev_get_drvdata(dev); |
| 137 | struct snd_soc_card *card = socdev->card; |
| 138 | |
Mark Brown | 6c5f1fe | 2010-02-17 14:30:44 +0000 | [diff] [blame] | 139 | return sprintf(buf, "%ld\n", card->pmdown_time); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static ssize_t pmdown_time_set(struct device *dev, |
| 143 | struct device_attribute *attr, |
| 144 | const char *buf, size_t count) |
| 145 | { |
| 146 | struct snd_soc_device *socdev = dev_get_drvdata(dev); |
| 147 | struct snd_soc_card *card = socdev->card; |
| 148 | |
| 149 | strict_strtol(buf, 10, &card->pmdown_time); |
| 150 | |
| 151 | return count; |
| 152 | } |
| 153 | |
| 154 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); |
| 155 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 156 | #ifdef CONFIG_DEBUG_FS |
| 157 | static int codec_reg_open_file(struct inode *inode, struct file *file) |
| 158 | { |
| 159 | file->private_data = inode->i_private; |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, |
| 164 | size_t count, loff_t *ppos) |
| 165 | { |
| 166 | ssize_t ret; |
| 167 | struct snd_soc_codec *codec = file->private_data; |
| 168 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 169 | if (!buf) |
| 170 | return -ENOMEM; |
| 171 | ret = soc_codec_reg_show(codec, buf); |
| 172 | if (ret >= 0) |
| 173 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 174 | kfree(buf); |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | static ssize_t codec_reg_write_file(struct file *file, |
| 179 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 180 | { |
| 181 | char buf[32]; |
| 182 | int buf_size; |
| 183 | char *start = buf; |
| 184 | unsigned long reg, value; |
| 185 | int step = 1; |
| 186 | struct snd_soc_codec *codec = file->private_data; |
| 187 | |
| 188 | buf_size = min(count, (sizeof(buf)-1)); |
| 189 | if (copy_from_user(buf, user_buf, buf_size)) |
| 190 | return -EFAULT; |
| 191 | buf[buf_size] = 0; |
| 192 | |
| 193 | if (codec->reg_cache_step) |
| 194 | step = codec->reg_cache_step; |
| 195 | |
| 196 | while (*start == ' ') |
| 197 | start++; |
| 198 | reg = simple_strtoul(start, &start, 16); |
| 199 | if ((reg >= codec->reg_cache_size) || (reg % step)) |
| 200 | return -EINVAL; |
| 201 | while (*start == ' ') |
| 202 | start++; |
| 203 | if (strict_strtoul(start, 16, &value)) |
| 204 | return -EINVAL; |
| 205 | codec->write(codec, reg, value); |
| 206 | return buf_size; |
| 207 | } |
| 208 | |
| 209 | static const struct file_operations codec_reg_fops = { |
| 210 | .open = codec_reg_open_file, |
| 211 | .read = codec_reg_read_file, |
| 212 | .write = codec_reg_write_file, |
| 213 | }; |
| 214 | |
| 215 | static void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 216 | { |
| 217 | char codec_root[128]; |
| 218 | |
| 219 | if (codec->dev) |
| 220 | snprintf(codec_root, sizeof(codec_root), |
| 221 | "%s.%s", codec->name, dev_name(codec->dev)); |
| 222 | else |
| 223 | snprintf(codec_root, sizeof(codec_root), |
| 224 | "%s", codec->name); |
| 225 | |
| 226 | codec->debugfs_codec_root = debugfs_create_dir(codec_root, |
| 227 | debugfs_root); |
| 228 | if (!codec->debugfs_codec_root) { |
| 229 | printk(KERN_WARNING |
| 230 | "ASoC: Failed to create codec debugfs directory\n"); |
| 231 | return; |
| 232 | } |
| 233 | |
| 234 | codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, |
| 235 | codec->debugfs_codec_root, |
| 236 | codec, &codec_reg_fops); |
| 237 | if (!codec->debugfs_reg) |
| 238 | printk(KERN_WARNING |
| 239 | "ASoC: Failed to create codec register debugfs file\n"); |
| 240 | |
| 241 | codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744, |
| 242 | codec->debugfs_codec_root, |
| 243 | &codec->pop_time); |
| 244 | if (!codec->debugfs_pop_time) |
| 245 | printk(KERN_WARNING |
| 246 | "Failed to create pop time debugfs file\n"); |
| 247 | |
| 248 | codec->debugfs_dapm = debugfs_create_dir("dapm", |
| 249 | codec->debugfs_codec_root); |
| 250 | if (!codec->debugfs_dapm) |
| 251 | printk(KERN_WARNING |
| 252 | "Failed to create DAPM debugfs directory\n"); |
| 253 | |
| 254 | snd_soc_dapm_debugfs_init(codec); |
| 255 | } |
| 256 | |
| 257 | static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 258 | { |
| 259 | debugfs_remove_recursive(codec->debugfs_codec_root); |
| 260 | } |
| 261 | |
| 262 | #else |
| 263 | |
| 264 | static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 265 | { |
| 266 | } |
| 267 | |
| 268 | static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 269 | { |
| 270 | } |
| 271 | #endif |
| 272 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 273 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 274 | /* unregister ac97 codec */ |
| 275 | static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) |
| 276 | { |
| 277 | if (codec->ac97->dev.bus) |
| 278 | device_unregister(&codec->ac97->dev); |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /* stop no dev release warning */ |
| 283 | static void soc_ac97_device_release(struct device *dev){} |
| 284 | |
| 285 | /* register ac97 codec to bus */ |
| 286 | static int soc_ac97_dev_register(struct snd_soc_codec *codec) |
| 287 | { |
| 288 | int err; |
| 289 | |
| 290 | codec->ac97->dev.bus = &ac97_bus_type; |
Mark Brown | 4ac5c61 | 2009-04-01 19:35:01 +0100 | [diff] [blame] | 291 | codec->ac97->dev.parent = codec->card->dev; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 292 | codec->ac97->dev.release = soc_ac97_device_release; |
| 293 | |
Kay Sievers | bb072bf | 2008-11-02 03:50:35 +0100 | [diff] [blame] | 294 | dev_set_name(&codec->ac97->dev, "%d-%d:%s", |
| 295 | codec->card->number, 0, codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 296 | err = device_register(&codec->ac97->dev); |
| 297 | if (err < 0) { |
| 298 | snd_printk(KERN_ERR "Can't register ac97 bus\n"); |
| 299 | codec->ac97->dev.bus = NULL; |
| 300 | return err; |
| 301 | } |
| 302 | return 0; |
| 303 | } |
| 304 | #endif |
| 305 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 306 | static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream) |
| 307 | { |
| 308 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 309 | struct snd_soc_device *socdev = rtd->socdev; |
| 310 | struct snd_soc_card *card = socdev->card; |
| 311 | struct snd_soc_dai_link *machine = rtd->dai; |
| 312 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 313 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
| 314 | int ret; |
| 315 | |
| 316 | if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates || |
| 317 | machine->symmetric_rates) { |
Peter Ujfalusi | 5083145 | 2010-03-03 15:08:04 +0200 | [diff] [blame] | 318 | dev_dbg(card->dev, "Symmetry forces %dHz rate\n", |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 319 | machine->rate); |
| 320 | |
| 321 | ret = snd_pcm_hw_constraint_minmax(substream->runtime, |
| 322 | SNDRV_PCM_HW_PARAM_RATE, |
| 323 | machine->rate, |
| 324 | machine->rate); |
| 325 | if (ret < 0) { |
| 326 | dev_err(card->dev, |
| 327 | "Unable to apply rate symmetry constraint: %d\n", ret); |
| 328 | return ret; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 335 | /* |
| 336 | * Called by ALSA when a PCM substream is opened, the runtime->hw record is |
| 337 | * then initialized and any private data can be allocated. This also calls |
| 338 | * startup for the cpu DAI, platform, machine and codec DAI. |
| 339 | */ |
| 340 | static int soc_pcm_open(struct snd_pcm_substream *substream) |
| 341 | { |
| 342 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 343 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 344 | struct snd_soc_card *card = socdev->card; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 345 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 346 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 347 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 348 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 349 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 350 | int ret = 0; |
| 351 | |
| 352 | mutex_lock(&pcm_mutex); |
| 353 | |
| 354 | /* startup the audio subsystem */ |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 355 | if (cpu_dai->ops->startup) { |
| 356 | ret = cpu_dai->ops->startup(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 357 | if (ret < 0) { |
| 358 | printk(KERN_ERR "asoc: can't open interface %s\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 359 | cpu_dai->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 360 | goto out; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if (platform->pcm_ops->open) { |
| 365 | ret = platform->pcm_ops->open(substream); |
| 366 | if (ret < 0) { |
| 367 | printk(KERN_ERR "asoc: can't open platform %s\n", platform->name); |
| 368 | goto platform_err; |
| 369 | } |
| 370 | } |
| 371 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 372 | if (codec_dai->ops->startup) { |
| 373 | ret = codec_dai->ops->startup(substream, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 374 | if (ret < 0) { |
| 375 | printk(KERN_ERR "asoc: can't open codec %s\n", |
| 376 | codec_dai->name); |
| 377 | goto codec_dai_err; |
| 378 | } |
| 379 | } |
| 380 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 381 | if (machine->ops && machine->ops->startup) { |
| 382 | ret = machine->ops->startup(substream); |
| 383 | if (ret < 0) { |
| 384 | printk(KERN_ERR "asoc: %s startup failed\n", machine->name); |
| 385 | goto machine_err; |
| 386 | } |
| 387 | } |
| 388 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 389 | /* Check that the codec and cpu DAI's are compatible */ |
| 390 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 391 | runtime->hw.rate_min = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 392 | max(codec_dai->playback.rate_min, |
| 393 | cpu_dai->playback.rate_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 394 | runtime->hw.rate_max = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 395 | min(codec_dai->playback.rate_max, |
| 396 | cpu_dai->playback.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 397 | runtime->hw.channels_min = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 398 | max(codec_dai->playback.channels_min, |
| 399 | cpu_dai->playback.channels_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 400 | runtime->hw.channels_max = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 401 | min(codec_dai->playback.channels_max, |
| 402 | cpu_dai->playback.channels_max); |
| 403 | runtime->hw.formats = |
| 404 | codec_dai->playback.formats & cpu_dai->playback.formats; |
| 405 | runtime->hw.rates = |
| 406 | codec_dai->playback.rates & cpu_dai->playback.rates; |
Jassi Brar | d9ad629 | 2010-03-12 13:38:52 +0900 | [diff] [blame] | 407 | if (codec_dai->playback.rates |
| 408 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
| 409 | runtime->hw.rates |= cpu_dai->playback.rates; |
| 410 | if (cpu_dai->playback.rates |
| 411 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
| 412 | runtime->hw.rates |= codec_dai->playback.rates; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 413 | } else { |
| 414 | runtime->hw.rate_min = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 415 | max(codec_dai->capture.rate_min, |
| 416 | cpu_dai->capture.rate_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 417 | runtime->hw.rate_max = |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 418 | min(codec_dai->capture.rate_max, |
| 419 | cpu_dai->capture.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 420 | runtime->hw.channels_min = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 421 | max(codec_dai->capture.channels_min, |
| 422 | cpu_dai->capture.channels_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 423 | runtime->hw.channels_max = |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 424 | min(codec_dai->capture.channels_max, |
| 425 | cpu_dai->capture.channels_max); |
| 426 | runtime->hw.formats = |
| 427 | codec_dai->capture.formats & cpu_dai->capture.formats; |
| 428 | runtime->hw.rates = |
| 429 | codec_dai->capture.rates & cpu_dai->capture.rates; |
Jassi Brar | d9ad629 | 2010-03-12 13:38:52 +0900 | [diff] [blame] | 430 | if (codec_dai->capture.rates |
| 431 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
| 432 | runtime->hw.rates |= cpu_dai->capture.rates; |
| 433 | if (cpu_dai->capture.rates |
| 434 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
| 435 | runtime->hw.rates |= codec_dai->capture.rates; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | snd_pcm_limit_hw_rates(runtime); |
| 439 | if (!runtime->hw.rates) { |
| 440 | printk(KERN_ERR "asoc: %s <-> %s No matching rates\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 441 | codec_dai->name, cpu_dai->name); |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 442 | goto config_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 443 | } |
| 444 | if (!runtime->hw.formats) { |
| 445 | printk(KERN_ERR "asoc: %s <-> %s No matching formats\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 446 | codec_dai->name, cpu_dai->name); |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 447 | goto config_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 448 | } |
| 449 | if (!runtime->hw.channels_min || !runtime->hw.channels_max) { |
| 450 | printk(KERN_ERR "asoc: %s <-> %s No matching channels\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 451 | codec_dai->name, cpu_dai->name); |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 452 | goto config_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 453 | } |
| 454 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 455 | /* Symmetry only applies if we've already got an active stream. */ |
| 456 | if (cpu_dai->active || codec_dai->active) { |
| 457 | ret = soc_pcm_apply_symmetry(substream); |
| 458 | if (ret != 0) |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 459 | goto config_err; |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Mark Brown | f24368c | 2008-10-21 21:45:08 +0100 | [diff] [blame] | 462 | pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name); |
| 463 | pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates); |
| 464 | pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min, |
| 465 | runtime->hw.channels_max); |
| 466 | pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min, |
| 467 | runtime->hw.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 468 | |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 469 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 470 | cpu_dai->playback.active++; |
| 471 | codec_dai->playback.active++; |
| 472 | } else { |
| 473 | cpu_dai->capture.active++; |
| 474 | codec_dai->capture.active++; |
| 475 | } |
| 476 | cpu_dai->active++; |
| 477 | codec_dai->active++; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 478 | card->codec->active++; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 479 | mutex_unlock(&pcm_mutex); |
| 480 | return 0; |
| 481 | |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 482 | config_err: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 483 | if (machine->ops && machine->ops->shutdown) |
| 484 | machine->ops->shutdown(substream); |
| 485 | |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 486 | machine_err: |
| 487 | if (codec_dai->ops->shutdown) |
| 488 | codec_dai->ops->shutdown(substream, codec_dai); |
| 489 | |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 490 | codec_dai_err: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 491 | if (platform->pcm_ops->close) |
| 492 | platform->pcm_ops->close(substream); |
| 493 | |
| 494 | platform_err: |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 495 | if (cpu_dai->ops->shutdown) |
| 496 | cpu_dai->ops->shutdown(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 497 | out: |
| 498 | mutex_unlock(&pcm_mutex); |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | /* |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 503 | * Power down the audio subsystem pmdown_time msecs after close is called. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 504 | * This is to ensure there are no pops or clicks in between any music tracks |
| 505 | * due to DAPM power cycling. |
| 506 | */ |
Andrew Morton | 4484bb2 | 2006-12-15 09:30:07 +0100 | [diff] [blame] | 507 | static void close_delayed_work(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 508 | { |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 509 | struct snd_soc_card *card = container_of(work, struct snd_soc_card, |
| 510 | delayed_work.work); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 511 | struct snd_soc_codec *codec = card->codec; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 512 | struct snd_soc_dai *codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 513 | int i; |
| 514 | |
| 515 | mutex_lock(&pcm_mutex); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 516 | for (i = 0; i < codec->num_dai; i++) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 517 | codec_dai = &codec->dai[i]; |
| 518 | |
Mark Brown | f24368c | 2008-10-21 21:45:08 +0100 | [diff] [blame] | 519 | pr_debug("pop wq checking: %s status: %s waiting: %s\n", |
| 520 | codec_dai->playback.stream_name, |
| 521 | codec_dai->playback.active ? "active" : "inactive", |
| 522 | codec_dai->pop_wait ? "yes" : "no"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 523 | |
| 524 | /* are we waiting on this codec DAI stream */ |
| 525 | if (codec_dai->pop_wait == 1) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 526 | codec_dai->pop_wait = 0; |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 527 | snd_soc_dapm_stream_event(codec, |
| 528 | codec_dai->playback.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 529 | SND_SOC_DAPM_STREAM_STOP); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | mutex_unlock(&pcm_mutex); |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Called by ALSA when a PCM substream is closed. Private data can be |
| 537 | * freed here. The cpu DAI, codec DAI, machine and platform are also |
| 538 | * shutdown. |
| 539 | */ |
| 540 | static int soc_codec_close(struct snd_pcm_substream *substream) |
| 541 | { |
| 542 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 543 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 544 | struct snd_soc_card *card = socdev->card; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 545 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 546 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 547 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 548 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 549 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 550 | |
| 551 | mutex_lock(&pcm_mutex); |
| 552 | |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 553 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 554 | cpu_dai->playback.active--; |
| 555 | codec_dai->playback.active--; |
| 556 | } else { |
| 557 | cpu_dai->capture.active--; |
| 558 | codec_dai->capture.active--; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 559 | } |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 560 | |
| 561 | cpu_dai->active--; |
| 562 | codec_dai->active--; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 563 | codec->active--; |
| 564 | |
Mark Brown | 6010b2d | 2008-09-06 18:33:24 +0100 | [diff] [blame] | 565 | /* Muting the DAC suppresses artifacts caused during digital |
| 566 | * shutdown, for example from stopping clocks. |
| 567 | */ |
| 568 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 569 | snd_soc_dai_digital_mute(codec_dai, 1); |
| 570 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 571 | if (cpu_dai->ops->shutdown) |
| 572 | cpu_dai->ops->shutdown(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 573 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 574 | if (codec_dai->ops->shutdown) |
| 575 | codec_dai->ops->shutdown(substream, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 576 | |
| 577 | if (machine->ops && machine->ops->shutdown) |
| 578 | machine->ops->shutdown(substream); |
| 579 | |
| 580 | if (platform->pcm_ops->close) |
| 581 | platform->pcm_ops->close(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 582 | |
| 583 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 584 | /* start delayed pop wq here for playback streams */ |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 585 | codec_dai->pop_wait = 1; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 586 | schedule_delayed_work(&card->delayed_work, |
Mark Brown | 96dd362 | 2010-02-12 11:05:44 +0000 | [diff] [blame] | 587 | msecs_to_jiffies(card->pmdown_time)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 588 | } else { |
| 589 | /* capture streams can be powered down now */ |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 590 | snd_soc_dapm_stream_event(codec, |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 591 | codec_dai->capture.stream_name, |
| 592 | SND_SOC_DAPM_STREAM_STOP); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | mutex_unlock(&pcm_mutex); |
| 596 | return 0; |
| 597 | } |
| 598 | |
| 599 | /* |
| 600 | * Called by ALSA when the PCM substream is prepared, can set format, sample |
| 601 | * rate, etc. This function is non atomic and can be called multiple times, |
| 602 | * it can refer to the runtime info. |
| 603 | */ |
| 604 | static int soc_pcm_prepare(struct snd_pcm_substream *substream) |
| 605 | { |
| 606 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 607 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 608 | struct snd_soc_card *card = socdev->card; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 609 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 610 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 611 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 612 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 613 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 614 | int ret = 0; |
| 615 | |
| 616 | mutex_lock(&pcm_mutex); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 617 | |
| 618 | if (machine->ops && machine->ops->prepare) { |
| 619 | ret = machine->ops->prepare(substream); |
| 620 | if (ret < 0) { |
| 621 | printk(KERN_ERR "asoc: machine prepare error\n"); |
| 622 | goto out; |
| 623 | } |
| 624 | } |
| 625 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 626 | if (platform->pcm_ops->prepare) { |
| 627 | ret = platform->pcm_ops->prepare(substream); |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 628 | if (ret < 0) { |
| 629 | printk(KERN_ERR "asoc: platform prepare error\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 630 | goto out; |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 631 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 632 | } |
| 633 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 634 | if (codec_dai->ops->prepare) { |
| 635 | ret = codec_dai->ops->prepare(substream, codec_dai); |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 636 | if (ret < 0) { |
| 637 | printk(KERN_ERR "asoc: codec DAI prepare error\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 638 | goto out; |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 639 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 640 | } |
| 641 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 642 | if (cpu_dai->ops->prepare) { |
| 643 | ret = cpu_dai->ops->prepare(substream, cpu_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 644 | if (ret < 0) { |
| 645 | printk(KERN_ERR "asoc: cpu DAI prepare error\n"); |
| 646 | goto out; |
| 647 | } |
| 648 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 649 | |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 650 | /* cancel any delayed stream shutdown that is pending */ |
| 651 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 652 | codec_dai->pop_wait) { |
| 653 | codec_dai->pop_wait = 0; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 654 | cancel_delayed_work(&card->delayed_work); |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 655 | } |
| 656 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 657 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 658 | snd_soc_dapm_stream_event(codec, |
| 659 | codec_dai->playback.stream_name, |
| 660 | SND_SOC_DAPM_STREAM_START); |
| 661 | else |
| 662 | snd_soc_dapm_stream_event(codec, |
| 663 | codec_dai->capture.stream_name, |
| 664 | SND_SOC_DAPM_STREAM_START); |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 665 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 666 | snd_soc_dai_digital_mute(codec_dai, 0); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 667 | |
| 668 | out: |
| 669 | mutex_unlock(&pcm_mutex); |
| 670 | return ret; |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * Called by ALSA when the hardware params are set by application. This |
| 675 | * function can also be called multiple times and can allocate buffers |
| 676 | * (using snd_pcm_lib_* ). It's non-atomic. |
| 677 | */ |
| 678 | static int soc_pcm_hw_params(struct snd_pcm_substream *substream, |
| 679 | struct snd_pcm_hw_params *params) |
| 680 | { |
| 681 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 682 | struct snd_soc_device *socdev = rtd->socdev; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 683 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 684 | struct snd_soc_card *card = socdev->card; |
| 685 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 686 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 687 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 688 | int ret = 0; |
| 689 | |
| 690 | mutex_lock(&pcm_mutex); |
| 691 | |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 692 | if (machine->ops && machine->ops->hw_params) { |
| 693 | ret = machine->ops->hw_params(substream, params); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 694 | if (ret < 0) { |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 695 | printk(KERN_ERR "asoc: machine hw_params failed\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 696 | goto out; |
| 697 | } |
| 698 | } |
| 699 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 700 | if (codec_dai->ops->hw_params) { |
| 701 | ret = codec_dai->ops->hw_params(substream, params, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 702 | if (ret < 0) { |
| 703 | printk(KERN_ERR "asoc: can't set codec %s hw params\n", |
| 704 | codec_dai->name); |
| 705 | goto codec_err; |
| 706 | } |
| 707 | } |
| 708 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 709 | if (cpu_dai->ops->hw_params) { |
| 710 | ret = cpu_dai->ops->hw_params(substream, params, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 711 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 712 | printk(KERN_ERR "asoc: interface %s hw params failed\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 713 | cpu_dai->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 714 | goto interface_err; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | if (platform->pcm_ops->hw_params) { |
| 719 | ret = platform->pcm_ops->hw_params(substream, params); |
| 720 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 721 | printk(KERN_ERR "asoc: platform %s hw params failed\n", |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 722 | platform->name); |
| 723 | goto platform_err; |
| 724 | } |
| 725 | } |
| 726 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 727 | machine->rate = params_rate(params); |
| 728 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 729 | out: |
| 730 | mutex_unlock(&pcm_mutex); |
| 731 | return ret; |
| 732 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 733 | platform_err: |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 734 | if (cpu_dai->ops->hw_free) |
| 735 | cpu_dai->ops->hw_free(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 736 | |
| 737 | interface_err: |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 738 | if (codec_dai->ops->hw_free) |
| 739 | codec_dai->ops->hw_free(substream, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 740 | |
| 741 | codec_err: |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 742 | if (machine->ops && machine->ops->hw_free) |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 743 | machine->ops->hw_free(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 744 | |
| 745 | mutex_unlock(&pcm_mutex); |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | /* |
| 750 | * Free's resources allocated by hw_params, can be called multiple times |
| 751 | */ |
| 752 | static int soc_pcm_hw_free(struct snd_pcm_substream *substream) |
| 753 | { |
| 754 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 755 | struct snd_soc_device *socdev = rtd->socdev; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 756 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 757 | struct snd_soc_card *card = socdev->card; |
| 758 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 759 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 760 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 761 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 762 | |
| 763 | mutex_lock(&pcm_mutex); |
| 764 | |
| 765 | /* apply codec digital mute */ |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 766 | if (!codec->active) |
| 767 | snd_soc_dai_digital_mute(codec_dai, 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 768 | |
| 769 | /* free any machine hw params */ |
| 770 | if (machine->ops && machine->ops->hw_free) |
| 771 | machine->ops->hw_free(substream); |
| 772 | |
| 773 | /* free any DMA resources */ |
| 774 | if (platform->pcm_ops->hw_free) |
| 775 | platform->pcm_ops->hw_free(substream); |
| 776 | |
| 777 | /* now free hw params for the DAI's */ |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 778 | if (codec_dai->ops->hw_free) |
| 779 | codec_dai->ops->hw_free(substream, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 780 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 781 | if (cpu_dai->ops->hw_free) |
| 782 | cpu_dai->ops->hw_free(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 783 | |
| 784 | mutex_unlock(&pcm_mutex); |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 789 | { |
| 790 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 791 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 792 | struct snd_soc_card *card= socdev->card; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 793 | struct snd_soc_dai_link *machine = rtd->dai; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 794 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 795 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 796 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 797 | int ret; |
| 798 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 799 | if (codec_dai->ops->trigger) { |
| 800 | ret = codec_dai->ops->trigger(substream, cmd, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 801 | if (ret < 0) |
| 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | if (platform->pcm_ops->trigger) { |
| 806 | ret = platform->pcm_ops->trigger(substream, cmd); |
| 807 | if (ret < 0) |
| 808 | return ret; |
| 809 | } |
| 810 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 811 | if (cpu_dai->ops->trigger) { |
| 812 | ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 813 | if (ret < 0) |
| 814 | return ret; |
| 815 | } |
| 816 | return 0; |
| 817 | } |
| 818 | |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 819 | /* |
| 820 | * soc level wrapper for pointer callback |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 821 | * If cpu_dai, codec_dai, platform driver has the delay callback, than |
| 822 | * the runtime->delay will be updated accordingly. |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 823 | */ |
| 824 | static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) |
| 825 | { |
| 826 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 827 | struct snd_soc_device *socdev = rtd->socdev; |
| 828 | struct snd_soc_card *card = socdev->card; |
| 829 | struct snd_soc_platform *platform = card->platform; |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 830 | struct snd_soc_dai_link *machine = rtd->dai; |
| 831 | struct snd_soc_dai *cpu_dai = machine->cpu_dai; |
| 832 | struct snd_soc_dai *codec_dai = machine->codec_dai; |
| 833 | struct snd_pcm_runtime *runtime = substream->runtime; |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 834 | snd_pcm_uframes_t offset = 0; |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 835 | snd_pcm_sframes_t delay = 0; |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 836 | |
| 837 | if (platform->pcm_ops->pointer) |
| 838 | offset = platform->pcm_ops->pointer(substream); |
| 839 | |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 840 | if (cpu_dai->ops->delay) |
| 841 | delay += cpu_dai->ops->delay(substream, cpu_dai); |
| 842 | |
| 843 | if (codec_dai->ops->delay) |
| 844 | delay += codec_dai->ops->delay(substream, codec_dai); |
| 845 | |
| 846 | if (platform->delay) |
| 847 | delay += platform->delay(substream, codec_dai); |
| 848 | |
| 849 | runtime->delay = delay; |
| 850 | |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 851 | return offset; |
| 852 | } |
| 853 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 854 | /* ASoC PCM operations */ |
| 855 | static struct snd_pcm_ops soc_pcm_ops = { |
| 856 | .open = soc_pcm_open, |
| 857 | .close = soc_codec_close, |
| 858 | .hw_params = soc_pcm_hw_params, |
| 859 | .hw_free = soc_pcm_hw_free, |
| 860 | .prepare = soc_pcm_prepare, |
| 861 | .trigger = soc_pcm_trigger, |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 862 | .pointer = soc_pcm_pointer, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 863 | }; |
| 864 | |
| 865 | #ifdef CONFIG_PM |
| 866 | /* powers down audio subsystem for suspend */ |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 867 | static int soc_suspend(struct device *dev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 868 | { |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 869 | struct platform_device *pdev = to_platform_device(dev); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 870 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 871 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 872 | struct snd_soc_platform *platform = card->platform; |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 873 | struct snd_soc_codec_device *codec_dev = socdev->codec_dev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 874 | struct snd_soc_codec *codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 875 | int i; |
| 876 | |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 877 | /* If the initialization of this soc device failed, there is no codec |
| 878 | * associated with it. Just bail out in this case. |
| 879 | */ |
| 880 | if (!codec) |
| 881 | return 0; |
| 882 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 883 | /* Due to the resume being scheduled into a workqueue we could |
| 884 | * suspend before that's finished - wait for it to complete. |
| 885 | */ |
| 886 | snd_power_lock(codec->card); |
| 887 | snd_power_wait(codec->card, SNDRV_CTL_POWER_D0); |
| 888 | snd_power_unlock(codec->card); |
| 889 | |
| 890 | /* we're going to block userspace touching us until resume completes */ |
| 891 | snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot); |
| 892 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 893 | /* mute any active DAC's */ |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 894 | for (i = 0; i < card->num_links; i++) { |
| 895 | struct snd_soc_dai *dai = card->dai_link[i].codec_dai; |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 896 | if (dai->ops->digital_mute && dai->playback.active) |
| 897 | dai->ops->digital_mute(dai, 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 898 | } |
| 899 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 900 | /* suspend all pcms */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 901 | for (i = 0; i < card->num_links; i++) |
| 902 | snd_pcm_suspend_all(card->dai_link[i].pcm); |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 903 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 904 | if (card->suspend_pre) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 905 | card->suspend_pre(pdev, PMSG_SUSPEND); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 906 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 907 | for (i = 0; i < card->num_links; i++) { |
| 908 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 909 | if (cpu_dai->suspend && !cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 910 | cpu_dai->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 911 | if (platform->suspend) |
jassi brar | d273ebe | 2010-02-22 15:58:04 +0900 | [diff] [blame] | 912 | platform->suspend(&card->dai_link[i]); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /* close any waiting streams and save state */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 916 | run_delayed_work(&card->delayed_work); |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 917 | codec->suspend_bias_level = codec->bias_level; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 918 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 919 | for (i = 0; i < codec->num_dai; i++) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 920 | char *stream = codec->dai[i].playback.stream_name; |
| 921 | if (stream != NULL) |
| 922 | snd_soc_dapm_stream_event(codec, stream, |
| 923 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 924 | stream = codec->dai[i].capture.stream_name; |
| 925 | if (stream != NULL) |
| 926 | snd_soc_dapm_stream_event(codec, stream, |
| 927 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 928 | } |
| 929 | |
| 930 | if (codec_dev->suspend) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 931 | codec_dev->suspend(pdev, PMSG_SUSPEND); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 932 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 933 | for (i = 0; i < card->num_links; i++) { |
| 934 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 935 | if (cpu_dai->suspend && cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 936 | cpu_dai->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 937 | } |
| 938 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 939 | if (card->suspend_post) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 940 | card->suspend_post(pdev, PMSG_SUSPEND); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 941 | |
| 942 | return 0; |
| 943 | } |
| 944 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 945 | /* deferred resume work, so resume can complete before we finished |
| 946 | * setting our codec back up, which can be very slow on I2C |
| 947 | */ |
| 948 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 949 | { |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 950 | struct snd_soc_card *card = container_of(work, |
| 951 | struct snd_soc_card, |
| 952 | deferred_resume_work); |
| 953 | struct snd_soc_device *socdev = card->socdev; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 954 | struct snd_soc_platform *platform = card->platform; |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 955 | struct snd_soc_codec_device *codec_dev = socdev->codec_dev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 956 | struct snd_soc_codec *codec = card->codec; |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 957 | struct platform_device *pdev = to_platform_device(socdev->dev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 958 | int i; |
| 959 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 960 | /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
| 961 | * so userspace apps are blocked from touching us |
| 962 | */ |
| 963 | |
Mark Brown | fde22f2 | 2008-11-24 18:08:18 +0000 | [diff] [blame] | 964 | dev_dbg(socdev->dev, "starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 965 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 966 | if (card->resume_pre) |
| 967 | card->resume_pre(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 968 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 969 | for (i = 0; i < card->num_links; i++) { |
| 970 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 971 | if (cpu_dai->resume && cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 972 | cpu_dai->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | if (codec_dev->resume) |
| 976 | codec_dev->resume(pdev); |
| 977 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 978 | for (i = 0; i < codec->num_dai; i++) { |
| 979 | char *stream = codec->dai[i].playback.stream_name; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 980 | if (stream != NULL) |
| 981 | snd_soc_dapm_stream_event(codec, stream, |
| 982 | SND_SOC_DAPM_STREAM_RESUME); |
| 983 | stream = codec->dai[i].capture.stream_name; |
| 984 | if (stream != NULL) |
| 985 | snd_soc_dapm_stream_event(codec, stream, |
| 986 | SND_SOC_DAPM_STREAM_RESUME); |
| 987 | } |
| 988 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 989 | /* unmute any active DACs */ |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 990 | for (i = 0; i < card->num_links; i++) { |
| 991 | struct snd_soc_dai *dai = card->dai_link[i].codec_dai; |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 992 | if (dai->ops->digital_mute && dai->playback.active) |
| 993 | dai->ops->digital_mute(dai, 0); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 994 | } |
| 995 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 996 | for (i = 0; i < card->num_links; i++) { |
| 997 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Mark Brown | 3ba9e10a | 2008-11-24 18:01:05 +0000 | [diff] [blame] | 998 | if (cpu_dai->resume && !cpu_dai->ac97_control) |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 999 | cpu_dai->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1000 | if (platform->resume) |
jassi brar | d273ebe | 2010-02-22 15:58:04 +0900 | [diff] [blame] | 1001 | platform->resume(&card->dai_link[i]); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1004 | if (card->resume_post) |
| 1005 | card->resume_post(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1006 | |
Mark Brown | fde22f2 | 2008-11-24 18:08:18 +0000 | [diff] [blame] | 1007 | dev_dbg(socdev->dev, "resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1008 | |
| 1009 | /* userspace can access us now we are back as we were before */ |
| 1010 | snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0); |
| 1011 | } |
| 1012 | |
| 1013 | /* powers up audio subsystem after a suspend */ |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1014 | static int soc_resume(struct device *dev) |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1015 | { |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1016 | struct platform_device *pdev = to_platform_device(dev); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1017 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1018 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 1019 | struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai; |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1020 | |
Peter Ujfalusi | b9dd94a | 2010-02-22 13:27:13 +0200 | [diff] [blame] | 1021 | /* If the initialization of this soc device failed, there is no codec |
| 1022 | * associated with it. Just bail out in this case. |
| 1023 | */ |
| 1024 | if (!card->codec) |
| 1025 | return 0; |
| 1026 | |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 1027 | /* AC97 devices might have other drivers hanging off them so |
| 1028 | * need to resume immediately. Other drivers don't have that |
| 1029 | * problem and may take a substantial amount of time to resume |
| 1030 | * due to I/O costs and anti-pop so handle them out of line. |
| 1031 | */ |
| 1032 | if (cpu_dai->ac97_control) { |
| 1033 | dev_dbg(socdev->dev, "Resuming AC97 immediately\n"); |
| 1034 | soc_resume_deferred(&card->deferred_resume_work); |
| 1035 | } else { |
| 1036 | dev_dbg(socdev->dev, "Scheduling resume work\n"); |
| 1037 | if (!schedule_work(&card->deferred_resume_work)) |
| 1038 | dev_err(socdev->dev, "resume work item may be lost\n"); |
| 1039 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1040 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1041 | return 0; |
| 1042 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1043 | #else |
| 1044 | #define soc_suspend NULL |
| 1045 | #define soc_resume NULL |
| 1046 | #endif |
| 1047 | |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 1048 | static struct snd_soc_dai_ops null_dai_ops = { |
| 1049 | }; |
| 1050 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1051 | static void snd_soc_instantiate_card(struct snd_soc_card *card) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1052 | { |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1053 | struct platform_device *pdev = container_of(card->dev, |
| 1054 | struct platform_device, |
| 1055 | dev); |
| 1056 | struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1057 | struct snd_soc_codec *codec; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1058 | struct snd_soc_platform *platform; |
| 1059 | struct snd_soc_dai *dai; |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1060 | int i, found, ret, ac97; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1061 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1062 | if (card->instantiated) |
| 1063 | return; |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1064 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1065 | found = 0; |
| 1066 | list_for_each_entry(platform, &platform_list, list) |
| 1067 | if (card->platform == platform) { |
| 1068 | found = 1; |
| 1069 | break; |
| 1070 | } |
| 1071 | if (!found) { |
| 1072 | dev_dbg(card->dev, "Platform %s not registered\n", |
| 1073 | card->platform->name); |
| 1074 | return; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1077 | ac97 = 0; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1078 | for (i = 0; i < card->num_links; i++) { |
| 1079 | found = 0; |
| 1080 | list_for_each_entry(dai, &dai_list, list) |
| 1081 | if (card->dai_link[i].cpu_dai == dai) { |
| 1082 | found = 1; |
| 1083 | break; |
| 1084 | } |
| 1085 | if (!found) { |
| 1086 | dev_dbg(card->dev, "DAI %s not registered\n", |
| 1087 | card->dai_link[i].cpu_dai->name); |
| 1088 | return; |
| 1089 | } |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1090 | |
| 1091 | if (card->dai_link[i].cpu_dai->ac97_control) |
| 1092 | ac97 = 1; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 1095 | for (i = 0; i < card->num_links; i++) { |
| 1096 | if (!card->dai_link[i].codec_dai->ops) |
| 1097 | card->dai_link[i].codec_dai->ops = &null_dai_ops; |
| 1098 | } |
| 1099 | |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1100 | /* If we have AC97 in the system then don't wait for the |
| 1101 | * codec. This will need revisiting if we have to handle |
| 1102 | * systems with mixed AC97 and non-AC97 parts. Only check for |
| 1103 | * DAIs currently; we can't do this per link since some AC97 |
| 1104 | * codecs have non-AC97 DAIs. |
| 1105 | */ |
| 1106 | if (!ac97) |
| 1107 | for (i = 0; i < card->num_links; i++) { |
| 1108 | found = 0; |
| 1109 | list_for_each_entry(dai, &dai_list, list) |
| 1110 | if (card->dai_link[i].codec_dai == dai) { |
| 1111 | found = 1; |
| 1112 | break; |
| 1113 | } |
| 1114 | if (!found) { |
| 1115 | dev_dbg(card->dev, "DAI %s not registered\n", |
| 1116 | card->dai_link[i].codec_dai->name); |
| 1117 | return; |
| 1118 | } |
| 1119 | } |
| 1120 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1121 | /* Note that we do not current check for codec components */ |
| 1122 | |
| 1123 | dev_dbg(card->dev, "All components present, instantiating\n"); |
| 1124 | |
| 1125 | /* Found everything, bring it up */ |
Mark Brown | 96dd362 | 2010-02-12 11:05:44 +0000 | [diff] [blame] | 1126 | card->pmdown_time = pmdown_time; |
| 1127 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1128 | if (card->probe) { |
| 1129 | ret = card->probe(pdev); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1130 | if (ret < 0) |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1131 | return; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1132 | } |
| 1133 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1134 | for (i = 0; i < card->num_links; i++) { |
| 1135 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1136 | if (cpu_dai->probe) { |
Mark Brown | bdb9287 | 2008-06-11 13:47:10 +0100 | [diff] [blame] | 1137 | ret = cpu_dai->probe(pdev, cpu_dai); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1138 | if (ret < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1139 | goto cpu_dai_err; |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | if (codec_dev->probe) { |
| 1144 | ret = codec_dev->probe(pdev); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1145 | if (ret < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1146 | goto cpu_dai_err; |
| 1147 | } |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1148 | codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1149 | |
| 1150 | if (platform->probe) { |
| 1151 | ret = platform->probe(pdev); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1152 | if (ret < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1153 | goto platform_err; |
| 1154 | } |
| 1155 | |
| 1156 | /* DAPM stream work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1157 | INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 1158 | #ifdef CONFIG_PM |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1159 | /* deferred resume work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1160 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 1161 | #endif |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1162 | |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1163 | for (i = 0; i < card->num_links; i++) { |
| 1164 | if (card->dai_link[i].init) { |
| 1165 | ret = card->dai_link[i].init(codec); |
| 1166 | if (ret < 0) { |
| 1167 | printk(KERN_ERR "asoc: failed to init %s\n", |
| 1168 | card->dai_link[i].stream_name); |
| 1169 | continue; |
| 1170 | } |
| 1171 | } |
Barry Song | f773205 | 2009-11-12 12:01:47 +0800 | [diff] [blame] | 1172 | if (card->dai_link[i].codec_dai->ac97_control) |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1173 | ac97 = 1; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | snprintf(codec->card->shortname, sizeof(codec->card->shortname), |
| 1177 | "%s", card->name); |
| 1178 | snprintf(codec->card->longname, sizeof(codec->card->longname), |
| 1179 | "%s (%s)", card->name, codec->name); |
| 1180 | |
| 1181 | /* Make sure all DAPM widgets are instantiated */ |
| 1182 | snd_soc_dapm_new_widgets(codec); |
| 1183 | |
| 1184 | ret = snd_card_register(codec->card); |
| 1185 | if (ret < 0) { |
| 1186 | printk(KERN_ERR "asoc: failed to register soundcard for %s\n", |
| 1187 | codec->name); |
| 1188 | goto card_err; |
| 1189 | } |
| 1190 | |
| 1191 | mutex_lock(&codec->mutex); |
| 1192 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 1193 | /* Only instantiate AC97 if not already done by the adaptor |
| 1194 | * for the generic AC97 subsystem. |
| 1195 | */ |
| 1196 | if (ac97 && strcmp(codec->name, "AC97") != 0) { |
| 1197 | ret = soc_ac97_dev_register(codec); |
| 1198 | if (ret < 0) { |
| 1199 | printk(KERN_ERR "asoc: AC97 device register failed\n"); |
| 1200 | snd_card_free(codec->card); |
| 1201 | mutex_unlock(&codec->mutex); |
| 1202 | goto card_err; |
| 1203 | } |
| 1204 | } |
| 1205 | #endif |
| 1206 | |
| 1207 | ret = snd_soc_dapm_sys_add(card->socdev->dev); |
| 1208 | if (ret < 0) |
| 1209 | printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n"); |
| 1210 | |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 1211 | ret = device_create_file(card->socdev->dev, &dev_attr_pmdown_time); |
| 1212 | if (ret < 0) |
| 1213 | printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); |
| 1214 | |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1215 | ret = device_create_file(card->socdev->dev, &dev_attr_codec_reg); |
| 1216 | if (ret < 0) |
| 1217 | printk(KERN_WARNING "asoc: failed to add codec sysfs files\n"); |
| 1218 | |
| 1219 | soc_init_codec_debugfs(codec); |
| 1220 | mutex_unlock(&codec->mutex); |
| 1221 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1222 | card->instantiated = 1; |
| 1223 | |
| 1224 | return; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1225 | |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1226 | card_err: |
| 1227 | if (platform->remove) |
| 1228 | platform->remove(pdev); |
| 1229 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1230 | platform_err: |
| 1231 | if (codec_dev->remove) |
| 1232 | codec_dev->remove(pdev); |
| 1233 | |
| 1234 | cpu_dai_err: |
Liam Girdwood | 18b9b3d | 2007-01-30 17:18:45 +0100 | [diff] [blame] | 1235 | for (i--; i >= 0; i--) { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1236 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1237 | if (cpu_dai->remove) |
Mark Brown | bdb9287 | 2008-06-11 13:47:10 +0100 | [diff] [blame] | 1238 | cpu_dai->remove(pdev, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1239 | } |
| 1240 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1241 | if (card->remove) |
| 1242 | card->remove(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1243 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1244 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1245 | /* |
| 1246 | * Attempt to initialise any uninitalised cards. Must be called with |
| 1247 | * client_mutex. |
| 1248 | */ |
| 1249 | static void snd_soc_instantiate_cards(void) |
| 1250 | { |
| 1251 | struct snd_soc_card *card; |
| 1252 | list_for_each_entry(card, &card_list, list) |
| 1253 | snd_soc_instantiate_card(card); |
| 1254 | } |
| 1255 | |
| 1256 | /* probes a new socdev */ |
| 1257 | static int soc_probe(struct platform_device *pdev) |
| 1258 | { |
| 1259 | int ret = 0; |
| 1260 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 1261 | struct snd_soc_card *card = socdev->card; |
| 1262 | |
| 1263 | /* Bodge while we push things out of socdev */ |
| 1264 | card->socdev = socdev; |
| 1265 | |
| 1266 | /* Bodge while we unpick instantiation */ |
| 1267 | card->dev = &pdev->dev; |
| 1268 | ret = snd_soc_register_card(card); |
| 1269 | if (ret != 0) { |
| 1270 | dev_err(&pdev->dev, "Failed to register card\n"); |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
| 1274 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | /* removes a socdev */ |
| 1278 | static int soc_remove(struct platform_device *pdev) |
| 1279 | { |
| 1280 | int i; |
| 1281 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1282 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1283 | struct snd_soc_platform *platform = card->platform; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1284 | struct snd_soc_codec_device *codec_dev = socdev->codec_dev; |
| 1285 | |
Guennadi Liakhovetski | b2dfa62 | 2010-03-18 08:23:33 +0100 | [diff] [blame^] | 1286 | if (card->instantiated) { |
| 1287 | run_delayed_work(&card->delayed_work); |
Mike Rapoport | 914dc18 | 2009-05-11 13:04:55 +0300 | [diff] [blame] | 1288 | |
Guennadi Liakhovetski | b2dfa62 | 2010-03-18 08:23:33 +0100 | [diff] [blame^] | 1289 | if (platform->remove) |
| 1290 | platform->remove(pdev); |
Liam Girdwood | 965ac42 | 2007-01-31 14:14:57 +0100 | [diff] [blame] | 1291 | |
Guennadi Liakhovetski | b2dfa62 | 2010-03-18 08:23:33 +0100 | [diff] [blame^] | 1292 | if (codec_dev->remove) |
| 1293 | codec_dev->remove(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1294 | |
Guennadi Liakhovetski | b2dfa62 | 2010-03-18 08:23:33 +0100 | [diff] [blame^] | 1295 | for (i = 0; i < card->num_links; i++) { |
| 1296 | struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; |
| 1297 | if (cpu_dai->remove) |
| 1298 | cpu_dai->remove(pdev, cpu_dai); |
| 1299 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1300 | |
Guennadi Liakhovetski | b2dfa62 | 2010-03-18 08:23:33 +0100 | [diff] [blame^] | 1301 | if (card->remove) |
| 1302 | card->remove(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1303 | } |
| 1304 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1305 | snd_soc_unregister_card(card); |
| 1306 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1307 | return 0; |
| 1308 | } |
| 1309 | |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1310 | static int soc_poweroff(struct device *dev) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1311 | { |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1312 | struct platform_device *pdev = to_platform_device(dev); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1313 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 1314 | struct snd_soc_card *card = socdev->card; |
| 1315 | |
| 1316 | if (!card->instantiated) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1317 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1318 | |
| 1319 | /* Flush out pmdown_time work - we actually do want to run it |
| 1320 | * now, we're shutting down so no imminent restart. */ |
| 1321 | run_delayed_work(&card->delayed_work); |
| 1322 | |
| 1323 | snd_soc_dapm_shutdown(socdev); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1324 | |
| 1325 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1326 | } |
| 1327 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1328 | static const struct dev_pm_ops soc_pm_ops = { |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1329 | .suspend = soc_suspend, |
| 1330 | .resume = soc_resume, |
| 1331 | .poweroff = soc_poweroff, |
| 1332 | }; |
| 1333 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1334 | /* ASoC platform driver */ |
| 1335 | static struct platform_driver soc_driver = { |
| 1336 | .driver = { |
| 1337 | .name = "soc-audio", |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 1338 | .owner = THIS_MODULE, |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1339 | .pm = &soc_pm_ops, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1340 | }, |
| 1341 | .probe = soc_probe, |
| 1342 | .remove = soc_remove, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1343 | }; |
| 1344 | |
| 1345 | /* create a new pcm */ |
| 1346 | static int soc_new_pcm(struct snd_soc_device *socdev, |
| 1347 | struct snd_soc_dai_link *dai_link, int num) |
| 1348 | { |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1349 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1350 | struct snd_soc_codec *codec = card->codec; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1351 | struct snd_soc_platform *platform = card->platform; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 1352 | struct snd_soc_dai *codec_dai = dai_link->codec_dai; |
| 1353 | struct snd_soc_dai *cpu_dai = dai_link->cpu_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1354 | struct snd_soc_pcm_runtime *rtd; |
| 1355 | struct snd_pcm *pcm; |
| 1356 | char new_name[64]; |
| 1357 | int ret = 0, playback = 0, capture = 0; |
| 1358 | |
| 1359 | rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL); |
| 1360 | if (rtd == NULL) |
| 1361 | return -ENOMEM; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 1362 | |
| 1363 | rtd->dai = dai_link; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1364 | rtd->socdev = socdev; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1365 | codec_dai->codec = card->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1366 | |
| 1367 | /* check client and interface hw capabilities */ |
Mark Brown | 40ca114 | 2009-12-24 13:44:28 +0000 | [diff] [blame] | 1368 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
| 1369 | dai_link->stream_name, codec_dai->name, num); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1370 | |
| 1371 | if (codec_dai->playback.channels_min) |
| 1372 | playback = 1; |
| 1373 | if (codec_dai->capture.channels_min) |
| 1374 | capture = 1; |
| 1375 | |
| 1376 | ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback, |
| 1377 | capture, &pcm); |
| 1378 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1379 | printk(KERN_ERR "asoc: can't create pcm for codec %s\n", |
| 1380 | codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1381 | kfree(rtd); |
| 1382 | return ret; |
| 1383 | } |
| 1384 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 1385 | dai_link->pcm = pcm; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1386 | pcm->private_data = rtd; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1387 | soc_pcm_ops.mmap = platform->pcm_ops->mmap; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1388 | soc_pcm_ops.ioctl = platform->pcm_ops->ioctl; |
| 1389 | soc_pcm_ops.copy = platform->pcm_ops->copy; |
| 1390 | soc_pcm_ops.silence = platform->pcm_ops->silence; |
| 1391 | soc_pcm_ops.ack = platform->pcm_ops->ack; |
| 1392 | soc_pcm_ops.page = platform->pcm_ops->page; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1393 | |
| 1394 | if (playback) |
| 1395 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops); |
| 1396 | |
| 1397 | if (capture) |
| 1398 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops); |
| 1399 | |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1400 | ret = platform->pcm_new(codec->card, codec_dai, pcm); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1401 | if (ret < 0) { |
| 1402 | printk(KERN_ERR "asoc: platform pcm constructor failed\n"); |
| 1403 | kfree(rtd); |
| 1404 | return ret; |
| 1405 | } |
| 1406 | |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 1407 | pcm->private_free = platform->pcm_free; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1408 | printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name, |
| 1409 | cpu_dai->name); |
| 1410 | return ret; |
| 1411 | } |
| 1412 | |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1413 | /** |
| 1414 | * snd_soc_codec_volatile_register: Report if a register is volatile. |
| 1415 | * |
| 1416 | * @codec: CODEC to query. |
| 1417 | * @reg: Register to query. |
| 1418 | * |
| 1419 | * Boolean function indiciating if a CODEC register is volatile. |
| 1420 | */ |
| 1421 | int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg) |
| 1422 | { |
| 1423 | if (codec->volatile_register) |
| 1424 | return codec->volatile_register(reg); |
| 1425 | else |
| 1426 | return 0; |
| 1427 | } |
| 1428 | EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); |
| 1429 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1430 | /** |
| 1431 | * snd_soc_new_ac97_codec - initailise AC97 device |
| 1432 | * @codec: audio codec |
| 1433 | * @ops: AC97 bus operations |
| 1434 | * @num: AC97 codec number |
| 1435 | * |
| 1436 | * Initialises AC97 codec resources for use by ad-hoc devices only. |
| 1437 | */ |
| 1438 | int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, |
| 1439 | struct snd_ac97_bus_ops *ops, int num) |
| 1440 | { |
| 1441 | mutex_lock(&codec->mutex); |
| 1442 | |
| 1443 | codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); |
| 1444 | if (codec->ac97 == NULL) { |
| 1445 | mutex_unlock(&codec->mutex); |
| 1446 | return -ENOMEM; |
| 1447 | } |
| 1448 | |
| 1449 | codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); |
| 1450 | if (codec->ac97->bus == NULL) { |
| 1451 | kfree(codec->ac97); |
| 1452 | codec->ac97 = NULL; |
| 1453 | mutex_unlock(&codec->mutex); |
| 1454 | return -ENOMEM; |
| 1455 | } |
| 1456 | |
| 1457 | codec->ac97->bus->ops = ops; |
| 1458 | codec->ac97->num = num; |
Mark Brown | 2718625 | 2010-01-28 12:36:29 +0000 | [diff] [blame] | 1459 | codec->dev = &codec->ac97->dev; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1460 | mutex_unlock(&codec->mutex); |
| 1461 | return 0; |
| 1462 | } |
| 1463 | EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); |
| 1464 | |
| 1465 | /** |
| 1466 | * snd_soc_free_ac97_codec - free AC97 codec device |
| 1467 | * @codec: audio codec |
| 1468 | * |
| 1469 | * Frees AC97 codec device resources. |
| 1470 | */ |
| 1471 | void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) |
| 1472 | { |
| 1473 | mutex_lock(&codec->mutex); |
| 1474 | kfree(codec->ac97->bus); |
| 1475 | kfree(codec->ac97); |
| 1476 | codec->ac97 = NULL; |
| 1477 | mutex_unlock(&codec->mutex); |
| 1478 | } |
| 1479 | EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); |
| 1480 | |
| 1481 | /** |
| 1482 | * snd_soc_update_bits - update codec register bits |
| 1483 | * @codec: audio codec |
| 1484 | * @reg: codec register |
| 1485 | * @mask: register mask |
| 1486 | * @value: new value |
| 1487 | * |
| 1488 | * Writes new register value. |
| 1489 | * |
| 1490 | * Returns 1 for change else 0. |
| 1491 | */ |
| 1492 | 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] | 1493 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1494 | { |
| 1495 | int change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1496 | unsigned int old, new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1497 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1498 | old = snd_soc_read(codec, reg); |
| 1499 | new = (old & ~mask) | value; |
| 1500 | change = old != new; |
| 1501 | if (change) |
| 1502 | snd_soc_write(codec, reg, new); |
| 1503 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1504 | return change; |
| 1505 | } |
| 1506 | EXPORT_SYMBOL_GPL(snd_soc_update_bits); |
| 1507 | |
| 1508 | /** |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 1509 | * snd_soc_update_bits_locked - update codec register bits |
| 1510 | * @codec: audio codec |
| 1511 | * @reg: codec register |
| 1512 | * @mask: register mask |
| 1513 | * @value: new value |
| 1514 | * |
| 1515 | * Writes new register value, and takes the codec mutex. |
| 1516 | * |
| 1517 | * Returns 1 for change else 0. |
| 1518 | */ |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 1519 | int snd_soc_update_bits_locked(struct snd_soc_codec *codec, |
| 1520 | unsigned short reg, unsigned int mask, |
| 1521 | unsigned int value) |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 1522 | { |
| 1523 | int change; |
| 1524 | |
| 1525 | mutex_lock(&codec->mutex); |
| 1526 | change = snd_soc_update_bits(codec, reg, mask, value); |
| 1527 | mutex_unlock(&codec->mutex); |
| 1528 | |
| 1529 | return change; |
| 1530 | } |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 1531 | EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 1532 | |
| 1533 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1534 | * snd_soc_test_bits - test register for change |
| 1535 | * @codec: audio codec |
| 1536 | * @reg: codec register |
| 1537 | * @mask: register mask |
| 1538 | * @value: new value |
| 1539 | * |
| 1540 | * Tests a register with a new value and checks if the new value is |
| 1541 | * different from the old value. |
| 1542 | * |
| 1543 | * Returns 1 for change else 0. |
| 1544 | */ |
| 1545 | 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] | 1546 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1547 | { |
| 1548 | int change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1549 | unsigned int old, new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1550 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1551 | old = snd_soc_read(codec, reg); |
| 1552 | new = (old & ~mask) | value; |
| 1553 | change = old != new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1554 | |
| 1555 | return change; |
| 1556 | } |
| 1557 | EXPORT_SYMBOL_GPL(snd_soc_test_bits); |
| 1558 | |
| 1559 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1560 | * snd_soc_new_pcms - create new sound card and pcms |
| 1561 | * @socdev: the SoC audio device |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1562 | * @idx: ALSA card index |
| 1563 | * @xid: card identification |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1564 | * |
| 1565 | * Create a new sound card based upon the codec and interface pcms. |
| 1566 | * |
| 1567 | * Returns 0 for success, else error. |
| 1568 | */ |
Liam Girdwood | bc7320c | 2007-02-01 12:26:07 +0100 | [diff] [blame] | 1569 | int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1570 | { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1571 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1572 | struct snd_soc_codec *codec = card->codec; |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 1573 | int ret, i; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1574 | |
| 1575 | mutex_lock(&codec->mutex); |
| 1576 | |
| 1577 | /* register a sound card */ |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 1578 | ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card); |
| 1579 | if (ret < 0) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1580 | printk(KERN_ERR "asoc: can't create sound card for codec %s\n", |
| 1581 | codec->name); |
| 1582 | mutex_unlock(&codec->mutex); |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 1583 | return ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1584 | } |
| 1585 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1586 | codec->socdev = socdev; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1587 | codec->card->dev = socdev->dev; |
| 1588 | codec->card->private_data = codec; |
| 1589 | strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver)); |
| 1590 | |
| 1591 | /* create the pcms */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1592 | for (i = 0; i < card->num_links; i++) { |
| 1593 | ret = soc_new_pcm(socdev, &card->dai_link[i], i); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1594 | if (ret < 0) { |
| 1595 | printk(KERN_ERR "asoc: can't create pcm %s\n", |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1596 | card->dai_link[i].stream_name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1597 | mutex_unlock(&codec->mutex); |
| 1598 | return ret; |
| 1599 | } |
Barry Song | f773205 | 2009-11-12 12:01:47 +0800 | [diff] [blame] | 1600 | if (card->dai_link[i].codec_dai->ac97_control) { |
| 1601 | snd_ac97_dev_add_pdata(codec->ac97, |
| 1602 | card->dai_link[i].cpu_dai->ac97_pdata); |
| 1603 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | mutex_unlock(&codec->mutex); |
| 1607 | return ret; |
| 1608 | } |
| 1609 | EXPORT_SYMBOL_GPL(snd_soc_new_pcms); |
| 1610 | |
| 1611 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1612 | * snd_soc_free_pcms - free sound card and pcms |
| 1613 | * @socdev: the SoC audio device |
| 1614 | * |
| 1615 | * Frees sound card and pcms associated with the socdev. |
| 1616 | * Also unregister the codec if it is an AC97 device. |
| 1617 | */ |
| 1618 | void snd_soc_free_pcms(struct snd_soc_device *socdev) |
| 1619 | { |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1620 | struct snd_soc_codec *codec = socdev->card->codec; |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1621 | #ifdef CONFIG_SND_SOC_AC97_BUS |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 1622 | struct snd_soc_dai *codec_dai; |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1623 | int i; |
| 1624 | #endif |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1625 | |
| 1626 | mutex_lock(&codec->mutex); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1627 | soc_cleanup_codec_debugfs(codec); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1628 | #ifdef CONFIG_SND_SOC_AC97_BUS |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1629 | for (i = 0; i < codec->num_dai; i++) { |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1630 | codec_dai = &codec->dai[i]; |
Atsushi Nemoto | d2314e0 | 2009-03-16 23:26:20 +0900 | [diff] [blame] | 1631 | if (codec_dai->ac97_control && codec->ac97 && |
| 1632 | strcmp(codec->name, "AC97") != 0) { |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 1633 | soc_ac97_dev_unregister(codec); |
| 1634 | goto free_card; |
| 1635 | } |
| 1636 | } |
| 1637 | free_card: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1638 | #endif |
| 1639 | |
| 1640 | if (codec->card) |
| 1641 | snd_card_free(codec->card); |
| 1642 | device_remove_file(socdev->dev, &dev_attr_codec_reg); |
| 1643 | mutex_unlock(&codec->mutex); |
| 1644 | } |
| 1645 | EXPORT_SYMBOL_GPL(snd_soc_free_pcms); |
| 1646 | |
| 1647 | /** |
| 1648 | * snd_soc_set_runtime_hwparams - set the runtime hardware parameters |
| 1649 | * @substream: the pcm substream |
| 1650 | * @hw: the hardware parameters |
| 1651 | * |
| 1652 | * Sets the substream runtime hardware parameters. |
| 1653 | */ |
| 1654 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, |
| 1655 | const struct snd_pcm_hardware *hw) |
| 1656 | { |
| 1657 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1658 | runtime->hw.info = hw->info; |
| 1659 | runtime->hw.formats = hw->formats; |
| 1660 | runtime->hw.period_bytes_min = hw->period_bytes_min; |
| 1661 | runtime->hw.period_bytes_max = hw->period_bytes_max; |
| 1662 | runtime->hw.periods_min = hw->periods_min; |
| 1663 | runtime->hw.periods_max = hw->periods_max; |
| 1664 | runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; |
| 1665 | runtime->hw.fifo_size = hw->fifo_size; |
| 1666 | return 0; |
| 1667 | } |
| 1668 | EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); |
| 1669 | |
| 1670 | /** |
| 1671 | * snd_soc_cnew - create new control |
| 1672 | * @_template: control template |
| 1673 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1674 | * @long_name: control long name |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1675 | * |
| 1676 | * Create a new mixer control from a template control. |
| 1677 | * |
| 1678 | * Returns 0 for success, else error. |
| 1679 | */ |
| 1680 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
| 1681 | void *data, char *long_name) |
| 1682 | { |
| 1683 | struct snd_kcontrol_new template; |
| 1684 | |
| 1685 | memcpy(&template, _template, sizeof(template)); |
| 1686 | if (long_name) |
| 1687 | template.name = long_name; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1688 | template.index = 0; |
| 1689 | |
| 1690 | return snd_ctl_new1(&template, data); |
| 1691 | } |
| 1692 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 1693 | |
| 1694 | /** |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1695 | * snd_soc_add_controls - add an array of controls to a codec. |
| 1696 | * Convienience function to add a list of controls. Many codecs were |
| 1697 | * duplicating this code. |
| 1698 | * |
| 1699 | * @codec: codec to add controls to |
| 1700 | * @controls: array of controls to add |
| 1701 | * @num_controls: number of elements in the array |
| 1702 | * |
| 1703 | * Return 0 for success, else error. |
| 1704 | */ |
| 1705 | int snd_soc_add_controls(struct snd_soc_codec *codec, |
| 1706 | const struct snd_kcontrol_new *controls, int num_controls) |
| 1707 | { |
| 1708 | struct snd_card *card = codec->card; |
| 1709 | int err, i; |
| 1710 | |
| 1711 | for (i = 0; i < num_controls; i++) { |
| 1712 | const struct snd_kcontrol_new *control = &controls[i]; |
| 1713 | err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL)); |
| 1714 | if (err < 0) { |
| 1715 | dev_err(codec->dev, "%s: Failed to add %s\n", |
| 1716 | codec->name, control->name); |
| 1717 | return err; |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | return 0; |
| 1722 | } |
| 1723 | EXPORT_SYMBOL_GPL(snd_soc_add_controls); |
| 1724 | |
| 1725 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1726 | * snd_soc_info_enum_double - enumerated double mixer info callback |
| 1727 | * @kcontrol: mixer control |
| 1728 | * @uinfo: control element information |
| 1729 | * |
| 1730 | * Callback to provide information about a double enumerated |
| 1731 | * mixer control. |
| 1732 | * |
| 1733 | * Returns 0 for success. |
| 1734 | */ |
| 1735 | int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, |
| 1736 | struct snd_ctl_elem_info *uinfo) |
| 1737 | { |
| 1738 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1739 | |
| 1740 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1741 | uinfo->count = e->shift_l == e->shift_r ? 1 : 2; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1742 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1743 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1744 | if (uinfo->value.enumerated.item > e->max - 1) |
| 1745 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1746 | strcpy(uinfo->value.enumerated.name, |
| 1747 | e->texts[uinfo->value.enumerated.item]); |
| 1748 | return 0; |
| 1749 | } |
| 1750 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); |
| 1751 | |
| 1752 | /** |
| 1753 | * snd_soc_get_enum_double - enumerated double mixer get callback |
| 1754 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1755 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1756 | * |
| 1757 | * Callback to get the value of a double enumerated mixer. |
| 1758 | * |
| 1759 | * Returns 0 for success. |
| 1760 | */ |
| 1761 | int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, |
| 1762 | struct snd_ctl_elem_value *ucontrol) |
| 1763 | { |
| 1764 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1765 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1766 | unsigned int val, bitmask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1767 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1768 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1769 | ; |
| 1770 | val = snd_soc_read(codec, e->reg); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1771 | ucontrol->value.enumerated.item[0] |
| 1772 | = (val >> e->shift_l) & (bitmask - 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1773 | if (e->shift_l != e->shift_r) |
| 1774 | ucontrol->value.enumerated.item[1] = |
| 1775 | (val >> e->shift_r) & (bitmask - 1); |
| 1776 | |
| 1777 | return 0; |
| 1778 | } |
| 1779 | EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); |
| 1780 | |
| 1781 | /** |
| 1782 | * snd_soc_put_enum_double - enumerated double mixer put callback |
| 1783 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1784 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1785 | * |
| 1786 | * Callback to set the value of a double enumerated mixer. |
| 1787 | * |
| 1788 | * Returns 0 for success. |
| 1789 | */ |
| 1790 | int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, |
| 1791 | struct snd_ctl_elem_value *ucontrol) |
| 1792 | { |
| 1793 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1794 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1795 | unsigned int val; |
| 1796 | unsigned int mask, bitmask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1797 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1798 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1799 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1800 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1801 | return -EINVAL; |
| 1802 | val = ucontrol->value.enumerated.item[0] << e->shift_l; |
| 1803 | mask = (bitmask - 1) << e->shift_l; |
| 1804 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1805 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1806 | return -EINVAL; |
| 1807 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 1808 | mask |= (bitmask - 1) << e->shift_r; |
| 1809 | } |
| 1810 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 1811 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1812 | } |
| 1813 | EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); |
| 1814 | |
| 1815 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1816 | * snd_soc_get_value_enum_double - semi enumerated double mixer get callback |
| 1817 | * @kcontrol: mixer control |
| 1818 | * @ucontrol: control element information |
| 1819 | * |
| 1820 | * Callback to get the value of a double semi enumerated mixer. |
| 1821 | * |
| 1822 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1823 | * used for handling bitfield coded enumeration for example. |
| 1824 | * |
| 1825 | * Returns 0 for success. |
| 1826 | */ |
| 1827 | int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1828 | struct snd_ctl_elem_value *ucontrol) |
| 1829 | { |
| 1830 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1831 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1832 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1833 | |
| 1834 | reg_val = snd_soc_read(codec, e->reg); |
| 1835 | val = (reg_val >> e->shift_l) & e->mask; |
| 1836 | for (mux = 0; mux < e->max; mux++) { |
| 1837 | if (val == e->values[mux]) |
| 1838 | break; |
| 1839 | } |
| 1840 | ucontrol->value.enumerated.item[0] = mux; |
| 1841 | if (e->shift_l != e->shift_r) { |
| 1842 | val = (reg_val >> e->shift_r) & e->mask; |
| 1843 | for (mux = 0; mux < e->max; mux++) { |
| 1844 | if (val == e->values[mux]) |
| 1845 | break; |
| 1846 | } |
| 1847 | ucontrol->value.enumerated.item[1] = mux; |
| 1848 | } |
| 1849 | |
| 1850 | return 0; |
| 1851 | } |
| 1852 | EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); |
| 1853 | |
| 1854 | /** |
| 1855 | * snd_soc_put_value_enum_double - semi enumerated double mixer put callback |
| 1856 | * @kcontrol: mixer control |
| 1857 | * @ucontrol: control element information |
| 1858 | * |
| 1859 | * Callback to set the value of a double semi enumerated mixer. |
| 1860 | * |
| 1861 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1862 | * used for handling bitfield coded enumeration for example. |
| 1863 | * |
| 1864 | * Returns 0 for success. |
| 1865 | */ |
| 1866 | int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1867 | struct snd_ctl_elem_value *ucontrol) |
| 1868 | { |
| 1869 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1870 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1871 | unsigned int val; |
| 1872 | unsigned int mask; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1873 | |
| 1874 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1875 | return -EINVAL; |
| 1876 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 1877 | mask = e->mask << e->shift_l; |
| 1878 | if (e->shift_l != e->shift_r) { |
| 1879 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 1880 | return -EINVAL; |
| 1881 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 1882 | mask |= e->mask << e->shift_r; |
| 1883 | } |
| 1884 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 1885 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1886 | } |
| 1887 | EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); |
| 1888 | |
| 1889 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1890 | * snd_soc_info_enum_ext - external enumerated single mixer info callback |
| 1891 | * @kcontrol: mixer control |
| 1892 | * @uinfo: control element information |
| 1893 | * |
| 1894 | * Callback to provide information about an external enumerated |
| 1895 | * single mixer. |
| 1896 | * |
| 1897 | * Returns 0 for success. |
| 1898 | */ |
| 1899 | int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, |
| 1900 | struct snd_ctl_elem_info *uinfo) |
| 1901 | { |
| 1902 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1903 | |
| 1904 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1905 | uinfo->count = 1; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1906 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1907 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1908 | if (uinfo->value.enumerated.item > e->max - 1) |
| 1909 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1910 | strcpy(uinfo->value.enumerated.name, |
| 1911 | e->texts[uinfo->value.enumerated.item]); |
| 1912 | return 0; |
| 1913 | } |
| 1914 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); |
| 1915 | |
| 1916 | /** |
| 1917 | * snd_soc_info_volsw_ext - external single mixer info callback |
| 1918 | * @kcontrol: mixer control |
| 1919 | * @uinfo: control element information |
| 1920 | * |
| 1921 | * Callback to provide information about a single external mixer control. |
| 1922 | * |
| 1923 | * Returns 0 for success. |
| 1924 | */ |
| 1925 | int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, |
| 1926 | struct snd_ctl_elem_info *uinfo) |
| 1927 | { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1928 | int max = kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1929 | |
Mark Brown | fd5dfad | 2009-04-15 21:37:46 +0100 | [diff] [blame] | 1930 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1931 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1932 | else |
| 1933 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1934 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1935 | uinfo->count = 1; |
| 1936 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1937 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1938 | return 0; |
| 1939 | } |
| 1940 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); |
| 1941 | |
| 1942 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1943 | * snd_soc_info_volsw - single mixer info callback |
| 1944 | * @kcontrol: mixer control |
| 1945 | * @uinfo: control element information |
| 1946 | * |
| 1947 | * Callback to provide information about a single mixer control. |
| 1948 | * |
| 1949 | * Returns 0 for success. |
| 1950 | */ |
| 1951 | int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, |
| 1952 | struct snd_ctl_elem_info *uinfo) |
| 1953 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1954 | struct soc_mixer_control *mc = |
| 1955 | (struct soc_mixer_control *)kcontrol->private_value; |
| 1956 | int max = mc->max; |
Mark Brown | 762b8df | 2008-10-30 12:37:08 +0000 | [diff] [blame] | 1957 | unsigned int shift = mc->shift; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1958 | unsigned int rshift = mc->rshift; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1959 | |
Mark Brown | fd5dfad | 2009-04-15 21:37:46 +0100 | [diff] [blame] | 1960 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1961 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1962 | else |
| 1963 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1964 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1965 | uinfo->count = shift == rshift ? 1 : 2; |
| 1966 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1967 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1968 | return 0; |
| 1969 | } |
| 1970 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw); |
| 1971 | |
| 1972 | /** |
| 1973 | * snd_soc_get_volsw - single mixer get callback |
| 1974 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1975 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1976 | * |
| 1977 | * Callback to get the value of a single mixer control. |
| 1978 | * |
| 1979 | * Returns 0 for success. |
| 1980 | */ |
| 1981 | int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, |
| 1982 | struct snd_ctl_elem_value *ucontrol) |
| 1983 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1984 | struct soc_mixer_control *mc = |
| 1985 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1986 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1987 | unsigned int reg = mc->reg; |
| 1988 | unsigned int shift = mc->shift; |
| 1989 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1990 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1991 | unsigned int mask = (1 << fls(max)) - 1; |
| 1992 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1993 | |
| 1994 | ucontrol->value.integer.value[0] = |
| 1995 | (snd_soc_read(codec, reg) >> shift) & mask; |
| 1996 | if (shift != rshift) |
| 1997 | ucontrol->value.integer.value[1] = |
| 1998 | (snd_soc_read(codec, reg) >> rshift) & mask; |
| 1999 | if (invert) { |
| 2000 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2001 | max - ucontrol->value.integer.value[0]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2002 | if (shift != rshift) |
| 2003 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2004 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | return 0; |
| 2008 | } |
| 2009 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw); |
| 2010 | |
| 2011 | /** |
| 2012 | * snd_soc_put_volsw - single mixer put callback |
| 2013 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2014 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2015 | * |
| 2016 | * Callback to set the value of a single mixer control. |
| 2017 | * |
| 2018 | * Returns 0 for success. |
| 2019 | */ |
| 2020 | int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, |
| 2021 | struct snd_ctl_elem_value *ucontrol) |
| 2022 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2023 | struct soc_mixer_control *mc = |
| 2024 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2025 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2026 | unsigned int reg = mc->reg; |
| 2027 | unsigned int shift = mc->shift; |
| 2028 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2029 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2030 | unsigned int mask = (1 << fls(max)) - 1; |
| 2031 | unsigned int invert = mc->invert; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2032 | unsigned int val, val2, val_mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2033 | |
| 2034 | val = (ucontrol->value.integer.value[0] & mask); |
| 2035 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2036 | val = max - val; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2037 | val_mask = mask << shift; |
| 2038 | val = val << shift; |
| 2039 | if (shift != rshift) { |
| 2040 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 2041 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2042 | val2 = max - val2; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2043 | val_mask |= mask << rshift; |
| 2044 | val |= val2 << rshift; |
| 2045 | } |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2046 | return snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2047 | } |
| 2048 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); |
| 2049 | |
| 2050 | /** |
| 2051 | * snd_soc_info_volsw_2r - double mixer info callback |
| 2052 | * @kcontrol: mixer control |
| 2053 | * @uinfo: control element information |
| 2054 | * |
| 2055 | * Callback to provide information about a double mixer control that |
| 2056 | * spans 2 codec registers. |
| 2057 | * |
| 2058 | * Returns 0 for success. |
| 2059 | */ |
| 2060 | int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol, |
| 2061 | struct snd_ctl_elem_info *uinfo) |
| 2062 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2063 | struct soc_mixer_control *mc = |
| 2064 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2065 | int max = mc->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2066 | |
Mark Brown | fd5dfad | 2009-04-15 21:37:46 +0100 | [diff] [blame] | 2067 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2068 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2069 | else |
| 2070 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2071 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2072 | uinfo->count = 2; |
| 2073 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2074 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2075 | return 0; |
| 2076 | } |
| 2077 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r); |
| 2078 | |
| 2079 | /** |
| 2080 | * snd_soc_get_volsw_2r - double mixer get callback |
| 2081 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2082 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2083 | * |
| 2084 | * Callback to get the value of a double mixer control that spans 2 registers. |
| 2085 | * |
| 2086 | * Returns 0 for success. |
| 2087 | */ |
| 2088 | int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol, |
| 2089 | struct snd_ctl_elem_value *ucontrol) |
| 2090 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2091 | struct soc_mixer_control *mc = |
| 2092 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2093 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2094 | unsigned int reg = mc->reg; |
| 2095 | unsigned int reg2 = mc->rreg; |
| 2096 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2097 | int max = mc->max; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2098 | unsigned int mask = (1 << fls(max)) - 1; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2099 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2100 | |
| 2101 | ucontrol->value.integer.value[0] = |
| 2102 | (snd_soc_read(codec, reg) >> shift) & mask; |
| 2103 | ucontrol->value.integer.value[1] = |
| 2104 | (snd_soc_read(codec, reg2) >> shift) & mask; |
| 2105 | if (invert) { |
| 2106 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2107 | max - ucontrol->value.integer.value[0]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2108 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2109 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | return 0; |
| 2113 | } |
| 2114 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r); |
| 2115 | |
| 2116 | /** |
| 2117 | * snd_soc_put_volsw_2r - double mixer set callback |
| 2118 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2119 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2120 | * |
| 2121 | * Callback to set the value of a double mixer control that spans 2 registers. |
| 2122 | * |
| 2123 | * Returns 0 for success. |
| 2124 | */ |
| 2125 | int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol, |
| 2126 | struct snd_ctl_elem_value *ucontrol) |
| 2127 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2128 | struct soc_mixer_control *mc = |
| 2129 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2130 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2131 | unsigned int reg = mc->reg; |
| 2132 | unsigned int reg2 = mc->rreg; |
| 2133 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2134 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2135 | unsigned int mask = (1 << fls(max)) - 1; |
| 2136 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2137 | int err; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2138 | unsigned int val, val2, val_mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2139 | |
| 2140 | val_mask = mask << shift; |
| 2141 | val = (ucontrol->value.integer.value[0] & mask); |
| 2142 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 2143 | |
| 2144 | if (invert) { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2145 | val = max - val; |
| 2146 | val2 = max - val2; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | val = val << shift; |
| 2150 | val2 = val2 << shift; |
| 2151 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2152 | err = snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2153 | if (err < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2154 | return err; |
| 2155 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2156 | err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2157 | return err; |
| 2158 | } |
| 2159 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r); |
| 2160 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2161 | /** |
| 2162 | * snd_soc_info_volsw_s8 - signed mixer info callback |
| 2163 | * @kcontrol: mixer control |
| 2164 | * @uinfo: control element information |
| 2165 | * |
| 2166 | * Callback to provide information about a signed mixer control. |
| 2167 | * |
| 2168 | * Returns 0 for success. |
| 2169 | */ |
| 2170 | int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2171 | struct snd_ctl_elem_info *uinfo) |
| 2172 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2173 | struct soc_mixer_control *mc = |
| 2174 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2175 | int max = mc->max; |
| 2176 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2177 | |
| 2178 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2179 | uinfo->count = 2; |
| 2180 | uinfo->value.integer.min = 0; |
| 2181 | uinfo->value.integer.max = max-min; |
| 2182 | return 0; |
| 2183 | } |
| 2184 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); |
| 2185 | |
| 2186 | /** |
| 2187 | * snd_soc_get_volsw_s8 - signed mixer get callback |
| 2188 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2189 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2190 | * |
| 2191 | * Callback to get the value of a signed mixer control. |
| 2192 | * |
| 2193 | * Returns 0 for success. |
| 2194 | */ |
| 2195 | int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2196 | struct snd_ctl_elem_value *ucontrol) |
| 2197 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2198 | struct soc_mixer_control *mc = |
| 2199 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2200 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2201 | unsigned int reg = mc->reg; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2202 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2203 | int val = snd_soc_read(codec, reg); |
| 2204 | |
| 2205 | ucontrol->value.integer.value[0] = |
| 2206 | ((signed char)(val & 0xff))-min; |
| 2207 | ucontrol->value.integer.value[1] = |
| 2208 | ((signed char)((val >> 8) & 0xff))-min; |
| 2209 | return 0; |
| 2210 | } |
| 2211 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); |
| 2212 | |
| 2213 | /** |
| 2214 | * snd_soc_put_volsw_sgn - signed mixer put callback |
| 2215 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2216 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2217 | * |
| 2218 | * Callback to set the value of a signed mixer control. |
| 2219 | * |
| 2220 | * Returns 0 for success. |
| 2221 | */ |
| 2222 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, |
| 2223 | struct snd_ctl_elem_value *ucontrol) |
| 2224 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2225 | struct soc_mixer_control *mc = |
| 2226 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2227 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2228 | unsigned int reg = mc->reg; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2229 | int min = mc->min; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2230 | unsigned int val; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2231 | |
| 2232 | val = (ucontrol->value.integer.value[0]+min) & 0xff; |
| 2233 | val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8; |
| 2234 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2235 | return snd_soc_update_bits_locked(codec, reg, 0xffff, val); |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 2236 | } |
| 2237 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); |
| 2238 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2239 | /** |
| 2240 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
| 2241 | * @dai: DAI |
| 2242 | * @clk_id: DAI specific clock ID |
| 2243 | * @freq: new clock frequency in Hz |
| 2244 | * @dir: new clock direction - input/output. |
| 2245 | * |
| 2246 | * Configures the DAI master (MCLK) or system (SYSCLK) clocking. |
| 2247 | */ |
| 2248 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 2249 | unsigned int freq, int dir) |
| 2250 | { |
Mark Brown | 3f1a4d8 | 2009-04-15 21:35:26 +0100 | [diff] [blame] | 2251 | if (dai->ops && dai->ops->set_sysclk) |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2252 | return dai->ops->set_sysclk(dai, clk_id, freq, dir); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2253 | else |
| 2254 | return -EINVAL; |
| 2255 | } |
| 2256 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); |
| 2257 | |
| 2258 | /** |
| 2259 | * snd_soc_dai_set_clkdiv - configure DAI clock dividers. |
| 2260 | * @dai: DAI |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2261 | * @div_id: DAI specific clock divider ID |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2262 | * @div: new clock divisor. |
| 2263 | * |
| 2264 | * Configures the clock dividers. This is used to derive the best DAI bit and |
| 2265 | * frame clocks from the system or master clock. It's best to set the DAI bit |
| 2266 | * and frame clocks as low as possible to save system power. |
| 2267 | */ |
| 2268 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 2269 | int div_id, int div) |
| 2270 | { |
Mark Brown | 3f1a4d8 | 2009-04-15 21:35:26 +0100 | [diff] [blame] | 2271 | if (dai->ops && dai->ops->set_clkdiv) |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2272 | return dai->ops->set_clkdiv(dai, div_id, div); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2273 | else |
| 2274 | return -EINVAL; |
| 2275 | } |
| 2276 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); |
| 2277 | |
| 2278 | /** |
| 2279 | * snd_soc_dai_set_pll - configure DAI PLL. |
| 2280 | * @dai: DAI |
| 2281 | * @pll_id: DAI specific PLL ID |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2282 | * @source: DAI specific source for the PLL |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2283 | * @freq_in: PLL input clock frequency in Hz |
| 2284 | * @freq_out: requested PLL output clock frequency in Hz |
| 2285 | * |
| 2286 | * Configures and enables PLL to generate output clock based on input clock. |
| 2287 | */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2288 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, |
| 2289 | unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2290 | { |
Mark Brown | 3f1a4d8 | 2009-04-15 21:35:26 +0100 | [diff] [blame] | 2291 | if (dai->ops && dai->ops->set_pll) |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2292 | return dai->ops->set_pll(dai, pll_id, source, |
| 2293 | freq_in, freq_out); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2294 | else |
| 2295 | return -EINVAL; |
| 2296 | } |
| 2297 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); |
| 2298 | |
| 2299 | /** |
| 2300 | * snd_soc_dai_set_fmt - configure DAI hardware audio format. |
| 2301 | * @dai: DAI |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2302 | * @fmt: SND_SOC_DAIFMT_ format value. |
| 2303 | * |
| 2304 | * Configures the DAI hardware format and clocking. |
| 2305 | */ |
| 2306 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 2307 | { |
Mark Brown | 3f1a4d8 | 2009-04-15 21:35:26 +0100 | [diff] [blame] | 2308 | if (dai->ops && dai->ops->set_fmt) |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2309 | return dai->ops->set_fmt(dai, fmt); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2310 | else |
| 2311 | return -EINVAL; |
| 2312 | } |
| 2313 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); |
| 2314 | |
| 2315 | /** |
| 2316 | * snd_soc_dai_set_tdm_slot - configure DAI TDM. |
| 2317 | * @dai: DAI |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2318 | * @tx_mask: bitmask representing active TX slots. |
| 2319 | * @rx_mask: bitmask representing active RX slots. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2320 | * @slots: Number of slots in use. |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2321 | * @slot_width: Width in bits for each slot. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2322 | * |
| 2323 | * Configures a DAI for TDM operation. Both mask and slots are codec and DAI |
| 2324 | * specific. |
| 2325 | */ |
| 2326 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2327 | 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] | 2328 | { |
Mark Brown | 3f1a4d8 | 2009-04-15 21:35:26 +0100 | [diff] [blame] | 2329 | if (dai->ops && dai->ops->set_tdm_slot) |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2330 | return dai->ops->set_tdm_slot(dai, tx_mask, rx_mask, |
| 2331 | slots, slot_width); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2332 | else |
| 2333 | return -EINVAL; |
| 2334 | } |
| 2335 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); |
| 2336 | |
| 2337 | /** |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 2338 | * snd_soc_dai_set_channel_map - configure DAI audio channel map |
| 2339 | * @dai: DAI |
| 2340 | * @tx_num: how many TX channels |
| 2341 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 2342 | * 0~num-1 uses |
| 2343 | * @rx_num: how many RX channels |
| 2344 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 2345 | * 0~num-1 uses |
| 2346 | * |
| 2347 | * configure the relationship between channel number and TDM slot number. |
| 2348 | */ |
| 2349 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 2350 | unsigned int tx_num, unsigned int *tx_slot, |
| 2351 | unsigned int rx_num, unsigned int *rx_slot) |
| 2352 | { |
| 2353 | if (dai->ops && dai->ops->set_channel_map) |
| 2354 | return dai->ops->set_channel_map(dai, tx_num, tx_slot, |
| 2355 | rx_num, rx_slot); |
| 2356 | else |
| 2357 | return -EINVAL; |
| 2358 | } |
| 2359 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); |
| 2360 | |
| 2361 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2362 | * snd_soc_dai_set_tristate - configure DAI system or master clock. |
| 2363 | * @dai: DAI |
| 2364 | * @tristate: tristate enable |
| 2365 | * |
| 2366 | * Tristates the DAI so that others can use it. |
| 2367 | */ |
| 2368 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
| 2369 | { |
Mark Brown | 3f1a4d8 | 2009-04-15 21:35:26 +0100 | [diff] [blame] | 2370 | if (dai->ops && dai->ops->set_tristate) |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2371 | return dai->ops->set_tristate(dai, tristate); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2372 | else |
| 2373 | return -EINVAL; |
| 2374 | } |
| 2375 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); |
| 2376 | |
| 2377 | /** |
| 2378 | * snd_soc_dai_digital_mute - configure DAI system or master clock. |
| 2379 | * @dai: DAI |
| 2380 | * @mute: mute enable |
| 2381 | * |
| 2382 | * Mutes the DAI DAC. |
| 2383 | */ |
| 2384 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) |
| 2385 | { |
Mark Brown | 3f1a4d8 | 2009-04-15 21:35:26 +0100 | [diff] [blame] | 2386 | if (dai->ops && dai->ops->digital_mute) |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2387 | return dai->ops->digital_mute(dai, mute); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2388 | else |
| 2389 | return -EINVAL; |
| 2390 | } |
| 2391 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
| 2392 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2393 | /** |
| 2394 | * snd_soc_register_card - Register a card with the ASoC core |
| 2395 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2396 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2397 | * |
| 2398 | * Note that currently this is an internal only function: it will be |
| 2399 | * exposed to machine drivers after further backporting of ASoC v2 |
| 2400 | * registration APIs. |
| 2401 | */ |
| 2402 | static int snd_soc_register_card(struct snd_soc_card *card) |
| 2403 | { |
| 2404 | if (!card->name || !card->dev) |
| 2405 | return -EINVAL; |
| 2406 | |
| 2407 | INIT_LIST_HEAD(&card->list); |
| 2408 | card->instantiated = 0; |
| 2409 | |
| 2410 | mutex_lock(&client_mutex); |
| 2411 | list_add(&card->list, &card_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2412 | snd_soc_instantiate_cards(); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2413 | mutex_unlock(&client_mutex); |
| 2414 | |
| 2415 | dev_dbg(card->dev, "Registered card '%s'\n", card->name); |
| 2416 | |
| 2417 | return 0; |
| 2418 | } |
| 2419 | |
| 2420 | /** |
| 2421 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 2422 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2423 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2424 | * |
| 2425 | * Note that currently this is an internal only function: it will be |
| 2426 | * exposed to machine drivers after further backporting of ASoC v2 |
| 2427 | * registration APIs. |
| 2428 | */ |
| 2429 | static int snd_soc_unregister_card(struct snd_soc_card *card) |
| 2430 | { |
| 2431 | mutex_lock(&client_mutex); |
| 2432 | list_del(&card->list); |
| 2433 | mutex_unlock(&client_mutex); |
| 2434 | |
| 2435 | dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); |
| 2436 | |
| 2437 | return 0; |
| 2438 | } |
| 2439 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2440 | /** |
| 2441 | * snd_soc_register_dai - Register a DAI with the ASoC core |
| 2442 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2443 | * @dai: DAI to register |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2444 | */ |
| 2445 | int snd_soc_register_dai(struct snd_soc_dai *dai) |
| 2446 | { |
| 2447 | if (!dai->name) |
| 2448 | return -EINVAL; |
| 2449 | |
| 2450 | /* The device should become mandatory over time */ |
| 2451 | if (!dai->dev) |
| 2452 | printk(KERN_WARNING "No device for DAI %s\n", dai->name); |
| 2453 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 2454 | if (!dai->ops) |
| 2455 | dai->ops = &null_dai_ops; |
| 2456 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2457 | INIT_LIST_HEAD(&dai->list); |
| 2458 | |
| 2459 | mutex_lock(&client_mutex); |
| 2460 | list_add(&dai->list, &dai_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2461 | snd_soc_instantiate_cards(); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2462 | mutex_unlock(&client_mutex); |
| 2463 | |
| 2464 | pr_debug("Registered DAI '%s'\n", dai->name); |
| 2465 | |
| 2466 | return 0; |
| 2467 | } |
| 2468 | EXPORT_SYMBOL_GPL(snd_soc_register_dai); |
| 2469 | |
| 2470 | /** |
| 2471 | * snd_soc_unregister_dai - Unregister a DAI from the ASoC core |
| 2472 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2473 | * @dai: DAI to unregister |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2474 | */ |
| 2475 | void snd_soc_unregister_dai(struct snd_soc_dai *dai) |
| 2476 | { |
| 2477 | mutex_lock(&client_mutex); |
| 2478 | list_del(&dai->list); |
| 2479 | mutex_unlock(&client_mutex); |
| 2480 | |
| 2481 | pr_debug("Unregistered DAI '%s'\n", dai->name); |
| 2482 | } |
| 2483 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); |
| 2484 | |
| 2485 | /** |
| 2486 | * snd_soc_register_dais - Register multiple DAIs with the ASoC core |
| 2487 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2488 | * @dai: Array of DAIs to register |
| 2489 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2490 | */ |
| 2491 | int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count) |
| 2492 | { |
| 2493 | int i, ret; |
| 2494 | |
| 2495 | for (i = 0; i < count; i++) { |
| 2496 | ret = snd_soc_register_dai(&dai[i]); |
| 2497 | if (ret != 0) |
| 2498 | goto err; |
| 2499 | } |
| 2500 | |
| 2501 | return 0; |
| 2502 | |
| 2503 | err: |
| 2504 | for (i--; i >= 0; i--) |
| 2505 | snd_soc_unregister_dai(&dai[i]); |
| 2506 | |
| 2507 | return ret; |
| 2508 | } |
| 2509 | EXPORT_SYMBOL_GPL(snd_soc_register_dais); |
| 2510 | |
| 2511 | /** |
| 2512 | * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core |
| 2513 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2514 | * @dai: Array of DAIs to unregister |
| 2515 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2516 | */ |
| 2517 | void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count) |
| 2518 | { |
| 2519 | int i; |
| 2520 | |
| 2521 | for (i = 0; i < count; i++) |
| 2522 | snd_soc_unregister_dai(&dai[i]); |
| 2523 | } |
| 2524 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); |
| 2525 | |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2526 | /** |
| 2527 | * snd_soc_register_platform - Register a platform with the ASoC core |
| 2528 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2529 | * @platform: platform to register |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2530 | */ |
| 2531 | int snd_soc_register_platform(struct snd_soc_platform *platform) |
| 2532 | { |
| 2533 | if (!platform->name) |
| 2534 | return -EINVAL; |
| 2535 | |
| 2536 | INIT_LIST_HEAD(&platform->list); |
| 2537 | |
| 2538 | mutex_lock(&client_mutex); |
| 2539 | list_add(&platform->list, &platform_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2540 | snd_soc_instantiate_cards(); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2541 | mutex_unlock(&client_mutex); |
| 2542 | |
| 2543 | pr_debug("Registered platform '%s'\n", platform->name); |
| 2544 | |
| 2545 | return 0; |
| 2546 | } |
| 2547 | EXPORT_SYMBOL_GPL(snd_soc_register_platform); |
| 2548 | |
| 2549 | /** |
| 2550 | * snd_soc_unregister_platform - Unregister a platform from the ASoC core |
| 2551 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2552 | * @platform: platform to unregister |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2553 | */ |
| 2554 | void snd_soc_unregister_platform(struct snd_soc_platform *platform) |
| 2555 | { |
| 2556 | mutex_lock(&client_mutex); |
| 2557 | list_del(&platform->list); |
| 2558 | mutex_unlock(&client_mutex); |
| 2559 | |
| 2560 | pr_debug("Unregistered platform '%s'\n", platform->name); |
| 2561 | } |
| 2562 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
| 2563 | |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 2564 | static u64 codec_format_map[] = { |
| 2565 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, |
| 2566 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, |
| 2567 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, |
| 2568 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, |
| 2569 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, |
| 2570 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, |
| 2571 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 2572 | SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 2573 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, |
| 2574 | SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, |
| 2575 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, |
| 2576 | SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, |
| 2577 | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, |
| 2578 | SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, |
| 2579 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE |
| 2580 | | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, |
| 2581 | }; |
| 2582 | |
| 2583 | /* Fix up the DAI formats for endianness: codecs don't actually see |
| 2584 | * the endianness of the data but we're using the CPU format |
| 2585 | * definitions which do need to include endianness so we ensure that |
| 2586 | * codec DAIs always have both big and little endian variants set. |
| 2587 | */ |
| 2588 | static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) |
| 2589 | { |
| 2590 | int i; |
| 2591 | |
| 2592 | for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) |
| 2593 | if (stream->formats & codec_format_map[i]) |
| 2594 | stream->formats |= codec_format_map[i]; |
| 2595 | } |
| 2596 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2597 | /** |
| 2598 | * snd_soc_register_codec - Register a codec with the ASoC core |
| 2599 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2600 | * @codec: codec to register |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2601 | */ |
| 2602 | int snd_soc_register_codec(struct snd_soc_codec *codec) |
| 2603 | { |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 2604 | int i; |
| 2605 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2606 | if (!codec->name) |
| 2607 | return -EINVAL; |
| 2608 | |
| 2609 | /* The device should become mandatory over time */ |
| 2610 | if (!codec->dev) |
| 2611 | printk(KERN_WARNING "No device for codec %s\n", codec->name); |
| 2612 | |
| 2613 | INIT_LIST_HEAD(&codec->list); |
| 2614 | |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 2615 | for (i = 0; i < codec->num_dai; i++) { |
| 2616 | fixup_codec_formats(&codec->dai[i].playback); |
| 2617 | fixup_codec_formats(&codec->dai[i].capture); |
| 2618 | } |
| 2619 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2620 | mutex_lock(&client_mutex); |
| 2621 | list_add(&codec->list, &codec_list); |
| 2622 | snd_soc_instantiate_cards(); |
| 2623 | mutex_unlock(&client_mutex); |
| 2624 | |
| 2625 | pr_debug("Registered codec '%s'\n", codec->name); |
| 2626 | |
| 2627 | return 0; |
| 2628 | } |
| 2629 | EXPORT_SYMBOL_GPL(snd_soc_register_codec); |
| 2630 | |
| 2631 | /** |
| 2632 | * snd_soc_unregister_codec - Unregister a codec from the ASoC core |
| 2633 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2634 | * @codec: codec to unregister |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 2635 | */ |
| 2636 | void snd_soc_unregister_codec(struct snd_soc_codec *codec) |
| 2637 | { |
| 2638 | mutex_lock(&client_mutex); |
| 2639 | list_del(&codec->list); |
| 2640 | mutex_unlock(&client_mutex); |
| 2641 | |
| 2642 | pr_debug("Unregistered codec '%s'\n", codec->name); |
| 2643 | } |
| 2644 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
| 2645 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 2646 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2647 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 2648 | #ifdef CONFIG_DEBUG_FS |
| 2649 | debugfs_root = debugfs_create_dir("asoc", NULL); |
| 2650 | if (IS_ERR(debugfs_root) || !debugfs_root) { |
| 2651 | printk(KERN_WARNING |
| 2652 | "ASoC: Failed to create debugfs directory\n"); |
| 2653 | debugfs_root = NULL; |
| 2654 | } |
| 2655 | #endif |
| 2656 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2657 | return platform_driver_register(&soc_driver); |
| 2658 | } |
| 2659 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 2660 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2661 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 2662 | #ifdef CONFIG_DEBUG_FS |
| 2663 | debugfs_remove_recursive(debugfs_root); |
| 2664 | #endif |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2665 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | module_init(snd_soc_init); |
| 2669 | module_exit(snd_soc_exit); |
| 2670 | |
| 2671 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 2672 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2673 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 2674 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 2675 | MODULE_ALIAS("platform:soc-audio"); |