diff options
Diffstat (limited to 'sound/pci')
-rw-r--r-- | sound/pci/rme9652/hdspm.c | 599 |
1 files changed, 325 insertions, 274 deletions
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 83ea4623e77c..30e0c4dc9484 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c | |||
@@ -1,5 +1,4 @@ | |||
1 | /* -*- linux-c -*- | 1 | /* |
2 | * | ||
3 | * ALSA driver for RME Hammerfall DSP MADI audio interface(s) | 2 | * ALSA driver for RME Hammerfall DSP MADI audio interface(s) |
4 | * | 3 | * |
5 | * Copyright (c) 2003 Winfried Ritsch (IEM) | 4 | * Copyright (c) 2003 Winfried Ritsch (IEM) |
@@ -78,7 +77,8 @@ MODULE_PARM_DESC(enable_monitor, | |||
78 | "Enable Analog Out on Channel 63/64 by default."); | 77 | "Enable Analog Out on Channel 63/64 by default."); |
79 | 78 | ||
80 | MODULE_AUTHOR | 79 | MODULE_AUTHOR |
81 | ("Winfried Ritsch <ritsch_AT_iem.at>, Paul Davis <paul@linuxaudiosystems.com>, " | 80 | ("Winfried Ritsch <ritsch_AT_iem.at>, " |
81 | "Paul Davis <paul@linuxaudiosystems.com>, " | ||
82 | "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, " | 82 | "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, " |
83 | "Remy Bruno <remy.bruno@trinnov.com>"); | 83 | "Remy Bruno <remy.bruno@trinnov.com>"); |
84 | MODULE_DESCRIPTION("RME HDSPM"); | 84 | MODULE_DESCRIPTION("RME HDSPM"); |
@@ -161,7 +161,9 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); | |||
161 | 0=off, 1=on */ /* MADI ONLY */ | 161 | 0=off, 1=on */ /* MADI ONLY */ |
162 | #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */ | 162 | #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */ |
163 | 163 | ||
164 | #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax */ /* MADI ONLY*/ | 164 | #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax |
165 | * -- MADI ONLY | ||
166 | */ | ||
165 | #define HDSPM_InputSelect1 (1<<15) /* should be 0 */ | 167 | #define HDSPM_InputSelect1 (1<<15) /* should be 0 */ |
166 | 168 | ||
167 | #define HDSPM_SyncRef0 (1<<16) /* 0=WOrd, 1=MADI */ | 169 | #define HDSPM_SyncRef0 (1<<16) /* 0=WOrd, 1=MADI */ |
@@ -189,11 +191,13 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); | |||
189 | 191 | ||
190 | /* --- bit helper defines */ | 192 | /* --- bit helper defines */ |
191 | #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2) | 193 | #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2) |
192 | #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|HDSPM_DoubleSpeed|HDSPM_QuadSpeed) | 194 | #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\ |
195 | HDSPM_DoubleSpeed|HDSPM_QuadSpeed) | ||
193 | #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1) | 196 | #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1) |
194 | #define HDSPM_InputOptical 0 | 197 | #define HDSPM_InputOptical 0 |
195 | #define HDSPM_InputCoaxial (HDSPM_InputSelect0) | 198 | #define HDSPM_InputCoaxial (HDSPM_InputSelect0) |
196 | #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|HDSPM_SyncRef2|HDSPM_SyncRef3) | 199 | #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\ |
200 | HDSPM_SyncRef2|HDSPM_SyncRef3) | ||
197 | #define HDSPM_SyncRef_Word 0 | 201 | #define HDSPM_SyncRef_Word 0 |
198 | #define HDSPM_SyncRef_MADI (HDSPM_SyncRef0) | 202 | #define HDSPM_SyncRef_MADI (HDSPM_SyncRef0) |
199 | 203 | ||
@@ -205,10 +209,12 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); | |||
205 | #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0) | 209 | #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0) |
206 | #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0) | 210 | #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0) |
207 | #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1) | 211 | #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1) |
208 | #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|HDSPM_Frequency0) | 212 | #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\ |
213 | HDSPM_Frequency0) | ||
209 | #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0) | 214 | #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0) |
210 | #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1) | 215 | #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1) |
211 | #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|HDSPM_Frequency0) | 216 | #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\ |
217 | HDSPM_Frequency0) | ||
212 | 218 | ||
213 | /* --- for internal discrimination */ | 219 | /* --- for internal discrimination */ |
214 | #define HDSPM_CLOCK_SOURCE_AUTOSYNC 0 /* Sample Clock Sources */ | 220 | #define HDSPM_CLOCK_SOURCE_AUTOSYNC 0 /* Sample Clock Sources */ |
@@ -256,10 +262,14 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); | |||
256 | #define HDSPM_RD_MULTIPLE (1<<10) | 262 | #define HDSPM_RD_MULTIPLE (1<<10) |
257 | 263 | ||
258 | /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and | 264 | /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and |
259 | that do not conflict with specific bits for AES32 seem to be valid also for the AES32 */ | 265 | that do not conflict with specific bits for AES32 seem to be valid also |
266 | for the AES32 | ||
267 | */ | ||
260 | #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */ | 268 | #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */ |
261 | #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn. MODE=0 */ | 269 | #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */ |
262 | #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1 (like inp0) */ | 270 | #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1 |
271 | * (like inp0) | ||
272 | */ | ||
263 | #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */ | 273 | #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */ |
264 | 274 | ||
265 | #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */ | 275 | #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */ |
@@ -274,12 +284,15 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); | |||
274 | #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */ | 284 | #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */ |
275 | #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */ | 285 | #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */ |
276 | 286 | ||
277 | #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with Interrupt */ | 287 | #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with |
288 | * Interrupt | ||
289 | */ | ||
278 | #define HDSPM_midi0IRQPending (1<<30) /* MIDI IRQ is pending */ | 290 | #define HDSPM_midi0IRQPending (1<<30) /* MIDI IRQ is pending */ |
279 | #define HDSPM_midi1IRQPending (1<<31) /* and aktiv */ | 291 | #define HDSPM_midi1IRQPending (1<<31) /* and aktiv */ |
280 | 292 | ||
281 | /* --- status bit helpers */ | 293 | /* --- status bit helpers */ |
282 | #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2|HDSPM_madiFreq3) | 294 | #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\ |
295 | HDSPM_madiFreq2|HDSPM_madiFreq3) | ||
283 | #define HDSPM_madiFreq32 (HDSPM_madiFreq0) | 296 | #define HDSPM_madiFreq32 (HDSPM_madiFreq0) |
284 | #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1) | 297 | #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1) |
285 | #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1) | 298 | #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1) |
@@ -319,10 +332,12 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); | |||
319 | #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2) | 332 | #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2) |
320 | 333 | ||
321 | 334 | ||
322 | #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|HDSPM_SelSyncRef2) | 335 | #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
336 | HDSPM_SelSyncRef2) | ||
323 | #define HDSPM_SelSyncRef_WORD 0 | 337 | #define HDSPM_SelSyncRef_WORD 0 |
324 | #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0) | 338 | #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0) |
325 | #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|HDSPM_SelSyncRef2) | 339 | #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
340 | HDSPM_SelSyncRef2) | ||
326 | 341 | ||
327 | /* | 342 | /* |
328 | For AES32, bits for status, status2 and timecode are different | 343 | For AES32, bits for status, status2 and timecode are different |
@@ -412,8 +427,9 @@ struct hdspm_midi { | |||
412 | 427 | ||
413 | struct hdspm { | 428 | struct hdspm { |
414 | spinlock_t lock; | 429 | spinlock_t lock; |
415 | struct snd_pcm_substream *capture_substream; /* only one playback */ | 430 | /* only one playback and/or capture stream */ |
416 | struct snd_pcm_substream *playback_substream; /* and/or capture stream */ | 431 | struct snd_pcm_substream *capture_substream; |
432 | struct snd_pcm_substream *playback_substream; | ||
417 | 433 | ||
418 | char *card_name; /* for procinfo */ | 434 | char *card_name; /* for procinfo */ |
419 | unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/ | 435 | unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/ |
@@ -460,9 +476,12 @@ struct hdspm { | |||
460 | struct pci_dev *pci; /* and an pci info */ | 476 | struct pci_dev *pci; /* and an pci info */ |
461 | 477 | ||
462 | /* Mixer vars */ | 478 | /* Mixer vars */ |
463 | struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; /* fast alsa mixer */ | 479 | /* fast alsa mixer */ |
464 | struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS]; /* but input to much, so not used */ | 480 | struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; |
465 | struct hdspm_mixer *mixer; /* full mixer accessable over mixer ioctl or hwdep-device */ | 481 | /* but input to much, so not used */ |
482 | struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS]; | ||
483 | /* full mixer accessable over mixer ioctl or hwdep-device */ | ||
484 | struct hdspm_mixer *mixer; | ||
466 | 485 | ||
467 | }; | 486 | }; |
468 | 487 | ||
@@ -616,13 +635,15 @@ static inline int hdspm_external_sample_rate(struct hdspm * hdspm) | |||
616 | if (hdspm->is_aes32) { | 635 | if (hdspm->is_aes32) { |
617 | unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | 636 | unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
618 | unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); | 637 | unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); |
619 | unsigned int timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); | 638 | unsigned int timecode = |
639 | hdspm_read(hdspm, HDSPM_timecodeRegister); | ||
620 | 640 | ||
621 | int syncref = hdspm_autosync_ref(hdspm); | 641 | int syncref = hdspm_autosync_ref(hdspm); |
622 | 642 | ||
623 | if (syncref == HDSPM_AES32_AUTOSYNC_FROM_WORD && | 643 | if (syncref == HDSPM_AES32_AUTOSYNC_FROM_WORD && |
624 | status & HDSPM_AES32_wcLock) | 644 | status & HDSPM_AES32_wcLock) |
625 | return HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF); | 645 | return HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) |
646 | & 0xF); | ||
626 | if (syncref >= HDSPM_AES32_AUTOSYNC_FROM_AES1 && | 647 | if (syncref >= HDSPM_AES32_AUTOSYNC_FROM_AES1 && |
627 | syncref <= HDSPM_AES32_AUTOSYNC_FROM_AES8 && | 648 | syncref <= HDSPM_AES32_AUTOSYNC_FROM_AES8 && |
628 | status2 & (HDSPM_LockAES >> | 649 | status2 & (HDSPM_LockAES >> |
@@ -668,7 +689,9 @@ static inline int hdspm_external_sample_rate(struct hdspm * hdspm) | |||
668 | } | 689 | } |
669 | } | 690 | } |
670 | 691 | ||
671 | /* if rate detected and Syncref is Word than have it, word has priority to MADI */ | 692 | /* if rate detected and Syncref is Word than have it, |
693 | * word has priority to MADI | ||
694 | */ | ||
672 | if (rate != 0 && | 695 | if (rate != 0 && |
673 | (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD) | 696 | (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD) |
674 | return rate; | 697 | return rate; |
@@ -727,12 +750,12 @@ static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm * hdspm) | |||
727 | 750 | ||
728 | position = hdspm_read(hdspm, HDSPM_statusRegister); | 751 | position = hdspm_read(hdspm, HDSPM_statusRegister); |
729 | 752 | ||
730 | if (!hdspm->precise_ptr) { | 753 | if (!hdspm->precise_ptr) |
731 | return (position & HDSPM_BufferID) ? (hdspm->period_bytes / | 754 | return (position & HDSPM_BufferID) ? |
732 | 4) : 0; | 755 | (hdspm->period_bytes / 4) : 0; |
733 | } | ||
734 | 756 | ||
735 | /* hwpointer comes in bytes and is 64Bytes accurate (by docu since PCI Burst) | 757 | /* hwpointer comes in bytes and is 64Bytes accurate (by docu since |
758 | PCI Burst) | ||
736 | i have experimented that it is at most 64 Byte to much for playing | 759 | i have experimented that it is at most 64 Byte to much for playing |
737 | so substraction of 64 byte should be ok for ALSA, but use it only | 760 | so substraction of 64 byte should be ok for ALSA, but use it only |
738 | for application where you know what you do since if you come to | 761 | for application where you know what you do since if you come to |
@@ -808,10 +831,10 @@ static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) | |||
808 | rate /= 2; | 831 | rate /= 2; |
809 | 832 | ||
810 | /* RME says n = 104857600000000, but in the windows MADI driver, I see: | 833 | /* RME says n = 104857600000000, but in the windows MADI driver, I see: |
811 | // return 104857600000000 / rate; // 100 MHz | 834 | return 104857600000000 / rate; // 100 MHz |
812 | return 110100480000000 / rate; // 105 MHz | 835 | return 110100480000000 / rate; // 105 MHz |
813 | */ | 836 | */ |
814 | //n = 104857600000000ULL; /* = 2^20 * 10^8 */ | 837 | /* n = 104857600000000ULL; */ /* = 2^20 * 10^8 */ |
815 | n = 110100480000000ULL; /* Value checked for AES32 and MADI */ | 838 | n = 110100480000000ULL; /* Value checked for AES32 and MADI */ |
816 | div64_32(&n, rate, &r); | 839 | div64_32(&n, rate, &r); |
817 | /* n should be less than 2^32 for being written to FREQ register */ | 840 | /* n should be less than 2^32 for being written to FREQ register */ |
@@ -841,8 +864,9 @@ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) | |||
841 | just make a warning an remember setting | 864 | just make a warning an remember setting |
842 | for future master mode switching */ | 865 | for future master mode switching */ |
843 | 866 | ||
844 | snd_printk | 867 | snd_printk(KERN_WARNING "HDSPM: " |
845 | (KERN_WARNING "HDSPM: Warning: device is not running as a clock master.\n"); | 868 | "Warning: device is not running " |
869 | "as a clock master.\n"); | ||
846 | not_set = 1; | 870 | not_set = 1; |
847 | } else { | 871 | } else { |
848 | 872 | ||
@@ -850,16 +874,18 @@ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) | |||
850 | int external_freq = | 874 | int external_freq = |
851 | hdspm_external_sample_rate(hdspm); | 875 | hdspm_external_sample_rate(hdspm); |
852 | 876 | ||
853 | if ((hdspm_autosync_ref(hdspm) == | 877 | if (hdspm_autosync_ref(hdspm) == |
854 | HDSPM_AUTOSYNC_FROM_NONE)) { | 878 | HDSPM_AUTOSYNC_FROM_NONE) { |
855 | 879 | ||
856 | snd_printk(KERN_WARNING "HDSPM: Detected no Externel Sync \n"); | 880 | snd_printk(KERN_WARNING "HDSPM: " |
881 | "Detected no Externel Sync \n"); | ||
857 | not_set = 1; | 882 | not_set = 1; |
858 | 883 | ||
859 | } else if (rate != external_freq) { | 884 | } else if (rate != external_freq) { |
860 | 885 | ||
861 | snd_printk | 886 | snd_printk(KERN_WARNING "HDSPM: " |
862 | (KERN_WARNING "HDSPM: Warning: No AutoSync source for requested rate\n"); | 887 | "Warning: No AutoSync source for " |
888 | "requested rate\n"); | ||
863 | not_set = 1; | 889 | not_set = 1; |
864 | } | 890 | } |
865 | } | 891 | } |
@@ -934,7 +960,9 @@ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) | |||
934 | if (reject_if_open | 960 | if (reject_if_open |
935 | && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) { | 961 | && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) { |
936 | snd_printk | 962 | snd_printk |
937 | (KERN_ERR "HDSPM: cannot change between single- and double-speed mode (capture PID = %d, playback PID = %d)\n", | 963 | (KERN_ERR "HDSPM: " |
964 | "cannot change between single- and double-speed mode " | ||
965 | "(capture PID = %d, playback PID = %d)\n", | ||
938 | hdspm->capture_pid, hdspm->playback_pid); | 966 | hdspm->capture_pid, hdspm->playback_pid); |
939 | return -EBUSY; | 967 | return -EBUSY; |
940 | } | 968 | } |
@@ -966,8 +994,14 @@ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) | |||
966 | static void all_in_all_mixer(struct hdspm * hdspm, int sgain) | 994 | static void all_in_all_mixer(struct hdspm * hdspm, int sgain) |
967 | { | 995 | { |
968 | int i, j; | 996 | int i, j; |
969 | unsigned int gain = | 997 | unsigned int gain; |
970 | (sgain > UNITY_GAIN) ? UNITY_GAIN : (sgain < 0) ? 0 : sgain; | 998 | |
999 | if (sgain > UNITY_GAIN) | ||
1000 | gain = UNITY_GAIN; | ||
1001 | else if (sgain < 0) | ||
1002 | gain = 0; | ||
1003 | else | ||
1004 | gain = sgain; | ||
971 | 1005 | ||
972 | for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) | 1006 | for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) |
973 | for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) { | 1007 | for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) { |
@@ -980,7 +1014,8 @@ static void all_in_all_mixer(struct hdspm * hdspm, int sgain) | |||
980 | MIDI | 1014 | MIDI |
981 | ----------------------------------------------------------------------------*/ | 1015 | ----------------------------------------------------------------------------*/ |
982 | 1016 | ||
983 | static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, int id) | 1017 | static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, |
1018 | int id) | ||
984 | { | 1019 | { |
985 | /* the hardware already does the relevant bit-mask with 0xff */ | 1020 | /* the hardware already does the relevant bit-mask with 0xff */ |
986 | if (id) | 1021 | if (id) |
@@ -989,7 +1024,8 @@ static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, int i | |||
989 | return hdspm_read(hdspm, HDSPM_midiDataIn0); | 1024 | return hdspm_read(hdspm, HDSPM_midiDataIn0); |
990 | } | 1025 | } |
991 | 1026 | ||
992 | static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id, int val) | 1027 | static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id, |
1028 | int val) | ||
993 | { | 1029 | { |
994 | /* the hardware already does the relevant bit-mask with 0xff */ | 1030 | /* the hardware already does the relevant bit-mask with 0xff */ |
995 | if (id) | 1031 | if (id) |
@@ -1011,9 +1047,10 @@ static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id) | |||
1011 | int fifo_bytes_used; | 1047 | int fifo_bytes_used; |
1012 | 1048 | ||
1013 | if (id) | 1049 | if (id) |
1014 | fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xff; | 1050 | fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut1); |
1015 | else | 1051 | else |
1016 | fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xff; | 1052 | fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut0); |
1053 | fifo_bytes_used &= 0xff; | ||
1017 | 1054 | ||
1018 | if (fifo_bytes_used < 128) | 1055 | if (fifo_bytes_used < 128) |
1019 | return 128 - fifo_bytes_used; | 1056 | return 128 - fifo_bytes_used; |
@@ -1038,16 +1075,21 @@ static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) | |||
1038 | /* Output is not interrupt driven */ | 1075 | /* Output is not interrupt driven */ |
1039 | 1076 | ||
1040 | spin_lock_irqsave (&hmidi->lock, flags); | 1077 | spin_lock_irqsave (&hmidi->lock, flags); |
1041 | if (hmidi->output) { | 1078 | if (hmidi->output && |
1042 | if (!snd_rawmidi_transmit_empty (hmidi->output)) { | 1079 | !snd_rawmidi_transmit_empty (hmidi->output)) { |
1043 | if ((n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, hmidi->id)) > 0) { | 1080 | n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, |
1044 | if (n_pending > (int)sizeof (buf)) | 1081 | hmidi->id); |
1045 | n_pending = sizeof (buf); | 1082 | if (n_pending > 0) { |
1046 | 1083 | if (n_pending > (int)sizeof (buf)) | |
1047 | if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) { | 1084 | n_pending = sizeof (buf); |
1048 | for (i = 0; i < to_write; ++i) | 1085 | |
1049 | snd_hdspm_midi_write_byte (hmidi->hdspm, hmidi->id, buf[i]); | 1086 | to_write = snd_rawmidi_transmit (hmidi->output, buf, |
1050 | } | 1087 | n_pending); |
1088 | if (to_write > 0) { | ||
1089 | for (i = 0; i < to_write; ++i) | ||
1090 | snd_hdspm_midi_write_byte (hmidi->hdspm, | ||
1091 | hmidi->id, | ||
1092 | buf[i]); | ||
1051 | } | 1093 | } |
1052 | } | 1094 | } |
1053 | } | 1095 | } |
@@ -1057,51 +1099,55 @@ static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) | |||
1057 | 1099 | ||
1058 | static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi) | 1100 | static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi) |
1059 | { | 1101 | { |
1060 | unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */ | 1102 | unsigned char buf[128]; /* this buffer is designed to match the MIDI |
1103 | * input FIFO size | ||
1104 | */ | ||
1061 | unsigned long flags; | 1105 | unsigned long flags; |
1062 | int n_pending; | 1106 | int n_pending; |
1063 | int i; | 1107 | int i; |
1064 | 1108 | ||
1065 | spin_lock_irqsave (&hmidi->lock, flags); | 1109 | spin_lock_irqsave (&hmidi->lock, flags); |
1066 | if ((n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id)) > 0) { | 1110 | n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); |
1111 | if (n_pending > 0) { | ||
1067 | if (hmidi->input) { | 1112 | if (hmidi->input) { |
1068 | if (n_pending > (int)sizeof (buf)) { | 1113 | if (n_pending > (int)sizeof (buf)) |
1069 | n_pending = sizeof (buf); | 1114 | n_pending = sizeof (buf); |
1070 | } | 1115 | for (i = 0; i < n_pending; ++i) |
1071 | for (i = 0; i < n_pending; ++i) { | 1116 | buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, |
1072 | buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id); | 1117 | hmidi->id); |
1073 | } | 1118 | if (n_pending) |
1074 | if (n_pending) { | 1119 | snd_rawmidi_receive (hmidi->input, buf, |
1075 | snd_rawmidi_receive (hmidi->input, buf, n_pending); | 1120 | n_pending); |
1076 | } | ||
1077 | } else { | 1121 | } else { |
1078 | /* flush the MIDI input FIFO */ | 1122 | /* flush the MIDI input FIFO */ |
1079 | while (n_pending--) { | 1123 | while (n_pending--) |
1080 | snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id); | 1124 | snd_hdspm_midi_read_byte (hmidi->hdspm, |
1081 | } | 1125 | hmidi->id); |
1082 | } | 1126 | } |
1083 | } | 1127 | } |
1084 | hmidi->pending = 0; | 1128 | hmidi->pending = 0; |
1085 | if (hmidi->id) { | 1129 | if (hmidi->id) |
1086 | hmidi->hdspm->control_register |= HDSPM_Midi1InterruptEnable; | 1130 | hmidi->hdspm->control_register |= HDSPM_Midi1InterruptEnable; |
1087 | } else { | 1131 | else |
1088 | hmidi->hdspm->control_register |= HDSPM_Midi0InterruptEnable; | 1132 | hmidi->hdspm->control_register |= HDSPM_Midi0InterruptEnable; |
1089 | } | 1133 | hdspm_write(hmidi->hdspm, HDSPM_controlRegister, |
1090 | hdspm_write(hmidi->hdspm, HDSPM_controlRegister, hmidi->hdspm->control_register); | 1134 | hmidi->hdspm->control_register); |
1091 | spin_unlock_irqrestore (&hmidi->lock, flags); | 1135 | spin_unlock_irqrestore (&hmidi->lock, flags); |
1092 | return snd_hdspm_midi_output_write (hmidi); | 1136 | return snd_hdspm_midi_output_write (hmidi); |
1093 | } | 1137 | } |
1094 | 1138 | ||
1095 | static void snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) | 1139 | static void |
1140 | snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) | ||
1096 | { | 1141 | { |
1097 | struct hdspm *hdspm; | 1142 | struct hdspm *hdspm; |
1098 | struct hdspm_midi *hmidi; | 1143 | struct hdspm_midi *hmidi; |
1099 | unsigned long flags; | 1144 | unsigned long flags; |
1100 | u32 ie; | 1145 | u32 ie; |
1101 | 1146 | ||
1102 | hmidi = (struct hdspm_midi *) substream->rmidi->private_data; | 1147 | hmidi = substream->rmidi->private_data; |
1103 | hdspm = hmidi->hdspm; | 1148 | hdspm = hmidi->hdspm; |
1104 | ie = hmidi->id ? HDSPM_Midi1InterruptEnable : HDSPM_Midi0InterruptEnable; | 1149 | ie = hmidi->id ? |
1150 | HDSPM_Midi1InterruptEnable : HDSPM_Midi0InterruptEnable; | ||
1105 | spin_lock_irqsave (&hdspm->lock, flags); | 1151 | spin_lock_irqsave (&hdspm->lock, flags); |
1106 | if (up) { | 1152 | if (up) { |
1107 | if (!(hdspm->control_register & ie)) { | 1153 | if (!(hdspm->control_register & ie)) { |
@@ -1138,12 +1184,13 @@ static void snd_hdspm_midi_output_timer(unsigned long data) | |||
1138 | spin_unlock_irqrestore (&hmidi->lock, flags); | 1184 | spin_unlock_irqrestore (&hmidi->lock, flags); |
1139 | } | 1185 | } |
1140 | 1186 | ||
1141 | static void snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) | 1187 | static void |
1188 | snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) | ||
1142 | { | 1189 | { |
1143 | struct hdspm_midi *hmidi; | 1190 | struct hdspm_midi *hmidi; |
1144 | unsigned long flags; | 1191 | unsigned long flags; |
1145 | 1192 | ||
1146 | hmidi = (struct hdspm_midi *) substream->rmidi->private_data; | 1193 | hmidi = substream->rmidi->private_data; |
1147 | spin_lock_irqsave (&hmidi->lock, flags); | 1194 | spin_lock_irqsave (&hmidi->lock, flags); |
1148 | if (up) { | 1195 | if (up) { |
1149 | if (!hmidi->istimer) { | 1196 | if (!hmidi->istimer) { |
@@ -1155,9 +1202,8 @@ static void snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substrea | |||
1155 | hmidi->istimer++; | 1202 | hmidi->istimer++; |
1156 | } | 1203 | } |
1157 | } else { | 1204 | } else { |
1158 | if (hmidi->istimer && --hmidi->istimer <= 0) { | 1205 | if (hmidi->istimer && --hmidi->istimer <= 0) |
1159 | del_timer (&hmidi->timer); | 1206 | del_timer (&hmidi->timer); |
1160 | } | ||
1161 | } | 1207 | } |
1162 | spin_unlock_irqrestore (&hmidi->lock, flags); | 1208 | spin_unlock_irqrestore (&hmidi->lock, flags); |
1163 | if (up) | 1209 | if (up) |
@@ -1168,7 +1214,7 @@ static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream) | |||
1168 | { | 1214 | { |
1169 | struct hdspm_midi *hmidi; | 1215 | struct hdspm_midi *hmidi; |
1170 | 1216 | ||
1171 | hmidi = (struct hdspm_midi *) substream->rmidi->private_data; | 1217 | hmidi = substream->rmidi->private_data; |
1172 | spin_lock_irq (&hmidi->lock); | 1218 | spin_lock_irq (&hmidi->lock); |
1173 | snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); | 1219 | snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); |
1174 | hmidi->input = substream; | 1220 | hmidi->input = substream; |
@@ -1181,7 +1227,7 @@ static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream) | |||
1181 | { | 1227 | { |
1182 | struct hdspm_midi *hmidi; | 1228 | struct hdspm_midi *hmidi; |
1183 | 1229 | ||
1184 | hmidi = (struct hdspm_midi *) substream->rmidi->private_data; | 1230 | hmidi = substream->rmidi->private_data; |
1185 | spin_lock_irq (&hmidi->lock); | 1231 | spin_lock_irq (&hmidi->lock); |
1186 | hmidi->output = substream; | 1232 | hmidi->output = substream; |
1187 | spin_unlock_irq (&hmidi->lock); | 1233 | spin_unlock_irq (&hmidi->lock); |
@@ -1195,7 +1241,7 @@ static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream) | |||
1195 | 1241 | ||
1196 | snd_hdspm_midi_input_trigger (substream, 0); | 1242 | snd_hdspm_midi_input_trigger (substream, 0); |
1197 | 1243 | ||
1198 | hmidi = (struct hdspm_midi *) substream->rmidi->private_data; | 1244 | hmidi = substream->rmidi->private_data; |
1199 | spin_lock_irq (&hmidi->lock); | 1245 | spin_lock_irq (&hmidi->lock); |
1200 | hmidi->input = NULL; | 1246 | hmidi->input = NULL; |
1201 | spin_unlock_irq (&hmidi->lock); | 1247 | spin_unlock_irq (&hmidi->lock); |
@@ -1209,7 +1255,7 @@ static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream) | |||
1209 | 1255 | ||
1210 | snd_hdspm_midi_output_trigger (substream, 0); | 1256 | snd_hdspm_midi_output_trigger (substream, 0); |
1211 | 1257 | ||
1212 | hmidi = (struct hdspm_midi *) substream->rmidi->private_data; | 1258 | hmidi = substream->rmidi->private_data; |
1213 | spin_lock_irq (&hmidi->lock); | 1259 | spin_lock_irq (&hmidi->lock); |
1214 | hmidi->output = NULL; | 1260 | hmidi->output = NULL; |
1215 | spin_unlock_irq (&hmidi->lock); | 1261 | spin_unlock_irq (&hmidi->lock); |
@@ -1231,29 +1277,28 @@ static struct snd_rawmidi_ops snd_hdspm_midi_input = | |||
1231 | .trigger = snd_hdspm_midi_input_trigger, | 1277 | .trigger = snd_hdspm_midi_input_trigger, |
1232 | }; | 1278 | }; |
1233 | 1279 | ||
1234 | static int __devinit snd_hdspm_create_midi (struct snd_card *card, struct hdspm *hdspm, int id) | 1280 | static int __devinit snd_hdspm_create_midi (struct snd_card *card, |
1281 | struct hdspm *hdspm, int id) | ||
1235 | { | 1282 | { |
1236 | int err; | 1283 | int err; |
1237 | char buf[32]; | 1284 | char buf[32]; |
1238 | 1285 | ||
1239 | hdspm->midi[id].id = id; | 1286 | hdspm->midi[id].id = id; |
1240 | hdspm->midi[id].rmidi = NULL; | ||
1241 | hdspm->midi[id].input = NULL; | ||
1242 | hdspm->midi[id].output = NULL; | ||
1243 | hdspm->midi[id].hdspm = hdspm; | 1287 | hdspm->midi[id].hdspm = hdspm; |
1244 | hdspm->midi[id].istimer = 0; | ||
1245 | hdspm->midi[id].pending = 0; | ||
1246 | spin_lock_init (&hdspm->midi[id].lock); | 1288 | spin_lock_init (&hdspm->midi[id].lock); |
1247 | 1289 | ||
1248 | sprintf (buf, "%s MIDI %d", card->shortname, id+1); | 1290 | sprintf (buf, "%s MIDI %d", card->shortname, id+1); |
1249 | if ((err = snd_rawmidi_new (card, buf, id, 1, 1, &hdspm->midi[id].rmidi)) < 0) | 1291 | err = snd_rawmidi_new (card, buf, id, 1, 1, &hdspm->midi[id].rmidi); |
1292 | if (err < 0) | ||
1250 | return err; | 1293 | return err; |
1251 | 1294 | ||
1252 | sprintf (hdspm->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1); | 1295 | sprintf (hdspm->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1); |
1253 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; | 1296 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; |
1254 | 1297 | ||
1255 | snd_rawmidi_set_ops (hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdspm_midi_output); | 1298 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, |
1256 | snd_rawmidi_set_ops (hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdspm_midi_input); | 1299 | &snd_hdspm_midi_output); |
1300 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, | ||
1301 | &snd_hdspm_midi_input); | ||
1257 | 1302 | ||
1258 | hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | | 1303 | hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | |
1259 | SNDRV_RAWMIDI_INFO_INPUT | | 1304 | SNDRV_RAWMIDI_INFO_INPUT | |
@@ -1637,7 +1682,8 @@ static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref) | |||
1637 | hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef1; | 1682 | hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef1; |
1638 | break; | 1683 | break; |
1639 | case 7: | 1684 | case 7: |
1640 | hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0; | 1685 | hdspm->control_register |= |
1686 | HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0; | ||
1641 | break; | 1687 | break; |
1642 | case 8: | 1688 | case 8: |
1643 | hdspm->control_register |= HDSPM_SyncRef3; | 1689 | hdspm->control_register |= HDSPM_SyncRef3; |
@@ -1675,7 +1721,8 @@ static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol, | |||
1675 | 1721 | ||
1676 | uinfo->value.enumerated.items = 9; | 1722 | uinfo->value.enumerated.items = 9; |
1677 | 1723 | ||
1678 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | 1724 | if (uinfo->value.enumerated.item >= |
1725 | uinfo->value.enumerated.items) | ||
1679 | uinfo->value.enumerated.item = | 1726 | uinfo->value.enumerated.item = |
1680 | uinfo->value.enumerated.items - 1; | 1727 | uinfo->value.enumerated.items - 1; |
1681 | strcpy(uinfo->value.enumerated.name, | 1728 | strcpy(uinfo->value.enumerated.name, |
@@ -1688,7 +1735,8 @@ static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol, | |||
1688 | 1735 | ||
1689 | uinfo->value.enumerated.items = 2; | 1736 | uinfo->value.enumerated.items = 2; |
1690 | 1737 | ||
1691 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | 1738 | if (uinfo->value.enumerated.item >= |
1739 | uinfo->value.enumerated.items) | ||
1692 | uinfo->value.enumerated.item = | 1740 | uinfo->value.enumerated.item = |
1693 | uinfo->value.enumerated.items - 1; | 1741 | uinfo->value.enumerated.items - 1; |
1694 | strcpy(uinfo->value.enumerated.name, | 1742 | strcpy(uinfo->value.enumerated.name, |
@@ -1740,7 +1788,8 @@ static int hdspm_autosync_ref(struct hdspm * hdspm) | |||
1740 | { | 1788 | { |
1741 | if (hdspm->is_aes32) { | 1789 | if (hdspm->is_aes32) { |
1742 | unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); | 1790 | unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); |
1743 | unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & 0xF; | 1791 | unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & |
1792 | 0xF; | ||
1744 | if (syncref == 0) | 1793 | if (syncref == 0) |
1745 | return HDSPM_AES32_AUTOSYNC_FROM_WORD; | 1794 | return HDSPM_AES32_AUTOSYNC_FROM_WORD; |
1746 | if (syncref <= 8) | 1795 | if (syncref <= 8) |
@@ -1777,20 +1826,20 @@ static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol, | |||
1777 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 1826 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
1778 | uinfo->count = 1; | 1827 | uinfo->count = 1; |
1779 | uinfo->value.enumerated.items = 10; | 1828 | uinfo->value.enumerated.items = 10; |
1780 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | 1829 | if (uinfo->value.enumerated.item >= |
1830 | uinfo->value.enumerated.items) | ||
1781 | uinfo->value.enumerated.item = | 1831 | uinfo->value.enumerated.item = |
1782 | uinfo->value.enumerated.items - 1; | 1832 | uinfo->value.enumerated.items - 1; |
1783 | strcpy(uinfo->value.enumerated.name, | 1833 | strcpy(uinfo->value.enumerated.name, |
1784 | texts[uinfo->value.enumerated.item]); | 1834 | texts[uinfo->value.enumerated.item]); |
1785 | } | 1835 | } else { |
1786 | else | ||
1787 | { | ||
1788 | static char *texts[] = { "WordClock", "MADI", "None" }; | 1836 | static char *texts[] = { "WordClock", "MADI", "None" }; |
1789 | 1837 | ||
1790 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 1838 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
1791 | uinfo->count = 1; | 1839 | uinfo->count = 1; |
1792 | uinfo->value.enumerated.items = 3; | 1840 | uinfo->value.enumerated.items = 3; |
1793 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | 1841 | if (uinfo->value.enumerated.item >= |
1842 | uinfo->value.enumerated.items) | ||
1794 | uinfo->value.enumerated.item = | 1843 | uinfo->value.enumerated.item = |
1795 | uinfo->value.enumerated.items - 1; | 1844 | uinfo->value.enumerated.items - 1; |
1796 | strcpy(uinfo->value.enumerated.name, | 1845 | strcpy(uinfo->value.enumerated.name, |
@@ -2416,7 +2465,7 @@ static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol, | |||
2416 | if (val > 2) | 2465 | if (val > 2) |
2417 | val = 2; | 2466 | val = 2; |
2418 | spin_lock_irq(&hdspm->lock); | 2467 | spin_lock_irq(&hdspm->lock); |
2419 | change = (int) val != hdspm_qs_wire(hdspm); | 2468 | change = val != hdspm_qs_wire(hdspm); |
2420 | hdspm_set_qs_wire(hdspm, val); | 2469 | hdspm_set_qs_wire(hdspm, val); |
2421 | spin_unlock_irq(&hdspm->lock); | 2470 | spin_unlock_irq(&hdspm->lock); |
2422 | return change; | 2471 | return change; |
@@ -2517,8 +2566,8 @@ static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, | |||
2517 | source - | 2566 | source - |
2518 | HDSPM_MAX_CHANNELS); | 2567 | HDSPM_MAX_CHANNELS); |
2519 | else | 2568 | else |
2520 | change = | 2569 | change = gain != hdspm_read_in_gain(hdspm, destination, |
2521 | gain != hdspm_read_in_gain(hdspm, destination, source); | 2570 | source); |
2522 | 2571 | ||
2523 | if (change) { | 2572 | if (change) { |
2524 | if (source >= HDSPM_MAX_CHANNELS) | 2573 | if (source >= HDSPM_MAX_CHANNELS) |
@@ -2571,7 +2620,8 @@ static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, | |||
2571 | snd_assert(channel >= 0 | 2620 | snd_assert(channel >= 0 |
2572 | || channel < HDSPM_MAX_CHANNELS, return -EINVAL); | 2621 | || channel < HDSPM_MAX_CHANNELS, return -EINVAL); |
2573 | 2622 | ||
2574 | if ((mapped_channel = hdspm->channel_map[channel]) < 0) | 2623 | mapped_channel = hdspm->channel_map[channel]; |
2624 | if (mapped_channel < 0) | ||
2575 | return -EINVAL; | 2625 | return -EINVAL; |
2576 | 2626 | ||
2577 | spin_lock_irq(&hdspm->lock); | 2627 | spin_lock_irq(&hdspm->lock); |
@@ -2579,10 +2629,12 @@ static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, | |||
2579 | hdspm_read_pb_gain(hdspm, mapped_channel, mapped_channel); | 2629 | hdspm_read_pb_gain(hdspm, mapped_channel, mapped_channel); |
2580 | spin_unlock_irq(&hdspm->lock); | 2630 | spin_unlock_irq(&hdspm->lock); |
2581 | 2631 | ||
2582 | /* snd_printdd("get pb mixer index %d, channel %d, mapped_channel %d, value %d\n", | 2632 | /* |
2583 | ucontrol->id.index, channel, mapped_channel, ucontrol->value.integer.value[0]); | 2633 | snd_printdd("get pb mixer index %d, channel %d, mapped_channel %d, " |
2584 | */ | 2634 | "value %d\n", |
2585 | 2635 | ucontrol->id.index, channel, mapped_channel, | |
2636 | ucontrol->value.integer.value[0]); | ||
2637 | */ | ||
2586 | return 0; | 2638 | return 0; |
2587 | } | 2639 | } |
2588 | 2640 | ||
@@ -2603,7 +2655,8 @@ static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, | |||
2603 | snd_assert(channel >= 0 | 2655 | snd_assert(channel >= 0 |
2604 | || channel < HDSPM_MAX_CHANNELS, return -EINVAL); | 2656 | || channel < HDSPM_MAX_CHANNELS, return -EINVAL); |
2605 | 2657 | ||
2606 | if ((mapped_channel = hdspm->channel_map[channel]) < 0) | 2658 | mapped_channel = hdspm->channel_map[channel]; |
2659 | if (mapped_channel < 0) | ||
2607 | return -EINVAL; | 2660 | return -EINVAL; |
2608 | 2661 | ||
2609 | gain = ucontrol->value.integer.value[0]; | 2662 | gain = ucontrol->value.integer.value[0]; |
@@ -2853,28 +2906,26 @@ static int snd_hdspm_create_controls(struct snd_card *card, struct hdspm * hdspm | |||
2853 | } | 2906 | } |
2854 | 2907 | ||
2855 | /* Channel playback mixer as default control | 2908 | /* Channel playback mixer as default control |
2856 | Note: the whole matrix would be 128*HDSPM_MIXER_CHANNELS Faders, thats too big for any alsamixer | 2909 | Note: the whole matrix would be 128*HDSPM_MIXER_CHANNELS Faders, |
2857 | they are accesible via special IOCTL on hwdep | 2910 | thats too * big for any alsamixer they are accesible via special |
2858 | and the mixer 2dimensional mixer control */ | 2911 | IOCTL on hwdep and the mixer 2dimensional mixer control |
2912 | */ | ||
2859 | 2913 | ||
2860 | snd_hdspm_playback_mixer.name = "Chn"; | 2914 | snd_hdspm_playback_mixer.name = "Chn"; |
2861 | limit = HDSPM_MAX_CHANNELS; | 2915 | limit = HDSPM_MAX_CHANNELS; |
2862 | 2916 | ||
2863 | /* The index values are one greater than the channel ID so that alsamixer | 2917 | /* The index values are one greater than the channel ID so that |
2864 | will display them correctly. We want to use the index for fast lookup | 2918 | * alsamixer will display them correctly. We want to use the index |
2865 | of the relevant channel, but if we use it at all, most ALSA software | 2919 | * for fast lookup of the relevant channel, but if we use it at all, |
2866 | does the wrong thing with it ... | 2920 | * most ALSA software does the wrong thing with it ... |
2867 | */ | 2921 | */ |
2868 | 2922 | ||
2869 | for (idx = 0; idx < limit; ++idx) { | 2923 | for (idx = 0; idx < limit; ++idx) { |
2870 | snd_hdspm_playback_mixer.index = idx + 1; | 2924 | snd_hdspm_playback_mixer.index = idx + 1; |
2871 | if ((err = snd_ctl_add(card, | 2925 | kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm); |
2872 | kctl = | 2926 | err = snd_ctl_add(card, kctl); |
2873 | snd_ctl_new1 | 2927 | if (err < 0) |
2874 | (&snd_hdspm_playback_mixer, | ||
2875 | hdspm)))) { | ||
2876 | return err; | 2928 | return err; |
2877 | } | ||
2878 | hdspm->playback_mixer_ctls[idx] = kctl; | 2929 | hdspm->playback_mixer_ctls[idx] = kctl; |
2879 | } | 2930 | } |
2880 | 2931 | ||
@@ -2889,7 +2940,7 @@ static void | |||
2889 | snd_hdspm_proc_read_madi(struct snd_info_entry * entry, | 2940 | snd_hdspm_proc_read_madi(struct snd_info_entry * entry, |
2890 | struct snd_info_buffer *buffer) | 2941 | struct snd_info_buffer *buffer) |
2891 | { | 2942 | { |
2892 | struct hdspm *hdspm = (struct hdspm *) entry->private_data; | 2943 | struct hdspm *hdspm = entry->private_data; |
2893 | unsigned int status; | 2944 | unsigned int status; |
2894 | unsigned int status2; | 2945 | unsigned int status2; |
2895 | char *pref_sync_ref; | 2946 | char *pref_sync_ref; |
@@ -2922,14 +2973,14 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry, | |||
2922 | (status & HDSPM_midi1IRQPending) ? 1 : 0, | 2973 | (status & HDSPM_midi1IRQPending) ? 1 : 0, |
2923 | hdspm->irq_count); | 2974 | hdspm->irq_count); |
2924 | snd_iprintf(buffer, | 2975 | snd_iprintf(buffer, |
2925 | "HW pointer: id = %d, rawptr = %d (%d->%d) estimated= %ld (bytes)\n", | 2976 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
2977 | "estimated= %ld (bytes)\n", | ||
2926 | ((status & HDSPM_BufferID) ? 1 : 0), | 2978 | ((status & HDSPM_BufferID) ? 1 : 0), |
2927 | (status & HDSPM_BufferPositionMask), | 2979 | (status & HDSPM_BufferPositionMask), |
2928 | (status & HDSPM_BufferPositionMask) % (2 * | 2980 | (status & HDSPM_BufferPositionMask) % |
2929 | (int)hdspm-> | 2981 | (2 * (int)hdspm->period_bytes), |
2930 | period_bytes), | 2982 | ((status & HDSPM_BufferPositionMask) - 64) % |
2931 | ((status & HDSPM_BufferPositionMask) - | 2983 | (2 * (int)hdspm->period_bytes), |
2932 | 64) % (2 * (int)hdspm->period_bytes), | ||
2933 | (long) hdspm_hw_pointer(hdspm) * 4); | 2984 | (long) hdspm_hw_pointer(hdspm) * 4); |
2934 | 2985 | ||
2935 | snd_iprintf(buffer, | 2986 | snd_iprintf(buffer, |
@@ -2939,24 +2990,22 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry, | |||
2939 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, | 2990 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, |
2940 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); | 2991 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); |
2941 | snd_iprintf(buffer, | 2992 | snd_iprintf(buffer, |
2942 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, status2=0x%x\n", | 2993 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " |
2994 | "status2=0x%x\n", | ||
2943 | hdspm->control_register, hdspm->control2_register, | 2995 | hdspm->control_register, hdspm->control2_register, |
2944 | status, status2); | 2996 | status, status2); |
2945 | 2997 | ||
2946 | snd_iprintf(buffer, "--- Settings ---\n"); | 2998 | snd_iprintf(buffer, "--- Settings ---\n"); |
2947 | 2999 | ||
2948 | x = 1 << (6 + | 3000 | x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & |
2949 | hdspm_decode_latency(hdspm-> | 3001 | HDSPM_LatencyMask)); |
2950 | control_register & | ||
2951 | HDSPM_LatencyMask)); | ||
2952 | 3002 | ||
2953 | snd_iprintf(buffer, | 3003 | snd_iprintf(buffer, |
2954 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", | 3004 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
2955 | x, (unsigned long) hdspm->period_bytes); | 3005 | x, (unsigned long) hdspm->period_bytes); |
2956 | 3006 | ||
2957 | snd_iprintf(buffer, "Line out: %s, Precise Pointer: %s\n", | 3007 | snd_iprintf(buffer, "Line out: %s, Precise Pointer: %s\n", |
2958 | (hdspm-> | 3008 | (hdspm->control_register & HDSPM_LineOut) ? "on " : "off", |
2959 | control_register & HDSPM_LineOut) ? "on " : "off", | ||
2960 | (hdspm->precise_ptr) ? "on" : "off"); | 3009 | (hdspm->precise_ptr) ? "on" : "off"); |
2961 | 3010 | ||
2962 | switch (hdspm->control_register & HDSPM_InputMask) { | 3011 | switch (hdspm->control_register & HDSPM_InputMask) { |
@@ -2984,7 +3033,8 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry, | |||
2984 | syncref); | 3033 | syncref); |
2985 | 3034 | ||
2986 | snd_iprintf(buffer, | 3035 | snd_iprintf(buffer, |
2987 | "ClearTrackMarker = %s, Transmit in %s Channel Mode, Auto Input %s\n", | 3036 | "ClearTrackMarker = %s, Transmit in %s Channel Mode, " |
3037 | "Auto Input %s\n", | ||
2988 | (hdspm-> | 3038 | (hdspm-> |
2989 | control_register & HDSPM_clr_tms) ? "on" : "off", | 3039 | control_register & HDSPM_clr_tms) ? "on" : "off", |
2990 | (hdspm-> | 3040 | (hdspm-> |
@@ -3085,7 +3135,7 @@ static void | |||
3085 | snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, | 3135 | snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, |
3086 | struct snd_info_buffer *buffer) | 3136 | struct snd_info_buffer *buffer) |
3087 | { | 3137 | { |
3088 | struct hdspm *hdspm = (struct hdspm *) entry->private_data; | 3138 | struct hdspm *hdspm = entry->private_data; |
3089 | unsigned int status; | 3139 | unsigned int status; |
3090 | unsigned int status2; | 3140 | unsigned int status2; |
3091 | unsigned int timecode; | 3141 | unsigned int timecode; |
@@ -3115,14 +3165,14 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, | |||
3115 | (status & HDSPM_midi1IRQPending) ? 1 : 0, | 3165 | (status & HDSPM_midi1IRQPending) ? 1 : 0, |
3116 | hdspm->irq_count); | 3166 | hdspm->irq_count); |
3117 | snd_iprintf(buffer, | 3167 | snd_iprintf(buffer, |
3118 | "HW pointer: id = %d, rawptr = %d (%d->%d) estimated= %ld (bytes)\n", | 3168 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
3169 | "estimated= %ld (bytes)\n", | ||
3119 | ((status & HDSPM_BufferID) ? 1 : 0), | 3170 | ((status & HDSPM_BufferID) ? 1 : 0), |
3120 | (status & HDSPM_BufferPositionMask), | 3171 | (status & HDSPM_BufferPositionMask), |
3121 | (status & HDSPM_BufferPositionMask) % (2 * | 3172 | (status & HDSPM_BufferPositionMask) % |
3122 | (int)hdspm-> | 3173 | (2 * (int)hdspm->period_bytes), |
3123 | period_bytes), | 3174 | ((status & HDSPM_BufferPositionMask) - 64) % |
3124 | ((status & HDSPM_BufferPositionMask) - | 3175 | (2 * (int)hdspm->period_bytes), |
3125 | 64) % (2 * (int)hdspm->period_bytes), | ||
3126 | (long) hdspm_hw_pointer(hdspm) * 4); | 3176 | (long) hdspm_hw_pointer(hdspm) * 4); |
3127 | 3177 | ||
3128 | snd_iprintf(buffer, | 3178 | snd_iprintf(buffer, |
@@ -3132,16 +3182,15 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, | |||
3132 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, | 3182 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, |
3133 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); | 3183 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); |
3134 | snd_iprintf(buffer, | 3184 | snd_iprintf(buffer, |
3135 | "Register: ctrl1=0x%x, status1=0x%x, status2=0x%x, timecode=0x%x\n", | 3185 | "Register: ctrl1=0x%x, status1=0x%x, status2=0x%x, " |
3186 | "timecode=0x%x\n", | ||
3136 | hdspm->control_register, | 3187 | hdspm->control_register, |
3137 | status, status2, timecode); | 3188 | status, status2, timecode); |
3138 | 3189 | ||
3139 | snd_iprintf(buffer, "--- Settings ---\n"); | 3190 | snd_iprintf(buffer, "--- Settings ---\n"); |
3140 | 3191 | ||
3141 | x = 1 << (6 + | 3192 | x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & |
3142 | hdspm_decode_latency(hdspm-> | 3193 | HDSPM_LatencyMask)); |
3143 | control_register & | ||
3144 | HDSPM_LatencyMask)); | ||
3145 | 3194 | ||
3146 | snd_iprintf(buffer, | 3195 | snd_iprintf(buffer, |
3147 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", | 3196 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
@@ -3224,14 +3273,15 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, | |||
3224 | snd_iprintf(buffer, "--- Status:\n"); | 3273 | snd_iprintf(buffer, "--- Status:\n"); |
3225 | 3274 | ||
3226 | snd_iprintf(buffer, "Word: %s Frequency: %d\n", | 3275 | snd_iprintf(buffer, "Word: %s Frequency: %d\n", |
3227 | (status & HDSPM_AES32_wcLock)? "Sync " : "No Lock", | 3276 | (status & HDSPM_AES32_wcLock)? "Sync " : "No Lock", |
3228 | HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF)); | 3277 | HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF)); |
3229 | 3278 | ||
3230 | for (x = 0; x < 8; x++) { | 3279 | for (x = 0; x < 8; x++) { |
3231 | snd_iprintf(buffer, "AES%d: %s Frequency: %d\n", | 3280 | snd_iprintf(buffer, "AES%d: %s Frequency: %d\n", |
3232 | x+1, | 3281 | x+1, |
3233 | (status2 & (HDSPM_LockAES >> x))? "Sync ": "No Lock", | 3282 | (status2 & (HDSPM_LockAES >> x)) ? |
3234 | HDSPM_bit2freq((timecode >> (4*x)) & 0xF)); | 3283 | "Sync ": "No Lock", |
3284 | HDSPM_bit2freq((timecode >> (4*x)) & 0xF)); | ||
3235 | } | 3285 | } |
3236 | 3286 | ||
3237 | switch (hdspm_autosync_ref(hdspm)) { | 3287 | switch (hdspm_autosync_ref(hdspm)) { |
@@ -3257,12 +3307,11 @@ static void | |||
3257 | snd_hdspm_proc_read_debug(struct snd_info_entry * entry, | 3307 | snd_hdspm_proc_read_debug(struct snd_info_entry * entry, |
3258 | struct snd_info_buffer *buffer) | 3308 | struct snd_info_buffer *buffer) |
3259 | { | 3309 | { |
3260 | struct hdspm *hdspm = (struct hdspm *)entry->private_data; | 3310 | struct hdspm *hdspm = entry->private_data; |
3261 | 3311 | ||
3262 | int j,i; | 3312 | int j,i; |
3263 | 3313 | ||
3264 | for (i = 0; i < 256 /* 1024*64 */; i += j) | 3314 | for (i = 0; i < 256 /* 1024*64 */; i += j) { |
3265 | { | ||
3266 | snd_iprintf(buffer, "0x%08X: ", i); | 3315 | snd_iprintf(buffer, "0x%08X: ", i); |
3267 | for (j = 0; j < 16; j += 4) | 3316 | for (j = 0; j < 16; j += 4) |
3268 | snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j)); | 3317 | snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j)); |
@@ -3305,14 +3354,20 @@ static int snd_hdspm_set_defaults(struct hdspm * hdspm) | |||
3305 | /* set defaults: */ | 3354 | /* set defaults: */ |
3306 | 3355 | ||
3307 | if (hdspm->is_aes32) | 3356 | if (hdspm->is_aes32) |
3308 | hdspm->control_register = HDSPM_ClockModeMaster | /* Master Cloack Mode on */ | 3357 | hdspm->control_register = |
3309 | hdspm_encode_latency(7) | /* latency maximum = 8192 samples */ | 3358 | HDSPM_ClockModeMaster | /* Master Cloack Mode on */ |
3359 | hdspm_encode_latency(7) | /* latency maximum = | ||
3360 | * 8192 samples | ||
3361 | */ | ||
3310 | HDSPM_SyncRef0 | /* AES1 is syncclock */ | 3362 | HDSPM_SyncRef0 | /* AES1 is syncclock */ |
3311 | HDSPM_LineOut | /* Analog output in */ | 3363 | HDSPM_LineOut | /* Analog output in */ |
3312 | HDSPM_Professional; /* Professional mode */ | 3364 | HDSPM_Professional; /* Professional mode */ |
3313 | else | 3365 | else |
3314 | hdspm->control_register = HDSPM_ClockModeMaster | /* Master Cloack Mode on */ | 3366 | hdspm->control_register = |
3315 | hdspm_encode_latency(7) | /* latency maximum = 8192 samples */ | 3367 | HDSPM_ClockModeMaster | /* Master Cloack Mode on */ |
3368 | hdspm_encode_latency(7) | /* latency maximum = | ||
3369 | * 8192 samples | ||
3370 | */ | ||
3316 | HDSPM_InputCoaxial | /* Input Coax not Optical */ | 3371 | HDSPM_InputCoaxial | /* Input Coax not Optical */ |
3317 | HDSPM_SyncRef_MADI | /* Madi is syncclock */ | 3372 | HDSPM_SyncRef_MADI | /* Madi is syncclock */ |
3318 | HDSPM_LineOut | /* Analog output in */ | 3373 | HDSPM_LineOut | /* Analog output in */ |
@@ -3343,7 +3398,8 @@ static int snd_hdspm_set_defaults(struct hdspm * hdspm) | |||
3343 | 3398 | ||
3344 | if (line_outs_monitor[hdspm->dev]) { | 3399 | if (line_outs_monitor[hdspm->dev]) { |
3345 | 3400 | ||
3346 | snd_printk(KERN_INFO "HDSPM: sending all playback streams to line outs.\n"); | 3401 | snd_printk(KERN_INFO "HDSPM: " |
3402 | "sending all playback streams to line outs.\n"); | ||
3347 | 3403 | ||
3348 | for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) { | 3404 | for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) { |
3349 | if (hdspm_write_pb_gain(hdspm, i, i, UNITY_GAIN)) | 3405 | if (hdspm_write_pb_gain(hdspm, i, i, UNITY_GAIN)) |
@@ -3392,20 +3448,16 @@ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id) | |||
3392 | if (audio) { | 3448 | if (audio) { |
3393 | 3449 | ||
3394 | if (hdspm->capture_substream) | 3450 | if (hdspm->capture_substream) |
3395 | snd_pcm_period_elapsed(hdspm->pcm-> | 3451 | snd_pcm_period_elapsed(hdspm->capture_substream); |
3396 | streams | ||
3397 | [SNDRV_PCM_STREAM_CAPTURE]. | ||
3398 | substream); | ||
3399 | 3452 | ||
3400 | if (hdspm->playback_substream) | 3453 | if (hdspm->playback_substream) |
3401 | snd_pcm_period_elapsed(hdspm->pcm-> | 3454 | snd_pcm_period_elapsed(hdspm->playback_substream); |
3402 | streams | ||
3403 | [SNDRV_PCM_STREAM_PLAYBACK]. | ||
3404 | substream); | ||
3405 | } | 3455 | } |
3406 | 3456 | ||
3407 | if (midi0 && midi0status) { | 3457 | if (midi0 && midi0status) { |
3408 | /* we disable interrupts for this input until processing is done */ | 3458 | /* we disable interrupts for this input until processing |
3459 | * is done | ||
3460 | */ | ||
3409 | hdspm->control_register &= ~HDSPM_Midi0InterruptEnable; | 3461 | hdspm->control_register &= ~HDSPM_Midi0InterruptEnable; |
3410 | hdspm_write(hdspm, HDSPM_controlRegister, | 3462 | hdspm_write(hdspm, HDSPM_controlRegister, |
3411 | hdspm->control_register); | 3463 | hdspm->control_register); |
@@ -3413,7 +3465,9 @@ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id) | |||
3413 | schedule = 1; | 3465 | schedule = 1; |
3414 | } | 3466 | } |
3415 | if (midi1 && midi1status) { | 3467 | if (midi1 && midi1status) { |
3416 | /* we disable interrupts for this input until processing is done */ | 3468 | /* we disable interrupts for this input until processing |
3469 | * is done | ||
3470 | */ | ||
3417 | hdspm->control_register &= ~HDSPM_Midi1InterruptEnable; | 3471 | hdspm->control_register &= ~HDSPM_Midi1InterruptEnable; |
3418 | hdspm_write(hdspm, HDSPM_controlRegister, | 3472 | hdspm_write(hdspm, HDSPM_controlRegister, |
3419 | hdspm->control_register); | 3473 | hdspm->control_register); |
@@ -3445,16 +3499,16 @@ static char *hdspm_channel_buffer_location(struct hdspm * hdspm, | |||
3445 | snd_assert(channel >= 0 | 3499 | snd_assert(channel >= 0 |
3446 | || channel < HDSPM_MAX_CHANNELS, return NULL); | 3500 | || channel < HDSPM_MAX_CHANNELS, return NULL); |
3447 | 3501 | ||
3448 | if ((mapped_channel = hdspm->channel_map[channel]) < 0) | 3502 | mapped_channel = hdspm->channel_map[channel]; |
3503 | if (mapped_channel < 0) | ||
3449 | return NULL; | 3504 | return NULL; |
3450 | 3505 | ||
3451 | if (stream == SNDRV_PCM_STREAM_CAPTURE) { | 3506 | if (stream == SNDRV_PCM_STREAM_CAPTURE) |
3452 | return hdspm->capture_buffer + | 3507 | return hdspm->capture_buffer + |
3453 | mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES; | 3508 | mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES; |
3454 | } else { | 3509 | else |
3455 | return hdspm->playback_buffer + | 3510 | return hdspm->playback_buffer + |
3456 | mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES; | 3511 | mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES; |
3457 | } | ||
3458 | } | 3512 | } |
3459 | 3513 | ||
3460 | 3514 | ||
@@ -3469,9 +3523,9 @@ static int snd_hdspm_playback_copy(struct snd_pcm_substream *substream, | |||
3469 | snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, | 3523 | snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, |
3470 | return -EINVAL); | 3524 | return -EINVAL); |
3471 | 3525 | ||
3472 | channel_buf = hdspm_channel_buffer_location(hdspm, | 3526 | channel_buf = |
3473 | substream->pstr-> | 3527 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, |
3474 | stream, channel); | 3528 | channel); |
3475 | 3529 | ||
3476 | snd_assert(channel_buf != NULL, return -EIO); | 3530 | snd_assert(channel_buf != NULL, return -EIO); |
3477 | 3531 | ||
@@ -3488,9 +3542,9 @@ static int snd_hdspm_capture_copy(struct snd_pcm_substream *substream, | |||
3488 | snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, | 3542 | snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4, |
3489 | return -EINVAL); | 3543 | return -EINVAL); |
3490 | 3544 | ||
3491 | channel_buf = hdspm_channel_buffer_location(hdspm, | 3545 | channel_buf = |
3492 | substream->pstr-> | 3546 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, |
3493 | stream, channel); | 3547 | channel); |
3494 | snd_assert(channel_buf != NULL, return -EIO); | 3548 | snd_assert(channel_buf != NULL, return -EIO); |
3495 | return copy_to_user(dst, channel_buf + pos * 4, count * 4); | 3549 | return copy_to_user(dst, channel_buf + pos * 4, count * 4); |
3496 | } | 3550 | } |
@@ -3503,8 +3557,8 @@ static int snd_hdspm_hw_silence(struct snd_pcm_substream *substream, | |||
3503 | char *channel_buf; | 3557 | char *channel_buf; |
3504 | 3558 | ||
3505 | channel_buf = | 3559 | channel_buf = |
3506 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, | 3560 | hdspm_channel_buffer_location(hdspm, substream->pstr->stream, |
3507 | channel); | 3561 | channel); |
3508 | snd_assert(channel_buf != NULL, return -EIO); | 3562 | snd_assert(channel_buf != NULL, return -EIO); |
3509 | memset(channel_buf + pos * 4, 0, count * 4); | 3563 | memset(channel_buf + pos * 4, 0, count * 4); |
3510 | return 0; | 3564 | return 0; |
@@ -3560,7 +3614,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3560 | other_pid = hdspm->playback_pid; | 3614 | other_pid = hdspm->playback_pid; |
3561 | } | 3615 | } |
3562 | 3616 | ||
3563 | if ((other_pid > 0) && (this_pid != other_pid)) { | 3617 | if (other_pid > 0 && this_pid != other_pid) { |
3564 | 3618 | ||
3565 | /* The other stream is open, and not by the same | 3619 | /* The other stream is open, and not by the same |
3566 | task as this one. Make sure that the parameters | 3620 | task as this one. Make sure that the parameters |
@@ -3577,7 +3631,7 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3577 | if (params_period_size(params) != hdspm->period_bytes / 4) { | 3631 | if (params_period_size(params) != hdspm->period_bytes / 4) { |
3578 | spin_unlock_irq(&hdspm->lock); | 3632 | spin_unlock_irq(&hdspm->lock); |
3579 | _snd_pcm_hw_param_setempty(params, | 3633 | _snd_pcm_hw_param_setempty(params, |
3580 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); | 3634 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
3581 | return -EBUSY; | 3635 | return -EBUSY; |
3582 | } | 3636 | } |
3583 | 3637 | ||
@@ -3588,7 +3642,8 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3588 | /* how to make sure that the rate matches an externally-set one ? */ | 3642 | /* how to make sure that the rate matches an externally-set one ? */ |
3589 | 3643 | ||
3590 | spin_lock_irq(&hdspm->lock); | 3644 | spin_lock_irq(&hdspm->lock); |
3591 | if ((err = hdspm_set_rate(hdspm, params_rate(params), 0)) < 0) { | 3645 | err = hdspm_set_rate(hdspm, params_rate(params), 0); |
3646 | if (err < 0) { | ||
3592 | spin_unlock_irq(&hdspm->lock); | 3647 | spin_unlock_irq(&hdspm->lock); |
3593 | _snd_pcm_hw_param_setempty(params, | 3648 | _snd_pcm_hw_param_setempty(params, |
3594 | SNDRV_PCM_HW_PARAM_RATE); | 3649 | SNDRV_PCM_HW_PARAM_RATE); |
@@ -3596,16 +3651,17 @@ static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, | |||
3596 | } | 3651 | } |
3597 | spin_unlock_irq(&hdspm->lock); | 3652 | spin_unlock_irq(&hdspm->lock); |
3598 | 3653 | ||
3599 | if ((err = | 3654 | err = hdspm_set_interrupt_interval(hdspm, |
3600 | hdspm_set_interrupt_interval(hdspm, | 3655 | params_period_size(params)); |
3601 | params_period_size(params))) < | 3656 | if (err < 0) { |
3602 | 0) { | ||
3603 | _snd_pcm_hw_param_setempty(params, | 3657 | _snd_pcm_hw_param_setempty(params, |
3604 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); | 3658 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
3605 | return err; | 3659 | return err; |
3606 | } | 3660 | } |
3607 | 3661 | ||
3608 | /* Memory allocation, takashi's method, dont know if we should spinlock */ | 3662 | /* Memory allocation, takashi's method, dont know if we should |
3663 | * spinlock | ||
3664 | */ | ||
3609 | /* malloc all buffer even if not enabled to get sure */ | 3665 | /* malloc all buffer even if not enabled to get sure */ |
3610 | /* Update for MADI rev 204: we need to allocate for all channels, | 3666 | /* Update for MADI rev 204: we need to allocate for all channels, |
3611 | * otherwise it doesn't work at 96kHz */ | 3667 | * otherwise it doesn't work at 96kHz */ |
@@ -3690,7 +3746,8 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream, | |||
3690 | 3746 | ||
3691 | snd_assert(info->channel < HDSPM_MAX_CHANNELS, return -EINVAL); | 3747 | snd_assert(info->channel < HDSPM_MAX_CHANNELS, return -EINVAL); |
3692 | 3748 | ||
3693 | if ((mapped_channel = hdspm->channel_map[info->channel]) < 0) | 3749 | mapped_channel = hdspm->channel_map[info->channel]; |
3750 | if (mapped_channel < 0) | ||
3694 | return -EINVAL; | 3751 | return -EINVAL; |
3695 | 3752 | ||
3696 | info->offset = mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES; | 3753 | info->offset = mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES; |
@@ -3704,15 +3761,13 @@ static int snd_hdspm_ioctl(struct snd_pcm_substream *substream, | |||
3704 | { | 3761 | { |
3705 | switch (cmd) { | 3762 | switch (cmd) { |
3706 | case SNDRV_PCM_IOCTL1_RESET: | 3763 | case SNDRV_PCM_IOCTL1_RESET: |
3707 | { | 3764 | return snd_hdspm_reset(substream); |
3708 | return snd_hdspm_reset(substream); | ||
3709 | } | ||
3710 | 3765 | ||
3711 | case SNDRV_PCM_IOCTL1_CHANNEL_INFO: | 3766 | case SNDRV_PCM_IOCTL1_CHANNEL_INFO: |
3712 | { | 3767 | { |
3713 | struct snd_pcm_channel_info *info = arg; | 3768 | struct snd_pcm_channel_info *info = arg; |
3714 | return snd_hdspm_channel_info(substream, info); | 3769 | return snd_hdspm_channel_info(substream, info); |
3715 | } | 3770 | } |
3716 | default: | 3771 | default: |
3717 | break; | 3772 | break; |
3718 | } | 3773 | } |
@@ -3923,9 +3978,12 @@ static int snd_hdspm_hw_rule_channels(struct snd_pcm_hw_params *params, | |||
3923 | } | 3978 | } |
3924 | 3979 | ||
3925 | 3980 | ||
3926 | static unsigned int hdspm_aes32_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 }; | 3981 | static unsigned int hdspm_aes32_sample_rates[] = { |
3982 | 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 | ||
3983 | }; | ||
3927 | 3984 | ||
3928 | static struct snd_pcm_hw_constraint_list hdspm_hw_constraints_aes32_sample_rates = { | 3985 | static struct snd_pcm_hw_constraint_list |
3986 | hdspm_hw_constraints_aes32_sample_rates = { | ||
3929 | .count = ARRAY_SIZE(hdspm_aes32_sample_rates), | 3987 | .count = ARRAY_SIZE(hdspm_aes32_sample_rates), |
3930 | .list = hdspm_aes32_sample_rates, | 3988 | .list = hdspm_aes32_sample_rates, |
3931 | .mask = 0 | 3989 | .mask = 0 |
@@ -4051,7 +4109,7 @@ static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep * hw, struct file *file) | |||
4051 | static int snd_hdspm_hwdep_ioctl(struct snd_hwdep * hw, struct file *file, | 4109 | static int snd_hdspm_hwdep_ioctl(struct snd_hwdep * hw, struct file *file, |
4052 | unsigned int cmd, unsigned long arg) | 4110 | unsigned int cmd, unsigned long arg) |
4053 | { | 4111 | { |
4054 | struct hdspm *hdspm = (struct hdspm *) hw->private_data; | 4112 | struct hdspm *hdspm = hw->private_data; |
4055 | struct hdspm_mixer_ioctl mixer; | 4113 | struct hdspm_mixer_ioctl mixer; |
4056 | struct hdspm_config_info info; | 4114 | struct hdspm_config_info info; |
4057 | struct hdspm_version hdspm_version; | 4115 | struct hdspm_version hdspm_version; |
@@ -4059,11 +4117,12 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep * hw, struct file *file, | |||
4059 | 4117 | ||
4060 | switch (cmd) { | 4118 | switch (cmd) { |
4061 | 4119 | ||
4062 | |||
4063 | case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS: | 4120 | case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS: |
4064 | if (copy_from_user(&rms, (void __user *)arg, sizeof(rms))) | 4121 | if (copy_from_user(&rms, (void __user *)arg, sizeof(rms))) |
4065 | return -EFAULT; | 4122 | return -EFAULT; |
4066 | /* maybe there is a chance to memorymap in future so dont touch just copy */ | 4123 | /* maybe there is a chance to memorymap in future |
4124 | * so dont touch just copy | ||
4125 | */ | ||
4067 | if(copy_to_user_fromio((void __user *)rms.peak, | 4126 | if(copy_to_user_fromio((void __user *)rms.peak, |
4068 | hdspm->iobase+HDSPM_MADI_peakrmsbase, | 4127 | hdspm->iobase+HDSPM_MADI_peakrmsbase, |
4069 | sizeof(struct hdspm_peak_rms)) != 0 ) | 4128 | sizeof(struct hdspm_peak_rms)) != 0 ) |
@@ -4075,21 +4134,16 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep * hw, struct file *file, | |||
4075 | case SNDRV_HDSPM_IOCTL_GET_CONFIG_INFO: | 4134 | case SNDRV_HDSPM_IOCTL_GET_CONFIG_INFO: |
4076 | 4135 | ||
4077 | spin_lock_irq(&hdspm->lock); | 4136 | spin_lock_irq(&hdspm->lock); |
4078 | info.pref_sync_ref = | 4137 | info.pref_sync_ref = hdspm_pref_sync_ref(hdspm); |
4079 | (unsigned char) hdspm_pref_sync_ref(hdspm); | 4138 | info.wordclock_sync_check = hdspm_wc_sync_check(hdspm); |
4080 | info.wordclock_sync_check = | ||
4081 | (unsigned char) hdspm_wc_sync_check(hdspm); | ||
4082 | 4139 | ||
4083 | info.system_sample_rate = hdspm->system_sample_rate; | 4140 | info.system_sample_rate = hdspm->system_sample_rate; |
4084 | info.autosync_sample_rate = | 4141 | info.autosync_sample_rate = |
4085 | hdspm_external_sample_rate(hdspm); | 4142 | hdspm_external_sample_rate(hdspm); |
4086 | info.system_clock_mode = | 4143 | info.system_clock_mode = hdspm_system_clock_mode(hdspm); |
4087 | (unsigned char) hdspm_system_clock_mode(hdspm); | 4144 | info.clock_source = hdspm_clock_source(hdspm); |
4088 | info.clock_source = | 4145 | info.autosync_ref = hdspm_autosync_ref(hdspm); |
4089 | (unsigned char) hdspm_clock_source(hdspm); | 4146 | info.line_out = hdspm_line_out(hdspm); |
4090 | info.autosync_ref = | ||
4091 | (unsigned char) hdspm_autosync_ref(hdspm); | ||
4092 | info.line_out = (unsigned char) hdspm_line_out(hdspm); | ||
4093 | info.passthru = 0; | 4147 | info.passthru = 0; |
4094 | spin_unlock_irq(&hdspm->lock); | 4148 | spin_unlock_irq(&hdspm->lock); |
4095 | if (copy_to_user((void __user *) arg, &info, sizeof(info))) | 4149 | if (copy_to_user((void __user *) arg, &info, sizeof(info))) |
@@ -4106,8 +4160,8 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep * hw, struct file *file, | |||
4106 | case SNDRV_HDSPM_IOCTL_GET_MIXER: | 4160 | case SNDRV_HDSPM_IOCTL_GET_MIXER: |
4107 | if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer))) | 4161 | if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer))) |
4108 | return -EFAULT; | 4162 | return -EFAULT; |
4109 | if (copy_to_user | 4163 | if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, |
4110 | ((void __user *)mixer.mixer, hdspm->mixer, sizeof(struct hdspm_mixer))) | 4164 | sizeof(struct hdspm_mixer))) |
4111 | return -EFAULT; | 4165 | return -EFAULT; |
4112 | break; | 4166 | break; |
4113 | 4167 | ||
@@ -4150,7 +4204,8 @@ static int __devinit snd_hdspm_create_hwdep(struct snd_card *card, | |||
4150 | struct snd_hwdep *hw; | 4204 | struct snd_hwdep *hw; |
4151 | int err; | 4205 | int err; |
4152 | 4206 | ||
4153 | if ((err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw)) < 0) | 4207 | err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw); |
4208 | if (err < 0) | ||
4154 | return err; | 4209 | return err; |
4155 | 4210 | ||
4156 | hdspm->hwdep = hw; | 4211 | hdspm->hwdep = hw; |
@@ -4176,15 +4231,15 @@ static int __devinit snd_hdspm_preallocate_memory(struct hdspm * hdspm) | |||
4176 | 4231 | ||
4177 | pcm = hdspm->pcm; | 4232 | pcm = hdspm->pcm; |
4178 | 4233 | ||
4179 | /* wanted = HDSPM_DMA_AREA_BYTES + 4096;*/ /* dont know why, but it works */ | ||
4180 | wanted = HDSPM_DMA_AREA_BYTES; | 4234 | wanted = HDSPM_DMA_AREA_BYTES; |
4181 | 4235 | ||
4182 | if ((err = | 4236 | err = |
4183 | snd_pcm_lib_preallocate_pages_for_all(pcm, | 4237 | snd_pcm_lib_preallocate_pages_for_all(pcm, |
4184 | SNDRV_DMA_TYPE_DEV_SG, | 4238 | SNDRV_DMA_TYPE_DEV_SG, |
4185 | snd_dma_pci_data(hdspm->pci), | 4239 | snd_dma_pci_data(hdspm->pci), |
4186 | wanted, | 4240 | wanted, |
4187 | wanted)) < 0) { | 4241 | wanted); |
4242 | if (err < 0) { | ||
4188 | snd_printdd("Could not preallocate %zd Bytes\n", wanted); | 4243 | snd_printdd("Could not preallocate %zd Bytes\n", wanted); |
4189 | 4244 | ||
4190 | return err; | 4245 | return err; |
@@ -4200,8 +4255,7 @@ static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf, | |||
4200 | int i; | 4255 | int i; |
4201 | for (i = 0; i < (channels * 16); i++) | 4256 | for (i = 0; i < (channels * 16); i++) |
4202 | hdspm_write(hdspm, reg + 4 * i, | 4257 | hdspm_write(hdspm, reg + 4 * i, |
4203 | snd_pcm_sgbuf_get_addr(sgbuf, | 4258 | snd_pcm_sgbuf_get_addr(sgbuf, (size_t) 4096 * i)); |
4204 | (size_t) 4096 * i)); | ||
4205 | } | 4259 | } |
4206 | 4260 | ||
4207 | /* ------------- ALSA Devices ---------------------------- */ | 4261 | /* ------------- ALSA Devices ---------------------------- */ |
@@ -4211,7 +4265,8 @@ static int __devinit snd_hdspm_create_pcm(struct snd_card *card, | |||
4211 | struct snd_pcm *pcm; | 4265 | struct snd_pcm *pcm; |
4212 | int err; | 4266 | int err; |
4213 | 4267 | ||
4214 | if ((err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm)) < 0) | 4268 | err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm); |
4269 | if (err < 0) | ||
4215 | return err; | 4270 | return err; |
4216 | 4271 | ||
4217 | hdspm->pcm = pcm; | 4272 | hdspm->pcm = pcm; |
@@ -4225,7 +4280,8 @@ static int __devinit snd_hdspm_create_pcm(struct snd_card *card, | |||
4225 | 4280 | ||
4226 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; | 4281 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
4227 | 4282 | ||
4228 | if ((err = snd_hdspm_preallocate_memory(hdspm)) < 0) | 4283 | err = snd_hdspm_preallocate_memory(hdspm); |
4284 | if (err < 0) | ||
4229 | return err; | 4285 | return err; |
4230 | 4286 | ||
4231 | return 0; | 4287 | return 0; |
@@ -4243,19 +4299,24 @@ static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card, | |||
4243 | int err; | 4299 | int err; |
4244 | 4300 | ||
4245 | snd_printdd("Create card...\n"); | 4301 | snd_printdd("Create card...\n"); |
4246 | if ((err = snd_hdspm_create_pcm(card, hdspm)) < 0) | 4302 | err = snd_hdspm_create_pcm(card, hdspm); |
4303 | if (err < 0) | ||
4247 | return err; | 4304 | return err; |
4248 | 4305 | ||
4249 | if ((err = snd_hdspm_create_midi(card, hdspm, 0)) < 0) | 4306 | err = snd_hdspm_create_midi(card, hdspm, 0); |
4307 | if (err < 0) | ||
4250 | return err; | 4308 | return err; |
4251 | 4309 | ||
4252 | if ((err = snd_hdspm_create_midi(card, hdspm, 1)) < 0) | 4310 | err = snd_hdspm_create_midi(card, hdspm, 1); |
4311 | if (err < 0) | ||
4253 | return err; | 4312 | return err; |
4254 | 4313 | ||
4255 | if ((err = snd_hdspm_create_controls(card, hdspm)) < 0) | 4314 | err = snd_hdspm_create_controls(card, hdspm); |
4315 | if (err < 0) | ||
4256 | return err; | 4316 | return err; |
4257 | 4317 | ||
4258 | if ((err = snd_hdspm_create_hwdep(card, hdspm)) < 0) | 4318 | err = snd_hdspm_create_hwdep(card, hdspm); |
4319 | if (err < 0) | ||
4259 | return err; | 4320 | return err; |
4260 | 4321 | ||
4261 | snd_printdd("proc init...\n"); | 4322 | snd_printdd("proc init...\n"); |
@@ -4270,7 +4331,8 @@ static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card, | |||
4270 | hdspm->playback_substream = NULL; | 4331 | hdspm->playback_substream = NULL; |
4271 | 4332 | ||
4272 | snd_printdd("Set defaults...\n"); | 4333 | snd_printdd("Set defaults...\n"); |
4273 | if ((err = snd_hdspm_set_defaults(hdspm)) < 0) | 4334 | err = snd_hdspm_set_defaults(hdspm); |
4335 | if (err < 0) | ||
4274 | return err; | 4336 | return err; |
4275 | 4337 | ||
4276 | snd_printdd("Update mixer controls...\n"); | 4338 | snd_printdd("Update mixer controls...\n"); |
@@ -4278,7 +4340,8 @@ static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card, | |||
4278 | 4340 | ||
4279 | snd_printdd("Initializeing complete ???\n"); | 4341 | snd_printdd("Initializeing complete ???\n"); |
4280 | 4342 | ||
4281 | if ((err = snd_card_register(card)) < 0) { | 4343 | err = snd_card_register(card); |
4344 | if (err < 0) { | ||
4282 | snd_printk(KERN_ERR "HDSPM: error registering card\n"); | 4345 | snd_printk(KERN_ERR "HDSPM: error registering card\n"); |
4283 | return err; | 4346 | return err; |
4284 | } | 4347 | } |
@@ -4288,36 +4351,18 @@ static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card, | |||
4288 | return 0; | 4351 | return 0; |
4289 | } | 4352 | } |
4290 | 4353 | ||
4291 | static int __devinit snd_hdspm_create(struct snd_card *card, struct hdspm * hdspm, | 4354 | static int __devinit snd_hdspm_create(struct snd_card *card, |
4355 | struct hdspm *hdspm, | ||
4292 | int precise_ptr, int enable_monitor) | 4356 | int precise_ptr, int enable_monitor) |
4293 | { | 4357 | { |
4294 | struct pci_dev *pci = hdspm->pci; | 4358 | struct pci_dev *pci = hdspm->pci; |
4295 | int err; | 4359 | int err; |
4296 | int i; | ||
4297 | |||
4298 | unsigned long io_extent; | 4360 | unsigned long io_extent; |
4299 | 4361 | ||
4300 | hdspm->irq = -1; | 4362 | hdspm->irq = -1; |
4301 | hdspm->irq_count = 0; | 4363 | |
4302 | |||
4303 | hdspm->midi[0].rmidi = NULL; | ||
4304 | hdspm->midi[1].rmidi = NULL; | ||
4305 | hdspm->midi[0].input = NULL; | ||
4306 | hdspm->midi[1].input = NULL; | ||
4307 | hdspm->midi[0].output = NULL; | ||
4308 | hdspm->midi[1].output = NULL; | ||
4309 | spin_lock_init(&hdspm->midi[0].lock); | 4364 | spin_lock_init(&hdspm->midi[0].lock); |
4310 | spin_lock_init(&hdspm->midi[1].lock); | 4365 | spin_lock_init(&hdspm->midi[1].lock); |
4311 | hdspm->iobase = NULL; | ||
4312 | hdspm->control_register = 0; | ||
4313 | hdspm->control2_register = 0; | ||
4314 | |||
4315 | hdspm->playback_buffer = NULL; | ||
4316 | hdspm->capture_buffer = NULL; | ||
4317 | |||
4318 | for (i = 0; i < HDSPM_MAX_CHANNELS; ++i) | ||
4319 | hdspm->playback_mixer_ctls[i] = NULL; | ||
4320 | hdspm->mixer = NULL; | ||
4321 | 4366 | ||
4322 | hdspm->card = card; | 4367 | hdspm->card = card; |
4323 | 4368 | ||
@@ -4340,12 +4385,14 @@ static int __devinit snd_hdspm_create(struct snd_card *card, struct hdspm * hdsp | |||
4340 | hdspm->card_name = "RME HDSPM MADI"; | 4385 | hdspm->card_name = "RME HDSPM MADI"; |
4341 | } | 4386 | } |
4342 | 4387 | ||
4343 | if ((err = pci_enable_device(pci)) < 0) | 4388 | err = pci_enable_device(pci); |
4389 | if (err < 0) | ||
4344 | return err; | 4390 | return err; |
4345 | 4391 | ||
4346 | pci_set_master(hdspm->pci); | 4392 | pci_set_master(hdspm->pci); |
4347 | 4393 | ||
4348 | if ((err = pci_request_regions(pci, "hdspm")) < 0) | 4394 | err = pci_request_regions(pci, "hdspm"); |
4395 | if (err < 0) | ||
4349 | return err; | 4396 | return err; |
4350 | 4397 | ||
4351 | hdspm->port = pci_resource_start(pci, 0); | 4398 | hdspm->port = pci_resource_start(pci, 0); |
@@ -4355,8 +4402,10 @@ static int __devinit snd_hdspm_create(struct snd_card *card, struct hdspm * hdsp | |||
4355 | hdspm->port, hdspm->port + io_extent - 1); | 4402 | hdspm->port, hdspm->port + io_extent - 1); |
4356 | 4403 | ||
4357 | 4404 | ||
4358 | if ((hdspm->iobase = ioremap_nocache(hdspm->port, io_extent)) == NULL) { | 4405 | hdspm->iobase = ioremap_nocache(hdspm->port, io_extent); |
4359 | snd_printk(KERN_ERR "HDSPM: unable to remap region 0x%lx-0x%lx\n", | 4406 | if (!hdspm->iobase) { |
4407 | snd_printk(KERN_ERR "HDSPM: " | ||
4408 | "unable to remap region 0x%lx-0x%lx\n", | ||
4360 | hdspm->port, hdspm->port + io_extent - 1); | 4409 | hdspm->port, hdspm->port + io_extent - 1); |
4361 | return -EBUSY; | 4410 | return -EBUSY; |
4362 | } | 4411 | } |
@@ -4379,9 +4428,10 @@ static int __devinit snd_hdspm_create(struct snd_card *card, struct hdspm * hdsp | |||
4379 | 4428 | ||
4380 | snd_printdd("kmalloc Mixer memory of %zd Bytes\n", | 4429 | snd_printdd("kmalloc Mixer memory of %zd Bytes\n", |
4381 | sizeof(struct hdspm_mixer)); | 4430 | sizeof(struct hdspm_mixer)); |
4382 | if ((hdspm->mixer = kmalloc(sizeof(struct hdspm_mixer), GFP_KERNEL)) | 4431 | hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL); |
4383 | == NULL) { | 4432 | if (!hdspm->mixer) { |
4384 | snd_printk(KERN_ERR "HDSPM: unable to kmalloc Mixer memory of %d Bytes\n", | 4433 | snd_printk(KERN_ERR "HDSPM: " |
4434 | "unable to kmalloc Mixer memory of %d Bytes\n", | ||
4385 | (int)sizeof(struct hdspm_mixer)); | 4435 | (int)sizeof(struct hdspm_mixer)); |
4386 | return err; | 4436 | return err; |
4387 | } | 4437 | } |
@@ -4391,7 +4441,8 @@ static int __devinit snd_hdspm_create(struct snd_card *card, struct hdspm * hdsp | |||
4391 | hdspm->qs_channels = MADI_QS_CHANNELS; | 4441 | hdspm->qs_channels = MADI_QS_CHANNELS; |
4392 | 4442 | ||
4393 | snd_printdd("create alsa devices.\n"); | 4443 | snd_printdd("create alsa devices.\n"); |
4394 | if ((err = snd_hdspm_create_alsa_devices(card, hdspm)) < 0) | 4444 | err = snd_hdspm_create_alsa_devices(card, hdspm); |
4445 | if (err < 0) | ||
4395 | return err; | 4446 | return err; |
4396 | 4447 | ||
4397 | snd_hdspm_initialize_midi_flush(hdspm); | 4448 | snd_hdspm_initialize_midi_flush(hdspm); |
@@ -4406,9 +4457,8 @@ static int snd_hdspm_free(struct hdspm * hdspm) | |||
4406 | 4457 | ||
4407 | /* stop th audio, and cancel all interrupts */ | 4458 | /* stop th audio, and cancel all interrupts */ |
4408 | hdspm->control_register &= | 4459 | hdspm->control_register &= |
4409 | ~(HDSPM_Start | HDSPM_AudioInterruptEnable | 4460 | ~(HDSPM_Start | HDSPM_AudioInterruptEnable | |
4410 | | HDSPM_Midi0InterruptEnable | | 4461 | HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable); |
4411 | HDSPM_Midi1InterruptEnable); | ||
4412 | hdspm_write(hdspm, HDSPM_controlRegister, | 4462 | hdspm_write(hdspm, HDSPM_controlRegister, |
4413 | hdspm->control_register); | 4463 | hdspm->control_register); |
4414 | } | 4464 | } |
@@ -4416,7 +4466,6 @@ static int snd_hdspm_free(struct hdspm * hdspm) | |||
4416 | if (hdspm->irq >= 0) | 4466 | if (hdspm->irq >= 0) |
4417 | free_irq(hdspm->irq, (void *) hdspm); | 4467 | free_irq(hdspm->irq, (void *) hdspm); |
4418 | 4468 | ||
4419 | |||
4420 | kfree(hdspm->mixer); | 4469 | kfree(hdspm->mixer); |
4421 | 4470 | ||
4422 | if (hdspm->iobase) | 4471 | if (hdspm->iobase) |
@@ -4431,7 +4480,7 @@ static int snd_hdspm_free(struct hdspm * hdspm) | |||
4431 | 4480 | ||
4432 | static void snd_hdspm_card_free(struct snd_card *card) | 4481 | static void snd_hdspm_card_free(struct snd_card *card) |
4433 | { | 4482 | { |
4434 | struct hdspm *hdspm = (struct hdspm *) card->private_data; | 4483 | struct hdspm *hdspm = card->private_data; |
4435 | 4484 | ||
4436 | if (hdspm) | 4485 | if (hdspm) |
4437 | snd_hdspm_free(hdspm); | 4486 | snd_hdspm_free(hdspm); |
@@ -4452,20 +4501,21 @@ static int __devinit snd_hdspm_probe(struct pci_dev *pci, | |||
4452 | return -ENOENT; | 4501 | return -ENOENT; |
4453 | } | 4502 | } |
4454 | 4503 | ||
4455 | if (!(card = snd_card_new(index[dev], id[dev], | 4504 | card = snd_card_new(index[dev], id[dev], |
4456 | THIS_MODULE, sizeof(struct hdspm)))) | 4505 | THIS_MODULE, sizeof(struct hdspm)); |
4506 | if (!card) | ||
4457 | return -ENOMEM; | 4507 | return -ENOMEM; |
4458 | 4508 | ||
4459 | hdspm = (struct hdspm *) card->private_data; | 4509 | hdspm = card->private_data; |
4460 | card->private_free = snd_hdspm_card_free; | 4510 | card->private_free = snd_hdspm_card_free; |
4461 | hdspm->dev = dev; | 4511 | hdspm->dev = dev; |
4462 | hdspm->pci = pci; | 4512 | hdspm->pci = pci; |
4463 | 4513 | ||
4464 | snd_card_set_dev(card, &pci->dev); | 4514 | snd_card_set_dev(card, &pci->dev); |
4465 | 4515 | ||
4466 | if ((err = | 4516 | err = snd_hdspm_create(card, hdspm, precise_ptr[dev], |
4467 | snd_hdspm_create(card, hdspm, precise_ptr[dev], | 4517 | enable_monitor[dev]); |
4468 | enable_monitor[dev])) < 0) { | 4518 | if (err < 0) { |
4469 | snd_card_free(card); | 4519 | snd_card_free(card); |
4470 | return err; | 4520 | return err; |
4471 | } | 4521 | } |
@@ -4474,7 +4524,8 @@ static int __devinit snd_hdspm_probe(struct pci_dev *pci, | |||
4474 | sprintf(card->longname, "%s at 0x%lx, irq %d", hdspm->card_name, | 4524 | sprintf(card->longname, "%s at 0x%lx, irq %d", hdspm->card_name, |
4475 | hdspm->port, hdspm->irq); | 4525 | hdspm->port, hdspm->irq); |
4476 | 4526 | ||
4477 | if ((err = snd_card_register(card)) < 0) { | 4527 | err = snd_card_register(card); |
4528 | if (err < 0) { | ||
4478 | snd_card_free(card); | 4529 | snd_card_free(card); |
4479 | return err; | 4530 | return err; |
4480 | } | 4531 | } |