forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/sound/pci/rme9652/hdsp.c
....@@ -1,24 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ALSA driver for RME Hammerfall DSP audio interface(s)
34 *
45 * Copyright (c) 2002 Paul Davis
56 * Marcus Andersson
67 * Thomas Charbonnel
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
- *
228 */
239
2410 #include <linux/init.h>
....@@ -450,7 +436,7 @@
450436 struct snd_rawmidi *rmidi;
451437 struct snd_rawmidi_substream *input;
452438 struct snd_rawmidi_substream *output;
453
- char istimer; /* timer in use */
439
+ signed char istimer; /* timer in use */
454440 struct timer_list timer;
455441 spinlock_t lock;
456442 int pending;
....@@ -461,8 +447,8 @@
461447 struct snd_pcm_substream *capture_substream;
462448 struct snd_pcm_substream *playback_substream;
463449 struct hdsp_midi midi[2];
464
- struct tasklet_struct midi_tasklet;
465
- int use_midi_tasklet;
450
+ struct work_struct midi_work;
451
+ int use_midi_work;
466452 int precise_ptr;
467453 u32 control_register; /* cached value */
468454 u32 control2_register; /* cached value */
....@@ -493,7 +479,7 @@
493479 pid_t playback_pid;
494480 int running;
495481 int system_sample_rate;
496
- char *channel_map;
482
+ const signed char *channel_map;
497483 int dev;
498484 int irq;
499485 unsigned long port;
....@@ -515,12 +501,12 @@
515501 where the data for that channel can be read/written from/to.
516502 */
517503
518
-static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
504
+static const signed char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
519505 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
520506 18, 19, 20, 21, 22, 23, 24, 25
521507 };
522508
523
-static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
509
+static const char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
524510 /* Analog */
525511 0, 1, 2, 3, 4, 5, 6, 7,
526512 /* ADAT 2 */
....@@ -530,7 +516,7 @@
530516 -1, -1, -1, -1, -1, -1, -1, -1
531517 };
532518
533
-static char channel_map_ds[HDSP_MAX_CHANNELS] = {
519
+static const signed char channel_map_ds[HDSP_MAX_CHANNELS] = {
534520 /* ADAT channels are remapped */
535521 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
536522 /* channels 12 and 13 are S/PDIF */
....@@ -539,7 +525,7 @@
539525 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
540526 };
541527
542
-static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
528
+static const signed char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
543529 /* ADAT channels */
544530 0, 1, 2, 3, 4, 5, 6, 7,
545531 /* SPDIF */
....@@ -553,7 +539,7 @@
553539 -1, -1
554540 };
555541
556
-static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
542
+static const signed char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
557543 /* ADAT */
558544 1, 3, 5, 7,
559545 /* SPDIF */
....@@ -567,7 +553,7 @@
567553 -1, -1, -1, -1, -1, -1
568554 };
569555
570
-static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
556
+static const signed char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
571557 /* ADAT is disabled in this mode */
572558 /* SPDIF */
573559 8, 9,
....@@ -583,12 +569,7 @@
583569
584570 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
585571 {
586
- dmab->dev.type = SNDRV_DMA_TYPE_DEV;
587
- dmab->dev.dev = snd_dma_pci_data(pci);
588
- if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
589
- size, dmab) < 0)
590
- return -ENOMEM;
591
- return 0;
572
+ return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, size, dmab);
592573 }
593574
594575 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
....@@ -1404,7 +1385,6 @@
14041385 }
14051386 } else {
14061387 hdsp->control_register &= ~ie;
1407
- tasklet_kill(&hdsp->midi_tasklet);
14081388 }
14091389
14101390 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
....@@ -2561,37 +2541,37 @@
25612541 return change;
25622542 }
25632543
2564
-#define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2544
+#define HDSP_USE_MIDI_WORK(xname, xindex) \
25652545 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
25662546 .name = xname, \
25672547 .index = xindex, \
2568
- .info = snd_hdsp_info_use_midi_tasklet, \
2569
- .get = snd_hdsp_get_use_midi_tasklet, \
2570
- .put = snd_hdsp_put_use_midi_tasklet \
2548
+ .info = snd_hdsp_info_use_midi_work, \
2549
+ .get = snd_hdsp_get_use_midi_work, \
2550
+ .put = snd_hdsp_put_use_midi_work \
25712551 }
25722552
2573
-static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
2553
+static int hdsp_set_use_midi_work(struct hdsp *hdsp, int use_work)
25742554 {
2575
- if (use_tasklet)
2576
- hdsp->use_midi_tasklet = 1;
2555
+ if (use_work)
2556
+ hdsp->use_midi_work = 1;
25772557 else
2578
- hdsp->use_midi_tasklet = 0;
2558
+ hdsp->use_midi_work = 0;
25792559 return 0;
25802560 }
25812561
2582
-#define snd_hdsp_info_use_midi_tasklet snd_ctl_boolean_mono_info
2562
+#define snd_hdsp_info_use_midi_work snd_ctl_boolean_mono_info
25832563
2584
-static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2564
+static int snd_hdsp_get_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
25852565 {
25862566 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
25872567
25882568 spin_lock_irq(&hdsp->lock);
2589
- ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2569
+ ucontrol->value.integer.value[0] = hdsp->use_midi_work;
25902570 spin_unlock_irq(&hdsp->lock);
25912571 return 0;
25922572 }
25932573
2594
-static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2574
+static int snd_hdsp_put_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
25952575 {
25962576 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
25972577 int change;
....@@ -2601,8 +2581,8 @@
26012581 return -EBUSY;
26022582 val = ucontrol->value.integer.value[0] & 1;
26032583 spin_lock_irq(&hdsp->lock);
2604
- change = (int)val != hdsp->use_midi_tasklet;
2605
- hdsp_set_use_midi_tasklet(hdsp, val);
2584
+ change = (int)val != hdsp->use_midi_work;
2585
+ hdsp_set_use_midi_work(hdsp, val);
26062586 spin_unlock_irq(&hdsp->lock);
26072587 return change;
26082588 }
....@@ -2898,7 +2878,7 @@
28982878 return change;
28992879 }
29002880
2901
-static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
2881
+static const struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
29022882 HDSP_DA_GAIN("DA Gain", 0),
29032883 HDSP_AD_GAIN("AD Gain", 0),
29042884 HDSP_PHONE_GAIN("Phones Gain", 0),
....@@ -2906,7 +2886,7 @@
29062886 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
29072887 };
29082888
2909
-static struct snd_kcontrol_new snd_hdsp_controls[] = {
2889
+static const struct snd_kcontrol_new snd_hdsp_controls[] = {
29102890 {
29112891 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
29122892 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
....@@ -2969,7 +2949,7 @@
29692949 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
29702950 HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut),
29712951 HDSP_PRECISE_POINTER("Precise Pointer", 0),
2972
-HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
2952
+HDSP_USE_MIDI_WORK("Use Midi Tasklet", 0),
29732953 };
29742954
29752955
....@@ -3235,7 +3215,7 @@
32353215 return snd_ctl_enum_info(uinfo, 1, 2, texts);
32363216 }
32373217
3238
-static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
3218
+static const struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
32393219 {
32403220 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
32413221 .name = "RPM Bypass",
....@@ -3268,7 +3248,7 @@
32683248 HDSP_MIXER("Mixer", 0)
32693249 };
32703250
3271
-static struct snd_kcontrol_new snd_hdsp_96xx_aeb =
3251
+static const struct snd_kcontrol_new snd_hdsp_96xx_aeb =
32723252 HDSP_TOGGLE_SETTING("Analog Extension Board",
32733253 HDSP_AnalogExtensionBoard);
32743254 static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
....@@ -3372,7 +3352,8 @@
33723352 return;
33733353 }
33743354 } else {
3375
- int err = -EINVAL;
3355
+ int err;
3356
+
33763357 err = hdsp_request_fw_loader(hdsp);
33773358 if (err < 0) {
33783359 snd_iprintf(buffer,
....@@ -3388,7 +3369,7 @@
33883369 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
33893370 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
33903371 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3391
- snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
3372
+ snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_work ? "on" : "off");
33923373
33933374 snd_iprintf(buffer, "\n");
33943375
....@@ -3708,10 +3689,7 @@
37083689
37093690 static void snd_hdsp_proc_init(struct hdsp *hdsp)
37103691 {
3711
- struct snd_info_entry *entry;
3712
-
3713
- if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3714
- snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
3692
+ snd_card_ro_proc_new(hdsp->card, "hdsp", hdsp, snd_hdsp_proc_read);
37153693 }
37163694
37173695 static void snd_hdsp_free_buffers(struct hdsp *hdsp)
....@@ -3812,9 +3790,9 @@
38123790 return 0;
38133791 }
38143792
3815
-static void hdsp_midi_tasklet(unsigned long arg)
3793
+static void hdsp_midi_work(struct work_struct *work)
38163794 {
3817
- struct hdsp *hdsp = (struct hdsp *)arg;
3795
+ struct hdsp *hdsp = container_of(work, struct hdsp, midi_work);
38183796
38193797 if (hdsp->midi[0].pending)
38203798 snd_hdsp_midi_input_read (&hdsp->midi[0]);
....@@ -3859,7 +3837,7 @@
38593837 }
38603838
38613839 if (midi0 && midi0status) {
3862
- if (hdsp->use_midi_tasklet) {
3840
+ if (hdsp->use_midi_work) {
38633841 /* we disable interrupts for this input until processing is done */
38643842 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
38653843 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
....@@ -3870,7 +3848,7 @@
38703848 }
38713849 }
38723850 if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) {
3873
- if (hdsp->use_midi_tasklet) {
3851
+ if (hdsp->use_midi_work) {
38743852 /* we disable interrupts for this input until processing is done */
38753853 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
38763854 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
....@@ -3880,8 +3858,8 @@
38803858 snd_hdsp_midi_input_read (&hdsp->midi[1]);
38813859 }
38823860 }
3883
- if (hdsp->use_midi_tasklet && schedule)
3884
- tasklet_schedule(&hdsp->midi_tasklet);
3861
+ if (hdsp->use_midi_work && schedule)
3862
+ queue_work(system_highpri_wq, &hdsp->midi_work);
38853863 return IRQ_HANDLED;
38863864 }
38873865
....@@ -3891,7 +3869,7 @@
38913869 return hdsp_hw_pointer(hdsp);
38923870 }
38933871
3894
-static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3872
+static signed char *hdsp_channel_buffer_location(struct hdsp *hdsp,
38953873 int stream,
38963874 int channel)
38973875
....@@ -3915,7 +3893,7 @@
39153893 void __user *src, unsigned long count)
39163894 {
39173895 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3918
- char *channel_buf;
3896
+ signed char *channel_buf;
39193897
39203898 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES))
39213899 return -EINVAL;
....@@ -3933,7 +3911,7 @@
39333911 void *src, unsigned long count)
39343912 {
39353913 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3936
- char *channel_buf;
3914
+ signed char *channel_buf;
39373915
39383916 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
39393917 if (snd_BUG_ON(!channel_buf))
....@@ -3947,7 +3925,7 @@
39473925 void __user *dst, unsigned long count)
39483926 {
39493927 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3950
- char *channel_buf;
3928
+ signed char *channel_buf;
39513929
39523930 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES))
39533931 return -EINVAL;
....@@ -3965,7 +3943,7 @@
39653943 void *dst, unsigned long count)
39663944 {
39673945 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3968
- char *channel_buf;
3946
+ signed char *channel_buf;
39693947
39703948 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
39713949 if (snd_BUG_ON(!channel_buf))
....@@ -3979,7 +3957,7 @@
39793957 unsigned long count)
39803958 {
39813959 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3982
- char *channel_buf;
3960
+ signed char *channel_buf;
39833961
39843962 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
39853963 if (snd_BUG_ON(!channel_buf))
....@@ -4824,7 +4802,7 @@
48244802 break;
48254803 }
48264804 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4827
- struct hdsp_firmware __user *firmware;
4805
+ struct hdsp_firmware firmware;
48284806 u32 __user *firmware_data;
48294807 int err;
48304808
....@@ -4837,10 +4815,9 @@
48374815
48384816 dev_info(hdsp->card->dev,
48394817 "initializing firmware upload\n");
4840
- firmware = (struct hdsp_firmware __user *)argp;
4841
-
4842
- if (get_user(firmware_data, &firmware->firmware_data))
4818
+ if (copy_from_user(&firmware, argp, sizeof(firmware)))
48434819 return -EFAULT;
4820
+ firmware_data = (u32 __user *)firmware.firmware_data;
48444821
48454822 if (hdsp_check_for_iobox (hdsp))
48464823 return -EIO;
....@@ -5204,7 +5181,7 @@
52045181
52055182 spin_lock_init(&hdsp->lock);
52065183
5207
- tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5184
+ INIT_WORK(&hdsp->midi_work, hdsp_midi_work);
52085185
52095186 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
52105187 hdsp->firmware_rev &= 0xff;
....@@ -5242,7 +5219,7 @@
52425219 if ((err = pci_request_regions(pci, "hdsp")) < 0)
52435220 return err;
52445221 hdsp->port = pci_resource_start(pci, 0);
5245
- if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5222
+ if ((hdsp->iobase = ioremap(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
52465223 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
52475224 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
52485225 return -EBUSY;
....@@ -5255,8 +5232,9 @@
52555232 }
52565233
52575234 hdsp->irq = pci->irq;
5235
+ card->sync_irq = hdsp->irq;
52585236 hdsp->precise_ptr = 0;
5259
- hdsp->use_midi_tasklet = 1;
5237
+ hdsp->use_midi_work = 1;
52605238 hdsp->dds_value = 0;
52615239
52625240 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
....@@ -5326,7 +5304,7 @@
53265304 {
53275305 if (hdsp->port) {
53285306 /* stop the audio, and cancel all interrupts */
5329
- tasklet_kill(&hdsp->midi_tasklet);
5307
+ cancel_work_sync(&hdsp->midi_work);
53305308 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
53315309 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
53325310 }