From patchwork Wed Sep 12 12:19:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-yi Chiang X-Patchwork-Id: 10597411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16EE2920 for ; Wed, 12 Sep 2018 12:20:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E642529DB3 for ; Wed, 12 Sep 2018 12:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA66329DC7; Wed, 12 Sep 2018 12:20:27 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham 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 0CB4F29DC3 for ; Wed, 12 Sep 2018 12:20:26 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 6C35D2677BB; Wed, 12 Sep 2018 14:20:15 +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 6CC92267815; Wed, 12 Sep 2018 14:20:13 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by alsa0.perex.cz (Postfix) with ESMTP id 190B32673F4 for ; Wed, 12 Sep 2018 14:20:09 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id x26-v6so963317pge.12 for ; Wed, 12 Sep 2018 05:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XX9BUw85r/ljBlG69pn1fPXhcwk59z61wwuJst7K/bM=; b=bKXWgFYdYIx83fDBI2COUboshCd0lK/+e9T26PIVVX9l3XNMozx550yLq4eqTyQr8j NJGLaSAkx11UxQWrkXSxuEt1TryIe/+PSFEV6jWV7vXLC+Iv6xM5OF95+t0kqLFQKR+w kX/xE8rLcMtH131xvqf7iDfgLqcEe/FX6giWc= 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:mime-version :content-transfer-encoding; bh=XX9BUw85r/ljBlG69pn1fPXhcwk59z61wwuJst7K/bM=; b=U8wR4EqLOJQOK5Q0GUTrqcTtmXl/w7rmYnbHnJeHSeWBKgEUDOUX4TwODu2S6QaZQi nAiX1X7cMs6qJ1ptqaG8WdBQt1LpiXzOplaq+e1RBFDMtaDuEDJGGFxbwoDLYe+PgW1u W6OxHXvy0h8ewgUXXpV5/8QjhspcTl8jHWiDqTMbNJS9ZdvNMOPdVD0OLlTXl+gIDCj+ M+sx9wkRV8utbJSFQJn2k39NALL+HuJi9i0Yl2NudlsFe2wv2o1MfTRaXznBSchT6pDW 8A8cPHLWX/yi9Hp7SZkCNzFzfqbucOqudAzhwN0ysN53/QrMHxD5RVIxjokgf2tdp81I Cxhg== X-Gm-Message-State: APzg51ArmR8fUt79aQrodbOwj/FgXRqR0FSJCKkugbY9l47YCmClAK1j KCQ8XYdq2rZxoHnsiYDSyAwqXg== X-Google-Smtp-Source: ANB0VdbX4zKz7vWdnWRgyVJhjDWH1K7K0KZNWpJnUsJ1TQrpUxvo3qKPPYYObYwB+bTyZ4FBvOHACw== X-Received: by 2002:a63:ba1c:: with SMTP id k28-v6mr1965745pgf.76.1536754808557; Wed, 12 Sep 2018 05:20:08 -0700 (PDT) Received: from cychiang-z840.tpe.corp.google.com ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id t9-v6sm1729038pgi.87.2018.09.12.05.20.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 05:20:07 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Date: Wed, 12 Sep 2018 20:19:54 +0800 Message-Id: <20180912121955.33048-1-cychiang@chromium.org> X-Mailer: git-send-email 2.19.0.rc2.392.g5ba43deb5a-goog MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Mark Brown , dgreid@chromium.org, ryans.lee@maximintegrated.com, Cheng-Yi Chiang Subject: [alsa-devel] [PATCH 1/2] ASoC: max9892x: Add documentation for reset-gpio 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP max98927 codec driver will support reset-gpio binding so it can toggle reset line in its probe function. Signed-off-by: Cheng-Yi Chiang --- Documentation/devicetree/bindings/sound/max9892x.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/max9892x.txt b/Documentation/devicetree/bindings/sound/max9892x.txt index f6171591ddc61..8bf30483eedcd 100644 --- a/Documentation/devicetree/bindings/sound/max9892x.txt +++ b/Documentation/devicetree/bindings/sound/max9892x.txt @@ -29,6 +29,8 @@ Required properties: Range : 0 (off), 1 (on), Default : 0 - reg : the I2C address of the device for I2C + - reset-gpio: reset gpio the chip is connected to. This is supported + on max98927. Example: @@ -38,4 +40,5 @@ codec: max98927@3a { imon-slot-no = <1>; interleave-mode = <0>; reg = <0x3a>; + reset-gpio = <&tlmm 75 GPIO_ACTIVE_LOW>; }; From patchwork Wed Sep 12 12:19:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-yi Chiang X-Patchwork-Id: 10597413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15A4714F9 for ; Wed, 12 Sep 2018 12:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0227229E19 for ; Wed, 12 Sep 2018 12:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA80229DEE; Wed, 12 Sep 2018 12:20:40 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham 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 29BE829E3A for ; Wed, 12 Sep 2018 12:20:40 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 0A3DB267815; Wed, 12 Sep 2018 14:20:39 +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 AE362267818; Wed, 12 Sep 2018 14:20:36 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by alsa0.perex.cz (Postfix) with ESMTP id D88132673F4 for ; Wed, 12 Sep 2018 14:20:34 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id h79-v6so930734pfk.8 for ; Wed, 12 Sep 2018 05:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bx4U/efRCYPj+DbdOzjjJdclFU9QHreZRHqNGwFsXYo=; b=aOKTVol0aNYDGorMvHx76vyO9F4TLnwdZDHsRbYWfpRpohp7Doxc19nkiX1YxN1pz7 lxjutPNS52mXRP7iCt63N9qOEAjoymEEC7QtG8AyhYhjNufbPsS1PFyEyA0y+aUN/Tpn ECT9cM5lQWE4d0QORuyaxL4AS2HDdgAAytPZg= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=bx4U/efRCYPj+DbdOzjjJdclFU9QHreZRHqNGwFsXYo=; b=DxL2XwKihRylShFm+/O+3v78jPqz+sWVpXuPt2lZTfGqHh9LpmfDEYnvizYjpT01GY hcm0ZVFHvdp+GNc3+YtBO2rF81jg63192uO6RyZFcPAQISGyIPaJhXj0GqaQevy1vR1I plTcoQxb2dvL+GD7YxxhGJDVrwzKeABQ4lqJQNVQEvVbXMQLB+8ozGbNlAVK7GZvaDME z/JTGqRoOxmdYAatv3cpsa4BIEwzMlqkYCtBvA3q9VtVv6ZXSoVGmgQqDYM13vFDrkR6 2Nb8rW0x4o5PPFuxsHjqJeY2xY99CKZSwX0sbX95lnes6YvM6KYtUMXStyNJUXFJjpay b5EA== X-Gm-Message-State: APzg51DUQNum6aLQo/0JdxJOQ1qy1BucW8qP6Ztnitx0/mMS7ic0aSuk 3w33Queh6fA5zNUP8jH8kbno0w== X-Google-Smtp-Source: ANB0VdbzZre5W7iirO5Q2EETc5JhQEOlKFJgpaWjRoIwJTu9j/wWglMWjhujryKSQKdZhghBTfvxiA== X-Received: by 2002:a65:62d8:: with SMTP id m24-v6mr1950853pgv.307.1536754833576; Wed, 12 Sep 2018 05:20:33 -0700 (PDT) Received: from cychiang-z840.tpe.corp.google.com ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id t9-v6sm1729038pgi.87.2018.09.12.05.20.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 05:20:32 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Date: Wed, 12 Sep 2018 20:19:55 +0800 Message-Id: <20180912121955.33048-2-cychiang@chromium.org> X-Mailer: git-send-email 2.19.0.rc2.392.g5ba43deb5a-goog In-Reply-To: <20180912121955.33048-1-cychiang@chromium.org> References: <20180912121955.33048-1-cychiang@chromium.org> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, Mark Brown , dgreid@chromium.org, ryans.lee@maximintegrated.com, Cheng-Yi Chiang Subject: [alsa-devel] [PATCH 2/2] ASoC: max98927: Add reset-gpio 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Toggle reset line in max98927_i2c_probe. Use a list to store max98927 instances so we do not toggle reset line again if more than one instances share the same reset line. Signed-off-by: Cheng-Yi Chiang --- sound/soc/codecs/max98927.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/max98927.h | 2 ++ 2 files changed, 80 insertions(+) diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c index 941712058a8f5..789b27cdfd9e0 100644 --- a/sound/soc/codecs/max98927.c +++ b/sound/soc/codecs/max98927.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -24,6 +25,11 @@ #include #include "max98927.h" +#define MAX98927_MIN_RESET_US 1 +#define MAX98927_RELEASE_RESET_DELAY_US 500 + +static LIST_HEAD(reset_list); + static struct reg_default max98927_reg[] = { {MAX98927_R0001_INT_RAW1, 0x00}, {MAX98927_R0002_INT_RAW2, 0x00}, @@ -877,6 +883,54 @@ static void max98927_slot_config(struct i2c_client *i2c, max98927->i_l_slot = 1; } +static int max98927_i2c_toggle_reset(struct device *dev, + struct max98927_priv *max98927) +{ + /* + * If we do not have reset gpio, assume platform firmware + * controls the regulator and toggles it for us. + */ + if (!max98927->reset_gpio) + return 0; + + gpiod_set_value_cansleep(max98927->reset_gpio, 1); + + /* + * We need to wait a bit before we are allowed to release reset GPIO. + */ + usleep_range(MAX98927_MIN_RESET_US, MAX98927_MIN_RESET_US + 5); + + gpiod_set_value_cansleep(max98927->reset_gpio, 0); + + /* + * We need to wait a bit before I2C communication is available. + */ + usleep_range(MAX98927_RELEASE_RESET_DELAY_US, + MAX98927_RELEASE_RESET_DELAY_US + 5); + + /* + * Release reset GPIO because we are not going to use it. + */ + devm_gpiod_put(dev, max98927->reset_gpio); + + return 0; +} + +static bool max98927_is_first_to_reset(struct max98927_priv *max98927) +{ + struct max98927_priv *p; + + if (!max98927->reset_gpio) + return false; + + list_for_each_entry(p, &reset_list, list) { + if (max98927->reset_gpio == p->reset_gpio) + return false; + } + + return true; +} + static int max98927_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -904,6 +958,28 @@ static int max98927_i2c_probe(struct i2c_client *i2c, } else max98927->interleave_mode = 0; + /* Gets optional GPIO for reset line. */ + max98927->reset_gpio = devm_gpiod_get_optional( + &i2c->dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(max98927->reset_gpio)) { + ret = PTR_ERR(max98927->reset_gpio); + dev_err(&i2c->dev, "error getting reset gpio: %d\n", ret); + return ret; + } + + /* + * Only toggle reset line for the first instance when the + * reset line is shared among instances. For example, + * left and right amplifier share the same reset line, and + * we should only toggle the reset line once. + */ + if (max98927_is_first_to_reset(max98927)) { + dev_info(&i2c->dev, "%s: toggle reset line\n", __func__); + ret = max98927_i2c_toggle_reset(&i2c->dev, max98927); + if (ret) + return ret; + } + /* regmap initialization */ max98927->regmap = devm_regmap_init_i2c(i2c, &max98927_regmap); @@ -934,6 +1010,8 @@ static int max98927_i2c_probe(struct i2c_client *i2c, if (ret < 0) dev_err(&i2c->dev, "Failed to register component: %d\n", ret); + list_add(&max98927->list, &reset_list); + return ret; } diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h index 538992a238b28..d48f61f6c3ba5 100644 --- a/sound/soc/codecs/max98927.h +++ b/sound/soc/codecs/max98927.h @@ -275,5 +275,7 @@ struct max98927_priv { unsigned int master; unsigned int digital_gain; bool tdm_mode; + struct gpio_desc *reset_gpio; + struct list_head list; }; #endif