1 // SPDX-License-Identifier: GPL-2.0 1 2 // 3 // soc-card.c 4 // 5 // Copyright (C) 2019 Renesas Electronics Corp 6 // Kuninori Morimoto <kuninori.morimoto.gx@ren 7 // 8 9 #include <linux/lockdep.h> 10 #include <linux/rwsem.h> 11 #include <sound/soc.h> 12 #include <sound/jack.h> 13 14 #define soc_card_ret(dai, ret) _soc_card_ret(d 15 static inline int _soc_card_ret(struct snd_soc 16 const char *fu 17 { 18 switch (ret) { 19 case -EPROBE_DEFER: 20 case -ENOTSUPP: 21 case 0: 22 break; 23 default: 24 dev_err(card->dev, 25 "ASoC: error at %s on 26 func, card->name, ret) 27 } 28 29 return ret; 30 } 31 32 struct snd_kcontrol *snd_soc_card_get_kcontrol 33 34 { 35 if (unlikely(!name)) 36 return NULL; 37 38 return snd_ctl_find_id_mixer(soc_card- 39 } 40 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); 41 42 static int jack_new(struct snd_soc_card *card, 43 struct snd_soc_jack *jack, 44 { 45 mutex_init(&jack->mutex); 46 jack->card = card; 47 INIT_LIST_HEAD(&jack->pins); 48 INIT_LIST_HEAD(&jack->jack_zones); 49 BLOCKING_INIT_NOTIFIER_HEAD(&jack->not 50 51 return snd_jack_new(card->snd_card, id 52 } 53 54 /** 55 * snd_soc_card_jack_new - Create a new jack w 56 * @card: ASoC card 57 * @id: an identifying string for this jack 58 * @type: a bitmask of enum snd_jack_type val 59 * this jack 60 * @jack: structure to use for the jack 61 * 62 * Creates a new jack object without pins. If 63 * snd_soc_card_jack_new_pins() should be used 64 * argument. 65 * 66 * Returns zero if successful, or a negative e 67 * On success jack will be initialised. 68 */ 69 int snd_soc_card_jack_new(struct snd_soc_card 70 struct snd_soc_jack 71 { 72 return soc_card_ret(card, jack_new(car 73 } 74 EXPORT_SYMBOL_GPL(snd_soc_card_jack_new); 75 76 /** 77 * snd_soc_card_jack_new_pins - Create a new j 78 * @card: ASoC card 79 * @id: an identifying string for this jack 80 * @type: a bitmask of enum snd_jack_type val 81 * this jack 82 * @jack: structure to use for the jack 83 * @pins: Array of jack pins to be added to t 84 * @num_pins: Number of elements in the @pins 85 * 86 * Creates a new jack object with pins. If not 87 * snd_soc_card_jack_new() should be used inst 88 * 89 * Returns zero if successful, or a negative e 90 * On success jack will be initialised. 91 */ 92 int snd_soc_card_jack_new_pins(struct snd_soc_ 93 int type, struc 94 struct snd_soc_ 95 unsigned int nu 96 { 97 int ret; 98 99 ret = jack_new(card, id, type, jack, f 100 if (ret) 101 goto end; 102 103 if (num_pins) 104 ret = snd_soc_jack_add_pins(ja 105 end: 106 return soc_card_ret(card, ret); 107 } 108 EXPORT_SYMBOL_GPL(snd_soc_card_jack_new_pins); 109 110 int snd_soc_card_suspend_pre(struct snd_soc_ca 111 { 112 int ret = 0; 113 114 if (card->suspend_pre) 115 ret = card->suspend_pre(card); 116 117 return soc_card_ret(card, ret); 118 } 119 120 int snd_soc_card_suspend_post(struct snd_soc_c 121 { 122 int ret = 0; 123 124 if (card->suspend_post) 125 ret = card->suspend_post(card) 126 127 return soc_card_ret(card, ret); 128 } 129 130 int snd_soc_card_resume_pre(struct snd_soc_car 131 { 132 int ret = 0; 133 134 if (card->resume_pre) 135 ret = card->resume_pre(card); 136 137 return soc_card_ret(card, ret); 138 } 139 140 int snd_soc_card_resume_post(struct snd_soc_ca 141 { 142 int ret = 0; 143 144 if (card->resume_post) 145 ret = card->resume_post(card); 146 147 return soc_card_ret(card, ret); 148 } 149 150 int snd_soc_card_probe(struct snd_soc_card *ca 151 { 152 if (card->probe) { 153 int ret = card->probe(card); 154 155 if (ret < 0) 156 return soc_card_ret(ca 157 158 /* 159 * It has "card->probe" and "c 160 * So, set "probed" flag here, 161 * about "late_probe". 162 * 163 * see 164 * snd_soc_bind_card() 165 * snd_soc_card_late_prob 166 */ 167 card->probed = 1; 168 } 169 170 return 0; 171 } 172 173 int snd_soc_card_late_probe(struct snd_soc_car 174 { 175 if (card->late_probe) { 176 int ret = card->late_probe(car 177 178 if (ret < 0) 179 return soc_card_ret(ca 180 } 181 182 /* 183 * It has "card->probe" and "card->lat 184 * and "late_probe" callback is called 185 * This means, we can set "card->probe 186 * for all cases. 187 * 188 * see 189 * snd_soc_bind_card() 190 * snd_soc_card_probe() 191 */ 192 card->probed = 1; 193 194 return 0; 195 } 196 197 void snd_soc_card_fixup_controls(struct snd_so 198 { 199 if (card->fixup_controls) 200 card->fixup_controls(card); 201 } 202 203 int snd_soc_card_remove(struct snd_soc_card *c 204 { 205 int ret = 0; 206 207 if (card->probed && 208 card->remove) 209 ret = card->remove(card); 210 211 card->probed = 0; 212 213 return soc_card_ret(card, ret); 214 } 215 216 int snd_soc_card_set_bias_level(struct snd_soc 217 struct snd_soc 218 enum snd_soc_b 219 { 220 int ret = 0; 221 222 if (card && card->set_bias_level) 223 ret = card->set_bias_level(car 224 225 return soc_card_ret(card, ret); 226 } 227 228 int snd_soc_card_set_bias_level_post(struct sn 229 struct sn 230 enum snd_ 231 { 232 int ret = 0; 233 234 if (card && card->set_bias_level_post) 235 ret = card->set_bias_level_pos 236 237 return soc_card_ret(card, ret); 238 } 239 240 int snd_soc_card_add_dai_link(struct snd_soc_c 241 struct snd_soc_d 242 { 243 int ret = 0; 244 245 if (card->add_dai_link) 246 ret = card->add_dai_link(card, 247 248 return soc_card_ret(card, ret); 249 } 250 EXPORT_SYMBOL_GPL(snd_soc_card_add_dai_link); 251 252 void snd_soc_card_remove_dai_link(struct snd_s 253 struct snd_s 254 { 255 if (card->remove_dai_link) 256 card->remove_dai_link(card, da 257 } 258 EXPORT_SYMBOL_GPL(snd_soc_card_remove_dai_link 259
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.