forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/pci/asihpi/asihpi.c
....@@ -1,20 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Asihpi soundcard
34 * Copyright (c) by AudioScience Inc <support@audioscience.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of version 2 of the GNU General Public License as
7
- * published by the Free Software Foundation;
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
- *
185 *
196 * The following is not a condition of use, merely a request:
207 * If you modify this program, particularly if you fix errors, AudioScience Inc
....@@ -130,7 +117,6 @@
130117 * snd_card_asihpi_timer_function().
131118 */
132119 struct snd_card_asihpi_pcm *llmode_streampriv;
133
- struct tasklet_struct t;
134120 void (*pcm_start)(struct snd_pcm_substream *substream);
135121 void (*pcm_stop)(struct snd_pcm_substream *substream);
136122
....@@ -271,15 +257,6 @@
271257 return hpi_instream_group_reset(h_stream);
272258 }
273259
274
-static inline u16 hpi_stream_group_get_map(
275
- u32 h_stream, u32 *mo, u32 *mi)
276
-{
277
- if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
278
- return hpi_outstream_group_get_map(h_stream, mo, mi);
279
- else
280
- return hpi_instream_group_get_map(h_stream, mo, mi);
281
-}
282
-
283260 static u16 handle_error(u16 err, int line, char *filename)
284261 {
285262 if (err)
....@@ -313,7 +290,7 @@
313290
314291 #define INVALID_FORMAT (__force snd_pcm_format_t)(-1)
315292
316
-static snd_pcm_format_t hpi_to_alsa_formats[] = {
293
+static const snd_pcm_format_t hpi_to_alsa_formats[] = {
317294 INVALID_FORMAT, /* INVALID */
318295 SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
319296 SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */
....@@ -462,9 +439,6 @@
462439 unsigned int bytes_per_sec;
463440
464441 print_hwparams(substream, params);
465
- err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
466
- if (err < 0)
467
- return err;
468442 err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format);
469443 if (err)
470444 return err;
....@@ -522,7 +496,6 @@
522496 if (dpcm->hpi_buffer_attached)
523497 hpi_stream_host_buffer_detach(dpcm->h_stream);
524498
525
- snd_pcm_lib_free_pages(substream);
526499 return 0;
527500 }
528501
....@@ -564,9 +537,7 @@
564537 card = snd_pcm_substream_chip(substream);
565538
566539 WARN_ON(in_interrupt());
567
- tasklet_disable(&card->t);
568540 card->llmode_streampriv = dpcm;
569
- tasklet_enable(&card->t);
570541
571542 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
572543 HPI_ADAPTER_PROPERTY_IRQ_RATE,
....@@ -582,13 +553,7 @@
582553 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
583554 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
584555
585
- if (in_interrupt())
586
- card->llmode_streampriv = NULL;
587
- else {
588
- tasklet_disable(&card->t);
589
- card->llmode_streampriv = NULL;
590
- tasklet_enable(&card->t);
591
- }
556
+ card->llmode_streampriv = NULL;
592557 }
593558
594559 static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
....@@ -938,9 +903,8 @@
938903 add_timer(&dpcm->timer);
939904 }
940905
941
-static void snd_card_asihpi_int_task(unsigned long data)
906
+static void snd_card_asihpi_isr(struct hpi_adapter *a)
942907 {
943
- struct hpi_adapter *a = (struct hpi_adapter *)data;
944908 struct snd_card_asihpi *asihpi;
945909
946910 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
....@@ -950,25 +914,7 @@
950914 &asihpi->llmode_streampriv->timer);
951915 }
952916
953
-static void snd_card_asihpi_isr(struct hpi_adapter *a)
954
-{
955
- struct snd_card_asihpi *asihpi;
956
-
957
- WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
958
- asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
959
- tasklet_schedule(&asihpi->t);
960
-}
961
-
962917 /***************************** PLAYBACK OPS ****************/
963
-static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,
964
- unsigned int cmd, void *arg)
965
-{
966
- char name[16];
967
- snd_pcm_debug_name(substream, name, sizeof(name));
968
- snd_printddd(KERN_INFO "%s ioctl %d\n", name, cmd);
969
- return snd_pcm_lib_ioctl(substream, cmd, arg);
970
-}
971
-
972918 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
973919 substream)
974920 {
....@@ -1135,7 +1081,6 @@
11351081 static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
11361082 .open = snd_card_asihpi_playback_open,
11371083 .close = snd_card_asihpi_playback_close,
1138
- .ioctl = snd_card_asihpi_playback_ioctl,
11391084 .hw_params = snd_card_asihpi_pcm_hw_params,
11401085 .hw_free = snd_card_asihpi_hw_free,
11411086 .prepare = snd_card_asihpi_playback_prepare,
....@@ -1160,12 +1105,6 @@
11601105 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
11611106 }
11621107
1163
-static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream,
1164
- unsigned int cmd, void *arg)
1165
-{
1166
- return snd_pcm_lib_ioctl(substream, cmd, arg);
1167
-}
1168
-
11691108 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
11701109 {
11711110 struct snd_pcm_runtime *runtime = substream->runtime;
....@@ -1183,7 +1122,7 @@
11831122 static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi,
11841123 u32 h_stream)
11851124 {
1186
- struct hpi_format hpi_format;
1125
+ struct hpi_format hpi_format;
11871126 u16 format;
11881127 u16 err;
11891128 u32 h_control;
....@@ -1301,7 +1240,6 @@
13011240 static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
13021241 .open = snd_card_asihpi_capture_open,
13031242 .close = snd_card_asihpi_capture_close,
1304
- .ioctl = snd_card_asihpi_capture_ioctl,
13051243 .hw_params = snd_card_asihpi_pcm_hw_params,
13061244 .hw_free = snd_card_asihpi_hw_free,
13071245 .prepare = snd_card_asihpi_capture_prepare,
....@@ -1337,9 +1275,9 @@
13371275
13381276 /*? do we want to emulate MMAP for non-BBM cards?
13391277 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1340
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1341
- snd_dma_pci_data(asihpi->pci),
1342
- 64*1024, BUFFER_BYTES_MAX);
1278
+ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1279
+ &asihpi->pci->dev,
1280
+ 64*1024, BUFFER_BYTES_MAX);
13431281
13441282 return 0;
13451283 }
....@@ -1532,7 +1470,6 @@
15321470 static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
15331471 struct snd_ctl_elem_value *ucontrol)
15341472 {
1535
- int change;
15361473 u32 h_control = kcontrol->private_value;
15371474 short an_gain_mB[HPI_MAX_CHANNELS];
15381475
....@@ -1543,9 +1480,8 @@
15431480 /* change = asihpi->mixer_volume[addr][0] != left ||
15441481 asihpi->mixer_volume[addr][1] != right;
15451482 */
1546
- change = 1;
15471483 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
1548
- return change;
1484
+ return 1;
15491485 }
15501486
15511487 static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
....@@ -1568,13 +1504,12 @@
15681504 struct snd_ctl_elem_value *ucontrol)
15691505 {
15701506 u32 h_control = kcontrol->private_value;
1571
- int change = 1;
15721507 /* HPI currently only supports all or none muting of multichannel volume
15731508 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
15741509 */
15751510 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
15761511 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1577
- return change;
1512
+ return 1;
15781513 }
15791514
15801515 static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
....@@ -1941,7 +1876,7 @@
19411876 */
19421877 u16 band, idx;
19431878 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1944
- u32 num_bands = 0;
1879
+ __always_unused u32 num_bands;
19451880
19461881 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
19471882 HPI_TUNER_BAND_LAST);
....@@ -1968,7 +1903,7 @@
19681903 unsigned int idx;
19691904 u16 band;
19701905 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1971
- u32 num_bands = 0;
1906
+ __always_unused u32 num_bands;
19721907
19731908 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
19741909 HPI_TUNER_BAND_LAST);
....@@ -2110,7 +2045,7 @@
21102045 }
21112046
21122047 /* linear values for 10dB steps */
2113
-static int log2lin[] = {
2048
+static const int log2lin[] = {
21142049 0x7FFFFFFF, /* 0dB */
21152050 679093956,
21162051 214748365,
....@@ -2198,7 +2133,6 @@
21982133 static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
21992134 struct snd_ctl_elem_info *uinfo)
22002135 {
2201
- int err;
22022136 u16 src_node_type, src_node_index;
22032137 u32 h_control = kcontrol->private_value;
22042138
....@@ -2211,10 +2145,9 @@
22112145 uinfo->value.enumerated.item =
22122146 uinfo->value.enumerated.items - 1;
22132147
2214
- err =
2215
- hpi_multiplexer_query_source(h_control,
2216
- uinfo->value.enumerated.item,
2217
- &src_node_type, &src_node_index);
2148
+ hpi_multiplexer_query_source(h_control,
2149
+ uinfo->value.enumerated.item,
2150
+ &src_node_type, &src_node_index);
22182151
22192152 sprintf(uinfo->value.enumerated.name, "%s %d",
22202153 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
....@@ -2782,10 +2715,8 @@
27822715
27832716 static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
27842717 {
2785
- struct snd_info_entry *entry;
2786
-
2787
- if (!snd_card_proc_new(asihpi->card, "info", &entry))
2788
- snd_info_set_text_ops(entry, asihpi, snd_asihpi_proc_read);
2718
+ snd_card_ro_proc_new(asihpi->card, "info", asihpi,
2719
+ snd_asihpi_proc_read);
27892720 }
27902721
27912722 /*------------------------------------------------------------
....@@ -2912,8 +2843,6 @@
29122843 if (hpi->interrupt_mode) {
29132844 asihpi->pcm_start = snd_card_asihpi_pcm_int_start;
29142845 asihpi->pcm_stop = snd_card_asihpi_pcm_int_stop;
2915
- tasklet_init(&asihpi->t, snd_card_asihpi_int_task,
2916
- (unsigned long)hpi);
29172846 hpi->interrupt_callback = snd_card_asihpi_isr;
29182847 } else {
29192848 asihpi->pcm_start = snd_card_asihpi_pcm_timer_start;
....@@ -3002,14 +2931,12 @@
30022931 static void snd_asihpi_remove(struct pci_dev *pci_dev)
30032932 {
30042933 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
3005
- struct snd_card_asihpi *asihpi = hpi->snd_card->private_data;
30062934
30072935 /* Stop interrupts */
30082936 if (hpi->interrupt_mode) {
30092937 hpi->interrupt_callback = NULL;
30102938 hpi_handle_error(hpi_adapter_set_property(hpi->adapter->index,
30112939 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
3012
- tasklet_kill(&asihpi->t);
30132940 }
30142941
30152942 snd_card_free(hpi->snd_card);