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