From patchwork Thu Mar 27 20:42:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 3899711 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 3BF329F334 for ; Thu, 27 Mar 2014 20:42:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 536DC20253 for ; Thu, 27 Mar 2014 20:42:51 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 2C1CF20256 for ; Thu, 27 Mar 2014 20:42:50 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 57EC52654AA; Thu, 27 Mar 2014 21:42:48 +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 84ACB265486; Thu, 27 Mar 2014 21:42:35 +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 52D23265488; Thu, 27 Mar 2014 21:42:34 +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 A5C9B265475 for ; Thu, 27 Mar 2014 21:42:27 +0100 (CET) Received: by mail-ee0-f42.google.com with SMTP id d17so3371961eek.1 for ; Thu, 27 Mar 2014 13:42:27 -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; bh=QsXLXesfBAfZVpUrXBo+UoclqmpHvA5InqMfzLdjGeg=; b=q6h1pQYjMcsjV3FMX7MEW9UEq/rQfJMCYgwLI15dbBLS2ODtqLIcswg99EWR3rPWns 8/fjUg9u86cGg3Lt3bhs2gus5NWvpOnian/wXZhazKOMZXYfOkmHcR0Y9I861f7HTDZD A0S3Atc1Y8Waj1jZJiBFw6jxwWm/f3X4NKx2Tsw8OIJ8110ymtJiRpknjh1VK60A7X1m Y+s7cKvtvnnOoKx0xNfTQJiqzkTKTk6iCc+S9SCCPQhAORwoa52Ys37R2/6OeHvjq2bD yYMu4qWtFK0L6bltZ2OdfK4JHxfgylT3QW4efU5ullOQj/G1D0wDLoJ76/Tj6X917qnR poUw== X-Received: by 10.14.104.135 with SMTP id i7mr4038795eeg.34.1395952947326; Thu, 27 Mar 2014 13:42:27 -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.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Mar 2014 13:42:26 -0700 (PDT) From: Daniel Mack To: broonie@kernel.org Date: Thu, 27 Mar 2014 21:42:14 +0100 Message-Id: <1395952936-10670-1-git-send-email-zonque@gmail.com> X-Mailer: git-send-email 1.8.5.3 Cc: alsa-devel@alsa-project.org, Daniel Mack Subject: [alsa-devel] [PATCH 1/3 v2] ASoC: ak5386: 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 chip has two power supplies, VA and VDD. Enable them both as long as the codec is in use. Signed-off-by: Daniel Mack --- sound/soc/codecs/ak5386.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/sound/soc/codecs/ak5386.c b/sound/soc/codecs/ak5386.c index 72e953b..a30be5c 100644 --- a/sound/soc/codecs/ak5386.c +++ b/sound/soc/codecs/ak5386.c @@ -14,12 +14,18 @@ #include #include #include +#include #include #include #include +static const char const *supply_names[] = { + "va", "vd" +}; + struct ak5386_priv { int reset_gpio; + struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; }; static const struct snd_soc_dapm_widget ak5386_dapm_widgets[] = { @@ -32,7 +38,42 @@ static const struct snd_soc_dapm_route ak5386_dapm_routes[] = { { "Capture", NULL, "AINR" }, }; +static int ak5386_soc_probe(struct snd_soc_codec *codec) +{ + struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); + return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); +} + +static int ak5386_soc_remove(struct snd_soc_codec *codec) +{ + struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); + regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); + return 0; +} + +#ifdef CONFIG_PM +static int ak5386_soc_suspend(struct snd_soc_codec *codec) +{ + struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); + regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); + return 0; +} + +static int ak5386_soc_resume(struct snd_soc_codec *codec) +{ + struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); + return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); +} +#else +#define ak5386_soc_suspend NULL +#define ak5386_soc_resume NULL +#endif /* CONFIG_PM */ + static struct snd_soc_codec_driver soc_codec_ak5386 = { + .probe = ak5386_soc_probe, + .remove = ak5386_soc_remove, + .suspend = ak5386_soc_suspend, + .resume = ak5386_soc_resume, .dapm_widgets = ak5386_dapm_widgets, .num_dapm_widgets = ARRAY_SIZE(ak5386_dapm_widgets), .dapm_routes = ak5386_dapm_routes, @@ -122,6 +163,7 @@ static int ak5386_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct ak5386_priv *priv; + int ret, i; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -130,6 +172,14 @@ static int ak5386_probe(struct platform_device *pdev) priv->reset_gpio = -EINVAL; dev_set_drvdata(dev, priv); + 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) + return ret; + if (of_match_device(of_match_ptr(ak5386_dt_ids), dev)) priv->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpio", 0);