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