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