From patchwork Thu Mar 27 20:42:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 3899731 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 36E739F391 for ; Thu, 27 Mar 2014 20:43:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 583C120253 for ; Thu, 27 Mar 2014 20:43:39 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id A421820256 for ; Thu, 27 Mar 2014 20:43:37 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id B73802654D1; Thu, 27 Mar 2014 21:43:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NO_DNS_FOR_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 5307D26549C; Thu, 27 Mar 2014 21:42:39 +0100 (CET) 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 0542026549E; Thu, 27 Mar 2014 21:42:37 +0100 (CET) Received: from mail-ee0-f42.google.com (mail-ee0-f42.google.com [74.125.83.42]) by alsa0.perex.cz (Postfix) with ESMTP id 4C49A26547F for ; Thu, 27 Mar 2014 21:42:30 +0100 (CET) Received: by mail-ee0-f42.google.com with SMTP id d17so3371994eek.1 for ; Thu, 27 Mar 2014 13:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mxYnGgGg3v64D3K2m8zCfFUk/VnvSdn/ZGSf+l9W2fc=; b=P7SaBAYoljyAd593JHpx6rR8iBLw0D+Tm0caEOD8EWbRdy3W4bwMhGDHZl+tZ3XuyT 8uDZNrdAr/mUCSjOY6LwiIFkKspq2nQntIQ9+GW8Od/FdpYF8s5kwmfOL5RlWUEPv7nN jivUuKKoWxrG0w+crsv0/9BjKBIS7hwNUHMkLIv1z2B7YSGJPI9Je1tmrI12Mu76YQeE 2++Wh5wsZtFGTxoUBhAgFmRHMbisPbnWxO279u4VZQ3MthfLrn1UIbGDpU5/0LRfIing ZRJ9UWc7QGrbTKUdUtcWGST6TRb0jTRkOMZHxTb+gijIH1q1nezHQZrz5Bjov6WSoNF9 vZJQ== X-Received: by 10.15.31.137 with SMTP id y9mr4023813eeu.12.1395952950111; Thu, 27 Mar 2014 13:42:30 -0700 (PDT) Received: from tamtam.fritz.box ([2001:4dd0:ff00:9394:224:d7ff:fec6:a0ec]) by mx.google.com with ESMTPSA id s46sm6777292ees.3.2014.03.27.13.42.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Mar 2014 13:42:29 -0700 (PDT) From: Daniel Mack To: broonie@kernel.org Date: Thu, 27 Mar 2014 21:42:16 +0100 Message-Id: <1395952936-10670-3-git-send-email-zonque@gmail.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1395952936-10670-1-git-send-email-zonque@gmail.com> References: <1395952936-10670-1-git-send-email-zonque@gmail.com> Cc: alsa-devel@alsa-project.org, Daniel Mack Subject: [alsa-devel] [PATCH 3/3 v2] ASoC: tas5086: add regulator consumer support 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 The TAS5086 has two power domains, DVDD and AVDD. Enable them both as long as the codec is in use. While at it, move the device identification from the i2c probe to the codec probe, so we do it after the regulators have been enabled. Signed-off-by: Daniel Mack --- sound/soc/codecs/tas5086.c | 64 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/sound/soc/codecs/tas5086.c b/sound/soc/codecs/tas5086.c index a895a5e..2ee03b6 100644 --- a/sound/soc/codecs/tas5086.c +++ b/sound/soc/codecs/tas5086.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -240,6 +241,10 @@ static int tas5086_reg_read(void *context, unsigned int reg, return 0; } +static const char const *supply_names[] = { + "dvdd", "avdd" +}; + struct tas5086_private { struct regmap *regmap; unsigned int mclk, sclk; @@ -251,6 +256,7 @@ struct tas5086_private { int rate; /* GPIO driving Reset pin, if any */ int gpio_nreset; + struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; }; static int tas5086_deemph[] = { 0, 32000, 44100, 48000 }; @@ -773,6 +779,8 @@ static int tas5086_soc_suspend(struct snd_soc_codec *codec) if (ret < 0) return ret; + regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); + return 0; } @@ -781,6 +789,10 @@ static int tas5086_soc_resume(struct snd_soc_codec *codec) struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec); int ret; + ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); + if (ret < 0) + return ret; + tas5086_reset(priv); regcache_mark_dirty(priv->regmap); @@ -812,6 +824,25 @@ static int tas5086_probe(struct snd_soc_codec *codec) struct tas5086_private *priv = snd_soc_codec_get_drvdata(codec); int i, ret; + ret = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); + if (ret < 0) { + dev_err(codec->dev, "Failed to enable regulators: %d\n", ret); + return ret; + } + + tas5086_reset(priv); + + /* The TAS5086 always returns 0x03 in its TAS5086_DEV_ID register */ + ret = regmap_read(priv->regmap, TAS5086_DEV_ID, &i); + if (ret < 0) + goto exit_disable_regulators; + + if (i != 0x3) { + dev_err(codec->dev, + "Failed to identify TAS5086 codec (got %02x)\n", i); + goto exit_disable_regulators; + } + priv->pwm_start_mid_z = 0; priv->charge_period = 1300000; /* hardware default is 1300 ms */ @@ -834,14 +865,19 @@ static int tas5086_probe(struct snd_soc_codec *codec) ret = tas5086_init(codec->dev, priv); if (ret < 0) - return ret; + goto exit_disable_regulators; /* set master volume to 0 dB */ ret = regmap_write(priv->regmap, TAS5086_MASTER_VOL, 0x30); if (ret < 0) - return ret; + goto exit_disable_regulators; return 0; + +exit_disable_regulators: + regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); + + return ret; } static int tas5086_remove(struct snd_soc_codec *codec) @@ -852,6 +888,8 @@ static int tas5086_remove(struct snd_soc_codec *codec) /* Set codec to the reset state */ gpio_set_value(priv->gpio_nreset, 0); + regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); + return 0; }; @@ -900,6 +938,16 @@ static int tas5086_i2c_probe(struct i2c_client *i2c, if (!priv) return -ENOMEM; + for (i = 0; i < ARRAY_SIZE(supply_names); i++) + priv->supplies[i].supply = supply_names[i]; + + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies), + priv->supplies); + if (ret < 0) { + dev_err(dev, "Failed to get regulators: %d\n", ret); + return ret; + } + priv->regmap = devm_regmap_init(dev, NULL, i2c, &tas5086_regmap); if (IS_ERR(priv->regmap)) { ret = PTR_ERR(priv->regmap); @@ -919,18 +967,6 @@ static int tas5086_i2c_probe(struct i2c_client *i2c, gpio_nreset = -EINVAL; priv->gpio_nreset = gpio_nreset; - tas5086_reset(priv); - - /* The TAS5086 always returns 0x03 in its TAS5086_DEV_ID register */ - ret = regmap_read(priv->regmap, TAS5086_DEV_ID, &i); - if (ret < 0) - return ret; - - if (i != 0x3) { - dev_err(dev, - "Failed to identify TAS5086 codec (got %02x)\n", i); - return -ENODEV; - } return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_tas5086, &tas5086_dai, 1);