ALSA: usb-audio: Reset Blue Yeti firmware 0.20 after system resume
PATCH v2 1/1 ALSA: usb-audio: Reset Blue Yeti firmware 0.20 after system resume
From: "Jasmeet (Jazz) Bhatia" <[email protected]>
Blue Yeti Classic microphones (046d:0ab7, bcdDevice 0x0020) may remain enumerated after system suspend/resume while capture fails with -EIO. USB resets, unbind/rebind and USB_QUIRK_RESET_RESUME do not recover capture on this firmware.
Send the device-specific AudioControl SET_CUR command to restart the Yeti's MCU and USB logic, allowing it to disconnect and re-enumerate. Since the command disconnects the device, defer it to a freezable work item after the last ALSA interface completes its system-resume bookkeeping instead of sending it inline from the resume callback.
Keep a single work item in the card, avoid overlapping reset requests, and serialize scheduling against the disconnect shutdown transition. Drain the work item before ALSA resources are released. On a failed control transfer, allow a later system resume to retry while the device remains connected, without immediately requeuing the running work. Disable runtime autosuspend for the affected firmware so that a runtime-suspended interface does not bypass this system-resume path.
On the affected device, five consecutive system suspend/resume cycles caused automatic disconnect and re-enumeration, with capture working without a manual replug. Unplug/replug and suspend while unplugged followed by reconnect were also tested. ftrace confirmed that the firmware-reset worker completed in about 2 ms.
---
v2:
- Rebase onto ALSA commit 01f46c3244c9.
- Use one embedded work item per card instead of dynamically allocating work and managing module references.
- Queue after ALSA system-resume bookkeeping completes.
- Synchronize reset scheduling with shutdown and drain work during disconnect.
- Retry failed transfers on a later system resume.
- Disable autosuspend only for the affected firmware.
v1: https://lore.kernel.org/lkml/[email protected]/
sound/usb/card.c | 17 +++++++++++++- sound/usb/quirks.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/quirks.h | 4 ++++ sound/usb/usbaudio.h | 6 ++++++ 4 files changed, 87 insertions(+), 1 deletion(-)
sound/usb/card.c +16 -1
@@ -756,6 +756,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,atomic_set (&chip->active,1 );/* avoid autopm during probing */ snd_refcount_init (&chip->usage_count);atomic_set (&chip->shutdown,0 ); +snd_usb_init_resume_quirk (chip); chip->usb_id = usb_id;INIT_LIST_HEAD (&chip->pcm_list);
@@ -767,6 +768,8 @@ static int snd_usb_audio_create(struct usb_interface *intf,INIT_LIST_HEAD (&chip->mixer_list);snd_usb_init_quirk_flags (idx, chip); +if (snd_usb_yeti_fw_020 (dev)) + chip->quirk_flags |=QUIRK_FLAG_DISABLE_AUTOSUSPEND ; card->private_free = snd_usb_audio_free;
@@ -1104,12 +1107,20 @@ static bool __usb_audio_disconnect(struct usb_interface *intf,struct snd_usb_audio *chip, struct snd_card *card) { + unsigned long flags; +bool first_disconnect; +guard (mutex)(®ister_mutex);if (platform_ops && platform_ops->disconnect_cb) platform_ops->disconnect_cb (chip); -if (atomic_inc_return (&chip->shutdown) ==1 ) { +/* Exclude new reset work before waiting for pending work to exit. */ +spin_lock_irqsave (&chip->resume_reset_lock, flags); + first_disconnect =atomic_inc_return (&chip->shutdown) ==1 ; +spin_unlock_irqrestore (&chip->resume_reset_lock, flags); +if (first_disconnect) { +cancel_work_sync (&chip->resume_reset_work);/* wait until all pending tasks done; * they are protected by snd_usb_lock_shutdown() */
@@ -1248,6 +1259,7 @@ static int usb_audio_resume(struct usb_interface *intf)struct snd_usb_stream *as;struct usb_mixer_interface *mixer;struct list_head *p; +bool system_resume = false;int err =0 ;if (chip ==USB_AUDIO_IFACE_UNUSED )
@@ -1291,12 +1303,15 @@ static int usb_audio_resume(struct usb_interface *intf) out:if (chip->num_suspended_intf == chip->system_suspend) {snd_power_change_state (chip->card,SNDRV_CTL_POWER_D0 ); + system_resume = chip->system_suspend !=0 ; chip->system_suspend =0 ; } chip->num_suspended_intf--; err_out:atomic_dec (&chip->active);/* allow autopm after this point */ +if (system_resume) +snd_usb_apply_resume_quirk (chip);return err; }
sound/usb/quirks.c +61 -0
73 lines not on this page · raw message
sound/usb/quirks.h +4 -0
@@ -15,6 +15,10 @@ int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,int iface, int altno); +bool snd_usb_yeti_fw_020 (struct usb_device *dev); +void snd_usb_init_resume_quirk (struct snd_usb_audio *chip); +void snd_usb_apply_resume_quirk (struct snd_usb_audio *chip); + int snd_usb_apply_boot_quirk(struct usb_device *dev, struct usb_interface *intf, const struct snd_usb_audio_quirk *quirk,
sound/usb/usbaudio.h +6 -0
@@ -7,6 +7,8 @@* Copyright (c) 2002 by Takashi Iwai <[email protected]> */ +#include <linux/spinlock.h> +#include <linux/workqueue.h> #include <sound/core.h> /* handling of USB vendor/product ID pairs as 32-bit numbers */
@@ -43,6 +45,10 @@ struct snd_usb_audio {unsigned int system_suspend;atomic_t active;atomic_t shutdown; +/* Protects reset queueing against concurrent device shutdown. */ +spinlock_t resume_reset_lock; +struct work_struct resume_reset_work; +bool resume_reset_queued;struct snd_refcount usage_count;u64 quirk_flags; unsigned int need_delayed_register:1; /* warn for delayed registration */
Signature · 2 lines
2.47.3 base-commit: 01f46c3244c9df036f751d12e4d2037a029f3891