All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source
@ 2014-10-31  1:57 Damien Zammit
  2014-10-31  3:29 ` Takashi Sakamoto
  0 siblings, 1 reply; 6+ messages in thread
From: Damien Zammit @ 2014-10-31  1:57 UTC (permalink / raw)
  To: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 244 bytes --]

This patch provides a mixer control for selecting the clock source of
the Digidesign Mbox 1 to either internal clock or S/PDIF external.
Trial and error and bus snooping were the only way to get this
information, but it works on the hardware.


[-- Attachment #2: 0001-mbox1-spdif.patch --]
[-- Type: text/x-patch, Size: 6716 bytes --]

>From d19804aa8b1d3355b647a3209dce4cb5c181ee2b Mon Sep 17 00:00:00 2001
From: Damien Zammit <damien@zamaudio.com>
Date: Fri, 31 Oct 2014 12:44:25 +1100
Subject: [PATCH] snd-usb-audio: Add mixer control for Digidesign Mbox 1 clock
 source

Signed-off-by: Damien Zammit <damien@zamaudio.com>
---
 sound/usb/mixer.h        |   1 +
 sound/usb/mixer_maps.c   |   9 +++
 sound/usb/mixer_quirks.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 196 insertions(+)

diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index 73b1f64..5ab6935 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -23,6 +23,7 @@ struct usb_mixer_interface {
 
 	u8 audigy2nx_leds[3];
 	u8 xonar_u1_status;
+	u8 mbox1_status;
 };
 
 #define MAX_CHANNELS	16	/* max logical channels */
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index d1d72ff..9ee3fc2 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -179,6 +179,11 @@ static struct usbmix_name_map audigy2nx_map[] = {
 	{ 0 } /* terminator */
 };
 
+static struct usbmix_name_map mbox1_map[] = {
+	{ 1, "Control" },
+	{ 0 } /* terminator */
+};
+
 static struct usbmix_selector_map c400_selectors[] = {
 	{
 		.id = 0x80,
@@ -416,6 +421,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
 		.map = aureon_51_2_map,
 	},
 	{
+		.id = USB_ID(0x0dba, 0x1000),
+		.map = mbox1_map,
+	},
+	{
 		.id = USB_ID(0x13e5, 0x0001),
 		.map = scratch_live_map,
 		.ignore_ctl_error = 1,
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 3980bf5..b69e8f4 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -565,6 +565,185 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
 	return 0;
 }
 
+/* Digidesign Mbox 1 clock source switch (internal/spdif) */
+
+struct snd_mbox1_switch_priv_val {
+	struct usb_mixer_interface *mixer;
+	int cached_value;
+	int is_cached;
+};
+
+static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_mbox1_switch_priv_val *pval;
+	unsigned char value;
+
+	value = 0x00;
+
+	pval = (struct snd_mbox1_switch_priv_val *)
+		kctl->private_value;
+
+	if (pval->is_cached) {
+		ucontrol->value.enumerated.item[0] = pval->cached_value;
+		return 0;
+	}
+
+	ucontrol->value.enumerated.item[0] = value;
+	pval->cached_value = value;
+	pval->is_cached = 1;
+
+	return 0;
+}
+
+static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_usb_audio *chip;
+	struct snd_mbox1_switch_priv_val *pval;
+
+	struct usb_mixer_interface *mixer;
+	int changed, cur_val, err, new_val;
+	unsigned char value[2];
+	unsigned char buff[3];
+
+	changed = 0;
+	value[0] = 0x00;
+	value[1] = 0x00;
+
+	pval = (struct snd_mbox1_switch_priv_val *)
+		kctl->private_value;
+	cur_val = pval->cached_value;
+	new_val = ucontrol->value.enumerated.item[0];
+
+	mixer = (struct usb_mixer_interface *) pval->mixer;
+	if (snd_BUG_ON(!mixer))
+		return -EINVAL;
+
+	chip = (struct snd_usb_audio *) mixer->chip;
+	if (snd_BUG_ON(!chip))
+		return -EINVAL;
+
+	if (!pval->is_cached) {
+		cur_val = value[0];
+		pval->cached_value = cur_val;
+		pval->is_cached = 1;
+	}
+	/* update value if needed */
+	if (cur_val != new_val) {
+		value[0] = new_val;
+		value[1] = 0;
+		down_read(&mixer->chip->shutdown_rwsem);
+		if (mixer->chip->shutdown) {
+			err = -ENODEV;
+		} else {
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				      usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				      USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+				      0x00, 0x500, buff, 1);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				      usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				      USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
+				      0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			if (new_val == 0) {
+				buff[0] = 0x80;
+				buff[1] = 0xbb;
+				buff[2] = 0x00;
+			} else {
+				buff[0] = buff[1] = buff[2] = 0;
+			}
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				      usb_sndctrlpipe(mixer->chip->dev, 0), 0x1,
+				      USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
+				      0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				      usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				      USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
+				      0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				      usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				      USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
+				      0x100, 0x2, buff, 3);
+			if (err < 0)
+				return err;
+		}
+		up_read(&mixer->chip->shutdown_rwsem);
+		if (err < 0)
+			return err;
+
+		pval->cached_value = new_val;
+		pval->is_cached = 1;
+		changed = 1;
+	}
+
+	return changed;
+}
+
+static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_info *uinfo)
+{
+	static const char *texts[2] = {"Internal",
+				       "S/PDIF"
+	};
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 2;
+	if (uinfo->value.enumerated.item > 1)
+		uinfo->value.enumerated.item = 1;
+	strcpy(uinfo->value.enumerated.name,
+		texts[uinfo->value.enumerated.item]);
+
+	return 0;
+}
+
+static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
+	/*int validx, int bUnitID)*/
+{
+	static struct snd_kcontrol_new template = {
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Clock Source",
+		.index = 0,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+		.info = snd_mbox1_switch_info,
+		.get = snd_mbox1_switch_get,
+		.put = snd_mbox1_switch_put
+	};
+
+	int err;
+	struct snd_kcontrol *kctl;
+	struct snd_mbox1_switch_priv_val *pval;
+
+	pval = kzalloc(sizeof(*pval), GFP_KERNEL);
+	if (!pval)
+		return -ENOMEM;
+
+	pval->cached_value = 0;
+	pval->is_cached = 0;
+	pval->mixer = mixer;
+
+	template.private_value = (unsigned long) pval;
+	kctl = snd_ctl_new1(&template, mixer->chip);
+	if (!kctl) {
+		kfree(pval);
+		return -ENOMEM;
+	}
+
+	err = snd_ctl_add(mixer->chip->card, kctl);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
 /* Native Instruments device quirks */
 
 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
@@ -1605,6 +1784,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
 					      snd_audigy2nx_proc_read);
 		break;
 
+	/* Digidesign Mbox 1 */
+	case USB_ID(0x0dba, 0x1000):
+		err = snd_mbox1_create_sync_switch(mixer);
+		if (err < 0)
+			break;
+		break;
+
 	/* EMU0204 */
 	case USB_ID(0x041e, 0x3f19):
 		err = snd_emu0204_controls_create(mixer);
-- 
1.9.1


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source
  2014-10-31  1:57 [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source Damien Zammit
@ 2014-10-31  3:29 ` Takashi Sakamoto
  2014-10-31  4:02   ` Damien Zammit
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Sakamoto @ 2014-10-31  3:29 UTC (permalink / raw)
  To: Damien Zammit; +Cc: alsa-devel

Hi Damien,

On Oct 31 2014 10:57, Damien Zammit wrote:
> This patch provides a mixer control for selecting the clock source of
> the Digidesign Mbox 1 to either internal clock or S/PDIF external.
> Trial and error and bus snooping were the only way to get this
> information, but it works on the hardware.

This patch includes lines over 80 characters. Furthermore, these lines 
include inappropriate white-space for indentation. How about indenting 
with tab only and add more line-breaks between each function parameter?

$ ./scripts/checkpatch.pl /tmp/0001-mbox1-spdif.patch
WARNING: line over 80 characters
#134: FILE: sound/usb/mixer_quirks.c:641:
+                                     usb_rcvctrlpipe(mixer->chip->dev, 
0), 0x81,

WARNING: line over 80 characters
#135: FILE: sound/usb/mixer_quirks.c:642:
+                                     USB_DIR_IN | USB_TYPE_CLASS | 
USB_RECIP_INTERFACE,

WARNING: line over 80 characters
#140: FILE: sound/usb/mixer_quirks.c:647:
+                                     usb_rcvctrlpipe(mixer->chip->dev, 
0), 0x81,

WARNING: line over 80 characters
#141: FILE: sound/usb/mixer_quirks.c:648:
+                                     USB_DIR_IN | USB_TYPE_CLASS | 
USB_RECIP_ENDPOINT,

WARNING: line over 80 characters
#159: FILE: sound/usb/mixer_quirks.c:666:
+                                     usb_rcvctrlpipe(mixer->chip->dev, 
0), 0x81,

WARNING: line over 80 characters
#160: FILE: sound/usb/mixer_quirks.c:667:
+                                     USB_DIR_IN | USB_TYPE_CLASS | 
USB_RECIP_ENDPOINT,

WARNING: line over 80 characters
#165: FILE: sound/usb/mixer_quirks.c:672:
+                                     usb_rcvctrlpipe(mixer->chip->dev, 
0), 0x81,

WARNING: line over 80 characters
#166: FILE: sound/usb/mixer_quirks.c:673:
+                                     USB_DIR_IN | USB_TYPE_CLASS | 
USB_RECIP_ENDPOINT,

total: 0 errors, 8 warnings, 226 lines checked

/tmp/0001-mbox1-spdif.patch has style problems, please review.

If any of these errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.


Regards

Takashi Sakamoto
o-takashi@sakamocchi.jp

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source
  2014-10-31  3:29 ` Takashi Sakamoto
