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