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