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,