• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/src/linux/linux-2.6/sound/pci/rme9652/

Lines Matching defs:hdsp

41 #include <sound/hdsp.h>
425 struct hdsp *hdsp;
436 struct hdsp {
596 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
597 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
598 static int snd_hdsp_enable_io (struct hdsp *hdsp);
599 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
600 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
601 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
602 static int hdsp_autosync_ref(struct hdsp *hdsp);
603 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
604 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
606 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
608 switch (hdsp->firmware_rev) {
620 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
622 switch (hdsp->firmware_rev) {
634 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
636 writel(val, hdsp->iobase + reg);
639 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
641 return readl (hdsp->iobase + reg);
644 static int hdsp_check_for_iobox (struct hdsp *hdsp)
647 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
648 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
650 hdsp->state &= ~HDSP_FirmwareLoaded;
657 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
662 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
666 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
667 hdsp_write (hdsp, HDSP_fifoData, 0);
669 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
674 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
677 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
678 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
686 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
692 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
694 hdsp->control2_register = 0;
696 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
700 if (hdsp->state & HDSP_InitializationComplete) {
702 spin_lock_irqsave(&hdsp->lock, flags);
703 snd_hdsp_set_defaults(hdsp);
704 spin_unlock_irqrestore(&hdsp->lock, flags);
707 hdsp->state |= HDSP_FirmwareLoaded;
712 static int hdsp_get_iobox_version (struct hdsp *hdsp)
714 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
716 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
717 hdsp_write (hdsp, HDSP_fifoData, 0);
718 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
721 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
722 hdsp_write (hdsp, HDSP_fifoData, 0);
724 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
725 hdsp->io_type = Multiface;
726 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
727 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
728 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
730 hdsp->io_type = Digiface;
734 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
735 hdsp->io_type = Multiface;
737 hdsp->io_type = Digiface;
744 static int __devinit hdsp_request_fw_loader(struct hdsp *hdsp);
747 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
749 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
751 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
752 hdsp->state &= ~HDSP_FirmwareLoaded;
757 if (! (hdsp->state & HDSP_FirmwareCached)) {
759 if (! hdsp_request_fw_loader(hdsp))
767 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
778 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
788 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
803 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
808 return hdsp->mixer_matrix[addr];
811 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
818 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
832 if (hdsp->io_type == H9632 && addr >= 512)
835 if (hdsp->io_type == H9652 && addr >= 1352)
838 hdsp->mixer_matrix[addr] = data;
850 hdsp_write (hdsp, 4096 + (ad*4),
851 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
852 hdsp->mixer_matrix[addr&0x7fe]);
860 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
863 hdsp_write (hdsp, HDSP_fifoData, ad);
864 hdsp->mixer_matrix[addr] = data;
871 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
876 spin_lock_irqsave(&hdsp->lock, flags);
877 if ((hdsp->playback_pid != hdsp->capture_pid) &&
878 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
880 spin_unlock_irqrestore(&hdsp->lock, flags);
884 static int hdsp_external_sample_rate (struct hdsp *hdsp)
886 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
901 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
903 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
917 if (hdsp->io_type == H9632) return 128000;
920 if (hdsp->io_type == H9632) return 176400;
923 if (hdsp->io_type == H9632) return 192000;
932 static void hdsp_compute_period_size(struct hdsp *hdsp)
934 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
937 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
941 position = hdsp_read(hdsp, HDSP_statusRegister);
943 if (!hdsp->precise_ptr)
944 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
948 position &= (hdsp->period_bytes/2) - 1;
952 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
954 hdsp_write (hdsp, HDSP_resetPointer, 0);
955 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
959 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
962 static void hdsp_start_audio(struct hdsp *s)
968 static void hdsp_stop_audio(struct hdsp *s)
974 static void hdsp_silence_playback(struct hdsp *hdsp)
976 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
979 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1004 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1020 hdsp->dds_value = n;
1021 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1024 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1030 /* ASSUMPTION: hdsp->lock is either held, or
1035 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1042 int external_freq = hdsp_external_sample_rate(hdsp);
1043 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1045 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1047 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1056 current_rate = hdsp->system_sample_rate;
1068 if (rate > 96000 && hdsp->io_type != H9632)
1121 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1123 hdsp->capture_pid,
1124 hdsp->playback_pid);
1128 hdsp->control_register &= ~HDSP_FrequencyMask;
1129 hdsp->control_register |= rate_bits;
1130 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1133 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1134 hdsp_set_dds_value(hdsp, rate);
1137 hdsp->channel_map = channel_map_H9632_qs;
1139 if (hdsp->io_type == H9632)
1140 hdsp->channel_map = channel_map_H9632_ds;
1142 hdsp->channel_map = channel_map_ds;
1144 switch (hdsp->io_type) {
1146 hdsp->channel_map = channel_map_mf_ss;
1150 hdsp->channel_map = channel_map_df_ss;
1153 hdsp->channel_map = channel_map_H9632_ss;
1161 hdsp->system_sample_rate = rate;
1170 static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
1174 return hdsp_read(hdsp, HDSP_midiDataIn1);
1176 return hdsp_read(hdsp, HDSP_midiDataIn0);
1179 static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
1183 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1185 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1188 static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
1191 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1193 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1196 static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
1201 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1203 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1211 static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
1213 while (snd_hdsp_midi_input_available (hdsp, id))
1214 snd_hdsp_midi_read_byte (hdsp, id);
1230 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1236 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1253 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1258 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1264 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1269 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1271 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1272 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1279 struct hdsp *hdsp;
1285 hdsp = hmidi->hdsp;
1287 spin_lock_irqsave (&hdsp->lock, flags);
1289 if (!(hdsp->control_register & ie)) {
1290 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1291 hdsp->control_register |= ie;
1294 hdsp->control_register &= ~ie;
1295 tasklet_kill(&hdsp->midi_tasklet);
1298 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1299 spin_unlock_irqrestore (&hdsp->lock, flags);
1355 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1416 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1420 hdsp->midi[id].id = id;
1421 hdsp->midi[id].rmidi = NULL;
1422 hdsp->midi[id].input = NULL;
1423 hdsp->midi[id].output = NULL;
1424 hdsp->midi[id].hdsp = hdsp;
1425 hdsp->midi[id].istimer = 0;
1426 hdsp->midi[id].pending = 0;
1427 spin_lock_init (&hdsp->midi[id].lock);
1430 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1433 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1434 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1436 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1437 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1439 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1481 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1483 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1489 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1494 spin_lock_irq(&hdsp->lock);
1495 change = val != hdsp->creg_spdif;
1496 hdsp->creg_spdif = val;
1497 spin_unlock_irq(&hdsp->lock);
1510 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1512 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1518 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1523 spin_lock_irq(&hdsp->lock);
1524 change = val != hdsp->creg_spdif_stream;
1525 hdsp->creg_spdif_stream = val;
1526 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1527 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1528 spin_unlock_irq(&hdsp->lock);
1553 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1555 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1558 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1560 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1561 hdsp->control_register |= hdsp_encode_spdif_in(in);
1562 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1569 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1573 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1574 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1575 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1582 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1584 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1590 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1594 if (!snd_hdsp_use_is_exclusive(hdsp))
1596 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1597 spin_lock_irq(&hdsp->lock);
1598 change = val != hdsp_spdif_in(hdsp);
1600 hdsp_set_spdif_input(hdsp, val);
1601 spin_unlock_irq(&hdsp->lock);
1610 static int hdsp_spdif_out(struct hdsp *hdsp)
1612 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1615 static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
1618 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1620 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1621 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1636 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1638 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1644 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1648 if (!snd_hdsp_use_is_exclusive(hdsp))
1651 spin_lock_irq(&hdsp->lock);
1652 change = (int)val != hdsp_spdif_out(hdsp);
1653 hdsp_set_spdif_output(hdsp, val);
1654 spin_unlock_irq(&hdsp->lock);
1663 static int hdsp_spdif_professional(struct hdsp *hdsp)
1665 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1668 static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val)
1671 hdsp->control_register |= HDSP_SPDIFProfessional;
1673 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1674 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1680 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1682 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1688 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1692 if (!snd_hdsp_use_is_exclusive(hdsp))
1695 spin_lock_irq(&hdsp->lock);
1696 change = (int)val != hdsp_spdif_professional(hdsp);
1697 hdsp_set_spdif_professional(hdsp, val);
1698 spin_unlock_irq(&hdsp->lock);
1707 static int hdsp_spdif_emphasis(struct hdsp *hdsp)
1709 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1712 static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
1715 hdsp->control_register |= HDSP_SPDIFEmphasis;
1717 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1718 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1724 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1726 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1732 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1736 if (!snd_hdsp_use_is_exclusive(hdsp))
1739 spin_lock_irq(&hdsp->lock);
1740 change = (int)val != hdsp_spdif_emphasis(hdsp);
1741 hdsp_set_spdif_emphasis(hdsp, val);
1742 spin_unlock_irq(&hdsp->lock);
1751 static int hdsp_spdif_nonaudio(struct hdsp *hdsp)
1753 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1756 static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
1759 hdsp->control_register |= HDSP_SPDIFNonAudio;
1761 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1762 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1768 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1770 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1776 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1780 if (!snd_hdsp_use_is_exclusive(hdsp))
1783 spin_lock_irq(&hdsp->lock);
1784 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1785 hdsp_set_spdif_nonaudio(hdsp, val);
1786 spin_unlock_irq(&hdsp->lock);
1802 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1806 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1815 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1817 switch (hdsp_spdif_sample_rate(hdsp)) {
1869 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1871 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1886 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1890 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1899 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1901 switch (hdsp_external_sample_rate(hdsp)) {
1944 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1946 if (hdsp->control_register & HDSP_ClockModeMaster)
1948 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1968 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1970 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1983 static int hdsp_clock_source(struct hdsp *hdsp)
1985 if (hdsp->control_register & HDSP_ClockModeMaster) {
1986 switch (hdsp->system_sample_rate) {
2013 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
2018 if (hdsp_external_sample_rate(hdsp) != 0) {
2019 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2020 hdsp->control_register &= ~HDSP_ClockModeMaster;
2021 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2056 hdsp->control_register |= HDSP_ClockModeMaster;
2057 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2058 hdsp_set_rate(hdsp, rate, 1);
2065 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2069 if (hdsp->io_type == H9632)
2081 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2083 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2089 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2093 if (!snd_hdsp_use_is_exclusive(hdsp))
2097 if (hdsp->io_type == H9632) {
2104 spin_lock_irq(&hdsp->lock);
2105 if (val != hdsp_clock_source(hdsp))
2106 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2109 spin_unlock_irq(&hdsp->lock);
2124 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2126 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2132 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2135 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2137 hdsp->clock_source_locked = ucontrol->value.integer.value[0];
2150 static int hdsp_da_gain(struct hdsp *hdsp)
2152 switch (hdsp->control_register & HDSP_DAGainMask) {
2164 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2166 hdsp->control_register &= ~HDSP_DAGainMask;
2169 hdsp->control_register |= HDSP_DAGainHighGain;
2172 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2175 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2181 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2200 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2202 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2208 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2212 if (!snd_hdsp_use_is_exclusive(hdsp))
2217 spin_lock_irq(&hdsp->lock);
2218 if (val != hdsp_da_gain(hdsp))
2219 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2222 spin_unlock_irq(&hdsp->lock);
2235 static int hdsp_ad_gain(struct hdsp *hdsp)
2237 switch (hdsp->control_register & HDSP_ADGainMask) {
2249 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2251 hdsp->control_register &= ~HDSP_ADGainMask;
2254 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2257 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2260 hdsp->control_register |= HDSP_ADGainLowGain;
2266 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2285 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2287 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2293 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2297 if (!snd_hdsp_use_is_exclusive(hdsp))
2302 spin_lock_irq(&hdsp->lock);
2303 if (val != hdsp_ad_gain(hdsp))
2304 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2307 spin_unlock_irq(&hdsp->lock);
2320 static int hdsp_phone_gain(struct hdsp *hdsp)
2322 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2334 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2336 hdsp->control_register &= ~HDSP_PhoneGainMask;
2339 hdsp->control_register |= HDSP_PhoneGain0dB;
2342 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2345 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2351 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2370 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2372 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2378 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2382 if (!snd_hdsp_use_is_exclusive(hdsp))
2387 spin_lock_irq(&hdsp->lock);
2388 if (val != hdsp_phone_gain(hdsp))
2389 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2392 spin_unlock_irq(&hdsp->lock);
2405 static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)
2407 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2412 static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
2415 hdsp->control_register |= HDSP_XLRBreakoutCable;
2417 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2418 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2433 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2435 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2441 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2445 if (!snd_hdsp_use_is_exclusive(hdsp))
2448 spin_lock_irq(&hdsp->lock);
2449 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2450 hdsp_set_xlr_breakout_cable(hdsp, val);
2451 spin_unlock_irq(&hdsp->lock);
2468 static int hdsp_aeb(struct hdsp *hdsp)
2470 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2475 static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
2478 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2480 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2481 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2496 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2498 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2504 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2508 if (!snd_hdsp_use_is_exclusive(hdsp))
2511 spin_lock_irq(&hdsp->lock);
2512 change = (int)val != hdsp_aeb(hdsp);
2513 hdsp_set_aeb(hdsp, val);
2514 spin_unlock_irq(&hdsp->lock);
2527 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2533 switch (hdsp->control_register & HDSP_SyncRefMask) {
2552 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2554 hdsp->control_register &= ~HDSP_SyncRefMask;
2557 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2560 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2563 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2566 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2569 hdsp->control_register |= HDSP_SyncRef_WORD;
2572 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2577 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2584 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2589 switch (hdsp->io_type) {
2613 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2615 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2621 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2625 if (!snd_hdsp_use_is_exclusive(hdsp))
2628 switch (hdsp->io_type) {
2644 spin_lock_irq(&hdsp->lock);
2645 change = (int)val != hdsp_pref_sync_ref(hdsp);
2646 hdsp_set_pref_sync_ref(hdsp, val);
2647 spin_unlock_irq(&hdsp->lock);
2660 static int hdsp_autosync_ref(struct hdsp *hdsp)
2663 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2701 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2703 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2716 static int hdsp_line_out(struct hdsp *hdsp)
2718 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2721 static int hdsp_set_line_output(struct hdsp *hdsp, int out)
2724 hdsp->control_register |= HDSP_LineOut;
2726 hdsp->control_register &= ~HDSP_LineOut;
2727 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2742 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2744 spin_lock_irq(&hdsp->lock);
2745 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2746 spin_unlock_irq(&hdsp->lock);
2752 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2756 if (!snd_hdsp_use_is_exclusive(hdsp))
2759 spin_lock_irq(&hdsp->lock);
2760 change = (int)val != hdsp_line_out(hdsp);
2761 hdsp_set_line_output(hdsp, val);
2762 spin_unlock_irq(&hdsp->lock);
2775 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2778 hdsp->precise_ptr = 1;
2780 hdsp->precise_ptr = 0;
2795 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2797 spin_lock_irq(&hdsp->lock);
2798 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2799 spin_unlock_irq(&hdsp->lock);
2805 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2809 if (!snd_hdsp_use_is_exclusive(hdsp))
2812 spin_lock_irq(&hdsp->lock);
2813 change = (int)val != hdsp->precise_ptr;
2814 hdsp_set_precise_pointer(hdsp, val);
2815 spin_unlock_irq(&hdsp->lock);
2828 static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
2831 hdsp->use_midi_tasklet = 1;
2833 hdsp->use_midi_tasklet = 0;
2848 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2850 spin_lock_irq(&hdsp->lock);
2851 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2852 spin_unlock_irq(&hdsp->lock);
2858 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2862 if (!snd_hdsp_use_is_exclusive(hdsp))
2865 spin_lock_irq(&hdsp->lock);
2866 change = (int)val != hdsp->use_midi_tasklet;
2867 hdsp_set_use_midi_tasklet(hdsp, val);
2868 spin_unlock_irq(&hdsp->lock);
2896 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2904 if (source >= hdsp->max_channels)
2905 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2907 addr = hdsp_input_to_output_key(hdsp,source, destination);
2909 spin_lock_irq(&hdsp->lock);
2910 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2911 spin_unlock_irq(&hdsp->lock);
2917 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2924 if (!snd_hdsp_use_is_exclusive(hdsp))
2930 if (source >= hdsp->max_channels)
2931 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2933 addr = hdsp_input_to_output_key(hdsp,source, destination);
2937 spin_lock_irq(&hdsp->lock);
2938 change = gain != hdsp_read_gain(hdsp, addr);
2940 hdsp_write_gain(hdsp, addr, gain);
2941 spin_unlock_irq(&hdsp->lock);
2966 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2968 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2981 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2983 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2996 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2998 int status = hdsp_read(hdsp, HDSP_statusRegister);
3012 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3014 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
3027 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
3029 int status = hdsp_read(hdsp, HDSP_statusRegister);
3041 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3043 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3054 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
3056 int status = hdsp_read(hdsp, HDSP_statusRegister);
3070 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3075 switch (hdsp->io_type) {
3090 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3103 static int hdsp_dds_offset(struct hdsp *hdsp)
3107 unsigned int dds_value = hdsp->dds_value;
3108 int system_sample_rate = hdsp->system_sample_rate;
3123 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
3125 int rate = hdsp->system_sample_rate + offset_hz;
3126 hdsp_set_dds_value(hdsp, rate);
3141 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3143 ucontrol->value.enumerated.item[0] = hdsp_dds_offset(hdsp);
3149 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3153 if (!snd_hdsp_use_is_exclusive(hdsp))
3156 spin_lock_irq(&hdsp->lock);
3157 if (val != hdsp_dds_offset(hdsp))
3158 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
3161 spin_unlock_irq(&hdsp->lock);
3242 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3249 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3252 hdsp->spdif_ctl = kctl;
3258 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3260 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3263 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3269 if (hdsp->io_type == H9632) {
3271 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3277 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3278 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3292 struct hdsp *hdsp = (struct hdsp *) entry->private_data;
3301 if (hdsp_check_for_iobox (hdsp)) {
3306 if (hdsp_check_for_firmware(hdsp, 0)) {
3307 if (hdsp->state & HDSP_FirmwareCached) {
3308 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3315 err = hdsp_request_fw_loader(hdsp);
3326 status = hdsp_read(hdsp, HDSP_statusRegister);
3327 status2 = hdsp_read(hdsp, HDSP_status2Register);
3329 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3331 hdsp->capture_buffer, hdsp->playback_buffer);
3333 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3334 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3335 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
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");
3359 switch (hdsp_clock_source(hdsp)) {
3395 if (hdsp_system_clock_mode(hdsp))
3400 switch (hdsp_pref_sync_ref (hdsp)) {
3425 switch (hdsp_autosync_ref (hdsp)) {
3453 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3457 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3458 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3462 switch (hdsp_spdif_in(hdsp)) {
3480 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3485 if (hdsp->control_register & HDSP_SPDIFProfessional)
3490 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3495 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3499 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0)
3513 switch (hdsp->io_type) {
3553 if (hdsp->io_type == H9632) {
3556 switch (hdsp_ad_gain(hdsp)) {
3569 switch (hdsp_da_gain(hdsp)) {
3582 switch (hdsp_phone_gain(hdsp)) {
3595 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3597 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3606 static void __devinit snd_hdsp_proc_init(struct hdsp *hdsp)
3610 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3611 snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
3614 static void snd_hdsp_free_buffers(struct hdsp *hdsp)
3616 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3617 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3620 static int __devinit snd_hdsp_initialize_memory(struct hdsp *hdsp)
3624 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3625 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3626 if (hdsp->capture_dma_buf.area)
3627 snd_dma_free_pages(&hdsp->capture_dma_buf);
3628 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
3634 cb_bus = ALIGN(hdsp->capture_dma_buf.addr, 0x10000ul);
3635 pb_bus = ALIGN(hdsp->playback_dma_buf.addr, 0x10000ul);
3639 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3640 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3642 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3643 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3648 static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3652 /* ASSUMPTION: hdsp->lock is either held, or
3666 hdsp->control_register = HDSP_ClockModeMaster |
3672 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3675 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3677 hdsp->control2_register = 0;
3679 if (hdsp->io_type == H9652)
3680 snd_hdsp_9652_enable_mixer (hdsp);
3682 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3684 hdsp_reset_hw_pointer(hdsp);
3685 hdsp_compute_period_size(hdsp);
3690 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3692 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3693 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3698 if (hdsp->io_type == H9632) {
3699 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3700 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3706 hdsp_set_rate(hdsp, 48000, 1);
3713 struct hdsp *hdsp = (struct hdsp *)arg;
3715 if (hdsp->midi[0].pending)
3716 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3717 if (hdsp->midi[1].pending)
3718 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3723 struct hdsp *hdsp = (struct hdsp *) dev_id;
3732 status = hdsp_read(hdsp, HDSP_statusRegister);
3741 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3743 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3744 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3747 if (hdsp->capture_substream)
3748 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3750 if (hdsp->playback_substream)
3751 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3755 if (hdsp->use_midi_tasklet) {
3757 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3758 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3759 hdsp->midi[0].pending = 1;
3762 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3765 if (hdsp->io_type != Multiface && hdsp->io_type != H9632 && midi1 && midi1status) {
3766 if (hdsp->use_midi_tasklet) {
3768 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3769 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3770 hdsp->midi[1].pending = 1;
3773 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3776 if (hdsp->use_midi_tasklet && schedule)
3777 tasklet_hi_schedule(&hdsp->midi_tasklet);
3783 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3784 return hdsp_hw_pointer(hdsp);
3787 static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3794 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3796 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3800 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3802 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3808 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3813 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3823 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3828 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3838 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3841 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3850 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3853 other = hdsp->capture_substream;
3855 other = hdsp->playback_substream;
3856 if (hdsp->running)
3857 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3876 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3881 if (hdsp_check_for_iobox (hdsp))
3884 if (hdsp_check_for_firmware(hdsp, 1))
3887 spin_lock_irq(&hdsp->lock);
3890 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
3891 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
3892 this_pid = hdsp->playback_pid;
3893 other_pid = hdsp->capture_pid;
3895 this_pid = hdsp->capture_pid;
3896 other_pid = hdsp->playback_pid;
3906 if (params_rate(params) != hdsp->system_sample_rate) {
3907 spin_unlock_irq(&hdsp->lock);
3912 if (params_period_size(params) != hdsp->period_bytes / 4) {
3913 spin_unlock_irq(&hdsp->lock);
3920 spin_unlock_irq(&hdsp->lock);
3924 spin_unlock_irq(&hdsp->lock);
3930 spin_lock_irq(&hdsp->lock);
3931 if (! hdsp->clock_source_locked) {
3932 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
3933 spin_unlock_irq(&hdsp->lock);
3938 spin_unlock_irq(&hdsp->lock);
3940 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
3951 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3954 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3956 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
3982 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3986 if (hdsp_check_for_iobox (hdsp))
3989 if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
3992 spin_lock(&hdsp->lock);
3993 running = hdsp->running;
4003 spin_unlock(&hdsp->lock);
4007 other = hdsp->capture_substream;
4009 other = hdsp->playback_substream;
4026 hdsp_silence_playback(hdsp);
4030 hdsp_silence_playback(hdsp);
4034 hdsp_silence_playback(hdsp);
4038 if (!hdsp->running && running)
4039 hdsp_start_audio(hdsp);
4040 else if (hdsp->running && !running)
4041 hdsp_stop_audio(hdsp);
4042 hdsp->running = running;
4043 spin_unlock(&hdsp->lock);
4050 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4053 if (hdsp_check_for_iobox (hdsp))
4056 if (hdsp_check_for_firmware(hdsp, 1))
4059 spin_lock_irq(&hdsp->lock);
4060 if (!hdsp->running)
4061 hdsp_reset_hw_pointer(hdsp);
4062 spin_unlock_irq(&hdsp->lock);
4144 struct hdsp *hdsp = rule->private;
4146 if (hdsp->io_type == H9632) {
4148 list[0] = hdsp->qs_in_channels;
4149 list[1] = hdsp->ds_in_channels;
4150 list[2] = hdsp->ss_in_channels;
4154 list[0] = hdsp->ds_in_channels;
4155 list[1] = hdsp->ss_in_channels;
4164 struct hdsp *hdsp = rule->private;
4166 if (hdsp->io_type == H9632) {
4167 list[0] = hdsp->qs_out_channels;
4168 list[1] = hdsp->ds_out_channels;
4169 list[2] = hdsp->ss_out_channels;
4172 list[0] = hdsp->ds_out_channels;
4173 list[1] = hdsp->ss_out_channels;
4181 struct hdsp *hdsp = rule->private;
4184 if (r->min > 96000 && hdsp->io_type == H9632) {
4186 .min = hdsp->qs_in_channels,
4187 .max = hdsp->qs_in_channels,
4193 .min = hdsp->ds_in_channels,
4194 .max = hdsp->ds_in_channels,
4200 .min = hdsp->ss_in_channels,
4201 .max = hdsp->ss_in_channels,
4212 struct hdsp *hdsp = rule->private;
4215 if (r->min > 96000 && hdsp->io_type == H9632) {
4217 .min = hdsp->qs_out_channels,
4218 .max = hdsp->qs_out_channels,
4224 .min = hdsp->ds_out_channels,
4225 .max = hdsp->ds_out_channels,
4231 .min = hdsp->ss_out_channels,
4232 .max = hdsp->ss_out_channels,
4243 struct hdsp *hdsp = rule->private;
4246 if (c->min >= hdsp->ss_out_channels) {
4253 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4260 } else if (c->max <= hdsp->ds_out_channels) {
4274 struct hdsp *hdsp = rule->private;
4277 if (c->min >= hdsp->ss_in_channels) {
4284 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4291 } else if (c->max <= hdsp->ds_in_channels) {
4304 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4307 if (hdsp_check_for_iobox (hdsp))
4310 if (hdsp_check_for_firmware(hdsp, 1))
4313 spin_lock_irq(&hdsp->lock);
4318 runtime->dma_area = hdsp->playback_buffer;
4321 hdsp->playback_pid = current->pid;
4322 hdsp->playback_substream = substream;
4324 spin_unlock_irq(&hdsp->lock);
4328 if (hdsp->clock_source_locked) {
4329 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4330 } else if (hdsp->io_type == H9632) {
4335 if (hdsp->io_type == H9632) {
4336 runtime->hw.channels_min = hdsp->qs_out_channels;
4337 runtime->hw.channels_max = hdsp->ss_out_channels;
4341 snd_hdsp_hw_rule_out_channels, hdsp,
4344 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4347 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4350 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4351 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4352 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4353 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4359 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4361 spin_lock_irq(&hdsp->lock);
4363 hdsp->playback_pid = -1;
4364 hdsp->playback_substream = NULL;
4366 spin_unlock_irq(&hdsp->lock);
4368 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4369 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4370 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4377 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4380 if (hdsp_check_for_iobox (hdsp))
4383 if (hdsp_check_for_firmware(hdsp, 1))
4386 spin_lock_irq(&hdsp->lock);
4391 runtime->dma_area = hdsp->capture_buffer;
4394 hdsp->capture_pid = current->pid;
4395 hdsp->capture_substream = substream;
4397 spin_unlock_irq(&hdsp->lock);
4401 if (hdsp->io_type == H9632) {
4402 runtime->hw.channels_min = hdsp->qs_in_channels;
4403 runtime->hw.channels_max = hdsp->ss_in_channels;
4409 snd_hdsp_hw_rule_in_channels, hdsp,
4412 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4415 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4422 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4424 spin_lock_irq(&hdsp->lock);
4426 hdsp->capture_pid = -1;
4427 hdsp->capture_substream = NULL;
4429 spin_unlock_irq(&hdsp->lock);
4467 static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4472 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4479 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4482 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4485 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4488 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4489 hdsp->iobase + ofs + 4))
4492 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4493 hdsp->iobase + ofs + 4))
4496 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4497 hdsp->iobase + ofs + 4))
4504 static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4510 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4512 m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4534 static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4540 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4543 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4548 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4553 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4554 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4557 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4558 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4566 struct hdsp *hdsp = (struct hdsp *)hw->private_data;
4573 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4578 switch (hdsp->io_type) {
4580 return hdsp_9652_get_peak(hdsp, peak_rms);
4582 return hdsp_9632_get_peak(hdsp, peak_rms);
4584 return hdsp_get_peak(hdsp, peak_rms);
4592 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4596 spin_lock_irqsave(&hdsp->lock, flags);
4597 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4598 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4599 if (hdsp->io_type != H9632)
4600 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4601 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)
4603 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4604 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4605 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4606 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
4607 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
4608 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
4609 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4610 info.system_sample_rate = hdsp->system_sample_rate;
4611 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4612 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4613 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4614 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4615 info.line_out = (unsigned char)hdsp_line_out(hdsp);
4616 if (hdsp->io_type == H9632) {
4617 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4618 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4619 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4620 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4623 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4624 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4625 spin_unlock_irqrestore(&hdsp->lock, flags);
4633 if (hdsp->io_type != H9632) return -EINVAL;
4634 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4635 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4644 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4645 if (hdsp->io_type == Undefined) {
4646 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4649 hdsp_version.io_type = hdsp->io_type;
4650 hdsp_version.firmware_rev = hdsp->firmware_rev;
4660 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4662 if (hdsp->io_type == Undefined) return -EINVAL;
4664 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4673 if (hdsp_check_for_iobox (hdsp))
4676 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
4679 hdsp->state |= HDSP_FirmwareCached;
4681 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4684 if (!(hdsp->state & HDSP_InitializationComplete)) {
4685 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4688 snd_hdsp_initialize_channels(hdsp);
4689 snd_hdsp_initialize_midi_flush(hdsp);
4691 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4700 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4734 struct hdsp *hdsp)
4742 hdsp->hwdep = hw;
4743 hw->private_data = hdsp;
4753 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4758 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4761 hdsp->pcm = pcm;
4762 pcm->private_data = hdsp;
4763 strcpy(pcm->name, hdsp->card_name);
4773 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
4775 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4776 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4779 static int snd_hdsp_enable_io (struct hdsp *hdsp)
4783 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4788 for (i = 0; i < hdsp->max_channels; ++i) {
4789 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4790 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4796 static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4800 switch (hdsp->io_type) {
4802 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4803 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4804 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4808 hdsp->card_name = "RME Hammerfall HDSP 9652";
4809 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4810 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4814 status = hdsp_read(hdsp, HDSP_statusRegister);
4818 hdsp->card_name = "RME Hammerfall HDSP 9632";
4819 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4820 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4821 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4822 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4823 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4824 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4828 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4829 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4830 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4839 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
4841 snd_hdsp_flush_midi_input (hdsp, 0);
4842 snd_hdsp_flush_midi_input (hdsp, 1);
4845 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
4849 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4855 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4860 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
4861 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4867 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4872 snd_hdsp_proc_init(hdsp);
4874 hdsp->system_sample_rate = -1;
4875 hdsp->playback_pid = -1;
4876 hdsp->capture_pid = -1;
4877 hdsp->capture_substream = NULL;
4878 hdsp->playback_substream = NULL;
4880 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4885 if (!(hdsp->state & HDSP_InitializationComplete)) {
4887 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4888 hdsp->port, hdsp->irq);
4894 hdsp->state |= HDSP_InitializationComplete;
4902 static int __devinit hdsp_request_fw_loader(struct hdsp *hdsp)
4908 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4910 if (hdsp->io_type == Undefined) {
4911 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4913 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4918 switch (hdsp->io_type) {
4920 if (hdsp->firmware_rev == 0xa)
4926 if (hdsp->firmware_rev == 0xa)
4932 snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type);
4936 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
4940 if (fw->size < sizeof(hdsp->firmware_cache)) {
4942 (int)fw->size, (int)sizeof(hdsp->firmware_cache));
4947 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
4951 hdsp->state |= HDSP_FirmwareCached;
4953 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4956 if (!(hdsp->state & HDSP_InitializationComplete)) {
4957 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4960 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
4964 snd_hdsp_initialize_channels(hdsp);
4965 snd_hdsp_initialize_midi_flush(hdsp);
4966 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4976 struct hdsp *hdsp)
4978 struct pci_dev *pci = hdsp->pci;
4983 hdsp->irq = -1;
4984 hdsp->state = 0;
4985 hdsp->midi[0].rmidi = NULL;
4986 hdsp->midi[1].rmidi = NULL;
4987 hdsp->midi[0].input = NULL;
4988 hdsp->midi[1].input = NULL;
4989 hdsp->midi[0].output = NULL;
4990 hdsp->midi[1].output = NULL;
4991 hdsp->midi[0].pending = 0;
4992 hdsp->midi[1].pending = 0;
4993 spin_lock_init(&hdsp->midi[0].lock);
4994 spin_lock_init(&hdsp->midi[1].lock);
4995 hdsp->iobase = NULL;
4996 hdsp->control_register = 0;
4997 hdsp->control2_register = 0;
4998 hdsp->io_type = Undefined;
4999 hdsp->max_channels = 26;
5001 hdsp->card = card;
5003 spin_lock_init(&hdsp->lock);
5005 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5007 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5008 hdsp->firmware_rev &= 0xff;
5017 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5022 if (hdsp->firmware_rev < 0xa)
5024 else if (hdsp->firmware_rev < 0x64)
5025 hdsp->card_name = "RME Hammerfall DSP";
5026 else if (hdsp->firmware_rev < 0x96) {
5027 hdsp->card_name = "RME HDSP 9652";
5030 hdsp->card_name = "RME HDSP 9632";
5031 hdsp->max_channels = 16;
5038 pci_set_master(hdsp->pci);
5040 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5042 hdsp->port = pci_resource_start(pci, 0);
5043 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5044 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5049 "hdsp", hdsp)) {
5054 hdsp->irq = pci->irq;
5055 hdsp->precise_ptr = 0;
5056 hdsp->use_midi_tasklet = 1;
5057 hdsp->dds_value = 0;
5059 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5066 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5068 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5080 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5085 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5086 hdsp->io_type = Multiface;
5088 hdsp->io_type = Digiface;
5092 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5096 hdsp->io_type = H9652;
5099 hdsp->io_type = H9632;
5101 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5104 snd_hdsp_initialize_channels(hdsp);
5105 snd_hdsp_initialize_midi_flush(hdsp);
5107 hdsp->state |= HDSP_FirmwareLoaded;
5109 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5115 static int snd_hdsp_free(struct hdsp *hdsp)
5117 if (hdsp->port) {
5119 tasklet_kill(&hdsp->midi_tasklet);
5120 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5121 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5124 if (hdsp->irq >= 0)
5125 free_irq(hdsp->irq, (void *)hdsp);
5127 snd_hdsp_free_buffers(hdsp);
5129 if (hdsp->iobase)
5130 iounmap(hdsp->iobase);
5132 if (hdsp->port)
5133 pci_release_regions(hdsp->pci);
5135 pci_disable_device(hdsp->pci);
5141 struct hdsp *hdsp = (struct hdsp *) card->private_data;
5143 if (hdsp)
5144 snd_hdsp_free(hdsp);
5151 struct hdsp *hdsp;
5162 if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct hdsp))))
5165 hdsp = (struct hdsp *) card->private_data;
5167 hdsp->dev = dev;
5168 hdsp->pci = pci;
5171 if ((err = snd_hdsp_create(card, hdsp)) < 0) {
5177 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5178 hdsp->port, hdsp->irq);