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