From patchwork Tue Feb 16 15:19:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pascal Huerst X-Patchwork-Id: 8327861 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 730119F399 for ; Tue, 16 Feb 2016 15:19:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6426320266 for ; Tue, 16 Feb 2016 15:19:49 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 1401C20263 for ; Tue, 16 Feb 2016 15:19:47 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id EAD21265913; Tue, 16 Feb 2016 16:19:40 +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, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 3205F265775; Tue, 16 Feb 2016 16:19:33 +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 DBD6F265823; Tue, 16 Feb 2016 16:19:31 +0100 (CET) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by alsa0.perex.cz (Postfix) with ESMTP id D33D3260824 for ; Tue, 16 Feb 2016 16:19:24 +0100 (CET) Received: by mail-wm0-f48.google.com with SMTP id c200so166864790wme.0 for ; Tue, 16 Feb 2016 07:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=xDIZCQpPfKddvKy8X5VhGWJxGwF2blCboORHq463NdQ=; b=HjSTaTifUuZ2mpb2rqELp21SrQCvNLUZeX7/mqxtyjwARK07xcZ8dTHg1bISkqUUqz 0jDDCvc8XfEZxRUiH857R0glyYbpIe+faFglFTBKv7OqV36CbSxmz2eKUe7t2cGHQlfm BzEEKEsi4XXuocxk3r3/vLyBw5VDGR3ri4eHsSuuvAJiqxWs+sfI/KGF1tprk3zMDpwx Q2vXbOgrM5QlCEdYIpsrmeVE4rG5WcF7BKP46JAnSFFcspPLuxlU2Sp7RPQVxoStGRQA 6D4/kcKTa6YUkX5/JaXCORmVDIOseHqhZYu7nx6M1hMxkJrl2P5kl4ObkHLhxgV6+VDa tYrQ== 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=xDIZCQpPfKddvKy8X5VhGWJxGwF2blCboORHq463NdQ=; b=GH50c+E8gtVWncfzXmM9ghLqdN83nIl6AOW5haRTMWXJdInHqtB370YKuChWyeF8ic HZV+B3q6eYh6wP5zRu/NfslM7TJZ0yVMoMJDQHMb3RQL7nG4P1BcW5Dv7VsV6ApNYFcC 7sqwHOfXOeQuV3sVP3G++rLzoceKsVYCyDbcaB9tW794WFipjQAUYYH69Tzqc6RsKjFS I7npNxbOphIrs4/CY6/GNImLQYZYqhprvt8okwnoOM5v9IraCXrs5aGVXZc73ct10oAj EwlDlfA+Q1IY787aXpM7kzpgw+iTdAwXjORdg4Wxg+J3hAP2x7sEfeHTilzuInKnLQnC 7RHA== X-Gm-Message-State: AG10YOR9QLBfSX6hY5/IdYax8o8zHu8t6g2N9Enz3MsxWGqXxQ0bATcjAVKV/WV/utiJfQ== X-Received: by 10.28.210.73 with SMTP id j70mr18787808wmg.8.1455635964611; Tue, 16 Feb 2016 07:19:24 -0800 (PST) Received: from localhost.localdomain ([212.91.253.218]) by smtp.gmail.com with ESMTPSA id s2sm30713622wjs.39.2016.02.16.07.19.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Feb 2016 07:19:23 -0800 (PST) From: pascal.huerst@gmail.com To: Paul.Handrigan@cirrus.com Date: Tue, 16 Feb 2016 16:19:06 +0100 Message-Id: <1455635946-16267-1-git-send-email-pascal.huerst@gmail.com> X-Mailer: git-send-email 2.5.0 Cc: alsa-devel@alsa-project.org, broonie@kernel.org, Pascal Huerst , lgirdwood@gmail.com Subject: [alsa-devel] [RESEND PATCH] ASoC: cs4271: 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 From: Pascal Huerst The cs4271 has three power domains: vd, vl and va. Enable them all, as long as the codec is in use. While at it, factored out the reset code into its own function. Signed-off-by: Pascal Huerst --- Documentation/devicetree/bindings/sound/cs4271.txt | 7 +++ sound/soc/codecs/cs4271.c | 69 +++++++++++++++++++--- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/cs4271.txt b/Documentation/devicetree/bindings/sound/cs4271.txt index e2cd1d7..6e699ce 100644 --- a/Documentation/devicetree/bindings/sound/cs4271.txt +++ b/Documentation/devicetree/bindings/sound/cs4271.txt @@ -33,12 +33,19 @@ Optional properties: Note that this is not needed in case the clocks are stable throughout the entire runtime of the codec. + - vd-supply: Digital power + - vl-supply: Logic power + - va-supply: Analog Power + Examples: codec_i2c: cs4271@10 { compatible = "cirrus,cs4271"; reg = <0x10>; reset-gpio = <&gpio 23 0>; + vd-supply = <&vdd_3v3_reg>; + vl-supply = <&vdd_3v3_reg>; + va-supply = <&vdd_3v3_reg>; }; codec_spi: cs4271@0 { diff --git a/sound/soc/codecs/cs4271.c b/sound/soc/codecs/cs4271.c index e770ee6..0c0010b 100644 --- a/sound/soc/codecs/cs4271.c +++ b/sound/soc/codecs/cs4271.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -157,6 +158,10 @@ static bool cs4271_volatile_reg(struct device *dev, unsigned int reg) return reg == CS4271_CHIPID; } +static const char * const supply_names[] = { + "vd", "vl", "va" +}; + struct cs4271_private { unsigned int mclk; bool master; @@ -170,6 +175,7 @@ struct cs4271_private { int gpio_disable; /* enable soft reset workaround */ bool enable_soft_reset; + struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; }; static const struct snd_soc_dapm_widget cs4271_dapm_widgets[] = { @@ -487,6 +493,20 @@ static struct snd_soc_dai_driver cs4271_dai = { .symmetric_rates = 1, }; +static int cs4271_reset(struct snd_soc_codec *codec) +{ + struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); + + if (gpio_is_valid(cs4271->gpio_nreset)) { + gpio_set_value(cs4271->gpio_nreset, 0); + mdelay(1); + gpio_set_value(cs4271->gpio_nreset, 1); + mdelay(1); + } + + return 0; +} + #ifdef CONFIG_PM static int cs4271_soc_suspend(struct snd_soc_codec *codec) { @@ -499,6 +519,9 @@ static int cs4271_soc_suspend(struct snd_soc_codec *codec) if (ret < 0) return ret; + regcache_mark_dirty(cs4271->regmap); + regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); + return 0; } @@ -507,6 +530,16 @@ static int cs4271_soc_resume(struct snd_soc_codec *codec) int ret; struct cs4271_private *cs4271 = snd_soc_codec_get_drvdata(codec); + ret = regulator_bulk_enable(ARRAY_SIZE(cs4271->supplies), + cs4271->supplies); + if (ret < 0) { + dev_err(codec->dev, "Failed to enable regulators: %d\n", ret); + return ret; + } + + /* Do a proper reset after power up */ + cs4271_reset(codec); + /* Restore codec state */ ret = regcache_sync(cs4271->regmap); if (ret < 0) @@ -553,19 +586,24 @@ static int cs4271_codec_probe(struct snd_soc_codec *codec) } #endif + ret = regulator_bulk_enable(ARRAY_SIZE(cs4271->supplies), + cs4271->supplies); + if (ret < 0) { + dev_err(codec->dev, "Failed to enable regulators: %d\n", ret); + return ret; + } + if (cs4271plat) { amutec_eq_bmutec = cs4271plat->amutec_eq_bmutec; cs4271->enable_soft_reset = cs4271plat->enable_soft_reset; } - if (gpio_is_valid(cs4271->gpio_nreset)) { - /* Reset codec */ - gpio_direction_output(cs4271->gpio_nreset, 0); - mdelay(1); - gpio_set_value(cs4271->gpio_nreset, 1); - /* Give the codec time to wake up */ - mdelay(1); - } + /* Reset codec */ + cs4271_reset(codec); + + ret = regcache_sync(cs4271->regmap); + if (ret < 0) + return ret; ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, CS4271_MODE2_PDN | CS4271_MODE2_CPEN, @@ -595,6 +633,9 @@ static int cs4271_codec_remove(struct snd_soc_codec *codec) /* Set codec to the reset state */ gpio_set_value(cs4271->gpio_nreset, 0); + regcache_mark_dirty(cs4271->regmap); + regulator_bulk_disable(ARRAY_SIZE(cs4271->supplies), cs4271->supplies); + return 0; }; @@ -617,6 +658,7 @@ static int cs4271_common_probe(struct device *dev, { struct cs4271_platform_data *cs4271plat = dev->platform_data; struct cs4271_private *cs4271; + int i, ret; cs4271 = devm_kzalloc(dev, sizeof(*cs4271), GFP_KERNEL); if (!cs4271) @@ -638,6 +680,17 @@ static int cs4271_common_probe(struct device *dev, return ret; } + for (i = 0; i < ARRAY_SIZE(supply_names); i++) + cs4271->supplies[i].supply = supply_names[i]; + + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(cs4271->supplies), + cs4271->supplies); + + if (ret < 0) { + dev_err(dev, "Failed to get regulators: %d\n", ret); + return ret; + } + *c = cs4271; return 0; }