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