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