From patchwork Mon Dec 1 06:51:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Hsu X-Patchwork-Id: 41747 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 90BB820672 for ; Mon, 1 Dec 2014 06:52:46 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf6210149eek.10 for ; Sun, 30 Nov 2014 22:52:45 -0800 (PST) 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=c0ctABCSBiG8yT7Ds1xR2WrK9ujodh91SL1dOuhaEs4=; b=XlcJjfmCu/h0GNqmJ6ZpanctTZ54BhjRKdp4qK3RfPaYWI2djnn33Fu3ZInzttLfJs 4tOnt1nBoGL+2bSJyWxe25vtcp5PsRFvGQZO2yZYPKRgPKksBouaAsISg/awgiGRGjp5 iuVyB+TI8k+ae9eGkfQ+qY+IBAfkJaofTqE2Cg0WJ96wZ4D+70JkU8l4ZYE+v5kYeTzb Plyta2Fsg4dQp9ba0u8O002zrl0h62XlmpwDN3euImXD+K1JxSUHAHrE87Sj/tv7gnoH jDIUyqpcsNqc3Rexaiiv/IgJG0EcaFQ9MHEalokh4xeFNakwdVIcu/xPJt+BTkUiV6a/ sKiw== X-Gm-Message-State: ALoCoQkh7YgrysTYRpZmqtHKQ8TwGrXWWd9rrESL0nHqRdKyrVfthEK7Y+5Lm01bl2YUyEbeAzk0 X-Received: by 10.180.108.101 with SMTP id hj5mr13266763wib.3.1417416765380; Sun, 30 Nov 2014 22:52:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.10 with SMTP id lc10ls1121255lac.22.gmail; Sun, 30 Nov 2014 22:52:45 -0800 (PST) X-Received: by 10.112.204.193 with SMTP id la1mr14081470lbc.43.1417416765225; Sun, 30 Nov 2014 22:52:45 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id j1si16740763lah.68.2014.11.30.22.52.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 30 Nov 2014 22:52:44 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id w7so8143054lbi.15 for ; Sun, 30 Nov 2014 22:52:44 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr54414351lbo.32.1417416764837; Sun, 30 Nov 2014 22:52:44 -0800 (PST) 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.112.184.201 with SMTP id ew9csp236477lbc; Sun, 30 Nov 2014 22:52:43 -0800 (PST) X-Received: by 10.68.57.225 with SMTP id l1mr95181449pbq.87.1417416758559; Sun, 30 Nov 2014 22:52:38 -0800 (PST) Received: from Kraken ([124.219.7.128]) by mx.google.com with ESMTP id cc10si26634167pdb.37.2014.11.30.22.52.36 for ; Sun, 30 Nov 2014 22:52:38 -0800 (PST) Received-SPF: temperror (google.com: error in processing during lookup of xavier@kraken: DNS timeout) client-ip=124.219.7.128; Received: by Kraken (Postfix, from userid 1011) id 4EF606A2A4C; Mon, 1 Dec 2014 14:52:15 +0800 (CST) From: Xavier Hsu To: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com, patches@linaro.org Cc: lars@metafoo.de, ckeepax@opensource.wolfsonmicro.com, Xavier Hsu , Andy Green Subject: [PATCHv6 3/9] ASOC: wm8971: modify the control of deemphasis Date: Mon, 1 Dec 2014 14:51:55 +0800 Message-Id: <1417416721-17271-3-git-send-email-xavier.hsu@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1417416721-17271-1-git-send-email-xavier.hsu@linaro.org> References: <1417416721-17271-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.217.170 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: , We add a switch for automatic updating the frequency of wm8971. Signed-off-by: Xavier Hsu Signed-off-by: Andy Green --- sound/soc/codecs/wm8971.c | 75 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 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 60c90c6..b5cb636 --- a/sound/soc/codecs/wm8971.c +++ b/sound/soc/codecs/wm8971.c @@ -40,6 +40,11 @@ static struct workqueue_struct *wm8971_workq; /* codec private data */ struct wm8971_priv { unsigned int sysclk; + + /* De-emphasis */ + struct mutex deemph_mutex; + int playback_fs; + bool deemph; }; /* @@ -104,7 +109,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"}; @@ -118,6 +122,66 @@ 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 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(&wm8971->deemph_mutex); + if (wm8971->deemph != deemph) { + wm8971->deemph = deemph; + wm8971_set_deemph(codec); + + ret = 1; + } + mutex_unlock(&wm8971->deemph_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, @@ -142,7 +206,6 @@ static const SOC_ENUM_SINGLE_DECL(right_pga, WM8971_RADCIN, 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 SOC_ENUM_SINGLE_DECL(deemp, WM8971_ADCDAC, 1, wm8971_deemp); static const struct snd_kcontrol_new wm8971_snd_controls[] = { SOC_DOUBLE_R("Capture Volume", WM8971_LINVOL, WM8971_RINVOL, 0, 63, 0), @@ -196,7 +259,8 @@ static const struct snd_kcontrol_new wm8971_snd_controls[] = { 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", deemp), + 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), @@ -546,6 +610,9 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream, break; } + wm8971->playback_fs = params_rate(params); + wm8971_set_deemph(codec); + /* set iface & srate */ snd_soc_write(codec, WM8971_IFACE, iface); if (coeff >= 0) @@ -739,6 +806,8 @@ static int wm8971_i2c_probe(struct i2c_client *i2c, if (wm8971 == NULL) return -ENOMEM; + mutex_init(&wm8971->deemph_mutex); + regmap = devm_regmap_init_i2c(i2c, &wm8971_regmap); if (IS_ERR(regmap)) return PTR_ERR(regmap);