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