From patchwork Tue May 7 10:12:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 10932723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20B8B13AD for ; Tue, 7 May 2019 10:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E04628754 for ; Tue, 7 May 2019 10:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C73B2898B; Tue, 7 May 2019 10:31:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0BE3728987 for ; Tue, 7 May 2019 10:31:57 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5768C18A4; Tue, 7 May 2019 12:13:52 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5768C18A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557224082; bh=QvvDzMxeWJA7SGj0diSpZbFBLnuKpApJDYyEqKm6eXs=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ENsYTTfc4gso86M8xJvKpa9pV2x4/JN6aeXJrrSjyEUeUU0/5GijNPOZzXkiO3sM5 Hs6wrjWXsQsHFA1augr6w+bGaFAjLBWcCClSrDcdl7YMF8/OGEzCzu4amOXL6kQoZO uetWxQKjYawMApqZ0poVRiTxU7aEELWosi6GKGRQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E6968F896DA; Tue, 7 May 2019 12:13:00 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1CB58F896EC; Tue, 7 May 2019 12:12:59 +0200 (CEST) Received: from mail-yw1-xc49.google.com (mail-yw1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id CDB67F89682 for ; Tue, 7 May 2019 12:12:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CDB67F89682 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c4BkH8PB" Received: by mail-yw1-xc49.google.com with SMTP id b189so18017483ywa.19 for ; Tue, 07 May 2019 03:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=pEs0YAvpVnOXt4JVkdCiFZqbRy+rm3fq+3JWY10YEQU=; b=c4BkH8PBLGS+qBp4V6RPqreYoE57I8tSGB6i/7uwu3d9bUvWfPK1/Go0bNPO1+tqPb c88JPinlV84R0YG0zEW+TiCwYpp/ytQnWzvLgN7nH0DGgMhgEP5zXaeQ6iCmJm8kNWMY uG1xivpq4OIxoDhGiVtQ703eRRS9B1Eig4brGJCydv22CoAy/NIygwMhbex9K78eCiVo ZtebXkJrxlHI5PvHZLmX46Sie5Q2cLo6L9ubUtWqIUXLJYKlN3owNiiKtjuB43tgZlVZ iAKtEeLWpW5WiGp1fYJWF8P8ozOJTq3RcpASKJz1jQo4ZBUq9Gn2BK73S4jG1BkLmyto TpeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pEs0YAvpVnOXt4JVkdCiFZqbRy+rm3fq+3JWY10YEQU=; b=amQ4eZTc3ooELd3w0IUFYO+8PO4Sc4veg2Or1JETeCqar7G+tNk+ExDJN/8r2MQy8G EtVAUJdTGEnaqvmnVHe6mmrm+uMAdZVHSWsWSv2exLBIr1DGrBM15dljvwZH8bcWwMO2 UKyvF0c3CVKEhENa95hUe7gtOVD8v7UZRR2ujnzYWXpOf/bTMH/3YoHClxAzf5vAPh59 gkbpX/GTgISPmJe3BLOYTfS626NJ6/KXgz8e7Sy1iEVjF0DcuWJ8HKFDN3a5XXxEB3xg SmT7XcCdWXNxRc4J21x7ludHB4W9nBgYTP1VUmDsmzX0kXCmbhO4xboVkQIY2Woo1QfO nK/A== X-Gm-Message-State: APjAAAUhZ6Ek2Y8GWWhkyb9xJrnqqWKOyF2uxWjL+4Y8ApRu0XwrhCMR W/G/YUZJx1LGamu6B0OYXbnwv5otiBtj X-Google-Smtp-Source: APXvYqx3q+rVt6nHw7Q3W+MKT568yVbp4Fx30fN5sz2RETBeaJP64CAtnFQOy+MaIZNJrJFmNUvN6vlNm+im X-Received: by 2002:a0d:c481:: with SMTP id g123mr11460226ywd.230.1557223975376; Tue, 07 May 2019 03:12:55 -0700 (PDT) Date: Tue, 7 May 2019 18:12:18 +0800 In-Reply-To: <20190507101220.182466-1-tzungbi@google.com> Message-Id: <20190507101220.182466-2-tzungbi@google.com> Mime-Version: 1.0 References: <20190507101220.182466-1-tzungbi@google.com> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog From: Tzung-Bi Shih To: broonie@kernel.org, tiwai@suse.com Cc: tzungbi@google.com, alsa-devel@alsa-project.org, dgreid@google.com, cychiang@google.com Subject: [alsa-devel] [PATCH 1/3] ASoC: mediatek: mt6358: initialize setting when ramping volume X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP Mt6358 ramps up from the smallest volume (i.e. -10dB) to target dB when opening and ramps down from target dB to mute (i.e. -40dB) when closing. If target is equal to -10dB when opening, headset_volume_ramp() simply leaves current setting (which may not be -10dB) unchanged. Execute the loop at least once to initialize the setting to the starting point (i.e. from). Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/mt6358.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/mt6358.c b/sound/soc/codecs/mt6358.c index d4c4fee6d3d9..96547ae50a5d 100644 --- a/sound/soc/codecs/mt6358.c +++ b/sound/soc/codecs/mt6358.c @@ -405,10 +405,9 @@ static bool is_valid_hp_pga_idx(int reg_idx) reg_idx == DL_GAIN_N_40DB; } -static void headset_volume_ramp(struct mt6358_priv *priv, - int from, int to) +static void headset_volume_ramp(struct mt6358_priv *priv, int from, int to) { - int offset = 0, count = 1, reg_idx; + int offset = 0, count = 0, reg_idx; if (!is_valid_hp_pga_idx(from) || !is_valid_hp_pga_idx(to)) dev_warn(priv->dev, "%s(), volume index is not valid, from %d, to %d\n", @@ -422,7 +421,7 @@ static void headset_volume_ramp(struct mt6358_priv *priv, else offset = from - to; - while (offset > 0) { + while (offset >= 0) { if (to > from) reg_idx = from + count; else From patchwork Tue May 7 10:12:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 10932721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E4CC1575 for ; Tue, 7 May 2019 10:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF10028969 for ; Tue, 7 May 2019 10:31:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E378128754; Tue, 7 May 2019 10:31:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E2BE92883A for ; Tue, 7 May 2019 10:31:57 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 91B301872; Tue, 7 May 2019 12:14:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 91B301872 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557224127; bh=SVJPf+TNobkF0bOj0ZWm3jIXY9gsU9h3LNlGA0wUeMg=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HqGrIgo7Irn9IAJ67HjN0BiaTQt7emxcmQW3o49Wc3vOf/TwzMIjvJ4EGyUs41S5B dGj5+vRCV1LO0l8v0it2uY1hwDAl3+VNGC6dPM+E5ZWXduO5uhvddgp/7dF/Jk5JQf 3DM4QcAgAHL66clqWSdZ6w7KOTcU++GoMk8J2+kA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 122B1F89725; Tue, 7 May 2019 12:13:05 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id E6E3FF89726; Tue, 7 May 2019 12:13:03 +0200 (CEST) Received: from mail-vk1-xa4a.google.com (mail-vk1-xa4a.google.com [IPv6:2607:f8b0:4864:20::a4a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8BA5DF89724 for ; Tue, 7 May 2019 12:13:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8BA5DF89724 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pzdr+DQG" Received: by mail-vk1-xa4a.google.com with SMTP id r14so7177739vkd.18 for ; Tue, 07 May 2019 03:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=luodapv6xiETVaKZ1KJ6xc1kmnnmoklRcPYvajqLPZg=; b=pzdr+DQGeQu/8/ekH+t6LiJYQVxSAyYa0/DmtP4zs1kZr9CFWFRSpnYGdViw2h5rEN fk0RR6d4o+xoa7oQ4LFT/KRCznxk8oF4eQTwHatc42G3DZrpfK2+//JGWgI1tb2MAAMJ szJrO4zt02OYdG8s7ptUJkQgz+Iyq8V4Tt+i6lqzu3gxbg+WvEZRtQU6JvfSJT1N1net VK/ElQC69VAOxgfNtOYBEIV/XrWjFRjji+3CgveNwTdty++JWgCvmetrRHsJGvold6LU AWO3M6TyJtrhGfTjbu4K+v2DKkbJUarRa1MwQSl87CR3BnmlmzmJ8wpc9OOFVfqGIOzL u15A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=luodapv6xiETVaKZ1KJ6xc1kmnnmoklRcPYvajqLPZg=; b=oZt+7zVYjXwjk3/PExZ7zA+qtR8sAIgb1k9xxxNhO1mE3YQWWa1GOseqFvizTD0tGX 0o25s5mQIfktE5NtAMLKvBaSkcuoV3B4C3izDBB+JZegQ99jd+cwuA9iW0IhkUl6x6eX WT9FZtJSdn9bmNRHg5NYLlE41MOIveqyvlnMPr4jvAHQ2OWqxm5pWu8ip0Vh+tDoo1Sm ut+qifg6Kw3zQn+VHQ9Dr+/EC90LxRtq0bztyhUnH9XFYjLXQ6FGwB1l1atLe2pbINej ToEcQ/4UKFrL6GQedOMvJ1FUhue4X/ErgM2W5y+fgcJNfwIgi+d68oS4dQL1evx15NF0 LGwg== X-Gm-Message-State: APjAAAW7o65eN3Vz7UobkGm4p0ylp3/MRciVpC53JXY/u0GYEMpDzTlc Pm5jhKWSZjT8c6fFCnWcp5e+GdCL4OAW X-Google-Smtp-Source: APXvYqyhLWc24NN7aEFyK27zt+XdE56uORXJYQSvTbf+2cC+fgWc9VIi5LZYeXvDAYNOdDar5J9xQQKRZoEy X-Received: by 2002:a67:ce91:: with SMTP id c17mr8740909vse.33.1557223979911; Tue, 07 May 2019 03:12:59 -0700 (PDT) Date: Tue, 7 May 2019 18:12:19 +0800 In-Reply-To: <20190507101220.182466-1-tzungbi@google.com> Message-Id: <20190507101220.182466-3-tzungbi@google.com> Mime-Version: 1.0 References: <20190507101220.182466-1-tzungbi@google.com> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog From: Tzung-Bi Shih To: broonie@kernel.org, tiwai@suse.com Cc: tzungbi@google.com, alsa-devel@alsa-project.org, dgreid@google.com, cychiang@google.com Subject: [alsa-devel] [PATCH 2/3] ASoC: mediatek: mt6358: save output volume for mixer controls X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP Output volume settings from mixer controls would be lost. Imagine that "Headphone Volume" has set to -10dB via amixer: - in mtk_hp_enable() - hp_store_gain() saves the volume setting -10dB from regmap_read() to ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] - headset_volume_ramp() ramps up from -10dB to -10dB - in mtk_hp_disable() - headset_volume_ramp() ramps down from -10dB to -40dB Next time in mtk_hp_enable(), hp_store_gain() would save -40dB but not -10dB. As a result, headset_volume_ramp() would ramp from -10dB to -40dB (which is mute). Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/mt6358.c | 91 ++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/sound/soc/codecs/mt6358.c b/sound/soc/codecs/mt6358.c index 96547ae50a5d..44edbda8afcc 100644 --- a/sound/soc/codecs/mt6358.c +++ b/sound/soc/codecs/mt6358.c @@ -320,32 +320,6 @@ enum { #define DL_GAIN_N_40DB_REG (DL_GAIN_N_40DB << 7 | DL_GAIN_N_40DB) #define DL_GAIN_REG_MASK 0x0f9f -static void lo_store_gain(struct mt6358_priv *priv) -{ - unsigned int reg; - unsigned int gain_l, gain_r; - - regmap_read(priv->regmap, MT6358_ZCD_CON1, ®); - gain_l = (reg >> RG_AUDLOLGAIN_SFT) & RG_AUDLOLGAIN_MASK; - gain_r = (reg >> RG_AUDLORGAIN_SFT) & RG_AUDLORGAIN_MASK; - - priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL] = gain_l; - priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR] = gain_r; -} - -static void hp_store_gain(struct mt6358_priv *priv) -{ - unsigned int reg; - unsigned int gain_l, gain_r; - - regmap_read(priv->regmap, MT6358_ZCD_CON2, ®); - gain_l = (reg >> RG_AUDHPLGAIN_SFT) & RG_AUDHPLGAIN_MASK; - gain_r = (reg >> RG_AUDHPRGAIN_SFT) & RG_AUDHPRGAIN_MASK; - - priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = gain_l; - priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = gain_r; -} - static void hp_zcd_disable(struct mt6358_priv *priv) { regmap_write(priv->regmap, MT6358_ZCD_CON0, 0x0000); @@ -439,20 +413,62 @@ static void headset_volume_ramp(struct mt6358_priv *priv, int from, int to) } } +static int mt6358_put_volsw(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = + snd_soc_kcontrol_component(kcontrol); + struct mt6358_priv *priv = snd_soc_component_get_drvdata(component); + struct soc_mixer_control *mc = + (struct soc_mixer_control *)kcontrol->private_value; + unsigned int reg; + int ret; + + ret = snd_soc_put_volsw(kcontrol, ucontrol); + if (ret < 0) + return ret; + + switch (mc->reg) { + case MT6358_ZCD_CON2: + regmap_read(priv->regmap, MT6358_ZCD_CON2, ®); + priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTL] = + (reg >> RG_AUDHPLGAIN_SFT) & RG_AUDHPLGAIN_MASK; + priv->ana_gain[AUDIO_ANALOG_VOLUME_HPOUTR] = + (reg >> RG_AUDHPRGAIN_SFT) & RG_AUDHPRGAIN_MASK; + break; + case MT6358_ZCD_CON1: + regmap_read(priv->regmap, MT6358_ZCD_CON1, ®); + priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTL] = + (reg >> RG_AUDLOLGAIN_SFT) & RG_AUDLOLGAIN_MASK; + priv->ana_gain[AUDIO_ANALOG_VOLUME_LINEOUTR] = + (reg >> RG_AUDLORGAIN_SFT) & RG_AUDLORGAIN_MASK; + break; + case MT6358_ZCD_CON3: + regmap_read(priv->regmap, MT6358_ZCD_CON3, ®); + priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTL] = + (reg >> RG_AUDHSGAIN_SFT) & RG_AUDHSGAIN_MASK; + priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTR] = + (reg >> RG_AUDHSGAIN_SFT) & RG_AUDHSGAIN_MASK; + break; + } + + return ret; +} + static const DECLARE_TLV_DB_SCALE(playback_tlv, -1000, 100, 0); static const DECLARE_TLV_DB_SCALE(pga_tlv, 0, 600, 0); static const struct snd_kcontrol_new mt6358_snd_controls[] = { /* dl pga gain */ - SOC_DOUBLE_TLV("Headphone Volume", - MT6358_ZCD_CON2, 0, 7, 0x12, 1, - playback_tlv), - SOC_DOUBLE_TLV("Lineout Volume", - MT6358_ZCD_CON1, 0, 7, 0x12, 1, - playback_tlv), - SOC_SINGLE_TLV("Handset Volume", - MT6358_ZCD_CON3, 0, 0x12, 1, - playback_tlv), + SOC_DOUBLE_EXT_TLV("Headphone Volume", + MT6358_ZCD_CON2, 0, 7, 0x12, 1, + snd_soc_get_volsw, mt6358_put_volsw, playback_tlv), + SOC_DOUBLE_EXT_TLV("Lineout Volume", + MT6358_ZCD_CON1, 0, 7, 0x12, 1, + snd_soc_get_volsw, mt6358_put_volsw, playback_tlv), + SOC_SINGLE_EXT_TLV("Handset Volume", + MT6358_ZCD_CON3, 0, 0x12, 1, + snd_soc_get_volsw, mt6358_put_volsw, playback_tlv), /* ul pga gain */ SOC_DOUBLE_R_TLV("PGA Volume", MT6358_AUDENC_ANA_CON0, MT6358_AUDENC_ANA_CON1, @@ -831,8 +847,6 @@ static int mtk_hp_enable(struct mt6358_priv *priv) /* Reduce ESD resistance of AU_REFN */ regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON2, 0x4000); - /* save target gain to restore after hardware open complete */ - hp_store_gain(priv); /* Set HPR/HPL gain as minimum (~ -40dB) */ regmap_write(priv->regmap, MT6358_ZCD_CON2, DL_GAIN_N_40DB_REG); @@ -1042,8 +1056,6 @@ static int mtk_hp_spk_enable(struct mt6358_priv *priv) /* Reduce ESD resistance of AU_REFN */ regmap_write(priv->regmap, MT6358_AUDDEC_ANA_CON2, 0x4000); - /* save target gain to restore after hardware open complete */ - hp_store_gain(priv); /* Set HPR/HPL gain to -10dB */ regmap_write(priv->regmap, MT6358_ZCD_CON2, DL_GAIN_N_10DB_REG); @@ -1103,7 +1115,6 @@ static int mtk_hp_spk_enable(struct mt6358_priv *priv) hp_main_output_ramp(priv, true); /* Set LO gain as minimum (~ -40dB) */ - lo_store_gain(priv); regmap_write(priv->regmap, MT6358_ZCD_CON1, DL_GAIN_N_40DB_REG); /* apply volume setting */ headset_volume_ramp(priv, From patchwork Tue May 7 10:12:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 10932725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 875AB186E for ; Tue, 7 May 2019 10:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74F3F288CE for ; Tue, 7 May 2019 10:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 695A7288CF; Tue, 7 May 2019 10:31:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 07B1928985 for ; Tue, 7 May 2019 10:31:57 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 7DFB2184A; Tue, 7 May 2019 12:15:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7DFB2184A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557224166; bh=7WvQxeh3raWLkzbocyphaB5rU2vmFPB9SSxU4b6t1VI=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NY2LyEOWaiXJrZa9dy0XKFnbIWpRfJIw7A6U8q5xxcB3HqmL0NwXHbPLRoVqeazOn HZ5vUathiHFJboWWd+x5YWe3BWR4/x+DQKEJDHljW98yqnwLz6A0LtkjXbWoMXOG2N QWf/nEauuf4INJ2btQfT8senvtFdZLdR6pWYD94c= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 180F4F89727; Tue, 7 May 2019 12:13:09 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id C8BB2F8972B; Tue, 7 May 2019 12:13:07 +0200 (CEST) Received: from mail-yw1-xc49.google.com (mail-yw1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9DD81F89727 for ; Tue, 7 May 2019 12:13:05 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9DD81F89727 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iTzwyM2j" Received: by mail-yw1-xc49.google.com with SMTP id q2so30502773ywd.9 for ; Tue, 07 May 2019 03:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=/z4fADeK2fLL67CzFV8fJ52P+/KQ/nXPgKIO88Uq6ms=; b=iTzwyM2jDB4YZJ2hoHnVjIzwIXPHs5cX9AdyDlt+MOLOxcTfeerWLDpy4942ck9z+y NQY2nAMAxlNGEvYeKvv4J8gipxmRwP3QBFD4BRDLYd3Ma8SXZTImQXF1DIljbhOYfERJ Re+mPtK5ODjW6xSyYzCfH8T4NiPb199AsKOzkLW/6sjQs1QkJ1whWme3mI1S4D6NJW5U sRNfZo8gjt3G44bFTMnS2fvwGJXNX5fnPPXLW3c7rDyePQRYiH7LnyF5cDygoo/1z7tH hs5q2R2zh+gQeIAXOIXYz18Kh3QGeBXnFbucUSad2hqd8wzbNRq7WfqTbVly0npQVjZ6 MrbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/z4fADeK2fLL67CzFV8fJ52P+/KQ/nXPgKIO88Uq6ms=; b=d+OCf+gr/luxG6gysI/JPnsZqbUsQW6H6tX9pkBhW8NJyIW42b5ZLOuQDF+MJMWsri +BvVpk8eZRq5VYdP7fSWunrA86ahPmKdt44NWSGhJXCNX1RoEf7Kycj7rvyuL7uA82Us y/KeQ1lmWdNKGTlu7J36mOwLno6xFj3QVIEHEWL7P0dFhfUvqaz56NTfX9OBg25HLObf KmciZc5tRmvCF5R1GGVme3p7YFmbGzPQYjcY+jMR6G32qEMOfiSnpA8LDQFF6kHo3re+ NqRxIkREU65flYIRdpGpuCK67ILXh7+hps/1ngdqSJq6VMwKEVWGg7iouJcCk9kairve DJ8Q== X-Gm-Message-State: APjAAAXj70h0absuV0DYaLeHKG0auwMes7foljfOy5GjTlA+pr7CYXWh oagyv6v76Si48Zg05J5MJ5FHKW70pStN X-Google-Smtp-Source: APXvYqzNvb0zqPqpmCM1mvRYB6mf7opx4jk0uh09oTV6Kr2iamdljO6Vw0Ia/jUdJeisaldHzcTzBlRY4e5o X-Received: by 2002:a81:b717:: with SMTP id v23mr21255218ywh.120.1557223984586; Tue, 07 May 2019 03:13:04 -0700 (PDT) Date: Tue, 7 May 2019 18:12:20 +0800 In-Reply-To: <20190507101220.182466-1-tzungbi@google.com> Message-Id: <20190507101220.182466-4-tzungbi@google.com> Mime-Version: 1.0 References: <20190507101220.182466-1-tzungbi@google.com> X-Mailer: git-send-email 2.21.0.1020.gf2820cf01a-goog From: Tzung-Bi Shih To: broonie@kernel.org, tiwai@suse.com Cc: tzungbi@google.com, alsa-devel@alsa-project.org, dgreid@google.com, cychiang@google.com Subject: [alsa-devel] [PATCH 3/3] ASoC: mediatek: mt6358: save PGA for mixer control X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP mt6358_amic_disable() resets PGA to 0. Save the gain settings from mixer control and restore them when using the microphone. Signed-off-by: Tzung-Bi Shih --- sound/soc/codecs/mt6358.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/mt6358.c b/sound/soc/codecs/mt6358.c index 44edbda8afcc..50b3fc5457ea 100644 --- a/sound/soc/codecs/mt6358.c +++ b/sound/soc/codecs/mt6358.c @@ -450,6 +450,15 @@ static int mt6358_put_volsw(struct snd_kcontrol *kcontrol, priv->ana_gain[AUDIO_ANALOG_VOLUME_HSOUTR] = (reg >> RG_AUDHSGAIN_SFT) & RG_AUDHSGAIN_MASK; break; + case MT6358_AUDENC_ANA_CON0: + case MT6358_AUDENC_ANA_CON1: + regmap_read(priv->regmap, MT6358_AUDENC_ANA_CON0, ®); + priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1] = + (reg >> RG_AUDPREAMPLGAIN_SFT) & RG_AUDPREAMPLGAIN_MASK; + regmap_read(priv->regmap, MT6358_AUDENC_ANA_CON1, ®); + priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2] = + (reg >> RG_AUDPREAMPRGAIN_SFT) & RG_AUDPREAMPRGAIN_MASK; + break; } return ret; @@ -470,10 +479,10 @@ static const struct snd_kcontrol_new mt6358_snd_controls[] = { MT6358_ZCD_CON3, 0, 0x12, 1, snd_soc_get_volsw, mt6358_put_volsw, playback_tlv), /* ul pga gain */ - SOC_DOUBLE_R_TLV("PGA Volume", - MT6358_AUDENC_ANA_CON0, MT6358_AUDENC_ANA_CON1, - 8, 4, 0, - pga_tlv), + SOC_DOUBLE_R_EXT_TLV("PGA Volume", + MT6358_AUDENC_ANA_CON0, MT6358_AUDENC_ANA_CON1, + 8, 4, 0, + snd_soc_get_volsw, mt6358_put_volsw, pga_tlv), }; /* MUX */ @@ -1750,6 +1759,21 @@ static void mt6358_dmic_disable(struct mt6358_priv *priv) regmap_write(priv->regmap, MT6358_AUDENC_ANA_CON9, 0x0000); } +static void mt6358_restore_pga(struct mt6358_priv *priv) +{ + unsigned int gain_l, gain_r; + + gain_l = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP1]; + gain_r = priv->ana_gain[AUDIO_ANALOG_VOLUME_MICAMP2]; + + regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON0, + RG_AUDPREAMPLGAIN_MASK_SFT, + gain_l << RG_AUDPREAMPLGAIN_SFT); + regmap_update_bits(priv->regmap, MT6358_AUDENC_ANA_CON1, + RG_AUDPREAMPRGAIN_MASK_SFT, + gain_r << RG_AUDPREAMPRGAIN_SFT); +} + static int mt_mic_type_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) @@ -1774,6 +1798,7 @@ static int mt_mic_type_event(struct snd_soc_dapm_widget *w, mt6358_amic_enable(priv); break; } + mt6358_restore_pga(priv); break; case SND_SOC_DAPM_POST_PMD: