From patchwork Mon Mar 20 09:13:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9633351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 60721602D6 for ; Mon, 20 Mar 2017 09:14:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B2D72022C for ; Mon, 20 Mar 2017 09:14:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FFA927FA3; Mon, 20 Mar 2017 09:14:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 800862022C for ; Mon, 20 Mar 2017 09:14:08 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id F3D40266D04; Mon, 20 Mar 2017 10:14:05 +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 747CA266D0E; Mon, 20 Mar 2017 10:14:05 +0100 (CET) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by alsa0.perex.cz (Postfix) with ESMTP id 5A117266CC6 for ; Mon, 20 Mar 2017 10:13:58 +0100 (CET) Received: by mail-lf0-f47.google.com with SMTP id z15so52730897lfd.1 for ; Mon, 20 Mar 2017 02:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=QoFZqGRiYCdVX1cXzjSJqP5zqgznJ8o1iziLgcj3aA0=; b=U7fX6EgTWqv+xCHN1W0uI5vABuz9WgvJNNuQRLI0tklNbL3jqgQ9kdn11BBBl3Yy6E ubTF5Or3FJtyRquszkONKlo2tVzGtOCpfRJgnPr2IVC5KyDpc60XxBIsvoWI2nJr0X0h 63J6BYfx07Mi+g23Da3hDcMWoUEo4c5fWO/CE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QoFZqGRiYCdVX1cXzjSJqP5zqgznJ8o1iziLgcj3aA0=; b=jpSjrEMJunt9S1ITz1XQy6g0ivAzXrP0Fs6yauxbzsySGeNBMbpzFyvONzy08RLL2X cVWY4PZKVkZ1TsTzEILj2k6TDzkt6yGR4Yx4+NsjPyzMSVbULcwPZDXjEsE30eNJItQZ E67BQmS/OoJ3KEkX9bsR9Z0R3PxYff0sbcq0CfiHTAB4bLX4FbwOWZDU3FovUeNN30ih DdoAdNviCW8ldIC5nlq2TXiQHrj2+B8ryj9YncC8ScNwkLKLiWzMIgrHyS3scPqETVHm p8xuaUqk7FcU/PPpKMujyKSdJPeQvSHfqgslWStDF22aUkeKee+ba7GkaZ+O4wAl9KTd ssBg== X-Gm-Message-State: AFeK/H3shMsfi+VW2mg2ypwyz79idjGOBm0g6AqekKfnZZLVW4i1z1VKYfRsA/V5ENfeHtXw X-Received: by 10.46.7.18 with SMTP id 18mr8799909ljh.5.1490001238302; Mon, 20 Mar 2017 02:13:58 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id h24sm2931988ljb.46.2017.03.20.02.13.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 02:13:57 -0700 (PDT) From: Linus Walleij To: Liam Girdwood , Mark Brown Date: Mon, 20 Mar 2017 10:13:52 +0100 Message-Id: <20170320091352.4115-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Stephen Warren , Linus Walleij , Charles Keepax Subject: [alsa-devel] [PATCH] ASoC: wm8903: add regulator handling 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 WM8903 has four different voltage inputs: AVDD, CPVDD, DBVDD and DCVDD. On the Qualcomm APQ8060 Dragonboard these are all supplied from proper regulators and thus need activating and binding. This is a quick-and-dirty solution just grabbing and enabling the regulator supplies on probe() and disabling them on remove() and the errorpath. More elaborate power management is likely possible. I assume the nVidia designs using this codec have some hard-wired always-on power and will be happy with using the dummy regulators for this. But someone from the nVidia camp should probably check whether they can bind these to proper regulators instead. We also amend the DT binding document. A small change like this does not warrant a separate patch for augmenting these. Cc: devicetree@vger.kernel.org Cc: Mark Brown Cc: Liam Girdwood Cc: Stephen Warren Cc: Charles Keepax Signed-off-by: Linus Walleij Acked-by: Charles Keepax Acked-by: Rob Herring Tested-by: Stephen Warren --- Mark: I was thinking about adding runtime PM for disabling these regulators when unused, but I'm uncertain about the interaction with DAPM in that regard. This atleast gives us control over the supplies. --- Documentation/devicetree/bindings/sound/wm8903.txt | 13 +++++++++ sound/soc/codecs/wm8903.c | 31 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/wm8903.txt b/Documentation/devicetree/bindings/sound/wm8903.txt index 94ec32c194bb..afc51caf1137 100644 --- a/Documentation/devicetree/bindings/sound/wm8903.txt +++ b/Documentation/devicetree/bindings/sound/wm8903.txt @@ -28,6 +28,14 @@ Optional properties: performed. If any entry has the value 0xffffffff, that GPIO's configuration will not be modified. + - AVDD-supply : Analog power supply regulator on the AVDD pin. + + - CPVDD-supply : Charge pump supply regulator on the CPVDD pin. + + - DBVDD-supply : Digital buffer supply regulator for the DBVDD pin. + + - DCVDD-supply : Digital core supply regulator for the DCVDD pin. + Pins on the device (for linking into audio routes): * IN1L @@ -54,6 +62,11 @@ codec: wm8903@1a { reg = <0x1a>; interrupts = < 347 >; + AVDD-supply = <&fooreg_a>; + CPVDD-supply = <&fooreg_b>; + DBVDD-supply = <&fooreg_c>; + DCVDC-supply = <&fooreg_d>; + gpio-controller; #gpio-cells = <2>; diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c index 6e887c2c42b1..237eeb9a8b97 100644 --- a/sound/soc/codecs/wm8903.c +++ b/sound/soc/codecs/wm8903.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -115,10 +116,19 @@ static const struct reg_default wm8903_reg_defaults[] = { { 172, 0x0000 }, /* R172 - Analogue Output Bias 0 */ }; +#define WM8903_NUM_SUPPLIES 4 +static const char *wm8903_supply_names[WM8903_NUM_SUPPLIES] = { + "AVDD", + "CPVDD", + "DBVDD", + "DCVDD", +}; + struct wm8903_priv { struct wm8903_platform_data *pdata; struct device *dev; struct regmap *regmap; + struct regulator_bulk_data supplies[WM8903_NUM_SUPPLIES]; int sysclk; int irq; @@ -2030,6 +2040,23 @@ static int wm8903_i2c_probe(struct i2c_client *i2c, pdata = wm8903->pdata; + for (i = 0; i < ARRAY_SIZE(wm8903->supplies); i++) + wm8903->supplies[i].supply = wm8903_supply_names[i]; + + ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8903->supplies), + wm8903->supplies); + if (ret != 0) { + dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); + return ret; + } + + ret = regulator_bulk_enable(ARRAY_SIZE(wm8903->supplies), + wm8903->supplies); + if (ret != 0) { + dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); + return ret; + } + ret = regmap_read(wm8903->regmap, WM8903_SW_RESET_AND_ID, &val); if (ret != 0) { dev_err(&i2c->dev, "Failed to read chip ID: %d\n", ret); @@ -2160,6 +2187,8 @@ static int wm8903_i2c_probe(struct i2c_client *i2c, return 0; err: + regulator_bulk_disable(ARRAY_SIZE(wm8903->supplies), + wm8903->supplies); return ret; } @@ -2167,6 +2196,8 @@ static int wm8903_i2c_remove(struct i2c_client *client) { struct wm8903_priv *wm8903 = i2c_get_clientdata(client); + regulator_bulk_disable(ARRAY_SIZE(wm8903->supplies), + wm8903->supplies); if (client->irq) free_irq(client->irq, wm8903); wm8903_free_gpio(wm8903);