162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * bebob_yamaha.c - a part of driver for BeBoB based devices
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2013-2014 Takashi Sakamoto
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include "./bebob.h"
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/*
1162306a36Sopenharmony_ci * NOTE:
1262306a36Sopenharmony_ci * Yamaha GO44 is not designed to be used as stand-alone mixer. So any streams
1362306a36Sopenharmony_ci * must be accompanied. If changing the state, a LED on the device starts to
1462306a36Sopenharmony_ci * blink and its sync status is false. In this state, the device sounds nothing
1562306a36Sopenharmony_ci * even if streaming. To start streaming at the current sampling rate is only
1662306a36Sopenharmony_ci * way to recover this state. GO46 is better for stand-alone mixer.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * Both of them have a capability to change its sampling rate up to 192.0kHz.
1962306a36Sopenharmony_ci * At 192.0kHz, the device reports 4 PCM-in, 1 MIDI-in, 6 PCM-out, 1 MIDI-out.
2062306a36Sopenharmony_ci * But Yamaha's driver reduce 2 PCM-in, 1 MIDI-in, 2 PCM-out, 1 MIDI-out to use
2162306a36Sopenharmony_ci * 'Extended Stream Format Information Command - Single Request' in 'Additional
2262306a36Sopenharmony_ci * AVC commands' defined by BridgeCo.
2362306a36Sopenharmony_ci * This ALSA driver don't do this because a bit tiresome. Then isochronous
2462306a36Sopenharmony_ci * streaming with many asynchronous transactions brings sounds with noises.
2562306a36Sopenharmony_ci * Unfortunately current 'ffado-mixer' generated many asynchronous transaction
2662306a36Sopenharmony_ci * to observe device's state, mainly check cmp connection and signal format. I
2762306a36Sopenharmony_ci * recommend users to close ffado-mixer at 192.0kHz if mixer is needless.
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * Terratec PHASE 24 FW and PHASE X24 FW are internally the same as
3062306a36Sopenharmony_ci * Yamaha GO 44 and GO 46. Yamaha and Terratec had cooperated for these models.
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_cistatic const enum snd_bebob_clock_type clk_src_types[] = {
3462306a36Sopenharmony_ci	SND_BEBOB_CLOCK_TYPE_INTERNAL,
3562306a36Sopenharmony_ci	SND_BEBOB_CLOCK_TYPE_EXTERNAL,	/* S/PDIF */
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_cistatic int
3862306a36Sopenharmony_ciclk_src_get(struct snd_bebob *bebob, unsigned int *id)
3962306a36Sopenharmony_ci{
4062306a36Sopenharmony_ci	int err;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	err = avc_audio_get_selector(bebob->unit, 0, 4, id);
4362306a36Sopenharmony_ci	if (err < 0)
4462306a36Sopenharmony_ci		return err;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci	if (*id >= ARRAY_SIZE(clk_src_types))
4762306a36Sopenharmony_ci		return -EIO;
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	return 0;
5062306a36Sopenharmony_ci}
5162306a36Sopenharmony_cistatic const struct snd_bebob_clock_spec clock_spec = {
5262306a36Sopenharmony_ci	.num	= ARRAY_SIZE(clk_src_types),
5362306a36Sopenharmony_ci	.types	= clk_src_types,
5462306a36Sopenharmony_ci	.get	= &clk_src_get,
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_cistatic const struct snd_bebob_rate_spec rate_spec = {
5762306a36Sopenharmony_ci	.get	= &snd_bebob_stream_get_rate,
5862306a36Sopenharmony_ci	.set	= &snd_bebob_stream_set_rate,
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ciconst struct snd_bebob_spec yamaha_terratec_spec = {
6162306a36Sopenharmony_ci	.clock	= &clock_spec,
6262306a36Sopenharmony_ci	.rate	= &rate_spec,
6362306a36Sopenharmony_ci	.meter	= NULL
6462306a36Sopenharmony_ci};
65