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