From patchwork Tue Sep 2 03:27:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Hsu X-Patchwork-Id: 36427 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C26BB2032B for ; Tue, 2 Sep 2014 03:27:58 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id uq10sf33539714igb.3 for ; Mon, 01 Sep 2014 20:27:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Rl1nwjVb61F7GXJueaI+gdzF+sJ9IrDXj7dpcjgSNdg=; b=TZw4BGXEWFtCQB6wxgnS8CUeuIk+CJ0KAERDDH7GnQMdiGHbgbvxzViuaFloKQNbAz Qs32zRqNk/lUgXEF4b+GGJuwrMI3Bb4CMH0MZ10yIaYHu/4WBIcEnc2MaO3Jf30nn7Y8 7+fJpPDPcvYBiakq0r4227hfOvguLJhGEHFD+TdLWY8PToLBNQA9rHzkVsNYwjITvPW7 Qeo17fr0ftVBbLQazdUaxYmsn9gqctYomDxBFzCHLJLFC3b4RJ3nX4CK2JOBzyQdBIw+ Zbf9j1sOHd+HTRgQxqMgy391uWIZS6q86wg3ns6k7+MrToUN1JZi5cEH3JOEnMRVeD5R o5wg== X-Gm-Message-State: ALoCoQmIy5MKo50S1lqu3Ppx5XAUPKdoQWIrbfKymPxv9l2y9IAhf2ucAuZ+8uGqxthHf7m3MCD9 X-Received: by 10.182.107.135 with SMTP id hc7mr2337580obb.48.1409628478098; Mon, 01 Sep 2014 20:27:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.91.40 with SMTP id y37ls2246383qgd.2.gmail; Mon, 01 Sep 2014 20:27:58 -0700 (PDT) X-Received: by 10.52.26.206 with SMTP id n14mr23467349vdg.0.1409628478002; Mon, 01 Sep 2014 20:27:58 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id ck3si1733496vcb.102.2014.09.01.20.27.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 20:27:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so6404391vcb.33 for ; Mon, 01 Sep 2014 20:27:57 -0700 (PDT) X-Received: by 10.220.168.210 with SMTP id v18mr28398523vcy.3.1409628477910; Mon, 01 Sep 2014 20:27:57 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp465111vcb; Mon, 1 Sep 2014 20:27:57 -0700 (PDT) X-Received: by 10.68.220.71 with SMTP id pu7mr44650215pbc.22.1409628476982; Mon, 01 Sep 2014 20:27:56 -0700 (PDT) Received: from Kraken ([124.219.7.128]) by mx.google.com with ESMTP id h17si3514758pdj.216.2014.09.01.20.27.55 for ; Mon, 01 Sep 2014 20:27:56 -0700 (PDT) Received-SPF: none (google.com: xavier@kraken does not designate permitted sender hosts) client-ip=124.219.7.128; Received: by Kraken (Postfix, from userid 1011) id A47056A27A2; Tue, 2 Sep 2014 11:27:53 +0800 (CST) From: Xavier Hsu To: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com, patches@linaro.org Cc: Xavier Hsu , Andy Green Subject: [PATCHv3 2/9] WM8971 uses SOC_ENUM_SINGLE_DECL to replace SOC_ENUM_SINGLE Date: Tue, 2 Sep 2014 11:27:43 +0800 Message-Id: <1409628470-13059-2-git-send-email-xavier.hsu@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1409628470-13059-1-git-send-email-xavier.hsu@linaro.org> References: <1409628470-13059-1-git-send-email-xavier.hsu@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: xavier.hsu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch improves WM8971. We uses SOC_ENUM_SINGLE_DECL macro to replace SOC_ENUM_SINGLE macro. Any comments about improving the patch are welcome. Thanks. Signed-off-by: Xavier Hsu Signed-off-by: Andy Green --- sound/soc/codecs/wm8971.c | 136 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 30 deletions(-) mode change 100644 => 100755 sound/soc/codecs/wm8971.c diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c old mode 100644 new mode 100755 index 064278f..59c4828 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c @@ -7,6 +7,10 @@ * * Based on wm8753.c by Liam Girdwood * + * WM8971 Improve Copyright (C) 2014 Linaro, Ltd + * Author: Xavier Hsu + * Andy Green + * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your @@ -36,6 +40,8 @@ static struct workqueue_struct *wm8971_workq; /* codec private data */ struct wm8971_priv { unsigned int sysclk; + int playback_fs; + bool deemph; }; /* @@ -100,7 +106,6 @@ static const char const *wm8971_alc_func[] = {"Off", "Right", "Left", "Stereo"}; static const char const *wm8971_ng_type[] = {"Constant PGA Gain", "Mute ADC Output"}; -static const char const *wm8971_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz"}; static const char const *wm8971_mono_mux[] = {"Stereo", "Mono (Left)", "Mono (Right)", "Digital Mono"}; static const char const *wm8971_dac_phase[] = {"Non Inverted", "Inverted"}; @@ -114,23 +119,91 @@ static const char const *wm8971_rpga_sel[] = {"Line", "Mic", "NC", "Differential"}; static const char const *wm8971_adcpol[] = {"Normal", "L Invert", "R Invert", "L + R Invert"}; +static const char const *wm8971_deemp[] = {"None", "32kHz", + "44.1kHz", "48kHz"}; -static const struct soc_enum wm8971_enum[] = { - SOC_ENUM_SINGLE(WM8971_BASS, 7, 2, wm8971_bass), /* 0 */ - SOC_ENUM_SINGLE(WM8971_BASS, 6, 2, wm8971_bass_filter), - SOC_ENUM_SINGLE(WM8971_TREBLE, 6, 2, wm8971_treble), - SOC_ENUM_SINGLE(WM8971_ALC1, 7, 4, wm8971_alc_func), - SOC_ENUM_SINGLE(WM8971_NGATE, 1, 2, wm8971_ng_type), /* 4 */ - SOC_ENUM_SINGLE(WM8971_ADCDAC, 1, 4, wm8971_deemp), - SOC_ENUM_SINGLE(WM8971_ADCTL1, 4, 4, wm8971_mono_mux), - SOC_ENUM_SINGLE(WM8971_ADCTL1, 1, 2, wm8971_dac_phase), - SOC_ENUM_SINGLE(WM8971_LOUTM1, 0, 5, wm8971_lline_mux), /* 8 */ - SOC_ENUM_SINGLE(WM8971_ROUTM1, 0, 5, wm8971_rline_mux), - SOC_ENUM_SINGLE(WM8971_LADCIN, 6, 4, wm8971_lpga_sel), - SOC_ENUM_SINGLE(WM8971_RADCIN, 6, 4, wm8971_rpga_sel), - SOC_ENUM_SINGLE(WM8971_ADCDAC, 5, 4, wm8971_adcpol), /* 12 */ - SOC_ENUM_SINGLE(WM8971_ADCIN, 6, 4, wm8971_mono_mux), -}; +static int wm8971_set_deemph(struct snd_soc_codec *codec) +{ + struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); + int val = 0, i, best = 0; + + /* If we're using deemphasis select the nearest available sample + * rate. + */ + if (wm8971->deemph) { + best = 1; + for (i = 2; i < ARRAY_SIZE(wm8971_deemp); i++) { + if (abs(wm8971_deemp[i] - wm8971->playback_fs) < + abs(wm8971_deemp[best] - + wm8971->playback_fs)) + best = i; + } + val = best << 1; + } + + dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n", + best, wm8971_deemp[best]); + + return snd_soc_update_bits(codec, WM8971_ADCDAC, 0x6, val); +} + +static int wm8971_get_deemph(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); + struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); + + ucontrol->value.enumerated.item[0] = wm8971->deemph; + + return 0; +} + +static int wm8971_put_deemph(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); + struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec); + int deemph = ucontrol->value.enumerated.item[0]; + int ret = 0; + + if (deemph > 1) + return -EINVAL; + + mutex_lock(&codec->mutex); + if (wm8971->deemph != deemph) { + wm8971->deemph = deemph; + wm8971_set_deemph(codec); + + ret = 1; + } + mutex_unlock(&codec->mutex); + + return ret; +} + +static const SOC_ENUM_SINGLE_DECL(bass_boost, WM8971_BASS, 7, wm8971_bass); +static const SOC_ENUM_SINGLE_DECL(bass_filter, WM8971_BASS, + 6, wm8971_bass_filter); +static const SOC_ENUM_SINGLE_DECL(treble_cutoff, WM8971_TREBLE, + 6, wm8971_treble); +static const SOC_ENUM_SINGLE_DECL(alc_capture_func, WM8971_ALC1, + 7, wm8971_alc_func); +static const SOC_ENUM_SINGLE_DECL(alc_capture_ngtype, WM8971_NGATE, + 1, wm8971_ng_type); +static const SOC_ENUM_SINGLE_DECL(dac_mono_mix, WM8971_ADCTL1, + 4, wm8971_mono_mux); +static const SOC_ENUM_SINGLE_DECL(dac_phase_inv, WM8971_ADCTL1, + 1, wm8971_dac_phase); +static const SOC_ENUM_SINGLE_DECL(left_line, WM8971_LOUTM1, + 0, wm8971_lline_mux); +static const SOC_ENUM_SINGLE_DECL(right_line, WM8971_ROUTM1, + 0, wm8971_rline_mux); +static const SOC_ENUM_SINGLE_DECL(left_pga, WM8971_LADCIN, 6, wm8971_lpga_sel); +static const SOC_ENUM_SINGLE_DECL(right_pga, WM8971_RADCIN, + 6, wm8971_rpga_sel); +static const SOC_ENUM_SINGLE_DECL(capture_polarity, WM8971_ADCDAC, + 5, wm8971_adcpol); +static const SOC_ENUM_SINGLE_DECL(monomux, WM8971_ADCIN, 6, wm8971_mono_mux); static const struct snd_kcontrol_new wm8971_snd_controls[] = { SOC_DOUBLE_R("Capture Volume", WM8971_LINVOL, WM8971_RINVOL, 0, 63, 0), @@ -158,12 +231,12 @@ static const struct snd_kcontrol_new wm8971_snd_controls[] = { SOC_DOUBLE_R("Speaker Playback Volume", WM8971_LOUT2V, WM8971_ROUT2V, 0, 127, 0), - SOC_ENUM("Bass Boost", wm8971_enum[0]), - SOC_ENUM("Bass Filter", wm8971_enum[1]), + SOC_ENUM("Bass Boost", bass_boost), + SOC_ENUM("Bass Filter", bass_filter), SOC_SINGLE("Bass Volume", WM8971_BASS, 0, 7, 1), SOC_SINGLE("Treble Volume", WM8971_TREBLE, 0, 7, 0), - SOC_ENUM("Treble Cut-off", wm8971_enum[2]), + SOC_ENUM("Treble Cut-off", treble_cutoff), SOC_SINGLE("Capture Filter Switch", WM8971_ADCDAC, 0, 1, 1), @@ -172,21 +245,22 @@ static const struct snd_kcontrol_new wm8971_snd_controls[] = { SOC_SINGLE("ALC Capture Target Volume", WM8971_ALC1, 0, 7, 0), SOC_SINGLE("ALC Capture Max Volume", WM8971_ALC1, 4, 7, 0), - SOC_ENUM("ALC Capture Function", wm8971_enum[3]), + SOC_ENUM("ALC Capture Function", alc_capture_func), SOC_SINGLE("ALC Capture ZC Switch", WM8971_ALC2, 7, 1, 0), SOC_SINGLE("ALC Capture Hold Time", WM8971_ALC2, 0, 15, 0), SOC_SINGLE("ALC Capture Decay Time", WM8971_ALC3, 4, 15, 0), SOC_SINGLE("ALC Capture Attack Time", WM8971_ALC3, 0, 15, 0), SOC_SINGLE("ALC Capture NG Threshold", WM8971_NGATE, 3, 31, 0), - SOC_ENUM("ALC Capture NG Type", wm8971_enum[4]), + SOC_ENUM("ALC Capture NG Type", alc_capture_ngtype), SOC_SINGLE("ALC Capture NG Switch", WM8971_NGATE, 0, 1, 0), SOC_SINGLE("Capture 6dB Attenuate", WM8971_ADCDAC, 8, 1, 0), SOC_SINGLE("Playback 6dB Attenuate", WM8971_ADCDAC, 7, 1, 0), - SOC_ENUM("Playback De-emphasis", wm8971_enum[5]), - SOC_ENUM("Playback Function", wm8971_enum[6]), - SOC_ENUM("Playback Phase", wm8971_enum[7]), + SOC_SINGLE_BOOL_EXT("Playback De-emphasis Switch", 0, + wm8971_get_deemph, wm8971_put_deemph), + SOC_ENUM("Playback Function", dac_mono_mix), + SOC_ENUM("Playback Phase", dac_phase_inv), SOC_DOUBLE_R("Mic Boost", WM8971_LADCIN, WM8971_RADCIN, 4, 3, 0), }; @@ -221,23 +295,23 @@ SOC_DAPM_SINGLE("Right Bypass Switch", WM8971_MOUTM2, 7, 1, 0), /* Left Line Mux */ static const struct snd_kcontrol_new wm8971_left_line_controls = -SOC_DAPM_ENUM("Route", wm8971_enum[8]); +SOC_DAPM_ENUM("Route", left_line); /* Right Line Mux */ static const struct snd_kcontrol_new wm8971_right_line_controls = -SOC_DAPM_ENUM("Route", wm8971_enum[9]); +SOC_DAPM_ENUM("Route", right_line); /* Left PGA Mux */ static const struct snd_kcontrol_new wm8971_left_pga_controls = -SOC_DAPM_ENUM("Route", wm8971_enum[10]); +SOC_DAPM_ENUM("Route", left_pga); /* Right PGA Mux */ static const struct snd_kcontrol_new wm8971_right_pga_controls = -SOC_DAPM_ENUM("Route", wm8971_enum[11]); +SOC_DAPM_ENUM("Route", right_pga); /* Mono ADC Mux */ static const struct snd_kcontrol_new wm8971_monomux_controls = -SOC_DAPM_ENUM("Route", wm8971_enum[13]); +SOC_DAPM_ENUM("Route", monomux); static const struct snd_soc_dapm_widget wm8971_dapm_widgets[] = { SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM, 0, 0, @@ -534,6 +608,8 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream, break; } + wm8971_set_deemph(codec); + /* set iface & srate */ snd_soc_write(codec, WM8971_IFACE, iface); if (coeff >= 0)