hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/sound/core/init.c
....@@ -1,22 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Initialization routines
34 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4
- *
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; if not, write to the Free Software
18
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
- *
205 */
216
227 #include <linux/init.h>
....@@ -29,6 +14,7 @@
2914 #include <linux/ctype.h>
3015 #include <linux/pm.h>
3116 #include <linux/completion.h>
17
+#include <linux/interrupt.h>
3218
3319 #include <sound/core.h>
3420 #include <sound/control.h>
....@@ -49,8 +35,7 @@
4935
5036 /* locked for registering/using */
5137 static DECLARE_BITMAP(snd_cards_lock, SNDRV_CARDS);
52
-struct snd_card *snd_cards[SNDRV_CARDS];
53
-EXPORT_SYMBOL(snd_cards);
38
+static struct snd_card *snd_cards[SNDRV_CARDS];
5439
5540 static DEFINE_MUTEX(snd_card_mutex);
5641
....@@ -98,31 +83,6 @@
9883 #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
9984 int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag);
10085 EXPORT_SYMBOL(snd_mixer_oss_notify_callback);
101
-#endif
102
-
103
-#ifdef CONFIG_SND_PROC_FS
104
-static void snd_card_id_read(struct snd_info_entry *entry,
105
- struct snd_info_buffer *buffer)
106
-{
107
- snd_iprintf(buffer, "%s\n", entry->card->id);
108
-}
109
-
110
-static int init_info_for_card(struct snd_card *card)
111
-{
112
- struct snd_info_entry *entry;
113
-
114
- entry = snd_info_create_card_entry(card, "id", card->proc_root);
115
- if (!entry) {
116
- dev_dbg(card->dev, "unable to create card entry\n");
117
- return -ENOMEM;
118
- }
119
- entry->c.text.read = snd_card_id_read;
120
- card->proc_id = entry;
121
-
122
- return snd_info_card_register(card);
123
-}
124
-#else /* !CONFIG_SND_PROC_FS */
125
-#define init_info_for_card(card)
12686 #endif
12787
12888 static int check_empty_slot(struct module *module, int slot)
....@@ -244,7 +204,10 @@
244204 mutex_unlock(&snd_card_mutex);
245205 card->dev = parent;
246206 card->number = idx;
207
+#ifdef MODULE
208
+ WARN_ON(!module);
247209 card->module = module;
210
+#endif
248211 INIT_LIST_HEAD(&card->devices);
249212 init_rwsem(&card->controls_rwsem);
250213 rwlock_init(&card->ctl_files_rwlock);
....@@ -252,12 +215,13 @@
252215 INIT_LIST_HEAD(&card->ctl_files);
253216 spin_lock_init(&card->files_lock);
254217 INIT_LIST_HEAD(&card->files_list);
218
+ mutex_init(&card->memory_mutex);
255219 #ifdef CONFIG_PM
256220 init_waitqueue_head(&card->power_sleep);
257221 #endif
258222 init_waitqueue_head(&card->remove_sleep);
223
+ card->sync_irq = -1;
259224
260
- init_waitqueue_head(&card->offline_poll_wait);
261225 device_initialize(&card->card_dev);
262226 card->card_dev.parent = parent;
263227 card->card_dev.class = sound_class;
....@@ -293,6 +257,26 @@
293257 return err;
294258 }
295259 EXPORT_SYMBOL(snd_card_new);
260
+
261
+/**
262
+ * snd_card_ref - Get the card object from the index
263
+ * @idx: the card index
264
+ *
265
+ * Returns a card object corresponding to the given index or NULL if not found.
266
+ * Release the object via snd_card_unref().
267
+ */
268
+struct snd_card *snd_card_ref(int idx)
269
+{
270
+ struct snd_card *card;
271
+
272
+ mutex_lock(&snd_card_mutex);
273
+ card = snd_cards[idx];
274
+ if (card)
275
+ get_device(&card->card_dev);
276
+ mutex_unlock(&snd_card_mutex);
277
+ return card;
278
+}
279
+EXPORT_SYMBOL_GPL(snd_card_ref);
296280
297281 /* return non-zero if a card is already locked */
298282 int snd_card_locked(int card)
....@@ -433,6 +417,9 @@
433417 /* notify all devices that we are disconnected */
434418 snd_device_disconnect_all(card);
435419
420
+ if (card->sync_irq > 0)
421
+ synchronize_irq(card->sync_irq);
422
+
436423 snd_info_card_disconnect(card);
437424 if (card->registered) {
438425 device_del(&card->card_dev);
....@@ -490,7 +477,6 @@
490477 snd_device_free_all(card);
491478 if (card->private_free)
492479 card->private_free(card);
493
- snd_info_free_entry(card->proc_id);
494480 if (snd_info_card_free(card) < 0) {
495481 dev_warn(card->dev, "unable to free card info\n");
496482 /* Not fatal error */
....@@ -535,10 +521,9 @@
535521 */
536522 int snd_card_free(struct snd_card *card)
537523 {
538
- struct completion released;
524
+ DECLARE_COMPLETION_ONSTACK(released);
539525 int ret;
540526
541
- init_completion(&released);
542527 card->release_completion = &released;
543528 ret = snd_card_free_when_closed(card);
544529 if (ret)
....@@ -794,7 +779,10 @@
794779 }
795780 snd_cards[card->number] = card;
796781 mutex_unlock(&snd_card_mutex);
797
- init_info_for_card(card);
782
+ err = snd_info_card_register(card);
783
+ if (err < 0)
784
+ return err;
785
+
798786 #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
799787 if (snd_mixer_oss_notify_callback)
800788 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER);
....@@ -998,25 +986,6 @@
998986 return 0;
999987 }
1000988 EXPORT_SYMBOL(snd_card_file_remove);
1001
-
1002
-/**
1003
- * snd_card_change_online_state - mark card's online/offline state
1004
- * @card: Card to mark
1005
- * @online: whether online of offline
1006
- *
1007
- * Mutes the DAI DAC.
1008
- */
1009
-void snd_card_change_online_state(struct snd_card *card, int online)
1010
-{
1011
- snd_printd("snd card %s state change %d -> %d\n",
1012
- card->shortname, !card->offline, online);
1013
- card->offline = !online;
1014
- /* make sure offline is updated prior to wake up */
1015
- wmb();
1016
- xchg(&card->offline_change, 1);
1017
- wake_up_interruptible(&card->offline_poll_wait);
1018
-}
1019
-EXPORT_SYMBOL_GPL(snd_card_change_online_state);
1020989
1021990 #ifdef CONFIG_PM
1022991 /**