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