From patchwork Fri Oct 24 06:00:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Hsu X-Patchwork-Id: 39403 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DC62620341 for ; Fri, 24 Oct 2014 06:01:00 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf1385697lab.11 for ; Thu, 23 Oct 2014 23:00:59 -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=qBeRh7ywl1vlSX9ZOt3aT0VKX0c/VAatbeUuSet/8R0=; b=WL5MgQv08kV2VmKtCPdG0M1dUGvfZb11Wy8WXE3jHqWd/xykbtJ4/dlK5pApn0SJfe +gCDMNcnFtQonNXWSfNSPug4gQMty1IDJ6zNsUmIdNEP41Wy5NJg0kCT2/HJiS1ofpep pS5kp45USr8qZxpEsQp9W1j/kjXkcCUaqXUEpE1eeBVH6d/vMwL/Yb4e6r5kGXuJdE7e 5hdgOiGNNyT547cjdGC99Hna0FaBjQ4tRoly9BSpJ5Zj1bQVZ3wE3GwRV6Br0zegZ7M+ RnT7tueWAbh8qWbOkrCtF4f/O702Ecq5wDImSvpl04X/OUgCgCOxfQHn9V3eWDseMCSX Ot8g== X-Gm-Message-State: ALoCoQkxPBnHVp9hgYHp+tlFWF+Yia6brEkoREY6VTzOctjNgzocAy0fgz7eApl4FM3LzeqwoSMx X-Received: by 10.152.21.170 with SMTP id w10mr1815990lae.6.1414130459559; Thu, 23 Oct 2014 23:00:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.100 with SMTP id w4ls370198laz.16.gmail; Thu, 23 Oct 2014 23:00:59 -0700 (PDT) X-Received: by 10.152.43.97 with SMTP id v1mr2071824lal.3.1414130459232; Thu, 23 Oct 2014 23:00:59 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id oc10si5400454lbb.99.2014.10.23.23.00.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Oct 2014 23:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id s18so2054440lam.37 for ; Thu, 23 Oct 2014 23:00:59 -0700 (PDT) X-Received: by 10.152.120.199 with SMTP id le7mr1981173lab.67.1414130459000; Thu, 23 Oct 2014 23:00:59 -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.112.84.229 with SMTP id c5csp374963lbz; Thu, 23 Oct 2014 23:00:57 -0700 (PDT) X-Received: by 10.66.65.206 with SMTP id z14mr84242pas.46.1414130457216; Thu, 23 Oct 2014 23:00:57 -0700 (PDT) Received: from Kraken ([124.219.7.128]) by mx.google.com with ESMTP id kt7si3313345pab.214.2014.10.23.23.00.55 for ; Thu, 23 Oct 2014 23:00:57 -0700 (PDT) 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 3E0D86A27A2; Fri, 24 Oct 2014 14:00:46 +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: [PATCHv5 2/9] ASOC: wm8971: modify the control of deemphasis Date: Fri, 24 Oct 2014 14:00:28 +0800 Message-Id: <1414130435-14183-2-git-send-email-xavier.hsu@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414130435-14183-1-git-send-email-xavier.hsu@linaro.org> References: <1414130435-14183-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.215.50 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 | 77 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 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 01c76a4..6df0a3b --- 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,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; }; /* @@ -100,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"}; @@ -114,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 struct soc_enum wm8971_enum[] = { SOC_ENUM_SINGLE(WM8971_BASS, 7, 2, wm8971_bass), /* 0 */ @@ -184,7 +252,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", wm8971_enum[5]), + SOC_SINGLE_BOOL_EXT("Playback De-emphasis Switch", 0, + wm8971_get_deemph, wm8971_put_deemph), SOC_ENUM("Playback Function", wm8971_enum[6]), SOC_ENUM("Playback Phase", wm8971_enum[7]), @@ -534,6 +603,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) @@ -727,6 +798,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);