1da607e19SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2df6a8866STakashi Sakamoto /*
3df6a8866STakashi Sakamoto  * bebob_yamaha.c - a part of driver for BeBoB based devices
4df6a8866STakashi Sakamoto  *
5df6a8866STakashi Sakamoto  * Copyright (c) 2013-2014 Takashi Sakamoto
6df6a8866STakashi Sakamoto  */
7df6a8866STakashi Sakamoto 
8df6a8866STakashi Sakamoto #include "./bebob.h"
9df6a8866STakashi Sakamoto 
10df6a8866STakashi Sakamoto /*
11df6a8866STakashi Sakamoto  * NOTE:
12df6a8866STakashi Sakamoto  * Yamaha GO44 is not designed to be used as stand-alone mixer. So any streams
13df6a8866STakashi Sakamoto  * must be accompanied. If changing the state, a LED on the device starts to
14df6a8866STakashi Sakamoto  * blink and its sync status is false. In this state, the device sounds nothing
15df6a8866STakashi Sakamoto  * even if streaming. To start streaming at the current sampling rate is only
16df6a8866STakashi Sakamoto  * way to recover this state. GO46 is better for stand-alone mixer.
17df6a8866STakashi Sakamoto  *
18df6a8866STakashi Sakamoto  * Both of them have a capability to change its sampling rate up to 192.0kHz.
19df6a8866STakashi Sakamoto  * At 192.0kHz, the device reports 4 PCM-in, 1 MIDI-in, 6 PCM-out, 1 MIDI-out.
20df6a8866STakashi Sakamoto  * But Yamaha's driver reduce 2 PCM-in, 1 MIDI-in, 2 PCM-out, 1 MIDI-out to use
21df6a8866STakashi Sakamoto  * 'Extended Stream Format Information Command - Single Request' in 'Additional
22df6a8866STakashi Sakamoto  * AVC commands' defined by BridgeCo.
23df6a8866STakashi Sakamoto  * This ALSA driver don't do this because a bit tiresome. Then isochronous
24df6a8866STakashi Sakamoto  * streaming with many asynchronous transactions brings sounds with noises.
25df6a8866STakashi Sakamoto  * Unfortunately current 'ffado-mixer' generated many asynchronous transaction
26df6a8866STakashi Sakamoto  * to observe device's state, mainly check cmp connection and signal format. I
27df6a8866STakashi Sakamoto  * recommend users to close ffado-mixer at 192.0kHz if mixer is needless.
28e15c282eSTakashi Sakamoto  *
29e15c282eSTakashi Sakamoto  * Terratec PHASE 24 FW and PHASE X24 FW are internally the same as
30e15c282eSTakashi Sakamoto  * Yamaha GO 44 and GO 46. Yamaha and Terratec had cooperated for these models.
31df6a8866STakashi Sakamoto  */
32df6a8866STakashi Sakamoto 
33782fbec7STakashi Sakamoto static const enum snd_bebob_clock_type clk_src_types[] = {
34df6a8866STakashi Sakamoto 	SND_BEBOB_CLOCK_TYPE_INTERNAL,
35df6a8866STakashi Sakamoto 	SND_BEBOB_CLOCK_TYPE_EXTERNAL,	/* S/PDIF */
36df6a8866STakashi Sakamoto };
37df6a8866STakashi Sakamoto static int
clk_src_get(struct snd_bebob * bebob,unsigned int * id)38df6a8866STakashi Sakamoto clk_src_get(struct snd_bebob *bebob, unsigned int *id)
39df6a8866STakashi Sakamoto {
40df6a8866STakashi Sakamoto 	int err;
41df6a8866STakashi Sakamoto 
42df6a8866STakashi Sakamoto 	err = avc_audio_get_selector(bebob->unit, 0, 4, id);
43df6a8866STakashi Sakamoto 	if (err < 0)
44df6a8866STakashi Sakamoto 		return err;
45df6a8866STakashi Sakamoto 
46df6a8866STakashi Sakamoto 	if (*id >= ARRAY_SIZE(clk_src_types))
47df6a8866STakashi Sakamoto 		return -EIO;
48df6a8866STakashi Sakamoto 
49df6a8866STakashi Sakamoto 	return 0;
50df6a8866STakashi Sakamoto }
51df6a8866STakashi Sakamoto static const struct snd_bebob_clock_spec clock_spec = {
52df6a8866STakashi Sakamoto 	.num	= ARRAY_SIZE(clk_src_types),
53df6a8866STakashi Sakamoto 	.types	= clk_src_types,
54df6a8866STakashi Sakamoto 	.get	= &clk_src_get,
55df6a8866STakashi Sakamoto };
56df6a8866STakashi Sakamoto static const struct snd_bebob_rate_spec rate_spec = {
57df6a8866STakashi Sakamoto 	.get	= &snd_bebob_stream_get_rate,
58df6a8866STakashi Sakamoto 	.set	= &snd_bebob_stream_set_rate,
59df6a8866STakashi Sakamoto };
60e15c282eSTakashi Sakamoto const struct snd_bebob_spec yamaha_terratec_spec = {
61df6a8866STakashi Sakamoto 	.clock	= &clock_spec,
62df6a8866STakashi Sakamoto 	.rate	= &rate_spec,
63df6a8866STakashi Sakamoto 	.meter	= NULL
64df6a8866STakashi Sakamoto };
65