forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/sound/pci/ca0106/ca0106_main.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
34 * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
....@@ -119,21 +120,6 @@
119120 *
120121 * This code was initially based on code from ALSA's emu10k1x.c which is:
121122 * Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
122
- *
123
- * This program is free software; you can redistribute it and/or modify
124
- * it under the terms of the GNU General Public License as published by
125
- * the Free Software Foundation; either version 2 of the License, or
126
- * (at your option) any later version.
127
- *
128
- * This program is distributed in the hope that it will be useful,
129
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
130
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131
- * GNU General Public License for more details.
132
- *
133
- * You should have received a copy of the GNU General Public License
134
- * along with this program; if not, write to the Free Software
135
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
136
- *
137123 */
138124 #include <linux/delay.h>
139125 #include <linux/init.h>
....@@ -170,7 +156,7 @@
170156
171157 #include "ca0106.h"
172158
173
-static struct snd_ca0106_details ca0106_chip_details[] = {
159
+static const struct snd_ca0106_details ca0106_chip_details[] = {
174160 /* Sound Blaster X-Fi Extreme Audio. This does not have an AC97. 53SB079000000 */
175161 /* It is really just a normal SB Live 24bit. */
176162 /* Tested:
....@@ -517,7 +503,7 @@
517503 }
518504
519505 static int snd_ca0106_channel_dac(struct snd_ca0106 *chip,
520
- struct snd_ca0106_details *details,
506
+ const struct snd_ca0106_details *details,
521507 int channel_id)
522508 {
523509 switch (channel_id) {
....@@ -720,34 +706,6 @@
720706 static int snd_ca0106_pcm_open_3_capture(struct snd_pcm_substream *substream)
721707 {
722708 return snd_ca0106_pcm_open_capture_channel(substream, 3);
723
-}
724
-
725
-/* hw_params callback */
726
-static int snd_ca0106_pcm_hw_params_playback(struct snd_pcm_substream *substream,
727
- struct snd_pcm_hw_params *hw_params)
728
-{
729
- return snd_pcm_lib_malloc_pages(substream,
730
- params_buffer_bytes(hw_params));
731
-}
732
-
733
-/* hw_free callback */
734
-static int snd_ca0106_pcm_hw_free_playback(struct snd_pcm_substream *substream)
735
-{
736
- return snd_pcm_lib_free_pages(substream);
737
-}
738
-
739
-/* hw_params callback */
740
-static int snd_ca0106_pcm_hw_params_capture(struct snd_pcm_substream *substream,
741
- struct snd_pcm_hw_params *hw_params)
742
-{
743
- return snd_pcm_lib_malloc_pages(substream,
744
- params_buffer_bytes(hw_params));
745
-}
746
-
747
-/* hw_free callback */
748
-static int snd_ca0106_pcm_hw_free_capture(struct snd_pcm_substream *substream)
749
-{
750
- return snd_pcm_lib_free_pages(substream);
751709 }
752710
753711 /* prepare playback callback */
....@@ -1111,9 +1069,6 @@
11111069 static const struct snd_pcm_ops snd_ca0106_playback_front_ops = {
11121070 .open = snd_ca0106_pcm_open_playback_front,
11131071 .close = snd_ca0106_pcm_close_playback,
1114
- .ioctl = snd_pcm_lib_ioctl,
1115
- .hw_params = snd_ca0106_pcm_hw_params_playback,
1116
- .hw_free = snd_ca0106_pcm_hw_free_playback,
11171072 .prepare = snd_ca0106_pcm_prepare_playback,
11181073 .trigger = snd_ca0106_pcm_trigger_playback,
11191074 .pointer = snd_ca0106_pcm_pointer_playback,
....@@ -1122,9 +1077,6 @@
11221077 static const struct snd_pcm_ops snd_ca0106_capture_0_ops = {
11231078 .open = snd_ca0106_pcm_open_0_capture,
11241079 .close = snd_ca0106_pcm_close_capture,
1125
- .ioctl = snd_pcm_lib_ioctl,
1126
- .hw_params = snd_ca0106_pcm_hw_params_capture,
1127
- .hw_free = snd_ca0106_pcm_hw_free_capture,
11281080 .prepare = snd_ca0106_pcm_prepare_capture,
11291081 .trigger = snd_ca0106_pcm_trigger_capture,
11301082 .pointer = snd_ca0106_pcm_pointer_capture,
....@@ -1133,9 +1085,6 @@
11331085 static const struct snd_pcm_ops snd_ca0106_capture_1_ops = {
11341086 .open = snd_ca0106_pcm_open_1_capture,
11351087 .close = snd_ca0106_pcm_close_capture,
1136
- .ioctl = snd_pcm_lib_ioctl,
1137
- .hw_params = snd_ca0106_pcm_hw_params_capture,
1138
- .hw_free = snd_ca0106_pcm_hw_free_capture,
11391088 .prepare = snd_ca0106_pcm_prepare_capture,
11401089 .trigger = snd_ca0106_pcm_trigger_capture,
11411090 .pointer = snd_ca0106_pcm_pointer_capture,
....@@ -1144,9 +1093,6 @@
11441093 static const struct snd_pcm_ops snd_ca0106_capture_2_ops = {
11451094 .open = snd_ca0106_pcm_open_2_capture,
11461095 .close = snd_ca0106_pcm_close_capture,
1147
- .ioctl = snd_pcm_lib_ioctl,
1148
- .hw_params = snd_ca0106_pcm_hw_params_capture,
1149
- .hw_free = snd_ca0106_pcm_hw_free_capture,
11501096 .prepare = snd_ca0106_pcm_prepare_capture,
11511097 .trigger = snd_ca0106_pcm_trigger_capture,
11521098 .pointer = snd_ca0106_pcm_pointer_capture,
....@@ -1155,9 +1101,6 @@
11551101 static const struct snd_pcm_ops snd_ca0106_capture_3_ops = {
11561102 .open = snd_ca0106_pcm_open_3_capture,
11571103 .close = snd_ca0106_pcm_close_capture,
1158
- .ioctl = snd_pcm_lib_ioctl,
1159
- .hw_params = snd_ca0106_pcm_hw_params_capture,
1160
- .hw_free = snd_ca0106_pcm_hw_free_capture,
11611104 .prepare = snd_ca0106_pcm_prepare_capture,
11621105 .trigger = snd_ca0106_pcm_trigger_capture,
11631106 .pointer = snd_ca0106_pcm_pointer_capture,
....@@ -1166,9 +1109,6 @@
11661109 static const struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
11671110 .open = snd_ca0106_pcm_open_playback_center_lfe,
11681111 .close = snd_ca0106_pcm_close_playback,
1169
- .ioctl = snd_pcm_lib_ioctl,
1170
- .hw_params = snd_ca0106_pcm_hw_params_playback,
1171
- .hw_free = snd_ca0106_pcm_hw_free_playback,
11721112 .prepare = snd_ca0106_pcm_prepare_playback,
11731113 .trigger = snd_ca0106_pcm_trigger_playback,
11741114 .pointer = snd_ca0106_pcm_pointer_playback,
....@@ -1177,9 +1117,6 @@
11771117 static const struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
11781118 .open = snd_ca0106_pcm_open_playback_unknown,
11791119 .close = snd_ca0106_pcm_close_playback,
1180
- .ioctl = snd_pcm_lib_ioctl,
1181
- .hw_params = snd_ca0106_pcm_hw_params_playback,
1182
- .hw_free = snd_ca0106_pcm_hw_free_playback,
11831120 .prepare = snd_ca0106_pcm_prepare_playback,
11841121 .trigger = snd_ca0106_pcm_trigger_playback,
11851122 .pointer = snd_ca0106_pcm_pointer_playback,
....@@ -1188,9 +1125,6 @@
11881125 static const struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
11891126 .open = snd_ca0106_pcm_open_playback_rear,
11901127 .close = snd_ca0106_pcm_close_playback,
1191
- .ioctl = snd_pcm_lib_ioctl,
1192
- .hw_params = snd_ca0106_pcm_hw_params_playback,
1193
- .hw_free = snd_ca0106_pcm_hw_free_playback,
11941128 .prepare = snd_ca0106_pcm_prepare_playback,
11951129 .trigger = snd_ca0106_pcm_trigger_playback,
11961130 .pointer = snd_ca0106_pcm_pointer_playback,
....@@ -1228,7 +1162,7 @@
12281162 struct snd_ac97_bus *pbus;
12291163 struct snd_ac97_template ac97;
12301164 int err;
1231
- static struct snd_ac97_bus_ops ops = {
1165
+ static const struct snd_ac97_bus_ops ops = {
12321166 .write = snd_ca0106_ac97_write,
12331167 .read = snd_ca0106_ac97_read,
12341168 };
....@@ -1403,21 +1337,17 @@
14031337 for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
14041338 substream;
14051339 substream = substream->next) {
1406
- if ((err = snd_pcm_lib_preallocate_pages(substream,
1407
- SNDRV_DMA_TYPE_DEV,
1408
- snd_dma_pci_data(emu->pci),
1409
- 64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
1410
- return err;
1340
+ snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
1341
+ &emu->pci->dev,
1342
+ 64*1024, 64*1024);
14111343 }
14121344
14131345 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
14141346 substream;
14151347 substream = substream->next) {
1416
- if ((err = snd_pcm_lib_preallocate_pages(substream,
1417
- SNDRV_DMA_TYPE_DEV,
1418
- snd_dma_pci_data(emu->pci),
1419
- 64*1024, 64*1024)) < 0)
1420
- return err;
1348
+ snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
1349
+ &emu->pci->dev,
1350
+ 64*1024, 64*1024);
14211351 }
14221352
14231353 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, map, 2,
....@@ -1431,7 +1361,7 @@
14311361 }
14321362
14331363 #define SPI_REG(reg, value) (((reg) << SPI_REG_SHIFT) | (value))
1434
-static unsigned int spi_dac_init[] = {
1364
+static const unsigned int spi_dac_init[] = {
14351365 SPI_REG(SPI_LDA1_REG, SPI_DA_BIT_0dB), /* 0dB dig. attenuation */
14361366 SPI_REG(SPI_RDA1_REG, SPI_DA_BIT_0dB),
14371367 SPI_REG(SPI_PL_REG, SPI_PL_BIT_L_L | SPI_PL_BIT_R_R | SPI_IZD_BIT),
....@@ -1449,7 +1379,7 @@
14491379 SPI_REG(SPI_DACD4_REG, SPI_DACD4_BIT),
14501380 };
14511381
1452
-static unsigned int i2c_adc_init[][2] = {
1382
+static const unsigned int i2c_adc_init[][2] = {
14531383 { 0x17, 0x00 }, /* Reset */
14541384 { 0x07, 0x00 }, /* Timeout */
14551385 { 0x0b, 0x22 }, /* Interface control */
....@@ -1664,9 +1594,9 @@
16641594 struct snd_ca0106 **rchip)
16651595 {
16661596 struct snd_ca0106 *chip;
1667
- struct snd_ca0106_details *c;
1597
+ const struct snd_ca0106_details *c;
16681598 int err;
1669
- static struct snd_device_ops ops = {
1599
+ static const struct snd_device_ops ops = {
16701600 .dev_free = snd_ca0106_dev_free,
16711601 };
16721602
....@@ -1709,9 +1639,10 @@
17091639 return -EBUSY;
17101640 }
17111641 chip->irq = pci->irq;
1642
+ card->sync_irq = chip->irq;
17121643
17131644 /* This stores the periods table. */
1714
- if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1645
+ if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
17151646 1024, &chip->buffer) < 0) {
17161647 snd_ca0106_free(chip);
17171648 return -ENOMEM;
....@@ -1911,11 +1842,8 @@
19111842 {
19121843 struct snd_card *card = dev_get_drvdata(dev);
19131844 struct snd_ca0106 *chip = card->private_data;
1914
- int i;
19151845
19161846 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1917
- for (i = 0; i < 4; i++)
1918
- snd_pcm_suspend_all(chip->pcm[i]);
19191847 if (chip->details->ac97)
19201848 snd_ac97_suspend(chip->ac97);
19211849 snd_ca0106_mixer_suspend(chip);