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