Lines Matching refs:hdsp

29 #include <sound/hdsp.h>
434 struct hdsp *hdsp;
445 struct hdsp {
595 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
596 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
597 static int snd_hdsp_enable_io (struct hdsp *hdsp);
598 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
599 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
600 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
601 static int hdsp_autosync_ref(struct hdsp *hdsp);
602 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
603 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
605 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
607 switch (hdsp->io_type) {
612 if (hdsp->firmware_rev == 0xa)
623 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
625 switch (hdsp->io_type) {
630 if (hdsp->firmware_rev == 0xa)
641 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
643 writel(val, hdsp->iobase + reg);
646 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
648 return readl (hdsp->iobase + reg);
651 static int hdsp_check_for_iobox (struct hdsp *hdsp)
655 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
657 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) &
660 dev_dbg(hdsp->card->dev,
668 dev_err(hdsp->card->dev, "no IO box connected!\n");
669 hdsp->state &= ~HDSP_FirmwareLoaded;
673 static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
678 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
682 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
685 dev_dbg(hdsp->card->dev, "iobox found after %ums!\n",
691 dev_info(hdsp->card->dev, "no IO box connected!\n");
692 hdsp->state &= ~HDSP_FirmwareLoaded;
696 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
702 if (hdsp->fw_uploaded)
703 cache = hdsp->fw_uploaded;
705 if (!hdsp->firmware)
707 cache = (u32 *)hdsp->firmware->data;
712 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
714 dev_info(hdsp->card->dev, "loading firmware\n");
716 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
717 hdsp_write (hdsp, HDSP_fifoData, 0);
719 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
720 dev_info(hdsp->card->dev,
722 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
726 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
729 hdsp_write(hdsp, HDSP_fifoData, cache[i]);
730 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
731 dev_info(hdsp->card->dev,
733 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
738 hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT);
739 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
743 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
745 hdsp->control2_register = 0;
747 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
748 dev_info(hdsp->card->dev, "finished firmware loading\n");
751 if (hdsp->state & HDSP_InitializationComplete) {
752 dev_info(hdsp->card->dev,
754 spin_lock_irqsave(&hdsp->lock, flags);
755 snd_hdsp_set_defaults(hdsp);
756 spin_unlock_irqrestore(&hdsp->lock, flags);
759 hdsp->state |= HDSP_FirmwareLoaded;
764 static int hdsp_get_iobox_version (struct hdsp *hdsp)
766 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
768 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
769 hdsp_write(hdsp, HDSP_fifoData, 0);
771 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
772 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
773 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
776 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM);
777 hdsp_write (hdsp, HDSP_fifoData, 0);
778 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
781 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
782 hdsp_write(hdsp, HDSP_fifoData, 0);
783 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
784 hdsp->io_type = Digiface;
785 dev_info(hdsp->card->dev, "Digiface found\n");
789 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
790 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
791 hdsp_write(hdsp, HDSP_fifoData, 0);
792 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0)
795 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
796 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
797 hdsp_write(hdsp, HDSP_fifoData, 0);
798 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
801 hdsp->io_type = RPM;
802 dev_info(hdsp->card->dev, "RPM found\n");
806 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
807 hdsp->io_type = RPM;
808 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
809 hdsp->io_type = Multiface;
811 hdsp->io_type = Digiface;
816 hdsp->io_type = Multiface;
817 dev_info(hdsp->card->dev, "Multiface found\n");
822 static int hdsp_request_fw_loader(struct hdsp *hdsp);
824 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
826 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
828 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
829 hdsp->state &= ~HDSP_FirmwareLoaded;
832 dev_err(hdsp->card->dev, "firmware not present.\n");
834 if (! (hdsp->state & HDSP_FirmwareCached)) {
835 if (! hdsp_request_fw_loader(hdsp))
837 dev_err(hdsp->card->dev,
841 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
842 dev_err(hdsp->card->dev,
851 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
861 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
871 dev_warn(hdsp->card->dev,
877 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
882 return hdsp->mixer_matrix[addr];
885 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
892 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
906 if (hdsp->io_type == H9632 && addr >= 512)
909 if (hdsp->io_type == H9652 && addr >= 1352)
912 hdsp->mixer_matrix[addr] = data;
924 hdsp_write (hdsp, 4096 + (ad*4),
925 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
926 hdsp->mixer_matrix[addr&0x7fe]);
934 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
937 hdsp_write (hdsp, HDSP_fifoData, ad);
938 hdsp->mixer_matrix[addr] = data;
945 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
950 spin_lock_irqsave(&hdsp->lock, flags);
951 if ((hdsp->playback_pid != hdsp->capture_pid) &&
952 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
954 spin_unlock_irqrestore(&hdsp->lock, flags);
958 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
960 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
964 if (hdsp->io_type == H9632)
978 if (hdsp->io_type == H9632) return 128000;
981 if (hdsp->io_type == H9632) return 176400;
984 if (hdsp->io_type == H9632) return 192000;
989 dev_warn(hdsp->card->dev,
995 static int hdsp_external_sample_rate(struct hdsp *hdsp)
997 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
1004 if (hdsp->io_type == H9632 &&
1005 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
1006 return hdsp_spdif_sample_rate(hdsp);
1020 static void hdsp_compute_period_size(struct hdsp *hdsp)
1022 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
1025 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
1029 position = hdsp_read(hdsp, HDSP_statusRegister);
1031 if (!hdsp->precise_ptr)
1032 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
1036 position &= (hdsp->period_bytes/2) - 1;
1040 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
1042 hdsp_write (hdsp, HDSP_resetPointer, 0);
1043 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1047 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
1050 static void hdsp_start_audio(struct hdsp *s)
1056 static void hdsp_stop_audio(struct hdsp *s)
1062 static void hdsp_silence_playback(struct hdsp *hdsp)
1064 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
1067 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1092 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1107 hdsp->dds_value = n;
1108 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1111 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1117 /* ASSUMPTION: hdsp->lock is either held, or
1122 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1125 dev_err(hdsp->card->dev,
1130 int external_freq = hdsp_external_sample_rate(hdsp);
1131 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1133 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1134 dev_info(hdsp->card->dev,
1136 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1137 dev_info(hdsp->card->dev,
1140 dev_info(hdsp->card->dev,
1147 current_rate = hdsp->system_sample_rate;
1159 if (rate > 96000 && hdsp->io_type != H9632)
1212 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1213 dev_warn(hdsp->card->dev,
1215 hdsp->capture_pid,
1216 hdsp->playback_pid);
1220 hdsp->control_register &= ~HDSP_FrequencyMask;
1221 hdsp->control_register |= rate_bits;
1222 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1225 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1226 hdsp_set_dds_value(hdsp, rate);
1229 hdsp->channel_map = channel_map_H9632_qs;
1231 if (hdsp->io_type == H9632)
1232 hdsp->channel_map = channel_map_H9632_ds;
1234 hdsp->channel_map = channel_map_ds;
1236 switch (hdsp->io_type) {
1239 hdsp->channel_map = channel_map_mf_ss;
1243 hdsp->channel_map = channel_map_df_ss;
1246 hdsp->channel_map = channel_map_H9632_ss;
1254 hdsp->system_sample_rate = rate;
1263 static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
1267 return hdsp_read(hdsp, HDSP_midiDataIn1);
1269 return hdsp_read(hdsp, HDSP_midiDataIn0);
1272 static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
1276 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1278 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1281 static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
1284 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1286 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1289 static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
1294 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1296 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1304 static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
1306 while (snd_hdsp_midi_input_available (hdsp, id))
1307 snd_hdsp_midi_read_byte (hdsp, id);
1323 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1329 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1346 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1351 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1357 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1362 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1364 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1365 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1372 struct hdsp *hdsp;
1378 hdsp = hmidi->hdsp;
1380 spin_lock_irqsave (&hdsp->lock, flags);
1382 if (!(hdsp->control_register & ie)) {
1383 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1384 hdsp->control_register |= ie;
1387 hdsp->control_register &= ~ie;
1390 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1391 spin_unlock_irqrestore (&hdsp->lock, flags);
1443 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1504 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1508 hdsp->midi[id].id = id;
1509 hdsp->midi[id].rmidi = NULL;
1510 hdsp->midi[id].input = NULL;
1511 hdsp->midi[id].output = NULL;
1512 hdsp->midi[id].hdsp = hdsp;
1513 hdsp->midi[id].istimer = 0;
1514 hdsp->midi[id].pending = 0;
1515 spin_lock_init (&hdsp->midi[id].lock);
1518 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1521 sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1);
1522 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1524 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1525 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1527 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1569 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1571 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1577 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1582 spin_lock_irq(&hdsp->lock);
1583 change = val != hdsp->creg_spdif;
1584 hdsp->creg_spdif = val;
1585 spin_unlock_irq(&hdsp->lock);
1598 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1600 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1606 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1611 spin_lock_irq(&hdsp->lock);
1612 change = val != hdsp->creg_spdif_stream;
1613 hdsp->creg_spdif_stream = val;
1614 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1615 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1616 spin_unlock_irq(&hdsp->lock);
1641 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1643 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1646 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1648 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1649 hdsp->control_register |= hdsp_encode_spdif_in(in);
1650 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1659 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1661 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3,
1667 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1669 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1675 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1679 if (!snd_hdsp_use_is_exclusive(hdsp))
1681 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1682 spin_lock_irq(&hdsp->lock);
1683 change = val != hdsp_spdif_in(hdsp);
1685 hdsp_set_spdif_input(hdsp, val);
1686 spin_unlock_irq(&hdsp->lock);
1699 static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask)
1701 return (hdsp->control_register & regmask) ? 1 : 0;
1704 static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out)
1707 hdsp->control_register |= regmask;
1709 hdsp->control_register &= ~regmask;
1710 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1720 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1723 spin_lock_irq(&hdsp->lock);
1724 ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask);
1725 spin_unlock_irq(&hdsp->lock);
1732 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1737 if (!snd_hdsp_use_is_exclusive(hdsp))
1740 spin_lock_irq(&hdsp->lock);
1741 change = (int) val != hdsp_toggle_setting(hdsp, regmask);
1743 hdsp_set_toggle_setting(hdsp, regmask, val);
1744 spin_unlock_irq(&hdsp->lock);
1763 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1765 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1771 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1773 switch (hdsp_spdif_sample_rate(hdsp)) {
1825 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1827 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1842 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1848 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1854 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1856 switch (hdsp_external_sample_rate(hdsp)) {
1899 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1901 if (hdsp->control_register & HDSP_ClockModeMaster)
1903 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1917 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1919 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1932 static int hdsp_clock_source(struct hdsp *hdsp)
1934 if (hdsp->control_register & HDSP_ClockModeMaster) {
1935 switch (hdsp->system_sample_rate) {
1962 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
1967 if (hdsp_external_sample_rate(hdsp) != 0) {
1968 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
1969 hdsp->control_register &= ~HDSP_ClockModeMaster;
1970 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2005 hdsp->control_register |= HDSP_ClockModeMaster;
2006 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2007 hdsp_set_rate(hdsp, rate, 1);
2019 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2021 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
2027 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2029 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2035 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2039 if (!snd_hdsp_use_is_exclusive(hdsp))
2043 if (hdsp->io_type == H9632) {
2050 spin_lock_irq(&hdsp->lock);
2051 if (val != hdsp_clock_source(hdsp))
2052 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2055 spin_unlock_irq(&hdsp->lock);
2063 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2065 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2071 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2074 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2076 hdsp->clock_source_locked = !!ucontrol->value.integer.value[0];
2089 static int hdsp_da_gain(struct hdsp *hdsp)
2091 switch (hdsp->control_register & HDSP_DAGainMask) {
2103 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2105 hdsp->control_register &= ~HDSP_DAGainMask;
2108 hdsp->control_register |= HDSP_DAGainHighGain;
2111 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2114 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2120 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2133 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2135 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2141 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2145 if (!snd_hdsp_use_is_exclusive(hdsp))
2150 spin_lock_irq(&hdsp->lock);
2151 if (val != hdsp_da_gain(hdsp))
2152 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2155 spin_unlock_irq(&hdsp->lock);
2168 static int hdsp_ad_gain(struct hdsp *hdsp)
2170 switch (hdsp->control_register & HDSP_ADGainMask) {
2182 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2184 hdsp->control_register &= ~HDSP_ADGainMask;
2187 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2190 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2193 hdsp->control_register |= HDSP_ADGainLowGain;
2199 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2212 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2214 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2220 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2224 if (!snd_hdsp_use_is_exclusive(hdsp))
2229 spin_lock_irq(&hdsp->lock);
2230 if (val != hdsp_ad_gain(hdsp))
2231 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2234 spin_unlock_irq(&hdsp->lock);
2247 static int hdsp_phone_gain(struct hdsp *hdsp)
2249 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2261 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2263 hdsp->control_register &= ~HDSP_PhoneGainMask;
2266 hdsp->control_register |= HDSP_PhoneGain0dB;
2269 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2272 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2278 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2291 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2293 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2299 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2303 if (!snd_hdsp_use_is_exclusive(hdsp))
2308 spin_lock_irq(&hdsp->lock);
2309 if (val != hdsp_phone_gain(hdsp))
2310 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2313 spin_unlock_irq(&hdsp->lock);
2326 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2332 switch (hdsp->control_register & HDSP_SyncRefMask) {
2351 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2353 hdsp->control_register &= ~HDSP_SyncRefMask;
2356 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2359 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2362 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2365 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2368 hdsp->control_register |= HDSP_SyncRef_WORD;
2371 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2376 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2385 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2388 switch (hdsp->io_type) {
2408 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2410 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2416 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2420 if (!snd_hdsp_use_is_exclusive(hdsp))
2423 switch (hdsp->io_type) {
2439 spin_lock_irq(&hdsp->lock);
2440 change = (int)val != hdsp_pref_sync_ref(hdsp);
2441 hdsp_set_pref_sync_ref(hdsp, val);
2442 spin_unlock_irq(&hdsp->lock);
2455 static int hdsp_autosync_ref(struct hdsp *hdsp)
2458 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2492 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2494 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2507 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2510 hdsp->precise_ptr = 1;
2512 hdsp->precise_ptr = 0;
2520 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2522 spin_lock_irq(&hdsp->lock);
2523 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2524 spin_unlock_irq(&hdsp->lock);
2530 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2534 if (!snd_hdsp_use_is_exclusive(hdsp))
2537 spin_lock_irq(&hdsp->lock);
2538 change = (int)val != hdsp->precise_ptr;
2539 hdsp_set_precise_pointer(hdsp, val);
2540 spin_unlock_irq(&hdsp->lock);
2553 static int hdsp_set_use_midi_work(struct hdsp *hdsp, int use_work)
2556 hdsp->use_midi_work = 1;
2558 hdsp->use_midi_work = 0;
2566 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2568 spin_lock_irq(&hdsp->lock);
2569 ucontrol->value.integer.value[0] = hdsp->use_midi_work;
2570 spin_unlock_irq(&hdsp->lock);
2576 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2580 if (!snd_hdsp_use_is_exclusive(hdsp))
2583 spin_lock_irq(&hdsp->lock);
2584 change = (int)val != hdsp->use_midi_work;
2585 hdsp_set_use_midi_work(hdsp, val);
2586 spin_unlock_irq(&hdsp->lock);
2614 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2622 if (source >= hdsp->max_channels)
2623 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2625 addr = hdsp_input_to_output_key(hdsp,source, destination);
2627 spin_lock_irq(&hdsp->lock);
2628 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2629 spin_unlock_irq(&hdsp->lock);
2635 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2642 if (!snd_hdsp_use_is_exclusive(hdsp))
2648 if (source >= hdsp->max_channels)
2649 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2651 addr = hdsp_input_to_output_key(hdsp,source, destination);
2655 spin_lock_irq(&hdsp->lock);
2656 change = gain != hdsp_read_gain(hdsp, addr);
2658 hdsp_write_gain(hdsp, addr, gain);
2659 spin_unlock_irq(&hdsp->lock);
2679 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2681 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2694 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2696 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2709 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2711 int status = hdsp_read(hdsp, HDSP_statusRegister);
2725 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2727 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
2740 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
2742 int status = hdsp_read(hdsp, HDSP_statusRegister);
2754 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2756 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
2767 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
2769 int status = hdsp_read(hdsp, HDSP_statusRegister);
2783 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2789 switch (hdsp->io_type) {
2804 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
2817 static int hdsp_dds_offset(struct hdsp *hdsp)
2820 unsigned int dds_value = hdsp->dds_value;
2821 int system_sample_rate = hdsp->system_sample_rate;
2839 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
2841 int rate = hdsp->system_sample_rate + offset_hz;
2842 hdsp_set_dds_value(hdsp, rate);
2857 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2859 ucontrol->value.integer.value[0] = hdsp_dds_offset(hdsp);
2865 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2869 if (!snd_hdsp_use_is_exclusive(hdsp))
2872 spin_lock_irq(&hdsp->lock);
2873 if (val != hdsp_dds_offset(hdsp))
2874 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
2877 spin_unlock_irq(&hdsp->lock);
2956 static int hdsp_rpm_input12(struct hdsp *hdsp)
2958 switch (hdsp->control_register & HDSP_RPM_Inp12) {
2974 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2976 ucontrol->value.enumerated.item[0] = hdsp_rpm_input12(hdsp);
2981 static int hdsp_set_rpm_input12(struct hdsp *hdsp, int mode)
2983 hdsp->control_register &= ~HDSP_RPM_Inp12;
2986 hdsp->control_register |= HDSP_RPM_Inp12_Phon_6dB;
2991 hdsp->control_register |= HDSP_RPM_Inp12_Phon_n6dB;
2994 hdsp->control_register |= HDSP_RPM_Inp12_Line_0dB;
2997 hdsp->control_register |= HDSP_RPM_Inp12_Line_n6dB;
3003 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3010 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3014 if (!snd_hdsp_use_is_exclusive(hdsp))
3021 spin_lock_irq(&hdsp->lock);
3022 if (val != hdsp_rpm_input12(hdsp))
3023 change = (hdsp_set_rpm_input12(hdsp, val) == 0) ? 1 : 0;
3026 spin_unlock_irq(&hdsp->lock);
3041 static int hdsp_rpm_input34(struct hdsp *hdsp)
3043 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3059 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3061 ucontrol->value.enumerated.item[0] = hdsp_rpm_input34(hdsp);
3066 static int hdsp_set_rpm_input34(struct hdsp *hdsp, int mode)
3068 hdsp->control_register &= ~HDSP_RPM_Inp34;
3071 hdsp->control_register |= HDSP_RPM_Inp34_Phon_6dB;
3076 hdsp->control_register |= HDSP_RPM_Inp34_Phon_n6dB;
3079 hdsp->control_register |= HDSP_RPM_Inp34_Line_0dB;
3082 hdsp->control_register |= HDSP_RPM_Inp34_Line_n6dB;
3088 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3095 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3099 if (!snd_hdsp_use_is_exclusive(hdsp))
3106 spin_lock_irq(&hdsp->lock);
3107 if (val != hdsp_rpm_input34(hdsp))
3108 change = (hdsp_set_rpm_input34(hdsp, val) == 0) ? 1 : 0;
3111 spin_unlock_irq(&hdsp->lock);
3117 static int hdsp_rpm_bypass(struct hdsp *hdsp)
3119 return (hdsp->control_register & HDSP_RPM_Bypass) ? 1 : 0;
3125 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3127 ucontrol->value.integer.value[0] = hdsp_rpm_bypass(hdsp);
3132 static int hdsp_set_rpm_bypass(struct hdsp *hdsp, int on)
3135 hdsp->control_register |= HDSP_RPM_Bypass;
3137 hdsp->control_register &= ~HDSP_RPM_Bypass;
3138 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3145 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3149 if (!snd_hdsp_use_is_exclusive(hdsp))
3152 spin_lock_irq(&hdsp->lock);
3153 change = (int)val != hdsp_rpm_bypass(hdsp);
3154 hdsp_set_rpm_bypass(hdsp, val);
3155 spin_unlock_irq(&hdsp->lock);
3169 static int hdsp_rpm_disconnect(struct hdsp *hdsp)
3171 return (hdsp->control_register & HDSP_RPM_Disconnect) ? 1 : 0;
3177 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3179 ucontrol->value.integer.value[0] = hdsp_rpm_disconnect(hdsp);
3184 static int hdsp_set_rpm_disconnect(struct hdsp *hdsp, int on)
3187 hdsp->control_register |= HDSP_RPM_Disconnect;
3189 hdsp->control_register &= ~HDSP_RPM_Disconnect;
3190 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3197 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3201 if (!snd_hdsp_use_is_exclusive(hdsp))
3204 spin_lock_irq(&hdsp->lock);
3205 change = (int)val != hdsp_rpm_disconnect(hdsp);
3206 hdsp_set_rpm_disconnect(hdsp, val);
3207 spin_unlock_irq(&hdsp->lock);
3256 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3262 if (hdsp->io_type == RPM) {
3265 err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp));
3273 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3276 hdsp->spdif_ctl = kctl;
3282 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3284 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3287 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3293 if (hdsp->io_type == H9632) {
3295 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3301 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3302 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3316 struct hdsp *hdsp = entry->private_data;
3325 status = hdsp_read(hdsp, HDSP_statusRegister);
3326 status2 = hdsp_read(hdsp, HDSP_status2Register);
3328 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name,
3329 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);
3336 hdsp->control2_register);
3340 if (hdsp_check_for_iobox(hdsp)) {
3346 if (hdsp_check_for_firmware(hdsp, 0)) {
3347 if (hdsp->state & HDSP_FirmwareCached) {
3348 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3357 err = hdsp_request_fw_loader(hdsp);
3367 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3368 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3369 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3370 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3371 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3372 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_work ? "on" : "off");
3376 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3378 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3379 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3380 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3381 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3387 switch (hdsp_clock_source(hdsp)) {
3423 if (hdsp_system_clock_mode(hdsp))
3428 switch (hdsp_pref_sync_ref (hdsp)) {
3453 switch (hdsp_autosync_ref (hdsp)) {
3481 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3485 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3486 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3490 if (hdsp->io_type != RPM) {
3491 switch (hdsp_spdif_in(hdsp)) {
3510 if (RPM == hdsp->io_type) {
3511 if (hdsp->control_register & HDSP_RPM_Bypass)
3515 if (hdsp->control_register & HDSP_RPM_Disconnect)
3520 switch (hdsp->control_register & HDSP_RPM_Inp12) {
3540 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3561 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3566 if (hdsp->control_register & HDSP_SPDIFProfessional)
3571 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3576 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3580 x = hdsp_spdif_sample_rate(hdsp);
3595 switch (hdsp->io_type) {
3635 if (hdsp->io_type == H9632) {
3638 switch (hdsp_ad_gain(hdsp)) {
3651 switch (hdsp_da_gain(hdsp)) {
3664 switch (hdsp_phone_gain(hdsp)) {
3678 hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ?
3681 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3690 static void snd_hdsp_proc_init(struct hdsp *hdsp)
3692 snd_card_ro_proc_new(hdsp->card, "hdsp", hdsp, snd_hdsp_proc_read);
3695 static void snd_hdsp_free_buffers(struct hdsp *hdsp)
3697 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3698 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3701 static int snd_hdsp_initialize_memory(struct hdsp *hdsp)
3705 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3706 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3707 if (hdsp->capture_dma_buf.area)
3708 snd_dma_free_pages(&hdsp->capture_dma_buf);
3709 dev_err(hdsp->card->dev,
3710 "%s: no buffers available\n", hdsp->card_name);
3716 cb_bus = ALIGN(hdsp->capture_dma_buf.addr, 0x10000ul);
3717 pb_bus = ALIGN(hdsp->playback_dma_buf.addr, 0x10000ul);
3721 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3722 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3724 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3725 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3730 static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3734 /* ASSUMPTION: hdsp->lock is either held, or
3748 hdsp->control_register = HDSP_ClockModeMaster |
3754 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3757 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3759 hdsp->control2_register = 0;
3761 if (hdsp->io_type == H9652)
3762 snd_hdsp_9652_enable_mixer (hdsp);
3764 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3766 hdsp_reset_hw_pointer(hdsp);
3767 hdsp_compute_period_size(hdsp);
3772 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3774 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3775 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3780 if (hdsp->io_type == H9632) {
3781 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3782 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3788 hdsp_set_rate(hdsp, 48000, 1);
3795 struct hdsp *hdsp = container_of(work, struct hdsp, midi_work);
3797 if (hdsp->midi[0].pending)
3798 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3799 if (hdsp->midi[1].pending)
3800 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3805 struct hdsp *hdsp = (struct hdsp *) dev_id;
3814 status = hdsp_read(hdsp, HDSP_statusRegister);
3823 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3825 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3826 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3828 if (!(hdsp->state & HDSP_InitializationComplete))
3832 if (hdsp->capture_substream)
3833 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3835 if (hdsp->playback_substream)
3836 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3840 if (hdsp->use_midi_work) {
3842 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3843 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3844 hdsp->midi[0].pending = 1;
3847 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3850 if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) {
3851 if (hdsp->use_midi_work) {
3853 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3854 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3855 hdsp->midi[1].pending = 1;
3858 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3861 if (hdsp->use_midi_work && schedule)
3862 queue_work(system_highpri_wq, &hdsp->midi_work);
3868 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3869 return hdsp_hw_pointer(hdsp);
3872 static signed char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3879 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3882 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3886 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3888 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3895 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3901 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3913 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3916 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
3927 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3933 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3945 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3948 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
3959 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3962 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3972 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3975 other = hdsp->capture_substream;
3977 other = hdsp->playback_substream;
3978 if (hdsp->running)
3979 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3998 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4003 if (hdsp_check_for_iobox (hdsp))
4006 if (hdsp_check_for_firmware(hdsp, 1))
4009 spin_lock_irq(&hdsp->lock);
4012 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
4013 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
4014 this_pid = hdsp->playback_pid;
4015 other_pid = hdsp->capture_pid;
4017 this_pid = hdsp->capture_pid;
4018 other_pid = hdsp->playback_pid;
4028 if (params_rate(params) != hdsp->system_sample_rate) {
4029 spin_unlock_irq(&hdsp->lock);
4034 if (params_period_size(params) != hdsp->period_bytes / 4) {
4035 spin_unlock_irq(&hdsp->lock);
4042 spin_unlock_irq(&hdsp->lock);
4046 spin_unlock_irq(&hdsp->lock);
4052 spin_lock_irq(&hdsp->lock);
4053 if (! hdsp->clock_source_locked) {
4054 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
4055 spin_unlock_irq(&hdsp->lock);
4060 spin_unlock_irq(&hdsp->lock);
4062 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
4073 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4076 if (snd_BUG_ON(channel >= hdsp->max_channels))
4078 channel = array_index_nospec(channel, hdsp->max_channels);
4080 if (hdsp->channel_map[channel] < 0)
4083 info->offset = hdsp->channel_map[channel] * HDSP_CHANNEL_BUFFER_BYTES;
4106 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4110 if (hdsp_check_for_iobox (hdsp))
4113 if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
4116 spin_lock(&hdsp->lock);
4117 running = hdsp->running;
4127 spin_unlock(&hdsp->lock);
4131 other = hdsp->capture_substream;
4133 other = hdsp->playback_substream;
4150 hdsp_silence_playback(hdsp);
4154 hdsp_silence_playback(hdsp);
4158 hdsp_silence_playback(hdsp);
4162 if (!hdsp->running && running)
4163 hdsp_start_audio(hdsp);
4164 else if (hdsp->running && !running)
4165 hdsp_stop_audio(hdsp);
4166 hdsp->running = running;
4167 spin_unlock(&hdsp->lock);
4174 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4177 if (hdsp_check_for_iobox (hdsp))
4180 if (hdsp_check_for_firmware(hdsp, 1))
4183 spin_lock_irq(&hdsp->lock);
4184 if (!hdsp->running)
4185 hdsp_reset_hw_pointer(hdsp);
4186 spin_unlock_irq(&hdsp->lock);
4268 struct hdsp *hdsp = rule->private;
4270 if (hdsp->io_type == H9632) {
4272 list[0] = hdsp->qs_in_channels;
4273 list[1] = hdsp->ds_in_channels;
4274 list[2] = hdsp->ss_in_channels;
4278 list[0] = hdsp->ds_in_channels;
4279 list[1] = hdsp->ss_in_channels;
4288 struct hdsp *hdsp = rule->private;
4290 if (hdsp->io_type == H9632) {
4291 list[0] = hdsp->qs_out_channels;
4292 list[1] = hdsp->ds_out_channels;
4293 list[2] = hdsp->ss_out_channels;
4296 list[0] = hdsp->ds_out_channels;
4297 list[1] = hdsp->ss_out_channels;
4305 struct hdsp *hdsp = rule->private;
4308 if (r->min > 96000 && hdsp->io_type == H9632) {
4310 .min = hdsp->qs_in_channels,
4311 .max = hdsp->qs_in_channels,
4317 .min = hdsp->ds_in_channels,
4318 .max = hdsp->ds_in_channels,
4324 .min = hdsp->ss_in_channels,
4325 .max = hdsp->ss_in_channels,
4336 struct hdsp *hdsp = rule->private;
4339 if (r->min > 96000 && hdsp->io_type == H9632) {
4341 .min = hdsp->qs_out_channels,
4342 .max = hdsp->qs_out_channels,
4348 .min = hdsp->ds_out_channels,
4349 .max = hdsp->ds_out_channels,
4355 .min = hdsp->ss_out_channels,
4356 .max = hdsp->ss_out_channels,
4367 struct hdsp *hdsp = rule->private;
4370 if (c->min >= hdsp->ss_out_channels) {
4377 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4384 } else if (c->max <= hdsp->ds_out_channels) {
4398 struct hdsp *hdsp = rule->private;
4401 if (c->min >= hdsp->ss_in_channels) {
4408 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4415 } else if (c->max <= hdsp->ds_in_channels) {
4428 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4431 if (hdsp_check_for_iobox (hdsp))
4434 if (hdsp_check_for_firmware(hdsp, 1))
4437 spin_lock_irq(&hdsp->lock);
4442 runtime->dma_area = hdsp->playback_buffer;
4445 hdsp->playback_pid = current->pid;
4446 hdsp->playback_substream = substream;
4448 spin_unlock_irq(&hdsp->lock);
4452 if (hdsp->clock_source_locked) {
4453 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4454 } else if (hdsp->io_type == H9632) {
4459 if (hdsp->io_type == H9632) {
4460 runtime->hw.channels_min = hdsp->qs_out_channels;
4461 runtime->hw.channels_max = hdsp->ss_out_channels;
4465 snd_hdsp_hw_rule_out_channels, hdsp,
4468 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4471 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4474 if (RPM != hdsp->io_type) {
4475 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4476 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4477 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4478 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4485 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4487 spin_lock_irq(&hdsp->lock);
4489 hdsp->playback_pid = -1;
4490 hdsp->playback_substream = NULL;
4492 spin_unlock_irq(&hdsp->lock);
4494 if (RPM != hdsp->io_type) {
4495 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4496 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4497 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4505 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4508 if (hdsp_check_for_iobox (hdsp))
4511 if (hdsp_check_for_firmware(hdsp, 1))
4514 spin_lock_irq(&hdsp->lock);
4519 runtime->dma_area = hdsp->capture_buffer;
4522 hdsp->capture_pid = current->pid;
4523 hdsp->capture_substream = substream;
4525 spin_unlock_irq(&hdsp->lock);
4529 if (hdsp->io_type == H9632) {
4530 runtime->hw.channels_min = hdsp->qs_in_channels;
4531 runtime->hw.channels_max = hdsp->ss_in_channels;
4537 snd_hdsp_hw_rule_in_channels, hdsp,
4540 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4543 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4550 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4552 spin_lock_irq(&hdsp->lock);
4554 hdsp->capture_pid = -1;
4555 hdsp->capture_substream = NULL;
4557 spin_unlock_irq(&hdsp->lock);
4588 static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4593 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4600 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4603 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4606 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4609 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4610 hdsp->iobase + ofs + 4))
4613 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4614 hdsp->iobase + ofs + 4))
4617 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4618 hdsp->iobase + ofs + 4))
4625 static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4631 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4633 m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4655 static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4661 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4664 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4669 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4674 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4675 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4678 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4679 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4687 struct hdsp *hdsp = hw->private_data;
4695 err = hdsp_check_for_iobox(hdsp);
4699 err = hdsp_check_for_firmware(hdsp, 1);
4703 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4704 dev_err(hdsp->card->dev,
4709 switch (hdsp->io_type) {
4711 return hdsp_9652_get_peak(hdsp, peak_rms);
4713 return hdsp_9632_get_peak(hdsp, peak_rms);
4715 return hdsp_get_peak(hdsp, peak_rms);
4723 err = hdsp_check_for_iobox(hdsp);
4727 err = hdsp_check_for_firmware(hdsp, 1);
4732 spin_lock_irqsave(&hdsp->lock, flags);
4733 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4734 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4735 if (hdsp->io_type != H9632)
4736 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4737 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4738 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i)
4739 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4740 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4741 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp,
4744 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional);
4746 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis);
4748 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio);
4749 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4750 info.system_sample_rate = hdsp->system_sample_rate;
4751 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4752 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4753 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4754 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4756 hdsp_toggle_setting(hdsp, HDSP_LineOut);
4757 if (hdsp->io_type == H9632) {
4758 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4759 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4760 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4762 (unsigned char)hdsp_toggle_setting(hdsp,
4765 } else if (hdsp->io_type == RPM) {
4766 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp);
4767 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp);
4769 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4771 (unsigned char)hdsp_toggle_setting(hdsp,
4773 spin_unlock_irqrestore(&hdsp->lock, flags);
4781 if (hdsp->io_type != H9632) return -EINVAL;
4782 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4783 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4792 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4793 if (hdsp->io_type == Undefined) {
4794 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4798 hdsp_version.io_type = hdsp->io_type;
4799 hdsp_version.firmware_rev = hdsp->firmware_rev;
4809 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4811 if (hdsp->io_type == Undefined) return -EINVAL;
4813 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4816 dev_info(hdsp->card->dev,
4822 if (hdsp_check_for_iobox (hdsp))
4825 if (!hdsp->fw_uploaded) {
4826 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE);
4827 if (!hdsp->fw_uploaded)
4831 if (copy_from_user(hdsp->fw_uploaded, firmware_data,
4833 vfree(hdsp->fw_uploaded);
4834 hdsp->fw_uploaded = NULL;
4838 hdsp->state |= HDSP_FirmwareCached;
4840 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4843 if (!(hdsp->state & HDSP_InitializationComplete)) {
4844 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4847 snd_hdsp_initialize_channels(hdsp);
4848 snd_hdsp_initialize_midi_flush(hdsp);
4850 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4851 dev_err(hdsp->card->dev,
4860 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4895 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4903 hdsp->hwdep = hw;
4904 hw->private_data = hdsp;
4913 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4918 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4921 hdsp->pcm = pcm;
4922 pcm->private_data = hdsp;
4923 strcpy(pcm->name, hdsp->card_name);
4933 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
4935 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4936 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4939 static int snd_hdsp_enable_io (struct hdsp *hdsp)
4943 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4944 dev_err(hdsp->card->dev,
4949 for (i = 0; i < hdsp->max_channels; ++i) {
4950 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4951 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4957 static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4961 switch (hdsp->io_type) {
4963 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4964 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4965 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4969 hdsp->card_name = "RME Hammerfall HDSP 9652";
4970 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4971 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4975 status = hdsp_read(hdsp, HDSP_statusRegister);
4979 hdsp->card_name = "RME Hammerfall HDSP 9632";
4980 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4981 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4982 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4983 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4984 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4985 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4989 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4990 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4991 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4995 hdsp->card_name = "RME Hammerfall DSP + RPM";
4996 hdsp->ss_in_channels = RPM_CHANNELS-1;
4997 hdsp->ss_out_channels = RPM_CHANNELS;
4998 hdsp->ds_in_channels = RPM_CHANNELS-1;
4999 hdsp->ds_out_channels = RPM_CHANNELS;
5008 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
5010 snd_hdsp_flush_midi_input (hdsp, 0);
5011 snd_hdsp_flush_midi_input (hdsp, 1);
5014 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
5018 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
5025 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
5031 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
5032 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
5039 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
5045 snd_hdsp_proc_init(hdsp);
5047 hdsp->system_sample_rate = -1;
5048 hdsp->playback_pid = -1;
5049 hdsp->capture_pid = -1;
5050 hdsp->capture_substream = NULL;
5051 hdsp->playback_substream = NULL;
5053 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
5059 if (!(hdsp->state & HDSP_InitializationComplete)) {
5061 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5062 hdsp->port, hdsp->irq);
5069 hdsp->state |= HDSP_InitializationComplete;
5076 static int hdsp_request_fw_loader(struct hdsp *hdsp)
5082 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5084 if (hdsp->io_type == Undefined) {
5085 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
5087 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5092 switch (hdsp->io_type) {
5097 if (hdsp->firmware_rev == 0xa)
5103 if (hdsp->firmware_rev == 0xa)
5109 dev_err(hdsp->card->dev,
5110 "invalid io_type %d\n", hdsp->io_type);
5114 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
5115 dev_err(hdsp->card->dev,
5120 dev_err(hdsp->card->dev,
5127 hdsp->firmware = fw;
5129 hdsp->state |= HDSP_FirmwareCached;
5131 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
5134 if (!(hdsp->state & HDSP_InitializationComplete)) {
5135 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
5138 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
5139 dev_err(hdsp->card->dev,
5143 snd_hdsp_initialize_channels(hdsp);
5144 snd_hdsp_initialize_midi_flush(hdsp);
5145 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
5146 dev_err(hdsp->card->dev,
5155 struct hdsp *hdsp)
5157 struct pci_dev *pci = hdsp->pci;
5162 hdsp->irq = -1;
5163 hdsp->state = 0;
5164 hdsp->midi[0].rmidi = NULL;
5165 hdsp->midi[1].rmidi = NULL;
5166 hdsp->midi[0].input = NULL;
5167 hdsp->midi[1].input = NULL;
5168 hdsp->midi[0].output = NULL;
5169 hdsp->midi[1].output = NULL;
5170 hdsp->midi[0].pending = 0;
5171 hdsp->midi[1].pending = 0;
5172 spin_lock_init(&hdsp->midi[0].lock);
5173 spin_lock_init(&hdsp->midi[1].lock);
5174 hdsp->iobase = NULL;
5175 hdsp->control_register = 0;
5176 hdsp->control2_register = 0;
5177 hdsp->io_type = Undefined;
5178 hdsp->max_channels = 26;
5180 hdsp->card = card;
5182 spin_lock_init(&hdsp->lock);
5184 INIT_WORK(&hdsp->midi_work, hdsp_midi_work);
5186 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5187 hdsp->firmware_rev &= 0xff;
5196 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5201 if (hdsp->firmware_rev < 0xa)
5203 else if (hdsp->firmware_rev < 0x64)
5204 hdsp->card_name = "RME Hammerfall DSP";
5205 else if (hdsp->firmware_rev < 0x96) {
5206 hdsp->card_name = "RME HDSP 9652";
5209 hdsp->card_name = "RME HDSP 9632";
5210 hdsp->max_channels = 16;
5217 pci_set_master(hdsp->pci);
5219 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5221 hdsp->port = pci_resource_start(pci, 0);
5222 if ((hdsp->iobase = ioremap(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5223 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
5224 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5229 KBUILD_MODNAME, hdsp)) {
5230 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
5234 hdsp->irq = pci->irq;
5235 card->sync_irq = hdsp->irq;
5236 hdsp->precise_ptr = 0;
5237 hdsp->use_midi_work = 1;
5238 hdsp->dds_value = 0;
5240 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5246 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5251 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5252 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5257 dev_err(hdsp->card->dev,
5263 dev_info(hdsp->card->dev,
5265 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5269 dev_info(hdsp->card->dev,
5271 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5272 hdsp->io_type = RPM;
5273 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5274 hdsp->io_type = Multiface;
5276 hdsp->io_type = Digiface;
5280 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5284 hdsp->io_type = H9652;
5287 hdsp->io_type = H9632;
5289 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5292 snd_hdsp_initialize_channels(hdsp);
5293 snd_hdsp_initialize_midi_flush(hdsp);
5295 hdsp->state |= HDSP_FirmwareLoaded;
5297 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5303 static int snd_hdsp_free(struct hdsp *hdsp)
5305 if (hdsp->port) {
5307 cancel_work_sync(&hdsp->midi_work);
5308 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5309 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5312 if (hdsp->irq >= 0)
5313 free_irq(hdsp->irq, (void *)hdsp);
5315 snd_hdsp_free_buffers(hdsp);
5317 release_firmware(hdsp->firmware);
5318 vfree(hdsp->fw_uploaded);
5319 iounmap(hdsp->iobase);
5321 if (hdsp->port)
5322 pci_release_regions(hdsp->pci);
5324 if (pci_is_enabled(hdsp->pci))
5325 pci_disable_device(hdsp->pci);
5331 struct hdsp *hdsp = card->private_data;
5333 if (hdsp)
5334 snd_hdsp_free(hdsp);
5341 struct hdsp *hdsp;
5353 sizeof(struct hdsp), &card);
5357 hdsp = card->private_data;
5359 hdsp->dev = dev;
5360 hdsp->pci = pci;
5361 err = snd_hdsp_create(card, hdsp);
5366 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5367 hdsp->port, hdsp->irq);