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