.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Dummy soundcard |
---|
3 | 4 | * 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 | | - * |
---|
19 | 5 | */ |
---|
20 | 6 | |
---|
21 | 7 | #include <linux/init.h> |
---|
.. | .. |
---|
131 | 117 | |
---|
132 | 118 | struct snd_dummy { |
---|
133 | 119 | struct snd_card *card; |
---|
134 | | - struct dummy_model *model; |
---|
| 120 | + const struct dummy_model *model; |
---|
135 | 121 | struct snd_pcm *pcm; |
---|
136 | 122 | struct snd_pcm_hardware pcm_hw; |
---|
137 | 123 | spinlock_t mixer_lock; |
---|
.. | .. |
---|
158 | 144 | return 0; |
---|
159 | 145 | } |
---|
160 | 146 | |
---|
161 | | -static struct dummy_model model_emu10k1 = { |
---|
| 147 | +static const struct dummy_model model_emu10k1 = { |
---|
162 | 148 | .name = "emu10k1", |
---|
163 | 149 | .playback_constraints = emu10k1_playback_constraints, |
---|
164 | 150 | .buffer_bytes_max = 128 * 1024, |
---|
165 | 151 | }; |
---|
166 | 152 | |
---|
167 | | -static struct dummy_model model_rme9652 = { |
---|
| 153 | +static const struct dummy_model model_rme9652 = { |
---|
168 | 154 | .name = "rme9652", |
---|
169 | 155 | .buffer_bytes_max = 26 * 64 * 1024, |
---|
170 | 156 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
---|
.. | .. |
---|
174 | 160 | .periods_max = 2, |
---|
175 | 161 | }; |
---|
176 | 162 | |
---|
177 | | -static struct dummy_model model_ice1712 = { |
---|
| 163 | +static const struct dummy_model model_ice1712 = { |
---|
178 | 164 | .name = "ice1712", |
---|
179 | 165 | .buffer_bytes_max = 256 * 1024, |
---|
180 | 166 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
---|
.. | .. |
---|
184 | 170 | .periods_max = 1024, |
---|
185 | 171 | }; |
---|
186 | 172 | |
---|
187 | | -static struct dummy_model model_uda1341 = { |
---|
| 173 | +static const struct dummy_model model_uda1341 = { |
---|
188 | 174 | .name = "uda1341", |
---|
189 | 175 | .buffer_bytes_max = 16380, |
---|
190 | 176 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
---|
.. | .. |
---|
194 | 180 | .periods_max = 255, |
---|
195 | 181 | }; |
---|
196 | 182 | |
---|
197 | | -static struct dummy_model model_ac97 = { |
---|
| 183 | +static const struct dummy_model model_ac97 = { |
---|
198 | 184 | .name = "ac97", |
---|
199 | 185 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
---|
200 | 186 | .channels_min = 2, |
---|
.. | .. |
---|
204 | 190 | .rate_max = 48000, |
---|
205 | 191 | }; |
---|
206 | 192 | |
---|
207 | | -static struct dummy_model model_ca0106 = { |
---|
| 193 | +static const struct dummy_model model_ca0106 = { |
---|
208 | 194 | .name = "ca0106", |
---|
209 | 195 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
---|
210 | 196 | .buffer_bytes_max = ((65536-64)*8), |
---|
.. | .. |
---|
218 | 204 | .rate_max = 192000, |
---|
219 | 205 | }; |
---|
220 | 206 | |
---|
221 | | -static struct dummy_model *dummy_models[] = { |
---|
| 207 | +static const struct dummy_model *dummy_models[] = { |
---|
222 | 208 | &model_emu10k1, |
---|
223 | 209 | &model_rme9652, |
---|
224 | 210 | &model_ice1712, |
---|
.. | .. |
---|
543 | 529 | substream->runtime->dma_bytes = params_buffer_bytes(hw_params); |
---|
544 | 530 | return 0; |
---|
545 | 531 | } |
---|
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; |
---|
555 | 533 | } |
---|
556 | 534 | |
---|
557 | 535 | static int dummy_pcm_open(struct snd_pcm_substream *substream) |
---|
558 | 536 | { |
---|
559 | 537 | struct snd_dummy *dummy = snd_pcm_substream_chip(substream); |
---|
560 | | - struct dummy_model *model = dummy->model; |
---|
| 538 | + const struct dummy_model *model = dummy->model; |
---|
561 | 539 | struct snd_pcm_runtime *runtime = substream->runtime; |
---|
562 | 540 | const struct dummy_timer_ops *ops; |
---|
563 | 541 | int err; |
---|
.. | .. |
---|
666 | 644 | return virt_to_page(dummy_page[substream->stream]); /* the same page */ |
---|
667 | 645 | } |
---|
668 | 646 | |
---|
669 | | -static struct snd_pcm_ops dummy_pcm_ops = { |
---|
| 647 | +static const struct snd_pcm_ops dummy_pcm_ops = { |
---|
670 | 648 | .open = dummy_pcm_open, |
---|
671 | 649 | .close = dummy_pcm_close, |
---|
672 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
673 | 650 | .hw_params = dummy_pcm_hw_params, |
---|
674 | | - .hw_free = dummy_pcm_hw_free, |
---|
675 | 651 | .prepare = dummy_pcm_prepare, |
---|
676 | 652 | .trigger = dummy_pcm_trigger, |
---|
677 | 653 | .pointer = dummy_pcm_pointer, |
---|
678 | 654 | }; |
---|
679 | 655 | |
---|
680 | | -static struct snd_pcm_ops dummy_pcm_ops_no_buf = { |
---|
| 656 | +static const struct snd_pcm_ops dummy_pcm_ops_no_buf = { |
---|
681 | 657 | .open = dummy_pcm_open, |
---|
682 | 658 | .close = dummy_pcm_close, |
---|
683 | | - .ioctl = snd_pcm_lib_ioctl, |
---|
684 | 659 | .hw_params = dummy_pcm_hw_params, |
---|
685 | | - .hw_free = dummy_pcm_hw_free, |
---|
686 | 660 | .prepare = dummy_pcm_prepare, |
---|
687 | 661 | .trigger = dummy_pcm_trigger, |
---|
688 | 662 | .pointer = dummy_pcm_pointer, |
---|
.. | .. |
---|
696 | 670 | int substreams) |
---|
697 | 671 | { |
---|
698 | 672 | struct snd_pcm *pcm; |
---|
699 | | - struct snd_pcm_ops *ops; |
---|
| 673 | + const struct snd_pcm_ops *ops; |
---|
700 | 674 | int err; |
---|
701 | 675 | |
---|
702 | 676 | err = snd_pcm_new(dummy->card, "Dummy PCM", device, |
---|
.. | .. |
---|
714 | 688 | pcm->info_flags = 0; |
---|
715 | 689 | strcpy(pcm->name, "Dummy PCM"); |
---|
716 | 690 | if (!fake_buffer) { |
---|
717 | | - snd_pcm_lib_preallocate_pages_for_all(pcm, |
---|
| 691 | + snd_pcm_set_managed_buffer_all(pcm, |
---|
718 | 692 | SNDRV_DMA_TYPE_CONTINUOUS, |
---|
719 | | - snd_dma_continuous_data(GFP_KERNEL), |
---|
| 693 | + NULL, |
---|
720 | 694 | 0, 64*1024); |
---|
721 | 695 | } |
---|
722 | 696 | return 0; |
---|
.. | .. |
---|
875 | 849 | return changed; |
---|
876 | 850 | } |
---|
877 | 851 | |
---|
878 | | -static struct snd_kcontrol_new snd_dummy_controls[] = { |
---|
| 852 | +static const struct snd_kcontrol_new snd_dummy_controls[] = { |
---|
879 | 853 | DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), |
---|
880 | 854 | DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), |
---|
881 | 855 | DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), |
---|
.. | .. |
---|
927 | 901 | static void print_formats(struct snd_dummy *dummy, |
---|
928 | 902 | struct snd_info_buffer *buffer) |
---|
929 | 903 | { |
---|
930 | | - int i; |
---|
| 904 | + snd_pcm_format_t i; |
---|
931 | 905 | |
---|
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)) |
---|
934 | 908 | snd_iprintf(buffer, " %s", snd_pcm_format_name(i)); |
---|
935 | 909 | } |
---|
936 | 910 | } |
---|
.. | .. |
---|
938 | 912 | static void print_rates(struct snd_dummy *dummy, |
---|
939 | 913 | struct snd_info_buffer *buffer) |
---|
940 | 914 | { |
---|
941 | | - static int rates[] = { |
---|
| 915 | + static const int rates[] = { |
---|
942 | 916 | 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, |
---|
943 | 917 | 64000, 88200, 96000, 176400, 192000, |
---|
944 | 918 | }; |
---|
.. | .. |
---|
970 | 944 | .offset = offsetof(struct snd_pcm_hardware, item), \ |
---|
971 | 945 | .size = sizeof(dummy_pcm_hardware.item) } |
---|
972 | 946 | |
---|
973 | | -static struct dummy_hw_field fields[] = { |
---|
| 947 | +static const struct dummy_hw_field fields[] = { |
---|
974 | 948 | FIELD_ENTRY(formats, "%#llx"), |
---|
975 | 949 | FIELD_ENTRY(rates, "%#x"), |
---|
976 | 950 | FIELD_ENTRY(rate_min, "%d"), |
---|
.. | .. |
---|
1037 | 1011 | |
---|
1038 | 1012 | static void dummy_proc_init(struct snd_dummy *chip) |
---|
1039 | 1013 | { |
---|
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); |
---|
1048 | 1016 | } |
---|
1049 | 1017 | #else |
---|
1050 | 1018 | #define dummy_proc_init(x) |
---|
.. | .. |
---|
1054 | 1022 | { |
---|
1055 | 1023 | struct snd_card *card; |
---|
1056 | 1024 | struct snd_dummy *dummy; |
---|
1057 | | - struct dummy_model *m = NULL, **mdl; |
---|
| 1025 | + const struct dummy_model *m = NULL, **mdl; |
---|
1058 | 1026 | int idx, err; |
---|
1059 | 1027 | int dev = devptr->id; |
---|
1060 | 1028 | |
---|
.. | .. |
---|
1138 | 1106 | static int snd_dummy_suspend(struct device *pdev) |
---|
1139 | 1107 | { |
---|
1140 | 1108 | struct snd_card *card = dev_get_drvdata(pdev); |
---|
1141 | | - struct snd_dummy *dummy = card->private_data; |
---|
1142 | 1109 | |
---|
1143 | 1110 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
---|
1144 | | - snd_pcm_suspend_all(dummy->pcm); |
---|
1145 | 1111 | return 0; |
---|
1146 | 1112 | } |
---|
1147 | 1113 | |
---|