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