[alsa-devel] [PATCH 10/13] speakers: Add support for Behringer/Mackie devices

Takashi Sakamoto o-takashi at sakamocchi.jp
Fri Jan 10 16:29:32 CET 2014


FFADO project have already identified that some devices produced by
Behringer/Mackie are based on OXFW970/971.

They support 'AV/C Stream Format Information' command. But some of them
don't implement 'LIST' subfunction. So this commit uses an assumption
that 'if they don't implement it, they don't change formation of stream
for each sampling rate'.

With this assumption, this driver generate formations for the devices by:
 1.getting current formation by SINGLE subfunction
 2.getting supported sampling rates
 3.applying current formation for all of supported sampling rates

Behringer/Mackie devices support capture/playback of PCM-samples and some
of them supports capture/playback of MIDI-messages. Followed commits will
add these functionalities.

Signed-off-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>
---
 sound/firewire/Kconfig                    |  11 +-
 sound/firewire/speakers/speakers.c        |  48 +++++++-
 sound/firewire/speakers/speakers.h        |   1 +
 sound/firewire/speakers/speakers_stream.c | 197 ++++++++++++++++++++++++++++++
 4 files changed, 249 insertions(+), 8 deletions(-)

diff --git a/sound/firewire/Kconfig b/sound/firewire/Kconfig
index b2c5a7e..1cf371f 100644
--- a/sound/firewire/Kconfig
+++ b/sound/firewire/Kconfig
@@ -27,12 +27,17 @@ config SND_DICE
 	  will be called snd-dice.
 
 config SND_FIREWIRE_SPEAKERS
-	tristate "FireWire speakers"
+	tristate "Oxford OXFW970/971 chipset support"
 	select SND_PCM
 	select SND_FIREWIRE_LIB
 	help
-	  Say Y here to include support for the Griffin FireWave Surround
-	  and the LaCie FireWire Speakers.
+	  Say Y here to include support for Firewire devices based on
+	  Oxford Semiconductor OXFW970/971.
+	   * Griffin Firewave
+	   * LaCie Firewire Speakers
+	   * Behringer F-Control Audio 202
+	   * Mackie Onyx-i series (former model)
+	   * Mackie Onyx Satellite
 
 	  To compile this driver as a module, choose M here: the module
 	  will be called snd-firewire-speakers.
diff --git a/sound/firewire/speakers/speakers.c b/sound/firewire/speakers/speakers.c
index 8c3bf4a..e68046c 100644
--- a/sound/firewire/speakers/speakers.c
+++ b/sound/firewire/speakers/speakers.c
@@ -16,6 +16,8 @@
 
 #define VENDOR_GRIFFIN		0x001292
 #define VENDOR_LACIE		0x00d04b
+#define VEN_BEHRINGER		0x001564
+#define VEN_LOUD		0x000ff2
 
 #define SPECIFIER_1394TA	0x00a02d
 #define VERSION_AVC		0x010001
@@ -64,7 +66,12 @@ static int name_card(struct fwspk *fwspk)
 		goto end;
 	be32_to_cpus(&firmware);
 
