blob: 1d154284873e36f9e99b6e84bbd2aaa2b4f4d7bc [file] [log] [blame]
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +09001/*
2 * oxfw_stream.c - a part of driver for OXFW970/971 based devices
3 *
4 * Copyright (c) 2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "oxfw.h"
Takashi Sakamotof3699e22014-12-09 00:10:44 +090010#include <linux/delay.h>
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +090011
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090012#define AVC_GENERIC_FRAME_MAXIMUM_BYTES 512
Takashi Sakamotof3699e22014-12-09 00:10:44 +090013#define CALLBACK_TIMEOUT 200
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +090014
15/*
16 * According to datasheet of Oxford Semiconductor:
17 * OXFW970: 32.0/44.1/48.0/96.0 Khz, 8 audio channels I/O
18 * OXFW971: 32.0/44.1/48.0/88.2/96.0/192.0 kHz, 16 audio channels I/O, MIDI I/O
19 */
20static const unsigned int oxfw_rate_table[] = {
21 [0] = 32000,
22 [1] = 44100,
23 [2] = 48000,
24 [3] = 88200,
25 [4] = 96000,
26 [5] = 192000,
27};
28
29/*
30 * See Table 5.7 – Sampling frequency for Multi-bit Audio
31 * in AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
32 */
33static const unsigned int avc_stream_rate_table[] = {
34 [0] = 0x02,
35 [1] = 0x03,
36 [2] = 0x04,
37 [3] = 0x0a,
38 [4] = 0x05,
39 [5] = 0x07,
40};
41
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090042static int set_rate(struct snd_oxfw *oxfw, unsigned int rate)
43{
44 int err;
45
46 err = avc_general_set_sig_fmt(oxfw->unit, rate,
47 AVC_GENERAL_PLUG_DIR_IN, 0);
48 if (err < 0)
49 goto end;
50
51 if (oxfw->has_output)
52 err = avc_general_set_sig_fmt(oxfw->unit, rate,
53 AVC_GENERAL_PLUG_DIR_OUT, 0);
54end:
55 return err;
56}
57
Takashi Sakamotof3699e22014-12-09 00:10:44 +090058static int set_stream_format(struct snd_oxfw *oxfw, struct amdtp_stream *s,
59 unsigned int rate, unsigned int pcm_channels)
60{
61 u8 **formats;
62 struct snd_oxfw_stream_formation formation;
63 enum avc_general_plug_dir dir;
64 unsigned int i, err, len;
65
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090066 if (s == &oxfw->tx_stream) {
67 formats = oxfw->tx_stream_formats;
68 dir = AVC_GENERAL_PLUG_DIR_OUT;
69 } else {
70 formats = oxfw->rx_stream_formats;
71 dir = AVC_GENERAL_PLUG_DIR_IN;
72 }
Takashi Sakamotof3699e22014-12-09 00:10:44 +090073
74 /* Seek stream format for requirements. */
75 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
76 err = snd_oxfw_stream_parse_format(formats[i], &formation);
77 if (err < 0)
78 return err;
79
80 if ((formation.rate == rate) && (formation.pcm == pcm_channels))
81 break;
82 }
83 if (i == SND_OXFW_STREAM_FORMAT_ENTRIES)
84 return -EINVAL;
85
86 /* If assumed, just change rate. */
87 if (oxfw->assumed)
Takashi Sakamotob0ac0002014-12-09 00:10:46 +090088 return set_rate(oxfw, rate);
Takashi Sakamotof3699e22014-12-09 00:10:44 +090089
90 /* Calculate format length. */
91 len = 5 + formats[i][4] * 2;
92
93 err = avc_stream_set_format(oxfw->unit, dir, 0, formats[i], len);
94 if (err < 0)
95 return err;
96
97 /* Some requests just after changing format causes freezing. */
98 msleep(100);
99
100 return 0;
101}
102
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900103static void stop_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900104{
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900105 amdtp_stream_pcm_abort(stream);
106 amdtp_stream_stop(stream);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900107
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900108 if (stream == &oxfw->tx_stream)
109 cmp_connection_break(&oxfw->out_conn);
110 else
111 cmp_connection_break(&oxfw->in_conn);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900112}
113
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900114static int start_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream,
115 unsigned int rate, unsigned int pcm_channels)
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900116{
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900117 u8 **formats;
118 struct cmp_connection *conn;
119 struct snd_oxfw_stream_formation formation;
120 unsigned int i, midi_ports;
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900121 int err;
122
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900123 if (stream == &oxfw->rx_stream) {
124 formats = oxfw->rx_stream_formats;
125 conn = &oxfw->in_conn;
126 } else {
127 formats = oxfw->tx_stream_formats;
128 conn = &oxfw->out_conn;
129 }
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900130
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900131 /* Get stream format */
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900132 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
133 if (formats[i] == NULL)
134 break;
135
136 err = snd_oxfw_stream_parse_format(formats[i], &formation);
137 if (err < 0)
138 goto end;
139 if (rate != formation.rate)
140 continue;
141 if (pcm_channels == 0 || pcm_channels == formation.pcm)
142 break;
143 }
144 if (i == SND_OXFW_STREAM_FORMAT_ENTRIES) {
145 err = -EINVAL;
146 goto end;
147 }
148
149 pcm_channels = formation.pcm;
150 midi_ports = DIV_ROUND_UP(formation.midi, 8);
151
152 /* The stream should have one pcm channels at least */
153 if (pcm_channels == 0) {
154 err = -EINVAL;
155 goto end;
156 }
157 amdtp_stream_set_parameters(stream, rate, pcm_channels, midi_ports);
158
159 err = cmp_connection_establish(conn,
160 amdtp_stream_get_max_payload(stream));
161 if (err < 0)
162 goto end;
163
164 err = amdtp_stream_start(stream,
165 conn->resources.channel,
166 conn->speed);
167 if (err < 0) {
168 cmp_connection_break(conn);
169 goto end;
170 }
171
172 /* Wait first packet */
173 err = amdtp_stream_wait_callback(stream, CALLBACK_TIMEOUT);
174 if (err < 0)
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900175 stop_stream(oxfw, stream);
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900176end:
177 return err;
178}
179
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900180static int check_connection_used_by_others(struct snd_oxfw *oxfw,
181 struct amdtp_stream *stream)
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900182{
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900183 struct cmp_connection *conn;
184 bool used;
185 int err;
186
187 if (stream == &oxfw->tx_stream)
188 conn = &oxfw->out_conn;
189 else
190 conn = &oxfw->in_conn;
191
192 err = cmp_connection_check_used(conn, &used);
193 if ((err >= 0) && used && !amdtp_stream_running(stream)) {
194 dev_err(&oxfw->unit->device,
195 "Connection established by others: %cPCR[%d]\n",
196 (conn->direction == CMP_OUTPUT) ? 'o' : 'i',
197 conn->pcr_index);
198 err = -EBUSY;
199 }
200
201 return err;
202}
203
204int snd_oxfw_stream_init_simplex(struct snd_oxfw *oxfw,
205 struct amdtp_stream *stream)
206{
207 struct cmp_connection *conn;
208 enum cmp_direction c_dir;
209 enum amdtp_stream_direction s_dir;
210 int err;
211
212 if (stream == &oxfw->tx_stream) {
213 conn = &oxfw->out_conn;
214 c_dir = CMP_OUTPUT;
215 s_dir = AMDTP_IN_STREAM;
216 } else {
217 conn = &oxfw->in_conn;
218 c_dir = CMP_INPUT;
219 s_dir = AMDTP_OUT_STREAM;
220 }
221
222 err = cmp_connection_init(conn, oxfw->unit, c_dir, 0);
223 if (err < 0)
224 goto end;
225
226 err = amdtp_stream_init(stream, oxfw->unit, s_dir, CIP_NONBLOCKING);
227 if (err < 0) {
228 amdtp_stream_destroy(stream);
229 cmp_connection_destroy(conn);
230 goto end;
231 }
232
233 /* OXFW starts to transmit packets with non-zero dbc. */
234 if (stream == &oxfw->tx_stream)
235 oxfw->tx_stream.flags |= CIP_SKIP_INIT_DBC_CHECK;
236end:
237 return err;
238}
239
240int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,
241 struct amdtp_stream *stream,
242 unsigned int rate, unsigned int pcm_channels)
243{
244 struct amdtp_stream *opposite;
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900245 struct snd_oxfw_stream_formation formation;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900246 enum avc_general_plug_dir dir;
247 unsigned int substreams, opposite_substreams;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900248 int err = 0;
249
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900250 if (stream == &oxfw->tx_stream) {
251 substreams = oxfw->capture_substreams;
252 opposite = &oxfw->rx_stream;
253 opposite_substreams = oxfw->playback_substreams;
254 dir = AVC_GENERAL_PLUG_DIR_OUT;
255 } else {
256 substreams = oxfw->playback_substreams;
257 opposite_substreams = oxfw->capture_substreams;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900258
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900259 if (oxfw->has_output)
260 opposite = &oxfw->rx_stream;
261 else
262 opposite = NULL;
263
264 dir = AVC_GENERAL_PLUG_DIR_IN;
265 }
266
267 if (substreams == 0)
268 goto end;
269
270 /*
271 * Considering JACK/FFADO streaming:
272 * TODO: This can be removed hwdep functionality becomes popular.
273 */
274 err = check_connection_used_by_others(oxfw, stream);
275 if (err < 0)
276 goto end;
277
278 /* packet queueing error */
279 if (amdtp_streaming_error(stream))
280 stop_stream(oxfw, stream);
281
282 err = snd_oxfw_stream_get_current_formation(oxfw, dir, &formation);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900283 if (err < 0)
284 goto end;
285
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900286 if ((formation.rate != rate) || (formation.pcm != pcm_channels)) {
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900287 if (opposite != NULL) {
288 err = check_connection_used_by_others(oxfw, opposite);
289 if (err < 0)
290 goto end;
291 stop_stream(oxfw, opposite);
292 }
293 stop_stream(oxfw, stream);
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900294
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900295 err = set_stream_format(oxfw, stream, rate, pcm_channels);
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900296 if (err < 0) {
297 dev_err(&oxfw->unit->device,
298 "fail to set stream format: %d\n", err);
299 goto end;
300 }
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900301
302 /* Start opposite stream if needed. */
303 if (opposite && !amdtp_stream_running(opposite) &&
304 (opposite_substreams > 0)) {
305 err = start_stream(oxfw, opposite, rate, 0);
306 if (err < 0) {
307 dev_err(&oxfw->unit->device,
308 "fail to restart stream: %d\n", err);
309 goto end;
310 }
311 }
Takashi Sakamotof3699e22014-12-09 00:10:44 +0900312 }
313
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900314 /* Start requested stream. */
315 if (!amdtp_stream_running(stream)) {
316 err = start_stream(oxfw, stream, rate, pcm_channels);
317 if (err < 0)
318 dev_err(&oxfw->unit->device,
319 "fail to start stream: %d\n", err);
320 }
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900321end:
322 return err;
323}
324
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900325void snd_oxfw_stream_stop_simplex(struct snd_oxfw *oxfw,
326 struct amdtp_stream *stream)
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900327{
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900328 if (((stream == &oxfw->tx_stream) && (oxfw->capture_substreams > 0)) ||
329 ((stream == &oxfw->rx_stream) && (oxfw->playback_substreams > 0)))
330 return;
331
332 stop_stream(oxfw, stream);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900333}
334
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900335void snd_oxfw_stream_destroy_simplex(struct snd_oxfw *oxfw,
336 struct amdtp_stream *stream)
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900337{
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900338 struct cmp_connection *conn;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900339
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900340 if (stream == &oxfw->tx_stream)
341 conn = &oxfw->out_conn;
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900342 else
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900343 conn = &oxfw->in_conn;
344
345 stop_stream(oxfw, stream);
346
347 amdtp_stream_destroy(stream);
348 cmp_connection_destroy(conn);
349}
350
351void snd_oxfw_stream_update_simplex(struct snd_oxfw *oxfw,
352 struct amdtp_stream *stream)
353{
354 struct cmp_connection *conn;
355
356 if (stream == &oxfw->tx_stream)
357 conn = &oxfw->out_conn;
358 else
359 conn = &oxfw->in_conn;
360
361 if (cmp_connection_update(conn) < 0)
362 stop_stream(oxfw, stream);
363 else
364 amdtp_stream_update(stream);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900365}
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900366
Takashi Sakamoto3c961012014-12-09 00:10:43 +0900367int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
368 enum avc_general_plug_dir dir,
369 struct snd_oxfw_stream_formation *formation)
370{
371 u8 *format;
372 unsigned int len;
373 int err;
374
375 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
376 format = kmalloc(len, GFP_KERNEL);
377 if (format == NULL)
378 return -ENOMEM;
379
380 err = avc_stream_get_format_single(oxfw->unit, dir, 0, format, &len);
381 if (err < 0)
382 goto end;
383 if (len < 3) {
384 err = -EIO;
385 goto end;
386 }
387
388 err = snd_oxfw_stream_parse_format(format, formation);
389end:
390 kfree(format);
391 return err;
392}
393
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900394/*
395 * See Table 6.16 - AM824 Stream Format
396 * Figure 6.19 - format_information field for AM824 Compound
397 * in AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
398 * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
399 */
400int snd_oxfw_stream_parse_format(u8 *format,
401 struct snd_oxfw_stream_formation *formation)
402{
403 unsigned int i, e, channels, type;
404
405 memset(formation, 0, sizeof(struct snd_oxfw_stream_formation));
406
407 /*
408 * this module can support a hierarchy combination that:
409 * Root: Audio and Music (0x90)
410 * Level 1: AM824 Compound (0x40)
411 */
412 if ((format[0] != 0x90) || (format[1] != 0x40))
413 return -ENOSYS;
414
415 /* check the sampling rate */
416 for (i = 0; i < ARRAY_SIZE(avc_stream_rate_table); i++) {
417 if (format[2] == avc_stream_rate_table[i])
418 break;
419 }
420 if (i == ARRAY_SIZE(avc_stream_rate_table))
421 return -ENOSYS;
422
423 formation->rate = oxfw_rate_table[i];
424
425 for (e = 0; e < format[4]; e++) {
426 channels = format[5 + e * 2];
427 type = format[6 + e * 2];
428
429 switch (type) {
430 /* IEC 60958 Conformant, currently handled as MBLA */
431 case 0x00:
432 /* Multi Bit Linear Audio (Raw) */
433 case 0x06:
434 formation->pcm += channels;
435 break;
436 /* MIDI Conformant */
437 case 0x0d:
438 formation->midi = channels;
439 break;
440 /* IEC 61937-3 to 7 */
441 case 0x01:
442 case 0x02:
443 case 0x03:
444 case 0x04:
445 case 0x05:
446 /* Multi Bit Linear Audio */
447 case 0x07: /* DVD-Audio */
448 case 0x0c: /* High Precision */
449 /* One Bit Audio */
450 case 0x08: /* (Plain) Raw */
451 case 0x09: /* (Plain) SACD */
452 case 0x0a: /* (Encoded) Raw */
453 case 0x0b: /* (Encoded) SACD */
454 /* SMPTE Time-Code conformant */
455 case 0x0e:
456 /* Sample Count */
457 case 0x0f:
458 /* Anciliary Data */
459 case 0x10:
460 /* Synchronization Stream (Stereo Raw audio) */
461 case 0x40:
462 /* Don't care */
463 case 0xff:
464 default:
465 return -ENOSYS; /* not supported */
466 }
467 }
468
469 if (formation->pcm > AMDTP_MAX_CHANNELS_FOR_PCM ||
470 formation->midi > AMDTP_MAX_CHANNELS_FOR_MIDI)
471 return -ENOSYS;
472
473 return 0;
474}
475
476static int
477assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
478 unsigned int pid, u8 *buf, unsigned int *len,
479 u8 **formats)
480{
481 struct snd_oxfw_stream_formation formation;
482 unsigned int i, eid;
483 int err;
484
485 /* get format at current sampling rate */
486 err = avc_stream_get_format_single(oxfw->unit, dir, pid, buf, len);
487 if (err < 0) {
488 dev_err(&oxfw->unit->device,
489 "fail to get current stream format for isoc %s plug %d:%d\n",
490 (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" : "out",
491 pid, err);
492 goto end;
493 }
494
495 /* parse and set stream format */
496 eid = 0;
497 err = snd_oxfw_stream_parse_format(buf, &formation);
498 if (err < 0)
499 goto end;
500
501 formats[eid] = kmalloc(*len, GFP_KERNEL);
502 if (formats[eid] == NULL) {
503 err = -ENOMEM;
504 goto end;
505 }
506 memcpy(formats[eid], buf, *len);
507
508 /* apply the format for each available sampling rate */
509 for (i = 0; i < ARRAY_SIZE(oxfw_rate_table); i++) {
510 if (formation.rate == oxfw_rate_table[i])
511 continue;
512
513 err = avc_general_inquiry_sig_fmt(oxfw->unit,
514 oxfw_rate_table[i],
515 dir, pid);
516 if (err < 0)
517 continue;
518
519 eid++;
520 formats[eid] = kmalloc(*len, GFP_KERNEL);
521 if (formats[eid] == NULL) {
522 err = -ENOMEM;
523 goto end;
524 }
525 memcpy(formats[eid], buf, *len);
526 formats[eid][2] = avc_stream_rate_table[i];
527 }
528
529 err = 0;
530 oxfw->assumed = true;
531end:
532 return err;
533}
534
535static int fill_stream_formats(struct snd_oxfw *oxfw,
536 enum avc_general_plug_dir dir,
537 unsigned short pid)
538{
539 u8 *buf, **formats;
540 unsigned int len, eid = 0;
541 struct snd_oxfw_stream_formation dummy;
542 int err;
543
544 buf = kmalloc(AVC_GENERIC_FRAME_MAXIMUM_BYTES, GFP_KERNEL);
545 if (buf == NULL)
546 return -ENOMEM;
547
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900548 if (dir == AVC_GENERAL_PLUG_DIR_OUT)
549 formats = oxfw->tx_stream_formats;
550 else
551 formats = oxfw->rx_stream_formats;
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900552
553 /* get first entry */
554 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
555 err = avc_stream_get_format_list(oxfw->unit, dir, 0, buf, &len, 0);
556 if (err == -ENOSYS) {
557 /* LIST subfunction is not implemented */
558 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
559 err = assume_stream_formats(oxfw, dir, pid, buf, &len,
560 formats);
561 goto end;
562 } else if (err < 0) {
563 dev_err(&oxfw->unit->device,
564 "fail to get stream format %d for isoc %s plug %d:%d\n",
565 eid, (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" : "out",
566 pid, err);
567 goto end;
568 }
569
570 /* LIST subfunction is implemented */
571 while (eid < SND_OXFW_STREAM_FORMAT_ENTRIES) {
572 /* The format is too short. */
573 if (len < 3) {
574 err = -EIO;
575 break;
576 }
577
578 /* parse and set stream format */
579 err = snd_oxfw_stream_parse_format(buf, &dummy);
580 if (err < 0)
581 break;
582
583 formats[eid] = kmalloc(len, GFP_KERNEL);
584 if (formats[eid] == NULL) {
585 err = -ENOMEM;
586 break;
587 }
588 memcpy(formats[eid], buf, len);
589
590 /* get next entry */
591 len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
592 err = avc_stream_get_format_list(oxfw->unit, dir, 0,
593 buf, &len, ++eid);
594 /* No entries remained. */
595 if (err == -EINVAL) {
596 err = 0;
597 break;
598 } else if (err < 0) {
599 dev_err(&oxfw->unit->device,
600 "fail to get stream format %d for isoc %s plug %d:%d\n",
601 eid, (dir == AVC_GENERAL_PLUG_DIR_IN) ? "in" :
602 "out",
603 pid, err);
604 break;
605 }
606 }
607end:
608 kfree(buf);
609 return err;
610}
611
612int snd_oxfw_stream_discover(struct snd_oxfw *oxfw)
613{
614 u8 plugs[AVC_PLUG_INFO_BUF_BYTES];
615 int err;
616
617 /* the number of plugs for isoc in/out, ext in/out */
618 err = avc_general_get_plug_info(oxfw->unit, 0x1f, 0x07, 0x00, plugs);
619 if (err < 0) {
620 dev_err(&oxfw->unit->device,
621 "fail to get info for isoc/external in/out plugs: %d\n",
622 err);
623 goto end;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900624 } else if ((plugs[0] == 0) && (plugs[1] == 0)) {
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900625 err = -ENOSYS;
626 goto end;
627 }
628
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900629 /* use oPCR[0] if exists */
630 if (plugs[1] > 0) {
631 err = fill_stream_formats(oxfw, AVC_GENERAL_PLUG_DIR_OUT, 0);
632 if (err < 0)
633 goto end;
634 oxfw->has_output = true;
635 }
636
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900637 /* use iPCR[0] if exists */
638 if (plugs[0] > 0)
639 err = fill_stream_formats(oxfw, AVC_GENERAL_PLUG_DIR_IN, 0);
640end:
641 return err;
642}