xref: /openbmc/linux/include/sound/soc-card.h (revision 3ddc8b84)
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 
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 
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 
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 int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
34 			  struct snd_soc_jack *jack);
35 int snd_soc_card_jack_new_pins(struct snd_soc_card *card, const char *id,
36 			       int type, struct snd_soc_jack *jack,
37 			       struct snd_soc_jack_pin *pins,
38 			       unsigned int num_pins);
39 
40 int snd_soc_card_suspend_pre(struct snd_soc_card *card);
41 int snd_soc_card_suspend_post(struct snd_soc_card *card);
42 int snd_soc_card_resume_pre(struct snd_soc_card *card);
43 int snd_soc_card_resume_post(struct snd_soc_card *card);
44 
45 int snd_soc_card_probe(struct snd_soc_card *card);
46 int snd_soc_card_late_probe(struct snd_soc_card *card);
47 void snd_soc_card_fixup_controls(struct snd_soc_card *card);
48 int snd_soc_card_remove(struct snd_soc_card *card);
49 
50 int snd_soc_card_set_bias_level(struct snd_soc_card *card,
51 				struct snd_soc_dapm_context *dapm,
52 				enum snd_soc_bias_level level);
53 int snd_soc_card_set_bias_level_post(struct snd_soc_card *card,
54 				     struct snd_soc_dapm_context *dapm,
55 				     enum snd_soc_bias_level level);
56 
57 int snd_soc_card_add_dai_link(struct snd_soc_card *card,
58 			      struct snd_soc_dai_link *dai_link);
59 void snd_soc_card_remove_dai_link(struct snd_soc_card *card,
60 				  struct snd_soc_dai_link *dai_link);
61 
62 #ifdef CONFIG_PCI
63 static inline void snd_soc_card_set_pci_ssid(struct snd_soc_card *card,
64 					     unsigned short vendor,
65 					     unsigned short device)
66 {
67 	card->pci_subsystem_vendor = vendor;
68 	card->pci_subsystem_device = device;
69 	card->pci_subsystem_set = true;
70 }
71 
72 static inline int snd_soc_card_get_pci_ssid(struct snd_soc_card *card,
73 					    unsigned short *vendor,
74 					    unsigned short *device)
75 {
76 	if (!card->pci_subsystem_set)
77 		return -ENOENT;
78 
79 	*vendor = card->pci_subsystem_vendor;
80 	*device = card->pci_subsystem_device;
81 
82 	return 0;
83 }
84 #else /* !CONFIG_PCI */
85 static inline void snd_soc_card_set_pci_ssid(struct snd_soc_card *card,
86 					     unsigned short vendor,
87 					     unsigned short device)
88 {
89 }
90 
91 static inline int snd_soc_card_get_pci_ssid(struct snd_soc_card *card,
92 					    unsigned short *vendor,
93 					    unsigned short *device)
94 {
95 	return -ENOENT;
96 }
97 #endif /* CONFIG_PCI */
98 
99 /* device driver data */
100 static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
101 					    void *data)
102 {
103 	card->drvdata = data;
104 }
105 
106 static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
107 {
108 	return card->drvdata;
109 }
110 
111 static inline
112 struct snd_soc_dai *snd_soc_card_get_codec_dai(struct snd_soc_card *card,
113 					       const char *dai_name)
114 {
115 	struct snd_soc_pcm_runtime *rtd;
116 
117 	for_each_card_rtds(card, rtd) {
118 		if (!strcmp(asoc_rtd_to_codec(rtd, 0)->name, dai_name))
119 			return asoc_rtd_to_codec(rtd, 0);
120 	}
121 
122 	return NULL;
123 }
124 
125 #endif /* __SOC_CARD_H */
126