@ 2014-10-31  4:02   ` Damien Zammit
  2014-10-31  4:28     ` Takashi Sakamoto
  0 siblings, 1 reply; 6+ messages in thread
From: Damien Zammit @ 2014-10-31  4:02 UTC (permalink / raw)
  To: Takashi Sakamoto; +Cc: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 2388 bytes --]

Hi, sorry for the style problems.  See attached for better version.

Damien

On 31/10/14 14:29, Takashi Sakamoto wrote:
> Hi Damien,
> 
> On Oct 31 2014 10:57, Damien Zammit wrote:
>> This patch provides a mixer control for selecting the clock source of
>> the Digidesign Mbox 1 to either internal clock or S/PDIF external.
>> Trial and error and bus snooping were the only way to get this
>> information, but it works on the hardware.
> 
> This patch includes lines over 80 characters. Furthermore, these lines
> include inappropriate white-space for indentation. How about indenting
> with tab only and add more line-breaks between each function parameter?
> 
> $ ./scripts/checkpatch.pl /tmp/0001-mbox1-spdif.patch
> WARNING: line over 80 characters
> #134: FILE: sound/usb/mixer_quirks.c:641:
> +                                     usb_rcvctrlpipe(mixer->chip->dev,
> 0), 0x81,
> 
> WARNING: line over 80 characters
> #135: FILE: sound/usb/mixer_quirks.c:642:
> +                                     USB_DIR_IN | USB_TYPE_CLASS |
> USB_RECIP_INTERFACE,
> 
> WARNING: line over 80 characters
> #140: FILE: sound/usb/mixer_quirks.c:647:
> +                                     usb_rcvctrlpipe(mixer->chip->dev,
> 0), 0x81,
> 
> WARNING: line over 80 characters
> #141: FILE: sound/usb/mixer_quirks.c:648:
> +                                     USB_DIR_IN | USB_TYPE_CLASS |
> USB_RECIP_ENDPOINT,
> 
> WARNING: line over 80 characters
> #159: FILE: sound/usb/mixer_quirks.c:666:
> +                                     usb_rcvctrlpipe(mixer->chip->dev,
> 0), 0x81,
> 
> WARNING: line over 80 characters
> #160: FILE: sound/usb/mixer_quirks.c:667:
> +                                     USB_DIR_IN | USB_TYPE_CLASS |
> USB_RECIP_ENDPOINT,
> 
> WARNING: line over 80 characters
> #165: FILE: sound/usb/mixer_quirks.c:672:
> +                                     usb_rcvctrlpipe(mixer->chip->dev,
> 0), 0x81,
> 
> WARNING: line over 80 characters
> #166: FILE: sound/usb/mixer_quirks.c:673:
> +                                     USB_DIR_IN | USB_TYPE_CLASS |
> USB_RECIP_ENDPOINT,
> 
> total: 0 errors, 8 warnings, 226 lines checked
> 
> /tmp/0001-mbox1-spdif.patch has style problems, please review.
> 
> If any of these errors are false positives, please report
> them to the maintainer, see CHECKPATCH in MAINTAINERS.
> 
> 
> Regards
> 
> Takashi Sakamoto
> o-takashi@sakamocchi.jp

