1 // SPDX-License-Identifier: GPL-2.0-only
3 * bebob_stream.c - a part of driver for BeBoB based devices
5 * Copyright (c) 2013-2014 Takashi Sakamoto
10 #define CALLBACK_TIMEOUT 2000
11 #define FW_ISO_RESOURCE_DELAY 1000
15 * For BeBoB streams, Both of input and output CMP connection are important.
17 * For most devices, each CMP connection starts to transmit/receive a
18 * corresponding stream. But for a few devices, both of CMP connection needs
19 * to start transmitting stream. An example is 'M-Audio Firewire 410'.
22 /* 128 is an arbitrary length but it seems to be enough */
23 #define FORMAT_MAXIMUM_LENGTH 128
25 const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES] = {
36 * See: Table 51: Extended Stream Format Info ‘Sampling Frequency’
37 * in Additional AVC commands (Nov 2003, BridgeCo)
39 static const unsigned int bridgeco_freq_table[] = {
50 get_formation_index(unsigned int rate, unsigned int *index)
54 for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {
55 if (snd_bebob_rate_table[i] == rate) {
64 snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *curr_rate)
66 unsigned int tx_rate, rx_rate, trials;
71 err = avc_general_get_sig_fmt(bebob->unit, &tx_rate,
72 AVC_GENERAL_PLUG_DIR_OUT, 0);
73 } while (err == -EAGAIN && ++trials < 3);
79 err = avc_general_get_sig_fmt(bebob->unit, &rx_rate,
80 AVC_GENERAL_PLUG_DIR_IN, 0);
81 } while (err == -EAGAIN && ++trials < 3);
86 if (rx_rate == tx_rate)
89 /* synchronize receive stream rate to transmit stream rate */
90 err = avc_general_set_sig_fmt(bebob->unit, rx_rate,
91 AVC_GENERAL_PLUG_DIR_IN, 0);
97 snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate)
101 err = avc_general_set_sig_fmt(bebob->unit, rate,
102 AVC_GENERAL_PLUG_DIR_OUT, 0);
106 err = avc_general_set_sig_fmt(bebob->unit, rate,
107 AVC_GENERAL_PLUG_DIR_IN, 0);
112 * Some devices need a bit time for transition.
113 * 300msec is got by some experiments.
120 int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
121 enum snd_bebob_clock_type *src)
123 const struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
124 u8 addr[AVC_BRIDGECO_ADDR_BYTES], input[7];
126 enum avc_bridgeco_plug_type type;
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);
138 if (id >= clk_spec->num) {
139 dev_err(&bebob->unit->device,
140 "clock source %d out of range 0..%d\n",
141 id, clk_spec->num - 1);
146 *src = clk_spec->types[id];
151 * 2.The device don't support to switch source of clock then assumed
152 * to use internal clock always
154 if (bebob->sync_input_plug < 0) {
155 *src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
160 * 3.The device supports to switch source of clock by an usual way.
161 * Let's check input for 'Music Sub Unit Sync Input' plug.
163 avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
164 bebob->sync_input_plug);
165 err = avc_bridgeco_get_plug_input(bebob->unit, addr, input);
167 dev_err(&bebob->unit->device,
168 "fail to get an input for MSU in plug %d: %d\n",
169 bebob->sync_input_plug, err);
174 * If there are no input plugs, all of fields are 0xff.
175 * Here check the first field. This field is used for direction.
177 if (input[0] == 0xff) {
178 *src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
182 /* The source from any output plugs is for one purpose only. */
183 if (input[0] == AVC_BRIDGECO_PLUG_DIR_OUT) {
185 * In BeBoB architecture, the source from music subunit may
186 * bypass from oPCR[0]. This means that this source gives
187 * synchronization to IEEE 1394 cycle start packet.
189 if (input[1] == AVC_BRIDGECO_PLUG_MODE_SUBUNIT &&
191 *src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
194 /* The source from any input units is for several purposes. */
195 } else if (input[1] == AVC_BRIDGECO_PLUG_MODE_UNIT) {
196 if (input[2] == AVC_BRIDGECO_PLUG_UNIT_ISOC) {
197 if (input[3] == 0x00) {
199 * This source comes from iPCR[0]. This means
200 * that presentation timestamp calculated by
201 * SYT series of the received packets. In
202 * short, this driver is the master of
205 *src = SND_BEBOB_CLOCK_TYPE_SYT;
209 * This source comes from iPCR[1-29]. This
210 * means that the synchronization stream is not
211 * the Audio/MIDI compound stream.
213 *src = SND_BEBOB_CLOCK_TYPE_EXTERNAL;
216 } else if (input[2] == AVC_BRIDGECO_PLUG_UNIT_EXT) {
217 /* Check type of this plug. */
218 avc_bridgeco_fill_unit_addr(addr,
219 AVC_BRIDGECO_PLUG_DIR_IN,
220 AVC_BRIDGECO_PLUG_UNIT_EXT,
222 err = avc_bridgeco_get_plug_type(bebob->unit, addr,
227 if (type == AVC_BRIDGECO_PLUG_TYPE_DIG) {
229 * SPDIF/ADAT or sometimes (not always) word
232 *src = SND_BEBOB_CLOCK_TYPE_EXTERNAL;
234 } else if (type == AVC_BRIDGECO_PLUG_TYPE_SYNC) {
235 /* Often word clock. */
236 *src = SND_BEBOB_CLOCK_TYPE_EXTERNAL;
238 } else if (type == AVC_BRIDGECO_PLUG_TYPE_ADDITION) {
241 * Mostly, additional internal clock.
243 *src = SND_BEBOB_CLOCK_TYPE_INTERNAL;
255 static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
257 unsigned int sec, sections, ch, channels;
258 unsigned int pcm, midi, location;
259 unsigned int stm_pos, sec_loc, pos;
260 u8 *buf, addr[AVC_BRIDGECO_ADDR_BYTES], type;
261 enum avc_bridgeco_plug_dir dir;
265 * The length of return value of this command cannot be expected. Here
266 * use the maximum length of FCP.
268 buf = kzalloc(256, GFP_KERNEL);
272 if (s == &bebob->tx_stream)
273 dir = AVC_BRIDGECO_PLUG_DIR_OUT;
275 dir = AVC_BRIDGECO_PLUG_DIR_IN;
277 avc_bridgeco_fill_unit_addr(addr, dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
278 err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, 256);
280 dev_err(&bebob->unit->device,
281 "fail to get channel position for isoc %s plug 0: %d\n",
282 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" : "out",
288 /* positions in I/O buffer */
292 /* the number of sections in AMDTP packet */
293 sections = buf[pos++];
295 for (sec = 0; sec < sections; sec++) {
296 /* type of this section */
297 avc_bridgeco_fill_unit_addr(addr, dir,
298 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
299 err = avc_bridgeco_get_plug_section_type(bebob->unit, addr,
302 dev_err(&bebob->unit->device,
303 "fail to get section type for isoc %s plug 0: %d\n",
304 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :
315 /* the number of channels in this section */
316 channels = buf[pos++];
318 for (ch = 0; ch < channels; ch++) {
319 /* position of this channel in AMDTP packet */
320 stm_pos = buf[pos++] - 1;
321 /* location of this channel in this section */
322 sec_loc = buf[pos++] - 1;
325 * Basically the number of location is within the
326 * number of channels in this section. But some models
327 * of M-Audio don't follow this. Its location for MIDI
328 * is the position of MIDI channels in AMDTP packet.
330 if (sec_loc >= channels)
334 /* for MIDI conformant data channel */
336 /* AMDTP_MAX_CHANNELS_FOR_MIDI is 1. */
337 if ((midi > 0) && (stm_pos != midi)) {
341 amdtp_am824_set_midi_position(s, stm_pos);
344 /* for PCM data channel */
345 case 0x01: /* Headphone */
346 case 0x02: /* Microphone */
347 case 0x03: /* Line */
348 case 0x04: /* SPDIF */
349 case 0x05: /* ADAT */
350 case 0x06: /* TDIF */
351 case 0x07: /* MADI */
352 /* for undefined/changeable signal */
353 case 0x08: /* Analog */
354 case 0x09: /* Digital */
356 location = pcm + sec_loc;
357 if (location >= AM824_MAX_CHANNELS_FOR_PCM) {
361 amdtp_am824_set_pcm_position(s, location,
378 check_connection_used_by_others(struct snd_bebob *bebob, struct amdtp_stream *s)
380 struct cmp_connection *conn;
384 if (s == &bebob->tx_stream)
385 conn = &bebob->out_conn;
387 conn = &bebob->in_conn;
389 err = cmp_connection_check_used(conn, &used);
390 if ((err >= 0) && used && !amdtp_stream_running(s)) {
391 dev_err(&bebob->unit->device,
392 "Connection established by others: %cPCR[%d]\n",
393 (conn->direction == CMP_OUTPUT) ? 'o' : 'i',
401 static int make_both_connections(struct snd_bebob *bebob)
405 err = cmp_connection_establish(&bebob->out_conn);
409 err = cmp_connection_establish(&bebob->in_conn);
411 cmp_connection_break(&bebob->out_conn);
419 break_both_connections(struct snd_bebob *bebob)
421 cmp_connection_break(&bebob->in_conn);
422 cmp_connection_break(&bebob->out_conn);
424 /* These models seems to be in transition state for a longer time. */
425 if (bebob->maudio_special_quirk != NULL)
430 start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
432 struct cmp_connection *conn;
435 if (stream == &bebob->rx_stream)
436 conn = &bebob->in_conn;
438 conn = &bebob->out_conn;
440 /* channel mapping */
441 if (bebob->maudio_special_quirk == NULL) {
442 err = map_data_channels(bebob, stream);
447 /* start amdtp stream */
448 err = amdtp_stream_start(stream,
449 conn->resources.channel,
455 static int init_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
457 enum amdtp_stream_direction dir_stream;
458 struct cmp_connection *conn;
459 enum cmp_direction dir_conn;
462 if (stream == &bebob->tx_stream) {
463 dir_stream = AMDTP_IN_STREAM;
464 conn = &bebob->out_conn;
465 dir_conn = CMP_OUTPUT;
467 dir_stream = AMDTP_OUT_STREAM;
468 conn = &bebob->in_conn;
469 dir_conn = CMP_INPUT;
472 err = cmp_connection_init(conn, bebob->unit, dir_conn, 0);
476 err = amdtp_am824_init(stream, bebob->unit, dir_stream, CIP_BLOCKING);
478 cmp_connection_destroy(conn);
482 if (stream == &bebob->tx_stream) {
483 // BeBoB v3 transfers packets with these qurks:
484 // - In the beginning of streaming, the value of dbc is
485 // incremented even if no data blocks are transferred.
486 // - The value of dbc is reset suddenly.
487 if (bebob->version > 2)
488 bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC |
489 CIP_SKIP_DBC_ZERO_CHECK;
491 // At high sampling rate, M-Audio special firmware transmits
492 // empty packet with the value of dbc incremented by 8 but the
493 // others are valid to IEC 61883-1.
494 if (bebob->maudio_special_quirk)
495 bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC;
501 static void destroy_stream(struct snd_bebob *bebob, struct amdtp_stream *stream)
503 amdtp_stream_destroy(stream);
505 if (stream == &bebob->tx_stream)
506 cmp_connection_destroy(&bebob->out_conn);
508 cmp_connection_destroy(&bebob->in_conn);
511 int snd_bebob_stream_init_duplex(struct snd_bebob *bebob)
515 err = init_stream(bebob, &bebob->tx_stream);
519 err = init_stream(bebob, &bebob->rx_stream);
521 destroy_stream(bebob, &bebob->tx_stream);
528 static int keep_resources(struct snd_bebob *bebob, struct amdtp_stream *stream,
529 unsigned int rate, unsigned int index)
531 struct snd_bebob_stream_formation *formation;
532 struct cmp_connection *conn;
535 if (stream == &bebob->tx_stream) {
536 formation = bebob->tx_stream_formations + index;
537 conn = &bebob->out_conn;
539 formation = bebob->rx_stream_formations + index;
540 conn = &bebob->in_conn;
543 err = amdtp_am824_set_parameters(stream, rate, formation->pcm,
544 formation->midi, false);
548 return cmp_connection_reserve(conn, amdtp_stream_get_max_payload(stream));
551 int snd_bebob_stream_reserve_duplex(struct snd_bebob *bebob, unsigned int rate)
553 unsigned int curr_rate;
556 // Considering JACK/FFADO streaming:
557 // TODO: This can be removed hwdep functionality becomes popular.
558 err = check_connection_used_by_others(bebob, &bebob->rx_stream);
562 err = bebob->spec->rate->get(bebob, &curr_rate);
567 if (curr_rate != rate) {
568 amdtp_stream_stop(&bebob->tx_stream);
569 amdtp_stream_stop(&bebob->rx_stream);
571 break_both_connections(bebob);
573 cmp_connection_release(&bebob->out_conn);
574 cmp_connection_release(&bebob->in_conn);
577 if (bebob->substreams_counter == 0 || curr_rate != rate) {
581 // If establishing connections at first, Yamaha GO46
582 // (and maybe Terratec X24) don't generate sound.
584 // For firmware customized by M-Audio, refer to next NOTE.
585 err = bebob->spec->rate->set(bebob, rate);
587 dev_err(&bebob->unit->device,
588 "fail to set sampling rate: %d\n",
593 err = get_formation_index(rate, &index);
597 err = keep_resources(bebob, &bebob->tx_stream, rate, index);
601 err = keep_resources(bebob, &bebob->rx_stream, rate, index);
603 cmp_connection_release(&bebob->out_conn);
611 int snd_bebob_stream_start_duplex(struct snd_bebob *bebob)
615 // Need no substreams.
616 if (bebob->substreams_counter == 0)
619 // packet queueing error or detecting discontinuity
620 if (amdtp_streaming_error(&bebob->rx_stream) ||
621 amdtp_streaming_error(&bebob->tx_stream)) {
622 amdtp_stream_stop(&bebob->rx_stream);
623 amdtp_stream_stop(&bebob->tx_stream);
625 break_both_connections(bebob);
628 if (!amdtp_stream_running(&bebob->rx_stream)) {
629 unsigned int curr_rate;
631 if (bebob->maudio_special_quirk) {
632 err = bebob->spec->rate->get(bebob, &curr_rate);
637 err = make_both_connections(bebob);
641 err = start_stream(bebob, &bebob->rx_stream);
643 dev_err(&bebob->unit->device,
644 "fail to run AMDTP master stream:%d\n", err);
649 // The firmware customized by M-Audio uses these commands to
650 // start transmitting stream. This is not usual way.
651 if (bebob->maudio_special_quirk) {
652 err = bebob->spec->rate->set(bebob, curr_rate);
654 dev_err(&bebob->unit->device,
655 "fail to ensure sampling rate: %d\n",
661 if (!amdtp_stream_wait_callback(&bebob->rx_stream,
668 if (!amdtp_stream_running(&bebob->tx_stream)) {
669 err = start_stream(bebob, &bebob->tx_stream);
671 dev_err(&bebob->unit->device,
672 "fail to run AMDTP slave stream:%d\n", err);
676 if (!amdtp_stream_wait_callback(&bebob->tx_stream,
685 amdtp_stream_stop(&bebob->tx_stream);
686 amdtp_stream_stop(&bebob->rx_stream);
687 break_both_connections(bebob);
691 void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)
693 if (bebob->substreams_counter == 0) {
694 amdtp_stream_stop(&bebob->rx_stream);
695 amdtp_stream_stop(&bebob->tx_stream);
697 break_both_connections(bebob);
699 cmp_connection_release(&bebob->out_conn);
700 cmp_connection_release(&bebob->in_conn);
705 * This function should be called before starting streams or after stopping
708 void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob)
710 destroy_stream(bebob, &bebob->tx_stream);
711 destroy_stream(bebob, &bebob->rx_stream);
715 * See: Table 50: Extended Stream Format Info Format Hierarchy Level 2’
716 * in Additional AVC commands (Nov 2003, BridgeCo)
717 * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
720 parse_stream_formation(u8 *buf, unsigned int len,
721 struct snd_bebob_stream_formation *formation)
723 unsigned int i, e, channels, format;
726 * this module can support a hierarchy combination that:
727 * Root: Audio and Music (0x90)
728 * Level 1: AM824 Compound (0x40)
730 if ((buf[0] != 0x90) || (buf[1] != 0x40))
733 /* check sampling rate */
734 for (i = 0; i < ARRAY_SIZE(bridgeco_freq_table); i++) {
735 if (buf[2] == bridgeco_freq_table[i])
738 if (i == ARRAY_SIZE(bridgeco_freq_table))
741 /* Avoid double count by different entries for the same rate. */
742 memset(&formation[i], 0, sizeof(struct snd_bebob_stream_formation));
744 for (e = 0; e < buf[4]; e++) {
745 channels = buf[5 + e * 2];
746 format = buf[6 + e * 2];
749 /* IEC 60958 Conformant, currently handled as MBLA */
751 /* Multi bit linear audio */
753 formation[i].pcm += channels;
755 /* MIDI Conformant */
757 formation[i].midi += channels;
759 /* IEC 61937-3 to 7 */
765 /* Multi bit linear audio */
766 case 0x07: /* DVD-Audio */
767 case 0x0c: /* High Precision */
769 case 0x08: /* (Plain) Raw */
770 case 0x09: /* (Plain) SACD */
771 case 0x0a: /* (Encoded) Raw */
772 case 0x0b: /* (Encoded) SACD */
773 /* Synchronization Stream (Stereo Raw audio) */
778 return -ENOSYS; /* not supported */
782 if (formation[i].pcm > AM824_MAX_CHANNELS_FOR_PCM ||
783 formation[i].midi > AM824_MAX_CHANNELS_FOR_MIDI)
790 fill_stream_formations(struct snd_bebob *bebob, enum avc_bridgeco_plug_dir dir,
794 struct snd_bebob_stream_formation *formations;
795 unsigned int len, eid;
796 u8 addr[AVC_BRIDGECO_ADDR_BYTES];
799 buf = kmalloc(FORMAT_MAXIMUM_LENGTH, GFP_KERNEL);
803 if (dir == AVC_BRIDGECO_PLUG_DIR_IN)
804 formations = bebob->rx_stream_formations;
806 formations = bebob->tx_stream_formations;
808 for (eid = 0; eid < SND_BEBOB_STRM_FMT_ENTRIES; eid++) {
809 len = FORMAT_MAXIMUM_LENGTH;
810 avc_bridgeco_fill_unit_addr(addr, dir,
811 AVC_BRIDGECO_PLUG_UNIT_ISOC, pid);
812 err = avc_bridgeco_get_plug_strm_fmt(bebob->unit, addr, buf,
814 /* No entries remained. */
815 if (err == -EINVAL && eid > 0) {
818 } else if (err < 0) {
819 dev_err(&bebob->unit->device,
820 "fail to get stream format %d for isoc %s plug %d:%d\n",
822 (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :
828 err = parse_stream_formation(buf, len, formations);
838 seek_msu_sync_input_plug(struct snd_bebob *bebob)
840 u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
842 enum avc_bridgeco_plug_type type;
845 /* Get the number of Music Sub Unit for both direction. */
846 err = avc_general_get_plug_info(bebob->unit, 0x0c, 0x00, 0x00, plugs);
848 dev_err(&bebob->unit->device,
849 "fail to get info for MSU in/out plugs: %d\n",
854 /* seek destination plugs for 'MSU sync input' */
855 bebob->sync_input_plug = -1;
856 for (i = 0; i < plugs[0]; i++) {
857 avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN, i);
858 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
860 dev_err(&bebob->unit->device,
861 "fail to get type for MSU in plug %d: %d\n",
866 if (type == AVC_BRIDGECO_PLUG_TYPE_SYNC) {
867 bebob->sync_input_plug = i;
875 int snd_bebob_stream_discover(struct snd_bebob *bebob)
877 const struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;
878 u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];
879 enum avc_bridgeco_plug_type type;
883 /* the number of plugs for isoc in/out, ext in/out */
884 err = avc_general_get_plug_info(bebob->unit, 0x1f, 0x07, 0x00, plugs);
886 dev_err(&bebob->unit->device,
887 "fail to get info for isoc/external in/out plugs: %d\n",
893 * This module supports at least one isoc input plug and one isoc
896 if ((plugs[0] == 0) || (plugs[1] == 0)) {
901 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
902 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
903 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
905 dev_err(&bebob->unit->device,
906 "fail to get type for isoc in plug 0: %d\n", err);
908 } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {
912 err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_IN, 0);
916 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,
917 AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
918 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
920 dev_err(&bebob->unit->device,
921 "fail to get type for isoc out plug 0: %d\n", err);
923 } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {
927 err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_OUT, 0);
931 /* count external input plugs for MIDI */
932 bebob->midi_input_ports = 0;
933 for (i = 0; i < plugs[2]; i++) {
934 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,
935 AVC_BRIDGECO_PLUG_UNIT_EXT, i);
936 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
938 dev_err(&bebob->unit->device,
939 "fail to get type for external in plug %d: %d\n",
942 } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {
943 bebob->midi_input_ports++;
947 /* count external output plugs for MIDI */
948 bebob->midi_output_ports = 0;
949 for (i = 0; i < plugs[3]; i++) {
950 avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,
951 AVC_BRIDGECO_PLUG_UNIT_EXT, i);
952 err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);
954 dev_err(&bebob->unit->device,
955 "fail to get type for external out plug %d: %d\n",
958 } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {
959 bebob->midi_output_ports++;
963 /* for check source of clock later */
965 err = seek_msu_sync_input_plug(bebob);
970 void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)
972 bebob->dev_lock_changed = true;
973 wake_up(&bebob->hwdep_wait);
976 int snd_bebob_stream_lock_try(struct snd_bebob *bebob)
980 spin_lock_irq(&bebob->lock);
982 /* user land lock this */
983 if (bebob->dev_lock_count < 0) {
988 /* this is the first time */
989 if (bebob->dev_lock_count++ == 0)
990 snd_bebob_stream_lock_changed(bebob);
993 spin_unlock_irq(&bebob->lock);
997 void snd_bebob_stream_lock_release(struct snd_bebob *bebob)
999 spin_lock_irq(&bebob->lock);
1001 if (WARN_ON(bebob->dev_lock_count <= 0))
1003 if (--bebob->dev_lock_count == 0)
1004 snd_bebob_stream_lock_changed(bebob);
1006 spin_unlock_irq(&bebob->lock);