Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp439178pxf; Thu, 25 Mar 2021 07:27:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCC3mfaBHbM8dZsEOID52GJCD/7Jl7Q8rxn+snoGhdkLuq5vncM8/8BtXFyffzLJxfDOFA X-Received: by 2002:a17:906:39cf:: with SMTP id i15mr9752969eje.534.1616682442064; Thu, 25 Mar 2021 07:27:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616682442; cv=none; d=google.com; s=arc-20160816; b=xKNk7UvyoYQGGs/yh2K764QbVNBBH5kPDDwAkE7Anj5H7ieyEywLclXWueL7EIcqDt bzEHwGoN4XQcbYhnXRYpc1ZIraflShObRX09UN7XOq3vYwi7AAlw54q3otfWBDGJu2V8 b7medEVggV+6uPRCUWN5JvIGo/7tZWBXUfWMZpmFpFghhgMoiyp8hLRObnkzMpFywv9G 8GOhADzyxEYUZSa5/xf2kstdxgKSoKWtuj1m2dWjfZLi2cqzcuCz8UNvT8Ml+2xt081Q 7CnC8uUjoCeHbvtJKXsaEtSggCbkG0FU8YjTAcNabaW6OX01cYB7lhU2Hr2cmda6M2YU w+Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=C6GP4Z3q3QGtdVDSvOH0+jTBijfgDZ/MgAqVve/FMLw=; b=duEWTn2QDxRH61WWxyeBu1oQLu3DQLopA4ca9aliXOPWn8Qb5qS/uMYyFzKvcMlip8 gu50vmwG7kebCVJmuxEnDa5Jqp6UzLO5b32xDr+XuayYO1XxplVuL8NohQwrLpj59jY+ 8a9mwwbF8jJCNDnvpCJUvJST8OFPVOIo6wt0JqFRx+kSkLIrYKLeyWxY6JGUsNz01a07 NsHzhdsaI8KVqFoyJWhq8NrcltE+QMNllOvf1uKHkWd837BgNP8poPFIAtz//6d8NPio QOOLWZ0LhJ+iCnmIViFyfDYKFs7vuSs9VIFqiJh9j/bZDw/en655q5GyNfAOkrrP8WJl ylbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b17si4315069eds.443.2021.03.25.07.26.57; Thu, 25 Mar 2021 07:27:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231208AbhCYOZY (ORCPT + 99 others); Thu, 25 Mar 2021 10:25:24 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58663 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbhCYOY5 (ORCPT ); Thu, 25 Mar 2021 10:24:57 -0400 Received: from mail-lj1-f197.google.com ([209.85.208.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lPQuu-0001Ky-GW for linux-kernel@vger.kernel.org; Thu, 25 Mar 2021 14:24:56 +0000 Received: by mail-lj1-f197.google.com with SMTP id d16so3127027lja.12 for ; Thu, 25 Mar 2021 07:24:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=C6GP4Z3q3QGtdVDSvOH0+jTBijfgDZ/MgAqVve/FMLw=; b=ZPSt7QEn1TP1cP1rXOiFZxgperXo9wqZOWk4jgtsxwiepOQi/b18Yn3L6f75CjaESw kEFoM2Lh1Bn8h5khGzbir1OCl9HmSkjLDwkyCAluyZACB63bXyQbM+BAKRnPp8Sph0p/ GTbxggmS/QQcJEDViPHTGFxG4qoAIT1Im1toF/UJ6fgMQ/eJ9SzzRFe1FVGbbl7V2vo2 9PJEdZ+g7kpvYdJ2L8DI5ippDRa07/0eVmibBStPMDiY1EfMKCpb4NxW27wKrgD9xVh3 3rZ4xeAvnYWWoC/W/76gjY+bVbj+rvVAbeB+wcisyE+zomJZHu0wxhB90xsJWWvJ/DzG RX1w== X-Gm-Message-State: AOAM533+KacGNIvB+o0bJHV64JFRKDTEKxQaPoMxBJdmx7NALvNry+Ag z7sMMP6bzPeB0voIKaEp/I3bhekXrB4AfZJfB1e647p1by1kf/hazr4CnsORpcfvKEj5yqYwLun Z7+XQwKXg0/nP9H16Sg1hW5ss1RKMlHZfflmZ1goxgFAe0Hfzec2AqHqsOA== X-Received: by 2002:a05:6512:1084:: with SMTP id j4mr5089761lfg.194.1616682295897; Thu, 25 Mar 2021 07:24:55 -0700 (PDT) X-Received: by 2002:a05:6512:1084:: with SMTP id j4mr5089742lfg.194.1616682295598; Thu, 25 Mar 2021 07:24:55 -0700 (PDT) MIME-Version: 1.0 References: <20210325121250.133009-1-kai.heng.feng@canonical.com> <20210325121250.133009-2-kai.heng.feng@canonical.com> In-Reply-To: From: Kai-Heng Feng Date: Thu, 25 Mar 2021 22:24:42 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] ALSA: usb-audio: Check connector value on resume To: Takashi Iwai Cc: Takashi Iwai , Jaroslav Kysela , Pavel Skripkin , Chris Chiu , Mark Brown , Lars-Peter Clausen , Tom Yan , Joe Perches , "moderated list:SOUND" , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 25, 2021 at 9:55 PM Kai-Heng Feng wrote: > > On Thu, Mar 25, 2021 at 9:41 PM Takashi Iwai wrote: > > > > On Thu, 25 Mar 2021 13:12:48 +0100, > > Kai-Heng Feng wrote: > > > > > > Rear Mic on Lenovo P620 cannot record after S3, despite that there's no > > > error and the other two functions of the USB audio, Line In and Line > > > Out, work just fine. > > > > > > The mic starts to work again after running userspace app like "alsactl > > > store". Following the lead, the evidence shows that as soon as connector > > > status is queried, the mic can work again. > > > > > > So also check connector value on resume to "wake up" the USB audio to > > > make it functional. > > > > > > This can be device specific, however I think this generic approach may > > > benefit more than one device. > > > > > > While at it, also remove reset-resume path to consolidate mixer resume > > > path. > > > > > > Signed-off-by: Kai-Heng Feng > > > --- > > > v2: > > > - Remove reset-resume. > > > - Fold the connector checking to the mixer resume callback. > > > > That's not what I meant exactly... I meant to put both into the > > single resume callback, but handle each part conditionally depending > > on reset_resume argument. > > OK, I get what you mean now. > > > > > But this turned out to need more changes in mixer_quirks.c > > unnecessarily. Maybe adding the two resume functions is a better > > approach in the end, but not for the specific connection thing but > > generically both resume and reset_resume callbacks. Something like > > below. > > This approach looks good. Let me send another one. Actually, it works really well and I don't I think I should send the code you wrote. Is it possible to push your version with my commit log, and with my tested tag? Tested-by: Kai-Heng Feng > Kai-Heng > > > > > > > thanks, > > > > Takashi > > > > > > diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c > > index b004b2e63a5d..1dab281bb269 100644 > > --- a/sound/usb/mixer.c > > +++ b/sound/usb/mixer.c > > @@ -3615,20 +3615,43 @@ static int restore_mixer_value(struct usb_mixer_elem_list *list) > > return 0; > > } > > > > +static int default_mixer_resume(struct usb_mixer_elem_list *list) > > +{ > > + struct usb_mixer_elem_info *cval = mixer_elem_list_to_info(list); > > + > > + /* get connector value to "wake up" the USB audio */ > > + if (cval->val_type == USB_MIXER_BOOLEAN && cval->channels == 1) > > + get_connector_value(cval, NULL, NULL); > > + > > + return 0; > > +} > > + > > +static int default_mixer_reset_resume(struct usb_mixer_elem_list *list) > > +{ > > + int err = default_mixer_resume(list); > > + > > + if (err < 0) > > + return err; > > + return restore_mixer_value(list); > > +} > > + > > int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume) > > { > > struct usb_mixer_elem_list *list; > > + usb_mixer_elem_resume_func_t f; > > int id, err; > > > > - if (reset_resume) { > > - /* restore cached mixer values */ > > - for (id = 0; id < MAX_ID_ELEMS; id++) { > > - for_each_mixer_elem(list, mixer, id) { > > - if (list->resume) { > > - err = list->resume(list); > > - if (err < 0) > > - return err; > > - } > > + /* restore cached mixer values */ > > + for (id = 0; id < MAX_ID_ELEMS; id++) { > > + for_each_mixer_elem(list, mixer, id) { > > + if (reset_resume) > > + f = list->reset_resume; > > + else > > + f = list->resume; > > + if (f) { > > + err = list->resume(list); > > + if (err < 0) > > + return err; > > } > > } > > } > > @@ -3647,6 +3670,7 @@ void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list, > > list->id = unitid; > > list->dump = snd_usb_mixer_dump_cval; > > #ifdef CONFIG_PM > > - list->resume = restore_mixer_value; > > + list->resume = default_mixer_resume; > > + list->reset_resume = default_mixer_reset_resume; > > #endif > > } > > diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h > > index c29e27ac43a7..e5a01f17bf3c 100644 > > --- a/sound/usb/mixer.h > > +++ b/sound/usb/mixer.h > > @@ -69,6 +69,7 @@ struct usb_mixer_elem_list { > > bool is_std_info; > > usb_mixer_elem_dump_func_t dump; > > usb_mixer_elem_resume_func_t resume; > > + usb_mixer_elem_resume_func_t reset_resume; > > }; > > > > /* iterate over mixer element list of the given unit id */ > > diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c > > index ffd922327ae4..b7f9c2fded05 100644 > > --- a/sound/usb/mixer_quirks.c > > +++ b/sound/usb/mixer_quirks.c > > @@ -151,7 +151,7 @@ static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer, > > *listp = list; > > list->mixer = mixer; > > list->id = id; > > - list->resume = resume; > > + list->reset_resume = resume; > > kctl = snd_ctl_new1(knew, list); > > if (!kctl) { > > kfree(list);