[-- Attachment #2: mbox1-spdif-2.patch --]
[-- Type: text/x-patch, Size: 6646 bytes --]

>From 57c714d22b9749be4e3fa3ce5e185832863b60c2 Mon Sep 17 00:00:00 2001
From: Damien Zammit <damien@zamaudio.com>
Date: Fri, 31 Oct 2014 12:44:25 +1100
Subject: [PATCH] snd-usb-audio: Add mixer control for Digidesign Mbox 1 clock
 source

Signed-off-by: Damien Zammit <damien@zamaudio.com>
---
 sound/usb/mixer.h        |   1 +
 sound/usb/mixer_maps.c   |   9 +++
 sound/usb/mixer_quirks.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 200 insertions(+)

diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index 73b1f64..5ab6935 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -23,6 +23,7 @@ struct usb_mixer_interface {
 
 	u8 audigy2nx_leds[3];
 	u8 xonar_u1_status;
+	u8 mbox1_status;
 };
 
 #define MAX_CHANNELS	16	/* max logical channels */
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index d1d72ff..9ee3fc2 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -179,6 +179,11 @@ static struct usbmix_name_map audigy2nx_map[] = {
 	{ 0 } /* terminator */
 };
 
+static struct usbmix_name_map mbox1_map[] = {
+	{ 1, "Control" },
+	{ 0 } /* terminator */
+};
+
 static struct usbmix_selector_map c400_selectors[] = {
 	{
 		.id = 0x80,
@@ -416,6 +421,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
 		.map = aureon_51_2_map,
 	},
 	{
+		.id = USB_ID(0x0dba, 0x1000),
+		.map = mbox1_map,
+	},
+	{
 		.id = USB_ID(0x13e5, 0x0001),
 		.map = scratch_live_map,
 		.ignore_ctl_error = 1,
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 3980bf5..6a21dec 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -565,6 +565,189 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
 	return 0;
 }
 
+/* Digidesign Mbox 1 clock source switch (internal/spdif) */
+
+struct snd_mbox1_switch_priv_val {
+	struct usb_mixer_interface *mixer;
+	int cached_value;
+	int is_cached;
+};
+
+static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_mbox1_switch_priv_val *pval;
+	unsigned char value;
+
+	value = 0x00;
+
+	pval = (struct snd_mbox1_switch_priv_val *)
+		kctl->private_value;
+
+	if (pval->is_cached) {
+		ucontrol->value.enumerated.item[0] = pval->cached_value;
+		return 0;
+	}
+
+	ucontrol->value.enumerated.item[0] = value;
+	pval->cached_value = value;
+	pval->is_cached = 1;
+
+	return 0;
+}
+
+static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_usb_audio *chip;
+	struct snd_mbox1_switch_priv_val *pval;
+
+	struct usb_mixer_interface *mixer;
+	int changed, cur_val, err, new_val;
+	unsigned char value[2];
+	unsigned char buff[3];
+
+	changed = 0;
+	value[0] = 0x00;
+	value[1] = 0x00;
+
+	pval = (struct snd_mbox1_switch_priv_val *)
+		kctl->private_value;
+	cur_val = pval->cached_value;
+	new_val = ucontrol->value.enumerated.item[0];
+
+	mixer = (struct usb_mixer_interface *) pval->mixer;
+	if (snd_BUG_ON(!mixer))
+		return -EINVAL;
+
+	chip = (struct snd_usb_audio *) mixer->chip;
+	if (snd_BUG_ON(!chip))
+		return -EINVAL;
+
+	if (!pval->is_cached) {
+		cur_val = value[0];
+		pval->cached_value = cur_val;
+		pval->is_cached = 1;
+	}
+	/* update value if needed */
+	if (cur_val != new_val) {
+		value[0] = new_val;
+		value[1] = 0;
+		down_read(&mixer->chip->shutdown_rwsem);
+		if (mixer->chip->shutdown) {
+			err = -ENODEV;
+		} else {
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			if (new_val == 0) {
+				buff[0] = 0x80;
+				buff[1] = 0xbb;
+				buff[2] = 0x00;
+			} else {
+				buff[0] = buff[1] = buff[2] = 0;
+			}
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_sndctrlpipe(mixer->chip->dev, 0), 0x1,
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
+			if (err < 0)
+				return err;
+		}
+		up_read(&mixer->chip->shutdown_rwsem);
+		if (err < 0)
+			return err;
+
+		pval->cached_value = new_val;
+		pval->is_cached = 1;
+		changed = 1;
+	}
+
+	return changed;
+}
+
+static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_info *uinfo)
+{
+	static const char *texts[2] = {"Internal",
+				       "S/PDIF"
+	};
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = 2;
+	if (uinfo->value.enumerated.item > 1)
+		uinfo->value.enumerated.item = 1;
+	strcpy(uinfo->value.enumerated.name,
+		texts[uinfo->value.enumerated.item]);
+
+	return 0;
+}
+
+static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
+	/*int validx, int bUnitID)*/
+{
+	static struct snd_kcontrol_new template = {
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Clock Source",
+		.index = 0,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+		.info = snd_mbox1_switch_info,
+		.get = snd_mbox1_switch_get,
+		.put = snd_mbox1_switch_put
+	};
+
+	int err;
+	struct snd_kcontrol *kctl;
+	struct snd_mbox1_switch_priv_val *pval;
+
+	pval = kzalloc(sizeof(*pval), GFP_KERNEL);
+	if (!pval)
+		return -ENOMEM;
+
+	pval->cached_value = 0;
+	pval->is_cached = 0;
+	pval->mixer = mixer;
+
+	template.private_value = (unsigned long) pval;
+	kctl = snd_ctl_new1(&template, mixer->chip);
+	if (!kctl) {
+		kfree(pval);
+		return -ENOMEM;
+	}
+
+	err = snd_ctl_add(mixer->chip->card, kctl);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
 /* Native Instruments device quirks */
 
 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
@@ -1605,6 +1788,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
 					      snd_audigy2nx_proc_read);
 		break;
 
