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
);
46 * snd_soc_card_jack_new - Create a new jack
48 * @id: an identifying string for this jack
49 * @type: a bitmask of enum snd_jack_type values that can be detected by
51 * @jack: structure to use for the jack
52 * @pins: Array of jack pins to be added to the jack or NULL
53 * @num_pins: Number of elements in the @pins array
55 * Creates a new jack object.
57 * Returns zero if successful, or a negative error code on failure.
58 * On success jack will be initialised.
60 int snd_soc_card_jack_new(struct snd_soc_card
*card
, const char *id
, int type
,
61 struct snd_soc_jack
*jack
,
62 struct snd_soc_jack_pin
*pins
, unsigned int num_pins
)
66 mutex_init(&jack
->mutex
);
68 INIT_LIST_HEAD(&jack
->pins
);
69 INIT_LIST_HEAD(&jack
->jack_zones
);
70 BLOCKING_INIT_NOTIFIER_HEAD(&jack
->notifier
);
72 ret
= snd_jack_new(card
->snd_card
, id
, type
, &jack
->jack
, false, false);
77 ret
= snd_soc_jack_add_pins(jack
, num_pins
, pins
);
79 return soc_card_ret(card
, ret
);
81 EXPORT_SYMBOL_GPL(snd_soc_card_jack_new
);
83 int snd_soc_card_suspend_pre(struct snd_soc_card
*card
)
87 if (card
->suspend_pre
)
88 ret
= card
->suspend_pre(card
);
90 return soc_card_ret(card
, ret
);
93 int snd_soc_card_suspend_post(struct snd_soc_card
*card
)
97 if (card
->suspend_post
)
98 ret
= card
->suspend_post(card
);
100 return soc_card_ret(card
, ret
);
103 int snd_soc_card_resume_pre(struct snd_soc_card
*card
)
107 if (card
->resume_pre
)
108 ret
= card
->resume_pre(card
);
110 return soc_card_ret(card
, ret
);
113 int snd_soc_card_resume_post(struct snd_soc_card
*card
)
117 if (card
->resume_post
)
118 ret
= card
->resume_post(card
);
120 return soc_card_ret(card
, ret
);
123 int snd_soc_card_probe(struct snd_soc_card
*card
)
126 int ret
= card
->probe(card
);
129 return soc_card_ret(card
, ret
);
132 * It has "card->probe" and "card->late_probe" callbacks.
133 * So, set "probed" flag here, because it needs to care
134 * about "late_probe".
137 * snd_soc_bind_card()
138 * snd_soc_card_late_probe()
146 int snd_soc_card_late_probe(struct snd_soc_card
*card
)
148 if (card
->late_probe
) {
149 int ret
= card
->late_probe(card
);
152 return soc_card_ret(card
, ret
);
156 * It has "card->probe" and "card->late_probe" callbacks,
157 * and "late_probe" callback is called after "probe".
158 * This means, we can set "card->probed" flag afer "late_probe"
162 * snd_soc_bind_card()
163 * snd_soc_card_probe()
170 int snd_soc_card_remove(struct snd_soc_card
*card
)
176 ret
= card
->remove(card
);
180 return soc_card_ret(card
, ret
);
183 int snd_soc_card_set_bias_level(struct snd_soc_card
*card
,
184 struct snd_soc_dapm_context
*dapm
,
185 enum snd_soc_bias_level level
)
189 if (card
&& card
->set_bias_level
)
190 ret
= card
->set_bias_level(card
, dapm
, level
);
192 return soc_card_ret(card
, ret
);
195 int snd_soc_card_set_bias_level_post(struct snd_soc_card
*card
,
196 struct snd_soc_dapm_context
*dapm
,
197 enum snd_soc_bias_level level
)
201 if (card
&& card
->set_bias_level_post
)
202 ret
= card
->set_bias_level_post(card
, dapm
, level
);
204 return soc_card_ret(card
, ret
);
207 int snd_soc_card_add_dai_link(struct snd_soc_card
*card
,
208 struct snd_soc_dai_link
*dai_link
)
212 if (card
->add_dai_link
)
213 ret
= card
->add_dai_link(card
, dai_link
);
215 return soc_card_ret(card
, ret
);
217 EXPORT_SYMBOL_GPL(snd_soc_card_add_dai_link
);
219 void snd_soc_card_remove_dai_link(struct snd_soc_card
*card
,
220 struct snd_soc_dai_link
*dai_link
)
222 if (card
->remove_dai_link
)
223 card
->remove_dai_link(card
, dai_link
);
225 EXPORT_SYMBOL_GPL(snd_soc_card_remove_dai_link
);