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