xref: /openbmc/linux/sound/soc/soc-core.c (revision baed393e8550fa075512772fad27e98ba9dcb527)
1873486edSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0+
2873486edSKuninori Morimoto //
3873486edSKuninori Morimoto // soc-core.c  --  ALSA SoC Audio Layer
4873486edSKuninori Morimoto //
5873486edSKuninori Morimoto // Copyright 2005 Wolfson Microelectronics PLC.
6873486edSKuninori Morimoto // Copyright 2005 Openedhand Ltd.
7873486edSKuninori Morimoto // Copyright (C) 2010 Slimlogic Ltd.
8873486edSKuninori Morimoto // Copyright (C) 2010 Texas Instruments Inc.
9873486edSKuninori Morimoto //
10873486edSKuninori Morimoto // Author: Liam Girdwood <lrg@slimlogic.co.uk>
11873486edSKuninori Morimoto //         with code, comments and ideas from :-
12873486edSKuninori Morimoto //         Richard Purdie <richard@openedhand.com>
13873486edSKuninori Morimoto //
14873486edSKuninori Morimoto //  TODO:
15873486edSKuninori Morimoto //   o Add hw rules to enforce rates, etc.
16873486edSKuninori Morimoto //   o More testing with other codecs/machines.
17873486edSKuninori Morimoto //   o Add more codecs and platforms to ensure good API coverage.
18873486edSKuninori Morimoto //   o Support TDM on PCM and I2S
19db2a4165SFrank Mandarino 
20db2a4165SFrank Mandarino #include <linux/module.h>
21db2a4165SFrank Mandarino #include <linux/moduleparam.h>
22db2a4165SFrank Mandarino #include <linux/init.h>
23db2a4165SFrank Mandarino #include <linux/delay.h>
24db2a4165SFrank Mandarino #include <linux/pm.h>
25db2a4165SFrank Mandarino #include <linux/bitops.h>
2612ef193dSTroy Kisky #include <linux/debugfs.h>
27db2a4165SFrank Mandarino #include <linux/platform_device.h>
28741a509fSMarkus Pargmann #include <linux/pinctrl/consumer.h>
29f0e8ed85SMark Brown #include <linux/ctype.h>
305a0e3ad6STejun Heo #include <linux/slab.h>
31bec4fa05SStephen Warren #include <linux/of.h>
32a180e8b9SKuninori Morimoto #include <linux/of_graph.h>
33345233d7SLiam Girdwood #include <linux/dmi.h>
34db2a4165SFrank Mandarino #include <sound/core.h>
353028eb8cSMark Brown #include <sound/jack.h>
36db2a4165SFrank Mandarino #include <sound/pcm.h>
37db2a4165SFrank Mandarino #include <sound/pcm_params.h>
38db2a4165SFrank Mandarino #include <sound/soc.h>
3901d7584cSLiam Girdwood #include <sound/soc-dpcm.h>
408a978234SLiam Girdwood #include <sound/soc-topology.h>
4102e75636SKuninori Morimoto #include <sound/soc-link.h>
42db2a4165SFrank Mandarino #include <sound/initval.h>
43db2a4165SFrank Mandarino 
44a8b1d34fSMark Brown #define CREATE_TRACE_POINTS
45a8b1d34fSMark Brown #include <trace/events/asoc.h>
46a8b1d34fSMark Brown 
47c5af3a2eSMark Brown static DEFINE_MUTEX(client_mutex);
48030e79f6SKuninori Morimoto static LIST_HEAD(component_list);
49e894efefSSrinivas Kandagatla static LIST_HEAD(unbind_card_list);
50c5af3a2eSMark Brown 
51368dee94SKuninori Morimoto #define for_each_component(component)			\
52368dee94SKuninori Morimoto 	list_for_each_entry(component, &component_list, list)
53368dee94SKuninori Morimoto 
54db2a4165SFrank Mandarino /*
55587c9844SKuninori Morimoto  * This is used if driver don't need to have CPU/Codec/Platform
56587c9844SKuninori Morimoto  * dai_link. see soc.h
57587c9844SKuninori Morimoto  */
58587c9844SKuninori Morimoto struct snd_soc_dai_link_component null_dailink_component[0];
59587c9844SKuninori Morimoto EXPORT_SYMBOL_GPL(null_dailink_component);
60587c9844SKuninori Morimoto 
61587c9844SKuninori Morimoto /*
62db2a4165SFrank Mandarino  * This is a timeout to do a DAPM powerdown after a stream is closed().
63db2a4165SFrank Mandarino  * It can be used to eliminate pops between different playback streams, e.g.
64db2a4165SFrank Mandarino  * between two audio tracks.
65db2a4165SFrank Mandarino  */
66db2a4165SFrank Mandarino static int pmdown_time = 5000;
67db2a4165SFrank Mandarino module_param(pmdown_time, int, 0);
68db2a4165SFrank Mandarino MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
69db2a4165SFrank Mandarino 
70dbe21408SMark Brown static ssize_t pmdown_time_show(struct device *dev,
71dbe21408SMark Brown 				struct device_attribute *attr, char *buf)
72dbe21408SMark Brown {
7336ae1a96SMark Brown 	struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
74dbe21408SMark Brown 
75f0fba2adSLiam Girdwood 	return sprintf(buf, "%ld\n", rtd->pmdown_time);
76dbe21408SMark Brown }
77dbe21408SMark Brown 
78dbe21408SMark Brown static ssize_t pmdown_time_set(struct device *dev,
79dbe21408SMark Brown 			       struct device_attribute *attr,
80dbe21408SMark Brown 			       const char *buf, size_t count)
81dbe21408SMark Brown {
8236ae1a96SMark Brown 	struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
83c593b520SMark Brown 	int ret;
84dbe21408SMark Brown 
85b785a492SJingoo Han 	ret = kstrtol(buf, 10, &rtd->pmdown_time);
86c593b520SMark Brown 	if (ret)
87c593b520SMark Brown 		return ret;
88dbe21408SMark Brown 
89dbe21408SMark Brown 	return count;
90dbe21408SMark Brown }
91dbe21408SMark Brown 
92dbe21408SMark Brown static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
93dbe21408SMark Brown 
94d29697dcSTakashi Iwai static struct attribute *soc_dev_attrs[] = {
95d29697dcSTakashi Iwai 	&dev_attr_pmdown_time.attr,
96d29697dcSTakashi Iwai 	NULL
97d29697dcSTakashi Iwai };
98d29697dcSTakashi Iwai 
99d29697dcSTakashi Iwai static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
100d29697dcSTakashi Iwai 				       struct attribute *attr, int idx)
101d29697dcSTakashi Iwai {
102d29697dcSTakashi Iwai 	struct device *dev = kobj_to_dev(kobj);
103d29697dcSTakashi Iwai 	struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
104d29697dcSTakashi Iwai 
105d918a376SKuninori Morimoto 	if (!rtd)
106d918a376SKuninori Morimoto 		return 0;
107d918a376SKuninori Morimoto 
108d29697dcSTakashi Iwai 	if (attr == &dev_attr_pmdown_time.attr)
109d29697dcSTakashi Iwai 		return attr->mode; /* always visible */
1103b6eed8dSKuninori Morimoto 	return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */
111d29697dcSTakashi Iwai }
112d29697dcSTakashi Iwai 
113d29697dcSTakashi Iwai static const struct attribute_group soc_dapm_dev_group = {
114d29697dcSTakashi Iwai 	.attrs = soc_dapm_dev_attrs,
115d29697dcSTakashi Iwai 	.is_visible = soc_dev_attr_is_visible,
116d29697dcSTakashi Iwai };
117d29697dcSTakashi Iwai 
118f7e73b26SMark Brown static const struct attribute_group soc_dev_group = {
119d29697dcSTakashi Iwai 	.attrs = soc_dev_attrs,
120d29697dcSTakashi Iwai 	.is_visible = soc_dev_attr_is_visible,
121d29697dcSTakashi Iwai };
122d29697dcSTakashi Iwai 
123d29697dcSTakashi Iwai static const struct attribute_group *soc_dev_attr_groups[] = {
124d29697dcSTakashi Iwai 	&soc_dapm_dev_group,
125f7e73b26SMark Brown 	&soc_dev_group,
126d29697dcSTakashi Iwai 	NULL
127d29697dcSTakashi Iwai };
128d29697dcSTakashi Iwai 
1292624d5faSMark Brown #ifdef CONFIG_DEBUG_FS
130a4072cdfSKuninori Morimoto struct dentry *snd_soc_debugfs_root;
131a4072cdfSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
132a4072cdfSKuninori Morimoto 
13381c7cfd1SLars-Peter Clausen static void soc_init_component_debugfs(struct snd_soc_component *component)
134e73f3de5SRussell King {
1356553bf06SLars-Peter Clausen 	if (!component->card->debugfs_card_root)
1366553bf06SLars-Peter Clausen 		return;
1376553bf06SLars-Peter Clausen 
13881c7cfd1SLars-Peter Clausen 	if (component->debugfs_prefix) {
13981c7cfd1SLars-Peter Clausen 		char *name;
140e73f3de5SRussell King 
14181c7cfd1SLars-Peter Clausen 		name = kasprintf(GFP_KERNEL, "%s:%s",
14281c7cfd1SLars-Peter Clausen 			component->debugfs_prefix, component->name);
14381c7cfd1SLars-Peter Clausen 		if (name) {
14481c7cfd1SLars-Peter Clausen 			component->debugfs_root = debugfs_create_dir(name,
14581c7cfd1SLars-Peter Clausen 				component->card->debugfs_card_root);
14681c7cfd1SLars-Peter Clausen 			kfree(name);
14781c7cfd1SLars-Peter Clausen 		}
14881c7cfd1SLars-Peter Clausen 	} else {
14981c7cfd1SLars-Peter Clausen 		component->debugfs_root = debugfs_create_dir(component->name,
15081c7cfd1SLars-Peter Clausen 				component->card->debugfs_card_root);
151e73f3de5SRussell King 	}
152e73f3de5SRussell King 
15381c7cfd1SLars-Peter Clausen 	snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
15481c7cfd1SLars-Peter Clausen 		component->debugfs_root);
15581c7cfd1SLars-Peter Clausen }
15681c7cfd1SLars-Peter Clausen 
15781c7cfd1SLars-Peter Clausen static void soc_cleanup_component_debugfs(struct snd_soc_component *component)
15881c7cfd1SLars-Peter Clausen {
159ad64bfbdSKuninori Morimoto 	if (!component->debugfs_root)
160ad64bfbdSKuninori Morimoto 		return;
16181c7cfd1SLars-Peter Clausen 	debugfs_remove_recursive(component->debugfs_root);
162ad64bfbdSKuninori Morimoto 	component->debugfs_root = NULL;
16381c7cfd1SLars-Peter Clausen }
16481c7cfd1SLars-Peter Clausen 
165c15b2a1dSPeng Donglin static int dai_list_show(struct seq_file *m, void *v)
166f3208780SMark Brown {
1671438c2f6SLars-Peter Clausen 	struct snd_soc_component *component;
168f3208780SMark Brown 	struct snd_soc_dai *dai;
169f3208780SMark Brown 
17034e81ab4SLars-Peter Clausen 	mutex_lock(&client_mutex);
17134e81ab4SLars-Peter Clausen 
172368dee94SKuninori Morimoto 	for_each_component(component)
17315a0c645SKuninori Morimoto 		for_each_component_dais(component, dai)
174700c17caSDonglin Peng 			seq_printf(m, "%s\n", dai->name);
175f3208780SMark Brown 
17634e81ab4SLars-Peter Clausen 	mutex_unlock(&client_mutex);
17734e81ab4SLars-Peter Clausen 
178700c17caSDonglin Peng 	return 0;
179700c17caSDonglin Peng }
180c15b2a1dSPeng Donglin DEFINE_SHOW_ATTRIBUTE(dai_list);
181f3208780SMark Brown 
182db795f9bSKuninori Morimoto static int component_list_show(struct seq_file *m, void *v)
183db795f9bSKuninori Morimoto {
184db795f9bSKuninori Morimoto 	struct snd_soc_component *component;
185db795f9bSKuninori Morimoto 
186db795f9bSKuninori Morimoto 	mutex_lock(&client_mutex);
187db795f9bSKuninori Morimoto 
188368dee94SKuninori Morimoto 	for_each_component(component)
189db795f9bSKuninori Morimoto 		seq_printf(m, "%s\n", component->name);
190db795f9bSKuninori Morimoto 
191db795f9bSKuninori Morimoto 	mutex_unlock(&client_mutex);
192db795f9bSKuninori Morimoto 
193db795f9bSKuninori Morimoto 	return 0;
194db795f9bSKuninori Morimoto }
195db795f9bSKuninori Morimoto DEFINE_SHOW_ATTRIBUTE(component_list);
196db795f9bSKuninori Morimoto 
197a6052154SJarkko Nikula static void soc_init_card_debugfs(struct snd_soc_card *card)
198a6052154SJarkko Nikula {
199a6052154SJarkko Nikula 	card->debugfs_card_root = debugfs_create_dir(card->name,
2008a9dab1aSMark Brown 						     snd_soc_debugfs_root);
2013a45b867SJarkko Nikula 
202fee531d6SGreg Kroah-Hartman 	debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root,
2033a45b867SJarkko Nikula 			   &card->pop_time);
204d8ca7a0aSKuninori Morimoto 
205d8ca7a0aSKuninori Morimoto 	snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
206a6052154SJarkko Nikula }
207a6052154SJarkko Nikula 
208a6052154SJarkko Nikula static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
209a6052154SJarkko Nikula {
210a6052154SJarkko Nikula 	debugfs_remove_recursive(card->debugfs_card_root);
21129040d1aSKuninori Morimoto 	card->debugfs_card_root = NULL;
212a6052154SJarkko Nikula }
213a6052154SJarkko Nikula 
2146553bf06SLars-Peter Clausen static void snd_soc_debugfs_init(void)
2156553bf06SLars-Peter Clausen {
2166553bf06SLars-Peter Clausen 	snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
2176553bf06SLars-Peter Clausen 
218fee531d6SGreg Kroah-Hartman 	debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
219fee531d6SGreg Kroah-Hartman 			    &dai_list_fops);
220db795f9bSKuninori Morimoto 
221fee531d6SGreg Kroah-Hartman 	debugfs_create_file("components", 0444, snd_soc_debugfs_root, NULL,
222fee531d6SGreg Kroah-Hartman 			    &component_list_fops);
2236553bf06SLars-Peter Clausen }
2246553bf06SLars-Peter Clausen 
2256553bf06SLars-Peter Clausen static void snd_soc_debugfs_exit(void)
2266553bf06SLars-Peter Clausen {
2276553bf06SLars-Peter Clausen 	debugfs_remove_recursive(snd_soc_debugfs_root);
2286553bf06SLars-Peter Clausen }
2296553bf06SLars-Peter Clausen 
2302624d5faSMark Brown #else
2312624d5faSMark Brown 
23281c7cfd1SLars-Peter Clausen static inline void soc_init_component_debugfs(
23381c7cfd1SLars-Peter Clausen 	struct snd_soc_component *component)
2342624d5faSMark Brown {
2352624d5faSMark Brown }
2362624d5faSMark Brown 
23781c7cfd1SLars-Peter Clausen static inline void soc_cleanup_component_debugfs(
23881c7cfd1SLars-Peter Clausen 	struct snd_soc_component *component)
239731f1ab2SSebastien Guiriec {
240731f1ab2SSebastien Guiriec }
241731f1ab2SSebastien Guiriec 
242b95fccbcSAxel Lin static inline void soc_init_card_debugfs(struct snd_soc_card *card)
243b95fccbcSAxel Lin {
244b95fccbcSAxel Lin }
245b95fccbcSAxel Lin 
246b95fccbcSAxel Lin static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
247b95fccbcSAxel Lin {
248b95fccbcSAxel Lin }
2496553bf06SLars-Peter Clausen 
2506553bf06SLars-Peter Clausen static inline void snd_soc_debugfs_init(void)
2516553bf06SLars-Peter Clausen {
2526553bf06SLars-Peter Clausen }
2536553bf06SLars-Peter Clausen 
2546553bf06SLars-Peter Clausen static inline void snd_soc_debugfs_exit(void)
2556553bf06SLars-Peter Clausen {
2566553bf06SLars-Peter Clausen }
2576553bf06SLars-Peter Clausen 
2582624d5faSMark Brown #endif
2592624d5faSMark Brown 
26012b05232SKuninori Morimoto static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
261a0ac4411SKuninori Morimoto 				     struct snd_soc_component *component)
262a0ac4411SKuninori Morimoto {
2632b544dd7SKuninori Morimoto 	struct snd_soc_component *comp;
264613fb500SKuninori Morimoto 	int i;
265a0ac4411SKuninori Morimoto 
266613fb500SKuninori Morimoto 	for_each_rtd_components(rtd, i, comp) {
267a0ac4411SKuninori Morimoto 		/* already connected */
2682b544dd7SKuninori Morimoto 		if (comp == component)
269a0ac4411SKuninori Morimoto 			return 0;
270a0ac4411SKuninori Morimoto 	}
271a0ac4411SKuninori Morimoto 
272613fb500SKuninori Morimoto 	/* see for_each_rtd_components */
273613fb500SKuninori Morimoto 	rtd->components[rtd->num_components] = component;
274613fb500SKuninori Morimoto 	rtd->num_components++;
275a0ac4411SKuninori Morimoto 
276a0ac4411SKuninori Morimoto 	return 0;
277a0ac4411SKuninori Morimoto }
278a0ac4411SKuninori Morimoto 
279a0ac4411SKuninori Morimoto struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
280a0ac4411SKuninori Morimoto 						const char *driver_name)
281a0ac4411SKuninori Morimoto {
2822b544dd7SKuninori Morimoto 	struct snd_soc_component *component;
283613fb500SKuninori Morimoto 	int i;
284a0ac4411SKuninori Morimoto 
285971da24cSKuninori Morimoto 	if (!driver_name)
286971da24cSKuninori Morimoto 		return NULL;
287971da24cSKuninori Morimoto 
288a33c0d16SKuninori Morimoto 	/*
289a33c0d16SKuninori Morimoto 	 * NOTE
290a33c0d16SKuninori Morimoto 	 *
291a33c0d16SKuninori Morimoto 	 * snd_soc_rtdcom_lookup() will find component from rtd by using
292a33c0d16SKuninori Morimoto 	 * specified driver name.
293a33c0d16SKuninori Morimoto 	 * But, if many components which have same driver name are connected
294a33c0d16SKuninori Morimoto 	 * to 1 rtd, this function will return 1st found component.
295a33c0d16SKuninori Morimoto 	 */
296613fb500SKuninori Morimoto 	for_each_rtd_components(rtd, i, component) {
2972b544dd7SKuninori Morimoto 		const char *component_name = component->driver->name;
298971da24cSKuninori Morimoto 
299971da24cSKuninori Morimoto 		if (!component_name)
300971da24cSKuninori Morimoto 			continue;
301971da24cSKuninori Morimoto 
302971da24cSKuninori Morimoto 		if ((component_name == driver_name) ||
303971da24cSKuninori Morimoto 		    strcmp(component_name, driver_name) == 0)
304613fb500SKuninori Morimoto 			return component;
305a0ac4411SKuninori Morimoto 	}
306a0ac4411SKuninori Morimoto 
307a0ac4411SKuninori Morimoto 	return NULL;
308a0ac4411SKuninori Morimoto }
309031734b7SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup);
310a0ac4411SKuninori Morimoto 
3116fbea6b6SShengjiu Wang struct snd_soc_component
31218dd66eaSKuninori Morimoto *snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name)
313b8132657SKuninori Morimoto {
314b8132657SKuninori Morimoto 	struct snd_soc_component *component;
3155bd7e08bSKuninori Morimoto 	struct snd_soc_component *found_component;
316b8132657SKuninori Morimoto 
3175bd7e08bSKuninori Morimoto 	found_component = NULL;
318b8132657SKuninori Morimoto 	for_each_component(component) {
3195bd7e08bSKuninori Morimoto 		if ((dev == component->dev) &&
3205bd7e08bSKuninori Morimoto 		    (!driver_name ||
3215bd7e08bSKuninori Morimoto 		     (driver_name == component->driver->name) ||
3225bd7e08bSKuninori Morimoto 		     (strcmp(component->driver->name, driver_name) == 0))) {
3235bd7e08bSKuninori Morimoto 			found_component = component;
324b8132657SKuninori Morimoto 			break;
325b8132657SKuninori Morimoto 		}
3265bd7e08bSKuninori Morimoto 	}
327b8132657SKuninori Morimoto 
3285bd7e08bSKuninori Morimoto 	return found_component;
329b8132657SKuninori Morimoto }
3306fbea6b6SShengjiu Wang EXPORT_SYMBOL_GPL(snd_soc_lookup_component_nolocked);
33118dd66eaSKuninori Morimoto 
33218dd66eaSKuninori Morimoto struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
33318dd66eaSKuninori Morimoto 						   const char *driver_name)
33418dd66eaSKuninori Morimoto {
33518dd66eaSKuninori Morimoto 	struct snd_soc_component *component;
33618dd66eaSKuninori Morimoto 
33718dd66eaSKuninori Morimoto 	mutex_lock(&client_mutex);
33818dd66eaSKuninori Morimoto 	component = snd_soc_lookup_component_nolocked(dev, driver_name);
33918dd66eaSKuninori Morimoto 	mutex_unlock(&client_mutex);
34018dd66eaSKuninori Morimoto 
34118dd66eaSKuninori Morimoto 	return component;
34218dd66eaSKuninori Morimoto }
343b8132657SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
344b8132657SKuninori Morimoto 
34594def8eaSKuninori Morimoto struct snd_soc_pcm_runtime
34694def8eaSKuninori Morimoto *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
3474468189fSKuninori Morimoto 			 struct snd_soc_dai_link *dai_link)
34894def8eaSKuninori Morimoto {
34994def8eaSKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
35094def8eaSKuninori Morimoto 
35194def8eaSKuninori Morimoto 	for_each_card_rtds(card, rtd) {
3524468189fSKuninori Morimoto 		if (rtd->dai_link == dai_link)
35394def8eaSKuninori Morimoto 			return rtd;
35494def8eaSKuninori Morimoto 	}
3554468189fSKuninori Morimoto 	dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link->name);
35694def8eaSKuninori Morimoto 	return NULL;
35794def8eaSKuninori Morimoto }
35894def8eaSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
35994def8eaSKuninori Morimoto 
36083f94a2eSKuninori Morimoto /*
36183f94a2eSKuninori Morimoto  * Power down the audio subsystem pmdown_time msecs after close is called.
36283f94a2eSKuninori Morimoto  * This is to ensure there are no pops or clicks in between any music tracks
36383f94a2eSKuninori Morimoto  * due to DAPM power cycling.
36483f94a2eSKuninori Morimoto  */
36583f94a2eSKuninori Morimoto void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
36683f94a2eSKuninori Morimoto {
367c2233a26SKuninori Morimoto 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
3680f6011fdSKuninori Morimoto 	int playback = SNDRV_PCM_STREAM_PLAYBACK;
36983f94a2eSKuninori Morimoto 
37083f94a2eSKuninori Morimoto 	mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
37183f94a2eSKuninori Morimoto 
37283f94a2eSKuninori Morimoto 	dev_dbg(rtd->dev,
37383f94a2eSKuninori Morimoto 		"ASoC: pop wq checking: %s status: %s waiting: %s\n",
37483f94a2eSKuninori Morimoto 		codec_dai->driver->playback.stream_name,
375b3dea624SKuninori Morimoto 		snd_soc_dai_stream_active(codec_dai, playback) ?
376b3dea624SKuninori Morimoto 		"active" : "inactive",
37783f94a2eSKuninori Morimoto 		rtd->pop_wait ? "yes" : "no");
37883f94a2eSKuninori Morimoto 
37983f94a2eSKuninori Morimoto 	/* are we waiting on this codec DAI stream */
38083f94a2eSKuninori Morimoto 	if (rtd->pop_wait == 1) {
38183f94a2eSKuninori Morimoto 		rtd->pop_wait = 0;
3820f6011fdSKuninori Morimoto 		snd_soc_dapm_stream_event(rtd, playback,
38383f94a2eSKuninori Morimoto 					  SND_SOC_DAPM_STREAM_STOP);
38483f94a2eSKuninori Morimoto 	}
38583f94a2eSKuninori Morimoto 
38683f94a2eSKuninori Morimoto 	mutex_unlock(&rtd->card->pcm_mutex);
38783f94a2eSKuninori Morimoto }
38883f94a2eSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work);
38983f94a2eSKuninori Morimoto 
3906e864344SKuninori Morimoto static void soc_release_rtd_dev(struct device *dev)
3916e864344SKuninori Morimoto {
3926e864344SKuninori Morimoto 	/* "dev" means "rtd->dev" */
3936e864344SKuninori Morimoto 	kfree(dev);
3946e864344SKuninori Morimoto }
3956e864344SKuninori Morimoto 
3961c93a9e0SKuninori Morimoto static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
3971c93a9e0SKuninori Morimoto {
3986e864344SKuninori Morimoto 	if (!rtd)
3996e864344SKuninori Morimoto 		return;
4006e864344SKuninori Morimoto 
401753ace0aSKuninori Morimoto 	list_del(&rtd->list);
402b7c5bc45SKuninori Morimoto 
4039c9b6520SCurtis Malainey 	if (delayed_work_pending(&rtd->delayed_work))
4040ced7b05SKuninori Morimoto 		flush_delayed_work(&rtd->delayed_work);
4050ced7b05SKuninori Morimoto 	snd_soc_pcm_component_free(rtd);
4060ced7b05SKuninori Morimoto 
407b7c5bc45SKuninori Morimoto 	/*
408b7c5bc45SKuninori Morimoto 	 * we don't need to call kfree() for rtd->dev
409b7c5bc45SKuninori Morimoto 	 * see
410b7c5bc45SKuninori Morimoto 	 *	soc_release_rtd_dev()
411d918a376SKuninori Morimoto 	 *
412d918a376SKuninori Morimoto 	 * We don't need rtd->dev NULL check, because
413d918a376SKuninori Morimoto 	 * it is alloced *before* rtd.
414d918a376SKuninori Morimoto 	 * see
415d918a376SKuninori Morimoto 	 *	soc_new_pcm_runtime()
416b7c5bc45SKuninori Morimoto 	 */
417b7c5bc45SKuninori Morimoto 	device_unregister(rtd->dev);
4181c93a9e0SKuninori Morimoto }
4191c93a9e0SKuninori Morimoto 
4204bf2e385SCurtis Malainey static void close_delayed_work(struct work_struct *work) {
4214bf2e385SCurtis Malainey 	struct snd_soc_pcm_runtime *rtd =
4224bf2e385SCurtis Malainey 			container_of(work, struct snd_soc_pcm_runtime,
4234bf2e385SCurtis Malainey 				     delayed_work.work);
4244bf2e385SCurtis Malainey 
4254bf2e385SCurtis Malainey 	if (rtd->close_delayed_work_func)
4264bf2e385SCurtis Malainey 		rtd->close_delayed_work_func(rtd);
4274bf2e385SCurtis Malainey }
4284bf2e385SCurtis Malainey 
4291a497983SMengdong Lin static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
4301a497983SMengdong Lin 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
4311a497983SMengdong Lin {
4321a497983SMengdong Lin 	struct snd_soc_pcm_runtime *rtd;
433613fb500SKuninori Morimoto 	struct snd_soc_component *component;
434d918a376SKuninori Morimoto 	struct device *dev;
4356e864344SKuninori Morimoto 	int ret;
436d74c2a15SKuninori Morimoto 	int stream;
4371a497983SMengdong Lin 
4386e864344SKuninori Morimoto 	/*
439d918a376SKuninori Morimoto 	 * for rtd->dev
440d918a376SKuninori Morimoto 	 */
441d918a376SKuninori Morimoto 	dev = kzalloc(sizeof(struct device), GFP_KERNEL);
442d918a376SKuninori Morimoto 	if (!dev)
443d918a376SKuninori Morimoto 		return NULL;
444d918a376SKuninori Morimoto 
445d918a376SKuninori Morimoto 	dev->parent	= card->dev;
446d918a376SKuninori Morimoto 	dev->release	= soc_release_rtd_dev;
447d918a376SKuninori Morimoto 
448d918a376SKuninori Morimoto 	dev_set_name(dev, "%s", dai_link->name);
449d918a376SKuninori Morimoto 
450d918a376SKuninori Morimoto 	ret = device_register(dev);
451d918a376SKuninori Morimoto 	if (ret < 0) {
452d918a376SKuninori Morimoto 		put_device(dev); /* soc_release_rtd_dev */
453d918a376SKuninori Morimoto 		return NULL;
454d918a376SKuninori Morimoto 	}
455d918a376SKuninori Morimoto 
456d918a376SKuninori Morimoto 	/*
4576e864344SKuninori Morimoto 	 * for rtd
4586e864344SKuninori Morimoto 	 */
459613fb500SKuninori Morimoto 	rtd = devm_kzalloc(dev,
460613fb500SKuninori Morimoto 			   sizeof(*rtd) +
461613fb500SKuninori Morimoto 			   sizeof(*component) * (dai_link->num_cpus +
462613fb500SKuninori Morimoto 						 dai_link->num_codecs +
463613fb500SKuninori Morimoto 						 dai_link->num_platforms),
464613fb500SKuninori Morimoto 			   GFP_KERNEL);
4651a497983SMengdong Lin 	if (!rtd)
4666e864344SKuninori Morimoto 		goto free_rtd;
4671a497983SMengdong Lin 
468d918a376SKuninori Morimoto 	rtd->dev = dev;
46907d22a9bSTakashi Iwai 	INIT_LIST_HEAD(&rtd->list);
470d74c2a15SKuninori Morimoto 	for_each_pcm_streams(stream) {
471d74c2a15SKuninori Morimoto 		INIT_LIST_HEAD(&rtd->dpcm[stream].be_clients);
472d74c2a15SKuninori Morimoto 		INIT_LIST_HEAD(&rtd->dpcm[stream].fe_clients);
473d74c2a15SKuninori Morimoto 	}
474d918a376SKuninori Morimoto 	dev_set_drvdata(dev, rtd);
4754bf2e385SCurtis Malainey 	INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
476d918a376SKuninori Morimoto 
4776e864344SKuninori Morimoto 	/*
47822a2fc81SKuninori Morimoto 	 * for rtd->dais
4796e864344SKuninori Morimoto 	 */
48022a2fc81SKuninori Morimoto 	rtd->dais = devm_kcalloc(dev, dai_link->num_cpus + dai_link->num_codecs,
4816396bb22SKees Cook 					sizeof(struct snd_soc_dai *),
4821a497983SMengdong Lin 					GFP_KERNEL);
48322a2fc81SKuninori Morimoto 	if (!rtd->dais)
4846e864344SKuninori Morimoto 		goto free_rtd;
4856e864344SKuninori Morimoto 
4866e864344SKuninori Morimoto 	/*
48722a2fc81SKuninori Morimoto 	 * dais = [][][][][][][][][][][][][][][][][][]
48822a2fc81SKuninori Morimoto 	 *	  ^cpu_dais         ^codec_dais
48922a2fc81SKuninori Morimoto 	 *	  |--- num_cpus ---|--- num_codecs --|
4901729025bSKuninori Morimoto 	 * see
4911729025bSKuninori Morimoto 	 *	asoc_rtd_to_cpu()
4921729025bSKuninori Morimoto 	 *	asoc_rtd_to_codec()
49376afa643SShreyas NC 	 */
49449648d02SKuninori Morimoto 	rtd->num_cpus	= dai_link->num_cpus;
49549648d02SKuninori Morimoto 	rtd->num_codecs	= dai_link->num_codecs;
496929deb84SKuninori Morimoto 	rtd->card	= card;
497929deb84SKuninori Morimoto 	rtd->dai_link	= dai_link;
49801faf501SKuninori Morimoto 	rtd->num	= card->num_rtd++;
499929deb84SKuninori Morimoto 
5006634e3d6SKuninori Morimoto 	/* see for_each_card_rtds */
5011a497983SMengdong Lin 	list_add_tail(&rtd->list, &card->rtd_list);
502a848125eSKuninori Morimoto 
5035c74c9d3SCharles Keepax 	ret = device_add_groups(dev, soc_dev_attr_groups);
5045c74c9d3SCharles Keepax 	if (ret < 0)
5055c74c9d3SCharles Keepax 		goto free_rtd;
5065c74c9d3SCharles Keepax 
507a848125eSKuninori Morimoto 	return rtd;
5086e864344SKuninori Morimoto 
5096e864344SKuninori Morimoto free_rtd:
5106e864344SKuninori Morimoto 	soc_free_pcm_runtime(rtd);
5116e864344SKuninori Morimoto 	return NULL;
5121a497983SMengdong Lin }
5131a497983SMengdong Lin 
51465462e44SKuninori Morimoto static void snd_soc_flush_all_delayed_work(struct snd_soc_card *card)
51565462e44SKuninori Morimoto {
51665462e44SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
51765462e44SKuninori Morimoto 
51865462e44SKuninori Morimoto 	for_each_card_rtds(card, rtd)
51965462e44SKuninori Morimoto 		flush_delayed_work(&rtd->delayed_work);
52065462e44SKuninori Morimoto }
52165462e44SKuninori Morimoto 
5226f8ab4acSMark Brown #ifdef CONFIG_PM_SLEEP
523d4c1d9ebSKuninori Morimoto static void soc_playback_digital_mute(struct snd_soc_card *card, int mute)
524d4c1d9ebSKuninori Morimoto {
525d4c1d9ebSKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
526d4c1d9ebSKuninori Morimoto 	struct snd_soc_dai *dai;
527d4c1d9ebSKuninori Morimoto 	int playback = SNDRV_PCM_STREAM_PLAYBACK;
528d4c1d9ebSKuninori Morimoto 	int i;
529d4c1d9ebSKuninori Morimoto 
530d4c1d9ebSKuninori Morimoto 	for_each_card_rtds(card, rtd) {
531d4c1d9ebSKuninori Morimoto 
532d4c1d9ebSKuninori Morimoto 		if (rtd->dai_link->ignore_suspend)
533d4c1d9ebSKuninori Morimoto 			continue;
534d4c1d9ebSKuninori Morimoto 
535d4c1d9ebSKuninori Morimoto 		for_each_rtd_dais(rtd, i, dai) {
536d4c1d9ebSKuninori Morimoto 			if (snd_soc_dai_stream_active(dai, playback))
537d4c1d9ebSKuninori Morimoto 				snd_soc_dai_digital_mute(dai, mute, playback);
538d4c1d9ebSKuninori Morimoto 		}
539d4c1d9ebSKuninori Morimoto 	}
540d4c1d9ebSKuninori Morimoto }
541d4c1d9ebSKuninori Morimoto 
542*baed393eSKuninori Morimoto static void soc_dapm_suspend_resume(struct snd_soc_card *card, int event)
543*baed393eSKuninori Morimoto {
544*baed393eSKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
545*baed393eSKuninori Morimoto 	int stream;
546*baed393eSKuninori Morimoto 
547*baed393eSKuninori Morimoto 	for_each_card_rtds(card, rtd) {
548*baed393eSKuninori Morimoto 
549*baed393eSKuninori Morimoto 		if (rtd->dai_link->ignore_suspend)
550*baed393eSKuninori Morimoto 			continue;
551*baed393eSKuninori Morimoto 
552*baed393eSKuninori Morimoto 		for_each_pcm_streams(stream)
553*baed393eSKuninori Morimoto 			snd_soc_dapm_stream_event(rtd, stream, event);
554*baed393eSKuninori Morimoto 	}
555*baed393eSKuninori Morimoto }
556*baed393eSKuninori Morimoto 
557db2a4165SFrank Mandarino /* powers down audio subsystem for suspend */
5586f8ab4acSMark Brown int snd_soc_suspend(struct device *dev)
559db2a4165SFrank Mandarino {
5606f8ab4acSMark Brown 	struct snd_soc_card *card = dev_get_drvdata(dev);
561d9fc4063SKuninori Morimoto 	struct snd_soc_component *component;
5621a497983SMengdong Lin 	struct snd_soc_pcm_runtime *rtd;
5631a497983SMengdong Lin 	int i;
564db2a4165SFrank Mandarino 
565c5599b87SLars-Peter Clausen 	/* If the card is not initialized yet there is nothing to do */
566c5599b87SLars-Peter Clausen 	if (!card->instantiated)
567e3509ff0SDaniel Mack 		return 0;
568e3509ff0SDaniel Mack 
5692c7b696aSMarcel Ziswiler 	/*
5702c7b696aSMarcel Ziswiler 	 * Due to the resume being scheduled into a workqueue we could
5716ed25978SAndy Green 	 * suspend before that's finished - wait for it to complete.
5726ed25978SAndy Green 	 */
573f0fba2adSLiam Girdwood 	snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
5746ed25978SAndy Green 
5756ed25978SAndy Green 	/* we're going to block userspace touching us until resume completes */
576f0fba2adSLiam Girdwood 	snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
5776ed25978SAndy Green 
578a00f90f9SMark Brown 	/* mute any active DACs */
579d4c1d9ebSKuninori Morimoto 	soc_playback_digital_mute(card, 1);
580db2a4165SFrank Mandarino 
5814ccab3e7SLiam Girdwood 	/* suspend all pcms */
582bcb1fd1fSKuninori Morimoto 	for_each_card_rtds(card, rtd) {
5831a497983SMengdong Lin 		if (rtd->dai_link->ignore_suspend)
5843efab7dcSMark Brown 			continue;
5853efab7dcSMark Brown 
5861a497983SMengdong Lin 		snd_pcm_suspend_all(rtd->pcm);
5873efab7dcSMark Brown 	}
5884ccab3e7SLiam Girdwood 
589130dc08cSKuninori Morimoto 	snd_soc_card_suspend_pre(card);
590db2a4165SFrank Mandarino 
59137660b6dSLars-Peter Clausen 	/* close any waiting streams */
59265462e44SKuninori Morimoto 	snd_soc_flush_all_delayed_work(card);
593db2a4165SFrank Mandarino 
594*baed393eSKuninori Morimoto 	soc_dapm_suspend_resume(card, SND_SOC_DAPM_STREAM_SUSPEND);
595db2a4165SFrank Mandarino 
5968be4da29SLars-Peter Clausen 	/* Recheck all endpoints too, their state is affected by suspend */
5978be4da29SLars-Peter Clausen 	dapm_mark_endpoints_dirty(card);
598e2d32ff6SMark Brown 	snd_soc_dapm_sync(&card->dapm);
599e2d32ff6SMark Brown 
6009178feb4SKuninori Morimoto 	/* suspend all COMPONENTs */
6011272063aSKuninori Morimoto 	for_each_card_rtds(card, rtd) {
6021272063aSKuninori Morimoto 
6031272063aSKuninori Morimoto 		if (rtd->dai_link->ignore_suspend)
6041272063aSKuninori Morimoto 			continue;
6051272063aSKuninori Morimoto 
6061272063aSKuninori Morimoto 		for_each_rtd_components(rtd, i, component) {
6072c7b696aSMarcel Ziswiler 			struct snd_soc_dapm_context *dapm =
6082c7b696aSMarcel Ziswiler 				snd_soc_component_get_dapm(component);
609d9fc4063SKuninori Morimoto 
6102c7b696aSMarcel Ziswiler 			/*
6111272063aSKuninori Morimoto 			 * ignore if component was already suspended
6122c7b696aSMarcel Ziswiler 			 */
6131272063aSKuninori Morimoto 			if (snd_soc_component_is_suspended(component))
6141272063aSKuninori Morimoto 				continue;
6151272063aSKuninori Morimoto 
6161272063aSKuninori Morimoto 			/*
6171272063aSKuninori Morimoto 			 * If there are paths active then the COMPONENT will be
6181272063aSKuninori Morimoto 			 * held with bias _ON and should not be suspended.
6191272063aSKuninori Morimoto 			 */
6204890140fSLars-Peter Clausen 			switch (snd_soc_dapm_get_bias_level(dapm)) {
6211547aba9SMark Brown 			case SND_SOC_BIAS_STANDBY:
622125a25daSMark Brown 				/*
6239178feb4SKuninori Morimoto 				 * If the COMPONENT is capable of idle
624125a25daSMark Brown 				 * bias off then being in STANDBY
625125a25daSMark Brown 				 * means it's doing something,
626125a25daSMark Brown 				 * otherwise fall through.
627125a25daSMark Brown 				 */
6284890140fSLars-Peter Clausen 				if (dapm->idle_bias_off) {
6299178feb4SKuninori Morimoto 					dev_dbg(component->dev,
63010e8aa9aSMichał Mirosław 						"ASoC: idle_bias_off CODEC on over suspend\n");
631125a25daSMark Brown 					break;
632125a25daSMark Brown 				}
633df561f66SGustavo A. R. Silva 				fallthrough;
634a8093297SLars-Peter Clausen 
6351547aba9SMark Brown 			case SND_SOC_BIAS_OFF:
63666c51573SKuninori Morimoto 				snd_soc_component_suspend(component);
6379178feb4SKuninori Morimoto 				if (component->regmap)
6389178feb4SKuninori Morimoto 					regcache_mark_dirty(component->regmap);
639988e8cc4SNicolin Chen 				/* deactivate pins to sleep state */
6409178feb4SKuninori Morimoto 				pinctrl_pm_select_sleep_state(component->dev);
6411547aba9SMark Brown 				break;
6421547aba9SMark Brown 			default:
6439178feb4SKuninori Morimoto 				dev_dbg(component->dev,
6449178feb4SKuninori Morimoto 					"ASoC: COMPONENT is on over suspend\n");
6451547aba9SMark Brown 				break;
6461547aba9SMark Brown 			}
6471547aba9SMark Brown 		}
648f0fba2adSLiam Girdwood 	}
649db2a4165SFrank Mandarino 
650d17b60b2SKuninori Morimoto 	snd_soc_card_suspend_post(card);
651db2a4165SFrank Mandarino 
652db2a4165SFrank Mandarino 	return 0;
653db2a4165SFrank Mandarino }
6546f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_suspend);
655db2a4165SFrank Mandarino 
6562c7b696aSMarcel Ziswiler /*
6572c7b696aSMarcel Ziswiler  * deferred resume work, so resume can complete before we finished
6586ed25978SAndy Green  * setting our codec back up, which can be very slow on I2C
6596ed25978SAndy Green  */
6606ed25978SAndy Green static void soc_resume_deferred(struct work_struct *work)
661db2a4165SFrank Mandarino {
662f0fba2adSLiam Girdwood 	struct snd_soc_card *card =
6632c7b696aSMarcel Ziswiler 			container_of(work, struct snd_soc_card,
6642c7b696aSMarcel Ziswiler 				     deferred_resume_work);
665d9fc4063SKuninori Morimoto 	struct snd_soc_component *component;
666db2a4165SFrank Mandarino 
6672c7b696aSMarcel Ziswiler 	/*
6682c7b696aSMarcel Ziswiler 	 * our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
6696ed25978SAndy Green 	 * so userspace apps are blocked from touching us
6706ed25978SAndy Green 	 */
6716ed25978SAndy Green 
672f110bfc7SLiam Girdwood 	dev_dbg(card->dev, "ASoC: starting resume work\n");
6736ed25978SAndy Green 
6749949788bSMark Brown 	/* Bring us up into D2 so that DAPM starts enabling things */
675f0fba2adSLiam Girdwood 	snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
6769949788bSMark Brown 
677934c752cSKuninori Morimoto 	snd_soc_card_resume_pre(card);
678db2a4165SFrank Mandarino 
679f70f18f7SKuninori Morimoto 	for_each_card_components(card, component) {
680e40fadbcSKuninori Morimoto 		if (snd_soc_component_is_suspended(component))
6819a840cbaSKuninori Morimoto 			snd_soc_component_resume(component);
6821547aba9SMark Brown 	}
683db2a4165SFrank Mandarino 
684*baed393eSKuninori Morimoto 	soc_dapm_suspend_resume(card, SND_SOC_DAPM_STREAM_RESUME);
685db2a4165SFrank Mandarino 
6863ff3f64bSMark Brown 	/* unmute any active DACs */
687d4c1d9ebSKuninori Morimoto 	soc_playback_digital_mute(card, 0);
688db2a4165SFrank Mandarino 
689739443d1SKuninori Morimoto 	snd_soc_card_resume_post(card);
690db2a4165SFrank Mandarino 
691f110bfc7SLiam Girdwood 	dev_dbg(card->dev, "ASoC: resume work completed\n");
6926ed25978SAndy Green 
6938be4da29SLars-Peter Clausen 	/* Recheck all endpoints too, their state is affected by suspend */
6948be4da29SLars-Peter Clausen 	dapm_mark_endpoints_dirty(card);
695e2d32ff6SMark Brown 	snd_soc_dapm_sync(&card->dapm);
6961a7aaa58SJeeja KP 
6971a7aaa58SJeeja KP 	/* userspace can access us now we are back as we were before */
6981a7aaa58SJeeja KP 	snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
6996ed25978SAndy Green }
7006ed25978SAndy Green 
7016ed25978SAndy Green /* powers up audio subsystem after a suspend */
7026f8ab4acSMark Brown int snd_soc_resume(struct device *dev)
7036ed25978SAndy Green {
7046f8ab4acSMark Brown 	struct snd_soc_card *card = dev_get_drvdata(dev);
70576c39e86SKuninori Morimoto 	struct snd_soc_component *component;
706b9dd94a8SPeter Ujfalusi 
707c5599b87SLars-Peter Clausen 	/* If the card is not initialized yet there is nothing to do */
708c5599b87SLars-Peter Clausen 	if (!card->instantiated)
7095ff1ddf2SEric Miao 		return 0;
7105ff1ddf2SEric Miao 
711988e8cc4SNicolin Chen 	/* activate pins from sleep state */
71276c39e86SKuninori Morimoto 	for_each_card_components(card, component)
713b3dea624SKuninori Morimoto 		if (snd_soc_component_active(component))
71476c39e86SKuninori Morimoto 			pinctrl_pm_select_default_state(component->dev);
715988e8cc4SNicolin Chen 
716f110bfc7SLiam Girdwood 	dev_dbg(dev, "ASoC: Scheduling resume work\n");
7176308419aSMark Brown 	if (!schedule_work(&card->deferred_resume_work))
718f110bfc7SLiam Girdwood 		dev_err(dev, "ASoC: resume work item may be lost\n");
7196ed25978SAndy Green 
720db2a4165SFrank Mandarino 	return 0;
721db2a4165SFrank Mandarino }
7226f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_resume);
723b3da4251SKuninori Morimoto 
724b3da4251SKuninori Morimoto static void soc_resume_init(struct snd_soc_card *card)
725b3da4251SKuninori Morimoto {
726b3da4251SKuninori Morimoto 	/* deferred resume work */
727b3da4251SKuninori Morimoto 	INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
728b3da4251SKuninori Morimoto }
729db2a4165SFrank Mandarino #else
7306f8ab4acSMark Brown #define snd_soc_suspend NULL
7316f8ab4acSMark Brown #define snd_soc_resume NULL
732b3da4251SKuninori Morimoto static inline void soc_resume_init(struct snd_soc_card *card)
733b3da4251SKuninori Morimoto {
734b3da4251SKuninori Morimoto }
735db2a4165SFrank Mandarino #endif
736db2a4165SFrank Mandarino 
737c0834440SKuninori Morimoto static struct device_node
738c0834440SKuninori Morimoto *soc_component_to_node(struct snd_soc_component *component)
73912023a9aSMisael Lopez Cruz {
740c0834440SKuninori Morimoto 	struct device_node *of_node;
74112023a9aSMisael Lopez Cruz 
742c0834440SKuninori Morimoto 	of_node = component->dev->of_node;
743c0834440SKuninori Morimoto 	if (!of_node && component->dev->parent)
744c0834440SKuninori Morimoto 		of_node = component->dev->parent->of_node;
74534e81ab4SLars-Peter Clausen 
746c0834440SKuninori Morimoto 	return of_node;
74712023a9aSMisael Lopez Cruz }
74812023a9aSMisael Lopez Cruz 
749be6ac0a9SKuninori Morimoto static int snd_soc_is_matching_component(
750be6ac0a9SKuninori Morimoto 	const struct snd_soc_dai_link_component *dlc,
751be6ac0a9SKuninori Morimoto 	struct snd_soc_component *component)
752be6ac0a9SKuninori Morimoto {
753be6ac0a9SKuninori Morimoto 	struct device_node *component_of_node;
754be6ac0a9SKuninori Morimoto 
7557d7db5d3SKuninori Morimoto 	if (!dlc)
7567d7db5d3SKuninori Morimoto 		return 0;
7577d7db5d3SKuninori Morimoto 
7587d7db5d3SKuninori Morimoto 	component_of_node = soc_component_to_node(component);
759be6ac0a9SKuninori Morimoto 
760be6ac0a9SKuninori Morimoto 	if (dlc->of_node && component_of_node != dlc->of_node)
761be6ac0a9SKuninori Morimoto 		return 0;
762be6ac0a9SKuninori Morimoto 	if (dlc->name && strcmp(component->name, dlc->name))
763be6ac0a9SKuninori Morimoto 		return 0;
764be6ac0a9SKuninori Morimoto 
765be6ac0a9SKuninori Morimoto 	return 1;
766be6ac0a9SKuninori Morimoto }
767be6ac0a9SKuninori Morimoto 
768db2a4165SFrank Mandarino static struct snd_soc_component *soc_find_component(
769c1e230f0SKuninori Morimoto 	const struct snd_soc_dai_link_component *dlc)
770db2a4165SFrank Mandarino {
771db2a4165SFrank Mandarino 	struct snd_soc_component *component;
772db2a4165SFrank Mandarino 
773db2a4165SFrank Mandarino 	lockdep_assert_held(&client_mutex);
774db2a4165SFrank Mandarino 
775e3303268SKuninori Morimoto 	/*
776e3303268SKuninori Morimoto 	 * NOTE
777e3303268SKuninori Morimoto 	 *
778e3303268SKuninori Morimoto 	 * It returns *1st* found component, but some driver
779e3303268SKuninori Morimoto 	 * has few components by same of_node/name
780e3303268SKuninori Morimoto 	 * ex)
781e3303268SKuninori Morimoto 	 *	CPU component and generic DMAEngine component
782e3303268SKuninori Morimoto 	 */
783c1e230f0SKuninori Morimoto 	for_each_component(component)
784c1e230f0SKuninori Morimoto 		if (snd_soc_is_matching_component(dlc, component))
785db2a4165SFrank Mandarino 			return component;
78602a06d30SBarry Song 
78702a06d30SBarry Song 	return NULL;
78812023a9aSMisael Lopez Cruz }
78912023a9aSMisael Lopez Cruz 
790fbb88b5cSMengdong Lin /**
791fbb88b5cSMengdong Lin  * snd_soc_find_dai - Find a registered DAI
792fbb88b5cSMengdong Lin  *
7934958471bSJeffy Chen  * @dlc: name of the DAI or the DAI driver and optional component info to match
794fbb88b5cSMengdong Lin  *
795ad61dd30SStephen Boyd  * This function will search all registered components and their DAIs to
796fbb88b5cSMengdong Lin  * find the DAI of the same name. The component's of_node and name
797fbb88b5cSMengdong Lin  * should also match if being specified.
798fbb88b5cSMengdong Lin  *
799fbb88b5cSMengdong Lin  * Return: pointer of DAI, or NULL if not found.
800fbb88b5cSMengdong Lin  */
801305e9020SMengdong Lin struct snd_soc_dai *snd_soc_find_dai(
80214621c7eSLars-Peter Clausen 	const struct snd_soc_dai_link_component *dlc)
80312023a9aSMisael Lopez Cruz {
80414621c7eSLars-Peter Clausen 	struct snd_soc_component *component;
80514621c7eSLars-Peter Clausen 	struct snd_soc_dai *dai;
80612023a9aSMisael Lopez Cruz 
80734e81ab4SLars-Peter Clausen 	lockdep_assert_held(&client_mutex);
80834e81ab4SLars-Peter Clausen 
80914621c7eSLars-Peter Clausen 	/* Find CPU DAI from registered DAIs */
810368dee94SKuninori Morimoto 	for_each_component(component) {
811be6ac0a9SKuninori Morimoto 		if (!snd_soc_is_matching_component(dlc, component))
81212023a9aSMisael Lopez Cruz 			continue;
81315a0c645SKuninori Morimoto 		for_each_component_dais(component, dai) {
8144958471bSJeffy Chen 			if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
8156a6dafdaSJeffy Chen 			    && (!dai->driver->name
8166a6dafdaSJeffy Chen 				|| strcmp(dai->driver->name, dlc->dai_name)))
81714621c7eSLars-Peter Clausen 				continue;
81812023a9aSMisael Lopez Cruz 
81914621c7eSLars-Peter Clausen 			return dai;
82012023a9aSMisael Lopez Cruz 		}
82112023a9aSMisael Lopez Cruz 	}
82212023a9aSMisael Lopez Cruz 
82312023a9aSMisael Lopez Cruz 	return NULL;
82412023a9aSMisael Lopez Cruz }
825305e9020SMengdong Lin EXPORT_SYMBOL_GPL(snd_soc_find_dai);
82612023a9aSMisael Lopez Cruz 
827c1c277b2SKuninori Morimoto struct snd_soc_dai *snd_soc_find_dai_with_mutex(
828c1c277b2SKuninori Morimoto 	const struct snd_soc_dai_link_component *dlc)
829c1c277b2SKuninori Morimoto {
830c1c277b2SKuninori Morimoto 	struct snd_soc_dai *dai;
831c1c277b2SKuninori Morimoto 
832c1c277b2SKuninori Morimoto 	mutex_lock(&client_mutex);
833c1c277b2SKuninori Morimoto 	dai = snd_soc_find_dai(dlc);
834c1c277b2SKuninori Morimoto 	mutex_unlock(&client_mutex);
835c1c277b2SKuninori Morimoto 
836c1c277b2SKuninori Morimoto 	return dai;
837c1c277b2SKuninori Morimoto }
838c1c277b2SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_find_dai_with_mutex);
839c1c277b2SKuninori Morimoto 
840bfce78a5SKuninori Morimoto static int soc_dai_link_sanity_check(struct snd_soc_card *card,
84136794902SKuninori Morimoto 				     struct snd_soc_dai_link *link)
84236794902SKuninori Morimoto {
84336794902SKuninori Morimoto 	int i;
84476afa643SShreyas NC 	struct snd_soc_dai_link_component *cpu, *codec, *platform;
84536794902SKuninori Morimoto 
84636794902SKuninori Morimoto 	for_each_link_codecs(link, i, codec) {
84736794902SKuninori Morimoto 		/*
84836794902SKuninori Morimoto 		 * Codec must be specified by 1 of name or OF node,
84936794902SKuninori Morimoto 		 * not both or neither.
85036794902SKuninori Morimoto 		 */
85136794902SKuninori Morimoto 		if (!!codec->name == !!codec->of_node) {
85236794902SKuninori Morimoto 			dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
85336794902SKuninori Morimoto 				link->name);
85436794902SKuninori Morimoto 			return -EINVAL;
85536794902SKuninori Morimoto 		}
85636794902SKuninori Morimoto 
85736794902SKuninori Morimoto 		/* Codec DAI name must be specified */
85836794902SKuninori Morimoto 		if (!codec->dai_name) {
85936794902SKuninori Morimoto 			dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
86036794902SKuninori Morimoto 				link->name);
86136794902SKuninori Morimoto 			return -EINVAL;
86236794902SKuninori Morimoto 		}
86336794902SKuninori Morimoto 
86436794902SKuninori Morimoto 		/*
86536794902SKuninori Morimoto 		 * Defer card registration if codec component is not added to
86636794902SKuninori Morimoto 		 * component list.
86736794902SKuninori Morimoto 		 */
868b2acc24cSRanjani Sridharan 		if (!soc_find_component(codec)) {
869b2acc24cSRanjani Sridharan 			dev_dbg(card->dev,
870b2acc24cSRanjani Sridharan 				"ASoC: codec component %s not found for link %s\n",
871b2acc24cSRanjani Sridharan 				codec->name, link->name);
87236794902SKuninori Morimoto 			return -EPROBE_DEFER;
87336794902SKuninori Morimoto 		}
874b2acc24cSRanjani Sridharan 	}
87536794902SKuninori Morimoto 
87636794902SKuninori Morimoto 	for_each_link_platforms(link, i, platform) {
87736794902SKuninori Morimoto 		/*
87836794902SKuninori Morimoto 		 * Platform may be specified by either name or OF node, but it
87936794902SKuninori Morimoto 		 * can be left unspecified, then no components will be inserted
88036794902SKuninori Morimoto 		 * in the rtdcom list
88136794902SKuninori Morimoto 		 */
88236794902SKuninori Morimoto 		if (!!platform->name == !!platform->of_node) {
88336794902SKuninori Morimoto 			dev_err(card->dev,
88436794902SKuninori Morimoto 				"ASoC: Neither/both platform name/of_node are set for %s\n",
88536794902SKuninori Morimoto 				link->name);
88636794902SKuninori Morimoto 			return -EINVAL;
88736794902SKuninori Morimoto 		}
88836794902SKuninori Morimoto 
88936794902SKuninori Morimoto 		/*
89036794902SKuninori Morimoto 		 * Defer card registration if platform component is not added to
89136794902SKuninori Morimoto 		 * component list.
89236794902SKuninori Morimoto 		 */
893b2acc24cSRanjani Sridharan 		if (!soc_find_component(platform)) {
894b2acc24cSRanjani Sridharan 			dev_dbg(card->dev,
895b2acc24cSRanjani Sridharan 				"ASoC: platform component %s not found for link %s\n",
896b2acc24cSRanjani Sridharan 				platform->name, link->name);
89736794902SKuninori Morimoto 			return -EPROBE_DEFER;
89836794902SKuninori Morimoto 		}
899b2acc24cSRanjani Sridharan 	}
90036794902SKuninori Morimoto 
90176afa643SShreyas NC 	for_each_link_cpus(link, i, cpu) {
90236794902SKuninori Morimoto 		/*
90336794902SKuninori Morimoto 		 * CPU device may be specified by either name or OF node, but
90436794902SKuninori Morimoto 		 * can be left unspecified, and will be matched based on DAI
90536794902SKuninori Morimoto 		 * name alone..
90636794902SKuninori Morimoto 		 */
90776afa643SShreyas NC 		if (cpu->name && cpu->of_node) {
90836794902SKuninori Morimoto 			dev_err(card->dev,
90936794902SKuninori Morimoto 				"ASoC: Neither/both cpu name/of_node are set for %s\n",
91036794902SKuninori Morimoto 				link->name);
91136794902SKuninori Morimoto 			return -EINVAL;
91236794902SKuninori Morimoto 		}
91336794902SKuninori Morimoto 
91436794902SKuninori Morimoto 		/*
915cd3c5ad7SKuninori Morimoto 		 * Defer card registration if cpu dai component is not added to
91636794902SKuninori Morimoto 		 * component list.
91736794902SKuninori Morimoto 		 */
91876afa643SShreyas NC 		if ((cpu->of_node || cpu->name) &&
919b2acc24cSRanjani Sridharan 		    !soc_find_component(cpu)) {
920b2acc24cSRanjani Sridharan 			dev_dbg(card->dev,
921b2acc24cSRanjani Sridharan 				"ASoC: cpu component %s not found for link %s\n",
922b2acc24cSRanjani Sridharan 				cpu->name, link->name);
92336794902SKuninori Morimoto 			return -EPROBE_DEFER;
924b2acc24cSRanjani Sridharan 		}
92536794902SKuninori Morimoto 
92636794902SKuninori Morimoto 		/*
92736794902SKuninori Morimoto 		 * At least one of CPU DAI name or CPU device name/node must be
92836794902SKuninori Morimoto 		 * specified
92936794902SKuninori Morimoto 		 */
93076afa643SShreyas NC 		if (!cpu->dai_name &&
93176afa643SShreyas NC 		    !(cpu->name || cpu->of_node)) {
93236794902SKuninori Morimoto 			dev_err(card->dev,
93336794902SKuninori Morimoto 				"ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
93436794902SKuninori Morimoto 				link->name);
93536794902SKuninori Morimoto 			return -EINVAL;
93636794902SKuninori Morimoto 		}
93776afa643SShreyas NC 	}
93836794902SKuninori Morimoto 
93936794902SKuninori Morimoto 	return 0;
94036794902SKuninori Morimoto }
94136794902SKuninori Morimoto 
942da704f26SKuninori Morimoto /**
94350cd9b53SKuninori Morimoto  * snd_soc_remove_pcm_runtime - Remove a pcm_runtime from card
94450cd9b53SKuninori Morimoto  * @card: The ASoC card to which the pcm_runtime has
94550cd9b53SKuninori Morimoto  * @rtd: The pcm_runtime to remove
946da704f26SKuninori Morimoto  *
94750cd9b53SKuninori Morimoto  * This function removes a pcm_runtime from the ASoC card.
948da704f26SKuninori Morimoto  */
94950cd9b53SKuninori Morimoto void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
95050cd9b53SKuninori Morimoto 				struct snd_soc_pcm_runtime *rtd)
951bc7a9091SKuninori Morimoto {
952da704f26SKuninori Morimoto 	lockdep_assert_held(&client_mutex);
953da704f26SKuninori Morimoto 
95421a00fb3SPierre-Louis Bossart 	/* release machine specific resources */
95521a00fb3SPierre-Louis Bossart 	snd_soc_link_exit(rtd);
95621a00fb3SPierre-Louis Bossart 
957da704f26SKuninori Morimoto 	/*
958da704f26SKuninori Morimoto 	 * Notify the machine driver for extra destruction
959da704f26SKuninori Morimoto 	 */
960fcbbcc32SKuninori Morimoto 	snd_soc_card_remove_dai_link(card, rtd->dai_link);
961da704f26SKuninori Morimoto 
962bc7a9091SKuninori Morimoto 	soc_free_pcm_runtime(rtd);
963bc7a9091SKuninori Morimoto }
96450cd9b53SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_remove_pcm_runtime);
965bc7a9091SKuninori Morimoto 
96663dc47daSKuninori Morimoto /**
9670c048004SKuninori Morimoto  * snd_soc_add_pcm_runtime - Add a pcm_runtime dynamically via dai_link
9680c048004SKuninori Morimoto  * @card: The ASoC card to which the pcm_runtime is added
9690c048004SKuninori Morimoto  * @dai_link: The DAI link to find pcm_runtime
97063dc47daSKuninori Morimoto  *
9710c048004SKuninori Morimoto  * This function adds a pcm_runtime ASoC card by using dai_link.
97263dc47daSKuninori Morimoto  *
9730c048004SKuninori Morimoto  * Note: Topology can use this API to add pcm_runtime when probing the
97463dc47daSKuninori Morimoto  * topology component. And machine drivers can still define static
97563dc47daSKuninori Morimoto  * DAI links in dai_link array.
97663dc47daSKuninori Morimoto  */
9770c048004SKuninori Morimoto int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
9786f2f1ff0SMengdong Lin 			    struct snd_soc_dai_link *dai_link)
979db2a4165SFrank Mandarino {
9801a497983SMengdong Lin 	struct snd_soc_pcm_runtime *rtd;
98176afa643SShreyas NC 	struct snd_soc_dai_link_component *codec, *platform, *cpu;
98290be711eSKuninori Morimoto 	struct snd_soc_component *component;
983bfce78a5SKuninori Morimoto 	int i, ret;
984db2a4165SFrank Mandarino 
98563dc47daSKuninori Morimoto 	lockdep_assert_held(&client_mutex);
98663dc47daSKuninori Morimoto 
98763dc47daSKuninori Morimoto 	/*
98863dc47daSKuninori Morimoto 	 * Notify the machine driver for extra initialization
98963dc47daSKuninori Morimoto 	 */
990cbc7a6b5SKuninori Morimoto 	ret = snd_soc_card_add_dai_link(card, dai_link);
991cbc7a6b5SKuninori Morimoto 	if (ret < 0)
992cbc7a6b5SKuninori Morimoto 		return ret;
99363dc47daSKuninori Morimoto 
994a655de80SLiam Girdwood 	if (dai_link->ignore)
995a655de80SLiam Girdwood 		return 0;
996a655de80SLiam Girdwood 
9976f2f1ff0SMengdong Lin 	dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
9986308419aSMark Brown 
999bfce78a5SKuninori Morimoto 	ret = soc_dai_link_sanity_check(card, dai_link);
1000bfce78a5SKuninori Morimoto 	if (ret < 0)
1001bfce78a5SKuninori Morimoto 		return ret;
1002bfce78a5SKuninori Morimoto 
1003513cb311SSudip Mukherjee 	rtd = soc_new_pcm_runtime(card, dai_link);
1004513cb311SSudip Mukherjee 	if (!rtd)
1005513cb311SSudip Mukherjee 		return -ENOMEM;
1006513cb311SSudip Mukherjee 
100776afa643SShreyas NC 	for_each_link_cpus(dai_link, i, cpu) {
1008c2233a26SKuninori Morimoto 		asoc_rtd_to_cpu(rtd, i) = snd_soc_find_dai(cpu);
1009c2233a26SKuninori Morimoto 		if (!asoc_rtd_to_cpu(rtd, i)) {
10106b490879SMartin Hundebøll 			dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
101176afa643SShreyas NC 				 cpu->dai_name);
10121a497983SMengdong Lin 			goto _err_defer;
1013c5af3a2eSMark Brown 		}
1014c2233a26SKuninori Morimoto 		snd_soc_rtd_add_component(rtd, asoc_rtd_to_cpu(rtd, i)->component);
101576afa643SShreyas NC 	}
101676afa643SShreyas NC 
101788bd870fSBenoit Cousson 	/* Find CODEC from registered CODECs */
101834614739SJerome Brunet 	for_each_link_codecs(dai_link, i, codec) {
1019c2233a26SKuninori Morimoto 		asoc_rtd_to_codec(rtd, i) = snd_soc_find_dai(codec);
1020c2233a26SKuninori Morimoto 		if (!asoc_rtd_to_codec(rtd, i)) {
10217c7e2d6aSStefan Agner 			dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n",
102234614739SJerome Brunet 				 codec->dai_name);
10231a497983SMengdong Lin 			goto _err_defer;
102412023a9aSMisael Lopez Cruz 		}
102534614739SJerome Brunet 
1026c2233a26SKuninori Morimoto 		snd_soc_rtd_add_component(rtd, asoc_rtd_to_codec(rtd, i)->component);
102788bd870fSBenoit Cousson 	}
102888bd870fSBenoit Cousson 
1029e2b30edfSKuninori Morimoto 	/* Find PLATFORM from registered PLATFORMs */
103034614739SJerome Brunet 	for_each_link_platforms(dai_link, i, platform) {
1031368dee94SKuninori Morimoto 		for_each_component(component) {
103234614739SJerome Brunet 			if (!snd_soc_is_matching_component(platform, component))
103390be711eSKuninori Morimoto 				continue;
103490be711eSKuninori Morimoto 
103512b05232SKuninori Morimoto 			snd_soc_rtd_add_component(rtd, component);
103690be711eSKuninori Morimoto 		}
103734614739SJerome Brunet 	}
103890be711eSKuninori Morimoto 
1039b19e6e7bSMark Brown 	return 0;
10401a497983SMengdong Lin 
10411a497983SMengdong Lin _err_defer:
104250cd9b53SKuninori Morimoto 	snd_soc_remove_pcm_runtime(card, rtd);
10431a497983SMengdong Lin 	return -EPROBE_DEFER;
10446b05eda6SMark Brown }
10450c048004SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtime);
10466b05eda6SMark Brown 
1047eaffeefbSKuninori Morimoto static int soc_init_pcm_runtime(struct snd_soc_card *card,
104846496acbSKuninori Morimoto 				struct snd_soc_pcm_runtime *rtd)
104946496acbSKuninori Morimoto {
105046496acbSKuninori Morimoto 	struct snd_soc_dai_link *dai_link = rtd->dai_link;
1051c2233a26SKuninori Morimoto 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
105246496acbSKuninori Morimoto 	struct snd_soc_component *component;
1053613fb500SKuninori Morimoto 	int ret, num, i;
105446496acbSKuninori Morimoto 
105546496acbSKuninori Morimoto 	/* set default power off timeout */
105646496acbSKuninori Morimoto 	rtd->pmdown_time = pmdown_time;
105746496acbSKuninori Morimoto 
105846496acbSKuninori Morimoto 	/* do machine specific initialization */
105902e75636SKuninori Morimoto 	ret = snd_soc_link_init(rtd);
106002e75636SKuninori Morimoto 	if (ret < 0)
106146496acbSKuninori Morimoto 		return ret;
106246496acbSKuninori Morimoto 
106346496acbSKuninori Morimoto 	if (dai_link->dai_fmt) {
106446496acbSKuninori Morimoto 		ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
106546496acbSKuninori Morimoto 		if (ret)
106646496acbSKuninori Morimoto 			return ret;
106746496acbSKuninori Morimoto 	}
106846496acbSKuninori Morimoto 
106946496acbSKuninori Morimoto 	/* add DPCM sysfs entries */
107046496acbSKuninori Morimoto 	soc_dpcm_debugfs_add(rtd);
107146496acbSKuninori Morimoto 
107246496acbSKuninori Morimoto 	num = rtd->num;
107346496acbSKuninori Morimoto 
107446496acbSKuninori Morimoto 	/*
107546496acbSKuninori Morimoto 	 * most drivers will register their PCMs using DAI link ordering but
107646496acbSKuninori Morimoto 	 * topology based drivers can use the DAI link id field to set PCM
107746496acbSKuninori Morimoto 	 * device number and then use rtd + a base offset of the BEs.
107846496acbSKuninori Morimoto 	 */
1079613fb500SKuninori Morimoto 	for_each_rtd_components(rtd, i, component) {
108046496acbSKuninori Morimoto 		if (!component->driver->use_dai_pcm_id)
108146496acbSKuninori Morimoto 			continue;
108246496acbSKuninori Morimoto 
108346496acbSKuninori Morimoto 		if (rtd->dai_link->no_pcm)
108446496acbSKuninori Morimoto 			num += component->driver->be_pcm_base;
108546496acbSKuninori Morimoto 		else
108646496acbSKuninori Morimoto 			num = rtd->dai_link->id;
108746496acbSKuninori Morimoto 	}
108846496acbSKuninori Morimoto 
108946496acbSKuninori Morimoto 	/* create compress_device if possible */
109046496acbSKuninori Morimoto 	ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);
109146496acbSKuninori Morimoto 	if (ret != -ENOTSUPP) {
109246496acbSKuninori Morimoto 		if (ret < 0)
109346496acbSKuninori Morimoto 			dev_err(card->dev, "ASoC: can't create compress %s\n",
109446496acbSKuninori Morimoto 				dai_link->stream_name);
109546496acbSKuninori Morimoto 		return ret;
109646496acbSKuninori Morimoto 	}
109746496acbSKuninori Morimoto 
109846496acbSKuninori Morimoto 	/* create the pcm */
109946496acbSKuninori Morimoto 	ret = soc_new_pcm(rtd, num);
110046496acbSKuninori Morimoto 	if (ret < 0) {
110146496acbSKuninori Morimoto 		dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
110246496acbSKuninori Morimoto 			dai_link->stream_name, ret);
110346496acbSKuninori Morimoto 		return ret;
110446496acbSKuninori Morimoto 	}
1105d1eb6d11SKuninori Morimoto 
11060b73ba55SKuninori Morimoto 	return snd_soc_pcm_dai_new(rtd);
110746496acbSKuninori Morimoto }
110846496acbSKuninori Morimoto 
1109ffd60fbaSKuninori Morimoto static void soc_set_name_prefix(struct snd_soc_card *card,
1110ffd60fbaSKuninori Morimoto 				struct snd_soc_component *component)
1111ffd60fbaSKuninori Morimoto {
1112aec3ff99SKuninori Morimoto 	struct device_node *of_node = soc_component_to_node(component);
111329d9fc7aSKuninori Morimoto 	const char *str;
111429d9fc7aSKuninori Morimoto 	int ret, i;
1115ffd60fbaSKuninori Morimoto 
11164702f991SKuninori Morimoto 	for (i = 0; i < card->num_configs; i++) {
1117ffd60fbaSKuninori Morimoto 		struct snd_soc_codec_conf *map = &card->codec_conf[i];
1118ffd60fbaSKuninori Morimoto 
11193256ef98SSameer Pujar 		if (snd_soc_is_matching_component(&map->dlc, component) &&
11203256ef98SSameer Pujar 		    map->name_prefix) {
1121ffd60fbaSKuninori Morimoto 			component->name_prefix = map->name_prefix;
1122ffd60fbaSKuninori Morimoto 			return;
1123ffd60fbaSKuninori Morimoto 		}
1124c13493a2SKuninori Morimoto 	}
1125ffd60fbaSKuninori Morimoto 
1126ffd60fbaSKuninori Morimoto 	/*
1127ffd60fbaSKuninori Morimoto 	 * If there is no configuration table or no match in the table,
1128ffd60fbaSKuninori Morimoto 	 * check if a prefix is provided in the node
1129ffd60fbaSKuninori Morimoto 	 */
113029d9fc7aSKuninori Morimoto 	ret = of_property_read_string(of_node, "sound-name-prefix", &str);
113129d9fc7aSKuninori Morimoto 	if (ret < 0)
113229d9fc7aSKuninori Morimoto 		return;
113329d9fc7aSKuninori Morimoto 
113429d9fc7aSKuninori Morimoto 	component->name_prefix = str;
1135ffd60fbaSKuninori Morimoto }
1136ffd60fbaSKuninori Morimoto 
1137c6619b72SKuninori Morimoto static void soc_remove_component(struct snd_soc_component *component,
1138c6619b72SKuninori Morimoto 				 int probed)
113922d14231SKuninori Morimoto {
1140c6619b72SKuninori Morimoto 
1141c6619b72SKuninori Morimoto 	if (!component->card)
1142c6619b72SKuninori Morimoto 		return;
1143c6619b72SKuninori Morimoto 
1144c6619b72SKuninori Morimoto 	if (probed)
1145c6619b72SKuninori Morimoto 		snd_soc_component_remove(component);
1146c6619b72SKuninori Morimoto 
114704f770d9SKuninori Morimoto 	/* For framework level robustness */
11483bb936f5SAmadeusz Sławiński 	snd_soc_component_set_jack(component, NULL, NULL);
114904f770d9SKuninori Morimoto 
11507a5d9815SBard liao 	list_del_init(&component->card_list);
115122d14231SKuninori Morimoto 	snd_soc_dapm_free(snd_soc_component_get_dapm(component));
115222d14231SKuninori Morimoto 	soc_cleanup_component_debugfs(component);
115322d14231SKuninori Morimoto 	component->card = NULL;
11540e36f36bSPierre-Louis Bossart 	snd_soc_component_module_put_when_remove(component);
115522d14231SKuninori Morimoto }
115622d14231SKuninori Morimoto 
1157ffd60fbaSKuninori Morimoto static int soc_probe_component(struct snd_soc_card *card,
1158ffd60fbaSKuninori Morimoto 			       struct snd_soc_component *component)
1159ffd60fbaSKuninori Morimoto {
1160ffd60fbaSKuninori Morimoto 	struct snd_soc_dapm_context *dapm =
1161ffd60fbaSKuninori Morimoto 		snd_soc_component_get_dapm(component);
1162ffd60fbaSKuninori Morimoto 	struct snd_soc_dai *dai;
1163c6619b72SKuninori Morimoto 	int probed = 0;
1164ffd60fbaSKuninori Morimoto 	int ret;
1165ffd60fbaSKuninori Morimoto 
1166ffd60fbaSKuninori Morimoto 	if (!strcmp(component->name, "snd-soc-dummy"))
1167ffd60fbaSKuninori Morimoto 		return 0;
1168ffd60fbaSKuninori Morimoto 
1169ffd60fbaSKuninori Morimoto 	if (component->card) {
1170ffd60fbaSKuninori Morimoto 		if (component->card != card) {
1171ffd60fbaSKuninori Morimoto 			dev_err(component->dev,
1172ffd60fbaSKuninori Morimoto 				"Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n",
1173ffd60fbaSKuninori Morimoto 				card->name, component->card->name);
1174ffd60fbaSKuninori Morimoto 			return -ENODEV;
1175ffd60fbaSKuninori Morimoto 		}
1176ffd60fbaSKuninori Morimoto 		return 0;
1177ffd60fbaSKuninori Morimoto 	}
1178ffd60fbaSKuninori Morimoto 
1179ffd60fbaSKuninori Morimoto 	ret = snd_soc_component_module_get_when_probe(component);
1180ffd60fbaSKuninori Morimoto 	if (ret < 0)
1181ffd60fbaSKuninori Morimoto 		return ret;
1182ffd60fbaSKuninori Morimoto 
1183ffd60fbaSKuninori Morimoto 	component->card = card;
1184ffd60fbaSKuninori Morimoto 	soc_set_name_prefix(card, component);
1185ffd60fbaSKuninori Morimoto 
1186ffd60fbaSKuninori Morimoto 	soc_init_component_debugfs(component);
1187ffd60fbaSKuninori Morimoto 
118895c267ddSKuninori Morimoto 	snd_soc_dapm_init(dapm, card, component);
1189b614beafSKuninori Morimoto 
1190ffd60fbaSKuninori Morimoto 	ret = snd_soc_dapm_new_controls(dapm,
1191ffd60fbaSKuninori Morimoto 					component->driver->dapm_widgets,
1192ffd60fbaSKuninori Morimoto 					component->driver->num_dapm_widgets);
1193ffd60fbaSKuninori Morimoto 
1194ffd60fbaSKuninori Morimoto 	if (ret != 0) {
1195ffd60fbaSKuninori Morimoto 		dev_err(component->dev,
1196ffd60fbaSKuninori Morimoto 			"Failed to create new controls %d\n", ret);
1197ffd60fbaSKuninori Morimoto 		goto err_probe;
1198ffd60fbaSKuninori Morimoto 	}
1199ffd60fbaSKuninori Morimoto 
1200ffd60fbaSKuninori Morimoto 	for_each_component_dais(component, dai) {
1201ffd60fbaSKuninori Morimoto 		ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1202ffd60fbaSKuninori Morimoto 		if (ret != 0) {
1203ffd60fbaSKuninori Morimoto 			dev_err(component->dev,
1204ffd60fbaSKuninori Morimoto 				"Failed to create DAI widgets %d\n", ret);
1205ffd60fbaSKuninori Morimoto 			goto err_probe;
1206ffd60fbaSKuninori Morimoto 		}
1207ffd60fbaSKuninori Morimoto 	}
1208ffd60fbaSKuninori Morimoto 
1209ffd60fbaSKuninori Morimoto 	ret = snd_soc_component_probe(component);
1210ffd60fbaSKuninori Morimoto 	if (ret < 0) {
1211ffd60fbaSKuninori Morimoto 		dev_err(component->dev,
1212ffd60fbaSKuninori Morimoto 			"ASoC: failed to probe component %d\n", ret);
1213ffd60fbaSKuninori Morimoto 		goto err_probe;
1214ffd60fbaSKuninori Morimoto 	}
1215ffd60fbaSKuninori Morimoto 	WARN(dapm->idle_bias_off &&
1216ffd60fbaSKuninori Morimoto 	     dapm->bias_level != SND_SOC_BIAS_OFF,
1217ffd60fbaSKuninori Morimoto 	     "codec %s can not start from non-off bias with idle_bias_off==1\n",
1218ffd60fbaSKuninori Morimoto 	     component->name);
1219c6619b72SKuninori Morimoto 	probed = 1;
1220ffd60fbaSKuninori Morimoto 
1221257c4dacSKuninori Morimoto 	/*
1222257c4dacSKuninori Morimoto 	 * machine specific init
1223257c4dacSKuninori Morimoto 	 * see
1224257c4dacSKuninori Morimoto 	 *	snd_soc_component_set_aux()
1225257c4dacSKuninori Morimoto 	 */
1226257c4dacSKuninori Morimoto 	ret = snd_soc_component_init(component);
1227257c4dacSKuninori Morimoto 	if (ret < 0)
1228ffd60fbaSKuninori Morimoto 		goto err_probe;
1229ffd60fbaSKuninori Morimoto 
1230ffd60fbaSKuninori Morimoto 	ret = snd_soc_add_component_controls(component,
1231ffd60fbaSKuninori Morimoto 					     component->driver->controls,
1232ffd60fbaSKuninori Morimoto 					     component->driver->num_controls);
1233ffd60fbaSKuninori Morimoto 	if (ret < 0)
1234ffd60fbaSKuninori Morimoto 		goto err_probe;
1235ffd60fbaSKuninori Morimoto 
1236ffd60fbaSKuninori Morimoto 	ret = snd_soc_dapm_add_routes(dapm,
1237ffd60fbaSKuninori Morimoto 				      component->driver->dapm_routes,
1238ffd60fbaSKuninori Morimoto 				      component->driver->num_dapm_routes);
1239a22ae72bSPierre-Louis Bossart 	if (ret < 0) {
1240a22ae72bSPierre-Louis Bossart 		if (card->disable_route_checks) {
1241a22ae72bSPierre-Louis Bossart 			dev_info(card->dev,
1242a22ae72bSPierre-Louis Bossart 				 "%s: disable_route_checks set, ignoring errors on add_routes\n",
1243a22ae72bSPierre-Louis Bossart 				 __func__);
1244a22ae72bSPierre-Louis Bossart 		} else {
1245a22ae72bSPierre-Louis Bossart 			dev_err(card->dev,
1246a22ae72bSPierre-Louis Bossart 				"%s: snd_soc_dapm_add_routes failed: %d\n",
1247a22ae72bSPierre-Louis Bossart 				__func__, ret);
1248ffd60fbaSKuninori Morimoto 			goto err_probe;
1249a22ae72bSPierre-Louis Bossart 		}
1250a22ae72bSPierre-Louis Bossart 	}
1251ffd60fbaSKuninori Morimoto 
1252ffd60fbaSKuninori Morimoto 	/* see for_each_card_components */
1253ffd60fbaSKuninori Morimoto 	list_add(&component->card_list, &card->component_dev_list);
1254ffd60fbaSKuninori Morimoto 
1255ffd60fbaSKuninori Morimoto err_probe:
1256ffd60fbaSKuninori Morimoto 	if (ret < 0)
1257c6619b72SKuninori Morimoto 		soc_remove_component(component, probed);
1258ffd60fbaSKuninori Morimoto 
1259ffd60fbaSKuninori Morimoto 	return ret;
1260ffd60fbaSKuninori Morimoto }
1261ffd60fbaSKuninori Morimoto 
12624ca47d21SKuninori Morimoto static void soc_remove_link_dais(struct snd_soc_card *card)
1263f0fba2adSLiam Girdwood {
12644ca47d21SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
12654ca47d21SKuninori Morimoto 	int order;
12664ca47d21SKuninori Morimoto 
12674ca47d21SKuninori Morimoto 	for_each_comp_order(order) {
12684ca47d21SKuninori Morimoto 		for_each_card_rtds(card, rtd) {
12697eaa313bSKuninori Morimoto 			/* remove all rtd connected DAIs in good order */
12707eaa313bSKuninori Morimoto 			snd_soc_pcm_dai_remove(rtd, order);
1271f0fba2adSLiam Girdwood 		}
12724ca47d21SKuninori Morimoto 	}
12734ca47d21SKuninori Morimoto }
1274f0fba2adSLiam Girdwood 
1275bc7c16c2SKuninori Morimoto static int soc_probe_link_dais(struct snd_soc_card *card)
1276bc7c16c2SKuninori Morimoto {
1277bc7c16c2SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
127851801aeaSKuninori Morimoto 	int order, ret;
1279bc7c16c2SKuninori Morimoto 
1280bc7c16c2SKuninori Morimoto 	for_each_comp_order(order) {
1281bc7c16c2SKuninori Morimoto 		for_each_card_rtds(card, rtd) {
1282bc7c16c2SKuninori Morimoto 
1283bc7c16c2SKuninori Morimoto 			dev_dbg(card->dev,
1284bc7c16c2SKuninori Morimoto 				"ASoC: probe %s dai link %d late %d\n",
1285bc7c16c2SKuninori Morimoto 				card->name, rtd->num, order);
1286bc7c16c2SKuninori Morimoto 
128751801aeaSKuninori Morimoto 			/* probe all rtd connected DAIs in good order */
128851801aeaSKuninori Morimoto 			ret = snd_soc_pcm_dai_probe(rtd, order);
1289bc7c16c2SKuninori Morimoto 			if (ret)
1290bc7c16c2SKuninori Morimoto 				return ret;
1291bc7c16c2SKuninori Morimoto 		}
1292bc7c16c2SKuninori Morimoto 	}
1293bc7c16c2SKuninori Morimoto 
1294bc7c16c2SKuninori Morimoto 	return 0;
1295bc7c16c2SKuninori Morimoto }
1296bc7c16c2SKuninori Morimoto 
1297b006c0c6SKuninori Morimoto static void soc_remove_link_components(struct snd_soc_card *card)
129862ae68faSStephen Warren {
129961aca564SLars-Peter Clausen 	struct snd_soc_component *component;
1300b006c0c6SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
1301613fb500SKuninori Morimoto 	int i, order;
130262ae68faSStephen Warren 
1303b006c0c6SKuninori Morimoto 	for_each_comp_order(order) {
1304b006c0c6SKuninori Morimoto 		for_each_card_rtds(card, rtd) {
1305613fb500SKuninori Morimoto 			for_each_rtd_components(rtd, i, component) {
1306b006c0c6SKuninori Morimoto 				if (component->driver->remove_order != order)
1307b006c0c6SKuninori Morimoto 					continue;
1308b006c0c6SKuninori Morimoto 
1309c6619b72SKuninori Morimoto 				soc_remove_component(component, 1);
131062ae68faSStephen Warren 			}
131162ae68faSStephen Warren 		}
1312b006c0c6SKuninori Morimoto 	}
1313b006c0c6SKuninori Morimoto }
131462ae68faSStephen Warren 
131562f07a6bSKuninori Morimoto static int soc_probe_link_components(struct snd_soc_card *card)
13166fb03550SKuninori Morimoto {
13176fb03550SKuninori Morimoto 	struct snd_soc_component *component;
131862f07a6bSKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd;
1319613fb500SKuninori Morimoto 	int i, ret, order;
13206fb03550SKuninori Morimoto 
132162f07a6bSKuninori Morimoto 	for_each_comp_order(order) {
132262f07a6bSKuninori Morimoto 		for_each_card_rtds(card, rtd) {
1323613fb500SKuninori Morimoto 			for_each_rtd_components(rtd, i, component) {
132462f07a6bSKuninori Morimoto 				if (component->driver->probe_order != order)
132562f07a6bSKuninori Morimoto 					continue;
132662f07a6bSKuninori Morimoto 
13276fb03550SKuninori Morimoto 				ret = soc_probe_component(card, component);
13286fb03550SKuninori Morimoto 				if (ret < 0)
13296fb03550SKuninori Morimoto 					return ret;
13306fb03550SKuninori Morimoto 			}
13316fb03550SKuninori Morimoto 		}
133262f07a6bSKuninori Morimoto 	}
13336fb03550SKuninori Morimoto 
13346fb03550SKuninori Morimoto 	return 0;
13356fb03550SKuninori Morimoto }
13366fb03550SKuninori Morimoto 
1337e8fbd250SKuninori Morimoto static void soc_unbind_aux_dev(struct snd_soc_card *card)
13384893a2ebSKuninori Morimoto {
1339e8fbd250SKuninori Morimoto 	struct snd_soc_component *component, *_component;
1340e8fbd250SKuninori Morimoto 
1341e8fbd250SKuninori Morimoto 	for_each_card_auxs_safe(card, component, _component) {
1342257c4dacSKuninori Morimoto 		/* for snd_soc_component_init() */
1343257c4dacSKuninori Morimoto 		snd_soc_component_set_aux(component, NULL);
13444893a2ebSKuninori Morimoto 		list_del(&component->card_aux_list);
13454893a2ebSKuninori Morimoto 	}
1346e8fbd250SKuninori Morimoto }
13474893a2ebSKuninori Morimoto 
1348bee886f1SKuninori Morimoto static int soc_bind_aux_dev(struct snd_soc_card *card)
1349b19e6e7bSMark Brown {
1350f2ed6b07SMengdong Lin 	struct snd_soc_component *component;
1351bee886f1SKuninori Morimoto 	struct snd_soc_aux_dev *aux;
1352bee886f1SKuninori Morimoto 	int i;
13533ca041edSSebastian Reichel 
1354bee886f1SKuninori Morimoto 	for_each_card_pre_auxs(card, i, aux) {
1355f2ed6b07SMengdong Lin 		/* codecs, usually analog devices */
1356bee886f1SKuninori Morimoto 		component = soc_find_component(&aux->dlc);
1357f2ed6b07SMengdong Lin 		if (!component)
13583dc29b8bSKuninori Morimoto 			return -EPROBE_DEFER;
13593ca041edSSebastian Reichel 
1360257c4dacSKuninori Morimoto 		/* for snd_soc_component_init() */
1361257c4dacSKuninori Morimoto 		snd_soc_component_set_aux(component, aux);
1362c2b71c71SKuninori Morimoto 		/* see for_each_card_auxs */
1363d2e3a135SSylwester Nawrocki 		list_add(&component->card_aux_list, &card->aux_comp_list);
1364bee886f1SKuninori Morimoto 	}
1365f2ed6b07SMengdong Lin 	return 0;
1366b19e6e7bSMark Brown }
1367b19e6e7bSMark Brown 
1368f2ed6b07SMengdong Lin static int soc_probe_aux_devices(struct snd_soc_card *card)
1369f2ed6b07SMengdong Lin {
137074bd3f92SKuninori Morimoto 	struct snd_soc_component *component;
1371f2ed6b07SMengdong Lin 	int order;
1372f2ed6b07SMengdong Lin 	int ret;
1373f2ed6b07SMengdong Lin 
13741a1035a9SKuninori Morimoto 	for_each_comp_order(order) {
137574bd3f92SKuninori Morimoto 		for_each_card_auxs(card, component) {
137674bd3f92SKuninori Morimoto 			if (component->driver->probe_order != order)
137774bd3f92SKuninori Morimoto 				continue;
137874bd3f92SKuninori Morimoto 
137974bd3f92SKuninori Morimoto 			ret = soc_probe_component(card,	component);
138074bd3f92SKuninori Morimoto 			if (ret < 0)
1381f2ed6b07SMengdong Lin 				return ret;
1382f2ed6b07SMengdong Lin 		}
1383f2ed6b07SMengdong Lin 	}
138465d9361fSLars-Peter Clausen 
138544c69bb1SLars-Peter Clausen 	return 0;
13863ca041edSSebastian Reichel }
13872eea392dSJarkko Nikula 
1388f2ed6b07SMengdong Lin static void soc_remove_aux_devices(struct snd_soc_card *card)
138944c69bb1SLars-Peter Clausen {
1390f2ed6b07SMengdong Lin 	struct snd_soc_component *comp, *_comp;
1391f2ed6b07SMengdong Lin 	int order;
139244c69bb1SLars-Peter Clausen 
13931a1035a9SKuninori Morimoto 	for_each_comp_order(order) {
1394c2b71c71SKuninori Morimoto 		for_each_card_auxs_safe(card, comp, _comp) {
1395e8fbd250SKuninori Morimoto 			if (comp->driver->remove_order == order)
1396c6619b72SKuninori Morimoto 				soc_remove_component(comp, 1);
13975f3484acSLars-Peter Clausen 		}
13982eea392dSJarkko Nikula 	}
13992eea392dSJarkko Nikula }
14002eea392dSJarkko Nikula 
1401ce64c8b9SLars-Peter Clausen /**
1402ce64c8b9SLars-Peter Clausen  * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
1403ce64c8b9SLars-Peter Clausen  * @rtd: The runtime for which the DAI link format should be changed
1404ce64c8b9SLars-Peter Clausen  * @dai_fmt: The new DAI link format
1405ce64c8b9SLars-Peter Clausen  *
1406ce64c8b9SLars-Peter Clausen  * This function updates the DAI link format for all DAIs connected to the DAI
1407ce64c8b9SLars-Peter Clausen  * link for the specified runtime.
1408ce64c8b9SLars-Peter Clausen  *
1409ce64c8b9SLars-Peter Clausen  * Note: For setups with a static format set the dai_fmt field in the
1410ce64c8b9SLars-Peter Clausen  * corresponding snd_dai_link struct instead of using this function.
1411ce64c8b9SLars-Peter Clausen  *
1412ce64c8b9SLars-Peter Clausen  * Returns 0 on success, otherwise a negative error code.
1413ce64c8b9SLars-Peter Clausen  */
1414ce64c8b9SLars-Peter Clausen int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
1415ce64c8b9SLars-Peter Clausen 	unsigned int dai_fmt)
1416ce64c8b9SLars-Peter Clausen {
141776afa643SShreyas NC 	struct snd_soc_dai *cpu_dai;
14180b7990e3SKuninori Morimoto 	struct snd_soc_dai *codec_dai;
141976afa643SShreyas NC 	unsigned int inv_dai_fmt;
1420ce64c8b9SLars-Peter Clausen 	unsigned int i;
1421ce64c8b9SLars-Peter Clausen 	int ret;
1422ce64c8b9SLars-Peter Clausen 
1423a4be4187SKuninori Morimoto 	for_each_rtd_codec_dais(rtd, i, codec_dai) {
1424ce64c8b9SLars-Peter Clausen 		ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1425ce64c8b9SLars-Peter Clausen 		if (ret != 0 && ret != -ENOTSUPP) {
1426ce64c8b9SLars-Peter Clausen 			dev_warn(codec_dai->dev,
1427ce64c8b9SLars-Peter Clausen 				 "ASoC: Failed to set DAI format: %d\n", ret);
1428ce64c8b9SLars-Peter Clausen 			return ret;
1429ce64c8b9SLars-Peter Clausen 		}
1430ce64c8b9SLars-Peter Clausen 	}
1431ce64c8b9SLars-Peter Clausen 
14322c7b696aSMarcel Ziswiler 	/*
14332c7b696aSMarcel Ziswiler 	 * Flip the polarity for the "CPU" end of a CODEC<->CODEC link
14342c7b696aSMarcel Ziswiler 	 * the component which has non_legacy_dai_naming is Codec
14352c7b696aSMarcel Ziswiler 	 */
1436ce64c8b9SLars-Peter Clausen 	inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1437ce64c8b9SLars-Peter Clausen 	switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1438ce64c8b9SLars-Peter Clausen 	case SND_SOC_DAIFMT_CBM_CFM:
1439ce64c8b9SLars-Peter Clausen 		inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1440ce64c8b9SLars-Peter Clausen 		break;
1441ce64c8b9SLars-Peter Clausen 	case SND_SOC_DAIFMT_CBM_CFS:
1442ce64c8b9SLars-Peter Clausen 		inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1443ce64c8b9SLars-Peter Clausen 		break;
1444ce64c8b9SLars-Peter Clausen 	case SND_SOC_DAIFMT_CBS_CFM:
1445ce64c8b9SLars-Peter Clausen 		inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1446ce64c8b9SLars-Peter Clausen 		break;
1447ce64c8b9SLars-Peter Clausen 	case SND_SOC_DAIFMT_CBS_CFS:
1448ce64c8b9SLars-Peter Clausen 		inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1449ce64c8b9SLars-Peter Clausen 		break;
1450ce64c8b9SLars-Peter Clausen 	}
1451a4be4187SKuninori Morimoto 	for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
145276afa643SShreyas NC 		unsigned int fmt = dai_fmt;
1453ce64c8b9SLars-Peter Clausen 
145476afa643SShreyas NC 		if (cpu_dai->component->driver->non_legacy_dai_naming)
145576afa643SShreyas NC 			fmt = inv_dai_fmt;
1456ce64c8b9SLars-Peter Clausen 
145776afa643SShreyas NC 		ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
1458ce64c8b9SLars-Peter Clausen 		if (ret != 0 && ret != -ENOTSUPP) {
1459ce64c8b9SLars-Peter Clausen 			dev_warn(cpu_dai->dev,
1460ce64c8b9SLars-Peter Clausen 				 "ASoC: Failed to set DAI format: %d\n", ret);
1461ce64c8b9SLars-Peter Clausen 			return ret;
1462ce64c8b9SLars-Peter Clausen 		}
146376afa643SShreyas NC 	}
1464ce64c8b9SLars-Peter Clausen 
1465ce64c8b9SLars-Peter Clausen 	return 0;
1466ce64c8b9SLars-Peter Clausen }
1467ddaca25aSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
1468ce64c8b9SLars-Peter Clausen 
14691f5a4535STakashi Iwai #ifdef CONFIG_DMI
14702c7b696aSMarcel Ziswiler /*
14718a6a6a38SKuninori Morimoto  * If a DMI filed contain strings in this blacklist (e.g.
14728a6a6a38SKuninori Morimoto  * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
14738a6a6a38SKuninori Morimoto  * as invalid and dropped when setting the card long name from DMI info.
14748a6a6a38SKuninori Morimoto  */
14758a6a6a38SKuninori Morimoto static const char * const dmi_blacklist[] = {
14768a6a6a38SKuninori Morimoto 	"To be filled by OEM",
14778a6a6a38SKuninori Morimoto 	"TBD by OEM",
14788a6a6a38SKuninori Morimoto 	"Default String",
14798a6a6a38SKuninori Morimoto 	"Board Manufacturer",
14808a6a6a38SKuninori Morimoto 	"Board Vendor Name",
14818a6a6a38SKuninori Morimoto 	"Board Product Name",
14828a6a6a38SKuninori Morimoto 	NULL,	/* terminator */
14838a6a6a38SKuninori Morimoto };
14848a6a6a38SKuninori Morimoto 
14858a6a6a38SKuninori Morimoto /*
14862c7b696aSMarcel Ziswiler  * Trim special characters, and replace '-' with '_' since '-' is used to
1487345233d7SLiam Girdwood  * separate different DMI fields in the card long name. Only number and
1488345233d7SLiam Girdwood  * alphabet characters and a few separator characters are kept.
1489345233d7SLiam Girdwood  */
1490345233d7SLiam Girdwood static void cleanup_dmi_name(char *name)
1491345233d7SLiam Girdwood {
1492345233d7SLiam Girdwood 	int i, j = 0;
1493345233d7SLiam Girdwood 
1494345233d7SLiam Girdwood 	for (i = 0; name[i]; i++) {
1495345233d7SLiam Girdwood 		if (isalnum(name[i]) || (name[i] == '.')
1496345233d7SLiam Girdwood 		    || (name[i] == '_'))
1497345233d7SLiam Girdwood 			name[j++] = name[i];
1498345233d7SLiam Girdwood 		else if (name[i] == '-')
1499345233d7SLiam Girdwood 			name[j++] = '_';
1500345233d7SLiam Girdwood 	}
1501345233d7SLiam Girdwood 
1502345233d7SLiam Girdwood 	name[j] = '\0';
1503345233d7SLiam Girdwood }
1504345233d7SLiam Girdwood 
15052c7b696aSMarcel Ziswiler /*
15062c7b696aSMarcel Ziswiler  * Check if a DMI field is valid, i.e. not containing any string
150798faf436SMengdong Lin  * in the black list.
150898faf436SMengdong Lin  */
150998faf436SMengdong Lin static int is_dmi_valid(const char *field)
151098faf436SMengdong Lin {
151198faf436SMengdong Lin 	int i = 0;
151298faf436SMengdong Lin 
151398faf436SMengdong Lin 	while (dmi_blacklist[i]) {
151498faf436SMengdong Lin 		if (strstr(field, dmi_blacklist[i]))
151598faf436SMengdong Lin 			return 0;
151698faf436SMengdong Lin 		i++;
151746b5a4d2SWu Fengguang 	}
151898faf436SMengdong Lin 
151998faf436SMengdong Lin 	return 1;
152098faf436SMengdong Lin }
152198faf436SMengdong Lin 
15224e01e5dbSJaroslav Kysela /*
15234e01e5dbSJaroslav Kysela  * Append a string to card->dmi_longname with character cleanups.
15244e01e5dbSJaroslav Kysela  */
15254e01e5dbSJaroslav Kysela static void append_dmi_string(struct snd_soc_card *card, const char *str)
15264e01e5dbSJaroslav Kysela {
15274e01e5dbSJaroslav Kysela 	char *dst = card->dmi_longname;
15284e01e5dbSJaroslav Kysela 	size_t dst_len = sizeof(card->dmi_longname);
15294e01e5dbSJaroslav Kysela 	size_t len;
15304e01e5dbSJaroslav Kysela 
15314e01e5dbSJaroslav Kysela 	len = strlen(dst);
15324e01e5dbSJaroslav Kysela 	snprintf(dst + len, dst_len - len, "-%s", str);
15334e01e5dbSJaroslav Kysela 
15344e01e5dbSJaroslav Kysela 	len++;	/* skip the separator "-" */
15354e01e5dbSJaroslav Kysela 	if (len < dst_len)
15364e01e5dbSJaroslav Kysela 		cleanup_dmi_name(dst + len);
15374e01e5dbSJaroslav Kysela }
15384e01e5dbSJaroslav Kysela 
1539345233d7SLiam Girdwood /**
1540345233d7SLiam Girdwood  * snd_soc_set_dmi_name() - Register DMI names to card
1541345233d7SLiam Girdwood  * @card: The card to register DMI names
1542345233d7SLiam Girdwood  * @flavour: The flavour "differentiator" for the card amongst its peers.
1543345233d7SLiam Girdwood  *
1544345233d7SLiam Girdwood  * An Intel machine driver may be used by many different devices but are
1545345233d7SLiam Girdwood  * difficult for userspace to differentiate, since machine drivers ususally
1546345233d7SLiam Girdwood  * use their own name as the card short name and leave the card long name
1547345233d7SLiam Girdwood  * blank. To differentiate such devices and fix bugs due to lack of
1548345233d7SLiam Girdwood  * device-specific configurations, this function allows DMI info to be used
1549345233d7SLiam Girdwood  * as the sound card long name, in the format of
1550345233d7SLiam Girdwood  * "vendor-product-version-board"
1551345233d7SLiam Girdwood  * (Character '-' is used to separate different DMI fields here).
1552345233d7SLiam Girdwood  * This will help the user space to load the device-specific Use Case Manager
1553345233d7SLiam Girdwood  * (UCM) configurations for the card.
1554345233d7SLiam Girdwood  *
1555345233d7SLiam Girdwood  * Possible card long names may be:
1556345233d7SLiam Girdwood  * DellInc.-XPS139343-01-0310JH
1557345233d7SLiam Girdwood  * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
1558345233d7SLiam Girdwood  * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
1559345233d7SLiam Girdwood  *
1560345233d7SLiam Girdwood  * This function also supports flavoring the card longname to provide
1561345233d7SLiam Girdwood  * the extra differentiation, like "vendor-product-version-board-flavor".
1562345233d7SLiam Girdwood  *
1563345233d7SLiam Girdwood  * We only keep number and alphabet characters and a few separator characters
1564345233d7SLiam Girdwood  * in the card long name since UCM in the user space uses the card long names
1565345233d7SLiam Girdwood  * as card configuration directory names and AudoConf cannot support special
1566345233d7SLiam Girdwood  * charactors like SPACE.
1567345233d7SLiam Girdwood  *
1568345233d7SLiam Girdwood  * Returns 0 on success, otherwise a negative error code.
1569345233d7SLiam Girdwood  */
1570345233d7SLiam Girdwood int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
1571345233d7SLiam Girdwood {
1572345233d7SLiam Girdwood 	const char *vendor, *product, *product_version, *board;
1573345233d7SLiam Girdwood 
1574345233d7SLiam Girdwood 	if (card->long_name)
1575345233d7SLiam Girdwood 		return 0; /* long name already set by driver or from DMI */
1576345233d7SLiam Girdwood 
15774e01e5dbSJaroslav Kysela 	/* make up dmi long name as: vendor-product-version-board */
1578345233d7SLiam Girdwood 	vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
157998faf436SMengdong Lin 	if (!vendor || !is_dmi_valid(vendor)) {
1580345233d7SLiam Girdwood 		dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
1581345233d7SLiam Girdwood 		return 0;
1582345233d7SLiam Girdwood 	}
1583345233d7SLiam Girdwood 
15844e01e5dbSJaroslav Kysela 	snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
1585345233d7SLiam Girdwood 	cleanup_dmi_name(card->dmi_longname);
1586345233d7SLiam Girdwood 
1587345233d7SLiam Girdwood 	product = dmi_get_system_info(DMI_PRODUCT_NAME);
158898faf436SMengdong Lin 	if (product && is_dmi_valid(product)) {
15894e01e5dbSJaroslav Kysela 		append_dmi_string(card, product);
1590345233d7SLiam Girdwood 
15912c7b696aSMarcel Ziswiler 		/*
15922c7b696aSMarcel Ziswiler 		 * some vendors like Lenovo may only put a self-explanatory
1593345233d7SLiam Girdwood 		 * name in the product version field
1594345233d7SLiam Girdwood 		 */
1595345233d7SLiam Girdwood 		product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
15964e01e5dbSJaroslav Kysela 		if (product_version && is_dmi_valid(product_version))
15974e01e5dbSJaroslav Kysela 			append_dmi_string(card, product_version);
1598345233d7SLiam Girdwood 	}
1599345233d7SLiam Girdwood 
1600345233d7SLiam Girdwood 	board = dmi_get_system_info(DMI_BOARD_NAME);
160198faf436SMengdong Lin 	if (board && is_dmi_valid(board)) {
160239870b0dSJaroslav Kysela 		if (!product || strcasecmp(board, product))
16034e01e5dbSJaroslav Kysela 			append_dmi_string(card, board);
1604345233d7SLiam Girdwood 	} else if (!product) {
1605345233d7SLiam Girdwood 		/* fall back to using legacy name */
1606345233d7SLiam Girdwood 		dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
1607345233d7SLiam Girdwood 		return 0;
1608345233d7SLiam Girdwood 	}
1609345233d7SLiam Girdwood 
1610345233d7SLiam Girdwood 	/* Add flavour to dmi long name */
16114e01e5dbSJaroslav Kysela 	if (flavour)
16124e01e5dbSJaroslav Kysela 		append_dmi_string(card, flavour);
1613345233d7SLiam Girdwood 
1614345233d7SLiam Girdwood 	/* set the card long name */
1615345233d7SLiam Girdwood 	card->long_name = card->dmi_longname;
1616345233d7SLiam Girdwood 
1617345233d7SLiam Girdwood 	return 0;
1618345233d7SLiam Girdwood }
1619345233d7SLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
16201f5a4535STakashi Iwai #endif /* CONFIG_DMI */
1621345233d7SLiam Girdwood 
1622a655de80SLiam Girdwood static void soc_check_tplg_fes(struct snd_soc_card *card)
1623a655de80SLiam Girdwood {
1624a655de80SLiam Girdwood 	struct snd_soc_component *component;
1625a655de80SLiam Girdwood 	const struct snd_soc_component_driver *comp_drv;
1626a655de80SLiam Girdwood 	struct snd_soc_dai_link *dai_link;
1627a655de80SLiam Girdwood 	int i;
1628a655de80SLiam Girdwood 
1629368dee94SKuninori Morimoto 	for_each_component(component) {
1630a655de80SLiam Girdwood 
163149f9c4f2SDaniel Baluta 		/* does this component override BEs ? */
1632a655de80SLiam Girdwood 		if (!component->driver->ignore_machine)
1633a655de80SLiam Girdwood 			continue;
1634a655de80SLiam Girdwood 
1635a655de80SLiam Girdwood 		/* for this machine ? */
1636e194098bSPierre-Louis Bossart 		if (!strcmp(component->driver->ignore_machine,
1637a655de80SLiam Girdwood 			    card->dev->driver->name))
1638e194098bSPierre-Louis Bossart 			goto match;
1639e194098bSPierre-Louis Bossart 		if (strcmp(component->driver->ignore_machine,
1640e194098bSPierre-Louis Bossart 			   dev_name(card->dev)))
1641a655de80SLiam Girdwood 			continue;
1642e194098bSPierre-Louis Bossart match:
1643a655de80SLiam Girdwood 		/* machine matches, so override the rtd data */
16447fe072b4SKuninori Morimoto 		for_each_card_prelinks(card, i, dai_link) {
1645a655de80SLiam Girdwood 
1646a655de80SLiam Girdwood 			/* ignore this FE */
1647a655de80SLiam Girdwood 			if (dai_link->dynamic) {
1648a655de80SLiam Girdwood 				dai_link->ignore = true;
1649a655de80SLiam Girdwood 				continue;
1650a655de80SLiam Girdwood 			}
1651a655de80SLiam Girdwood 
16521328948fSPierre-Louis Bossart 			dev_dbg(card->dev, "info: override BE DAI link %s\n",
1653a655de80SLiam Girdwood 				card->dai_link[i].name);
1654a655de80SLiam Girdwood 
1655a655de80SLiam Girdwood 			/* override platform component */
1656adb76b5bSKuninori Morimoto 			if (!dai_link->platforms) {
1657daecf46eSKuninori Morimoto 				dev_err(card->dev, "init platform error");
1658daecf46eSKuninori Morimoto 				continue;
1659daecf46eSKuninori Morimoto 			}
1660910fdcabSKuninori Morimoto 			dai_link->platforms->name = component->name;
1661a655de80SLiam Girdwood 
1662a655de80SLiam Girdwood 			/* convert non BE into BE */
1663607fa205SBard Liao 			if (!dai_link->no_pcm) {
1664a655de80SLiam Girdwood 				dai_link->no_pcm = 1;
1665607fa205SBard Liao 
1666607fa205SBard Liao 				if (dai_link->dpcm_playback)
1667607fa205SBard Liao 					dev_warn(card->dev,
1668607fa205SBard Liao 						 "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_playback=1\n",
1669607fa205SBard Liao 						 dai_link->name);
1670607fa205SBard Liao 				if (dai_link->dpcm_capture)
1671607fa205SBard Liao 					dev_warn(card->dev,
1672607fa205SBard Liao 						 "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_capture=1\n",
1673607fa205SBard Liao 						 dai_link->name);
1674607fa205SBard Liao 
1675607fa205SBard Liao 				/* convert normal link into DPCM one */
1676607fa205SBard Liao 				if (!(dai_link->dpcm_playback ||
1677607fa205SBard Liao 				      dai_link->dpcm_capture)) {
1678607fa205SBard Liao 					dai_link->dpcm_playback = !dai_link->capture_only;
1679607fa205SBard Liao 					dai_link->dpcm_capture = !dai_link->playback_only;
1680607fa205SBard Liao 				}
1681607fa205SBard Liao 			}
1682a655de80SLiam Girdwood 
16830cbbf8a0SKuninori Morimoto 			/*
16840cbbf8a0SKuninori Morimoto 			 * override any BE fixups
16850cbbf8a0SKuninori Morimoto 			 * see
16860cbbf8a0SKuninori Morimoto 			 *	snd_soc_link_be_hw_params_fixup()
16870cbbf8a0SKuninori Morimoto 			 */
1688a655de80SLiam Girdwood 			dai_link->be_hw_params_fixup =
1689a655de80SLiam Girdwood 				component->driver->be_hw_params_fixup;
1690a655de80SLiam Girdwood 
16912c7b696aSMarcel Ziswiler 			/*
16922c7b696aSMarcel Ziswiler 			 * most BE links don't set stream name, so set it to
1693a655de80SLiam Girdwood 			 * dai link name if it's NULL to help bind widgets.
1694a655de80SLiam Girdwood 			 */
1695a655de80SLiam Girdwood 			if (!dai_link->stream_name)
1696a655de80SLiam Girdwood 				dai_link->stream_name = dai_link->name;
1697a655de80SLiam Girdwood 		}
1698a655de80SLiam Girdwood 
1699a655de80SLiam Girdwood 		/* Inform userspace we are using alternate topology */
1700a655de80SLiam Girdwood 		if (component->driver->topology_name_prefix) {
1701a655de80SLiam Girdwood 
1702a655de80SLiam Girdwood 			/* topology shortname created? */
1703a655de80SLiam Girdwood 			if (!card->topology_shortname_created) {
1704a655de80SLiam Girdwood 				comp_drv = component->driver;
1705a655de80SLiam Girdwood 
1706a655de80SLiam Girdwood 				snprintf(card->topology_shortname, 32, "%s-%s",
1707a655de80SLiam Girdwood 					 comp_drv->topology_name_prefix,
1708a655de80SLiam Girdwood 					 card->name);
1709a655de80SLiam Girdwood 				card->topology_shortname_created = true;
1710a655de80SLiam Girdwood 			}
1711a655de80SLiam Girdwood 
1712a655de80SLiam Girdwood 			/* use topology shortname */
1713a655de80SLiam Girdwood 			card->name = card->topology_shortname;
1714a655de80SLiam Girdwood 		}
1715a655de80SLiam Girdwood 	}
1716a655de80SLiam Girdwood }
1717a655de80SLiam Girdwood 
17180f23f718SKuninori Morimoto #define soc_setup_card_name(name, name1, name2, norm)		\
17190f23f718SKuninori Morimoto 	__soc_setup_card_name(name, sizeof(name), name1, name2, norm)
17200f23f718SKuninori Morimoto static void __soc_setup_card_name(char *name, int len,
17210f23f718SKuninori Morimoto 				  const char *name1, const char *name2,
17220f23f718SKuninori Morimoto 				  int normalization)
17230f23f718SKuninori Morimoto {
17240f23f718SKuninori Morimoto 	int i;
17250f23f718SKuninori Morimoto 
17260f23f718SKuninori Morimoto 	snprintf(name, len, "%s", name1 ? name1 : name2);
17270f23f718SKuninori Morimoto 
17280f23f718SKuninori Morimoto 	if (!normalization)
17290f23f718SKuninori Morimoto 		return;
17300f23f718SKuninori Morimoto 
17310f23f718SKuninori Morimoto 	/*
17320f23f718SKuninori Morimoto 	 * Name normalization
17330f23f718SKuninori Morimoto 	 *
17340f23f718SKuninori Morimoto 	 * The driver name is somewhat special, as it's used as a key for
17350f23f718SKuninori Morimoto 	 * searches in the user-space.
17360f23f718SKuninori Morimoto 	 *
17370f23f718SKuninori Morimoto 	 * ex)
17380f23f718SKuninori Morimoto 	 *	"abcd??efg" -> "abcd__efg"
17390f23f718SKuninori Morimoto 	 */
17400f23f718SKuninori Morimoto 	for (i = 0; i < len; i++) {
17410f23f718SKuninori Morimoto 		switch (name[i]) {
17420f23f718SKuninori Morimoto 		case '_':
17430f23f718SKuninori Morimoto 		case '-':
17440f23f718SKuninori Morimoto 		case '\0':
17450f23f718SKuninori Morimoto 			break;
17460f23f718SKuninori Morimoto 		default:
17470f23f718SKuninori Morimoto 			if (!isalnum(name[i]))
17480f23f718SKuninori Morimoto 				name[i] = '_';
17490f23f718SKuninori Morimoto 			break;
17500f23f718SKuninori Morimoto 		}
17510f23f718SKuninori Morimoto 	}
17520f23f718SKuninori Morimoto }
17530f23f718SKuninori Morimoto 
175427f07cacSKuninori Morimoto static void soc_cleanup_card_resources(struct snd_soc_card *card)
175553e947a0SKuninori Morimoto {
1756cc733900SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd, *n;
17577ce6088fSKuninori Morimoto 
17580ced7b05SKuninori Morimoto 	if (card->snd_card)
17590ced7b05SKuninori Morimoto 		snd_card_disconnect_sync(card->snd_card);
176053e947a0SKuninori Morimoto 
17612a6f0892SKuninori Morimoto 	snd_soc_dapm_shutdown(card);
17622a6f0892SKuninori Morimoto 
176353e947a0SKuninori Morimoto 	/* remove and free each DAI */
17647ce6088fSKuninori Morimoto 	soc_remove_link_dais(card);
17650ced7b05SKuninori Morimoto 	soc_remove_link_components(card);
17667ce6088fSKuninori Morimoto 
1767cc733900SKuninori Morimoto 	for_each_card_rtds_safe(card, rtd, n)
176850cd9b53SKuninori Morimoto 		snd_soc_remove_pcm_runtime(card, rtd);
17697ce6088fSKuninori Morimoto 
177053e947a0SKuninori Morimoto 	/* remove auxiliary devices */
177153e947a0SKuninori Morimoto 	soc_remove_aux_devices(card);
1772e8fbd250SKuninori Morimoto 	soc_unbind_aux_dev(card);
177353e947a0SKuninori Morimoto 
177453e947a0SKuninori Morimoto 	snd_soc_dapm_free(&card->dapm);
177553e947a0SKuninori Morimoto 	soc_cleanup_card_debugfs(card);
177653e947a0SKuninori Morimoto 
177753e947a0SKuninori Morimoto 	/* remove the card */
1778b0275d95SKuninori Morimoto 	snd_soc_card_remove(card);
17790ced7b05SKuninori Morimoto 
17800ced7b05SKuninori Morimoto 	if (card->snd_card) {
17810ced7b05SKuninori Morimoto 		snd_card_free(card->snd_card);
17820ced7b05SKuninori Morimoto 		card->snd_card = NULL;
17830ced7b05SKuninori Morimoto 	}
178453e947a0SKuninori Morimoto }
178553e947a0SKuninori Morimoto 
17862cc1afcfSKuninori Morimoto static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister)
17872cc1afcfSKuninori Morimoto {
17882cc1afcfSKuninori Morimoto 	if (card->instantiated) {
17892cc1afcfSKuninori Morimoto 		card->instantiated = false;
17902cc1afcfSKuninori Morimoto 		snd_soc_flush_all_delayed_work(card);
17912cc1afcfSKuninori Morimoto 
179227f07cacSKuninori Morimoto 		soc_cleanup_card_resources(card);
17932cc1afcfSKuninori Morimoto 		if (!unregister)
17942cc1afcfSKuninori Morimoto 			list_add(&card->list, &unbind_card_list);
17952cc1afcfSKuninori Morimoto 	} else {
17962cc1afcfSKuninori Morimoto 		if (unregister)
17972cc1afcfSKuninori Morimoto 			list_del(&card->list);
17982cc1afcfSKuninori Morimoto 	}
17992cc1afcfSKuninori Morimoto }
18002cc1afcfSKuninori Morimoto 
1801ed90c013SKuninori Morimoto static int snd_soc_bind_card(struct snd_soc_card *card)
1802f0fba2adSLiam Girdwood {
18031a497983SMengdong Lin 	struct snd_soc_pcm_runtime *rtd;
180476c39e86SKuninori Morimoto 	struct snd_soc_component *component;
180561b0088bSMengdong Lin 	struct snd_soc_dai_link *dai_link;
180627f07cacSKuninori Morimoto 	int ret, i;
180796dd3622SMark Brown 
180834e81ab4SLars-Peter Clausen 	mutex_lock(&client_mutex);
180901b9d99aSLiam Girdwood 	mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1810f0fba2adSLiam Girdwood 
181195c267ddSKuninori Morimoto 	snd_soc_dapm_init(&card->dapm, card, NULL);
181253e947a0SKuninori Morimoto 
1813a655de80SLiam Girdwood 	/* check whether any platform is ignore machine FE and using topology */
1814a655de80SLiam Girdwood 	soc_check_tplg_fes(card);
1815a655de80SLiam Girdwood 
181644c69bb1SLars-Peter Clausen 	/* bind aux_devs too */
1817bee886f1SKuninori Morimoto 	ret = soc_bind_aux_dev(card);
1818bee886f1SKuninori Morimoto 	if (ret < 0)
181953e947a0SKuninori Morimoto 		goto probe_end;
1820db2a4165SFrank Mandarino 
1821f8f80361SMengdong Lin 	/* add predefined DAI links to the list */
1822d8145989SKuninori Morimoto 	card->num_rtd = 0;
18235b99a0aaSKuninori Morimoto 	for_each_card_prelinks(card, i, dai_link) {
18240c048004SKuninori Morimoto 		ret = snd_soc_add_pcm_runtime(card, dai_link);
18255b99a0aaSKuninori Morimoto 		if (ret < 0)
18265b99a0aaSKuninori Morimoto 			goto probe_end;
18275b99a0aaSKuninori Morimoto 	}
1828f8f80361SMengdong Lin 
1829f0fba2adSLiam Girdwood 	/* card bind complete so register a sound card */
1830102b5a8dSTakashi Iwai 	ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1831f0fba2adSLiam Girdwood 			card->owner, 0, &card->snd_card);
1832f0fba2adSLiam Girdwood 	if (ret < 0) {
183310e8aa9aSMichał Mirosław 		dev_err(card->dev,
183410e8aa9aSMichał Mirosław 			"ASoC: can't create sound card for card %s: %d\n",
183510e8aa9aSMichał Mirosław 			card->name, ret);
183653e947a0SKuninori Morimoto 		goto probe_end;
1837db2a4165SFrank Mandarino 	}
1838db2a4165SFrank Mandarino 
18390757d834SLars-Peter Clausen 	soc_init_card_debugfs(card);
18400757d834SLars-Peter Clausen 
1841b3da4251SKuninori Morimoto 	soc_resume_init(card);
18426ed25978SAndy Green 
1843b8ba3b57SKuninori Morimoto 	ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
18449a841ebbSMark Brown 					card->num_dapm_widgets);
1845b8ba3b57SKuninori Morimoto 	if (ret < 0)
1846b8ba3b57SKuninori Morimoto 		goto probe_end;
18479a841ebbSMark Brown 
1848b8ba3b57SKuninori Morimoto 	ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
1849f23e860eSNicolin Chen 					card->num_of_dapm_widgets);
1850b8ba3b57SKuninori Morimoto 	if (ret < 0)
1851b8ba3b57SKuninori Morimoto 		goto probe_end;
1852f23e860eSNicolin Chen 
1853f0fba2adSLiam Girdwood 	/* initialise the sound card only once */
185473de4b02SKuninori Morimoto 	ret = snd_soc_card_probe(card);
1855f0fba2adSLiam Girdwood 	if (ret < 0)
185653e947a0SKuninori Morimoto 		goto probe_end;
1857f0fba2adSLiam Girdwood 
185862ae68faSStephen Warren 	/* probe all components used by DAI links on this card */
185962f07a6bSKuninori Morimoto 	ret = soc_probe_link_components(card);
186062ae68faSStephen Warren 	if (ret < 0) {
1861f110bfc7SLiam Girdwood 		dev_err(card->dev,
186262f07a6bSKuninori Morimoto 			"ASoC: failed to instantiate card %d\n", ret);
186353e947a0SKuninori Morimoto 		goto probe_end;
186462ae68faSStephen Warren 	}
186562ae68faSStephen Warren 
1866f2ed6b07SMengdong Lin 	/* probe auxiliary components */
1867f2ed6b07SMengdong Lin 	ret = soc_probe_aux_devices(card);
186874bd3f92SKuninori Morimoto 	if (ret < 0) {
186974bd3f92SKuninori Morimoto 		dev_err(card->dev,
187074bd3f92SKuninori Morimoto 			"ASoC: failed to probe aux component %d\n", ret);
187153e947a0SKuninori Morimoto 		goto probe_end;
187274bd3f92SKuninori Morimoto 	}
1873f2ed6b07SMengdong Lin 
187462ae68faSStephen Warren 	/* probe all DAI links on this card */
1875c7e73774SKuninori Morimoto 	ret = soc_probe_link_dais(card);
1876fe3e78e0SMark Brown 	if (ret < 0) {
1877f110bfc7SLiam Girdwood 		dev_err(card->dev,
1878c7e73774SKuninori Morimoto 			"ASoC: failed to instantiate card %d\n", ret);
187953e947a0SKuninori Morimoto 		goto probe_end;
1880fe3e78e0SMark Brown 	}
1881fe3e78e0SMark Brown 
1882626c2e57SKuninori Morimoto 	for_each_card_rtds(card, rtd) {
1883eaffeefbSKuninori Morimoto 		ret = soc_init_pcm_runtime(card, rtd);
1884626c2e57SKuninori Morimoto 		if (ret < 0)
1885626c2e57SKuninori Morimoto 			goto probe_end;
1886626c2e57SKuninori Morimoto 	}
1887c4b46982SKuninori Morimoto 
1888888df395SMark Brown 	snd_soc_dapm_link_dai_widgets(card);
1889b893ea5fSLiam Girdwood 	snd_soc_dapm_connect_dai_link_widgets(card);
1890888df395SMark Brown 
18919b98c7c2SKuninori Morimoto 	ret = snd_soc_add_card_controls(card, card->controls,
18922c7b696aSMarcel Ziswiler 					card->num_controls);
18939b98c7c2SKuninori Morimoto 	if (ret < 0)
18949b98c7c2SKuninori Morimoto 		goto probe_end;
1895b7af1dafSMark Brown 
1896daa480bdSKuninori Morimoto 	ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
1897b8ad29deSMark Brown 				      card->num_dapm_routes);
1898a22ae72bSPierre-Louis Bossart 	if (ret < 0) {
1899a22ae72bSPierre-Louis Bossart 		if (card->disable_route_checks) {
1900a22ae72bSPierre-Louis Bossart 			dev_info(card->dev,
1901a22ae72bSPierre-Louis Bossart 				 "%s: disable_route_checks set, ignoring errors on add_routes\n",
1902a22ae72bSPierre-Louis Bossart 				 __func__);
1903a22ae72bSPierre-Louis Bossart 		} else {
1904a22ae72bSPierre-Louis Bossart 			dev_err(card->dev,
1905a22ae72bSPierre-Louis Bossart 				 "%s: snd_soc_dapm_add_routes failed: %d\n",
1906a22ae72bSPierre-Louis Bossart 				 __func__, ret);
1907daa480bdSKuninori Morimoto 			goto probe_end;
1908a22ae72bSPierre-Louis Bossart 		}
1909a22ae72bSPierre-Louis Bossart 	}
1910b8ad29deSMark Brown 
1911daa480bdSKuninori Morimoto 	ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
1912f23e860eSNicolin Chen 				      card->num_of_dapm_routes);
1913daa480bdSKuninori Morimoto 	if (ret < 0)
1914daa480bdSKuninori Morimoto 		goto probe_end;
191575d9ac46SMark Brown 
1916861886d3STakashi Iwai 	/* try to set some sane longname if DMI is available */
1917861886d3STakashi Iwai 	snd_soc_set_dmi_name(card, NULL);
1918861886d3STakashi Iwai 
19190f23f718SKuninori Morimoto 	soc_setup_card_name(card->snd_card->shortname,
19200f23f718SKuninori Morimoto 			    card->name, NULL, 0);
19210f23f718SKuninori Morimoto 	soc_setup_card_name(card->snd_card->longname,
19220f23f718SKuninori Morimoto 			    card->long_name, card->name, 0);
19230f23f718SKuninori Morimoto 	soc_setup_card_name(card->snd_card->driver,
19240f23f718SKuninori Morimoto 			    card->driver_name, card->name, 1);
1925fe3e78e0SMark Brown 
1926dc73d73aSJaroslav Kysela 	if (card->components) {
1927dc73d73aSJaroslav Kysela 		/* the current implementation of snd_component_add() accepts */
1928dc73d73aSJaroslav Kysela 		/* multiple components in the string separated by space, */
1929dc73d73aSJaroslav Kysela 		/* but the string collision (identical string) check might */
1930dc73d73aSJaroslav Kysela 		/* not work correctly */
1931dc73d73aSJaroslav Kysela 		ret = snd_component_add(card->snd_card, card->components);
1932dc73d73aSJaroslav Kysela 		if (ret < 0) {
1933dc73d73aSJaroslav Kysela 			dev_err(card->dev, "ASoC: %s snd_component_add() failed: %d\n",
1934dc73d73aSJaroslav Kysela 				card->name, ret);
1935dc73d73aSJaroslav Kysela 			goto probe_end;
1936dc73d73aSJaroslav Kysela 		}
1937dc73d73aSJaroslav Kysela 	}
1938dc73d73aSJaroslav Kysela 
19395c0eac03SKuninori Morimoto 	ret = snd_soc_card_late_probe(card);
19405c0eac03SKuninori Morimoto 	if (ret < 0)
194153e947a0SKuninori Morimoto 		goto probe_end;
194228e9ad92SMark Brown 
1943824ef826SLars-Peter Clausen 	snd_soc_dapm_new_widgets(card);
19448c193b8dSLars-Peter Clausen 
1945f0fba2adSLiam Girdwood 	ret = snd_card_register(card->snd_card);
1946fe3e78e0SMark Brown 	if (ret < 0) {
1947f110bfc7SLiam Girdwood 		dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
1948f110bfc7SLiam Girdwood 				ret);
194953e947a0SKuninori Morimoto 		goto probe_end;
1950fe3e78e0SMark Brown 	}
1951fe3e78e0SMark Brown 
1952435c5e25SMark Brown 	card->instantiated = 1;
1953882eab6cSTzung-Bi Shih 	dapm_mark_endpoints_dirty(card);
19544f4c0072SMark Brown 	snd_soc_dapm_sync(&card->dapm);
1955b19e6e7bSMark Brown 
1956ed90c013SKuninori Morimoto 	/* deactivate pins to sleep state */
195776c39e86SKuninori Morimoto 	for_each_card_components(card, component)
1958b3dea624SKuninori Morimoto 		if (!snd_soc_component_active(component))
195976c39e86SKuninori Morimoto 			pinctrl_pm_select_sleep_state(component->dev);
1960ed90c013SKuninori Morimoto 
196153e947a0SKuninori Morimoto probe_end:
196253e947a0SKuninori Morimoto 	if (ret < 0)
196327f07cacSKuninori Morimoto 		soc_cleanup_card_resources(card);
1964db2a4165SFrank Mandarino 
1965f0fba2adSLiam Girdwood 	mutex_unlock(&card->mutex);
196634e81ab4SLars-Peter Clausen 	mutex_unlock(&client_mutex);
1967db2a4165SFrank Mandarino 
1968b19e6e7bSMark Brown 	return ret;
1969435c5e25SMark Brown }
1970435c5e25SMark Brown 
1971435c5e25SMark Brown /* probes a new socdev */
1972435c5e25SMark Brown static int soc_probe(struct platform_device *pdev)
1973435c5e25SMark Brown {
1974f0fba2adSLiam Girdwood 	struct snd_soc_card *card = platform_get_drvdata(pdev);
1975435c5e25SMark Brown 
197670a7ca34SVinod Koul 	/*
197770a7ca34SVinod Koul 	 * no card, so machine driver should be registering card
197870a7ca34SVinod Koul 	 * we should not be here in that case so ret error
197970a7ca34SVinod Koul 	 */
198070a7ca34SVinod Koul 	if (!card)
198170a7ca34SVinod Koul 		return -EINVAL;
198270a7ca34SVinod Koul 
1983fe4085e8SMark Brown 	dev_warn(&pdev->dev,
1984f110bfc7SLiam Girdwood 		 "ASoC: machine %s should use snd_soc_register_card()\n",
1985fe4085e8SMark Brown 		 card->name);
1986fe4085e8SMark Brown 
1987435c5e25SMark Brown 	/* Bodge while we unpick instantiation */
1988435c5e25SMark Brown 	card->dev = &pdev->dev;
1989f0fba2adSLiam Girdwood 
1990ad61b78eSQinglang Miao 	return devm_snd_soc_register_card(&pdev->dev, card);
1991db2a4165SFrank Mandarino }
1992db2a4165SFrank Mandarino 
19936f8ab4acSMark Brown int snd_soc_poweroff(struct device *dev)
199451737470SMark Brown {
19956f8ab4acSMark Brown 	struct snd_soc_card *card = dev_get_drvdata(dev);
199676c39e86SKuninori Morimoto 	struct snd_soc_component *component;
199751737470SMark Brown 
199851737470SMark Brown 	if (!card->instantiated)
1999416356fcSMark Brown 		return 0;
200051737470SMark Brown 
20012c7b696aSMarcel Ziswiler 	/*
20022c7b696aSMarcel Ziswiler 	 * Flush out pmdown_time work - we actually do want to run it
20032c7b696aSMarcel Ziswiler 	 * now, we're shutting down so no imminent restart.
20042c7b696aSMarcel Ziswiler 	 */
200565462e44SKuninori Morimoto 	snd_soc_flush_all_delayed_work(card);
200651737470SMark Brown 
2007f0fba2adSLiam Girdwood 	snd_soc_dapm_shutdown(card);
2008416356fcSMark Brown 
2009988e8cc4SNicolin Chen 	/* deactivate pins to sleep state */
201076c39e86SKuninori Morimoto 	for_each_card_components(card, component)
201176c39e86SKuninori Morimoto 		pinctrl_pm_select_sleep_state(component->dev);
2012988e8cc4SNicolin Chen 
2013416356fcSMark Brown 	return 0;
201451737470SMark Brown }
20156f8ab4acSMark Brown EXPORT_SYMBOL_GPL(snd_soc_poweroff);
201651737470SMark Brown 
20176f8ab4acSMark Brown const struct dev_pm_ops snd_soc_pm_ops = {
2018b1dd5897SViresh Kumar 	.suspend = snd_soc_suspend,
2019b1dd5897SViresh Kumar 	.resume = snd_soc_resume,
2020b1dd5897SViresh Kumar 	.freeze = snd_soc_suspend,
2021b1dd5897SViresh Kumar 	.thaw = snd_soc_resume,
20226f8ab4acSMark Brown 	.poweroff = snd_soc_poweroff,
2023b1dd5897SViresh Kumar 	.restore = snd_soc_resume,
2024416356fcSMark Brown };
2025deb2607eSStephen Warren EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
2026416356fcSMark Brown 
2027db2a4165SFrank Mandarino /* ASoC platform driver */
2028db2a4165SFrank Mandarino static struct platform_driver soc_driver = {
2029db2a4165SFrank Mandarino 	.driver		= {
2030db2a4165SFrank Mandarino 		.name		= "soc-audio",
20316f8ab4acSMark Brown 		.pm		= &snd_soc_pm_ops,
2032db2a4165SFrank Mandarino 	},
2033db2a4165SFrank Mandarino 	.probe		= soc_probe,
2034db2a4165SFrank Mandarino };
2035db2a4165SFrank Mandarino 
2036096e49d5SMark Brown /**
2037db2a4165SFrank Mandarino  * snd_soc_cnew - create new control
2038db2a4165SFrank Mandarino  * @_template: control template
2039db2a4165SFrank Mandarino  * @data: control private data
2040ac11a2b3SMark Brown  * @long_name: control long name
2041efb7ac3fSMark Brown  * @prefix: control name prefix
2042db2a4165SFrank Mandarino  *
2043db2a4165SFrank Mandarino  * Create a new mixer control from a template control.
2044db2a4165SFrank Mandarino  *
2045db2a4165SFrank Mandarino  * Returns 0 for success, else error.
2046db2a4165SFrank Mandarino  */
2047db2a4165SFrank Mandarino struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
20483056557fSMark Brown 				  void *data, const char *long_name,
2049efb7ac3fSMark Brown 				  const char *prefix)
2050db2a4165SFrank Mandarino {
2051db2a4165SFrank Mandarino 	struct snd_kcontrol_new template;
2052efb7ac3fSMark Brown 	struct snd_kcontrol *kcontrol;
2053efb7ac3fSMark Brown 	char *name = NULL;
2054db2a4165SFrank Mandarino 
2055db2a4165SFrank Mandarino 	memcpy(&template, _template, sizeof(template));
2056db2a4165SFrank Mandarino 	template.index = 0;
2057db2a4165SFrank Mandarino 
2058efb7ac3fSMark Brown 	if (!long_name)
2059efb7ac3fSMark Brown 		long_name = template.name;
2060efb7ac3fSMark Brown 
2061efb7ac3fSMark Brown 	if (prefix) {
20622b581074SLars-Peter Clausen 		name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
2063efb7ac3fSMark Brown 		if (!name)
2064efb7ac3fSMark Brown 			return NULL;
2065efb7ac3fSMark Brown 
2066efb7ac3fSMark Brown 		template.name = name;
2067efb7ac3fSMark Brown 	} else {
2068efb7ac3fSMark Brown 		template.name = long_name;
2069efb7ac3fSMark Brown 	}
2070efb7ac3fSMark Brown 
2071efb7ac3fSMark Brown 	kcontrol = snd_ctl_new1(&template, data);
2072efb7ac3fSMark Brown 
2073efb7ac3fSMark Brown 	kfree(name);
2074efb7ac3fSMark Brown 
2075efb7ac3fSMark Brown 	return kcontrol;
2076db2a4165SFrank Mandarino }
2077db2a4165SFrank Mandarino EXPORT_SYMBOL_GPL(snd_soc_cnew);
2078db2a4165SFrank Mandarino 
2079022658beSLiam Girdwood static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
2080022658beSLiam Girdwood 	const struct snd_kcontrol_new *controls, int num_controls,
2081022658beSLiam Girdwood 	const char *prefix, void *data)
2082022658beSLiam Girdwood {
2083022658beSLiam Girdwood 	int err, i;
2084022658beSLiam Girdwood 
2085022658beSLiam Girdwood 	for (i = 0; i < num_controls; i++) {
2086022658beSLiam Girdwood 		const struct snd_kcontrol_new *control = &controls[i];
20872c7b696aSMarcel Ziswiler 
2088022658beSLiam Girdwood 		err = snd_ctl_add(card, snd_soc_cnew(control, data,
2089022658beSLiam Girdwood 						     control->name, prefix));
2090022658beSLiam Girdwood 		if (err < 0) {
2091f110bfc7SLiam Girdwood 			dev_err(dev, "ASoC: Failed to add %s: %d\n",
2092f110bfc7SLiam Girdwood 				control->name, err);
2093022658beSLiam Girdwood 			return err;
2094022658beSLiam Girdwood 		}
2095022658beSLiam Girdwood 	}
2096022658beSLiam Girdwood 
2097022658beSLiam Girdwood 	return 0;
2098022658beSLiam Girdwood }
2099022658beSLiam Girdwood 
2100db2a4165SFrank Mandarino /**
21010f2780adSLars-Peter Clausen  * snd_soc_add_component_controls - Add an array of controls to a component.
21020f2780adSLars-Peter Clausen  *
21030f2780adSLars-Peter Clausen  * @component: Component to add controls to
21040f2780adSLars-Peter Clausen  * @controls: Array of controls to add
21050f2780adSLars-Peter Clausen  * @num_controls: Number of elements in the array
21060f2780adSLars-Peter Clausen  *
21070f2780adSLars-Peter Clausen  * Return: 0 for success, else error.
21080f2780adSLars-Peter Clausen  */
21090f2780adSLars-Peter Clausen int snd_soc_add_component_controls(struct snd_soc_component *component,
21100f2780adSLars-Peter Clausen 	const struct snd_kcontrol_new *controls, unsigned int num_controls)
21110f2780adSLars-Peter Clausen {
21120f2780adSLars-Peter Clausen 	struct snd_card *card = component->card->snd_card;
21130f2780adSLars-Peter Clausen 
21140f2780adSLars-Peter Clausen 	return snd_soc_add_controls(card, component->dev, controls,
21150f2780adSLars-Peter Clausen 			num_controls, component->name_prefix, component);
21160f2780adSLars-Peter Clausen }
21170f2780adSLars-Peter Clausen EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
21180f2780adSLars-Peter Clausen 
21190f2780adSLars-Peter Clausen /**
2120022658beSLiam Girdwood  * snd_soc_add_card_controls - add an array of controls to a SoC card.
2121022658beSLiam Girdwood  * Convenience function to add a list of controls.
2122022658beSLiam Girdwood  *
2123022658beSLiam Girdwood  * @soc_card: SoC card to add controls to
2124022658beSLiam Girdwood  * @controls: array of controls to add
2125022658beSLiam Girdwood  * @num_controls: number of elements in the array
2126022658beSLiam Girdwood  *
2127022658beSLiam Girdwood  * Return 0 for success, else error.
2128022658beSLiam Girdwood  */
2129022658beSLiam Girdwood int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
2130022658beSLiam Girdwood 	const struct snd_kcontrol_new *controls, int num_controls)
2131022658beSLiam Girdwood {
2132022658beSLiam Girdwood 	struct snd_card *card = soc_card->snd_card;
2133022658beSLiam Girdwood 
2134022658beSLiam Girdwood 	return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
2135022658beSLiam Girdwood 			NULL, soc_card);
2136022658beSLiam Girdwood }
2137022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
2138022658beSLiam Girdwood 
2139022658beSLiam Girdwood /**
2140022658beSLiam Girdwood  * snd_soc_add_dai_controls - add an array of controls to a DAI.
2141022658beSLiam Girdwood  * Convienience function to add a list of controls.
2142022658beSLiam Girdwood  *
2143022658beSLiam Girdwood  * @dai: DAI to add controls to
2144022658beSLiam Girdwood  * @controls: array of controls to add
2145022658beSLiam Girdwood  * @num_controls: number of elements in the array
2146022658beSLiam Girdwood  *
2147022658beSLiam Girdwood  * Return 0 for success, else error.
2148022658beSLiam Girdwood  */
2149022658beSLiam Girdwood int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
2150022658beSLiam Girdwood 	const struct snd_kcontrol_new *controls, int num_controls)
2151022658beSLiam Girdwood {
2152313665b9SLars-Peter Clausen 	struct snd_card *card = dai->component->card->snd_card;
2153022658beSLiam Girdwood 
2154022658beSLiam Girdwood 	return snd_soc_add_controls(card, dai->dev, controls, num_controls,
2155022658beSLiam Girdwood 			NULL, dai);
2156022658beSLiam Girdwood }
2157022658beSLiam Girdwood EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2158022658beSLiam Girdwood 
2159c5af3a2eSMark Brown /**
2160c5af3a2eSMark Brown  * snd_soc_register_card - Register a card with the ASoC core
2161c5af3a2eSMark Brown  *
2162ac11a2b3SMark Brown  * @card: Card to register
2163c5af3a2eSMark Brown  *
2164c5af3a2eSMark Brown  */
216570a7ca34SVinod Koul int snd_soc_register_card(struct snd_soc_card *card)
2166c5af3a2eSMark Brown {
2167c5af3a2eSMark Brown 	if (!card->name || !card->dev)
2168c5af3a2eSMark Brown 		return -EINVAL;
2169c5af3a2eSMark Brown 
2170ed77cc12SMark Brown 	dev_set_drvdata(card->dev, card);
2171ed77cc12SMark Brown 
2172b03bfaecSKuninori Morimoto 	INIT_LIST_HEAD(&card->widgets);
2173b03bfaecSKuninori Morimoto 	INIT_LIST_HEAD(&card->paths);
2174b03bfaecSKuninori Morimoto 	INIT_LIST_HEAD(&card->dapm_list);
2175b03bfaecSKuninori Morimoto 	INIT_LIST_HEAD(&card->aux_comp_list);
2176b03bfaecSKuninori Morimoto 	INIT_LIST_HEAD(&card->component_dev_list);
2177b03bfaecSKuninori Morimoto 	INIT_LIST_HEAD(&card->list);
21781a497983SMengdong Lin 	INIT_LIST_HEAD(&card->rtd_list);
2179db432b41SMark Brown 	INIT_LIST_HEAD(&card->dapm_dirty);
21808a978234SLiam Girdwood 	INIT_LIST_HEAD(&card->dobj_list);
2181b03bfaecSKuninori Morimoto 
2182c5af3a2eSMark Brown 	card->instantiated = 0;
2183f0fba2adSLiam Girdwood 	mutex_init(&card->mutex);
2184a73fb2dfSLiam Girdwood 	mutex_init(&card->dapm_mutex);
218572b745e3SPeter Ujfalusi 	mutex_init(&card->pcm_mutex);
2186a9764869SKaiChieh Chuang 	spin_lock_init(&card->dpcm_lock);
2187c5af3a2eSMark Brown 
2188e894efefSSrinivas Kandagatla 	return snd_soc_bind_card(card);
2189c5af3a2eSMark Brown }
219070a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_register_card);
2191c5af3a2eSMark Brown 
2192c5af3a2eSMark Brown /**
2193c5af3a2eSMark Brown  * snd_soc_unregister_card - Unregister a card with the ASoC core
2194c5af3a2eSMark Brown  *
2195ac11a2b3SMark Brown  * @card: Card to unregister
2196c5af3a2eSMark Brown  *
2197c5af3a2eSMark Brown  */
219870a7ca34SVinod Koul int snd_soc_unregister_card(struct snd_soc_card *card)
2199c5af3a2eSMark Brown {
2200b545542aSKuninori Morimoto 	mutex_lock(&client_mutex);
2201e894efefSSrinivas Kandagatla 	snd_soc_unbind_card(card, true);
2202b545542aSKuninori Morimoto 	mutex_unlock(&client_mutex);
2203f110bfc7SLiam Girdwood 	dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
2204c5af3a2eSMark Brown 
2205c5af3a2eSMark Brown 	return 0;
2206c5af3a2eSMark Brown }
220770a7ca34SVinod Koul EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
2208c5af3a2eSMark Brown 
2209f0fba2adSLiam Girdwood /*
2210f0fba2adSLiam Girdwood  * Simplify DAI link configuration by removing ".-1" from device names
2211f0fba2adSLiam Girdwood  * and sanitizing names.
2212f0fba2adSLiam Girdwood  */
22130b9a214aSDimitris Papastamos static char *fmt_single_name(struct device *dev, int *id)
2214f0fba2adSLiam Girdwood {
221545dd9943SDmitry Baryshkov 	const char *devname = dev_name(dev);
221645dd9943SDmitry Baryshkov 	char *found, *name;
2217f0fba2adSLiam Girdwood 	int id1, id2;
2218f0fba2adSLiam Girdwood 
221945dd9943SDmitry Baryshkov 	if (devname == NULL)
2220f0fba2adSLiam Girdwood 		return NULL;
2221f0fba2adSLiam Girdwood 
222245dd9943SDmitry Baryshkov 	name = devm_kstrdup(dev, devname, GFP_KERNEL);
2223f0fba2adSLiam Girdwood 
2224f0fba2adSLiam Girdwood 	/* are we a "%s.%d" name (platform and SPI components) */
2225f0fba2adSLiam Girdwood 	found = strstr(name, dev->driver->name);
2226f0fba2adSLiam Girdwood 	if (found) {
2227f0fba2adSLiam Girdwood 		/* get ID */
2228f0fba2adSLiam Girdwood 		if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2229f0fba2adSLiam Girdwood 
2230f0fba2adSLiam Girdwood 			/* discard ID from name if ID == -1 */
2231f0fba2adSLiam Girdwood 			if (*id == -1)
2232f0fba2adSLiam Girdwood 				found[strlen(dev->driver->name)] = '\0';
2233f0fba2adSLiam Girdwood 		}
2234f0fba2adSLiam Girdwood 
2235f0fba2adSLiam Girdwood 	/* I2C component devices are named "bus-addr" */
223645dd9943SDmitry Baryshkov 	} else if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2237f0fba2adSLiam Girdwood 
2238f0fba2adSLiam Girdwood 		/* create unique ID number from I2C addr and bus */
223905899446SJarkko Nikula 		*id = ((id1 & 0xffff) << 16) + id2;
2240f0fba2adSLiam Girdwood 
224145dd9943SDmitry Baryshkov 		devm_kfree(dev, name);
224245dd9943SDmitry Baryshkov 
2243f0fba2adSLiam Girdwood 		/* sanitize component name for DAI link creation */
224445dd9943SDmitry Baryshkov 		name = devm_kasprintf(dev, GFP_KERNEL, "%s.%s", dev->driver->name, devname);
224545dd9943SDmitry Baryshkov 	} else {
2246f0fba2adSLiam Girdwood 		*id = 0;
2247f0fba2adSLiam Girdwood 	}
2248f0fba2adSLiam Girdwood 
224945dd9943SDmitry Baryshkov 	return name;
2250f0fba2adSLiam Girdwood }
2251f0fba2adSLiam Girdwood 
2252f0fba2adSLiam Girdwood /*
2253f0fba2adSLiam Girdwood  * Simplify DAI link naming for single devices with multiple DAIs by removing
2254f0fba2adSLiam Girdwood  * any ".-1" and using the DAI name (instead of device name).
2255f0fba2adSLiam Girdwood  */
2256f0fba2adSLiam Girdwood static inline char *fmt_multiple_name(struct device *dev,
2257f0fba2adSLiam Girdwood 		struct snd_soc_dai_driver *dai_drv)
2258f0fba2adSLiam Girdwood {
2259f0fba2adSLiam Girdwood 	if (dai_drv->name == NULL) {
226010e8aa9aSMichał Mirosław 		dev_err(dev,
226110e8aa9aSMichał Mirosław 			"ASoC: error - multiple DAI %s registered with no name\n",
226210e8aa9aSMichał Mirosław 			dev_name(dev));
2263f0fba2adSLiam Girdwood 		return NULL;
2264f0fba2adSLiam Girdwood 	}
2265f0fba2adSLiam Girdwood 
226650014499SKuninori Morimoto 	return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL);
2267f0fba2adSLiam Girdwood }
2268f0fba2adSLiam Girdwood 
2269ffdbca0bSKuninori Morimoto void snd_soc_unregister_dai(struct snd_soc_dai *dai)
2270e11381f3SKuninori Morimoto {
2271e11381f3SKuninori Morimoto 	dev_dbg(dai->dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
2272e11381f3SKuninori Morimoto 	list_del(&dai->list);
2273e11381f3SKuninori Morimoto }
2274ffdbca0bSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
2275e11381f3SKuninori Morimoto 
22767ca24386SKuninori Morimoto /**
22777ca24386SKuninori Morimoto  * snd_soc_register_dai - Register a DAI dynamically & create its widgets
22787ca24386SKuninori Morimoto  *
22797ca24386SKuninori Morimoto  * @component: The component the DAIs are registered for
22807ca24386SKuninori Morimoto  * @dai_drv: DAI driver to use for the DAI
2281bc9a6655SRandy Dunlap  * @legacy_dai_naming: if %true, use legacy single-name format;
2282bc9a6655SRandy Dunlap  * 	if %false, use multiple-name format;
22837ca24386SKuninori Morimoto  *
22847ca24386SKuninori Morimoto  * Topology can use this API to register DAIs when probing a component.
22857ca24386SKuninori Morimoto  * These DAIs's widgets will be freed in the card cleanup and the DAIs
22867ca24386SKuninori Morimoto  * will be freed in the component cleanup.
22877ca24386SKuninori Morimoto  */
22887ca24386SKuninori Morimoto struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
22895e4fb372SMengdong Lin 					 struct snd_soc_dai_driver *dai_drv,
22905e4fb372SMengdong Lin 					 bool legacy_dai_naming)
22915e4fb372SMengdong Lin {
22925e4fb372SMengdong Lin 	struct device *dev = component->dev;
22935e4fb372SMengdong Lin 	struct snd_soc_dai *dai;
22945e4fb372SMengdong Lin 
22955e4fb372SMengdong Lin 	dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
22965e4fb372SMengdong Lin 
22977ca24386SKuninori Morimoto 	lockdep_assert_held(&client_mutex);
22987ca24386SKuninori Morimoto 
229950014499SKuninori Morimoto 	dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL);
23005e4fb372SMengdong Lin 	if (dai == NULL)
23015e4fb372SMengdong Lin 		return NULL;
23025e4fb372SMengdong Lin 
23035e4fb372SMengdong Lin 	/*
23045e4fb372SMengdong Lin 	 * Back in the old days when we still had component-less DAIs,
23055e4fb372SMengdong Lin 	 * instead of having a static name, component-less DAIs would
23065e4fb372SMengdong Lin 	 * inherit the name of the parent device so it is possible to
23075e4fb372SMengdong Lin 	 * register multiple instances of the DAI. We still need to keep
23085e4fb372SMengdong Lin 	 * the same naming style even though those DAIs are not
23095e4fb372SMengdong Lin 	 * component-less anymore.
23105e4fb372SMengdong Lin 	 */
23115e4fb372SMengdong Lin 	if (legacy_dai_naming &&
23125e4fb372SMengdong Lin 	    (dai_drv->id == 0 || dai_drv->name == NULL)) {
23135e4fb372SMengdong Lin 		dai->name = fmt_single_name(dev, &dai->id);
23145e4fb372SMengdong Lin 	} else {
23155e4fb372SMengdong Lin 		dai->name = fmt_multiple_name(dev, dai_drv);
23165e4fb372SMengdong Lin 		if (dai_drv->id)
23175e4fb372SMengdong Lin 			dai->id = dai_drv->id;
23185e4fb372SMengdong Lin 		else
23195e4fb372SMengdong Lin 			dai->id = component->num_dai;
23205e4fb372SMengdong Lin 	}
232150014499SKuninori Morimoto 	if (!dai->name)
23225e4fb372SMengdong Lin 		return NULL;
23235e4fb372SMengdong Lin 
23245e4fb372SMengdong Lin 	dai->component = component;
23255e4fb372SMengdong Lin 	dai->dev = dev;
23265e4fb372SMengdong Lin 	dai->driver = dai_drv;
23275e4fb372SMengdong Lin 
232815a0c645SKuninori Morimoto 	/* see for_each_component_dais */
232958bf4179SKuninori Morimoto 	list_add_tail(&dai->list, &component->dai_list);
23305e4fb372SMengdong Lin 	component->num_dai++;
23315e4fb372SMengdong Lin 
23325e4fb372SMengdong Lin 	dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
23335e4fb372SMengdong Lin 	return dai;
23345e4fb372SMengdong Lin }
2335e11381f3SKuninori Morimoto 
23369115171aSMark Brown /**
23373f6674aeSKuninori Morimoto  * snd_soc_unregister_dai - Unregister DAIs from the ASoC core
23383f6674aeSKuninori Morimoto  *
23393f6674aeSKuninori Morimoto  * @component: The component for which the DAIs should be unregistered
23403f6674aeSKuninori Morimoto  */
23413f6674aeSKuninori Morimoto static void snd_soc_unregister_dais(struct snd_soc_component *component)
23423f6674aeSKuninori Morimoto {
23433f6674aeSKuninori Morimoto 	struct snd_soc_dai *dai, *_dai;
23443f6674aeSKuninori Morimoto 
2345e11381f3SKuninori Morimoto 	for_each_component_dais_safe(component, dai, _dai)
2346e11381f3SKuninori Morimoto 		snd_soc_unregister_dai(dai);
23473f6674aeSKuninori Morimoto }
23483f6674aeSKuninori Morimoto 
23493f6674aeSKuninori Morimoto /**
2350daf77373SKuninori Morimoto  * snd_soc_register_dais - Register a DAI with the ASoC core
2351daf77373SKuninori Morimoto  *
2352daf77373SKuninori Morimoto  * @component: The component the DAIs are registered for
2353daf77373SKuninori Morimoto  * @dai_drv: DAI driver to use for the DAIs
2354daf77373SKuninori Morimoto  * @count: Number of DAIs
2355daf77373SKuninori Morimoto  */
2356daf77373SKuninori Morimoto static int snd_soc_register_dais(struct snd_soc_component *component,
2357daf77373SKuninori Morimoto 				 struct snd_soc_dai_driver *dai_drv,
2358daf77373SKuninori Morimoto 				 size_t count)
2359daf77373SKuninori Morimoto {
2360daf77373SKuninori Morimoto 	struct snd_soc_dai *dai;
2361daf77373SKuninori Morimoto 	unsigned int i;
2362daf77373SKuninori Morimoto 	int ret;
2363daf77373SKuninori Morimoto 
2364daf77373SKuninori Morimoto 	for (i = 0; i < count; i++) {
236571cb85f5SKuninori Morimoto 		dai = snd_soc_register_dai(component, dai_drv + i, count == 1 &&
2366daf77373SKuninori Morimoto 				  !component->driver->non_legacy_dai_naming);
2367daf77373SKuninori Morimoto 		if (dai == NULL) {
2368daf77373SKuninori Morimoto 			ret = -ENOMEM;
2369daf77373SKuninori Morimoto 			goto err;
2370daf77373SKuninori Morimoto 		}
2371daf77373SKuninori Morimoto 	}
2372daf77373SKuninori Morimoto 
2373daf77373SKuninori Morimoto 	return 0;
2374daf77373SKuninori Morimoto 
2375daf77373SKuninori Morimoto err:
2376daf77373SKuninori Morimoto 	snd_soc_unregister_dais(component);
2377daf77373SKuninori Morimoto 
2378daf77373SKuninori Morimoto 	return ret;
2379daf77373SKuninori Morimoto }
2380daf77373SKuninori Morimoto 
2381273d778eSKuninori Morimoto #define ENDIANNESS_MAP(name) \
2382273d778eSKuninori Morimoto 	(SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
2383273d778eSKuninori Morimoto static u64 endianness_format_map[] = {
2384273d778eSKuninori Morimoto 	ENDIANNESS_MAP(S16_),
2385273d778eSKuninori Morimoto 	ENDIANNESS_MAP(U16_),
2386273d778eSKuninori Morimoto 	ENDIANNESS_MAP(S24_),
2387273d778eSKuninori Morimoto 	ENDIANNESS_MAP(U24_),
2388273d778eSKuninori Morimoto 	ENDIANNESS_MAP(S32_),
2389273d778eSKuninori Morimoto 	ENDIANNESS_MAP(U32_),
2390273d778eSKuninori Morimoto 	ENDIANNESS_MAP(S24_3),
2391273d778eSKuninori Morimoto 	ENDIANNESS_MAP(U24_3),
2392273d778eSKuninori Morimoto 	ENDIANNESS_MAP(S20_3),
2393273d778eSKuninori Morimoto 	ENDIANNESS_MAP(U20_3),
2394273d778eSKuninori Morimoto 	ENDIANNESS_MAP(S18_3),
2395273d778eSKuninori Morimoto 	ENDIANNESS_MAP(U18_3),
2396273d778eSKuninori Morimoto 	ENDIANNESS_MAP(FLOAT_),
2397273d778eSKuninori Morimoto 	ENDIANNESS_MAP(FLOAT64_),
2398273d778eSKuninori Morimoto 	ENDIANNESS_MAP(IEC958_SUBFRAME_),
2399273d778eSKuninori Morimoto };
2400273d778eSKuninori Morimoto 
2401273d778eSKuninori Morimoto /*
2402273d778eSKuninori Morimoto  * Fix up the DAI formats for endianness: codecs don't actually see
2403273d778eSKuninori Morimoto  * the endianness of the data but we're using the CPU format
2404273d778eSKuninori Morimoto  * definitions which do need to include endianness so we ensure that
2405273d778eSKuninori Morimoto  * codec DAIs always have both big and little endian variants set.
2406273d778eSKuninori Morimoto  */
2407273d778eSKuninori Morimoto static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
2408273d778eSKuninori Morimoto {
2409273d778eSKuninori Morimoto 	int i;
2410273d778eSKuninori Morimoto 
2411273d778eSKuninori Morimoto 	for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++)
2412273d778eSKuninori Morimoto 		if (stream->formats & endianness_format_map[i])
2413273d778eSKuninori Morimoto 			stream->formats |= endianness_format_map[i];
2414273d778eSKuninori Morimoto }
2415273d778eSKuninori Morimoto 
2416e894efefSSrinivas Kandagatla static void snd_soc_try_rebind_card(void)
2417e894efefSSrinivas Kandagatla {
2418e894efefSSrinivas Kandagatla 	struct snd_soc_card *card, *c;
2419e894efefSSrinivas Kandagatla 
2420b245d273SKuninori Morimoto 	list_for_each_entry_safe(card, c, &unbind_card_list, list)
2421e894efefSSrinivas Kandagatla 		if (!snd_soc_bind_card(card))
2422e894efefSSrinivas Kandagatla 			list_del(&card->list);
2423e894efefSSrinivas Kandagatla }
2424e894efefSSrinivas Kandagatla 
2425486c7978SKuninori Morimoto static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
2426486c7978SKuninori Morimoto {
2427b18768f5SKuninori Morimoto 	struct snd_soc_card *card = component->card;
2428b18768f5SKuninori Morimoto 
2429486c7978SKuninori Morimoto 	snd_soc_unregister_dais(component);
2430b18768f5SKuninori Morimoto 
2431b18768f5SKuninori Morimoto 	if (card)
2432b18768f5SKuninori Morimoto 		snd_soc_unbind_card(card, false);
2433b18768f5SKuninori Morimoto 
2434b18768f5SKuninori Morimoto 	list_del(&component->list);
2435486c7978SKuninori Morimoto }
2436486c7978SKuninori Morimoto 
243708ff7209SCezary Rojewski int snd_soc_component_initialize(struct snd_soc_component *component,
243808ff7209SCezary Rojewski 				 const struct snd_soc_component_driver *driver,
24397274d4cdSCezary Rojewski 				 struct device *dev)
244008ff7209SCezary Rojewski {
244108ff7209SCezary Rojewski 	INIT_LIST_HEAD(&component->dai_list);
244208ff7209SCezary Rojewski 	INIT_LIST_HEAD(&component->dobj_list);
244308ff7209SCezary Rojewski 	INIT_LIST_HEAD(&component->card_list);
244408ff7209SCezary Rojewski 	mutex_init(&component->io_mutex);
244508ff7209SCezary Rojewski 
24467274d4cdSCezary Rojewski 	component->name = fmt_single_name(dev, &component->id);
24477274d4cdSCezary Rojewski 	if (!component->name) {
24487274d4cdSCezary Rojewski 		dev_err(dev, "ASoC: Failed to allocate name\n");
24497274d4cdSCezary Rojewski 		return -ENOMEM;
24507274d4cdSCezary Rojewski 	}
24517274d4cdSCezary Rojewski 
245208ff7209SCezary Rojewski 	component->dev		= dev;
245308ff7209SCezary Rojewski 	component->driver	= driver;
245408ff7209SCezary Rojewski 
245508ff7209SCezary Rojewski 	return 0;
245608ff7209SCezary Rojewski }
245708ff7209SCezary Rojewski EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
245808ff7209SCezary Rojewski 
2459ea029dd8SCezary Rojewski int snd_soc_add_component(struct snd_soc_component *component,
2460d191bd8dSKuninori Morimoto 			  struct snd_soc_dai_driver *dai_drv,
2461d191bd8dSKuninori Morimoto 			  int num_dai)
2462d191bd8dSKuninori Morimoto {
2463bb13109dSLars-Peter Clausen 	int ret;
2464273d778eSKuninori Morimoto 	int i;
2465d191bd8dSKuninori Morimoto 
2466b18768f5SKuninori Morimoto 	mutex_lock(&client_mutex);
2467b18768f5SKuninori Morimoto 
2468ea029dd8SCezary Rojewski 	if (component->driver->endianness) {
2469273d778eSKuninori Morimoto 		for (i = 0; i < num_dai; i++) {
2470273d778eSKuninori Morimoto 			convert_endianness_formats(&dai_drv[i].playback);
2471273d778eSKuninori Morimoto 			convert_endianness_formats(&dai_drv[i].capture);
2472273d778eSKuninori Morimoto 		}
2473273d778eSKuninori Morimoto 	}
2474273d778eSKuninori Morimoto 
24750e7b25c6SKuninori Morimoto 	ret = snd_soc_register_dais(component, dai_drv, num_dai);
2476bb13109dSLars-Peter Clausen 	if (ret < 0) {
2477ea029dd8SCezary Rojewski 		dev_err(component->dev, "ASoC: Failed to register DAIs: %d\n",
2478ea029dd8SCezary Rojewski 			ret);
2479bb13109dSLars-Peter Clausen 		goto err_cleanup;
2480bb13109dSLars-Peter Clausen 	}
2481bb13109dSLars-Peter Clausen 
2482b18768f5SKuninori Morimoto 	if (!component->driver->write && !component->driver->read) {
2483b18768f5SKuninori Morimoto 		if (!component->regmap)
2484b18768f5SKuninori Morimoto 			component->regmap = dev_get_regmap(component->dev,
2485b18768f5SKuninori Morimoto 							   NULL);
2486b18768f5SKuninori Morimoto 		if (component->regmap)
2487b18768f5SKuninori Morimoto 			snd_soc_component_setup_regmap(component);
2488b18768f5SKuninori Morimoto 	}
2489bb13109dSLars-Peter Clausen 
2490b18768f5SKuninori Morimoto 	/* see for_each_component */
2491b18768f5SKuninori Morimoto 	list_add(&component->list, &component_list);
2492bb13109dSLars-Peter Clausen 
2493bb13109dSLars-Peter Clausen err_cleanup:
2494b18768f5SKuninori Morimoto 	if (ret < 0)
2495486c7978SKuninori Morimoto 		snd_soc_del_component_unlocked(component);
2496ea029dd8SCezary Rojewski 
2497b18768f5SKuninori Morimoto 	mutex_unlock(&client_mutex);
2498b18768f5SKuninori Morimoto 
2499b18768f5SKuninori Morimoto 	if (ret == 0)
2500b18768f5SKuninori Morimoto 		snd_soc_try_rebind_card();
2501b18768f5SKuninori Morimoto 
2502bb13109dSLars-Peter Clausen 	return ret;
2503d191bd8dSKuninori Morimoto }
2504e0dac41bSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_add_component);
2505e0dac41bSKuninori Morimoto 
2506e0dac41bSKuninori Morimoto int snd_soc_register_component(struct device *dev,
2507e0dac41bSKuninori Morimoto 			const struct snd_soc_component_driver *component_driver,
2508e0dac41bSKuninori Morimoto 			struct snd_soc_dai_driver *dai_drv,
2509e0dac41bSKuninori Morimoto 			int num_dai)
2510e0dac41bSKuninori Morimoto {
2511e0dac41bSKuninori Morimoto 	struct snd_soc_component *component;
2512ea029dd8SCezary Rojewski 	int ret;
2513e0dac41bSKuninori Morimoto 
25147ecbd6a9SKuninori Morimoto 	component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
251508e61d03SKuninori Morimoto 	if (!component)
2516e0dac41bSKuninori Morimoto 		return -ENOMEM;
2517e0dac41bSKuninori Morimoto 
2518ea029dd8SCezary Rojewski 	ret = snd_soc_component_initialize(component, component_driver, dev);
2519ea029dd8SCezary Rojewski 	if (ret < 0)
2520ea029dd8SCezary Rojewski 		return ret;
2521ea029dd8SCezary Rojewski 
2522ea029dd8SCezary Rojewski 	return snd_soc_add_component(component, dai_drv, num_dai);
2523e0dac41bSKuninori Morimoto }
2524d191bd8dSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_register_component);
2525d191bd8dSKuninori Morimoto 
2526d191bd8dSKuninori Morimoto /**
252758f30150SMaxime Ripard  * snd_soc_unregister_component_by_driver - Unregister component using a given driver
252858f30150SMaxime Ripard  * from the ASoC core
252958f30150SMaxime Ripard  *
253058f30150SMaxime Ripard  * @dev: The device to unregister
253158f30150SMaxime Ripard  * @component_driver: The component driver to unregister
253258f30150SMaxime Ripard  */
253358f30150SMaxime Ripard void snd_soc_unregister_component_by_driver(struct device *dev,
253458f30150SMaxime Ripard 					    const struct snd_soc_component_driver *component_driver)
253558f30150SMaxime Ripard {
253658f30150SMaxime Ripard 	struct snd_soc_component *component;
253758f30150SMaxime Ripard 
253858f30150SMaxime Ripard 	if (!component_driver)
253958f30150SMaxime Ripard 		return;
254058f30150SMaxime Ripard 
254158f30150SMaxime Ripard 	mutex_lock(&client_mutex);
254258f30150SMaxime Ripard 	component = snd_soc_lookup_component_nolocked(dev, component_driver->name);
254358f30150SMaxime Ripard 	if (!component)
254458f30150SMaxime Ripard 		goto out;
254558f30150SMaxime Ripard 
254658f30150SMaxime Ripard 	snd_soc_del_component_unlocked(component);
254758f30150SMaxime Ripard 
254858f30150SMaxime Ripard out:
254958f30150SMaxime Ripard 	mutex_unlock(&client_mutex);
255058f30150SMaxime Ripard }
255158f30150SMaxime Ripard EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver);
255258f30150SMaxime Ripard 
255358f30150SMaxime Ripard /**
25542eccea8cSKuninori Morimoto  * snd_soc_unregister_component - Unregister all related component
25552eccea8cSKuninori Morimoto  * from the ASoC core
2556d191bd8dSKuninori Morimoto  *
2557628536eaSJonathan Corbet  * @dev: The device to unregister
2558d191bd8dSKuninori Morimoto  */
25592eccea8cSKuninori Morimoto void snd_soc_unregister_component(struct device *dev)
25602eccea8cSKuninori Morimoto {
2561ac6a4dd3SKuninori Morimoto 	struct snd_soc_component *component;
2562ac6a4dd3SKuninori Morimoto 
2563ac6a4dd3SKuninori Morimoto 	mutex_lock(&client_mutex);
2564ac6a4dd3SKuninori Morimoto 	while (1) {
256518dd66eaSKuninori Morimoto 		component = snd_soc_lookup_component_nolocked(dev, NULL);
2566ac6a4dd3SKuninori Morimoto 		if (!component)
2567ac6a4dd3SKuninori Morimoto 			break;
2568ac6a4dd3SKuninori Morimoto 
2569ac6a4dd3SKuninori Morimoto 		snd_soc_del_component_unlocked(component);
2570ac6a4dd3SKuninori Morimoto 	}
2571ac6a4dd3SKuninori Morimoto 	mutex_unlock(&client_mutex);
2572d191bd8dSKuninori Morimoto }
2573d191bd8dSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
2574d191bd8dSKuninori Morimoto 
2575bec4fa05SStephen Warren /* Retrieve a card's name from device tree */
2576b07609ceSKuninori Morimoto int snd_soc_of_parse_card_name(struct snd_soc_card *card,
2577bec4fa05SStephen Warren 			       const char *propname)
2578bec4fa05SStephen Warren {
2579b07609ceSKuninori Morimoto 	struct device_node *np;
2580bec4fa05SStephen Warren 	int ret;
2581bec4fa05SStephen Warren 
25827e07e7c0STushar Behera 	if (!card->dev) {
25837e07e7c0STushar Behera 		pr_err("card->dev is not set before calling %s\n", __func__);
25847e07e7c0STushar Behera 		return -EINVAL;
25857e07e7c0STushar Behera 	}
25867e07e7c0STushar Behera 
25877e07e7c0STushar Behera 	np = card->dev->of_node;
25887e07e7c0STushar Behera 
2589bec4fa05SStephen Warren 	ret = of_property_read_string_index(np, propname, 0, &card->name);
2590bec4fa05SStephen Warren 	/*
2591bec4fa05SStephen Warren 	 * EINVAL means the property does not exist. This is fine providing
2592bec4fa05SStephen Warren 	 * card->name was previously set, which is checked later in
2593bec4fa05SStephen Warren 	 * snd_soc_register_card.
2594bec4fa05SStephen Warren 	 */
2595bec4fa05SStephen Warren 	if (ret < 0 && ret != -EINVAL) {
2596bec4fa05SStephen Warren 		dev_err(card->dev,
2597f110bfc7SLiam Girdwood 			"ASoC: Property '%s' could not be read: %d\n",
2598bec4fa05SStephen Warren 			propname, ret);
2599bec4fa05SStephen Warren 		return ret;
2600bec4fa05SStephen Warren 	}
2601bec4fa05SStephen Warren 
2602bec4fa05SStephen Warren 	return 0;
2603bec4fa05SStephen Warren }
2604b07609ceSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
2605bec4fa05SStephen Warren 
26069a6d4860SXiubo Li static const struct snd_soc_dapm_widget simple_widgets[] = {
26079a6d4860SXiubo Li 	SND_SOC_DAPM_MIC("Microphone", NULL),
26089a6d4860SXiubo Li 	SND_SOC_DAPM_LINE("Line", NULL),
26099a6d4860SXiubo Li 	SND_SOC_DAPM_HP("Headphone", NULL),
26109a6d4860SXiubo Li 	SND_SOC_DAPM_SPK("Speaker", NULL),
26119a6d4860SXiubo Li };
26129a6d4860SXiubo Li 
261321efde50SKuninori Morimoto int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
26149a6d4860SXiubo Li 					  const char *propname)
26159a6d4860SXiubo Li {
261621efde50SKuninori Morimoto 	struct device_node *np = card->dev->of_node;
26179a6d4860SXiubo Li 	struct snd_soc_dapm_widget *widgets;
26189a6d4860SXiubo Li 	const char *template, *wname;
26199a6d4860SXiubo Li 	int i, j, num_widgets, ret;
26209a6d4860SXiubo Li 
26219a6d4860SXiubo Li 	num_widgets = of_property_count_strings(np, propname);
26229a6d4860SXiubo Li 	if (num_widgets < 0) {
26239a6d4860SXiubo Li 		dev_err(card->dev,
26249a6d4860SXiubo Li 			"ASoC: Property '%s' does not exist\n",	propname);
26259a6d4860SXiubo Li 		return -EINVAL;
26269a6d4860SXiubo Li 	}
26279a6d4860SXiubo Li 	if (num_widgets & 1) {
26289a6d4860SXiubo Li 		dev_err(card->dev,
26299a6d4860SXiubo Li 			"ASoC: Property '%s' length is not even\n", propname);
26309a6d4860SXiubo Li 		return -EINVAL;
26319a6d4860SXiubo Li 	}
26329a6d4860SXiubo Li 
26339a6d4860SXiubo Li 	num_widgets /= 2;
26349a6d4860SXiubo Li 	if (!num_widgets) {
26359a6d4860SXiubo Li 		dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
26369a6d4860SXiubo Li 			propname);
26379a6d4860SXiubo Li 		return -EINVAL;
26389a6d4860SXiubo Li 	}
26399a6d4860SXiubo Li 
26409a6d4860SXiubo Li 	widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
26419a6d4860SXiubo Li 			       GFP_KERNEL);
26429a6d4860SXiubo Li 	if (!widgets) {
26439a6d4860SXiubo Li 		dev_err(card->dev,
26449a6d4860SXiubo Li 			"ASoC: Could not allocate memory for widgets\n");
26459a6d4860SXiubo Li 		return -ENOMEM;
26469a6d4860SXiubo Li 	}
26479a6d4860SXiubo Li 
26489a6d4860SXiubo Li 	for (i = 0; i < num_widgets; i++) {
26499a6d4860SXiubo Li 		ret = of_property_read_string_index(np, propname,
26509a6d4860SXiubo Li 			2 * i, &template);
26519a6d4860SXiubo Li 		if (ret) {
26529a6d4860SXiubo Li 			dev_err(card->dev,
26539a6d4860SXiubo Li 				"ASoC: Property '%s' index %d read error:%d\n",
26549a6d4860SXiubo Li 				propname, 2 * i, ret);
26559a6d4860SXiubo Li 			return -EINVAL;
26569a6d4860SXiubo Li 		}
26579a6d4860SXiubo Li 
26589a6d4860SXiubo Li 		for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
26599a6d4860SXiubo Li 			if (!strncmp(template, simple_widgets[j].name,
26609a6d4860SXiubo Li 				     strlen(simple_widgets[j].name))) {
26619a6d4860SXiubo Li 				widgets[i] = simple_widgets[j];
26629a6d4860SXiubo Li 				break;
26639a6d4860SXiubo Li 			}
26649a6d4860SXiubo Li 		}
26659a6d4860SXiubo Li 
26669a6d4860SXiubo Li 		if (j >= ARRAY_SIZE(simple_widgets)) {
26679a6d4860SXiubo Li 			dev_err(card->dev,
26689a6d4860SXiubo Li 				"ASoC: DAPM widget '%s' is not supported\n",
26699a6d4860SXiubo Li 				template);
26709a6d4860SXiubo Li 			return -EINVAL;
26719a6d4860SXiubo Li 		}
26729a6d4860SXiubo Li 
26739a6d4860SXiubo Li 		ret = of_property_read_string_index(np, propname,
26749a6d4860SXiubo Li 						    (2 * i) + 1,
26759a6d4860SXiubo Li 						    &wname);
26769a6d4860SXiubo Li 		if (ret) {
26779a6d4860SXiubo Li 			dev_err(card->dev,
26789a6d4860SXiubo Li 				"ASoC: Property '%s' index %d read error:%d\n",
26799a6d4860SXiubo Li 				propname, (2 * i) + 1, ret);
26809a6d4860SXiubo Li 			return -EINVAL;
26819a6d4860SXiubo Li 		}
26829a6d4860SXiubo Li 
26839a6d4860SXiubo Li 		widgets[i].name = wname;
26849a6d4860SXiubo Li 	}
26859a6d4860SXiubo Li 
2686f23e860eSNicolin Chen 	card->of_dapm_widgets = widgets;
2687f23e860eSNicolin Chen 	card->num_of_dapm_widgets = num_widgets;
26889a6d4860SXiubo Li 
26899a6d4860SXiubo Li 	return 0;
26909a6d4860SXiubo Li }
269121efde50SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
26929a6d4860SXiubo Li 
2693cbdfab3bSJerome Brunet int snd_soc_of_get_slot_mask(struct device_node *np,
26946131084aSJyri Sarha 			     const char *prop_name,
26956131084aSJyri Sarha 			     unsigned int *mask)
26966131084aSJyri Sarha {
26976131084aSJyri Sarha 	u32 val;
26986c84e591SJyri Sarha 	const __be32 *of_slot_mask = of_get_property(np, prop_name, &val);
26996131084aSJyri Sarha 	int i;
27006131084aSJyri Sarha 
27016131084aSJyri Sarha 	if (!of_slot_mask)
27026131084aSJyri Sarha 		return 0;
27036131084aSJyri Sarha 	val /= sizeof(u32);
27046131084aSJyri Sarha 	for (i = 0; i < val; i++)
27056131084aSJyri Sarha 		if (be32_to_cpup(&of_slot_mask[i]))
27066131084aSJyri Sarha 			*mask |= (1 << i);
27076131084aSJyri Sarha 
27086131084aSJyri Sarha 	return val;
27096131084aSJyri Sarha }
2710cbdfab3bSJerome Brunet EXPORT_SYMBOL_GPL(snd_soc_of_get_slot_mask);
27116131084aSJyri Sarha 
271289c67857SXiubo Li int snd_soc_of_parse_tdm_slot(struct device_node *np,
27136131084aSJyri Sarha 			      unsigned int *tx_mask,
27146131084aSJyri Sarha 			      unsigned int *rx_mask,
271589c67857SXiubo Li 			      unsigned int *slots,
271689c67857SXiubo Li 			      unsigned int *slot_width)
271789c67857SXiubo Li {
271889c67857SXiubo Li 	u32 val;
271989c67857SXiubo Li 	int ret;
272089c67857SXiubo Li 
27216131084aSJyri Sarha 	if (tx_mask)
27226131084aSJyri Sarha 		snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask);
27236131084aSJyri Sarha 	if (rx_mask)
27246131084aSJyri Sarha 		snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask);
27256131084aSJyri Sarha 
272689c67857SXiubo Li 	if (of_property_read_bool(np, "dai-tdm-slot-num")) {
272789c67857SXiubo Li 		ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
272889c67857SXiubo Li 		if (ret)
272989c67857SXiubo Li 			return ret;
273089c67857SXiubo Li 
273189c67857SXiubo Li 		if (slots)
273289c67857SXiubo Li 			*slots = val;
273389c67857SXiubo Li 	}
273489c67857SXiubo Li 
273589c67857SXiubo Li 	if (of_property_read_bool(np, "dai-tdm-slot-width")) {
273689c67857SXiubo Li 		ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
273789c67857SXiubo Li 		if (ret)
273889c67857SXiubo Li 			return ret;
273989c67857SXiubo Li 
274089c67857SXiubo Li 		if (slot_width)
274189c67857SXiubo Li 			*slot_width = val;
274289c67857SXiubo Li 	}
274389c67857SXiubo Li 
274489c67857SXiubo Li 	return 0;
274589c67857SXiubo Li }
274689c67857SXiubo Li EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
274789c67857SXiubo Li 
27483b710356SKuninori Morimoto void snd_soc_of_parse_node_prefix(struct device_node *np,
27495e3cdaa2SKuninori Morimoto 				  struct snd_soc_codec_conf *codec_conf,
27505e3cdaa2SKuninori Morimoto 				  struct device_node *of_node,
27515e3cdaa2SKuninori Morimoto 				  const char *propname)
27525e3cdaa2SKuninori Morimoto {
27535e3cdaa2SKuninori Morimoto 	const char *str;
27545e3cdaa2SKuninori Morimoto 	int ret;
27555e3cdaa2SKuninori Morimoto 
27565e3cdaa2SKuninori Morimoto 	ret = of_property_read_string(np, propname, &str);
27575e3cdaa2SKuninori Morimoto 	if (ret < 0) {
27585e3cdaa2SKuninori Morimoto 		/* no prefix is not error */
27595e3cdaa2SKuninori Morimoto 		return;
27605e3cdaa2SKuninori Morimoto 	}
27615e3cdaa2SKuninori Morimoto 
2762c13493a2SKuninori Morimoto 	codec_conf->dlc.of_node	= of_node;
27635e3cdaa2SKuninori Morimoto 	codec_conf->name_prefix	= str;
27645e3cdaa2SKuninori Morimoto }
27653b710356SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_node_prefix);
27665e3cdaa2SKuninori Morimoto 
27672bc644afSKuninori Morimoto int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
2768a4a54dd5SStephen Warren 				   const char *propname)
2769a4a54dd5SStephen Warren {
27702bc644afSKuninori Morimoto 	struct device_node *np = card->dev->of_node;
2771e3b1e6a1SMark Brown 	int num_routes;
2772a4a54dd5SStephen Warren 	struct snd_soc_dapm_route *routes;
2773a4a54dd5SStephen Warren 	int i, ret;
2774a4a54dd5SStephen Warren 
2775a4a54dd5SStephen Warren 	num_routes = of_property_count_strings(np, propname);
2776c34ce320SRichard Zhao 	if (num_routes < 0 || num_routes & 1) {
277710e8aa9aSMichał Mirosław 		dev_err(card->dev,
277810e8aa9aSMichał Mirosław 			"ASoC: Property '%s' does not exist or its length is not even\n",
277910e8aa9aSMichał Mirosław 			propname);
2780a4a54dd5SStephen Warren 		return -EINVAL;
2781a4a54dd5SStephen Warren 	}
2782a4a54dd5SStephen Warren 	num_routes /= 2;
2783a4a54dd5SStephen Warren 	if (!num_routes) {
2784f110bfc7SLiam Girdwood 		dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
2785a4a54dd5SStephen Warren 			propname);
2786a4a54dd5SStephen Warren 		return -EINVAL;
2787a4a54dd5SStephen Warren 	}
2788a4a54dd5SStephen Warren 
2789a86854d0SKees Cook 	routes = devm_kcalloc(card->dev, num_routes, sizeof(*routes),
2790a4a54dd5SStephen Warren 			      GFP_KERNEL);
2791a4a54dd5SStephen Warren 	if (!routes) {
2792a4a54dd5SStephen Warren 		dev_err(card->dev,
2793f110bfc7SLiam Girdwood 			"ASoC: Could not allocate DAPM route table\n");
2794a4a54dd5SStephen Warren 		return -EINVAL;
2795a4a54dd5SStephen Warren 	}
2796a4a54dd5SStephen Warren 
2797a4a54dd5SStephen Warren 	for (i = 0; i < num_routes; i++) {
2798a4a54dd5SStephen Warren 		ret = of_property_read_string_index(np, propname,
2799e3b1e6a1SMark Brown 			2 * i, &routes[i].sink);
2800a4a54dd5SStephen Warren 		if (ret) {
2801c871bd0bSMark Brown 			dev_err(card->dev,
2802c871bd0bSMark Brown 				"ASoC: Property '%s' index %d could not be read: %d\n",
2803c871bd0bSMark Brown 				propname, 2 * i, ret);
2804a4a54dd5SStephen Warren 			return -EINVAL;
2805a4a54dd5SStephen Warren 		}
2806a4a54dd5SStephen Warren 		ret = of_property_read_string_index(np, propname,
2807e3b1e6a1SMark Brown 			(2 * i) + 1, &routes[i].source);
2808a4a54dd5SStephen Warren 		if (ret) {
2809a4a54dd5SStephen Warren 			dev_err(card->dev,
2810c871bd0bSMark Brown 				"ASoC: Property '%s' index %d could not be read: %d\n",
2811c871bd0bSMark Brown 				propname, (2 * i) + 1, ret);
2812a4a54dd5SStephen Warren 			return -EINVAL;
2813a4a54dd5SStephen Warren 		}
2814a4a54dd5SStephen Warren 	}
2815a4a54dd5SStephen Warren 
2816f23e860eSNicolin Chen 	card->num_of_dapm_routes = num_routes;
2817f23e860eSNicolin Chen 	card->of_dapm_routes = routes;
2818a4a54dd5SStephen Warren 
2819a4a54dd5SStephen Warren 	return 0;
2820a4a54dd5SStephen Warren }
28212bc644afSKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
2822a4a54dd5SStephen Warren 
28231ae0965dSStephan Gerhold int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname)
28241ae0965dSStephan Gerhold {
28251ae0965dSStephan Gerhold 	struct device_node *node = card->dev->of_node;
28261ae0965dSStephan Gerhold 	struct snd_soc_aux_dev *aux;
28271ae0965dSStephan Gerhold 	int num, i;
28281ae0965dSStephan Gerhold 
28291ae0965dSStephan Gerhold 	num = of_count_phandle_with_args(node, propname, NULL);
28301ae0965dSStephan Gerhold 	if (num == -ENOENT) {
28311ae0965dSStephan Gerhold 		return 0;
28321ae0965dSStephan Gerhold 	} else if (num < 0) {
28331ae0965dSStephan Gerhold 		dev_err(card->dev, "ASOC: Property '%s' could not be read: %d\n",
28341ae0965dSStephan Gerhold 			propname, num);
28351ae0965dSStephan Gerhold 		return num;
28361ae0965dSStephan Gerhold 	}
28371ae0965dSStephan Gerhold 
28381ae0965dSStephan Gerhold 	aux = devm_kcalloc(card->dev, num, sizeof(*aux), GFP_KERNEL);
28391ae0965dSStephan Gerhold 	if (!aux)
28401ae0965dSStephan Gerhold 		return -ENOMEM;
28411ae0965dSStephan Gerhold 	card->aux_dev = aux;
28421ae0965dSStephan Gerhold 	card->num_aux_devs = num;
28431ae0965dSStephan Gerhold 
28441ae0965dSStephan Gerhold 	for_each_card_pre_auxs(card, i, aux) {
28451ae0965dSStephan Gerhold 		aux->dlc.of_node = of_parse_phandle(node, propname, i);
28461ae0965dSStephan Gerhold 		if (!aux->dlc.of_node)
28471ae0965dSStephan Gerhold 			return -EINVAL;
28481ae0965dSStephan Gerhold 	}
28491ae0965dSStephan Gerhold 
28501ae0965dSStephan Gerhold 	return 0;
28511ae0965dSStephan Gerhold }
28521ae0965dSStephan Gerhold EXPORT_SYMBOL_GPL(snd_soc_of_parse_aux_devs);
28531ae0965dSStephan Gerhold 
2854a7930ed4SKuninori Morimoto unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
2855389cb834SJyri Sarha 				     const char *prefix,
2856389cb834SJyri Sarha 				     struct device_node **bitclkmaster,
2857389cb834SJyri Sarha 				     struct device_node **framemaster)
2858a7930ed4SKuninori Morimoto {
2859a7930ed4SKuninori Morimoto 	int ret, i;
2860a7930ed4SKuninori Morimoto 	char prop[128];
2861a7930ed4SKuninori Morimoto 	unsigned int format = 0;
2862a7930ed4SKuninori Morimoto 	int bit, frame;
2863a7930ed4SKuninori Morimoto 	const char *str;
2864a7930ed4SKuninori Morimoto 	struct {
2865a7930ed4SKuninori Morimoto 		char *name;
2866a7930ed4SKuninori Morimoto 		unsigned int val;
2867a7930ed4SKuninori Morimoto 	} of_fmt_table[] = {
2868a7930ed4SKuninori Morimoto 		{ "i2s",	SND_SOC_DAIFMT_I2S },
2869a7930ed4SKuninori Morimoto 		{ "right_j",	SND_SOC_DAIFMT_RIGHT_J },
2870a7930ed4SKuninori Morimoto 		{ "left_j",	SND_SOC_DAIFMT_LEFT_J },
2871a7930ed4SKuninori Morimoto 		{ "dsp_a",	SND_SOC_DAIFMT_DSP_A },
2872a7930ed4SKuninori Morimoto 		{ "dsp_b",	SND_SOC_DAIFMT_DSP_B },
2873a7930ed4SKuninori Morimoto 		{ "ac97",	SND_SOC_DAIFMT_AC97 },
2874a7930ed4SKuninori Morimoto 		{ "pdm",	SND_SOC_DAIFMT_PDM},
2875a7930ed4SKuninori Morimoto 		{ "msb",	SND_SOC_DAIFMT_MSB },
2876a7930ed4SKuninori Morimoto 		{ "lsb",	SND_SOC_DAIFMT_LSB },
2877a7930ed4SKuninori Morimoto 	};
2878a7930ed4SKuninori Morimoto 
2879a7930ed4SKuninori Morimoto 	if (!prefix)
2880a7930ed4SKuninori Morimoto 		prefix = "";
2881a7930ed4SKuninori Morimoto 
2882a7930ed4SKuninori Morimoto 	/*
28835711c979SKuninori Morimoto 	 * check "dai-format = xxx"
28845711c979SKuninori Morimoto 	 * or    "[prefix]format = xxx"
2885a7930ed4SKuninori Morimoto 	 * SND_SOC_DAIFMT_FORMAT_MASK area
2886a7930ed4SKuninori Morimoto 	 */
28875711c979SKuninori Morimoto 	ret = of_property_read_string(np, "dai-format", &str);
28885711c979SKuninori Morimoto 	if (ret < 0) {
2889a7930ed4SKuninori Morimoto 		snprintf(prop, sizeof(prop), "%sformat", prefix);
2890a7930ed4SKuninori Morimoto 		ret = of_property_read_string(np, prop, &str);
28915711c979SKuninori Morimoto 	}
2892a7930ed4SKuninori Morimoto 	if (ret == 0) {
2893a7930ed4SKuninori Morimoto 		for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
2894a7930ed4SKuninori Morimoto 			if (strcmp(str, of_fmt_table[i].name) == 0) {
2895a7930ed4SKuninori Morimoto 				format |= of_fmt_table[i].val;
2896a7930ed4SKuninori Morimoto 				break;
2897a7930ed4SKuninori Morimoto 			}
2898a7930ed4SKuninori Morimoto 		}
2899a7930ed4SKuninori Morimoto 	}
2900a7930ed4SKuninori Morimoto 
2901a7930ed4SKuninori Morimoto 	/*
29028c2d6a9fSKuninori Morimoto 	 * check "[prefix]continuous-clock"
2903a7930ed4SKuninori Morimoto 	 * SND_SOC_DAIFMT_CLOCK_MASK area
2904a7930ed4SKuninori Morimoto 	 */
29058c2d6a9fSKuninori Morimoto 	snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
290651930295SJulia Lawall 	if (of_property_read_bool(np, prop))
29078c2d6a9fSKuninori Morimoto 		format |= SND_SOC_DAIFMT_CONT;
29088c2d6a9fSKuninori Morimoto 	else
29098c2d6a9fSKuninori Morimoto 		format |= SND_SOC_DAIFMT_GATED;
2910a7930ed4SKuninori Morimoto 
2911a7930ed4SKuninori Morimoto 	/*
2912a7930ed4SKuninori Morimoto 	 * check "[prefix]bitclock-inversion"
2913a7930ed4SKuninori Morimoto 	 * check "[prefix]frame-inversion"
2914a7930ed4SKuninori Morimoto 	 * SND_SOC_DAIFMT_INV_MASK area
2915a7930ed4SKuninori Morimoto 	 */
2916a7930ed4SKuninori Morimoto 	snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
2917a7930ed4SKuninori Morimoto 	bit = !!of_get_property(np, prop, NULL);
2918a7930ed4SKuninori Morimoto 
2919a7930ed4SKuninori Morimoto 	snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
2920a7930ed4SKuninori Morimoto 	frame = !!of_get_property(np, prop, NULL);
2921a7930ed4SKuninori Morimoto 
2922a7930ed4SKuninori Morimoto 	switch ((bit << 4) + frame) {
2923a7930ed4SKuninori Morimoto 	case 0x11:
2924a7930ed4SKuninori Morimoto 		format |= SND_SOC_DAIFMT_IB_IF;
2925a7930ed4SKuninori Morimoto 		break;
2926a7930ed4SKuninori Morimoto 	case 0x10:
2927a7930ed4SKuninori Morimoto 		format |= SND_SOC_DAIFMT_IB_NF;
2928a7930ed4SKuninori Morimoto 		break;
2929a7930ed4SKuninori Morimoto 	case 0x01:
2930a7930ed4SKuninori Morimoto 		format |= SND_SOC_DAIFMT_NB_IF;
2931a7930ed4SKuninori Morimoto 		break;
2932a7930ed4SKuninori Morimoto 	default:
2933a7930ed4SKuninori Morimoto 		/* SND_SOC_DAIFMT_NB_NF is default */
2934a7930ed4SKuninori Morimoto 		break;
2935a7930ed4SKuninori Morimoto 	}
2936a7930ed4SKuninori Morimoto 
2937a7930ed4SKuninori Morimoto 	/*
2938a7930ed4SKuninori Morimoto 	 * check "[prefix]bitclock-master"
2939a7930ed4SKuninori Morimoto 	 * check "[prefix]frame-master"
2940a7930ed4SKuninori Morimoto 	 * SND_SOC_DAIFMT_MASTER_MASK area
2941a7930ed4SKuninori Morimoto 	 */
2942a7930ed4SKuninori Morimoto 	snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
2943a7930ed4SKuninori Morimoto 	bit = !!of_get_property(np, prop, NULL);
2944389cb834SJyri Sarha 	if (bit && bitclkmaster)
2945389cb834SJyri Sarha 		*bitclkmaster = of_parse_phandle(np, prop, 0);
2946a7930ed4SKuninori Morimoto 
2947a7930ed4SKuninori Morimoto 	snprintf(prop, sizeof(prop), "%sframe-master", prefix);
2948a7930ed4SKuninori Morimoto 	frame = !!of_get_property(np, prop, NULL);
2949389cb834SJyri Sarha 	if (frame && framemaster)
2950389cb834SJyri Sarha 		*framemaster = of_parse_phandle(np, prop, 0);
2951a7930ed4SKuninori Morimoto 
2952a7930ed4SKuninori Morimoto 	switch ((bit << 4) + frame) {
2953a7930ed4SKuninori Morimoto 	case 0x11:
2954a7930ed4SKuninori Morimoto 		format |= SND_SOC_DAIFMT_CBM_CFM;
2955a7930ed4SKuninori Morimoto 		break;
2956a7930ed4SKuninori Morimoto 	case 0x10:
2957a7930ed4SKuninori Morimoto 		format |= SND_SOC_DAIFMT_CBM_CFS;
2958a7930ed4SKuninori Morimoto 		break;
2959a7930ed4SKuninori Morimoto 	case 0x01:
2960a7930ed4SKuninori Morimoto 		format |= SND_SOC_DAIFMT_CBS_CFM;
2961a7930ed4SKuninori Morimoto 		break;
2962a7930ed4SKuninori Morimoto 	default:
2963a7930ed4SKuninori Morimoto 		format |= SND_SOC_DAIFMT_CBS_CFS;
2964a7930ed4SKuninori Morimoto 		break;
2965a7930ed4SKuninori Morimoto 	}
2966a7930ed4SKuninori Morimoto 
2967a7930ed4SKuninori Morimoto 	return format;
2968a7930ed4SKuninori Morimoto }
2969a7930ed4SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
2970a7930ed4SKuninori Morimoto 
2971a180e8b9SKuninori Morimoto int snd_soc_get_dai_id(struct device_node *ep)
2972a180e8b9SKuninori Morimoto {
297309d4cc03SKuninori Morimoto 	struct snd_soc_component *component;
2974c1e230f0SKuninori Morimoto 	struct snd_soc_dai_link_component dlc;
2975a180e8b9SKuninori Morimoto 	int ret;
2976a180e8b9SKuninori Morimoto 
2977c1e230f0SKuninori Morimoto 	dlc.of_node	= of_graph_get_port_parent(ep);
2978c1e230f0SKuninori Morimoto 	dlc.name	= NULL;
2979a180e8b9SKuninori Morimoto 	/*
2980a180e8b9SKuninori Morimoto 	 * For example HDMI case, HDMI has video/sound port,
2981a180e8b9SKuninori Morimoto 	 * but ALSA SoC needs sound port number only.
2982a180e8b9SKuninori Morimoto 	 * Thus counting HDMI DT port/endpoint doesn't work.
2983a180e8b9SKuninori Morimoto 	 * Then, it should have .of_xlate_dai_id
2984a180e8b9SKuninori Morimoto 	 */
2985a180e8b9SKuninori Morimoto 	ret = -ENOTSUPP;
2986a180e8b9SKuninori Morimoto 	mutex_lock(&client_mutex);
2987c1e230f0SKuninori Morimoto 	component = soc_find_component(&dlc);
29882c7b1704SKuninori Morimoto 	if (component)
29892c7b1704SKuninori Morimoto 		ret = snd_soc_component_of_xlate_dai_id(component, ep);
2990a180e8b9SKuninori Morimoto 	mutex_unlock(&client_mutex);
2991a180e8b9SKuninori Morimoto 
2992c1e230f0SKuninori Morimoto 	of_node_put(dlc.of_node);
2993c0a480d1STony Lindgren 
2994a180e8b9SKuninori Morimoto 	return ret;
2995a180e8b9SKuninori Morimoto }
2996a180e8b9SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
2997a180e8b9SKuninori Morimoto 
29981ad8ec53SKuninori Morimoto int snd_soc_get_dai_name(struct of_phandle_args *args,
2999cb470087SKuninori Morimoto 				const char **dai_name)
3000cb470087SKuninori Morimoto {
3001cb470087SKuninori Morimoto 	struct snd_soc_component *pos;
30023e0aa8d8SJyri Sarha 	struct device_node *component_of_node;
300393b0f3eeSJean-Francois Moine 	int ret = -EPROBE_DEFER;
3004cb470087SKuninori Morimoto 
3005cb470087SKuninori Morimoto 	mutex_lock(&client_mutex);
3006368dee94SKuninori Morimoto 	for_each_component(pos) {
3007c0834440SKuninori Morimoto 		component_of_node = soc_component_to_node(pos);
30083e0aa8d8SJyri Sarha 
30093e0aa8d8SJyri Sarha 		if (component_of_node != args->np)
3010cb470087SKuninori Morimoto 			continue;
3011cb470087SKuninori Morimoto 
3012a2a34175SKuninori Morimoto 		ret = snd_soc_component_of_xlate_dai_name(pos, args, dai_name);
3013a2a34175SKuninori Morimoto 		if (ret == -ENOTSUPP) {
301458bf4179SKuninori Morimoto 			struct snd_soc_dai *dai;
30156833c452SKuninori Morimoto 			int id = -1;
30166833c452SKuninori Morimoto 
301793b0f3eeSJean-Francois Moine 			switch (args->args_count) {
30186833c452SKuninori Morimoto 			case 0:
30196833c452SKuninori Morimoto 				id = 0; /* same as dai_drv[0] */
30206833c452SKuninori Morimoto 				break;
30216833c452SKuninori Morimoto 			case 1:
302293b0f3eeSJean-Francois Moine 				id = args->args[0];
30236833c452SKuninori Morimoto 				break;
30246833c452SKuninori Morimoto 			default:
30256833c452SKuninori Morimoto 				/* not supported */
3026cb470087SKuninori Morimoto 				break;
3027cb470087SKuninori Morimoto 			}
3028cb470087SKuninori Morimoto 
30296833c452SKuninori Morimoto 			if (id < 0 || id >= pos->num_dai) {
30306833c452SKuninori Morimoto 				ret = -EINVAL;
30313dcba280SNicolin Chen 				continue;
30326833c452SKuninori Morimoto 			}
3033e41975edSXiubo Li 
3034e41975edSXiubo Li 			ret = 0;
3035e41975edSXiubo Li 
303658bf4179SKuninori Morimoto 			/* find target DAI */
303715a0c645SKuninori Morimoto 			for_each_component_dais(pos, dai) {
303858bf4179SKuninori Morimoto 				if (id == 0)
303958bf4179SKuninori Morimoto 					break;
304058bf4179SKuninori Morimoto 				id--;
304158bf4179SKuninori Morimoto 			}
304258bf4179SKuninori Morimoto 
304358bf4179SKuninori Morimoto 			*dai_name = dai->driver->name;
3044e41975edSXiubo Li 			if (!*dai_name)
3045e41975edSXiubo Li 				*dai_name = pos->name;
30461dfa5a5aSJerome Brunet 		} else if (ret) {
30471dfa5a5aSJerome Brunet 			/*
30481dfa5a5aSJerome Brunet 			 * if another error than ENOTSUPP is returned go on and
30491dfa5a5aSJerome Brunet 			 * check if another component is provided with the same
30501dfa5a5aSJerome Brunet 			 * node. This may happen if a device provides several
30511dfa5a5aSJerome Brunet 			 * components
30521dfa5a5aSJerome Brunet 			 */
30531dfa5a5aSJerome Brunet 			continue;
30546833c452SKuninori Morimoto 		}
30556833c452SKuninori Morimoto 
3056cb470087SKuninori Morimoto 		break;
3057cb470087SKuninori Morimoto 	}
3058cb470087SKuninori Morimoto 	mutex_unlock(&client_mutex);
305993b0f3eeSJean-Francois Moine 	return ret;
306093b0f3eeSJean-Francois Moine }
30611ad8ec53SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
306293b0f3eeSJean-Francois Moine 
306393b0f3eeSJean-Francois Moine int snd_soc_of_get_dai_name(struct device_node *of_node,
306493b0f3eeSJean-Francois Moine 			    const char **dai_name)
306593b0f3eeSJean-Francois Moine {
306693b0f3eeSJean-Francois Moine 	struct of_phandle_args args;
306793b0f3eeSJean-Francois Moine 	int ret;
306893b0f3eeSJean-Francois Moine 
306993b0f3eeSJean-Francois Moine 	ret = of_parse_phandle_with_args(of_node, "sound-dai",
307093b0f3eeSJean-Francois Moine 					 "#sound-dai-cells", 0, &args);
307193b0f3eeSJean-Francois Moine 	if (ret)
307293b0f3eeSJean-Francois Moine 		return ret;
307393b0f3eeSJean-Francois Moine 
307493b0f3eeSJean-Francois Moine 	ret = snd_soc_get_dai_name(&args, dai_name);
3075cb470087SKuninori Morimoto 
3076cb470087SKuninori Morimoto 	of_node_put(args.np);
3077cb470087SKuninori Morimoto 
3078cb470087SKuninori Morimoto 	return ret;
3079cb470087SKuninori Morimoto }
3080cb470087SKuninori Morimoto EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
3081cb470087SKuninori Morimoto 
308293b0f3eeSJean-Francois Moine /*
308394685763SSylwester Nawrocki  * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
308494685763SSylwester Nawrocki  * @dai_link: DAI link
308594685763SSylwester Nawrocki  *
308694685763SSylwester Nawrocki  * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs().
308794685763SSylwester Nawrocki  */
308894685763SSylwester Nawrocki void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
308994685763SSylwester Nawrocki {
30903db769f1SKuninori Morimoto 	struct snd_soc_dai_link_component *component;
309194685763SSylwester Nawrocki 	int index;
309294685763SSylwester Nawrocki 
30933db769f1SKuninori Morimoto 	for_each_link_codecs(dai_link, index, component) {
309494685763SSylwester Nawrocki 		if (!component->of_node)
309594685763SSylwester Nawrocki 			break;
309694685763SSylwester Nawrocki 		of_node_put(component->of_node);
309794685763SSylwester Nawrocki 		component->of_node = NULL;
309894685763SSylwester Nawrocki 	}
309994685763SSylwester Nawrocki }
310094685763SSylwester Nawrocki EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
310194685763SSylwester Nawrocki 
310294685763SSylwester Nawrocki /*
310393b0f3eeSJean-Francois Moine  * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
310493b0f3eeSJean-Francois Moine  * @dev: Card device
310593b0f3eeSJean-Francois Moine  * @of_node: Device node
310693b0f3eeSJean-Francois Moine  * @dai_link: DAI link
310793b0f3eeSJean-Francois Moine  *
310893b0f3eeSJean-Francois Moine  * Builds an array of CODEC DAI components from the DAI link property
310993b0f3eeSJean-Francois Moine  * 'sound-dai'.
311093b0f3eeSJean-Francois Moine  * The array is set in the DAI link and the number of DAIs is set accordingly.
311194685763SSylwester Nawrocki  * The device nodes in the array (of_node) must be dereferenced by calling
311294685763SSylwester Nawrocki  * snd_soc_of_put_dai_link_codecs() on @dai_link.
311393b0f3eeSJean-Francois Moine  *
311493b0f3eeSJean-Francois Moine  * Returns 0 for success
311593b0f3eeSJean-Francois Moine  */
311693b0f3eeSJean-Francois Moine int snd_soc_of_get_dai_link_codecs(struct device *dev,
311793b0f3eeSJean-Francois Moine 				   struct device_node *of_node,
311893b0f3eeSJean-Francois Moine 				   struct snd_soc_dai_link *dai_link)
311993b0f3eeSJean-Francois Moine {
312093b0f3eeSJean-Francois Moine 	struct of_phandle_args args;
312193b0f3eeSJean-Francois Moine 	struct snd_soc_dai_link_component *component;
312293b0f3eeSJean-Francois Moine 	char *name;
312393b0f3eeSJean-Francois Moine 	int index, num_codecs, ret;
312493b0f3eeSJean-Francois Moine 
312593b0f3eeSJean-Francois Moine 	/* Count the number of CODECs */
312693b0f3eeSJean-Francois Moine 	name = "sound-dai";
312793b0f3eeSJean-Francois Moine 	num_codecs = of_count_phandle_with_args(of_node, name,
312893b0f3eeSJean-Francois Moine 						"#sound-dai-cells");
312993b0f3eeSJean-Francois Moine 	if (num_codecs <= 0) {
313093b0f3eeSJean-Francois Moine 		if (num_codecs == -ENOENT)
313193b0f3eeSJean-Francois Moine 			dev_err(dev, "No 'sound-dai' property\n");
313293b0f3eeSJean-Francois Moine 		else
313393b0f3eeSJean-Francois Moine 			dev_err(dev, "Bad phandle in 'sound-dai'\n");
313493b0f3eeSJean-Francois Moine 		return num_codecs;
313593b0f3eeSJean-Francois Moine 	}
3136a86854d0SKees Cook 	component = devm_kcalloc(dev,
3137a86854d0SKees Cook 				 num_codecs, sizeof(*component),
313893b0f3eeSJean-Francois Moine 				 GFP_KERNEL);
313993b0f3eeSJean-Francois Moine 	if (!component)
314093b0f3eeSJean-Francois Moine 		return -ENOMEM;
314193b0f3eeSJean-Francois Moine 	dai_link->codecs = component;
314293b0f3eeSJean-Francois Moine 	dai_link->num_codecs = num_codecs;
314393b0f3eeSJean-Francois Moine 
314493b0f3eeSJean-Francois Moine 	/* Parse the list */
31453db769f1SKuninori Morimoto 	for_each_link_codecs(dai_link, index, component) {
314693b0f3eeSJean-Francois Moine 		ret = of_parse_phandle_with_args(of_node, name,
314793b0f3eeSJean-Francois Moine 						 "#sound-dai-cells",
314893b0f3eeSJean-Francois Moine 						 index, &args);
314993b0f3eeSJean-Francois Moine 		if (ret)
315093b0f3eeSJean-Francois Moine 			goto err;
315193b0f3eeSJean-Francois Moine 		component->of_node = args.np;
315293b0f3eeSJean-Francois Moine 		ret = snd_soc_get_dai_name(&args, &component->dai_name);
315393b0f3eeSJean-Francois Moine 		if (ret < 0)
315493b0f3eeSJean-Francois Moine 			goto err;
315593b0f3eeSJean-Francois Moine 	}
315693b0f3eeSJean-Francois Moine 	return 0;
315793b0f3eeSJean-Francois Moine err:
315894685763SSylwester Nawrocki 	snd_soc_of_put_dai_link_codecs(dai_link);
315993b0f3eeSJean-Francois Moine 	dai_link->codecs = NULL;
316093b0f3eeSJean-Francois Moine 	dai_link->num_codecs = 0;
316193b0f3eeSJean-Francois Moine 	return ret;
316293b0f3eeSJean-Francois Moine }
316393b0f3eeSJean-Francois Moine EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
316493b0f3eeSJean-Francois Moine 
3165c9b3a40fSTakashi Iwai static int __init snd_soc_init(void)
3166db2a4165SFrank Mandarino {
31676553bf06SLars-Peter Clausen 	snd_soc_debugfs_init();
3168fb257897SMark Brown 	snd_soc_util_init();
3169fb257897SMark Brown 
3170db2a4165SFrank Mandarino 	return platform_driver_register(&soc_driver);
3171db2a4165SFrank Mandarino }
31724abe8e16SMark Brown module_init(snd_soc_init);
3173db2a4165SFrank Mandarino 
31747d8c16a6SMark Brown static void __exit snd_soc_exit(void)
3175db2a4165SFrank Mandarino {
3176fb257897SMark Brown 	snd_soc_util_exit();
31776553bf06SLars-Peter Clausen 	snd_soc_debugfs_exit();
3178fb257897SMark Brown 
3179db2a4165SFrank Mandarino 	platform_driver_unregister(&soc_driver);
3180db2a4165SFrank Mandarino }
3181db2a4165SFrank Mandarino module_exit(snd_soc_exit);
3182db2a4165SFrank Mandarino 
3183db2a4165SFrank Mandarino /* Module information */
3184d331124dSLiam Girdwood MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
3185db2a4165SFrank Mandarino MODULE_DESCRIPTION("ALSA SoC Core");
3186db2a4165SFrank Mandarino MODULE_LICENSE("GPL");
31878b45a209SKay Sievers MODULE_ALIAS("platform:soc-audio");
3188