hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/drivers/dummy.c
....@@ -1,21 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Dummy soundcard
34 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
- *
195 */
206
217 #include <linux/init.h>
....@@ -131,7 +117,7 @@
131117
132118 struct snd_dummy {
133119 struct snd_card *card;
134
- struct dummy_model *model;
120
+ const struct dummy_model *model;
135121 struct snd_pcm *pcm;
136122 struct snd_pcm_hardware pcm_hw;
137123 spinlock_t mixer_lock;
....@@ -158,13 +144,13 @@
158144 return 0;
159145 }
160146
161
-static struct dummy_model model_emu10k1 = {
147
+static const struct dummy_model model_emu10k1 = {
162148 .name = "emu10k1",
163149 .playback_constraints = emu10k1_playback_constraints,
164150 .buffer_bytes_max = 128 * 1024,
165151 };
166152
167
-static struct dummy_model model_rme9652 = {
153
+static const struct dummy_model model_rme9652 = {
168154 .name = "rme9652",
169155 .buffer_bytes_max = 26 * 64 * 1024,
170156 .formats = SNDRV_PCM_FMTBIT_S32_LE,
....@@ -174,7 +160,7 @@
174160 .periods_max = 2,
175161 };
176162
177
-static struct dummy_model model_ice1712 = {
163
+static const struct dummy_model model_ice1712 = {
178164 .name = "ice1712",
179165 .buffer_bytes_max = 256 * 1024,
180166 .formats = SNDRV_PCM_FMTBIT_S32_LE,
....@@ -184,7 +170,7 @@
184170 .periods_max = 1024,
185171 };
186172
187
-static struct dummy_model model_uda1341 = {
173
+static const struct dummy_model model_uda1341 = {
188174 .name = "uda1341",
189175 .buffer_bytes_max = 16380,
190176 .formats = SNDRV_PCM_FMTBIT_S16_LE,
....@@ -194,7 +180,7 @@
194180 .periods_max = 255,
195181 };
196182
197
-static struct dummy_model model_ac97 = {
183
+static const struct dummy_model model_ac97 = {
198184 .name = "ac97",
199185 .formats = SNDRV_PCM_FMTBIT_S16_LE,
200186 .channels_min = 2,
....@@ -204,7 +190,7 @@
204190 .rate_max = 48000,
205191 };
206192
207
-static struct dummy_model model_ca0106 = {
193
+static const struct dummy_model model_ca0106 = {
208194 .name = "ca0106",
209195 .formats = SNDRV_PCM_FMTBIT_S16_LE,
210196 .buffer_bytes_max = ((65536-64)*8),
....@@ -218,7 +204,7 @@
218204 .rate_max = 192000,
219205 };
220206
221
-static struct dummy_model *dummy_models[] = {
207
+static const struct dummy_model *dummy_models[] = {
222208 &model_emu10k1,
223209 &model_rme9652,
224210 &model_ice1712,
....@@ -543,21 +529,13 @@
543529 substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
544530 return 0;
545531 }
546
- return snd_pcm_lib_malloc_pages(substream,
547
- params_buffer_bytes(hw_params));
548
-}
549
-
550
-static int dummy_pcm_hw_free(struct snd_pcm_substream *substream)
551
-{
552
- if (fake_buffer)
553
- return 0;
554
- return snd_pcm_lib_free_pages(substream);
532
+ return 0;
555533 }
556534
557535 static int dummy_pcm_open(struct snd_pcm_substream *substream)
558536 {
559537 struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
560
- struct dummy_model *model = dummy->model;
538
+ const struct dummy_model *model = dummy->model;
561539 struct snd_pcm_runtime *runtime = substream->runtime;
562540 const struct dummy_timer_ops *ops;
563541 int err;
....@@ -666,23 +644,19 @@
666644 return virt_to_page(dummy_page[substream->stream]); /* the same page */
667645 }
668646
669
-static struct snd_pcm_ops dummy_pcm_ops = {
647
+static const struct snd_pcm_ops dummy_pcm_ops = {
670648 .open = dummy_pcm_open,
671649 .close = dummy_pcm_close,
672
- .ioctl = snd_pcm_lib_ioctl,
673650 .hw_params = dummy_pcm_hw_params,
674
- .hw_free = dummy_pcm_hw_free,
675651 .prepare = dummy_pcm_prepare,
676652 .trigger = dummy_pcm_trigger,
677653 .pointer = dummy_pcm_pointer,
678654 };
679655
680
-static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
656
+static const struct snd_pcm_ops dummy_pcm_ops_no_buf = {
681657 .open = dummy_pcm_open,
682658 .close = dummy_pcm_close,
683
- .ioctl = snd_pcm_lib_ioctl,
684659 .hw_params = dummy_pcm_hw_params,
685
- .hw_free = dummy_pcm_hw_free,
686660 .prepare = dummy_pcm_prepare,
687661 .trigger = dummy_pcm_trigger,
688662 .pointer = dummy_pcm_pointer,
....@@ -696,7 +670,7 @@
696670 int substreams)
697671 {
698672 struct snd_pcm *pcm;
699
- struct snd_pcm_ops *ops;
673
+ const struct snd_pcm_ops *ops;
700674 int err;
701675
702676 err = snd_pcm_new(dummy->card, "Dummy PCM", device,
....@@ -714,9 +688,9 @@
714688 pcm->info_flags = 0;
715689 strcpy(pcm->name, "Dummy PCM");
716690 if (!fake_buffer) {
717
- snd_pcm_lib_preallocate_pages_for_all(pcm,
691
+ snd_pcm_set_managed_buffer_all(pcm,
718692 SNDRV_DMA_TYPE_CONTINUOUS,
719
- snd_dma_continuous_data(GFP_KERNEL),
693
+ NULL,
720694 0, 64*1024);
721695 }
722696 return 0;
....@@ -875,7 +849,7 @@
875849 return changed;
876850 }
877851
878
-static struct snd_kcontrol_new snd_dummy_controls[] = {
852
+static const struct snd_kcontrol_new snd_dummy_controls[] = {
879853 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
880854 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
881855 DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
....@@ -927,10 +901,10 @@
927901 static void print_formats(struct snd_dummy *dummy,
928902 struct snd_info_buffer *buffer)
929903 {
930
- int i;
904
+ snd_pcm_format_t i;
931905
932
- for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) {
933
- if (dummy->pcm_hw.formats & (1ULL << i))
906
+ pcm_for_each_format(i) {
907
+ if (dummy->pcm_hw.formats & pcm_format_to_bits(i))
934908 snd_iprintf(buffer, " %s", snd_pcm_format_name(i));
935909 }
936910 }
....@@ -938,7 +912,7 @@
938912 static void print_rates(struct snd_dummy *dummy,
939913 struct snd_info_buffer *buffer)
940914 {
941
- static int rates[] = {
915
+ static const int rates[] = {
942916 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
943917 64000, 88200, 96000, 176400, 192000,
944918 };
....@@ -970,7 +944,7 @@
970944 .offset = offsetof(struct snd_pcm_hardware, item), \
971945 .size = sizeof(dummy_pcm_hardware.item) }
972946
973
-static struct dummy_hw_field fields[] = {
947
+static const struct dummy_hw_field fields[] = {
974948 FIELD_ENTRY(formats, "%#llx"),
975949 FIELD_ENTRY(rates, "%#x"),
976950 FIELD_ENTRY(rate_min, "%d"),
....@@ -1037,14 +1011,8 @@
10371011
10381012 static void dummy_proc_init(struct snd_dummy *chip)
10391013 {
1040
- struct snd_info_entry *entry;
1041
-
1042
- if (!snd_card_proc_new(chip->card, "dummy_pcm", &entry)) {
1043
- snd_info_set_text_ops(entry, chip, dummy_proc_read);
1044
- entry->c.text.write = dummy_proc_write;
1045
- entry->mode |= 0200;
1046
- entry->private_data = chip;
1047
- }
1014
+ snd_card_rw_proc_new(chip->card, "dummy_pcm", chip,
1015
+ dummy_proc_read, dummy_proc_write);
10481016 }
10491017 #else
10501018 #define dummy_proc_init(x)
....@@ -1054,7 +1022,7 @@
10541022 {
10551023 struct snd_card *card;
10561024 struct snd_dummy *dummy;
1057
- struct dummy_model *m = NULL, **mdl;
1025
+ const struct dummy_model *m = NULL, **mdl;
10581026 int idx, err;
10591027 int dev = devptr->id;
10601028
....@@ -1138,10 +1106,8 @@
11381106 static int snd_dummy_suspend(struct device *pdev)
11391107 {
11401108 struct snd_card *card = dev_get_drvdata(pdev);
1141
- struct snd_dummy *dummy = card->private_data;
11421109
11431110 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1144
- snd_pcm_suspend_all(dummy->pcm);
11451111 return 0;
11461112 }
11471113