All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Geoffrey D. Bennett" <g@b4.vu>
To: alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.de>
Cc: Hin-Tak Leung <htl10@users.sourceforge.net>,
	Vladimir Sadovnikov <sadko4u@gmail.com>
Subject: [PATCH 06/17] ALSA: usb-audio: scarlett2: Allow bit-level access to config
Date: Wed, 23 Jun 2021 02:32:25 +0930	[thread overview]
Message-ID: <4e54e9e106ec7029c1a668c51b4fc769a7eb4ed0.1624379707.git.g@b4.vu> (raw)
In-Reply-To: <cover.1624379707.git.g@b4.vu>

Add support for accessing configuration values when multiple values
are stored in one byte. Needed by the upcoming Solo and 2i2 Gen 3
support.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
---
 sound/usb/mixer_scarlett_gen2.c | 68 ++++++++++++++++++++++++++-------
 1 file changed, 55 insertions(+), 13 deletions(-)

diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
index 7a5346c68603..08e7b687484e 100644
--- a/sound/usb/mixer_scarlett_gen2.c
+++ b/sound/usb/mixer_scarlett_gen2.c
@@ -814,7 +814,7 @@ enum {
 };
 
 /* Location, size, and activation command number for the configuration
- * parameters
+ * parameters. Size is in bits and may be 1, 8, or 16.
  */
 struct scarlett2_config {
 	u8 offset;
@@ -825,25 +825,25 @@ struct scarlett2_config {
 static const struct scarlett2_config
 		scarlett2_config_items[SCARLETT2_CONFIG_COUNT] = {
 	[SCARLETT2_CONFIG_DIM_MUTE] = {
-		.offset = 0x31, .size = 1, .activate = 2 },
+		.offset = 0x31, .size = 8, .activate = 2 },
 
 	[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
-		.offset = 0x34, .size = 2, .activate = 1 },
+		.offset = 0x34, .size = 16, .activate = 1 },
 
 	[SCARLETT2_CONFIG_MUTE_SWITCH] = {
-		.offset = 0x5c, .size = 1, .activate = 1 },
+		.offset = 0x5c, .size = 8, .activate = 1 },
 
 	[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
-		.offset = 0x66, .size = 1, .activate = 3 },
+		.offset = 0x66, .size = 8, .activate = 3 },
 
 	[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
-		.offset = 0x7c, .size = 1, .activate = 7 },
+		.offset = 0x7c, .size = 8, .activate = 7 },
 
 	[SCARLETT2_CONFIG_PAD_SWITCH] = {
-		.offset = 0x84, .size = 1, .activate = 8 },
+		.offset = 0x84, .size = 8, .activate = 8 },
 
 	[SCARLETT2_CONFIG_MSD_SWITCH] = {
-		.offset = 0x9d, .size = 1, .activate = 6 },
+		.offset = 0x9d, .size = 8, .activate = 6 },
 };
 
 /* proprietary request/response format */
