Commit 7f4d8dbe authored by Geoffrey D. Bennett's avatar Geoffrey D. Bennett Committed by Takashi Iwai

ALSA: scarlett2: Refactor scarlett2_usb_set_config()

Pull out common code from scarlett2_usb_set_config() and create
scarlett2_usb_set_data() and scarlett2_usb_activate_config().
Signed-off-by: default avatarGeoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/257eca0b07708339133f916930e388057d116eb8.1703444932.git.g@b4.vuSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 43222a61
......@@ -1583,20 +1583,52 @@ static void scarlett2_config_save_work(struct work_struct *work)
scarlett2_config_save(private->mixer);
}
/* Send a USB message to set a SCARLETT2_CONFIG_* parameter */
static int scarlett2_usb_set_config(
/* Send a SCARLETT2_USB_SET_DATA command.
* offset: location in the device's data space
* size: size in bytes of the value (1, 2, 4)
*/
static int scarlett2_usb_set_data(
struct usb_mixer_interface *mixer,
int config_item_num, int index, int value)
int offset, int size, int value)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_config *config_item =
&private->config_set->items[config_item_num];
struct {
__le32 offset;
__le32 bytes;
__le32 size;
__le32 value;
} __packed req;
__le32 req2;
req.offset = cpu_to_le32(offset);
req.size = cpu_to_le32(size);
req.value = cpu_to_le32(value);
return scarlett2_usb(private->mixer, SCARLETT2_USB_SET_DATA,
&req, sizeof(u32) * 2 + size, NULL, 0);
}
/* Send a SCARLETT2_USB_DATA_CMD command.
* Configuration changes require activation with this after they have
* been uploaded by a previous SCARLETT2_USB_SET_DATA.
* The value for activate needed is determined by the configuration
* item.
*/
static int scarlett2_usb_activate_config(
struct usb_mixer_interface *mixer, int activate)
{
__le32 req;
req = cpu_to_le32(activate);
return scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
&req, sizeof(req), NULL, 0);
}
/* Send USB messages to set a SCARLETT2_CONFIG_* parameter */
static int scarlett2_usb_set_config(
struct usb_mixer_interface *mixer,
int config_item_num, int index, int value)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_config *config_item =
&private->config_set->items[config_item_num];
int offset, size;
int err;
......@@ -1638,19 +1670,12 @@ static int scarlett2_usb_set_config(
}
/* Send the configuration parameter data */
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 + size,
NULL, 0);
err = scarlett2_usb_set_data(mixer, offset, size, value);
if (err < 0)
return err;
/* Activate the change */
req2 = cpu_to_le32(config_item->activate);
err = scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
&req2, sizeof(req2), NULL, 0);
err = scarlett2_usb_activate_config(mixer, config_item->activate);
if (err < 0)
return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment