Lines Matching refs:hdsp
29 #include <sound/hdsp.h>
431 struct hdsp *hdsp;
442 struct hdsp {
590 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
591 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
592 static int snd_hdsp_enable_io (struct hdsp *hdsp);
593 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
594 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
595 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
596 static int hdsp_autosync_ref(struct hdsp *hdsp);
597 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
598 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
600 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
602 switch (hdsp->io_type) {
607 if (hdsp->firmware_rev == 0xa)
618 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
620 switch (hdsp->io_type) {
625 if (hdsp->firmware_rev == 0xa)
636 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
638 writel(val, hdsp->iobase + reg);
641 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
643 return readl (hdsp->iobase + reg);
646 static int hdsp_check_for_iobox (struct hdsp *hdsp)
650 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
652 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) &
655 dev_dbg(hdsp->card->dev,
663 dev_err(hdsp->card->dev, "no IO box connected!\n");
664 hdsp->state &= ~HDSP_FirmwareLoaded;
668 static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
673 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
677 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
680 dev_dbg(hdsp->card->dev, "iobox found after %ums!\n",
686 dev_info(hdsp->card->dev, "no IO box connected!\n");
687 hdsp->state &= ~HDSP_FirmwareLoaded;
691 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
697 if (hdsp->fw_uploaded)
698 cache = hdsp->fw_uploaded;
700 if (!hdsp->firmware)
702 cache = (u32 *)hdsp->firmware->data;
707 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
709 dev_info(hdsp->card->dev, "loading firmware\n");
711 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
712 hdsp_write (hdsp, HDSP_fifoData, 0);
714 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
715 dev_info(hdsp->card->dev,
717 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
721 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
724 hdsp_write(hdsp, HDSP_fifoData, cache[i]);
725 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
726 dev_info(hdsp->card->dev,
728 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
733 hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT);
734 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
738 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
740 hdsp->control2_register = 0;
742 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
743 dev_info(hdsp->card->dev, "finished firmware loading\n");
746 if (hdsp->state & HDSP_InitializationComplete) {
747 dev_info(hdsp->card->dev,
749 spin_lock_irqsave(&hdsp->lock, flags);
750 snd_hdsp_set_defaults(hdsp);
751 spin_unlock_irqrestore(&hdsp->lock, flags);
754 hdsp->state |= HDSP_FirmwareLoaded;
759 static int hdsp_get_iobox_version (struct hdsp *hdsp)
761 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
763 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
764 hdsp_write(hdsp, HDSP_fifoData, 0);
766 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
767 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
768 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
771 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM);
772 hdsp_write (hdsp, HDSP_fifoData, 0);
773 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
776 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
777 hdsp_write(hdsp, HDSP_fifoData, 0);
778 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
779 hdsp->io_type = Digiface;
780 dev_info(hdsp->card->dev, "Digiface found\n");
784 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
785 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
786 hdsp_write(hdsp, HDSP_fifoData, 0);
787 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0)
790 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
791 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
792 hdsp_write(hdsp, HDSP_fifoData, 0);
793 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
796 hdsp->io_type = RPM;
797 dev_info(hdsp->card->dev, "RPM found\n");
801 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
802 hdsp->io_type = RPM;
803 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
804 hdsp->io_type = Multiface;
806 hdsp->io_type = Digiface;
811 hdsp->io_type = Multiface;
812 dev_info(hdsp->card->dev, "Multiface found\n");
817 static int hdsp_request_fw_loader(struct hdsp *hdsp);
819 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
821 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
823 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
824 hdsp->state &= ~HDSP_FirmwareLoaded;
827 dev_err(hdsp->card->dev, "firmware not present.\n");
829 if (! (hdsp->state & HDSP_FirmwareCached)) {
830 if (! hdsp_request_fw_loader(hdsp))
832 dev_err(hdsp->card->dev,
836 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
837 dev_err(hdsp->card->dev,
846 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
856 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
866 dev_warn(hdsp->card->dev,
872 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
877 return hdsp->mixer_matrix[addr];
880 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
887 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
901 if (hdsp->io_type == H9632 && addr >= 512)
904 if (hdsp->io_type == H9652 && addr >= 1352)
907 hdsp->mixer_matrix[addr] = data;
919 hdsp_write (hdsp, 4096 + (ad*4),
920 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
921 hdsp->mixer_matrix[addr&0x7fe]);
929 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
932 hdsp_write (hdsp, HDSP_fifoData, ad);
933 hdsp->mixer_matrix[addr] = data;
940 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
945 spin_lock_irqsave(&hdsp->lock, flags);
946 if ((hdsp->playback_pid != hdsp->capture_pid) &&
947 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
949 spin_unlock_irqrestore(&hdsp->lock, flags);
953 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
955 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
959 if (hdsp->io_type == H9632)
973 if (hdsp->io_type == H9632) return 128000;
976 if (hdsp->io_type == H9632) return 176400;
979 if (hdsp->io_type == H9632) return 192000;
984 dev_warn(hdsp->card->dev,
990 static int hdsp_external_sample_rate(struct hdsp *hdsp)
992 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
999 if (hdsp->io_type == H9632 &&
1000 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
1001 return hdsp_spdif_sample_rate(hdsp);
1015 static void hdsp_compute_period_size(struct hdsp *hdsp)
1017 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
1020 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
1024 position = hdsp_read(hdsp, HDSP_statusRegister);
1026 if (!hdsp->precise_ptr)
1027 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
1031 position &= (hdsp->period_bytes/2) - 1;
1035 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
1037 hdsp_write (hdsp, HDSP_resetPointer, 0);
1038 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1042 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
1045 static void hdsp_start_audio(struct hdsp *s)
1051 static void hdsp_stop_audio(struct hdsp *s)
1057 static void hdsp_silence_playback(struct hdsp *hdsp)
1059 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
1062 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1087 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1102 hdsp->dds_value = n;
1103 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1106 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1112 /* ASSUMPTION: hdsp->lock is either held, or
1117 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1120 dev_err(hdsp->card->dev,
1125 int external_freq = hdsp_external_sample_rate(hdsp);
1126 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1128 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1129 dev_info(hdsp->card->dev,
1131 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1132 dev_info(hdsp->card->dev,
1135 dev_info(hdsp->card->dev,
1142 current_rate = hdsp->system_sample_rate;
1154 if (rate > 96000 && hdsp->io_type != H9632)
1207 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1208 dev_warn(hdsp->card->dev,
1210 hdsp->capture_pid,
1211 hdsp->playback_pid);
1215 hdsp->control_register &= ~HDSP_FrequencyMask;
1216 hdsp->control_register |= rate_bits;
1217 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1220 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1221 hdsp_set_dds_value(hdsp, rate);
1224 hdsp->channel_map = channel_map_H9632_qs;
1226 if (hdsp->io_type == H9632)
1227 hdsp->channel_map = channel_map_H9632_ds;
1229 hdsp->channel_map = channel_map_ds;
1231 switch (hdsp->io_type) {
1234 hdsp->channel_map = channel_map_mf_ss;
1238 hdsp->channel_map = channel_map_df_ss;
1241 hdsp->channel_map = channel_map_H9632_ss;
1249 hdsp->system_sample_rate = rate;
1258 static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
1262 return hdsp_read(hdsp, HDSP_midiDataIn1);
1264 return hdsp_read(hdsp, HDSP_midiDataIn0);
1267 static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
1271 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1273 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1276 static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
1279 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1281 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1284 static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
1289 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1291 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1299 static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
1301 while (snd_hdsp_midi_input_available (hdsp, id))
1302 snd_hdsp_midi_read_byte (hdsp, id);
1318 n_pending = snd_hdsp_midi_output_possible(hmidi->hdsp, hmidi->id);
1326 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1343 n_pending = snd_hdsp_midi_input_available(hmidi->hdsp, hmidi->id);
1349 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1355 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1360 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1362 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1363 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1370 struct hdsp *hdsp;
1376 hdsp = hmidi->hdsp;
1378 spin_lock_irqsave (&hdsp->lock, flags);
1380 if (!(hdsp->control_register & ie)) {
1381 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1382 hdsp->control_register |= ie;
1385 hdsp->control_register &= ~ie;
1388 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1389 spin_unlock_irqrestore (&hdsp->lock, flags);
1441 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1502 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1506 hdsp->midi[id].id = id;
1507 hdsp->midi[id].rmidi = NULL;
1508 hdsp->midi[id].input = NULL;
1509 hdsp->midi[id].output = NULL;
1510 hdsp->midi[id].hdsp = hdsp;
1511 hdsp->midi[id].istimer = 0;
1512 hdsp->midi[id].pending = 0;
1513 spin_lock_init (&hdsp->midi[id].lock);
1516 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1519 sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1);
1520 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1522 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1523 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1525 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1567 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1569 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1575 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1580 spin_lock_irq(&hdsp->lock);
1581 change = val != hdsp->creg_spdif;
1582 hdsp->creg_spdif = val;
1583 spin_unlock_irq(&hdsp->lock);
1596 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1598 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1604 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1609 spin_lock_irq(&hdsp->lock);
1610 change = val != hdsp->creg_spdif_stream;
1611 hdsp->creg_spdif_stream = val;
1612 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1613 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1614 spin_unlock_irq(&hdsp->lock);
1639 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1641 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1644 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1646 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1647 hdsp->control_register |= hdsp_encode_spdif_in(in);
1648 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1657 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1659 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3,
1665 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1667 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1673 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1677 if (!snd_hdsp_use_is_exclusive(hdsp))
1679 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1680 spin_lock_irq(&hdsp->lock);
1681 change = val != hdsp_spdif_in(hdsp);
1683 hdsp_set_spdif_input(hdsp, val);
1684 spin_unlock_irq(&hdsp->lock);
1697 static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask)
1699 return (hdsp->control_register & regmask) ? 1 : 0;
1702 static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out)
1705 hdsp->control_register |= regmask;
1707 hdsp->control_register &= ~regmask;
1708 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1718 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1721 spin_lock_irq(&hdsp->lock);
1722 ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask);
1723 spin_unlock_irq(&hdsp->lock);
1730 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1735 if (!snd_hdsp_use_is_exclusive(hdsp))
1738 spin_lock_irq(&hdsp->lock);
1739 change = (int) val != hdsp_toggle_setting(hdsp, regmask);
1741 hdsp_set_toggle_setting(hdsp, regmask, val);
1742 spin_unlock_irq(&hdsp->lock);
1761 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1763 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1769 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1771 switch (hdsp_spdif_sample_rate(hdsp)) {
1823 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1825 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1840 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1846 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1852 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1854 switch (hdsp_external_sample_rate(hdsp)) {
1897 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1899 if (hdsp->control_register & HDSP_ClockModeMaster)
1901 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1915 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1917 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1930 static int hdsp_clock_source(struct hdsp *hdsp)
1932 if (hdsp->control_register & HDSP_ClockModeMaster) {
1933 switch (hdsp->system_sample_rate) {
1960 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
1965 if (hdsp_external_sample_rate(hdsp) != 0) {
1966 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
1967 hdsp->control_register &= ~HDSP_ClockModeMaster;
1968 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2003 hdsp->control_register |= HDSP_ClockModeMaster;
2004 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2005 hdsp_set_rate(hdsp, rate, 1);
2017 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2019 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
2025 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2027 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2033 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2037 if (!snd_hdsp_use_is_exclusive(hdsp))
2041 if (hdsp->io_type == H9632) {
2048 spin_lock_irq(&hdsp->lock);
2049 if (val != hdsp_clock_source(hdsp))
2050 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2053 spin_unlock_irq(&hdsp->lock);
2061 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2063 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2069 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2072 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2074 hdsp->clock_source_locked = !!ucontrol->value.integer.value[0];
2087 static int hdsp_da_gain(struct hdsp *hdsp)
2089 switch (hdsp->control_register & HDSP_DAGainMask) {
2101 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2103 hdsp->control_register &= ~HDSP_DAGainMask;
2106 hdsp->control_register |= HDSP_DAGainHighGain;
2109 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2112 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2118 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2131 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2133 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2139 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2143 if (!snd_hdsp_use_is_exclusive(hdsp))
2148 spin_lock_irq(&hdsp->lock);
2149 if (val != hdsp_da_gain(hdsp))
2150 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2153 spin_unlock_irq(&hdsp->lock);
2166 static int hdsp_ad_gain(struct hdsp *hdsp)
2168 switch (hdsp->control_register & HDSP_ADGainMask) {
2180 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2182 hdsp->control_register &= ~HDSP_ADGainMask;
2185 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2188 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2191 hdsp->control_register |= HDSP_ADGainLowGain;
2197 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2210 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2212 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2218 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2222 if (!snd_hdsp_use_is_exclusive(hdsp))
2227 spin_lock_irq(&hdsp->lock);
2228 if (val != hdsp_ad_gain(hdsp))
2229 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2232 spin_unlock_irq(&hdsp->lock);
2245 static int hdsp_phone_gain(struct hdsp *hdsp)
2247 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2259 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2261 hdsp->control_register &= ~HDSP_PhoneGainMask;
2264 hdsp->control_register |= HDSP_PhoneGain0dB;
2267 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2270 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2276 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2289 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2291 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2297 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2301 if (!snd_hdsp_use_is_exclusive(hdsp))
2306 spin_lock_irq(&hdsp->lock);
2307 if (val != hdsp_phone_gain(hdsp))
2308 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2311 spin_unlock_irq(&hdsp->lock);
2324 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2330 switch (hdsp->control_register & HDSP_SyncRefMask) {
2349 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2351 hdsp->control_register &= ~HDSP_SyncRefMask;
2354 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2357 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2360 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2363 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2366 hdsp->control_register |= HDSP_SyncRef_WORD;
2369 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2374 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2383 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2386 switch (hdsp->io_type) {
2406 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2408 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2414 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2418 if (!snd_hdsp_use_is_exclusive(hdsp))
2421 switch (hdsp->io_type) {
2437 spin_lock_irq(&hdsp->lock);
2438 change = (int)val != hdsp_pref_sync_ref(hdsp);
2439 hdsp_set_pref_sync_ref(hdsp, val);
2440 spin_unlock_irq(&hdsp->lock);
2453 static int hdsp_autosync_ref(struct hdsp *hdsp)
2456 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2490 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2492 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2505 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2508 hdsp->precise_ptr = 1;
2510 hdsp->precise_ptr = 0;
2518 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2520 spin_lock_irq(&hdsp->lock);
2521 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2522 spin_unlock_irq(&hdsp->lock);
2528 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2532 if (!snd_hdsp_use_is_exclusive(hdsp))
2535 spin_lock_irq(&hdsp->lock);
2536 change = (int)val != hdsp->precise_ptr;
2537 hdsp_set_precise_pointer(hdsp, val);
2538 spin_unlock_irq(&hdsp->lock);
2551 static int hdsp_set_use_midi_work(struct hdsp *hdsp, int use_work)
2554 hdsp->use_midi_work = 1;
2556 hdsp->use_midi_work = 0;
2564 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2566 spin_lock_irq(&hdsp->lock);
2567 ucontrol->value.integer.value[0] = hdsp->use_midi_work;
2568 spin_unlock_irq(&hdsp->lock);
2574 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2578 if (!snd_hdsp_use_is_exclusive(hdsp))
2581 spin_lock_irq(&hdsp->lock);
2582 change = (int)val != hdsp->use_midi_work;
2583 hdsp_set_use_midi_work(hdsp, val);
2584 spin_unlock_irq(&hdsp->lock);
2612 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2620 if (source >= hdsp->max_channels)
2621 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2623 addr = hdsp_input_to_output_key(hdsp,source, destination);
2625 spin_lock_irq(&hdsp->lock);
2626 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2627 spin_unlock_irq(&hdsp->lock);
2633 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2640 if (!snd_hdsp_use_is_exclusive(hdsp))
2646 if (source >= hdsp->max_channels)
2647 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2649 addr = hdsp_input_to_output_key(hdsp,source, destination);
2653 spin_lock_irq(&hdsp->lock);
2654 change = gain != hdsp_read_gain(hdsp, addr);
2656 hdsp_write_gain(hdsp, addr, gain);
2657 spin_unlock_irq(&hdsp->lock);
2677 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2679 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2692 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2694 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2707 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2709 int status = hdsp_read(hdsp, HDSP_statusRegister);
2723 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2725 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
2738 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
2740 int status = hdsp_read(hdsp, HDSP_statusRegister);
2752 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2754 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
2765 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
2767 int status = hdsp_read(hdsp, HDSP_statusRegister);
2781 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2787 switch (hdsp->io_type) {
2802 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
2815 static int hdsp_dds_offset(struct hdsp *hdsp)
2818 unsigned int dds_value = hdsp->dds_value;
2819 int system_sample_rate = hdsp->system_sample_rate;
2837 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
2839 int rate = hdsp->system_sample_rate + offset_hz;
2840 hdsp_set_dds_value(hdsp, rate);
2855 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2857 ucontrol->value.integer.value[0] = hdsp_dds_offset(hdsp);
2863 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2867 if (!snd_hdsp_use_is_exclusive(hdsp))
2870 spin_lock_irq(&hdsp->lock);
2871 if (val != hdsp_dds_offset(hdsp))
2872 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
2875 spin_unlock_irq(&hdsp->lock);
2954 static int hdsp_rpm_input12(struct hdsp *hdsp)
2956 switch (hdsp->control_register & HDSP_RPM_Inp12) {
2972 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2974 ucontrol->value.enumerated.item[0] = hdsp_rpm_input12(hdsp);
2979 static int hdsp_set_rpm_input12(struct hdsp *hdsp, int mode)
2981 hdsp->control_register &= ~HDSP_RPM_Inp12;
2984 hdsp->control_register |= HDSP_RPM_Inp12_Phon_6dB;
2989 hdsp->control_register |= HDSP_RPM_Inp12_Phon_n6dB;
2992 hdsp->control_register |= HDSP_RPM_Inp12_Line_0dB;
2995 hdsp->control_register |= HDSP_RPM_Inp12_Line_n6dB;
3001 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3008 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3012 if (!snd_hdsp_use_is_exclusive(hdsp))
3019 spin_lock_irq(&hdsp->lock);
3020 if (val != hdsp_rpm_input12(hdsp))
3021 change = (hdsp_set_rpm_input12(hdsp, val) == 0) ? 1 : 0;
3024 spin_unlock_irq(&hdsp->lock);
3039 static int hdsp_rpm_input34(struct hdsp *hdsp)
3041 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3057 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3059 ucontrol->value.enumerated.item[0] = hdsp_rpm_input34(hdsp);
3064 static int hdsp_set_rpm_input34(struct hdsp *hdsp, int mode)
3066 hdsp->control_register &= ~HDSP_RPM_Inp34;
3069 hdsp->control_register |= HDSP_RPM_Inp34_Phon_6dB;
3074 hdsp->control_register |= HDSP_RPM_Inp34_Phon_n6dB;
3077 hdsp->control_register |= HDSP_RPM_Inp34_Line_0dB;
3080 hdsp->control_register |= HDSP_RPM_Inp34_Line_n6dB;
3086 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3093 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3097 if (!snd_hdsp_use_is_exclusive(hdsp))
3104 spin_lock_irq(&hdsp->lock);
3105 if (val != hdsp_rpm_input34(hdsp))
3106 change = (hdsp_set_rpm_input34(hdsp, val) == 0) ? 1 : 0;
3109 spin_unlock_irq(&hdsp->lock);
3115 static int hdsp_rpm_bypass(struct hdsp *hdsp)
3117 return (hdsp->control_register & HDSP_RPM_Bypass) ? 1 : 0;
3123 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3125 ucontrol->value.integer.value[0] = hdsp_rpm_bypass(hdsp);
3130 static int hdsp_set_rpm_bypass(struct hdsp *hdsp, int on)
3133 hdsp->control_register |= HDSP_RPM_Bypass;
3135 hdsp->control_register &= ~HDSP_RPM_Bypass;
3136 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3143 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3147 if (!snd_hdsp_use_is_exclusive(hdsp))
3150 spin_lock_irq(&hdsp->lock);
3151 change = (int)val != hdsp_rpm_bypass(hdsp);
3152 hdsp_set_rpm_bypass(hdsp, val);
3153 spin_unlock_irq(&hdsp->lock);
3167 static int hdsp_rpm_disconnect(struct hdsp *hdsp)
3169 return (hdsp->control_register & HDSP_RPM_Disconnect) ? 1 : 0;
3175 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3177 ucontrol->value.integer.value[0] = hdsp_rpm_disconnect(hdsp);
3182 static int hdsp_set_rpm_disconnect(struct hdsp *hdsp, int on)
3185 hdsp->control_register |= HDSP_RPM_Disconnect;
3187 hdsp->control_register &= ~HDSP_RPM_Disconnect;
3188 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3195 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3199 if (!snd_hdsp_use_is_exclusive(hdsp))
3202 spin_lock_irq(&hdsp->lock);
3203 change = (int)val != hdsp_rpm_disconnect(hdsp);
3204 hdsp_set_rpm_disconnect(hdsp, val);
3205 spin_unlock_irq(&hdsp->lock);
3255 static bool hdsp_loopback_get(struct hdsp *const hdsp, const u8 channel)
3257 return hdsp->io_loopback & (1 << channel);
3260 static int hdsp_loopback_set(struct hdsp *const hdsp, const u8 channel, const bool enable)
3262 if (hdsp_loopback_get(hdsp, channel) == enable)
3265 hdsp->io_loopback ^= (1 << channel);
3267 hdsp_write(hdsp, HDSP_inputEnable + (4 * (hdsp->max_channels + channel)), enable);
3275 struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol);
3278 if (channel >= hdsp->max_channels)
3281 ucontrol->value.integer.value[0] = hdsp_loopback_get(hdsp, channel);
3289 struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol);
3293 if (channel >= hdsp->max_channels)
3296 return hdsp_loopback_set(hdsp, channel, enable);
3308 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3314 if (hdsp->io_type == RPM) {
3317 err = snd_ctl_add(card, snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp));
3325 kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp);
3330 hdsp->spdif_ctl = kctl;
3336 kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp);
3340 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3343 kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp);
3351 if (hdsp->io_type == H9632) {
3353 kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp);
3361 if (hdsp->io_type == H9632) {
3362 snd_hdsp_loopback_control.count = hdsp->max_channels;
3363 kctl = snd_ctl_new1(&snd_hdsp_loopback_control, hdsp);
3372 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3373 kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp);
3389 struct hdsp *hdsp = entry->private_data;
3398 status = hdsp_read(hdsp, HDSP_statusRegister);
3399 status2 = hdsp_read(hdsp, HDSP_status2Register);
3401 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name,
3402 hdsp->card->number + 1);
3404 hdsp->capture_buffer, hdsp->playback_buffer);
3406 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3407 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3409 hdsp->control2_register);
3413 if (hdsp_check_for_iobox(hdsp)) {
3419 if (hdsp_check_for_firmware(hdsp, 0)) {
3420 if (hdsp->state & HDSP_FirmwareCached) {
3421 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3430 err = hdsp_request_fw_loader(hdsp);
3440 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3441 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3442 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3443 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3444 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3445 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_work ? "on" : "off");
3449 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3451 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3452 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3453 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3454 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3460 switch (hdsp_clock_source(hdsp)) {
3496 if (hdsp_system_clock_mode(hdsp))
3501 switch (hdsp_pref_sync_ref (hdsp)) {
3526 switch (hdsp_autosync_ref (hdsp)) {
3554 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3558 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3559 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3563 if (hdsp->io_type != RPM) {
3564 switch (hdsp_spdif_in(hdsp)) {
3583 if (RPM == hdsp->io_type) {
3584 if (hdsp->control_register & HDSP_RPM_Bypass)
3588 if (hdsp->control_register & HDSP_RPM_Disconnect)
3593 switch (hdsp->control_register & HDSP_RPM_Inp12) {
3613 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3634 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3639 if (hdsp->control_register & HDSP_SPDIFProfessional)
3644 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3649 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3653 x = hdsp_spdif_sample_rate(hdsp);
3668 switch (hdsp->io_type) {
3708 if (hdsp->io_type == H9632) {
3711 switch (hdsp_ad_gain(hdsp)) {
3724 switch (hdsp_da_gain(hdsp)) {
3737 switch (hdsp_phone_gain(hdsp)) {
3751 hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ?
3754 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3763 static void snd_hdsp_proc_init(struct hdsp *hdsp)
3765 snd_card_ro_proc_new(hdsp->card, "hdsp", hdsp, snd_hdsp_proc_read);
3768 static int snd_hdsp_initialize_memory(struct hdsp *hdsp)
3772 capture_dma = snd_hammerfall_get_buffer(hdsp->pci, HDSP_DMA_AREA_BYTES);
3773 playback_dma = snd_hammerfall_get_buffer(hdsp->pci, HDSP_DMA_AREA_BYTES);
3775 dev_err(hdsp->card->dev,
3776 "%s: no buffers available\n", hdsp->card_name);
3781 hdsp->capture_dma_buf = *capture_dma;
3782 hdsp->playback_dma_buf = *playback_dma;
3785 hdsp->capture_dma_buf.addr = ALIGN(capture_dma->addr, 0x10000ul);
3786 hdsp->playback_dma_buf.addr = ALIGN(playback_dma->addr, 0x10000ul);
3789 hdsp_write(hdsp, HDSP_inputBufferAddress, hdsp->capture_dma_buf.addr);
3790 hdsp_write(hdsp, HDSP_outputBufferAddress, hdsp->playback_dma_buf.addr);
3792 hdsp->capture_dma_buf.area += hdsp->capture_dma_buf.addr - capture_dma->addr;
3793 hdsp->playback_dma_buf.area += hdsp->playback_dma_buf.addr - playback_dma->addr;
3794 hdsp->capture_buffer = hdsp->capture_dma_buf.area;
3795 hdsp->playback_buffer = hdsp->playback_dma_buf.area;
3800 static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3804 /* ASSUMPTION: hdsp->lock is either held, or
3818 hdsp->control_register = HDSP_ClockModeMaster |
3824 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3827 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3829 hdsp->control2_register = 0;
3831 if (hdsp->io_type == H9652)
3832 snd_hdsp_9652_enable_mixer (hdsp);
3834 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3836 hdsp_reset_hw_pointer(hdsp);
3837 hdsp_compute_period_size(hdsp);
3842 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3844 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3845 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3850 if (hdsp->io_type == H9632) {
3851 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3852 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3858 hdsp_set_rate(hdsp, 48000, 1);
3865 struct hdsp *hdsp = container_of(work, struct hdsp, midi_work);
3867 if (hdsp->midi[0].pending)
3868 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3869 if (hdsp->midi[1].pending)
3870 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3875 struct hdsp *hdsp = (struct hdsp *) dev_id;
3884 status = hdsp_read(hdsp, HDSP_statusRegister);
3893 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3895 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3896 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3898 if (!(hdsp->state & HDSP_InitializationComplete))
3902 if (hdsp->capture_substream)
3903 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3905 if (hdsp->playback_substream)
3906 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3910 if (hdsp->use_midi_work) {
3912 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3913 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3914 hdsp->midi[0].pending = 1;
3917 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3920 if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) {
3921 if (hdsp->use_midi_work) {
3923 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3924 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3925 hdsp->midi[1].pending = 1;
3928 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3931 if (hdsp->use_midi_work && schedule)
3932 queue_work(system_highpri_wq, &hdsp->midi_work);
3938 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3939 return hdsp_hw_pointer(hdsp);
3942 static signed char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3949 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3952 mapped_channel = hdsp->channel_map[channel];
3957 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3959 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3966 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3972 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3984 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3990 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
4002 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4005 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
4015 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4018 other = hdsp->capture_substream;
4020 other = hdsp->playback_substream;
4021 if (hdsp->running)
4022 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
4041 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4046 if (hdsp_check_for_iobox (hdsp))
4049 if (hdsp_check_for_firmware(hdsp, 1))
4052 spin_lock_irq(&hdsp->lock);
4055 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
4056 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
4057 this_pid = hdsp->playback_pid;
4058 other_pid = hdsp->capture_pid;
4060 this_pid = hdsp->capture_pid;
4061 other_pid = hdsp->playback_pid;
4071 if (params_rate(params) != hdsp->system_sample_rate) {
4072 spin_unlock_irq(&hdsp->lock);
4077 if (params_period_size(params) != hdsp->period_bytes / 4) {
4078 spin_unlock_irq(&hdsp->lock);
4085 spin_unlock_irq(&hdsp->lock);
4089 spin_unlock_irq(&hdsp->lock);
4095 spin_lock_irq(&hdsp->lock);
4096 if (! hdsp->clock_source_locked) {
4097 err = hdsp_set_rate(hdsp, params_rate(params), 0);
4099 spin_unlock_irq(&hdsp->lock);
4104 spin_unlock_irq(&hdsp->lock);
4106 err = hdsp_set_interrupt_interval(hdsp, params_period_size(params));
4118 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4121 if (snd_BUG_ON(channel >= hdsp->max_channels))
4123 channel = array_index_nospec(channel, hdsp->max_channels);
4125 if (hdsp->channel_map[channel] < 0)
4128 info->offset = hdsp->channel_map[channel] * HDSP_CHANNEL_BUFFER_BYTES;
4151 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4155 if (hdsp_check_for_iobox (hdsp))
4158 if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
4161 spin_lock(&hdsp->lock);
4162 running = hdsp->running;
4172 spin_unlock(&hdsp->lock);
4176 other = hdsp->capture_substream;
4178 other = hdsp->playback_substream;
4195 hdsp_silence_playback(hdsp);
4199 hdsp_silence_playback(hdsp);
4203 hdsp_silence_playback(hdsp);
4207 if (!hdsp->running && running)
4208 hdsp_start_audio(hdsp);
4209 else if (hdsp->running && !running)
4210 hdsp_stop_audio(hdsp);
4211 hdsp->running = running;
4212 spin_unlock(&hdsp->lock);
4219 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4222 if (hdsp_check_for_iobox (hdsp))
4225 if (hdsp_check_for_firmware(hdsp, 1))
4228 spin_lock_irq(&hdsp->lock);
4229 if (!hdsp->running)
4230 hdsp_reset_hw_pointer(hdsp);
4231 spin_unlock_irq(&hdsp->lock);
4313 struct hdsp *hdsp = rule->private;
4315 if (hdsp->io_type == H9632) {
4317 list[0] = hdsp->qs_in_channels;
4318 list[1] = hdsp->ds_in_channels;
4319 list[2] = hdsp->ss_in_channels;
4323 list[0] = hdsp->ds_in_channels;
4324 list[1] = hdsp->ss_in_channels;
4333 struct hdsp *hdsp = rule->private;
4335 if (hdsp->io_type == H9632) {
4336 list[0] = hdsp->qs_out_channels;
4337 list[1] = hdsp->ds_out_channels;
4338 list[2] = hdsp->ss_out_channels;
4341 list[0] = hdsp->ds_out_channels;
4342 list[1] = hdsp->ss_out_channels;
4350 struct hdsp *hdsp = rule->private;
4353 if (r->min > 96000 && hdsp->io_type == H9632) {
4355 .min = hdsp->qs_in_channels,
4356 .max = hdsp->qs_in_channels,
4362 .min = hdsp->ds_in_channels,
4363 .max = hdsp->ds_in_channels,
4369 .min = hdsp->ss_in_channels,
4370 .max = hdsp->ss_in_channels,
4381 struct hdsp *hdsp = rule->private;
4384 if (r->min > 96000 && hdsp->io_type == H9632) {
4386 .min = hdsp->qs_out_channels,
4387 .max = hdsp->qs_out_channels,
4393 .min = hdsp->ds_out_channels,
4394 .max = hdsp->ds_out_channels,
4400 .min = hdsp->ss_out_channels,
4401 .max = hdsp->ss_out_channels,
4412 struct hdsp *hdsp = rule->private;
4415 if (c->min >= hdsp->ss_out_channels) {
4422 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4429 } else if (c->max <= hdsp->ds_out_channels) {
4443 struct hdsp *hdsp = rule->private;
4446 if (c->min >= hdsp->ss_in_channels) {
4453 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4460 } else if (c->max <= hdsp->ds_in_channels) {
4473 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4476 if (hdsp_check_for_iobox (hdsp))
4479 if (hdsp_check_for_firmware(hdsp, 1))
4482 spin_lock_irq(&hdsp->lock);
4487 snd_pcm_set_runtime_buffer(substream, &hdsp->playback_dma_buf);
4489 hdsp->playback_pid = current->pid;
4490 hdsp->playback_substream = substream;
4492 spin_unlock_irq(&hdsp->lock);
4496 if (hdsp->clock_source_locked) {
4497 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4498 } else if (hdsp->io_type == H9632) {
4503 if (hdsp->io_type == H9632) {
4504 runtime->hw.channels_min = hdsp->qs_out_channels;
4505 runtime->hw.channels_max = hdsp->ss_out_channels;
4509 snd_hdsp_hw_rule_out_channels, hdsp,
4512 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4515 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4518 if (RPM != hdsp->io_type) {
4519 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4520 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4521 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4522 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4529 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4531 spin_lock_irq(&hdsp->lock);
4533 hdsp->playback_pid = -1;
4534 hdsp->playback_substream = NULL;
4536 spin_unlock_irq(&hdsp->lock);
4538 if (RPM != hdsp->io_type) {
4539 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4540 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4541 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4549 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4552 if (hdsp_check_for_iobox (hdsp))
4555 if (hdsp_check_for_firmware(hdsp, 1))
4558 spin_lock_irq(&hdsp->lock);
4563 snd_pcm_set_runtime_buffer(substream, &hdsp->capture_dma_buf);
4565 hdsp->capture_pid = current->pid;
4566 hdsp->capture_substream = substream;
4568 spin_unlock_irq(&hdsp->lock);
4572 if (hdsp->io_type == H9632) {
4573 runtime->hw.channels_min = hdsp->qs_in_channels;
4574 runtime->hw.channels_max = hdsp->ss_in_channels;
4580 snd_hdsp_hw_rule_in_channels, hdsp,
4583 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4586 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4593 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4595 spin_lock_irq(&hdsp->lock);
4597 hdsp->capture_pid = -1;
4598 hdsp->capture_substream = NULL;
4600 spin_unlock_irq(&hdsp->lock);
4631 static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4636 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4643 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4646 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4649 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4652 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4653 hdsp->iobase + ofs + 4))
4656 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4657 hdsp->iobase + ofs + 4))
4660 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4661 hdsp->iobase + ofs + 4))
4668 static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4674 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4676 m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4698 static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4704 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4707 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4712 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4717 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4718 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4721 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4722 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4730 struct hdsp *hdsp = hw->private_data;
4738 err = hdsp_check_for_iobox(hdsp);
4742 err = hdsp_check_for_firmware(hdsp, 1);
4746 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4747 dev_err(hdsp->card->dev,
4752 switch (hdsp->io_type) {
4754 return hdsp_9652_get_peak(hdsp, peak_rms);
4756 return hdsp_9632_get_peak(hdsp, peak_rms);
4758 return hdsp_get_peak(hdsp, peak_rms);
4766 err = hdsp_check_for_iobox(hdsp);
4770 err = hdsp_check_for_firmware(hdsp, 1);
4775 spin_lock_irqsave(&hdsp->lock, flags);
4776 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4777 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4778 if (hdsp->io_type != H9632)
4779 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4780 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4781 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i)
4782 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4783 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4784 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp,
4787 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional);
4789 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis);
4791 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio);
4792 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4793 info.system_sample_rate = hdsp->system_sample_rate;
4794 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4795 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4796 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4797 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4799 hdsp_toggle_setting(hdsp, HDSP_LineOut);
4800 if (hdsp->io_type == H9632) {
4801 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4802 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4803 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4805 (unsigned char)hdsp_toggle_setting(hdsp,
4808 } else if (hdsp->io_type == RPM) {
4809 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp);
4810 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp);
4812 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4814 (unsigned char)hdsp_toggle_setting(hdsp,
4816 spin_unlock_irqrestore(&hdsp->lock, flags);
4824 if (hdsp->io_type != H9632) return -EINVAL;
4825 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4826 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4835 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4836 if (hdsp->io_type == Undefined) {
4837 err = hdsp_get_iobox_version(hdsp);
4842 hdsp_version.io_type = hdsp->io_type;
4843 hdsp_version.firmware_rev = hdsp->firmware_rev;
4853 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4855 if (hdsp->io_type == Undefined) return -EINVAL;
4857 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4860 dev_info(hdsp->card->dev,
4866 if (hdsp_check_for_iobox (hdsp))
4869 if (!hdsp->fw_uploaded) {
4870 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE);
4871 if (!hdsp->fw_uploaded)
4875 if (copy_from_user(hdsp->fw_uploaded, firmware_data,
4877 vfree(hdsp->fw_uploaded);
4878 hdsp->fw_uploaded = NULL;
4882 hdsp->state |= HDSP_FirmwareCached;
4884 err = snd_hdsp_load_firmware_from_cache(hdsp);
4888 if (!(hdsp->state & HDSP_InitializationComplete)) {
4889 err = snd_hdsp_enable_io(hdsp);
4893 snd_hdsp_initialize_channels(hdsp);
4894 snd_hdsp_initialize_midi_flush(hdsp);
4896 err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp);
4898 dev_err(hdsp->card->dev,
4907 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4940 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4949 hdsp->hwdep = hw;
4950 hw->private_data = hdsp;
4959 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4964 err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm);
4968 hdsp->pcm = pcm;
4969 pcm->private_data = hdsp;
4970 strcpy(pcm->name, hdsp->card_name);
4980 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
4982 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4983 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4986 static int snd_hdsp_enable_io (struct hdsp *hdsp)
4990 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4991 dev_err(hdsp->card->dev,
4996 for (i = 0; i < hdsp->max_channels; ++i) {
4997 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4998 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
5004 static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
5008 switch (hdsp->io_type) {
5010 hdsp->card_name = "RME Hammerfall DSP + Digiface";
5011 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
5012 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
5016 hdsp->card_name = "RME Hammerfall HDSP 9652";
5017 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
5018 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
5022 status = hdsp_read(hdsp, HDSP_statusRegister);
5026 hdsp->card_name = "RME Hammerfall HDSP 9632";
5027 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
5028 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
5029 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
5030 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
5031 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
5032 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
5036 hdsp->io_loopback = 0xffffffff;
5037 for (i = 0; i < hdsp->max_channels; ++i)
5038 hdsp_loopback_set(hdsp, i, false);
5042 hdsp->card_name = "RME Hammerfall DSP + Multiface";
5043 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
5044 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
5048 hdsp->card_name = "RME Hammerfall DSP + RPM";
5049 hdsp->ss_in_channels = RPM_CHANNELS-1;
5050 hdsp->ss_out_channels = RPM_CHANNELS;
5051 hdsp->ds_in_channels = RPM_CHANNELS-1;
5052 hdsp->ds_out_channels = RPM_CHANNELS;
5061 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
5063 snd_hdsp_flush_midi_input (hdsp, 0);
5064 snd_hdsp_flush_midi_input (hdsp, 1);
5067 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
5071 err = snd_hdsp_create_pcm(card, hdsp);
5079 err = snd_hdsp_create_midi(card, hdsp, 0);
5086 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
5087 err = snd_hdsp_create_midi(card, hdsp, 1);
5095 err = snd_hdsp_create_controls(card, hdsp);
5102 snd_hdsp_proc_init(hdsp);
5104 hdsp->system_sample_rate = -1;
5105 hdsp->playback_pid = -1;
5106 hdsp->capture_pid = -1;
5107 hdsp->capture_substream = NULL;
5108 hdsp->playback_substream = NULL;
5110 err = snd_hdsp_set_defaults(hdsp);
5117 if (!(hdsp->state & HDSP_InitializationComplete)) {
5119 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5120 hdsp->port, hdsp->irq);
5128 hdsp->state |= HDSP_InitializationComplete;
5135 static int hdsp_request_fw_loader(struct hdsp *hdsp)
5141 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5143 if (hdsp->io_type == Undefined) {
5144 err = hdsp_get_iobox_version(hdsp);
5147 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5152 switch (hdsp->io_type) {
5157 if (hdsp->firmware_rev == 0xa)
5163 if (hdsp->firmware_rev == 0xa)
5169 dev_err(hdsp->card->dev,
5170 "invalid io_type %d\n", hdsp->io_type);
5174 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
5175 dev_err(hdsp->card->dev,
5180 dev_err(hdsp->card->dev,
5187 hdsp->firmware = fw;
5189 hdsp->state |= HDSP_FirmwareCached;
5191 err = snd_hdsp_load_firmware_from_cache(hdsp);
5195 if (!(hdsp->state & HDSP_InitializationComplete)) {
5196 err = snd_hdsp_enable_io(hdsp);
5200 err = snd_hdsp_create_hwdep(hdsp->card, hdsp);
5202 dev_err(hdsp->card->dev,
5206 snd_hdsp_initialize_channels(hdsp);
5207 snd_hdsp_initialize_midi_flush(hdsp);
5208 err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp);
5210 dev_err(hdsp->card->dev,
5219 struct hdsp *hdsp)
5221 struct pci_dev *pci = hdsp->pci;
5226 hdsp->irq = -1;
5227 hdsp->state = 0;
5228 hdsp->midi[0].rmidi = NULL;
5229 hdsp->midi[1].rmidi = NULL;
5230 hdsp->midi[0].input = NULL;
5231 hdsp->midi[1].input = NULL;
5232 hdsp->midi[0].output = NULL;
5233 hdsp->midi[1].output = NULL;
5234 hdsp->midi[0].pending = 0;
5235 hdsp->midi[1].pending = 0;
5236 spin_lock_init(&hdsp->midi[0].lock);
5237 spin_lock_init(&hdsp->midi[1].lock);
5238 hdsp->iobase = NULL;
5239 hdsp->control_register = 0;
5240 hdsp->control2_register = 0;
5241 hdsp->io_type = Undefined;
5242 hdsp->max_channels = 26;
5244 hdsp->card = card;
5246 spin_lock_init(&hdsp->lock);
5248 INIT_WORK(&hdsp->midi_work, hdsp_midi_work);
5250 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5251 hdsp->firmware_rev &= 0xff;
5260 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5265 if (hdsp->firmware_rev < 0xa)
5267 else if (hdsp->firmware_rev < 0x64)
5268 hdsp->card_name = "RME Hammerfall DSP";
5269 else if (hdsp->firmware_rev < 0x96) {
5270 hdsp->card_name = "RME HDSP 9652";
5273 hdsp->card_name = "RME HDSP 9632";
5274 hdsp->max_channels = 16;
5282 pci_set_master(hdsp->pci);
5284 err = pci_request_regions(pci, "hdsp");
5287 hdsp->port = pci_resource_start(pci, 0);
5288 hdsp->iobase = devm_ioremap(&pci->dev, hdsp->port, HDSP_IO_EXTENT);
5289 if (!hdsp->iobase) {
5290 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
5291 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5296 IRQF_SHARED, KBUILD_MODNAME, hdsp)) {
5297 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
5301 hdsp->irq = pci->irq;
5302 card->sync_irq = hdsp->irq;
5303 hdsp->precise_ptr = 0;
5304 hdsp->use_midi_work = 1;
5305 hdsp->dds_value = 0;
5307 err = snd_hdsp_initialize_memory(hdsp);
5314 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5319 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5320 err = hdsp_request_fw_loader(hdsp);
5326 dev_err(hdsp->card->dev,
5332 dev_info(hdsp->card->dev,
5334 err = snd_hdsp_create_hwdep(card, hdsp);
5339 dev_info(hdsp->card->dev,
5341 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5342 hdsp->io_type = RPM;
5343 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5344 hdsp->io_type = Multiface;
5346 hdsp->io_type = Digiface;
5350 err = snd_hdsp_enable_io(hdsp);
5355 hdsp->io_type = H9652;
5358 hdsp->io_type = H9632;
5360 err = snd_hdsp_create_hwdep(card, hdsp);
5364 snd_hdsp_initialize_channels(hdsp);
5365 snd_hdsp_initialize_midi_flush(hdsp);
5367 hdsp->state |= HDSP_FirmwareLoaded;
5369 err = snd_hdsp_create_alsa_devices(card, hdsp);
5378 struct hdsp *hdsp = card->private_data;
5380 if (hdsp->port) {
5382 cancel_work_sync(&hdsp->midi_work);
5383 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5384 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5387 release_firmware(hdsp->firmware);
5388 vfree(hdsp->fw_uploaded);
5395 struct hdsp *hdsp;
5407 sizeof(struct hdsp), &card);
5411 hdsp = card->private_data;
5413 hdsp->dev = dev;
5414 hdsp->pci = pci;
5415 err = snd_hdsp_create(card, hdsp);
5420 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5421 hdsp->port, hdsp->irq);