+	/* Digidesign Mbox 1 */
+	case USB_ID(0x0dba, 0x1000):
+		err = snd_mbox1_create_sync_switch(mixer);
+		if (err < 0)
+			break;
+		break;
+
 	/* EMU0204 */
 	case USB_ID(0x041e, 0x3f19):
 		err = snd_emu0204_controls_create(mixer);
-- 
1.9.1


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source
  2014-10-31  4:02   ` Damien Zammit
@ 2014-10-31  4:28     ` Takashi Sakamoto
  2014-10-31  4:45       ` Damien Zammit
  2014-10-31  5:13       ` Takashi Sakamoto
  0 siblings, 2 replies; 6+ messages in thread
From: Takashi Sakamoto @ 2014-10-31  4:28 UTC (permalink / raw)
  To: Damien Zammit; +Cc: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 1479 bytes --]

Hi Damien,

On Oct 31 2014 13:02, Damien Zammit wrote:
> Hi, sorry for the style problems.  See attached for better version.

4 points.

1. please use white-spaces or tabs for indentation to align parameters 
to function-start blacket:

 > +static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
 > +                                       struct snd_ctl_elem_value 
*ucontrol)

 > +static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
 > +                                       struct snd_ctl_elem_info *uinfo)

 > +static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
 > +                                       struct snd_ctl_elem_value 
