Kuninori Morimoto | 873486e | 2018-07-02 06:24:18 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // soc-core.c -- ALSA SoC Audio Layer |
| 4 | // |
| 5 | // Copyright 2005 Wolfson Microelectronics PLC. |
| 6 | // Copyright 2005 Openedhand Ltd. |
| 7 | // Copyright (C) 2010 Slimlogic Ltd. |
| 8 | // Copyright (C) 2010 Texas Instruments Inc. |
| 9 | // |
| 10 | // Author: Liam Girdwood <lrg@slimlogic.co.uk> |
| 11 | // with code, comments and ideas from :- |
| 12 | // Richard Purdie <richard@openedhand.com> |
| 13 | // |
| 14 | // TODO: |
| 15 | // o Add hw rules to enforce rates, etc. |
| 16 | // o More testing with other codecs/machines. |
| 17 | // o Add more codecs and platforms to ensure good API coverage. |
| 18 | // o Support TDM on PCM and I2S |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/moduleparam.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/pm.h> |
| 25 | #include <linux/bitops.h> |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 26 | #include <linux/debugfs.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
Markus Pargmann | 741a509 | 2013-08-19 17:05:55 +0200 | [diff] [blame] | 28 | #include <linux/pinctrl/consumer.h> |
Mark Brown | f0e8ed8 | 2011-09-20 11:41:54 +0100 | [diff] [blame] | 29 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 31 | #include <linux/of.h> |
Kuninori Morimoto | a180e8b | 2017-05-18 01:39:25 +0000 | [diff] [blame] | 32 | #include <linux/of_graph.h> |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 33 | #include <linux/dmi.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 34 | #include <sound/core.h> |
Mark Brown | 3028eb8 | 2010-12-05 12:22:46 +0000 | [diff] [blame] | 35 | #include <sound/jack.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 36 | #include <sound/pcm.h> |
| 37 | #include <sound/pcm_params.h> |
| 38 | #include <sound/soc.h> |
Liam Girdwood | 01d7584 | 2012-04-25 12:12:49 +0100 | [diff] [blame] | 39 | #include <sound/soc-dpcm.h> |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 40 | #include <sound/soc-topology.h> |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 41 | #include <sound/initval.h> |
| 42 | |
Mark Brown | a8b1d34 | 2010-11-03 18:05:58 -0400 | [diff] [blame] | 43 | #define CREATE_TRACE_POINTS |
| 44 | #include <trace/events/asoc.h> |
| 45 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 46 | #define NAME_SIZE 32 |
| 47 | |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 49 | struct dentry *snd_soc_debugfs_root; |
| 50 | EXPORT_SYMBOL_GPL(snd_soc_debugfs_root); |
Mark Brown | 384c89e | 2008-12-03 17:34:03 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 53 | static DEFINE_MUTEX(client_mutex); |
Kuninori Morimoto | 030e79f | 2013-03-11 18:27:21 -0700 | [diff] [blame] | 54 | static LIST_HEAD(component_list); |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 55 | static LIST_HEAD(unbind_card_list); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 56 | |
Kuninori Morimoto | 368dee9 | 2018-09-21 05:23:01 +0000 | [diff] [blame] | 57 | #define for_each_component(component) \ |
| 58 | list_for_each_entry(component, &component_list, list) |
| 59 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 60 | /* |
Kuninori Morimoto | 587c984 | 2019-06-06 13:07:42 +0900 | [diff] [blame] | 61 | * This is used if driver don't need to have CPU/Codec/Platform |
| 62 | * dai_link. see soc.h |
| 63 | */ |
| 64 | struct snd_soc_dai_link_component null_dailink_component[0]; |
| 65 | EXPORT_SYMBOL_GPL(null_dailink_component); |
| 66 | |
| 67 | /* |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 68 | * This is a timeout to do a DAPM powerdown after a stream is closed(). |
| 69 | * It can be used to eliminate pops between different playback streams, e.g. |
| 70 | * between two audio tracks. |
| 71 | */ |
| 72 | static int pmdown_time = 5000; |
| 73 | module_param(pmdown_time, int, 0); |
| 74 | MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)"); |
| 75 | |
YueHaibing | 0faf123 | 2019-08-13 22:25:01 +0800 | [diff] [blame] | 76 | #ifdef CONFIG_DMI |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 77 | /* |
| 78 | * If a DMI filed contain strings in this blacklist (e.g. |
| 79 | * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 80 | * as invalid and dropped when setting the card long name from DMI info. |
| 81 | */ |
| 82 | static const char * const dmi_blacklist[] = { |
| 83 | "To be filled by OEM", |
| 84 | "TBD by OEM", |
| 85 | "Default String", |
| 86 | "Board Manufacturer", |
| 87 | "Board Vendor Name", |
| 88 | "Board Product Name", |
| 89 | NULL, /* terminator */ |
| 90 | }; |
YueHaibing | 0faf123 | 2019-08-13 22:25:01 +0800 | [diff] [blame] | 91 | #endif |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 92 | |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 93 | static ssize_t pmdown_time_show(struct device *dev, |
| 94 | struct device_attribute *attr, char *buf) |
| 95 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 96 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 97 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 98 | return sprintf(buf, "%ld\n", rtd->pmdown_time); |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static ssize_t pmdown_time_set(struct device *dev, |
| 102 | struct device_attribute *attr, |
| 103 | const char *buf, size_t count) |
| 104 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 105 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 106 | int ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 107 | |
Jingoo Han | b785a49 | 2013-07-19 16:24:59 +0900 | [diff] [blame] | 108 | ret = kstrtol(buf, 10, &rtd->pmdown_time); |
Mark Brown | c593b52 | 2010-10-27 20:11:17 -0700 | [diff] [blame] | 109 | if (ret) |
| 110 | return ret; |
Mark Brown | dbe2140 | 2010-02-12 11:37:24 +0000 | [diff] [blame] | 111 | |
| 112 | return count; |
| 113 | } |
| 114 | |
| 115 | static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); |
| 116 | |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 117 | static struct attribute *soc_dev_attrs[] = { |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 118 | &dev_attr_pmdown_time.attr, |
| 119 | NULL |
| 120 | }; |
| 121 | |
| 122 | static umode_t soc_dev_attr_is_visible(struct kobject *kobj, |
| 123 | struct attribute *attr, int idx) |
| 124 | { |
| 125 | struct device *dev = kobj_to_dev(kobj); |
| 126 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
| 127 | |
Kuninori Morimoto | d918a37 | 2019-09-12 13:42:30 +0900 | [diff] [blame] | 128 | if (!rtd) |
| 129 | return 0; |
| 130 | |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 131 | if (attr == &dev_attr_pmdown_time.attr) |
| 132 | return attr->mode; /* always visible */ |
Kuninori Morimoto | 3b6eed8d | 2017-12-05 04:20:42 +0000 | [diff] [blame] | 133 | return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */ |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static const struct attribute_group soc_dapm_dev_group = { |
| 137 | .attrs = soc_dapm_dev_attrs, |
| 138 | .is_visible = soc_dev_attr_is_visible, |
| 139 | }; |
| 140 | |
Mark Brown | f7e73b26 | 2018-03-09 12:46:27 +0000 | [diff] [blame] | 141 | static const struct attribute_group soc_dev_group = { |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 142 | .attrs = soc_dev_attrs, |
| 143 | .is_visible = soc_dev_attr_is_visible, |
| 144 | }; |
| 145 | |
| 146 | static const struct attribute_group *soc_dev_attr_groups[] = { |
| 147 | &soc_dapm_dev_group, |
Mark Brown | f7e73b26 | 2018-03-09 12:46:27 +0000 | [diff] [blame] | 148 | &soc_dev_group, |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 149 | NULL |
| 150 | }; |
| 151 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 152 | #ifdef CONFIG_DEBUG_FS |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 153 | static void soc_init_component_debugfs(struct snd_soc_component *component) |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 154 | { |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 155 | if (!component->card->debugfs_card_root) |
| 156 | return; |
| 157 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 158 | if (component->debugfs_prefix) { |
| 159 | char *name; |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 160 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 161 | name = kasprintf(GFP_KERNEL, "%s:%s", |
| 162 | component->debugfs_prefix, component->name); |
| 163 | if (name) { |
| 164 | component->debugfs_root = debugfs_create_dir(name, |
| 165 | component->card->debugfs_card_root); |
| 166 | kfree(name); |
| 167 | } |
| 168 | } else { |
| 169 | component->debugfs_root = debugfs_create_dir(component->name, |
| 170 | component->card->debugfs_card_root); |
| 171 | } |
Russell King | e73f3de | 2014-06-26 15:22:50 +0100 | [diff] [blame] | 172 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 173 | snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component), |
| 174 | component->debugfs_root); |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void soc_cleanup_component_debugfs(struct snd_soc_component *component) |
| 178 | { |
Kuninori Morimoto | ad64bfb | 2019-08-07 10:30:13 +0900 | [diff] [blame] | 179 | if (!component->debugfs_root) |
| 180 | return; |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 181 | debugfs_remove_recursive(component->debugfs_root); |
Kuninori Morimoto | ad64bfb | 2019-08-07 10:30:13 +0900 | [diff] [blame] | 182 | component->debugfs_root = NULL; |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Peng Donglin | c15b2a1 | 2018-02-14 22:48:07 +0800 | [diff] [blame] | 185 | static int dai_list_show(struct seq_file *m, void *v) |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 186 | { |
Lars-Peter Clausen | 1438c2f | 2014-03-09 17:41:47 +0100 | [diff] [blame] | 187 | struct snd_soc_component *component; |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 188 | struct snd_soc_dai *dai; |
| 189 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 190 | mutex_lock(&client_mutex); |
| 191 | |
Kuninori Morimoto | 368dee9 | 2018-09-21 05:23:01 +0000 | [diff] [blame] | 192 | for_each_component(component) |
Kuninori Morimoto | 15a0c64 | 2018-09-21 05:23:17 +0000 | [diff] [blame] | 193 | for_each_component_dais(component, dai) |
Donglin Peng | 700c17c | 2018-01-18 13:31:26 +0800 | [diff] [blame] | 194 | seq_printf(m, "%s\n", dai->name); |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 195 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 196 | mutex_unlock(&client_mutex); |
| 197 | |
Donglin Peng | 700c17c | 2018-01-18 13:31:26 +0800 | [diff] [blame] | 198 | return 0; |
| 199 | } |
Peng Donglin | c15b2a1 | 2018-02-14 22:48:07 +0800 | [diff] [blame] | 200 | DEFINE_SHOW_ATTRIBUTE(dai_list); |
Mark Brown | f320878 | 2010-09-15 18:19:07 +0100 | [diff] [blame] | 201 | |
Kuninori Morimoto | db795f9 | 2018-05-08 03:21:00 +0000 | [diff] [blame] | 202 | static int component_list_show(struct seq_file *m, void *v) |
| 203 | { |
| 204 | struct snd_soc_component *component; |
| 205 | |
| 206 | mutex_lock(&client_mutex); |
| 207 | |
Kuninori Morimoto | 368dee9 | 2018-09-21 05:23:01 +0000 | [diff] [blame] | 208 | for_each_component(component) |
Kuninori Morimoto | db795f9 | 2018-05-08 03:21:00 +0000 | [diff] [blame] | 209 | seq_printf(m, "%s\n", component->name); |
| 210 | |
| 211 | mutex_unlock(&client_mutex); |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | DEFINE_SHOW_ATTRIBUTE(component_list); |
| 216 | |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 217 | static void soc_init_card_debugfs(struct snd_soc_card *card) |
| 218 | { |
| 219 | card->debugfs_card_root = debugfs_create_dir(card->name, |
Mark Brown | 8a9dab1 | 2011-01-10 22:25:21 +0000 | [diff] [blame] | 220 | snd_soc_debugfs_root); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 221 | |
Greg Kroah-Hartman | fee531d | 2019-07-31 15:17:15 +0200 | [diff] [blame] | 222 | debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root, |
| 223 | &card->pop_time); |
Kuninori Morimoto | d8ca7a0 | 2019-08-07 10:31:14 +0900 | [diff] [blame] | 224 | |
| 225 | snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 229 | { |
| 230 | debugfs_remove_recursive(card->debugfs_card_root); |
Kuninori Morimoto | 29040d1 | 2019-05-27 16:51:34 +0900 | [diff] [blame] | 231 | card->debugfs_card_root = NULL; |
Jarkko Nikula | a605215 | 2010-11-05 20:35:19 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 234 | static void snd_soc_debugfs_init(void) |
| 235 | { |
| 236 | snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL); |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 237 | |
Greg Kroah-Hartman | fee531d | 2019-07-31 15:17:15 +0200 | [diff] [blame] | 238 | debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL, |
| 239 | &dai_list_fops); |
Kuninori Morimoto | db795f9 | 2018-05-08 03:21:00 +0000 | [diff] [blame] | 240 | |
Greg Kroah-Hartman | fee531d | 2019-07-31 15:17:15 +0200 | [diff] [blame] | 241 | debugfs_create_file("components", 0444, snd_soc_debugfs_root, NULL, |
| 242 | &component_list_fops); |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static void snd_soc_debugfs_exit(void) |
| 246 | { |
| 247 | debugfs_remove_recursive(snd_soc_debugfs_root); |
| 248 | } |
| 249 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 250 | #else |
| 251 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 252 | static inline void soc_init_component_debugfs( |
| 253 | struct snd_soc_component *component) |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 254 | { |
| 255 | } |
| 256 | |
Lars-Peter Clausen | 81c7cfd | 2014-08-19 15:51:18 +0200 | [diff] [blame] | 257 | static inline void soc_cleanup_component_debugfs( |
| 258 | struct snd_soc_component *component) |
Sebastien Guiriec | 731f1ab | 2012-02-15 15:25:31 +0000 | [diff] [blame] | 259 | { |
| 260 | } |
| 261 | |
Axel Lin | b95fccb | 2010-11-09 17:06:44 +0800 | [diff] [blame] | 262 | static inline void soc_init_card_debugfs(struct snd_soc_card *card) |
| 263 | { |
| 264 | } |
| 265 | |
| 266 | static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) |
| 267 | { |
| 268 | } |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 269 | |
| 270 | static inline void snd_soc_debugfs_init(void) |
| 271 | { |
| 272 | } |
| 273 | |
| 274 | static inline void snd_soc_debugfs_exit(void) |
| 275 | { |
| 276 | } |
| 277 | |
Mark Brown | 2624d5f | 2009-11-03 21:56:13 +0000 | [diff] [blame] | 278 | #endif |
| 279 | |
Kuninori Morimoto | 8ec241c | 2019-10-02 14:31:06 +0900 | [diff] [blame] | 280 | /* |
| 281 | * This is glue code between snd_pcm_lib_ioctl() and |
| 282 | * snd_soc_component_driver :: ioctl |
| 283 | */ |
| 284 | int snd_soc_pcm_lib_ioctl(struct snd_soc_component *component, |
| 285 | struct snd_pcm_substream *substream, |
| 286 | unsigned int cmd, void *arg) |
| 287 | { |
| 288 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 289 | } |
| 290 | EXPORT_SYMBOL_GPL(snd_soc_pcm_lib_ioctl); |
| 291 | |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 292 | static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd, |
| 293 | struct snd_soc_component *component) |
| 294 | { |
| 295 | struct snd_soc_rtdcom_list *rtdcom; |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 296 | struct snd_soc_component *comp; |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 297 | |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 298 | for_each_rtd_components(rtd, rtdcom, comp) { |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 299 | /* already connected */ |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 300 | if (comp == component) |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
Kuninori Morimoto | 353e16bf | 2019-09-12 13:42:44 +0900 | [diff] [blame] | 304 | /* |
| 305 | * created rtdcom here will be freed when rtd->dev was freed. |
| 306 | * see |
| 307 | * soc_free_pcm_runtime() :: device_unregister(rtd->dev) |
| 308 | */ |
| 309 | rtdcom = devm_kzalloc(rtd->dev, sizeof(*rtdcom), GFP_KERNEL); |
Kuninori Morimoto | 32d2c17 | 2019-08-07 10:30:47 +0900 | [diff] [blame] | 310 | if (!rtdcom) |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 311 | return -ENOMEM; |
| 312 | |
Kuninori Morimoto | 32d2c17 | 2019-08-07 10:30:47 +0900 | [diff] [blame] | 313 | rtdcom->component = component; |
| 314 | INIT_LIST_HEAD(&rtdcom->list); |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 315 | |
Kuninori Morimoto | 353e16bf | 2019-09-12 13:42:44 +0900 | [diff] [blame] | 316 | /* |
| 317 | * When rtd was freed, created rtdcom here will be |
| 318 | * also freed. |
| 319 | * And we don't need to call list_del(&rtdcom->list) |
| 320 | * when freed, because rtd is also freed. |
| 321 | */ |
Kuninori Morimoto | 32d2c17 | 2019-08-07 10:30:47 +0900 | [diff] [blame] | 322 | list_add_tail(&rtdcom->list, &rtd->component_list); |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 327 | struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd, |
| 328 | const char *driver_name) |
| 329 | { |
| 330 | struct snd_soc_rtdcom_list *rtdcom; |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 331 | struct snd_soc_component *component; |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 332 | |
Kuninori Morimoto | 971da24 | 2018-01-23 00:41:24 +0000 | [diff] [blame] | 333 | if (!driver_name) |
| 334 | return NULL; |
| 335 | |
Kuninori Morimoto | a33c0d1 | 2019-08-20 14:05:02 +0900 | [diff] [blame] | 336 | /* |
| 337 | * NOTE |
| 338 | * |
| 339 | * snd_soc_rtdcom_lookup() will find component from rtd by using |
| 340 | * specified driver name. |
| 341 | * But, if many components which have same driver name are connected |
| 342 | * to 1 rtd, this function will return 1st found component. |
| 343 | */ |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 344 | for_each_rtd_components(rtd, rtdcom, component) { |
| 345 | const char *component_name = component->driver->name; |
Kuninori Morimoto | 971da24 | 2018-01-23 00:41:24 +0000 | [diff] [blame] | 346 | |
| 347 | if (!component_name) |
| 348 | continue; |
| 349 | |
| 350 | if ((component_name == driver_name) || |
| 351 | strcmp(component_name, driver_name) == 0) |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 352 | return rtdcom->component; |
| 353 | } |
| 354 | |
| 355 | return NULL; |
| 356 | } |
Kuninori Morimoto | 031734b | 2018-01-18 01:13:54 +0000 | [diff] [blame] | 357 | EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup); |
Kuninori Morimoto | a0ac441 | 2017-08-08 06:17:47 +0000 | [diff] [blame] | 358 | |
Kuninori Morimoto | 18dd66e | 2019-11-06 16:05:05 +0900 | [diff] [blame] | 359 | static struct snd_soc_component |
| 360 | *snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name) |
Kuninori Morimoto | b813265 | 2019-11-05 15:46:30 +0900 | [diff] [blame] | 361 | { |
| 362 | struct snd_soc_component *component; |
Kuninori Morimoto | 5bd7e08 | 2019-11-05 15:46:35 +0900 | [diff] [blame] | 363 | struct snd_soc_component *found_component; |
Kuninori Morimoto | b813265 | 2019-11-05 15:46:30 +0900 | [diff] [blame] | 364 | |
Kuninori Morimoto | 5bd7e08 | 2019-11-05 15:46:35 +0900 | [diff] [blame] | 365 | found_component = NULL; |
Kuninori Morimoto | b813265 | 2019-11-05 15:46:30 +0900 | [diff] [blame] | 366 | for_each_component(component) { |
Kuninori Morimoto | 5bd7e08 | 2019-11-05 15:46:35 +0900 | [diff] [blame] | 367 | if ((dev == component->dev) && |
| 368 | (!driver_name || |
| 369 | (driver_name == component->driver->name) || |
| 370 | (strcmp(component->driver->name, driver_name) == 0))) { |
| 371 | found_component = component; |
| 372 | break; |
| 373 | } |
Kuninori Morimoto | b813265 | 2019-11-05 15:46:30 +0900 | [diff] [blame] | 374 | } |
Kuninori Morimoto | b813265 | 2019-11-05 15:46:30 +0900 | [diff] [blame] | 375 | |
Kuninori Morimoto | 5bd7e08 | 2019-11-05 15:46:35 +0900 | [diff] [blame] | 376 | return found_component; |
Kuninori Morimoto | b813265 | 2019-11-05 15:46:30 +0900 | [diff] [blame] | 377 | } |
Kuninori Morimoto | 18dd66e | 2019-11-06 16:05:05 +0900 | [diff] [blame] | 378 | |
| 379 | struct snd_soc_component *snd_soc_lookup_component(struct device *dev, |
| 380 | const char *driver_name) |
| 381 | { |
| 382 | struct snd_soc_component *component; |
| 383 | |
| 384 | mutex_lock(&client_mutex); |
| 385 | component = snd_soc_lookup_component_nolocked(dev, driver_name); |
| 386 | mutex_unlock(&client_mutex); |
| 387 | |
| 388 | return component; |
| 389 | } |
Kuninori Morimoto | b813265 | 2019-11-05 15:46:30 +0900 | [diff] [blame] | 390 | EXPORT_SYMBOL_GPL(snd_soc_lookup_component); |
| 391 | |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 392 | struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card, |
| 393 | const char *dai_link, int stream) |
| 394 | { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 395 | struct snd_soc_pcm_runtime *rtd; |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 396 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 397 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 398 | if (rtd->dai_link->no_pcm && |
| 399 | !strcmp(rtd->dai_link->name, dai_link)) |
| 400 | return rtd->pcm->streams[stream].substream; |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 401 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 402 | 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] | 403 | return NULL; |
| 404 | } |
| 405 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); |
| 406 | |
Kuninori Morimoto | 75ab9eb | 2017-09-26 00:40:42 +0000 | [diff] [blame] | 407 | static const struct snd_soc_ops null_snd_soc_ops; |
| 408 | |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 409 | static void soc_release_rtd_dev(struct device *dev) |
| 410 | { |
| 411 | /* "dev" means "rtd->dev" */ |
| 412 | kfree(dev); |
| 413 | } |
| 414 | |
Kuninori Morimoto | 1c93a9e | 2019-09-12 13:38:22 +0900 | [diff] [blame] | 415 | static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd) |
| 416 | { |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 417 | if (!rtd) |
| 418 | return; |
| 419 | |
Kuninori Morimoto | 753ace0 | 2019-09-12 13:38:50 +0900 | [diff] [blame] | 420 | list_del(&rtd->list); |
Kuninori Morimoto | b7c5bc4 | 2019-09-12 13:41:01 +0900 | [diff] [blame] | 421 | |
| 422 | /* |
| 423 | * we don't need to call kfree() for rtd->dev |
| 424 | * see |
| 425 | * soc_release_rtd_dev() |
Kuninori Morimoto | d918a37 | 2019-09-12 13:42:30 +0900 | [diff] [blame] | 426 | * |
| 427 | * We don't need rtd->dev NULL check, because |
| 428 | * it is alloced *before* rtd. |
| 429 | * see |
| 430 | * soc_new_pcm_runtime() |
Kuninori Morimoto | b7c5bc4 | 2019-09-12 13:41:01 +0900 | [diff] [blame] | 431 | */ |
Kuninori Morimoto | d918a37 | 2019-09-12 13:42:30 +0900 | [diff] [blame] | 432 | device_unregister(rtd->dev); |
Kuninori Morimoto | 1c93a9e | 2019-09-12 13:38:22 +0900 | [diff] [blame] | 433 | } |
| 434 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 435 | static struct snd_soc_pcm_runtime *soc_new_pcm_runtime( |
| 436 | struct snd_soc_card *card, struct snd_soc_dai_link *dai_link) |
| 437 | { |
| 438 | struct snd_soc_pcm_runtime *rtd; |
Kuninori Morimoto | d918a37 | 2019-09-12 13:42:30 +0900 | [diff] [blame] | 439 | struct device *dev; |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 440 | int ret; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 441 | |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 442 | /* |
Kuninori Morimoto | d918a37 | 2019-09-12 13:42:30 +0900 | [diff] [blame] | 443 | * for rtd->dev |
| 444 | */ |
| 445 | dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 446 | if (!dev) |
| 447 | return NULL; |
| 448 | |
| 449 | dev->parent = card->dev; |
| 450 | dev->release = soc_release_rtd_dev; |
| 451 | dev->groups = soc_dev_attr_groups; |
| 452 | |
| 453 | dev_set_name(dev, "%s", dai_link->name); |
| 454 | |
| 455 | ret = device_register(dev); |
| 456 | if (ret < 0) { |
| 457 | put_device(dev); /* soc_release_rtd_dev */ |
| 458 | return NULL; |
| 459 | } |
| 460 | |
| 461 | /* |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 462 | * for rtd |
| 463 | */ |
Kuninori Morimoto | 4dc0e7d | 2019-10-02 14:22:32 +0900 | [diff] [blame] | 464 | rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL); |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 465 | if (!rtd) |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 466 | goto free_rtd; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 467 | |
Kuninori Morimoto | d918a37 | 2019-09-12 13:42:30 +0900 | [diff] [blame] | 468 | rtd->dev = dev; |
| 469 | dev_set_drvdata(dev, rtd); |
| 470 | |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 471 | /* |
| 472 | * for rtd->codec_dais |
| 473 | */ |
Kuninori Morimoto | 4dc0e7d | 2019-10-02 14:22:32 +0900 | [diff] [blame] | 474 | rtd->codec_dais = devm_kcalloc(dev, dai_link->num_codecs, |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 475 | sizeof(struct snd_soc_dai *), |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 476 | GFP_KERNEL); |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 477 | if (!rtd->codec_dais) |
| 478 | goto free_rtd; |
| 479 | |
| 480 | /* |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 481 | * rtd remaining settings |
| 482 | */ |
Kuninori Morimoto | 929deb8 | 2019-09-12 13:39:32 +0900 | [diff] [blame] | 483 | INIT_LIST_HEAD(&rtd->component_list); |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 484 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients); |
| 485 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients); |
| 486 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients); |
| 487 | INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients); |
| 488 | |
Kuninori Morimoto | 929deb8 | 2019-09-12 13:39:32 +0900 | [diff] [blame] | 489 | rtd->card = card; |
| 490 | rtd->dai_link = dai_link; |
| 491 | if (!rtd->dai_link->ops) |
| 492 | rtd->dai_link->ops = &null_snd_soc_ops; |
| 493 | |
Kuninori Morimoto | 6634e3d | 2019-08-07 10:30:31 +0900 | [diff] [blame] | 494 | /* see for_each_card_rtds */ |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 495 | list_add_tail(&rtd->list, &card->rtd_list); |
| 496 | rtd->num = card->num_rtd; |
| 497 | card->num_rtd++; |
Kuninori Morimoto | a848125 | 2019-09-12 13:38:34 +0900 | [diff] [blame] | 498 | |
| 499 | return rtd; |
Kuninori Morimoto | 6e86434 | 2019-09-12 13:40:08 +0900 | [diff] [blame] | 500 | |
| 501 | free_rtd: |
| 502 | soc_free_pcm_runtime(rtd); |
| 503 | return NULL; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 504 | } |
| 505 | |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 506 | struct snd_soc_pcm_runtime *snd_soc_get_pcm_runtime(struct snd_soc_card *card, |
| 507 | const char *dai_link) |
| 508 | { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 509 | struct snd_soc_pcm_runtime *rtd; |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 510 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 511 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 512 | if (!strcmp(rtd->dai_link->name, dai_link)) |
| 513 | return rtd; |
Liam Girdwood | 47c88ff | 2012-04-25 12:12:53 +0100 | [diff] [blame] | 514 | } |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 515 | 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] | 516 | return NULL; |
| 517 | } |
| 518 | EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); |
| 519 | |
Kuninori Morimoto | 65462e44 | 2019-01-21 09:32:37 +0900 | [diff] [blame] | 520 | static void snd_soc_flush_all_delayed_work(struct snd_soc_card *card) |
| 521 | { |
| 522 | struct snd_soc_pcm_runtime *rtd; |
| 523 | |
| 524 | for_each_card_rtds(card, rtd) |
| 525 | flush_delayed_work(&rtd->delayed_work); |
| 526 | } |
| 527 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 528 | #ifdef CONFIG_PM_SLEEP |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 529 | /* powers down audio subsystem for suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 530 | int snd_soc_suspend(struct device *dev) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 531 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 532 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 533 | struct snd_soc_component *component; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 534 | struct snd_soc_pcm_runtime *rtd; |
| 535 | int i; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 536 | |
Lars-Peter Clausen | c5599b8 | 2014-08-19 15:51:30 +0200 | [diff] [blame] | 537 | /* If the card is not initialized yet there is nothing to do */ |
| 538 | if (!card->instantiated) |
Daniel Mack | e3509ff | 2009-06-03 17:44:49 +0200 | [diff] [blame] | 539 | return 0; |
| 540 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 541 | /* |
| 542 | * Due to the resume being scheduled into a workqueue we could |
| 543 | * suspend before that's finished - wait for it to complete. |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 544 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 545 | snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 546 | |
| 547 | /* we're going to block userspace touching us until resume completes */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 548 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 549 | |
Mark Brown | a00f90f | 2010-12-02 16:24:24 +0000 | [diff] [blame] | 550 | /* mute any active DACs */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 551 | for_each_card_rtds(card, rtd) { |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 552 | struct snd_soc_dai *dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 553 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 554 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 555 | continue; |
| 556 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 557 | for_each_rtd_codec_dai(rtd, i, dai) { |
Kuninori Morimoto | 88fdffa | 2019-07-22 10:36:27 +0900 | [diff] [blame] | 558 | if (dai->playback_active) |
| 559 | snd_soc_dai_digital_mute(dai, 1, |
| 560 | SNDRV_PCM_STREAM_PLAYBACK); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 561 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 564 | /* suspend all pcms */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 565 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 566 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 567 | continue; |
| 568 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 569 | snd_pcm_suspend_all(rtd->pcm); |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 570 | } |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 571 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 572 | if (card->suspend_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 573 | card->suspend_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 574 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 575 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 576 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 577 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 578 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 579 | continue; |
| 580 | |
Kuninori Morimoto | e0f2262 | 2019-07-22 10:34:29 +0900 | [diff] [blame] | 581 | if (!cpu_dai->driver->bus_control) |
| 582 | snd_soc_dai_suspend(cpu_dai); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 583 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 584 | |
Lars-Peter Clausen | 37660b6 | 2015-03-30 21:04:50 +0200 | [diff] [blame] | 585 | /* close any waiting streams */ |
Kuninori Morimoto | 65462e44 | 2019-01-21 09:32:37 +0900 | [diff] [blame] | 586 | snd_soc_flush_all_delayed_work(card); |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 587 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 588 | for_each_card_rtds(card, rtd) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 589 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 590 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 591 | continue; |
| 592 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 593 | snd_soc_dapm_stream_event(rtd, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 594 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 595 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 596 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 597 | snd_soc_dapm_stream_event(rtd, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 598 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 599 | SND_SOC_DAPM_STREAM_SUSPEND); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 600 | } |
| 601 | |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 602 | /* Recheck all endpoints too, their state is affected by suspend */ |
| 603 | dapm_mark_endpoints_dirty(card); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 604 | snd_soc_dapm_sync(&card->dapm); |
| 605 | |
Kuninori Morimoto | 9178feb | 2016-11-30 06:23:13 +0000 | [diff] [blame] | 606 | /* suspend all COMPONENTs */ |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 607 | for_each_card_components(card, component) { |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 608 | struct snd_soc_dapm_context *dapm = |
| 609 | snd_soc_component_get_dapm(component); |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 610 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 611 | /* |
| 612 | * If there are paths active then the COMPONENT will be held |
| 613 | * with bias _ON and should not be suspended. |
| 614 | */ |
Kuninori Morimoto | e40fadb | 2019-07-26 13:51:13 +0900 | [diff] [blame] | 615 | if (!snd_soc_component_is_suspended(component)) { |
Lars-Peter Clausen | 4890140 | 2015-07-06 15:38:11 +0200 | [diff] [blame] | 616 | switch (snd_soc_dapm_get_bias_level(dapm)) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 617 | case SND_SOC_BIAS_STANDBY: |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 618 | /* |
Kuninori Morimoto | 9178feb | 2016-11-30 06:23:13 +0000 | [diff] [blame] | 619 | * If the COMPONENT is capable of idle |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 620 | * bias off then being in STANDBY |
| 621 | * means it's doing something, |
| 622 | * otherwise fall through. |
| 623 | */ |
Lars-Peter Clausen | 4890140 | 2015-07-06 15:38:11 +0200 | [diff] [blame] | 624 | if (dapm->idle_bias_off) { |
Kuninori Morimoto | 9178feb | 2016-11-30 06:23:13 +0000 | [diff] [blame] | 625 | dev_dbg(component->dev, |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 626 | "ASoC: idle_bias_off CODEC on over suspend\n"); |
Mark Brown | 125a25d | 2012-01-31 15:49:10 +0000 | [diff] [blame] | 627 | break; |
| 628 | } |
Gustavo A. R. Silva | 1a12d5d | 2018-08-03 11:34:30 -0500 | [diff] [blame] | 629 | /* fall through */ |
Lars-Peter Clausen | a809329 | 2014-09-04 19:44:07 +0200 | [diff] [blame] | 630 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 631 | case SND_SOC_BIAS_OFF: |
Kuninori Morimoto | 66c5157 | 2019-07-26 13:50:34 +0900 | [diff] [blame] | 632 | snd_soc_component_suspend(component); |
Kuninori Morimoto | 9178feb | 2016-11-30 06:23:13 +0000 | [diff] [blame] | 633 | if (component->regmap) |
| 634 | regcache_mark_dirty(component->regmap); |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 635 | /* deactivate pins to sleep state */ |
Kuninori Morimoto | 9178feb | 2016-11-30 06:23:13 +0000 | [diff] [blame] | 636 | pinctrl_pm_select_sleep_state(component->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 637 | break; |
| 638 | default: |
Kuninori Morimoto | 9178feb | 2016-11-30 06:23:13 +0000 | [diff] [blame] | 639 | dev_dbg(component->dev, |
| 640 | "ASoC: COMPONENT is on over suspend\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 641 | break; |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 646 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 647 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 648 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 649 | if (rtd->dai_link->ignore_suspend) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 650 | continue; |
| 651 | |
Kuninori Morimoto | e0f2262 | 2019-07-22 10:34:29 +0900 | [diff] [blame] | 652 | if (cpu_dai->driver->bus_control) |
| 653 | snd_soc_dai_suspend(cpu_dai); |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 654 | |
| 655 | /* deactivate pins to sleep state */ |
| 656 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 657 | } |
| 658 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 659 | if (card->suspend_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 660 | card->suspend_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 661 | |
| 662 | return 0; |
| 663 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 664 | EXPORT_SYMBOL_GPL(snd_soc_suspend); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 665 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 666 | /* |
| 667 | * deferred resume work, so resume can complete before we finished |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 668 | * setting our codec back up, which can be very slow on I2C |
| 669 | */ |
| 670 | static void soc_resume_deferred(struct work_struct *work) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 671 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 672 | struct snd_soc_card *card = |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 673 | container_of(work, struct snd_soc_card, |
| 674 | deferred_resume_work); |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 675 | struct snd_soc_pcm_runtime *rtd; |
Kuninori Morimoto | d9fc406 | 2016-11-30 06:22:36 +0000 | [diff] [blame] | 676 | struct snd_soc_component *component; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 677 | int i; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 678 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 679 | /* |
| 680 | * our power state is still SNDRV_CTL_POWER_D3hot from suspend time, |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 681 | * so userspace apps are blocked from touching us |
| 682 | */ |
| 683 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 684 | dev_dbg(card->dev, "ASoC: starting resume work\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 685 | |
Mark Brown | 9949788b | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 686 | /* Bring us up into D2 so that DAPM starts enabling things */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 687 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); |
Mark Brown | 9949788b | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 688 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 689 | if (card->resume_pre) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 690 | card->resume_pre(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 691 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 692 | /* resume control bus DAIs */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 693 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 694 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 695 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 696 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 697 | continue; |
| 698 | |
Kuninori Morimoto | 24b09d0 | 2019-07-22 10:34:43 +0900 | [diff] [blame] | 699 | if (cpu_dai->driver->bus_control) |
| 700 | snd_soc_dai_resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 701 | } |
| 702 | |
Kuninori Morimoto | f70f18f7 | 2018-09-18 01:29:55 +0000 | [diff] [blame] | 703 | for_each_card_components(card, component) { |
Kuninori Morimoto | e40fadb | 2019-07-26 13:51:13 +0900 | [diff] [blame] | 704 | if (snd_soc_component_is_suspended(component)) |
Kuninori Morimoto | 9a840cb | 2019-07-26 13:51:08 +0900 | [diff] [blame] | 705 | snd_soc_component_resume(component); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 706 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 707 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 708 | for_each_card_rtds(card, rtd) { |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 709 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 710 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 711 | continue; |
| 712 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 713 | snd_soc_dapm_stream_event(rtd, |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 714 | SNDRV_PCM_STREAM_PLAYBACK, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 715 | SND_SOC_DAPM_STREAM_RESUME); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 716 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 717 | snd_soc_dapm_stream_event(rtd, |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 718 | SNDRV_PCM_STREAM_CAPTURE, |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 719 | SND_SOC_DAPM_STREAM_RESUME); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 720 | } |
| 721 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 722 | /* unmute any active DACs */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 723 | for_each_card_rtds(card, rtd) { |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 724 | struct snd_soc_dai *dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 725 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 726 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 727 | continue; |
| 728 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 729 | for_each_rtd_codec_dai(rtd, i, dai) { |
Kuninori Morimoto | 88fdffa | 2019-07-22 10:36:27 +0900 | [diff] [blame] | 730 | if (dai->playback_active) |
| 731 | snd_soc_dai_digital_mute(dai, 0, |
| 732 | SNDRV_PCM_STREAM_PLAYBACK); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 733 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 734 | } |
| 735 | |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 736 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 737 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 738 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 739 | if (rtd->dai_link->ignore_suspend) |
Mark Brown | 3efab7d | 2010-05-09 13:25:43 +0100 | [diff] [blame] | 740 | continue; |
| 741 | |
Kuninori Morimoto | 24b09d0 | 2019-07-22 10:34:43 +0900 | [diff] [blame] | 742 | if (!cpu_dai->driver->bus_control) |
| 743 | snd_soc_dai_resume(cpu_dai); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 744 | } |
| 745 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 746 | if (card->resume_post) |
Mark Brown | 70b2ac1 | 2011-01-26 14:05:25 +0000 | [diff] [blame] | 747 | card->resume_post(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 748 | |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 749 | dev_dbg(card->dev, "ASoC: resume work completed\n"); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 750 | |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 751 | /* Recheck all endpoints too, their state is affected by suspend */ |
| 752 | dapm_mark_endpoints_dirty(card); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 753 | snd_soc_dapm_sync(&card->dapm); |
Jeeja KP | 1a7aaa5 | 2015-11-23 21:22:31 +0530 | [diff] [blame] | 754 | |
| 755 | /* userspace can access us now we are back as we were before */ |
| 756 | snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /* powers up audio subsystem after a suspend */ |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 760 | int snd_soc_resume(struct device *dev) |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 761 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 762 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 763 | bool bus_control = false; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 764 | struct snd_soc_pcm_runtime *rtd; |
Kuninori Morimoto | 22d251a | 2019-05-13 16:06:07 +0900 | [diff] [blame] | 765 | struct snd_soc_dai *codec_dai; |
| 766 | int i; |
Peter Ujfalusi | b9dd94a | 2010-02-22 13:27:13 +0200 | [diff] [blame] | 767 | |
Lars-Peter Clausen | c5599b8 | 2014-08-19 15:51:30 +0200 | [diff] [blame] | 768 | /* If the card is not initialized yet there is nothing to do */ |
| 769 | if (!card->instantiated) |
Eric Miao | 5ff1ddf | 2011-11-23 22:37:00 +0800 | [diff] [blame] | 770 | return 0; |
| 771 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 772 | /* activate pins from sleep state */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 773 | for_each_card_rtds(card, rtd) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 774 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 775 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 776 | if (cpu_dai->active) |
| 777 | pinctrl_pm_select_default_state(cpu_dai->dev); |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 778 | |
Kuninori Morimoto | 22d251a | 2019-05-13 16:06:07 +0900 | [diff] [blame] | 779 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 780 | if (codec_dai->active) |
| 781 | pinctrl_pm_select_default_state(codec_dai->dev); |
| 782 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 783 | } |
| 784 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 785 | /* |
| 786 | * DAIs that also act as the control bus master might have other drivers |
| 787 | * hanging off them so need to resume immediately. Other drivers don't |
| 788 | * have that problem and may take a substantial amount of time to resume |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 789 | * due to I/O costs and anti-pop so handle them out of line. |
| 790 | */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 791 | for_each_card_rtds(card, rtd) { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 792 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 793 | |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 794 | bus_control |= cpu_dai->driver->bus_control; |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 795 | } |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 796 | if (bus_control) { |
| 797 | dev_dbg(dev, "ASoC: Resuming control bus master immediately\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 798 | soc_resume_deferred(&card->deferred_resume_work); |
| 799 | } else { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 800 | dev_dbg(dev, "ASoC: Scheduling resume work\n"); |
Stephen Warren | 82e14e8 | 2011-05-25 14:06:41 -0600 | [diff] [blame] | 801 | if (!schedule_work(&card->deferred_resume_work)) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 802 | dev_err(dev, "ASoC: resume work item may be lost\n"); |
Mark Brown | 64ab9ba | 2009-03-31 11:27:03 +0100 | [diff] [blame] | 803 | } |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 804 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 805 | return 0; |
| 806 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 807 | EXPORT_SYMBOL_GPL(snd_soc_resume); |
Kuninori Morimoto | b3da425 | 2019-08-07 10:31:24 +0900 | [diff] [blame] | 808 | |
| 809 | static void soc_resume_init(struct snd_soc_card *card) |
| 810 | { |
| 811 | /* deferred resume work */ |
| 812 | INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); |
| 813 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 814 | #else |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 815 | #define snd_soc_suspend NULL |
| 816 | #define snd_soc_resume NULL |
Kuninori Morimoto | b3da425 | 2019-08-07 10:31:24 +0900 | [diff] [blame] | 817 | static inline void soc_resume_init(struct snd_soc_card *card) |
| 818 | { |
| 819 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 820 | #endif |
| 821 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 822 | static const struct snd_soc_dai_ops null_dai_ops = { |
Barry Song | 02a06d3 | 2009-10-16 18:13:38 +0800 | [diff] [blame] | 823 | }; |
| 824 | |
Kuninori Morimoto | c083444 | 2019-05-13 16:06:59 +0900 | [diff] [blame] | 825 | static struct device_node |
| 826 | *soc_component_to_node(struct snd_soc_component *component) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 827 | { |
Kuninori Morimoto | c083444 | 2019-05-13 16:06:59 +0900 | [diff] [blame] | 828 | struct device_node *of_node; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 829 | |
Kuninori Morimoto | c083444 | 2019-05-13 16:06:59 +0900 | [diff] [blame] | 830 | of_node = component->dev->of_node; |
| 831 | if (!of_node && component->dev->parent) |
| 832 | of_node = component->dev->parent->of_node; |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 833 | |
Kuninori Morimoto | c083444 | 2019-05-13 16:06:59 +0900 | [diff] [blame] | 834 | return of_node; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 835 | } |
| 836 | |
Kuninori Morimoto | be6ac0a | 2018-09-11 06:51:45 +0000 | [diff] [blame] | 837 | static int snd_soc_is_matching_component( |
| 838 | const struct snd_soc_dai_link_component *dlc, |
| 839 | struct snd_soc_component *component) |
| 840 | { |
| 841 | struct device_node *component_of_node; |
| 842 | |
Kuninori Morimoto | 7d7db5d | 2019-06-20 09:49:17 +0900 | [diff] [blame] | 843 | if (!dlc) |
| 844 | return 0; |
| 845 | |
| 846 | component_of_node = soc_component_to_node(component); |
Kuninori Morimoto | be6ac0a | 2018-09-11 06:51:45 +0000 | [diff] [blame] | 847 | |
| 848 | if (dlc->of_node && component_of_node != dlc->of_node) |
| 849 | return 0; |
| 850 | if (dlc->name && strcmp(component->name, dlc->name)) |
| 851 | return 0; |
| 852 | |
| 853 | return 1; |
| 854 | } |
| 855 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 856 | static struct snd_soc_component *soc_find_component( |
Kuninori Morimoto | c1e230f | 2019-06-20 09:49:27 +0900 | [diff] [blame] | 857 | const struct snd_soc_dai_link_component *dlc) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 858 | { |
| 859 | struct snd_soc_component *component; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 860 | |
| 861 | lockdep_assert_held(&client_mutex); |
| 862 | |
Kuninori Morimoto | e330326 | 2019-06-26 10:40:59 +0900 | [diff] [blame] | 863 | /* |
| 864 | * NOTE |
| 865 | * |
| 866 | * It returns *1st* found component, but some driver |
| 867 | * has few components by same of_node/name |
| 868 | * ex) |
| 869 | * CPU component and generic DMAEngine component |
| 870 | */ |
Kuninori Morimoto | c1e230f | 2019-06-20 09:49:27 +0900 | [diff] [blame] | 871 | for_each_component(component) |
| 872 | if (snd_soc_is_matching_component(dlc, component)) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 873 | return component; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 874 | |
| 875 | return NULL; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 876 | } |
| 877 | |
Mengdong Lin | fbb88b5 | 2016-04-22 12:25:33 +0800 | [diff] [blame] | 878 | /** |
| 879 | * snd_soc_find_dai - Find a registered DAI |
| 880 | * |
Jeffy Chen | 4958471 | 2017-08-22 15:57:21 +0800 | [diff] [blame] | 881 | * @dlc: name of the DAI or the DAI driver and optional component info to match |
Mengdong Lin | fbb88b5 | 2016-04-22 12:25:33 +0800 | [diff] [blame] | 882 | * |
Stephen Boyd | ad61dd3 | 2017-05-08 15:57:50 -0700 | [diff] [blame] | 883 | * This function will search all registered components and their DAIs to |
Mengdong Lin | fbb88b5 | 2016-04-22 12:25:33 +0800 | [diff] [blame] | 884 | * find the DAI of the same name. The component's of_node and name |
| 885 | * should also match if being specified. |
| 886 | * |
| 887 | * Return: pointer of DAI, or NULL if not found. |
| 888 | */ |
Mengdong Lin | 305e902 | 2016-04-19 13:12:25 +0800 | [diff] [blame] | 889 | struct snd_soc_dai *snd_soc_find_dai( |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 890 | const struct snd_soc_dai_link_component *dlc) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 891 | { |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 892 | struct snd_soc_component *component; |
| 893 | struct snd_soc_dai *dai; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 894 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 895 | lockdep_assert_held(&client_mutex); |
| 896 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 897 | /* Find CPU DAI from registered DAIs */ |
Kuninori Morimoto | 368dee9 | 2018-09-21 05:23:01 +0000 | [diff] [blame] | 898 | for_each_component(component) { |
Kuninori Morimoto | be6ac0a | 2018-09-11 06:51:45 +0000 | [diff] [blame] | 899 | if (!snd_soc_is_matching_component(dlc, component)) |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 900 | continue; |
Kuninori Morimoto | 15a0c64 | 2018-09-21 05:23:17 +0000 | [diff] [blame] | 901 | for_each_component_dais(component, dai) { |
Jeffy Chen | 4958471 | 2017-08-22 15:57:21 +0800 | [diff] [blame] | 902 | if (dlc->dai_name && strcmp(dai->name, dlc->dai_name) |
Jeffy Chen | 6a6dafd | 2017-08-24 12:40:17 +0800 | [diff] [blame] | 903 | && (!dai->driver->name |
| 904 | || strcmp(dai->driver->name, dlc->dai_name))) |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 905 | continue; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 906 | |
Lars-Peter Clausen | 14621c7 | 2014-08-19 15:51:27 +0200 | [diff] [blame] | 907 | return dai; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
| 911 | return NULL; |
| 912 | } |
Mengdong Lin | 305e902 | 2016-04-19 13:12:25 +0800 | [diff] [blame] | 913 | EXPORT_SYMBOL_GPL(snd_soc_find_dai); |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 914 | |
Mengdong Lin | 17fb1755 | 2016-11-03 01:04:12 +0800 | [diff] [blame] | 915 | /** |
| 916 | * snd_soc_find_dai_link - Find a DAI link |
| 917 | * |
| 918 | * @card: soc card |
| 919 | * @id: DAI link ID to match |
| 920 | * @name: DAI link name to match, optional |
Charles Keepax | 8abab35 | 2017-01-12 11:38:15 +0000 | [diff] [blame] | 921 | * @stream_name: DAI link stream name to match, optional |
Mengdong Lin | 17fb1755 | 2016-11-03 01:04:12 +0800 | [diff] [blame] | 922 | * |
| 923 | * This function will search all existing DAI links of the soc card to |
| 924 | * find the link of the same ID. Since DAI links may not have their |
| 925 | * unique ID, so name and stream name should also match if being |
| 926 | * specified. |
| 927 | * |
| 928 | * Return: pointer of DAI link, or NULL if not found. |
| 929 | */ |
| 930 | struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card, |
| 931 | int id, const char *name, |
| 932 | const char *stream_name) |
| 933 | { |
Kuninori Morimoto | 4284906 | 2019-08-07 10:30:41 +0900 | [diff] [blame] | 934 | struct snd_soc_dai_link *link; |
Mengdong Lin | 17fb1755 | 2016-11-03 01:04:12 +0800 | [diff] [blame] | 935 | |
| 936 | lockdep_assert_held(&client_mutex); |
| 937 | |
Kuninori Morimoto | 4284906 | 2019-08-07 10:30:41 +0900 | [diff] [blame] | 938 | for_each_card_links(card, link) { |
Mengdong Lin | 17fb1755 | 2016-11-03 01:04:12 +0800 | [diff] [blame] | 939 | if (link->id != id) |
| 940 | continue; |
| 941 | |
| 942 | if (name && (!link->name || strcmp(name, link->name))) |
| 943 | continue; |
| 944 | |
| 945 | if (stream_name && (!link->stream_name |
| 946 | || strcmp(stream_name, link->stream_name))) |
| 947 | continue; |
| 948 | |
| 949 | return link; |
| 950 | } |
| 951 | |
| 952 | return NULL; |
| 953 | } |
| 954 | EXPORT_SYMBOL_GPL(snd_soc_find_dai_link); |
| 955 | |
Kuninori Morimoto | bfce78a | 2019-11-05 15:45:50 +0900 | [diff] [blame] | 956 | static int soc_dai_link_sanity_check(struct snd_soc_card *card, |
| 957 | struct snd_soc_dai_link *link) |
Kuninori Morimoto | 3679490 | 2019-11-05 15:45:41 +0900 | [diff] [blame] | 958 | { |
| 959 | int i; |
| 960 | struct snd_soc_dai_link_component *codec, *platform; |
| 961 | |
| 962 | for_each_link_codecs(link, i, codec) { |
| 963 | /* |
| 964 | * Codec must be specified by 1 of name or OF node, |
| 965 | * not both or neither. |
| 966 | */ |
| 967 | if (!!codec->name == !!codec->of_node) { |
| 968 | dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n", |
| 969 | link->name); |
| 970 | return -EINVAL; |
| 971 | } |
| 972 | |
| 973 | /* Codec DAI name must be specified */ |
| 974 | if (!codec->dai_name) { |
| 975 | dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n", |
| 976 | link->name); |
| 977 | return -EINVAL; |
| 978 | } |
| 979 | |
| 980 | /* |
| 981 | * Defer card registration if codec component is not added to |
| 982 | * component list. |
| 983 | */ |
| 984 | if (!soc_find_component(codec)) |
| 985 | return -EPROBE_DEFER; |
| 986 | } |
| 987 | |
| 988 | for_each_link_platforms(link, i, platform) { |
| 989 | /* |
| 990 | * Platform may be specified by either name or OF node, but it |
| 991 | * can be left unspecified, then no components will be inserted |
| 992 | * in the rtdcom list |
| 993 | */ |
| 994 | if (!!platform->name == !!platform->of_node) { |
| 995 | dev_err(card->dev, |
| 996 | "ASoC: Neither/both platform name/of_node are set for %s\n", |
| 997 | link->name); |
| 998 | return -EINVAL; |
| 999 | } |
| 1000 | |
| 1001 | /* |
| 1002 | * Defer card registration if platform component is not added to |
| 1003 | * component list. |
| 1004 | */ |
| 1005 | if (!soc_find_component(platform)) |
| 1006 | return -EPROBE_DEFER; |
| 1007 | } |
| 1008 | |
| 1009 | /* FIXME */ |
| 1010 | if (link->num_cpus > 1) { |
| 1011 | dev_err(card->dev, |
| 1012 | "ASoC: multi cpu is not yet supported %s\n", |
| 1013 | link->name); |
| 1014 | return -EINVAL; |
| 1015 | } |
| 1016 | |
| 1017 | /* |
| 1018 | * CPU device may be specified by either name or OF node, but |
| 1019 | * can be left unspecified, and will be matched based on DAI |
| 1020 | * name alone.. |
| 1021 | */ |
| 1022 | if (link->cpus->name && link->cpus->of_node) { |
| 1023 | dev_err(card->dev, |
| 1024 | "ASoC: Neither/both cpu name/of_node are set for %s\n", |
| 1025 | link->name); |
| 1026 | return -EINVAL; |
| 1027 | } |
| 1028 | |
| 1029 | /* |
Kuninori Morimoto | cd3c5ad | 2019-11-05 15:46:00 +0900 | [diff] [blame] | 1030 | * Defer card registration if cpu dai component is not added to |
Kuninori Morimoto | 3679490 | 2019-11-05 15:45:41 +0900 | [diff] [blame] | 1031 | * component list. |
| 1032 | */ |
| 1033 | if ((link->cpus->of_node || link->cpus->name) && |
| 1034 | !soc_find_component(link->cpus)) |
| 1035 | return -EPROBE_DEFER; |
| 1036 | |
| 1037 | /* |
| 1038 | * At least one of CPU DAI name or CPU device name/node must be |
| 1039 | * specified |
| 1040 | */ |
| 1041 | if (!link->cpus->dai_name && |
| 1042 | !(link->cpus->name || link->cpus->of_node)) { |
| 1043 | dev_err(card->dev, |
| 1044 | "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n", |
| 1045 | link->name); |
| 1046 | return -EINVAL; |
| 1047 | } |
| 1048 | |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
Kuninori Morimoto | da704f2 | 2019-11-06 10:07:38 +0900 | [diff] [blame] | 1052 | /** |
| 1053 | * snd_soc_remove_dai_link - Remove a DAI link from the list |
| 1054 | * @card: The ASoC card that owns the link |
| 1055 | * @dai_link: The DAI link to remove |
| 1056 | * |
| 1057 | * This function removes a DAI link from the ASoC card's link list. |
| 1058 | * |
| 1059 | * For DAI links previously added by topology, topology should |
| 1060 | * remove them by using the dobj embedded in the link. |
| 1061 | */ |
| 1062 | void snd_soc_remove_dai_link(struct snd_soc_card *card, |
| 1063 | struct snd_soc_dai_link *dai_link) |
Kuninori Morimoto | bc7a909 | 2019-11-05 15:46:25 +0900 | [diff] [blame] | 1064 | { |
| 1065 | struct snd_soc_pcm_runtime *rtd; |
| 1066 | |
Kuninori Morimoto | da704f2 | 2019-11-06 10:07:38 +0900 | [diff] [blame] | 1067 | lockdep_assert_held(&client_mutex); |
| 1068 | |
| 1069 | /* |
| 1070 | * Notify the machine driver for extra destruction |
| 1071 | */ |
| 1072 | if (card->remove_dai_link) |
| 1073 | card->remove_dai_link(card, dai_link); |
| 1074 | |
| 1075 | list_del(&dai_link->list); |
| 1076 | |
Kuninori Morimoto | bc7a909 | 2019-11-05 15:46:25 +0900 | [diff] [blame] | 1077 | rtd = snd_soc_get_pcm_runtime(card, dai_link->name); |
| 1078 | if (rtd) |
| 1079 | soc_free_pcm_runtime(rtd); |
| 1080 | } |
Kuninori Morimoto | da704f2 | 2019-11-06 10:07:38 +0900 | [diff] [blame] | 1081 | EXPORT_SYMBOL_GPL(snd_soc_remove_dai_link); |
Kuninori Morimoto | bc7a909 | 2019-11-05 15:46:25 +0900 | [diff] [blame] | 1082 | |
Kuninori Morimoto | 63dc47d | 2019-11-06 10:07:31 +0900 | [diff] [blame] | 1083 | /** |
| 1084 | * snd_soc_add_dai_link - Add a DAI link dynamically |
| 1085 | * @card: The ASoC card to which the DAI link is added |
| 1086 | * @dai_link: The new DAI link to add |
| 1087 | * |
| 1088 | * This function adds a DAI link to the ASoC card's link list. |
| 1089 | * |
| 1090 | * Note: Topology can use this API to add DAI links when probing the |
| 1091 | * topology component. And machine drivers can still define static |
| 1092 | * DAI links in dai_link array. |
| 1093 | */ |
| 1094 | int snd_soc_add_dai_link(struct snd_soc_card *card, |
| 1095 | struct snd_soc_dai_link *dai_link) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1096 | { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 1097 | struct snd_soc_pcm_runtime *rtd; |
Jerome Brunet | 3461473 | 2019-06-27 14:13:50 +0200 | [diff] [blame] | 1098 | struct snd_soc_dai_link_component *codec, *platform; |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 1099 | struct snd_soc_component *component; |
Kuninori Morimoto | bfce78a | 2019-11-05 15:45:50 +0900 | [diff] [blame] | 1100 | int i, ret; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 1101 | |
Kuninori Morimoto | 63dc47d | 2019-11-06 10:07:31 +0900 | [diff] [blame] | 1102 | lockdep_assert_held(&client_mutex); |
| 1103 | |
| 1104 | /* |
| 1105 | * Notify the machine driver for extra initialization |
| 1106 | */ |
| 1107 | if (card->add_dai_link) |
| 1108 | card->add_dai_link(card, dai_link); |
| 1109 | |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1110 | if (dai_link->ignore) |
| 1111 | return 0; |
| 1112 | |
Mengdong Lin | 6f2f1ff | 2015-11-23 11:03:52 -0500 | [diff] [blame] | 1113 | dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name); |
Mark Brown | 6308419 | 2008-12-02 15:08:03 +0000 | [diff] [blame] | 1114 | |
Kuninori Morimoto | bfce78a | 2019-11-05 15:45:50 +0900 | [diff] [blame] | 1115 | ret = soc_dai_link_sanity_check(card, dai_link); |
| 1116 | if (ret < 0) |
| 1117 | return ret; |
| 1118 | |
Sudip Mukherjee | 513cb311 | 2016-02-22 14:14:31 +0530 | [diff] [blame] | 1119 | rtd = soc_new_pcm_runtime(card, dai_link); |
| 1120 | if (!rtd) |
| 1121 | return -ENOMEM; |
| 1122 | |
Kuninori Morimoto | 08a5841 | 2019-06-06 13:07:22 +0900 | [diff] [blame] | 1123 | /* FIXME: we need multi CPU support in the future */ |
| 1124 | rtd->cpu_dai = snd_soc_find_dai(dai_link->cpus); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1125 | if (!rtd->cpu_dai) { |
Martin Hundebøll | 6b49087 | 2018-02-01 11:09:41 +0100 | [diff] [blame] | 1126 | dev_info(card->dev, "ASoC: CPU DAI %s not registered\n", |
Kuninori Morimoto | 08a5841 | 2019-06-06 13:07:22 +0900 | [diff] [blame] | 1127 | dai_link->cpus->dai_name); |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 1128 | goto _err_defer; |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1129 | } |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 1130 | snd_soc_rtdcom_add(rtd, rtd->cpu_dai->component); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 1131 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1132 | /* Find CODEC from registered CODECs */ |
Kuninori Morimoto | e2b30ed | 2019-05-13 16:06:44 +0900 | [diff] [blame] | 1133 | rtd->num_codecs = dai_link->num_codecs; |
Jerome Brunet | 3461473 | 2019-06-27 14:13:50 +0200 | [diff] [blame] | 1134 | for_each_link_codecs(dai_link, i, codec) { |
| 1135 | rtd->codec_dais[i] = snd_soc_find_dai(codec); |
Kuninori Morimoto | 0a2cfcd | 2019-05-13 16:06:30 +0900 | [diff] [blame] | 1136 | if (!rtd->codec_dais[i]) { |
Stefan Agner | 7c7e2d6 | 2019-01-18 10:55:04 +0100 | [diff] [blame] | 1137 | dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n", |
Jerome Brunet | 3461473 | 2019-06-27 14:13:50 +0200 | [diff] [blame] | 1138 | codec->dai_name); |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 1139 | goto _err_defer; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1140 | } |
Jerome Brunet | 3461473 | 2019-06-27 14:13:50 +0200 | [diff] [blame] | 1141 | |
Kuninori Morimoto | 0a2cfcd | 2019-05-13 16:06:30 +0900 | [diff] [blame] | 1142 | snd_soc_rtdcom_add(rtd, rtd->codec_dais[i]->component); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1143 | } |
Mark Brown | 848dd8b | 2011-04-27 18:16:32 +0100 | [diff] [blame] | 1144 | |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 1145 | /* Single codec links expect codec and codec_dai in runtime data */ |
Kuninori Morimoto | 0a2cfcd | 2019-05-13 16:06:30 +0900 | [diff] [blame] | 1146 | rtd->codec_dai = rtd->codec_dais[0]; |
Misael Lopez Cruz | 12023a9 | 2014-03-21 16:27:25 +0100 | [diff] [blame] | 1147 | |
Kuninori Morimoto | e2b30ed | 2019-05-13 16:06:44 +0900 | [diff] [blame] | 1148 | /* Find PLATFORM from registered PLATFORMs */ |
Jerome Brunet | 3461473 | 2019-06-27 14:13:50 +0200 | [diff] [blame] | 1149 | for_each_link_platforms(dai_link, i, platform) { |
| 1150 | for_each_component(component) { |
| 1151 | if (!snd_soc_is_matching_component(platform, component)) |
| 1152 | continue; |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 1153 | |
Jerome Brunet | 3461473 | 2019-06-27 14:13:50 +0200 | [diff] [blame] | 1154 | snd_soc_rtdcom_add(rtd, component); |
| 1155 | } |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Kuninori Morimoto | 63dc47d | 2019-11-06 10:07:31 +0900 | [diff] [blame] | 1158 | /* see for_each_card_links */ |
| 1159 | list_add_tail(&dai_link->list, &card->dai_link_list); |
| 1160 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1161 | return 0; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 1162 | |
| 1163 | _err_defer: |
| 1164 | soc_free_pcm_runtime(rtd); |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1165 | return -EPROBE_DEFER; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1166 | } |
Kuninori Morimoto | 63dc47d | 2019-11-06 10:07:31 +0900 | [diff] [blame] | 1167 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_link); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1168 | |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1169 | static void soc_set_of_name_prefix(struct snd_soc_component *component) |
| 1170 | { |
| 1171 | struct device_node *of_node = soc_component_to_node(component); |
| 1172 | const char *str; |
| 1173 | int ret; |
| 1174 | |
| 1175 | ret = of_property_read_string(of_node, "sound-name-prefix", &str); |
| 1176 | if (!ret) |
| 1177 | component->name_prefix = str; |
| 1178 | } |
| 1179 | |
| 1180 | static void soc_set_name_prefix(struct snd_soc_card *card, |
| 1181 | struct snd_soc_component *component) |
| 1182 | { |
| 1183 | int i; |
| 1184 | |
| 1185 | for (i = 0; i < card->num_configs && card->codec_conf; i++) { |
| 1186 | struct snd_soc_codec_conf *map = &card->codec_conf[i]; |
| 1187 | struct device_node *of_node = soc_component_to_node(component); |
| 1188 | |
| 1189 | if (map->of_node && of_node != map->of_node) |
| 1190 | continue; |
| 1191 | if (map->dev_name && strcmp(component->name, map->dev_name)) |
| 1192 | continue; |
| 1193 | component->name_prefix = map->name_prefix; |
| 1194 | return; |
| 1195 | } |
| 1196 | |
| 1197 | /* |
| 1198 | * If there is no configuration table or no match in the table, |
| 1199 | * check if a prefix is provided in the node |
| 1200 | */ |
| 1201 | soc_set_of_name_prefix(component); |
| 1202 | } |
| 1203 | |
Kuninori Morimoto | c6619b7 | 2019-11-06 10:07:46 +0900 | [diff] [blame^] | 1204 | static void soc_remove_component(struct snd_soc_component *component, |
| 1205 | int probed) |
Kuninori Morimoto | 22d1423 | 2019-01-21 09:32:55 +0900 | [diff] [blame] | 1206 | { |
Kuninori Morimoto | c6619b7 | 2019-11-06 10:07:46 +0900 | [diff] [blame^] | 1207 | |
| 1208 | if (!component->card) |
| 1209 | return; |
| 1210 | |
| 1211 | if (probed) |
| 1212 | snd_soc_component_remove(component); |
| 1213 | |
Kuninori Morimoto | 04f770d | 2019-09-04 09:14:35 +0900 | [diff] [blame] | 1214 | /* For framework level robustness */ |
Amadeusz Sławiński | 3bb936f5 | 2019-06-05 15:45:53 +0200 | [diff] [blame] | 1215 | snd_soc_component_set_jack(component, NULL, NULL); |
Kuninori Morimoto | 04f770d | 2019-09-04 09:14:35 +0900 | [diff] [blame] | 1216 | |
Bard liao | 7a5d981 | 2019-09-18 21:31:31 +0800 | [diff] [blame] | 1217 | list_del_init(&component->card_list); |
Kuninori Morimoto | 22d1423 | 2019-01-21 09:32:55 +0900 | [diff] [blame] | 1218 | snd_soc_dapm_free(snd_soc_component_get_dapm(component)); |
| 1219 | soc_cleanup_component_debugfs(component); |
| 1220 | component->card = NULL; |
Pierre-Louis Bossart | 0e36f36 | 2019-08-07 21:51:31 -0500 | [diff] [blame] | 1221 | snd_soc_component_module_put_when_remove(component); |
Kuninori Morimoto | 22d1423 | 2019-01-21 09:32:55 +0900 | [diff] [blame] | 1222 | } |
| 1223 | |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1224 | static int soc_probe_component(struct snd_soc_card *card, |
| 1225 | struct snd_soc_component *component) |
| 1226 | { |
| 1227 | struct snd_soc_dapm_context *dapm = |
| 1228 | snd_soc_component_get_dapm(component); |
| 1229 | struct snd_soc_dai *dai; |
Kuninori Morimoto | c6619b7 | 2019-11-06 10:07:46 +0900 | [diff] [blame^] | 1230 | int probed = 0; |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1231 | int ret; |
| 1232 | |
| 1233 | if (!strcmp(component->name, "snd-soc-dummy")) |
| 1234 | return 0; |
| 1235 | |
| 1236 | if (component->card) { |
| 1237 | if (component->card != card) { |
| 1238 | dev_err(component->dev, |
| 1239 | "Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n", |
| 1240 | card->name, component->card->name); |
| 1241 | return -ENODEV; |
| 1242 | } |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
| 1246 | ret = snd_soc_component_module_get_when_probe(component); |
| 1247 | if (ret < 0) |
| 1248 | return ret; |
| 1249 | |
| 1250 | component->card = card; |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1251 | soc_set_name_prefix(card, component); |
| 1252 | |
| 1253 | soc_init_component_debugfs(component); |
| 1254 | |
Kuninori Morimoto | 95c267d | 2019-08-23 09:58:52 +0900 | [diff] [blame] | 1255 | snd_soc_dapm_init(dapm, card, component); |
Kuninori Morimoto | b614bea | 2019-08-23 09:58:47 +0900 | [diff] [blame] | 1256 | |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1257 | ret = snd_soc_dapm_new_controls(dapm, |
| 1258 | component->driver->dapm_widgets, |
| 1259 | component->driver->num_dapm_widgets); |
| 1260 | |
| 1261 | if (ret != 0) { |
| 1262 | dev_err(component->dev, |
| 1263 | "Failed to create new controls %d\n", ret); |
| 1264 | goto err_probe; |
| 1265 | } |
| 1266 | |
| 1267 | for_each_component_dais(component, dai) { |
| 1268 | ret = snd_soc_dapm_new_dai_widgets(dapm, dai); |
| 1269 | if (ret != 0) { |
| 1270 | dev_err(component->dev, |
| 1271 | "Failed to create DAI widgets %d\n", ret); |
| 1272 | goto err_probe; |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | ret = snd_soc_component_probe(component); |
| 1277 | if (ret < 0) { |
| 1278 | dev_err(component->dev, |
| 1279 | "ASoC: failed to probe component %d\n", ret); |
| 1280 | goto err_probe; |
| 1281 | } |
| 1282 | WARN(dapm->idle_bias_off && |
| 1283 | dapm->bias_level != SND_SOC_BIAS_OFF, |
| 1284 | "codec %s can not start from non-off bias with idle_bias_off==1\n", |
| 1285 | component->name); |
Kuninori Morimoto | c6619b7 | 2019-11-06 10:07:46 +0900 | [diff] [blame^] | 1286 | probed = 1; |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1287 | |
| 1288 | /* machine specific init */ |
| 1289 | if (component->init) { |
| 1290 | ret = component->init(component); |
| 1291 | if (ret < 0) { |
| 1292 | dev_err(component->dev, |
| 1293 | "Failed to do machine specific init %d\n", ret); |
| 1294 | goto err_probe; |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | ret = snd_soc_add_component_controls(component, |
| 1299 | component->driver->controls, |
| 1300 | component->driver->num_controls); |
| 1301 | if (ret < 0) |
| 1302 | goto err_probe; |
| 1303 | |
| 1304 | ret = snd_soc_dapm_add_routes(dapm, |
| 1305 | component->driver->dapm_routes, |
| 1306 | component->driver->num_dapm_routes); |
| 1307 | if (ret < 0) |
| 1308 | goto err_probe; |
| 1309 | |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1310 | /* see for_each_card_components */ |
| 1311 | list_add(&component->card_list, &card->component_dev_list); |
| 1312 | |
| 1313 | err_probe: |
| 1314 | if (ret < 0) |
Kuninori Morimoto | c6619b7 | 2019-11-06 10:07:46 +0900 | [diff] [blame^] | 1315 | soc_remove_component(component, probed); |
Kuninori Morimoto | ffd60fb | 2019-08-23 09:58:42 +0900 | [diff] [blame] | 1316 | |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1320 | static void soc_remove_dai(struct snd_soc_dai *dai, int order) |
Jarkko Nikula | 589c356 | 2010-12-06 16:27:07 +0200 | [diff] [blame] | 1321 | { |
| 1322 | int err; |
| 1323 | |
Guennadi Liakhovetski | 52abe6c | 2019-02-01 11:05:13 -0600 | [diff] [blame] | 1324 | if (!dai || !dai->probed || !dai->driver || |
Kuninori Morimoto | 2eda3cb | 2018-09-11 06:54:26 +0000 | [diff] [blame] | 1325 | dai->driver->remove_order != order) |
| 1326 | return; |
| 1327 | |
Kuninori Morimoto | dcdab58 | 2019-07-22 10:35:05 +0900 | [diff] [blame] | 1328 | err = snd_soc_dai_remove(dai); |
| 1329 | if (err < 0) |
| 1330 | dev_err(dai->dev, |
| 1331 | "ASoC: failed to remove %s: %d\n", |
| 1332 | dai->name, err); |
| 1333 | |
Kuninori Morimoto | 2eda3cb | 2018-09-11 06:54:26 +0000 | [diff] [blame] | 1334 | dai->probed = 0; |
Misael Lopez Cruz | b0aa88a | 2014-03-21 16:27:26 +0100 | [diff] [blame] | 1335 | } |
| 1336 | |
Kuninori Morimoto | a7d44f7 | 2019-09-04 09:15:06 +0900 | [diff] [blame] | 1337 | static int soc_probe_dai(struct snd_soc_dai *dai, int order) |
| 1338 | { |
| 1339 | int ret; |
| 1340 | |
| 1341 | if (dai->probed || |
| 1342 | dai->driver->probe_order != order) |
| 1343 | return 0; |
| 1344 | |
| 1345 | ret = snd_soc_dai_probe(dai); |
| 1346 | if (ret < 0) { |
| 1347 | dev_err(dai->dev, "ASoC: failed to probe DAI %s: %d\n", |
| 1348 | dai->name, ret); |
| 1349 | return ret; |
| 1350 | } |
| 1351 | |
| 1352 | dai->probed = 1; |
| 1353 | |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
Kuninori Morimoto | 4ca47d2 | 2019-09-04 09:14:57 +0900 | [diff] [blame] | 1357 | static void soc_remove_link_dais(struct snd_soc_card *card) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1358 | { |
Lars-Peter Clausen | e60cd14 | 2014-08-19 15:51:26 +0200 | [diff] [blame] | 1359 | int i; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1360 | struct snd_soc_dai *codec_dai; |
Kuninori Morimoto | 4ca47d2 | 2019-09-04 09:14:57 +0900 | [diff] [blame] | 1361 | struct snd_soc_pcm_runtime *rtd; |
| 1362 | int order; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1363 | |
Kuninori Morimoto | 4ca47d2 | 2019-09-04 09:14:57 +0900 | [diff] [blame] | 1364 | for_each_comp_order(order) { |
| 1365 | for_each_card_rtds(card, rtd) { |
Kuninori Morimoto | 4ca47d2 | 2019-09-04 09:14:57 +0900 | [diff] [blame] | 1366 | /* remove the CODEC DAI */ |
| 1367 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 1368 | soc_remove_dai(codec_dai, order); |
| 1369 | |
| 1370 | soc_remove_dai(rtd->cpu_dai, order); |
| 1371 | } |
| 1372 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Kuninori Morimoto | bc7c16c | 2019-09-04 09:15:23 +0900 | [diff] [blame] | 1375 | static int soc_probe_link_dais(struct snd_soc_card *card) |
| 1376 | { |
| 1377 | struct snd_soc_dai *codec_dai; |
| 1378 | struct snd_soc_pcm_runtime *rtd; |
| 1379 | int i, order, ret; |
| 1380 | |
| 1381 | for_each_comp_order(order) { |
| 1382 | for_each_card_rtds(card, rtd) { |
| 1383 | |
| 1384 | dev_dbg(card->dev, |
| 1385 | "ASoC: probe %s dai link %d late %d\n", |
| 1386 | card->name, rtd->num, order); |
| 1387 | |
| 1388 | ret = soc_probe_dai(rtd->cpu_dai, order); |
| 1389 | if (ret) |
| 1390 | return ret; |
| 1391 | |
| 1392 | /* probe the CODEC DAI */ |
| 1393 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 1394 | ret = soc_probe_dai(codec_dai, order); |
| 1395 | if (ret) |
| 1396 | return ret; |
| 1397 | } |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
Kuninori Morimoto | b006c0c | 2019-09-04 09:14:51 +0900 | [diff] [blame] | 1404 | static void soc_remove_link_components(struct snd_soc_card *card) |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1405 | { |
Lars-Peter Clausen | 61aca564 | 2014-08-19 15:51:21 +0200 | [diff] [blame] | 1406 | struct snd_soc_component *component; |
Kuninori Morimoto | b006c0c | 2019-09-04 09:14:51 +0900 | [diff] [blame] | 1407 | struct snd_soc_pcm_runtime *rtd; |
Kuninori Morimoto | 90be711 | 2017-08-08 06:18:10 +0000 | [diff] [blame] | 1408 | struct snd_soc_rtdcom_list *rtdcom; |
Kuninori Morimoto | b006c0c | 2019-09-04 09:14:51 +0900 | [diff] [blame] | 1409 | int order; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1410 | |
Kuninori Morimoto | b006c0c | 2019-09-04 09:14:51 +0900 | [diff] [blame] | 1411 | for_each_comp_order(order) { |
| 1412 | for_each_card_rtds(card, rtd) { |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 1413 | for_each_rtd_components(rtd, rtdcom, component) { |
Kuninori Morimoto | b006c0c | 2019-09-04 09:14:51 +0900 | [diff] [blame] | 1414 | if (component->driver->remove_order != order) |
| 1415 | continue; |
| 1416 | |
Kuninori Morimoto | c6619b7 | 2019-11-06 10:07:46 +0900 | [diff] [blame^] | 1417 | soc_remove_component(component, 1); |
Kuninori Morimoto | b006c0c | 2019-09-04 09:14:51 +0900 | [diff] [blame] | 1418 | } |
| 1419 | } |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1420 | } |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 1421 | } |
| 1422 | |
Kuninori Morimoto | 62f07a6 | 2019-09-04 09:14:46 +0900 | [diff] [blame] | 1423 | static int soc_probe_link_components(struct snd_soc_card *card) |
Kuninori Morimoto | 6fb0355 | 2019-08-23 09:58:58 +0900 | [diff] [blame] | 1424 | { |
| 1425 | struct snd_soc_component *component; |
Kuninori Morimoto | 62f07a6 | 2019-09-04 09:14:46 +0900 | [diff] [blame] | 1426 | struct snd_soc_pcm_runtime *rtd; |
Kuninori Morimoto | 6fb0355 | 2019-08-23 09:58:58 +0900 | [diff] [blame] | 1427 | struct snd_soc_rtdcom_list *rtdcom; |
Kuninori Morimoto | 62f07a6 | 2019-09-04 09:14:46 +0900 | [diff] [blame] | 1428 | int ret, order; |
Kuninori Morimoto | 6fb0355 | 2019-08-23 09:58:58 +0900 | [diff] [blame] | 1429 | |
Kuninori Morimoto | 62f07a6 | 2019-09-04 09:14:46 +0900 | [diff] [blame] | 1430 | for_each_comp_order(order) { |
| 1431 | for_each_card_rtds(card, rtd) { |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 1432 | for_each_rtd_components(rtd, rtdcom, component) { |
Kuninori Morimoto | 62f07a6 | 2019-09-04 09:14:46 +0900 | [diff] [blame] | 1433 | if (component->driver->probe_order != order) |
| 1434 | continue; |
| 1435 | |
| 1436 | ret = soc_probe_component(card, component); |
| 1437 | if (ret < 0) |
| 1438 | return ret; |
| 1439 | } |
Kuninori Morimoto | 6fb0355 | 2019-08-23 09:58:58 +0900 | [diff] [blame] | 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | return 0; |
| 1444 | } |
| 1445 | |
Kuninori Morimoto | ef2e817 | 2017-11-28 06:27:09 +0000 | [diff] [blame] | 1446 | void snd_soc_disconnect_sync(struct device *dev) |
| 1447 | { |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1448 | struct snd_soc_component *component = |
| 1449 | snd_soc_lookup_component(dev, NULL); |
Kuninori Morimoto | ef2e817 | 2017-11-28 06:27:09 +0000 | [diff] [blame] | 1450 | |
| 1451 | if (!component || !component->card) |
| 1452 | return; |
| 1453 | |
| 1454 | snd_card_disconnect_sync(component->card->snd_card); |
| 1455 | } |
Kuninori Morimoto | df53218 | 2017-11-29 02:38:27 +0000 | [diff] [blame] | 1456 | EXPORT_SYMBOL_GPL(snd_soc_disconnect_sync); |
Kuninori Morimoto | ef2e817 | 2017-11-28 06:27:09 +0000 | [diff] [blame] | 1457 | |
Arnaud Pouliquen | 25f7b70 | 2017-01-03 16:52:51 +0100 | [diff] [blame] | 1458 | static int soc_link_dai_pcm_new(struct snd_soc_dai **dais, int num_dais, |
| 1459 | struct snd_soc_pcm_runtime *rtd) |
| 1460 | { |
| 1461 | int i, ret = 0; |
| 1462 | |
| 1463 | for (i = 0; i < num_dais; ++i) { |
| 1464 | struct snd_soc_dai_driver *drv = dais[i]->driver; |
| 1465 | |
Rohit kumar | de17f14 | 2018-11-01 18:08:49 +0530 | [diff] [blame] | 1466 | if (drv->pcm_new) |
Arnaud Pouliquen | 25f7b70 | 2017-01-03 16:52:51 +0100 | [diff] [blame] | 1467 | ret = drv->pcm_new(rtd, dais[i]); |
| 1468 | if (ret < 0) { |
| 1469 | dev_err(dais[i]->dev, |
| 1470 | "ASoC: Failed to bind %s with pcm device\n", |
| 1471 | dais[i]->name); |
| 1472 | return ret; |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
Kuninori Morimoto | c4b4698 | 2019-09-04 09:15:12 +0900 | [diff] [blame] | 1479 | static int soc_link_init(struct snd_soc_card *card, |
| 1480 | struct snd_soc_pcm_runtime *rtd) |
| 1481 | { |
| 1482 | struct snd_soc_dai_link *dai_link = rtd->dai_link; |
| 1483 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 1484 | struct snd_soc_rtdcom_list *rtdcom; |
| 1485 | struct snd_soc_component *component; |
| 1486 | int ret, num; |
| 1487 | |
| 1488 | /* set default power off timeout */ |
| 1489 | rtd->pmdown_time = pmdown_time; |
Liam Girdwood | 0168bf0 | 2011-06-07 16:08:05 +0100 | [diff] [blame] | 1490 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1491 | /* do machine specific initialization */ |
| 1492 | if (dai_link->init) { |
| 1493 | ret = dai_link->init(rtd); |
| 1494 | if (ret < 0) { |
| 1495 | dev_err(card->dev, "ASoC: failed to init %s: %d\n", |
| 1496 | dai_link->name, ret); |
| 1497 | return ret; |
| 1498 | } |
| 1499 | } |
| 1500 | |
Ricard Wanderlof | 40aa538 | 2019-07-24 11:38:44 +0200 | [diff] [blame] | 1501 | if (dai_link->dai_fmt) { |
| 1502 | ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt); |
| 1503 | if (ret) |
| 1504 | return ret; |
| 1505 | } |
Kuninori Morimoto | a5053a8 | 2015-04-10 09:47:00 +0000 | [diff] [blame] | 1506 | |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1507 | /* add DPCM sysfs entries */ |
Kuninori Morimoto | 596becd | 2019-08-07 10:31:36 +0900 | [diff] [blame] | 1508 | soc_dpcm_debugfs_add(rtd); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1509 | |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1510 | num = rtd->num; |
| 1511 | |
| 1512 | /* |
| 1513 | * most drivers will register their PCMs using DAI link ordering but |
| 1514 | * topology based drivers can use the DAI link id field to set PCM |
| 1515 | * device number and then use rtd + a base offset of the BEs. |
| 1516 | */ |
Kuninori Morimoto | 2b544dd | 2019-10-15 12:59:31 +0900 | [diff] [blame] | 1517 | for_each_rtd_components(rtd, rtdcom, component) { |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1518 | if (!component->driver->use_dai_pcm_id) |
| 1519 | continue; |
| 1520 | |
| 1521 | if (rtd->dai_link->no_pcm) |
| 1522 | num += component->driver->be_pcm_base; |
| 1523 | else |
| 1524 | num = rtd->dai_link->id; |
| 1525 | } |
| 1526 | |
Kuninori Morimoto | b423c42 | 2019-07-22 10:35:29 +0900 | [diff] [blame] | 1527 | /* create compress_device if possible */ |
| 1528 | ret = snd_soc_dai_compress_new(cpu_dai, rtd, num); |
| 1529 | if (ret != -ENOTSUPP) { |
| 1530 | if (ret < 0) |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 1531 | dev_err(card->dev, "ASoC: can't create compress %s\n", |
Namarta Kohli | 1245b70 | 2012-08-16 17:10:41 +0530 | [diff] [blame] | 1532 | dai_link->stream_name); |
Kuninori Morimoto | b423c42 | 2019-07-22 10:35:29 +0900 | [diff] [blame] | 1533 | return ret; |
| 1534 | } |
| 1535 | |
Jerome Brunet | a342031 | 2019-07-25 18:59:47 +0200 | [diff] [blame] | 1536 | /* create the pcm */ |
| 1537 | ret = soc_new_pcm(rtd, num); |
| 1538 | if (ret < 0) { |
| 1539 | dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", |
| 1540 | dai_link->stream_name, ret); |
| 1541 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1542 | } |
Jerome Brunet | a342031 | 2019-07-25 18:59:47 +0200 | [diff] [blame] | 1543 | ret = soc_link_dai_pcm_new(&cpu_dai, 1, rtd); |
| 1544 | if (ret < 0) |
| 1545 | return ret; |
| 1546 | ret = soc_link_dai_pcm_new(rtd->codec_dais, |
| 1547 | rtd->num_codecs, rtd); |
| 1548 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Kuninori Morimoto | e8fbd25 | 2019-09-04 09:15:40 +0900 | [diff] [blame] | 1551 | static void soc_unbind_aux_dev(struct snd_soc_card *card) |
Kuninori Morimoto | 4893a2e | 2019-09-04 09:15:35 +0900 | [diff] [blame] | 1552 | { |
Kuninori Morimoto | e8fbd25 | 2019-09-04 09:15:40 +0900 | [diff] [blame] | 1553 | struct snd_soc_component *component, *_component; |
| 1554 | |
| 1555 | for_each_card_auxs_safe(card, component, _component) { |
| 1556 | component->init = NULL; |
| 1557 | list_del(&component->card_aux_list); |
| 1558 | } |
Kuninori Morimoto | 4893a2e | 2019-09-04 09:15:35 +0900 | [diff] [blame] | 1559 | } |
| 1560 | |
Kuninori Morimoto | bee886f | 2019-09-04 09:15:28 +0900 | [diff] [blame] | 1561 | static int soc_bind_aux_dev(struct snd_soc_card *card) |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1562 | { |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 1563 | struct snd_soc_component *component; |
Kuninori Morimoto | bee886f | 2019-09-04 09:15:28 +0900 | [diff] [blame] | 1564 | struct snd_soc_aux_dev *aux; |
| 1565 | int i; |
Sebastian Reichel | 3ca041e | 2014-04-28 16:07:22 +0200 | [diff] [blame] | 1566 | |
Kuninori Morimoto | bee886f | 2019-09-04 09:15:28 +0900 | [diff] [blame] | 1567 | for_each_card_pre_auxs(card, i, aux) { |
| 1568 | /* codecs, usually analog devices */ |
| 1569 | component = soc_find_component(&aux->dlc); |
| 1570 | if (!component) |
| 1571 | return -EPROBE_DEFER; |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1572 | |
Kuninori Morimoto | bee886f | 2019-09-04 09:15:28 +0900 | [diff] [blame] | 1573 | component->init = aux->init; |
| 1574 | /* see for_each_card_auxs */ |
| 1575 | list_add(&component->card_aux_list, &card->aux_comp_list); |
| 1576 | } |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 1577 | return 0; |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | static int soc_probe_aux_devices(struct snd_soc_card *card) |
| 1581 | { |
Kuninori Morimoto | 991454e | 2017-03-24 00:13:00 +0000 | [diff] [blame] | 1582 | struct snd_soc_component *comp; |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 1583 | int order; |
| 1584 | int ret; |
| 1585 | |
Kuninori Morimoto | 1a1035a | 2018-09-18 01:30:41 +0000 | [diff] [blame] | 1586 | for_each_comp_order(order) { |
Kuninori Morimoto | c2b71c7 | 2019-08-08 14:54:44 +0900 | [diff] [blame] | 1587 | for_each_card_auxs(card, comp) { |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 1588 | if (comp->driver->probe_order == order) { |
| 1589 | ret = soc_probe_component(card, comp); |
| 1590 | if (ret < 0) { |
| 1591 | dev_err(card->dev, |
| 1592 | "ASoC: failed to probe aux component %s %d\n", |
| 1593 | comp->name, ret); |
| 1594 | return ret; |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | } |
Lars-Peter Clausen | 65d9361 | 2014-08-19 15:51:22 +0200 | [diff] [blame] | 1599 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1600 | return 0; |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 1603 | static void soc_remove_aux_devices(struct snd_soc_card *card) |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1604 | { |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 1605 | struct snd_soc_component *comp, *_comp; |
| 1606 | int order; |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1607 | |
Kuninori Morimoto | 1a1035a | 2018-09-18 01:30:41 +0000 | [diff] [blame] | 1608 | for_each_comp_order(order) { |
Kuninori Morimoto | c2b71c7 | 2019-08-08 14:54:44 +0900 | [diff] [blame] | 1609 | for_each_card_auxs_safe(card, comp, _comp) { |
Kuninori Morimoto | e8fbd25 | 2019-09-04 09:15:40 +0900 | [diff] [blame] | 1610 | if (comp->driver->remove_order == order) |
Kuninori Morimoto | c6619b7 | 2019-11-06 10:07:46 +0900 | [diff] [blame^] | 1611 | soc_remove_component(comp, 1); |
Lars-Peter Clausen | 5f3484a | 2014-07-01 22:13:48 +0200 | [diff] [blame] | 1612 | } |
| 1613 | } |
Jarkko Nikula | 2eea392 | 2010-11-25 17:47:38 +0200 | [diff] [blame] | 1614 | } |
| 1615 | |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1616 | /** |
| 1617 | * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime |
| 1618 | * @rtd: The runtime for which the DAI link format should be changed |
| 1619 | * @dai_fmt: The new DAI link format |
| 1620 | * |
| 1621 | * This function updates the DAI link format for all DAIs connected to the DAI |
| 1622 | * link for the specified runtime. |
| 1623 | * |
| 1624 | * Note: For setups with a static format set the dai_fmt field in the |
| 1625 | * corresponding snd_dai_link struct instead of using this function. |
| 1626 | * |
| 1627 | * Returns 0 on success, otherwise a negative error code. |
| 1628 | */ |
| 1629 | int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, |
| 1630 | unsigned int dai_fmt) |
| 1631 | { |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1632 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1633 | struct snd_soc_dai *codec_dai; |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1634 | unsigned int i; |
| 1635 | int ret; |
| 1636 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 1637 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1638 | ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); |
| 1639 | if (ret != 0 && ret != -ENOTSUPP) { |
| 1640 | dev_warn(codec_dai->dev, |
| 1641 | "ASoC: Failed to set DAI format: %d\n", ret); |
| 1642 | return ret; |
| 1643 | } |
| 1644 | } |
| 1645 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1646 | /* |
| 1647 | * Flip the polarity for the "CPU" end of a CODEC<->CODEC link |
| 1648 | * the component which has non_legacy_dai_naming is Codec |
| 1649 | */ |
Kuninori Morimoto | 999f7f5 | 2018-05-08 03:20:24 +0000 | [diff] [blame] | 1650 | if (cpu_dai->component->driver->non_legacy_dai_naming) { |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1651 | unsigned int inv_dai_fmt; |
| 1652 | |
| 1653 | inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK; |
| 1654 | switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1655 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1656 | inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; |
| 1657 | break; |
| 1658 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1659 | inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; |
| 1660 | break; |
| 1661 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1662 | inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; |
| 1663 | break; |
| 1664 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1665 | inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; |
| 1666 | break; |
| 1667 | } |
| 1668 | |
| 1669 | dai_fmt = inv_dai_fmt; |
| 1670 | } |
| 1671 | |
| 1672 | ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); |
| 1673 | if (ret != 0 && ret != -ENOTSUPP) { |
| 1674 | dev_warn(cpu_dai->dev, |
| 1675 | "ASoC: Failed to set DAI format: %d\n", ret); |
| 1676 | return ret; |
| 1677 | } |
| 1678 | |
| 1679 | return 0; |
| 1680 | } |
Lars-Peter Clausen | ddaca25 | 2015-01-08 12:23:05 +0100 | [diff] [blame] | 1681 | EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt); |
Lars-Peter Clausen | ce64c8b | 2015-01-06 15:17:20 +0100 | [diff] [blame] | 1682 | |
Takashi Iwai | 1f5a453 | 2017-04-24 08:54:41 +0200 | [diff] [blame] | 1683 | #ifdef CONFIG_DMI |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1684 | /* |
| 1685 | * Trim special characters, and replace '-' with '_' since '-' is used to |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1686 | * separate different DMI fields in the card long name. Only number and |
| 1687 | * alphabet characters and a few separator characters are kept. |
| 1688 | */ |
| 1689 | static void cleanup_dmi_name(char *name) |
| 1690 | { |
| 1691 | int i, j = 0; |
| 1692 | |
| 1693 | for (i = 0; name[i]; i++) { |
| 1694 | if (isalnum(name[i]) || (name[i] == '.') |
| 1695 | || (name[i] == '_')) |
| 1696 | name[j++] = name[i]; |
| 1697 | else if (name[i] == '-') |
| 1698 | name[j++] = '_'; |
| 1699 | } |
| 1700 | |
| 1701 | name[j] = '\0'; |
| 1702 | } |
| 1703 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1704 | /* |
| 1705 | * Check if a DMI field is valid, i.e. not containing any string |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 1706 | * in the black list. |
| 1707 | */ |
| 1708 | static int is_dmi_valid(const char *field) |
| 1709 | { |
| 1710 | int i = 0; |
| 1711 | |
| 1712 | while (dmi_blacklist[i]) { |
| 1713 | if (strstr(field, dmi_blacklist[i])) |
| 1714 | return 0; |
| 1715 | i++; |
Wu Fengguang | 46b5a4d | 2017-06-30 00:27:13 +0800 | [diff] [blame] | 1716 | } |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 1717 | |
| 1718 | return 1; |
| 1719 | } |
| 1720 | |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1721 | /** |
| 1722 | * snd_soc_set_dmi_name() - Register DMI names to card |
| 1723 | * @card: The card to register DMI names |
| 1724 | * @flavour: The flavour "differentiator" for the card amongst its peers. |
| 1725 | * |
| 1726 | * An Intel machine driver may be used by many different devices but are |
| 1727 | * difficult for userspace to differentiate, since machine drivers ususally |
| 1728 | * use their own name as the card short name and leave the card long name |
| 1729 | * blank. To differentiate such devices and fix bugs due to lack of |
| 1730 | * device-specific configurations, this function allows DMI info to be used |
| 1731 | * as the sound card long name, in the format of |
| 1732 | * "vendor-product-version-board" |
| 1733 | * (Character '-' is used to separate different DMI fields here). |
| 1734 | * This will help the user space to load the device-specific Use Case Manager |
| 1735 | * (UCM) configurations for the card. |
| 1736 | * |
| 1737 | * Possible card long names may be: |
| 1738 | * DellInc.-XPS139343-01-0310JH |
| 1739 | * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA |
| 1740 | * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX |
| 1741 | * |
| 1742 | * This function also supports flavoring the card longname to provide |
| 1743 | * the extra differentiation, like "vendor-product-version-board-flavor". |
| 1744 | * |
| 1745 | * We only keep number and alphabet characters and a few separator characters |
| 1746 | * in the card long name since UCM in the user space uses the card long names |
| 1747 | * as card configuration directory names and AudoConf cannot support special |
| 1748 | * charactors like SPACE. |
| 1749 | * |
| 1750 | * Returns 0 on success, otherwise a negative error code. |
| 1751 | */ |
| 1752 | int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour) |
| 1753 | { |
| 1754 | const char *vendor, *product, *product_version, *board; |
| 1755 | size_t longname_buf_size = sizeof(card->snd_card->longname); |
| 1756 | size_t len; |
| 1757 | |
| 1758 | if (card->long_name) |
| 1759 | return 0; /* long name already set by driver or from DMI */ |
| 1760 | |
| 1761 | /* make up dmi long name as: vendor.product.version.board */ |
| 1762 | vendor = dmi_get_system_info(DMI_BOARD_VENDOR); |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 1763 | if (!vendor || !is_dmi_valid(vendor)) { |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1764 | dev_warn(card->dev, "ASoC: no DMI vendor name!\n"); |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
| 1768 | snprintf(card->dmi_longname, sizeof(card->snd_card->longname), |
| 1769 | "%s", vendor); |
| 1770 | cleanup_dmi_name(card->dmi_longname); |
| 1771 | |
| 1772 | product = dmi_get_system_info(DMI_PRODUCT_NAME); |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 1773 | if (product && is_dmi_valid(product)) { |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1774 | len = strlen(card->dmi_longname); |
| 1775 | snprintf(card->dmi_longname + len, |
| 1776 | longname_buf_size - len, |
| 1777 | "-%s", product); |
| 1778 | |
| 1779 | len++; /* skip the separator "-" */ |
| 1780 | if (len < longname_buf_size) |
| 1781 | cleanup_dmi_name(card->dmi_longname + len); |
| 1782 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1783 | /* |
| 1784 | * some vendors like Lenovo may only put a self-explanatory |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1785 | * name in the product version field |
| 1786 | */ |
| 1787 | product_version = dmi_get_system_info(DMI_PRODUCT_VERSION); |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 1788 | if (product_version && is_dmi_valid(product_version)) { |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1789 | len = strlen(card->dmi_longname); |
| 1790 | snprintf(card->dmi_longname + len, |
| 1791 | longname_buf_size - len, |
| 1792 | "-%s", product_version); |
| 1793 | |
| 1794 | len++; |
| 1795 | if (len < longname_buf_size) |
| 1796 | cleanup_dmi_name(card->dmi_longname + len); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | board = dmi_get_system_info(DMI_BOARD_NAME); |
Mengdong Lin | 98faf43 | 2017-06-28 15:01:39 +0800 | [diff] [blame] | 1801 | if (board && is_dmi_valid(board)) { |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1802 | len = strlen(card->dmi_longname); |
| 1803 | snprintf(card->dmi_longname + len, |
| 1804 | longname_buf_size - len, |
| 1805 | "-%s", board); |
| 1806 | |
| 1807 | len++; |
| 1808 | if (len < longname_buf_size) |
| 1809 | cleanup_dmi_name(card->dmi_longname + len); |
| 1810 | } else if (!product) { |
| 1811 | /* fall back to using legacy name */ |
| 1812 | dev_warn(card->dev, "ASoC: no DMI board/product name!\n"); |
| 1813 | return 0; |
| 1814 | } |
| 1815 | |
| 1816 | /* Add flavour to dmi long name */ |
| 1817 | if (flavour) { |
| 1818 | len = strlen(card->dmi_longname); |
| 1819 | snprintf(card->dmi_longname + len, |
| 1820 | longname_buf_size - len, |
| 1821 | "-%s", flavour); |
| 1822 | |
| 1823 | len++; |
| 1824 | if (len < longname_buf_size) |
| 1825 | cleanup_dmi_name(card->dmi_longname + len); |
| 1826 | } |
| 1827 | |
| 1828 | /* set the card long name */ |
| 1829 | card->long_name = card->dmi_longname; |
| 1830 | |
| 1831 | return 0; |
| 1832 | } |
| 1833 | EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name); |
Takashi Iwai | 1f5a453 | 2017-04-24 08:54:41 +0200 | [diff] [blame] | 1834 | #endif /* CONFIG_DMI */ |
Liam Girdwood | 345233d | 2017-01-14 16:13:02 +0800 | [diff] [blame] | 1835 | |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1836 | static void soc_check_tplg_fes(struct snd_soc_card *card) |
| 1837 | { |
| 1838 | struct snd_soc_component *component; |
| 1839 | const struct snd_soc_component_driver *comp_drv; |
| 1840 | struct snd_soc_dai_link *dai_link; |
| 1841 | int i; |
| 1842 | |
Kuninori Morimoto | 368dee9 | 2018-09-21 05:23:01 +0000 | [diff] [blame] | 1843 | for_each_component(component) { |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1844 | |
Daniel Baluta | 49f9c4f | 2019-09-25 21:33:58 +0300 | [diff] [blame] | 1845 | /* does this component override BEs ? */ |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1846 | if (!component->driver->ignore_machine) |
| 1847 | continue; |
| 1848 | |
| 1849 | /* for this machine ? */ |
Pierre-Louis Bossart | e194098b | 2019-03-01 19:08:51 -0600 | [diff] [blame] | 1850 | if (!strcmp(component->driver->ignore_machine, |
| 1851 | card->dev->driver->name)) |
| 1852 | goto match; |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1853 | if (strcmp(component->driver->ignore_machine, |
Pierre-Louis Bossart | e194098b | 2019-03-01 19:08:51 -0600 | [diff] [blame] | 1854 | dev_name(card->dev))) |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1855 | continue; |
Pierre-Louis Bossart | e194098b | 2019-03-01 19:08:51 -0600 | [diff] [blame] | 1856 | match: |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1857 | /* machine matches, so override the rtd data */ |
Kuninori Morimoto | 7fe072b | 2018-09-18 01:28:49 +0000 | [diff] [blame] | 1858 | for_each_card_prelinks(card, i, dai_link) { |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1859 | |
| 1860 | /* ignore this FE */ |
| 1861 | if (dai_link->dynamic) { |
| 1862 | dai_link->ignore = true; |
| 1863 | continue; |
| 1864 | } |
| 1865 | |
Daniel Baluta | 49f9c4f | 2019-09-25 21:33:58 +0300 | [diff] [blame] | 1866 | dev_info(card->dev, "info: override BE DAI link %s\n", |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1867 | card->dai_link[i].name); |
| 1868 | |
| 1869 | /* override platform component */ |
Kuninori Morimoto | adb76b5 | 2019-06-06 13:22:19 +0900 | [diff] [blame] | 1870 | if (!dai_link->platforms) { |
Kuninori Morimoto | daecf46 | 2018-08-31 03:10:08 +0000 | [diff] [blame] | 1871 | dev_err(card->dev, "init platform error"); |
| 1872 | continue; |
| 1873 | } |
Kuninori Morimoto | 910fdca | 2019-01-21 09:32:32 +0900 | [diff] [blame] | 1874 | dai_link->platforms->name = component->name; |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1875 | |
| 1876 | /* convert non BE into BE */ |
| 1877 | dai_link->no_pcm = 1; |
| 1878 | |
| 1879 | /* override any BE fixups */ |
| 1880 | dai_link->be_hw_params_fixup = |
| 1881 | component->driver->be_hw_params_fixup; |
| 1882 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1883 | /* |
| 1884 | * most BE links don't set stream name, so set it to |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1885 | * dai link name if it's NULL to help bind widgets. |
| 1886 | */ |
| 1887 | if (!dai_link->stream_name) |
| 1888 | dai_link->stream_name = dai_link->name; |
| 1889 | } |
| 1890 | |
| 1891 | /* Inform userspace we are using alternate topology */ |
| 1892 | if (component->driver->topology_name_prefix) { |
| 1893 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 1894 | /* topology shortname created? */ |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1895 | if (!card->topology_shortname_created) { |
| 1896 | comp_drv = component->driver; |
| 1897 | |
| 1898 | snprintf(card->topology_shortname, 32, "%s-%s", |
| 1899 | comp_drv->topology_name_prefix, |
| 1900 | card->name); |
| 1901 | card->topology_shortname_created = true; |
| 1902 | } |
| 1903 | |
| 1904 | /* use topology shortname */ |
| 1905 | card->name = card->topology_shortname; |
| 1906 | } |
| 1907 | } |
| 1908 | } |
| 1909 | |
Kuninori Morimoto | 0f23f71 | 2019-10-02 14:22:49 +0900 | [diff] [blame] | 1910 | #define soc_setup_card_name(name, name1, name2, norm) \ |
| 1911 | __soc_setup_card_name(name, sizeof(name), name1, name2, norm) |
| 1912 | static void __soc_setup_card_name(char *name, int len, |
| 1913 | const char *name1, const char *name2, |
| 1914 | int normalization) |
| 1915 | { |
| 1916 | int i; |
| 1917 | |
| 1918 | snprintf(name, len, "%s", name1 ? name1 : name2); |
| 1919 | |
| 1920 | if (!normalization) |
| 1921 | return; |
| 1922 | |
| 1923 | /* |
| 1924 | * Name normalization |
| 1925 | * |
| 1926 | * The driver name is somewhat special, as it's used as a key for |
| 1927 | * searches in the user-space. |
| 1928 | * |
| 1929 | * ex) |
| 1930 | * "abcd??efg" -> "abcd__efg" |
| 1931 | */ |
| 1932 | for (i = 0; i < len; i++) { |
| 1933 | switch (name[i]) { |
| 1934 | case '_': |
| 1935 | case '-': |
| 1936 | case '\0': |
| 1937 | break; |
| 1938 | default: |
| 1939 | if (!isalnum(name[i])) |
| 1940 | name[i] = '_'; |
| 1941 | break; |
| 1942 | } |
| 1943 | } |
| 1944 | } |
| 1945 | |
Kuninori Morimoto | a4de83a | 2019-08-20 14:05:10 +0900 | [diff] [blame] | 1946 | static void soc_cleanup_card_resources(struct snd_soc_card *card) |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1947 | { |
Kuninori Morimoto | 7ce6088 | 2019-10-02 14:22:40 +0900 | [diff] [blame] | 1948 | struct snd_soc_dai_link *link, *_link; |
| 1949 | |
Pierre-Louis Bossart | df95a16 | 2019-11-06 08:58:01 -0600 | [diff] [blame] | 1950 | /* This should be called before snd_card_free() */ |
| 1951 | soc_remove_link_components(card); |
| 1952 | |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1953 | /* free the ALSA card at first; this syncs with pending operations */ |
Kuninori Morimoto | 29040d1 | 2019-05-27 16:51:34 +0900 | [diff] [blame] | 1954 | if (card->snd_card) { |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1955 | snd_card_free(card->snd_card); |
Kuninori Morimoto | 29040d1 | 2019-05-27 16:51:34 +0900 | [diff] [blame] | 1956 | card->snd_card = NULL; |
| 1957 | } |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1958 | |
| 1959 | /* remove and free each DAI */ |
Kuninori Morimoto | 7ce6088 | 2019-10-02 14:22:40 +0900 | [diff] [blame] | 1960 | soc_remove_link_dais(card); |
Kuninori Morimoto | 7ce6088 | 2019-10-02 14:22:40 +0900 | [diff] [blame] | 1961 | |
| 1962 | for_each_card_links_safe(card, link, _link) |
| 1963 | snd_soc_remove_dai_link(card, link); |
| 1964 | |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1965 | /* remove auxiliary devices */ |
| 1966 | soc_remove_aux_devices(card); |
Kuninori Morimoto | e8fbd25 | 2019-09-04 09:15:40 +0900 | [diff] [blame] | 1967 | soc_unbind_aux_dev(card); |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1968 | |
| 1969 | snd_soc_dapm_free(&card->dapm); |
| 1970 | soc_cleanup_card_debugfs(card); |
| 1971 | |
| 1972 | /* remove the card */ |
| 1973 | if (card->remove) |
| 1974 | card->remove(card); |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1975 | } |
| 1976 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 1977 | static int snd_soc_instantiate_card(struct snd_soc_card *card) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1978 | { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 1979 | struct snd_soc_pcm_runtime *rtd; |
Mengdong Lin | 61b0088 | 2015-12-02 14:11:48 +0800 | [diff] [blame] | 1980 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | c7e7377 | 2019-09-04 09:15:17 +0900 | [diff] [blame] | 1981 | int ret, i; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1982 | |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 1983 | mutex_lock(&client_mutex); |
Liam Girdwood | 01b9d99 | 2012-03-07 10:38:25 +0000 | [diff] [blame] | 1984 | mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1985 | |
Kuninori Morimoto | 95c267d | 2019-08-23 09:58:52 +0900 | [diff] [blame] | 1986 | snd_soc_dapm_init(&card->dapm, card, NULL); |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 1987 | |
Liam Girdwood | a655de8 | 2018-07-02 16:59:54 +0100 | [diff] [blame] | 1988 | /* check whether any platform is ignore machine FE and using topology */ |
| 1989 | soc_check_tplg_fes(card); |
| 1990 | |
Lars-Peter Clausen | 44c69bb | 2014-07-01 22:13:47 +0200 | [diff] [blame] | 1991 | /* bind aux_devs too */ |
Kuninori Morimoto | bee886f | 2019-09-04 09:15:28 +0900 | [diff] [blame] | 1992 | ret = soc_bind_aux_dev(card); |
| 1993 | if (ret < 0) |
| 1994 | goto probe_end; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1995 | |
Mengdong Lin | f8f8036 | 2015-12-02 14:11:22 +0800 | [diff] [blame] | 1996 | /* add predefined DAI links to the list */ |
Kuninori Morimoto | d814598 | 2019-10-02 14:23:07 +0900 | [diff] [blame] | 1997 | card->num_rtd = 0; |
Kuninori Morimoto | 5b99a0a | 2019-08-07 10:30:36 +0900 | [diff] [blame] | 1998 | for_each_card_prelinks(card, i, dai_link) { |
| 1999 | ret = snd_soc_add_dai_link(card, dai_link); |
| 2000 | if (ret < 0) |
| 2001 | goto probe_end; |
| 2002 | } |
Mengdong Lin | f8f8036 | 2015-12-02 14:11:22 +0800 | [diff] [blame] | 2003 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2004 | /* card bind complete so register a sound card */ |
Takashi Iwai | 102b5a8 | 2014-01-29 14:42:55 +0100 | [diff] [blame] | 2005 | ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2006 | card->owner, 0, &card->snd_card); |
| 2007 | if (ret < 0) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2008 | dev_err(card->dev, |
| 2009 | "ASoC: can't create sound card for card %s: %d\n", |
| 2010 | card->name, ret); |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 2011 | goto probe_end; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2012 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2013 | |
Lars-Peter Clausen | 0757d83 | 2015-04-09 10:52:36 +0200 | [diff] [blame] | 2014 | soc_init_card_debugfs(card); |
| 2015 | |
Kuninori Morimoto | b3da425 | 2019-08-07 10:31:24 +0900 | [diff] [blame] | 2016 | soc_resume_init(card); |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 2017 | |
Kuninori Morimoto | b8ba3b5 | 2019-08-07 10:30:53 +0900 | [diff] [blame] | 2018 | ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, |
| 2019 | card->num_dapm_widgets); |
| 2020 | if (ret < 0) |
| 2021 | goto probe_end; |
Mark Brown | 9a841eb | 2011-04-12 17:51:37 -0700 | [diff] [blame] | 2022 | |
Kuninori Morimoto | b8ba3b5 | 2019-08-07 10:30:53 +0900 | [diff] [blame] | 2023 | ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets, |
| 2024 | card->num_of_dapm_widgets); |
| 2025 | if (ret < 0) |
| 2026 | goto probe_end; |
Nicolin Chen | f23e860 | 2015-02-14 17:22:49 -0800 | [diff] [blame] | 2027 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2028 | /* initialise the sound card only once */ |
| 2029 | if (card->probe) { |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 2030 | ret = card->probe(card); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2031 | if (ret < 0) |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 2032 | goto probe_end; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 2035 | /* probe all components used by DAI links on this card */ |
Kuninori Morimoto | 62f07a6 | 2019-09-04 09:14:46 +0900 | [diff] [blame] | 2036 | ret = soc_probe_link_components(card); |
| 2037 | if (ret < 0) { |
| 2038 | dev_err(card->dev, |
| 2039 | "ASoC: failed to instantiate card %d\n", ret); |
| 2040 | goto probe_end; |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 2041 | } |
| 2042 | |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 2043 | /* probe auxiliary components */ |
| 2044 | ret = soc_probe_aux_devices(card); |
| 2045 | if (ret < 0) |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 2046 | goto probe_end; |
Mengdong Lin | f2ed6b0 | 2016-01-06 13:29:31 +0800 | [diff] [blame] | 2047 | |
Stephen Warren | 62ae68f | 2012-06-08 12:34:23 -0600 | [diff] [blame] | 2048 | /* probe all DAI links on this card */ |
Kuninori Morimoto | c7e7377 | 2019-09-04 09:15:17 +0900 | [diff] [blame] | 2049 | ret = soc_probe_link_dais(card); |
| 2050 | if (ret < 0) { |
| 2051 | dev_err(card->dev, |
| 2052 | "ASoC: failed to instantiate card %d\n", ret); |
| 2053 | goto probe_end; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
Kuninori Morimoto | c4b4698 | 2019-09-04 09:15:12 +0900 | [diff] [blame] | 2056 | for_each_card_rtds(card, rtd) |
| 2057 | soc_link_init(card, rtd); |
| 2058 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 2059 | snd_soc_dapm_link_dai_widgets(card); |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 2060 | snd_soc_dapm_connect_dai_link_widgets(card); |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 2061 | |
Kuninori Morimoto | 9b98c7c | 2019-08-07 10:31:08 +0900 | [diff] [blame] | 2062 | ret = snd_soc_add_card_controls(card, card->controls, |
| 2063 | card->num_controls); |
| 2064 | if (ret < 0) |
| 2065 | goto probe_end; |
Mark Brown | b7af1da | 2011-04-07 19:18:44 +0900 | [diff] [blame] | 2066 | |
Kuninori Morimoto | daa480b | 2019-08-07 10:31:03 +0900 | [diff] [blame] | 2067 | ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, |
| 2068 | card->num_dapm_routes); |
| 2069 | if (ret < 0) |
| 2070 | goto probe_end; |
Mark Brown | b8ad29d | 2011-03-02 18:35:51 +0000 | [diff] [blame] | 2071 | |
Kuninori Morimoto | daa480b | 2019-08-07 10:31:03 +0900 | [diff] [blame] | 2072 | ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes, |
| 2073 | card->num_of_dapm_routes); |
| 2074 | if (ret < 0) |
| 2075 | goto probe_end; |
Mark Brown | 75d9ac4 | 2011-09-27 16:41:01 +0100 | [diff] [blame] | 2076 | |
Takashi Iwai | 861886d | 2017-04-24 08:54:42 +0200 | [diff] [blame] | 2077 | /* try to set some sane longname if DMI is available */ |
| 2078 | snd_soc_set_dmi_name(card, NULL); |
| 2079 | |
Kuninori Morimoto | 0f23f71 | 2019-10-02 14:22:49 +0900 | [diff] [blame] | 2080 | soc_setup_card_name(card->snd_card->shortname, |
| 2081 | card->name, NULL, 0); |
| 2082 | soc_setup_card_name(card->snd_card->longname, |
| 2083 | card->long_name, card->name, 0); |
| 2084 | soc_setup_card_name(card->snd_card->driver, |
| 2085 | card->driver_name, card->name, 1); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2086 | |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 2087 | if (card->late_probe) { |
| 2088 | ret = card->late_probe(card); |
| 2089 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2090 | dev_err(card->dev, "ASoC: %s late_probe() failed: %d\n", |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 2091 | card->name, ret); |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 2092 | goto probe_end; |
Mark Brown | 28e9ad9 | 2011-03-02 18:36:34 +0000 | [diff] [blame] | 2093 | } |
| 2094 | } |
| 2095 | |
Lars-Peter Clausen | 824ef82 | 2013-08-27 15:51:01 +0200 | [diff] [blame] | 2096 | snd_soc_dapm_new_widgets(card); |
Lars-Peter Clausen | 8c193b8 | 2013-08-27 15:51:00 +0200 | [diff] [blame] | 2097 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2098 | ret = snd_card_register(card->snd_card); |
| 2099 | if (ret < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2100 | dev_err(card->dev, "ASoC: failed to register soundcard %d\n", |
| 2101 | ret); |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 2102 | goto probe_end; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2105 | card->instantiated = 1; |
Tzung-Bi Shih | 882eab6 | 2018-11-14 17:06:13 +0800 | [diff] [blame] | 2106 | dapm_mark_endpoints_dirty(card); |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 2107 | snd_soc_dapm_sync(&card->dapm); |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 2108 | |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 2109 | probe_end: |
| 2110 | if (ret < 0) |
| 2111 | soc_cleanup_card_resources(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2112 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2113 | mutex_unlock(&card->mutex); |
Lars-Peter Clausen | 34e81ab | 2015-03-07 19:34:03 +0100 | [diff] [blame] | 2114 | mutex_unlock(&client_mutex); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2115 | |
Mark Brown | b19e6e7 | 2012-03-14 21:18:39 +0000 | [diff] [blame] | 2116 | return ret; |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | /* probes a new socdev */ |
| 2120 | static int soc_probe(struct platform_device *pdev) |
| 2121 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2122 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2123 | |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2124 | /* |
| 2125 | * no card, so machine driver should be registering card |
| 2126 | * we should not be here in that case so ret error |
| 2127 | */ |
| 2128 | if (!card) |
| 2129 | return -EINVAL; |
| 2130 | |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 2131 | dev_warn(&pdev->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2132 | "ASoC: machine %s should use snd_soc_register_card()\n", |
Mark Brown | fe4085e | 2012-03-02 13:07:41 +0000 | [diff] [blame] | 2133 | card->name); |
| 2134 | |
Mark Brown | 435c5e2 | 2008-12-04 15:32:53 +0000 | [diff] [blame] | 2135 | /* Bodge while we unpick instantiation */ |
| 2136 | card->dev = &pdev->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2137 | |
Mark Brown | 28d528c | 2012-08-09 18:45:23 +0100 | [diff] [blame] | 2138 | return snd_soc_register_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | /* removes a socdev */ |
| 2142 | static int soc_remove(struct platform_device *pdev) |
| 2143 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2144 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2145 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2146 | snd_soc_unregister_card(card); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2147 | return 0; |
| 2148 | } |
| 2149 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2150 | int snd_soc_poweroff(struct device *dev) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2151 | { |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2152 | struct snd_soc_card *card = dev_get_drvdata(dev); |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 2153 | struct snd_soc_pcm_runtime *rtd; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2154 | |
| 2155 | if (!card->instantiated) |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2156 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2157 | |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2158 | /* |
| 2159 | * Flush out pmdown_time work - we actually do want to run it |
| 2160 | * now, we're shutting down so no imminent restart. |
| 2161 | */ |
Kuninori Morimoto | 65462e44 | 2019-01-21 09:32:37 +0900 | [diff] [blame] | 2162 | snd_soc_flush_all_delayed_work(card); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2163 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2164 | snd_soc_dapm_shutdown(card); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2165 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 2166 | /* deactivate pins to sleep state */ |
Kuninori Morimoto | bcb1fd1 | 2018-09-18 01:29:35 +0000 | [diff] [blame] | 2167 | for_each_card_rtds(card, rtd) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2168 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 2169 | struct snd_soc_dai *codec_dai; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 2170 | int i; |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2171 | |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 2172 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 2173 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Benoit Cousson | 88bd870 | 2014-07-08 23:19:34 +0200 | [diff] [blame] | 2174 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
| 2175 | } |
Nicolin Chen | 988e8cc | 2013-11-04 14:57:31 +0800 | [diff] [blame] | 2176 | } |
| 2177 | |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2178 | return 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2179 | } |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2180 | EXPORT_SYMBOL_GPL(snd_soc_poweroff); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2181 | |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2182 | const struct dev_pm_ops snd_soc_pm_ops = { |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 2183 | .suspend = snd_soc_suspend, |
| 2184 | .resume = snd_soc_resume, |
| 2185 | .freeze = snd_soc_suspend, |
| 2186 | .thaw = snd_soc_resume, |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2187 | .poweroff = snd_soc_poweroff, |
Viresh Kumar | b1dd589 | 2012-02-24 16:25:49 +0530 | [diff] [blame] | 2188 | .restore = snd_soc_resume, |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2189 | }; |
Stephen Warren | deb2607 | 2011-04-05 19:35:30 -0600 | [diff] [blame] | 2190 | EXPORT_SYMBOL_GPL(snd_soc_pm_ops); |
Mark Brown | 416356f | 2009-06-30 19:05:15 +0100 | [diff] [blame] | 2191 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2192 | /* ASoC platform driver */ |
| 2193 | static struct platform_driver soc_driver = { |
| 2194 | .driver = { |
| 2195 | .name = "soc-audio", |
Mark Brown | 6f8ab4a | 2011-01-26 14:59:27 +0000 | [diff] [blame] | 2196 | .pm = &snd_soc_pm_ops, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2197 | }, |
| 2198 | .probe = soc_probe, |
| 2199 | .remove = soc_remove, |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2200 | }; |
| 2201 | |
Mark Brown | 096e49d | 2009-07-05 15:12:22 +0100 | [diff] [blame] | 2202 | /** |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2203 | * snd_soc_cnew - create new control |
| 2204 | * @_template: control template |
| 2205 | * @data: control private data |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2206 | * @long_name: control long name |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2207 | * @prefix: control name prefix |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2208 | * |
| 2209 | * Create a new mixer control from a template control. |
| 2210 | * |
| 2211 | * Returns 0 for success, else error. |
| 2212 | */ |
| 2213 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
Mark Brown | 3056557 | 2012-02-16 17:07:42 -0800 | [diff] [blame] | 2214 | void *data, const char *long_name, |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2215 | const char *prefix) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2216 | { |
| 2217 | struct snd_kcontrol_new template; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2218 | struct snd_kcontrol *kcontrol; |
| 2219 | char *name = NULL; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2220 | |
| 2221 | memcpy(&template, _template, sizeof(template)); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2222 | template.index = 0; |
| 2223 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2224 | if (!long_name) |
| 2225 | long_name = template.name; |
| 2226 | |
| 2227 | if (prefix) { |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 2228 | name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name); |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2229 | if (!name) |
| 2230 | return NULL; |
| 2231 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 2232 | template.name = name; |
| 2233 | } else { |
| 2234 | template.name = long_name; |
| 2235 | } |
| 2236 | |
| 2237 | kcontrol = snd_ctl_new1(&template, data); |
| 2238 | |
| 2239 | kfree(name); |
| 2240 | |
| 2241 | return kcontrol; |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2242 | } |
| 2243 | EXPORT_SYMBOL_GPL(snd_soc_cnew); |
| 2244 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2245 | static int snd_soc_add_controls(struct snd_card *card, struct device *dev, |
| 2246 | const struct snd_kcontrol_new *controls, int num_controls, |
| 2247 | const char *prefix, void *data) |
| 2248 | { |
| 2249 | int err, i; |
| 2250 | |
| 2251 | for (i = 0; i < num_controls; i++) { |
| 2252 | const struct snd_kcontrol_new *control = &controls[i]; |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2253 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2254 | err = snd_ctl_add(card, snd_soc_cnew(control, data, |
| 2255 | control->name, prefix)); |
| 2256 | if (err < 0) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2257 | dev_err(dev, "ASoC: Failed to add %s: %d\n", |
| 2258 | control->name, err); |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2259 | return err; |
| 2260 | } |
| 2261 | } |
| 2262 | |
| 2263 | return 0; |
| 2264 | } |
| 2265 | |
Dimitris Papastamos | 4fefd69 | 2013-07-29 13:51:58 +0100 | [diff] [blame] | 2266 | struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, |
| 2267 | const char *name) |
| 2268 | { |
| 2269 | struct snd_card *card = soc_card->snd_card; |
| 2270 | struct snd_kcontrol *kctl; |
| 2271 | |
| 2272 | if (unlikely(!name)) |
| 2273 | return NULL; |
| 2274 | |
| 2275 | list_for_each_entry(kctl, &card->controls, list) |
| 2276 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) |
| 2277 | return kctl; |
| 2278 | return NULL; |
| 2279 | } |
| 2280 | EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); |
| 2281 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 2282 | /** |
Lars-Peter Clausen | 0f2780a | 2014-07-17 22:01:08 +0200 | [diff] [blame] | 2283 | * snd_soc_add_component_controls - Add an array of controls to a component. |
| 2284 | * |
| 2285 | * @component: Component to add controls to |
| 2286 | * @controls: Array of controls to add |
| 2287 | * @num_controls: Number of elements in the array |
| 2288 | * |
| 2289 | * Return: 0 for success, else error. |
| 2290 | */ |
| 2291 | int snd_soc_add_component_controls(struct snd_soc_component *component, |
| 2292 | const struct snd_kcontrol_new *controls, unsigned int num_controls) |
| 2293 | { |
| 2294 | struct snd_card *card = component->card->snd_card; |
| 2295 | |
| 2296 | return snd_soc_add_controls(card, component->dev, controls, |
| 2297 | num_controls, component->name_prefix, component); |
| 2298 | } |
| 2299 | EXPORT_SYMBOL_GPL(snd_soc_add_component_controls); |
| 2300 | |
| 2301 | /** |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2302 | * snd_soc_add_card_controls - add an array of controls to a SoC card. |
| 2303 | * Convenience function to add a list of controls. |
| 2304 | * |
| 2305 | * @soc_card: SoC card to add controls to |
| 2306 | * @controls: array of controls to add |
| 2307 | * @num_controls: number of elements in the array |
| 2308 | * |
| 2309 | * Return 0 for success, else error. |
| 2310 | */ |
| 2311 | int snd_soc_add_card_controls(struct snd_soc_card *soc_card, |
| 2312 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2313 | { |
| 2314 | struct snd_card *card = soc_card->snd_card; |
| 2315 | |
| 2316 | return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, |
| 2317 | NULL, soc_card); |
| 2318 | } |
| 2319 | EXPORT_SYMBOL_GPL(snd_soc_add_card_controls); |
| 2320 | |
| 2321 | /** |
| 2322 | * snd_soc_add_dai_controls - add an array of controls to a DAI. |
| 2323 | * Convienience function to add a list of controls. |
| 2324 | * |
| 2325 | * @dai: DAI to add controls to |
| 2326 | * @controls: array of controls to add |
| 2327 | * @num_controls: number of elements in the array |
| 2328 | * |
| 2329 | * Return 0 for success, else error. |
| 2330 | */ |
| 2331 | int snd_soc_add_dai_controls(struct snd_soc_dai *dai, |
| 2332 | const struct snd_kcontrol_new *controls, int num_controls) |
| 2333 | { |
Lars-Peter Clausen | 313665b | 2014-11-04 11:30:58 +0100 | [diff] [blame] | 2334 | struct snd_card *card = dai->component->card->snd_card; |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 2335 | |
| 2336 | return snd_soc_add_controls(card, dai->dev, controls, num_controls, |
| 2337 | NULL, dai); |
| 2338 | } |
| 2339 | EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls); |
| 2340 | |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2341 | static int snd_soc_bind_card(struct snd_soc_card *card) |
| 2342 | { |
| 2343 | struct snd_soc_pcm_runtime *rtd; |
| 2344 | int ret; |
| 2345 | |
| 2346 | ret = snd_soc_instantiate_card(card); |
| 2347 | if (ret != 0) |
| 2348 | return ret; |
| 2349 | |
| 2350 | /* deactivate pins to sleep state */ |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2351 | for_each_card_rtds(card, rtd) { |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2352 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 2353 | struct snd_soc_dai *codec_dai; |
| 2354 | int j; |
| 2355 | |
| 2356 | for_each_rtd_codec_dai(rtd, j, codec_dai) { |
| 2357 | if (!codec_dai->active) |
| 2358 | pinctrl_pm_select_sleep_state(codec_dai->dev); |
| 2359 | } |
| 2360 | |
| 2361 | if (!cpu_dai->active) |
| 2362 | pinctrl_pm_select_sleep_state(cpu_dai->dev); |
| 2363 | } |
| 2364 | |
| 2365 | return ret; |
| 2366 | } |
| 2367 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2368 | /** |
| 2369 | * snd_soc_register_card - Register a card with the ASoC core |
| 2370 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2371 | * @card: Card to register |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2372 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2373 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2374 | int snd_soc_register_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2375 | { |
| 2376 | if (!card->name || !card->dev) |
| 2377 | return -EINVAL; |
| 2378 | |
Mark Brown | ed77cc1 | 2011-05-03 18:25:34 +0100 | [diff] [blame] | 2379 | dev_set_drvdata(card->dev, card); |
| 2380 | |
Kuninori Morimoto | b03bfae | 2019-08-20 14:04:54 +0900 | [diff] [blame] | 2381 | INIT_LIST_HEAD(&card->widgets); |
| 2382 | INIT_LIST_HEAD(&card->paths); |
| 2383 | INIT_LIST_HEAD(&card->dapm_list); |
| 2384 | INIT_LIST_HEAD(&card->aux_comp_list); |
| 2385 | INIT_LIST_HEAD(&card->component_dev_list); |
| 2386 | INIT_LIST_HEAD(&card->list); |
Mengdong Lin | f8f8036 | 2015-12-02 14:11:22 +0800 | [diff] [blame] | 2387 | INIT_LIST_HEAD(&card->dai_link_list); |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 2388 | INIT_LIST_HEAD(&card->rtd_list); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 2389 | INIT_LIST_HEAD(&card->dapm_dirty); |
Liam Girdwood | 8a97823 | 2015-05-29 19:06:14 +0100 | [diff] [blame] | 2390 | INIT_LIST_HEAD(&card->dobj_list); |
Kuninori Morimoto | b03bfae | 2019-08-20 14:04:54 +0900 | [diff] [blame] | 2391 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2392 | card->instantiated = 0; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2393 | mutex_init(&card->mutex); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2394 | mutex_init(&card->dapm_mutex); |
Peter Ujfalusi | 72b745e | 2019-08-13 13:45:32 +0300 | [diff] [blame] | 2395 | mutex_init(&card->pcm_mutex); |
KaiChieh Chuang | a976486 | 2019-03-08 13:05:53 +0800 | [diff] [blame] | 2396 | spin_lock_init(&card->dpcm_lock); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2397 | |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2398 | return snd_soc_bind_card(card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2399 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2400 | EXPORT_SYMBOL_GPL(snd_soc_register_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2401 | |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2402 | static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister) |
| 2403 | { |
| 2404 | if (card->instantiated) { |
| 2405 | card->instantiated = false; |
| 2406 | snd_soc_dapm_shutdown(card); |
Kuninori Morimoto | 53e947a | 2019-01-21 09:32:42 +0900 | [diff] [blame] | 2407 | snd_soc_flush_all_delayed_work(card); |
Ranjani Sridharan | f96fb7d | 2019-04-04 17:30:40 -0700 | [diff] [blame] | 2408 | |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2409 | soc_cleanup_card_resources(card); |
| 2410 | if (!unregister) |
| 2411 | list_add(&card->list, &unbind_card_list); |
| 2412 | } else { |
| 2413 | if (unregister) |
| 2414 | list_del(&card->list); |
| 2415 | } |
| 2416 | } |
| 2417 | |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2418 | /** |
| 2419 | * snd_soc_unregister_card - Unregister a card with the ASoC core |
| 2420 | * |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2421 | * @card: Card to unregister |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2422 | * |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2423 | */ |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2424 | int snd_soc_unregister_card(struct snd_soc_card *card) |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2425 | { |
Kuninori Morimoto | b545542 | 2019-06-19 10:07:19 +0900 | [diff] [blame] | 2426 | mutex_lock(&client_mutex); |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2427 | snd_soc_unbind_card(card, true); |
Kuninori Morimoto | b545542 | 2019-06-19 10:07:19 +0900 | [diff] [blame] | 2428 | mutex_unlock(&client_mutex); |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2429 | dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2430 | |
| 2431 | return 0; |
| 2432 | } |
Vinod Koul | 70a7ca3 | 2011-01-14 19:22:48 +0530 | [diff] [blame] | 2433 | EXPORT_SYMBOL_GPL(snd_soc_unregister_card); |
Mark Brown | c5af3a2 | 2008-11-28 13:29:45 +0000 | [diff] [blame] | 2434 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2435 | /* |
| 2436 | * Simplify DAI link configuration by removing ".-1" from device names |
| 2437 | * and sanitizing names. |
| 2438 | */ |
Dimitris Papastamos | 0b9a214 | 2010-12-06 15:49:20 +0000 | [diff] [blame] | 2439 | static char *fmt_single_name(struct device *dev, int *id) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2440 | { |
| 2441 | char *found, name[NAME_SIZE]; |
| 2442 | int id1, id2; |
| 2443 | |
| 2444 | if (dev_name(dev) == NULL) |
| 2445 | return NULL; |
| 2446 | |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 2447 | strlcpy(name, dev_name(dev), NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2448 | |
| 2449 | /* are we a "%s.%d" name (platform and SPI components) */ |
| 2450 | found = strstr(name, dev->driver->name); |
| 2451 | if (found) { |
| 2452 | /* get ID */ |
| 2453 | if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { |
| 2454 | |
| 2455 | /* discard ID from name if ID == -1 */ |
| 2456 | if (*id == -1) |
| 2457 | found[strlen(dev->driver->name)] = '\0'; |
| 2458 | } |
| 2459 | |
| 2460 | } else { |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2461 | /* I2C component devices are named "bus-addr" */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2462 | if (sscanf(name, "%x-%x", &id1, &id2) == 2) { |
| 2463 | char tmp[NAME_SIZE]; |
| 2464 | |
| 2465 | /* create unique ID number from I2C addr and bus */ |
Jarkko Nikula | 0589944 | 2010-10-19 11:10:45 +0300 | [diff] [blame] | 2466 | *id = ((id1 & 0xffff) << 16) + id2; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2467 | |
| 2468 | /* sanitize component name for DAI link creation */ |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2469 | snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, |
| 2470 | name); |
Dimitris Papastamos | 58818a7 | 2010-12-06 15:42:17 +0000 | [diff] [blame] | 2471 | strlcpy(name, tmp, NAME_SIZE); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2472 | } else |
| 2473 | *id = 0; |
| 2474 | } |
| 2475 | |
Kuninori Morimoto | 5001449 | 2019-10-02 14:22:57 +0900 | [diff] [blame] | 2476 | return devm_kstrdup(dev, name, GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | /* |
| 2480 | * Simplify DAI link naming for single devices with multiple DAIs by removing |
| 2481 | * any ".-1" and using the DAI name (instead of device name). |
| 2482 | */ |
| 2483 | static inline char *fmt_multiple_name(struct device *dev, |
| 2484 | struct snd_soc_dai_driver *dai_drv) |
| 2485 | { |
| 2486 | if (dai_drv->name == NULL) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 2487 | dev_err(dev, |
| 2488 | "ASoC: error - multiple DAI %s registered with no name\n", |
| 2489 | dev_name(dev)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2490 | return NULL; |
| 2491 | } |
| 2492 | |
Kuninori Morimoto | 5001449 | 2019-10-02 14:22:57 +0900 | [diff] [blame] | 2493 | return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
Kuninori Morimoto | ffdbca0 | 2019-11-06 10:07:23 +0900 | [diff] [blame] | 2496 | void snd_soc_unregister_dai(struct snd_soc_dai *dai) |
Kuninori Morimoto | e11381f | 2019-11-05 15:47:04 +0900 | [diff] [blame] | 2497 | { |
| 2498 | dev_dbg(dai->dev, "ASoC: Unregistered DAI '%s'\n", dai->name); |
| 2499 | list_del(&dai->list); |
| 2500 | } |
Kuninori Morimoto | ffdbca0 | 2019-11-06 10:07:23 +0900 | [diff] [blame] | 2501 | EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); |
Kuninori Morimoto | e11381f | 2019-11-05 15:47:04 +0900 | [diff] [blame] | 2502 | |
Kuninori Morimoto | 7ca2438 | 2019-11-06 10:07:17 +0900 | [diff] [blame] | 2503 | /** |
| 2504 | * snd_soc_register_dai - Register a DAI dynamically & create its widgets |
| 2505 | * |
| 2506 | * @component: The component the DAIs are registered for |
| 2507 | * @dai_drv: DAI driver to use for the DAI |
| 2508 | * |
| 2509 | * Topology can use this API to register DAIs when probing a component. |
| 2510 | * These DAIs's widgets will be freed in the card cleanup and the DAIs |
| 2511 | * will be freed in the component cleanup. |
| 2512 | */ |
| 2513 | struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component, |
| 2514 | struct snd_soc_dai_driver *dai_drv, |
| 2515 | bool legacy_dai_naming) |
Mengdong Lin | 5e4fb37 | 2015-12-31 16:40:20 +0800 | [diff] [blame] | 2516 | { |
| 2517 | struct device *dev = component->dev; |
| 2518 | struct snd_soc_dai *dai; |
| 2519 | |
| 2520 | dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev)); |
| 2521 | |
Kuninori Morimoto | 7ca2438 | 2019-11-06 10:07:17 +0900 | [diff] [blame] | 2522 | lockdep_assert_held(&client_mutex); |
| 2523 | |
Kuninori Morimoto | 5001449 | 2019-10-02 14:22:57 +0900 | [diff] [blame] | 2524 | dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL); |
Mengdong Lin | 5e4fb37 | 2015-12-31 16:40:20 +0800 | [diff] [blame] | 2525 | if (dai == NULL) |
| 2526 | return NULL; |
| 2527 | |
| 2528 | /* |
| 2529 | * Back in the old days when we still had component-less DAIs, |
| 2530 | * instead of having a static name, component-less DAIs would |
| 2531 | * inherit the name of the parent device so it is possible to |
| 2532 | * register multiple instances of the DAI. We still need to keep |
| 2533 | * the same naming style even though those DAIs are not |
| 2534 | * component-less anymore. |
| 2535 | */ |
| 2536 | if (legacy_dai_naming && |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2537 | (dai_drv->id == 0 || dai_drv->name == NULL)) { |
Mengdong Lin | 5e4fb37 | 2015-12-31 16:40:20 +0800 | [diff] [blame] | 2538 | dai->name = fmt_single_name(dev, &dai->id); |
| 2539 | } else { |
| 2540 | dai->name = fmt_multiple_name(dev, dai_drv); |
| 2541 | if (dai_drv->id) |
| 2542 | dai->id = dai_drv->id; |
| 2543 | else |
| 2544 | dai->id = component->num_dai; |
| 2545 | } |
Kuninori Morimoto | 5001449 | 2019-10-02 14:22:57 +0900 | [diff] [blame] | 2546 | if (!dai->name) |
Mengdong Lin | 5e4fb37 | 2015-12-31 16:40:20 +0800 | [diff] [blame] | 2547 | return NULL; |
Mengdong Lin | 5e4fb37 | 2015-12-31 16:40:20 +0800 | [diff] [blame] | 2548 | |
| 2549 | dai->component = component; |
| 2550 | dai->dev = dev; |
| 2551 | dai->driver = dai_drv; |
| 2552 | if (!dai->driver->ops) |
| 2553 | dai->driver->ops = &null_dai_ops; |
| 2554 | |
Kuninori Morimoto | 15a0c64 | 2018-09-21 05:23:17 +0000 | [diff] [blame] | 2555 | /* see for_each_component_dais */ |
Kuninori Morimoto | 58bf417 | 2017-12-20 01:48:29 +0000 | [diff] [blame] | 2556 | list_add_tail(&dai->list, &component->dai_list); |
Mengdong Lin | 5e4fb37 | 2015-12-31 16:40:20 +0800 | [diff] [blame] | 2557 | component->num_dai++; |
| 2558 | |
| 2559 | dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); |
| 2560 | return dai; |
| 2561 | } |
Kuninori Morimoto | e11381f | 2019-11-05 15:47:04 +0900 | [diff] [blame] | 2562 | |
Mark Brown | 9115171 | 2008-11-30 23:31:24 +0000 | [diff] [blame] | 2563 | /** |
Kuninori Morimoto | 3f6674a | 2019-11-05 15:47:00 +0900 | [diff] [blame] | 2564 | * snd_soc_unregister_dai - Unregister DAIs from the ASoC core |
| 2565 | * |
| 2566 | * @component: The component for which the DAIs should be unregistered |
| 2567 | */ |
| 2568 | static void snd_soc_unregister_dais(struct snd_soc_component *component) |
| 2569 | { |
| 2570 | struct snd_soc_dai *dai, *_dai; |
| 2571 | |
Kuninori Morimoto | e11381f | 2019-11-05 15:47:04 +0900 | [diff] [blame] | 2572 | for_each_component_dais_safe(component, dai, _dai) |
| 2573 | snd_soc_unregister_dai(dai); |
Kuninori Morimoto | 3f6674a | 2019-11-05 15:47:00 +0900 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | /** |
Kuninori Morimoto | daf7737 | 2019-11-05 15:46:55 +0900 | [diff] [blame] | 2577 | * snd_soc_register_dais - Register a DAI with the ASoC core |
| 2578 | * |
| 2579 | * @component: The component the DAIs are registered for |
| 2580 | * @dai_drv: DAI driver to use for the DAIs |
| 2581 | * @count: Number of DAIs |
| 2582 | */ |
| 2583 | static int snd_soc_register_dais(struct snd_soc_component *component, |
| 2584 | struct snd_soc_dai_driver *dai_drv, |
| 2585 | size_t count) |
| 2586 | { |
Kuninori Morimoto | daf7737 | 2019-11-05 15:46:55 +0900 | [diff] [blame] | 2587 | struct snd_soc_dai *dai; |
| 2588 | unsigned int i; |
| 2589 | int ret; |
| 2590 | |
Kuninori Morimoto | daf7737 | 2019-11-05 15:46:55 +0900 | [diff] [blame] | 2591 | for (i = 0; i < count; i++) { |
Kuninori Morimoto | 71cb85f | 2019-11-05 15:47:18 +0900 | [diff] [blame] | 2592 | dai = snd_soc_register_dai(component, dai_drv + i, count == 1 && |
Kuninori Morimoto | daf7737 | 2019-11-05 15:46:55 +0900 | [diff] [blame] | 2593 | !component->driver->non_legacy_dai_naming); |
| 2594 | if (dai == NULL) { |
| 2595 | ret = -ENOMEM; |
| 2596 | goto err; |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | return 0; |
| 2601 | |
| 2602 | err: |
| 2603 | snd_soc_unregister_dais(component); |
| 2604 | |
| 2605 | return ret; |
| 2606 | } |
| 2607 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2608 | static int snd_soc_component_initialize(struct snd_soc_component *component, |
| 2609 | const struct snd_soc_component_driver *driver, struct device *dev) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2610 | { |
Kuninori Morimoto | 8d92bb5 | 2019-08-20 14:05:16 +0900 | [diff] [blame] | 2611 | INIT_LIST_HEAD(&component->dai_list); |
Kuninori Morimoto | 495efdb | 2019-08-20 14:05:20 +0900 | [diff] [blame] | 2612 | INIT_LIST_HEAD(&component->dobj_list); |
| 2613 | INIT_LIST_HEAD(&component->card_list); |
Kuninori Morimoto | 8d92bb5 | 2019-08-20 14:05:16 +0900 | [diff] [blame] | 2614 | mutex_init(&component->io_mutex); |
| 2615 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2616 | component->name = fmt_single_name(dev, &component->id); |
| 2617 | if (!component->name) { |
| 2618 | dev_err(dev, "ASoC: Failed to allocate name\n"); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2619 | return -ENOMEM; |
| 2620 | } |
| 2621 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2622 | component->dev = dev; |
| 2623 | component->driver = driver; |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 2624 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2625 | return 0; |
| 2626 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2627 | |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2628 | 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] | 2629 | { |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2630 | int val_bytes = regmap_get_val_bytes(component->regmap); |
| 2631 | |
| 2632 | /* Errors are legitimate for non-integer byte multiples */ |
| 2633 | if (val_bytes > 0) |
| 2634 | component->val_bytes = val_bytes; |
Lars-Peter Clausen | 886f569 | 2014-08-19 15:51:28 +0200 | [diff] [blame] | 2635 | } |
| 2636 | |
Lars-Peter Clausen | e874bf5 | 2014-11-25 21:41:03 +0100 | [diff] [blame] | 2637 | #ifdef CONFIG_REGMAP |
| 2638 | |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2639 | /** |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2640 | * snd_soc_component_init_regmap() - Initialize regmap instance for the |
| 2641 | * component |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2642 | * @component: The component for which to initialize the regmap instance |
| 2643 | * @regmap: The regmap instance that should be used by the component |
| 2644 | * |
| 2645 | * This function allows deferred assignment of the regmap instance that is |
| 2646 | * associated with the component. Only use this if the regmap instance is not |
| 2647 | * yet ready when the component is registered. The function must also be called |
| 2648 | * before the first IO attempt of the component. |
| 2649 | */ |
| 2650 | void snd_soc_component_init_regmap(struct snd_soc_component *component, |
| 2651 | struct regmap *regmap) |
| 2652 | { |
| 2653 | component->regmap = regmap; |
| 2654 | snd_soc_component_setup_regmap(component); |
| 2655 | } |
| 2656 | EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap); |
| 2657 | |
| 2658 | /** |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 2659 | * snd_soc_component_exit_regmap() - De-initialize regmap instance for the |
| 2660 | * component |
Lars-Peter Clausen | 20feb88 | 2014-11-18 19:45:52 +0100 | [diff] [blame] | 2661 | * @component: The component for which to de-initialize the regmap instance |
| 2662 | * |
| 2663 | * Calls regmap_exit() on the regmap instance associated to the component and |
| 2664 | * removes the regmap instance from the component. |
| 2665 | * |
| 2666 | * This function should only be used if snd_soc_component_init_regmap() was used |
| 2667 | * to initialize the regmap instance. |
| 2668 | */ |
| 2669 | void snd_soc_component_exit_regmap(struct snd_soc_component *component) |
| 2670 | { |
| 2671 | regmap_exit(component->regmap); |
| 2672 | component->regmap = NULL; |
| 2673 | } |
| 2674 | EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); |
| 2675 | |
Lars-Peter Clausen | e874bf5 | 2014-11-25 21:41:03 +0100 | [diff] [blame] | 2676 | #endif |
| 2677 | |
Kuninori Morimoto | 273d778 | 2017-10-11 01:38:29 +0000 | [diff] [blame] | 2678 | #define ENDIANNESS_MAP(name) \ |
| 2679 | (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE) |
| 2680 | static u64 endianness_format_map[] = { |
| 2681 | ENDIANNESS_MAP(S16_), |
| 2682 | ENDIANNESS_MAP(U16_), |
| 2683 | ENDIANNESS_MAP(S24_), |
| 2684 | ENDIANNESS_MAP(U24_), |
| 2685 | ENDIANNESS_MAP(S32_), |
| 2686 | ENDIANNESS_MAP(U32_), |
| 2687 | ENDIANNESS_MAP(S24_3), |
| 2688 | ENDIANNESS_MAP(U24_3), |
| 2689 | ENDIANNESS_MAP(S20_3), |
| 2690 | ENDIANNESS_MAP(U20_3), |
| 2691 | ENDIANNESS_MAP(S18_3), |
| 2692 | ENDIANNESS_MAP(U18_3), |
| 2693 | ENDIANNESS_MAP(FLOAT_), |
| 2694 | ENDIANNESS_MAP(FLOAT64_), |
| 2695 | ENDIANNESS_MAP(IEC958_SUBFRAME_), |
| 2696 | }; |
| 2697 | |
| 2698 | /* |
| 2699 | * Fix up the DAI formats for endianness: codecs don't actually see |
| 2700 | * the endianness of the data but we're using the CPU format |
| 2701 | * definitions which do need to include endianness so we ensure that |
| 2702 | * codec DAIs always have both big and little endian variants set. |
| 2703 | */ |
| 2704 | static void convert_endianness_formats(struct snd_soc_pcm_stream *stream) |
| 2705 | { |
| 2706 | int i; |
| 2707 | |
| 2708 | for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++) |
| 2709 | if (stream->formats & endianness_format_map[i]) |
| 2710 | stream->formats |= endianness_format_map[i]; |
| 2711 | } |
| 2712 | |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2713 | static void snd_soc_try_rebind_card(void) |
| 2714 | { |
| 2715 | struct snd_soc_card *card, *c; |
| 2716 | |
Kuninori Morimoto | b245d27 | 2019-08-07 10:31:19 +0900 | [diff] [blame] | 2717 | list_for_each_entry_safe(card, c, &unbind_card_list, list) |
| 2718 | if (!snd_soc_bind_card(card)) |
| 2719 | list_del(&card->list); |
Srinivas Kandagatla | e894efe | 2018-09-12 10:15:00 +0100 | [diff] [blame] | 2720 | } |
| 2721 | |
Kuninori Morimoto | 486c797 | 2019-11-05 15:46:39 +0900 | [diff] [blame] | 2722 | static void snd_soc_del_component_unlocked(struct snd_soc_component *component) |
| 2723 | { |
Kuninori Morimoto | b18768f | 2019-11-05 15:46:45 +0900 | [diff] [blame] | 2724 | struct snd_soc_card *card = component->card; |
| 2725 | |
Kuninori Morimoto | 486c797 | 2019-11-05 15:46:39 +0900 | [diff] [blame] | 2726 | snd_soc_unregister_dais(component); |
Kuninori Morimoto | b18768f | 2019-11-05 15:46:45 +0900 | [diff] [blame] | 2727 | |
| 2728 | if (card) |
| 2729 | snd_soc_unbind_card(card, false); |
| 2730 | |
| 2731 | list_del(&component->list); |
Kuninori Morimoto | 486c797 | 2019-11-05 15:46:39 +0900 | [diff] [blame] | 2732 | } |
| 2733 | |
Kuninori Morimoto | e0dac41 | 2017-10-02 05:10:17 +0000 | [diff] [blame] | 2734 | int snd_soc_add_component(struct device *dev, |
| 2735 | struct snd_soc_component *component, |
| 2736 | const struct snd_soc_component_driver *component_driver, |
| 2737 | struct snd_soc_dai_driver *dai_drv, |
| 2738 | int num_dai) |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2739 | { |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2740 | int ret; |
Kuninori Morimoto | 273d778 | 2017-10-11 01:38:29 +0000 | [diff] [blame] | 2741 | int i; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2742 | |
Kuninori Morimoto | b18768f | 2019-11-05 15:46:45 +0900 | [diff] [blame] | 2743 | mutex_lock(&client_mutex); |
| 2744 | |
Kuninori Morimoto | cf9e829 | 2017-08-07 02:06:23 +0000 | [diff] [blame] | 2745 | ret = snd_soc_component_initialize(component, component_driver, dev); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2746 | if (ret) |
| 2747 | goto err_free; |
| 2748 | |
Kuninori Morimoto | 273d778 | 2017-10-11 01:38:29 +0000 | [diff] [blame] | 2749 | if (component_driver->endianness) { |
| 2750 | for (i = 0; i < num_dai; i++) { |
| 2751 | convert_endianness_formats(&dai_drv[i].playback); |
| 2752 | convert_endianness_formats(&dai_drv[i].capture); |
| 2753 | } |
| 2754 | } |
| 2755 | |
Kuninori Morimoto | 0e7b25c | 2018-05-08 03:23:01 +0000 | [diff] [blame] | 2756 | ret = snd_soc_register_dais(component, dai_drv, num_dai); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2757 | if (ret < 0) { |
Masanari Iida | f42cf8d | 2015-02-24 23:11:26 +0900 | [diff] [blame] | 2758 | dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2759 | goto err_cleanup; |
| 2760 | } |
| 2761 | |
Kuninori Morimoto | b18768f | 2019-11-05 15:46:45 +0900 | [diff] [blame] | 2762 | if (!component->driver->write && !component->driver->read) { |
| 2763 | if (!component->regmap) |
| 2764 | component->regmap = dev_get_regmap(component->dev, |
| 2765 | NULL); |
| 2766 | if (component->regmap) |
| 2767 | snd_soc_component_setup_regmap(component); |
| 2768 | } |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2769 | |
Kuninori Morimoto | b18768f | 2019-11-05 15:46:45 +0900 | [diff] [blame] | 2770 | /* see for_each_component */ |
| 2771 | list_add(&component->list, &component_list); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2772 | |
| 2773 | err_cleanup: |
Kuninori Morimoto | b18768f | 2019-11-05 15:46:45 +0900 | [diff] [blame] | 2774 | if (ret < 0) |
| 2775 | snd_soc_del_component_unlocked(component); |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2776 | err_free: |
Kuninori Morimoto | b18768f | 2019-11-05 15:46:45 +0900 | [diff] [blame] | 2777 | mutex_unlock(&client_mutex); |
| 2778 | |
| 2779 | if (ret == 0) |
| 2780 | snd_soc_try_rebind_card(); |
| 2781 | |
Lars-Peter Clausen | bb13109 | 2014-06-16 18:13:03 +0200 | [diff] [blame] | 2782 | return ret; |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2783 | } |
Kuninori Morimoto | e0dac41 | 2017-10-02 05:10:17 +0000 | [diff] [blame] | 2784 | EXPORT_SYMBOL_GPL(snd_soc_add_component); |
| 2785 | |
| 2786 | int snd_soc_register_component(struct device *dev, |
| 2787 | const struct snd_soc_component_driver *component_driver, |
| 2788 | struct snd_soc_dai_driver *dai_drv, |
| 2789 | int num_dai) |
| 2790 | { |
| 2791 | struct snd_soc_component *component; |
| 2792 | |
Kuninori Morimoto | 7ecbd6a | 2018-03-19 07:27:17 +0000 | [diff] [blame] | 2793 | component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL); |
Kuninori Morimoto | 08e61d0 | 2017-10-02 05:10:33 +0000 | [diff] [blame] | 2794 | if (!component) |
Kuninori Morimoto | e0dac41 | 2017-10-02 05:10:17 +0000 | [diff] [blame] | 2795 | return -ENOMEM; |
Kuninori Morimoto | e0dac41 | 2017-10-02 05:10:17 +0000 | [diff] [blame] | 2796 | |
| 2797 | return snd_soc_add_component(dev, component, component_driver, |
| 2798 | dai_drv, num_dai); |
| 2799 | } |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2800 | EXPORT_SYMBOL_GPL(snd_soc_register_component); |
| 2801 | |
| 2802 | /** |
Kuninori Morimoto | 2eccea8 | 2017-08-07 02:06:55 +0000 | [diff] [blame] | 2803 | * snd_soc_unregister_component - Unregister all related component |
| 2804 | * from the ASoC core |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2805 | * |
Jonathan Corbet | 628536e | 2015-08-25 01:14:48 -0600 | [diff] [blame] | 2806 | * @dev: The device to unregister |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2807 | */ |
Kuninori Morimoto | 2eccea8 | 2017-08-07 02:06:55 +0000 | [diff] [blame] | 2808 | void snd_soc_unregister_component(struct device *dev) |
| 2809 | { |
Kuninori Morimoto | ac6a4dd | 2019-11-05 15:46:51 +0900 | [diff] [blame] | 2810 | struct snd_soc_component *component; |
| 2811 | |
| 2812 | mutex_lock(&client_mutex); |
| 2813 | while (1) { |
Kuninori Morimoto | 18dd66e | 2019-11-06 16:05:05 +0900 | [diff] [blame] | 2814 | component = snd_soc_lookup_component_nolocked(dev, NULL); |
Kuninori Morimoto | ac6a4dd | 2019-11-05 15:46:51 +0900 | [diff] [blame] | 2815 | if (!component) |
| 2816 | break; |
| 2817 | |
| 2818 | snd_soc_del_component_unlocked(component); |
| 2819 | } |
| 2820 | mutex_unlock(&client_mutex); |
Kuninori Morimoto | d191bd8 | 2013-09-04 19:39:03 -0700 | [diff] [blame] | 2821 | } |
| 2822 | EXPORT_SYMBOL_GPL(snd_soc_unregister_component); |
| 2823 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 2824 | /* Retrieve a card's name from device tree */ |
Kuninori Morimoto | b07609ce | 2017-01-27 06:37:51 +0000 | [diff] [blame] | 2825 | int snd_soc_of_parse_card_name(struct snd_soc_card *card, |
| 2826 | const char *propname) |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 2827 | { |
Kuninori Morimoto | b07609ce | 2017-01-27 06:37:51 +0000 | [diff] [blame] | 2828 | struct device_node *np; |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 2829 | int ret; |
| 2830 | |
Tushar Behera | 7e07e7c | 2014-07-04 14:23:00 +0530 | [diff] [blame] | 2831 | if (!card->dev) { |
| 2832 | pr_err("card->dev is not set before calling %s\n", __func__); |
| 2833 | return -EINVAL; |
| 2834 | } |
| 2835 | |
Kuninori Morimoto | b07609ce | 2017-01-27 06:37:51 +0000 | [diff] [blame] | 2836 | np = card->dev->of_node; |
Tushar Behera | 7e07e7c | 2014-07-04 14:23:00 +0530 | [diff] [blame] | 2837 | |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 2838 | ret = of_property_read_string_index(np, propname, 0, &card->name); |
| 2839 | /* |
| 2840 | * EINVAL means the property does not exist. This is fine providing |
| 2841 | * card->name was previously set, which is checked later in |
| 2842 | * snd_soc_register_card. |
| 2843 | */ |
| 2844 | if (ret < 0 && ret != -EINVAL) { |
| 2845 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 2846 | "ASoC: Property '%s' could not be read: %d\n", |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 2847 | propname, ret); |
| 2848 | return ret; |
| 2849 | } |
| 2850 | |
| 2851 | return 0; |
| 2852 | } |
Kuninori Morimoto | b07609ce | 2017-01-27 06:37:51 +0000 | [diff] [blame] | 2853 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name); |
Stephen Warren | bec4fa0 | 2011-12-12 15:55:34 -0700 | [diff] [blame] | 2854 | |
Xiubo Li | 9a6d486 | 2014-02-08 15:59:52 +0800 | [diff] [blame] | 2855 | static const struct snd_soc_dapm_widget simple_widgets[] = { |
| 2856 | SND_SOC_DAPM_MIC("Microphone", NULL), |
| 2857 | SND_SOC_DAPM_LINE("Line", NULL), |
| 2858 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 2859 | SND_SOC_DAPM_SPK("Speaker", NULL), |
| 2860 | }; |
| 2861 | |
Kuninori Morimoto | 21efde5 | 2017-01-27 06:37:34 +0000 | [diff] [blame] | 2862 | 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] | 2863 | const char *propname) |
| 2864 | { |
Kuninori Morimoto | 21efde5 | 2017-01-27 06:37:34 +0000 | [diff] [blame] | 2865 | struct device_node *np = card->dev->of_node; |
Xiubo Li | 9a6d486 | 2014-02-08 15:59:52 +0800 | [diff] [blame] | 2866 | struct snd_soc_dapm_widget *widgets; |
| 2867 | const char *template, *wname; |
| 2868 | int i, j, num_widgets, ret; |
| 2869 | |
| 2870 | num_widgets = of_property_count_strings(np, propname); |
| 2871 | if (num_widgets < 0) { |
| 2872 | dev_err(card->dev, |
| 2873 | "ASoC: Property '%s' does not exist\n", propname); |
| 2874 | return -EINVAL; |
| 2875 | } |
| 2876 | if (num_widgets & 1) { |
| 2877 | dev_err(card->dev, |
| 2878 | "ASoC: Property '%s' length is not even\n", propname); |
| 2879 | return -EINVAL; |
| 2880 | } |
| 2881 | |
| 2882 | num_widgets /= 2; |
| 2883 | if (!num_widgets) { |
| 2884 | dev_err(card->dev, "ASoC: Property '%s's length is zero\n", |
| 2885 | propname); |
| 2886 | return -EINVAL; |
| 2887 | } |
| 2888 | |
| 2889 | widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets), |
| 2890 | GFP_KERNEL); |
| 2891 | if (!widgets) { |
| 2892 | dev_err(card->dev, |
| 2893 | "ASoC: Could not allocate memory for widgets\n"); |
| 2894 | return -ENOMEM; |
| 2895 | } |
| 2896 | |
| 2897 | for (i = 0; i < num_widgets; i++) { |
| 2898 | ret = of_property_read_string_index(np, propname, |
| 2899 | 2 * i, &template); |
| 2900 | if (ret) { |
| 2901 | dev_err(card->dev, |
| 2902 | "ASoC: Property '%s' index %d read error:%d\n", |
| 2903 | propname, 2 * i, ret); |
| 2904 | return -EINVAL; |
| 2905 | } |
| 2906 | |
| 2907 | for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) { |
| 2908 | if (!strncmp(template, simple_widgets[j].name, |
| 2909 | strlen(simple_widgets[j].name))) { |
| 2910 | widgets[i] = simple_widgets[j]; |
| 2911 | break; |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | if (j >= ARRAY_SIZE(simple_widgets)) { |
| 2916 | dev_err(card->dev, |
| 2917 | "ASoC: DAPM widget '%s' is not supported\n", |
| 2918 | template); |
| 2919 | return -EINVAL; |
| 2920 | } |
| 2921 | |
| 2922 | ret = of_property_read_string_index(np, propname, |
| 2923 | (2 * i) + 1, |
| 2924 | &wname); |
| 2925 | if (ret) { |
| 2926 | dev_err(card->dev, |
| 2927 | "ASoC: Property '%s' index %d read error:%d\n", |
| 2928 | propname, (2 * i) + 1, ret); |
| 2929 | return -EINVAL; |
| 2930 | } |
| 2931 | |
| 2932 | widgets[i].name = wname; |
| 2933 | } |
| 2934 | |
Nicolin Chen | f23e860 | 2015-02-14 17:22:49 -0800 | [diff] [blame] | 2935 | card->of_dapm_widgets = widgets; |
| 2936 | card->num_of_dapm_widgets = num_widgets; |
Xiubo Li | 9a6d486 | 2014-02-08 15:59:52 +0800 | [diff] [blame] | 2937 | |
| 2938 | return 0; |
| 2939 | } |
Kuninori Morimoto | 21efde5 | 2017-01-27 06:37:34 +0000 | [diff] [blame] | 2940 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets); |
Xiubo Li | 9a6d486 | 2014-02-08 15:59:52 +0800 | [diff] [blame] | 2941 | |
Jerome Brunet | cbdfab3 | 2018-07-17 17:43:02 +0200 | [diff] [blame] | 2942 | int snd_soc_of_get_slot_mask(struct device_node *np, |
| 2943 | const char *prop_name, |
| 2944 | unsigned int *mask) |
Jyri Sarha | 6131084 | 2015-09-09 21:27:43 +0300 | [diff] [blame] | 2945 | { |
| 2946 | u32 val; |
Jyri Sarha | 6c84e591 | 2015-09-17 13:13:38 +0300 | [diff] [blame] | 2947 | const __be32 *of_slot_mask = of_get_property(np, prop_name, &val); |
Jyri Sarha | 6131084 | 2015-09-09 21:27:43 +0300 | [diff] [blame] | 2948 | int i; |
| 2949 | |
| 2950 | if (!of_slot_mask) |
| 2951 | return 0; |
| 2952 | val /= sizeof(u32); |
| 2953 | for (i = 0; i < val; i++) |
| 2954 | if (be32_to_cpup(&of_slot_mask[i])) |
| 2955 | *mask |= (1 << i); |
| 2956 | |
| 2957 | return val; |
| 2958 | } |
Jerome Brunet | cbdfab3 | 2018-07-17 17:43:02 +0200 | [diff] [blame] | 2959 | EXPORT_SYMBOL_GPL(snd_soc_of_get_slot_mask); |
Jyri Sarha | 6131084 | 2015-09-09 21:27:43 +0300 | [diff] [blame] | 2960 | |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2961 | int snd_soc_of_parse_tdm_slot(struct device_node *np, |
Jyri Sarha | 6131084 | 2015-09-09 21:27:43 +0300 | [diff] [blame] | 2962 | unsigned int *tx_mask, |
| 2963 | unsigned int *rx_mask, |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2964 | unsigned int *slots, |
| 2965 | unsigned int *slot_width) |
| 2966 | { |
| 2967 | u32 val; |
| 2968 | int ret; |
| 2969 | |
Jyri Sarha | 6131084 | 2015-09-09 21:27:43 +0300 | [diff] [blame] | 2970 | if (tx_mask) |
| 2971 | snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask); |
| 2972 | if (rx_mask) |
| 2973 | snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask); |
| 2974 | |
Xiubo Li | 89c6785 | 2014-02-14 09:34:35 +0800 | [diff] [blame] | 2975 | if (of_property_read_bool(np, "dai-tdm-slot-num")) { |
| 2976 | ret = of_property_read_u32(np, "dai-tdm-slot-num", &val); |
| 2977 | if (ret) |
| 2978 | return ret; |
| 2979 | |
| 2980 | if (slots) |
| 2981 | *slots = val; |
| 2982 | } |
| 2983 | |
| 2984 | if (of_property_read_bool(np, "dai-tdm-slot-width")) { |
| 2985 | ret = of_property_read_u32(np, "dai-tdm-slot-width", &val); |
| 2986 | if (ret) |
| 2987 | return ret; |
| 2988 | |
| 2989 | if (slot_width) |
| 2990 | *slot_width = val; |
| 2991 | } |
| 2992 | |
| 2993 | return 0; |
| 2994 | } |
| 2995 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot); |
| 2996 | |
Kuninori Morimoto | 3b71035 | 2018-11-22 00:55:09 +0000 | [diff] [blame] | 2997 | void snd_soc_of_parse_node_prefix(struct device_node *np, |
| 2998 | struct snd_soc_codec_conf *codec_conf, |
| 2999 | struct device_node *of_node, |
| 3000 | const char *propname) |
Kuninori Morimoto | 5e3cdaa | 2015-07-15 07:07:42 +0000 | [diff] [blame] | 3001 | { |
Kuninori Morimoto | 5e3cdaa | 2015-07-15 07:07:42 +0000 | [diff] [blame] | 3002 | const char *str; |
| 3003 | int ret; |
| 3004 | |
| 3005 | ret = of_property_read_string(np, propname, &str); |
| 3006 | if (ret < 0) { |
| 3007 | /* no prefix is not error */ |
| 3008 | return; |
| 3009 | } |
| 3010 | |
| 3011 | codec_conf->of_node = of_node; |
| 3012 | codec_conf->name_prefix = str; |
| 3013 | } |
Kuninori Morimoto | 3b71035 | 2018-11-22 00:55:09 +0000 | [diff] [blame] | 3014 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_node_prefix); |
Kuninori Morimoto | 5e3cdaa | 2015-07-15 07:07:42 +0000 | [diff] [blame] | 3015 | |
Kuninori Morimoto | 2bc644a | 2017-01-27 06:36:50 +0000 | [diff] [blame] | 3016 | int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3017 | const char *propname) |
| 3018 | { |
Kuninori Morimoto | 2bc644a | 2017-01-27 06:36:50 +0000 | [diff] [blame] | 3019 | struct device_node *np = card->dev->of_node; |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3020 | int num_routes; |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3021 | struct snd_soc_dapm_route *routes; |
| 3022 | int i, ret; |
| 3023 | |
| 3024 | num_routes = of_property_count_strings(np, propname); |
Richard Zhao | c34ce32 | 2012-04-24 15:24:43 +0800 | [diff] [blame] | 3025 | if (num_routes < 0 || num_routes & 1) { |
Michał Mirosław | 10e8aa9 | 2013-05-04 22:21:38 +0200 | [diff] [blame] | 3026 | dev_err(card->dev, |
| 3027 | "ASoC: Property '%s' does not exist or its length is not even\n", |
| 3028 | propname); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3029 | return -EINVAL; |
| 3030 | } |
| 3031 | num_routes /= 2; |
| 3032 | if (!num_routes) { |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3033 | dev_err(card->dev, "ASoC: Property '%s's length is zero\n", |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3034 | propname); |
| 3035 | return -EINVAL; |
| 3036 | } |
| 3037 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 3038 | routes = devm_kcalloc(card->dev, num_routes, sizeof(*routes), |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3039 | GFP_KERNEL); |
| 3040 | if (!routes) { |
| 3041 | dev_err(card->dev, |
Liam Girdwood | f110bfc | 2012-11-19 14:47:09 +0000 | [diff] [blame] | 3042 | "ASoC: Could not allocate DAPM route table\n"); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3043 | return -EINVAL; |
| 3044 | } |
| 3045 | |
| 3046 | for (i = 0; i < num_routes; i++) { |
| 3047 | ret = of_property_read_string_index(np, propname, |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3048 | 2 * i, &routes[i].sink); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3049 | if (ret) { |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 3050 | dev_err(card->dev, |
| 3051 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 3052 | propname, 2 * i, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3053 | return -EINVAL; |
| 3054 | } |
| 3055 | ret = of_property_read_string_index(np, propname, |
Mark Brown | e3b1e6a | 2014-12-18 11:46:38 +0000 | [diff] [blame] | 3056 | (2 * i) + 1, &routes[i].source); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3057 | if (ret) { |
| 3058 | dev_err(card->dev, |
Mark Brown | c871bd0 | 2012-12-10 16:19:52 +0900 | [diff] [blame] | 3059 | "ASoC: Property '%s' index %d could not be read: %d\n", |
| 3060 | propname, (2 * i) + 1, ret); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3061 | return -EINVAL; |
| 3062 | } |
| 3063 | } |
| 3064 | |
Nicolin Chen | f23e860 | 2015-02-14 17:22:49 -0800 | [diff] [blame] | 3065 | card->num_of_dapm_routes = num_routes; |
| 3066 | card->of_dapm_routes = routes; |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3067 | |
| 3068 | return 0; |
| 3069 | } |
Kuninori Morimoto | 2bc644a | 2017-01-27 06:36:50 +0000 | [diff] [blame] | 3070 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing); |
Stephen Warren | a4a54dd | 2011-12-12 15:55:35 -0700 | [diff] [blame] | 3071 | |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3072 | unsigned int snd_soc_of_parse_daifmt(struct device_node *np, |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3073 | const char *prefix, |
| 3074 | struct device_node **bitclkmaster, |
| 3075 | struct device_node **framemaster) |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3076 | { |
| 3077 | int ret, i; |
| 3078 | char prop[128]; |
| 3079 | unsigned int format = 0; |
| 3080 | int bit, frame; |
| 3081 | const char *str; |
| 3082 | struct { |
| 3083 | char *name; |
| 3084 | unsigned int val; |
| 3085 | } of_fmt_table[] = { |
| 3086 | { "i2s", SND_SOC_DAIFMT_I2S }, |
| 3087 | { "right_j", SND_SOC_DAIFMT_RIGHT_J }, |
| 3088 | { "left_j", SND_SOC_DAIFMT_LEFT_J }, |
| 3089 | { "dsp_a", SND_SOC_DAIFMT_DSP_A }, |
| 3090 | { "dsp_b", SND_SOC_DAIFMT_DSP_B }, |
| 3091 | { "ac97", SND_SOC_DAIFMT_AC97 }, |
| 3092 | { "pdm", SND_SOC_DAIFMT_PDM}, |
| 3093 | { "msb", SND_SOC_DAIFMT_MSB }, |
| 3094 | { "lsb", SND_SOC_DAIFMT_LSB }, |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3095 | }; |
| 3096 | |
| 3097 | if (!prefix) |
| 3098 | prefix = ""; |
| 3099 | |
| 3100 | /* |
Kuninori Morimoto | 5711c97 | 2017-04-20 01:33:24 +0000 | [diff] [blame] | 3101 | * check "dai-format = xxx" |
| 3102 | * or "[prefix]format = xxx" |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3103 | * SND_SOC_DAIFMT_FORMAT_MASK area |
| 3104 | */ |
Kuninori Morimoto | 5711c97 | 2017-04-20 01:33:24 +0000 | [diff] [blame] | 3105 | ret = of_property_read_string(np, "dai-format", &str); |
| 3106 | if (ret < 0) { |
| 3107 | snprintf(prop, sizeof(prop), "%sformat", prefix); |
| 3108 | ret = of_property_read_string(np, prop, &str); |
| 3109 | } |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3110 | if (ret == 0) { |
| 3111 | for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) { |
| 3112 | if (strcmp(str, of_fmt_table[i].name) == 0) { |
| 3113 | format |= of_fmt_table[i].val; |
| 3114 | break; |
| 3115 | } |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | /* |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 3120 | * check "[prefix]continuous-clock" |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3121 | * SND_SOC_DAIFMT_CLOCK_MASK area |
| 3122 | */ |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 3123 | snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); |
Julia Lawall | 5193029 | 2016-08-05 10:56:51 +0200 | [diff] [blame] | 3124 | if (of_property_read_bool(np, prop)) |
Kuninori Morimoto | 8c2d6a9 | 2013-01-29 21:03:36 -0800 | [diff] [blame] | 3125 | format |= SND_SOC_DAIFMT_CONT; |
| 3126 | else |
| 3127 | format |= SND_SOC_DAIFMT_GATED; |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3128 | |
| 3129 | /* |
| 3130 | * check "[prefix]bitclock-inversion" |
| 3131 | * check "[prefix]frame-inversion" |
| 3132 | * SND_SOC_DAIFMT_INV_MASK area |
| 3133 | */ |
| 3134 | snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); |
| 3135 | bit = !!of_get_property(np, prop, NULL); |
| 3136 | |
| 3137 | snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); |
| 3138 | frame = !!of_get_property(np, prop, NULL); |
| 3139 | |
| 3140 | switch ((bit << 4) + frame) { |
| 3141 | case 0x11: |
| 3142 | format |= SND_SOC_DAIFMT_IB_IF; |
| 3143 | break; |
| 3144 | case 0x10: |
| 3145 | format |= SND_SOC_DAIFMT_IB_NF; |
| 3146 | break; |
| 3147 | case 0x01: |
| 3148 | format |= SND_SOC_DAIFMT_NB_IF; |
| 3149 | break; |
| 3150 | default: |
| 3151 | /* SND_SOC_DAIFMT_NB_NF is default */ |
| 3152 | break; |
| 3153 | } |
| 3154 | |
| 3155 | /* |
| 3156 | * check "[prefix]bitclock-master" |
| 3157 | * check "[prefix]frame-master" |
| 3158 | * SND_SOC_DAIFMT_MASTER_MASK area |
| 3159 | */ |
| 3160 | snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); |
| 3161 | bit = !!of_get_property(np, prop, NULL); |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3162 | if (bit && bitclkmaster) |
| 3163 | *bitclkmaster = of_parse_phandle(np, prop, 0); |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3164 | |
| 3165 | snprintf(prop, sizeof(prop), "%sframe-master", prefix); |
| 3166 | frame = !!of_get_property(np, prop, NULL); |
Jyri Sarha | 389cb83 | 2014-03-24 12:15:24 +0200 | [diff] [blame] | 3167 | if (frame && framemaster) |
| 3168 | *framemaster = of_parse_phandle(np, prop, 0); |
Kuninori Morimoto | a7930ed | 2013-01-14 18:36:04 -0800 | [diff] [blame] | 3169 | |
| 3170 | switch ((bit << 4) + frame) { |
| 3171 | case 0x11: |
| 3172 | format |= SND_SOC_DAIFMT_CBM_CFM; |
| 3173 | break; |
| 3174 | case 0x10: |
| 3175 | format |= SND_SOC_DAIFMT_CBM_CFS; |
| 3176 | break; |
| 3177 | case 0x01: |
| 3178 | format |= SND_SOC_DAIFMT_CBS_CFM; |
| 3179 | break; |
| 3180 | default: |
| 3181 | format |= SND_SOC_DAIFMT_CBS_CFS; |
| 3182 | break; |
| 3183 | } |
| 3184 | |
| 3185 | return format; |
| 3186 | } |
| 3187 | EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt); |
| 3188 | |
Kuninori Morimoto | a180e8b | 2017-05-18 01:39:25 +0000 | [diff] [blame] | 3189 | int snd_soc_get_dai_id(struct device_node *ep) |
| 3190 | { |
Kuninori Morimoto | 09d4cc0 | 2019-05-13 16:07:20 +0900 | [diff] [blame] | 3191 | struct snd_soc_component *component; |
Kuninori Morimoto | c1e230f | 2019-06-20 09:49:27 +0900 | [diff] [blame] | 3192 | struct snd_soc_dai_link_component dlc; |
Kuninori Morimoto | a180e8b | 2017-05-18 01:39:25 +0000 | [diff] [blame] | 3193 | int ret; |
| 3194 | |
Kuninori Morimoto | c1e230f | 2019-06-20 09:49:27 +0900 | [diff] [blame] | 3195 | dlc.of_node = of_graph_get_port_parent(ep); |
| 3196 | dlc.name = NULL; |
Kuninori Morimoto | a180e8b | 2017-05-18 01:39:25 +0000 | [diff] [blame] | 3197 | /* |
| 3198 | * For example HDMI case, HDMI has video/sound port, |
| 3199 | * but ALSA SoC needs sound port number only. |
| 3200 | * Thus counting HDMI DT port/endpoint doesn't work. |
| 3201 | * Then, it should have .of_xlate_dai_id |
| 3202 | */ |
| 3203 | ret = -ENOTSUPP; |
| 3204 | mutex_lock(&client_mutex); |
Kuninori Morimoto | c1e230f | 2019-06-20 09:49:27 +0900 | [diff] [blame] | 3205 | component = soc_find_component(&dlc); |
Kuninori Morimoto | 2c7b170 | 2019-07-26 13:51:26 +0900 | [diff] [blame] | 3206 | if (component) |
| 3207 | ret = snd_soc_component_of_xlate_dai_id(component, ep); |
Kuninori Morimoto | a180e8b | 2017-05-18 01:39:25 +0000 | [diff] [blame] | 3208 | mutex_unlock(&client_mutex); |
| 3209 | |
Kuninori Morimoto | c1e230f | 2019-06-20 09:49:27 +0900 | [diff] [blame] | 3210 | of_node_put(dlc.of_node); |
Tony Lindgren | c0a480d | 2017-07-28 01:23:15 -0700 | [diff] [blame] | 3211 | |
Kuninori Morimoto | a180e8b | 2017-05-18 01:39:25 +0000 | [diff] [blame] | 3212 | return ret; |
| 3213 | } |
| 3214 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_id); |
| 3215 | |
Kuninori Morimoto | 1ad8ec5 | 2016-11-11 01:19:28 +0000 | [diff] [blame] | 3216 | int snd_soc_get_dai_name(struct of_phandle_args *args, |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3217 | const char **dai_name) |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3218 | { |
| 3219 | struct snd_soc_component *pos; |
Jyri Sarha | 3e0aa8d | 2015-05-26 21:59:05 +0300 | [diff] [blame] | 3220 | struct device_node *component_of_node; |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3221 | int ret = -EPROBE_DEFER; |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3222 | |
| 3223 | mutex_lock(&client_mutex); |
Kuninori Morimoto | 368dee9 | 2018-09-21 05:23:01 +0000 | [diff] [blame] | 3224 | for_each_component(pos) { |
Kuninori Morimoto | c083444 | 2019-05-13 16:06:59 +0900 | [diff] [blame] | 3225 | component_of_node = soc_component_to_node(pos); |
Jyri Sarha | 3e0aa8d | 2015-05-26 21:59:05 +0300 | [diff] [blame] | 3226 | |
| 3227 | if (component_of_node != args->np) |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3228 | continue; |
| 3229 | |
Kuninori Morimoto | a2a3417 | 2019-07-26 13:51:31 +0900 | [diff] [blame] | 3230 | ret = snd_soc_component_of_xlate_dai_name(pos, args, dai_name); |
| 3231 | if (ret == -ENOTSUPP) { |
Kuninori Morimoto | 58bf417 | 2017-12-20 01:48:29 +0000 | [diff] [blame] | 3232 | struct snd_soc_dai *dai; |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3233 | int id = -1; |
| 3234 | |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3235 | switch (args->args_count) { |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3236 | case 0: |
| 3237 | id = 0; /* same as dai_drv[0] */ |
| 3238 | break; |
| 3239 | case 1: |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3240 | id = args->args[0]; |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3241 | break; |
| 3242 | default: |
| 3243 | /* not supported */ |
| 3244 | break; |
| 3245 | } |
| 3246 | |
| 3247 | if (id < 0 || id >= pos->num_dai) { |
| 3248 | ret = -EINVAL; |
Nicolin Chen | 3dcba28 | 2014-04-21 19:14:46 +0800 | [diff] [blame] | 3249 | continue; |
Kuninori Morimoto | 6833c45 | 2013-10-16 22:05:26 -0700 | [diff] [blame] | 3250 | } |
Xiubo Li | e41975e | 2013-12-20 14:39:51 +0800 | [diff] [blame] | 3251 | |
| 3252 | ret = 0; |
| 3253 | |
Kuninori Morimoto | 58bf417 | 2017-12-20 01:48:29 +0000 | [diff] [blame] | 3254 | /* find target DAI */ |
Kuninori Morimoto | 15a0c64 | 2018-09-21 05:23:17 +0000 | [diff] [blame] | 3255 | for_each_component_dais(pos, dai) { |
Kuninori Morimoto | 58bf417 | 2017-12-20 01:48:29 +0000 | [diff] [blame] | 3256 | if (id == 0) |
| 3257 | break; |
| 3258 | id--; |
| 3259 | } |
| 3260 | |
| 3261 | *dai_name = dai->driver->name; |
Xiubo Li | e41975e | 2013-12-20 14:39:51 +0800 | [diff] [blame] | 3262 | if (!*dai_name) |
| 3263 | *dai_name = pos->name; |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3266 | break; |
| 3267 | } |
| 3268 | mutex_unlock(&client_mutex); |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3269 | return ret; |
| 3270 | } |
Kuninori Morimoto | 1ad8ec5 | 2016-11-11 01:19:28 +0000 | [diff] [blame] | 3271 | EXPORT_SYMBOL_GPL(snd_soc_get_dai_name); |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3272 | |
| 3273 | int snd_soc_of_get_dai_name(struct device_node *of_node, |
| 3274 | const char **dai_name) |
| 3275 | { |
| 3276 | struct of_phandle_args args; |
| 3277 | int ret; |
| 3278 | |
| 3279 | ret = of_parse_phandle_with_args(of_node, "sound-dai", |
| 3280 | "#sound-dai-cells", 0, &args); |
| 3281 | if (ret) |
| 3282 | return ret; |
| 3283 | |
| 3284 | ret = snd_soc_get_dai_name(&args, dai_name); |
Kuninori Morimoto | cb47008 | 2013-09-10 17:39:56 -0700 | [diff] [blame] | 3285 | |
| 3286 | of_node_put(args.np); |
| 3287 | |
| 3288 | return ret; |
| 3289 | } |
| 3290 | EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name); |
| 3291 | |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3292 | /* |
Sylwester Nawrocki | 9468576 | 2018-03-09 18:48:54 +0100 | [diff] [blame] | 3293 | * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array |
| 3294 | * @dai_link: DAI link |
| 3295 | * |
| 3296 | * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs(). |
| 3297 | */ |
| 3298 | void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link) |
| 3299 | { |
Kuninori Morimoto | 3db769f | 2018-09-03 02:12:40 +0000 | [diff] [blame] | 3300 | struct snd_soc_dai_link_component *component; |
Sylwester Nawrocki | 9468576 | 2018-03-09 18:48:54 +0100 | [diff] [blame] | 3301 | int index; |
| 3302 | |
Kuninori Morimoto | 3db769f | 2018-09-03 02:12:40 +0000 | [diff] [blame] | 3303 | for_each_link_codecs(dai_link, index, component) { |
Sylwester Nawrocki | 9468576 | 2018-03-09 18:48:54 +0100 | [diff] [blame] | 3304 | if (!component->of_node) |
| 3305 | break; |
| 3306 | of_node_put(component->of_node); |
| 3307 | component->of_node = NULL; |
| 3308 | } |
| 3309 | } |
| 3310 | EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs); |
| 3311 | |
| 3312 | /* |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3313 | * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree |
| 3314 | * @dev: Card device |
| 3315 | * @of_node: Device node |
| 3316 | * @dai_link: DAI link |
| 3317 | * |
| 3318 | * Builds an array of CODEC DAI components from the DAI link property |
| 3319 | * 'sound-dai'. |
| 3320 | * The array is set in the DAI link and the number of DAIs is set accordingly. |
Sylwester Nawrocki | 9468576 | 2018-03-09 18:48:54 +0100 | [diff] [blame] | 3321 | * The device nodes in the array (of_node) must be dereferenced by calling |
| 3322 | * snd_soc_of_put_dai_link_codecs() on @dai_link. |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3323 | * |
| 3324 | * Returns 0 for success |
| 3325 | */ |
| 3326 | int snd_soc_of_get_dai_link_codecs(struct device *dev, |
| 3327 | struct device_node *of_node, |
| 3328 | struct snd_soc_dai_link *dai_link) |
| 3329 | { |
| 3330 | struct of_phandle_args args; |
| 3331 | struct snd_soc_dai_link_component *component; |
| 3332 | char *name; |
| 3333 | int index, num_codecs, ret; |
| 3334 | |
| 3335 | /* Count the number of CODECs */ |
| 3336 | name = "sound-dai"; |
| 3337 | num_codecs = of_count_phandle_with_args(of_node, name, |
| 3338 | "#sound-dai-cells"); |
| 3339 | if (num_codecs <= 0) { |
| 3340 | if (num_codecs == -ENOENT) |
| 3341 | dev_err(dev, "No 'sound-dai' property\n"); |
| 3342 | else |
| 3343 | dev_err(dev, "Bad phandle in 'sound-dai'\n"); |
| 3344 | return num_codecs; |
| 3345 | } |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 3346 | component = devm_kcalloc(dev, |
| 3347 | num_codecs, sizeof(*component), |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3348 | GFP_KERNEL); |
| 3349 | if (!component) |
| 3350 | return -ENOMEM; |
| 3351 | dai_link->codecs = component; |
| 3352 | dai_link->num_codecs = num_codecs; |
| 3353 | |
| 3354 | /* Parse the list */ |
Kuninori Morimoto | 3db769f | 2018-09-03 02:12:40 +0000 | [diff] [blame] | 3355 | for_each_link_codecs(dai_link, index, component) { |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3356 | ret = of_parse_phandle_with_args(of_node, name, |
| 3357 | "#sound-dai-cells", |
Marcel Ziswiler | 2c7b696 | 2018-10-18 13:18:28 +0200 | [diff] [blame] | 3358 | index, &args); |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3359 | if (ret) |
| 3360 | goto err; |
| 3361 | component->of_node = args.np; |
| 3362 | ret = snd_soc_get_dai_name(&args, &component->dai_name); |
| 3363 | if (ret < 0) |
| 3364 | goto err; |
| 3365 | } |
| 3366 | return 0; |
| 3367 | err: |
Sylwester Nawrocki | 9468576 | 2018-03-09 18:48:54 +0100 | [diff] [blame] | 3368 | snd_soc_of_put_dai_link_codecs(dai_link); |
Jean-Francois Moine | 93b0f3ee | 2014-11-25 13:16:12 +0100 | [diff] [blame] | 3369 | dai_link->codecs = NULL; |
| 3370 | dai_link->num_codecs = 0; |
| 3371 | return ret; |
| 3372 | } |
| 3373 | EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs); |
| 3374 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 3375 | static int __init snd_soc_init(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3376 | { |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 3377 | snd_soc_debugfs_init(); |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3378 | snd_soc_util_init(); |
| 3379 | |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3380 | return platform_driver_register(&soc_driver); |
| 3381 | } |
Mark Brown | 4abe8e1 | 2010-10-12 17:41:03 +0100 | [diff] [blame] | 3382 | module_init(snd_soc_init); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3383 | |
Mark Brown | 7d8c16a | 2008-11-30 22:11:24 +0000 | [diff] [blame] | 3384 | static void __exit snd_soc_exit(void) |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3385 | { |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3386 | snd_soc_util_exit(); |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 3387 | snd_soc_debugfs_exit(); |
Mark Brown | fb25789 | 2011-04-28 10:57:54 +0100 | [diff] [blame] | 3388 | |
Mark Brown | 3ff3f64 | 2008-05-19 12:32:25 +0200 | [diff] [blame] | 3389 | platform_driver_unregister(&soc_driver); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3390 | } |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3391 | module_exit(snd_soc_exit); |
| 3392 | |
| 3393 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 3394 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Frank Mandarino | db2a416 | 2006-10-06 18:31:09 +0200 | [diff] [blame] | 3395 | MODULE_DESCRIPTION("ALSA SoC Core"); |
| 3396 | MODULE_LICENSE("GPL"); |
Kay Sievers | 8b45a20 | 2008-04-14 13:33:36 +0200 | [diff] [blame] | 3397 | MODULE_ALIAS("platform:soc-audio"); |