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