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> |
Mark Brown | 10f672f | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 33 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Marek Vasut | 474828a | 2009-07-22 13:01:03 +0200 | [diff] [blame] | 35 | #include <sound/ac97_codec.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 36 | #include <sound/core.h> |
Mark Brown | 3028eb8 | 2010-12-05 12:22:46 +0000 | [diff] [blame] | 37 | #include <sound/jack.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 38 | #include <sound/pcm.h> |
| 39 | #include <sound/pcm_params.h> |
| 40 | #include <sound/soc.h> |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 41 | #include <sound/soc-dsp.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 42 | #include <sound/initval.h> |
| 43 | |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 44 | #define CREATE_TRACE_POINTS |
| 45 | #include <trace/events/asoc.h> |
| 46 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 47 | #define NAME_SIZE 32 |
| 48 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 49 | static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); |
| 50 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 51 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 52 | struct dentry *snd_soc_debugfs_root; |
| 53 | EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 54 | #endif |
| 55 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 56 | static DEFINE_MUTEX(client_mutex); |
| 57 | static LIST_HEAD(card_list); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 58 | static LIST_HEAD(dai_list); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 59 | static LIST_HEAD(platform_list); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 60 | static LIST_HEAD(codec_list); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 61 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 62 | static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 63 | int soc_dsp_debugfs_add(struct snd_soc_pcm_runtime *rtd); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 64 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 65 | /* |
| 66 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
| 67 | * It can be used to eliminate pops between different playback streams, e.g. |
| 68 | * between two audio tracks. |
| 69 | */ |
Patrick Lai | 95c1e67 | 2012-04-13 21:52:20 -0700 | [diff] [blame] | 70 | static int pmdown_time; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 71 | module_param(pmdown_time, int, 0); |
| 72 | MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); |
| 73 | |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 74 | /* returns the minimum number of bytes needed to represent |
| 75 | * a particular given value */ |
| 76 | static int min_bytes_needed(unsigned long val) |
| 77 | { |
| 78 | int c = 0; |
| 79 | int i; |
| 80 | |
| 81 | for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c) |
| 82 | if (val & (1UL << i)) |
| 83 | break; |
| 84 | c = (sizeof val * 8) - c; |
| 85 | if (!c || (c % 8)) |
| 86 | c = (c + 8) / 8; |
| 87 | else |
| 88 | c /= 8; |
| 89 | return c; |
| 90 | } |
| 91 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 92 | /* fill buf which is 'len' bytes with a formatted |
| 93 | * string of the form 'reg: value\n' */ |
| 94 | static int format_register_str(struct snd_soc_codec *codec, |
| 95 | unsigned int reg, char *buf, size_t len) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 96 | { |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 97 | int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 98 | int regsize = codec->driver->reg_word_size * 2; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 99 | int ret; |
| 100 | char tmpbuf[len + 1]; |
| 101 | char regbuf[regsize + 1]; |
| 102 | |
| 103 | /* since tmpbuf is allocated on the stack, warn the callers if they |
| 104 | * try to abuse this function */ |
| 105 | WARN_ON(len > 63); |
| 106 | |
| 107 | /* +2 for ': ' and + 1 for '\n' */ |
| 108 | if (wordsize + regsize + 2 + 1 != len) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | ret = snd_soc_read(codec , reg); |
| 112 | if (ret < 0) { |
| 113 | memset(regbuf, 'X', regsize); |
| 114 | regbuf[regsize] = '\0'; |
| 115 | } else { |
| 116 | snprintf(regbuf, regsize + 1, "%.*x", regsize, ret); |
| 117 | } |
| 118 | |
| 119 | /* prepare the buffer */ |
| 120 | snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf); |
| 121 | /* copy it back to the caller without the '\0' */ |
| 122 | memcpy(buf, tmpbuf, len); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 127 | /* ASoC no host IO hardware. |
| 128 | * TODO: fine tune these values for all host less transfers. |
| 129 | */ |
| 130 | static const struct snd_pcm_hardware no_host_hardware = { |
| 131 | .info = SNDRV_PCM_INFO_MMAP | |
| 132 | SNDRV_PCM_INFO_MMAP_VALID | |
| 133 | SNDRV_PCM_INFO_INTERLEAVED | |
| 134 | SNDRV_PCM_INFO_PAUSE | |
| 135 | SNDRV_PCM_INFO_RESUME, |
| 136 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 137 | SNDRV_PCM_FMTBIT_S32_LE, |
| 138 | .period_bytes_min = PAGE_SIZE >> 2, |
| 139 | .period_bytes_max = PAGE_SIZE >> 1, |
| 140 | .periods_min = 2, |
| 141 | .periods_max = 4, |
| 142 | .buffer_bytes_max = PAGE_SIZE, |
| 143 | }; |
| 144 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 145 | /* codec register dump */ |
| 146 | static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, |
| 147 | size_t count, loff_t pos) |
| 148 | { |
| 149 | int i, step = 1; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 150 | int wordsize, regsize; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 151 | int len; |
| 152 | size_t total = 0; |
| 153 | loff_t p = 0; |
Dimitris Papastamos | 2bc9a81 | 2011-02-01 12:24:08 +0000 | [diff] [blame] | 154 | |
Stephen Warren | 00b317a | 2011-04-01 14:50:44 -0600 | [diff] [blame] | 155 | wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; |
| 156 | regsize = codec->driver->reg_word_size * 2; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 157 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 158 | len = wordsize + regsize + 2 + 1; |
| 159 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 160 | if (!codec->driver->reg_cache_size) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 161 | return 0; |
| 162 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 163 | if (codec->driver->reg_cache_step) |
| 164 | step = codec->driver->reg_cache_step; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 165 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 166 | for (i = 0; i < codec->driver->reg_cache_size; i += step) { |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 167 | if (codec->readable_register && !codec->readable_register(codec, i)) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 168 | continue; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 169 | if (codec->driver->display_register) { |
| 170 | count += codec->driver->display_register(codec, buf + count, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 171 | PAGE_SIZE - count, i); |
Mark Brown | 5164d74 | 2010-07-14 16:14:33 +0100 | [diff] [blame] | 172 | } else { |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 173 | /* only support larger than PAGE_SIZE bytes debugfs |
| 174 | * entries for the default case */ |
| 175 | if (p >= pos) { |
| 176 | if (total + len >= count - 1) |
| 177 | break; |
| 178 | format_register_str(codec, i, buf + total, len); |
| 179 | total += len; |
| 180 | } |
| 181 | p += len; |
Mark Brown | 5164d74 | 2010-07-14 16:14:33 +0100 | [diff] [blame] | 182 | } |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 185 | total = min(total, count - 1); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 186 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 187 | return total; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 188 | } |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 189 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 190 | static ssize_t codec_reg_show(struct device *dev, |
| 191 | struct device_attribute *attr, char *buf) |
| 192 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 193 | struct snd_soc_pcm_runtime *rtd = |
| 194 | container_of(dev, struct snd_soc_pcm_runtime, dev); |
| 195 | |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 196 | return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); |
| 200 | |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 201 | static ssize_t pmdown_time_show(struct device *dev, |
| 202 | struct device_attribute *attr, char *buf) |
| 203 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 204 | struct snd_soc_pcm_runtime *rtd = |
| 205 | container_of(dev, struct snd_soc_pcm_runtime, dev); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 206 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 207 | return sprintf(buf, "%ld\n", rtd->pmdown_time); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static ssize_t pmdown_time_set(struct device *dev, |
| 211 | struct device_attribute *attr, |
| 212 | const char *buf, size_t count) |
| 213 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 214 | struct snd_soc_pcm_runtime *rtd = |
| 215 | container_of(dev, struct snd_soc_pcm_runtime, dev); |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 216 | int ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 217 | |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 218 | ret = strict_strtol(buf, 10, &rtd->pmdown_time); |
| 219 | if (ret) |
| 220 | return ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 221 | |
| 222 | return count; |
| 223 | } |
| 224 | |
| 225 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); |
| 226 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 227 | #ifdef CONFIG_DEBUG_FS |
| 228 | static int codec_reg_open_file(struct inode *inode, struct file *file) |
| 229 | { |
| 230 | file->private_data = inode->i_private; |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 235 | size_t count, loff_t *ppos) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 236 | { |
| 237 | ssize_t ret; |
| 238 | struct snd_soc_codec *codec = file->private_data; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 239 | char *buf; |
| 240 | |
| 241 | if (*ppos < 0 || !count) |
| 242 | return -EINVAL; |
| 243 | |
| 244 | buf = kmalloc(count, GFP_KERNEL); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 245 | if (!buf) |
| 246 | return -ENOMEM; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 247 | |
| 248 | ret = soc_codec_reg_show(codec, buf, count, *ppos); |
| 249 | if (ret >= 0) { |
| 250 | if (copy_to_user(user_buf, buf, ret)) { |
| 251 | kfree(buf); |
| 252 | return -EFAULT; |
| 253 | } |
| 254 | *ppos += ret; |
| 255 | } |
| 256 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 257 | kfree(buf); |
| 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | static ssize_t codec_reg_write_file(struct file *file, |
| 262 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 263 | { |
| 264 | char buf[32]; |
Stephen Boyd | 34e268d | 2011-05-12 16:50:10 -0700 | [diff] [blame] | 265 | size_t buf_size; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 266 | char *start = buf; |
| 267 | unsigned long reg, value; |
| 268 | int step = 1; |
| 269 | struct snd_soc_codec *codec = file->private_data; |
| 270 | |
| 271 | buf_size = min(count, (sizeof(buf)-1)); |
| 272 | if (copy_from_user(buf, user_buf, buf_size)) |
| 273 | return -EFAULT; |
| 274 | buf[buf_size] = 0; |
| 275 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 276 | if (codec->driver->reg_cache_step) |
| 277 | step = codec->driver->reg_cache_step; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 278 | |
| 279 | while (*start == ' ') |
| 280 | start++; |
| 281 | reg = simple_strtoul(start, &start, 16); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 282 | while (*start == ' ') |
| 283 | start++; |
| 284 | if (strict_strtoul(start, 16, &value)) |
| 285 | return -EINVAL; |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 286 | |
| 287 | /* Userspace has been fiddling around behind the kernel's back */ |
| 288 | add_taint(TAINT_USER); |
| 289 | |
Dimitris Papastamos | e4f078d | 2010-12-07 16:30:38 +0000 | [diff] [blame] | 290 | snd_soc_write(codec, reg, value); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 291 | return buf_size; |
| 292 | } |
| 293 | |
| 294 | static const struct file_operations codec_reg_fops = { |
| 295 | .open = codec_reg_open_file, |
| 296 | .read = codec_reg_read_file, |
| 297 | .write = codec_reg_write_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 298 | .llseek = default_llseek, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | static void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 302 | { |
Jarkko Nikula | d6ce4cf | 2010-11-05 20:35:20 +0200 | [diff] [blame] | 303 | struct dentry *debugfs_card_root = codec->card->debugfs_card_root; |
| 304 | |
| 305 | codec->debugfs_codec_root = debugfs_create_dir(codec->name, |
| 306 | debugfs_card_root); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 307 | if (!codec->debugfs_codec_root) { |
| 308 | printk(KERN_WARNING |
| 309 | "ASoC: Failed to create codec debugfs directory\n"); |
| 310 | return; |
| 311 | } |
| 312 | |
Mark Brown | aaee8ef | 2011-01-26 20:53:50 +0000 | [diff] [blame] | 313 | debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root, |
| 314 | &codec->cache_sync); |
| 315 | debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root, |
| 316 | &codec->cache_only); |
| 317 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 318 | codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, |
| 319 | codec->debugfs_codec_root, |
| 320 | codec, &codec_reg_fops); |
| 321 | if (!codec->debugfs_reg) |
| 322 | printk(KERN_WARNING |
| 323 | "ASoC: Failed to create codec register debugfs file\n"); |
| 324 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 325 | snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 329 | { |
| 330 | debugfs_remove_recursive(codec->debugfs_codec_root); |
| 331 | } |
| 332 | |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 333 | static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, |
| 334 | size_t count, loff_t *ppos) |
| 335 | { |
| 336 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 337 | ssize_t len, ret = 0; |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 338 | struct snd_soc_codec *codec; |
| 339 | |
| 340 | if (!buf) |
| 341 | return -ENOMEM; |
| 342 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 343 | list_for_each_entry(codec, &codec_list, list) { |
| 344 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 345 | codec->name); |
| 346 | if (len >= 0) |
| 347 | ret += len; |
| 348 | if (ret > PAGE_SIZE) { |
| 349 | ret = PAGE_SIZE; |
| 350 | break; |
| 351 | } |
| 352 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 353 | |
| 354 | if (ret >= 0) |
| 355 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 356 | |
| 357 | kfree(buf); |
| 358 | |
| 359 | return ret; |
| 360 | } |
| 361 | |
| 362 | static const struct file_operations codec_list_fops = { |
| 363 | .read = codec_list_read_file, |
| 364 | .llseek = default_llseek,/* read accesses f_pos */ |
| 365 | }; |
| 366 | |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 367 | static ssize_t dai_list_read_file(struct file *file, char __user *user_buf, |
| 368 | size_t count, loff_t *ppos) |
| 369 | { |
| 370 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 371 | ssize_t len, ret = 0; |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 372 | struct snd_soc_dai *dai; |
| 373 | |
| 374 | if (!buf) |
| 375 | return -ENOMEM; |
| 376 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 377 | list_for_each_entry(dai, &dai_list, list) { |
| 378 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name); |
| 379 | if (len >= 0) |
| 380 | ret += len; |
| 381 | if (ret > PAGE_SIZE) { |
| 382 | ret = PAGE_SIZE; |
| 383 | break; |
| 384 | } |
| 385 | } |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 386 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 387 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 388 | |
| 389 | kfree(buf); |
| 390 | |
| 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | static const struct file_operations dai_list_fops = { |
| 395 | .read = dai_list_read_file, |
| 396 | .llseek = default_llseek,/* read accesses f_pos */ |
| 397 | }; |
| 398 | |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 399 | static ssize_t platform_list_read_file(struct file *file, |
| 400 | char __user *user_buf, |
| 401 | size_t count, loff_t *ppos) |
| 402 | { |
| 403 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 404 | ssize_t len, ret = 0; |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 405 | struct snd_soc_platform *platform; |
| 406 | |
| 407 | if (!buf) |
| 408 | return -ENOMEM; |
| 409 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 410 | list_for_each_entry(platform, &platform_list, list) { |
| 411 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 412 | platform->name); |
| 413 | if (len >= 0) |
| 414 | ret += len; |
| 415 | if (ret > PAGE_SIZE) { |
| 416 | ret = PAGE_SIZE; |
| 417 | break; |
| 418 | } |
| 419 | } |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 420 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 421 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 422 | |
| 423 | kfree(buf); |
| 424 | |
| 425 | return ret; |
| 426 | } |
| 427 | |
| 428 | static const struct file_operations platform_list_fops = { |
| 429 | .read = platform_list_read_file, |
| 430 | .llseek = default_llseek,/* read accesses f_pos */ |
| 431 | }; |
| 432 | |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 433 | static void soc_init_card_debugfs(struct snd_soc_card *card) |
| 434 | { |
| 435 | card->debugfs_card_root = debugfs_create_dir(card->name, |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 436 | snd_soc_debugfs_root); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 437 | if (!card->debugfs_card_root) { |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 438 | dev_warn(card->dev, |
| 439 | "ASoC: Failed to create codec debugfs directory\n"); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 440 | return; |
| 441 | } |
| 442 | |
| 443 | card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, |
| 444 | card->debugfs_card_root, |
| 445 | &card->pop_time); |
| 446 | if (!card->debugfs_pop_time) |
| 447 | dev_warn(card->dev, |
| 448 | "Failed to create pop time debugfs file\n"); |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | static void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 452 | { |
| 453 | debugfs_remove_recursive(card->debugfs_card_root); |
| 454 | } |
| 455 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 456 | #else |
| 457 | |
| 458 | static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec) |
| 459 | { |
| 460 | } |
| 461 | |
| 462 | static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) |
| 463 | { |
| 464 | } |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 465 | |
| 466 | static inline void soc_init_card_debugfs(struct snd_soc_card *card) |
| 467 | { |
| 468 | } |
| 469 | |
| 470 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 471 | { |
| 472 | } |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 473 | #endif |
| 474 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 475 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 476 | /* unregister ac97 codec */ |
| 477 | static int soc_ac97_dev_unregister(struct snd_soc_codec *codec) |
| 478 | { |
| 479 | if (codec->ac97->dev.bus) |
| 480 | device_unregister(&codec->ac97->dev); |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | /* stop no dev release warning */ |
| 485 | static void soc_ac97_device_release(struct device *dev){} |
| 486 | |
| 487 | /* register ac97 codec to bus */ |
| 488 | static int soc_ac97_dev_register(struct snd_soc_codec *codec) |
| 489 | { |
| 490 | int err; |
| 491 | |
| 492 | codec->ac97->dev.bus = &ac97_bus_type; |
Mark Brown | 4ac5c61 | 2009-04-01 19:35:01 +0100 | [diff] [blame] | 493 | codec->ac97->dev.parent = codec->card->dev; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 494 | codec->ac97->dev.release = soc_ac97_device_release; |
| 495 | |
Kay Sievers | bb072bf | 2008-11-02 03:50:35 +0100 | [diff] [blame] | 496 | dev_set_name(&codec->ac97->dev, "%d-%d:%s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 497 | codec->card->snd_card->number, 0, codec->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 498 | err = device_register(&codec->ac97->dev); |
| 499 | if (err < 0) { |
| 500 | snd_printk(KERN_ERR "Can't register ac97 bus\n"); |
| 501 | codec->ac97->dev.bus = NULL; |
| 502 | return err; |
| 503 | } |
| 504 | return 0; |
| 505 | } |
| 506 | #endif |
| 507 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 508 | static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream) |
| 509 | { |
| 510 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 511 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 512 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 513 | int ret; |
| 514 | |
Mark Brown | 4f333b2 | 2011-03-08 00:11:15 +0000 | [diff] [blame] | 515 | if (!codec_dai->driver->symmetric_rates && |
| 516 | !cpu_dai->driver->symmetric_rates && |
| 517 | !rtd->dai_link->symmetric_rates) |
| 518 | return 0; |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 519 | |
Mark Brown | c4ef878 | 2011-03-08 00:17:56 +0000 | [diff] [blame] | 520 | /* This can happen if multiple streams are starting simultaneously - |
| 521 | * the second can need to get its constraints before the first has |
| 522 | * picked a rate. Complain and allow the application to carry on. |
| 523 | */ |
| 524 | if (!rtd->rate) { |
| 525 | dev_warn(&rtd->dev, |
| 526 | "Not enforcing symmetric_rates due to race\n"); |
| 527 | return 0; |
| 528 | } |
| 529 | |
Mark Brown | 4f333b2 | 2011-03-08 00:11:15 +0000 | [diff] [blame] | 530 | dev_dbg(&rtd->dev, "Symmetry forces %dHz rate\n", rtd->rate); |
| 531 | |
| 532 | ret = snd_pcm_hw_constraint_minmax(substream->runtime, |
| 533 | SNDRV_PCM_HW_PARAM_RATE, |
| 534 | rtd->rate, rtd->rate); |
| 535 | if (ret < 0) { |
| 536 | dev_err(&rtd->dev, |
| 537 | "Unable to apply rate symmetry constraint: %d\n", ret); |
| 538 | return ret; |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 544 | /* |
| 545 | * Called by ALSA when a PCM substream is opened, the runtime->hw record is |
| 546 | * then initialized and any private data can be allocated. This also calls |
| 547 | * startup for the cpu DAI, platform, machine and codec DAI. |
| 548 | */ |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 549 | int soc_pcm_open(struct snd_pcm_substream *substream) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 550 | { |
| 551 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 552 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 553 | struct snd_soc_platform *platform = rtd->platform; |
| 554 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 555 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 556 | struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver; |
| 557 | struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 558 | int ret = 0; |
| 559 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 560 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 561 | |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 562 | if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST) |
| 563 | snd_soc_set_runtime_hwparams(substream, &no_host_hardware); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 564 | |
| 565 | /* startup the audio subsystem */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 566 | if (cpu_dai->driver->ops->startup) { |
| 567 | ret = cpu_dai->driver->ops->startup(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 568 | if (ret < 0) { |
| 569 | printk(KERN_ERR "asoc: can't open interface %s\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 570 | cpu_dai->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 571 | goto out; |
| 572 | } |
| 573 | } |
| 574 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 575 | if (platform->driver->ops && platform->driver->ops->open) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 576 | ret = platform->driver->ops->open(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 577 | if (ret < 0) { |
| 578 | printk(KERN_ERR "asoc: can't open platform %s\n", platform->name); |
| 579 | goto platform_err; |
| 580 | } |
| 581 | } |
| 582 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 583 | if (codec_dai->driver->ops->startup) { |
| 584 | ret = codec_dai->driver->ops->startup(substream, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 585 | if (ret < 0) { |
| 586 | printk(KERN_ERR "asoc: can't open codec %s\n", |
| 587 | codec_dai->name); |
| 588 | goto codec_dai_err; |
| 589 | } |
| 590 | } |
| 591 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 592 | if (rtd->dai_link->ops && rtd->dai_link->ops->startup) { |
| 593 | ret = rtd->dai_link->ops->startup(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 594 | if (ret < 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 595 | printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 596 | goto machine_err; |
| 597 | } |
| 598 | } |
| 599 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 600 | /* DSP DAI links compat checks are different */ |
| 601 | if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) |
| 602 | goto dynamic; |
| 603 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 604 | /* Check that the codec and cpu DAIs are compatible */ |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 605 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 606 | runtime->hw.rate_min = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 607 | max(codec_dai_drv->playback.rate_min, |
| 608 | cpu_dai_drv->playback.rate_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 609 | runtime->hw.rate_max = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 610 | min(codec_dai_drv->playback.rate_max, |
| 611 | cpu_dai_drv->playback.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 612 | runtime->hw.channels_min = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 613 | max(codec_dai_drv->playback.channels_min, |
| 614 | cpu_dai_drv->playback.channels_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 615 | runtime->hw.channels_max = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 616 | min(codec_dai_drv->playback.channels_max, |
| 617 | cpu_dai_drv->playback.channels_max); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 618 | runtime->hw.formats = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 619 | codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 620 | runtime->hw.rates = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 621 | codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates; |
| 622 | if (codec_dai_drv->playback.rates |
Jassi Brar | d9ad629 | 2010-03-12 13:38:52 +0900 | [diff] [blame] | 623 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 624 | runtime->hw.rates |= cpu_dai_drv->playback.rates; |
| 625 | if (cpu_dai_drv->playback.rates |
Jassi Brar | d9ad629 | 2010-03-12 13:38:52 +0900 | [diff] [blame] | 626 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 627 | runtime->hw.rates |= codec_dai_drv->playback.rates; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 628 | } else { |
| 629 | runtime->hw.rate_min = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 630 | max(codec_dai_drv->capture.rate_min, |
| 631 | cpu_dai_drv->capture.rate_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 632 | runtime->hw.rate_max = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 633 | min(codec_dai_drv->capture.rate_max, |
| 634 | cpu_dai_drv->capture.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 635 | runtime->hw.channels_min = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 636 | max(codec_dai_drv->capture.channels_min, |
| 637 | cpu_dai_drv->capture.channels_min); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 638 | runtime->hw.channels_max = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 639 | min(codec_dai_drv->capture.channels_max, |
| 640 | cpu_dai_drv->capture.channels_max); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 641 | runtime->hw.formats = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 642 | codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats; |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 643 | runtime->hw.rates = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 644 | codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates; |
| 645 | if (codec_dai_drv->capture.rates |
Jassi Brar | d9ad629 | 2010-03-12 13:38:52 +0900 | [diff] [blame] | 646 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 647 | runtime->hw.rates |= cpu_dai_drv->capture.rates; |
| 648 | if (cpu_dai_drv->capture.rates |
Jassi Brar | d9ad629 | 2010-03-12 13:38:52 +0900 | [diff] [blame] | 649 | & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 650 | runtime->hw.rates |= codec_dai_drv->capture.rates; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 651 | } |
| 652 | |
Lu Guanqun | c51def6 | 2011-04-06 23:25:21 +0800 | [diff] [blame] | 653 | ret = -EINVAL; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 654 | snd_pcm_limit_hw_rates(runtime); |
| 655 | if (!runtime->hw.rates) { |
| 656 | printk(KERN_ERR "asoc: %s <-> %s No matching rates\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 657 | codec_dai->name, cpu_dai->name); |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 658 | goto config_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 659 | } |
| 660 | if (!runtime->hw.formats) { |
| 661 | printk(KERN_ERR "asoc: %s <-> %s No matching formats\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 662 | codec_dai->name, cpu_dai->name); |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 663 | goto config_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 664 | } |
Lu Guanqun | b04cfcf | 2011-04-06 23:25:11 +0800 | [diff] [blame] | 665 | if (!runtime->hw.channels_min || !runtime->hw.channels_max || |
| 666 | runtime->hw.channels_min > runtime->hw.channels_max) { |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 667 | printk(KERN_ERR "asoc: %s <-> %s No matching channels\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 668 | codec_dai->name, cpu_dai->name); |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 669 | goto config_err; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 670 | } |
| 671 | |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 672 | /* Symmetry only applies if we've already got an active stream. */ |
| 673 | if (cpu_dai->active || codec_dai->active) { |
| 674 | ret = soc_pcm_apply_symmetry(substream); |
| 675 | if (ret != 0) |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 676 | goto config_err; |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 679 | pr_debug("asoc: %s <-> %s info:\n", |
| 680 | codec_dai->name, cpu_dai->name); |
Mark Brown | f24368c | 2008-10-21 21:45:08 +0100 | [diff] [blame] | 681 | pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates); |
| 682 | pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min, |
| 683 | runtime->hw.channels_max); |
| 684 | pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min, |
| 685 | runtime->hw.rate_max); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 686 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 687 | dynamic: |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 688 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 689 | cpu_dai->playback_active++; |
| 690 | codec_dai->playback_active++; |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 691 | } else { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 692 | cpu_dai->capture_active++; |
| 693 | codec_dai->capture_active++; |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 694 | } |
| 695 | cpu_dai->active++; |
| 696 | codec_dai->active++; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 697 | rtd->codec->active++; |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 698 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 699 | return 0; |
| 700 | |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 701 | config_err: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 702 | if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown) |
| 703 | rtd->dai_link->ops->shutdown(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 704 | |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 705 | machine_err: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 706 | if (codec_dai->driver->ops->shutdown) |
| 707 | codec_dai->driver->ops->shutdown(substream, codec_dai); |
Jassi Brar | bb1c047 | 2010-02-25 11:24:53 +0900 | [diff] [blame] | 708 | |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 709 | codec_dai_err: |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 710 | if (platform->driver->ops && platform->driver->ops->close) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 711 | platform->driver->ops->close(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 712 | |
| 713 | platform_err: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 714 | if (cpu_dai->driver->ops->shutdown) |
| 715 | cpu_dai->driver->ops->shutdown(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 716 | out: |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 717 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 718 | return ret; |
| 719 | } |
| 720 | |
| 721 | /* |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 722 | * Power down the audio subsystem pmdown_time msecs after close is called. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 723 | * This is to ensure there are no pops or clicks in between any music tracks |
| 724 | * due to DAPM power cycling. |
| 725 | */ |
Andrew Morton | 4484bb2 | 2006-12-15 09:30:07 +0100 | [diff] [blame] | 726 | static void close_delayed_work(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 727 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 728 | struct snd_soc_pcm_runtime *rtd = |
| 729 | container_of(work, struct snd_soc_pcm_runtime, delayed_work.work); |
| 730 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 731 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 732 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 733 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 734 | pr_debug("pop wq checking: %s status: %s waiting: %s\n", |
| 735 | codec_dai->driver->playback.stream_name, |
| 736 | codec_dai->playback_active ? "active" : "inactive", |
| 737 | codec_dai->pop_wait ? "yes" : "no"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 738 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 739 | /* are we waiting on this codec DAI stream */ |
| 740 | if (codec_dai->pop_wait == 1) { |
| 741 | codec_dai->pop_wait = 0; |
| 742 | snd_soc_dapm_stream_event(rtd, |
| 743 | codec_dai->driver->playback.stream_name, |
| 744 | SND_SOC_DAPM_STREAM_STOP); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 745 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 746 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 747 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* |
| 751 | * Called by ALSA when a PCM substream is closed. Private data can be |
| 752 | * freed here. The cpu DAI, codec DAI, machine and platform are also |
| 753 | * shutdown. |
| 754 | */ |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 755 | int soc_pcm_close(struct snd_pcm_substream *substream) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 756 | { |
| 757 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 758 | struct snd_soc_platform *platform = rtd->platform; |
| 759 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 760 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 761 | struct snd_soc_codec *codec = rtd->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 762 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 763 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 764 | |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 765 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 766 | cpu_dai->playback_active--; |
| 767 | codec_dai->playback_active--; |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 768 | } else { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 769 | cpu_dai->capture_active--; |
| 770 | codec_dai->capture_active--; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 771 | } |
Jassi Brar | 14dc573 | 2010-02-26 09:12:32 +0900 | [diff] [blame] | 772 | |
| 773 | cpu_dai->active--; |
| 774 | codec_dai->active--; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 775 | codec->active--; |
| 776 | |
Mark Brown | 6010b2d | 2008-09-06 18:33:24 +0100 | [diff] [blame] | 777 | /* Muting the DAC suppresses artifacts caused during digital |
| 778 | * shutdown, for example from stopping clocks. |
| 779 | */ |
| 780 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 781 | snd_soc_dai_digital_mute(codec_dai, 1); |
| 782 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 783 | if (cpu_dai->driver->ops->shutdown) |
| 784 | cpu_dai->driver->ops->shutdown(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 785 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 786 | if (codec_dai->driver->ops->shutdown) |
| 787 | codec_dai->driver->ops->shutdown(substream, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 788 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 789 | if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown) |
| 790 | rtd->dai_link->ops->shutdown(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 791 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 792 | if (platform->driver->ops && platform->driver->ops->close) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 793 | platform->driver->ops->close(substream); |
| 794 | cpu_dai->runtime = NULL; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 795 | |
| 796 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 797 | /* start delayed pop wq here for playback streams */ |
Kiran Kandi | 28ef14e | 2011-09-16 15:45:47 -0700 | [diff] [blame] | 798 | if (rtd->pmdown_time) { |
| 799 | codec_dai->pop_wait = 1; |
| 800 | schedule_delayed_work(&rtd->delayed_work, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 801 | msecs_to_jiffies(rtd->pmdown_time)); |
Kiran Kandi | 28ef14e | 2011-09-16 15:45:47 -0700 | [diff] [blame] | 802 | } else { |
| 803 | snd_soc_dapm_stream_event(rtd, |
| 804 | codec_dai->driver->playback.stream_name, |
| 805 | SND_SOC_DAPM_STREAM_STOP); |
| 806 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 807 | } else { |
| 808 | /* capture streams can be powered down now */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 809 | snd_soc_dapm_stream_event(rtd, |
| 810 | codec_dai->driver->capture.stream_name, |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 811 | SND_SOC_DAPM_STREAM_STOP); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 812 | } |
| 813 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 814 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | /* |
| 819 | * Called by ALSA when the PCM substream is prepared, can set format, sample |
| 820 | * rate, etc. This function is non atomic and can be called multiple times, |
| 821 | * it can refer to the runtime info. |
| 822 | */ |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 823 | int soc_pcm_prepare(struct snd_pcm_substream *substream) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 824 | { |
| 825 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 826 | struct snd_soc_platform *platform = rtd->platform; |
| 827 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 828 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 829 | int ret = 0; |
| 830 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 831 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 832 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 833 | if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) { |
| 834 | ret = rtd->dai_link->ops->prepare(substream); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 835 | if (ret < 0) { |
| 836 | printk(KERN_ERR "asoc: machine prepare error\n"); |
| 837 | goto out; |
| 838 | } |
| 839 | } |
| 840 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 841 | if (platform->driver->ops && platform->driver->ops->prepare) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 842 | ret = platform->driver->ops->prepare(substream); |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 843 | if (ret < 0) { |
| 844 | printk(KERN_ERR "asoc: platform prepare error\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 845 | goto out; |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 846 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 847 | } |
| 848 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 849 | if (codec_dai->driver->ops->prepare) { |
| 850 | ret = codec_dai->driver->ops->prepare(substream, codec_dai); |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 851 | if (ret < 0) { |
| 852 | printk(KERN_ERR "asoc: codec DAI prepare error\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 853 | goto out; |
Liam Girdwood | a71a468 | 2006-10-19 20:35:56 +0200 | [diff] [blame] | 854 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 855 | } |
| 856 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 857 | if (cpu_dai->driver->ops->prepare) { |
| 858 | ret = cpu_dai->driver->ops->prepare(substream, cpu_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 859 | if (ret < 0) { |
| 860 | printk(KERN_ERR "asoc: cpu DAI prepare error\n"); |
| 861 | goto out; |
| 862 | } |
| 863 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 864 | |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 865 | /* cancel any delayed stream shutdown that is pending */ |
| 866 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 867 | codec_dai->pop_wait) { |
| 868 | codec_dai->pop_wait = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 869 | cancel_delayed_work(&rtd->delayed_work); |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 872 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 873 | snd_soc_dapm_stream_event(rtd, |
| 874 | codec_dai->driver->playback.stream_name, |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 875 | SND_SOC_DAPM_STREAM_START); |
| 876 | else |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 877 | snd_soc_dapm_stream_event(rtd, |
| 878 | codec_dai->driver->capture.stream_name, |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 879 | SND_SOC_DAPM_STREAM_START); |
Mark Brown | d45f621 | 2008-10-14 13:58:36 +0100 | [diff] [blame] | 880 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 881 | snd_soc_dai_digital_mute(codec_dai, 0); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 882 | |
| 883 | out: |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 884 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 885 | return ret; |
| 886 | } |
| 887 | |
| 888 | /* |
| 889 | * Called by ALSA when the hardware params are set by application. This |
| 890 | * function can also be called multiple times and can allocate buffers |
| 891 | * (using snd_pcm_lib_* ). It's non-atomic. |
| 892 | */ |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 893 | int soc_pcm_hw_params(struct snd_pcm_substream *substream, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 894 | struct snd_pcm_hw_params *params) |
| 895 | { |
| 896 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 897 | struct snd_soc_platform *platform = rtd->platform; |
| 898 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 899 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 900 | int ret = 0; |
| 901 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 902 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 903 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 904 | if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) { |
| 905 | ret = rtd->dai_link->ops->hw_params(substream, params); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 906 | if (ret < 0) { |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 907 | printk(KERN_ERR "asoc: machine hw_params failed\n"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 908 | goto out; |
| 909 | } |
| 910 | } |
| 911 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 912 | if (codec_dai->driver->ops->hw_params) { |
| 913 | ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 914 | if (ret < 0) { |
| 915 | printk(KERN_ERR "asoc: can't set codec %s hw params\n", |
| 916 | codec_dai->name); |
| 917 | goto codec_err; |
| 918 | } |
| 919 | } |
| 920 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 921 | if (cpu_dai->driver->ops->hw_params) { |
| 922 | ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 923 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 924 | printk(KERN_ERR "asoc: interface %s hw params failed\n", |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 925 | cpu_dai->name); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 926 | goto interface_err; |
| 927 | } |
| 928 | } |
| 929 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 930 | if (platform->driver->ops && platform->driver->ops->hw_params) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 931 | ret = platform->driver->ops->hw_params(substream, params); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 932 | if (ret < 0) { |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 933 | printk(KERN_ERR "asoc: platform %s hw params failed\n", |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 934 | platform->name); |
| 935 | goto platform_err; |
| 936 | } |
| 937 | } |
| 938 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 939 | rtd->rate = params_rate(params); |
Mark Brown | 06f409d | 2009-04-07 18:10:13 +0100 | [diff] [blame] | 940 | |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 941 | /* malloc a page for hostless IO. |
| 942 | * FIXME: rework with alsa-lib changes so that this malloc is not required. |
| 943 | */ |
| 944 | if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST) { |
| 945 | substream->dma_buffer.dev.type = SNDRV_DMA_TYPE_DEV; |
| 946 | substream->dma_buffer.dev.dev = &rtd->dev; |
| 947 | substream->dma_buffer.dev.dev->coherent_dma_mask = ISA_DMA_THRESHOLD; |
| 948 | substream->dma_buffer.private_data = NULL; |
| 949 | |
| 950 | ret = snd_pcm_lib_malloc_pages(substream, PAGE_SIZE); |
| 951 | if (ret < 0) |
| 952 | goto platform_err; |
| 953 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 954 | out: |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 955 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 956 | return ret; |
| 957 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 958 | platform_err: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 959 | if (cpu_dai->driver->ops->hw_free) |
| 960 | cpu_dai->driver->ops->hw_free(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 961 | |
| 962 | interface_err: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 963 | if (codec_dai->driver->ops->hw_free) |
| 964 | codec_dai->driver->ops->hw_free(substream, codec_dai); |
Liam Girdwood | cb666e5 | 2007-02-02 17:13:49 +0100 | [diff] [blame] | 965 | |
| 966 | codec_err: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 967 | if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) |
| 968 | rtd->dai_link->ops->hw_free(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 969 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 970 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 971 | return ret; |
| 972 | } |
| 973 | |
| 974 | /* |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 975 | * Frees resources allocated by hw_params, can be called multiple times |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 976 | */ |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 977 | int soc_pcm_hw_free(struct snd_pcm_substream *substream) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 978 | { |
| 979 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 980 | struct snd_soc_platform *platform = rtd->platform; |
| 981 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 982 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 983 | struct snd_soc_codec *codec = rtd->codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 984 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 985 | mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 986 | |
| 987 | /* apply codec digital mute */ |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 988 | if (!codec->active) |
| 989 | snd_soc_dai_digital_mute(codec_dai, 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 990 | |
| 991 | /* free any machine hw params */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 992 | if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) |
| 993 | rtd->dai_link->ops->hw_free(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 994 | |
| 995 | /* free any DMA resources */ |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 996 | if (platform->driver->ops && platform->driver->ops->hw_free) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 997 | platform->driver->ops->hw_free(substream); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 998 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 999 | /* now free hw params for the DAIs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1000 | if (codec_dai->driver->ops->hw_free) |
| 1001 | codec_dai->driver->ops->hw_free(substream, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1002 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1003 | if (cpu_dai->driver->ops->hw_free) |
| 1004 | cpu_dai->driver->ops->hw_free(substream, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1005 | |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 1006 | if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST) |
| 1007 | snd_pcm_lib_free_pages(substream); |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 1008 | mutex_unlock(&rtd->pcm_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1009 | return 0; |
| 1010 | } |
| 1011 | |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 1012 | int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1013 | { |
| 1014 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1015 | struct snd_soc_platform *platform = rtd->platform; |
| 1016 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1017 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1018 | int ret; |
| 1019 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1020 | if (codec_dai->driver->ops->trigger) { |
| 1021 | ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1022 | if (ret < 0) |
| 1023 | return ret; |
| 1024 | } |
| 1025 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 1026 | if (platform->driver->ops && platform->driver->ops->trigger) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1027 | ret = platform->driver->ops->trigger(substream, cmd); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1028 | if (ret < 0) |
| 1029 | return ret; |
| 1030 | } |
| 1031 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1032 | if (cpu_dai->driver->ops->trigger) { |
| 1033 | ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1034 | if (ret < 0) |
| 1035 | return ret; |
| 1036 | } |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
Liam Girdwood | 59c96f1 | 2011-03-08 15:11:02 +0000 | [diff] [blame] | 1040 | int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, int cmd) |
| 1041 | { |
| 1042 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 1043 | struct snd_soc_platform *platform = rtd->platform; |
| 1044 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1045 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 1046 | int ret; |
| 1047 | |
| 1048 | if (codec_dai->driver->ops->bespoke_trigger) { |
| 1049 | ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai); |
| 1050 | if (ret < 0) |
| 1051 | return ret; |
| 1052 | } |
| 1053 | |
| 1054 | if (platform->driver->bespoke_trigger) { |
| 1055 | ret = platform->driver->bespoke_trigger(substream, cmd); |
| 1056 | if (ret < 0) |
| 1057 | return ret; |
| 1058 | } |
| 1059 | |
| 1060 | if (cpu_dai->driver->ops->bespoke_trigger) { |
| 1061 | ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai); |
| 1062 | if (ret < 0) |
| 1063 | return ret; |
| 1064 | } |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 1068 | /* |
| 1069 | * soc level wrapper for pointer callback |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 1070 | * If cpu_dai, codec_dai, platform driver has the delay callback, than |
| 1071 | * the runtime->delay will be updated accordingly. |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 1072 | */ |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 1073 | snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 1074 | { |
| 1075 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1076 | struct snd_soc_platform *platform = rtd->platform; |
| 1077 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1078 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 1079 | struct snd_pcm_runtime *runtime = substream->runtime; |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 1080 | snd_pcm_uframes_t offset = 0; |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 1081 | snd_pcm_sframes_t delay = 0; |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 1082 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 1083 | if (platform->driver->ops && platform->driver->ops->pointer) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1084 | offset = platform->driver->ops->pointer(substream); |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 1085 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1086 | if (cpu_dai->driver->ops->delay) |
| 1087 | delay += cpu_dai->driver->ops->delay(substream, cpu_dai); |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 1088 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1089 | if (codec_dai->driver->ops->delay) |
| 1090 | delay += codec_dai->driver->ops->delay(substream, codec_dai); |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 1091 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1092 | if (platform->driver->delay) |
| 1093 | delay += platform->driver->delay(substream, codec_dai); |
Peter Ujfalusi | 258020d | 2010-03-03 15:08:07 +0200 | [diff] [blame] | 1094 | |
| 1095 | runtime->delay = delay; |
| 1096 | |
Peter Ujfalusi | 377b6f6 | 2010-03-03 15:08:06 +0200 | [diff] [blame] | 1097 | return offset; |
| 1098 | } |
| 1099 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1100 | static int soc_pcm_ioctl(struct snd_pcm_substream *substream, |
| 1101 | unsigned int cmd, void *arg) |
| 1102 | { |
| 1103 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 1104 | struct snd_soc_platform *platform = rtd->platform; |
| 1105 | |
| 1106 | if (platform->driver->ops->ioctl) |
| 1107 | return platform->driver->ops->ioctl(substream, cmd, arg); |
| 1108 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 1109 | } |
| 1110 | |
| 1111 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, |
| 1112 | const char *dai_link, int stream) |
| 1113 | { |
| 1114 | int i; |
| 1115 | |
| 1116 | for (i = 0; i < card->num_links; i++) { |
| 1117 | if (card->rtd[i].dai_link->no_pcm && |
| 1118 | !strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 1119 | return card->rtd[i].pcm->streams[stream].substream; |
| 1120 | } |
| 1121 | dev_dbg(card->dev, "failed to find dai link %s\n", dai_link); |
| 1122 | return NULL; |
| 1123 | } |
| 1124 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); |
| 1125 | |
| 1126 | struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, |
| 1127 | const char *dai_link) |
| 1128 | { |
| 1129 | int i; |
| 1130 | |
| 1131 | for (i = 0; i < card->num_links; i++) { |
| 1132 | if (!strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 1133 | return &card->rtd[i]; |
| 1134 | } |
| 1135 | dev_dbg(card->dev, "failed to find rtd %s\n", dai_link); |
| 1136 | return NULL; |
| 1137 | } |
| 1138 | EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1139 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1140 | #ifdef CONFIG_PM_SLEEP |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1141 | /* powers down audio subsystem for suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1142 | int snd_soc_suspend(struct device *dev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1143 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1144 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1145 | struct snd_soc_codec *codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1146 | int i; |
| 1147 | |
Kuirong Wang | 5ab054f | 2012-02-29 16:09:09 -0800 | [diff] [blame] | 1148 | if (!card->instantiated) { |
| 1149 | dev_dbg(card->dev, "uninsantiated card found card->name = %s\n", |
| 1150 | card->name); |
| 1151 | return 0; |
| 1152 | } |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 1153 | /* If the initialization of this soc device failed, there is no codec |
| 1154 | * associated with it. Just bail out in this case. |
| 1155 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1156 | if (list_empty(&card->codec_dev_list)) |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 1157 | return 0; |
| 1158 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1159 | /* Due to the resume being scheduled into a workqueue we could |
| 1160 | * suspend before that's finished - wait for it to complete. |
| 1161 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1162 | snd_power_lock(card->snd_card); |
| 1163 | snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); |
| 1164 | snd_power_unlock(card->snd_card); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1165 | |
| 1166 | /* we're going to block userspace touching us until resume completes */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1167 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1168 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 1169 | /* mute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1170 | for (i = 0; i < card->num_rtd; i++) { |
| 1171 | struct snd_soc_dai *dai = card->rtd[i].codec_dai; |
| 1172 | struct snd_soc_dai_driver *drv = dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1173 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1174 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1175 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1176 | continue; |
| 1177 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1178 | if (card->rtd[i].dai_link->dynamic) |
| 1179 | soc_dsp_be_digital_mute(&card->rtd[i], 1); |
| 1180 | else { |
| 1181 | if (drv->ops->digital_mute && dai->playback_active) |
| 1182 | drv->ops->digital_mute(dai, 1); |
| 1183 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 1186 | /* suspend all pcms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1187 | for (i = 0; i < card->num_rtd; i++) { |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1188 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1189 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1190 | continue; |
| 1191 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1192 | snd_pcm_suspend_all(card->rtd[i].pcm); |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1193 | } |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 1194 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1195 | if (card->suspend_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 1196 | card->suspend_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1197 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1198 | for (i = 0; i < card->num_rtd; i++) { |
| 1199 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 1200 | struct snd_soc_platform *platform = card->rtd[i].platform; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1201 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1202 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1203 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1204 | continue; |
| 1205 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1206 | if (card->rtd[i].dai_link->dynamic) { |
| 1207 | soc_dsp_be_cpu_dai_suspend(&card->rtd[i]); |
| 1208 | soc_dsp_be_platform_suspend(&card->rtd[i]); |
| 1209 | } else { |
| 1210 | if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control) |
| 1211 | cpu_dai->driver->suspend(cpu_dai); |
| 1212 | if (platform->driver->suspend && !platform->suspended) { |
| 1213 | platform->driver->suspend(cpu_dai); |
| 1214 | platform->suspended = 1; |
| 1215 | } |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 1216 | } |
| 1217 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1218 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1219 | /* close any waiting streams and save state */ |
| 1220 | for (i = 0; i < card->num_rtd; i++) { |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 1221 | flush_delayed_work_sync(&card->rtd[i].delayed_work); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1222 | card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1223 | } |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1224 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1225 | for (i = 0; i < card->num_rtd; i++) { |
| 1226 | struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; |
| 1227 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1228 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1229 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1230 | continue; |
| 1231 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1232 | if (driver->playback.stream_name != NULL) |
| 1233 | snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, |
| 1234 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 1235 | |
| 1236 | if (driver->capture.stream_name != NULL) |
| 1237 | snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, |
| 1238 | SND_SOC_DAPM_STREAM_SUSPEND); |
| 1239 | } |
| 1240 | |
| 1241 | /* suspend all CODECs */ |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1242 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1243 | /* If there are paths active then the CODEC will be held with |
| 1244 | * bias _ON and should not be suspended. */ |
| 1245 | if (!codec->suspended && codec->driver->suspend) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1246 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1247 | case SND_SOC_BIAS_STANDBY: |
| 1248 | case SND_SOC_BIAS_OFF: |
| 1249 | codec->driver->suspend(codec, PMSG_SUSPEND); |
| 1250 | codec->suspended = 1; |
Mark Brown | d2f9cb3 | 2011-07-18 13:17:13 +0900 | [diff] [blame] | 1251 | codec->cache_sync = 1; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1252 | break; |
| 1253 | default: |
| 1254 | dev_dbg(codec->dev, "CODEC is on over suspend\n"); |
| 1255 | break; |
| 1256 | } |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | for (i = 0; i < card->num_rtd; i++) { |
| 1261 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 1262 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1263 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1264 | card->rtd[i].dai_link->no_pcm) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1265 | continue; |
| 1266 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1267 | if (card->rtd[i].dai_link->dynamic) |
| 1268 | soc_dsp_be_ac97_cpu_dai_suspend(&card->rtd[i]); |
| 1269 | else |
| 1270 | if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control) |
| 1271 | cpu_dai->driver->suspend(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1272 | } |
| 1273 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1274 | if (card->suspend_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 1275 | card->suspend_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1276 | |
| 1277 | return 0; |
| 1278 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1279 | EXPORT_SYMBOL_GPL(snd_soc_suspend); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1280 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1281 | /* deferred resume work, so resume can complete before we finished |
| 1282 | * setting our codec back up, which can be very slow on I2C |
| 1283 | */ |
| 1284 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1285 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1286 | struct snd_soc_card *card = |
| 1287 | container_of(work, struct snd_soc_card, deferred_resume_work); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1288 | struct snd_soc_codec *codec; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1289 | int i; |
| 1290 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1291 | /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
| 1292 | * so userspace apps are blocked from touching us |
| 1293 | */ |
| 1294 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1295 | dev_dbg(card->dev, "starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1296 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1297 | /* Bring us up into D2 so that DAPM starts enabling things */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1298 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1299 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1300 | if (card->resume_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 1301 | card->resume_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1302 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1303 | /* resume AC97 DAIs */ |
| 1304 | for (i = 0; i < card->num_rtd; i++) { |
| 1305 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1306 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1307 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1308 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1309 | continue; |
| 1310 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1311 | if (card->rtd[i].dai_link->dynamic) |
| 1312 | soc_dsp_be_ac97_cpu_dai_resume(&card->rtd[i]); |
| 1313 | else |
| 1314 | if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control) |
| 1315 | cpu_dai->driver->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1316 | } |
| 1317 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1318 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1319 | /* If the CODEC was idle over suspend then it will have been |
| 1320 | * left with bias OFF or STANDBY and suspended so we must now |
| 1321 | * resume. Otherwise the suspend was suppressed. |
| 1322 | */ |
| 1323 | if (codec->driver->resume && codec->suspended) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1324 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1325 | case SND_SOC_BIAS_STANDBY: |
| 1326 | case SND_SOC_BIAS_OFF: |
| 1327 | codec->driver->resume(codec); |
| 1328 | codec->suspended = 0; |
| 1329 | break; |
| 1330 | default: |
| 1331 | dev_dbg(codec->dev, "CODEC was on over suspend\n"); |
| 1332 | break; |
| 1333 | } |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 1334 | } |
| 1335 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1336 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1337 | for (i = 0; i < card->num_rtd; i++) { |
| 1338 | struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1339 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1340 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1341 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1342 | continue; |
| 1343 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1344 | if (driver->playback.stream_name != NULL) |
| 1345 | snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1346 | SND_SOC_DAPM_STREAM_RESUME); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1347 | |
| 1348 | if (driver->capture.stream_name != NULL) |
| 1349 | snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1350 | SND_SOC_DAPM_STREAM_RESUME); |
| 1351 | } |
| 1352 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 1353 | /* unmute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1354 | for (i = 0; i < card->num_rtd; i++) { |
| 1355 | struct snd_soc_dai *dai = card->rtd[i].codec_dai; |
| 1356 | struct snd_soc_dai_driver *drv = dai->driver; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1357 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1358 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1359 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1360 | continue; |
| 1361 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1362 | if (card->rtd[i].dai_link->dynamic) |
| 1363 | soc_dsp_be_digital_mute(&card->rtd[i], 0); |
| 1364 | else { |
| 1365 | if (drv->ops->digital_mute && dai->playback_active) |
| 1366 | drv->ops->digital_mute(dai, 0); |
| 1367 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1368 | } |
| 1369 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1370 | for (i = 0; i < card->num_rtd; i++) { |
| 1371 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 1372 | struct snd_soc_platform *platform = card->rtd[i].platform; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1373 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1374 | if (card->rtd[i].dai_link->ignore_suspend || |
| 1375 | card->rtd[i].dai_link->no_pcm) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 1376 | continue; |
| 1377 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1378 | if (card->rtd[i].dai_link->dynamic) { |
| 1379 | soc_dsp_be_cpu_dai_resume(&card->rtd[i]); |
| 1380 | soc_dsp_be_platform_resume(&card->rtd[i]); |
| 1381 | } else { |
| 1382 | if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control) |
| 1383 | cpu_dai->driver->resume(cpu_dai); |
| 1384 | if (platform->driver->resume && platform->suspended) { |
| 1385 | platform->driver->resume(cpu_dai); |
| 1386 | platform->suspended = 0; |
| 1387 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1388 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1391 | if (card->resume_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 1392 | card->resume_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1393 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1394 | dev_dbg(card->dev, "resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1395 | |
| 1396 | /* userspace can access us now we are back as we were before */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1397 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /* powers up audio subsystem after a suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1401 | int snd_soc_resume(struct device *dev) |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1402 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1403 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Stephen Warren | 390f202 | 2011-06-10 20:15:21 -0700 | [diff] [blame] | 1404 | int i, ac97_control = 0; |
Peter Ujfalusi | b9dd94a | 2010-02-22 13:27:13 +0200 | [diff] [blame] | 1405 | |
Kuirong Wang | 5ab054f | 2012-02-29 16:09:09 -0800 | [diff] [blame] | 1406 | if (!card->instantiated) { |
| 1407 | dev_dbg(card->dev, "uninsantiated card found card->name = %s\n", |
| 1408 | card->name); |
| 1409 | return 0; |
| 1410 | } |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 1411 | /* AC97 devices might have other drivers hanging off them so |
| 1412 | * need to resume immediately. Other drivers don't have that |
| 1413 | * problem and may take a substantial amount of time to resume |
| 1414 | * due to I/O costs and anti-pop so handle them out of line. |
| 1415 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1416 | for (i = 0; i < card->num_rtd; i++) { |
| 1417 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Stephen Warren | 390f202 | 2011-06-10 20:15:21 -0700 | [diff] [blame] | 1418 | ac97_control |= cpu_dai->driver->ac97_control; |
| 1419 | } |
| 1420 | if (ac97_control) { |
| 1421 | dev_dbg(dev, "Resuming AC97 immediately\n"); |
| 1422 | soc_resume_deferred(&card->deferred_resume_work); |
| 1423 | } else { |
| 1424 | dev_dbg(dev, "Scheduling resume work\n"); |
| 1425 | if (!schedule_work(&card->deferred_resume_work)) |
| 1426 | dev_err(dev, "resume work item may be lost\n"); |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 1427 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1428 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1429 | return 0; |
| 1430 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1431 | EXPORT_SYMBOL_GPL(snd_soc_resume); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1432 | #else |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1433 | #define snd_soc_suspend NULL |
| 1434 | #define snd_soc_resume NULL |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1435 | #endif |
| 1436 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1437 | #define NULL_FORMATS \ |
| 1438 | (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 |\ |
| 1439 | SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 |\ |
| 1440 | SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32) |
| 1441 | |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 1442 | static struct snd_soc_dai_ops null_dai_ops = { |
| 1443 | }; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1444 | static struct snd_soc_dai_driver null_codec_dai_drv = { |
| 1445 | .name = "null-codec-dai", |
| 1446 | .ops = &null_dai_ops, |
| 1447 | .capture = { |
| 1448 | .channels_min = 1 , |
| 1449 | .channels_max = 16, |
| 1450 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 1451 | .formats = NULL_FORMATS, |
| 1452 | }, |
| 1453 | .playback = { |
| 1454 | .channels_min = 1 , |
| 1455 | .channels_max = 16, |
| 1456 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 1457 | .formats = NULL_FORMATS, |
| 1458 | }, |
| 1459 | }; |
| 1460 | static struct snd_soc_codec_driver null_codec_drv = {}; |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 1461 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1462 | 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] | 1463 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1464 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 1465 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1466 | struct snd_soc_codec *codec; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1467 | struct snd_soc_platform *platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1468 | struct snd_soc_dai *codec_dai, *cpu_dai; |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 1469 | const char *platform_name; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1470 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1471 | if (rtd->complete) |
| 1472 | return 1; |
| 1473 | 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] | 1474 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1475 | /* do we already have the CPU DAI for this link ? */ |
| 1476 | if (rtd->cpu_dai) { |
| 1477 | goto find_codec; |
| 1478 | } |
| 1479 | /* no, then find CPU DAI from registered DAIs*/ |
| 1480 | list_for_each_entry(cpu_dai, &dai_list, list) { |
| 1481 | if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1482 | rtd->cpu_dai = cpu_dai; |
| 1483 | goto find_codec; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1484 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1485 | } |
| 1486 | dev_dbg(card->dev, "CPU DAI %s not registered\n", |
| 1487 | dai_link->cpu_dai_name); |
| 1488 | |
| 1489 | find_codec: |
| 1490 | /* do we already have the CODEC for this link ? */ |
| 1491 | if (rtd->codec) { |
| 1492 | goto find_platform; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1495 | /* no, then find CODEC from registered CODECs*/ |
| 1496 | list_for_each_entry(codec, &codec_list, list) { |
| 1497 | if (!strcmp(codec->name, dai_link->codec_name)) { |
| 1498 | rtd->codec = codec; |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1499 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1500 | /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/ |
| 1501 | list_for_each_entry(codec_dai, &dai_list, list) { |
Liam Girdwood | bfe7dc4 | 2011-01-31 21:26:35 +0000 | [diff] [blame] | 1502 | if ((codec->dev == codec_dai->dev || codec->driver == &null_codec_drv) && |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1503 | !strcmp(codec_dai->name, dai_link->codec_dai_name)) { |
| 1504 | rtd->codec_dai = codec_dai; |
| 1505 | goto find_platform; |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1506 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1507 | } |
| 1508 | dev_dbg(card->dev, "CODEC DAI %s not registered\n", |
| 1509 | dai_link->codec_dai_name); |
| 1510 | |
| 1511 | goto find_platform; |
| 1512 | } |
| 1513 | } |
| 1514 | dev_dbg(card->dev, "CODEC %s not registered\n", |
| 1515 | dai_link->codec_name); |
| 1516 | |
| 1517 | find_platform: |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 1518 | /* do we need a platform? */ |
| 1519 | if (rtd->platform) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1520 | goto out; |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 1521 | |
| 1522 | /* if there's no platform we match on the empty platform */ |
| 1523 | platform_name = dai_link->platform_name; |
| 1524 | if (!platform_name) |
| 1525 | platform_name = "snd-soc-dummy"; |
| 1526 | |
| 1527 | /* no, then find one from the set of registered platforms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1528 | list_for_each_entry(platform, &platform_list, list) { |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 1529 | if (!strcmp(platform->name, platform_name)) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1530 | rtd->platform = platform; |
| 1531 | goto out; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | dev_dbg(card->dev, "platform %s not registered\n", |
| 1536 | dai_link->platform_name); |
| 1537 | return 0; |
| 1538 | |
| 1539 | out: |
| 1540 | /* mark rtd as complete if we found all 4 of our client devices */ |
| 1541 | if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) { |
| 1542 | rtd->complete = 1; |
| 1543 | card->num_rtd++; |
| 1544 | } |
| 1545 | return 1; |
| 1546 | } |
| 1547 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1548 | static void soc_remove_codec(struct snd_soc_codec *codec) |
| 1549 | { |
| 1550 | int err; |
| 1551 | |
| 1552 | if (codec->driver->remove) { |
| 1553 | err = codec->driver->remove(codec); |
| 1554 | if (err < 0) |
| 1555 | dev_err(codec->dev, |
| 1556 | "asoc: failed to remove %s: %d\n", |
| 1557 | codec->name, err); |
| 1558 | } |
| 1559 | |
| 1560 | /* Make sure all DAPM widgets are freed */ |
| 1561 | snd_soc_dapm_free(&codec->dapm); |
| 1562 | |
| 1563 | soc_cleanup_codec_debugfs(codec); |
| 1564 | codec->probed = 0; |
| 1565 | list_del(&codec->card_list); |
| 1566 | module_put(codec->dev->driver->owner); |
| 1567 | } |
| 1568 | |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1569 | static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1570 | { |
| 1571 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 1572 | struct snd_soc_codec *codec = rtd->codec; |
| 1573 | struct snd_soc_platform *platform = rtd->platform; |
| 1574 | struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; |
| 1575 | int err; |
| 1576 | |
| 1577 | /* unregister the rtd device */ |
| 1578 | if (rtd->dev_registered) { |
| 1579 | device_remove_file(&rtd->dev, &dev_attr_pmdown_time); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1580 | device_remove_file(&rtd->dev, &dev_attr_codec_reg); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1581 | device_unregister(&rtd->dev); |
| 1582 | rtd->dev_registered = 0; |
| 1583 | } |
| 1584 | |
| 1585 | /* remove the CODEC DAI */ |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1586 | if (codec_dai && codec_dai->probed && |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1587 | codec_dai->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1588 | if (codec_dai->driver->remove) { |
| 1589 | err = codec_dai->driver->remove(codec_dai); |
| 1590 | if (err < 0) |
| 1591 | printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name); |
| 1592 | } |
| 1593 | codec_dai->probed = 0; |
| 1594 | list_del(&codec_dai->card_list); |
Liam Girdwood | c0b7972 | 2011-03-05 18:30:34 +0000 | [diff] [blame] | 1595 | module_put(codec_dai->dev->driver->owner); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | /* remove the platform */ |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1599 | if (platform && platform->probed && |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1600 | platform->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1601 | if (platform->driver->remove) { |
| 1602 | err = platform->driver->remove(platform); |
| 1603 | if (err < 0) |
| 1604 | printk(KERN_ERR "asoc: failed to remove %s\n", platform->name); |
| 1605 | } |
| 1606 | platform->probed = 0; |
| 1607 | list_del(&platform->card_list); |
| 1608 | module_put(platform->dev->driver->owner); |
| 1609 | } |
| 1610 | |
| 1611 | /* remove the CODEC */ |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1612 | if (codec && codec->probed && |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1613 | codec->driver->remove_order == order) |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1614 | soc_remove_codec(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1615 | |
| 1616 | /* remove the cpu_dai */ |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1617 | if (cpu_dai && cpu_dai->probed && |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1618 | cpu_dai->driver->remove_order == order) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1619 | if (cpu_dai->driver->remove) { |
| 1620 | err = cpu_dai->driver->remove(cpu_dai); |
| 1621 | if (err < 0) |
| 1622 | printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name); |
| 1623 | } |
| 1624 | cpu_dai->probed = 0; |
| 1625 | list_del(&cpu_dai->card_list); |
| 1626 | module_put(cpu_dai->dev->driver->owner); |
| 1627 | } |
| 1628 | } |
| 1629 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1630 | static void soc_remove_dai_links(struct snd_soc_card *card) |
| 1631 | { |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1632 | int dai, order; |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1633 | |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1634 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1635 | order++) { |
| 1636 | for (dai = 0; dai < card->num_rtd; dai++) |
| 1637 | soc_remove_dai_link(card, dai, order); |
| 1638 | } |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1639 | card->num_rtd = 0; |
| 1640 | } |
| 1641 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1642 | static void soc_set_name_prefix(struct snd_soc_card *card, |
| 1643 | struct snd_soc_codec *codec) |
| 1644 | { |
| 1645 | int i; |
| 1646 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1647 | if (card->codec_conf == NULL) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1648 | return; |
| 1649 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1650 | for (i = 0; i < card->num_configs; i++) { |
| 1651 | struct snd_soc_codec_conf *map = &card->codec_conf[i]; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1652 | if (map->dev_name && !strcmp(codec->name, map->dev_name)) { |
| 1653 | codec->name_prefix = map->name_prefix; |
| 1654 | break; |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1659 | static int soc_probe_codec(struct snd_soc_card *card, |
| 1660 | struct snd_soc_codec *codec) |
| 1661 | { |
| 1662 | int ret = 0; |
Mark Brown | 89b95ac | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1663 | const struct snd_soc_codec_driver *driver = codec->driver; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1664 | |
| 1665 | codec->card = card; |
| 1666 | codec->dapm.card = card; |
| 1667 | soc_set_name_prefix(card, codec); |
| 1668 | |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1669 | if (!try_module_get(codec->dev->driver->owner)) |
| 1670 | return -ENODEV; |
| 1671 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1672 | soc_init_codec_debugfs(codec); |
| 1673 | |
Lars-Peter Clausen | 7753015 | 2011-05-05 16:59:09 +0200 | [diff] [blame] | 1674 | if (driver->dapm_widgets) |
| 1675 | snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets, |
| 1676 | driver->num_dapm_widgets); |
| 1677 | |
Mark Brown | 89b95ac | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1678 | if (driver->probe) { |
| 1679 | ret = driver->probe(codec); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1680 | if (ret < 0) { |
| 1681 | dev_err(codec->dev, |
| 1682 | "asoc: failed to probe CODEC %s: %d\n", |
| 1683 | codec->name, ret); |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1684 | goto err_probe; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1685 | } |
| 1686 | } |
| 1687 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1688 | if (driver->controls) |
| 1689 | snd_soc_add_controls(codec, driver->controls, |
| 1690 | driver->num_controls); |
Mark Brown | 89b95ac | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1691 | if (driver->dapm_routes) |
| 1692 | snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes, |
| 1693 | driver->num_dapm_routes); |
| 1694 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1695 | /* mark codec as probed and add to card codec list */ |
| 1696 | codec->probed = 1; |
| 1697 | list_add(&codec->card_list, &card->codec_dev_list); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1698 | list_add(&codec->dapm.list, &card->dapm_list); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1699 | |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1700 | return 0; |
| 1701 | |
| 1702 | err_probe: |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1703 | soc_cleanup_codec_debugfs(codec); |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1704 | module_put(codec->dev->driver->owner); |
| 1705 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1706 | return ret; |
| 1707 | } |
| 1708 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1709 | static void rtd_release(struct device *dev) {} |
| 1710 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1711 | static int soc_post_component_init(struct snd_soc_card *card, |
| 1712 | struct snd_soc_codec *codec, |
| 1713 | int num, int dailess) |
| 1714 | { |
| 1715 | struct snd_soc_dai_link *dai_link = NULL; |
| 1716 | struct snd_soc_aux_dev *aux_dev = NULL; |
| 1717 | struct snd_soc_pcm_runtime *rtd; |
| 1718 | const char *temp, *name; |
| 1719 | int ret = 0; |
| 1720 | |
| 1721 | if (!dailess) { |
| 1722 | dai_link = &card->dai_link[num]; |
| 1723 | rtd = &card->rtd[num]; |
| 1724 | name = dai_link->name; |
| 1725 | } else { |
| 1726 | aux_dev = &card->aux_dev[num]; |
| 1727 | rtd = &card->rtd_aux[num]; |
| 1728 | name = aux_dev->name; |
| 1729 | } |
Janusz Krzysztofik | 0962bb2 | 2011-02-02 21:11:41 +0100 | [diff] [blame] | 1730 | rtd->card = card; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1731 | |
| 1732 | /* machine controls, routes and widgets are not prefixed */ |
| 1733 | temp = codec->name_prefix; |
| 1734 | codec->name_prefix = NULL; |
| 1735 | |
| 1736 | /* do machine specific initialization */ |
| 1737 | if (!dailess && dai_link->init) |
| 1738 | ret = dai_link->init(rtd); |
| 1739 | else if (dailess && aux_dev->init) |
| 1740 | ret = aux_dev->init(&codec->dapm); |
| 1741 | if (ret < 0) { |
| 1742 | dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret); |
| 1743 | return ret; |
| 1744 | } |
| 1745 | codec->name_prefix = temp; |
| 1746 | |
| 1747 | /* Make sure all DAPM widgets are instantiated */ |
| 1748 | snd_soc_dapm_new_widgets(&codec->dapm); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1749 | |
| 1750 | /* register the rtd device */ |
| 1751 | rtd->codec = codec; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1752 | rtd->dev.parent = card->dev; |
| 1753 | rtd->dev.release = rtd_release; |
| 1754 | rtd->dev.init_name = name; |
Liam Girdwood | 0f8bae9 | 2011-01-27 19:35:01 +0000 | [diff] [blame] | 1755 | mutex_init(&rtd->pcm_mutex); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1756 | INIT_LIST_HEAD(&rtd->dsp[SNDRV_PCM_STREAM_PLAYBACK].be_clients); |
| 1757 | INIT_LIST_HEAD(&rtd->dsp[SNDRV_PCM_STREAM_CAPTURE].be_clients); |
| 1758 | INIT_LIST_HEAD(&rtd->dsp[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); |
| 1759 | INIT_LIST_HEAD(&rtd->dsp[SNDRV_PCM_STREAM_CAPTURE].fe_clients); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1760 | ret = device_register(&rtd->dev); |
| 1761 | if (ret < 0) { |
| 1762 | dev_err(card->dev, |
| 1763 | "asoc: failed to register runtime device: %d\n", ret); |
| 1764 | return ret; |
| 1765 | } |
| 1766 | rtd->dev_registered = 1; |
| 1767 | |
| 1768 | /* add DAPM sysfs entries for this codec */ |
| 1769 | ret = snd_soc_dapm_sys_add(&rtd->dev); |
| 1770 | if (ret < 0) |
| 1771 | dev_err(codec->dev, |
| 1772 | "asoc: failed to add codec dapm sysfs entries: %d\n", |
| 1773 | ret); |
| 1774 | |
| 1775 | /* add codec sysfs entries */ |
| 1776 | ret = device_create_file(&rtd->dev, &dev_attr_codec_reg); |
| 1777 | if (ret < 0) |
| 1778 | dev_err(codec->dev, |
| 1779 | "asoc: failed to add codec sysfs files: %d\n", ret); |
| 1780 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 1781 | #ifdef CONFIG_DEBUG_FS |
| 1782 | /* add DSP sysfs entries */ |
| 1783 | if (!dai_link->dynamic) |
| 1784 | goto out; |
| 1785 | |
| 1786 | ret = soc_dsp_debugfs_add(rtd); |
| 1787 | if (ret < 0) |
| 1788 | dev_err(&rtd->dev, "asoc: failed to add dsp sysfs entries: %d\n", ret); |
| 1789 | |
| 1790 | out: |
| 1791 | #endif |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1792 | return 0; |
| 1793 | } |
| 1794 | |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1795 | static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1796 | { |
| 1797 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 1798 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 1799 | struct snd_soc_codec *codec = rtd->codec; |
| 1800 | struct snd_soc_platform *platform = rtd->platform; |
| 1801 | struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; |
| 1802 | int ret; |
| 1803 | |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1804 | dev_dbg(card->dev, "probe %s dai link %d late %d\n", |
| 1805 | card->name, num, order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1806 | |
| 1807 | /* config components */ |
| 1808 | codec_dai->codec = codec; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1809 | cpu_dai->platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1810 | codec_dai->card = card; |
| 1811 | cpu_dai->card = card; |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 1812 | codec->dapm.card = platform->dapm.card = card; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1813 | |
| 1814 | /* set default power off timeout */ |
| 1815 | rtd->pmdown_time = pmdown_time; |
| 1816 | |
| 1817 | /* probe the cpu_dai */ |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1818 | if (!cpu_dai->probed && |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1819 | cpu_dai->driver->probe_order == order) { |
Liam Girdwood | 61b61e3 | 2011-05-24 13:57:43 +0100 | [diff] [blame] | 1820 | if (!try_module_get(cpu_dai->dev->driver->owner)) |
| 1821 | return -ENODEV; |
| 1822 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1823 | if (cpu_dai->driver->probe) { |
| 1824 | ret = cpu_dai->driver->probe(cpu_dai); |
| 1825 | if (ret < 0) { |
| 1826 | printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n", |
| 1827 | cpu_dai->name); |
Liam Girdwood | 61b61e3 | 2011-05-24 13:57:43 +0100 | [diff] [blame] | 1828 | module_put(cpu_dai->dev->driver->owner); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1829 | return ret; |
| 1830 | } |
| 1831 | } |
| 1832 | cpu_dai->probed = 1; |
| 1833 | /* mark cpu_dai as probed and add to card cpu_dai list */ |
| 1834 | list_add(&cpu_dai->card_list, &card->dai_dev_list); |
| 1835 | } |
| 1836 | |
| 1837 | /* probe the CODEC */ |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1838 | if (!codec->probed && |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1839 | codec->driver->probe_order == order) { |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1840 | ret = soc_probe_codec(card, codec); |
| 1841 | if (ret < 0) |
| 1842 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | /* probe the platform */ |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1846 | if (!platform->probed && |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1847 | platform->driver->probe_order == order) { |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1848 | if (!try_module_get(platform->dev->driver->owner)) |
| 1849 | return -ENODEV; |
| 1850 | |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 1851 | platform->card = card; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1852 | if (platform->driver->probe) { |
| 1853 | ret = platform->driver->probe(platform); |
| 1854 | if (ret < 0) { |
| 1855 | printk(KERN_ERR "asoc: failed to probe platform %s\n", |
| 1856 | platform->name); |
Jarkko Nikula | 70d29331 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1857 | module_put(platform->dev->driver->owner); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1858 | return ret; |
| 1859 | } |
| 1860 | } |
| 1861 | /* mark platform as probed and add to card platform list */ |
| 1862 | platform->probed = 1; |
| 1863 | list_add(&platform->card_list, &card->platform_dev_list); |
| 1864 | } |
| 1865 | |
| 1866 | /* probe the CODEC DAI */ |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1867 | if (!codec_dai->probed && codec_dai->driver->probe_order == order) { |
Liam Girdwood | c0b7972 | 2011-03-05 18:30:34 +0000 | [diff] [blame] | 1868 | if (!try_module_get(codec_dai->dev->driver->owner)) |
| 1869 | return -ENODEV; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1870 | if (codec_dai->driver->probe) { |
| 1871 | ret = codec_dai->driver->probe(codec_dai); |
| 1872 | if (ret < 0) { |
| 1873 | printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n", |
| 1874 | codec_dai->name); |
Liam Girdwood | c0b7972 | 2011-03-05 18:30:34 +0000 | [diff] [blame] | 1875 | module_put(codec_dai->dev->driver->owner); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1876 | return ret; |
Mark Brown | 6b05eda | 2008-12-08 19:26:48 +0000 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1880 | /* mark cpu_dai as probed and add to card cpu_dai list */ |
| 1881 | codec_dai->probed = 1; |
| 1882 | list_add(&codec_dai->card_list, &card->dai_dev_list); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1883 | } |
| 1884 | |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 1885 | /* complete DAI probe during last probe */ |
| 1886 | if (order != SND_SOC_COMP_ORDER_LAST) |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 1887 | return 0; |
| 1888 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1889 | /* DAPM dai link stream work */ |
| 1890 | INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); |
| 1891 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1892 | ret = soc_post_component_init(card, codec, num, 0); |
| 1893 | if (ret) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1894 | return ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1895 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1896 | ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time); |
| 1897 | if (ret < 0) |
| 1898 | printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n"); |
| 1899 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1900 | /* create the pcm */ |
| 1901 | ret = soc_new_pcm(rtd, num); |
| 1902 | if (ret < 0) { |
| 1903 | printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name); |
| 1904 | return ret; |
| 1905 | } |
| 1906 | |
| 1907 | /* add platform data for AC97 devices */ |
| 1908 | if (rtd->codec_dai->driver->ac97_control) |
| 1909 | snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); |
| 1910 | |
| 1911 | return 0; |
| 1912 | } |
| 1913 | |
| 1914 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 1915 | static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) |
| 1916 | { |
| 1917 | int ret; |
| 1918 | |
| 1919 | /* Only instantiate AC97 if not already done by the adaptor |
| 1920 | * for the generic AC97 subsystem. |
| 1921 | */ |
| 1922 | if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) { |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 1923 | /* |
| 1924 | * It is possible that the AC97 device is already registered to |
| 1925 | * the device subsystem. This happens when the device is created |
| 1926 | * via snd_ac97_mixer(). Currently only SoC codec that does so |
| 1927 | * is the generic AC97 glue but others migh emerge. |
| 1928 | * |
| 1929 | * In those cases we don't try to register the device again. |
| 1930 | */ |
| 1931 | if (!rtd->codec->ac97_created) |
| 1932 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1933 | |
| 1934 | ret = soc_ac97_dev_register(rtd->codec); |
| 1935 | if (ret < 0) { |
| 1936 | printk(KERN_ERR "asoc: AC97 device register failed\n"); |
| 1937 | return ret; |
| 1938 | } |
| 1939 | |
| 1940 | rtd->codec->ac97_registered = 1; |
| 1941 | } |
| 1942 | return 0; |
| 1943 | } |
| 1944 | |
| 1945 | static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec) |
| 1946 | { |
| 1947 | if (codec->ac97_registered) { |
| 1948 | soc_ac97_dev_unregister(codec); |
| 1949 | codec->ac97_registered = 0; |
| 1950 | } |
| 1951 | } |
| 1952 | #endif |
| 1953 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1954 | static int soc_probe_aux_dev(struct snd_soc_card *card, int num) |
| 1955 | { |
| 1956 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1957 | struct snd_soc_codec *codec; |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1958 | int ret = -ENODEV; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1959 | |
| 1960 | /* find CODEC from registered CODECs*/ |
| 1961 | list_for_each_entry(codec, &codec_list, list) { |
| 1962 | if (!strcmp(codec->name, aux_dev->codec_name)) { |
| 1963 | if (codec->probed) { |
| 1964 | dev_err(codec->dev, |
| 1965 | "asoc: codec already probed"); |
| 1966 | ret = -EBUSY; |
| 1967 | goto out; |
| 1968 | } |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1969 | goto found; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1970 | } |
| 1971 | } |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1972 | /* codec not found */ |
| 1973 | dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name); |
| 1974 | goto out; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1975 | |
Jarkko Nikula | 676ad98 | 2010-12-03 09:18:22 +0200 | [diff] [blame] | 1976 | found: |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1977 | ret = soc_probe_codec(card, codec); |
| 1978 | if (ret < 0) |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1979 | return ret; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1980 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1981 | ret = soc_post_component_init(card, codec, num, 1); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1982 | |
| 1983 | out: |
| 1984 | return ret; |
| 1985 | } |
| 1986 | |
| 1987 | static void soc_remove_aux_dev(struct snd_soc_card *card, int num) |
| 1988 | { |
| 1989 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
| 1990 | struct snd_soc_codec *codec = rtd->codec; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1991 | |
| 1992 | /* unregister the rtd device */ |
| 1993 | if (rtd->dev_registered) { |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1994 | device_remove_file(&rtd->dev, &dev_attr_codec_reg); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1995 | device_unregister(&rtd->dev); |
| 1996 | rtd->dev_registered = 0; |
| 1997 | } |
| 1998 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1999 | if (codec && codec->probed) |
| 2000 | soc_remove_codec(codec); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 2001 | } |
| 2002 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 2003 | static int snd_soc_init_codec_cache(struct snd_soc_codec *codec, |
| 2004 | enum snd_soc_compress_type compress_type) |
| 2005 | { |
| 2006 | int ret; |
| 2007 | |
| 2008 | if (codec->cache_init) |
| 2009 | return 0; |
| 2010 | |
| 2011 | /* override the compress_type if necessary */ |
| 2012 | if (compress_type && codec->compress_type != compress_type) |
| 2013 | codec->compress_type = compress_type; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 2014 | ret = snd_soc_cache_init(codec); |
| 2015 | if (ret < 0) { |
| 2016 | dev_err(codec->dev, "Failed to set cache compression type: %d\n", |
| 2017 | ret); |
| 2018 | return ret; |
| 2019 | } |
| 2020 | codec->cache_init = 1; |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2024 | static void snd_soc_instantiate_card(struct snd_soc_card *card) |
| 2025 | { |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 2026 | struct snd_soc_codec *codec; |
| 2027 | struct snd_soc_codec_conf *codec_conf; |
| 2028 | enum snd_soc_compress_type compress_type; |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 2029 | int ret, i, order; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2030 | |
| 2031 | mutex_lock(&card->mutex); |
| 2032 | |
| 2033 | if (card->instantiated) { |
| 2034 | mutex_unlock(&card->mutex); |
| 2035 | return; |
| 2036 | } |
| 2037 | |
| 2038 | /* bind DAIs */ |
| 2039 | for (i = 0; i < card->num_links; i++) |
| 2040 | soc_bind_dai_link(card, i); |
| 2041 | |
| 2042 | /* bind completed ? */ |
| 2043 | if (card->num_rtd != card->num_links) { |
| 2044 | mutex_unlock(&card->mutex); |
| 2045 | return; |
| 2046 | } |
| 2047 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 2048 | /* initialize the register cache for each available codec */ |
| 2049 | list_for_each_entry(codec, &codec_list, list) { |
| 2050 | if (codec->cache_init) |
| 2051 | continue; |
Dimitris Papastamos | 861f2fa | 2011-01-11 11:43:51 +0000 | [diff] [blame] | 2052 | /* by default we don't override the compress_type */ |
| 2053 | compress_type = 0; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 2054 | /* check to see if we need to override the compress_type */ |
| 2055 | for (i = 0; i < card->num_configs; ++i) { |
| 2056 | codec_conf = &card->codec_conf[i]; |
| 2057 | if (!strcmp(codec->name, codec_conf->dev_name)) { |
| 2058 | compress_type = codec_conf->compress_type; |
| 2059 | if (compress_type && compress_type |
| 2060 | != codec->compress_type) |
| 2061 | break; |
| 2062 | } |
| 2063 | } |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 2064 | ret = snd_soc_init_codec_cache(codec, compress_type); |
| 2065 | if (ret < 0) { |
| 2066 | mutex_unlock(&card->mutex); |
| 2067 | return; |
| 2068 | } |
| 2069 | } |
| 2070 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2071 | /* card bind complete so register a sound card */ |
| 2072 | ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
| 2073 | card->owner, 0, &card->snd_card); |
| 2074 | if (ret < 0) { |
| 2075 | printk(KERN_ERR "asoc: can't create sound card for card %s\n", |
| 2076 | card->name); |
| 2077 | mutex_unlock(&card->mutex); |
| 2078 | return; |
| 2079 | } |
| 2080 | card->snd_card->dev = card->dev; |
| 2081 | |
Mark Brown | e37a497 | 2011-03-02 18:21:57 +0000 | [diff] [blame] | 2082 | card->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 2083 | card->dapm.dev = card->dev; |
| 2084 | card->dapm.card = card; |
| 2085 | list_add(&card->dapm.list, &card->dapm_list); |
| 2086 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2087 | #ifdef CONFIG_DEBUG_FS |
| 2088 | snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); |
| 2089 | #endif |
| 2090 | |
Mark Brown | 88ee1c6 | 2011-02-02 10:43:26 +0000 | [diff] [blame] | 2091 | #ifdef CONFIG_PM_SLEEP |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 2092 | /* deferred resume work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 2093 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 2094 | #endif |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 2095 | |
Mark Brown | 9a841eb | 2011-04-12 17:51:37 -0700 | [diff] [blame] | 2096 | if (card->dapm_widgets) |
| 2097 | snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, |
| 2098 | card->num_dapm_widgets); |
| 2099 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2100 | /* initialise the sound card only once */ |
| 2101 | if (card->probe) { |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 2102 | ret = card->probe(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2103 | if (ret < 0) |
| 2104 | goto card_probe_error; |
| 2105 | } |
| 2106 | |
Liam Girdwood | 0218408 | 2011-03-30 23:26:53 +0100 | [diff] [blame] | 2107 | /* early DAI link probe */ |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 2108 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 2109 | order++) { |
| 2110 | for (i = 0; i < card->num_links; i++) { |
| 2111 | ret = soc_probe_dai_link(card, i, order); |
| 2112 | if (ret < 0) { |
| 2113 | pr_err("asoc: failed to instantiate card %s: %d\n", |
Mark Brown | 321de0d | 2010-09-21 15:09:37 +0100 | [diff] [blame] | 2114 | card->name, ret); |
Liam Girdwood | 6e30b2e | 2011-06-03 18:13:02 +0100 | [diff] [blame] | 2115 | goto probe_dai_err; |
| 2116 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 2120 | for (i = 0; i < card->num_aux_devs; i++) { |
| 2121 | ret = soc_probe_aux_dev(card, i); |
| 2122 | if (ret < 0) { |
| 2123 | pr_err("asoc: failed to add auxiliary devices %s: %d\n", |
| 2124 | card->name, ret); |
| 2125 | goto probe_aux_dev_err; |
| 2126 | } |
| 2127 | } |
| 2128 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 2129 | /* We should have a non-codec control add function but we don't */ |
| 2130 | if (card->controls) |
| 2131 | snd_soc_add_controls(list_first_entry(&card->codec_dev_list, |
| 2132 | struct snd_soc_codec, |
| 2133 | card_list), |
| 2134 | card->controls, |
| 2135 | card->num_controls); |
| 2136 | |
Mark Brown | b8ad29d | 2011-03-02 18:35:51 +0000 | [diff] [blame] | 2137 | if (card->dapm_routes) |
| 2138 | snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, |
| 2139 | card->num_dapm_routes); |
| 2140 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2141 | snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2142 | "%s", card->name); |
Liam Girdwood | 22de71b | 2011-05-12 16:14:04 +0100 | [diff] [blame] | 2143 | snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), |
| 2144 | "%s", card->long_name ? card->long_name : card->name); |
Mark Brown | 10f672f | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 2145 | snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), |
| 2146 | "%s", card->driver_name ? card->driver_name : card->name); |
| 2147 | for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { |
| 2148 | switch (card->snd_card->driver[i]) { |
| 2149 | case '_': |
| 2150 | case '-': |
| 2151 | case '\0': |
| 2152 | break; |
| 2153 | default: |
| 2154 | if (!isalnum(card->snd_card->driver[i])) |
| 2155 | card->snd_card->driver[i] = '_'; |
| 2156 | break; |
| 2157 | } |
| 2158 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2159 | |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 2160 | if (card->late_probe) { |
| 2161 | ret = card->late_probe(card); |
| 2162 | if (ret < 0) { |
| 2163 | dev_err(card->dev, "%s late_probe() failed: %d\n", |
| 2164 | card->name, ret); |
| 2165 | goto probe_aux_dev_err; |
| 2166 | } |
| 2167 | } |
| 2168 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2169 | ret = snd_card_register(card->snd_card); |
| 2170 | if (ret < 0) { |
| 2171 | printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 2172 | goto probe_aux_dev_err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 2176 | /* register any AC97 codecs */ |
| 2177 | for (i = 0; i < card->num_rtd; i++) { |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 2178 | ret = soc_register_ac97_dai_link(&card->rtd[i]); |
| 2179 | if (ret < 0) { |
| 2180 | printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name); |
| 2181 | while (--i >= 0) |
Mark Brown | 7d8316d | 2010-12-13 17:03:27 +0000 | [diff] [blame] | 2182 | soc_unregister_ac97_dai_link(card->rtd[i].codec); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 2183 | goto probe_aux_dev_err; |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 2184 | } |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 2185 | } |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 2186 | #endif |
| 2187 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2188 | card->instantiated = 1; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2189 | mutex_unlock(&card->mutex); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2190 | return; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2191 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 2192 | probe_aux_dev_err: |
| 2193 | for (i = 0; i < card->num_aux_devs; i++) |
| 2194 | soc_remove_aux_dev(card, i); |
| 2195 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2196 | probe_dai_err: |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 2197 | soc_remove_dai_links(card); |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 2198 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2199 | card_probe_error: |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 2200 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 2201 | card->remove(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2202 | |
| 2203 | snd_card_free(card->snd_card); |
| 2204 | |
| 2205 | mutex_unlock(&card->mutex); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2206 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2207 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2208 | /* |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 2209 | * Attempt to initialise any uninitialised cards. Must be called with |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2210 | * client_mutex. |
| 2211 | */ |
| 2212 | static void snd_soc_instantiate_cards(void) |
| 2213 | { |
| 2214 | struct snd_soc_card *card; |
| 2215 | list_for_each_entry(card, &card_list, list) |
| 2216 | snd_soc_instantiate_card(card); |
| 2217 | } |
| 2218 | |
| 2219 | /* probes a new socdev */ |
| 2220 | static int soc_probe(struct platform_device *pdev) |
| 2221 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2222 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2223 | int ret = 0; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2224 | |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2225 | /* |
| 2226 | * no card, so machine driver should be registering card |
| 2227 | * we should not be here in that case so ret error |
| 2228 | */ |
| 2229 | if (!card) |
| 2230 | return -EINVAL; |
| 2231 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2232 | /* Bodge while we unpick instantiation */ |
| 2233 | card->dev = &pdev->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2234 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2235 | ret = snd_soc_register_card(card); |
| 2236 | if (ret != 0) { |
| 2237 | dev_err(&pdev->dev, "Failed to register card\n"); |
| 2238 | return ret; |
| 2239 | } |
| 2240 | |
| 2241 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2242 | } |
| 2243 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 2244 | static int soc_cleanup_card_resources(struct snd_soc_card *card) |
| 2245 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 2246 | int i; |
| 2247 | |
| 2248 | /* make sure any delayed work runs */ |
| 2249 | for (i = 0; i < card->num_rtd; i++) { |
| 2250 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 2251 | flush_delayed_work_sync(&rtd->delayed_work); |
| 2252 | } |
| 2253 | |
| 2254 | /* remove auxiliary devices */ |
| 2255 | for (i = 0; i < card->num_aux_devs; i++) |
| 2256 | soc_remove_aux_dev(card, i); |
| 2257 | |
| 2258 | /* remove and free each DAI */ |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 2259 | soc_remove_dai_links(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 2260 | |
| 2261 | soc_cleanup_card_debugfs(card); |
| 2262 | |
| 2263 | /* remove the card */ |
| 2264 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 2265 | card->remove(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 2266 | |
Lars-Peter Clausen | 0aaae52 | 2011-04-30 19:45:47 +0200 | [diff] [blame] | 2267 | snd_soc_dapm_free(&card->dapm); |
| 2268 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 2269 | kfree(card->rtd); |
| 2270 | snd_card_free(card->snd_card); |
| 2271 | return 0; |
| 2272 | |
| 2273 | } |
| 2274 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2275 | /* removes a socdev */ |
| 2276 | static int soc_remove(struct platform_device *pdev) |
| 2277 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2278 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2279 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2280 | snd_soc_unregister_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2281 | return 0; |
| 2282 | } |
| 2283 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2284 | int snd_soc_poweroff(struct device *dev) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2285 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2286 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2287 | int i; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2288 | |
| 2289 | if (!card->instantiated) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2290 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2291 | |
| 2292 | /* Flush out pmdown_time work - we actually do want to run it |
| 2293 | * now, we're shutting down so no imminent restart. */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2294 | for (i = 0; i < card->num_rtd; i++) { |
| 2295 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 2296 | flush_delayed_work_sync(&rtd->delayed_work); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2297 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2298 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2299 | snd_soc_dapm_shutdown(card); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2300 | |
| 2301 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2302 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2303 | EXPORT_SYMBOL_GPL(snd_soc_poweroff); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2304 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2305 | const struct dev_pm_ops snd_soc_pm_ops = { |
| 2306 | .suspend = snd_soc_suspend, |
| 2307 | .resume = snd_soc_resume, |
| 2308 | .poweroff = snd_soc_poweroff, |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2309 | }; |
Stephen Warren | deb2607 | 2011-04-05 19:35:30 -0600 | [diff] [blame] | 2310 | EXPORT_SYMBOL_GPL(snd_soc_pm_ops); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2311 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2312 | /* ASoC platform driver */ |
| 2313 | static struct platform_driver soc_driver = { |
| 2314 | .driver = { |
| 2315 | .name = "soc-audio", |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 2316 | .owner = THIS_MODULE, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2317 | .pm = &snd_soc_pm_ops, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2318 | }, |
| 2319 | .probe = soc_probe, |
| 2320 | .remove = soc_remove, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2321 | }; |
| 2322 | |
| 2323 | /* create a new pcm */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2324 | 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] | 2325 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2326 | struct snd_soc_codec *codec = rtd->codec; |
| 2327 | struct snd_soc_platform *platform = rtd->platform; |
| 2328 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 2329 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2330 | struct snd_pcm_substream *substream[2]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2331 | struct snd_pcm *pcm; |
| 2332 | char new_name[64]; |
| 2333 | int ret = 0, playback = 0, capture = 0; |
| 2334 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2335 | /* check client and interface hw capabilities */ |
Mark Brown | 40ca114 | 2009-12-24 13:44:28 +0000 | [diff] [blame] | 2336 | snprintf(new_name, sizeof(new_name), "%s %s-%d", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2337 | rtd->dai_link->stream_name, codec_dai->name, num); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2338 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2339 | if (rtd->dai_link->dynamic) { |
Liam Girdwood | a42d64d | 2011-06-03 14:26:07 +0100 | [diff] [blame] | 2340 | playback = rtd->dai_link->dsp_link->playback; |
| 2341 | capture = rtd->dai_link->dsp_link->capture; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2342 | } else { |
| 2343 | if (codec_dai->driver->playback.channels_min) |
| 2344 | playback = 1; |
| 2345 | if (codec_dai->driver->capture.channels_min) |
| 2346 | capture = 1; |
| 2347 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2348 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2349 | dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num,new_name); |
| 2350 | ret = snd_pcm_new(rtd->card->snd_card, new_name, |
| 2351 | num, playback, capture, &pcm); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2352 | if (ret < 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2353 | 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] | 2354 | return ret; |
| 2355 | } |
| 2356 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2357 | rtd->pcm = pcm; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2358 | pcm->private_data = rtd; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2359 | |
| 2360 | substream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 2361 | pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; |
| 2362 | substream[SNDRV_PCM_STREAM_CAPTURE] = |
| 2363 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; |
| 2364 | |
| 2365 | if (rtd->dai_link->no_pcm) { |
| 2366 | if (playback) |
| 2367 | substream[SNDRV_PCM_STREAM_PLAYBACK]->private_data = rtd; |
| 2368 | if (capture) |
| 2369 | substream[SNDRV_PCM_STREAM_CAPTURE]->private_data = rtd; |
| 2370 | goto out; |
| 2371 | } |
| 2372 | |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 2373 | /* setup any hostless PCMs - i.e. no host IO is performed */ |
| 2374 | if (rtd->dai_link->no_host_mode) { |
Patrick Lai | 3f78c4b | 2011-05-25 17:07:53 -0700 | [diff] [blame] | 2375 | if (substream[SNDRV_PCM_STREAM_PLAYBACK]) { |
| 2376 | substream[SNDRV_PCM_STREAM_PLAYBACK]->hw_no_buffer = 1; |
| 2377 | snd_soc_set_runtime_hwparams( |
| 2378 | substream[SNDRV_PCM_STREAM_PLAYBACK], |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 2379 | &no_host_hardware); |
Patrick Lai | 3f78c4b | 2011-05-25 17:07:53 -0700 | [diff] [blame] | 2380 | } |
| 2381 | if (substream[SNDRV_PCM_STREAM_CAPTURE]) { |
| 2382 | substream[SNDRV_PCM_STREAM_CAPTURE]->hw_no_buffer = 1; |
| 2383 | snd_soc_set_runtime_hwparams( |
| 2384 | substream[SNDRV_PCM_STREAM_CAPTURE], |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 2385 | &no_host_hardware); |
Patrick Lai | 3f78c4b | 2011-05-25 17:07:53 -0700 | [diff] [blame] | 2386 | } |
Liam Girdwood | f320fdd | 2011-02-01 21:31:50 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2389 | /* ASoC PCM operations */ |
| 2390 | if (rtd->dai_link->dynamic) { |
| 2391 | rtd->ops.open = soc_dsp_fe_dai_open; |
| 2392 | rtd->ops.hw_params = soc_dsp_fe_dai_hw_params; |
| 2393 | rtd->ops.prepare = soc_dsp_fe_dai_prepare; |
| 2394 | rtd->ops.trigger = soc_dsp_fe_dai_trigger; |
| 2395 | rtd->ops.hw_free = soc_dsp_fe_dai_hw_free; |
| 2396 | rtd->ops.close = soc_dsp_fe_dai_close; |
| 2397 | rtd->ops.pointer = soc_pcm_pointer; |
| 2398 | rtd->ops.ioctl = soc_pcm_ioctl; |
| 2399 | } else { |
| 2400 | rtd->ops.open = soc_pcm_open; |
| 2401 | rtd->ops.hw_params = soc_pcm_hw_params; |
| 2402 | rtd->ops.prepare = soc_pcm_prepare; |
| 2403 | rtd->ops.trigger = soc_pcm_trigger; |
| 2404 | rtd->ops.hw_free = soc_pcm_hw_free; |
| 2405 | rtd->ops.close = soc_pcm_close; |
| 2406 | rtd->ops.pointer = soc_pcm_pointer; |
| 2407 | rtd->ops.ioctl = soc_pcm_ioctl; |
| 2408 | } |
| 2409 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 2410 | if (platform->driver->ops) { |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2411 | rtd->ops.ack = platform->driver->ops->ack; |
| 2412 | rtd->ops.copy = platform->driver->ops->copy; |
| 2413 | rtd->ops.silence = platform->driver->ops->silence; |
| 2414 | rtd->ops.page = platform->driver->ops->page; |
| 2415 | rtd->ops.mmap = platform->driver->ops->mmap; |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 2416 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2417 | |
| 2418 | if (playback) |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2419 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2420 | |
| 2421 | if (capture) |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2422 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2423 | |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 2424 | if (platform->driver->pcm_new) { |
Liam Girdwood | c6ac984 | 2011-02-04 22:12:30 +0000 | [diff] [blame] | 2425 | ret = platform->driver->pcm_new(rtd); |
Mark Brown | 8842c72 | 2011-04-27 18:58:17 +0100 | [diff] [blame] | 2426 | if (ret < 0) { |
| 2427 | pr_err("asoc: platform pcm constructor failed\n"); |
| 2428 | return ret; |
| 2429 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2430 | } |
| 2431 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2432 | pcm->private_free = platform->driver->pcm_free; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2433 | out: |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2434 | printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name, |
| 2435 | cpu_dai->name); |
| 2436 | return ret; |
| 2437 | } |
| 2438 | |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 2439 | /** |
| 2440 | * snd_soc_codec_volatile_register: Report if a register is volatile. |
| 2441 | * |
| 2442 | * @codec: CODEC to query. |
| 2443 | * @reg: Register to query. |
| 2444 | * |
| 2445 | * Boolean function indiciating if a CODEC register is volatile. |
| 2446 | */ |
Mark Brown | 181e055 | 2011-01-24 14:05:25 +0000 | [diff] [blame] | 2447 | int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, |
| 2448 | unsigned int reg) |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 2449 | { |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 2450 | if (codec->volatile_register) |
| 2451 | return codec->volatile_register(codec, reg); |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 2452 | else |
| 2453 | return 0; |
| 2454 | } |
| 2455 | EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register); |
| 2456 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2457 | /** |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 2458 | * snd_soc_codec_readable_register: Report if a register is readable. |
| 2459 | * |
| 2460 | * @codec: CODEC to query. |
| 2461 | * @reg: Register to query. |
| 2462 | * |
| 2463 | * Boolean function indicating if a CODEC register is readable. |
| 2464 | */ |
| 2465 | int snd_soc_codec_readable_register(struct snd_soc_codec *codec, |
| 2466 | unsigned int reg) |
| 2467 | { |
| 2468 | if (codec->readable_register) |
| 2469 | return codec->readable_register(codec, reg); |
| 2470 | else |
| 2471 | return 0; |
| 2472 | } |
| 2473 | EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register); |
| 2474 | |
| 2475 | /** |
| 2476 | * snd_soc_codec_writable_register: Report if a register is writable. |
| 2477 | * |
| 2478 | * @codec: CODEC to query. |
| 2479 | * @reg: Register to query. |
| 2480 | * |
| 2481 | * Boolean function indicating if a CODEC register is writable. |
| 2482 | */ |
| 2483 | int snd_soc_codec_writable_register(struct snd_soc_codec *codec, |
| 2484 | unsigned int reg) |
| 2485 | { |
| 2486 | if (codec->writable_register) |
| 2487 | return codec->writable_register(codec, reg); |
| 2488 | else |
| 2489 | return 0; |
| 2490 | } |
| 2491 | EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register); |
| 2492 | |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 2493 | unsigned int snd_soc_platform_read(struct snd_soc_platform *platform, |
| 2494 | unsigned int reg) |
| 2495 | { |
| 2496 | unsigned int ret; |
| 2497 | |
| 2498 | ret = platform->driver->read(platform, reg); |
| 2499 | dev_dbg(platform->dev, "read %x => %x\n", reg, ret); |
| 2500 | trace_snd_soc_preg_read(platform, reg, ret); |
| 2501 | |
| 2502 | return ret; |
| 2503 | } |
| 2504 | EXPORT_SYMBOL_GPL(snd_soc_platform_read); |
| 2505 | |
| 2506 | unsigned int snd_soc_platform_write(struct snd_soc_platform *platform, |
| 2507 | unsigned int reg, unsigned int val) |
| 2508 | { |
| 2509 | dev_dbg(platform->dev, "write %x = %x\n", reg, val); |
| 2510 | trace_snd_soc_preg_write(platform, reg, val); |
| 2511 | return platform->driver->write(platform, reg, val); |
| 2512 | } |
| 2513 | EXPORT_SYMBOL_GPL(snd_soc_platform_write); |
| 2514 | |
Dimitris Papastamos | 239c970 | 2011-03-24 13:45:18 +0000 | [diff] [blame] | 2515 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2516 | * snd_soc_new_ac97_codec - initailise AC97 device |
| 2517 | * @codec: audio codec |
| 2518 | * @ops: AC97 bus operations |
| 2519 | * @num: AC97 codec number |
| 2520 | * |
| 2521 | * Initialises AC97 codec resources for use by ad-hoc devices only. |
| 2522 | */ |
| 2523 | int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, |
| 2524 | struct snd_ac97_bus_ops *ops, int num) |
| 2525 | { |
| 2526 | mutex_lock(&codec->mutex); |
| 2527 | |
| 2528 | codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); |
| 2529 | if (codec->ac97 == NULL) { |
| 2530 | mutex_unlock(&codec->mutex); |
| 2531 | return -ENOMEM; |
| 2532 | } |
| 2533 | |
| 2534 | codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL); |
| 2535 | if (codec->ac97->bus == NULL) { |
| 2536 | kfree(codec->ac97); |
| 2537 | codec->ac97 = NULL; |
| 2538 | mutex_unlock(&codec->mutex); |
| 2539 | return -ENOMEM; |
| 2540 | } |
| 2541 | |
| 2542 | codec->ac97->bus->ops = ops; |
| 2543 | codec->ac97->num = num; |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 2544 | |
| 2545 | /* |
| 2546 | * Mark the AC97 device to be created by us. This way we ensure that the |
| 2547 | * device will be registered with the device subsystem later on. |
| 2548 | */ |
| 2549 | codec->ac97_created = 1; |
| 2550 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2551 | mutex_unlock(&codec->mutex); |
| 2552 | return 0; |
| 2553 | } |
| 2554 | EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); |
| 2555 | |
| 2556 | /** |
| 2557 | * snd_soc_free_ac97_codec - free AC97 codec device |
| 2558 | * @codec: audio codec |
| 2559 | * |
| 2560 | * Frees AC97 codec device resources. |
| 2561 | */ |
| 2562 | void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) |
| 2563 | { |
| 2564 | mutex_lock(&codec->mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2565 | #ifdef CONFIG_SND_SOC_AC97_BUS |
| 2566 | soc_unregister_ac97_dai_link(codec); |
| 2567 | #endif |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2568 | kfree(codec->ac97->bus); |
| 2569 | kfree(codec->ac97); |
| 2570 | codec->ac97 = NULL; |
Mika Westerberg | 0562f78 | 2010-10-13 11:30:32 +0300 | [diff] [blame] | 2571 | codec->ac97_created = 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2572 | mutex_unlock(&codec->mutex); |
| 2573 | } |
| 2574 | EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec); |
| 2575 | |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2576 | unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg) |
| 2577 | { |
| 2578 | unsigned int ret; |
| 2579 | |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 2580 | ret = codec->read(codec, reg); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2581 | dev_dbg(codec->dev, "read %x => %x\n", reg, ret); |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 2582 | trace_snd_soc_reg_read(codec, reg, ret); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2583 | |
| 2584 | return ret; |
| 2585 | } |
| 2586 | EXPORT_SYMBOL_GPL(snd_soc_read); |
| 2587 | |
| 2588 | unsigned int snd_soc_write(struct snd_soc_codec *codec, |
| 2589 | unsigned int reg, unsigned int val) |
| 2590 | { |
| 2591 | dev_dbg(codec->dev, "write %x = %x\n", reg, val); |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 2592 | trace_snd_soc_reg_write(codec, reg, val); |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 2593 | return codec->write(codec, reg, val); |
Mark Brown | c375370 | 2010-11-01 15:41:57 -0400 | [diff] [blame] | 2594 | } |
| 2595 | EXPORT_SYMBOL_GPL(snd_soc_write); |
| 2596 | |
Dimitris Papastamos | 5fb609d | 2011-03-22 10:37:03 +0000 | [diff] [blame] | 2597 | unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec, |
| 2598 | unsigned int reg, const void *data, size_t len) |
| 2599 | { |
| 2600 | return codec->bulk_write_raw(codec, reg, data, len); |
| 2601 | } |
| 2602 | EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw); |
| 2603 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2604 | /** |
| 2605 | * snd_soc_update_bits - update codec register bits |
| 2606 | * @codec: audio codec |
| 2607 | * @reg: codec register |
| 2608 | * @mask: register mask |
| 2609 | * @value: new value |
| 2610 | * |
| 2611 | * Writes new register value. |
| 2612 | * |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2613 | * Returns 1 for change, 0 for no change, or negative error code. |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2614 | */ |
| 2615 | 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] | 2616 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2617 | { |
| 2618 | int change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2619 | unsigned int old, new; |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2620 | int ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2621 | |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2622 | ret = snd_soc_read(codec, reg); |
| 2623 | if (ret < 0) |
| 2624 | return ret; |
| 2625 | |
| 2626 | old = ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2627 | new = (old & ~mask) | value; |
| 2628 | change = old != new; |
Timur Tabi | 180c329 | 2011-01-10 15:58:13 -0600 | [diff] [blame] | 2629 | if (change) { |
| 2630 | ret = snd_soc_write(codec, reg, new); |
| 2631 | if (ret < 0) |
| 2632 | return ret; |
| 2633 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2634 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2635 | return change; |
| 2636 | } |
| 2637 | EXPORT_SYMBOL_GPL(snd_soc_update_bits); |
| 2638 | |
| 2639 | /** |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2640 | * snd_soc_update_bits_locked - update codec register bits |
| 2641 | * @codec: audio codec |
| 2642 | * @reg: codec register |
| 2643 | * @mask: register mask |
| 2644 | * @value: new value |
| 2645 | * |
| 2646 | * Writes new register value, and takes the codec mutex. |
| 2647 | * |
| 2648 | * Returns 1 for change else 0. |
| 2649 | */ |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 2650 | int snd_soc_update_bits_locked(struct snd_soc_codec *codec, |
| 2651 | unsigned short reg, unsigned int mask, |
| 2652 | unsigned int value) |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2653 | { |
| 2654 | int change; |
| 2655 | |
| 2656 | mutex_lock(&codec->mutex); |
| 2657 | change = snd_soc_update_bits(codec, reg, mask, value); |
| 2658 | mutex_unlock(&codec->mutex); |
| 2659 | |
| 2660 | return change; |
| 2661 | } |
Mark Brown | dd1b3d5 | 2009-12-04 14:22:03 +0000 | [diff] [blame] | 2662 | EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked); |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2663 | |
| 2664 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2665 | * snd_soc_test_bits - test register for change |
| 2666 | * @codec: audio codec |
| 2667 | * @reg: codec register |
| 2668 | * @mask: register mask |
| 2669 | * @value: new value |
| 2670 | * |
| 2671 | * Tests a register with a new value and checks if the new value is |
| 2672 | * different from the old value. |
| 2673 | * |
| 2674 | * Returns 1 for change else 0. |
| 2675 | */ |
| 2676 | 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] | 2677 | unsigned int mask, unsigned int value) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2678 | { |
| 2679 | int change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2680 | unsigned int old, new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2681 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2682 | old = snd_soc_read(codec, reg); |
| 2683 | new = (old & ~mask) | value; |
| 2684 | change = old != new; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2685 | |
| 2686 | return change; |
| 2687 | } |
| 2688 | EXPORT_SYMBOL_GPL(snd_soc_test_bits); |
| 2689 | |
| 2690 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2691 | * snd_soc_set_runtime_hwparams - set the runtime hardware parameters |
| 2692 | * @substream: the pcm substream |
| 2693 | * @hw: the hardware parameters |
| 2694 | * |
| 2695 | * Sets the substream runtime hardware parameters. |
| 2696 | */ |
| 2697 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, |
| 2698 | const struct snd_pcm_hardware *hw) |
| 2699 | { |
| 2700 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2701 | if (!runtime) |
| 2702 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2703 | runtime->hw.info = hw->info; |
| 2704 | runtime->hw.formats = hw->formats; |
| 2705 | runtime->hw.period_bytes_min = hw->period_bytes_min; |
| 2706 | runtime->hw.period_bytes_max = hw->period_bytes_max; |
| 2707 | runtime->hw.periods_min = hw->periods_min; |
| 2708 | runtime->hw.periods_max = hw->periods_max; |
| 2709 | runtime->hw.buffer_bytes_max = hw->buffer_bytes_max; |
| 2710 | runtime->hw.fifo_size = hw->fifo_size; |
| 2711 | return 0; |
| 2712 | } |
| 2713 | EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); |
| 2714 | |
| 2715 | /** |
| 2716 | * snd_soc_cnew - create new control |
| 2717 | * @_template: control template |
| 2718 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2719 | * @long_name: control long name |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2720 | * @prefix: control name prefix |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2721 | * |
| 2722 | * Create a new mixer control from a template control. |
| 2723 | * |
| 2724 | * Returns 0 for success, else error. |
| 2725 | */ |
| 2726 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2727 | void *data, char *long_name, |
| 2728 | const char *prefix) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2729 | { |
| 2730 | struct snd_kcontrol_new template; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2731 | struct snd_kcontrol *kcontrol; |
| 2732 | char *name = NULL; |
| 2733 | int name_len; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2734 | |
| 2735 | memcpy(&template, _template, sizeof(template)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2736 | template.index = 0; |
| 2737 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2738 | if (!long_name) |
| 2739 | long_name = template.name; |
| 2740 | |
| 2741 | if (prefix) { |
| 2742 | name_len = strlen(long_name) + strlen(prefix) + 2; |
| 2743 | name = kmalloc(name_len, GFP_ATOMIC); |
| 2744 | if (!name) |
| 2745 | return NULL; |
| 2746 | |
| 2747 | snprintf(name, name_len, "%s %s", prefix, long_name); |
| 2748 | |
| 2749 | template.name = name; |
| 2750 | } else { |
| 2751 | template.name = long_name; |
| 2752 | } |
| 2753 | |
| 2754 | kcontrol = snd_ctl_new1(&template, data); |
| 2755 | |
| 2756 | kfree(name); |
| 2757 | |
| 2758 | return kcontrol; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2759 | } |
| 2760 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 2761 | |
| 2762 | /** |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2763 | * snd_soc_add_controls - add an array of controls to a codec. |
| 2764 | * Convienience function to add a list of controls. Many codecs were |
| 2765 | * duplicating this code. |
| 2766 | * |
| 2767 | * @codec: codec to add controls to |
| 2768 | * @controls: array of controls to add |
| 2769 | * @num_controls: number of elements in the array |
| 2770 | * |
| 2771 | * Return 0 for success, else error. |
| 2772 | */ |
| 2773 | int snd_soc_add_controls(struct snd_soc_codec *codec, |
| 2774 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2775 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2776 | struct snd_card *card = codec->card->snd_card; |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2777 | int err, i; |
| 2778 | |
| 2779 | for (i = 0; i < num_controls; i++) { |
| 2780 | const struct snd_kcontrol_new *control = &controls[i]; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2781 | err = snd_ctl_add(card, snd_soc_cnew(control, codec, |
| 2782 | control->name, |
| 2783 | codec->name_prefix)); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2784 | if (err < 0) { |
Mark Brown | 082100d | 2010-09-20 19:03:28 +0100 | [diff] [blame] | 2785 | dev_err(codec->dev, "%s: Failed to add %s: %d\n", |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2786 | codec->name, control->name, err); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 2787 | return err; |
| 2788 | } |
| 2789 | } |
| 2790 | |
| 2791 | return 0; |
| 2792 | } |
| 2793 | EXPORT_SYMBOL_GPL(snd_soc_add_controls); |
| 2794 | |
| 2795 | /** |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 2796 | * snd_soc_add_platform_controls - add an array of controls to a platform. |
| 2797 | * Convienience function to add a list of controls. |
| 2798 | * |
| 2799 | * @platform: platform to add controls to |
| 2800 | * @controls: array of controls to add |
| 2801 | * @num_controls: number of elements in the array |
| 2802 | * |
| 2803 | * Return 0 for success, else error. |
| 2804 | */ |
| 2805 | int snd_soc_add_platform_controls(struct snd_soc_platform *platform, |
| 2806 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2807 | { |
| 2808 | struct snd_card *card = platform->card->snd_card; |
| 2809 | int err, i; |
| 2810 | |
| 2811 | for (i = 0; i < num_controls; i++) { |
| 2812 | const struct snd_kcontrol_new *control = &controls[i]; |
| 2813 | err = snd_ctl_add(card, snd_soc_cnew(control, platform, |
| 2814 | control->name, NULL)); |
| 2815 | if (err < 0) { |
| 2816 | dev_err(platform->dev, "Failed to add %s %d\n",control->name, err); |
| 2817 | return err; |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | return 0; |
| 2822 | } |
| 2823 | EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); |
| 2824 | |
| 2825 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2826 | * snd_soc_info_enum_double - enumerated double mixer info callback |
| 2827 | * @kcontrol: mixer control |
| 2828 | * @uinfo: control element information |
| 2829 | * |
| 2830 | * Callback to provide information about a double enumerated |
| 2831 | * mixer control. |
| 2832 | * |
| 2833 | * Returns 0 for success. |
| 2834 | */ |
| 2835 | int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, |
| 2836 | struct snd_ctl_elem_info *uinfo) |
| 2837 | { |
| 2838 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2839 | |
| 2840 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2841 | uinfo->count = e->shift_l == e->shift_r ? 1 : 2; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2842 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2843 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2844 | if (uinfo->value.enumerated.item > e->max - 1) |
| 2845 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2846 | strcpy(uinfo->value.enumerated.name, |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame] | 2847 | snd_soc_get_enum_text(e, uinfo->value.enumerated.item)); |
| 2848 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2849 | return 0; |
| 2850 | } |
| 2851 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_double); |
| 2852 | |
| 2853 | /** |
| 2854 | * snd_soc_get_enum_double - enumerated double mixer get callback |
| 2855 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2856 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2857 | * |
| 2858 | * Callback to get the value of a double enumerated mixer. |
| 2859 | * |
| 2860 | * Returns 0 for success. |
| 2861 | */ |
| 2862 | int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2863 | struct snd_ctl_elem_value *ucontrol) |
| 2864 | { |
| 2865 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2866 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2867 | unsigned int val, bitmask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2868 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2869 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2870 | ; |
| 2871 | val = snd_soc_read(codec, e->reg); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 2872 | ucontrol->value.enumerated.item[0] |
| 2873 | = (val >> e->shift_l) & (bitmask - 1); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2874 | if (e->shift_l != e->shift_r) |
| 2875 | ucontrol->value.enumerated.item[1] = |
| 2876 | (val >> e->shift_r) & (bitmask - 1); |
| 2877 | |
| 2878 | return 0; |
| 2879 | } |
| 2880 | EXPORT_SYMBOL_GPL(snd_soc_get_enum_double); |
| 2881 | |
| 2882 | /** |
| 2883 | * snd_soc_put_enum_double - enumerated double mixer put callback |
| 2884 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2885 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2886 | * |
| 2887 | * Callback to set the value of a double enumerated mixer. |
| 2888 | * |
| 2889 | * Returns 0 for success. |
| 2890 | */ |
| 2891 | int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2892 | struct snd_ctl_elem_value *ucontrol) |
| 2893 | { |
| 2894 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2895 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2896 | unsigned int val; |
| 2897 | unsigned int mask, bitmask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2898 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2899 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2900 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2901 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2902 | return -EINVAL; |
| 2903 | val = ucontrol->value.enumerated.item[0] << e->shift_l; |
| 2904 | mask = (bitmask - 1) << e->shift_l; |
| 2905 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2906 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2907 | return -EINVAL; |
| 2908 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 2909 | mask |= (bitmask - 1) << e->shift_r; |
| 2910 | } |
| 2911 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2912 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2913 | } |
| 2914 | EXPORT_SYMBOL_GPL(snd_soc_put_enum_double); |
| 2915 | |
| 2916 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2917 | * snd_soc_get_value_enum_double - semi enumerated double mixer get callback |
| 2918 | * @kcontrol: mixer control |
| 2919 | * @ucontrol: control element information |
| 2920 | * |
| 2921 | * Callback to get the value of a double semi enumerated mixer. |
| 2922 | * |
| 2923 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2924 | * used for handling bitfield coded enumeration for example. |
| 2925 | * |
| 2926 | * Returns 0 for success. |
| 2927 | */ |
| 2928 | int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2929 | struct snd_ctl_elem_value *ucontrol) |
| 2930 | { |
| 2931 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2932 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2933 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2934 | |
| 2935 | reg_val = snd_soc_read(codec, e->reg); |
| 2936 | val = (reg_val >> e->shift_l) & e->mask; |
| 2937 | for (mux = 0; mux < e->max; mux++) { |
| 2938 | if (val == e->values[mux]) |
| 2939 | break; |
| 2940 | } |
| 2941 | ucontrol->value.enumerated.item[0] = mux; |
| 2942 | if (e->shift_l != e->shift_r) { |
| 2943 | val = (reg_val >> e->shift_r) & e->mask; |
| 2944 | for (mux = 0; mux < e->max; mux++) { |
| 2945 | if (val == e->values[mux]) |
| 2946 | break; |
| 2947 | } |
| 2948 | ucontrol->value.enumerated.item[1] = mux; |
| 2949 | } |
| 2950 | |
| 2951 | return 0; |
| 2952 | } |
| 2953 | EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double); |
| 2954 | |
| 2955 | /** |
| 2956 | * snd_soc_put_value_enum_double - semi enumerated double mixer put callback |
| 2957 | * @kcontrol: mixer control |
| 2958 | * @ucontrol: control element information |
| 2959 | * |
| 2960 | * Callback to set the value of a double semi enumerated mixer. |
| 2961 | * |
| 2962 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2963 | * used for handling bitfield coded enumeration for example. |
| 2964 | * |
| 2965 | * Returns 0 for success. |
| 2966 | */ |
| 2967 | int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2968 | struct snd_ctl_elem_value *ucontrol) |
| 2969 | { |
| 2970 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2971 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2972 | unsigned int val; |
| 2973 | unsigned int mask; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2974 | |
| 2975 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2976 | return -EINVAL; |
| 2977 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2978 | mask = e->mask << e->shift_l; |
| 2979 | if (e->shift_l != e->shift_r) { |
| 2980 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2981 | return -EINVAL; |
| 2982 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2983 | mask |= e->mask << e->shift_r; |
| 2984 | } |
| 2985 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 2986 | return snd_soc_update_bits_locked(codec, e->reg, mask, val); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2987 | } |
| 2988 | EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double); |
| 2989 | |
| 2990 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2991 | * snd_soc_info_enum_ext - external enumerated single mixer info callback |
| 2992 | * @kcontrol: mixer control |
| 2993 | * @uinfo: control element information |
| 2994 | * |
| 2995 | * Callback to provide information about an external enumerated |
| 2996 | * single mixer. |
| 2997 | * |
| 2998 | * Returns 0 for success. |
| 2999 | */ |
| 3000 | int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, |
| 3001 | struct snd_ctl_elem_info *uinfo) |
| 3002 | { |
| 3003 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 3004 | |
| 3005 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3006 | uinfo->count = 1; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 3007 | uinfo->value.enumerated.items = e->max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3008 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 3009 | if (uinfo->value.enumerated.item > e->max - 1) |
| 3010 | uinfo->value.enumerated.item = e->max - 1; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3011 | strcpy(uinfo->value.enumerated.name, |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame] | 3012 | snd_soc_get_enum_text(e, uinfo->value.enumerated.item)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3013 | return 0; |
| 3014 | } |
| 3015 | EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext); |
| 3016 | |
| 3017 | /** |
| 3018 | * snd_soc_info_volsw_ext - external single mixer info callback |
| 3019 | * @kcontrol: mixer control |
| 3020 | * @uinfo: control element information |
| 3021 | * |
| 3022 | * Callback to provide information about a single external mixer control. |
| 3023 | * |
| 3024 | * Returns 0 for success. |
| 3025 | */ |
| 3026 | int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, |
| 3027 | struct snd_ctl_elem_info *uinfo) |
| 3028 | { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3029 | int max = kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3030 | |
Mark Brown | fd5dfad | 2009-04-15 21:37:46 +0100 | [diff] [blame] | 3031 | if (max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3032 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3033 | else |
| 3034 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3035 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3036 | uinfo->count = 1; |
| 3037 | uinfo->value.integer.min = 0; |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3038 | uinfo->value.integer.max = max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3039 | return 0; |
| 3040 | } |
| 3041 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext); |
| 3042 | |
| 3043 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3044 | * snd_soc_info_volsw - single mixer info callback |
| 3045 | * @kcontrol: mixer control |
| 3046 | * @uinfo: control element information |
| 3047 | * |
| 3048 | * Callback to provide information about a single mixer control. |
| 3049 | * |
| 3050 | * Returns 0 for success. |
| 3051 | */ |
| 3052 | int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, |
| 3053 | struct snd_ctl_elem_info *uinfo) |
| 3054 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3055 | struct soc_mixer_control *mc = |
| 3056 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3057 | int platform_max; |
Mark Brown | 762b8df | 2008-10-30 12:37:08 +0000 | [diff] [blame] | 3058 | unsigned int shift = mc->shift; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3059 | unsigned int rshift = mc->rshift; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3060 | |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3061 | if (!mc->platform_max) |
| 3062 | mc->platform_max = mc->max; |
| 3063 | platform_max = mc->platform_max; |
| 3064 | |
| 3065 | if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3066 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3067 | else |
| 3068 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3069 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3070 | uinfo->count = shift == rshift ? 1 : 2; |
| 3071 | uinfo->value.integer.min = 0; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3072 | uinfo->value.integer.max = platform_max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3073 | return 0; |
| 3074 | } |
| 3075 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw); |
| 3076 | |
| 3077 | /** |
Ben Romberger | 8f1dc4c | 2011-09-22 13:51:35 -0700 | [diff] [blame] | 3078 | * snd_soc_info_multi_ext - external single mixer info callback |
| 3079 | * @kcontrol: mixer control |
| 3080 | * @uinfo: control element information |
| 3081 | * |
| 3082 | * Callback to provide information about a single external mixer control. |
| 3083 | * that accepts multiple input. |
| 3084 | * |
| 3085 | * Returns 0 for success. |
| 3086 | */ |
| 3087 | int snd_soc_info_multi_ext(struct snd_kcontrol *kcontrol, |
| 3088 | struct snd_ctl_elem_info *uinfo) |
| 3089 | { |
| 3090 | struct soc_multi_mixer_control *mc = |
| 3091 | (struct soc_multi_mixer_control *)kcontrol->private_value; |
| 3092 | int platform_max; |
| 3093 | |
| 3094 | if (!mc->platform_max) |
| 3095 | mc->platform_max = mc->max; |
| 3096 | platform_max = mc->platform_max; |
| 3097 | |
| 3098 | if (platform_max == 1 && !strnstr(kcontrol->id.name, " Volume", 30)) |
| 3099 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3100 | else |
| 3101 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3102 | |
| 3103 | uinfo->count = mc->count; |
| 3104 | uinfo->value.integer.min = 0; |
| 3105 | uinfo->value.integer.max = platform_max; |
| 3106 | return 0; |
| 3107 | } |
| 3108 | EXPORT_SYMBOL_GPL(snd_soc_info_multi_ext); |
| 3109 | |
| 3110 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3111 | * snd_soc_get_volsw - single mixer get callback |
| 3112 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3113 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3114 | * |
| 3115 | * Callback to get the value of a single mixer control. |
| 3116 | * |
| 3117 | * Returns 0 for success. |
| 3118 | */ |
| 3119 | int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, |
| 3120 | struct snd_ctl_elem_value *ucontrol) |
| 3121 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3122 | struct soc_mixer_control *mc = |
| 3123 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3124 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3125 | unsigned int reg = mc->reg; |
| 3126 | unsigned int shift = mc->shift; |
| 3127 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3128 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3129 | unsigned int mask = (1 << fls(max)) - 1; |
| 3130 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3131 | |
| 3132 | ucontrol->value.integer.value[0] = |
| 3133 | (snd_soc_read(codec, reg) >> shift) & mask; |
| 3134 | if (shift != rshift) |
| 3135 | ucontrol->value.integer.value[1] = |
| 3136 | (snd_soc_read(codec, reg) >> rshift) & mask; |
| 3137 | if (invert) { |
| 3138 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3139 | max - ucontrol->value.integer.value[0]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3140 | if (shift != rshift) |
| 3141 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3142 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | return 0; |
| 3146 | } |
| 3147 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw); |
| 3148 | |
| 3149 | /** |
| 3150 | * snd_soc_put_volsw - single mixer put callback |
| 3151 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3152 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3153 | * |
| 3154 | * Callback to set the value of a single mixer control. |
| 3155 | * |
| 3156 | * Returns 0 for success. |
| 3157 | */ |
| 3158 | int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, |
| 3159 | struct snd_ctl_elem_value *ucontrol) |
| 3160 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3161 | struct soc_mixer_control *mc = |
| 3162 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3163 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3164 | unsigned int reg = mc->reg; |
| 3165 | unsigned int shift = mc->shift; |
| 3166 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3167 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3168 | unsigned int mask = (1 << fls(max)) - 1; |
| 3169 | unsigned int invert = mc->invert; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 3170 | unsigned int val, val2, val_mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3171 | |
| 3172 | val = (ucontrol->value.integer.value[0] & mask); |
| 3173 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3174 | val = max - val; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3175 | val_mask = mask << shift; |
| 3176 | val = val << shift; |
| 3177 | if (shift != rshift) { |
| 3178 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 3179 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3180 | val2 = max - val2; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3181 | val_mask |= mask << rshift; |
| 3182 | val |= val2 << rshift; |
| 3183 | } |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 3184 | return snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3185 | } |
| 3186 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw); |
| 3187 | |
| 3188 | /** |
| 3189 | * snd_soc_info_volsw_2r - double mixer info callback |
| 3190 | * @kcontrol: mixer control |
| 3191 | * @uinfo: control element information |
| 3192 | * |
| 3193 | * Callback to provide information about a double mixer control that |
| 3194 | * spans 2 codec registers. |
| 3195 | * |
| 3196 | * Returns 0 for success. |
| 3197 | */ |
| 3198 | int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol, |
| 3199 | struct snd_ctl_elem_info *uinfo) |
| 3200 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3201 | struct soc_mixer_control *mc = |
| 3202 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3203 | int platform_max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3204 | |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3205 | if (!mc->platform_max) |
| 3206 | mc->platform_max = mc->max; |
| 3207 | platform_max = mc->platform_max; |
| 3208 | |
| 3209 | if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume")) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3210 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3211 | else |
| 3212 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3213 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3214 | uinfo->count = 2; |
| 3215 | uinfo->value.integer.min = 0; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3216 | uinfo->value.integer.max = platform_max; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3217 | return 0; |
| 3218 | } |
| 3219 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r); |
| 3220 | |
| 3221 | /** |
| 3222 | * snd_soc_get_volsw_2r - double mixer get callback |
| 3223 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3224 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3225 | * |
| 3226 | * Callback to get the value of a double mixer control that spans 2 registers. |
| 3227 | * |
| 3228 | * Returns 0 for success. |
| 3229 | */ |
| 3230 | int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol, |
| 3231 | struct snd_ctl_elem_value *ucontrol) |
| 3232 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3233 | struct soc_mixer_control *mc = |
| 3234 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3235 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3236 | unsigned int reg = mc->reg; |
| 3237 | unsigned int reg2 = mc->rreg; |
| 3238 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3239 | int max = mc->max; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 3240 | unsigned int mask = (1 << fls(max)) - 1; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3241 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3242 | |
| 3243 | ucontrol->value.integer.value[0] = |
| 3244 | (snd_soc_read(codec, reg) >> shift) & mask; |
| 3245 | ucontrol->value.integer.value[1] = |
| 3246 | (snd_soc_read(codec, reg2) >> shift) & mask; |
| 3247 | if (invert) { |
| 3248 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3249 | max - ucontrol->value.integer.value[0]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3250 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3251 | max - ucontrol->value.integer.value[1]; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | return 0; |
| 3255 | } |
| 3256 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r); |
| 3257 | |
| 3258 | /** |
| 3259 | * snd_soc_put_volsw_2r - double mixer set callback |
| 3260 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3261 | * @ucontrol: control element information |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3262 | * |
| 3263 | * Callback to set the value of a double mixer control that spans 2 registers. |
| 3264 | * |
| 3265 | * Returns 0 for success. |
| 3266 | */ |
| 3267 | int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol, |
| 3268 | struct snd_ctl_elem_value *ucontrol) |
| 3269 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3270 | struct soc_mixer_control *mc = |
| 3271 | (struct soc_mixer_control *)kcontrol->private_value; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3272 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3273 | unsigned int reg = mc->reg; |
| 3274 | unsigned int reg2 = mc->rreg; |
| 3275 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3276 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3277 | unsigned int mask = (1 << fls(max)) - 1; |
| 3278 | unsigned int invert = mc->invert; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3279 | int err; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 3280 | unsigned int val, val2, val_mask; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3281 | |
| 3282 | val_mask = mask << shift; |
| 3283 | val = (ucontrol->value.integer.value[0] & mask); |
| 3284 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 3285 | |
| 3286 | if (invert) { |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3287 | val = max - val; |
| 3288 | val2 = max - val2; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | val = val << shift; |
| 3292 | val2 = val2 << shift; |
| 3293 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 3294 | err = snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 3295 | if (err < 0) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3296 | return err; |
| 3297 | |
Eero Nurkkala | 6c508c6 | 2009-10-30 13:34:03 +0200 | [diff] [blame] | 3298 | err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3299 | return err; |
| 3300 | } |
| 3301 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r); |
| 3302 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3303 | /** |
| 3304 | * snd_soc_info_volsw_s8 - signed mixer info callback |
| 3305 | * @kcontrol: mixer control |
| 3306 | * @uinfo: control element information |
| 3307 | * |
| 3308 | * Callback to provide information about a signed mixer control. |
| 3309 | * |
| 3310 | * Returns 0 for success. |
| 3311 | */ |
| 3312 | int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, |
| 3313 | struct snd_ctl_elem_info *uinfo) |
| 3314 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3315 | struct soc_mixer_control *mc = |
| 3316 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3317 | int platform_max; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3318 | int min = mc->min; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3319 | unsigned int shift = mc->shift; |
| 3320 | unsigned int rshift = mc->rshift; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3321 | |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3322 | if (!mc->platform_max) |
| 3323 | mc->platform_max = mc->max; |
| 3324 | platform_max = mc->platform_max; |
| 3325 | |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3326 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3327 | uinfo->count = shift == rshift ? 1 : 2; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3328 | uinfo->value.integer.min = 0; |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3329 | uinfo->value.integer.max = platform_max - min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3330 | return 0; |
| 3331 | } |
| 3332 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8); |
| 3333 | |
| 3334 | /** |
| 3335 | * snd_soc_get_volsw_s8 - signed mixer get callback |
| 3336 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3337 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3338 | * |
| 3339 | * Callback to get the value of a signed mixer control. |
| 3340 | * |
| 3341 | * Returns 0 for success. |
| 3342 | */ |
| 3343 | int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, |
| 3344 | struct snd_ctl_elem_value *ucontrol) |
| 3345 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3346 | struct soc_mixer_control *mc = |
| 3347 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3348 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3349 | unsigned int reg = mc->reg; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3350 | unsigned int shift = mc->shift; |
| 3351 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3352 | int min = mc->min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3353 | int val = snd_soc_read(codec, reg); |
| 3354 | |
| 3355 | ucontrol->value.integer.value[0] = |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3356 | ((signed char)((val >> shift) & 0xff))-min; |
| 3357 | if (shift != rshift) |
| 3358 | ucontrol->value.integer.value[1] = |
| 3359 | ((signed char)((val >> rshift) & 0xff))-min; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3360 | return 0; |
| 3361 | } |
| 3362 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8); |
| 3363 | |
| 3364 | /** |
| 3365 | * snd_soc_put_volsw_sgn - signed mixer put callback |
| 3366 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3367 | * @ucontrol: control element information |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3368 | * |
| 3369 | * Callback to set the value of a signed mixer control. |
| 3370 | * |
| 3371 | * Returns 0 for success. |
| 3372 | */ |
| 3373 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, |
| 3374 | struct snd_ctl_elem_value *ucontrol) |
| 3375 | { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3376 | struct soc_mixer_control *mc = |
| 3377 | (struct soc_mixer_control *)kcontrol->private_value; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3378 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3379 | unsigned int reg = mc->reg; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3380 | unsigned int shift = mc->shift; |
| 3381 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3382 | int min = mc->min; |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3383 | unsigned int val, val2, val_mask; |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3384 | |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3385 | val = ((ucontrol->value.integer.value[0]+min) & 0xff) << shift; |
| 3386 | val_mask = 0xff << shift; |
| 3387 | if (shift != rshift) { |
| 3388 | val2 = (ucontrol->value.integer.value[1]+min) & 0xff; |
| 3389 | val |= val2 << rshift; |
| 3390 | val_mask |= 0xff << rshift; |
| 3391 | } |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3392 | |
Bradley Rubin | 572c3b4 | 2011-07-07 18:23:44 -0700 | [diff] [blame] | 3393 | return snd_soc_update_bits_locked(codec, reg, val_mask, val); |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 3394 | } |
| 3395 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8); |
| 3396 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3397 | /** |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 3398 | * snd_soc_limit_volume - Set new limit to an existing volume control. |
| 3399 | * |
| 3400 | * @codec: where to look for the control |
| 3401 | * @name: Name of the control |
| 3402 | * @max: new maximum limit |
| 3403 | * |
| 3404 | * Return 0 for success, else error. |
| 3405 | */ |
| 3406 | int snd_soc_limit_volume(struct snd_soc_codec *codec, |
| 3407 | const char *name, int max) |
| 3408 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3409 | struct snd_card *card = codec->card->snd_card; |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 3410 | struct snd_kcontrol *kctl; |
| 3411 | struct soc_mixer_control *mc; |
| 3412 | int found = 0; |
| 3413 | int ret = -EINVAL; |
| 3414 | |
| 3415 | /* Sanity check for name and max */ |
| 3416 | if (unlikely(!name || max <= 0)) |
| 3417 | return -EINVAL; |
| 3418 | |
| 3419 | list_for_each_entry(kctl, &card->controls, list) { |
| 3420 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) { |
| 3421 | found = 1; |
| 3422 | break; |
| 3423 | } |
| 3424 | } |
| 3425 | if (found) { |
| 3426 | mc = (struct soc_mixer_control *)kctl->private_value; |
| 3427 | if (max <= mc->max) { |
Peter Ujfalusi | d11bb4a | 2010-05-10 14:39:24 +0300 | [diff] [blame] | 3428 | mc->platform_max = max; |
Peter Ujfalusi | 637d384 | 2010-05-07 14:05:49 +0300 | [diff] [blame] | 3429 | ret = 0; |
| 3430 | } |
| 3431 | } |
| 3432 | return ret; |
| 3433 | } |
| 3434 | EXPORT_SYMBOL_GPL(snd_soc_limit_volume); |
| 3435 | |
| 3436 | /** |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 3437 | * snd_soc_info_volsw_2r_sx - double with tlv and variable data size |
| 3438 | * mixer info callback |
| 3439 | * @kcontrol: mixer control |
| 3440 | * @uinfo: control element information |
| 3441 | * |
| 3442 | * Returns 0 for success. |
| 3443 | */ |
| 3444 | int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol, |
| 3445 | struct snd_ctl_elem_info *uinfo) |
| 3446 | { |
| 3447 | struct soc_mixer_control *mc = |
| 3448 | (struct soc_mixer_control *)kcontrol->private_value; |
| 3449 | int max = mc->max; |
| 3450 | int min = mc->min; |
| 3451 | |
| 3452 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3453 | uinfo->count = 2; |
| 3454 | uinfo->value.integer.min = 0; |
| 3455 | uinfo->value.integer.max = max-min; |
| 3456 | |
| 3457 | return 0; |
| 3458 | } |
| 3459 | EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx); |
| 3460 | |
| 3461 | /** |
| 3462 | * snd_soc_get_volsw_2r_sx - double with tlv and variable data size |
| 3463 | * mixer get callback |
| 3464 | * @kcontrol: mixer control |
| 3465 | * @uinfo: control element information |
| 3466 | * |
| 3467 | * Returns 0 for success. |
| 3468 | */ |
| 3469 | int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol, |
| 3470 | struct snd_ctl_elem_value *ucontrol) |
| 3471 | { |
| 3472 | struct soc_mixer_control *mc = |
| 3473 | (struct soc_mixer_control *)kcontrol->private_value; |
| 3474 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3475 | unsigned int mask = (1<<mc->shift)-1; |
| 3476 | int min = mc->min; |
| 3477 | int val = snd_soc_read(codec, mc->reg) & mask; |
| 3478 | int valr = snd_soc_read(codec, mc->rreg) & mask; |
| 3479 | |
Stuart Longland | 20630c7 | 2010-06-18 12:56:10 +1000 | [diff] [blame] | 3480 | ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask; |
| 3481 | ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask; |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 3482 | return 0; |
| 3483 | } |
| 3484 | EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx); |
| 3485 | |
| 3486 | /** |
| 3487 | * snd_soc_put_volsw_2r_sx - double with tlv and variable data size |
| 3488 | * mixer put callback |
| 3489 | * @kcontrol: mixer control |
| 3490 | * @uinfo: control element information |
| 3491 | * |
| 3492 | * Returns 0 for success. |
| 3493 | */ |
| 3494 | int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol, |
| 3495 | struct snd_ctl_elem_value *ucontrol) |
| 3496 | { |
| 3497 | struct soc_mixer_control *mc = |
| 3498 | (struct soc_mixer_control *)kcontrol->private_value; |
| 3499 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3500 | unsigned int mask = (1<<mc->shift)-1; |
| 3501 | int min = mc->min; |
| 3502 | int ret; |
| 3503 | unsigned int val, valr, oval, ovalr; |
| 3504 | |
| 3505 | val = ((ucontrol->value.integer.value[0]+min) & 0xff); |
| 3506 | val &= mask; |
| 3507 | valr = ((ucontrol->value.integer.value[1]+min) & 0xff); |
| 3508 | valr &= mask; |
| 3509 | |
| 3510 | oval = snd_soc_read(codec, mc->reg) & mask; |
| 3511 | ovalr = snd_soc_read(codec, mc->rreg) & mask; |
| 3512 | |
| 3513 | ret = 0; |
| 3514 | if (oval != val) { |
| 3515 | ret = snd_soc_write(codec, mc->reg, val); |
| 3516 | if (ret < 0) |
Mark Brown | f1df5ae | 2010-06-15 15:14:31 +0100 | [diff] [blame] | 3517 | return ret; |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 3518 | } |
| 3519 | if (ovalr != valr) { |
| 3520 | ret = snd_soc_write(codec, mc->rreg, valr); |
| 3521 | if (ret < 0) |
Mark Brown | f1df5ae | 2010-06-15 15:14:31 +0100 | [diff] [blame] | 3522 | return ret; |
apatard@mandriva.com | b6f4bb3 | 2010-05-15 17:30:01 +0200 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | return 0; |
| 3526 | } |
| 3527 | EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx); |
| 3528 | |
| 3529 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3530 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
| 3531 | * @dai: DAI |
| 3532 | * @clk_id: DAI specific clock ID |
| 3533 | * @freq: new clock frequency in Hz |
| 3534 | * @dir: new clock direction - input/output. |
| 3535 | * |
| 3536 | * Configures the DAI master (MCLK) or system (SYSCLK) clocking. |
| 3537 | */ |
| 3538 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 3539 | unsigned int freq, int dir) |
| 3540 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3541 | if (dai->driver && dai->driver->ops->set_sysclk) |
| 3542 | return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3543 | else if (dai->codec && dai->codec->driver->set_sysclk) |
| 3544 | return dai->codec->driver->set_sysclk(dai->codec, clk_id, |
| 3545 | freq, dir); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3546 | else |
| 3547 | return -EINVAL; |
| 3548 | } |
| 3549 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); |
| 3550 | |
| 3551 | /** |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3552 | * snd_soc_codec_set_sysclk - configure CODEC system or master clock. |
| 3553 | * @codec: CODEC |
| 3554 | * @clk_id: DAI specific clock ID |
| 3555 | * @freq: new clock frequency in Hz |
| 3556 | * @dir: new clock direction - input/output. |
| 3557 | * |
| 3558 | * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. |
| 3559 | */ |
| 3560 | int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id, |
| 3561 | unsigned int freq, int dir) |
| 3562 | { |
| 3563 | if (codec->driver->set_sysclk) |
| 3564 | return codec->driver->set_sysclk(codec, clk_id, freq, dir); |
| 3565 | else |
| 3566 | return -EINVAL; |
| 3567 | } |
| 3568 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); |
| 3569 | |
| 3570 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3571 | * snd_soc_dai_set_clkdiv - configure DAI clock dividers. |
| 3572 | * @dai: DAI |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3573 | * @div_id: DAI specific clock divider ID |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3574 | * @div: new clock divisor. |
| 3575 | * |
| 3576 | * Configures the clock dividers. This is used to derive the best DAI bit and |
| 3577 | * frame clocks from the system or master clock. It's best to set the DAI bit |
| 3578 | * and frame clocks as low as possible to save system power. |
| 3579 | */ |
| 3580 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 3581 | int div_id, int div) |
| 3582 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3583 | if (dai->driver && dai->driver->ops->set_clkdiv) |
| 3584 | return dai->driver->ops->set_clkdiv(dai, div_id, div); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3585 | else |
| 3586 | return -EINVAL; |
| 3587 | } |
| 3588 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); |
| 3589 | |
| 3590 | /** |
| 3591 | * snd_soc_dai_set_pll - configure DAI PLL. |
| 3592 | * @dai: DAI |
| 3593 | * @pll_id: DAI specific PLL ID |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3594 | * @source: DAI specific source for the PLL |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3595 | * @freq_in: PLL input clock frequency in Hz |
| 3596 | * @freq_out: requested PLL output clock frequency in Hz |
| 3597 | * |
| 3598 | * Configures and enables PLL to generate output clock based on input clock. |
| 3599 | */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3600 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, |
| 3601 | unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3602 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3603 | if (dai->driver && dai->driver->ops->set_pll) |
| 3604 | return dai->driver->ops->set_pll(dai, pll_id, source, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 3605 | freq_in, freq_out); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3606 | else if (dai->codec && dai->codec->driver->set_pll) |
| 3607 | return dai->codec->driver->set_pll(dai->codec, pll_id, source, |
| 3608 | freq_in, freq_out); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3609 | else |
| 3610 | return -EINVAL; |
| 3611 | } |
| 3612 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); |
| 3613 | |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 3614 | /* |
| 3615 | * snd_soc_codec_set_pll - configure codec PLL. |
| 3616 | * @codec: CODEC |
| 3617 | * @pll_id: DAI specific PLL ID |
| 3618 | * @source: DAI specific source for the PLL |
| 3619 | * @freq_in: PLL input clock frequency in Hz |
| 3620 | * @freq_out: requested PLL output clock frequency in Hz |
| 3621 | * |
| 3622 | * Configures and enables PLL to generate output clock based on input clock. |
| 3623 | */ |
| 3624 | int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, |
| 3625 | unsigned int freq_in, unsigned int freq_out) |
| 3626 | { |
| 3627 | if (codec->driver->set_pll) |
| 3628 | return codec->driver->set_pll(codec, pll_id, source, |
| 3629 | freq_in, freq_out); |
| 3630 | else |
| 3631 | return -EINVAL; |
| 3632 | } |
| 3633 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); |
| 3634 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3635 | /** |
| 3636 | * snd_soc_dai_set_fmt - configure DAI hardware audio format. |
| 3637 | * @dai: DAI |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3638 | * @fmt: SND_SOC_DAIFMT_ format value. |
| 3639 | * |
| 3640 | * Configures the DAI hardware format and clocking. |
| 3641 | */ |
| 3642 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 3643 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3644 | if (dai->driver && dai->driver->ops->set_fmt) |
| 3645 | return dai->driver->ops->set_fmt(dai, fmt); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3646 | else |
| 3647 | return -EINVAL; |
| 3648 | } |
| 3649 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); |
| 3650 | |
| 3651 | /** |
| 3652 | * snd_soc_dai_set_tdm_slot - configure DAI TDM. |
| 3653 | * @dai: DAI |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3654 | * @tx_mask: bitmask representing active TX slots. |
| 3655 | * @rx_mask: bitmask representing active RX slots. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3656 | * @slots: Number of slots in use. |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3657 | * @slot_width: Width in bits for each slot. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3658 | * |
| 3659 | * Configures a DAI for TDM operation. Both mask and slots are codec and DAI |
| 3660 | * specific. |
| 3661 | */ |
| 3662 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3663 | 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] | 3664 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3665 | if (dai->driver && dai->driver->ops->set_tdm_slot) |
| 3666 | return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 3667 | slots, slot_width); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3668 | else |
| 3669 | return -EINVAL; |
| 3670 | } |
| 3671 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); |
| 3672 | |
| 3673 | /** |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 3674 | * snd_soc_dai_set_channel_map - configure DAI audio channel map |
| 3675 | * @dai: DAI |
| 3676 | * @tx_num: how many TX channels |
| 3677 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 3678 | * 0~num-1 uses |
| 3679 | * @rx_num: how many RX channels |
| 3680 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 3681 | * 0~num-1 uses |
| 3682 | * |
| 3683 | * configure the relationship between channel number and TDM slot number. |
| 3684 | */ |
| 3685 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 3686 | unsigned int tx_num, unsigned int *tx_slot, |
| 3687 | unsigned int rx_num, unsigned int *rx_slot) |
| 3688 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3689 | if (dai->driver && dai->driver->ops->set_channel_map) |
| 3690 | return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 3691 | rx_num, rx_slot); |
| 3692 | else |
| 3693 | return -EINVAL; |
| 3694 | } |
| 3695 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); |
| 3696 | |
| 3697 | /** |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3698 | * snd_soc_dai_get_channel_map - configure DAI audio channel map |
| 3699 | * @dai: DAI |
| 3700 | * @tx_num: how many TX channels |
| 3701 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 3702 | * 0~num-1 uses |
| 3703 | * @rx_num: how many RX channels |
| 3704 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 3705 | * 0~num-1 uses |
| 3706 | * |
| 3707 | * configure the relationship between channel number and TDM slot number. |
| 3708 | */ |
| 3709 | int snd_soc_dai_get_channel_map(struct snd_soc_dai *dai, |
| 3710 | unsigned int *tx_num, unsigned int *tx_slot, |
| 3711 | unsigned int *rx_num, unsigned int *rx_slot) |
| 3712 | { |
| 3713 | if (dai->driver && dai->driver->ops->get_channel_map) |
| 3714 | return dai->driver->ops->get_channel_map(dai, tx_num, tx_slot, |
| 3715 | rx_num, rx_slot); |
| 3716 | else |
| 3717 | return -EINVAL; |
| 3718 | } |
| 3719 | EXPORT_SYMBOL_GPL(snd_soc_dai_get_channel_map); |
| 3720 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3721 | * snd_soc_dai_set_tristate - configure DAI system or master clock. |
| 3722 | * @dai: DAI |
| 3723 | * @tristate: tristate enable |
| 3724 | * |
| 3725 | * Tristates the DAI so that others can use it. |
| 3726 | */ |
| 3727 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
| 3728 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3729 | if (dai->driver && dai->driver->ops->set_tristate) |
| 3730 | return dai->driver->ops->set_tristate(dai, tristate); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3731 | else |
| 3732 | return -EINVAL; |
| 3733 | } |
| 3734 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); |
| 3735 | |
| 3736 | /** |
| 3737 | * snd_soc_dai_digital_mute - configure DAI system or master clock. |
| 3738 | * @dai: DAI |
| 3739 | * @mute: mute enable |
| 3740 | * |
| 3741 | * Mutes the DAI DAC. |
| 3742 | */ |
| 3743 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) |
| 3744 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3745 | if (dai->driver && dai->driver->ops->digital_mute) |
| 3746 | return dai->driver->ops->digital_mute(dai, mute); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 3747 | else |
| 3748 | return -EINVAL; |
| 3749 | } |
| 3750 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
| 3751 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3752 | /** |
| 3753 | * snd_soc_register_card - Register a card with the ASoC core |
| 3754 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3755 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3756 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3757 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3758 | int snd_soc_register_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3759 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3760 | int i; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 3761 | int ret = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3762 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3763 | if (!card->name || !card->dev) |
| 3764 | return -EINVAL; |
| 3765 | |
Mark Brown | ed77cc1 | 2011-05-03 18:25:34 +0100 | [diff] [blame] | 3766 | dev_set_drvdata(card->dev, card); |
| 3767 | |
Stephen Warren | 111c641 | 2011-01-28 14:26:35 -0700 | [diff] [blame] | 3768 | snd_soc_initialize_card_lists(card); |
| 3769 | |
Vinod Koul | 150dd2f | 2011-01-13 22:48:32 +0530 | [diff] [blame] | 3770 | soc_init_card_debugfs(card); |
| 3771 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 3772 | card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) * |
| 3773 | (card->num_links + card->num_aux_devs), |
| 3774 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3775 | if (card->rtd == NULL) |
| 3776 | return -ENOMEM; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 3777 | card->rtd_aux = &card->rtd[card->num_links]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3778 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 3779 | for (i = 0; i < card->num_links; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3780 | card->rtd[i].dai_link = &card->dai_link[i]; |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 3781 | if (card->rtd[i].dai_link->dynamic) { |
| 3782 | |
| 3783 | card->rtd[i].dai_link->codec_name = "null-codec"; |
| 3784 | card->rtd[i].dai_link->codec_dai_name = "null-codec-dai"; |
| 3785 | |
| 3786 | ret = snd_soc_register_codec(card->dev, &null_codec_drv, |
| 3787 | &null_codec_dai_drv, 1); |
| 3788 | if (ret < 0) { |
| 3789 | printk(KERN_ERR "%s: failed to register dynamic DAI link %d\n", |
| 3790 | __func__, ret); |
| 3791 | goto out; |
| 3792 | } |
| 3793 | |
| 3794 | continue; |
| 3795 | } |
| 3796 | if (card->rtd[i].dai_link->no_codec) { |
| 3797 | card->rtd[i].dai_link->codec_name = "null-codec"; |
| 3798 | |
| 3799 | ret = snd_soc_register_codec(card->dev, &null_codec_drv, |
| 3800 | &null_codec_dai_drv, 1); |
| 3801 | if (ret < 0) { |
| 3802 | printk(KERN_ERR "%s: failed to register dynamic DAI link %d\n", |
| 3803 | __func__, ret); |
| 3804 | goto out; |
| 3805 | } |
| 3806 | continue; |
| 3807 | } |
| 3808 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3809 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3810 | INIT_LIST_HEAD(&card->list); |
| 3811 | card->instantiated = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3812 | mutex_init(&card->mutex); |
Liam Girdwood | ecc1a0d | 2011-02-16 16:24:17 +0000 | [diff] [blame] | 3813 | mutex_init(&card->dapm_mutex); |
Jayasena Sangaraboina | 247d36e | 2012-04-17 10:16:18 -0700 | [diff] [blame] | 3814 | mutex_init(&card->dapm_power_mutex); |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 3815 | mutex_init(&card->dsp_mutex); |
Jayasena Sangaraboina | bac6062 | 2012-04-09 10:21:43 -0700 | [diff] [blame] | 3816 | spin_lock_init(&card->dsp_spinlock); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3817 | |
| 3818 | mutex_lock(&client_mutex); |
| 3819 | list_add(&card->list, &card_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 3820 | snd_soc_instantiate_cards(); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3821 | mutex_unlock(&client_mutex); |
| 3822 | |
| 3823 | dev_dbg(card->dev, "Registered card '%s'\n", card->name); |
| 3824 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 3825 | out: |
| 3826 | return ret; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3827 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3828 | EXPORT_SYMBOL_GPL(snd_soc_register_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3829 | |
| 3830 | /** |
| 3831 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 3832 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3833 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3834 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3835 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3836 | int snd_soc_unregister_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3837 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 3838 | if (card->instantiated) |
| 3839 | soc_cleanup_card_resources(card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3840 | mutex_lock(&client_mutex); |
| 3841 | list_del(&card->list); |
| 3842 | mutex_unlock(&client_mutex); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3843 | dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); |
| 3844 | |
| 3845 | return 0; |
| 3846 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 3847 | EXPORT_SYMBOL_GPL(snd_soc_unregister_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 3848 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3849 | /* |
| 3850 | * Simplify DAI link configuration by removing ".-1" from device names |
| 3851 | * and sanitizing names. |
| 3852 | */ |
Dimitris Papastamos | 0b9a214 | 2010-12-06 15:49:20 +0000 | [diff] [blame] | 3853 | static char *fmt_single_name(struct device *dev, int *id) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3854 | { |
| 3855 | char *found, name[NAME_SIZE]; |
| 3856 | int id1, id2; |
| 3857 | |
| 3858 | if (dev_name(dev) == NULL) |
| 3859 | return NULL; |
| 3860 | |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 3861 | strlcpy(name, dev_name(dev), NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3862 | |
| 3863 | /* are we a "%s.%d" name (platform and SPI components) */ |
| 3864 | found = strstr(name, dev->driver->name); |
| 3865 | if (found) { |
| 3866 | /* get ID */ |
| 3867 | if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { |
| 3868 | |
| 3869 | /* discard ID from name if ID == -1 */ |
| 3870 | if (*id == -1) |
| 3871 | found[strlen(dev->driver->name)] = '\0'; |
| 3872 | } |
| 3873 | |
| 3874 | } else { |
| 3875 | /* I2C component devices are named "bus-addr" */ |
| 3876 | if (sscanf(name, "%x-%x", &id1, &id2) == 2) { |
| 3877 | char tmp[NAME_SIZE]; |
| 3878 | |
| 3879 | /* create unique ID number from I2C addr and bus */ |
Jarkko Nikula | 0589944 | 2010-10-19 11:10:45 +0300 | [diff] [blame] | 3880 | *id = ((id1 & 0xffff) << 16) + id2; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3881 | |
| 3882 | /* sanitize component name for DAI link creation */ |
| 3883 | snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 3884 | strlcpy(name, tmp, NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3885 | } else |
| 3886 | *id = 0; |
| 3887 | } |
| 3888 | |
| 3889 | return kstrdup(name, GFP_KERNEL); |
| 3890 | } |
| 3891 | |
| 3892 | /* |
| 3893 | * Simplify DAI link naming for single devices with multiple DAIs by removing |
| 3894 | * any ".-1" and using the DAI name (instead of device name). |
| 3895 | */ |
| 3896 | static inline char *fmt_multiple_name(struct device *dev, |
| 3897 | struct snd_soc_dai_driver *dai_drv) |
| 3898 | { |
| 3899 | if (dai_drv->name == NULL) { |
| 3900 | printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n", |
| 3901 | dev_name(dev)); |
| 3902 | return NULL; |
| 3903 | } |
| 3904 | |
| 3905 | return kstrdup(dai_drv->name, GFP_KERNEL); |
| 3906 | } |
| 3907 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3908 | /** |
| 3909 | * snd_soc_register_dai - Register a DAI with the ASoC core |
| 3910 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3911 | * @dai: DAI to register |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3912 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3913 | int snd_soc_register_dai(struct device *dev, |
| 3914 | struct snd_soc_dai_driver *dai_drv) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3915 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3916 | struct snd_soc_dai *dai; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3917 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3918 | dev_dbg(dev, "dai register %s\n", dev_name(dev)); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3919 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3920 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
| 3921 | if (dai == NULL) |
Lu Guanqun | a739362 | 2011-04-20 16:00:51 +0800 | [diff] [blame] | 3922 | return -ENOMEM; |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 3923 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3924 | /* create DAI component name */ |
| 3925 | dai->name = fmt_single_name(dev, &dai->id); |
| 3926 | if (dai->name == NULL) { |
| 3927 | kfree(dai); |
| 3928 | return -ENOMEM; |
| 3929 | } |
| 3930 | |
| 3931 | dai->dev = dev; |
| 3932 | dai->driver = dai_drv; |
| 3933 | if (!dai->driver->ops) |
| 3934 | dai->driver->ops = &null_dai_ops; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3935 | |
| 3936 | mutex_lock(&client_mutex); |
| 3937 | list_add(&dai->list, &dai_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 3938 | snd_soc_instantiate_cards(); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3939 | mutex_unlock(&client_mutex); |
| 3940 | |
| 3941 | pr_debug("Registered DAI '%s'\n", dai->name); |
| 3942 | |
| 3943 | return 0; |
| 3944 | } |
| 3945 | EXPORT_SYMBOL_GPL(snd_soc_register_dai); |
| 3946 | |
| 3947 | /** |
| 3948 | * snd_soc_unregister_dai - Unregister a DAI from the ASoC core |
| 3949 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3950 | * @dai: DAI to unregister |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3951 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3952 | void snd_soc_unregister_dai(struct device *dev) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3953 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3954 | struct snd_soc_dai *dai; |
| 3955 | |
| 3956 | list_for_each_entry(dai, &dai_list, list) { |
| 3957 | if (dev == dai->dev) |
| 3958 | goto found; |
| 3959 | } |
| 3960 | return; |
| 3961 | |
| 3962 | found: |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3963 | mutex_lock(&client_mutex); |
| 3964 | list_del(&dai->list); |
| 3965 | mutex_unlock(&client_mutex); |
| 3966 | |
| 3967 | pr_debug("Unregistered DAI '%s'\n", dai->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3968 | kfree(dai->name); |
| 3969 | kfree(dai); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3970 | } |
| 3971 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); |
| 3972 | |
| 3973 | /** |
| 3974 | * snd_soc_register_dais - Register multiple DAIs with the ASoC core |
| 3975 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3976 | * @dai: Array of DAIs to register |
| 3977 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3978 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3979 | int snd_soc_register_dais(struct device *dev, |
| 3980 | struct snd_soc_dai_driver *dai_drv, size_t count) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3981 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3982 | struct snd_soc_dai *dai; |
| 3983 | int i, ret = 0; |
| 3984 | |
Liam Girdwood | 720ffa4 | 2010-08-18 00:30:30 +0100 | [diff] [blame] | 3985 | dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 3986 | |
| 3987 | for (i = 0; i < count; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3988 | |
| 3989 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
Axel Lin | c46e007 | 2010-11-03 15:04:45 +0800 | [diff] [blame] | 3990 | if (dai == NULL) { |
| 3991 | ret = -ENOMEM; |
| 3992 | goto err; |
| 3993 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3994 | |
| 3995 | /* create DAI component name */ |
| 3996 | dai->name = fmt_multiple_name(dev, &dai_drv[i]); |
| 3997 | if (dai->name == NULL) { |
| 3998 | kfree(dai); |
| 3999 | ret = -EINVAL; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 4000 | goto err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4001 | } |
| 4002 | |
| 4003 | dai->dev = dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4004 | dai->driver = &dai_drv[i]; |
Mark Brown | 0f9141c | 2010-10-12 15:43:21 +0100 | [diff] [blame] | 4005 | if (dai->driver->id) |
| 4006 | dai->id = dai->driver->id; |
| 4007 | else |
| 4008 | dai->id = i; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4009 | if (!dai->driver->ops) |
| 4010 | dai->driver->ops = &null_dai_ops; |
| 4011 | |
| 4012 | mutex_lock(&client_mutex); |
| 4013 | list_add(&dai->list, &dai_list); |
| 4014 | mutex_unlock(&client_mutex); |
| 4015 | |
| 4016 | pr_debug("Registered DAI '%s'\n", dai->name); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
Axel Lin | 1dcb4f3 | 2010-12-06 16:48:03 +0800 | [diff] [blame] | 4019 | mutex_lock(&client_mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4020 | snd_soc_instantiate_cards(); |
Axel Lin | 1dcb4f3 | 2010-12-06 16:48:03 +0800 | [diff] [blame] | 4021 | mutex_unlock(&client_mutex); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 4022 | return 0; |
| 4023 | |
| 4024 | err: |
| 4025 | for (i--; i >= 0; i--) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4026 | snd_soc_unregister_dai(dev); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 4027 | |
| 4028 | return ret; |
| 4029 | } |
| 4030 | EXPORT_SYMBOL_GPL(snd_soc_register_dais); |
| 4031 | |
| 4032 | /** |
| 4033 | * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core |
| 4034 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 4035 | * @dai: Array of DAIs to unregister |
| 4036 | * @count: Number of DAIs |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 4037 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4038 | void snd_soc_unregister_dais(struct device *dev, size_t count) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 4039 | { |
| 4040 | int i; |
| 4041 | |
| 4042 | for (i = 0; i < count; i++) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4043 | snd_soc_unregister_dai(dev); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 4044 | } |
| 4045 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); |
| 4046 | |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4047 | /** |
| 4048 | * snd_soc_register_platform - Register a platform with the ASoC core |
| 4049 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 4050 | * @platform: platform to register |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4051 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4052 | int snd_soc_register_platform(struct device *dev, |
| 4053 | struct snd_soc_platform_driver *platform_drv) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4054 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4055 | struct snd_soc_platform *platform; |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4056 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4057 | dev_dbg(dev, "platform register %s\n", dev_name(dev)); |
| 4058 | |
| 4059 | platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); |
| 4060 | if (platform == NULL) |
Lu Guanqun | a739362 | 2011-04-20 16:00:51 +0800 | [diff] [blame] | 4061 | return -ENOMEM; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4062 | |
| 4063 | /* create platform component name */ |
| 4064 | platform->name = fmt_single_name(dev, &platform->id); |
| 4065 | if (platform->name == NULL) { |
| 4066 | kfree(platform); |
| 4067 | return -ENOMEM; |
| 4068 | } |
| 4069 | |
| 4070 | platform->dev = dev; |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 4071 | platform->dapm.platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4072 | platform->driver = platform_drv; |
Liam Girdwood | aff46a0 | 2011-03-30 23:25:37 +0100 | [diff] [blame] | 4073 | platform->dapm.dev = dev; |
Liam Girdwood | 670ff44 | 2011-03-30 23:27:27 +0100 | [diff] [blame] | 4074 | platform->dapm.stream_event = platform_drv->stream_event; |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4075 | |
| 4076 | mutex_lock(&client_mutex); |
| 4077 | list_add(&platform->list, &platform_list); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 4078 | snd_soc_instantiate_cards(); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4079 | mutex_unlock(&client_mutex); |
| 4080 | |
| 4081 | pr_debug("Registered platform '%s'\n", platform->name); |
| 4082 | |
| 4083 | return 0; |
| 4084 | } |
| 4085 | EXPORT_SYMBOL_GPL(snd_soc_register_platform); |
| 4086 | |
| 4087 | /** |
| 4088 | * snd_soc_unregister_platform - Unregister a platform from the ASoC core |
| 4089 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 4090 | * @platform: platform to unregister |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4091 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4092 | void snd_soc_unregister_platform(struct device *dev) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4093 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4094 | struct snd_soc_platform *platform; |
| 4095 | |
| 4096 | list_for_each_entry(platform, &platform_list, list) { |
| 4097 | if (dev == platform->dev) |
| 4098 | goto found; |
| 4099 | } |
| 4100 | return; |
| 4101 | |
| 4102 | found: |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4103 | mutex_lock(&client_mutex); |
| 4104 | list_del(&platform->list); |
| 4105 | mutex_unlock(&client_mutex); |
| 4106 | |
| 4107 | pr_debug("Unregistered platform '%s'\n", platform->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4108 | kfree(platform->name); |
| 4109 | kfree(platform); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 4110 | } |
| 4111 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
| 4112 | |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 4113 | static u64 codec_format_map[] = { |
| 4114 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, |
| 4115 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, |
| 4116 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, |
| 4117 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, |
| 4118 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, |
| 4119 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, |
| 4120 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 4121 | SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 4122 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, |
| 4123 | SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, |
| 4124 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, |
| 4125 | SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, |
| 4126 | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, |
| 4127 | SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, |
| 4128 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE |
| 4129 | | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, |
| 4130 | }; |
| 4131 | |
| 4132 | /* Fix up the DAI formats for endianness: codecs don't actually see |
| 4133 | * the endianness of the data but we're using the CPU format |
| 4134 | * definitions which do need to include endianness so we ensure that |
| 4135 | * codec DAIs always have both big and little endian variants set. |
| 4136 | */ |
| 4137 | static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) |
| 4138 | { |
| 4139 | int i; |
| 4140 | |
| 4141 | for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) |
| 4142 | if (stream->formats & codec_format_map[i]) |
| 4143 | stream->formats |= codec_format_map[i]; |
| 4144 | } |
| 4145 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4146 | /** |
| 4147 | * snd_soc_register_codec - Register a codec with the ASoC core |
| 4148 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 4149 | * @codec: codec to register |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4150 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4151 | int snd_soc_register_codec(struct device *dev, |
Mark Brown | 001ae4c | 2010-12-02 16:21:08 +0000 | [diff] [blame] | 4152 | const struct snd_soc_codec_driver *codec_drv, |
| 4153 | struct snd_soc_dai_driver *dai_drv, |
| 4154 | int num_dai) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4155 | { |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4156 | size_t reg_size; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4157 | struct snd_soc_codec *codec; |
| 4158 | int ret, i; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 4159 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4160 | dev_dbg(dev, "codec register %s\n", dev_name(dev)); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4161 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4162 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 4163 | if (codec == NULL) |
| 4164 | return -ENOMEM; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4165 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4166 | /* create CODEC component name */ |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 4167 | if (codec_drv == &null_codec_drv) |
| 4168 | codec->name = kstrdup("null-codec", GFP_KERNEL); |
| 4169 | else |
| 4170 | codec->name = fmt_single_name(dev, &codec->id); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4171 | if (codec->name == NULL) { |
| 4172 | kfree(codec); |
| 4173 | return -ENOMEM; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 4174 | } |
| 4175 | |
Dimitris Papastamos | 23bbce3 | 2010-12-02 14:53:01 +0000 | [diff] [blame] | 4176 | if (codec_drv->compress_type) |
| 4177 | codec->compress_type = codec_drv->compress_type; |
| 4178 | else |
| 4179 | codec->compress_type = SND_SOC_FLAT_COMPRESSION; |
| 4180 | |
Mark Brown | c3acec2 | 2010-12-02 16:15:29 +0000 | [diff] [blame] | 4181 | codec->write = codec_drv->write; |
| 4182 | codec->read = codec_drv->read; |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 4183 | codec->volatile_register = codec_drv->volatile_register; |
| 4184 | codec->readable_register = codec_drv->readable_register; |
Dimitris Papastamos | 8020454 | 2011-03-24 13:45:17 +0000 | [diff] [blame] | 4185 | codec->writable_register = codec_drv->writable_register; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4186 | codec->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 4187 | codec->dapm.dev = dev; |
| 4188 | codec->dapm.codec = codec; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 4189 | codec->dapm.seq_notifier = codec_drv->seq_notifier; |
Liam Girdwood | 670ff44 | 2011-03-30 23:27:27 +0100 | [diff] [blame] | 4190 | codec->dapm.stream_event = codec_drv->stream_event; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4191 | codec->dev = dev; |
| 4192 | codec->driver = codec_drv; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4193 | codec->num_dai = num_dai; |
| 4194 | mutex_init(&codec->mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4195 | |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 4196 | /* allocate CODEC register cache */ |
| 4197 | if (codec_drv->reg_cache_size && codec_drv->reg_word_size) { |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4198 | reg_size = codec_drv->reg_cache_size * codec_drv->reg_word_size; |
Dimitris Papastamos | aea170a | 2011-01-12 10:38:58 +0000 | [diff] [blame] | 4199 | codec->reg_size = reg_size; |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4200 | /* it is necessary to make a copy of the default register cache |
| 4201 | * because in the case of using a compression type that requires |
| 4202 | * the default register cache to be marked as __devinitconst the |
| 4203 | * kernel might have freed the array by the time we initialize |
| 4204 | * the cache. |
| 4205 | */ |
Dimitris Papastamos | 2aa8632 | 2011-01-10 10:10:56 +0000 | [diff] [blame] | 4206 | if (codec_drv->reg_cache_default) { |
| 4207 | codec->reg_def_copy = kmemdup(codec_drv->reg_cache_default, |
| 4208 | reg_size, GFP_KERNEL); |
| 4209 | if (!codec->reg_def_copy) { |
| 4210 | ret = -ENOMEM; |
| 4211 | goto fail; |
| 4212 | } |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 4213 | } |
| 4214 | } |
| 4215 | |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 4216 | if (codec_drv->reg_access_size && codec_drv->reg_access_default) { |
| 4217 | if (!codec->volatile_register) |
| 4218 | codec->volatile_register = snd_soc_default_volatile_register; |
| 4219 | if (!codec->readable_register) |
| 4220 | codec->readable_register = snd_soc_default_readable_register; |
Dimitris Papastamos | 8020454 | 2011-03-24 13:45:17 +0000 | [diff] [blame] | 4221 | if (!codec->writable_register) |
| 4222 | codec->writable_register = snd_soc_default_writable_register; |
Dimitris Papastamos | 1500b7b | 2011-01-13 12:20:38 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4225 | for (i = 0; i < num_dai; i++) { |
| 4226 | fixup_codec_formats(&dai_drv[i].playback); |
| 4227 | fixup_codec_formats(&dai_drv[i].capture); |
| 4228 | } |
| 4229 | |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 4230 | /* register any DAIs */ |
| 4231 | if (num_dai) { |
| 4232 | ret = snd_soc_register_dais(dev, dai_drv, num_dai); |
| 4233 | if (ret < 0) |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 4234 | goto fail; |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 4235 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4236 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4237 | mutex_lock(&client_mutex); |
| 4238 | list_add(&codec->list, &codec_list); |
| 4239 | snd_soc_instantiate_cards(); |
| 4240 | mutex_unlock(&client_mutex); |
| 4241 | |
| 4242 | pr_debug("Registered codec '%s'\n", codec->name); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4243 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4244 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 4245 | fail: |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4246 | kfree(codec->reg_def_copy); |
| 4247 | codec->reg_def_copy = NULL; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4248 | kfree(codec->name); |
| 4249 | kfree(codec); |
| 4250 | return ret; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4251 | } |
| 4252 | EXPORT_SYMBOL_GPL(snd_soc_register_codec); |
| 4253 | |
| 4254 | /** |
| 4255 | * snd_soc_unregister_codec - Unregister a codec from the ASoC core |
| 4256 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 4257 | * @codec: codec to unregister |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4258 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4259 | void snd_soc_unregister_codec(struct device *dev) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4260 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4261 | struct snd_soc_codec *codec; |
| 4262 | int i; |
| 4263 | |
| 4264 | list_for_each_entry(codec, &codec_list, list) { |
| 4265 | if (dev == codec->dev) |
| 4266 | goto found; |
| 4267 | } |
| 4268 | return; |
| 4269 | |
| 4270 | found: |
Mark Brown | 26b01cc | 2010-08-18 20:20:55 +0100 | [diff] [blame] | 4271 | if (codec->num_dai) |
| 4272 | for (i = 0; i < codec->num_dai; i++) |
| 4273 | snd_soc_unregister_dai(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4274 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4275 | mutex_lock(&client_mutex); |
| 4276 | list_del(&codec->list); |
| 4277 | mutex_unlock(&client_mutex); |
| 4278 | |
| 4279 | pr_debug("Unregistered codec '%s'\n", codec->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4280 | |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 4281 | snd_soc_cache_exit(codec); |
Dimitris Papastamos | 3335ddc | 2010-12-02 16:11:05 +0000 | [diff] [blame] | 4282 | kfree(codec->reg_def_copy); |
Dimitris Papastamos | 1aafcd4 | 2010-10-21 13:19:45 +0100 | [diff] [blame] | 4283 | kfree(codec->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4284 | kfree(codec); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 4285 | } |
| 4286 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
| 4287 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 4288 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4289 | { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4290 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4291 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); |
| 4292 | if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4293 | printk(KERN_WARNING |
| 4294 | "ASoC: Failed to create debugfs directory\n"); |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4295 | snd_soc_debugfs_root = NULL; |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4296 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 4297 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4298 | if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 4299 | &codec_list_fops)) |
| 4300 | pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); |
| 4301 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4302 | if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 4303 | &dai_list_fops)) |
| 4304 | pr_warn("ASoC: Failed to create DAI list debugfs file\n"); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 4305 | |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4306 | if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 4307 | &platform_list_fops)) |
| 4308 | pr_warn("ASoC: Failed to create platform list debugfs file\n"); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4309 | #endif |
| 4310 | |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 4311 | snd_soc_util_init(); |
| 4312 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4313 | return platform_driver_register(&soc_driver); |
| 4314 | } |
Mark Brown | 4abe8e1 | 2010-10-12 17:41:03 +0100 | [diff] [blame] | 4315 | module_init(snd_soc_init); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4316 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 4317 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4318 | { |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 4319 | snd_soc_util_exit(); |
| 4320 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4321 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 4322 | debugfs_remove_recursive(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 4323 | #endif |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 4324 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4325 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4326 | module_exit(snd_soc_exit); |
| 4327 | |
| 4328 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 4329 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 4330 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 4331 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 4332 | MODULE_ALIAS("platform:soc-audio"); |