xref: /openbmc/linux/include/sound/soc-card.h (revision fb3618f6)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * soc-card.h
4  *
5  * Copyright (C) 2019 Renesas Electronics Corp.
6  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7  */
8 #ifndef __SOC_CARD_H
9 #define __SOC_CARD_H
10 
11 enum snd_soc_card_subclass {
12 	SND_SOC_CARD_CLASS_ROOT		= 0,
13 	SND_SOC_CARD_CLASS_RUNTIME	= 1,
14 };
15 
snd_soc_card_mutex_lock_root(struct snd_soc_card * card)16 static inline void snd_soc_card_mutex_lock_root(struct snd_soc_card *card)
17 {
18 	mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_ROOT);
19 }
20 
snd_soc_card_mutex_lock(struct snd_soc_card * card)21 static inline void snd_soc_card_mutex_lock(struct snd_soc_card *card)
22 {
23 	mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
24 }
25 
snd_soc_card_mutex_unlock(struct snd_soc_card * card)26 static inline void snd_soc_card_mutex_unlock(struct snd_soc_card *card)
27 {
28 	mutex_unlock(&card->mutex);
29 }
30 
31 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
32 					       const char *name);
33 struct snd_kcontrol *snd_soc_card_get_kcontrol_locked(struct snd_soc_card *soc_card,
34 						      const char *name);
35 int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
36 			  struct snd_soc_jack *jack);
37 int snd_soc_card_jack_new_pins(struct snd_soc_card *card, const char *id,
38 			       int type, struct snd_soc_jack *jack,
39 			       struct snd_soc_jack_pin *pins,
40 			       unsigned int num_pins);
41 
42 int snd_soc_card_suspend_pre(struct snd_soc_card *card);
43 int snd_soc_card_suspend_post(struct snd_soc_card *card);
44 int snd_soc_card_resume_pre(struct snd_soc_card *card);
45 int snd_soc_card_resume_post(struct snd_soc_card *card);
46 
47 int snd_soc_card_probe(struct snd_soc_card *card);
48 int snd_soc_card_late_probe(struct snd_soc_card *card);
49 void snd_soc_card_fixup_controls(struct snd_soc_card *card);
50 int snd_soc_card_remove(struct snd_soc_card *card);
51 
52 int snd_soc_card_set_bias_level(struct snd_soc_card *card,
53 				struct snd_soc_dapm_context *dapm,
54 				enum snd_soc_bias_level level);
55 int snd_soc_card_set_bias_level_post(struct snd_soc_card *card,
56 				     struct snd_soc_dapm_context *dapm,
57 				     enum snd_soc_bias_level level);
58 
59 int snd_soc_card_add_dai_link(struct snd_soc_card *card,
60 			      struct snd_soc_dai_link *dai_link);
61 void snd_soc_card_remove_dai_link(struct snd_soc_card *card,
62 				  struct snd_soc_dai_link *dai_link);
63 
64 #ifdef CONFIG_PCI
snd_soc_card_set_pci_ssid(struct snd_soc_card * card,unsigned short vendor,unsigned short device)65 static inline void snd_soc_card_set_pci_ssid(struct snd_soc_card *card,
66 					     unsigned short vendor,
67 					     unsigned short device)
68 {
69 	card->pci_subsystem_vendor = vendor;
70 	card->pci_subsystem_device = device;
71 	card->pci_subsystem_set = true;
72 }
73 
snd_soc_card_get_pci_ssid(struct snd_soc_card * card,unsigned short * vendor,unsigned short * device)74 static inline int snd_soc_card_get_pci_ssid(struct snd_soc_card *card,
75 					    unsigned short *vendor,
76 					    unsigned short *device)
77 {
78 	if (!card->pci_subsystem_set)
79 		return -ENOENT;
80 
81 	*vendor = card->pci_subsystem_vendor;
82 	*device = card->pci_subsystem_device;
83 
84 	return 0;
85 }
86 #else /* !CONFIG_PCI */
snd_soc_card_set_pci_ssid(struct snd_soc_card * card,unsigned short vendor,unsigned short device)87 static inline void snd_soc_card_set_pci_ssid(struct snd_soc_card *card,
88 					     unsigned short vendor,
89 					     unsigned short device)
90 {
91 }
92 
snd_soc_card_get_pci_ssid(struct snd_soc_card * card,unsigned short * vendor,unsigned short * device)93 static inline int snd_soc_card_get_pci_ssid(struct snd_soc_card *card,
94 					    unsigned short *vendor,
95 					    unsigned short *device)
96 {
97 	return -ENOENT;
98 }
99 #endif /* CONFIG_PCI */
100 
101 /* device driver data */
snd_soc_card_set_drvdata(struct snd_soc_card * card,void * data)102 static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
103 					    void *data)
104 {
105 	card->drvdata = data;
106 }
107 
snd_soc_card_get_drvdata(struct snd_soc_card * card)108 static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
109 {
110 	return card->drvdata;
111 }
112 
113 static inline
snd_soc_card_get_codec_dai(struct snd_soc_card * card,const char * dai_name)114 struct snd_soc_dai *snd_soc_card_get_codec_dai(struct snd_soc_card *card,
115 					       const char *dai_name)
116 {
117 	struct snd_soc_pcm_runtime *rtd;
118 
119 	for_each_card_rtds(card, rtd) {
120 		if (!strcmp(snd_soc_rtd_to_codec(rtd, 0)->name, dai_name))
121 			return snd_soc_rtd_to_codec(rtd, 0);
122 	}
123 
124 	return NULL;
125 }
126 
127 #endif /* __SOC_CARD_H */
128