aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/pci/rme9652/hdsp.c588
1 files changed, 217 insertions, 371 deletions
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 52525eb198c7..845158b01b02 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -671,11 +671,7 @@ static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
671 } 671 }
672 } 672 }
673 673
674 if ((1000 / HZ) < 3000) { 674 ssleep(3);
675 ssleep(3);
676 } else {
677 mdelay(3000);
678 }
679 675
680 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 676 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
681 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n"); 677 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
@@ -692,7 +688,7 @@ static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
692 688
693 } 689 }
694 if (hdsp->state & HDSP_InitializationComplete) { 690 if (hdsp->state & HDSP_InitializationComplete) {
695 snd_printk("Hammerfall-DSP: firmware loaded from cache, restoring defaults\n"); 691 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
696 spin_lock_irqsave(&hdsp->lock, flags); 692 spin_lock_irqsave(&hdsp->lock, flags);
697 snd_hdsp_set_defaults(hdsp); 693 snd_hdsp_set_defaults(hdsp);
698 spin_unlock_irqrestore(&hdsp->lock, flags); 694 spin_unlock_irqrestore(&hdsp->lock, flags);
@@ -709,9 +705,8 @@ static int hdsp_get_iobox_version (hdsp_t *hdsp)
709 705
710 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM); 706 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
711 hdsp_write (hdsp, HDSP_fifoData, 0); 707 hdsp_write (hdsp, HDSP_fifoData, 0);
712 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) { 708 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
713 return -EIO; 709 return -EIO;
714 }
715 710
716 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 711 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
717 hdsp_write (hdsp, HDSP_fifoData, 0); 712 hdsp_write (hdsp, HDSP_fifoData, 0);
@@ -726,22 +721,30 @@ static int hdsp_get_iobox_version (hdsp_t *hdsp)
726 } 721 }
727 } else { 722 } else {
728 /* firmware was already loaded, get iobox type */ 723 /* firmware was already loaded, get iobox type */
729 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) { 724 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
730 hdsp->io_type = Multiface; 725 hdsp->io_type = Multiface;
731 } else { 726 else
732 hdsp->io_type = Digiface; 727 hdsp->io_type = Digiface;
733 }
734 } 728 }
735 return 0; 729 return 0;
736} 730}
737 731
738 732
739static int hdsp_check_for_firmware (hdsp_t *hdsp) 733static int hdsp_check_for_firmware (hdsp_t *hdsp, int show_err)
740{ 734{
741 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; 735 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
742 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 736 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
743 snd_printk("Hammerfall-DSP: firmware not present.\n"); 737 snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n");
744 hdsp->state &= ~HDSP_FirmwareLoaded; 738 hdsp->state &= ~HDSP_FirmwareLoaded;
739 if (! show_err)
740 return -EIO;
741 /* try to load firmware */
742 if (hdsp->state & HDSP_FirmwareCached) {
743 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0)
744 snd_printk(KERN_ERR "Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
745 } else {
746 snd_printk(KERN_ERR "Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
747 }
745 return -EIO; 748 return -EIO;
746 } 749 }
747 return 0; 750 return 0;
@@ -775,9 +778,9 @@ static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
775 778
776static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr) 779static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
777{ 780{
778 if (addr >= HDSP_MATRIX_MIXER_SIZE) { 781 if (addr >= HDSP_MATRIX_MIXER_SIZE)
779 return 0; 782 return 0;
780 } 783
781 return hdsp->mixer_matrix[addr]; 784 return hdsp->mixer_matrix[addr];
782} 785}
783 786
@@ -802,13 +805,11 @@ static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
802 memory." 805 memory."
803 */ 806 */
804 807
805 if (hdsp->io_type == H9632 && addr >= 512) { 808 if (hdsp->io_type == H9632 && addr >= 512)
806 return 0; 809 return 0;
807 }
808 810
809 if (hdsp->io_type == H9652 && addr >= 1352) { 811 if (hdsp->io_type == H9652 && addr >= 1352)
810 return 0; 812 return 0;
811 }
812 813
813 hdsp->mixer_matrix[addr] = data; 814 hdsp->mixer_matrix[addr] = data;
814 815
@@ -832,9 +833,8 @@ static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
832 833
833 ad = (addr << 16) + data; 834 ad = (addr << 16) + data;
834 835
835 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) { 836 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
836 return -1; 837 return -1;
837 }
838 838
839 hdsp_write (hdsp, HDSP_fifoData, ad); 839 hdsp_write (hdsp, HDSP_fifoData, ad);
840 hdsp->mixer_matrix[addr] = data; 840 hdsp->mixer_matrix[addr] = data;
@@ -851,9 +851,8 @@ static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
851 851
852 spin_lock_irqsave(&hdsp->lock, flags); 852 spin_lock_irqsave(&hdsp->lock, flags);
853 if ((hdsp->playback_pid != hdsp->capture_pid) && 853 if ((hdsp->playback_pid != hdsp->capture_pid) &&
854 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) { 854 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
855 ret = 0; 855 ret = 0;
856 }
857 spin_unlock_irqrestore(&hdsp->lock, flags); 856 spin_unlock_irqrestore(&hdsp->lock, flags);
858 return ret; 857 return ret;
859} 858}
@@ -880,9 +879,8 @@ static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
880 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister); 879 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
881 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask); 880 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
882 881
883 if (status & HDSP_SPDIFErrorFlag) { 882 if (status & HDSP_SPDIFErrorFlag)
884 return 0; 883 return 0;
885 }
886 884
887 switch (rate_bits) { 885 switch (rate_bits) {
888 case HDSP_spdifFrequency32KHz: return 32000; 886 case HDSP_spdifFrequency32KHz: return 32000;
@@ -918,9 +916,8 @@ static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
918 916
919 position = hdsp_read(hdsp, HDSP_statusRegister); 917 position = hdsp_read(hdsp, HDSP_statusRegister);
920 918
921 if (!hdsp->precise_ptr) { 919 if (!hdsp->precise_ptr)
922 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0; 920 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
923 }
924 921
925 position &= HDSP_BufferPositionMask; 922 position &= HDSP_BufferPositionMask;
926 position /= 4; 923 position /= 4;
@@ -989,19 +986,19 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
989 if (!(hdsp->control_register & HDSP_ClockModeMaster)) { 986 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
990 if (called_internally) { 987 if (called_internally) {
991 /* request from ctl or card initialization */ 988 /* request from ctl or card initialization */
992 snd_printk("Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n"); 989 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
993 return -1; 990 return -1;
994 } else { 991 } else {
995 /* hw_param request while in AutoSync mode */ 992 /* hw_param request while in AutoSync mode */
996 int external_freq = hdsp_external_sample_rate(hdsp); 993 int external_freq = hdsp_external_sample_rate(hdsp);
997 int spdif_freq = hdsp_spdif_sample_rate(hdsp); 994 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
998 995
999 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) { 996 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1000 snd_printk("Hammerfall-DSP: Detected ADAT in double speed mode\n"); 997 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
1001 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) { 998 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1002 snd_printk("Hammerfall-DSP: Detected ADAT in quad speed mode\n"); 999 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1003 } else if (rate != external_freq) { 1000 else if (rate != external_freq) {
1004 snd_printk("Hammerfall-DSP: No AutoSync source for requested rate\n"); 1001 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
1005 return -1; 1002 return -1;
1006 } 1003 }
1007 } 1004 }
@@ -1019,63 +1016,53 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1019 exists for externally-driven rate changes. All we can do 1016 exists for externally-driven rate changes. All we can do
1020 is to flag rate changes in the read/write routines. */ 1017 is to flag rate changes in the read/write routines. */
1021 1018
1022 if (rate > 96000 && hdsp->io_type != H9632) { 1019 if (rate > 96000 && hdsp->io_type != H9632)
1023 return -EINVAL; 1020 return -EINVAL;
1024 }
1025 1021
1026 switch (rate) { 1022 switch (rate) {
1027 case 32000: 1023 case 32000:
1028 if (current_rate > 48000) { 1024 if (current_rate > 48000)
1029 reject_if_open = 1; 1025 reject_if_open = 1;
1030 }
1031 rate_bits = HDSP_Frequency32KHz; 1026 rate_bits = HDSP_Frequency32KHz;
1032 break; 1027 break;
1033 case 44100: 1028 case 44100:
1034 if (current_rate > 48000) { 1029 if (current_rate > 48000)
1035 reject_if_open = 1; 1030 reject_if_open = 1;
1036 }
1037 rate_bits = HDSP_Frequency44_1KHz; 1031 rate_bits = HDSP_Frequency44_1KHz;
1038 break; 1032 break;
1039 case 48000: 1033 case 48000:
1040 if (current_rate > 48000) { 1034 if (current_rate > 48000)
1041 reject_if_open = 1; 1035 reject_if_open = 1;
1042 }
1043 rate_bits = HDSP_Frequency48KHz; 1036 rate_bits = HDSP_Frequency48KHz;
1044 break; 1037 break;
1045 case 64000: 1038 case 64000:
1046 if (current_rate <= 48000 || current_rate > 96000) { 1039 if (current_rate <= 48000 || current_rate > 96000)
1047 reject_if_open = 1; 1040 reject_if_open = 1;
1048 }
1049 rate_bits = HDSP_Frequency64KHz; 1041 rate_bits = HDSP_Frequency64KHz;
1050 break; 1042 break;
1051 case 88200: 1043 case 88200:
1052 if (current_rate <= 48000 || current_rate > 96000) { 1044 if (current_rate <= 48000 || current_rate > 96000)
1053 reject_if_open = 1; 1045 reject_if_open = 1;
1054 }
1055 rate_bits = HDSP_Frequency88_2KHz; 1046 rate_bits = HDSP_Frequency88_2KHz;
1056 break; 1047 break;
1057 case 96000: 1048 case 96000:
1058 if (current_rate <= 48000 || current_rate > 96000) { 1049 if (current_rate <= 48000 || current_rate > 96000)
1059 reject_if_open = 1; 1050 reject_if_open = 1;
1060 }
1061 rate_bits = HDSP_Frequency96KHz; 1051 rate_bits = HDSP_Frequency96KHz;
1062 break; 1052 break;
1063 case 128000: 1053 case 128000:
1064 if (current_rate < 128000) { 1054 if (current_rate < 128000)
1065 reject_if_open = 1; 1055 reject_if_open = 1;
1066 }
1067 rate_bits = HDSP_Frequency128KHz; 1056 rate_bits = HDSP_Frequency128KHz;
1068 break; 1057 break;
1069 case 176400: 1058 case 176400:
1070 if (current_rate < 128000) { 1059 if (current_rate < 128000)
1071 reject_if_open = 1; 1060 reject_if_open = 1;
1072 }
1073 rate_bits = HDSP_Frequency176_4KHz; 1061 rate_bits = HDSP_Frequency176_4KHz;
1074 break; 1062 break;
1075 case 192000: 1063 case 192000:
1076 if (current_rate < 128000) { 1064 if (current_rate < 128000)
1077 reject_if_open = 1; 1065 reject_if_open = 1;
1078 }
1079 rate_bits = HDSP_Frequency192KHz; 1066 rate_bits = HDSP_Frequency192KHz;
1080 break; 1067 break;
1081 default: 1068 default:
@@ -1096,11 +1083,10 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1096 if (rate >= 128000) { 1083 if (rate >= 128000) {
1097 hdsp->channel_map = channel_map_H9632_qs; 1084 hdsp->channel_map = channel_map_H9632_qs;
1098 } else if (rate > 48000) { 1085 } else if (rate > 48000) {
1099 if (hdsp->io_type == H9632) { 1086 if (hdsp->io_type == H9632)
1100 hdsp->channel_map = channel_map_H9632_ds; 1087 hdsp->channel_map = channel_map_H9632_ds;
1101 } else { 1088 else
1102 hdsp->channel_map = channel_map_ds; 1089 hdsp->channel_map = channel_map_ds;
1103 }
1104 } else { 1090 } else {
1105 switch (hdsp->io_type) { 1091 switch (hdsp->io_type) {
1106 case Multiface: 1092 case Multiface:
@@ -1131,54 +1117,48 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1131static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id) 1117static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1132{ 1118{
1133 /* the hardware already does the relevant bit-mask with 0xff */ 1119 /* the hardware already does the relevant bit-mask with 0xff */
1134 if (id) { 1120 if (id)
1135 return hdsp_read(hdsp, HDSP_midiDataIn1); 1121 return hdsp_read(hdsp, HDSP_midiDataIn1);
1136 } else { 1122 else
1137 return hdsp_read(hdsp, HDSP_midiDataIn0); 1123 return hdsp_read(hdsp, HDSP_midiDataIn0);
1138 }
1139} 1124}
1140 1125
1141static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val) 1126static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1142{ 1127{
1143 /* the hardware already does the relevant bit-mask with 0xff */ 1128 /* the hardware already does the relevant bit-mask with 0xff */
1144 if (id) { 1129 if (id)
1145 hdsp_write(hdsp, HDSP_midiDataOut1, val); 1130 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1146 } else { 1131 else
1147 hdsp_write(hdsp, HDSP_midiDataOut0, val); 1132 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1148 }
1149} 1133}
1150 1134
1151static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id) 1135static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1152{ 1136{
1153 if (id) { 1137 if (id)
1154 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff); 1138 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1155 } else { 1139 else
1156 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff); 1140 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1157 }
1158} 1141}
1159 1142
1160static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id) 1143static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1161{ 1144{
1162 int fifo_bytes_used; 1145 int fifo_bytes_used;
1163 1146
1164 if (id) { 1147 if (id)
1165 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff; 1148 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1166 } else { 1149 else
1167 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff; 1150 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1168 }
1169 1151
1170 if (fifo_bytes_used < 128) { 1152 if (fifo_bytes_used < 128)
1171 return 128 - fifo_bytes_used; 1153 return 128 - fifo_bytes_used;
1172 } else { 1154 else
1173 return 0; 1155 return 0;
1174 }
1175} 1156}
1176 1157
1177static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id) 1158static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1178{ 1159{
1179 while (snd_hdsp_midi_input_available (hdsp, id)) { 1160 while (snd_hdsp_midi_input_available (hdsp, id))
1180 snd_hdsp_midi_read_byte (hdsp, id); 1161 snd_hdsp_midi_read_byte (hdsp, id);
1181 }
1182} 1162}
1183 1163
1184static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi) 1164static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
@@ -1219,28 +1199,23 @@ static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1219 spin_lock_irqsave (&hmidi->lock, flags); 1199 spin_lock_irqsave (&hmidi->lock, flags);
1220 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) { 1200 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1221 if (hmidi->input) { 1201 if (hmidi->input) {
1222 if (n_pending > (int)sizeof (buf)) { 1202 if (n_pending > (int)sizeof (buf))
1223 n_pending = sizeof (buf); 1203 n_pending = sizeof (buf);
1224 } 1204 for (i = 0; i < n_pending; ++i)
1225 for (i = 0; i < n_pending; ++i) {
1226 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); 1205 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1227 } 1206 if (n_pending)
1228 if (n_pending) {
1229 snd_rawmidi_receive (hmidi->input, buf, n_pending); 1207 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1230 }
1231 } else { 1208 } else {
1232 /* flush the MIDI input FIFO */ 1209 /* flush the MIDI input FIFO */
1233 while (--n_pending) { 1210 while (--n_pending)
1234 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); 1211 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1235 }
1236 } 1212 }
1237 } 1213 }
1238 hmidi->pending = 0; 1214 hmidi->pending = 0;
1239 if (hmidi->id) { 1215 if (hmidi->id)
1240 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable; 1216 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1241 } else { 1217 else
1242 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable; 1218 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1243 }
1244 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register); 1219 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1245 spin_unlock_irqrestore (&hmidi->lock, flags); 1220 spin_unlock_irqrestore (&hmidi->lock, flags);
1246 return snd_hdsp_midi_output_write (hmidi); 1221 return snd_hdsp_midi_output_write (hmidi);
@@ -1310,9 +1285,8 @@ static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, in
1310 hmidi->istimer++; 1285 hmidi->istimer++;
1311 } 1286 }
1312 } else { 1287 } else {
1313 if (hmidi->istimer && --hmidi->istimer <= 0) { 1288 if (hmidi->istimer && --hmidi->istimer <= 0)
1314 del_timer (&hmidi->timer); 1289 del_timer (&hmidi->timer);
1315 }
1316 } 1290 }
1317 spin_unlock_irqrestore (&hmidi->lock, flags); 1291 spin_unlock_irqrestore (&hmidi->lock, flags);
1318 if (up) 1292 if (up)
@@ -1400,9 +1374,8 @@ static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int i
1400 spin_lock_init (&hdsp->midi[id].lock); 1374 spin_lock_init (&hdsp->midi[id].lock);
1401 1375
1402 sprintf (buf, "%s MIDI %d", card->shortname, id+1); 1376 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1403 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) { 1377 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1404 return -1; 1378 return -1;
1405 }
1406 1379
1407 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1); 1380 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1408 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id]; 1381 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
@@ -1588,11 +1561,10 @@ static int hdsp_spdif_out(hdsp_t *hdsp)
1588 1561
1589static int hdsp_set_spdif_output(hdsp_t *hdsp, int out) 1562static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1590{ 1563{
1591 if (out) { 1564 if (out)
1592 hdsp->control_register |= HDSP_SPDIFOpticalOut; 1565 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1593 } else { 1566 else
1594 hdsp->control_register &= ~HDSP_SPDIFOpticalOut; 1567 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1595 }
1596 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1568 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1597 return 0; 1569 return 0;
1598} 1570}
@@ -1642,11 +1614,10 @@ static int hdsp_spdif_professional(hdsp_t *hdsp)
1642 1614
1643static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val) 1615static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1644{ 1616{
1645 if (val) { 1617 if (val)
1646 hdsp->control_register |= HDSP_SPDIFProfessional; 1618 hdsp->control_register |= HDSP_SPDIFProfessional;
1647 } else { 1619 else
1648 hdsp->control_register &= ~HDSP_SPDIFProfessional; 1620 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1649 }
1650 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1621 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1651 return 0; 1622 return 0;
1652} 1623}
@@ -1687,11 +1658,10 @@ static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1687 1658
1688static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val) 1659static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1689{ 1660{
1690 if (val) { 1661 if (val)
1691 hdsp->control_register |= HDSP_SPDIFEmphasis; 1662 hdsp->control_register |= HDSP_SPDIFEmphasis;
1692 } else { 1663 else
1693 hdsp->control_register &= ~HDSP_SPDIFEmphasis; 1664 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1694 }
1695 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1665 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1696 return 0; 1666 return 0;
1697} 1667}
@@ -1732,11 +1702,10 @@ static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1732 1702
1733static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val) 1703static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1734{ 1704{
1735 if (val) { 1705 if (val)
1736 hdsp->control_register |= HDSP_SPDIFNonAudio; 1706 hdsp->control_register |= HDSP_SPDIFNonAudio;
1737 } else { 1707 else
1738 hdsp->control_register &= ~HDSP_SPDIFNonAudio; 1708 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1739 }
1740 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1709 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1741 return 0; 1710 return 0;
1742} 1711}
@@ -1921,11 +1890,10 @@ static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_
1921 1890
1922static int hdsp_system_clock_mode(hdsp_t *hdsp) 1891static int hdsp_system_clock_mode(hdsp_t *hdsp)
1923{ 1892{
1924 if (hdsp->control_register & HDSP_ClockModeMaster) { 1893 if (hdsp->control_register & HDSP_ClockModeMaster)
1925 return 0; 1894 return 0;
1926 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) { 1895 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1927 return 0; 1896 return 0;
1928 }
1929 return 1; 1897 return 1;
1930} 1898}
1931 1899
@@ -2074,16 +2042,17 @@ static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_val
2074 val = ucontrol->value.enumerated.item[0]; 2042 val = ucontrol->value.enumerated.item[0];
2075 if (val < 0) val = 0; 2043 if (val < 0) val = 0;
2076 if (hdsp->io_type == H9632) { 2044 if (hdsp->io_type == H9632) {
2077 if (val > 9) val = 9; 2045 if (val > 9)
2046 val = 9;
2078 } else { 2047 } else {
2079 if (val > 6) val = 6; 2048 if (val > 6)
2049 val = 6;
2080 } 2050 }
2081 spin_lock_irq(&hdsp->lock); 2051 spin_lock_irq(&hdsp->lock);
2082 if (val != hdsp_clock_source(hdsp)) { 2052 if (val != hdsp_clock_source(hdsp))
2083 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0; 2053 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2084 } else { 2054 else
2085 change = 0; 2055 change = 0;
2086 }
2087 spin_unlock_irq(&hdsp->lock); 2056 spin_unlock_irq(&hdsp->lock);
2088 return change; 2057 return change;
2089} 2058}
@@ -2193,11 +2162,10 @@ static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2193 if (val < 0) val = 0; 2162 if (val < 0) val = 0;
2194 if (val > 2) val = 2; 2163 if (val > 2) val = 2;
2195 spin_lock_irq(&hdsp->lock); 2164 spin_lock_irq(&hdsp->lock);
2196 if (val != hdsp_da_gain(hdsp)) { 2165 if (val != hdsp_da_gain(hdsp))
2197 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0; 2166 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2198 } else { 2167 else
2199 change = 0; 2168 change = 0;
2200 }
2201 spin_unlock_irq(&hdsp->lock); 2169 spin_unlock_irq(&hdsp->lock);
2202 return change; 2170 return change;
2203} 2171}
@@ -2279,11 +2247,10 @@ static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2279 if (val < 0) val = 0; 2247 if (val < 0) val = 0;
2280 if (val > 2) val = 2; 2248 if (val > 2) val = 2;
2281 spin_lock_irq(&hdsp->lock); 2249 spin_lock_irq(&hdsp->lock);
2282 if (val != hdsp_ad_gain(hdsp)) { 2250 if (val != hdsp_ad_gain(hdsp))
2283 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0; 2251 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2284 } else { 2252 else
2285 change = 0; 2253 change = 0;
2286 }
2287 spin_unlock_irq(&hdsp->lock); 2254 spin_unlock_irq(&hdsp->lock);
2288 return change; 2255 return change;
2289} 2256}
@@ -2365,11 +2332,10 @@ static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
2365 if (val < 0) val = 0; 2332 if (val < 0) val = 0;
2366 if (val > 2) val = 2; 2333 if (val > 2) val = 2;
2367 spin_lock_irq(&hdsp->lock); 2334 spin_lock_irq(&hdsp->lock);
2368 if (val != hdsp_phone_gain(hdsp)) { 2335 if (val != hdsp_phone_gain(hdsp))
2369 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0; 2336 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2370 } else { 2337 else
2371 change = 0; 2338 change = 0;
2372 }
2373 spin_unlock_irq(&hdsp->lock); 2339 spin_unlock_irq(&hdsp->lock);
2374 return change; 2340 return change;
2375} 2341}
@@ -2385,19 +2351,17 @@ static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
2385 2351
2386static int hdsp_xlr_breakout_cable(hdsp_t *hdsp) 2352static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2387{ 2353{
2388 if (hdsp->control_register & HDSP_XLRBreakoutCable) { 2354 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2389 return 1; 2355 return 1;
2390 }
2391 return 0; 2356 return 0;
2392} 2357}
2393 2358
2394static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode) 2359static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2395{ 2360{
2396 if (mode) { 2361 if (mode)
2397 hdsp->control_register |= HDSP_XLRBreakoutCable; 2362 hdsp->control_register |= HDSP_XLRBreakoutCable;
2398 } else { 2363 else
2399 hdsp->control_register &= ~HDSP_XLRBreakoutCable; 2364 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2400 }
2401 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2365 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2402 return 0; 2366 return 0;
2403} 2367}
@@ -2450,19 +2414,17 @@ static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_el
2450 2414
2451static int hdsp_aeb(hdsp_t *hdsp) 2415static int hdsp_aeb(hdsp_t *hdsp)
2452{ 2416{
2453 if (hdsp->control_register & HDSP_AnalogExtensionBoard) { 2417 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2454 return 1; 2418 return 1;
2455 }
2456 return 0; 2419 return 0;
2457} 2420}
2458 2421
2459static int hdsp_set_aeb(hdsp_t *hdsp, int mode) 2422static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2460{ 2423{
2461 if (mode) { 2424 if (mode)
2462 hdsp->control_register |= HDSP_AnalogExtensionBoard; 2425 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2463 } else { 2426 else
2464 hdsp->control_register &= ~HDSP_AnalogExtensionBoard; 2427 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2465 }
2466 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2428 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2467 return 0; 2429 return 0;
2468} 2430}
@@ -2705,11 +2667,10 @@ static int hdsp_line_out(hdsp_t *hdsp)
2705 2667
2706static int hdsp_set_line_output(hdsp_t *hdsp, int out) 2668static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2707{ 2669{
2708 if (out) { 2670 if (out)
2709 hdsp->control_register |= HDSP_LineOut; 2671 hdsp->control_register |= HDSP_LineOut;
2710 } else { 2672 else
2711 hdsp->control_register &= ~HDSP_LineOut; 2673 hdsp->control_register &= ~HDSP_LineOut;
2712 }
2713 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2674 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2714 return 0; 2675 return 0;
2715} 2676}
@@ -2760,11 +2721,10 @@ static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2760 2721
2761static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise) 2722static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise)
2762{ 2723{
2763 if (precise) { 2724 if (precise)
2764 hdsp->precise_ptr = 1; 2725 hdsp->precise_ptr = 1;
2765 } else { 2726 else
2766 hdsp->precise_ptr = 0; 2727 hdsp->precise_ptr = 0;
2767 }
2768 return 0; 2728 return 0;
2769} 2729}
2770 2730
@@ -2814,11 +2774,10 @@ static int snd_hdsp_put_precise_pointer(snd_kcontrol_t * kcontrol, snd_ctl_elem_
2814 2774
2815static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet) 2775static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet)
2816{ 2776{
2817 if (use_tasklet) { 2777 if (use_tasklet)
2818 hdsp->use_midi_tasklet = 1; 2778 hdsp->use_midi_tasklet = 1;
2819 } else { 2779 else
2820 hdsp->use_midi_tasklet = 0; 2780 hdsp->use_midi_tasklet = 0;
2821 }
2822 return 0; 2781 return 0;
2823} 2782}
2824 2783
@@ -2889,11 +2848,10 @@ static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
2889 source = ucontrol->value.integer.value[0]; 2848 source = ucontrol->value.integer.value[0];
2890 destination = ucontrol->value.integer.value[1]; 2849 destination = ucontrol->value.integer.value[1];
2891 2850
2892 if (source >= hdsp->max_channels) { 2851 if (source >= hdsp->max_channels)
2893 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination); 2852 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2894 } else { 2853 else
2895 addr = hdsp_input_to_output_key(hdsp,source, destination); 2854 addr = hdsp_input_to_output_key(hdsp,source, destination);
2896 }
2897 2855
2898 spin_lock_irq(&hdsp->lock); 2856 spin_lock_irq(&hdsp->lock);
2899 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr); 2857 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
@@ -2916,11 +2874,10 @@ static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
2916 source = ucontrol->value.integer.value[0]; 2874 source = ucontrol->value.integer.value[0];
2917 destination = ucontrol->value.integer.value[1]; 2875 destination = ucontrol->value.integer.value[1];
2918 2876
2919 if (source >= hdsp->max_channels) { 2877 if (source >= hdsp->max_channels)
2920 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination); 2878 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2921 } else { 2879 else
2922 addr = hdsp_input_to_output_key(hdsp,source, destination); 2880 addr = hdsp_input_to_output_key(hdsp,source, destination);
2923 }
2924 2881
2925 gain = ucontrol->value.integer.value[2]; 2882 gain = ucontrol->value.integer.value[2];
2926 2883
@@ -2957,14 +2914,12 @@ static int hdsp_wc_sync_check(hdsp_t *hdsp)
2957{ 2914{
2958 int status2 = hdsp_read(hdsp, HDSP_status2Register); 2915 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2959 if (status2 & HDSP_wc_lock) { 2916 if (status2 & HDSP_wc_lock) {
2960 if (status2 & HDSP_wc_sync) { 2917 if (status2 & HDSP_wc_sync)
2961 return 2; 2918 return 2;
2962 } else { 2919 else
2963 return 1; 2920 return 1;
2964 } 2921 } else
2965 } else {
2966 return 0; 2922 return 0;
2967 }
2968 return 0; 2923 return 0;
2969} 2924}
2970 2925
@@ -2988,14 +2943,13 @@ static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
2988static int hdsp_spdif_sync_check(hdsp_t *hdsp) 2943static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2989{ 2944{
2990 int status = hdsp_read(hdsp, HDSP_statusRegister); 2945 int status = hdsp_read(hdsp, HDSP_statusRegister);
2991 if (status & HDSP_SPDIFErrorFlag) { 2946 if (status & HDSP_SPDIFErrorFlag)
2992 return 0; 2947 return 0;
2993 } else { 2948 else {
2994 if (status & HDSP_SPDIFSync) { 2949 if (status & HDSP_SPDIFSync)
2995 return 2; 2950 return 2;
2996 } else { 2951 else
2997 return 1; 2952 return 1;
2998 }
2999 } 2953 }
3000 return 0; 2954 return 0;
3001} 2955}
@@ -3021,14 +2975,12 @@ static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3021{ 2975{
3022 int status = hdsp_read(hdsp, HDSP_statusRegister); 2976 int status = hdsp_read(hdsp, HDSP_statusRegister);
3023 if (status & HDSP_TimecodeLock) { 2977 if (status & HDSP_TimecodeLock) {
3024 if (status & HDSP_TimecodeSync) { 2978 if (status & HDSP_TimecodeSync)
3025 return 2; 2979 return 2;
3026 } else { 2980 else
3027 return 1; 2981 return 1;
3028 } 2982 } else
3029 } else {
3030 return 0; 2983 return 0;
3031 }
3032} 2984}
3033 2985
3034static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 2986static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
@@ -3051,14 +3003,12 @@ static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3051 int status = hdsp_read(hdsp, HDSP_statusRegister); 3003 int status = hdsp_read(hdsp, HDSP_statusRegister);
3052 3004
3053 if (status & (HDSP_Lock0>>idx)) { 3005 if (status & (HDSP_Lock0>>idx)) {
3054 if (status & (HDSP_Sync0>>idx)) { 3006 if (status & (HDSP_Sync0>>idx))
3055 return 2; 3007 return 2;
3056 } else { 3008 else
3057 return 1; 3009 return 1;
3058 } 3010 } else
3059 } else {
3060 return 0; 3011 return 0;
3061 }
3062} 3012}
3063 3013
3064static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 3014static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
@@ -3171,9 +3121,8 @@ static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3171 snd_kcontrol_t *kctl; 3121 snd_kcontrol_t *kctl;
3172 3122
3173 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) { 3123 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3174 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) { 3124 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3175 return err; 3125 return err;
3176 }
3177 if (idx == 1) /* IEC958 (S/PDIF) Stream */ 3126 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3178 hdsp->spdif_ctl = kctl; 3127 hdsp->spdif_ctl = kctl;
3179 } 3128 }
@@ -3181,32 +3130,28 @@ static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3181 /* ADAT SyncCheck status */ 3130 /* ADAT SyncCheck status */
3182 snd_hdsp_adat_sync_check.name = "ADAT Lock Status"; 3131 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3183 snd_hdsp_adat_sync_check.index = 1; 3132 snd_hdsp_adat_sync_check.index = 1;
3184 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) { 3133 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3185 return err; 3134 return err;
3186 }
3187 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 3135 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3188 for (idx = 1; idx < 3; ++idx) { 3136 for (idx = 1; idx < 3; ++idx) {
3189 snd_hdsp_adat_sync_check.index = idx+1; 3137 snd_hdsp_adat_sync_check.index = idx+1;
3190 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) { 3138 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3191 return err; 3139 return err;
3192 }
3193 } 3140 }
3194 } 3141 }
3195 3142
3196 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */ 3143 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3197 if (hdsp->io_type == H9632) { 3144 if (hdsp->io_type == H9632) {
3198 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) { 3145 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3199 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) { 3146 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3200 return err; 3147 return err;
3201 }
3202 } 3148 }
3203 } 3149 }
3204 3150
3205 /* AEB control for H96xx card */ 3151 /* AEB control for H96xx card */
3206 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { 3152 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3207 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) { 3153 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3208 return err; 3154 return err;
3209 }
3210 } 3155 }
3211 3156
3212 return 0; 3157 return 0;
@@ -3228,12 +3173,11 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3228 char *clock_source; 3173 char *clock_source;
3229 int x; 3174 int x;
3230 3175
3231 if (hdsp_check_for_iobox (hdsp)) { 3176 if (hdsp_check_for_iobox (hdsp))
3232 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n"); 3177 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3233 return; 3178 return;
3234 }
3235 3179
3236 if (hdsp_check_for_firmware(hdsp)) { 3180 if (hdsp_check_for_firmware(hdsp, 0)) {
3237 if (hdsp->state & HDSP_FirmwareCached) { 3181 if (hdsp->state & HDSP_FirmwareCached) {
3238 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { 3182 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3239 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n"); 3183 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
@@ -3314,11 +3258,10 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3314 } 3258 }
3315 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source); 3259 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3316 3260
3317 if (hdsp_system_clock_mode(hdsp)) { 3261 if (hdsp_system_clock_mode(hdsp))
3318 system_clock_mode = "Slave"; 3262 system_clock_mode = "Slave";
3319 } else { 3263 else
3320 system_clock_mode = "Master"; 3264 system_clock_mode = "Master";
3321 }
3322 3265
3323 switch (hdsp_pref_sync_ref (hdsp)) { 3266 switch (hdsp_pref_sync_ref (hdsp)) {
3324 case HDSP_SYNC_FROM_WORD: 3267 case HDSP_SYNC_FROM_WORD:
@@ -3400,85 +3343,75 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3400 break; 3343 break;
3401 } 3344 }
3402 3345
3403 if (hdsp->control_register & HDSP_SPDIFOpticalOut) { 3346 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3404 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n"); 3347 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3405 } else { 3348 else
3406 snd_iprintf(buffer, "IEC958 output: Coaxial only\n"); 3349 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3407 }
3408 3350
3409 if (hdsp->control_register & HDSP_SPDIFProfessional) { 3351 if (hdsp->control_register & HDSP_SPDIFProfessional)
3410 snd_iprintf(buffer, "IEC958 quality: Professional\n"); 3352 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3411 } else { 3353 else
3412 snd_iprintf(buffer, "IEC958 quality: Consumer\n"); 3354 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3413 }
3414 3355
3415 if (hdsp->control_register & HDSP_SPDIFEmphasis) { 3356 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3416 snd_iprintf(buffer, "IEC958 emphasis: on\n"); 3357 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3417 } else { 3358 else
3418 snd_iprintf(buffer, "IEC958 emphasis: off\n"); 3359 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3419 }
3420 3360
3421 if (hdsp->control_register & HDSP_SPDIFNonAudio) { 3361 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3422 snd_iprintf(buffer, "IEC958 NonAudio: on\n"); 3362 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3423 } else { 3363 else
3424 snd_iprintf(buffer, "IEC958 NonAudio: off\n"); 3364 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3425 } 3365 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0)
3426 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
3427 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x); 3366 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3428 } else { 3367 else
3429 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n"); 3368 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3430 }
3431 3369
3432 snd_iprintf(buffer, "\n"); 3370 snd_iprintf(buffer, "\n");
3433 3371
3434 /* Sync Check */ 3372 /* Sync Check */
3435 x = status & HDSP_Sync0; 3373 x = status & HDSP_Sync0;
3436 if (status & HDSP_Lock0) { 3374 if (status & HDSP_Lock0)
3437 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock"); 3375 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3438 } else { 3376 else
3439 snd_iprintf(buffer, "ADAT1: No Lock\n"); 3377 snd_iprintf(buffer, "ADAT1: No Lock\n");
3440 }
3441 3378
3442 switch (hdsp->io_type) { 3379 switch (hdsp->io_type) {
3443 case Digiface: 3380 case Digiface:
3444 case H9652: 3381 case H9652:
3445 x = status & HDSP_Sync1; 3382 x = status & HDSP_Sync1;
3446 if (status & HDSP_Lock1) { 3383 if (status & HDSP_Lock1)
3447 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock"); 3384 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3448 } else { 3385 else
3449 snd_iprintf(buffer, "ADAT2: No Lock\n"); 3386 snd_iprintf(buffer, "ADAT2: No Lock\n");
3450 }
3451 x = status & HDSP_Sync2; 3387 x = status & HDSP_Sync2;
3452 if (status & HDSP_Lock2) { 3388 if (status & HDSP_Lock2)
3453 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock"); 3389 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3454 } else { 3390 else
3455 snd_iprintf(buffer, "ADAT3: No Lock\n"); 3391 snd_iprintf(buffer, "ADAT3: No Lock\n");
3456 } 3392 break;
3457 default: 3393 default:
3458 /* relax */ 3394 /* relax */
3459 break; 3395 break;
3460 } 3396 }
3461 3397
3462 x = status & HDSP_SPDIFSync; 3398 x = status & HDSP_SPDIFSync;
3463 if (status & HDSP_SPDIFErrorFlag) { 3399 if (status & HDSP_SPDIFErrorFlag)
3464 snd_iprintf (buffer, "SPDIF: No Lock\n"); 3400 snd_iprintf (buffer, "SPDIF: No Lock\n");
3465 } else { 3401 else
3466 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock"); 3402 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3467 }
3468 3403
3469 x = status2 & HDSP_wc_sync; 3404 x = status2 & HDSP_wc_sync;
3470 if (status2 & HDSP_wc_lock) { 3405 if (status2 & HDSP_wc_lock)
3471 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock"); 3406 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3472 } else { 3407 else
3473 snd_iprintf (buffer, "Word Clock: No Lock\n"); 3408 snd_iprintf (buffer, "Word Clock: No Lock\n");
3474 }
3475 3409
3476 x = status & HDSP_TimecodeSync; 3410 x = status & HDSP_TimecodeSync;
3477 if (status & HDSP_TimecodeLock) { 3411 if (status & HDSP_TimecodeLock)
3478 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock"); 3412 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3479 } else { 3413 else
3480 snd_iprintf(buffer, "ADAT Sync: No Lock\n"); 3414 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3481 }
3482 3415
3483 snd_iprintf(buffer, "\n"); 3416 snd_iprintf(buffer, "\n");
3484 3417
@@ -3527,11 +3460,10 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3527 3460
3528 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no"); 3461 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3529 3462
3530 if (hdsp->control_register & HDSP_AnalogExtensionBoard) { 3463 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3531 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n"); 3464 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3532 } else { 3465 else
3533 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n"); 3466 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3534 }
3535 snd_iprintf(buffer, "\n"); 3467 snd_iprintf(buffer, "\n");
3536 } 3468 }
3537 3469
@@ -3610,25 +3542,22 @@ static int snd_hdsp_set_defaults(hdsp_t *hdsp)
3610#else 3542#else
3611 hdsp->control2_register = 0; 3543 hdsp->control2_register = 0;
3612#endif 3544#endif
3613 if (hdsp->io_type == H9652) { 3545 if (hdsp->io_type == H9652)
3614 snd_hdsp_9652_enable_mixer (hdsp); 3546 snd_hdsp_9652_enable_mixer (hdsp);
3615 } else { 3547 else
3616 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); 3548 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3617 }
3618 3549
3619 hdsp_reset_hw_pointer(hdsp); 3550 hdsp_reset_hw_pointer(hdsp);
3620 hdsp_compute_period_size(hdsp); 3551 hdsp_compute_period_size(hdsp);
3621 3552
3622 /* silence everything */ 3553 /* silence everything */
3623 3554
3624 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) { 3555 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
3625 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN; 3556 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3626 }
3627 3557
3628 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) { 3558 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3629 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) { 3559 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3630 return -EIO; 3560 return -EIO;
3631 }
3632 } 3561 }
3633 3562
3634 /* H9632 specific defaults */ 3563 /* H9632 specific defaults */
@@ -3649,12 +3578,10 @@ static void hdsp_midi_tasklet(unsigned long arg)
3649{ 3578{
3650 hdsp_t *hdsp = (hdsp_t *)arg; 3579 hdsp_t *hdsp = (hdsp_t *)arg;
3651 3580
3652 if (hdsp->midi[0].pending) { 3581 if (hdsp->midi[0].pending)
3653 snd_hdsp_midi_input_read (&hdsp->midi[0]); 3582 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3654 } 3583 if (hdsp->midi[1].pending)
3655 if (hdsp->midi[1].pending) {
3656 snd_hdsp_midi_input_read (&hdsp->midi[1]); 3584 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3657 }
3658} 3585}
3659 3586
3660static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs) 3587static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -3674,9 +3601,8 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *reg
3674 midi0 = status & HDSP_midi0IRQPending; 3601 midi0 = status & HDSP_midi0IRQPending;
3675 midi1 = status & HDSP_midi1IRQPending; 3602 midi1 = status & HDSP_midi1IRQPending;
3676 3603
3677 if (!audio && !midi0 && !midi1) { 3604 if (!audio && !midi0 && !midi1)
3678 return IRQ_NONE; 3605 return IRQ_NONE;
3679 }
3680 3606
3681 hdsp_write(hdsp, HDSP_interruptConfirmation, 0); 3607 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3682 3608
@@ -3684,13 +3610,11 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *reg
3684 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff; 3610 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3685 3611
3686 if (audio) { 3612 if (audio) {
3687 if (hdsp->capture_substream) { 3613 if (hdsp->capture_substream)
3688 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 3614 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3689 }
3690 3615
3691 if (hdsp->playback_substream) { 3616 if (hdsp->playback_substream)
3692 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream); 3617 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3693 }
3694 } 3618 }
3695 3619
3696 if (midi0 && midi0status) { 3620 if (midi0 && midi0status) {
@@ -3735,15 +3659,13 @@ static char *hdsp_channel_buffer_location(hdsp_t *hdsp,
3735 3659
3736 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL); 3660 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3737 3661
3738 if ((mapped_channel = hdsp->channel_map[channel]) < 0) { 3662 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3739 return NULL; 3663 return NULL;
3740 }
3741 3664
3742 if (stream == SNDRV_PCM_STREAM_CAPTURE) { 3665 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3743 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); 3666 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3744 } else { 3667 else
3745 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); 3668 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3746 }
3747} 3669}
3748 3670
3749static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel, 3671static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel,
@@ -3824,20 +3746,11 @@ static int snd_hdsp_hw_params(snd_pcm_substream_t *substream,
3824 pid_t this_pid; 3746 pid_t this_pid;
3825 pid_t other_pid; 3747 pid_t other_pid;
3826 3748
3827 if (hdsp_check_for_iobox (hdsp)) { 3749 if (hdsp_check_for_iobox (hdsp))
3828 return -EIO; 3750 return -EIO;
3829 }
3830 3751
3831 if (hdsp_check_for_firmware(hdsp)) { 3752 if (hdsp_check_for_firmware(hdsp, 1))
3832 if (hdsp->state & HDSP_FirmwareCached) {
3833 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3834 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3835 }
3836 } else {
3837 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3838 }
3839 return -EIO; 3753 return -EIO;
3840 }
3841 3754
3842 spin_lock_irq(&hdsp->lock); 3755 spin_lock_irq(&hdsp->lock);
3843 3756
@@ -3908,9 +3821,8 @@ static int snd_hdsp_channel_info(snd_pcm_substream_t *substream,
3908 3821
3909 snd_assert(info->channel < hdsp->max_channels, return -EINVAL); 3822 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3910 3823
3911 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) { 3824 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
3912 return -EINVAL; 3825 return -EINVAL;
3913 }
3914 3826
3915 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES; 3827 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3916 info->first = 0; 3828 info->first = 0;
@@ -3923,14 +3835,9 @@ static int snd_hdsp_ioctl(snd_pcm_substream_t *substream,
3923{ 3835{
3924 switch (cmd) { 3836 switch (cmd) {
3925 case SNDRV_PCM_IOCTL1_RESET: 3837 case SNDRV_PCM_IOCTL1_RESET:
3926 {
3927 return snd_hdsp_reset(substream); 3838 return snd_hdsp_reset(substream);
3928 }
3929 case SNDRV_PCM_IOCTL1_CHANNEL_INFO: 3839 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3930 { 3840 return snd_hdsp_channel_info(substream, arg);
3931 snd_pcm_channel_info_t *info = arg;
3932 return snd_hdsp_channel_info(substream, info);
3933 }
3934 default: 3841 default:
3935 break; 3842 break;
3936 } 3843 }
@@ -3944,20 +3851,11 @@ static int snd_hdsp_trigger(snd_pcm_substream_t *substream, int cmd)
3944 snd_pcm_substream_t *other; 3851 snd_pcm_substream_t *other;
3945 int running; 3852 int running;
3946 3853
3947 if (hdsp_check_for_iobox (hdsp)) { 3854 if (hdsp_check_for_iobox (hdsp))
3948 return -EIO; 3855 return -EIO;
3949 }
3950 3856
3951 if (hdsp_check_for_firmware(hdsp)) { 3857 if (hdsp_check_for_firmware(hdsp, 1))
3952 if (hdsp->state & HDSP_FirmwareCached) {
3953 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3954 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3955 }
3956 } else {
3957 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3958 }
3959 return -EIO; 3858 return -EIO;
3960 }
3961 3859
3962 spin_lock(&hdsp->lock); 3860 spin_lock(&hdsp->lock);
3963 running = hdsp->running; 3861 running = hdsp->running;
@@ -4022,20 +3920,11 @@ static int snd_hdsp_prepare(snd_pcm_substream_t *substream)
4022 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 3920 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4023 int result = 0; 3921 int result = 0;
4024 3922
4025 if (hdsp_check_for_iobox (hdsp)) { 3923 if (hdsp_check_for_iobox (hdsp))
4026 return -EIO; 3924 return -EIO;
4027 }
4028 3925
4029 if (hdsp_check_for_firmware(hdsp)) { 3926 if (hdsp_check_for_firmware(hdsp, 1))
4030 if (hdsp->state & HDSP_FirmwareCached) {
4031 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4032 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4033 }
4034 } else {
4035 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4036 }
4037 return -EIO; 3927 return -EIO;
4038 }
4039 3928
4040 spin_lock_irq(&hdsp->lock); 3929 spin_lock_irq(&hdsp->lock);
4041 if (!hdsp->running) 3930 if (!hdsp->running)
@@ -4285,20 +4174,11 @@ static int snd_hdsp_playback_open(snd_pcm_substream_t *substream)
4285 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 4174 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4286 snd_pcm_runtime_t *runtime = substream->runtime; 4175 snd_pcm_runtime_t *runtime = substream->runtime;
4287 4176
4288 if (hdsp_check_for_iobox (hdsp)) { 4177 if (hdsp_check_for_iobox (hdsp))
4289 return -EIO; 4178 return -EIO;
4290 }
4291 4179
4292 if (hdsp_check_for_firmware(hdsp)) { 4180 if (hdsp_check_for_firmware(hdsp, 1))
4293 if (hdsp->state & HDSP_FirmwareCached) {
4294 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4295 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4296 }
4297 } else {
4298 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4299 }
4300 return -EIO; 4181 return -EIO;
4301 }
4302 4182
4303 spin_lock_irq(&hdsp->lock); 4183 spin_lock_irq(&hdsp->lock);
4304 4184
@@ -4367,20 +4247,11 @@ static int snd_hdsp_capture_open(snd_pcm_substream_t *substream)
4367 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 4247 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4368 snd_pcm_runtime_t *runtime = substream->runtime; 4248 snd_pcm_runtime_t *runtime = substream->runtime;
4369 4249
4370 if (hdsp_check_for_iobox (hdsp)) { 4250 if (hdsp_check_for_iobox (hdsp))
4371 return -EIO; 4251 return -EIO;
4372 }
4373 4252
4374 if (hdsp_check_for_firmware(hdsp)) { 4253 if (hdsp_check_for_firmware(hdsp, 1))
4375 if (hdsp->state & HDSP_FirmwareCached) {
4376 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4377 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4378 }
4379 } else {
4380 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4381 }
4382 return -EIO; 4254 return -EIO;
4383 }
4384 4255
4385 spin_lock_irq(&hdsp->lock); 4256 spin_lock_irq(&hdsp->lock);
4386 4257
@@ -4589,19 +4460,17 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4589 int i; 4460 int i;
4590 4461
4591 if (!(hdsp->state & HDSP_FirmwareLoaded)) { 4462 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4592 snd_printk("Hammerfall-DSP: Firmware needs to be uploaded to the card.\n"); 4463 snd_printk(KERN_ERR "Hammerfall-DSP: Firmware needs to be uploaded to the card.\n");
4593 return -EINVAL; 4464 return -EINVAL;
4594 } 4465 }
4595 spin_lock_irqsave(&hdsp->lock, flags); 4466 spin_lock_irqsave(&hdsp->lock, flags);
4596 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp); 4467 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4597 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp); 4468 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4598 if (hdsp->io_type != H9632) { 4469 if (hdsp->io_type != H9632)
4599 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); 4470 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4600 }
4601 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); 4471 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4602 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i) { 4472 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i)
4603 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 4473 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4604 }
4605 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 4474 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4606 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp); 4475 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4607 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp); 4476 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
@@ -4621,9 +4490,8 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4621 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp); 4490 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4622 4491
4623 } 4492 }
4624 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { 4493 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4625 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp); 4494 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4626 }
4627 spin_unlock_irqrestore(&hdsp->lock, flags); 4495 spin_unlock_irqrestore(&hdsp->lock, flags);
4628 if (copy_to_user(argp, &info, sizeof(info))) 4496 if (copy_to_user(argp, &info, sizeof(info)))
4629 return -EFAULT; 4497 return -EFAULT;
@@ -4645,15 +4513,13 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4645 4513
4646 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4514 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4647 if (hdsp->io_type == Undefined) { 4515 if (hdsp->io_type == Undefined) {
4648 if ((err = hdsp_get_iobox_version(hdsp)) < 0) { 4516 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4649 return err; 4517 return err;
4650 }
4651 } 4518 }
4652 hdsp_version.io_type = hdsp->io_type; 4519 hdsp_version.io_type = hdsp->io_type;
4653 hdsp_version.firmware_rev = hdsp->firmware_rev; 4520 hdsp_version.firmware_rev = hdsp->firmware_rev;
4654 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) { 4521 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
4655 return -EFAULT; 4522 return -EFAULT;
4656 }
4657 break; 4523 break;
4658 } 4524 }
4659 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { 4525 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
@@ -4668,38 +4534,33 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4668 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) 4534 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4669 return -EBUSY; 4535 return -EBUSY;
4670 4536
4671 snd_printk("Hammerfall-DSP: initializing firmware upload\n"); 4537 snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n");
4672 firmware = (hdsp_firmware_t __user *)argp; 4538 firmware = (hdsp_firmware_t __user *)argp;
4673 4539
4674 if (get_user(firmware_data, &firmware->firmware_data)) { 4540 if (get_user(firmware_data, &firmware->firmware_data))
4675 return -EFAULT; 4541 return -EFAULT;
4676 }
4677 4542
4678 if (hdsp_check_for_iobox (hdsp)) { 4543 if (hdsp_check_for_iobox (hdsp))
4679 return -EIO; 4544 return -EIO;
4680 }
4681 4545
4682 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) { 4546 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
4683 return -EFAULT; 4547 return -EFAULT;
4684 }
4685 4548
4686 hdsp->state |= HDSP_FirmwareCached; 4549 hdsp->state |= HDSP_FirmwareCached;
4687 4550
4688 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) { 4551 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4689 return err; 4552 return err;
4690 }
4691 4553
4692 if (!(hdsp->state & HDSP_InitializationComplete)) { 4554 if (!(hdsp->state & HDSP_InitializationComplete)) {
4693 if ((err = snd_hdsp_enable_io(hdsp)) < 0) { 4555 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4694 return err; 4556 return err;
4695 }
4696 4557
4697 snd_hdsp_initialize_channels(hdsp); 4558 snd_hdsp_initialize_channels(hdsp);
4698 snd_hdsp_initialize_midi_flush(hdsp); 4559 snd_hdsp_initialize_midi_flush(hdsp);
4699 4560
4700 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4561 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4701 snd_printk("Hammerfall-DSP: error creating alsa devices\n"); 4562 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4702 return err; 4563 return err;
4703 } 4564 }
4704 } 4565 }
4705 break; 4566 break;
@@ -4790,7 +4651,7 @@ static int snd_hdsp_enable_io (hdsp_t *hdsp)
4790 int i; 4651 int i;
4791 4652
4792 if (hdsp_fifo_wait (hdsp, 0, 100)) { 4653 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4793 snd_printk("Hammerfall-DSP: enable_io fifo_wait failed\n"); 4654 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n");
4794 return -EIO; 4655 return -EIO;
4795 } 4656 }
4796 4657
@@ -4856,25 +4717,25 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4856 int err; 4717 int err;
4857 4718
4858 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) { 4719 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4859 snd_printk("Hammerfall-DSP: Error creating pcm interface\n"); 4720 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n");
4860 return err; 4721 return err;
4861 } 4722 }
4862 4723
4863 4724
4864 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) { 4725 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4865 snd_printk("Hammerfall-DSP: Error creating first midi interface\n"); 4726 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n");
4866 return err; 4727 return err;
4867 } 4728 }
4868 4729
4869 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 4730 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
4870 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) { 4731 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4871 snd_printk("Hammerfall-DSP: Error creating second midi interface\n"); 4732 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n");
4872 return err; 4733 return err;
4873 } 4734 }
4874 } 4735 }
4875 4736
4876 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) { 4737 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4877 snd_printk("Hammerfall-DSP: Error creating ctl interface\n"); 4738 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n");
4878 return err; 4739 return err;
4879 } 4740 }
4880 4741
@@ -4887,7 +4748,7 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4887 hdsp->playback_substream = NULL; 4748 hdsp->playback_substream = NULL;
4888 4749
4889 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) { 4750 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4890 snd_printk("Hammerfall-DSP: Error setting default values\n"); 4751 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n");
4891 return err; 4752 return err;
4892 } 4753 }
4893 4754
@@ -4897,7 +4758,7 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4897 hdsp->port, hdsp->irq); 4758 hdsp->port, hdsp->irq);
4898 4759
4899 if ((err = snd_card_register(card)) < 0) { 4760 if ((err = snd_card_register(card)) < 0) {
4900 snd_printk("Hammerfall-DSP: error registering card\n"); 4761 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n");
4901 return err; 4762 return err;
4902 } 4763 }
4903 hdsp->state |= HDSP_InitializationComplete; 4764 hdsp->state |= HDSP_InitializationComplete;
@@ -4963,18 +4824,17 @@ static int __devinit hdsp_request_fw_loader(hdsp_t *hdsp)
4963 return err; 4824 return err;
4964 4825
4965 if (!(hdsp->state & HDSP_InitializationComplete)) { 4826 if (!(hdsp->state & HDSP_InitializationComplete)) {
4966 if ((err = snd_hdsp_enable_io(hdsp)) < 0) { 4827 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4967 return err; 4828 return err;
4968 }
4969 4829
4970 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) { 4830 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
4971 snd_printk("Hammerfall-DSP: error creating hwdep device\n"); 4831 snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n");
4972 return err; 4832 return err;
4973 } 4833 }
4974 snd_hdsp_initialize_channels(hdsp); 4834 snd_hdsp_initialize_channels(hdsp);
4975 snd_hdsp_initialize_midi_flush(hdsp); 4835 snd_hdsp_initialize_midi_flush(hdsp);
4976 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4836 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4977 snd_printk("Hammerfall-DSP: error creating alsa devices\n"); 4837 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4978 return err; 4838 return err;
4979 } 4839 }
4980 } 4840 }
@@ -5029,11 +4889,11 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5029 strcpy(card->driver, "H-DSP"); 4889 strcpy(card->driver, "H-DSP");
5030 strcpy(card->mixername, "Xilinx FPGA"); 4890 strcpy(card->mixername, "Xilinx FPGA");
5031 4891
5032 if (hdsp->firmware_rev < 0xa) { 4892 if (hdsp->firmware_rev < 0xa)
5033 return -ENODEV; 4893 return -ENODEV;
5034 } else if (hdsp->firmware_rev < 0x64) { 4894 else if (hdsp->firmware_rev < 0x64)
5035 hdsp->card_name = "RME Hammerfall DSP"; 4895 hdsp->card_name = "RME Hammerfall DSP";
5036 } else if (hdsp->firmware_rev < 0x96) { 4896 else if (hdsp->firmware_rev < 0x96) {
5037 hdsp->card_name = "RME HDSP 9652"; 4897 hdsp->card_name = "RME HDSP 9652";
5038 is_9652 = 1; 4898 is_9652 = 1;
5039 } else { 4899 } else {
@@ -5042,9 +4902,8 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5042 is_9632 = 1; 4902 is_9632 = 1;
5043 } 4903 }
5044 4904
5045 if ((err = pci_enable_device(pci)) < 0) { 4905 if ((err = pci_enable_device(pci)) < 0)
5046 return err; 4906 return err;
5047 }
5048 4907
5049 pci_set_master(hdsp->pci); 4908 pci_set_master(hdsp->pci);
5050 4909
@@ -5052,12 +4911,12 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5052 return err; 4911 return err;
5053 hdsp->port = pci_resource_start(pci, 0); 4912 hdsp->port = pci_resource_start(pci, 0);
5054 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) { 4913 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5055 snd_printk("Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1); 4914 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5056 return -EBUSY; 4915 return -EBUSY;
5057 } 4916 }
5058 4917
5059 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) { 4918 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) {
5060 snd_printk("Hammerfall-DSP: unable to use IRQ %d\n", pci->irq); 4919 snd_printk(KERN_ERR "Hammerfall-DSP: unable to use IRQ %d\n", pci->irq);
5061 return -EBUSY; 4920 return -EBUSY;
5062 } 4921 }
5063 4922
@@ -5065,71 +4924,58 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5065 hdsp->precise_ptr = 1; 4924 hdsp->precise_ptr = 1;
5066 hdsp->use_midi_tasklet = 1; 4925 hdsp->use_midi_tasklet = 1;
5067 4926
5068 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) { 4927 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5069 return err; 4928 return err;
5070 }
5071 4929
5072 if (!is_9652 && !is_9632) { 4930 if (!is_9652 && !is_9632) {
5073 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */ 4931 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */
5074 if ((1000 / HZ) < 2000) { 4932 ssleep(2);
5075 ssleep(2);
5076 } else {
5077 mdelay(2000);
5078 }
5079 4933
5080 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 4934 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5081#ifdef HDSP_FW_LOADER 4935#ifdef HDSP_FW_LOADER
5082 if ((err = hdsp_request_fw_loader(hdsp)) < 0) { 4936 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5083 /* we don't fail as this can happen 4937 /* we don't fail as this can happen
5084 if userspace is not ready for 4938 if userspace is not ready for
5085 firmware upload 4939 firmware upload
5086 */ 4940 */
5087 snd_printk("Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n"); 4941 snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5088 } else { 4942 else
5089 /* init is complete, we return */ 4943 /* init is complete, we return */
5090 return 0; 4944 return 0;
5091 }
5092#endif 4945#endif
5093 /* no iobox connected, we defer initialization */ 4946 /* no iobox connected, we defer initialization */
5094 snd_printk("Hammerfall-DSP: card initialization pending : waiting for firmware\n"); 4947 snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5095 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) { 4948 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5096 return err; 4949 return err;
5097 }
5098 return 0; 4950 return 0;
5099 } else { 4951 } else {
5100 snd_printk("Hammerfall-DSP: Firmware already present, initializing card.\n"); 4952 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
5101 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) { 4953 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5102 hdsp->io_type = Multiface; 4954 hdsp->io_type = Multiface;
5103 } else { 4955 else
5104 hdsp->io_type = Digiface; 4956 hdsp->io_type = Digiface;
5105 }
5106 } 4957 }
5107 } 4958 }
5108 4959
5109 if ((err = snd_hdsp_enable_io(hdsp)) != 0) { 4960 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5110 return err; 4961 return err;
5111 }
5112 4962
5113 if (is_9652) { 4963 if (is_9652)
5114 hdsp->io_type = H9652; 4964 hdsp->io_type = H9652;
5115 }
5116 4965
5117 if (is_9632) { 4966 if (is_9632)
5118 hdsp->io_type = H9632; 4967 hdsp->io_type = H9632;
5119 }
5120 4968
5121 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) { 4969 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5122 return err; 4970 return err;
5123 }
5124 4971
5125 snd_hdsp_initialize_channels(hdsp); 4972 snd_hdsp_initialize_channels(hdsp);
5126 snd_hdsp_initialize_midi_flush(hdsp); 4973 snd_hdsp_initialize_midi_flush(hdsp);
5127 4974
5128 hdsp->state |= HDSP_FirmwareLoaded; 4975 hdsp->state |= HDSP_FirmwareLoaded;
5129 4976
5130 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) { 4977 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5131 return err; 4978 return err;
5132 }
5133 4979
5134 return 0; 4980 return 0;
5135} 4981}