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