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