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