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