@@ -1008,9 +1008,25 @@ static int scarlett2_usb_get_config(
 {
 	const struct scarlett2_config *config_item =
 		&scarlett2_config_items[config_item_num];
-	int size = config_item->size * count;
+	int size, err, i;
+	u8 value;
 
-	return scarlett2_usb_get(mixer, config_item->offset, buf, size);
+	/* For byte-sized parameters, retrieve directly into buf */
+	if (config_item->size >= 8) {
+		size = config_item->size / 8 * count;
+		return scarlett2_usb_get(mixer, config_item->offset, buf, size);
+	}
+
+	/* For bit-sized parameters, retrieve into value */
+	err = scarlett2_usb_get(mixer, config_item->offset, &value, 1);
+	if (err < 0)
+		return err;
+
+	/* then unpack from value into buf[] */
+	for (i = 0; i < 8 && i < count; i++, value >>= 1)
+		*(u8 *)buf++ = value & 1;
+
+	return 0;
 }
 
 /* Send SCARLETT2_USB_DATA_CMD SCARLETT2_USB_CONFIG_SAVE */
@@ -1047,18 +1063,44 @@ static int scarlett2_usb_set_config(
 		__le32 value;
 	} __packed req;
 	__le32 req2;
+	int offset, size;
 	int err;
 	struct scarlett2_data *private = mixer->private_data;
 
 	/* Cancel any pending NVRAM save */
 	cancel_delayed_work_sync(&private->work);
 
+	/* Convert config_item->size in bits to size in bytes and
+	 * calculate offset
+	 */
+	if (config_item->size >= 8) {
+		size = config_item->size / 8;
+		offset = config_item->offset + index * size;
+
+	/* If updating a bit, retrieve the old value, set/clear the
+	 * bit as needed, and update value
+	 */
+	} else {
+		u8 tmp;
+
+		size = 1;
+		offset = config_item->offset;
+
+		scarlett2_usb_get(mixer, offset, &tmp, 1);
+		if (value)
+			tmp |= (1 << index);
+		else
+			tmp &= ~(1 << index);
+
+		value = tmp;
+	}
+
 	/* Send the configuration parameter data */
-	req.offset = cpu_to_le32(config_item->offset + index * config_item->size);
-	req.bytes = cpu_to_le32(config_item->size);
+	req.offset = cpu_to_le32(offset);
+	req.bytes = cpu_to_le32(size);
 	req.value = cpu_to_le32(value);
 	err = scarlett2_usb(mixer, SCARLETT2_USB_SET_DATA,
-			    &req, sizeof(u32) * 2 + config_item->size,
+			    &req, sizeof(u32) * 2 + size,
 			    NULL, 0);
 	if (err < 0)
 		return err;
-- 
2.31.1


  parent reply	other threads:[~2021-06-22 17:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 17:00 [PATCH V3 00/17] Add Scarlett Gen 3 support Geoffrey D. Bennett
2021-06-22 17:00 ` [PATCH 01/17] ALSA: usb-audio: scarlett2: Fix wrong resume call Geoffrey D. Bennett
2021-06-22 19:42   ` Takashi Iwai
2021-06-23  1:03     ` Geoffrey D. Bennett
2021-06-23  6:39       ` Takashi Iwai
2021-06-25  2:09         ` Hin-Tak Leung
2021-06-22 17:01 ` [PATCH 02/17] ALSA: usb-audio: scarlett2: Add Gen 3 mixer support Geoffrey D. Bennett
2021-06-22 17:01 ` [PATCH 03/17] ALSA: usb-audio: scarlett2: Add support for "input-other" notify Geoffrey D. Bennett
2021-06-22 17:01 ` [PATCH 04/17] ALSA: usb-audio: scarlett2: Add Gen 3 MSD mode switch Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 05/17] ALSA: usb-audio: scarlett2: Move get config above set config Geoffrey D. Bennett
2021-06-22 17:02 ` Geoffrey D. Bennett [this message]
2021-06-22 17:02 ` [PATCH 07/17] ALSA: usb-audio: scarlett2: Add support for Solo and 2i2 Gen 3 Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 08/17] ALSA: usb-audio: scarlett2: Add "air" switch support Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 09/17] ALSA: usb-audio: scarlett2: Add phantom power " Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 10/17] ALSA: usb-audio: scarlett2: Add direct monitor support Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 11/17] ALSA: usb-audio: scarlett2: Label 18i8 Gen 3 line outputs correctly Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 12/17] ALSA: usb-audio: scarlett2: Split up sw_hw_enum_ctl_put() Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 13/17] ALSA: usb-audio: scarlett2: Add sw_hw_ctls and mux_ctls Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 14/17] ALSA: usb-audio: scarlett2: Update mux controls to allow updates Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 15/17] ALSA: usb-audio: scarlett2: Add speaker switching support Geoffrey D. Bennett
2021-06-22 17:04 ` [PATCH 16/17] ALSA: usb-audio: scarlett2: Update get_config to do endian conversion Geoffrey D. Bennett
2021-06-22 17:04 ` [PATCH 17/17] ALSA: usb-audio: scarlett2: Add support for the talkback feature Geoffrey D. Bennett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e54e9e106ec7029c1a668c51b4fc769a7eb4ed0.1624379707.git.g@b4.vu \
    --to=g@b4.vu \
    --cc=alsa-devel@alsa-project.org \
    --cc=htl10@users.sourceforge.net \
    --cc=sadko4u@gmail.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.