Commit d9b63123 authored by Geoffrey D. Bennett's avatar Geoffrey D. Bennett Committed by Takashi Iwai
Browse files

ALSA: scarlett2: Split input_other into level/pad/air/phantom



Gen 2/3 devices have a single notification value for "input other"
changes. Gen 4 has separate notification values for level, pad, air,
and phantom power changes. Therefore, split the input_other_updated
field and the scarlett2_update_input_other() function into the four
components so that they can be handled separately later.

Signed-off-by: default avatarGeoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/a1a1d190659d56689792aa20ceeb53a6175171ad.1703444932.git.g@b4.vu


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ad517460
Loading
Loading
Loading
Loading
+140 −58
Original line number Diff line number Diff line
@@ -685,7 +685,10 @@ struct scarlett2_data {
	u8 sync_updated;
	u8 vol_updated;
	u8 dim_mute_updated;
	u8 input_other_updated;
	u8 input_level_updated;
	u8 input_pad_updated;
	u8 input_air_updated;
	u8 input_phantom_updated;
	u8 monitor_other_updated;
	u8 mux_updated;
	u8 speaker_switching_switched;
@@ -2687,57 +2690,20 @@ static const struct snd_kcontrol_new scarlett2_sw_hw_enum_ctl = {

/*** Line Level/Instrument Level Switch Controls ***/

static int scarlett2_update_input_other(struct usb_mixer_interface *mixer)
static int scarlett2_update_input_level(struct usb_mixer_interface *mixer)
{
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;

	private->input_other_updated = 0;
	private->input_level_updated = 0;

	if (info->level_input_count) {
		int err = scarlett2_usb_get_config(
	if (!info->level_input_count)
		return 0;

	return scarlett2_usb_get_config(
		mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
		info->level_input_count + info->level_input_first,
		private->level_switch);
		if (err < 0)
			return err;
	}

	if (info->pad_input_count) {
		int err = scarlett2_usb_get_config(
			mixer, SCARLETT2_CONFIG_PAD_SWITCH,
			info->pad_input_count, private->pad_switch);
		if (err < 0)
			return err;
	}

	if (info->air_input_count) {
		int err = scarlett2_usb_get_config(
			mixer, SCARLETT2_CONFIG_AIR_SWITCH,
			info->air_input_count, private->air_switch);
		if (err < 0)
			return err;
	}

	if (info->phantom_count) {
		int err = scarlett2_usb_get_config(
			mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
			info->phantom_count, private->phantom_switch);
		if (err < 0)
			return err;

		if (scarlett2_has_config_item(
				private,
				SCARLETT2_CONFIG_PHANTOM_PERSISTENCE)) {
			err = scarlett2_usb_get_config(
				mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
				1, &private->phantom_persistence);
			if (err < 0)
				return err;
		}
	}

	return 0;
}

static int scarlett2_level_enum_ctl_info(struct snd_kcontrol *kctl,
@@ -2768,8 +2734,8 @@ static int scarlett2_level_enum_ctl_get(struct snd_kcontrol *kctl,
		goto unlock;
	}

	if (private->input_other_updated) {
		err = scarlett2_update_input_other(mixer);
	if (private->input_level_updated) {
		err = scarlett2_update_input_level(mixer);
		if (err < 0)
			goto unlock;
	}
@@ -2827,6 +2793,21 @@ static const struct snd_kcontrol_new scarlett2_level_enum_ctl = {

/*** Pad Switch Controls ***/

static int scarlett2_update_input_pad(struct usb_mixer_interface *mixer)
{
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;

	private->input_pad_updated = 0;

	if (!info->pad_input_count)
		return 0;

	return scarlett2_usb_get_config(
		mixer, SCARLETT2_CONFIG_PAD_SWITCH,
		info->pad_input_count, private->pad_switch);
}

static int scarlett2_pad_ctl_get(struct snd_kcontrol *kctl,
				 struct snd_ctl_elem_value *ucontrol)
{
@@ -2842,8 +2823,8 @@ static int scarlett2_pad_ctl_get(struct snd_kcontrol *kctl,
		goto unlock;
	}

	if (private->input_other_updated) {
		err = scarlett2_update_input_other(mixer);
	if (private->input_pad_updated) {
		err = scarlett2_update_input_pad(mixer);
		if (err < 0)
			goto unlock;
	}
@@ -2901,6 +2882,21 @@ static const struct snd_kcontrol_new scarlett2_pad_ctl = {

/*** Air Switch Controls ***/

static int scarlett2_update_input_air(struct usb_mixer_interface *mixer)
{
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;

	private->input_air_updated = 0;

	if (!info->air_input_count)
		return 0;

	return scarlett2_usb_get_config(
		mixer, SCARLETT2_CONFIG_AIR_SWITCH,
		info->air_input_count, private->air_switch);
}

static int scarlett2_air_ctl_get(struct snd_kcontrol *kctl,
				 struct snd_ctl_elem_value *ucontrol)
{
@@ -2916,8 +2912,8 @@ static int scarlett2_air_ctl_get(struct snd_kcontrol *kctl,
		goto unlock;
	}

	if (private->input_other_updated) {
		err = scarlett2_update_input_other(mixer);
	if (private->input_air_updated) {
		err = scarlett2_update_input_air(mixer);
		if (err < 0)
			goto unlock;
	}
@@ -2974,6 +2970,35 @@ static const struct snd_kcontrol_new scarlett2_air_ctl = {

/*** Phantom Switch Controls ***/

static int scarlett2_update_input_phantom(struct usb_mixer_interface *mixer)
{
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;
	int err;

	private->input_phantom_updated = 0;

	if (!info->phantom_count)
		return 0;

	err = scarlett2_usb_get_config(
		mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
		info->phantom_count, private->phantom_switch);
	if (err < 0)
		return err;

	if (scarlett2_has_config_item(private,
				      SCARLETT2_CONFIG_PHANTOM_PERSISTENCE)) {
		err = scarlett2_usb_get_config(
			mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
			1, &private->phantom_persistence);
		if (err < 0)
			return err;
	}

	return 0;
}

static int scarlett2_phantom_ctl_get(struct snd_kcontrol *kctl,
				     struct snd_ctl_elem_value *ucontrol)
{
@@ -2989,8 +3014,8 @@ static int scarlett2_phantom_ctl_get(struct snd_kcontrol *kctl,
		goto unlock;
	}

	if (private->input_other_updated) {
		err = scarlett2_update_input_other(mixer);
	if (private->input_phantom_updated) {
		err = scarlett2_update_input_phantom(mixer);
		if (err < 0)
			goto unlock;
	}
@@ -4598,7 +4623,19 @@ static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
			return 0;
	}

	err = scarlett2_update_input_other(mixer);
	err = scarlett2_update_input_level(mixer);
	if (err < 0)
		return err;

	err = scarlett2_update_input_pad(mixer);
	if (err < 0)
		return err;

	err = scarlett2_update_input_air(mixer);
	if (err < 0)
		return err;

	err = scarlett2_update_input_phantom(mixer);
	if (err < 0)
		return err;

@@ -4737,30 +4774,75 @@ static void scarlett2_notify_dim_mute(struct usb_mixer_interface *mixer)
				       &private->mute_ctls[i]->id);
}

/* Notify on "input other" change (level/pad/air) */
static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer)
/* Notify on input level switch change */
static void scarlett2_notify_input_level(struct usb_mixer_interface *mixer)
{
	struct snd_card *card = mixer->chip->card;
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;
	int i;

	private->input_other_updated = 1;
	private->input_level_updated = 1;

	for (i = 0; i < info->level_input_count; i++)
		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
			       &private->level_ctls[i]->id);
}

/* Notify on input pad switch change */
static void scarlett2_notify_input_pad(struct usb_mixer_interface *mixer)
{
	struct snd_card *card = mixer->chip->card;
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;
	int i;

	private->input_pad_updated = 1;

	for (i = 0; i < info->pad_input_count; i++)
		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
			       &private->pad_ctls[i]->id);
}

/* Notify on input air switch change */
static void scarlett2_notify_input_air(struct usb_mixer_interface *mixer)
{
	struct snd_card *card = mixer->chip->card;
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;
	int i;

	private->input_air_updated = 1;

	for (i = 0; i < info->air_input_count; i++)
		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
			       &private->air_ctls[i]->id);
}

/* Notify on input phantom switch change */
static void scarlett2_notify_input_phantom(struct usb_mixer_interface *mixer)
{
	struct snd_card *card = mixer->chip->card;
	struct scarlett2_data *private = mixer->private_data;
	const struct scarlett2_device_info *info = private->info;
	int i;

	private->input_phantom_updated = 1;

	for (i = 0; i < info->phantom_count; i++)
		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
			       &private->phantom_ctls[i]->id);
}

/* Notify on "input other" change (level/pad/air/phantom) */
static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer)
{
	scarlett2_notify_input_level(mixer);
	scarlett2_notify_input_pad(mixer);
	scarlett2_notify_input_air(mixer);
	scarlett2_notify_input_phantom(mixer);
}

/* Notify on "monitor other" change (direct monitor, speaker
 * switching, talkback)
 */