*ucontrol)

2.please use 'const char *const' for immutable arrays for immutable strings:
 > +       static const char *texts[2] = {"Internal",
 > +                                      "S/PDIF"
 > +       };
 > +

3. I think in your case, snd_ctl_enum_info() is available in struct 
snd_kcontrol_new.info() callback. Please read this thread:
[alsa-devel] [PATCH 00/43] Spread usage of snd_ctl_elem_info()
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-October/082573.html

4. I think 'err' local variable in snd_mbox1_create_sync_switch() can be 
removed because it's assign and evaluated at once:

 > +       err = snd_ctl_add(mixer->chip->card, kctl);
 > +       if (err < 0)
 > +               return err;
 > +
 > +       return 0;

See attached patch.


Regards

Takashi Sakamoto
o-takashi@sakamocchi.jp

[-- Attachment #2: 0001-Comments-for-mbox1-spdif-2.patch.patch --]
[-- Type: text/x-patch, Size: 2570 bytes --]

>From 6e889e1fc7d7101cfef14484849a412b002798e9 Mon Sep 17 00:00:00 2001
From: Takashi Sakamoto <mocchi@MocchiSakamoto64.miraclelinux.com>
Date: Fri, 31 Oct 2014 13:17:19 +0900
Subject: [PATCH] Comments for mbox1-spdif-2.patch

See:
[alsa-devel] [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source
http://mailman.alsa-project.org/pipermail/alsa-devel/2014-October/083264.html
---
 sound/usb/mixer_quirks.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 6a21dec..87f121f 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -574,7 +574,7 @@ struct snd_mbox1_switch_priv_val {
 };
 
 static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
-					struct snd_ctl_elem_value *ucontrol)
+				struct snd_ctl_elem_value *ucontrol)
 {
 	struct snd_mbox1_switch_priv_val *pval;
 	unsigned char value;
@@ -597,7 +597,7 @@ static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
 }
 
 static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
