[alsa-devel] [PATCH 48/52] oxfw: Add support for Behringer/Mackie devices

Takashi Sakamoto o-takashi at sakamocchi.jp
Wed Jan 29 14:44:55 CET 2014


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

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.

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

Signed-off-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>
---
 sound/firewire/Kconfig            |   3 +
 sound/firewire/oxfw/oxfw.c        |  48 +++++++-
 sound/firewire/oxfw/oxfw.h        |   1 +
 sound/firewire/oxfw/oxfw_stream.c | 233 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 276 insertions(+), 9 deletions(-)

diff --git a/sound/firewire/Kconfig b/sound/firewire/Kconfig
index d8b8c54..ff9448a 100644
--- a/sound/firewire/Kconfig
+++ b/sound/firewire/Kconfig
@@ -35,6 +35,9 @@ config SND_OXFW
 	  Oxford Semiconductor OXFW970/971 chipset.
 	   * Griffin Firewave
 	   * LaCie Firewire Speakers
+	   * Behringer F-Control Audio 202
+	   * Mackie Onyx-i series (former models)
+	   * Mackie Onyx Satellite
 
 	  To compile this driver as a module, choose M here: the module
 	  will be called snd-oxfw.
diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c
index 74319df..d45073a 100644
--- a/sound/firewire/oxfw/oxfw.c
+++ b/sound/firewire/oxfw/oxfw.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
@@ -65,7 +67,12 @@ static int name_card(struct snd_oxfw *oxfw)
 		goto end;
 	be32_to_cpus(&firmware);
 
-	strcpy(oxfw->card->driver, oxfw->device_info->driver_name);
+	/* to apply card definitions */
+	if (oxfw->device_info)
+		strcpy(oxfw->card->driver, oxfw->device_info->driver_name);
+	else
+		strcpy(oxfw->card->driver, "OXFW");
+
 	strcpy(oxfw->card->shortname, model);
 
 	snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
