Kuninori Morimoto | 1793936 | 2020-05-28 10:47:46 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // soc-card.c |
| 4 | // |
| 5 | // Copyright (C) 2019 Renesas Electronics Corp. |
| 6 | // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 7 | // |
| 8 | #include <sound/soc.h> |
Kuninori Morimoto | 3359e9b | 2020-05-28 10:48:03 +0900 | [diff] [blame] | 9 | #include <sound/jack.h> |
Kuninori Morimoto | 1793936 | 2020-05-28 10:47:46 +0900 | [diff] [blame] | 10 | |
| 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) |
| 14 | { |
| 15 | switch (ret) { |
| 16 | case -EPROBE_DEFER: |
| 17 | case -ENOTSUPP: |
| 18 | case 0: |
| 19 | break; |
| 20 | default: |
| 21 | dev_err(card->dev, |
| 22 | "ASoC: error at %s on %s: %d\n", |
| 23 | func, card->name, ret); |
| 24 | } |
| 25 | |
| 26 | return ret; |
| 27 | } |
Kuninori Morimoto | 209c6cd | 2020-05-28 10:47:56 +0900 | [diff] [blame] | 28 | |
| 29 | struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, |
| 30 | const char *name) |
| 31 | { |
| 32 | struct snd_card *card = soc_card->snd_card; |
| 33 | struct snd_kcontrol *kctl; |
| 34 | |
| 35 | if (unlikely(!name)) |
| 36 | return NULL; |
| 37 | |
| 38 | list_for_each_entry(kctl, &card->controls, list) |
| 39 | if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) |
| 40 | return kctl; |
| 41 | return NULL; |
| 42 | } |
| 43 | EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); |
Kuninori Morimoto | 3359e9b | 2020-05-28 10:48:03 +0900 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * snd_soc_card_jack_new - Create a new jack |
| 47 | * @card: ASoC card |
| 48 | * @id: an identifying string for this jack |
| 49 | * @type: a bitmask of enum snd_jack_type values that can be detected by |
| 50 | * this jack |
| 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 |
| 54 | * |
| 55 | * Creates a new jack object. |
| 56 | * |
| 57 | * Returns zero if successful, or a negative error code on failure. |
| 58 | * On success jack will be initialised. |
| 59 | */ |
| 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) |
| 63 | { |
| 64 | int ret; |
| 65 | |
| 66 | mutex_init(&jack->mutex); |
| 67 | jack->card = card; |
| 68 | INIT_LIST_HEAD(&jack->pins); |
| 69 | INIT_LIST_HEAD(&jack->jack_zones); |
| 70 | BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier); |
| 71 | |
| 72 | ret = snd_jack_new(card->snd_card, id, type, &jack->jack, false, false); |
| 73 | if (ret) |
| 74 | goto end; |
| 75 | |
| 76 | if (num_pins) |
| 77 | ret = snd_soc_jack_add_pins(jack, num_pins, pins); |
| 78 | end: |
| 79 | return soc_card_ret(card, ret); |
| 80 | } |
| 81 | EXPORT_SYMBOL_GPL(snd_soc_card_jack_new); |
Kuninori Morimoto | 130dc08 | 2020-05-28 10:48:39 +0900 | [diff] [blame] | 82 | |
| 83 | int snd_soc_card_suspend_pre(struct snd_soc_card *card) |
| 84 | { |
| 85 | int ret = 0; |
| 86 | |
| 87 | if (card->suspend_pre) |
| 88 | ret = card->suspend_pre(card); |
| 89 | |
| 90 | return soc_card_ret(card, ret); |
| 91 | } |
Kuninori Morimoto | d17b60b | 2020-05-28 10:48:48 +0900 | [diff] [blame] | 92 | |
| 93 | int snd_soc_card_suspend_post(struct snd_soc_card *card) |
| 94 | { |
| 95 | int ret = 0; |
| 96 | |
| 97 | if (card->suspend_post) |
| 98 | ret = card->suspend_post(card); |
| 99 | |
| 100 | return soc_card_ret(card, ret); |
| 101 | } |
Kuninori Morimoto | 934c752 | 2020-05-28 10:48:55 +0900 | [diff] [blame] | 102 | |
| 103 | int snd_soc_card_resume_pre(struct snd_soc_card *card) |
| 104 | { |
| 105 | int ret = 0; |
| 106 | |
| 107 | if (card->resume_pre) |
| 108 | ret = card->resume_pre(card); |
| 109 | |
| 110 | return soc_card_ret(card, ret); |
| 111 | } |
Kuninori Morimoto | 739443d | 2020-05-28 10:49:02 +0900 | [diff] [blame] | 112 | |
| 113 | int snd_soc_card_resume_post(struct snd_soc_card *card) |
| 114 | { |
| 115 | int ret = 0; |
| 116 | |
| 117 | if (card->resume_post) |
| 118 | ret = card->resume_post(card); |
| 119 | |
| 120 | return soc_card_ret(card, ret); |
| 121 | } |
Kuninori Morimoto | 73de4b02 | 2020-05-28 10:49:11 +0900 | [diff] [blame^] | 122 | |
| 123 | int snd_soc_card_probe(struct snd_soc_card *card) |
| 124 | { |
| 125 | if (card->probe) { |
| 126 | int ret = card->probe(card); |
| 127 | |
| 128 | if (ret < 0) |
| 129 | return soc_card_ret(card, ret); |
| 130 | |
| 131 | /* |
| 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". |
| 135 | * |
| 136 | * see |
| 137 | * snd_soc_bind_card() |
| 138 | * snd_soc_card_late_probe() |
| 139 | */ |
| 140 | card->probed = 1; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |