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