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