@@ -106,8 +113,10 @@ static int oxfw_probe(struct fw_unit *unit,
 
 	if (oxfw->device_info == &griffin_firewave)
 		err = firewave_stream_discover(oxfw);
-	else
+	else if (oxfw->device_info == &lacie_speakers)
 		err = lacie_speakers_stream_discover(oxfw);
+	else
+		err = snd_oxfw_stream_discover(oxfw);
 	if (err < 0)
 		goto err_card;
 
@@ -123,9 +132,11 @@ static int oxfw_probe(struct fw_unit *unit,
 	if (err < 0)
 		goto err_card;
 
-	err = snd_oxfw_create_mixer(oxfw);
-	if (err < 0)
-		goto err_card;
+	if (oxfw->device_info) {
+		err = snd_oxfw_create_mixer(oxfw);
+		if (err < 0)
+			goto err_card;
+	}
 
 	snd_oxfw_proc_init(oxfw);
 
@@ -182,6 +193,33 @@ static const struct ieee1394_device_id oxfw_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, oxfw_id_table);
diff --git a/sound/firewire/oxfw/oxfw.h b/sound/firewire/oxfw/oxfw.h
index 081ce83..fe6936e 100644
--- a/sound/firewire/oxfw/oxfw.h
+++ b/sound/firewire/oxfw/oxfw.h
@@ -98,6 +98,7 @@ void snd_oxfw_stream_update(struct snd_oxfw *oxfw);
 
 int firewave_stream_discover(struct snd_oxfw *oxfw);
 int lacie_speakers_stream_discover(struct snd_oxfw *oxfw);
+int snd_oxfw_stream_discover(struct snd_oxfw *oxfw);
 
 int snd_oxfw_create_pcm(struct snd_oxfw *oxfw);
 
diff --git a/sound/firewire/oxfw/oxfw_stream.c b/sound/firewire/oxfw/oxfw_stream.c
index 6554dec..4431571 100644
--- a/sound/firewire/oxfw/oxfw_stream.c
+++ b/sound/firewire/oxfw/oxfw_stream.c
@@ -24,6 +24,20 @@ const unsigned int snd_oxfw_rate_table[SND_OXFW_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_oxfw_stream_init(struct snd_oxfw *oxfw)
 {
 	int err;
@@ -93,6 +107,28 @@ end:
 	return err;
 }
 
+static int check_connection_used_by_others(struct snd_oxfw *oxfw)
+{
+	struct cmp_connection *conn;
+	struct amdtp_stream *stream;
+	bool used;
+	int err;
+
+	stream = &oxfw->rx_stream;
+	conn = &oxfw->in_conn;
+
+	err = cmp_connection_check_used(conn, &used);
+	if ((err >= 0) && used && !amdtp_stream_running(stream)) {
+		dev_err(&oxfw->unit->device,
+			"Connection established by others: %cPCR[%d]\n",
+			(conn->direction == CMP_OUTPUT) ? 'o' : 'i',
+			conn->pcr_index);
+		err = -EBUSY;
+	}
+
+	return err;
+}
+
 int snd_oxfw_stream_start(struct snd_oxfw *oxfw, unsigned int rate)
 {
 	unsigned int curr_rate;
@@ -100,13 +136,18 @@ int snd_oxfw_stream_start(struct snd_oxfw *oxfw, unsigned int rate)
 
 	mutex_lock(&oxfw->mutex);
 
+	/*
+	 * Considering JACK/FFADO streaming:
+	 * TODO: This can be removed hwdep functionality becomes popular.
+	 */
+	err = check_connection_used_by_others(oxfw);
+	if (err < 0)
+		goto end;
+
 	/* packet queueing error */
 	if (amdtp_streaming_error(&oxfw->rx_stream))
 		snd_oxfw_stream_stop(oxfw);
 
-	if (amdtp_stream_running(&oxfw->rx_stream))
-		goto end;
-
 	/* arrange sampling rate */
 	err = avc_general_get_sig_fmt(oxfw->unit, &curr_rate,
 				      AVC_GENERAL_PLUG_DIR_IN, 0);
@@ -131,7 +172,8 @@ int snd_oxfw_stream_start(struct snd_oxfw *oxfw, unsigned int rate)
 		}
 	}
 
-	err = start_stream(oxfw, rate);
+	if (!amdtp_stream_running(&oxfw->rx_stream))
+		err = start_stream(oxfw, rate);
 end:
 	mutex_unlock(&oxfw->mutex);
 	return err;
@@ -187,3 +229,186 @@ int lacie_speakers_stream_discover(struct snd_oxfw *oxfw)
 
 	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 snd_oxfw_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:
+			return -ENOSYS;	/* not supported */
+		}
+	}
+
+	return 0;
+}
+
+static int
+assume_stream_formations(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
+			 unsigned int pid, u8 *buf, unsigned int *len,
+			 struct snd_oxfw_stream_formation *formations)
+{
+	unsigned int i, pcm_channels, midi_channels;
+	int err;
+
+	/* get formation at current sampling rate */
+	err = avc_stream_get_format_single(oxfw->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 < SND_OXFW_STREAM_TABLE_ENTRIES; i++) {
+		err = avc_general_inquiry_sig_fmt(oxfw->unit,
+						  snd_oxfw_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 snd_oxfw *oxfw, enum avc_general_plug_dir dir,
+		       unsigned short pid)
+{
+	u8 *buf;
+	struct snd_oxfw_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 = oxfw->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(oxfw->unit, dir, 0, buf, &len, eid);
+	if ((err < 0) || (len < 3)) {
+		/* LIST subfunction is not implemented */
+		err = assume_stream_formations(oxfw, 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(oxfw->unit, dir, 0,
+						 buf, &len, ++eid);
+		if ((err < 0) || (len < 3))
+			break;
+	} while (eid < SND_OXFW_STREAM_TABLE_ENTRIES);
+end:
+	kfree(buf);
+	return err;
+}
+
+int snd_oxfw_stream_discover(struct snd_oxfw *oxfw)
+{
+	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(oxfw->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(oxfw, 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