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