1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright (C) 2019 Renesas Electronics Corp.
6 // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
9 #include <sound/jack.h>
11 #define soc_card_ret(dai, ret) _soc_card_ret(dai, __func__, ret)
12 static inline int _soc_card_ret(struct snd_soc_card *card,
13 const char *func, int ret)
22 "ASoC: error at %s on %s: %d\n",
23 func, card->name, ret);
29 struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
32 struct snd_card *card = soc_card->snd_card;
33 struct snd_kcontrol *kctl;
38 list_for_each_entry(kctl, &card->controls, list)
39 if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name)))
43 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
45 static int jack_new(struct snd_soc_card *card, const char *id, int type,
46 struct snd_soc_jack *jack, bool initial_kctl)
48 mutex_init(&jack->mutex);
50 INIT_LIST_HEAD(&jack->pins);
51 INIT_LIST_HEAD(&jack->jack_zones);
52 BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
54 return snd_jack_new(card->snd_card, id, type, &jack->jack, initial_kctl, false);
58 * snd_soc_card_jack_new - Create a new jack without pins
60 * @id: an identifying string for this jack
61 * @type: a bitmask of enum snd_jack_type values that can be detected by
63 * @jack: structure to use for the jack
65 * Creates a new jack object without pins. If adding pins later,
66 * snd_soc_card_jack_new_pins() should be used instead with 0 as num_pins
69 * Returns zero if successful, or a negative error code on failure.
70 * On success jack will be initialised.
72 int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
73 struct snd_soc_jack *jack)
75 return soc_card_ret(card, jack_new(card, id, type, jack, true));
77 EXPORT_SYMBOL_GPL(snd_soc_card_jack_new);
80 * snd_soc_card_jack_new_pins - Create a new jack with pins
82 * @id: an identifying string for this jack
83 * @type: a bitmask of enum snd_jack_type values that can be detected by
85 * @jack: structure to use for the jack
86 * @pins: Array of jack pins to be added to the jack or NULL
87 * @num_pins: Number of elements in the @pins array
89 * Creates a new jack object with pins. If not adding pins,
90 * snd_soc_card_jack_new() should be used instead.
92 * Returns zero if successful, or a negative error code on failure.
93 * On success jack will be initialised.
95 int snd_soc_card_jack_new_pins(struct snd_soc_card *card, const char *id,
96 int type, struct snd_soc_jack *jack,
97 struct snd_soc_jack_pin *pins,
98 unsigned int num_pins)
102 ret = jack_new(card, id, type, jack, false);
107 ret = snd_soc_jack_add_pins(jack, num_pins, pins);
109 return soc_card_ret(card, ret);
111 EXPORT_SYMBOL_GPL(snd_soc_card_jack_new_pins);
113 int snd_soc_card_suspend_pre(struct snd_soc_card *card)
117 if (card->suspend_pre)
118 ret = card->suspend_pre(card);
120 return soc_card_ret(card, ret);
123 int snd_soc_card_suspend_post(struct snd_soc_card *card)
127 if (card->suspend_post)
128 ret = card->suspend_post(card);
130 return soc_card_ret(card, ret);
133 int snd_soc_card_resume_pre(struct snd_soc_card *card)
137 if (card->resume_pre)
138 ret = card->resume_pre(card);
140 return soc_card_ret(card, ret);
143 int snd_soc_card_resume_post(struct snd_soc_card *card)
147 if (card->resume_post)
148 ret = card->resume_post(card);
150 return soc_card_ret(card, ret);
153 int snd_soc_card_probe(struct snd_soc_card *card)
156 int ret = card->probe(card);
159 return soc_card_ret(card, ret);
162 * It has "card->probe" and "card->late_probe" callbacks.
163 * So, set "probed" flag here, because it needs to care
164 * about "late_probe".
167 * snd_soc_bind_card()
168 * snd_soc_card_late_probe()
176 int snd_soc_card_late_probe(struct snd_soc_card *card)
178 if (card->late_probe) {
179 int ret = card->late_probe(card);
182 return soc_card_ret(card, ret);
186 * It has "card->probe" and "card->late_probe" callbacks,
187 * and "late_probe" callback is called after "probe".
188 * This means, we can set "card->probed" flag afer "late_probe"
192 * snd_soc_bind_card()
193 * snd_soc_card_probe()
200 void snd_soc_card_fixup_controls(struct snd_soc_card *card)
202 if (card->fixup_controls)
203 card->fixup_controls(card);
206 int snd_soc_card_remove(struct snd_soc_card *card)
212 ret = card->remove(card);
216 return soc_card_ret(card, ret);
219 int snd_soc_card_set_bias_level(struct snd_soc_card *card,
220 struct snd_soc_dapm_context *dapm,
221 enum snd_soc_bias_level level)
225 if (card && card->set_bias_level)
226 ret = card->set_bias_level(card, dapm, level);
228 return soc_card_ret(card, ret);
231 int snd_soc_card_set_bias_level_post(struct snd_soc_card *card,
232 struct snd_soc_dapm_context *dapm,
233 enum snd_soc_bias_level level)
237 if (card && card->set_bias_level_post)
238 ret = card->set_bias_level_post(card, dapm, level);
240 return soc_card_ret(card, ret);
243 int snd_soc_card_add_dai_link(struct snd_soc_card *card,
244 struct snd_soc_dai_link *dai_link)
248 if (card->add_dai_link)
249 ret = card->add_dai_link(card, dai_link);
251 return soc_card_ret(card, ret);
253 EXPORT_SYMBOL_GPL(snd_soc_card_add_dai_link);
255 void snd_soc_card_remove_dai_link(struct snd_soc_card *card,
256 struct snd_soc_dai_link *dai_link)
258 if (card->remove_dai_link)
259 card->remove_dai_link(card, dai_link);
261 EXPORT_SYMBOL_GPL(snd_soc_card_remove_dai_link);