From patchwork Sun Oct 12 21:39:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 5072161 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 72446C11AC for ; Sun, 12 Oct 2014 21:39:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DC7D2012D for ; Sun, 12 Oct 2014 21:39:57 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 0C3CC2010E for ; Sun, 12 Oct 2014 21:39:56 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5E3EA2604A0; Sun, 12 Oct 2014 23:39:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 51015260464; Sun, 12 Oct 2014 23:39:43 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 73FE526046D; Sun, 12 Oct 2014 23:39:41 +0200 (CEST) Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com [74.125.82.41]) by alsa0.perex.cz (Postfix) with ESMTP id 72165260462 for ; Sun, 12 Oct 2014 23:39:33 +0200 (CEST) Received: by mail-wg0-f41.google.com with SMTP id b13so7452138wgh.12 for ; Sun, 12 Oct 2014 14:39:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/bUkeQKw9PVWMp8WccsF7xfe04x4zdISqgK0t+Ec3UQ=; b=jyHs1IzlfPR4gxvJWMbOnb+5rVjP5//SG+VRGv42ZyWlN0TXWhPJ4nwMUA1gwBmX3v unW2gqnxh+GCUImKiGjaWuqdsbCMcH1LBivAtpGjP3xfOa3HwP3bXdIi+NPENX3O+DmN Of28gkR5s0v1iH6cGskigGiIHlKozF+APjHOfKyVxKeqoUcs93Q9g47qP9dEuDIC7s0X gvJP8ExJFceoogKEYK1l7TTnP8VAh2G3oogw3lnqmjdujkOSt/4OP4KB0pZjwYunF42h p/AvKTtkT4P6SNjFcVi45fUtJkojwW9dL992TSMLux5bcjAsPEwy1vual201aWvoG1cm zWrg== X-Gm-Message-State: ALoCoQnfOcFF2MAY7/LSea5jjR+4Zj9yZ9H9OsXNIFleNz5I+0iIkcCxZRsgfx3R4UF8QKnDF9Hg X-Received: by 10.180.91.52 with SMTP id cb20mr16279252wib.61.1413149970058; Sun, 12 Oct 2014 14:39:30 -0700 (PDT) Received: from localhost.localdomain (port-195-158-157-135.static.isionline-dialin.de. [195.158.157.135]) by mx.google.com with ESMTPSA id q10sm14529036wjq.35.2014.10.12.14.39.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Oct 2014 14:39:29 -0700 (PDT) From: Jean-Michel Hautbois To: broonie@kernel.org, fabio.estevam@freescale.com, alsa-devel@alsa-project.org Date: Sun, 12 Oct 2014 23:39:11 +0200 Message-Id: <1413149951-2882-1-git-send-email-jean-michel.hautbois@vodalys.com> X-Mailer: git-send-email 2.1.1 Cc: nicoleotsuka@gmail.com, devicetree@vger.kernel.org, Jean-Michel Hautbois Subject: [alsa-devel] [PATCH v2] audio: sgtl5000: Add MicBias resistor support in DT X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Some systems may require a different resistor than the default one (4K). This adds a property in sgtl5000 codec. It keeps the default of 4K when nothing is specified so it does not break existing code. v2: modify the default case on DT parsing Signed-off-by: Jean-Michel Hautbois --- .../devicetree/bindings/sound/sgtl5000.txt | 10 ++++ sound/soc/codecs/sgtl5000.c | 60 ++++++++++++++++++++-- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt index 955df60..dd38f84 100644 --- a/Documentation/devicetree/bindings/sound/sgtl5000.txt +++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt @@ -7,10 +7,20 @@ Required properties: - clocks : the clock provider of SYS_MCLK +- sgtl5000-micbias-resistor : the bias resistor to be used + 1 or SGTL5000_MICBIAS_2K - MICBIAS resistor is set to 2K + 2 or SGTL5000_MICBIAS_4K - MICBIAS resistor is set to 4K + 3 or SGTL5000_MICBIAS_8K - MICBIAS resistor is set to 8K + 0 or SGTL5000_MICBIAS_OFF - MICBIAS resistor is not used + If this node is not mentioned or if the value is unknown, then + micbias resistor is set to 4K. + + Example: codec: sgtl5000@0a { compatible = "fsl,sgtl5000"; reg = <0x0a>; clocks = <&clks 150>; + sgtl5000-micbias-resistor = <1>; }; diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c index 6bb77d7..a255754 100644 --- a/sound/soc/codecs/sgtl5000.c +++ b/sound/soc/codecs/sgtl5000.c @@ -121,6 +121,13 @@ struct ldo_regulator { bool enabled; }; +enum sgtl5000_micbias_resistor { + SGTL5000_MICBIAS_OFF = 0, + SGTL5000_MICBIAS_2K = 1, + SGTL5000_MICBIAS_4K = 2, + SGTL5000_MICBIAS_8K = 3, +}; + /* sgtl5000 private structure in codec */ struct sgtl5000_priv { int sysclk; /* sysclk rate */ @@ -131,6 +138,7 @@ struct sgtl5000_priv { struct regmap *regmap; struct clk *mclk; int revision; + enum sgtl5000_micbias_resistor micbias_resistor; }; /* @@ -145,12 +153,14 @@ struct sgtl5000_priv { static int mic_bias_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { + struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(w->codec); + switch (event) { case SND_SOC_DAPM_POST_PMU: - /* change mic bias resistor to 4Kohm */ + /* change mic bias resistor */ snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL, - SGTL5000_BIAS_R_MASK, - SGTL5000_BIAS_R_4k << SGTL5000_BIAS_R_SHIFT); + SGTL5000_BIAS_R_MASK, + sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); break; case SND_SOC_DAPM_PRE_PMD: @@ -1326,7 +1336,16 @@ static int sgtl5000_probe(struct snd_soc_codec *codec) SGTL5000_HP_ZCD_EN | SGTL5000_ADC_ZCD_EN); - snd_soc_write(codec, SGTL5000_CHIP_MIC_CTRL, 2); + switch (sgtl5000->micbias_resistor) { + case SGTL5000_MICBIAS_2K: + case SGTL5000_MICBIAS_4K: + case SGTL5000_MICBIAS_8K: + snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL, + SGTL5000_BIAS_R_MASK, + sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); + default: + break; + } /* * disable DAP @@ -1418,6 +1437,8 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, struct sgtl5000_priv *sgtl5000; int ret, reg, rev; unsigned int mclk; + struct device_node *np = client->dev.of_node; + u32 value; sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv), GFP_KERNEL); @@ -1470,6 +1491,37 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev); sgtl5000->revision = rev; + if (np) { + if (!of_property_read_u32(np, + "sgtl5000-micbias-resistor", &value)) { + switch (value) { + case 0: + sgtl5000->micbias_resistor = + SGTL5000_MICBIAS_OFF; + break; + case 1: + sgtl5000->micbias_resistor = + SGTL5000_MICBIAS_2K; + break; + case 2: + sgtl5000->micbias_resistor = + SGTL5000_MICBIAS_4K; + break; + case 3: + sgtl5000->micbias_resistor = + SGTL5000_MICBIAS_8K; + break; + default: + sgtl5000->micbias_resistor = + SGTL5000_MICBIAS_4K; + dev_err(&client->dev, + "Unsuitable MicBias resistor\n"); + } + } else { + sgtl5000->micbias_resistor = SGTL5000_MICBIAS_4K; + } + } + i2c_set_clientdata(client, sgtl5000); /* Ensure sgtl5000 will start with sane register values */