2 * bebob_stream.c - a part of driver for BeBoB based devices
4 * Copyright (c) 2013-2014 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
11 #define CALLBACK_TIMEOUT 1000
12 #define FW_ISO_RESOURCE_DELAY 1000
16 * For BeBoB streams, Both of input and output CMP connection are important.
18 * For most devices, each CMP connection starts to transmit/receive a
19 * corresponding stream. But for a few devices, both of CMP connection needs
20 * to start transmitting stream. An example is 'M-Audio Firewire 410'.
23 /* 128 is an arbitrary length but it seems to be enough */
24 #define FORMAT_MAXIMUM_LENGTH 128
26 const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES] = {
37 * See: Table 51: Extended Stream Format Info ‘Sampling Frequency’
38 * in Additional AVC commands (Nov 2003, BridgeCo)
40 static const unsigned int bridgeco_freq_table[] = {
51 get_formation_index(unsigned int rate)
55 for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {
56 if (snd_bebob_rate_table[i] == rate)
63 snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *curr_rate)
65 unsigned int tx_rate, rx_rate, trials;
70 err = avc_general_get_sig_fmt(bebob->unit, &tx_rate,
71 AVC_GENERAL_PLUG_DIR_OUT, 0);
72 } while (err == -EAGAIN && ++trials < 3);
78 err = avc_general_get_sig_fmt(bebob->unit, &rx_rate,
79 AVC_GENERAL_PLUG_DIR_IN, 0);
80 } while (err == -EAGAIN && ++trials < 3);
85 if (rx_rate == tx_rate)
88 /* synchronize receive stream rate to transmit stream rate */
89 err = avc_general_set_sig_fmt(bebob->unit, rx_rate,
90 AVC_GENERAL_PLUG_DIR_IN, 0);
96 snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate)
100 err = avc_general_set_sig_fmt(bebob->unit, rate,
101 AVC_GENERAL_PLUG_DIR_OUT, 0);
105 err = avc_general_set_sig_fmt(bebob->unit, rate,
106 AVC_GENERAL_PLUG_DIR_IN, 0);
111 * Some devices need a bit time for transition.
112 * 300msec is got by some experiments.
120 snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob, bool *internal)
122 u8 addr[AVC_BRIDGECO_ADDR_BYTES], input[7];
128 * 1.The device don't support to switch source of clock then assumed
129 * to use internal clock always
131 if (bebob->sync_input_plug < 0) {
137 * 2.The device supports to switch source of clock by an usual way.
138 * Let's check input for 'Music Sub Unit Sync Input' plug.
140 avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
141 bebob->sync_input_plug);
142 err = avc_bridgeco_get_plug_input(bebob->unit, addr, input);
144 dev_err(&bebob->unit->device,
145 "fail to get an input for MSU in plug %d: %d\n",
146 bebob->sync_input_plug, err);
151 * If there are no input plugs, all of fields are 0xff.
152 * Here check the first field. This field is used for direction.
154 if (input[0] == 0xff) {
160 * If source of clock is internal CSR, Music Sub Unit Sync Input is
161 * a destination of Music Sub Unit Sync Output.
163 *internal = ((input[0] == AVC_BRIDGECO_PLUG_DIR_OUT) &&
164 (input[1] == AVC_BRIDGECO_PLUG_MODE_SUBUNIT) &&
165 (input[2] == 0x0c) &&
172 map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
174 unsigned int sec, sections, ch, channels;
175 unsigned int pcm, midi, location;
176 unsigned int stm_pos, sec_loc, pos;
177 u8 *buf, addr[AVC_BRIDGECO_ADDR_BYTES], type;
178 enum avc_bridgeco_plug_dir dir;
182 * The length of return value of this command cannot be expected. Here
183 * use the maximum length of FCP.
185 buf = kzalloc(256, GFP_KERNEL);
189 if (s == &bebob->tx_stream)
190 dir = AVC_BRIDGECO_PLUG_DIR_OUT;
192 dir = AVC_BRIDGECO_PLUG_DIR_IN;
194 avc_bridgeco_fill_unit_addr(addr, dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
195 err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, 256);
197 dev_err(&bebob->unit->device,
198 "fail to get channel position for isoc %s plug 0: %d\n",
199 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" : "out",
205 /* positions in I/O buffer */
209 /* the number of sections in AMDTP packet */
210 sections = buf[pos++];
212 for (sec = 0; sec < sections; sec++) {
213 /* type of this section */
214 avc_bridgeco_fill_unit_addr(addr, dir,
215 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
216 err = avc_bridgeco_get_plug_section_type(bebob->unit, addr,
219 dev_err(&bebob->unit->device,
220 "fail to get section type for isoc %s plug 0: %d\n",
221 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :
232 /* the number of channels in this section */
233 channels = buf[pos++];
235 for (ch = 0; ch < channels; ch++) {
236 /* position of this channel in AMDTP packet */
237 stm_pos = buf[pos++] - 1;
238 /* location of this channel in this section */
239 sec_loc = buf[pos++] - 1;
242 /* for MIDI conformant data channel */
244 /* AMDTP_MAX_CHANNELS_FOR_MIDI is 1. */
245 if ((midi > 0) && (stm_pos != midi)) {
249 s->midi_position = stm_pos;
252 /* for PCM data channel */
253 case 0x01: /* Headphone */
254 case 0x02: /* Microphone */
255 case 0x03: /* Line */
256 case 0x04: /* SPDIF */
257 case 0x05: /* ADAT */
258 case 0x06: /* TDIF */
259 case 0x07: /* MADI */
260 /* for undefined/changeable signal */
261 case 0x08: /* Analog */
262 case 0x09: /* Digital */
264 location = pcm + sec_loc;
265 if (location >= AMDTP_MAX_CHANNELS_FOR_PCM) {
269 s->pcm_positions[location] = stm_pos;
285 init_both_connections(struct snd_bebob *bebob)
289 err = cmp_connection_init(&bebob->in_conn,
290 bebob->unit, CMP_INPUT, 0);
294 err = cmp_connection_init(&bebob->out_conn,
295 bebob->unit, CMP_OUTPUT, 0);
297 cmp_connection_destroy(&bebob->in_conn);
303 check_connection_used_by_others(struct snd_bebob *bebob, struct amdtp_stream *s)
305 struct cmp_connection *conn;
309 if (s == &bebob->tx_stream)
310 conn = &bebob->out_conn;
312 conn = &bebob->in_conn;
314 err = cmp_connection_check_used(conn, &used);
315 if ((err >= 0) && used && !amdtp_stream_running(s)) {
316 dev_err(&bebob->unit->device,
317 "Connection established by others: %cPCR[%d]\n",
318 (conn->direction == CMP_OUTPUT) ? 'o' : 'i',
327 make_both_connections(struct snd_bebob *bebob, unsigned int rate)
329 int index, pcm_channels, midi_channels, err = 0;
331 if (bebob->connected)
334 /* confirm params for both streams */
335 index = get_formation_index(rate);
336 pcm_channels = bebob->tx_stream_formations[index].pcm;
337 midi_channels = bebob->tx_stream_formations[index].midi;
338 amdtp_stream_set_parameters(&bebob->tx_stream,
339 rate, pcm_channels, midi_channels * 8);
340 pcm_channels = bebob->rx_stream_formations[index].pcm;
341 midi_channels = bebob->rx_stream_formations[index].midi;
342 amdtp_stream_set_parameters(&bebob->rx_stream,
343 rate, pcm_channels, midi_channels * 8);
345 /* establish connections for both streams */
346 err = cmp_connection_establish(&bebob->out_conn,
347 amdtp_stream_get_max_payload(&bebob->tx_stream));
350 err = cmp_connection_establish(&bebob->in_conn,
351 amdtp_stream_get_max_payload(&bebob->rx_stream));
353 cmp_connection_break(&bebob->out_conn);
357 bebob->connected = true;
363 break_both_connections(struct snd_bebob *bebob)
365 cmp_connection_break(&bebob->in_conn);
366 cmp_connection_break(&bebob->out_conn);
368 bebob->connected = false;
372 destroy_both_connections(struct snd_bebob *bebob)
374 break_both_connections(bebob);
376 cmp_connection_destroy(&bebob->in_conn);
377 cmp_connection_destroy(&bebob->out_conn);
381 get_sync_mode(struct snd_bebob *bebob, enum cip_flags *sync_mode)
383 /* currently this module doesn't support SYT-Match mode */
384 *sync_mode = CIP_SYNC_TO_DEVICE;
389 start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream,
392 struct cmp_connection *conn;
395 if (stream == &bebob->rx_stream)
396 conn = &bebob->in_conn;
398 conn = &bebob->out_conn;
400 /* channel mapping */
401 err = map_data_channels(bebob, stream);
405 /* start amdtp stream */
406 err = amdtp_stream_start(stream,
407 conn->resources.channel,
413 int snd_bebob_stream_init_duplex(struct snd_bebob *bebob)
417 err = init_both_connections(bebob);
421 err = amdtp_stream_init(&bebob->tx_stream, bebob->unit,
422 AMDTP_IN_STREAM, CIP_BLOCKING);
424 amdtp_stream_destroy(&bebob->tx_stream);
425 destroy_both_connections(bebob);
428 /* See comments in next function */
429 init_completion(&bebob->bus_reset);
430 bebob->tx_stream.flags |= CIP_SKIP_INIT_DBC_CHECK;
432 err = amdtp_stream_init(&bebob->rx_stream, bebob->unit,
433 AMDTP_OUT_STREAM, CIP_BLOCKING);
435 amdtp_stream_destroy(&bebob->tx_stream);
436 amdtp_stream_destroy(&bebob->rx_stream);
437 destroy_both_connections(bebob);
443 int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, int rate)
445 struct amdtp_stream *master, *slave;
446 atomic_t *slave_substreams;
447 enum cip_flags sync_mode;
448 unsigned int curr_rate;
449 bool updated = false;
453 * Normal BeBoB firmware has a quirk at bus reset to transmits packets
454 * with discontinuous value in dbc field.
456 * This 'struct completion' is used to call .update() at first to update
457 * connections/streams. Next following codes handle streaming error.
459 if (amdtp_streaming_error(&bebob->tx_stream)) {
460 if (completion_done(&bebob->bus_reset))
461 reinit_completion(&bebob->bus_reset);
463 updated = (wait_for_completion_interruptible_timeout(
465 msecs_to_jiffies(FW_ISO_RESOURCE_DELAY)) > 0);
468 mutex_lock(&bebob->mutex);
470 /* Need no substreams */
471 if (atomic_read(&bebob->playback_substreams) == 0 &&
472 atomic_read(&bebob->capture_substreams) == 0)
475 err = get_sync_mode(bebob, &sync_mode);
478 if (sync_mode == CIP_SYNC_TO_DEVICE) {
479 master = &bebob->tx_stream;
480 slave = &bebob->rx_stream;
481 slave_substreams = &bebob->playback_substreams;
483 master = &bebob->rx_stream;
484 slave = &bebob->tx_stream;
485 slave_substreams = &bebob->capture_substreams;
489 * Considering JACK/FFADO streaming:
490 * TODO: This can be removed hwdep functionality becomes popular.
492 err = check_connection_used_by_others(bebob, master);
497 * packet queueing error or detecting discontinuity
499 * At bus reset, connections should not be broken here. So streams need
500 * to be re-started. This is a reason to use SKIP_INIT_DBC_CHECK flag.
502 if (amdtp_streaming_error(master))
503 amdtp_stream_stop(master);
504 if (amdtp_streaming_error(slave))
505 amdtp_stream_stop(slave);
507 !amdtp_stream_running(master) && !amdtp_stream_running(slave))
508 break_both_connections(bebob);
510 /* stop streams if rate is different */
511 err = snd_bebob_stream_get_rate(bebob, &curr_rate);
513 dev_err(&bebob->unit->device,
514 "fail to get sampling rate: %d\n", err);
519 if (rate != curr_rate) {
520 amdtp_stream_stop(master);
521 amdtp_stream_stop(slave);
522 break_both_connections(bebob);
525 /* master should be always running */
526 if (!amdtp_stream_running(master)) {
527 amdtp_stream_set_sync(sync_mode, master, slave);
528 bebob->master = master;
532 * If establishing connections at first, Yamaha GO46
533 * (and maybe Terratec X24) don't generate sound.
535 err = snd_bebob_stream_set_rate(bebob, rate);
537 dev_err(&bebob->unit->device,
538 "fail to set sampling rate: %d\n",
543 err = make_both_connections(bebob, rate);
547 err = start_stream(bebob, master, rate);
549 dev_err(&bebob->unit->device,
550 "fail to run AMDTP master stream:%d\n", err);
551 break_both_connections(bebob);
555 /* wait first callback */
556 if (!amdtp_stream_wait_callback(master, CALLBACK_TIMEOUT)) {
557 amdtp_stream_stop(master);
558 break_both_connections(bebob);
564 /* start slave if needed */
565 if (atomic_read(slave_substreams) > 0 && !amdtp_stream_running(slave)) {
566 err = start_stream(bebob, slave, rate);
568 dev_err(&bebob->unit->device,
569 "fail to run AMDTP slave stream:%d\n", err);
570 amdtp_stream_stop(master);
571 break_both_connections(bebob);
575 /* wait first callback */
576 if (!amdtp_stream_wait_callback(slave, CALLBACK_TIMEOUT)) {
577 amdtp_stream_stop(slave);
578 amdtp_stream_stop(master);
579 break_both_connections(bebob);
584 mutex_unlock(&bebob->mutex);
588 void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)
590 struct amdtp_stream *master, *slave;
591 atomic_t *master_substreams, *slave_substreams;
593 mutex_lock(&bebob->mutex);
595 if (bebob->master == &bebob->rx_stream) {
596 slave = &bebob->tx_stream;
597 master = &bebob->rx_stream;
598 slave_substreams = &bebob->capture_substreams;
599 master_substreams = &bebob->playback_substreams;
601 slave = &bebob->rx_stream;
602 master = &bebob->tx_stream;
603 slave_substreams = &bebob->playback_substreams;
604 master_substreams = &bebob->capture_substreams;
607 if (atomic_read(slave_substreams) == 0) {
608 amdtp_stream_pcm_abort(slave);
609 amdtp_stream_stop(slave);
611 if (atomic_read(master_substreams) == 0) {
612 amdtp_stream_pcm_abort(master);
613 amdtp_stream_stop(master);
614 break_both_connections(bebob);
618 mutex_unlock(&bebob->mutex);
621 void snd_bebob_stream_update_duplex(struct snd_bebob *bebob)
623 /* vs. XRUN recovery due to discontinuity at bus reset */
624 mutex_lock(&bebob->mutex);
626 if ((cmp_connection_update(&bebob->in_conn) < 0) ||
627 (cmp_connection_update(&bebob->out_conn) < 0)) {
628 amdtp_stream_pcm_abort(&bebob->rx_stream);
629 amdtp_stream_pcm_abort(&bebob->tx_stream);
630 amdtp_stream_stop(&bebob->rx_stream);
631 amdtp_stream_stop(&bebob->tx_stream);
632 break_both_connections(bebob);
634 amdtp_stream_update(&bebob->rx_stream);
635 amdtp_stream_update(&bebob->tx_stream);
638 /* wake up stream_start_duplex() */
639 if (!completion_done(&bebob->bus_reset))
640 complete_all(&bebob->bus_reset);
642 mutex_unlock(&bebob->mutex);
645 void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob)
647 mutex_lock(&bebob->mutex);
649 amdtp_stream_pcm_abort(&bebob->rx_stream);
650 amdtp_stream_pcm_abort(&bebob->tx_stream);
652 amdtp_stream_stop(&bebob->rx_stream);
653 amdtp_stream_stop(&bebob->tx_stream);
655 amdtp_stream_destroy(&bebob->rx_stream);
656 amdtp_stream_destroy(&bebob->tx_stream);
658 destroy_both_connections(bebob);
660 mutex_unlock(&bebob->mutex);
664 * See: Table 50: Extended Stream Format Info Format Hierarchy Level 2’
665 * in Additional AVC commands (Nov 2003, BridgeCo)
666 * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
669 parse_stream_formation(u8 *buf, unsigned int len,
670 struct snd_bebob_stream_formation *formation)
672 unsigned int i, e, channels, format;
675 * this module can support a hierarchy combination that:
676 * Root: Audio and Music (0x90)
677 * Level 1: AM824 Compound (0x40)
679 if ((buf[0] != 0x90) || (buf[1] != 0x40))
682 /* check sampling rate */
683 for (i = 0; i < ARRAY_SIZE(bridgeco_freq_table); i++) {
684 if (buf[2] == bridgeco_freq_table[i])
687 if (i == sizeof(bridgeco_freq_table))
690 /* Avoid double count by different entries for the same rate. */
691 memset(&formation[i], 0, sizeof(struct snd_bebob_stream_formation));
693 for (e = 0; e < buf[4]; e++) {
694 channels = buf[5 + e * 2];
695 format = buf[6 + e * 2];
698 /* IEC 60958-3, currently handle as MBLA */
700 /* Multi bit linear audio */
702 formation[i].pcm += channels;
704 /* MIDI Conformant */
706 formation[i].midi += channels;
708 /* IEC 61937-3 to 7 */
714 /* Multi bit linear audio */
715 case 0x07: /* DVD-Audio */
716 case 0x0c: /* High Precision */
718 case 0x08: /* (Plain) Raw */
719 case 0x09: /* (Plain) SACD */
720 case 0x0a: /* (Encoded) Raw */
721 case 0x0b: /* (Encoded) SACD */
722 /* Synchronization Stream (Stereo Raw audio) */
727 return -ENOSYS; /* not supported */
731 if (formation[i].pcm > AMDTP_MAX_CHANNELS_FOR_PCM ||
732 formation[i].midi > AMDTP_MAX_CHANNELS_FOR_MIDI)
739 fill_stream_formations(struct snd_bebob *bebob, enum avc_bridgeco_plug_dir dir,
743 struct snd_bebob_stream_formation *formations;
744 unsigned int len, eid;
745 u8 addr[AVC_BRIDGECO_ADDR_BYTES];
748 buf = kmalloc(FORMAT_MAXIMUM_LENGTH, GFP_KERNEL);
752 if (dir == AVC_BRIDGECO_PLUG_DIR_IN)
753 formations = bebob->rx_stream_formations;
755 formations = bebob->tx_stream_formations;
757 for (eid = 0; eid < SND_BEBOB_STRM_FMT_ENTRIES; eid++) {
758 len = FORMAT_MAXIMUM_LENGTH;
759 avc_bridgeco_fill_unit_addr(addr, dir,
760 AVC_BRIDGECO_PLUG_UNIT_ISOC, pid);
761 err = avc_bridgeco_get_plug_strm_fmt(bebob->unit, addr, buf,
763 /* No entries remained. */
764 if (err == -EINVAL && eid > 0) {
767 } else if (err < 0) {
768 dev_err(&bebob->unit->device,
769 "fail to get stream format %d for isoc %s plug %d:%d\n",
771 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :
777 err = parse_stream_formation(buf, len, formations);
787 seek_msu_sync_input_plug(struct snd_bebob *bebob)
789 u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
790 unsigned int i, type;
793 /* Get the number of Music Sub Unit for both direction. */
794 err = avc_general_get_plug_info(bebob->unit, 0x0c, 0x00, 0x00, plugs);
796 dev_err(&bebob->unit->device,
797 "fail to get info for MSU in/out plugs: %d\n",
802 /* seek destination plugs for 'MSU sync input' */
803 bebob->sync_input_plug = -1;
804 for (i = 0; i < plugs[0]; i++) {
805 avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN, i);
806 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
808 dev_err(&bebob->unit->device,
809 "fail to get type for MSU in plug %d: %d\n",
814 if (type == AVC_BRIDGECO_PLUG_TYPE_SYNC) {
815 bebob->sync_input_plug = i;
823 int snd_bebob_stream_discover(struct snd_bebob *bebob)
825 u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
826 enum avc_bridgeco_plug_type type;
830 /* the number of plugs for isoc in/out, ext in/out */
831 err = avc_general_get_plug_info(bebob->unit, 0x1f, 0x07, 0x00, plugs);
833 dev_err(&bebob->unit->device,
834 "fail to get info for isoc/external in/out plugs: %d\n",
840 * This module supports at least one isoc input plug and one isoc
843 if ((plugs[0] == 0) || (plugs[1] == 0)) {
848 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
849 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
850 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
852 dev_err(&bebob->unit->device,
853 "fail to get type for isoc in plug 0: %d\n", err);
855 } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {
859 err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_IN, 0);
863 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,
864 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
865 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
867 dev_err(&bebob->unit->device,
868 "fail to get type for isoc out plug 0: %d\n", err);
870 } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {
874 err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_OUT, 0);
878 /* count external input plugs for MIDI */
879 bebob->midi_input_ports = 0;
880 for (i = 0; i < plugs[2]; i++) {
881 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
882 AVC_BRIDGECO_PLUG_UNIT_EXT, i);
883 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
885 dev_err(&bebob->unit->device,
886 "fail to get type for external in plug %d: %d\n",
889 } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {
890 bebob->midi_input_ports++;
894 /* count external output plugs for MIDI */
895 bebob->midi_output_ports = 0;
896 for (i = 0; i < plugs[3]; i++) {
897 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,
898 AVC_BRIDGECO_PLUG_UNIT_EXT, i);
899 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
901 dev_err(&bebob->unit->device,
902 "fail to get type for external out plug %d: %d\n",
905 } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {
906 bebob->midi_output_ports++;
910 /* for check source of clock later */
911 err = seek_msu_sync_input_plug(bebob);
916 void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)
918 bebob->dev_lock_changed = true;
919 wake_up(&bebob->hwdep_wait);
922 int snd_bebob_stream_lock_try(struct snd_bebob *bebob)
926 spin_lock_irq(&bebob->lock);
928 /* user land lock this */
929 if (bebob->dev_lock_count < 0) {
934 /* this is the first time */
935 if (bebob->dev_lock_count++ == 0)
936 snd_bebob_stream_lock_changed(bebob);
939 spin_unlock_irq(&bebob->lock);
943 void snd_bebob_stream_lock_release(struct snd_bebob *bebob)
945 spin_lock_irq(&bebob->lock);
947 if (WARN_ON(bebob->dev_lock_count <= 0))
949 if (--bebob->dev_lock_count == 0)
950 snd_bebob_stream_lock_changed(bebob);
952 spin_unlock_irq(&bebob->lock);