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 | |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 194 | static struct attribute *soc_dev_attrs[] = { |
| 195 | &dev_attr_codec_reg.attr, |
| 196 | &dev_attr_pmdown_time.attr, |
| 197 | NULL |
| 198 | }; |
| 199 | |
| 200 | static umode_t soc_dev_attr_is_visible(struct kobject *kobj, |
| 201 | struct attribute *attr, int idx) |
| 202 | { |
| 203 | struct device *dev = kobj_to_dev(kobj); |
| 204 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
| 205 | |
| 206 | if (attr == &dev_attr_pmdown_time.attr) |
| 207 | return attr->mode; /* always visible */ |
| 208 | return rtd->codec ? attr->mode : 0; /* enabled only with codec */ |
| 209 | } |
| 210 | |
| 211 | static const struct attribute_group soc_dapm_dev_group = { |
| 212 | .attrs = soc_dapm_dev_attrs, |
| 213 | .is_visible = soc_dev_attr_is_visible, |
| 214 | }; |
| 215 | |
| 216 | static const struct attribute_group soc_dev_roup = { |
| 217 | .attrs = soc_dev_attrs, |
| 218 | .is_visible = soc_dev_attr_is_visible, |
| 219 | }; |
| 220 | |
| 221 | static const struct attribute_group *soc_dev_attr_groups[] = { |
| 222 | &soc_dapm_dev_group, |
| 223 | &soc_dev_roup, |
| 224 | NULL |
| 225 | }; |
| 226 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 227 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 228 | 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] | 229 | size_t count, loff_t *ppos) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 230 | { |
| 231 | ssize_t ret; |
| 232 | struct snd_soc_codec *codec = file->private_data; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 233 | char *buf; |
| 234 | |
| 235 | if (*ppos < 0 || !count) |
| 236 | return -EINVAL; |
| 237 | |
| 238 | buf = kmalloc(count, GFP_KERNEL); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 239 | if (!buf) |
| 240 | return -ENOMEM; |
Dimitris Papastamos | 13fd179 | 2011-02-02 13:58:58 +0000 | [diff] [blame] | 241 | |
| 242 | ret = soc_codec_reg_show(codec, buf, count, *ppos); |
| 243 | if (ret >= 0) { |
| 244 | if (copy_to_user(user_buf, buf, ret)) { |
| 245 | kfree(buf); |
| 246 | return -EFAULT; |
| 247 | } |
| 248 | *ppos += ret; |
| 249 | } |
| 250 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 251 | kfree(buf); |
| 252 | return ret; |
| 253 | } |
| 254 | |
| 255 | static ssize_t codec_reg_write_file(struct file *file, |
| 256 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 257 | { |
| 258 | char buf[32]; |
Stephen Boyd | 34e268d | 2011-05-12 16:50:10 -0700 | [diff] [blame] | 259 | size_t buf_size; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 260 | char *start = buf; |
| 261 | unsigned long reg, value; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 262 | struct snd_soc_codec *codec = file->private_data; |
Jingoo Han | b785a49 | 2013-07-19 16:24:59 +0900 | [diff] [blame] | 263 | int ret; |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 264 | |
| 265 | buf_size = min(count, (sizeof(buf)-1)); |
| 266 | if (copy_from_user(buf, user_buf, buf_size)) |
| 267 | return -EFAULT; |
| 268 | buf[buf_size] = 0; |
| 269 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 270 | while (*start == ' ') |
| 271 | start++; |
| 272 | reg = simple_strtoul(start, &start, 16); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 273 | while (*start == ' ') |
| 274 | start++; |
Jingoo Han | b785a49 | 2013-07-19 16:24:59 +0900 | [diff] [blame] | 275 | ret = kstrtoul(start, 16, &value); |
| 276 | if (ret) |
| 277 | return ret; |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 278 | |
| 279 | /* Userspace has been fiddling around behind the kernel's back */ |
Rusty Russell | 373d4d0 | 2013-01-21 17:17:39 +1030 | [diff] [blame] | 280 | add_taint(TAINT_USER, LOCKDEP_NOW_UNRELIABLE); |
Mark Brown | 0d51a9c | 2011-01-06 16:04:57 +0000 | [diff] [blame] | 281 | |
Dimitris Papastamos | e4f078d | 2010-12-07 16:30:38 +0000 | [diff] [blame] | 282 | snd_soc_write(codec, reg, value); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 283 | return buf_size; |
| 284 | } |
| 285 | |
| 286 | static const struct file_operations codec_reg_fops = { |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 287 | .open = simple_open, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 288 | .read = codec_reg_read_file, |
| 289 | .write = codec_reg_write_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 290 | .llseek = default_llseek, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 291 | }; |
| 292 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 293 | static void soc_init_component_debugfs(struct snd_soc_component *component) |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 294 | { |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame^] | 295 | if (!component->card->debugfs_card_root) |
| 296 | return; |
| 297 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 298 | if (component->debugfs_prefix) { |
| 299 | char *name; |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 300 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 301 | name = kasprintf(GFP_KERNEL, "%s:%s", |
| 302 | component->debugfs_prefix, component->name); |
| 303 | if (name) { |
| 304 | component->debugfs_root = debugfs_create_dir(name, |
| 305 | component->card->debugfs_card_root); |
| 306 | kfree(name); |
| 307 | } |
| 308 | } else { |
| 309 | component->debugfs_root = debugfs_create_dir(component->name, |
| 310 | component->card->debugfs_card_root); |
| 311 | } |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 312 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 313 | if (!component->debugfs_root) { |
| 314 | dev_warn(component->dev, |
| 315 | "ASoC: Failed to create component debugfs directory\n"); |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 316 | return; |
| 317 | } |
| 318 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 319 | snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component), |
| 320 | component->debugfs_root); |
| 321 | |
| 322 | if (component->init_debugfs) |
| 323 | component->init_debugfs(component); |
| 324 | } |
| 325 | |
| 326 | static void soc_cleanup_component_debugfs(struct snd_soc_component *component) |
| 327 | { |
| 328 | debugfs_remove_recursive(component->debugfs_root); |
| 329 | } |
| 330 | |
| 331 | static void soc_init_codec_debugfs(struct snd_soc_component *component) |
| 332 | { |
| 333 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 334 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 335 | codec->debugfs_reg = debugfs_create_file("codec_reg", 0644, |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 336 | codec->component.debugfs_root, |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 337 | codec, &codec_reg_fops); |
| 338 | if (!codec->debugfs_reg) |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 339 | dev_warn(codec->dev, |
| 340 | "ASoC: Failed to create codec register debugfs file\n"); |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 343 | static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, |
| 344 | size_t count, loff_t *ppos) |
| 345 | { |
| 346 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 347 | ssize_t len, ret = 0; |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 348 | struct snd_soc_codec *codec; |
| 349 | |
| 350 | if (!buf) |
| 351 | return -ENOMEM; |
| 352 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 353 | mutex_lock(&client_mutex); |
| 354 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 355 | list_for_each_entry(codec, &codec_list, list) { |
| 356 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 357 | codec->component.name); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 358 | if (len >= 0) |
| 359 | ret += len; |
| 360 | if (ret > PAGE_SIZE) { |
| 361 | ret = PAGE_SIZE; |
| 362 | break; |
| 363 | } |
| 364 | } |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 365 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 366 | mutex_unlock(&client_mutex); |
| 367 | |
Mark Brown | c3c5a19 | 2010-09-15 18:15:14 +0100 | [diff] [blame] | 368 | if (ret >= 0) |
| 369 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 370 | |
| 371 | kfree(buf); |
| 372 | |
| 373 | return ret; |
| 374 | } |
| 375 | |
| 376 | static const struct file_operations codec_list_fops = { |
| 377 | .read = codec_list_read_file, |
| 378 | .llseek = default_llseek,/* read accesses f_pos */ |
| 379 | }; |
| 380 | |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 381 | static ssize_t dai_list_read_file(struct file *file, 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; |
Lars-Peter Clausen | 1438c2f | 2014-03-09 17:41:47 +0100 | [diff] [blame] | 386 | struct snd_soc_component *component; |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 387 | struct snd_soc_dai *dai; |
| 388 | |
| 389 | if (!buf) |
| 390 | return -ENOMEM; |
| 391 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 392 | mutex_lock(&client_mutex); |
| 393 | |
Lars-Peter Clausen | 1438c2f | 2014-03-09 17:41:47 +0100 | [diff] [blame] | 394 | list_for_each_entry(component, &component_list, list) { |
| 395 | list_for_each_entry(dai, &component->dai_list, list) { |
| 396 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
| 397 | dai->name); |
| 398 | if (len >= 0) |
| 399 | ret += len; |
| 400 | if (ret > PAGE_SIZE) { |
| 401 | ret = PAGE_SIZE; |
| 402 | break; |
| 403 | } |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 404 | } |
| 405 | } |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 406 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 407 | mutex_unlock(&client_mutex); |
| 408 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 409 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 410 | |
| 411 | kfree(buf); |
| 412 | |
| 413 | return ret; |
| 414 | } |
| 415 | |
| 416 | static const struct file_operations dai_list_fops = { |
| 417 | .read = dai_list_read_file, |
| 418 | .llseek = default_llseek,/* read accesses f_pos */ |
| 419 | }; |
| 420 | |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 421 | static ssize_t platform_list_read_file(struct file *file, |
| 422 | char __user *user_buf, |
| 423 | size_t count, loff_t *ppos) |
| 424 | { |
| 425 | char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 426 | ssize_t len, ret = 0; |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 427 | struct snd_soc_platform *platform; |
| 428 | |
| 429 | if (!buf) |
| 430 | return -ENOMEM; |
| 431 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 432 | mutex_lock(&client_mutex); |
| 433 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 434 | list_for_each_entry(platform, &platform_list, list) { |
| 435 | len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 436 | platform->component.name); |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 437 | if (len >= 0) |
| 438 | ret += len; |
| 439 | if (ret > PAGE_SIZE) { |
| 440 | ret = PAGE_SIZE; |
| 441 | break; |
| 442 | } |
| 443 | } |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 444 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 445 | mutex_unlock(&client_mutex); |
| 446 | |
Mark Brown | 2b194f9d | 2010-10-13 10:52:16 +0100 | [diff] [blame] | 447 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
Mark Brown | 19c7ac2 | 2010-09-15 18:22:40 +0100 | [diff] [blame] | 448 | |
| 449 | kfree(buf); |
| 450 | |
| 451 | return ret; |
| 452 | } |
| 453 | |
| 454 | static const struct file_operations platform_list_fops = { |
| 455 | .read = platform_list_read_file, |
| 456 | .llseek = default_llseek,/* read accesses f_pos */ |
| 457 | }; |
| 458 | |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 459 | static void soc_init_card_debugfs(struct snd_soc_card *card) |
| 460 | { |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame^] | 461 | if (!snd_soc_debugfs_root) |
| 462 | return; |
| 463 | |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 464 | card->debugfs_card_root = debugfs_create_dir(card->name, |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 465 | snd_soc_debugfs_root); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 466 | if (!card->debugfs_card_root) { |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 467 | dev_warn(card->dev, |
Lothar Waßmann | 7c08be8 | 2011-12-09 14:16:29 +0100 | [diff] [blame] | 468 | "ASoC: Failed to create card debugfs directory\n"); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 469 | return; |
| 470 | } |
| 471 | |
| 472 | card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644, |
| 473 | card->debugfs_card_root, |
| 474 | &card->pop_time); |
| 475 | if (!card->debugfs_pop_time) |
| 476 | dev_warn(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 477 | "ASoC: Failed to create pop time debugfs file\n"); |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | static void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 481 | { |
| 482 | debugfs_remove_recursive(card->debugfs_card_root); |
| 483 | } |
| 484 | |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame^] | 485 | |
| 486 | static void snd_soc_debugfs_init(void) |
| 487 | { |
| 488 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); |
| 489 | if (IS_ERR(snd_soc_debugfs_root) || !snd_soc_debugfs_root) { |
| 490 | pr_warn("ASoC: Failed to create debugfs directory\n"); |
| 491 | snd_soc_debugfs_root = NULL; |
| 492 | return; |
| 493 | } |
| 494 | |
| 495 | if (!debugfs_create_file("codecs", 0444, snd_soc_debugfs_root, NULL, |
| 496 | &codec_list_fops)) |
| 497 | pr_warn("ASoC: Failed to create CODEC list debugfs file\n"); |
| 498 | |
| 499 | if (!debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, |
| 500 | &dai_list_fops)) |
| 501 | pr_warn("ASoC: Failed to create DAI list debugfs file\n"); |
| 502 | |
| 503 | if (!debugfs_create_file("platforms", 0444, snd_soc_debugfs_root, NULL, |
| 504 | &platform_list_fops)) |
| 505 | pr_warn("ASoC: Failed to create platform list debugfs file\n"); |
| 506 | } |
| 507 | |
| 508 | static void snd_soc_debugfs_exit(void) |
| 509 | { |
| 510 | debugfs_remove_recursive(snd_soc_debugfs_root); |
| 511 | } |
| 512 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 513 | #else |
| 514 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 515 | #define soc_init_codec_debugfs NULL |
| 516 | |
| 517 | static inline void soc_init_component_debugfs( |
| 518 | struct snd_soc_component *component) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 519 | { |
| 520 | } |
| 521 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 522 | static inline void soc_cleanup_component_debugfs( |
| 523 | struct snd_soc_component *component) |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 524 | { |
| 525 | } |
| 526 | |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 527 | static inline void soc_init_card_debugfs(struct snd_soc_card *card) |
| 528 | { |
| 529 | } |
| 530 | |
| 531 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 532 | { |
| 533 | } |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame^] | 534 | |
| 535 | static inline void snd_soc_debugfs_init(void) |
| 536 | { |
| 537 | } |
| 538 | |
| 539 | static inline void snd_soc_debugfs_exit(void) |
| 540 | { |
| 541 | } |
| 542 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 543 | #endif |
| 544 | |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 545 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, |
| 546 | const char *dai_link, int stream) |
| 547 | { |
| 548 | int i; |
| 549 | |
| 550 | for (i = 0; i < card->num_links; i++) { |
| 551 | if (card->rtd[i].dai_link->no_pcm && |
| 552 | !strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 553 | return card->rtd[i].pcm->streams[stream].substream; |
| 554 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 555 | 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] | 556 | return NULL; |
| 557 | } |
| 558 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); |
| 559 | |
| 560 | struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, |
| 561 | const char *dai_link) |
| 562 | { |
| 563 | int i; |
| 564 | |
| 565 | for (i = 0; i < card->num_links; i++) { |
| 566 | if (!strcmp(card->rtd[i].dai_link->name, dai_link)) |
| 567 | return &card->rtd[i]; |
| 568 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 569 | 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] | 570 | return NULL; |
| 571 | } |
| 572 | EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); |
| 573 | |
Richard Fitzgerald | 9d58a07 | 2013-08-05 13:17:28 +0100 | [diff] [blame] | 574 | static void codec2codec_close_delayed_work(struct work_struct *work) |
| 575 | { |
| 576 | /* Currently nothing to do for c2c links |
| 577 | * Since c2c links are internal nodes in the DAPM graph and |
| 578 | * don't interface with the outside world or application layer |
| 579 | * we don't have to do any special handling on close. |
| 580 | */ |
| 581 | } |
| 582 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 583 | #ifdef CONFIG_PM_SLEEP |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 584 | /* powers down audio subsystem for suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 585 | int snd_soc_suspend(struct device *dev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 586 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 587 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 588 | struct snd_soc_codec *codec; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 589 | int i, j; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 590 | |
Lars-Peter Clausen | c5599b8 | 2014-08-19 15:51:30 +0200 | [diff] [blame] | 591 | /* If the card is not initialized yet there is nothing to do */ |
| 592 | if (!card->instantiated) |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 593 | return 0; |
| 594 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 595 | /* Due to the resume being scheduled into a workqueue we could |
| 596 | * suspend before that's finished - wait for it to complete. |
| 597 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 598 | snd_power_lock(card->snd_card); |
| 599 | snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); |
| 600 | snd_power_unlock(card->snd_card); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 601 | |
| 602 | /* we're going to block userspace touching us until resume completes */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 603 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 604 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 605 | /* mute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 606 | for (i = 0; i < card->num_rtd; i++) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 607 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 608 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 609 | continue; |
| 610 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 611 | for (j = 0; j < card->rtd[i].num_codecs; j++) { |
| 612 | struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; |
| 613 | struct snd_soc_dai_driver *drv = dai->driver; |
| 614 | |
| 615 | if (drv->ops->digital_mute && dai->playback_active) |
| 616 | drv->ops->digital_mute(dai, 1); |
| 617 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 618 | } |
| 619 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 620 | /* suspend all pcms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 621 | for (i = 0; i < card->num_rtd; i++) { |
| 622 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 623 | continue; |
| 624 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 625 | snd_pcm_suspend_all(card->rtd[i].pcm); |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 626 | } |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 627 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 628 | if (card->suspend_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 629 | card->suspend_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 630 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 631 | for (i = 0; i < card->num_rtd; i++) { |
| 632 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 633 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 634 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 635 | continue; |
| 636 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 637 | if (cpu_dai->driver->suspend && !cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 638 | cpu_dai->driver->suspend(cpu_dai); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 639 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 640 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 641 | /* close any waiting streams and save state */ |
| 642 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 643 | struct snd_soc_dai **codec_dais = card->rtd[i].codec_dais; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 644 | flush_delayed_work(&card->rtd[i].delayed_work); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 645 | for (j = 0; j < card->rtd[i].num_codecs; j++) { |
| 646 | codec_dais[j]->codec->dapm.suspend_bias_level = |
| 647 | codec_dais[j]->codec->dapm.bias_level; |
| 648 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 649 | } |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 650 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 651 | for (i = 0; i < card->num_rtd; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 652 | |
| 653 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 654 | continue; |
| 655 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 656 | snd_soc_dapm_stream_event(&card->rtd[i], |
| 657 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 658 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 659 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 660 | snd_soc_dapm_stream_event(&card->rtd[i], |
| 661 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 662 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 665 | /* Recheck all endpoints too, their state is affected by suspend */ |
| 666 | dapm_mark_endpoints_dirty(card); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 667 | snd_soc_dapm_sync(&card->dapm); |
| 668 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 669 | /* suspend all CODECs */ |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 670 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 671 | /* If there are paths active then the CODEC will be held with |
| 672 | * bias _ON and should not be suspended. */ |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 673 | if (!codec->suspended) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 674 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 675 | case SND_SOC_BIAS_STANDBY: |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 676 | /* |
| 677 | * If the CODEC is capable of idle |
| 678 | * bias off then being in STANDBY |
| 679 | * means it's doing something, |
| 680 | * otherwise fall through. |
| 681 | */ |
| 682 | if (codec->dapm.idle_bias_off) { |
| 683 | dev_dbg(codec->dev, |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 684 | "ASoC: idle_bias_off CODEC on over suspend\n"); |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 685 | break; |
| 686 | } |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 687 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 688 | case SND_SOC_BIAS_OFF: |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 689 | if (codec->driver->suspend) |
| 690 | codec->driver->suspend(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 691 | codec->suspended = 1; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 692 | if (codec->component.regmap) |
| 693 | regcache_mark_dirty(codec->component.regmap); |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 694 | /* deactivate pins to sleep state */ |
| 695 | pinctrl_pm_select_sleep_state(codec->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 696 | break; |
| 697 | default: |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 698 | dev_dbg(codec->dev, |
| 699 | "ASoC: CODEC is on over suspend\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 700 | break; |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | for (i = 0; i < card->num_rtd; i++) { |
| 706 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
| 707 | |
| 708 | if (card->rtd[i].dai_link->ignore_suspend) |
| 709 | continue; |
| 710 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 711 | if (cpu_dai->driver->suspend && cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 712 | cpu_dai->driver->suspend(cpu_dai); |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 713 | |
| 714 | /* deactivate pins to sleep state */ |
| 715 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 716 | } |
| 717 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 718 | if (card->suspend_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 719 | card->suspend_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 720 | |
| 721 | return 0; |
| 722 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 723 | EXPORT_SYMBOL_GPL(snd_soc_suspend); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 724 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 725 | /* deferred resume work, so resume can complete before we finished |
| 726 | * setting our codec back up, which can be very slow on I2C |
| 727 | */ |
| 728 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 729 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 730 | struct snd_soc_card *card = |
| 731 | container_of(work, struct snd_soc_card, deferred_resume_work); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 732 | struct snd_soc_codec *codec; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 733 | int i, j; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 734 | |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 735 | /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
| 736 | * so userspace apps are blocked from touching us |
| 737 | */ |
| 738 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 739 | dev_dbg(card->dev, "ASoC: starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 740 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 741 | /* Bring us up into D2 so that DAPM starts enabling things */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 742 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 743 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 744 | if (card->resume_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 745 | card->resume_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 746 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 747 | /* resume control bus DAIs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 748 | for (i = 0; i < card->num_rtd; i++) { |
| 749 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 750 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 751 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 752 | continue; |
| 753 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 754 | if (cpu_dai->driver->resume && cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 755 | cpu_dai->driver->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 758 | list_for_each_entry(codec, &card->codec_dev_list, card_list) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 759 | /* If the CODEC was idle over suspend then it will have been |
| 760 | * left with bias OFF or STANDBY and suspended so we must now |
| 761 | * resume. Otherwise the suspend was suppressed. |
| 762 | */ |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 763 | if (codec->suspended) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 764 | switch (codec->dapm.bias_level) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 765 | case SND_SOC_BIAS_STANDBY: |
| 766 | case SND_SOC_BIAS_OFF: |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 767 | if (codec->driver->resume) |
| 768 | codec->driver->resume(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 769 | codec->suspended = 0; |
| 770 | break; |
| 771 | default: |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 772 | dev_dbg(codec->dev, |
| 773 | "ASoC: CODEC was on over suspend\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 774 | break; |
| 775 | } |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 776 | } |
| 777 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 778 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 779 | for (i = 0; i < card->num_rtd; i++) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 780 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 781 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 782 | continue; |
| 783 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 784 | snd_soc_dapm_stream_event(&card->rtd[i], |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 785 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 786 | SND_SOC_DAPM_STREAM_RESUME); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 787 | |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 788 | snd_soc_dapm_stream_event(&card->rtd[i], |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 789 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 790 | SND_SOC_DAPM_STREAM_RESUME); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 791 | } |
| 792 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 793 | /* unmute any active DACs */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 794 | for (i = 0; i < card->num_rtd; i++) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 795 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 796 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 797 | continue; |
| 798 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 799 | for (j = 0; j < card->rtd[i].num_codecs; j++) { |
| 800 | struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; |
| 801 | struct snd_soc_dai_driver *drv = dai->driver; |
| 802 | |
| 803 | if (drv->ops->digital_mute && dai->playback_active) |
| 804 | drv->ops->digital_mute(dai, 0); |
| 805 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 806 | } |
| 807 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 808 | for (i = 0; i < card->num_rtd; i++) { |
| 809 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 810 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 811 | if (card->rtd[i].dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 812 | continue; |
| 813 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 814 | if (cpu_dai->driver->resume && !cpu_dai->driver->bus_control) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 815 | cpu_dai->driver->resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 816 | } |
| 817 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 818 | if (card->resume_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 819 | card->resume_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 820 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 821 | dev_dbg(card->dev, "ASoC: resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 822 | |
| 823 | /* userspace can access us now we are back as we were before */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 824 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 825 | |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 826 | /* Recheck all endpoints too, their state is affected by suspend */ |
| 827 | dapm_mark_endpoints_dirty(card); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 828 | snd_soc_dapm_sync(&card->dapm); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | /* powers up audio subsystem after a suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 832 | int snd_soc_resume(struct device *dev) |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 833 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 834 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 835 | bool bus_control = false; |
| 836 | int i; |
Peter Ujfalusi | b9dd94a | 2010-02-22 13:27:13 +0200 | [diff] [blame] | 837 | |
Lars-Peter Clausen | c5599b8 | 2014-08-19 15:51:30 +0200 | [diff] [blame] | 838 | /* If the card is not initialized yet there is nothing to do */ |
| 839 | if (!card->instantiated) |
Eric Miao | 5ff1ddf | 2011-11-23 22:37:00 +0800 | [diff] [blame] | 840 | return 0; |
| 841 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 842 | /* activate pins from sleep state */ |
| 843 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 844 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 845 | struct snd_soc_dai **codec_dais = rtd->codec_dais; |
| 846 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 847 | int j; |
| 848 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 849 | if (cpu_dai->active) |
| 850 | pinctrl_pm_select_default_state(cpu_dai->dev); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 851 | |
| 852 | for (j = 0; j < rtd->num_codecs; j++) { |
| 853 | struct snd_soc_dai *codec_dai = codec_dais[j]; |
| 854 | if (codec_dai->active) |
| 855 | pinctrl_pm_select_default_state(codec_dai->dev); |
| 856 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 857 | } |
| 858 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 859 | /* |
| 860 | * DAIs that also act as the control bus master might have other drivers |
| 861 | * hanging off them so need to resume immediately. Other drivers don't |
| 862 | * 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] | 863 | * due to I/O costs and anti-pop so handle them out of line. |
| 864 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 865 | for (i = 0; i < card->num_rtd; i++) { |
| 866 | struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 867 | bus_control |= cpu_dai->driver->bus_control; |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 868 | } |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 869 | if (bus_control) { |
| 870 | dev_dbg(dev, "ASoC: Resuming control bus master immediately\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 871 | soc_resume_deferred(&card->deferred_resume_work); |
| 872 | } else { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 873 | dev_dbg(dev, "ASoC: Scheduling resume work\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 874 | if (!schedule_work(&card->deferred_resume_work)) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 875 | dev_err(dev, "ASoC: resume work item may be lost\n"); |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 876 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 877 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 878 | return 0; |
| 879 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 880 | EXPORT_SYMBOL_GPL(snd_soc_resume); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 881 | #else |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 882 | #define snd_soc_suspend NULL |
| 883 | #define snd_soc_resume NULL |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 884 | #endif |
| 885 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 886 | static const struct snd_soc_dai_ops null_dai_ops = { |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 887 | }; |
| 888 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 889 | static struct snd_soc_component *soc_find_component( |
| 890 | const struct device_node *of_node, const char *name) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 891 | { |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 892 | struct snd_soc_component *component; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 893 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 894 | lockdep_assert_held(&client_mutex); |
| 895 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 896 | list_for_each_entry(component, &component_list, list) { |
| 897 | if (of_node) { |
| 898 | if (component->dev->of_node == of_node) |
| 899 | return component; |
| 900 | } else if (strcmp(component->name, name) == 0) { |
| 901 | return component; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 902 | } |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | return NULL; |
| 906 | } |
| 907 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 908 | static struct snd_soc_dai *snd_soc_find_dai( |
| 909 | const struct snd_soc_dai_link_component *dlc) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 910 | { |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 911 | struct snd_soc_component *component; |
| 912 | struct snd_soc_dai *dai; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 913 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 914 | lockdep_assert_held(&client_mutex); |
| 915 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 916 | /* Find CPU DAI from registered DAIs*/ |
| 917 | list_for_each_entry(component, &component_list, list) { |
| 918 | if (dlc->of_node && component->dev->of_node != dlc->of_node) |
| 919 | continue; |
Lars-Peter Clausen | 1ffae36 | 2014-10-29 21:46:30 +0100 | [diff] [blame] | 920 | if (dlc->name && strcmp(component->name, dlc->name)) |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 921 | continue; |
| 922 | list_for_each_entry(dai, &component->dai_list, list) { |
| 923 | if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 924 | continue; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 925 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 926 | return dai; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | return NULL; |
| 931 | } |
| 932 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 933 | 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] | 934 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 935 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 936 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 937 | struct snd_soc_dai_link_component *codecs = dai_link->codecs; |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 938 | struct snd_soc_dai_link_component cpu_dai_component; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 939 | struct snd_soc_dai **codec_dais = rtd->codec_dais; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 940 | struct snd_soc_platform *platform; |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 941 | const char *platform_name; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 942 | int i; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 943 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 944 | 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] | 945 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 946 | cpu_dai_component.name = dai_link->cpu_name; |
| 947 | cpu_dai_component.of_node = dai_link->cpu_of_node; |
| 948 | cpu_dai_component.dai_name = dai_link->cpu_dai_name; |
| 949 | rtd->cpu_dai = snd_soc_find_dai(&cpu_dai_component); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 950 | if (!rtd->cpu_dai) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 951 | dev_err(card->dev, "ASoC: CPU DAI %s not registered\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 952 | dai_link->cpu_dai_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 953 | return -EPROBE_DEFER; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 956 | rtd->num_codecs = dai_link->num_codecs; |
| 957 | |
| 958 | /* Find CODEC from registered CODECs */ |
| 959 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 960 | codec_dais[i] = snd_soc_find_dai(&codecs[i]); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 961 | if (!codec_dais[i]) { |
| 962 | dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", |
| 963 | codecs[i].dai_name); |
| 964 | return -EPROBE_DEFER; |
| 965 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 966 | } |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 967 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 968 | /* Single codec links expect codec and codec_dai in runtime data */ |
| 969 | rtd->codec_dai = codec_dais[0]; |
| 970 | rtd->codec = rtd->codec_dai->codec; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 971 | |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 972 | /* if there's no platform we match on the empty platform */ |
| 973 | platform_name = dai_link->platform_name; |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 974 | if (!platform_name && !dai_link->platform_of_node) |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 975 | platform_name = "snd-soc-dummy"; |
| 976 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 977 | /* find one from the set of registered platforms */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 978 | list_for_each_entry(platform, &platform_list, list) { |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 979 | if (dai_link->platform_of_node) { |
| 980 | if (platform->dev->of_node != |
| 981 | dai_link->platform_of_node) |
| 982 | continue; |
| 983 | } else { |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 984 | if (strcmp(platform->component.name, platform_name)) |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 985 | continue; |
| 986 | } |
Stephen Warren | 2610ab7 | 2011-12-07 13:58:27 -0700 | [diff] [blame] | 987 | |
| 988 | rtd->platform = platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 989 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 990 | if (!rtd->platform) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 991 | dev_err(card->dev, "ASoC: platform %s not registered\n", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 992 | dai_link->platform_name); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 993 | return -EPROBE_DEFER; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 994 | } |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 995 | |
| 996 | card->num_rtd++; |
| 997 | |
| 998 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1001 | static void soc_remove_component(struct snd_soc_component *component) |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 1002 | { |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1003 | if (!component->probed) |
| 1004 | return; |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 1005 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1006 | /* This is a HACK and will be removed soon */ |
| 1007 | if (component->codec) |
| 1008 | list_del(&component->codec->card_list); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 1009 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1010 | if (component->remove) |
| 1011 | component->remove(component); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 1012 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1013 | snd_soc_dapm_free(snd_soc_component_get_dapm(component)); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 1014 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1015 | soc_cleanup_component_debugfs(component); |
| 1016 | component->probed = 0; |
| 1017 | module_put(component->dev->driver->owner); |
Stephen Warren | d12cd19 | 2012-06-08 12:34:22 -0600 | [diff] [blame] | 1018 | } |
| 1019 | |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1020 | static void soc_remove_dai(struct snd_soc_dai *dai, int order) |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1021 | { |
| 1022 | int err; |
| 1023 | |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1024 | if (dai && dai->probed && |
| 1025 | dai->driver->remove_order == order) { |
| 1026 | if (dai->driver->remove) { |
| 1027 | err = dai->driver->remove(dai); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1028 | if (err < 0) |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1029 | dev_err(dai->dev, |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1030 | "ASoC: failed to remove %s: %d\n", |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1031 | dai->name, err); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1032 | } |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1033 | dai->probed = 0; |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1037 | 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] | 1038 | { |
| 1039 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1040 | int i; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1041 | |
| 1042 | /* unregister the rtd device */ |
| 1043 | if (rtd->dev_registered) { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1044 | device_unregister(rtd->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1045 | rtd->dev_registered = 0; |
| 1046 | } |
| 1047 | |
| 1048 | /* remove the CODEC DAI */ |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1049 | for (i = 0; i < rtd->num_codecs; i++) |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1050 | soc_remove_dai(rtd->codec_dais[i], order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1051 | |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1052 | soc_remove_dai(rtd->cpu_dai, order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1055 | static void soc_remove_link_components(struct snd_soc_card *card, int num, |
| 1056 | int order) |
| 1057 | { |
| 1058 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
| 1059 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1060 | struct snd_soc_platform *platform = rtd->platform; |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1061 | struct snd_soc_component *component; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1062 | int i; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1063 | |
| 1064 | /* remove the platform */ |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1065 | if (platform && platform->component.driver->remove_order == order) |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1066 | soc_remove_component(&platform->component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1067 | |
| 1068 | /* remove the CODEC-side CODEC */ |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1069 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1070 | component = rtd->codec_dais[i]->component; |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1071 | if (component->driver->remove_order == order) |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1072 | soc_remove_component(component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /* remove any CPU-side CODEC */ |
| 1076 | if (cpu_dai) { |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1077 | if (cpu_dai->component->driver->remove_order == order) |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1078 | soc_remove_component(cpu_dai->component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1082 | static void soc_remove_dai_links(struct snd_soc_card *card) |
| 1083 | { |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1084 | int dai, order; |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1085 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1086 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1087 | order++) { |
| 1088 | for (dai = 0; dai < card->num_rtd; dai++) |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1089 | soc_remove_link_dais(card, dai, order); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1090 | } |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1091 | |
| 1092 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1093 | order++) { |
| 1094 | for (dai = 0; dai < card->num_rtd; dai++) |
| 1095 | soc_remove_link_components(card, dai, order); |
| 1096 | } |
| 1097 | |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1098 | card->num_rtd = 0; |
| 1099 | } |
| 1100 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1101 | static void soc_set_name_prefix(struct snd_soc_card *card, |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1102 | struct snd_soc_component *component) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1103 | { |
| 1104 | int i; |
| 1105 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1106 | if (card->codec_conf == NULL) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1107 | return; |
| 1108 | |
Dimitris Papastamos | ff819b8 | 2010-12-02 14:53:03 +0000 | [diff] [blame] | 1109 | for (i = 0; i < card->num_configs; i++) { |
| 1110 | struct snd_soc_codec_conf *map = &card->codec_conf[i]; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1111 | if (map->of_node && component->dev->of_node != map->of_node) |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1112 | continue; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1113 | if (map->dev_name && strcmp(component->name, map->dev_name)) |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1114 | continue; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 1115 | component->name_prefix = map->name_prefix; |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1116 | break; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1120 | static int soc_probe_component(struct snd_soc_card *card, |
| 1121 | struct snd_soc_component *component) |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1122 | { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1123 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1124 | struct snd_soc_dai *dai; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1125 | int ret; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1126 | |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1127 | if (component->probed) |
| 1128 | return 0; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1129 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1130 | component->card = card; |
| 1131 | dapm->card = card; |
| 1132 | soc_set_name_prefix(card, component); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1133 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1134 | if (!try_module_get(component->dev->driver->owner)) |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1135 | return -ENODEV; |
| 1136 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1137 | soc_init_component_debugfs(component); |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1138 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1139 | if (component->dapm_widgets) { |
| 1140 | ret = snd_soc_dapm_new_controls(dapm, component->dapm_widgets, |
| 1141 | component->num_dapm_widgets); |
Nariman Poushin | b318ad5 | 2014-04-01 13:59:33 +0100 | [diff] [blame] | 1142 | |
| 1143 | if (ret != 0) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1144 | dev_err(component->dev, |
Nariman Poushin | b318ad5 | 2014-04-01 13:59:33 +0100 | [diff] [blame] | 1145 | "Failed to create new controls %d\n", ret); |
| 1146 | goto err_probe; |
| 1147 | } |
| 1148 | } |
Lars-Peter Clausen | 7753015 | 2011-05-05 16:59:09 +0200 | [diff] [blame] | 1149 | |
Lars-Peter Clausen | 0634814 | 2014-08-20 13:08:49 +0200 | [diff] [blame] | 1150 | list_for_each_entry(dai, &component->dai_list, list) { |
| 1151 | ret = snd_soc_dapm_new_dai_widgets(dapm, dai); |
Nariman Poushin | 261edc7 | 2014-03-31 15:47:12 +0100 | [diff] [blame] | 1152 | if (ret != 0) { |
Lars-Peter Clausen | 0634814 | 2014-08-20 13:08:49 +0200 | [diff] [blame] | 1153 | dev_err(component->dev, |
Nariman Poushin | 261edc7 | 2014-03-31 15:47:12 +0100 | [diff] [blame] | 1154 | "Failed to create DAI widgets %d\n", ret); |
| 1155 | goto err_probe; |
| 1156 | } |
| 1157 | } |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1158 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1159 | if (component->probe) { |
| 1160 | ret = component->probe(component); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1161 | if (ret < 0) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1162 | dev_err(component->dev, |
| 1163 | "ASoC: failed to probe component %d\n", ret); |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1164 | goto err_probe; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1165 | } |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1166 | |
| 1167 | WARN(dapm->idle_bias_off && |
| 1168 | dapm->bias_level != SND_SOC_BIAS_OFF, |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1169 | "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] | 1170 | component->name); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1171 | } |
| 1172 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1173 | if (component->controls) |
| 1174 | snd_soc_add_component_controls(component, component->controls, |
| 1175 | component->num_controls); |
| 1176 | if (component->dapm_routes) |
| 1177 | snd_soc_dapm_add_routes(dapm, component->dapm_routes, |
| 1178 | component->num_dapm_routes); |
Mark Brown | 89b95ac0 | 2011-03-07 16:38:44 +0000 | [diff] [blame] | 1179 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1180 | component->probed = 1; |
| 1181 | list_add(&dapm->list, &card->dapm_list); |
| 1182 | |
| 1183 | /* This is a HACK and will be removed soon */ |
| 1184 | if (component->codec) |
| 1185 | list_add(&component->codec->card_list, &card->codec_dev_list); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1186 | |
Jarkko Nikula | 70d2933 | 2011-01-27 16:24:22 +0200 | [diff] [blame] | 1187 | return 0; |
| 1188 | |
| 1189 | err_probe: |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1190 | soc_cleanup_component_debugfs(component); |
| 1191 | module_put(component->dev->driver->owner); |
Liam Girdwood | 956245e | 2011-07-01 16:54:08 +0100 | [diff] [blame] | 1192 | |
| 1193 | return ret; |
| 1194 | } |
| 1195 | |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1196 | static void rtd_release(struct device *dev) |
| 1197 | { |
| 1198 | kfree(dev); |
| 1199 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1200 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1201 | static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd, |
| 1202 | const char *name) |
Misael Lopez Cruz | 503ae5e | 2014-04-24 14:01:44 +0200 | [diff] [blame] | 1203 | { |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1204 | int ret = 0; |
| 1205 | |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1206 | /* register the rtd device */ |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1207 | rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 1208 | if (!rtd->dev) |
| 1209 | return -ENOMEM; |
| 1210 | device_initialize(rtd->dev); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1211 | rtd->dev->parent = rtd->card->dev; |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1212 | rtd->dev->release = rtd_release; |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 1213 | rtd->dev->groups = soc_dev_attr_groups; |
Lars-Peter Clausen | f294afe | 2014-08-17 11:28:35 +0200 | [diff] [blame] | 1214 | dev_set_name(rtd->dev, "%s", name); |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1215 | dev_set_drvdata(rtd->dev, rtd); |
Liam Girdwood | b8c0dab | 2011-06-09 17:04:39 +0100 | [diff] [blame] | 1216 | mutex_init(&rtd->pcm_mutex); |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 1217 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); |
| 1218 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); |
| 1219 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); |
| 1220 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1221 | ret = device_add(rtd->dev); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1222 | if (ret < 0) { |
Chuansheng Liu | 865df9c | 2012-12-26 00:56:05 +0800 | [diff] [blame] | 1223 | /* calling put_device() here to free the rtd->dev */ |
| 1224 | put_device(rtd->dev); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1225 | dev_err(rtd->card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1226 | "ASoC: failed to register runtime device: %d\n", ret); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1227 | return ret; |
| 1228 | } |
| 1229 | rtd->dev_registered = 1; |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1230 | return 0; |
| 1231 | } |
| 1232 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1233 | static int soc_probe_link_components(struct snd_soc_card *card, int num, |
| 1234 | int order) |
| 1235 | { |
| 1236 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1237 | struct snd_soc_platform *platform = rtd->platform; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1238 | struct snd_soc_component *component; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1239 | int i, ret; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1240 | |
| 1241 | /* probe the CPU-side component, if it is a CODEC */ |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1242 | component = rtd->cpu_dai->component; |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1243 | if (component->driver->probe_order == order) { |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1244 | ret = soc_probe_component(card, component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1245 | if (ret < 0) |
| 1246 | return ret; |
| 1247 | } |
| 1248 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1249 | /* probe the CODEC-side components */ |
| 1250 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1251 | component = rtd->codec_dais[i]->component; |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1252 | if (component->driver->probe_order == order) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1253 | ret = soc_probe_component(card, component); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1254 | if (ret < 0) |
| 1255 | return ret; |
| 1256 | } |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | /* probe the platform */ |
Lars-Peter Clausen | 70090bb | 2014-08-19 15:51:24 +0200 | [diff] [blame] | 1260 | if (platform->component.driver->probe_order == order) { |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 1261 | ret = soc_probe_component(card, &platform->component); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1262 | if (ret < 0) |
| 1263 | return ret; |
| 1264 | } |
| 1265 | |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1269 | static int soc_probe_dai(struct snd_soc_dai *dai, int order) |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1270 | { |
| 1271 | int ret; |
| 1272 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1273 | if (!dai->probed && dai->driver->probe_order == order) { |
| 1274 | if (dai->driver->probe) { |
| 1275 | ret = dai->driver->probe(dai); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1276 | if (ret < 0) { |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1277 | dev_err(dai->dev, |
| 1278 | "ASoC: failed to probe DAI %s: %d\n", |
| 1279 | dai->name, ret); |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1280 | return ret; |
| 1281 | } |
| 1282 | } |
| 1283 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1284 | dai->probed = 1; |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1290 | static int soc_link_dai_widgets(struct snd_soc_card *card, |
| 1291 | struct snd_soc_dai_link *dai_link, |
Benoit Cousson | 3f901a0 | 2014-07-01 09:47:54 +0200 | [diff] [blame] | 1292 | struct snd_soc_pcm_runtime *rtd) |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1293 | { |
Benoit Cousson | 3f901a0 | 2014-07-01 09:47:54 +0200 | [diff] [blame] | 1294 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1295 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1296 | struct snd_soc_dapm_widget *play_w, *capture_w; |
| 1297 | int ret; |
| 1298 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1299 | if (rtd->num_codecs > 1) |
| 1300 | dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n"); |
| 1301 | |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1302 | /* link the DAI widgets */ |
| 1303 | play_w = codec_dai->playback_widget; |
| 1304 | capture_w = cpu_dai->capture_widget; |
| 1305 | if (play_w && capture_w) { |
| 1306 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
| 1307 | capture_w, play_w); |
| 1308 | if (ret != 0) { |
| 1309 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
| 1310 | play_w->name, capture_w->name, ret); |
| 1311 | return ret; |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | play_w = cpu_dai->playback_widget; |
| 1316 | capture_w = codec_dai->capture_widget; |
| 1317 | if (play_w && capture_w) { |
| 1318 | ret = snd_soc_dapm_new_pcm(card, dai_link->params, |
| 1319 | capture_w, play_w); |
| 1320 | if (ret != 0) { |
| 1321 | dev_err(card->dev, "ASoC: Can't link %s to %s: %d\n", |
| 1322 | play_w->name, capture_w->name, ret); |
| 1323 | return ret; |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1330 | 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] | 1331 | { |
| 1332 | struct snd_soc_dai_link *dai_link = &card->dai_link[num]; |
| 1333 | struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1334 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1335 | int i, ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1336 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1337 | 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] | 1338 | card->name, num, order); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1339 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1340 | /* set default power off timeout */ |
| 1341 | rtd->pmdown_time = pmdown_time; |
| 1342 | |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1343 | ret = soc_probe_dai(cpu_dai, order); |
| 1344 | if (ret) |
| 1345 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1346 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1347 | /* probe the CODEC DAI */ |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1348 | for (i = 0; i < rtd->num_codecs; i++) { |
Lars-Peter Clausen | 8e2be56 | 2014-11-04 11:30:59 +0100 | [diff] [blame] | 1349 | ret = soc_probe_dai(rtd->codec_dais[i], order); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1350 | if (ret) |
| 1351 | return ret; |
| 1352 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1353 | |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1354 | /* complete DAI probe during last probe */ |
| 1355 | if (order != SND_SOC_COMP_ORDER_LAST) |
| 1356 | return 0; |
| 1357 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1358 | /* do machine specific initialization */ |
| 1359 | if (dai_link->init) { |
| 1360 | ret = dai_link->init(rtd); |
| 1361 | if (ret < 0) { |
| 1362 | dev_err(card->dev, "ASoC: failed to init %s: %d\n", |
| 1363 | dai_link->name, ret); |
| 1364 | return ret; |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | ret = soc_post_component_init(rtd, dai_link->name); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1369 | if (ret) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1370 | return ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1371 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1372 | #ifdef CONFIG_DEBUG_FS |
| 1373 | /* add DPCM sysfs entries */ |
Lars-Peter Clausen | 2e55b90 | 2015-04-09 10:52:37 +0200 | [diff] [blame] | 1374 | if (dai_link->dynamic) |
| 1375 | soc_dpcm_debugfs_add(rtd); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1376 | #endif |
| 1377 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1378 | if (cpu_dai->driver->compress_dai) { |
| 1379 | /*create compress_device"*/ |
| 1380 | ret = soc_new_compress(rtd, num); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1381 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1382 | dev_err(card->dev, "ASoC: can't create compress %s\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1383 | dai_link->stream_name); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1384 | return ret; |
| 1385 | } |
| 1386 | } else { |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1387 | |
| 1388 | if (!dai_link->params) { |
| 1389 | /* create the pcm */ |
| 1390 | ret = soc_new_pcm(rtd, num); |
| 1391 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1392 | dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1393 | dai_link->stream_name, ret); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1394 | return ret; |
| 1395 | } |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1396 | } else { |
Richard Fitzgerald | 9d58a07 | 2013-08-05 13:17:28 +0100 | [diff] [blame] | 1397 | INIT_DELAYED_WORK(&rtd->delayed_work, |
| 1398 | codec2codec_close_delayed_work); |
| 1399 | |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1400 | /* link the DAI widgets */ |
Benoit Cousson | 3f901a0 | 2014-07-01 09:47:54 +0200 | [diff] [blame] | 1401 | ret = soc_link_dai_widgets(card, dai_link, rtd); |
Misael Lopez Cruz | 2436a72 | 2014-03-21 16:27:27 +0100 | [diff] [blame] | 1402 | if (ret) |
| 1403 | return ret; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 1404 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1407 | return 0; |
| 1408 | } |
| 1409 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1410 | 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] | 1411 | { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1412 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1413 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1414 | const char *name = aux_dev->codec_name; |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1415 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1416 | rtd->component = soc_find_component(aux_dev->codec_of_node, name); |
| 1417 | if (!rtd->component) { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1418 | if (aux_dev->codec_of_node) |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1419 | name = of_node_full_name(aux_dev->codec_of_node); |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1420 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1421 | dev_err(card->dev, "ASoC: %s not registered\n", name); |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1422 | return -EPROBE_DEFER; |
| 1423 | } |
| 1424 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1425 | /* |
| 1426 | * Some places still reference rtd->codec, so we have to keep that |
| 1427 | * initialized if the component is a CODEC. Once all those references |
| 1428 | * have been removed, this code can be removed as well. |
| 1429 | */ |
| 1430 | rtd->codec = rtd->component->codec; |
| 1431 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1432 | return 0; |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1435 | static int soc_probe_aux_dev(struct snd_soc_card *card, int num) |
| 1436 | { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1437 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1438 | struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1439 | int ret; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1440 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1441 | ret = soc_probe_component(card, rtd->component); |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1442 | if (ret < 0) |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1443 | return ret; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1444 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1445 | /* do machine specific initialization */ |
| 1446 | if (aux_dev->init) { |
Lars-Peter Clausen | 57bf772 | 2014-08-19 15:51:23 +0200 | [diff] [blame] | 1447 | ret = aux_dev->init(rtd->component); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1448 | if (ret < 0) { |
| 1449 | dev_err(card->dev, "ASoC: failed to init %s: %d\n", |
| 1450 | aux_dev->name, ret); |
| 1451 | return ret; |
| 1452 | } |
| 1453 | } |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1454 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1455 | return soc_post_component_init(rtd, aux_dev->name); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | static void soc_remove_aux_dev(struct snd_soc_card *card, int num) |
| 1459 | { |
| 1460 | struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1461 | struct snd_soc_component *component = rtd->component; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1462 | |
| 1463 | /* unregister the rtd device */ |
| 1464 | if (rtd->dev_registered) { |
Chuansheng Liu | d3bf156 | 2012-12-26 00:57:32 +0800 | [diff] [blame] | 1465 | device_unregister(rtd->dev); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1466 | rtd->dev_registered = 0; |
| 1467 | } |
| 1468 | |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1469 | if (component && component->probed) |
| 1470 | soc_remove_component(component); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1471 | } |
| 1472 | |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 1473 | static int snd_soc_init_codec_cache(struct snd_soc_codec *codec) |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1474 | { |
| 1475 | int ret; |
| 1476 | |
| 1477 | if (codec->cache_init) |
| 1478 | return 0; |
| 1479 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1480 | ret = snd_soc_cache_init(codec); |
| 1481 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1482 | dev_err(codec->dev, |
| 1483 | "ASoC: Failed to set cache compression type: %d\n", |
| 1484 | ret); |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1485 | return ret; |
| 1486 | } |
| 1487 | codec->cache_init = 1; |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1491 | /** |
| 1492 | * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime |
| 1493 | * @rtd: The runtime for which the DAI link format should be changed |
| 1494 | * @dai_fmt: The new DAI link format |
| 1495 | * |
| 1496 | * This function updates the DAI link format for all DAIs connected to the DAI |
| 1497 | * link for the specified runtime. |
| 1498 | * |
| 1499 | * Note: For setups with a static format set the dai_fmt field in the |
| 1500 | * corresponding snd_dai_link struct instead of using this function. |
| 1501 | * |
| 1502 | * Returns 0 on success, otherwise a negative error code. |
| 1503 | */ |
| 1504 | int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, |
| 1505 | unsigned int dai_fmt) |
| 1506 | { |
| 1507 | struct snd_soc_dai **codec_dais = rtd->codec_dais; |
| 1508 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1509 | unsigned int i; |
| 1510 | int ret; |
| 1511 | |
| 1512 | for (i = 0; i < rtd->num_codecs; i++) { |
| 1513 | struct snd_soc_dai *codec_dai = codec_dais[i]; |
| 1514 | |
| 1515 | ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); |
| 1516 | if (ret != 0 && ret != -ENOTSUPP) { |
| 1517 | dev_warn(codec_dai->dev, |
| 1518 | "ASoC: Failed to set DAI format: %d\n", ret); |
| 1519 | return ret; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */ |
| 1524 | if (cpu_dai->codec) { |
| 1525 | unsigned int inv_dai_fmt; |
| 1526 | |
| 1527 | inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK; |
| 1528 | switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1529 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1530 | inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; |
| 1531 | break; |
| 1532 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1533 | inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; |
| 1534 | break; |
| 1535 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1536 | inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; |
| 1537 | break; |
| 1538 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1539 | inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; |
| 1540 | break; |
| 1541 | } |
| 1542 | |
| 1543 | dai_fmt = inv_dai_fmt; |
| 1544 | } |
| 1545 | |
| 1546 | ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); |
| 1547 | if (ret != 0 && ret != -ENOTSUPP) { |
| 1548 | dev_warn(cpu_dai->dev, |
| 1549 | "ASoC: Failed to set DAI format: %d\n", ret); |
| 1550 | return ret; |
| 1551 | } |
| 1552 | |
| 1553 | return 0; |
| 1554 | } |
Lars-Peter Clausen | ddaca25 | 2015-01-08 12:23:05 +0100 | [diff] [blame] | 1555 | EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt); |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1556 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1557 | static int snd_soc_instantiate_card(struct snd_soc_card *card) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1558 | { |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1559 | struct snd_soc_codec *codec; |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1560 | int ret, i, order; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1561 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 1562 | mutex_lock(&client_mutex); |
Liam Girdwood | 01b9d99 | 2012-03-07 10:38:25 +0000 | [diff] [blame] | 1563 | mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1564 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1565 | /* bind DAIs */ |
| 1566 | for (i = 0; i < card->num_links; i++) { |
| 1567 | ret = soc_bind_dai_link(card, i); |
| 1568 | if (ret != 0) |
| 1569 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1572 | /* bind aux_devs too */ |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1573 | for (i = 0; i < card->num_aux_devs; i++) { |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1574 | ret = soc_bind_aux_dev(card, i); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1575 | if (ret != 0) |
| 1576 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1579 | /* initialize the register cache for each available codec */ |
| 1580 | list_for_each_entry(codec, &codec_list, list) { |
| 1581 | if (codec->cache_init) |
| 1582 | continue; |
Lars-Peter Clausen | f90fb3f | 2013-08-31 20:31:15 +0200 | [diff] [blame] | 1583 | ret = snd_soc_init_codec_cache(codec); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1584 | if (ret < 0) |
| 1585 | goto base_error; |
Dimitris Papastamos | fdf0f54 | 2010-12-02 16:11:06 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1588 | /* card bind complete so register a sound card */ |
Takashi Iwai | 102b5a8 | 2014-01-29 14:42:55 +0100 | [diff] [blame] | 1589 | ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1590 | card->owner, 0, &card->snd_card); |
| 1591 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 1592 | dev_err(card->dev, |
| 1593 | "ASoC: can't create sound card for card %s: %d\n", |
| 1594 | card->name, ret); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1595 | goto base_error; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1596 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1597 | |
Lars-Peter Clausen | 0757d83 | 2015-04-09 10:52:36 +0200 | [diff] [blame] | 1598 | soc_init_card_debugfs(card); |
| 1599 | |
Mark Brown | e37a497 | 2011-03-02 18:21:57 +0000 | [diff] [blame] | 1600 | card->dapm.bias_level = SND_SOC_BIAS_OFF; |
| 1601 | card->dapm.dev = card->dev; |
| 1602 | card->dapm.card = card; |
| 1603 | list_add(&card->dapm.list, &card->dapm_list); |
| 1604 | |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1605 | #ifdef CONFIG_DEBUG_FS |
| 1606 | snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); |
| 1607 | #endif |
| 1608 | |
Mark Brown | 88ee1c6 | 2011-02-02 10:43:26 +0000 | [diff] [blame] | 1609 | #ifdef CONFIG_PM_SLEEP |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1610 | /* deferred resume work */ |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1611 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
Randy Dunlap | 1301a96 | 2008-06-17 19:19:34 +0100 | [diff] [blame] | 1612 | #endif |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 1613 | |
Mark Brown | 9a841eb | 2011-04-12 17:51:37 -0700 | [diff] [blame] | 1614 | if (card->dapm_widgets) |
| 1615 | snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, |
| 1616 | card->num_dapm_widgets); |
| 1617 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1618 | /* initialise the sound card only once */ |
| 1619 | if (card->probe) { |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1620 | ret = card->probe(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1621 | if (ret < 0) |
| 1622 | goto card_probe_error; |
| 1623 | } |
| 1624 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1625 | /* probe all components used by DAI links on this card */ |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1626 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1627 | order++) { |
| 1628 | for (i = 0; i < card->num_links; i++) { |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1629 | ret = soc_probe_link_components(card, i, order); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1630 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1631 | dev_err(card->dev, |
| 1632 | "ASoC: failed to instantiate card %d\n", |
| 1633 | ret); |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1634 | goto probe_dai_err; |
| 1635 | } |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | /* probe all DAI links on this card */ |
| 1640 | for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; |
| 1641 | order++) { |
| 1642 | for (i = 0; i < card->num_links; i++) { |
| 1643 | ret = soc_probe_link_dais(card, i, order); |
| 1644 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1645 | dev_err(card->dev, |
| 1646 | "ASoC: failed to instantiate card %d\n", |
| 1647 | ret); |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1648 | goto probe_dai_err; |
| 1649 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1653 | for (i = 0; i < card->num_aux_devs; i++) { |
| 1654 | ret = soc_probe_aux_dev(card, i); |
| 1655 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1656 | dev_err(card->dev, |
| 1657 | "ASoC: failed to add auxiliary devices %d\n", |
| 1658 | ret); |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1659 | goto probe_aux_dev_err; |
| 1660 | } |
| 1661 | } |
| 1662 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1663 | snd_soc_dapm_link_dai_widgets(card); |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 1664 | snd_soc_dapm_connect_dai_link_widgets(card); |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 1665 | |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1666 | if (card->controls) |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1667 | snd_soc_add_card_controls(card, card->controls, card->num_controls); |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 1668 | |
Mark Brown | b8ad29d | 2011-03-02 18:35:51 +0000 | [diff] [blame] | 1669 | if (card->dapm_routes) |
| 1670 | snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, |
| 1671 | card->num_dapm_routes); |
| 1672 | |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1673 | for (i = 0; i < card->num_links; i++) { |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1674 | if (card->dai_link[i].dai_fmt) |
| 1675 | snd_soc_runtime_set_dai_fmt(&card->rtd[i], |
| 1676 | card->dai_link[i].dai_fmt); |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 1677 | } |
| 1678 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1679 | snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1680 | "%s", card->name); |
Liam Girdwood | 22de71b | 2011-05-12 16:14:04 +0100 | [diff] [blame] | 1681 | snprintf(card->snd_card->longname, sizeof(card->snd_card->longname), |
| 1682 | "%s", card->long_name ? card->long_name : card->name); |
Mark Brown | f0e8ed8 | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 1683 | snprintf(card->snd_card->driver, sizeof(card->snd_card->driver), |
| 1684 | "%s", card->driver_name ? card->driver_name : card->name); |
| 1685 | for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) { |
| 1686 | switch (card->snd_card->driver[i]) { |
| 1687 | case '_': |
| 1688 | case '-': |
| 1689 | case '\0': |
| 1690 | break; |
| 1691 | default: |
| 1692 | if (!isalnum(card->snd_card->driver[i])) |
| 1693 | card->snd_card->driver[i] = '_'; |
| 1694 | break; |
| 1695 | } |
| 1696 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1697 | |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 1698 | if (card->late_probe) { |
| 1699 | ret = card->late_probe(card); |
| 1700 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1701 | dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n", |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 1702 | card->name, ret); |
| 1703 | goto probe_aux_dev_err; |
| 1704 | } |
| 1705 | } |
| 1706 | |
Lars-Peter Clausen | 824ef82 | 2013-08-27 15:51:01 +0200 | [diff] [blame] | 1707 | snd_soc_dapm_new_widgets(card); |
Lars-Peter Clausen | 8c193b8 | 2013-08-27 15:51:00 +0200 | [diff] [blame] | 1708 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1709 | ret = snd_card_register(card->snd_card); |
| 1710 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1711 | dev_err(card->dev, "ASoC: failed to register soundcard %d\n", |
| 1712 | ret); |
Axel Lin | 6b3ed78 | 2010-12-07 16:12:29 +0800 | [diff] [blame] | 1713 | goto probe_aux_dev_err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1716 | card->instantiated = 1; |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 1717 | snd_soc_dapm_sync(&card->dapm); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1718 | mutex_unlock(&card->mutex); |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 1719 | mutex_unlock(&client_mutex); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1720 | |
| 1721 | return 0; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1722 | |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1723 | probe_aux_dev_err: |
| 1724 | for (i = 0; i < card->num_aux_devs; i++) |
| 1725 | soc_remove_aux_dev(card, i); |
| 1726 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1727 | probe_dai_err: |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1728 | soc_remove_dai_links(card); |
Mark Brown | fe3e78e | 2009-11-03 22:13:13 +0000 | [diff] [blame] | 1729 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1730 | card_probe_error: |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1731 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1732 | card->remove(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1733 | |
Lars-Peter Clausen | 0757d83 | 2015-04-09 10:52:36 +0200 | [diff] [blame] | 1734 | soc_cleanup_card_debugfs(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1735 | snd_card_free(card->snd_card); |
| 1736 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1737 | base_error: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1738 | mutex_unlock(&card->mutex); |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 1739 | mutex_unlock(&client_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1740 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1741 | return ret; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | /* probes a new socdev */ |
| 1745 | static int soc_probe(struct platform_device *pdev) |
| 1746 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1747 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1748 | |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 1749 | /* |
| 1750 | * no card, so machine driver should be registering card |
| 1751 | * we should not be here in that case so ret error |
| 1752 | */ |
| 1753 | if (!card) |
| 1754 | return -EINVAL; |
| 1755 | |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 1756 | dev_warn(&pdev->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1757 | "ASoC: machine %s should use snd_soc_register_card()\n", |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 1758 | card->name); |
| 1759 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 1760 | /* Bodge while we unpick instantiation */ |
| 1761 | card->dev = &pdev->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1762 | |
Mark Brown | 28d528c | 2012-08-09 18:45:23 +0100 | [diff] [blame] | 1763 | return snd_soc_register_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1764 | } |
| 1765 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1766 | static int soc_cleanup_card_resources(struct snd_soc_card *card) |
| 1767 | { |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1768 | int i; |
| 1769 | |
| 1770 | /* make sure any delayed work runs */ |
| 1771 | for (i = 0; i < card->num_rtd; i++) { |
| 1772 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1773 | flush_delayed_work(&rtd->delayed_work); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | /* remove auxiliary devices */ |
| 1777 | for (i = 0; i < card->num_aux_devs; i++) |
| 1778 | soc_remove_aux_dev(card, i); |
| 1779 | |
| 1780 | /* remove and free each DAI */ |
Kuninori Morimoto | 0671fd8 | 2011-04-08 14:50:44 +0900 | [diff] [blame] | 1781 | soc_remove_dai_links(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1782 | |
| 1783 | soc_cleanup_card_debugfs(card); |
| 1784 | |
| 1785 | /* remove the card */ |
| 1786 | if (card->remove) |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 1787 | card->remove(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1788 | |
Lars-Peter Clausen | 0aaae52 | 2011-04-30 19:45:47 +0200 | [diff] [blame] | 1789 | snd_soc_dapm_free(&card->dapm); |
| 1790 | |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 1791 | snd_card_free(card->snd_card); |
| 1792 | return 0; |
| 1793 | |
| 1794 | } |
| 1795 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1796 | /* removes a socdev */ |
| 1797 | static int soc_remove(struct platform_device *pdev) |
| 1798 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1799 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1800 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1801 | snd_soc_unregister_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1802 | return 0; |
| 1803 | } |
| 1804 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1805 | int snd_soc_poweroff(struct device *dev) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1806 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1807 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1808 | int i; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1809 | |
| 1810 | if (!card->instantiated) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1811 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1812 | |
| 1813 | /* Flush out pmdown_time work - we actually do want to run it |
| 1814 | * now, we're shutting down so no imminent restart. */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1815 | for (i = 0; i < card->num_rtd; i++) { |
| 1816 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1817 | flush_delayed_work(&rtd->delayed_work); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1818 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1819 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1820 | snd_soc_dapm_shutdown(card); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1821 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 1822 | /* deactivate pins to sleep state */ |
| 1823 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1824 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 1825 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1826 | int j; |
| 1827 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 1828 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1829 | for (j = 0; j < rtd->num_codecs; j++) { |
| 1830 | struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; |
| 1831 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
| 1832 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 1833 | } |
| 1834 | |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1835 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1836 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1837 | EXPORT_SYMBOL_GPL(snd_soc_poweroff); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 1838 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1839 | const struct dev_pm_ops snd_soc_pm_ops = { |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 1840 | .suspend = snd_soc_suspend, |
| 1841 | .resume = snd_soc_resume, |
| 1842 | .freeze = snd_soc_suspend, |
| 1843 | .thaw = snd_soc_resume, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1844 | .poweroff = snd_soc_poweroff, |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 1845 | .restore = snd_soc_resume, |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1846 | }; |
Stephen Warren | deb2607 | 2011-04-05 19:35:30 -0600 | [diff] [blame] | 1847 | EXPORT_SYMBOL_GPL(snd_soc_pm_ops); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 1848 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1849 | /* ASoC platform driver */ |
| 1850 | static struct platform_driver soc_driver = { |
| 1851 | .driver = { |
| 1852 | .name = "soc-audio", |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 1853 | .pm = &snd_soc_pm_ops, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1854 | }, |
| 1855 | .probe = soc_probe, |
| 1856 | .remove = soc_remove, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1857 | }; |
| 1858 | |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 1859 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1860 | * snd_soc_cnew - create new control |
| 1861 | * @_template: control template |
| 1862 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1863 | * @long_name: control long name |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1864 | * @prefix: control name prefix |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1865 | * |
| 1866 | * Create a new mixer control from a template control. |
| 1867 | * |
| 1868 | * Returns 0 for success, else error. |
| 1869 | */ |
| 1870 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
Mark Brown | 3056557 | 2012-02-16 17:07:42 -0800 | [diff] [blame] | 1871 | void *data, const char *long_name, |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1872 | const char *prefix) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1873 | { |
| 1874 | struct snd_kcontrol_new template; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1875 | struct snd_kcontrol *kcontrol; |
| 1876 | char *name = NULL; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1877 | |
| 1878 | memcpy(&template, _template, sizeof(template)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1879 | template.index = 0; |
| 1880 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1881 | if (!long_name) |
| 1882 | long_name = template.name; |
| 1883 | |
| 1884 | if (prefix) { |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 1885 | name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name); |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1886 | if (!name) |
| 1887 | return NULL; |
| 1888 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 1889 | template.name = name; |
| 1890 | } else { |
| 1891 | template.name = long_name; |
| 1892 | } |
| 1893 | |
| 1894 | kcontrol = snd_ctl_new1(&template, data); |
| 1895 | |
| 1896 | kfree(name); |
| 1897 | |
| 1898 | return kcontrol; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1899 | } |
| 1900 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 1901 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1902 | static int snd_soc_add_controls(struct snd_card *card, struct device *dev, |
| 1903 | const struct snd_kcontrol_new *controls, int num_controls, |
| 1904 | const char *prefix, void *data) |
| 1905 | { |
| 1906 | int err, i; |
| 1907 | |
| 1908 | for (i = 0; i < num_controls; i++) { |
| 1909 | const struct snd_kcontrol_new *control = &controls[i]; |
| 1910 | err = snd_ctl_add(card, snd_soc_cnew(control, data, |
| 1911 | control->name, prefix)); |
| 1912 | if (err < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1913 | dev_err(dev, "ASoC: Failed to add %s: %d\n", |
| 1914 | control->name, err); |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1915 | return err; |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | return 0; |
| 1920 | } |
| 1921 | |
Dimitris Papastamos | 4fefd69 | 2013-07-29 13:51:58 +0100 | [diff] [blame] | 1922 | struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, |
| 1923 | const char *name) |
| 1924 | { |
| 1925 | struct snd_card *card = soc_card->snd_card; |
| 1926 | struct snd_kcontrol *kctl; |
| 1927 | |
| 1928 | if (unlikely(!name)) |
| 1929 | return NULL; |
| 1930 | |
| 1931 | list_for_each_entry(kctl, &card->controls, list) |
| 1932 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) |
| 1933 | return kctl; |
| 1934 | return NULL; |
| 1935 | } |
| 1936 | EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); |
| 1937 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1938 | /** |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1939 | * snd_soc_add_component_controls - Add an array of controls to a component. |
| 1940 | * |
| 1941 | * @component: Component to add controls to |
| 1942 | * @controls: Array of controls to add |
| 1943 | * @num_controls: Number of elements in the array |
| 1944 | * |
| 1945 | * Return: 0 for success, else error. |
| 1946 | */ |
| 1947 | int snd_soc_add_component_controls(struct snd_soc_component *component, |
| 1948 | const struct snd_kcontrol_new *controls, unsigned int num_controls) |
| 1949 | { |
| 1950 | struct snd_card *card = component->card->snd_card; |
| 1951 | |
| 1952 | return snd_soc_add_controls(card, component->dev, controls, |
| 1953 | num_controls, component->name_prefix, component); |
| 1954 | } |
| 1955 | EXPORT_SYMBOL_GPL(snd_soc_add_component_controls); |
| 1956 | |
| 1957 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1958 | * snd_soc_add_codec_controls - add an array of controls to a codec. |
| 1959 | * Convenience function to add a list of controls. Many codecs were |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1960 | * duplicating this code. |
| 1961 | * |
| 1962 | * @codec: codec to add controls to |
| 1963 | * @controls: array of controls to add |
| 1964 | * @num_controls: number of elements in the array |
| 1965 | * |
| 1966 | * Return 0 for success, else error. |
| 1967 | */ |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1968 | int snd_soc_add_codec_controls(struct snd_soc_codec *codec, |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1969 | const struct snd_kcontrol_new *controls, unsigned int num_controls) |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1970 | { |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1971 | return snd_soc_add_component_controls(&codec->component, controls, |
| 1972 | num_controls); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1973 | } |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1974 | EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); |
Ian Molton | 3e8e195 | 2009-01-09 00:23:21 +0000 | [diff] [blame] | 1975 | |
| 1976 | /** |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1977 | * 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] | 1978 | * Convenience function to add a list of controls. |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1979 | * |
| 1980 | * @platform: platform to add controls to |
| 1981 | * @controls: array of controls to add |
| 1982 | * @num_controls: number of elements in the array |
| 1983 | * |
| 1984 | * Return 0 for success, else error. |
| 1985 | */ |
| 1986 | int snd_soc_add_platform_controls(struct snd_soc_platform *platform, |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1987 | const struct snd_kcontrol_new *controls, unsigned int num_controls) |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1988 | { |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 1989 | return snd_soc_add_component_controls(&platform->component, controls, |
| 1990 | num_controls); |
Liam Girdwood | a491a5c | 2011-07-04 22:10:51 +0100 | [diff] [blame] | 1991 | } |
| 1992 | EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); |
| 1993 | |
| 1994 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1995 | * snd_soc_add_card_controls - add an array of controls to a SoC card. |
| 1996 | * Convenience function to add a list of controls. |
| 1997 | * |
| 1998 | * @soc_card: SoC card to add controls to |
| 1999 | * @controls: array of controls to add |
| 2000 | * @num_controls: number of elements in the array |
| 2001 | * |
| 2002 | * Return 0 for success, else error. |
| 2003 | */ |
| 2004 | int snd_soc_add_card_controls(struct snd_soc_card *soc_card, |
| 2005 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2006 | { |
| 2007 | struct snd_card *card = soc_card->snd_card; |
| 2008 | |
| 2009 | return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, |
| 2010 | NULL, soc_card); |
| 2011 | } |
| 2012 | EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); |
| 2013 | |
| 2014 | /** |
| 2015 | * snd_soc_add_dai_controls - add an array of controls to a DAI. |
| 2016 | * Convienience function to add a list of controls. |
| 2017 | * |
| 2018 | * @dai: DAI to add controls to |
| 2019 | * @controls: array of controls to add |
| 2020 | * @num_controls: number of elements in the array |
| 2021 | * |
| 2022 | * Return 0 for success, else error. |
| 2023 | */ |
| 2024 | int snd_soc_add_dai_controls(struct snd_soc_dai *dai, |
| 2025 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2026 | { |
Lars-Peter Clausen | 313665b | 2014-11-04 11:30:58 +0100 | [diff] [blame] | 2027 | struct snd_card *card = dai->component->card->snd_card; |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2028 | |
| 2029 | return snd_soc_add_controls(card, dai->dev, controls, num_controls, |
| 2030 | NULL, dai); |
| 2031 | } |
| 2032 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); |
| 2033 | |
| 2034 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2035 | * snd_soc_dai_set_sysclk - configure DAI system or master clock. |
| 2036 | * @dai: DAI |
| 2037 | * @clk_id: DAI specific clock ID |
| 2038 | * @freq: new clock frequency in Hz |
| 2039 | * @dir: new clock direction - input/output. |
| 2040 | * |
| 2041 | * Configures the DAI master (MCLK) or system (SYSCLK) clocking. |
| 2042 | */ |
| 2043 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 2044 | unsigned int freq, int dir) |
| 2045 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2046 | if (dai->driver && dai->driver->ops->set_sysclk) |
| 2047 | return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2048 | else if (dai->codec && dai->codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2049 | return dai->codec->driver->set_sysclk(dai->codec, clk_id, 0, |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2050 | freq, dir); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2051 | else |
Mark Brown | 1104a9c | 2014-01-15 19:04:19 +0000 | [diff] [blame] | 2052 | return -ENOTSUPP; |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2053 | } |
| 2054 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk); |
| 2055 | |
| 2056 | /** |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2057 | * snd_soc_codec_set_sysclk - configure CODEC system or master clock. |
| 2058 | * @codec: CODEC |
| 2059 | * @clk_id: DAI specific clock ID |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2060 | * @source: Source for the clock |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2061 | * @freq: new clock frequency in Hz |
| 2062 | * @dir: new clock direction - input/output. |
| 2063 | * |
| 2064 | * Configures the CODEC master (MCLK) or system (SYSCLK) clocking. |
| 2065 | */ |
| 2066 | 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] | 2067 | int source, unsigned int freq, int dir) |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2068 | { |
| 2069 | if (codec->driver->set_sysclk) |
Mark Brown | da1c6ea | 2011-08-24 20:09:01 +0100 | [diff] [blame] | 2070 | return codec->driver->set_sysclk(codec, clk_id, source, |
| 2071 | freq, dir); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2072 | else |
Mark Brown | 1104a9c | 2014-01-15 19:04:19 +0000 | [diff] [blame] | 2073 | return -ENOTSUPP; |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2074 | } |
| 2075 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk); |
| 2076 | |
| 2077 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2078 | * snd_soc_dai_set_clkdiv - configure DAI clock dividers. |
| 2079 | * @dai: DAI |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2080 | * @div_id: DAI specific clock divider ID |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2081 | * @div: new clock divisor. |
| 2082 | * |
| 2083 | * Configures the clock dividers. This is used to derive the best DAI bit and |
| 2084 | * frame clocks from the system or master clock. It's best to set the DAI bit |
| 2085 | * and frame clocks as low as possible to save system power. |
| 2086 | */ |
| 2087 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 2088 | int div_id, int div) |
| 2089 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2090 | if (dai->driver && dai->driver->ops->set_clkdiv) |
| 2091 | return dai->driver->ops->set_clkdiv(dai, div_id, div); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2092 | else |
| 2093 | return -EINVAL; |
| 2094 | } |
| 2095 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv); |
| 2096 | |
| 2097 | /** |
| 2098 | * snd_soc_dai_set_pll - configure DAI PLL. |
| 2099 | * @dai: DAI |
| 2100 | * @pll_id: DAI specific PLL ID |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2101 | * @source: DAI specific source for the PLL |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2102 | * @freq_in: PLL input clock frequency in Hz |
| 2103 | * @freq_out: requested PLL output clock frequency in Hz |
| 2104 | * |
| 2105 | * Configures and enables PLL to generate output clock based on input clock. |
| 2106 | */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2107 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, |
| 2108 | unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2109 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2110 | if (dai->driver && dai->driver->ops->set_pll) |
| 2111 | return dai->driver->ops->set_pll(dai, pll_id, source, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 2112 | freq_in, freq_out); |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2113 | else if (dai->codec && dai->codec->driver->set_pll) |
| 2114 | return dai->codec->driver->set_pll(dai->codec, pll_id, source, |
| 2115 | freq_in, freq_out); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2116 | else |
| 2117 | return -EINVAL; |
| 2118 | } |
| 2119 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll); |
| 2120 | |
Mark Brown | ec4ee52 | 2011-03-07 20:58:11 +0000 | [diff] [blame] | 2121 | /* |
| 2122 | * snd_soc_codec_set_pll - configure codec PLL. |
| 2123 | * @codec: CODEC |
| 2124 | * @pll_id: DAI specific PLL ID |
| 2125 | * @source: DAI specific source for the PLL |
| 2126 | * @freq_in: PLL input clock frequency in Hz |
| 2127 | * @freq_out: requested PLL output clock frequency in Hz |
| 2128 | * |
| 2129 | * Configures and enables PLL to generate output clock based on input clock. |
| 2130 | */ |
| 2131 | int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source, |
| 2132 | unsigned int freq_in, unsigned int freq_out) |
| 2133 | { |
| 2134 | if (codec->driver->set_pll) |
| 2135 | return codec->driver->set_pll(codec, pll_id, source, |
| 2136 | freq_in, freq_out); |
| 2137 | else |
| 2138 | return -EINVAL; |
| 2139 | } |
| 2140 | EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll); |
| 2141 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2142 | /** |
Liam Girdwood | e54cf76 | 2013-09-16 13:01:46 +0100 | [diff] [blame] | 2143 | * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio. |
| 2144 | * @dai: DAI |
| 2145 | * @ratio Ratio of BCLK to Sample rate. |
| 2146 | * |
| 2147 | * Configures the DAI for a preset BCLK to sample rate ratio. |
| 2148 | */ |
| 2149 | int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) |
| 2150 | { |
| 2151 | if (dai->driver && dai->driver->ops->set_bclk_ratio) |
| 2152 | return dai->driver->ops->set_bclk_ratio(dai, ratio); |
| 2153 | else |
| 2154 | return -EINVAL; |
| 2155 | } |
| 2156 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio); |
| 2157 | |
| 2158 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2159 | * snd_soc_dai_set_fmt - configure DAI hardware audio format. |
| 2160 | * @dai: DAI |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2161 | * @fmt: SND_SOC_DAIFMT_ format value. |
| 2162 | * |
| 2163 | * Configures the DAI hardware format and clocking. |
| 2164 | */ |
| 2165 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 2166 | { |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 2167 | if (dai->driver == NULL) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2168 | return -EINVAL; |
Shawn Guo | 5e4ba56 | 2012-03-09 00:59:40 +0800 | [diff] [blame] | 2169 | if (dai->driver->ops->set_fmt == NULL) |
| 2170 | return -ENOTSUPP; |
| 2171 | return dai->driver->ops->set_fmt(dai, fmt); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2172 | } |
| 2173 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt); |
| 2174 | |
| 2175 | /** |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2176 | * snd_soc_xlate_tdm_slot - generate tx/rx slot mask. |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2177 | * @slots: Number of slots in use. |
| 2178 | * @tx_mask: bitmask representing active TX slots. |
| 2179 | * @rx_mask: bitmask representing active RX slots. |
| 2180 | * |
| 2181 | * Generates the TDM tx and rx slot default masks for DAI. |
| 2182 | */ |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2183 | static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2184 | unsigned int *tx_mask, |
| 2185 | unsigned int *rx_mask) |
| 2186 | { |
| 2187 | if (*tx_mask || *rx_mask) |
| 2188 | return 0; |
| 2189 | |
| 2190 | if (!slots) |
| 2191 | return -EINVAL; |
| 2192 | |
| 2193 | *tx_mask = (1 << slots) - 1; |
| 2194 | *rx_mask = (1 << slots) - 1; |
| 2195 | |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
| 2199 | /** |
Lars-Peter Clausen | e46c936 | 2015-01-12 10:27:20 +0100 | [diff] [blame] | 2200 | * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation |
| 2201 | * @dai: The DAI to configure |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2202 | * @tx_mask: bitmask representing active TX slots. |
| 2203 | * @rx_mask: bitmask representing active RX slots. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2204 | * @slots: Number of slots in use. |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2205 | * @slot_width: Width in bits for each slot. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2206 | * |
Lars-Peter Clausen | e46c936 | 2015-01-12 10:27:20 +0100 | [diff] [blame] | 2207 | * This function configures the specified DAI for TDM operation. @slot contains |
| 2208 | * the total number of slots of the TDM stream and @slot_with the width of each |
| 2209 | * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the |
| 2210 | * active slots of the TDM stream for the specified DAI, i.e. which slots the |
| 2211 | * DAI should write to or read from. If a bit is set the corresponding slot is |
| 2212 | * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to |
| 2213 | * the first slot, bit 1 to the second slot and so on. The first active slot |
| 2214 | * maps to the first channel of the DAI, the second active slot to the second |
| 2215 | * channel and so on. |
| 2216 | * |
| 2217 | * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask, |
| 2218 | * @rx_mask and @slot_width will be ignored. |
| 2219 | * |
| 2220 | * Returns 0 on success, a negative error code otherwise. |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2221 | */ |
| 2222 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2223 | 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] | 2224 | { |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2225 | if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask) |
| 2226 | dai->driver->ops->xlate_tdm_slot_mask(slots, |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2227 | &tx_mask, &rx_mask); |
| 2228 | else |
Xiubo Li | e5c2151 | 2014-03-21 14:17:12 +0800 | [diff] [blame] | 2229 | snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask); |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2230 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2231 | dai->tx_mask = tx_mask; |
| 2232 | dai->rx_mask = rx_mask; |
| 2233 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2234 | if (dai->driver && dai->driver->ops->set_tdm_slot) |
| 2235 | return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 2236 | slots, slot_width); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2237 | else |
Xiubo Li | b2cbb6e | 2014-01-23 13:02:47 +0800 | [diff] [blame] | 2238 | return -ENOTSUPP; |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2239 | } |
| 2240 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot); |
| 2241 | |
| 2242 | /** |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 2243 | * snd_soc_dai_set_channel_map - configure DAI audio channel map |
| 2244 | * @dai: DAI |
| 2245 | * @tx_num: how many TX channels |
| 2246 | * @tx_slot: pointer to an array which imply the TX slot number channel |
| 2247 | * 0~num-1 uses |
| 2248 | * @rx_num: how many RX channels |
| 2249 | * @rx_slot: pointer to an array which imply the RX slot number channel |
| 2250 | * 0~num-1 uses |
| 2251 | * |
| 2252 | * configure the relationship between channel number and TDM slot number. |
| 2253 | */ |
| 2254 | int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, |
| 2255 | unsigned int tx_num, unsigned int *tx_slot, |
| 2256 | unsigned int rx_num, unsigned int *rx_slot) |
| 2257 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2258 | if (dai->driver && dai->driver->ops->set_channel_map) |
| 2259 | return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, |
Barry Song | 472df3c | 2009-09-12 01:16:29 +0800 | [diff] [blame] | 2260 | rx_num, rx_slot); |
| 2261 | else |
| 2262 | return -EINVAL; |
| 2263 | } |
| 2264 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map); |
| 2265 | |
| 2266 | /** |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2267 | * snd_soc_dai_set_tristate - configure DAI system or master clock. |
| 2268 | * @dai: DAI |
| 2269 | * @tristate: tristate enable |
| 2270 | * |
| 2271 | * Tristates the DAI so that others can use it. |
| 2272 | */ |
| 2273 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) |
| 2274 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2275 | if (dai->driver && dai->driver->ops->set_tristate) |
| 2276 | return dai->driver->ops->set_tristate(dai, tristate); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2277 | else |
| 2278 | return -EINVAL; |
| 2279 | } |
| 2280 | EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); |
| 2281 | |
| 2282 | /** |
| 2283 | * snd_soc_dai_digital_mute - configure DAI system or master clock. |
| 2284 | * @dai: DAI |
| 2285 | * @mute: mute enable |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 2286 | * @direction: stream to mute |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2287 | * |
| 2288 | * Mutes the DAI DAC. |
| 2289 | */ |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 2290 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, |
| 2291 | int direction) |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2292 | { |
Mark Brown | da18396 | 2013-02-06 15:44:07 +0000 | [diff] [blame] | 2293 | if (!dai->driver) |
| 2294 | return -ENOTSUPP; |
| 2295 | |
| 2296 | if (dai->driver->ops->mute_stream) |
| 2297 | return dai->driver->ops->mute_stream(dai, mute, direction); |
| 2298 | else if (direction == SNDRV_PCM_STREAM_PLAYBACK && |
| 2299 | dai->driver->ops->digital_mute) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2300 | return dai->driver->ops->digital_mute(dai, mute); |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2301 | else |
Mark Brown | 04570c6 | 2012-04-13 19:16:03 +0100 | [diff] [blame] | 2302 | return -ENOTSUPP; |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 2303 | } |
| 2304 | EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); |
| 2305 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2306 | static int snd_soc_init_multicodec(struct snd_soc_card *card, |
| 2307 | struct snd_soc_dai_link *dai_link) |
| 2308 | { |
| 2309 | /* Legacy codec/codec_dai link is a single entry in multicodec */ |
| 2310 | if (dai_link->codec_name || dai_link->codec_of_node || |
| 2311 | dai_link->codec_dai_name) { |
| 2312 | dai_link->num_codecs = 1; |
| 2313 | |
| 2314 | dai_link->codecs = devm_kzalloc(card->dev, |
| 2315 | sizeof(struct snd_soc_dai_link_component), |
| 2316 | GFP_KERNEL); |
| 2317 | if (!dai_link->codecs) |
| 2318 | return -ENOMEM; |
| 2319 | |
| 2320 | dai_link->codecs[0].name = dai_link->codec_name; |
| 2321 | dai_link->codecs[0].of_node = dai_link->codec_of_node; |
| 2322 | dai_link->codecs[0].dai_name = dai_link->codec_dai_name; |
| 2323 | } |
| 2324 | |
| 2325 | if (!dai_link->codecs) { |
| 2326 | dev_err(card->dev, "ASoC: DAI link has no CODECs\n"); |
| 2327 | return -EINVAL; |
| 2328 | } |
| 2329 | |
| 2330 | return 0; |
| 2331 | } |
| 2332 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2333 | /** |
| 2334 | * snd_soc_register_card - Register a card with the ASoC core |
| 2335 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2336 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2337 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2338 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2339 | int snd_soc_register_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2340 | { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2341 | int i, j, ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2342 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2343 | if (!card->name || !card->dev) |
| 2344 | return -EINVAL; |
| 2345 | |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2346 | for (i = 0; i < card->num_links; i++) { |
| 2347 | struct snd_soc_dai_link *link = &card->dai_link[i]; |
| 2348 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2349 | ret = snd_soc_init_multicodec(card, link); |
| 2350 | if (ret) { |
| 2351 | dev_err(card->dev, "ASoC: failed to init multicodec\n"); |
| 2352 | return ret; |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2353 | } |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2354 | |
| 2355 | for (j = 0; j < link->num_codecs; j++) { |
| 2356 | /* |
| 2357 | * Codec must be specified by 1 of name or OF node, |
| 2358 | * not both or neither. |
| 2359 | */ |
| 2360 | if (!!link->codecs[j].name == |
| 2361 | !!link->codecs[j].of_node) { |
| 2362 | dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n", |
| 2363 | link->name); |
| 2364 | return -EINVAL; |
| 2365 | } |
| 2366 | /* Codec DAI name must be specified */ |
| 2367 | if (!link->codecs[j].dai_name) { |
| 2368 | dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n", |
| 2369 | link->name); |
| 2370 | return -EINVAL; |
| 2371 | } |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2372 | } |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2373 | |
| 2374 | /* |
| 2375 | * Platform may be specified by either name or OF node, but |
| 2376 | * can be left unspecified, and a dummy platform will be used. |
| 2377 | */ |
| 2378 | if (link->platform_name && link->platform_of_node) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2379 | dev_err(card->dev, |
| 2380 | "ASoC: Both platform name/of_node are set for %s\n", |
| 2381 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2382 | return -EINVAL; |
| 2383 | } |
| 2384 | |
| 2385 | /* |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2386 | * CPU device may be specified by either name or OF node, but |
| 2387 | * can be left unspecified, and will be matched based on DAI |
| 2388 | * name alone.. |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2389 | */ |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2390 | if (link->cpu_name && link->cpu_of_node) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2391 | dev_err(card->dev, |
| 2392 | "ASoC: Neither/both cpu name/of_node are set for %s\n", |
| 2393 | link->name); |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 2394 | return -EINVAL; |
| 2395 | } |
| 2396 | /* |
| 2397 | * At least one of CPU DAI name or CPU device name/node must be |
| 2398 | * specified |
| 2399 | */ |
| 2400 | if (!link->cpu_dai_name && |
| 2401 | !(link->cpu_name || link->cpu_of_node)) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2402 | dev_err(card->dev, |
| 2403 | "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n", |
| 2404 | link->name); |
Stephen Warren | 5a50496 | 2011-12-21 10:40:59 -0700 | [diff] [blame] | 2405 | return -EINVAL; |
| 2406 | } |
| 2407 | } |
| 2408 | |
Mark Brown | ed77cc1 | 2011-05-03 18:25:34 +0100 | [diff] [blame] | 2409 | dev_set_drvdata(card->dev, card); |
| 2410 | |
Stephen Warren | 111c641 | 2011-01-28 14:26:35 -0700 | [diff] [blame] | 2411 | snd_soc_initialize_card_lists(card); |
| 2412 | |
Mark Brown | 181a689 | 2012-03-14 20:18:49 +0000 | [diff] [blame] | 2413 | card->rtd = devm_kzalloc(card->dev, |
| 2414 | sizeof(struct snd_soc_pcm_runtime) * |
| 2415 | (card->num_links + card->num_aux_devs), |
| 2416 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2417 | if (card->rtd == NULL) |
| 2418 | return -ENOMEM; |
Liam Girdwood | a7dbb60 | 2012-04-17 18:00:11 +0100 | [diff] [blame] | 2419 | card->num_rtd = 0; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 2420 | card->rtd_aux = &card->rtd[card->num_links]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2421 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 2422 | for (i = 0; i < card->num_links; i++) { |
| 2423 | card->rtd[i].card = card; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2424 | card->rtd[i].dai_link = &card->dai_link[i]; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2425 | card->rtd[i].codec_dais = devm_kzalloc(card->dev, |
| 2426 | sizeof(struct snd_soc_dai *) * |
| 2427 | (card->rtd[i].dai_link->num_codecs), |
| 2428 | GFP_KERNEL); |
| 2429 | if (card->rtd[i].codec_dais == NULL) |
| 2430 | return -ENOMEM; |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | for (i = 0; i < card->num_aux_devs; i++) |
| 2434 | card->rtd_aux[i].card = card; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2435 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 2436 | INIT_LIST_HEAD(&card->dapm_dirty); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2437 | card->instantiated = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2438 | mutex_init(&card->mutex); |
Liam Girdwood | a73fb2df | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2439 | mutex_init(&card->dapm_mutex); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2440 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 2441 | ret = snd_soc_instantiate_card(card); |
| 2442 | if (ret != 0) |
Kuninori Morimoto | 4e2576b | 2015-03-24 09:01:00 +0000 | [diff] [blame] | 2443 | return ret; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2444 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 2445 | /* deactivate pins to sleep state */ |
| 2446 | for (i = 0; i < card->num_rtd; i++) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2447 | struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; |
| 2448 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 2449 | int j; |
| 2450 | |
| 2451 | for (j = 0; j < rtd->num_codecs; j++) { |
| 2452 | struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; |
| 2453 | if (!codec_dai->active) |
| 2454 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
| 2455 | } |
| 2456 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 2457 | if (!cpu_dai->active) |
| 2458 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
| 2459 | } |
| 2460 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 2461 | return ret; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2462 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2463 | EXPORT_SYMBOL_GPL(snd_soc_register_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2464 | |
| 2465 | /** |
| 2466 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 2467 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2468 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2469 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2470 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2471 | int snd_soc_unregister_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2472 | { |
Lars-Peter Clausen | 01e0df6 | 2014-09-04 19:44:04 +0200 | [diff] [blame] | 2473 | if (card->instantiated) { |
| 2474 | card->instantiated = false; |
Lars-Peter Clausen | 1c325f7 | 2014-09-04 19:44:05 +0200 | [diff] [blame] | 2475 | snd_soc_dapm_shutdown(card); |
Vinod Koul | b0e2648 | 2011-01-13 22:48:02 +0530 | [diff] [blame] | 2476 | soc_cleanup_card_resources(card); |
Kuninori Morimoto | 8f6f9b2 | 2015-02-05 05:34:10 +0000 | [diff] [blame] | 2477 | dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); |
Lars-Peter Clausen | 01e0df6 | 2014-09-04 19:44:04 +0200 | [diff] [blame] | 2478 | } |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2479 | |
| 2480 | return 0; |
| 2481 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2482 | EXPORT_SYMBOL_GPL(snd_soc_unregister_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2483 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2484 | /* |
| 2485 | * Simplify DAI link configuration by removing ".-1" from device names |
| 2486 | * and sanitizing names. |
| 2487 | */ |
Dimitris Papastamos | 0b9a214 | 2010-12-06 15:49:20 +0000 | [diff] [blame] | 2488 | static char *fmt_single_name(struct device *dev, int *id) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2489 | { |
| 2490 | char *found, name[NAME_SIZE]; |
| 2491 | int id1, id2; |
| 2492 | |
| 2493 | if (dev_name(dev) == NULL) |
| 2494 | return NULL; |
| 2495 | |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 2496 | strlcpy(name, dev_name(dev), NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2497 | |
| 2498 | /* are we a "%s.%d" name (platform and SPI components) */ |
| 2499 | found = strstr(name, dev->driver->name); |
| 2500 | if (found) { |
| 2501 | /* get ID */ |
| 2502 | if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { |
| 2503 | |
| 2504 | /* discard ID from name if ID == -1 */ |
| 2505 | if (*id == -1) |
| 2506 | found[strlen(dev->driver->name)] = '\0'; |
| 2507 | } |
| 2508 | |
| 2509 | } else { |
| 2510 | /* I2C component devices are named "bus-addr" */ |
| 2511 | if (sscanf(name, "%x-%x", &id1, &id2) == 2) { |
| 2512 | char tmp[NAME_SIZE]; |
| 2513 | |
| 2514 | /* create unique ID number from I2C addr and bus */ |
Jarkko Nikula | 0589944 | 2010-10-19 11:10:45 +0300 | [diff] [blame] | 2515 | *id = ((id1 & 0xffff) << 16) + id2; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2516 | |
| 2517 | /* sanitize component name for DAI link creation */ |
| 2518 | snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name); |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 2519 | strlcpy(name, tmp, NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2520 | } else |
| 2521 | *id = 0; |
| 2522 | } |
| 2523 | |
| 2524 | return kstrdup(name, GFP_KERNEL); |
| 2525 | } |
| 2526 | |
| 2527 | /* |
| 2528 | * Simplify DAI link naming for single devices with multiple DAIs by removing |
| 2529 | * any ".-1" and using the DAI name (instead of device name). |
| 2530 | */ |
| 2531 | static inline char *fmt_multiple_name(struct device *dev, |
| 2532 | struct snd_soc_dai_driver *dai_drv) |
| 2533 | { |
| 2534 | if (dai_drv->name == NULL) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2535 | dev_err(dev, |
| 2536 | "ASoC: error - multiple DAI %s registered with no name\n", |
| 2537 | dev_name(dev)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2538 | return NULL; |
| 2539 | } |
| 2540 | |
| 2541 | return kstrdup(dai_drv->name, GFP_KERNEL); |
| 2542 | } |
| 2543 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2544 | /** |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2545 | * snd_soc_unregister_dai - Unregister DAIs from the ASoC core |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2546 | * |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2547 | * @component: The component for which the DAIs should be unregistered |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2548 | */ |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2549 | static void snd_soc_unregister_dais(struct snd_soc_component *component) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2550 | { |
Lars-Peter Clausen | 5c1d5f0 | 2014-03-12 08:34:39 +0100 | [diff] [blame] | 2551 | struct snd_soc_dai *dai, *_dai; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2552 | |
Lars-Peter Clausen | 5c1d5f0 | 2014-03-12 08:34:39 +0100 | [diff] [blame] | 2553 | list_for_each_entry_safe(dai, _dai, &component->dai_list, list) { |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2554 | dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n", |
| 2555 | dai->name); |
Lars-Peter Clausen | 5c1d5f0 | 2014-03-12 08:34:39 +0100 | [diff] [blame] | 2556 | list_del(&dai->list); |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2557 | kfree(dai->name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2558 | kfree(dai); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2559 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2560 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2561 | |
| 2562 | /** |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2563 | * snd_soc_register_dais - Register a DAI with the ASoC core |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2564 | * |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2565 | * @component: The component the DAIs are registered for |
| 2566 | * @dai_drv: DAI driver to use for the DAIs |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2567 | * @count: Number of DAIs |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2568 | * @legacy_dai_naming: Use the legacy naming scheme and let the DAI inherit the |
| 2569 | * parent's name. |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2570 | */ |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2571 | static int snd_soc_register_dais(struct snd_soc_component *component, |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2572 | struct snd_soc_dai_driver *dai_drv, size_t count, |
| 2573 | bool legacy_dai_naming) |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2574 | { |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2575 | struct device *dev = component->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2576 | struct snd_soc_dai *dai; |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2577 | unsigned int i; |
| 2578 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2579 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2580 | 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] | 2581 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2582 | component->dai_drv = dai_drv; |
| 2583 | component->num_dai = count; |
| 2584 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2585 | for (i = 0; i < count; i++) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2586 | |
| 2587 | dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL); |
Axel Lin | c46e007 | 2010-11-03 15:04:45 +0800 | [diff] [blame] | 2588 | if (dai == NULL) { |
| 2589 | ret = -ENOMEM; |
| 2590 | goto err; |
| 2591 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2592 | |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2593 | /* |
| 2594 | * Back in the old days when we still had component-less DAIs, |
| 2595 | * instead of having a static name, component-less DAIs would |
| 2596 | * inherit the name of the parent device so it is possible to |
| 2597 | * register multiple instances of the DAI. We still need to keep |
| 2598 | * the same naming style even though those DAIs are not |
| 2599 | * component-less anymore. |
| 2600 | */ |
| 2601 | if (count == 1 && legacy_dai_naming) { |
| 2602 | dai->name = fmt_single_name(dev, &dai->id); |
| 2603 | } else { |
| 2604 | dai->name = fmt_multiple_name(dev, &dai_drv[i]); |
| 2605 | if (dai_drv[i].id) |
| 2606 | dai->id = dai_drv[i].id; |
| 2607 | else |
| 2608 | dai->id = i; |
| 2609 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2610 | if (dai->name == NULL) { |
| 2611 | kfree(dai); |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2612 | ret = -ENOMEM; |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2613 | goto err; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
Lars-Peter Clausen | 6106d12 | 2014-03-05 13:17:46 +0100 | [diff] [blame] | 2616 | dai->component = component; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2617 | dai->dev = dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2618 | dai->driver = &dai_drv[i]; |
| 2619 | if (!dai->driver->ops) |
| 2620 | dai->driver->ops = &null_dai_ops; |
| 2621 | |
Lars-Peter Clausen | 1438c2f | 2014-03-09 17:41:47 +0100 | [diff] [blame] | 2622 | list_add(&dai->list, &component->dai_list); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 2623 | |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2624 | dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | return 0; |
| 2628 | |
| 2629 | err: |
Lars-Peter Clausen | 32c9ba5 | 2014-03-09 17:41:45 +0100 | [diff] [blame] | 2630 | snd_soc_unregister_dais(component); |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2631 | |
| 2632 | return ret; |
| 2633 | } |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2634 | |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2635 | static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm, |
| 2636 | enum snd_soc_dapm_type type, int subseq) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2637 | { |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2638 | struct snd_soc_component *component = dapm->component; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2639 | |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2640 | component->driver->seq_notifier(component, type, subseq); |
| 2641 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2642 | |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2643 | static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm, |
| 2644 | int event) |
| 2645 | { |
| 2646 | struct snd_soc_component *component = dapm->component; |
| 2647 | |
| 2648 | return component->driver->stream_event(component, event); |
| 2649 | } |
| 2650 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2651 | static int snd_soc_component_initialize(struct snd_soc_component *component, |
| 2652 | const struct snd_soc_component_driver *driver, struct device *dev) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2653 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2654 | struct snd_soc_dapm_context *dapm; |
| 2655 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2656 | component->name = fmt_single_name(dev, &component->id); |
| 2657 | if (!component->name) { |
| 2658 | dev_err(dev, "ASoC: Failed to allocate name\n"); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2659 | return -ENOMEM; |
| 2660 | } |
| 2661 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2662 | component->dev = dev; |
| 2663 | component->driver = driver; |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 2664 | component->probe = component->driver->probe; |
| 2665 | component->remove = component->driver->remove; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2666 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2667 | if (!component->dapm_ptr) |
| 2668 | component->dapm_ptr = &component->dapm; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2669 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 2670 | dapm = component->dapm_ptr; |
| 2671 | dapm->dev = dev; |
| 2672 | dapm->component = component; |
| 2673 | dapm->bias_level = SND_SOC_BIAS_OFF; |
Lars-Peter Clausen | 5819c2f | 2014-08-24 15:36:55 +0200 | [diff] [blame] | 2674 | dapm->idle_bias_off = true; |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 2675 | if (driver->seq_notifier) |
| 2676 | dapm->seq_notifier = snd_soc_component_seq_notifier; |
| 2677 | if (driver->stream_event) |
| 2678 | dapm->stream_event = snd_soc_component_stream_event; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2679 | |
Lars-Peter Clausen | 61aca56 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 2680 | component->controls = driver->controls; |
| 2681 | component->num_controls = driver->num_controls; |
| 2682 | component->dapm_widgets = driver->dapm_widgets; |
| 2683 | component->num_dapm_widgets = driver->num_dapm_widgets; |
| 2684 | component->dapm_routes = driver->dapm_routes; |
| 2685 | component->num_dapm_routes = driver->num_dapm_routes; |
| 2686 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2687 | INIT_LIST_HEAD(&component->dai_list); |
| 2688 | mutex_init(&component->io_mutex); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2689 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2690 | return 0; |
| 2691 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2692 | |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2693 | 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] | 2694 | { |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2695 | int val_bytes = regmap_get_val_bytes(component->regmap); |
| 2696 | |
| 2697 | /* Errors are legitimate for non-integer byte multiples */ |
| 2698 | if (val_bytes > 0) |
| 2699 | component->val_bytes = val_bytes; |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 2700 | } |
| 2701 | |
Lars-Peter Clausen | e874bf5 | 2014-11-25 21:41:03 +0100 | [diff] [blame] | 2702 | #ifdef CONFIG_REGMAP |
| 2703 | |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2704 | /** |
| 2705 | * snd_soc_component_init_regmap() - Initialize regmap instance for the component |
| 2706 | * @component: The component for which to initialize the regmap instance |
| 2707 | * @regmap: The regmap instance that should be used by the component |
| 2708 | * |
| 2709 | * This function allows deferred assignment of the regmap instance that is |
| 2710 | * associated with the component. Only use this if the regmap instance is not |
| 2711 | * yet ready when the component is registered. The function must also be called |
| 2712 | * before the first IO attempt of the component. |
| 2713 | */ |
| 2714 | void snd_soc_component_init_regmap(struct snd_soc_component *component, |
| 2715 | struct regmap *regmap) |
| 2716 | { |
| 2717 | component->regmap = regmap; |
| 2718 | snd_soc_component_setup_regmap(component); |
| 2719 | } |
| 2720 | EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); |
| 2721 | |
| 2722 | /** |
| 2723 | * snd_soc_component_exit_regmap() - De-initialize regmap instance for the component |
| 2724 | * @component: The component for which to de-initialize the regmap instance |
| 2725 | * |
| 2726 | * Calls regmap_exit() on the regmap instance associated to the component and |
| 2727 | * removes the regmap instance from the component. |
| 2728 | * |
| 2729 | * This function should only be used if snd_soc_component_init_regmap() was used |
| 2730 | * to initialize the regmap instance. |
| 2731 | */ |
| 2732 | void snd_soc_component_exit_regmap(struct snd_soc_component *component) |
| 2733 | { |
| 2734 | regmap_exit(component->regmap); |
| 2735 | component->regmap = NULL; |
| 2736 | } |
| 2737 | EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); |
| 2738 | |
Lars-Peter Clausen | e874bf5 | 2014-11-25 21:41:03 +0100 | [diff] [blame] | 2739 | #endif |
| 2740 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2741 | static void snd_soc_component_add_unlocked(struct snd_soc_component *component) |
| 2742 | { |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2743 | if (!component->write && !component->read) { |
| 2744 | if (!component->regmap) |
| 2745 | component->regmap = dev_get_regmap(component->dev, NULL); |
| 2746 | if (component->regmap) |
| 2747 | snd_soc_component_setup_regmap(component); |
| 2748 | } |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 2749 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2750 | list_add(&component->list, &component_list); |
| 2751 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2752 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2753 | static void snd_soc_component_add(struct snd_soc_component *component) |
| 2754 | { |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2755 | mutex_lock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2756 | snd_soc_component_add_unlocked(component); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2757 | mutex_unlock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2758 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2759 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2760 | static void snd_soc_component_cleanup(struct snd_soc_component *component) |
| 2761 | { |
| 2762 | snd_soc_unregister_dais(component); |
| 2763 | kfree(component->name); |
| 2764 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2765 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2766 | static void snd_soc_component_del_unlocked(struct snd_soc_component *component) |
| 2767 | { |
| 2768 | list_del(&component->list); |
| 2769 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2770 | |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2771 | int snd_soc_register_component(struct device *dev, |
| 2772 | const struct snd_soc_component_driver *cmpnt_drv, |
| 2773 | struct snd_soc_dai_driver *dai_drv, |
| 2774 | int num_dai) |
| 2775 | { |
| 2776 | struct snd_soc_component *cmpnt; |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2777 | int ret; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2778 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2779 | cmpnt = kzalloc(sizeof(*cmpnt), GFP_KERNEL); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2780 | if (!cmpnt) { |
| 2781 | dev_err(dev, "ASoC: Failed to allocate memory\n"); |
| 2782 | return -ENOMEM; |
| 2783 | } |
| 2784 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2785 | ret = snd_soc_component_initialize(cmpnt, cmpnt_drv, dev); |
| 2786 | if (ret) |
| 2787 | goto err_free; |
| 2788 | |
Lars-Peter Clausen | 3d59400 | 2014-03-05 13:17:48 +0100 | [diff] [blame] | 2789 | cmpnt->ignore_pmdown_time = true; |
Lars-Peter Clausen | 98e639f | 2014-03-18 09:02:11 +0100 | [diff] [blame] | 2790 | cmpnt->registered_as_component = true; |
Lars-Peter Clausen | 3d59400 | 2014-03-05 13:17:48 +0100 | [diff] [blame] | 2791 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2792 | ret = snd_soc_register_dais(cmpnt, dai_drv, num_dai, true); |
| 2793 | if (ret < 0) { |
| 2794 | dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); |
| 2795 | goto err_cleanup; |
| 2796 | } |
| 2797 | |
| 2798 | snd_soc_component_add(cmpnt); |
| 2799 | |
| 2800 | return 0; |
| 2801 | |
| 2802 | err_cleanup: |
| 2803 | snd_soc_component_cleanup(cmpnt); |
| 2804 | err_free: |
| 2805 | kfree(cmpnt); |
| 2806 | return ret; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2807 | } |
| 2808 | EXPORT_SYMBOL_GPL(snd_soc_register_component); |
| 2809 | |
| 2810 | /** |
| 2811 | * snd_soc_unregister_component - Unregister a component from the ASoC core |
| 2812 | * |
| 2813 | */ |
| 2814 | void snd_soc_unregister_component(struct device *dev) |
| 2815 | { |
| 2816 | struct snd_soc_component *cmpnt; |
| 2817 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2818 | mutex_lock(&client_mutex); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2819 | list_for_each_entry(cmpnt, &component_list, list) { |
Lars-Peter Clausen | 98e639f | 2014-03-18 09:02:11 +0100 | [diff] [blame] | 2820 | if (dev == cmpnt->dev && cmpnt->registered_as_component) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2821 | goto found; |
| 2822 | } |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2823 | mutex_unlock(&client_mutex); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2824 | return; |
| 2825 | |
| 2826 | found: |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2827 | snd_soc_component_del_unlocked(cmpnt); |
| 2828 | mutex_unlock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2829 | snd_soc_component_cleanup(cmpnt); |
| 2830 | kfree(cmpnt); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2831 | } |
| 2832 | EXPORT_SYMBOL_GPL(snd_soc_unregister_component); |
| 2833 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2834 | 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] | 2835 | { |
| 2836 | struct snd_soc_platform *platform = snd_soc_component_to_platform(component); |
| 2837 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2838 | return platform->driver->probe(platform); |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2839 | } |
| 2840 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2841 | 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] | 2842 | { |
| 2843 | struct snd_soc_platform *platform = snd_soc_component_to_platform(component); |
| 2844 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2845 | platform->driver->remove(platform); |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2846 | } |
| 2847 | |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2848 | /** |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2849 | * snd_soc_add_platform - Add a platform to the ASoC core |
| 2850 | * @dev: The parent device for the platform |
| 2851 | * @platform: The platform to add |
| 2852 | * @platform_driver: The driver for the platform |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2853 | */ |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2854 | 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] | 2855 | const struct snd_soc_platform_driver *platform_drv) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2856 | { |
Lars-Peter Clausen | b37f1d1 | 2014-03-18 09:02:12 +0100 | [diff] [blame] | 2857 | int ret; |
| 2858 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2859 | ret = snd_soc_component_initialize(&platform->component, |
| 2860 | &platform_drv->component_driver, dev); |
| 2861 | if (ret) |
| 2862 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2863 | |
| 2864 | platform->dev = dev; |
| 2865 | platform->driver = platform_drv; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 2866 | |
| 2867 | if (platform_drv->probe) |
| 2868 | platform->component.probe = snd_soc_platform_drv_probe; |
| 2869 | if (platform_drv->remove) |
| 2870 | platform->component.remove = snd_soc_platform_drv_remove; |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2871 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 2872 | #ifdef CONFIG_DEBUG_FS |
| 2873 | platform->component.debugfs_prefix = "platform"; |
| 2874 | #endif |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2875 | |
| 2876 | mutex_lock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2877 | snd_soc_component_add_unlocked(&platform->component); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2878 | list_add(&platform->list, &platform_list); |
| 2879 | mutex_unlock(&client_mutex); |
| 2880 | |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 2881 | dev_dbg(dev, "ASoC: Registered platform '%s'\n", |
| 2882 | platform->component.name); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2883 | |
| 2884 | return 0; |
| 2885 | } |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2886 | EXPORT_SYMBOL_GPL(snd_soc_add_platform); |
| 2887 | |
| 2888 | /** |
| 2889 | * snd_soc_register_platform - Register a platform with the ASoC core |
| 2890 | * |
| 2891 | * @platform: platform to register |
| 2892 | */ |
| 2893 | int snd_soc_register_platform(struct device *dev, |
| 2894 | const struct snd_soc_platform_driver *platform_drv) |
| 2895 | { |
| 2896 | struct snd_soc_platform *platform; |
| 2897 | int ret; |
| 2898 | |
| 2899 | dev_dbg(dev, "ASoC: platform register %s\n", dev_name(dev)); |
| 2900 | |
| 2901 | platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL); |
| 2902 | if (platform == NULL) |
| 2903 | return -ENOMEM; |
| 2904 | |
| 2905 | ret = snd_soc_add_platform(dev, platform, platform_drv); |
| 2906 | if (ret) |
| 2907 | kfree(platform); |
| 2908 | |
| 2909 | return ret; |
| 2910 | } |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2911 | EXPORT_SYMBOL_GPL(snd_soc_register_platform); |
| 2912 | |
| 2913 | /** |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2914 | * snd_soc_remove_platform - Remove a platform from the ASoC core |
| 2915 | * @platform: the platform to remove |
| 2916 | */ |
| 2917 | void snd_soc_remove_platform(struct snd_soc_platform *platform) |
| 2918 | { |
Lars-Peter Clausen | b37f1d1 | 2014-03-18 09:02:12 +0100 | [diff] [blame] | 2919 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2920 | mutex_lock(&client_mutex); |
| 2921 | list_del(&platform->list); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2922 | snd_soc_component_del_unlocked(&platform->component); |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2923 | mutex_unlock(&client_mutex); |
| 2924 | |
| 2925 | dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n", |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 2926 | platform->component.name); |
Daniel Mack | decc27b | 2014-10-07 13:41:23 +0200 | [diff] [blame] | 2927 | |
| 2928 | snd_soc_component_cleanup(&platform->component); |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2929 | } |
| 2930 | EXPORT_SYMBOL_GPL(snd_soc_remove_platform); |
| 2931 | |
| 2932 | struct snd_soc_platform *snd_soc_lookup_platform(struct device *dev) |
| 2933 | { |
| 2934 | struct snd_soc_platform *platform; |
| 2935 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2936 | mutex_lock(&client_mutex); |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2937 | list_for_each_entry(platform, &platform_list, list) { |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2938 | if (dev == platform->dev) { |
| 2939 | mutex_unlock(&client_mutex); |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2940 | return platform; |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2941 | } |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2942 | } |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2943 | mutex_unlock(&client_mutex); |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2944 | |
| 2945 | return NULL; |
| 2946 | } |
| 2947 | EXPORT_SYMBOL_GPL(snd_soc_lookup_platform); |
| 2948 | |
| 2949 | /** |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2950 | * snd_soc_unregister_platform - Unregister a platform from the ASoC core |
| 2951 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2952 | * @platform: platform to unregister |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2953 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2954 | void snd_soc_unregister_platform(struct device *dev) |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2955 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2956 | struct snd_soc_platform *platform; |
| 2957 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2958 | platform = snd_soc_lookup_platform(dev); |
| 2959 | if (!platform) |
| 2960 | return; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2961 | |
Lars-Peter Clausen | 71a45cd | 2013-04-15 19:19:49 +0200 | [diff] [blame] | 2962 | snd_soc_remove_platform(platform); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2963 | kfree(platform); |
Mark Brown | 12a48a8c | 2008-12-03 19:40:30 +0000 | [diff] [blame] | 2964 | } |
| 2965 | EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); |
| 2966 | |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 2967 | static u64 codec_format_map[] = { |
| 2968 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE, |
| 2969 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE, |
| 2970 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE, |
| 2971 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, |
| 2972 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE, |
| 2973 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE, |
| 2974 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 2975 | SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE, |
| 2976 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE, |
| 2977 | SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE, |
| 2978 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE, |
| 2979 | SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE, |
| 2980 | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE, |
| 2981 | SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE, |
| 2982 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE |
| 2983 | | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE, |
| 2984 | }; |
| 2985 | |
| 2986 | /* Fix up the DAI formats for endianness: codecs don't actually see |
| 2987 | * the endianness of the data but we're using the CPU format |
| 2988 | * definitions which do need to include endianness so we ensure that |
| 2989 | * codec DAIs always have both big and little endian variants set. |
| 2990 | */ |
| 2991 | static void fixup_codec_formats(struct snd_soc_pcm_stream *stream) |
| 2992 | { |
| 2993 | int i; |
| 2994 | |
| 2995 | for (i = 0; i < ARRAY_SIZE(codec_format_map); i++) |
| 2996 | if (stream->formats & codec_format_map[i]) |
| 2997 | stream->formats |= codec_format_map[i]; |
| 2998 | } |
| 2999 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 3000 | static int snd_soc_codec_drv_probe(struct snd_soc_component *component) |
| 3001 | { |
| 3002 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 3003 | |
| 3004 | return codec->driver->probe(codec); |
| 3005 | } |
| 3006 | |
| 3007 | static void snd_soc_codec_drv_remove(struct snd_soc_component *component) |
| 3008 | { |
| 3009 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 3010 | |
| 3011 | codec->driver->remove(codec); |
| 3012 | } |
| 3013 | |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 3014 | static int snd_soc_codec_drv_write(struct snd_soc_component *component, |
| 3015 | unsigned int reg, unsigned int val) |
| 3016 | { |
| 3017 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 3018 | |
| 3019 | return codec->driver->write(codec, reg, val); |
| 3020 | } |
| 3021 | |
| 3022 | static int snd_soc_codec_drv_read(struct snd_soc_component *component, |
| 3023 | unsigned int reg, unsigned int *val) |
| 3024 | { |
| 3025 | struct snd_soc_codec *codec = snd_soc_component_to_codec(component); |
| 3026 | |
| 3027 | *val = codec->driver->read(codec, reg); |
| 3028 | |
| 3029 | return 0; |
| 3030 | } |
| 3031 | |
Lars-Peter Clausen | 68f831c | 2014-06-16 18:13:05 +0200 | [diff] [blame] | 3032 | static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, |
| 3033 | enum snd_soc_bias_level level) |
| 3034 | { |
| 3035 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 3036 | |
| 3037 | return codec->driver->set_bias_level(codec, level); |
| 3038 | } |
| 3039 | |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3040 | /** |
| 3041 | * snd_soc_register_codec - Register a codec with the ASoC core |
| 3042 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3043 | * @codec: codec to register |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3044 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3045 | int snd_soc_register_codec(struct device *dev, |
Mark Brown | 001ae4c | 2010-12-02 16:21:08 +0000 | [diff] [blame] | 3046 | const struct snd_soc_codec_driver *codec_drv, |
| 3047 | struct snd_soc_dai_driver *dai_drv, |
| 3048 | int num_dai) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3049 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3050 | struct snd_soc_codec *codec; |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3051 | struct snd_soc_dai *dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3052 | int ret, i; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 3053 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3054 | dev_dbg(dev, "codec register %s\n", dev_name(dev)); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3055 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3056 | codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 3057 | if (codec == NULL) |
| 3058 | return -ENOMEM; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3059 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3060 | codec->component.dapm_ptr = &codec->dapm; |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 3061 | codec->component.codec = codec; |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3062 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3063 | ret = snd_soc_component_initialize(&codec->component, |
| 3064 | &codec_drv->component_driver, dev); |
| 3065 | if (ret) |
| 3066 | goto err_free; |
Mark Brown | 151ab22 | 2009-05-09 16:22:58 +0100 | [diff] [blame] | 3067 | |
Lars-Peter Clausen | f1d45cc3 | 2014-08-19 15:51:19 +0200 | [diff] [blame] | 3068 | if (codec_drv->controls) { |
| 3069 | codec->component.controls = codec_drv->controls; |
| 3070 | codec->component.num_controls = codec_drv->num_controls; |
| 3071 | } |
| 3072 | if (codec_drv->dapm_widgets) { |
| 3073 | codec->component.dapm_widgets = codec_drv->dapm_widgets; |
| 3074 | codec->component.num_dapm_widgets = codec_drv->num_dapm_widgets; |
| 3075 | } |
| 3076 | if (codec_drv->dapm_routes) { |
| 3077 | codec->component.dapm_routes = codec_drv->dapm_routes; |
| 3078 | codec->component.num_dapm_routes = codec_drv->num_dapm_routes; |
| 3079 | } |
| 3080 | |
| 3081 | if (codec_drv->probe) |
| 3082 | codec->component.probe = snd_soc_codec_drv_probe; |
| 3083 | if (codec_drv->remove) |
| 3084 | codec->component.remove = snd_soc_codec_drv_remove; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 3085 | if (codec_drv->write) |
| 3086 | codec->component.write = snd_soc_codec_drv_write; |
| 3087 | if (codec_drv->read) |
| 3088 | codec->component.read = snd_soc_codec_drv_read; |
Lars-Peter Clausen | 3d59400 | 2014-03-05 13:17:48 +0100 | [diff] [blame] | 3089 | codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; |
Lars-Peter Clausen | 5819c2f | 2014-08-24 15:36:55 +0200 | [diff] [blame] | 3090 | codec->dapm.idle_bias_off = codec_drv->idle_bias_off; |
Lars-Peter Clausen | 86dbf2a | 2014-09-04 19:44:06 +0200 | [diff] [blame] | 3091 | codec->dapm.suspend_bias_off = codec_drv->suspend_bias_off; |
Lars-Peter Clausen | 14e8bde | 2014-06-16 18:13:08 +0200 | [diff] [blame] | 3092 | if (codec_drv->seq_notifier) |
| 3093 | codec->dapm.seq_notifier = codec_drv->seq_notifier; |
Lars-Peter Clausen | 68f831c | 2014-06-16 18:13:05 +0200 | [diff] [blame] | 3094 | if (codec_drv->set_bias_level) |
| 3095 | codec->dapm.set_bias_level = snd_soc_codec_set_bias_level; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3096 | codec->dev = dev; |
| 3097 | codec->driver = codec_drv; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 3098 | codec->component.val_bytes = codec_drv->reg_word_size; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3099 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 3100 | #ifdef CONFIG_DEBUG_FS |
| 3101 | codec->component.init_debugfs = soc_init_codec_debugfs; |
| 3102 | codec->component.debugfs_prefix = "codec"; |
| 3103 | #endif |
Xiubo Li | a39f75f | 2014-03-26 13:40:23 +0800 | [diff] [blame] | 3104 | |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 3105 | if (codec_drv->get_regmap) |
| 3106 | codec->component.regmap = codec_drv->get_regmap(dev); |
Xiubo Li | a39f75f | 2014-03-26 13:40:23 +0800 | [diff] [blame] | 3107 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3108 | for (i = 0; i < num_dai; i++) { |
| 3109 | fixup_codec_formats(&dai_drv[i].playback); |
| 3110 | fixup_codec_formats(&dai_drv[i].capture); |
| 3111 | } |
| 3112 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3113 | ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false); |
| 3114 | if (ret < 0) { |
| 3115 | dev_err(dev, "ASoC: Failed to regster DAIs: %d\n", ret); |
| 3116 | goto err_cleanup; |
| 3117 | } |
| 3118 | |
| 3119 | list_for_each_entry(dai, &codec->component.dai_list, list) |
| 3120 | dai->codec = codec; |
| 3121 | |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3122 | mutex_lock(&client_mutex); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3123 | snd_soc_component_add_unlocked(&codec->component); |
Mark Brown | 054880f | 2012-04-09 17:29:19 +0100 | [diff] [blame] | 3124 | list_add(&codec->list, &codec_list); |
| 3125 | mutex_unlock(&client_mutex); |
| 3126 | |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 3127 | dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", |
| 3128 | codec->component.name); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3129 | return 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3130 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3131 | err_cleanup: |
| 3132 | snd_soc_component_cleanup(&codec->component); |
| 3133 | err_free: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3134 | kfree(codec); |
| 3135 | return ret; |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3136 | } |
| 3137 | EXPORT_SYMBOL_GPL(snd_soc_register_codec); |
| 3138 | |
| 3139 | /** |
| 3140 | * snd_soc_unregister_codec - Unregister a codec from the ASoC core |
| 3141 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3142 | * @codec: codec to unregister |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3143 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3144 | void snd_soc_unregister_codec(struct device *dev) |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3145 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3146 | struct snd_soc_codec *codec; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3147 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 3148 | mutex_lock(&client_mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3149 | list_for_each_entry(codec, &codec_list, list) { |
| 3150 | if (dev == codec->dev) |
| 3151 | goto found; |
| 3152 | } |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 3153 | mutex_unlock(&client_mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3154 | return; |
| 3155 | |
| 3156 | found: |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3157 | list_del(&codec->list); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3158 | snd_soc_component_del_unlocked(&codec->component); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3159 | mutex_unlock(&client_mutex); |
| 3160 | |
Lars-Peter Clausen | f433320 | 2014-06-16 18:13:02 +0200 | [diff] [blame] | 3161 | dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", |
| 3162 | codec->component.name); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3163 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 3164 | snd_soc_component_cleanup(&codec->component); |
Dimitris Papastamos | 7a30a3d | 2010-11-11 10:04:57 +0000 | [diff] [blame] | 3165 | snd_soc_cache_exit(codec); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3166 | kfree(codec); |
Mark Brown | 0d0cf00 | 2008-12-10 14:32:45 +0000 | [diff] [blame] | 3167 | } |
| 3168 | EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); |
| 3169 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3170 | /* Retrieve a card's name from device tree */ |
| 3171 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, |
| 3172 | const char *propname) |
| 3173 | { |
Tushar Behera | 7e07e7c | 2014-07-04 14:23:00 +0530 | [diff] [blame] | 3174 | struct device_node *np; |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3175 | int ret; |
| 3176 | |
Tushar Behera | 7e07e7c | 2014-07-04 14:23:00 +0530 | [diff] [blame] | 3177 | if (!card->dev) { |
| 3178 | pr_err("card->dev is not set before calling %s\n", __func__); |
| 3179 | return -EINVAL; |
| 3180 | } |
| 3181 | |
| 3182 | np = card->dev->of_node; |
| 3183 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3184 | ret = of_property_read_string_index(np, propname, 0, &card->name); |
| 3185 | /* |
| 3186 | * EINVAL means the property does not exist. This is fine providing |
| 3187 | * card->name was previously set, which is checked later in |
| 3188 | * snd_soc_register_card. |
| 3189 | */ |
| 3190 | if (ret < 0 && ret != -EINVAL) { |
| 3191 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3192 | "ASoC: Property '%s' could not be read: %d\n", |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 3193 | propname, ret); |
| 3194 | return ret; |
| 3195 | } |
| 3196 | |
| 3197 | return 0; |
| 3198 | } |
| 3199 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); |
| 3200 | |
Xiubo Li | 9a6d486 | 2014-02-08 15:59:52 +0800 | [diff] [blame] | 3201 | static const struct snd_soc_dapm_widget simple_widgets[] = { |
| 3202 | SND_SOC_DAPM_MIC("Microphone", NULL), |
| 3203 | SND_SOC_DAPM_LINE("Line", NULL), |
| 3204 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 3205 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 3206 | }; |
| 3207 | |
| 3208 | int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card, |
| 3209 | const char *propname) |
| 3210 | { |
| 3211 | struct device_node *np = card->dev->of_node; |
| 3212 | struct snd_soc_dapm_widget *widgets; |
| 3213 | const char *template, *wname; |
| 3214 | int i, j, num_widgets, ret; |
| 3215 | |
| 3216 | num_widgets = of_property_count_strings(np, propname); |
| 3217 | if (num_widgets < 0) { |
| 3218 | dev_err(card->dev, |
| 3219 | "ASoC: Property '%s' does not exist\n", propname); |
| 3220 | return -EINVAL; |
| 3221 | } |
| 3222 | if (num_widgets & 1) { |
| 3223 | dev_err(card->dev, |
| 3224 | "ASoC: Property '%s' length is not even\n", propname); |
| 3225 | return -EINVAL; |
| 3226 | } |
| 3227 | |
| 3228 | num_widgets /= 2; |
| 3229 | if (!num_widgets) { |
| 3230 | dev_err(card->dev, "ASoC: Property '%s's length is zero\n", |
| 3231 | propname); |
| 3232 | return -EINVAL; |
| 3233 | } |
| 3234 | |
| 3235 | widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets), |
| 3236 | GFP_KERNEL); |
| 3237 | if (!widgets) { |
| 3238 | dev_err(card->dev, |
| 3239 | "ASoC: Could not allocate memory for widgets\n"); |
| 3240 | return -ENOMEM; |
| 3241 | } |
| 3242 | |
| 3243 | for (i = 0; i < num_widgets; i++) { |
| 3244 | ret = of_property_read_string_index(np, propname, |
| 3245 | 2 * i, &template); |
| 3246 | if (ret) { |
| 3247 | dev_err(card->dev, |
| 3248 | "ASoC: Property '%s' index %d read error:%d\n", |
| 3249 | propname, 2 * i, ret); |
| 3250 | return -EINVAL; |
| 3251 | } |
| 3252 | |
| 3253 | for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) { |
| 3254 | if (!strncmp(template, simple_widgets[j].name, |
| 3255 | strlen(simple_widgets[j].name))) { |
| 3256 | widgets[i] = simple_widgets[j]; |
| 3257 | break; |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | if (j >= ARRAY_SIZE(simple_widgets)) { |
| 3262 | dev_err(card->dev, |
| 3263 | "ASoC: DAPM widget '%s' is not supported\n", |
| 3264 | template); |
| 3265 | return -EINVAL; |
| 3266 | } |
| 3267 | |
| 3268 | ret = of_property_read_string_index(np, propname, |
| 3269 | (2 * i) + 1, |
| 3270 | &wname); |
| 3271 | if (ret) { |
| 3272 | dev_err(card->dev, |
| 3273 | "ASoC: Property '%s' index %d read error:%d\n", |
| 3274 | propname, (2 * i) + 1, ret); |
| 3275 | return -EINVAL; |
| 3276 | } |
| 3277 | |
| 3278 | widgets[i].name = wname; |
| 3279 | } |
| 3280 | |
| 3281 | card->dapm_widgets = widgets; |
| 3282 | card->num_dapm_widgets = num_widgets; |
| 3283 | |
| 3284 | return 0; |
| 3285 | } |
| 3286 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets); |
| 3287 | |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 3288 | int snd_soc_of_parse_tdm_slot(struct device_node *np, |
| 3289 | unsigned int *slots, |
| 3290 | unsigned int *slot_width) |
| 3291 | { |
| 3292 | u32 val; |
| 3293 | int ret; |
| 3294 | |
| 3295 | if (of_property_read_bool(np, "dai-tdm-slot-num")) { |
| 3296 | ret = of_property_read_u32(np, "dai-tdm-slot-num", &val); |
| 3297 | if (ret) |
| 3298 | return ret; |
| 3299 | |
| 3300 | if (slots) |
| 3301 | *slots = val; |
| 3302 | } |
| 3303 | |
| 3304 | if (of_property_read_bool(np, "dai-tdm-slot-width")) { |
| 3305 | ret = of_property_read_u32(np, "dai-tdm-slot-width", &val); |
| 3306 | if (ret) |
| 3307 | return ret; |
| 3308 | |
| 3309 | if (slot_width) |
| 3310 | *slot_width = val; |
| 3311 | } |
| 3312 | |
| 3313 | return 0; |
| 3314 | } |
| 3315 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot); |
| 3316 | |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3317 | int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, |
| 3318 | const char *propname) |
| 3319 | { |
| 3320 | struct device_node *np = card->dev->of_node; |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3321 | int num_routes; |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3322 | struct snd_soc_dapm_route *routes; |
| 3323 | int i, ret; |
| 3324 | |
| 3325 | num_routes = of_property_count_strings(np, propname); |
Richard Zhao | c34ce32 | 2012-04-24 15:24:43 +0800 | [diff] [blame] | 3326 | if (num_routes < 0 || num_routes & 1) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3327 | dev_err(card->dev, |
| 3328 | "ASoC: Property '%s' does not exist or its length is not even\n", |
| 3329 | propname); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3330 | return -EINVAL; |
| 3331 | } |
| 3332 | num_routes /= 2; |
| 3333 | if (!num_routes) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3334 | dev_err(card->dev, "ASoC: Property '%s's length is zero\n", |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3335 | propname); |
| 3336 | return -EINVAL; |
| 3337 | } |
| 3338 | |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3339 | routes = devm_kzalloc(card->dev, num_routes * sizeof(*routes), |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3340 | GFP_KERNEL); |
| 3341 | if (!routes) { |
| 3342 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3343 | "ASoC: Could not allocate DAPM route table\n"); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3344 | return -EINVAL; |
| 3345 | } |
| 3346 | |
| 3347 | for (i = 0; i < num_routes; i++) { |
| 3348 | ret = of_property_read_string_index(np, propname, |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3349 | 2 * i, &routes[i].sink); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3350 | if (ret) { |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 3351 | dev_err(card->dev, |
| 3352 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 3353 | propname, 2 * i, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3354 | return -EINVAL; |
| 3355 | } |
| 3356 | ret = of_property_read_string_index(np, propname, |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3357 | (2 * i) + 1, &routes[i].source); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3358 | if (ret) { |
| 3359 | dev_err(card->dev, |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 3360 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 3361 | propname, (2 * i) + 1, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3362 | return -EINVAL; |
| 3363 | } |
| 3364 | } |
| 3365 | |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3366 | card->num_dapm_routes = num_routes; |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3367 | card->dapm_routes = routes; |
| 3368 | |
| 3369 | return 0; |
| 3370 | } |
| 3371 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); |
| 3372 | |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3373 | unsigned int snd_soc_of_parse_daifmt(struct device_node *np, |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3374 | const char *prefix, |
| 3375 | struct device_node **bitclkmaster, |
| 3376 | struct device_node **framemaster) |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3377 | { |
| 3378 | int ret, i; |
| 3379 | char prop[128]; |
| 3380 | unsigned int format = 0; |
| 3381 | int bit, frame; |
| 3382 | const char *str; |
| 3383 | struct { |
| 3384 | char *name; |
| 3385 | unsigned int val; |
| 3386 | } of_fmt_table[] = { |
| 3387 | { "i2s", SND_SOC_DAIFMT_I2S }, |
| 3388 | { "right_j", SND_SOC_DAIFMT_RIGHT_J }, |
| 3389 | { "left_j", SND_SOC_DAIFMT_LEFT_J }, |
| 3390 | { "dsp_a", SND_SOC_DAIFMT_DSP_A }, |
| 3391 | { "dsp_b", SND_SOC_DAIFMT_DSP_B }, |
| 3392 | { "ac97", SND_SOC_DAIFMT_AC97 }, |
| 3393 | { "pdm", SND_SOC_DAIFMT_PDM}, |
| 3394 | { "msb", SND_SOC_DAIFMT_MSB }, |
| 3395 | { "lsb", SND_SOC_DAIFMT_LSB }, |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3396 | }; |
| 3397 | |
| 3398 | if (!prefix) |
| 3399 | prefix = ""; |
| 3400 | |
| 3401 | /* |
| 3402 | * check "[prefix]format = xxx" |
| 3403 | * SND_SOC_DAIFMT_FORMAT_MASK area |
| 3404 | */ |
| 3405 | snprintf(prop, sizeof(prop), "%sformat", prefix); |
| 3406 | ret = of_property_read_string(np, prop, &str); |
| 3407 | if (ret == 0) { |
| 3408 | for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) { |
| 3409 | if (strcmp(str, of_fmt_table[i].name) == 0) { |
| 3410 | format |= of_fmt_table[i].val; |
| 3411 | break; |
| 3412 | } |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | /* |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 3417 | * check "[prefix]continuous-clock" |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3418 | * SND_SOC_DAIFMT_CLOCK_MASK area |
| 3419 | */ |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 3420 | snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); |
| 3421 | if (of_get_property(np, prop, NULL)) |
| 3422 | format |= SND_SOC_DAIFMT_CONT; |
| 3423 | else |
| 3424 | format |= SND_SOC_DAIFMT_GATED; |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3425 | |
| 3426 | /* |
| 3427 | * check "[prefix]bitclock-inversion" |
| 3428 | * check "[prefix]frame-inversion" |
| 3429 | * SND_SOC_DAIFMT_INV_MASK area |
| 3430 | */ |
| 3431 | snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); |
| 3432 | bit = !!of_get_property(np, prop, NULL); |
| 3433 | |
| 3434 | snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); |
| 3435 | frame = !!of_get_property(np, prop, NULL); |
| 3436 | |
| 3437 | switch ((bit << 4) + frame) { |
| 3438 | case 0x11: |
| 3439 | format |= SND_SOC_DAIFMT_IB_IF; |
| 3440 | break; |
| 3441 | case 0x10: |
| 3442 | format |= SND_SOC_DAIFMT_IB_NF; |
| 3443 | break; |
| 3444 | case 0x01: |
| 3445 | format |= SND_SOC_DAIFMT_NB_IF; |
| 3446 | break; |
| 3447 | default: |
| 3448 | /* SND_SOC_DAIFMT_NB_NF is default */ |
| 3449 | break; |
| 3450 | } |
| 3451 | |
| 3452 | /* |
| 3453 | * check "[prefix]bitclock-master" |
| 3454 | * check "[prefix]frame-master" |
| 3455 | * SND_SOC_DAIFMT_MASTER_MASK area |
| 3456 | */ |
| 3457 | snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); |
| 3458 | bit = !!of_get_property(np, prop, NULL); |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3459 | if (bit && bitclkmaster) |
| 3460 | *bitclkmaster = of_parse_phandle(np, prop, 0); |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3461 | |
| 3462 | snprintf(prop, sizeof(prop), "%sframe-master", prefix); |
| 3463 | frame = !!of_get_property(np, prop, NULL); |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3464 | if (frame && framemaster) |
| 3465 | *framemaster = of_parse_phandle(np, prop, 0); |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3466 | |
| 3467 | switch ((bit << 4) + frame) { |
| 3468 | case 0x11: |
| 3469 | format |= SND_SOC_DAIFMT_CBM_CFM; |
| 3470 | break; |
| 3471 | case 0x10: |
| 3472 | format |= SND_SOC_DAIFMT_CBM_CFS; |
| 3473 | break; |
| 3474 | case 0x01: |
| 3475 | format |= SND_SOC_DAIFMT_CBS_CFM; |
| 3476 | break; |
| 3477 | default: |
| 3478 | format |= SND_SOC_DAIFMT_CBS_CFS; |
| 3479 | break; |
| 3480 | } |
| 3481 | |
| 3482 | return format; |
| 3483 | } |
| 3484 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); |
| 3485 | |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3486 | static int snd_soc_get_dai_name(struct of_phandle_args *args, |
| 3487 | const char **dai_name) |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3488 | { |
| 3489 | struct snd_soc_component *pos; |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3490 | int ret = -EPROBE_DEFER; |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3491 | |
| 3492 | mutex_lock(&client_mutex); |
| 3493 | list_for_each_entry(pos, &component_list, list) { |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3494 | if (pos->dev->of_node != args->np) |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3495 | continue; |
| 3496 | |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3497 | if (pos->driver->of_xlate_dai_name) { |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3498 | ret = pos->driver->of_xlate_dai_name(pos, |
| 3499 | args, |
| 3500 | dai_name); |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3501 | } else { |
| 3502 | int id = -1; |
| 3503 | |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3504 | switch (args->args_count) { |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3505 | case 0: |
| 3506 | id = 0; /* same as dai_drv[0] */ |
| 3507 | break; |
| 3508 | case 1: |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3509 | id = args->args[0]; |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3510 | break; |
| 3511 | default: |
| 3512 | /* not supported */ |
| 3513 | break; |
| 3514 | } |
| 3515 | |
| 3516 | if (id < 0 || id >= pos->num_dai) { |
| 3517 | ret = -EINVAL; |
Nicolin Chen | 3dcba28 | 2014-04-21 19:14:46 +0800 | [diff] [blame] | 3518 | continue; |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3519 | } |
Xiubo Li | e41975e | 2013-12-20 14:39:51 +0800 | [diff] [blame] | 3520 | |
| 3521 | ret = 0; |
| 3522 | |
| 3523 | *dai_name = pos->dai_drv[id].name; |
| 3524 | if (!*dai_name) |
| 3525 | *dai_name = pos->name; |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3528 | break; |
| 3529 | } |
| 3530 | mutex_unlock(&client_mutex); |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3531 | return ret; |
| 3532 | } |
| 3533 | |
| 3534 | int snd_soc_of_get_dai_name(struct device_node *of_node, |
| 3535 | const char **dai_name) |
| 3536 | { |
| 3537 | struct of_phandle_args args; |
| 3538 | int ret; |
| 3539 | |
| 3540 | ret = of_parse_phandle_with_args(of_node, "sound-dai", |
| 3541 | "#sound-dai-cells", 0, &args); |
| 3542 | if (ret) |
| 3543 | return ret; |
| 3544 | |
| 3545 | ret = snd_soc_get_dai_name(&args, dai_name); |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3546 | |
| 3547 | of_node_put(args.np); |
| 3548 | |
| 3549 | return ret; |
| 3550 | } |
| 3551 | EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name); |
| 3552 | |
Jean-Francois Moine | 93b0f3e | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3553 | /* |
| 3554 | * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree |
| 3555 | * @dev: Card device |
| 3556 | * @of_node: Device node |
| 3557 | * @dai_link: DAI link |
| 3558 | * |
| 3559 | * Builds an array of CODEC DAI components from the DAI link property |
| 3560 | * 'sound-dai'. |
| 3561 | * The array is set in the DAI link and the number of DAIs is set accordingly. |
| 3562 | * The device nodes in the array (of_node) must be dereferenced by the caller. |
| 3563 | * |
| 3564 | * Returns 0 for success |
| 3565 | */ |
| 3566 | int snd_soc_of_get_dai_link_codecs(struct device *dev, |
| 3567 | struct device_node *of_node, |
| 3568 | struct snd_soc_dai_link *dai_link) |
| 3569 | { |
| 3570 | struct of_phandle_args args; |
| 3571 | struct snd_soc_dai_link_component *component; |
| 3572 | char *name; |
| 3573 | int index, num_codecs, ret; |
| 3574 | |
| 3575 | /* Count the number of CODECs */ |
| 3576 | name = "sound-dai"; |
| 3577 | num_codecs = of_count_phandle_with_args(of_node, name, |
| 3578 | "#sound-dai-cells"); |
| 3579 | if (num_codecs <= 0) { |
| 3580 | if (num_codecs == -ENOENT) |
| 3581 | dev_err(dev, "No 'sound-dai' property\n"); |
| 3582 | else |
| 3583 | dev_err(dev, "Bad phandle in 'sound-dai'\n"); |
| 3584 | return num_codecs; |
| 3585 | } |
| 3586 | component = devm_kzalloc(dev, |
| 3587 | sizeof *component * num_codecs, |
| 3588 | GFP_KERNEL); |
| 3589 | if (!component) |
| 3590 | return -ENOMEM; |
| 3591 | dai_link->codecs = component; |
| 3592 | dai_link->num_codecs = num_codecs; |
| 3593 | |
| 3594 | /* Parse the list */ |
| 3595 | for (index = 0, component = dai_link->codecs; |
| 3596 | index < dai_link->num_codecs; |
| 3597 | index++, component++) { |
| 3598 | ret = of_parse_phandle_with_args(of_node, name, |
| 3599 | "#sound-dai-cells", |
| 3600 | index, &args); |
| 3601 | if (ret) |
| 3602 | goto err; |
| 3603 | component->of_node = args.np; |
| 3604 | ret = snd_soc_get_dai_name(&args, &component->dai_name); |
| 3605 | if (ret < 0) |
| 3606 | goto err; |
| 3607 | } |
| 3608 | return 0; |
| 3609 | err: |
| 3610 | for (index = 0, component = dai_link->codecs; |
| 3611 | index < dai_link->num_codecs; |
| 3612 | index++, component++) { |
| 3613 | if (!component->of_node) |
| 3614 | break; |
| 3615 | of_node_put(component->of_node); |
| 3616 | component->of_node = NULL; |
| 3617 | } |
| 3618 | dai_link->codecs = NULL; |
| 3619 | dai_link->num_codecs = 0; |
| 3620 | return ret; |
| 3621 | } |
| 3622 | EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs); |
| 3623 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 3624 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3625 | { |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame^] | 3626 | snd_soc_debugfs_init(); |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3627 | snd_soc_util_init(); |
| 3628 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3629 | return platform_driver_register(&soc_driver); |
| 3630 | } |
Mark Brown | 4abe8e1 | 2010-10-12 17:41:03 +0100 | [diff] [blame] | 3631 | module_init(snd_soc_init); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3632 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 3633 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3634 | { |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3635 | snd_soc_util_exit(); |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame^] | 3636 | snd_soc_debugfs_exit(); |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3637 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3638 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 3639 | #endif |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 3640 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3641 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3642 | module_exit(snd_soc_exit); |
| 3643 | |
| 3644 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 3645 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3646 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 3647 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 3648 | MODULE_ALIAS("platform:soc-audio"); |