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