forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/sound/pci/ymfpci/ymfpci_main.c
....@@ -1,21 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
34 * Routines for control of YMF724/740/744/754 chips
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/delay.h>
....@@ -136,14 +122,14 @@
136122 }
137123 }
138124
139
-static u32 def_rate[8] = {
125
+static const u32 def_rate[8] = {
140126 100, 2000, 8000, 11025, 16000, 22050, 32000, 48000
141127 };
142128
143129 static u32 snd_ymfpci_calc_lpfK(u32 rate)
144130 {
145131 u32 i;
146
- static u32 val[8] = {
132
+ static const u32 val[8] = {
147133 0x00570000, 0x06AA0000, 0x18B20000, 0x20930000,
148134 0x2B9A0000, 0x35A10000, 0x3EAA0000, 0x40000000
149135 };
....@@ -159,7 +145,7 @@
159145 static u32 snd_ymfpci_calc_lpfQ(u32 rate)
160146 {
161147 u32 i;
162
- static u32 val[8] = {
148
+ static const u32 val[8] = {
163149 0x35280000, 0x34A70000, 0x32020000, 0x31770000,
164150 0x31390000, 0x31C90000, 0x33D00000, 0x40000000
165151 };
....@@ -414,7 +400,7 @@
414400 kctl = chip->pcm_mixer[substream->number].ctl;
415401 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
416402 }
417
- /* fall through */
403
+ fallthrough;
418404 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
419405 case SNDRV_PCM_TRIGGER_SUSPEND:
420406 chip->ctrl_playback[ypcm->voices[0]->number + 1] = 0;
....@@ -601,7 +587,7 @@
601587
602588 static int snd_ymfpci_ac3_init(struct snd_ymfpci *chip)
603589 {
604
- if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
590
+ if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
605591 4096, &chip->ac3_tmp_base) < 0)
606592 return -ENOMEM;
607593
....@@ -642,8 +628,6 @@
642628 struct snd_ymfpci_pcm *ypcm = runtime->private_data;
643629 int err;
644630
645
- if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
646
- return err;
647631 if ((err = snd_ymfpci_pcm_voice_alloc(ypcm, params_channels(hw_params))) < 0)
648632 return err;
649633 return 0;
....@@ -661,7 +645,6 @@
661645
662646 /* wait, until the PCI operations are not finished */
663647 snd_ymfpci_irq_wait(chip);
664
- snd_pcm_lib_free_pages(substream);
665648 if (ypcm->voices[1]) {
666649 snd_ymfpci_voice_free(chip, ypcm->voices[1]);
667650 ypcm->voices[1] = NULL;
....@@ -697,19 +680,13 @@
697680 return 0;
698681 }
699682
700
-static int snd_ymfpci_capture_hw_params(struct snd_pcm_substream *substream,
701
- struct snd_pcm_hw_params *hw_params)
702
-{
703
- return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
704
-}
705
-
706683 static int snd_ymfpci_capture_hw_free(struct snd_pcm_substream *substream)
707684 {
708685 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
709686
710687 /* wait, until the PCI operations are not finished */
711688 snd_ymfpci_irq_wait(chip);
712
- return snd_pcm_lib_free_pages(substream);
689
+ return 0;
713690 }
714691
715692 static int snd_ymfpci_capture_prepare(struct snd_pcm_substream *substream)
....@@ -1126,7 +1103,6 @@
11261103 static const struct snd_pcm_ops snd_ymfpci_playback_ops = {
11271104 .open = snd_ymfpci_playback_open,
11281105 .close = snd_ymfpci_playback_close,
1129
- .ioctl = snd_pcm_lib_ioctl,
11301106 .hw_params = snd_ymfpci_playback_hw_params,
11311107 .hw_free = snd_ymfpci_playback_hw_free,
11321108 .prepare = snd_ymfpci_playback_prepare,
....@@ -1137,8 +1113,6 @@
11371113 static const struct snd_pcm_ops snd_ymfpci_capture_rec_ops = {
11381114 .open = snd_ymfpci_capture_rec_open,
11391115 .close = snd_ymfpci_capture_close,
1140
- .ioctl = snd_pcm_lib_ioctl,
1141
- .hw_params = snd_ymfpci_capture_hw_params,
11421116 .hw_free = snd_ymfpci_capture_hw_free,
11431117 .prepare = snd_ymfpci_capture_prepare,
11441118 .trigger = snd_ymfpci_capture_trigger,
....@@ -1162,8 +1136,8 @@
11621136 strcpy(pcm->name, "YMFPCI");
11631137 chip->pcm = pcm;
11641138
1165
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1166
- snd_dma_pci_data(chip->pci), 64*1024, 256*1024);
1139
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1140
+ &chip->pci->dev, 64*1024, 256*1024);
11671141
11681142 return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
11691143 snd_pcm_std_chmaps, 2, 0, NULL);
....@@ -1172,8 +1146,6 @@
11721146 static const struct snd_pcm_ops snd_ymfpci_capture_ac97_ops = {
11731147 .open = snd_ymfpci_capture_ac97_open,
11741148 .close = snd_ymfpci_capture_close,
1175
- .ioctl = snd_pcm_lib_ioctl,
1176
- .hw_params = snd_ymfpci_capture_hw_params,
11771149 .hw_free = snd_ymfpci_capture_hw_free,
11781150 .prepare = snd_ymfpci_capture_prepare,
11791151 .trigger = snd_ymfpci_capture_trigger,
....@@ -1197,8 +1169,8 @@
11971169 chip->device_id == PCI_DEVICE_ID_YAMAHA_754 ? "Direct Recording" : "AC'97");
11981170 chip->pcm2 = pcm;
11991171
1200
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1201
- snd_dma_pci_data(chip->pci), 64*1024, 256*1024);
1172
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1173
+ &chip->pci->dev, 64*1024, 256*1024);
12021174
12031175 return 0;
12041176 }
....@@ -1206,7 +1178,6 @@
12061178 static const struct snd_pcm_ops snd_ymfpci_playback_spdif_ops = {
12071179 .open = snd_ymfpci_playback_spdif_open,
12081180 .close = snd_ymfpci_playback_spdif_close,
1209
- .ioctl = snd_pcm_lib_ioctl,
12101181 .hw_params = snd_ymfpci_playback_hw_params,
12111182 .hw_free = snd_ymfpci_playback_hw_free,
12121183 .prepare = snd_ymfpci_playback_prepare,
....@@ -1230,8 +1201,8 @@
12301201 strcpy(pcm->name, "YMFPCI - IEC958");
12311202 chip->pcm_spdif = pcm;
12321203
1233
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1234
- snd_dma_pci_data(chip->pci), 64*1024, 256*1024);
1204
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1205
+ &chip->pci->dev, 64*1024, 256*1024);
12351206
12361207 return 0;
12371208 }
....@@ -1239,7 +1210,6 @@
12391210 static const struct snd_pcm_ops snd_ymfpci_playback_4ch_ops = {
12401211 .open = snd_ymfpci_playback_4ch_open,
12411212 .close = snd_ymfpci_playback_4ch_close,
1242
- .ioctl = snd_pcm_lib_ioctl,
12431213 .hw_params = snd_ymfpci_playback_hw_params,
12441214 .hw_free = snd_ymfpci_playback_hw_free,
12451215 .prepare = snd_ymfpci_playback_prepare,
....@@ -1271,8 +1241,8 @@
12711241 strcpy(pcm->name, "YMFPCI - Rear PCM");
12721242 chip->pcm_4ch = pcm;
12731243
1274
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1275
- snd_dma_pci_data(chip->pci), 64*1024, 256*1024);
1244
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1245
+ &chip->pci->dev, 64*1024, 256*1024);
12761246
12771247 return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
12781248 surround_map, 2, 0, NULL);
....@@ -1618,7 +1588,7 @@
16181588 .put = snd_ymfpci_put_dup4ch,
16191589 };
16201590
1621
-static struct snd_kcontrol_new snd_ymfpci_controls[] = {
1591
+static const struct snd_kcontrol_new snd_ymfpci_controls[] = {
16221592 {
16231593 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16241594 .name = "Wave Playback Volume",
....@@ -1810,7 +1780,7 @@
18101780 struct snd_pcm_substream *substream;
18111781 unsigned int idx;
18121782 int err;
1813
- static struct snd_ac97_bus_ops ops = {
1783
+ static const struct snd_ac97_bus_ops ops = {
18141784 .write = snd_ymfpci_codec_write,
18151785 .read = snd_ymfpci_codec_read,
18161786 };
....@@ -1938,7 +1908,7 @@
19381908 return 0;
19391909 }
19401910
1941
-static struct snd_timer_hardware snd_ymfpci_timer_hw = {
1911
+static const struct snd_timer_hardware snd_ymfpci_timer_hw = {
19421912 .flags = SNDRV_TIMER_HW_AUTO,
19431913 .resolution = 10417, /* 1 / 96 kHz = 10.41666...us */
19441914 .ticks = 0x10000,
....@@ -1985,11 +1955,7 @@
19851955
19861956 static int snd_ymfpci_proc_init(struct snd_card *card, struct snd_ymfpci *chip)
19871957 {
1988
- struct snd_info_entry *entry;
1989
-
1990
- if (! snd_card_proc_new(card, "ymfpci", &entry))
1991
- snd_info_set_text_ops(entry, chip, snd_ymfpci_proc_read);
1992
- return 0;
1958
+ return snd_card_ro_proc_new(card, "ymfpci", chip, snd_ymfpci_proc_read);
19931959 }
19941960
19951961 /*
....@@ -2126,7 +2092,7 @@
21262092 chip->work_size;
21272093 /* work_ptr must be aligned to 256 bytes, but it's already
21282094 covered with the kernel page allocation mechanism */
2129
- if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
2095
+ if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
21302096 size, &chip->work_ptr) < 0)
21312097 return -ENOMEM;
21322098 ptr = chip->work_ptr.area;
....@@ -2268,7 +2234,7 @@
22682234 }
22692235
22702236 #ifdef CONFIG_PM_SLEEP
2271
-static int saved_regs_index[] = {
2237
+static const int saved_regs_index[] = {
22722238 /* spdif */
22732239 YDSXGR_SPDIFOUTCTRL,
22742240 YDSXGR_SPDIFOUTSTATUS,
....@@ -2304,10 +2270,6 @@
23042270 unsigned int i;
23052271
23062272 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
2307
- snd_pcm_suspend_all(chip->pcm);
2308
- snd_pcm_suspend_all(chip->pcm2);
2309
- snd_pcm_suspend_all(chip->pcm_spdif);
2310
- snd_pcm_suspend_all(chip->pcm_4ch);
23112273 snd_ac97_suspend(chip->ac97);
23122274 for (i = 0; i < YDSXGR_NUM_SAVED_REGS; i++)
23132275 chip->saved_regs[i] = snd_ymfpci_readl(chip, saved_regs_index[i]);
....@@ -2365,7 +2327,7 @@
23652327 {
23662328 struct snd_ymfpci *chip;
23672329 int err;
2368
- static struct snd_device_ops ops = {
2330
+ static const struct snd_device_ops ops = {
23692331 .dev_free = snd_ymfpci_dev_free,
23702332 };
23712333
....@@ -2391,7 +2353,7 @@
23912353 chip->device_id = pci->device;
23922354 chip->rev = pci->revision;
23932355 chip->reg_area_phys = pci_resource_start(pci, 0);
2394
- chip->reg_area_virt = ioremap_nocache(chip->reg_area_phys, 0x8000);
2356
+ chip->reg_area_virt = ioremap(chip->reg_area_phys, 0x8000);
23952357 pci_set_master(pci);
23962358 chip->src441_used = -1;
23972359
....@@ -2409,6 +2371,7 @@
24092371 goto free_chip;
24102372 }
24112373 chip->irq = pci->irq;
2374
+ card->sync_irq = chip->irq;
24122375
24132376 snd_ymfpci_aclink_reset(pci);
24142377 if (snd_ymfpci_codec_ready(chip, 0) < 0) {