• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/sound/pci/rme9652/

Lines Matching refs:hdsp

40 #include <sound/hdsp.h>
428 struct hdsp *hdsp;
439 struct hdsp {
599 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
600 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
601 static int snd_hdsp_enable_io (struct hdsp *hdsp);
602 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
603 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
604 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
605 static int hdsp_autosync_ref(struct hdsp *hdsp);
606 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
607 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
609 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
611 switch (hdsp->io_type) {
615 if (hdsp->firmware_rev == 0xa)
626 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
628 switch (hdsp->io_type) {
632 if (hdsp->firmware_rev == 0xa)
643 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
645 writel(val, hdsp->iobase + reg);
648 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
650 return readl (hdsp->iobase + reg);
653 static int hdsp_check_for_iobox (struct hdsp *hdsp)
655 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
656 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
658 hdsp->state &= ~HDSP_FirmwareLoaded;
664 static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
669 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
673 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
683 hdsp->state &= ~HDSP_FirmwareLoaded;
687 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
692 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
696 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
697 hdsp_write (hdsp, HDSP_fifoData, 0);
699 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
704 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
707 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
708 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
716 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
722 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
724 hdsp->control2_register = 0;
726 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
730 if (hdsp->state & HDSP_InitializationComplete) {
732 spin_lock_irqsave(&hdsp->lock, flags);
733 snd_hdsp_set_defaults(hdsp);
734 spin_unlock_irqrestore(&hdsp->lock, flags);
737 hdsp->state |= HDSP_FirmwareLoaded;
742 static int hdsp_get_iobox_version (struct hdsp *hdsp)
744 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
746 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
747 hdsp_write (hdsp, HDSP_fifoData, 0);
748 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
751 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
752 hdsp_write (hdsp, HDSP_fifoData, 0);
754 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
755 hdsp->io_type = Multiface;
756 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
757 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
758 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
760 hdsp->io_type = Digiface;
764 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
765 hdsp->io_type = Multiface;
767 hdsp->io_type = Digiface;
774 static int hdsp_request_fw_loader(struct hdsp *hdsp);
777 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
779 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
781 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
782 hdsp->state &= ~HDSP_FirmwareLoaded;
787 if (! (hdsp->state & HDSP_FirmwareCached)) {
789 if (! hdsp_request_fw_loader(hdsp))
797 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
808 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
818 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
833 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
838 return hdsp->mixer_matrix[addr];
841 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
848 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
862 if (hdsp->io_type == H9632 && addr >= 512)
865 if (hdsp->io_type == H9652 && addr >= 1352)
868 hdsp->mixer_matrix[addr] = data;
880 hdsp_write (hdsp, 4096 + (ad*4),
881 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
882 hdsp->mixer_matrix[addr&0x7fe]);
890 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
893 hdsp_write (hdsp, HDSP_fifoData, ad);
894 hdsp->mixer_matrix[addr] = data;
901 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
906 spin_lock_irqsave(&hdsp->lock, flags);
907 if ((hdsp->playback_pid != hdsp->capture_pid) &&
908 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
910 spin_unlock_irqrestore(&hdsp->lock, flags);
914 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
916 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
920 if (hdsp->io_type == H9632)
934 if (hdsp->io_type == H9632) return 128000;
937 if (hdsp->io_type == H9632) return 176400;
940 if (hdsp->io_type == H9632) return 192000;
949 static int hdsp_external_sample_rate(struct hdsp *hdsp)
951 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
958 if (hdsp->io_type == H9632 &&
959 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
960 return hdsp_spdif_sample_rate(hdsp);
974 static void hdsp_compute_period_size(struct hdsp *hdsp)
976 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
979 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
983 position = hdsp_read(hdsp, HDSP_statusRegister);
985 if (!hdsp->precise_ptr)
986 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
990 position &= (hdsp->period_bytes/2) - 1;
994 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
996 hdsp_write (hdsp, HDSP_resetPointer, 0);
997 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1001 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
1004 static void hdsp_start_audio(struct hdsp *s)
1010 static void hdsp_stop_audio(struct hdsp *s)
1016 static void hdsp_silence_playback(struct hdsp *hdsp)
1018 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
1021 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1046 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1061 hdsp->dds_value = n;
1062 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1065 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1071 /* ASSUMPTION: hdsp->lock is either held, or
1076 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1083 int external_freq = hdsp_external_sample_rate(hdsp);
1084 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1086 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1088 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1097 current_rate = hdsp->system_sample_rate;
1109 if (rate > 96000 && hdsp->io_type != H9632)
1162 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1164 hdsp->capture_pid,
1165 hdsp->playback_pid);
1169 hdsp->control_register &= ~HDSP_FrequencyMask;
1170 hdsp->control_register |= rate_bits;
1171 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1174 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1175 hdsp_set_dds_value(hdsp, rate);
1178 hdsp->channel_map = channel_map_H9632_qs;
1180 if (hdsp->io_type == H9632)
1181 hdsp->channel_map = channel_map_H9632_ds;
1183 hdsp->channel_map = channel_map_ds;
1185 switch (hdsp->io_type) {
1187 hdsp->channel_map = channel_map_mf_ss;
1191 hdsp->channel_map = channel_map_df_ss;
1194 hdsp->channel_map = channel_map_H9632_ss;
1202 hdsp->system_sample_rate = rate;
1211 static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
1215 return hdsp_read(hdsp, HDSP_midiDataIn1);
1217 return hdsp_read(hdsp, HDSP_midiDataIn0);
1220 static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
1224 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1226 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1229 static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
1232 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1234 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1237 static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
1242 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1244 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1252 static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
1254 while (snd_hdsp_midi_input_available (hdsp, id))
1255 snd_hdsp_midi_read_byte (hdsp, id);
1271 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1277 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1294 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1299 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1305 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1310 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1312 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1313 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1320 struct hdsp *hdsp;
1326 hdsp = hmidi->hdsp;
1328 spin_lock_irqsave (&hdsp->lock, flags);
1330 if (!(hdsp->control_register & ie)) {
1331 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1332 hdsp->control_register |= ie;
1335 hdsp->control_register &= ~ie;
1336 tasklet_kill(&hdsp->midi_tasklet);
1339 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1340 spin_unlock_irqrestore (&hdsp->lock, flags);
1396 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1457 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1461 hdsp->midi[id].id = id;
1462 hdsp->midi[id].rmidi = NULL;
1463 hdsp->midi[id].input = NULL;
1464 hdsp->midi[id].output = NULL;
1465 hdsp->midi[id].hdsp = hdsp;
1466 hdsp->midi[id].istimer = 0;
1467 hdsp->midi[id].pending = 0;
1468 spin_lock_init (&hdsp->midi[id].lock);
1471 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1474 sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1);
1475 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1477 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1478 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1480 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1522 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1524 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1530 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1535 spin_lock_irq(&hdsp->lock);
1536 change = val != hdsp->creg_spdif;
1537 hdsp->creg_spdif = val;
1538 spin_unlock_irq(&hdsp->lock);
1551 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1553 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1559 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1564 spin_lock_irq(&hdsp->lock);
1565 change = val != hdsp->creg_spdif_stream;
1566 hdsp->creg_spdif_stream = val;
1567 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1568 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1569 spin_unlock_irq(&hdsp->lock);
1594 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1596 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1599 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1601 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1602 hdsp->control_register |= hdsp_encode_spdif_in(in);
1603 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1610 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1614 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1615 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1616 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1623 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1625 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1631 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1635 if (!snd_hdsp_use_is_exclusive(hdsp))
1637 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1638 spin_lock_irq(&hdsp->lock);
1639 change = val != hdsp_spdif_in(hdsp);
1641 hdsp_set_spdif_input(hdsp, val);
1642 spin_unlock_irq(&hdsp->lock);
1651 static int hdsp_spdif_out(struct hdsp *hdsp)
1653 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1656 static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
1659 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1661 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1662 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1670 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1672 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1678 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1682 if (!snd_hdsp_use_is_exclusive(hdsp))
1685 spin_lock_irq(&hdsp->lock);
1686 change = (int)val != hdsp_spdif_out(hdsp);
1687 hdsp_set_spdif_output(hdsp, val);
1688 spin_unlock_irq(&hdsp->lock);
1697 static int hdsp_spdif_professional(struct hdsp *hdsp)
1699 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1702 static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val)
1705 hdsp->control_register |= HDSP_SPDIFProfessional;
1707 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1708 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1714 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1716 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1722 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1726 if (!snd_hdsp_use_is_exclusive(hdsp))
1729 spin_lock_irq(&hdsp->lock);
1730 change = (int)val != hdsp_spdif_professional(hdsp);
1731 hdsp_set_spdif_professional(hdsp, val);
1732 spin_unlock_irq(&hdsp->lock);
1741 static int hdsp_spdif_emphasis(struct hdsp *hdsp)
1743 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1746 static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
1749 hdsp->control_register |= HDSP_SPDIFEmphasis;
1751 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1752 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1758 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1760 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1766 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1770 if (!snd_hdsp_use_is_exclusive(hdsp))
1773 spin_lock_irq(&hdsp->lock);
1774 change = (int)val != hdsp_spdif_emphasis(hdsp);
1775 hdsp_set_spdif_emphasis(hdsp, val);
1776 spin_unlock_irq(&hdsp->lock);
1785 static int hdsp_spdif_nonaudio(struct hdsp *hdsp)
1787 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1790 static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
1793 hdsp->control_register |= HDSP_SPDIFNonAudio;
1795 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1796 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1802 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1804 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1810 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1814 if (!snd_hdsp_use_is_exclusive(hdsp))
1817 spin_lock_irq(&hdsp->lock);
1818 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1819 hdsp_set_spdif_nonaudio(hdsp, val);
1820 spin_unlock_irq(&hdsp->lock);
1836 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1840 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1849 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1851 switch (hdsp_spdif_sample_rate(hdsp)) {
1903 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1905 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1920 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1924 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1933 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1935 switch (hdsp_external_sample_rate(hdsp)) {
1978 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1980 if (hdsp->control_register & HDSP_ClockModeMaster)
1982 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
2002 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2004 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
2017 static int hdsp_clock_source(struct hdsp *hdsp)
2019 if (hdsp->control_register & HDSP_ClockModeMaster) {
2020 switch (hdsp->system_sample_rate) {
2047 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
2052 if (hdsp_external_sample_rate(hdsp) != 0) {
2053 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2054 hdsp->control_register &= ~HDSP_ClockModeMaster;
2055 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2090 hdsp->control_register |= HDSP_ClockModeMaster;
2091 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2092 hdsp_set_rate(hdsp, rate, 1);
2099 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2103 if (hdsp->io_type == H9632)
2115 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2117 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2123 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2127 if (!snd_hdsp_use_is_exclusive(hdsp))
2131 if (hdsp->io_type == H9632) {
2138 spin_lock_irq(&hdsp->lock);
2139 if (val != hdsp_clock_source(hdsp))
2140 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2143 spin_unlock_irq(&hdsp->lock);
2151 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2153 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2159 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2162 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2164 hdsp->clock_source_locked = !!ucontrol->value.integer.value[0];
2177 static int hdsp_da_gain(struct hdsp *hdsp)
2179 switch (hdsp->control_register & HDSP_DAGainMask) {
2191 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2193 hdsp->control_register &= ~HDSP_DAGainMask;
2196 hdsp->control_register |= HDSP_DAGainHighGain;
2199 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2202 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2208 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2227 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2229 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2235 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2239 if (!snd_hdsp_use_is_exclusive(hdsp))
2244 spin_lock_irq(&hdsp->lock);
2245 if (val != hdsp_da_gain(hdsp))
2246 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2249 spin_unlock_irq(&hdsp->lock);
2262 static int hdsp_ad_gain(struct hdsp *hdsp)
2264 switch (hdsp->control_register & HDSP_ADGainMask) {
2276 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2278 hdsp->control_register &= ~HDSP_ADGainMask;
2281 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2284 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2287 hdsp->control_register |= HDSP_ADGainLowGain;
2293 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2312 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2314 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2320 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2324 if (!snd_hdsp_use_is_exclusive(hdsp))
2329 spin_lock_irq(&hdsp->lock);
2330 if (val != hdsp_ad_gain(hdsp))
2331 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2334 spin_unlock_irq(&hdsp->lock);
2347 static int hdsp_phone_gain(struct hdsp *hdsp)
2349 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2361 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2363 hdsp->control_register &= ~HDSP_PhoneGainMask;
2366 hdsp->control_register |= HDSP_PhoneGain0dB;
2369 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2372 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2378 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2397 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2399 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2405 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2409 if (!snd_hdsp_use_is_exclusive(hdsp))
2414 spin_lock_irq(&hdsp->lock);
2415 if (val != hdsp_phone_gain(hdsp))
2416 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2419 spin_unlock_irq(&hdsp->lock);
2432 static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)
2434 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2439 static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
2442 hdsp->control_register |= HDSP_XLRBreakoutCable;
2444 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2445 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2453 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2455 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2461 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2465 if (!snd_hdsp_use_is_exclusive(hdsp))
2468 spin_lock_irq(&hdsp->lock);
2469 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2470 hdsp_set_xlr_breakout_cable(hdsp, val);
2471 spin_unlock_irq(&hdsp->lock);
2488 static int hdsp_aeb(struct hdsp *hdsp)
2490 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2495 static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
2498 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2500 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2501 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2509 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2511 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2517 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2521 if (!snd_hdsp_use_is_exclusive(hdsp))
2524 spin_lock_irq(&hdsp->lock);
2525 change = (int)val != hdsp_aeb(hdsp);
2526 hdsp_set_aeb(hdsp, val);
2527 spin_unlock_irq(&hdsp->lock);
2540 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2546 switch (hdsp->control_register & HDSP_SyncRefMask) {
2565 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2567 hdsp->control_register &= ~HDSP_SyncRefMask;
2570 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2573 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2576 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2579 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2582 hdsp->control_register |= HDSP_SyncRef_WORD;
2585 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2590 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2597 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2602 switch (hdsp->io_type) {
2626 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2628 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2634 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2638 if (!snd_hdsp_use_is_exclusive(hdsp))
2641 switch (hdsp->io_type) {
2657 spin_lock_irq(&hdsp->lock);
2658 change = (int)val != hdsp_pref_sync_ref(hdsp);
2659 hdsp_set_pref_sync_ref(hdsp, val);
2660 spin_unlock_irq(&hdsp->lock);
2673 static int hdsp_autosync_ref(struct hdsp *hdsp)
2676 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2714 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2716 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2729 static int hdsp_line_out(struct hdsp *hdsp)
2731 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2734 static int hdsp_set_line_output(struct hdsp *hdsp, int out)
2737 hdsp->control_register |= HDSP_LineOut;
2739 hdsp->control_register &= ~HDSP_LineOut;
2740 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2748 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2750 spin_lock_irq(&hdsp->lock);
2751 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2752 spin_unlock_irq(&hdsp->lock);
2758 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2762 if (!snd_hdsp_use_is_exclusive(hdsp))
2765 spin_lock_irq(&hdsp->lock);
2766 change = (int)val != hdsp_line_out(hdsp);
2767 hdsp_set_line_output(hdsp, val);
2768 spin_unlock_irq(&hdsp->lock);
2781 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2784 hdsp->precise_ptr = 1;
2786 hdsp->precise_ptr = 0;
2794 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2796 spin_lock_irq(&hdsp->lock);
2797 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2798 spin_unlock_irq(&hdsp->lock);
2804 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2808 if (!snd_hdsp_use_is_exclusive(hdsp))
2811 spin_lock_irq(&hdsp->lock);
2812 change = (int)val != hdsp->precise_ptr;
2813 hdsp_set_precise_pointer(hdsp, val);
2814 spin_unlock_irq(&hdsp->lock);
2827 static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
2830 hdsp->use_midi_tasklet = 1;
2832 hdsp->use_midi_tasklet = 0;
2840 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2842 spin_lock_irq(&hdsp->lock);
2843 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2844 spin_unlock_irq(&hdsp->lock);
2850 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2854 if (!snd_hdsp_use_is_exclusive(hdsp))
2857 spin_lock_irq(&hdsp->lock);
2858 change = (int)val != hdsp->use_midi_tasklet;
2859 hdsp_set_use_midi_tasklet(hdsp, val);
2860 spin_unlock_irq(&hdsp->lock);
2888 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2896 if (source >= hdsp->max_channels)
2897 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2899 addr = hdsp_input_to_output_key(hdsp,source, destination);
2901 spin_lock_irq(&hdsp->lock);
2902 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2903 spin_unlock_irq(&hdsp->lock);
2909 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2916 if (!snd_hdsp_use_is_exclusive(hdsp))
2922 if (source >= hdsp->max_channels)
2923 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2925 addr = hdsp_input_to_output_key(hdsp,source, destination);
2929 spin_lock_irq(&hdsp->lock);
2930 change = gain != hdsp_read_gain(hdsp, addr);
2932 hdsp_write_gain(hdsp, addr, gain);
2933 spin_unlock_irq(&hdsp->lock);
2958 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2960 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2973 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2975 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2988 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2990 int status = hdsp_read(hdsp, HDSP_statusRegister);
3004 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3006 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
3019 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
3021 int status = hdsp_read(hdsp, HDSP_statusRegister);
3033 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3035 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3046 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
3048 int status = hdsp_read(hdsp, HDSP_statusRegister);
3062 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3067 switch (hdsp->io_type) {
3082 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3095 static int hdsp_dds_offset(struct hdsp *hdsp)
3098 unsigned int dds_value = hdsp->dds_value;
3099 int system_sample_rate = hdsp->system_sample_rate;
3117 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
3119 int rate = hdsp->system_sample_rate + offset_hz;
3120 hdsp_set_dds_value(hdsp, rate);
3135 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3137 ucontrol->value.enumerated.item[0] = hdsp_dds_offset(hdsp);
3143 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3147 if (!snd_hdsp_use_is_exclusive(hdsp))
3150 spin_lock_irq(&hdsp->lock);
3151 if (val != hdsp_dds_offset(hdsp))
3152 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
3155 spin_unlock_irq(&hdsp->lock);
3236 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3243 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3246 hdsp->spdif_ctl = kctl;
3252 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3254 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3257 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3263 if (hdsp->io_type == H9632) {
3265 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3271 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3272 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3286 struct hdsp *hdsp = (struct hdsp *) entry->private_data;
3295 status = hdsp_read(hdsp, HDSP_statusRegister);
3296 status2 = hdsp_read(hdsp, HDSP_status2Register);
3298 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name,
3299 hdsp->card->number + 1);
3301 hdsp->capture_buffer, hdsp->playback_buffer);
3303 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3304 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3306 hdsp->control2_register);
3310 if (hdsp_check_for_iobox(hdsp)) {
3316 if (hdsp_check_for_firmware(hdsp, 0)) {
3317 if (hdsp->state & HDSP_FirmwareCached) {
3318 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3327 err = hdsp_request_fw_loader(hdsp);
3338 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3339 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3340 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3341 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3342 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3343 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
3347 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3349 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3350 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3351 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3352 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3358 switch (hdsp_clock_source(hdsp)) {
3394 if (hdsp_system_clock_mode(hdsp))
3399 switch (hdsp_pref_sync_ref (hdsp)) {
3424 switch (hdsp_autosync_ref (hdsp)) {
3452 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3456 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3457 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3461 switch (hdsp_spdif_in(hdsp)) {
3479 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3484 if (hdsp->control_register & HDSP_SPDIFProfessional)
3489 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3494 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3498 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0)
3512 switch (hdsp->io_type) {
3552 if (hdsp->io_type == H9632) {
3555 switch (hdsp_ad_gain(hdsp)) {
3568 switch (hdsp_da_gain(hdsp)) {
3581 switch (hdsp_phone_gain(hdsp)) {
3594 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3596 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3605 static void snd_hdsp_proc_init(struct hdsp *hdsp)
3609 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3610 snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
3613 static void snd_hdsp_free_buffers(struct hdsp *hdsp)
3615 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3616 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3619 static int __devinit snd_hdsp_initialize_memory(struct hdsp *hdsp)
3623 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3624 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3625 if (hdsp->capture_dma_buf.area)
3626 snd_dma_free_pages(&hdsp->capture_dma_buf);
3627 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
3633 cb_bus = ALIGN(hdsp->capture_dma_buf.addr, 0x10000ul);
3634 pb_bus = ALIGN(hdsp->playback_dma_buf.addr, 0x10000ul);
3638 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3639 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3641 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3642 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3647 static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3651 /* ASSUMPTION: hdsp->lock is either held, or
3665 hdsp->control_register = HDSP_ClockModeMaster |
3671 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3674 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3676 hdsp->control2_register = 0;
3678 if (hdsp->io_type == H9652)
3679 snd_hdsp_9652_enable_mixer (hdsp);
3681 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3683 hdsp_reset_hw_pointer(hdsp);
3684 hdsp_compute_period_size(hdsp);
3689 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3691 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3692 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3697 if (hdsp->io_type == H9632) {
3698 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3699 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3705 hdsp_set_rate(hdsp, 48000, 1);
3712 struct hdsp *hdsp = (struct hdsp *)arg;
3714 if (hdsp->midi[0].pending)
3715 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3716 if (hdsp->midi[1].pending)
3717 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3722 struct hdsp *hdsp = (struct hdsp *) dev_id;
3731 status = hdsp_read(hdsp, HDSP_statusRegister);
3740 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3742 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3743 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3745 if (!(hdsp->state & HDSP_InitializationComplete))
3749 if (hdsp->capture_substream)
3750 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3752 if (hdsp->playback_substream)
3753 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3757 if (hdsp->use_midi_tasklet) {
3759 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3760 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3761 hdsp->midi[0].pending = 1;
3764 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3767 if (hdsp->io_type != Multiface && hdsp->io_type != H9632 && midi1 && midi1status) {
3768 if (hdsp->use_midi_tasklet) {
3770 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3771 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3772 hdsp->midi[1].pending = 1;
3775 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3778 if (hdsp->use_midi_tasklet && schedule)
3779 tasklet_schedule(&hdsp->midi_tasklet);
3785 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3786 return hdsp_hw_pointer(hdsp);
3789 static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3796 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3799 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3803 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3805 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3811 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3817 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3828 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3834 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3845 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3848 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3858 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3861 other = hdsp->capture_substream;
3863 other = hdsp->playback_substream;
3864 if (hdsp->running)
3865 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3884 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3889 if (hdsp_check_for_iobox (hdsp))
3892 if (hdsp_check_for_firmware(hdsp, 1))
3895 spin_lock_irq(&hdsp->lock);
3898 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
3899 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
3900 this_pid = hdsp->playback_pid;
3901 other_pid = hdsp->capture_pid;
3903 this_pid = hdsp->capture_pid;
3904 other_pid = hdsp->playback_pid;
3914 if (params_rate(params) != hdsp->system_sample_rate) {
3915 spin_unlock_irq(&hdsp->lock);
3920 if (params_period_size(params) != hdsp->period_bytes / 4) {
3921 spin_unlock_irq(&hdsp->lock);
3928 spin_unlock_irq(&hdsp->lock);
3932 spin_unlock_irq(&hdsp->lock);
3938 spin_lock_irq(&hdsp->lock);
3939 if (! hdsp->clock_source_locked) {
3940 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
3941 spin_unlock_irq(&hdsp->lock);
3946 spin_unlock_irq(&hdsp->lock);
3948 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
3959 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3962 if (snd_BUG_ON(info->channel >= hdsp->max_channels))
3965 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
3991 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3995 if (hdsp_check_for_iobox (hdsp))
3998 if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
4001 spin_lock(&hdsp->lock);
4002 running = hdsp->running;
4012 spin_unlock(&hdsp->lock);
4016 other = hdsp->capture_substream;
4018 other = hdsp->playback_substream;
4035 hdsp_silence_playback(hdsp);
4039 hdsp_silence_playback(hdsp);
4043 hdsp_silence_playback(hdsp);
4047 if (!hdsp->running && running)
4048 hdsp_start_audio(hdsp);
4049 else if (hdsp->running && !running)
4050 hdsp_stop_audio(hdsp);
4051 hdsp->running = running;
4052 spin_unlock(&hdsp->lock);
4059 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4062 if (hdsp_check_for_iobox (hdsp))
4065 if (hdsp_check_for_firmware(hdsp, 1))
4068 spin_lock_irq(&hdsp->lock);
4069 if (!hdsp->running)
4070 hdsp_reset_hw_pointer(hdsp);
4071 spin_unlock_irq(&hdsp->lock);
4153 struct hdsp *hdsp = rule->private;
4155 if (hdsp->io_type == H9632) {
4157 list[0] = hdsp->qs_in_channels;
4158 list[1] = hdsp->ds_in_channels;
4159 list[2] = hdsp->ss_in_channels;
4163 list[0] = hdsp->ds_in_channels;
4164 list[1] = hdsp->ss_in_channels;
4173 struct hdsp *hdsp = rule->private;
4175 if (hdsp->io_type == H9632) {
4176 list[0] = hdsp->qs_out_channels;
4177 list[1] = hdsp->ds_out_channels;
4178 list[2] = hdsp->ss_out_channels;
4181 list[0] = hdsp->ds_out_channels;
4182 list[1] = hdsp->ss_out_channels;
4190 struct hdsp *hdsp = rule->private;
4193 if (r->min > 96000 && hdsp->io_type == H9632) {
4195 .min = hdsp->qs_in_channels,
4196 .max = hdsp->qs_in_channels,
4202 .min = hdsp->ds_in_channels,
4203 .max = hdsp->ds_in_channels,
4209 .min = hdsp->ss_in_channels,
4210 .max = hdsp->ss_in_channels,
4221 struct hdsp *hdsp = rule->private;
4224 if (r->min > 96000 && hdsp->io_type == H9632) {
4226 .min = hdsp->qs_out_channels,
4227 .max = hdsp->qs_out_channels,
4233 .min = hdsp->ds_out_channels,
4234 .max = hdsp->ds_out_channels,
4240 .min = hdsp->ss_out_channels,
4241 .max = hdsp->ss_out_channels,
4252 struct hdsp *hdsp = rule->private;
4255 if (c->min >= hdsp->ss_out_channels) {
4262 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4269 } else if (c->max <= hdsp->ds_out_channels) {
4283 struct hdsp *hdsp = rule->private;
4286 if (c->min >= hdsp->ss_in_channels) {
4293 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4300 } else if (c->max <= hdsp->ds_in_channels) {
4313 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4316 if (hdsp_check_for_iobox (hdsp))
4319 if (hdsp_check_for_firmware(hdsp, 1))
4322 spin_lock_irq(&hdsp->lock);
4327 runtime->dma_area = hdsp->playback_buffer;
4330 hdsp->playback_pid = current->pid;
4331 hdsp->playback_substream = substream;
4333 spin_unlock_irq(&hdsp->lock);
4337 if (hdsp->clock_source_locked) {
4338 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4339 } else if (hdsp->io_type == H9632) {
4344 if (hdsp->io_type == H9632) {
4345 runtime->hw.channels_min = hdsp->qs_out_channels;
4346 runtime->hw.channels_max = hdsp->ss_out_channels;
4350 snd_hdsp_hw_rule_out_channels, hdsp,
4353 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4356 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4359 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4360 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4361 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4362 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4368 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4370 spin_lock_irq(&hdsp->lock);
4372 hdsp->playback_pid = -1;
4373 hdsp->playback_substream = NULL;
4375 spin_unlock_irq(&hdsp->lock);
4377 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4378 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4379 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4386 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4389 if (hdsp_check_for_iobox (hdsp))
4392 if (hdsp_check_for_firmware(hdsp, 1))
4395 spin_lock_irq(&hdsp->lock);
4400 runtime->dma_area = hdsp->capture_buffer;
4403 hdsp->capture_pid = current->pid;
4404 hdsp->capture_substream = substream;
4406 spin_unlock_irq(&hdsp->lock);
4410 if (hdsp->io_type == H9632) {
4411 runtime->hw.channels_min = hdsp->qs_in_channels;
4412 runtime->hw.channels_max = hdsp->ss_in_channels;
4418 snd_hdsp_hw_rule_in_channels, hdsp,
4421 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4424 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4431 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4433 spin_lock_irq(&hdsp->lock);
4435 hdsp->capture_pid = -1;
4436 hdsp->capture_substream = NULL;
4438 spin_unlock_irq(&hdsp->lock);
4469 static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4474 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4481 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4484 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4487 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4490 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4491 hdsp->iobase + ofs + 4))
4494 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4495 hdsp->iobase + ofs + 4))
4498 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4499 hdsp->iobase + ofs + 4))
4506 static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4512 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4514 m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4536 static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4542 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4545 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4550 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4555 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4556 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4559 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4560 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4568 struct hdsp *hdsp = (struct hdsp *)hw->private_data;
4576 err = hdsp_check_for_iobox(hdsp);
4580 err = hdsp_check_for_firmware(hdsp, 1);
4584 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4589 switch (hdsp->io_type) {
4591 return hdsp_9652_get_peak(hdsp, peak_rms);
4593 return hdsp_9632_get_peak(hdsp, peak_rms);
4595 return hdsp_get_peak(hdsp, peak_rms);
4603 err = hdsp_check_for_iobox(hdsp);
4607 err = hdsp_check_for_firmware(hdsp, 1);
4612 spin_lock_irqsave(&hdsp->lock, flags);
4613 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4614 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4615 if (hdsp->io_type != H9632)
4616 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4617 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4618 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i)
4619 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4620 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4621 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4622 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
4623 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
4624 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
4625 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4626 info.system_sample_rate = hdsp->system_sample_rate;
4627 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4628 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4629 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4630 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4631 info.line_out = (unsigned char)hdsp_line_out(hdsp);
4632 if (hdsp->io_type == H9632) {
4633 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4634 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4635 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4636 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4639 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4640 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4641 spin_unlock_irqrestore(&hdsp->lock, flags);
4649 if (hdsp->io_type != H9632) return -EINVAL;
4650 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4651 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4660 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4661 if (hdsp->io_type == Undefined) {
4662 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4665 hdsp_version.io_type = hdsp->io_type;
4666 hdsp_version.firmware_rev = hdsp->firmware_rev;
4676 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4678 if (hdsp->io_type == Undefined) return -EINVAL;
4680 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4689 if (hdsp_check_for_iobox (hdsp))
4692 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
4695 hdsp->state |= HDSP_FirmwareCached;
4697 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4700 if (!(hdsp->state & HDSP_InitializationComplete)) {
4701 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4704 snd_hdsp_initialize_channels(hdsp);
4705 snd_hdsp_initialize_midi_flush(hdsp);
4707 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4716 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4749 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4757 hdsp->hwdep = hw;
4758 hw->private_data = hdsp;
4766 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4771 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4774 hdsp->pcm = pcm;
4775 pcm->private_data = hdsp;
4776 strcpy(pcm->name, hdsp->card_name);
4786 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
4788 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4789 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4792 static int snd_hdsp_enable_io (struct hdsp *hdsp)
4796 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4801 for (i = 0; i < hdsp->max_channels; ++i) {
4802 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4803 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4809 static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4813 switch (hdsp->io_type) {
4815 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4816 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4817 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4821 hdsp->card_name = "RME Hammerfall HDSP 9652";
4822 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4823 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4827 status = hdsp_read(hdsp, HDSP_statusRegister);
4831 hdsp->card_name = "RME Hammerfall HDSP 9632";
4832 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4833 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4834 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4835 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4836 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4837 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4841 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4842 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4843 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4852 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
4854 snd_hdsp_flush_midi_input (hdsp, 0);
4855 snd_hdsp_flush_midi_input (hdsp, 1);
4858 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
4862 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4868 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4873 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
4874 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4880 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4885 snd_hdsp_proc_init(hdsp);
4887 hdsp->system_sample_rate = -1;
4888 hdsp->playback_pid = -1;
4889 hdsp->capture_pid = -1;
4890 hdsp->capture_substream = NULL;
4891 hdsp->playback_substream = NULL;
4893 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4898 if (!(hdsp->state & HDSP_InitializationComplete)) {
4900 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4901 hdsp->port, hdsp->irq);
4907 hdsp->state |= HDSP_InitializationComplete;
4915 static int hdsp_request_fw_loader(struct hdsp *hdsp)
4921 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4923 if (hdsp->io_type == Undefined) {
4924 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4926 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4931 switch (hdsp->io_type) {
4933 if (hdsp->firmware_rev == 0xa)
4939 if (hdsp->firmware_rev == 0xa)
4945 snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type);
4949 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
4953 if (fw->size < sizeof(hdsp->firmware_cache)) {
4955 (int)fw->size, (int)sizeof(hdsp->firmware_cache));
4960 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
4964 hdsp->state |= HDSP_FirmwareCached;
4966 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4969 if (!(hdsp->state & HDSP_InitializationComplete)) {
4970 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4973 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
4977 snd_hdsp_initialize_channels(hdsp);
4978 snd_hdsp_initialize_midi_flush(hdsp);
4979 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4989 struct hdsp *hdsp)
4991 struct pci_dev *pci = hdsp->pci;
4996 hdsp->irq = -1;
4997 hdsp->state = 0;
4998 hdsp->midi[0].rmidi = NULL;
4999 hdsp->midi[1].rmidi = NULL;
5000 hdsp->midi[0].input = NULL;
5001 hdsp->midi[1].input = NULL;
5002 hdsp->midi[0].output = NULL;
5003 hdsp->midi[1].output = NULL;
5004 hdsp->midi[0].pending = 0;
5005 hdsp->midi[1].pending = 0;
5006 spin_lock_init(&hdsp->midi[0].lock);
5007 spin_lock_init(&hdsp->midi[1].lock);
5008 hdsp->iobase = NULL;
5009 hdsp->control_register = 0;
5010 hdsp->control2_register = 0;
5011 hdsp->io_type = Undefined;
5012 hdsp->max_channels = 26;
5014 hdsp->card = card;
5016 spin_lock_init(&hdsp->lock);
5018 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5020 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5021 hdsp->firmware_rev &= 0xff;
5030 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5035 if (hdsp->firmware_rev < 0xa)
5037 else if (hdsp->firmware_rev < 0x64)
5038 hdsp->card_name = "RME Hammerfall DSP";
5039 else if (hdsp->firmware_rev < 0x96) {
5040 hdsp->card_name = "RME HDSP 9652";
5043 hdsp->card_name = "RME HDSP 9632";
5044 hdsp->max_channels = 16;
5051 pci_set_master(hdsp->pci);
5053 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5055 hdsp->port = pci_resource_start(pci, 0);
5056 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5057 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5062 "hdsp", hdsp)) {
5067 hdsp->irq = pci->irq;
5068 hdsp->precise_ptr = 0;
5069 hdsp->use_midi_tasklet = 1;
5070 hdsp->dds_value = 0;
5072 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5078 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5083 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5085 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5097 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5102 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5103 hdsp->io_type = Multiface;
5105 hdsp->io_type = Digiface;
5109 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5113 hdsp->io_type = H9652;
5116 hdsp->io_type = H9632;
5118 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5121 snd_hdsp_initialize_channels(hdsp);
5122 snd_hdsp_initialize_midi_flush(hdsp);
5124 hdsp->state |= HDSP_FirmwareLoaded;
5126 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5132 static int snd_hdsp_free(struct hdsp *hdsp)
5134 if (hdsp->port) {
5136 tasklet_kill(&hdsp->midi_tasklet);
5137 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5138 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5141 if (hdsp->irq >= 0)
5142 free_irq(hdsp->irq, (void *)hdsp);
5144 snd_hdsp_free_buffers(hdsp);
5146 if (hdsp->iobase)
5147 iounmap(hdsp->iobase);
5149 if (hdsp->port)
5150 pci_release_regions(hdsp->pci);
5152 pci_disable_device(hdsp->pci);
5158 struct hdsp *hdsp = (struct hdsp *) card->private_data;
5160 if (hdsp)
5161 snd_hdsp_free(hdsp);
5168 struct hdsp *hdsp;
5180 sizeof(struct hdsp), &card);
5184 hdsp = (struct hdsp *) card->private_data;
5186 hdsp->dev = dev;
5187 hdsp->pci = pci;
5190 if ((err = snd_hdsp_create(card, hdsp)) < 0) {
5196 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5197 hdsp->port, hdsp->irq);