hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/pci/cmipci.c
....@@ -1,20 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for C-Media CMI8338 and 8738 PCI soundcards.
34 * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>
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
185 */
196
207 /* Does not work. Warning may block system in capture mode */
....@@ -55,7 +42,7 @@
5542 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
5643 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
5744 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable switches */
58
-static long mpu_port[SNDRV_CARDS];
45
+static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1};
5946 static long fm_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
6047 static bool soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
6148 #ifdef SUPPORT_JOYSTICK
....@@ -315,7 +302,6 @@
315302 #define CM_MICGAINZ 0x01 /* mic boost */
316303 #define CM_MICGAINZ_SHIFT 0
317304
318
-#define CM_REG_MIXER3 0x24
319305 #define CM_REG_AUX_VOL 0x26
320306 #define CM_VAUXL_MASK 0xf0
321307 #define CM_VAUXR_MASK 0x0f
....@@ -599,7 +585,7 @@
599585 * calculate frequency
600586 */
601587
602
-static unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 };
588
+static const unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 };
603589
604590 static unsigned int snd_cmipci_rate_freq(unsigned int rate)
605591 {
....@@ -679,12 +665,6 @@
679665 }
680666 #endif /* USE_VAR48KRATE */
681667
682
-static int snd_cmipci_hw_params(struct snd_pcm_substream *substream,
683
- struct snd_pcm_hw_params *hw_params)
684
-{
685
- return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
686
-}
687
-
688668 static int snd_cmipci_playback2_hw_params(struct snd_pcm_substream *substream,
689669 struct snd_pcm_hw_params *hw_params)
690670 {
....@@ -699,7 +679,7 @@
699679 cm->opened[CM_CH_PLAY] = CM_OPEN_PLAYBACK_MULTI;
700680 mutex_unlock(&cm->open_mutex);
701681 }
702
- return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
682
+ return 0;
703683 }
704684
705685 static void snd_cmipci_ch_reset(struct cmipci *cm, int ch)
....@@ -708,11 +688,6 @@
708688 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset);
709689 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset);
710690 udelay(10);
711
-}
712
-
713
-static int snd_cmipci_hw_free(struct snd_pcm_substream *substream)
714
-{
715
- return snd_pcm_lib_free_pages(substream);
716691 }
717692
718693
....@@ -1384,14 +1359,14 @@
13841359 setup_spdif_playback(cm, substream, 0, 0);
13851360 restore_mixer_state(cm);
13861361 snd_cmipci_silence_hack(cm, &cm->channel[0]);
1387
- return snd_cmipci_hw_free(substream);
1362
+ return 0;
13881363 }
13891364
13901365 static int snd_cmipci_playback2_hw_free(struct snd_pcm_substream *substream)
13911366 {
13921367 struct cmipci *cm = snd_pcm_substream_chip(substream);
13931368 snd_cmipci_silence_hack(cm, &cm->channel[1]);
1394
- return snd_cmipci_hw_free(substream);
1369
+ return 0;
13951370 }
13961371
13971372 /* capture */
....@@ -1433,7 +1408,7 @@
14331408 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL);
14341409 spin_unlock_irq(&cm->reg_lock);
14351410
1436
- return snd_cmipci_hw_free(subs);
1411
+ return 0;
14371412 }
14381413
14391414
....@@ -1841,8 +1816,6 @@
18411816 static const struct snd_pcm_ops snd_cmipci_playback_ops = {
18421817 .open = snd_cmipci_playback_open,
18431818 .close = snd_cmipci_playback_close,
1844
- .ioctl = snd_pcm_lib_ioctl,
1845
- .hw_params = snd_cmipci_hw_params,
18461819 .hw_free = snd_cmipci_playback_hw_free,
18471820 .prepare = snd_cmipci_playback_prepare,
18481821 .trigger = snd_cmipci_playback_trigger,
....@@ -1852,9 +1825,6 @@
18521825 static const struct snd_pcm_ops snd_cmipci_capture_ops = {
18531826 .open = snd_cmipci_capture_open,
18541827 .close = snd_cmipci_capture_close,
1855
- .ioctl = snd_pcm_lib_ioctl,
1856
- .hw_params = snd_cmipci_hw_params,
1857
- .hw_free = snd_cmipci_hw_free,
18581828 .prepare = snd_cmipci_capture_prepare,
18591829 .trigger = snd_cmipci_capture_trigger,
18601830 .pointer = snd_cmipci_capture_pointer,
....@@ -1863,7 +1833,6 @@
18631833 static const struct snd_pcm_ops snd_cmipci_playback2_ops = {
18641834 .open = snd_cmipci_playback2_open,
18651835 .close = snd_cmipci_playback2_close,
1866
- .ioctl = snd_pcm_lib_ioctl,
18671836 .hw_params = snd_cmipci_playback2_hw_params,
18681837 .hw_free = snd_cmipci_playback2_hw_free,
18691838 .prepare = snd_cmipci_capture_prepare, /* channel B */
....@@ -1874,8 +1843,6 @@
18741843 static const struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
18751844 .open = snd_cmipci_playback_spdif_open,
18761845 .close = snd_cmipci_playback_spdif_close,
1877
- .ioctl = snd_pcm_lib_ioctl,
1878
- .hw_params = snd_cmipci_hw_params,
18791846 .hw_free = snd_cmipci_playback_hw_free,
18801847 .prepare = snd_cmipci_playback_spdif_prepare, /* set up rate */
18811848 .trigger = snd_cmipci_playback_trigger,
....@@ -1885,8 +1852,6 @@
18851852 static const struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
18861853 .open = snd_cmipci_capture_spdif_open,
18871854 .close = snd_cmipci_capture_spdif_close,
1888
- .ioctl = snd_pcm_lib_ioctl,
1889
- .hw_params = snd_cmipci_hw_params,
18901855 .hw_free = snd_cmipci_capture_spdif_hw_free,
18911856 .prepare = snd_cmipci_capture_spdif_prepare,
18921857 .trigger = snd_cmipci_capture_trigger,
....@@ -1914,8 +1879,8 @@
19141879 strcpy(pcm->name, "C-Media PCI DAC/ADC");
19151880 cm->pcm = pcm;
19161881
1917
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1918
- snd_dma_pci_data(cm->pci), 64*1024, 128*1024);
1882
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1883
+ &cm->pci->dev, 64*1024, 128*1024);
19191884
19201885 return 0;
19211886 }
....@@ -1936,8 +1901,8 @@
19361901 strcpy(pcm->name, "C-Media PCI 2nd DAC");
19371902 cm->pcm2 = pcm;
19381903
1939
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1940
- snd_dma_pci_data(cm->pci), 64*1024, 128*1024);
1904
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1905
+ &cm->pci->dev, 64*1024, 128*1024);
19411906
19421907 return 0;
19431908 }
....@@ -1959,8 +1924,8 @@
19591924 strcpy(pcm->name, "C-Media PCI IEC958");
19601925 cm->pcm_spdif = pcm;
19611926
1962
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1963
- snd_dma_pci_data(cm->pci), 64*1024, 128*1024);
1927
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1928
+ &cm->pci->dev, 64*1024, 128*1024);
19641929
19651930 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
19661931 snd_pcm_alt_chmaps, cm->max_channels, 0,
....@@ -2290,7 +2255,7 @@
22902255 }
22912256
22922257
2293
-static struct snd_kcontrol_new snd_cmipci_mixers[] = {
2258
+static const struct snd_kcontrol_new snd_cmipci_mixers[] = {
22942259 CMIPCI_SB_VOL_STEREO("Master Playback Volume", SB_DSP4_MASTER_DEV, 3, 31),
22952260 CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0),
22962261 CMIPCI_SB_VOL_STEREO("PCM Playback Volume", SB_DSP4_PCM_DEV, 3, 31),
....@@ -2601,7 +2566,7 @@
26012566 }
26022567
26032568 /* both for CM8338/8738 */
2604
-static struct snd_kcontrol_new snd_cmipci_mixer_switches[] = {
2569
+static const struct snd_kcontrol_new snd_cmipci_mixer_switches[] = {
26052570 DEFINE_MIXER_SWITCH("Four Channel Mode", fourch),
26062571 {
26072572 .name = "Line-In Mode",
....@@ -2613,11 +2578,11 @@
26132578 };
26142579
26152580 /* for non-multichannel chips */
2616
-static struct snd_kcontrol_new snd_cmipci_nomulti_switch =
2581
+static const struct snd_kcontrol_new snd_cmipci_nomulti_switch =
26172582 DEFINE_MIXER_SWITCH("Exchange DAC", exchange_dac);
26182583
26192584 /* only for CM8738 */
2620
-static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] = {
2585
+static const struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] = {
26212586 #if 0 /* controlled in pcm device */
26222587 DEFINE_MIXER_SWITCH("IEC958 In Record", spdif_in),
26232588 DEFINE_MIXER_SWITCH("IEC958 Out", spdif_out),
....@@ -2639,14 +2604,14 @@
26392604 };
26402605
26412606 /* only for model 033/037 */
2642
-static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] = {
2607
+static const struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] = {
26432608 DEFINE_MIXER_SWITCH("IEC958 Mix Analog", spdif_dac_out),
26442609 DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase),
26452610 DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel1),
26462611 };
26472612
26482613 /* only for model 039 or later */
2649
-static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] = {
2614
+static const struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] = {
26502615 DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel2),
26512616 DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase2),
26522617 {
....@@ -2659,14 +2624,14 @@
26592624 };
26602625
26612626 /* card control switches */
2662
-static struct snd_kcontrol_new snd_cmipci_modem_switch =
2627
+static const struct snd_kcontrol_new snd_cmipci_modem_switch =
26632628 DEFINE_CARD_SWITCH("Modem", modem);
26642629
26652630
26662631 static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
26672632 {
26682633 struct snd_card *card;
2669
- struct snd_kcontrol_new *sw;
2634
+ const struct snd_kcontrol_new *sw;
26702635 struct snd_kcontrol *kctl;
26712636 unsigned int idx;
26722637 int err;
....@@ -2792,10 +2757,7 @@
27922757
27932758 static void snd_cmipci_proc_init(struct cmipci *cm)
27942759 {
2795
- struct snd_info_entry *entry;
2796
-
2797
- if (! snd_card_proc_new(cm->card, "cmipci", &entry))
2798
- snd_info_set_text_ops(entry, cm, snd_cmipci_proc_read);
2760
+ snd_card_ro_proc_new(cm->card, "cmipci", cm, snd_cmipci_proc_read);
27992761 }
28002762
28012763 static const struct pci_device_id snd_cmipci_ids[] = {
....@@ -2863,7 +2825,7 @@
28632825 #ifdef SUPPORT_JOYSTICK
28642826 static int snd_cmipci_create_gameport(struct cmipci *cm, int dev)
28652827 {
2866
- static int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */
2828
+ static const int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */
28672829 struct gameport *gp;
28682830 struct resource *r = NULL;
28692831 int i, io_port = 0;
....@@ -3013,7 +2975,7 @@
30132975 {
30142976 struct cmipci *cm;
30152977 int err;
3016
- static struct snd_device_ops ops = {
2978
+ static const struct snd_device_ops ops = {
30172979 .dev_free = snd_cmipci_dev_free,
30182980 };
30192981 unsigned int val;
....@@ -3061,6 +3023,7 @@
30613023 return -EBUSY;
30623024 }
30633025 cm->irq = pci->irq;
3026
+ card->sync_irq = cm->irq;
30643027
30653028 pci_set_master(cm->pci);
30663029
....@@ -3168,7 +3131,8 @@
31683131 if (cm->chip_version >= 39) {
31693132 val = snd_cmipci_read_b(cm, CM_REG_MPU_PCI + 1);
31703133 if (val != 0x00 && val != 0xff) {
3171
- iomidi = cm->iobase + CM_REG_MPU_PCI;
3134
+ if (mpu_port[dev])
3135
+ iomidi = cm->iobase + CM_REG_MPU_PCI;
31723136 integrated_midi = 1;
31733137 }
31743138 }
....@@ -3324,15 +3288,15 @@
33243288 /*
33253289 * power management
33263290 */
3327
-static unsigned char saved_regs[] = {
3291
+static const unsigned char saved_regs[] = {
33283292 CM_REG_FUNCTRL1, CM_REG_CHFORMAT, CM_REG_LEGACY_CTRL, CM_REG_MISC_CTRL,
3329
- CM_REG_MIXER0, CM_REG_MIXER1, CM_REG_MIXER2, CM_REG_MIXER3, CM_REG_PLL,
3293
+ CM_REG_MIXER0, CM_REG_MIXER1, CM_REG_MIXER2, CM_REG_AUX_VOL, CM_REG_PLL,
33303294 CM_REG_CH0_FRAME1, CM_REG_CH0_FRAME2,
33313295 CM_REG_CH1_FRAME1, CM_REG_CH1_FRAME2, CM_REG_EXT_MISC,
33323296 CM_REG_INT_STATUS, CM_REG_INT_HLDCLR, CM_REG_FUNCTRL0,
33333297 };
33343298
3335
-static unsigned char saved_mixers[] = {
3299
+static const unsigned char saved_mixers[] = {
33363300 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
33373301 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
33383302 SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1,
....@@ -3351,10 +3315,6 @@
33513315
33523316 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
33533317
3354
- snd_pcm_suspend_all(cm->pcm);
3355
- snd_pcm_suspend_all(cm->pcm2);
3356
- snd_pcm_suspend_all(cm->pcm_spdif);
3357
-
33583318 /* save registers */
33593319 for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
33603320 cm->saved_regs[i] = snd_cmipci_read(cm, saved_regs[i]);