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