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