18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * bebob_yamaha.c - a part of driver for BeBoB based devices
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2013-2014 Takashi Sakamoto
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "./bebob.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * NOTE:
128c2ecf20Sopenharmony_ci * Yamaha GO44 is not designed to be used as stand-alone mixer. So any streams
138c2ecf20Sopenharmony_ci * must be accompanied. If changing the state, a LED on the device starts to
148c2ecf20Sopenharmony_ci * blink and its sync status is false. In this state, the device sounds nothing
158c2ecf20Sopenharmony_ci * even if streaming. To start streaming at the current sampling rate is only
168c2ecf20Sopenharmony_ci * way to recover this state. GO46 is better for stand-alone mixer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * Both of them have a capability to change its sampling rate up to 192.0kHz.
198c2ecf20Sopenharmony_ci * At 192.0kHz, the device reports 4 PCM-in, 1 MIDI-in, 6 PCM-out, 1 MIDI-out.
208c2ecf20Sopenharmony_ci * But Yamaha's driver reduce 2 PCM-in, 1 MIDI-in, 2 PCM-out, 1 MIDI-out to use
218c2ecf20Sopenharmony_ci * 'Extended Stream Format Information Command - Single Request' in 'Additional
228c2ecf20Sopenharmony_ci * AVC commands' defined by BridgeCo.
238c2ecf20Sopenharmony_ci * This ALSA driver don't do this because a bit tiresome. Then isochronous
248c2ecf20Sopenharmony_ci * streaming with many asynchronous transactions brings sounds with noises.
258c2ecf20Sopenharmony_ci * Unfortunately current 'ffado-mixer' generated many asynchronous transaction
268c2ecf20Sopenharmony_ci * to observe device's state, mainly check cmp connection and signal format. I
278c2ecf20Sopenharmony_ci * recommend users to close ffado-mixer at 192.0kHz if mixer is needless.
288c2ecf20Sopenharmony_ci *
298c2ecf20Sopenharmony_ci * Terratec PHASE 24 FW and PHASE X24 FW are internally the same as
308c2ecf20Sopenharmony_ci * Yamaha GO 44 and GO 46. Yamaha and Terratec had cooperated for these models.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistatic const enum snd_bebob_clock_type clk_src_types[] = {
348c2ecf20Sopenharmony_ci	SND_BEBOB_CLOCK_TYPE_INTERNAL,
358c2ecf20Sopenharmony_ci	SND_BEBOB_CLOCK_TYPE_EXTERNAL,	/* S/PDIF */
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_cistatic int
388c2ecf20Sopenharmony_ciclk_src_get(struct snd_bebob *bebob, unsigned int *id)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci	int err;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	err = avc_audio_get_selector(bebob->unit, 0, 4, id);
438c2ecf20Sopenharmony_ci	if (err < 0)
448c2ecf20Sopenharmony_ci		return err;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	if (*id >= ARRAY_SIZE(clk_src_types))
478c2ecf20Sopenharmony_ci		return -EIO;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	return 0;
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_cistatic const struct snd_bebob_clock_spec clock_spec = {
528c2ecf20Sopenharmony_ci	.num	= ARRAY_SIZE(clk_src_types),
538c2ecf20Sopenharmony_ci	.types	= clk_src_types,
548c2ecf20Sopenharmony_ci	.get	= &clk_src_get,
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_cistatic const struct snd_bebob_rate_spec rate_spec = {
578c2ecf20Sopenharmony_ci	.get	= &snd_bebob_stream_get_rate,
588c2ecf20Sopenharmony_ci	.set	= &snd_bebob_stream_set_rate,
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ciconst struct snd_bebob_spec yamaha_terratec_spec = {
618c2ecf20Sopenharmony_ci	.clock	= &clock_spec,
628c2ecf20Sopenharmony_ci	.rate	= &rate_spec,
638c2ecf20Sopenharmony_ci	.meter	= NULL
648c2ecf20Sopenharmony_ci};
65