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 struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
123 u8 addr[AVC_BRIDGECO_ADDR_BYTES], input[7];
129 /* 1.The device has its own operation to switch source of clock */
131 err = clk_spec->get(bebob, &id);
133 dev_err(&bebob->unit->device,
134 "fail to get clock source: %d\n", err);
135 else if (strncmp(clk_spec->labels[id], SND_BEBOB_CLOCK_INTERNAL,
136 strlen(SND_BEBOB_CLOCK_INTERNAL)) == 0)
142 * 2.The device don't support to switch source of clock then assumed
143 * to use internal clock always
145 if (bebob->sync_input_plug < 0) {
151 * 3.The device supports to switch source of clock by an usual way.
152 * Let's check input for 'Music Sub Unit Sync Input' plug.
154 avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
155 bebob->sync_input_plug);
156 err = avc_bridgeco_get_plug_input(bebob->unit, addr, input);
158 dev_err(&bebob->unit->device,
159 "fail to get an input for MSU in plug %d: %d\n",
160 bebob->sync_input_plug, err);
165 * If there are no input plugs, all of fields are 0xff.
166 * Here check the first field. This field is used for direction.
168 if (input[0] == 0xff) {
174 * If source of clock is internal CSR, Music Sub Unit Sync Input is
175 * a destination of Music Sub Unit Sync Output.
177 *internal = ((input[0] == AVC_BRIDGECO_PLUG_DIR_OUT) &&
178 (input[1] == AVC_BRIDGECO_PLUG_MODE_SUBUNIT) &&
179 (input[2] == 0x0c) &&
186 map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
188 unsigned int sec, sections, ch, channels;
189 unsigned int pcm, midi, location;
190 unsigned int stm_pos, sec_loc, pos;
191 u8 *buf, addr[AVC_BRIDGECO_ADDR_BYTES], type;
192 enum avc_bridgeco_plug_dir dir;
196 * The length of return value of this command cannot be expected. Here
197 * use the maximum length of FCP.
199 buf = kzalloc(256, GFP_KERNEL);
203 if (s == &bebob->tx_stream)
204 dir = AVC_BRIDGECO_PLUG_DIR_OUT;
206 dir = AVC_BRIDGECO_PLUG_DIR_IN;
208 avc_bridgeco_fill_unit_addr(addr, dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
209 err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, 256);
211 dev_err(&bebob->unit->device,
212 "fail to get channel position for isoc %s plug 0: %d\n",
213 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" : "out",
219 /* positions in I/O buffer */
223 /* the number of sections in AMDTP packet */
224 sections = buf[pos++];
226 for (sec = 0; sec < sections; sec++) {
227 /* type of this section */
228 avc_bridgeco_fill_unit_addr(addr, dir,
229 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
230 err = avc_bridgeco_get_plug_section_type(bebob->unit, addr,
233 dev_err(&bebob->unit->device,
234 "fail to get section type for isoc %s plug 0: %d\n",
235 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :
246 /* the number of channels in this section */
247 channels = buf[pos++];
249 for (ch = 0; ch < channels; ch++) {
250 /* position of this channel in AMDTP packet */
251 stm_pos = buf[pos++] - 1;
252 /* location of this channel in this section */
253 sec_loc = buf[pos++] - 1;
256 * Basically the number of location is within the
257 * number of channels in this section. But some models
258 * of M-Audio don't follow this. Its location for MIDI
259 * is the position of MIDI channels in AMDTP packet.
261 if (sec_loc >= channels)
265 /* for MIDI conformant data channel */
267 /* AMDTP_MAX_CHANNELS_FOR_MIDI is 1. */
268 if ((midi > 0) && (stm_pos != midi)) {
272 s->midi_position = stm_pos;
275 /* for PCM data channel */
276 case 0x01: /* Headphone */
277 case 0x02: /* Microphone */
278 case 0x03: /* Line */
279 case 0x04: /* SPDIF */
280 case 0x05: /* ADAT */
281 case 0x06: /* TDIF */
282 case 0x07: /* MADI */
283 /* for undefined/changeable signal */
284 case 0x08: /* Analog */
285 case 0x09: /* Digital */
287 location = pcm + sec_loc;
288 if (location >= AMDTP_MAX_CHANNELS_FOR_PCM) {
292 s->pcm_positions[location] = stm_pos;
308 init_both_connections(struct snd_bebob *bebob)
312 err = cmp_connection_init(&bebob->in_conn,
313 bebob->unit, CMP_INPUT, 0);
317 err = cmp_connection_init(&bebob->out_conn,
318 bebob->unit, CMP_OUTPUT, 0);
320 cmp_connection_destroy(&bebob->in_conn);
326 check_connection_used_by_others(struct snd_bebob *bebob, struct amdtp_stream *s)
328 struct cmp_connection *conn;
332 if (s == &bebob->tx_stream)
333 conn = &bebob->out_conn;
335 conn = &bebob->in_conn;
337 err = cmp_connection_check_used(conn, &used);
338 if ((err >= 0) && used && !amdtp_stream_running(s)) {
339 dev_err(&bebob->unit->device,
340 "Connection established by others: %cPCR[%d]\n",
341 (conn->direction == CMP_OUTPUT) ? 'o' : 'i',
350 make_both_connections(struct snd_bebob *bebob, unsigned int rate)
352 int index, pcm_channels, midi_channels, err = 0;
354 if (bebob->connected)
357 /* confirm params for both streams */
358 index = get_formation_index(rate);
359 pcm_channels = bebob->tx_stream_formations[index].pcm;
360 midi_channels = bebob->tx_stream_formations[index].midi;
361 amdtp_stream_set_parameters(&bebob->tx_stream,
362 rate, pcm_channels, midi_channels * 8);
363 pcm_channels = bebob->rx_stream_formations[index].pcm;
364 midi_channels = bebob->rx_stream_formations[index].midi;
365 amdtp_stream_set_parameters(&bebob->rx_stream,
366 rate, pcm_channels, midi_channels * 8);
368 /* establish connections for both streams */
369 err = cmp_connection_establish(&bebob->out_conn,
370 amdtp_stream_get_max_payload(&bebob->tx_stream));
373 err = cmp_connection_establish(&bebob->in_conn,
374 amdtp_stream_get_max_payload(&bebob->rx_stream));
376 cmp_connection_break(&bebob->out_conn);
380 bebob->connected = true;
386 break_both_connections(struct snd_bebob *bebob)
388 cmp_connection_break(&bebob->in_conn);
389 cmp_connection_break(&bebob->out_conn);
391 bebob->connected = false;
393 /* These models seems to be in transition state for a longer time. */
394 if (bebob->maudio_special_quirk != NULL)
399 destroy_both_connections(struct snd_bebob *bebob)
401 break_both_connections(bebob);
403 cmp_connection_destroy(&bebob->in_conn);
404 cmp_connection_destroy(&bebob->out_conn);
408 get_sync_mode(struct snd_bebob *bebob, enum cip_flags *sync_mode)
410 /* currently this module doesn't support SYT-Match mode */
411 *sync_mode = CIP_SYNC_TO_DEVICE;
416 start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream,
419 struct cmp_connection *conn;
422 if (stream == &bebob->rx_stream)
423 conn = &bebob->in_conn;
425 conn = &bebob->out_conn;
427 /* channel mapping */
428 if (bebob->maudio_special_quirk == NULL) {
429 err = map_data_channels(bebob, stream);
434 /* start amdtp stream */
435 err = amdtp_stream_start(stream,
436 conn->resources.channel,
442 int snd_bebob_stream_init_duplex(struct snd_bebob *bebob)
446 err = init_both_connections(bebob);
450 err = amdtp_stream_init(&bebob->tx_stream, bebob->unit,
451 AMDTP_IN_STREAM, CIP_BLOCKING);
453 amdtp_stream_destroy(&bebob->tx_stream);
454 destroy_both_connections(bebob);
457 /* See comments in next function */
458 init_completion(&bebob->bus_reset);
459 bebob->tx_stream.flags |= CIP_SKIP_INIT_DBC_CHECK;
461 * At high sampling rate, M-Audio special firmware transmits empty
462 * packet with the value of dbc incremented by 8 but the others are
463 * valid to IEC 61883-1.
465 if (bebob->maudio_special_quirk)
466 bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC;
468 err = amdtp_stream_init(&bebob->rx_stream, bebob->unit,
469 AMDTP_OUT_STREAM, CIP_BLOCKING);
471 amdtp_stream_destroy(&bebob->tx_stream);
472 amdtp_stream_destroy(&bebob->rx_stream);
473 destroy_both_connections(bebob);
479 int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, int rate)
481 struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate;
482 struct amdtp_stream *master, *slave;
483 atomic_t *slave_substreams;
484 enum cip_flags sync_mode;
485 unsigned int curr_rate;
486 bool updated = false;
490 * Normal BeBoB firmware has a quirk at bus reset to transmits packets
491 * with discontinuous value in dbc field.
493 * This 'struct completion' is used to call .update() at first to update
494 * connections/streams. Next following codes handle streaming error.
496 if (amdtp_streaming_error(&bebob->tx_stream)) {
497 if (completion_done(&bebob->bus_reset))
498 reinit_completion(&bebob->bus_reset);
500 updated = (wait_for_completion_interruptible_timeout(
502 msecs_to_jiffies(FW_ISO_RESOURCE_DELAY)) > 0);
505 mutex_lock(&bebob->mutex);
507 /* Need no substreams */
508 if (atomic_read(&bebob->playback_substreams) == 0 &&
509 atomic_read(&bebob->capture_substreams) == 0)
512 err = get_sync_mode(bebob, &sync_mode);
515 if (sync_mode == CIP_SYNC_TO_DEVICE) {
516 master = &bebob->tx_stream;
517 slave = &bebob->rx_stream;
518 slave_substreams = &bebob->playback_substreams;
520 master = &bebob->rx_stream;
521 slave = &bebob->tx_stream;
522 slave_substreams = &bebob->capture_substreams;
526 * Considering JACK/FFADO streaming:
527 * TODO: This can be removed hwdep functionality becomes popular.
529 err = check_connection_used_by_others(bebob, master);
534 * packet queueing error or detecting discontinuity
536 * At bus reset, connections should not be broken here. So streams need
537 * to be re-started. This is a reason to use SKIP_INIT_DBC_CHECK flag.
539 if (amdtp_streaming_error(master))
540 amdtp_stream_stop(master);
541 if (amdtp_streaming_error(slave))
542 amdtp_stream_stop(slave);
544 !amdtp_stream_running(master) && !amdtp_stream_running(slave))
545 break_both_connections(bebob);
547 /* stop streams if rate is different */
548 err = rate_spec->get(bebob, &curr_rate);
550 dev_err(&bebob->unit->device,
551 "fail to get sampling rate: %d\n", err);
556 if (rate != curr_rate) {
557 amdtp_stream_stop(master);
558 amdtp_stream_stop(slave);
559 break_both_connections(bebob);
562 /* master should be always running */
563 if (!amdtp_stream_running(master)) {
564 amdtp_stream_set_sync(sync_mode, master, slave);
565 bebob->master = master;
569 * If establishing connections at first, Yamaha GO46
570 * (and maybe Terratec X24) don't generate sound.
572 * For firmware customized by M-Audio, refer to next NOTE.
574 if (bebob->maudio_special_quirk == NULL) {
575 err = rate_spec->set(bebob, rate);
577 dev_err(&bebob->unit->device,
578 "fail to set sampling rate: %d\n",
584 err = make_both_connections(bebob, rate);
588 err = start_stream(bebob, master, rate);
590 dev_err(&bebob->unit->device,
591 "fail to run AMDTP master stream:%d\n", err);
592 break_both_connections(bebob);
598 * The firmware customized by M-Audio uses these commands to
599 * start transmitting stream. This is not usual way.
601 if (bebob->maudio_special_quirk != NULL) {
602 err = rate_spec->set(bebob, rate);
604 dev_err(&bebob->unit->device,
605 "fail to ensure sampling rate: %d\n",
607 amdtp_stream_stop(master);
608 break_both_connections(bebob);
613 /* wait first callback */
614 if (!amdtp_stream_wait_callback(master, CALLBACK_TIMEOUT)) {
615 amdtp_stream_stop(master);
616 break_both_connections(bebob);
622 /* start slave if needed */
623 if (atomic_read(slave_substreams) > 0 && !amdtp_stream_running(slave)) {
624 err = start_stream(bebob, slave, rate);
626 dev_err(&bebob->unit->device,
627 "fail to run AMDTP slave stream:%d\n", err);
628 amdtp_stream_stop(master);
629 break_both_connections(bebob);
633 /* wait first callback */
634 if (!amdtp_stream_wait_callback(slave, CALLBACK_TIMEOUT)) {
635 amdtp_stream_stop(slave);
636 amdtp_stream_stop(master);
637 break_both_connections(bebob);
642 mutex_unlock(&bebob->mutex);
646 void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)
648 struct amdtp_stream *master, *slave;
649 atomic_t *master_substreams, *slave_substreams;
651 mutex_lock(&bebob->mutex);
653 if (bebob->master == &bebob->rx_stream) {
654 slave = &bebob->tx_stream;
655 master = &bebob->rx_stream;
656 slave_substreams = &bebob->capture_substreams;
657 master_substreams = &bebob->playback_substreams;
659 slave = &bebob->rx_stream;
660 master = &bebob->tx_stream;
661 slave_substreams = &bebob->playback_substreams;
662 master_substreams = &bebob->capture_substreams;
665 if (atomic_read(slave_substreams) == 0) {
666 amdtp_stream_pcm_abort(slave);
667 amdtp_stream_stop(slave);
669 if (atomic_read(master_substreams) == 0) {
670 amdtp_stream_pcm_abort(master);
671 amdtp_stream_stop(master);
672 break_both_connections(bebob);
676 mutex_unlock(&bebob->mutex);
679 void snd_bebob_stream_update_duplex(struct snd_bebob *bebob)
681 /* vs. XRUN recovery due to discontinuity at bus reset */
682 mutex_lock(&bebob->mutex);
684 if ((cmp_connection_update(&bebob->in_conn) < 0) ||
685 (cmp_connection_update(&bebob->out_conn) < 0)) {
686 amdtp_stream_pcm_abort(&bebob->rx_stream);
687 amdtp_stream_pcm_abort(&bebob->tx_stream);
688 amdtp_stream_stop(&bebob->rx_stream);
689 amdtp_stream_stop(&bebob->tx_stream);
690 break_both_connections(bebob);
692 amdtp_stream_update(&bebob->rx_stream);
693 amdtp_stream_update(&bebob->tx_stream);
696 /* wake up stream_start_duplex() */
697 if (!completion_done(&bebob->bus_reset))
698 complete_all(&bebob->bus_reset);
700 mutex_unlock(&bebob->mutex);
703 void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob)
705 mutex_lock(&bebob->mutex);
707 amdtp_stream_pcm_abort(&bebob->rx_stream);
708 amdtp_stream_pcm_abort(&bebob->tx_stream);
710 amdtp_stream_stop(&bebob->rx_stream);
711 amdtp_stream_stop(&bebob->tx_stream);
713 amdtp_stream_destroy(&bebob->rx_stream);
714 amdtp_stream_destroy(&bebob->tx_stream);
716 destroy_both_connections(bebob);
718 mutex_unlock(&bebob->mutex);
722 * See: Table 50: Extended Stream Format Info Format Hierarchy Level 2’
723 * in Additional AVC commands (Nov 2003, BridgeCo)
724 * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
727 parse_stream_formation(u8 *buf, unsigned int len,
728 struct snd_bebob_stream_formation *formation)
730 unsigned int i, e, channels, format;
733 * this module can support a hierarchy combination that:
734 * Root: Audio and Music (0x90)
735 * Level 1: AM824 Compound (0x40)
737 if ((buf[0] != 0x90) || (buf[1] != 0x40))
740 /* check sampling rate */
741 for (i = 0; i < ARRAY_SIZE(bridgeco_freq_table); i++) {
742 if (buf[2] == bridgeco_freq_table[i])
745 if (i == sizeof(bridgeco_freq_table))
748 /* Avoid double count by different entries for the same rate. */
749 memset(&formation[i], 0, sizeof(struct snd_bebob_stream_formation));
751 for (e = 0; e < buf[4]; e++) {
752 channels = buf[5 + e * 2];
753 format = buf[6 + e * 2];
756 /* IEC 60958-3, currently handle as MBLA */
758 /* Multi bit linear audio */
760 formation[i].pcm += channels;
762 /* MIDI Conformant */
764 formation[i].midi += channels;
766 /* IEC 61937-3 to 7 */
772 /* Multi bit linear audio */
773 case 0x07: /* DVD-Audio */
774 case 0x0c: /* High Precision */
776 case 0x08: /* (Plain) Raw */
777 case 0x09: /* (Plain) SACD */
778 case 0x0a: /* (Encoded) Raw */
779 case 0x0b: /* (Encoded) SACD */
780 /* Synchronization Stream (Stereo Raw audio) */
785 return -ENOSYS; /* not supported */
789 if (formation[i].pcm > AMDTP_MAX_CHANNELS_FOR_PCM ||
790 formation[i].midi > AMDTP_MAX_CHANNELS_FOR_MIDI)
797 fill_stream_formations(struct snd_bebob *bebob, enum avc_bridgeco_plug_dir dir,
801 struct snd_bebob_stream_formation *formations;
802 unsigned int len, eid;
803 u8 addr[AVC_BRIDGECO_ADDR_BYTES];
806 buf = kmalloc(FORMAT_MAXIMUM_LENGTH, GFP_KERNEL);
810 if (dir == AVC_BRIDGECO_PLUG_DIR_IN)
811 formations = bebob->rx_stream_formations;
813 formations = bebob->tx_stream_formations;
815 for (eid = 0; eid < SND_BEBOB_STRM_FMT_ENTRIES; eid++) {
816 len = FORMAT_MAXIMUM_LENGTH;
817 avc_bridgeco_fill_unit_addr(addr, dir,
818 AVC_BRIDGECO_PLUG_UNIT_ISOC, pid);
819 err = avc_bridgeco_get_plug_strm_fmt(bebob->unit, addr, buf,
821 /* No entries remained. */
822 if (err == -EINVAL && eid > 0) {
825 } else if (err < 0) {
826 dev_err(&bebob->unit->device,
827 "fail to get stream format %d for isoc %s plug %d:%d\n",
829 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :
835 err = parse_stream_formation(buf, len, formations);
845 seek_msu_sync_input_plug(struct snd_bebob *bebob)
847 u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
848 unsigned int i, type;
851 /* Get the number of Music Sub Unit for both direction. */
852 err = avc_general_get_plug_info(bebob->unit, 0x0c, 0x00, 0x00, plugs);
854 dev_err(&bebob->unit->device,
855 "fail to get info for MSU in/out plugs: %d\n",
860 /* seek destination plugs for 'MSU sync input' */
861 bebob->sync_input_plug = -1;
862 for (i = 0; i < plugs[0]; i++) {
863 avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN, i);
864 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
866 dev_err(&bebob->unit->device,
867 "fail to get type for MSU in plug %d: %d\n",
872 if (type == AVC_BRIDGECO_PLUG_TYPE_SYNC) {
873 bebob->sync_input_plug = i;
881 int snd_bebob_stream_discover(struct snd_bebob *bebob)
883 struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
884 u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
885 enum avc_bridgeco_plug_type type;
889 /* the number of plugs for isoc in/out, ext in/out */
890 err = avc_general_get_plug_info(bebob->unit, 0x1f, 0x07, 0x00, plugs);
892 dev_err(&bebob->unit->device,
893 "fail to get info for isoc/external in/out plugs: %d\n",
899 * This module supports at least one isoc input plug and one isoc
902 if ((plugs[0] == 0) || (plugs[1] == 0)) {
907 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
908 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
909 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
911 dev_err(&bebob->unit->device,
912 "fail to get type for isoc in plug 0: %d\n", err);
914 } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {
918 err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_IN, 0);
922 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,
923 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
924 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
926 dev_err(&bebob->unit->device,
927 "fail to get type for isoc out plug 0: %d\n", err);
929 } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {
933 err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_OUT, 0);
937 /* count external input plugs for MIDI */
938 bebob->midi_input_ports = 0;
939 for (i = 0; i < plugs[2]; i++) {
940 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
941 AVC_BRIDGECO_PLUG_UNIT_EXT, i);
942 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
944 dev_err(&bebob->unit->device,
945 "fail to get type for external in plug %d: %d\n",
948 } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {
949 bebob->midi_input_ports++;
953 /* count external output plugs for MIDI */
954 bebob->midi_output_ports = 0;
955 for (i = 0; i < plugs[3]; i++) {
956 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,
957 AVC_BRIDGECO_PLUG_UNIT_EXT, i);
958 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
960 dev_err(&bebob->unit->device,
961 "fail to get type for external out plug %d: %d\n",
964 } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {
965 bebob->midi_output_ports++;
969 /* for check source of clock later */
971 err = seek_msu_sync_input_plug(bebob);
976 void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)
978 bebob->dev_lock_changed = true;
979 wake_up(&bebob->hwdep_wait);
982 int snd_bebob_stream_lock_try(struct snd_bebob *bebob)
986 spin_lock_irq(&bebob->lock);
988 /* user land lock this */
989 if (bebob->dev_lock_count < 0) {
994 /* this is the first time */
995 if (bebob->dev_lock_count++ == 0)
996 snd_bebob_stream_lock_changed(bebob);
999 spin_unlock_irq(&bebob->lock);
1003 void snd_bebob_stream_lock_release(struct snd_bebob *bebob)
1005 spin_lock_irq(&bebob->lock);
1007 if (WARN_ON(bebob->dev_lock_count <= 0))
1009 if (--bebob->dev_lock_count == 0)
1010 snd_bebob_stream_lock_changed(bebob);
1012 spin_unlock_irq(&bebob->lock);