-					struct snd_ctl_elem_value *ucontrol)
+				struct snd_ctl_elem_value *ucontrol)
 {
 	struct snd_usb_audio *chip;
 	struct snd_mbox1_switch_priv_val *pval;
@@ -692,21 +692,14 @@ static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
 }
 
 static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
-					struct snd_ctl_elem_info *uinfo)
+				 struct snd_ctl_elem_info *uinfo)
 {
-	static const char *texts[2] = {"Internal",
-				       "S/PDIF"
+	static const char *const texts[2] = {
+		"Internal",
+		"S/PDIF"
 	};
 
-	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-	uinfo->count = 1;
-	uinfo->value.enumerated.items = 2;
-	if (uinfo->value.enumerated.item > 1)
-		uinfo->value.enumerated.item = 1;
-	strcpy(uinfo->value.enumerated.name,
-		texts[uinfo->value.enumerated.item]);
-
-	return 0;
+	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);;
 }
 
 static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
@@ -722,7 +715,6 @@ static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
 		.put = snd_mbox1_switch_put
 	};
 
-	int err;
 	struct snd_kcontrol *kctl;
 	struct snd_mbox1_switch_priv_val *pval;
 
@@ -741,11 +733,7 @@ static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
 		return -ENOMEM;
 	}
 
-	err = snd_ctl_add(mixer->chip->card, kctl);
-	if (err < 0)
-		return err;
-
-	return 0;
+	return snd_ctl_add(mixer->chip->card, kctl);
 }
 
 /* Native Instruments device quirks */
