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