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