-- 
1.9.1


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source
  2014-10-31  4:28     ` Takashi Sakamoto
@ 2014-10-31  4:45       ` Damien Zammit
  2014-10-31  5:13       ` Takashi Sakamoto
  1 sibling, 0 replies; 6+ messages in thread
From: Damien Zammit @ 2014-10-31  4:45 UTC (permalink / raw)
  To: Takashi Sakamoto; +Cc: alsa-devel

[-- Attachment #1: Type: text/plain, Size: 364 bytes --]

Hi Takashi,

On 31/10/14 15:28, Takashi Sakamoto wrote:
> See attached patch.
I have applied your changes, patch 3 attached.

I am also working on another patch that will provide duplex support with
a locked frequency at 48kHz.  I already have it working on the hardware
but there is some code refactoring required before I can submit it again
for review.

Damien

[-- Attachment #2: mbox1-spdif-3.patch --]
[-- Type: text/x-patch, Size: 6592 bytes --]

>From 39642d6806d8b19612b5e1e95b8538927af1b273 Mon Sep 17 00:00:00 2001
From: Damien Zammit <damien@zamaudio.com>
Date: Fri, 31 Oct 2014 12:44:25 +1100
Subject: [PATCH] snd-usb-audio: Add mixer control for Digidesign Mbox 1 clock
 source

This patch provides a mixer control for selecting the clock source of
the Digidesign Mbox 1 to either internal clock or S/PDIF external.
Trial and error and bus snooping were the only way to get this
information, but it works on the hardware.

Signed-off-by: Damien Zammit <damien@zamaudio.com>
---
 sound/usb/mixer.h        |   1 +
 sound/usb/mixer_maps.c   |   9 +++
 sound/usb/mixer_quirks.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 187 insertions(+)

diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index 73b1f64..5ab6935 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -23,6 +23,7 @@ struct usb_mixer_interface {
 
 	u8 audigy2nx_leds[3];
 	u8 xonar_u1_status;
+	u8 mbox1_status;
 };
 
 #define MAX_CHANNELS	16	/* max logical channels */
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index d1d72ff..9ee3fc2 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -179,6 +179,11 @@ static struct usbmix_name_map audigy2nx_map[] = {
 	{ 0 } /* terminator */
 };
 
+static struct usbmix_name_map mbox1_map[] = {
+	{ 1, "Control" },
+	{ 0 } /* terminator */
+};
+
 static struct usbmix_selector_map c400_selectors[] = {
 	{
 		.id = 0x80,
@@ -416,6 +421,10 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
 		.map = aureon_51_2_map,
 	},
 	{
+		.id = USB_ID(0x0dba, 0x1000),
+		.map = mbox1_map,
+	},
+	{
 		.id = USB_ID(0x13e5, 0x0001),
 		.map = scratch_live_map,
 		.ignore_ctl_error = 1,
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 3980bf5..716c32c 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -565,6 +565,176 @@ static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
 	return 0;
 }
 
+/* Digidesign Mbox 1 clock source switch (internal/spdif) */
+
+struct snd_mbox1_switch_priv_val {
+	struct usb_mixer_interface *mixer;
+	int cached_value;
+	int is_cached;
+};
+
+static int snd_mbox1_switch_get(struct snd_kcontrol *kctl,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_mbox1_switch_priv_val *pval;
+	unsigned char value;
+
+	value = 0x00;
+
+	pval = (struct snd_mbox1_switch_priv_val *)
+		kctl->private_value;
+
+	if (pval->is_cached) {
+		ucontrol->value.enumerated.item[0] = pval->cached_value;
+		return 0;
+	}
+
+	ucontrol->value.enumerated.item[0] = value;
+	pval->cached_value = value;
+	pval->is_cached = 1;
+
+	return 0;
+}
+
+static int snd_mbox1_switch_put(struct snd_kcontrol *kctl,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_usb_audio *chip;
+	struct snd_mbox1_switch_priv_val *pval;
+
+	struct usb_mixer_interface *mixer;
+	int changed, cur_val, err, new_val;
+	unsigned char value[2];
+	unsigned char buff[3];
+
+	changed = 0;
+	value[0] = 0x00;
+	value[1] = 0x00;
+
+	pval = (struct snd_mbox1_switch_priv_val *)
+		kctl->private_value;
+	cur_val = pval->cached_value;
+	new_val = ucontrol->value.enumerated.item[0];
+
+	mixer = (struct usb_mixer_interface *) pval->mixer;
+	if (snd_BUG_ON(!mixer))
+		return -EINVAL;
+
+	chip = (struct snd_usb_audio *) mixer->chip;
+	if (snd_BUG_ON(!chip))
+		return -EINVAL;
+
+	if (!pval->is_cached) {
+		cur_val = value[0];
+		pval->cached_value = cur_val;
+		pval->is_cached = 1;
+	}
+	/* update value if needed */
+	if (cur_val != new_val) {
+		value[0] = new_val;
+		value[1] = 0;
+		down_read(&mixer->chip->shutdown_rwsem);
+		if (mixer->chip->shutdown) {
+			err = -ENODEV;
+		} else {
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			if (new_val == 0) {
+				buff[0] = 0x80;
+				buff[1] = 0xbb;
+				buff[2] = 0x00;
+			} else {
+				buff[0] = buff[1] = buff[2] = 0;
+			}
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_sndctrlpipe(mixer->chip->dev, 0), 0x1,
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3);
+			if (err < 0)
+				return err;
+			err = snd_usb_ctl_msg(mixer->chip->dev,
+				usb_rcvctrlpipe(mixer->chip->dev, 0), 0x81,
+				USB_DIR_IN |
+				USB_TYPE_CLASS |
+				USB_RECIP_ENDPOINT, 0x100, 0x2, buff, 3);
+			if (err < 0)
+				return err;
+		}
+		up_read(&mixer->chip->shutdown_rwsem);
+		if (err < 0)
+			return err;
+
+		pval->cached_value = new_val;
+		pval->is_cached = 1;
+		changed = 1;
+	}
+
+	return changed;
+}
+
+static int snd_mbox1_switch_info(struct snd_kcontrol *kcontrol,
+				 struct snd_ctl_elem_info *uinfo)
+{
+	static const char *const texts[2] = {
+		"Internal",
+		"S/PDIF"
+	};
+
+	return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
+}
+
+static int snd_mbox1_create_sync_switch(struct usb_mixer_interface *mixer)
+{
+	static struct snd_kcontrol_new template = {
+		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+		.name = "Clock Source",
+		.index = 0,
+		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+		.info = snd_mbox1_switch_info,
+		.get = snd_mbox1_switch_get,
+		.put = snd_mbox1_switch_put
+	};
+
+	struct snd_kcontrol *kctl;
+	struct snd_mbox1_switch_priv_val *pval;
+
+	pval = kzalloc(sizeof(*pval), GFP_KERNEL);
+	if (!pval)
+		return -ENOMEM;
+
+	pval->cached_value = 0;
+	pval->is_cached = 0;
+	pval->mixer = mixer;
+
+	template.private_value = (unsigned long) pval;
+	kctl = snd_ctl_new1(&template, mixer->chip);
+	if (!kctl) {
+		kfree(pval);
+		return -ENOMEM;
+	}
+
+	return snd_ctl_add(mixer->chip->card, kctl);
+}
+
 /* Native Instruments device quirks */
 
 #define _MAKE_NI_CONTROL(bRequest,wIndex) ((bRequest) << 16 | (wIndex))
@@ -1605,6 +1775,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
 					      snd_audigy2nx_proc_read);
 		break;
 
+	/* Digidesign Mbox 1 */
+	case USB_ID(0x0dba, 0x1000):
+		err = snd_mbox1_create_sync_switch(mixer);
+		if (err < 0)
+			break;
+		break;
+
 	/* EMU0204 */
 	case USB_ID(0x041e, 0x3f19):
 		err = snd_emu0204_controls_create(mixer);
-- 
1.9.1


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source
  2014-10-31  4:28     ` Takashi Sakamoto
  2014-10-31  4:45       ` Damien Zammit
@ 2014-10-31  5:13       ` Takashi Sakamoto
  1 sibling, 0 replies; 6+ messages in thread
From: Takashi Sakamoto @ 2014-10-31  5:13 UTC (permalink / raw)
  To: Damien Zammit; +Cc: alsa-devel

On Oct 31 2014 13:28, Takashi Sakamoto wrote:
> 2.please use 'const char *const' for immutable arrays for immutable
> strings:
>  > +       static const char *texts[2] = {"Internal",
>  > +                                      "S/PDIF"
>  > +       };
>  > +

Oops. I mistook to use immutable as 'may not be changed'. It should be 
'mutable'...


Regards

Takashi Sakamoto
o-takashi@sakamocchi.jp

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-31  5:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-31  1:57 [PATCH] usb-audio: Add mixer control for Digidesign Mbox 1 clock source Damien Zammit
2014-10-31  3:29 ` Takashi Sakamoto
2014-10-31  4:02   ` Damien Zammit
2014-10-31  4:28     ` Takashi Sakamoto
2014-10-31  4:45       ` Damien Zammit
2014-10-31  5:13       ` Takashi Sakamoto

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.