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