-	strcpy(fwspk->card->driver, fwspk->device_info->driver_name);
+	/* to apply card definitions */
+	if (fwspk->device_info)
+		strcpy(fwspk->card->driver, fwspk->device_info->driver_name);
+	else
+		strcpy(fwspk->card->driver, "OXFW");
+
 	strcpy(fwspk->card->shortname, model);
 
 	snprintf(fwspk->card->longname, sizeof(fwspk->card->longname),
@@ -110,8 +117,10 @@ static int fwspk_probe(struct fw_unit *unit,
 
 	if (fwspk->device_info == &griffin_firewave)
 		err = firewave_stream_discover(fwspk);
-	else
+	else if (fwspk->device_info == &lacie_speakers)
 		err = lacie_speakers_stream_discover(fwspk);
+	else
+		err = snd_fwspk_stream_discover(fwspk);
 	if (err < 0)
 		goto err_card;
 
@@ -127,9 +136,11 @@ static int fwspk_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto err_card;
 
-	err = snd_fwspk_create_mixer(fwspk);
-	if (err < 0)
-		goto err_card;
+	if (fwspk->device_info) {
+		err = snd_fwspk_create_mixer(fwspk);
+		if (err < 0)
+			goto err_card;
+	}
 
 	snd_fwspk_proc_init(fwspk);
 
@@ -189,6 +200,33 @@ static const struct ieee1394_device_id fwspk_id_table[] = {
 		.version      = VERSION_AVC,
 		.driver_data  = (kernel_ulong_t)&lacie_speakers,
 	},
+	/* Behringer,F-Control Audio 202 */
+	{
+		.match_flags	= IEEE1394_MATCH_VENDOR_ID |
+				  IEEE1394_MATCH_MODEL_ID,
+		.vendor_id	= VEN_BEHRINGER,
+		.model_id	= 0x00fc22,
+	},
+	/* Mackie, Onyx-i series (former models) */
+	{
+		.match_flags	= IEEE1394_MATCH_VENDOR_ID |
+				  IEEE1394_MATCH_MODEL_ID,
+		.vendor_id	= VEN_LOUD,
+		.model_id	= 0x081216,
+	},
+	/* Mackie, Onyx Satellite */
+	{
+		.match_flags	= IEEE1394_MATCH_VENDOR_ID |
+				  IEEE1394_MATCH_MODEL_ID,
+		.vendor_id	= VEN_LOUD,
+		.model_id	= 0x00200f,
+	},
+	/* IDs are unknown but able to be supported */
+	/*  Mackie(Loud), d.2 pro */
+	/*  Mackie(Loud), d.4 pro */
+	/*  Mackie(Loud), U.420 */
+	/*  Mackie(Loud), U.420d */
+	/*  Mackie(Loud), Tapco Link.Firewire */
 	{ }
 };
 MODULE_DEVICE_TABLE(ieee1394, fwspk_id_table);
diff --git a/sound/firewire/speakers/speakers.h b/sound/firewire/speakers/speakers.h
index 386e267..017d972 100644
--- a/sound/firewire/speakers/speakers.h
+++ b/sound/firewire/speakers/speakers.h
@@ -95,6 +95,7 @@ void snd_fwspk_stream_update(struct fwspk *fwspk);
 
 int firewave_stream_discover(struct fwspk *fwspk);
 int lacie_speakers_stream_discover(struct fwspk *fwspk);
+int snd_fwspk_stream_discover(struct fwspk *fwspk);
 
 int snd_fwspk_create_pcm(struct fwspk *fwspk);
 
diff --git a/sound/firewire/speakers/speakers_stream.c b/sound/firewire/speakers/speakers_stream.c
index ef2ac9d..591e6bf 100644
--- a/sound/firewire/speakers/speakers_stream.c
+++ b/sound/firewire/speakers/speakers_stream.c
@@ -22,6 +22,20 @@ const unsigned int fwspk_rate_table[FWSPK_STREAM_TABLE_ENTRIES] = {
 	[6] = 192000,
 };
 
+/*
+ * See Table 5.7 – Sampling frequency for Multi-bit Audio
+ * at AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
+ */
+static const unsigned int avc_stream_rate_table[] = {
+	[0] = 0x02,
+	[1] = 0x03,
+	[2] = 0x04,
+	[3] = 0x0a,
+	[4] = 0x05,
+	[5] = 0x06,
+	[6] = 0x07,
+};
+
 int snd_fwspk_stream_init(struct fwspk *fwspk)
 {
 	int err;
@@ -164,3 +178,186 @@ int lacie_speakers_stream_discover(struct fwspk *fwspk)
 
 	return 0;
 }
+
+/*
+ * See Table 6.16 - AM824 Stream Format
+ *     Figure 6.19 - format_information field for AM824 Compound
+ * at AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
+ */
+static int
+parse_stream_formation(u8 *buf, unsigned int len,
+		       struct fwspk_stream_formation *formation,
+		       unsigned int *index)
+{
+	unsigned int e, channels, format;
+
+	/*
+	 * this module can support a hierarchy combination that:
+	 *  Root:	Audio and Music (0x90)
+	 *  Level 1:	AM824 Compound  (0x40)
+	 */
+	if ((buf[0] != 0x90) || (buf[1] != 0x40))
+		return -ENOSYS;
+
+	/* check the sampling rate */
+	for (*index = 0; *index < sizeof(avc_stream_rate_table); *index += 1) {
+		if (buf[2] == avc_stream_rate_table[*index])
+			break;
+	}
+	if (*index == sizeof(avc_stream_rate_table))
+		return -ENOSYS;
+
+	for (e = 0; e < buf[4]; e++) {
+		channels = buf[5 + e * 2];
+		format = buf[6 + e * 2];
+
+		switch (format) {
+		/* IEC 60958-3 */
+		case 0x00:
+		/* Multi Bit Linear Audio (Raw) */
+		case 0x06:
+			formation[*index].pcm += channels;
+			break;
+		/* MIDI comformant */
+		case 0x0d:
+			formation[*index].midi += channels;
+			break;
+		/* Multi Bit Linear Audio (DVD-audio) */
+		case 0x07:
+		/* IEC 61937-3 to 7 */
+		case 0x01:
+		case 0x02:
+		case 0x03:
+		case 0x04:
+		case 0x05:
+		/* One Bit Audio */
+		case 0x08:	/* (Plain) Raw */
+		case 0x09:	/* (Plain) SACD */
+		case 0x0a:	/* (Encoded) Raw */
+		case 0x0b:	/* (ENcoded) SACD */
+		/* High precision Multi-bit Linear Audio */
+		case 0x0c:
+		/* SMPTE Time-Code conformant */
+		case 0x0e:
+		/* Sample Count */
+		case 0x0f:
+		/* Anciliary Data */
+		case 0x10:
+		/* Synchronization Stream (Stereo Raw audio) */
+		case 0x40:
+		/* Don't care */
+		case 0xff:
+		default:
+			break;	/* not supported */
+		}
+	}
+
+	return 0;
+}
+
+static int
+assume_stream_formations(struct fwspk *fwspk, enum avc_general_plug_dir dir,
+			 unsigned int pid, u8 *buf, unsigned int *len,
+			 struct fwspk_stream_formation *formations)
+{
+	unsigned int i, pcm_channels, midi_channels;
+	int err;
+
+	/* get formation at current sampling rate */
+	err = avc_stream_get_format_single(fwspk->unit, dir, pid, buf, len);
+	if ((err < 0) || (err == 0x80) /* NOT IMPLEMENTED */)
+		goto end;
+
+	/* parse and set stream formation */
+	err = parse_stream_formation(buf, *len, formations, &i);
+	if (err < 0)
+		goto end;
+
+	pcm_channels = formations[i].pcm;
+	midi_channels = formations[i].midi;
+
+	/* apply the formation for each available sampling rate */
+	for (i = 0; i < FWSPK_STREAM_TABLE_ENTRIES; i++) {
+		err = avc_general_inquiry_sig_fmt(fwspk->unit,
+						  fwspk_rate_table[i],
+						  dir, pid);
+		if ((err < 0) || (err == 0x08) /* NOT IMPLEMENTED */)
+			continue;
+
+		formations[i].pcm = pcm_channels;
+		formations[i].midi = midi_channels;
+	}
+end:
+	return err;
+}
+
+static int
+fill_stream_formations(struct fwspk *fwspk, enum avc_general_plug_dir dir,
+		       unsigned short pid)
+{
+	u8 *buf;
+	struct fwspk_stream_formation *formations;
+	unsigned int i, len, eid;
+	int err;
+
+	buf = kmalloc(AVC_GENERIC_FRAME_MAXIMUM_BYTES, GFP_KERNEL);
+	if (buf == NULL)
+		return -ENOMEM;
+
+	formations = fwspk->rx_stream_formations;
+
+	/* initialize parameters here because of checking implementation */
+	eid = 0;
+	len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
+	memset(buf, 0, len);
+
+	/* get first entry */
+	err = avc_stream_get_format_list(fwspk->unit, dir, 0, buf, &len, eid);
+	if ((err < 0) || (len < 3)) {
+		/* LIST subfunction is not implemented */
+		err = assume_stream_formations(fwspk, dir, pid, buf, &len,
+					       formations);
+		goto end;
+	}
+
+	/* LIST subfunction is implemented */
+	do {
+		/* parse and set stream formation */
+		err = parse_stream_formation(buf, len, formations, &i);
+		if (err < 0)
+			continue;
+
+		/* get next entry */
+		len = AVC_GENERIC_FRAME_MAXIMUM_BYTES;
+		memset(buf, 0, len);
+		err = avc_stream_get_format_list(fwspk->unit, dir, 0,
+						 buf, &len, ++eid);
+		if ((err < 0) || (len < 3))
+			break;
+	} while (eid < FWSPK_STREAM_TABLE_ENTRIES);
+end:
+	kfree(buf);
+	return err;
+}
+
+int snd_fwspk_stream_discover(struct fwspk *fwspk)
+{
+	u8 plugs[AVC_PLUG_INFO_BUF_COUNT];
+	int err;
+
+	/* the number of plugs for isoc in/out, ext in/out  */
+	err = avc_general_get_plug_info(fwspk->unit, 0x1f, 0x07, 0x00, plugs);
+	if (err < 0)
+		goto end;
+	if ((plugs[0] == 0) || (plugs[0] == 0)) {
+		err = -EIO;
+		goto end;
+	}
+
+	/* use iPCR[0] */
+	err = fill_stream_formations(fwspk, AVC_GENERAL_PLUG_DIR_IN, 0);
+	if (err < 0)
+		goto end;
+end:
+	return err;
+}
-- 
1.8.3.2



More information about the Alsa-devel mailing list