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