Lines Matching defs:hdspm
45 #include <sound/hdspm.h>
402 struct hdspm *hdspm;
413 struct hdspm {
505 struct hdspm * hdspm);
507 struct hdspm * hdspm);
509 static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm);
510 static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm);
511 static int hdspm_autosync_ref(struct hdspm * hdspm);
512 static int snd_hdspm_set_defaults(struct hdspm * hdspm);
513 static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf,
528 static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg,
531 writel(val, hdspm->iobase + reg);
534 static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg)
536 return readl(hdspm->iobase + reg);
543 static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan,
549 return hdspm->mixer->ch[chan].in[in];
552 static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
557 return hdspm->mixer->ch[chan].pb[pb];
560 static inline int hdspm_write_in_gain(struct hdspm * hdspm, unsigned int chan,
566 hdspm_write(hdspm,
569 (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF));
573 static inline int hdspm_write_pb_gain(struct hdspm * hdspm, unsigned int chan,
579 hdspm_write(hdspm,
582 (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF));
588 static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v)
590 hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v);
593 static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
595 hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v);
599 static inline int snd_hdspm_use_is_exclusive(struct hdspm * hdspm)
604 spin_lock_irqsave(&hdspm->lock, flags);
605 if ((hdspm->playback_pid != hdspm->capture_pid) &&
606 (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) {
609 spin_unlock_irqrestore(&hdspm->lock, flags);
614 static inline int hdspm_external_sample_rate(struct hdspm * hdspm)
616 if (hdspm->is_aes32) {
617 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
618 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
619 unsigned int timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
621 int syncref = hdspm_autosync_ref(hdspm);
634 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
635 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
718 static inline void hdspm_compute_period_size(struct hdspm * hdspm)
720 hdspm->period_bytes =
721 1 << ((hdspm_decode_latency(hdspm->control_register) + 8));
724 static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm * hdspm)
728 position = hdspm_read(hdspm, HDSPM_statusRegister);
730 if (!hdspm->precise_ptr) {
731 return (position & HDSPM_BufferID) ? (hdspm->period_bytes /
742 position = ((position - 64) % (2 * hdspm->period_bytes)) / 4;
748 static inline void hdspm_start_audio(struct hdspm * s)
754 static inline void hdspm_stop_audio(struct hdspm * s)
761 static inline void hdspm_silence_playback(struct hdspm * hdspm)
764 int n = hdspm->period_bytes;
765 void *buf = hdspm->playback_buffer;
776 static int hdspm_set_interrupt_interval(struct hdspm * s, unsigned int frames)
800 static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
819 hdspm_write(hdspm, HDSPM_freqReg, (u32)n);
823 static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
831 /* ASSUMPTION: hdspm->lock is either set, or there is no need for
835 if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
851 hdspm_external_sample_rate(hdspm);
853 if ((hdspm_autosync_ref(hdspm) ==
868 current_rate = hdspm->system_sample_rate;
935 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
938 hdspm->capture_pid, hdspm->playback_pid);
942 hdspm->control_register &= ~HDSPM_FrequencyMask;
943 hdspm->control_register |= rate_bits;
944 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
948 hdspm_set_dds_value(hdspm, rate);
950 if (hdspm->is_aes32 && rate != current_rate)
951 hdspm_write(hdspm, HDSPM_eeprom_wr, 0);
955 hdspm->channel_map = channel_map_madi_ss;
957 hdspm->system_sample_rate = rate;
966 static void all_in_all_mixer(struct hdspm * hdspm, int sgain)
974 hdspm_write_in_gain(hdspm, i, j, gain);
975 hdspm_write_pb_gain(hdspm, i, j, gain);
983 static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, int id)
987 return hdspm_read(hdspm, HDSPM_midiDataIn1);
989 return hdspm_read(hdspm, HDSPM_midiDataIn0);
992 static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id, int val)
996 return hdspm_write(hdspm, HDSPM_midiDataOut1, val);
998 return hdspm_write(hdspm, HDSPM_midiDataOut0, val);
1001 static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
1004 return (hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xff);
1006 return (hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xff);
1009 static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
1014 fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xff;
1016 fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xff;
1024 static inline void snd_hdspm_flush_midi_input (struct hdspm *hdspm, int id)
1026 while (snd_hdspm_midi_input_available (hdspm, id))
1027 snd_hdspm_midi_read_byte (hdspm, id);
1043 if ((n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, hmidi->id)) > 0) {
1049 snd_hdspm_midi_write_byte (hmidi->hdspm, hmidi->id, buf[i]);
1066 if ((n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id)) > 0) {
1072 buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id);
1080 snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id);
1086 hmidi->hdspm->control_register |= HDSPM_Midi1InterruptEnable;
1088 hmidi->hdspm->control_register |= HDSPM_Midi0InterruptEnable;
1090 hdspm_write(hmidi->hdspm, HDSPM_controlRegister, hmidi->hdspm->control_register);
1097 struct hdspm *hdspm;
1103 hdspm = hmidi->hdspm;
1105 spin_lock_irqsave (&hdspm->lock, flags);
1107 if (!(hdspm->control_register & ie)) {
1108 snd_hdspm_flush_midi_input (hdspm, hmidi->id);
1109 hdspm->control_register |= ie;
1112 hdspm->control_register &= ~ie;
1115 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1116 spin_unlock_irqrestore (&hdspm->lock, flags);
1173 snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id);
1234 static int __devinit snd_hdspm_create_midi (struct snd_card *card, struct hdspm *hdspm, int id)
1239 hdspm->midi[id].id = id;
1240 hdspm->midi[id].rmidi = NULL;
1241 hdspm->midi[id].input = NULL;
1242 hdspm->midi[id].output = NULL;
1243 hdspm->midi[id].hdspm = hdspm;
1244 hdspm->midi[id].istimer = 0;
1245 hdspm->midi[id].pending = 0;
1246 spin_lock_init (&hdspm->midi[id].lock);
1249 if ((err = snd_rawmidi_new (card, buf, id, 1, 1, &hdspm->midi[id].rmidi)) < 0)
1252 sprintf (hdspm->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1253 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
1255 snd_rawmidi_set_ops (hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdspm_midi_output);
1256 snd_rawmidi_set_ops (hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdspm_midi_input);
1258 hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1268 struct hdspm *hdspm = (struct hdspm *)arg;
1270 if (hdspm->midi[0].pending)
1271 snd_hdspm_midi_input_read (&hdspm->midi[0]);
1272 if (hdspm->midi[1].pending)
1273 snd_hdspm_midi_input_read (&hdspm->midi[1]);
1304 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1306 ucontrol->value.enumerated.item[0] = hdspm->system_sample_rate;
1342 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1344 switch (hdspm_external_sample_rate(hdspm)) {
1390 static int hdspm_system_clock_mode(struct hdspm * hdspm)
1394 if (hdspm->control_register & HDSPM_ClockModeMaster)
1418 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1421 hdspm_system_clock_mode(hdspm);
1434 static int hdspm_clock_source(struct hdspm * hdspm)
1436 if (hdspm->control_register & HDSPM_ClockModeMaster) {
1437 switch (hdspm->system_sample_rate) {
1464 static int hdspm_set_clock_source(struct hdspm * hdspm, int mode)
1470 if (hdspm_external_sample_rate(hdspm) != 0) {
1471 hdspm->control_register &= ~HDSPM_ClockModeMaster;
1472 hdspm_write(hdspm, HDSPM_controlRegister,
1473 hdspm->control_register);
1508 hdspm->control_register |= HDSPM_ClockModeMaster;
1509 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1510 hdspm_set_rate(hdspm, rate, 1);
1543 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1545 ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm);
1552 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1556 if (!snd_hdspm_use_is_exclusive(hdspm))
1563 spin_lock_irq(&hdspm->lock);
1564 if (val != hdspm_clock_source(hdspm))
1565 change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0;
1568 spin_unlock_irq(&hdspm->lock);
1581 static int hdspm_pref_sync_ref(struct hdspm * hdspm)
1586 if (hdspm->is_aes32) {
1587 switch (hdspm->control_register & HDSPM_SyncRefMask) {
1601 switch (hdspm->control_register & HDSPM_SyncRefMask) {
1612 static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref)
1614 hdspm->control_register &= ~HDSPM_SyncRefMask;
1616 if (hdspm->is_aes32) {
1619 hdspm->control_register |= 0;
1622 hdspm->control_register |= HDSPM_SyncRef0;
1625 hdspm->control_register |= HDSPM_SyncRef1;
1628 hdspm->control_register |= HDSPM_SyncRef1+HDSPM_SyncRef0;
1631 hdspm->control_register |= HDSPM_SyncRef2;
1634 hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef0;
1637 hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef1;
1640 hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0;
1643 hdspm->control_register |= HDSPM_SyncRef3;
1651 hdspm->control_register |= HDSPM_SyncRef_MADI;
1654 hdspm->control_register |= HDSPM_SyncRef_Word;
1660 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1667 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1669 if (hdspm->is_aes32) {
1703 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1705 ucontrol->value.enumerated.item[0] = hdspm_pref_sync_ref(hdspm);
1712 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1716 max = hdspm->is_aes32 ? 9 : 2;
1718 if (!snd_hdspm_use_is_exclusive(hdspm))
1723 spin_lock_irq(&hdspm->lock);
1724 change = (int) val != hdspm_pref_sync_ref(hdspm);
1725 hdspm_set_pref_sync_ref(hdspm, val);
1726 spin_unlock_irq(&hdspm->lock);
1739 static int hdspm_autosync_ref(struct hdspm * hdspm)
1741 if (hdspm->is_aes32) {
1742 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
1751 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1771 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1773 if (hdspm->is_aes32) {
1805 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1807 ucontrol->value.enumerated.item[0] = hdspm_pref_sync_ref(hdspm);
1820 static int hdspm_line_out(struct hdspm * hdspm)
1822 return (hdspm->control_register & HDSPM_LineOut) ? 1 : 0;
1826 static int hdspm_set_line_output(struct hdspm * hdspm, int out)
1829 hdspm->control_register |= HDSPM_LineOut;
1831 hdspm->control_register &= ~HDSPM_LineOut;
1832 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1850 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1852 spin_lock_irq(&hdspm->lock);
1853 ucontrol->value.integer.value[0] = hdspm_line_out(hdspm);
1854 spin_unlock_irq(&hdspm->lock);
1861 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1865 if (!snd_hdspm_use_is_exclusive(hdspm))
1868 spin_lock_irq(&hdspm->lock);
1869 change = (int) val != hdspm_line_out(hdspm);
1870 hdspm_set_line_output(hdspm, val);
1871 spin_unlock_irq(&hdspm->lock);
1884 static int hdspm_tx_64(struct hdspm * hdspm)
1886 return (hdspm->control_register & HDSPM_TX_64ch) ? 1 : 0;
1889 static int hdspm_set_tx_64(struct hdspm * hdspm, int out)
1892 hdspm->control_register |= HDSPM_TX_64ch;
1894 hdspm->control_register &= ~HDSPM_TX_64ch;
1895 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1913 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1915 spin_lock_irq(&hdspm->lock);
1916 ucontrol->value.integer.value[0] = hdspm_tx_64(hdspm);
1917 spin_unlock_irq(&hdspm->lock);
1924 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1928 if (!snd_hdspm_use_is_exclusive(hdspm))
1931 spin_lock_irq(&hdspm->lock);
1932 change = (int) val != hdspm_tx_64(hdspm);
1933 hdspm_set_tx_64(hdspm, val);
1934 spin_unlock_irq(&hdspm->lock);
1947 static int hdspm_c_tms(struct hdspm * hdspm)
1949 return (hdspm->control_register & HDSPM_clr_tms) ? 1 : 0;
1952 static int hdspm_set_c_tms(struct hdspm * hdspm, int out)
1955 hdspm->control_register |= HDSPM_clr_tms;
1957 hdspm->control_register &= ~HDSPM_clr_tms;
1958 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1976 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1978 spin_lock_irq(&hdspm->lock);
1979 ucontrol->value.integer.value[0] = hdspm_c_tms(hdspm);
1980 spin_unlock_irq(&hdspm->lock);
1987 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
1991 if (!snd_hdspm_use_is_exclusive(hdspm))
1994 spin_lock_irq(&hdspm->lock);
1995 change = (int) val != hdspm_c_tms(hdspm);
1996 hdspm_set_c_tms(hdspm, val);
1997 spin_unlock_irq(&hdspm->lock);
2010 static int hdspm_safe_mode(struct hdspm * hdspm)
2012 return (hdspm->control_register & HDSPM_AutoInp) ? 1 : 0;
2015 static int hdspm_set_safe_mode(struct hdspm * hdspm, int out)
2018 hdspm->control_register |= HDSPM_AutoInp;
2020 hdspm->control_register &= ~HDSPM_AutoInp;
2021 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2039 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2041 spin_lock_irq(&hdspm->lock);
2042 ucontrol->value.integer.value[0] = hdspm_safe_mode(hdspm);
2043 spin_unlock_irq(&hdspm->lock);
2050 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2054 if (!snd_hdspm_use_is_exclusive(hdspm))
2057 spin_lock_irq(&hdspm->lock);
2058 change = (int) val != hdspm_safe_mode(hdspm);
2059 hdspm_set_safe_mode(hdspm, val);
2060 spin_unlock_irq(&hdspm->lock);
2073 static int hdspm_emphasis(struct hdspm * hdspm)
2075 return (hdspm->control_register & HDSPM_Emphasis) ? 1 : 0;
2078 static int hdspm_set_emphasis(struct hdspm * hdspm, int emp)
2081 hdspm->control_register |= HDSPM_Emphasis;
2083 hdspm->control_register &= ~HDSPM_Emphasis;
2084 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2102 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2104 spin_lock_irq(&hdspm->lock);
2105 ucontrol->value.enumerated.item[0] = hdspm_emphasis(hdspm);
2106 spin_unlock_irq(&hdspm->lock);
2113 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2117 if (!snd_hdspm_use_is_exclusive(hdspm))
2120 spin_lock_irq(&hdspm->lock);
2121 change = (int) val != hdspm_emphasis(hdspm);
2122 hdspm_set_emphasis(hdspm, val);
2123 spin_unlock_irq(&hdspm->lock);
2136 static int hdspm_dolby(struct hdspm * hdspm)
2138 return (hdspm->control_register & HDSPM_Dolby) ? 1 : 0;
2141 static int hdspm_set_dolby(struct hdspm * hdspm, int dol)
2144 hdspm->control_register |= HDSPM_Dolby;
2146 hdspm->control_register &= ~HDSPM_Dolby;
2147 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2165 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2167 spin_lock_irq(&hdspm->lock);
2168 ucontrol->value.enumerated.item[0] = hdspm_dolby(hdspm);
2169 spin_unlock_irq(&hdspm->lock);
2176 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2180 if (!snd_hdspm_use_is_exclusive(hdspm))
2183 spin_lock_irq(&hdspm->lock);
2184 change = (int) val != hdspm_dolby(hdspm);
2185 hdspm_set_dolby(hdspm, val);
2186 spin_unlock_irq(&hdspm->lock);
2199 static int hdspm_professional(struct hdspm * hdspm)
2201 return (hdspm->control_register & HDSPM_Professional) ? 1 : 0;
2204 static int hdspm_set_professional(struct hdspm * hdspm, int dol)
2207 hdspm->control_register |= HDSPM_Professional;
2209 hdspm->control_register &= ~HDSPM_Professional;
2210 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2228 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2230 spin_lock_irq(&hdspm->lock);
2231 ucontrol->value.enumerated.item[0] = hdspm_professional(hdspm);
2232 spin_unlock_irq(&hdspm->lock);
2239 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2243 if (!snd_hdspm_use_is_exclusive(hdspm))
2246 spin_lock_irq(&hdspm->lock);
2247 change = (int) val != hdspm_professional(hdspm);
2248 hdspm_set_professional(hdspm, val);
2249 spin_unlock_irq(&hdspm->lock);
2262 static int hdspm_input_select(struct hdspm * hdspm)
2264 return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;
2267 static int hdspm_set_input_select(struct hdspm * hdspm, int out)
2270 hdspm->control_register |= HDSPM_InputSelect0;
2272 hdspm->control_register &= ~HDSPM_InputSelect0;
2273 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2299 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2301 spin_lock_irq(&hdspm->lock);
2302 ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm);
2303 spin_unlock_irq(&hdspm->lock);
2310 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2314 if (!snd_hdspm_use_is_exclusive(hdspm))
2317 spin_lock_irq(&hdspm->lock);
2318 change = (int) val != hdspm_input_select(hdspm);
2319 hdspm_set_input_select(hdspm, val);
2320 spin_unlock_irq(&hdspm->lock);
2333 static int hdspm_ds_wire(struct hdspm * hdspm)
2335 return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0;
2338 static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds)
2341 hdspm->control_register |= HDSPM_DS_DoubleWire;
2343 hdspm->control_register &= ~HDSPM_DS_DoubleWire;
2344 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2370 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2372 spin_lock_irq(&hdspm->lock);
2373 ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm);
2374 spin_unlock_irq(&hdspm->lock);
2381 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2385 if (!snd_hdspm_use_is_exclusive(hdspm))
2388 spin_lock_irq(&hdspm->lock);
2389 change = (int) val != hdspm_ds_wire(hdspm);
2390 hdspm_set_ds_wire(hdspm, val);
2391 spin_unlock_irq(&hdspm->lock);
2404 static int hdspm_qs_wire(struct hdspm * hdspm)
2406 if (hdspm->control_register & HDSPM_QS_DoubleWire)
2408 if (hdspm->control_register & HDSPM_QS_QuadWire)
2413 static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode)
2415 hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire);
2420 hdspm->control_register |= HDSPM_QS_DoubleWire;
2423 hdspm->control_register |= HDSPM_QS_QuadWire;
2426 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2452 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2454 spin_lock_irq(&hdspm->lock);
2455 ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm);
2456 spin_unlock_irq(&hdspm->lock);
2463 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2467 if (!snd_hdspm_use_is_exclusive(hdspm))
2474 spin_lock_irq(&hdspm->lock);
2475 change = (int) val != hdspm_qs_wire(hdspm);
2476 hdspm_set_qs_wire(hdspm, val);
2477 spin_unlock_irq(&hdspm->lock);
2517 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2533 spin_lock_irq(&hdspm->lock);
2536 hdspm_read_pb_gain(hdspm, destination,
2540 hdspm_read_in_gain(hdspm, destination, source);
2542 spin_unlock_irq(&hdspm->lock);
2550 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2556 if (!snd_hdspm_use_is_exclusive(hdspm))
2569 spin_lock_irq(&hdspm->lock);
2572 change = gain != hdspm_read_pb_gain(hdspm, destination,
2577 gain != hdspm_read_in_gain(hdspm, destination, source);
2581 hdspm_write_pb_gain(hdspm, destination,
2585 hdspm_write_in_gain(hdspm, destination, source,
2588 spin_unlock_irq(&hdspm->lock);
2621 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2630 if ((mapped_channel = hdspm->channel_map[channel]) < 0)
2633 spin_lock_irq(&hdspm->lock);
2635 hdspm_read_pb_gain(hdspm, mapped_channel, mapped_channel);
2636 spin_unlock_irq(&hdspm->lock);
2648 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2654 if (!snd_hdspm_use_is_exclusive(hdspm))
2662 if ((mapped_channel = hdspm->channel_map[channel]) < 0)
2667 spin_lock_irq(&hdspm->lock);
2669 gain != hdspm_read_pb_gain(hdspm, mapped_channel,
2672 hdspm_write_pb_gain(hdspm, mapped_channel, mapped_channel,
2674 spin_unlock_irq(&hdspm->lock);
2702 static int hdspm_wc_sync_check(struct hdspm * hdspm)
2704 if (hdspm->is_aes32) {
2705 int status = hdspm_read(hdspm, HDSPM_statusRegister);
2713 int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
2727 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2729 ucontrol->value.enumerated.item[0] = hdspm_wc_sync_check(hdspm);
2743 static int hdspm_madisync_sync_check(struct hdspm * hdspm)
2745 int status = hdspm_read(hdspm, HDSPM_statusRegister);
2759 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2762 hdspm_madisync_sync_check(hdspm);
2776 static int hdspm_aes_sync_check(struct hdspm * hdspm, int idx)
2778 int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
2791 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2798 hdspm_aes_sync_check(hdspm, offset);
2850 static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm)
2854 for (i = hdspm->ds_channels; i < hdspm->ss_channels; ++i) {
2855 if (hdspm->system_sample_rate > 48000) {
2856 hdspm->playback_mixer_ctls[i]->vd[0].access =
2861 hdspm->playback_mixer_ctls[i]->vd[0].access =
2865 snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE |
2867 &hdspm->playback_mixer_ctls[i]->id);
2874 static int snd_hdspm_create_controls(struct snd_card *card, struct hdspm * hdspm)
2881 if (hdspm->is_aes32) {
2889 hdspm));
2896 snd_ctl_new1(&aes_sync_ctl, hdspm));
2905 hdspm));
2931 hdspm)))) {
2934 hdspm->playback_mixer_ctls[idx] = kctl;
2948 struct hdspm *hdspm = (struct hdspm *) entry->private_data;
2959 status = hdspm_read(hdspm, HDSPM_statusRegister);
2960 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
2963 hdspm->card_name, hdspm->card->number + 1,
2964 hdspm->firmware_rev,
2970 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
2979 hdspm->irq_count);
2985 (int)hdspm->
2988 64) % (2 * (int)hdspm->period_bytes),
2989 (long) hdspm_hw_pointer(hdspm) * 4);
2993 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
2994 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
2995 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
2996 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
2999 hdspm->control_register, hdspm->control2_register,
3005 hdspm_decode_latency(hdspm->
3011 x, (unsigned long) hdspm->period_bytes);
3014 (hdspm->
3016 (hdspm->precise_ptr) ? "on" : "off");
3018 switch (hdspm->control_register & HDSPM_InputMask) {
3029 switch (hdspm->control_register & HDSPM_SyncRefMask) {
3044 (hdspm->
3046 (hdspm->
3048 (hdspm->
3051 switch (hdspm_clock_source(hdspm)) {
3077 if (!(hdspm->control_register & HDSPM_ClockModeMaster))
3083 switch (hdspm_pref_sync_ref(hdspm)) {
3098 hdspm->system_sample_rate);
3112 switch (hdspm_autosync_ref(hdspm)) {
3128 autosync_ref, hdspm_external_sample_rate(hdspm),
3144 struct hdspm *hdspm = (struct hdspm *) entry->private_data;
3154 status = hdspm_read(hdspm, HDSPM_statusRegister);
3155 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
3156 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
3159 hdspm->card_name, hdspm->card->number + 1,
3160 hdspm->firmware_rev);
3163 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
3172 hdspm->irq_count);
3178 (int)hdspm->
3181 64) % (2 * (int)hdspm->period_bytes),
3182 (long) hdspm_hw_pointer(hdspm) * 4);
3186 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
3187 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
3188 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
3189 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
3192 hdspm->control_register,
3198 hdspm_decode_latency(hdspm->
3204 x, (unsigned long) hdspm->period_bytes);
3207 (hdspm->
3209 (hdspm->precise_ptr) ? "on" : "off");
3213 (hdspm->
3215 (hdspm->
3217 (hdspm->
3220 switch (hdspm_clock_source(hdspm)) {
3255 if (!(hdspm->control_register & HDSPM_ClockModeMaster))
3261 pref_syncref = hdspm_pref_sync_ref(hdspm);
3269 hdspm->system_sample_rate);
3272 hdspm->control_register & HDSPM_DS_DoubleWire?
3275 hdspm->control_register & HDSPM_QS_DoubleWire?
3277 hdspm->control_register & HDSPM_QS_QuadWire?
3293 switch (hdspm_autosync_ref(hdspm)) {
3316 struct hdspm *hdspm = (struct hdspm *)entry->private_data;
3324 snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j));
3332 static void __devinit snd_hdspm_proc_init(struct hdspm * hdspm)
3336 if (!snd_card_proc_new(hdspm->card, "hdspm", &entry))
3337 snd_info_set_text_ops(entry, hdspm,
3338 hdspm->is_aes32 ?
3342 /* debug file to read all hdspm registers */
3343 if (!snd_card_proc_new(hdspm->card, "debug", &entry))
3344 snd_info_set_text_ops(entry, hdspm,
3350 hdspm intitialize
3353 static int snd_hdspm_set_defaults(struct hdspm * hdspm)
3357 /* ASSUMPTION: hdspm->lock is either held, or there is no need to
3363 if (hdspm->is_aes32)
3364 hdspm->control_register = HDSPM_ClockModeMaster | /* Master Cloack Mode on */
3370 hdspm->control_register = HDSPM_ClockModeMaster | /* Master Cloack Mode on */
3382 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3384 if (!hdspm->is_aes32) {
3387 hdspm->control2_register = HDSPM_BIGENDIAN_MODE;
3389 hdspm->control2_register = 0;
3392 hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register);
3394 hdspm_compute_period_size(hdspm);
3398 all_in_all_mixer(hdspm, 0 * UNITY_GAIN);
3400 if (line_outs_monitor[hdspm->dev]) {
3405 if (hdspm_write_pb_gain(hdspm, i, i, UNITY_GAIN))
3411 hdspm->channel_map = channel_map_madi_ss;
3412 hdspm_set_rate(hdspm, 44100, 1);
3424 struct hdspm *hdspm = (struct hdspm *) dev_id;
3433 status = hdspm_read(hdspm, HDSPM_statusRegister);
3442 hdspm_write(hdspm, HDSPM_interruptConfirmation, 0);
3443 hdspm->irq_count++;
3445 midi0status = hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xff;
3446 midi1status = hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xff;
3450 if (hdspm->capture_substream)
3451 snd_pcm_period_elapsed(hdspm->pcm->
3456 if (hdspm->playback_substream)
3457 snd_pcm_period_elapsed(hdspm->pcm->
3465 hdspm->control_register &= ~HDSPM_Midi0InterruptEnable;
3466 hdspm_write(hdspm, HDSPM_controlRegister,
3467 hdspm->control_register);
3468 hdspm->midi[0].pending = 1;
3473 hdspm->control_register &= ~HDSPM_Midi1InterruptEnable;
3474 hdspm_write(hdspm, HDSPM_controlRegister,
3475 hdspm->control_register);
3476 hdspm->midi[1].pending = 1;
3480 tasklet_hi_schedule(&hdspm->midi_tasklet);
3492 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3493 return hdspm_hw_pointer(hdspm);
3496 static char *hdspm_channel_buffer_location(struct hdspm * hdspm,
3504 if ((mapped_channel = hdspm->channel_map[channel]) < 0)
3508 return hdspm->capture_buffer +
3511 return hdspm->playback_buffer +
3522 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3528 channel_buf = hdspm_channel_buffer_location(hdspm,
3541 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3547 channel_buf = hdspm_channel_buffer_location(hdspm,
3558 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3562 hdspm_channel_buffer_location(hdspm, substream->pstr->stream,
3572 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3576 other = hdspm->capture_substream;
3578 other = hdspm->playback_substream;
3580 if (hdspm->running)
3581 runtime->status->hw_ptr = hdspm_hw_pointer(hdspm);
3601 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3609 spin_lock_irq(&hdspm->lock);
3612 this_pid = hdspm->playback_pid;
3613 other_pid = hdspm->capture_pid;
3615 this_pid = hdspm->capture_pid;
3616 other_pid = hdspm->playback_pid;
3626 if (params_rate(params) != hdspm->system_sample_rate) {
3627 spin_unlock_irq(&hdspm->lock);
3633 if (params_period_size(params) != hdspm->period_bytes / 4) {
3634 spin_unlock_irq(&hdspm->lock);
3642 spin_unlock_irq(&hdspm->lock);
3646 spin_lock_irq(&hdspm->lock);
3647 if ((err = hdspm_set_rate(hdspm, params_rate(params), 0)) < 0) {
3648 spin_unlock_irq(&hdspm->lock);
3653 spin_unlock_irq(&hdspm->lock);
3656 hdspm_set_interrupt_interval(hdspm,
3677 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferOut,
3681 snd_hdspm_enable_out(hdspm, i, 1);
3683 hdspm->playback_buffer =
3686 hdspm->playback_buffer);
3688 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferIn,
3692 snd_hdspm_enable_in(hdspm, i, 1);
3694 hdspm->capture_buffer =
3697 hdspm->capture_buffer);
3718 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3725 snd_hdspm_enable_out(hdspm, i, 0);
3727 hdspm->playback_buffer = NULL;
3730 snd_hdspm_enable_in(hdspm, i, 0);
3732 hdspm->capture_buffer = NULL;
3744 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3749 if ((mapped_channel = hdspm->channel_map[info->channel]) < 0)
3781 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3785 spin_lock(&hdspm->lock);
3786 running = hdspm->running;
3796 spin_unlock(&hdspm->lock);
3800 other = hdspm->capture_substream;
3802 other = hdspm->playback_substream;
3820 hdspm_silence_playback(hdspm);
3824 hdspm_silence_playback(hdspm);
3828 hdspm_silence_playback(hdspm);
3832 if (!hdspm->running && running)
3833 hdspm_start_audio(hdspm);
3834 else if (hdspm->running && !running)
3835 hdspm_stop_audio(hdspm);
3836 hdspm->running = running;
3837 spin_unlock(&hdspm->lock);
3910 struct hdspm *hdspm = rule->private;
3918 .min = hdspm->ds_channels,
3919 .max = hdspm->ds_channels,
3925 .min = hdspm->ss_channels,
3926 .max = hdspm->ss_channels,
3937 struct hdspm *hdspm = rule->private;
3943 if (c->min >= hdspm->ss_channels) {
3950 } else if (c->max <= hdspm->ds_channels) {
3966 struct hdspm *hdspm = rule->private;
3969 if (hdspm->is_aes32) {
3970 list[0] = hdspm->qs_channels;
3971 list[1] = hdspm->ds_channels;
3972 list[2] = hdspm->ss_channels;
3975 list[0] = hdspm->ds_channels;
3976 list[1] = hdspm->ss_channels;
3992 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
3995 spin_lock_irq(&hdspm->lock);
4001 if (hdspm->capture_substream == NULL)
4002 hdspm_stop_audio(hdspm);
4004 hdspm->playback_pid = current->pid;
4005 hdspm->playback_substream = substream;
4007 spin_unlock_irq(&hdspm->lock);
4015 if (hdspm->is_aes32) {
4020 snd_hdspm_hw_rule_channels, hdspm,
4023 snd_hdspm_hw_rule_channels_rate, hdspm,
4027 snd_hdspm_hw_rule_rate_channels, hdspm,
4035 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
4037 spin_lock_irq(&hdspm->lock);
4039 hdspm->playback_pid = -1;
4040 hdspm->playback_substream = NULL;
4042 spin_unlock_irq(&hdspm->lock);
4050 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
4053 spin_lock_irq(&hdspm->lock);
4057 if (hdspm->playback_substream == NULL)
4058 hdspm_stop_audio(hdspm);
4060 hdspm->capture_pid = current->pid;
4061 hdspm->capture_substream = substream;
4063 spin_unlock_irq(&hdspm->lock);
4069 if (hdspm->is_aes32) {
4074 snd_hdspm_hw_rule_channels, hdspm,
4077 snd_hdspm_hw_rule_channels_rate, hdspm,
4081 snd_hdspm_hw_rule_rate_channels, hdspm,
4089 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
4091 spin_lock_irq(&hdspm->lock);
4093 hdspm->capture_pid = -1;
4094 hdspm->capture_substream = NULL;
4096 spin_unlock_irq(&hdspm->lock);
4110 struct hdspm *hdspm = (struct hdspm *) hw->private_data;
4124 hdspm->iobase+HDSPM_MADI_peakrmsbase,
4133 spin_lock_irq(&hdspm->lock);
4135 (unsigned char) hdspm_pref_sync_ref(hdspm);
4137 (unsigned char) hdspm_wc_sync_check(hdspm);
4139 info.system_sample_rate = hdspm->system_sample_rate;
4141 hdspm_external_sample_rate(hdspm);
4143 (unsigned char) hdspm_system_clock_mode(hdspm);
4145 (unsigned char) hdspm_clock_source(hdspm);
4147 (unsigned char) hdspm_autosync_ref(hdspm);
4148 info.line_out = (unsigned char) hdspm_line_out(hdspm);
4150 spin_unlock_irq(&hdspm->lock);
4156 hdspm_version.firmware_rev = hdspm->firmware_rev;
4166 ((void __user *)mixer.mixer, hdspm->mixer, sizeof(struct hdspm_mixer)))
4204 struct hdspm * hdspm)
4212 hdspm->hwdep = hw;
4213 hw->private_data = hdspm;
4227 static int __devinit snd_hdspm_preallocate_memory(struct hdspm * hdspm)
4233 pcm = hdspm->pcm;
4241 snd_dma_pci_data(hdspm->pci),
4253 static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf,
4258 hdspm_write(hdspm, reg + 4 * i,
4265 struct hdspm * hdspm)
4270 if ((err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm)) < 0)
4273 hdspm->pcm = pcm;
4274 pcm->private_data = hdspm;
4275 strcpy(pcm->name, hdspm->card_name);
4284 if ((err = snd_hdspm_preallocate_memory(hdspm)) < 0)
4290 static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm)
4292 snd_hdspm_flush_midi_input(hdspm, 0);
4293 snd_hdspm_flush_midi_input(hdspm, 1);
4297 struct hdspm * hdspm)
4302 if ((err = snd_hdspm_create_pcm(card, hdspm)) < 0)
4305 if ((err = snd_hdspm_create_midi(card, hdspm, 0)) < 0)
4308 if ((err = snd_hdspm_create_midi(card, hdspm, 1)) < 0)
4311 if ((err = snd_hdspm_create_controls(card, hdspm)) < 0)
4314 if ((err = snd_hdspm_create_hwdep(card, hdspm)) < 0)
4318 snd_hdspm_proc_init(hdspm);
4320 hdspm->system_sample_rate = -1;
4321 hdspm->last_external_sample_rate = -1;
4322 hdspm->last_internal_sample_rate = -1;
4323 hdspm->playback_pid = -1;
4324 hdspm->capture_pid = -1;
4325 hdspm->capture_substream = NULL;
4326 hdspm->playback_substream = NULL;
4329 if ((err = snd_hdspm_set_defaults(hdspm)) < 0)
4333 hdspm_update_simple_mixer_controls(hdspm);
4347 static int __devinit snd_hdspm_create(struct snd_card *card, struct hdspm * hdspm,
4350 struct pci_dev *pci = hdspm->pci;
4356 hdspm->irq = -1;
4357 hdspm->irq_count = 0;
4359 hdspm->midi[0].rmidi = NULL;
4360 hdspm->midi[1].rmidi = NULL;
4361 hdspm->midi[0].input = NULL;
4362 hdspm->midi[1].input = NULL;
4363 hdspm->midi[0].output = NULL;
4364 hdspm->midi[1].output = NULL;
4365 spin_lock_init(&hdspm->midi[0].lock);
4366 spin_lock_init(&hdspm->midi[1].lock);
4367 hdspm->iobase = NULL;
4368 hdspm->control_register = 0;
4369 hdspm->control2_register = 0;
4371 hdspm->playback_buffer = NULL;
4372 hdspm->capture_buffer = NULL;
4375 hdspm->playback_mixer_ctls[i] = NULL;
4376 hdspm->mixer = NULL;
4378 hdspm->card = card;
4380 spin_lock_init(&hdspm->lock);
4382 tasklet_init(&hdspm->midi_tasklet,
4383 hdspm_midi_tasklet, (unsigned long) hdspm);
4385 pci_read_config_word(hdspm->pci,
4386 PCI_CLASS_REVISION, &hdspm->firmware_rev);
4388 hdspm->is_aes32 = (hdspm->firmware_rev >= HDSPM_AESREVISION);
4391 if (hdspm->is_aes32) {
4393 hdspm->card_name = "RME HDSPM AES32";
4396 hdspm->card_name = "RME HDSPM MADI";
4402 pci_set_master(hdspm->pci);
4404 if ((err = pci_request_regions(pci, "hdspm")) < 0)
4407 hdspm->port = pci_resource_start(pci, 0);
4411 hdspm->port, hdspm->port + io_extent - 1);
4414 if ((hdspm->iobase = ioremap_nocache(hdspm->port, io_extent)) == NULL) {
4416 hdspm->port, hdspm->port + io_extent - 1);
4420 (unsigned long)hdspm->iobase, hdspm->port,
4421 hdspm->port + io_extent - 1);
4424 IRQF_SHARED, "hdspm", hdspm)) {
4431 hdspm->irq = pci->irq;
4432 hdspm->precise_ptr = precise_ptr;
4434 hdspm->monitor_outs = enable_monitor;
4438 if ((hdspm->mixer = kmalloc(sizeof(struct hdspm_mixer), GFP_KERNEL))
4445 hdspm->ss_channels = MADI_SS_CHANNELS;
4446 hdspm->ds_channels = MADI_DS_CHANNELS;
4447 hdspm->qs_channels = MADI_QS_CHANNELS;
4450 if ((err = snd_hdspm_create_alsa_devices(card, hdspm)) < 0)
4453 snd_hdspm_initialize_midi_flush(hdspm);
4458 static int snd_hdspm_free(struct hdspm * hdspm)
4461 if (hdspm->port) {
4464 hdspm->control_register &=
4468 hdspm_write(hdspm, HDSPM_controlRegister,
4469 hdspm->control_register);
4472 if (hdspm->irq >= 0)
4473 free_irq(hdspm->irq, (void *) hdspm);
4476 kfree(hdspm->mixer);
4478 if (hdspm->iobase)
4479 iounmap(hdspm->iobase);
4481 if (hdspm->port)
4482 pci_release_regions(hdspm->pci);
4484 pci_disable_device(hdspm->pci);
4490 struct hdspm *hdspm = (struct hdspm *) card->private_data;
4492 if (hdspm)
4493 snd_hdspm_free(hdspm);
4500 struct hdspm *hdspm;
4512 THIS_MODULE, sizeof(struct hdspm))))
4515 hdspm = (struct hdspm *) card->private_data;
4517 hdspm->dev = dev;
4518 hdspm->pci = pci;
4523 snd_hdspm_create(card, hdspm, precise_ptr[dev],
4530 sprintf(card->longname, "%s at 0x%lx, irq %d", hdspm->card_name,
4531 hdspm->port, hdspm->irq);