From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F13DCCA47A for ; Thu, 16 Jun 2022 20:49:25 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id AF9001AF0; Thu, 16 Jun 2022 22:48:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AF9001AF0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1655412563; bh=LFDox7Kp2mfWd5orHwgK+rckE7MAHDYJPFPjOlbb4u0=; h=Date:From:To:Subject:References:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=DgutI+guw7YIah920purxtF5jz/2vhS15e7kJW3/HoSxIyob+Qpnf5CP6FxaHjU49 SbtmfuaSmYxBN2JQHlBB/a/Plvd4KMARQai6ACClDBQMfrndhaknFqV/tRCDuKc7N/ m848A/7nrNqaChnphWbMA9uH93qrXtG/IYeTyLDI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 33A33F8012A; Thu, 16 Jun 2022 22:48:33 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1FF39F800B9; Thu, 16 Jun 2022 22:48:32 +0200 (CEST) Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8E0B9F800B9 for ; Thu, 16 Jun 2022 22:48:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8E0B9F800B9 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="i/kH0v1d" Received: by mail-pj1-x102f.google.com with SMTP id t3-20020a17090a510300b001ea87ef9a3dso2477349pjh.4 for ; Thu, 16 Jun 2022 13:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=i/kH0v1dne6Zn8uPbB1ueElswUjgT/yTFXTNnBQmQqVWocWZxvGDRFwBQPCgEjZcwt DHW+izRBKx0cz2xBlUq2RrN9DJ22qLSQ47bRF9P/mGJLryASSGePSxfmcFgmUCas2i23 asnkOlYviO3+ExgPo+5i6i0gV6JqUhM2S/znM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=pwadgP268sopw0iKleWYGQ30gBU+BbF85Stuum/Yx3/otX7EYnRfe2IKszNBo+XwRG eDZGqgjQ9sNGWvrTd/eac7O89bBSMVVeWz+W52cNYGjn4nTHqaV8E6O5KzaN9RBPbsih CGkvGZBW9ZyhlybP0AeKc/Xl6Pb6TJPUjVFxZBDS1kkQHLu3jCxARJmC42Tz48OyCah4 4wU3BAPs6a7v9XKyx9kMCOuhkz0DKtGpFgdaKlXo2NP0/x8jXFIvqxTMXzbtngns8RG8 +PKArPLc+QPhKhB44O2kbLvcCsdPyzMd8t7UPW3i4//J+nmbPLjL2bQQlM4TfqslXzvF r+Fw== X-Gm-Message-State: AJIora/U90QdLPQ/w2J628ebCCXtB+2jXVhSoyzZSYCOKjv7ES3TrgzW YXbG2+GAJ54RJYZuZyPx43BnPg== X-Google-Smtp-Source: AGRyM1sXlJmDftLj2gIeCg+QvZItPdfFXrzD22pR9q6/q1KwqJH22TcK4LdHMUYCPdy8v2eU0G7bwA== X-Received: by 2002:a17:90b:2310:b0:1e8:8379:6098 with SMTP id mt16-20020a17090b231000b001e883796098mr6832173pjb.112.1655412500987; Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Received: from google.com ([2620:15c:202:201:4709:a407:1ca6:24ea]) by smtp.gmail.com with ESMTPSA id fs20-20020a17090af29400b001ea75a02805sm4221264pjb.52.2022.06.16.13.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Date: Thu, 16 Jun 2022 13:48:18 -0700 From: Brian Norris To: Judy Hsiao Subject: Re: [PATCH v2 1/3] ASoC: rockchip: i2s: switch BCLK to GPIO Message-ID: References: <20220616155836.3401420-1-judyhsiao@chromium.org> <20220616155836.3401420-2-judyhsiao@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220616155836.3401420-2-judyhsiao@chromium.org> Cc: alsa-devel@alsa-project.org, Heiko Stuebner , linux-kernel@vger.kernel.org, Liam Girdwood , Rob Herring , linux-rockchip@lists.infradead.org, Mark Brown , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" Hi, On Thu, Jun 16, 2022 at 03:58:34PM +0000, Judy Hsiao wrote: > We discoverd that the state of BCLK on, LRCLK off and SD_MODE on > may cause the speaker melting issue. Removing LRCLK while BCLK > is present can cause unexpected output behavior including a large > DC output voltage as described in the Max98357a datasheet. > > In order to: > 1. prevent BCLK from turning on by other component. > 2. keep BCLK and LRCLK being present at the same time > > This patch switches BCLK to GPIO func before LRCLK output, and > configures BCLK func back during LRCLK is output. > > Without this fix, BCLK is turned on 11 ms earlier than LRCK by the > da7219. > With this fix, BCLK is turned on only 0.4 ms earlier than LRCK by > the rockchip codec. > > Signed-off-by: Judy Hsiao It feels like a lot of the noise in this patch is due to adding additional error handling, unrelated to the real change you're making. Maybe that deserves a separate patch? > --- > sound/soc/rockchip/rockchip_i2s.c | 134 ++++++++++++++++++++++++------ > 1 file changed, 108 insertions(+), 26 deletions(-) > > diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c > index 47a3971a9ce1..574d3d0900c4 100644 > --- a/sound/soc/rockchip/rockchip_i2s.c > +++ b/sound/soc/rockchip/rockchip_i2s.c > @@ -54,8 +54,40 @@ struct rk_i2s_dev { > const struct rk_i2s_pins *pins; > unsigned int bclk_ratio; > spinlock_t lock; /* tx/rx lock */ > + struct pinctrl *pinctrl; > + struct pinctrl_state *bclk_on; > + struct pinctrl_state *bclk_off; > }; > > +static int i2s_pinctrl_select_bclk_on(struct rk_i2s_dev *i2s) > +{ > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_on)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_on); > + > + if (ret) > + dev_err(i2s->dev, "bclk enable failed %d\n", ret); > + > + return ret; > +} > + > +static int i2s_pinctrl_select_bclk_off(struct rk_i2s_dev *i2s) > +{ > + > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_off)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_off); > + > + if (ret) > + dev_err(i2s->dev, "bclk disable failed %d\n", ret); > + > + return ret; > +} > + > static int i2s_runtime_suspend(struct device *dev) > { > struct rk_i2s_dev *i2s = dev_get_drvdata(dev); > @@ -92,39 +124,46 @@ static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai) > return snd_soc_dai_get_drvdata(dai); > } > > -static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > +static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > - > + int ret = 0; > + > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); I mentioned this off-list, but the 2nd-line indentation alignment *used* to be in a very particular style, and you've moved that around a lot. To match the previous style, it should be: ret = regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); (BTW, if you're using Gmail to view this, you're going to have no idea what I'm talking about, since it doesn't do whitespace or monospace font correctly...) The same applies throughout; most of the 2nd-line, 3rd-line, ... indentation is a little weird. > - > - regmap_update_bits(i2s->regmap, I2S_XFER, > + if (ret < 0) > + goto end; > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->tx_start = true; > } else { > i2s->tx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->rx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -138,42 +177,55 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > + int ret = 0; > > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); > + if (ret < 0) > + goto end; > > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->rx_start = true; > } else { > i2s->rx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->tx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > - I2S_XFER_RXS_START, > + I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -187,7 +239,12 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, > @@ -425,17 +482,25 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream, > case SNDRV_PCM_TRIGGER_RESUME: > case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: > if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 1); > + ret = rockchip_snd_rxctrl(i2s, 1); > else > - rockchip_snd_txctrl(i2s, 1); > + ret = rockchip_snd_txctrl(i2s, 1); > + if (ret < 0) > + return ret; > + i2s_pinctrl_select_bclk_on(i2s); > break; > case SNDRV_PCM_TRIGGER_SUSPEND: > case SNDRV_PCM_TRIGGER_STOP: > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: > - if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 0); > - else > - rockchip_snd_txctrl(i2s, 0); > + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { > + if (!i2s->tx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_rxctrl(i2s, 0); > + } else { > + if (!i2s->rx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_txctrl(i2s, 0); > + } > break; > default: > ret = -EINVAL; > @@ -736,6 +801,23 @@ static int rockchip_i2s_probe(struct platform_device *pdev) > } > > i2s->bclk_ratio = 64; > + i2s->pinctrl = devm_pinctrl_get(&pdev->dev); > + if (IS_ERR(i2s->pinctrl)) > + dev_err(&pdev->dev, "failed to find i2s pinctrl\n"); > + > + i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_on"); > + if (!IS_ERR_OR_NULL(i2s->bclk_on)) { > + dev_info(&pdev->dev, "switch bclk to GPIO func\n"); I don't think we need this printed at the KERN_INFO level. Either drop it, or maybe dev_dbg(). Brian > + i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_off"); > + if (IS_ERR_OR_NULL(i2s->bclk_off)) { > + dev_err(&pdev->dev, "failed to find i2s bclk_off\n"); > + goto err_clk; > + } > + } > + > + i2s_pinctrl_select_bclk_off(i2s); > > dev_set_drvdata(&pdev->dev, i2s); > > -- > 2.36.1.476.g0c4daa206d-goog > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F78CC433EF for ; Thu, 16 Jun 2022 20:52:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=04IMDRjMw+4SqZmx8UOZHoSUCHUfKIhNnEolviNhCRg=; b=TRoriUQ1FV1iO/ RmUm2iRKwJOnWKnYsaUG42iA7IfYzV61mwNsfDzrfEejcigbtlWM0P9Ib7Mt00IpiN36DSj8Dt3i5 W88CoQHiW8wve2l+k4qk7Wzuq2dD/WAbq62FGkBj1rAZar8jPqdzdXLfdl9ekAPVkJYfWrsRWpI0g JgsCEspzyBRuRXaEVmrKRvvhlEXzfeyJZ7rp1A+IUaP+ZXFZcx2P4Z1ymL280JKie1xlRyfmX1HEl IPaFDVvEU8tFi34DbnoDUzk7P5it82W6gnGzYGWNoUqV2sYCtVuDQsDa0OsfRzfizBuYbGnNV6gyn 9OIcWXp+12Um9eo7h6iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1wTb-004IA0-40; Thu, 16 Jun 2022 20:52:27 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1wPg-004Fxn-0E for linux-rockchip@lists.infradead.org; Thu, 16 Jun 2022 20:48:25 +0000 Received: by mail-pj1-x102d.google.com with SMTP id b12-20020a17090a6acc00b001ec2b181c98so1236602pjm.4 for ; Thu, 16 Jun 2022 13:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=i/kH0v1dne6Zn8uPbB1ueElswUjgT/yTFXTNnBQmQqVWocWZxvGDRFwBQPCgEjZcwt DHW+izRBKx0cz2xBlUq2RrN9DJ22qLSQ47bRF9P/mGJLryASSGePSxfmcFgmUCas2i23 asnkOlYviO3+ExgPo+5i6i0gV6JqUhM2S/znM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=PWS1TeBYVhZhw3XMwmL+r0AeI4r3elY6MJPxZdIHgy/sv5mD4X09+sdjhxCoMAzchg /XQZUcB+a1LqIR2/9riCNR62fj7uZ9lL6tsqxoypnmgkoPV91XSaOzAFvsyWTS+eE8Oo A6u4G58KoPiUsulH5PoIoWOx2ObE+EqiVksADjieAaAfx2TqoJZbBXsBHmpJ2Iv3dXEq OIAEPV9ircr8Pc2zd0aGKywmcnB3UCRqS7ftkzTWgEkUvDjL87Wcy8aLFuC93+W7hCMW 5IPTPLUPhwEdLvSyBnVm03J/HUYa/hhvZ/oJZE4icPZ6nJepcgBzm9YYdqS25p5YM2Fu sSuA== X-Gm-Message-State: AJIora8ZWsMTqqw5CJvnVRItQMnoBxYQKLpJ0ZsHBsq+KmFrVMe1mmph YZRwzHUo/YTxPUDN/gQmhy/y8w== X-Google-Smtp-Source: AGRyM1sXlJmDftLj2gIeCg+QvZItPdfFXrzD22pR9q6/q1KwqJH22TcK4LdHMUYCPdy8v2eU0G7bwA== X-Received: by 2002:a17:90b:2310:b0:1e8:8379:6098 with SMTP id mt16-20020a17090b231000b001e883796098mr6832173pjb.112.1655412500987; Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Received: from google.com ([2620:15c:202:201:4709:a407:1ca6:24ea]) by smtp.gmail.com with ESMTPSA id fs20-20020a17090af29400b001ea75a02805sm4221264pjb.52.2022.06.16.13.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Date: Thu, 16 Jun 2022 13:48:18 -0700 From: Brian Norris To: Judy Hsiao Cc: Heiko Stuebner , Liam Girdwood , Rob Herring , Mark Brown , Jaroslav Kysela , Chen-Yu Tsai , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] ASoC: rockchip: i2s: switch BCLK to GPIO Message-ID: References: <20220616155836.3401420-1-judyhsiao@chromium.org> <20220616155836.3401420-2-judyhsiao@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220616155836.3401420-2-judyhsiao@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220616_134824_105195_3996645E X-CRM114-Status: GOOD ( 35.99 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org Hi, On Thu, Jun 16, 2022 at 03:58:34PM +0000, Judy Hsiao wrote: > We discoverd that the state of BCLK on, LRCLK off and SD_MODE on > may cause the speaker melting issue. Removing LRCLK while BCLK > is present can cause unexpected output behavior including a large > DC output voltage as described in the Max98357a datasheet. > > In order to: > 1. prevent BCLK from turning on by other component. > 2. keep BCLK and LRCLK being present at the same time > > This patch switches BCLK to GPIO func before LRCLK output, and > configures BCLK func back during LRCLK is output. > > Without this fix, BCLK is turned on 11 ms earlier than LRCK by the > da7219. > With this fix, BCLK is turned on only 0.4 ms earlier than LRCK by > the rockchip codec. > > Signed-off-by: Judy Hsiao It feels like a lot of the noise in this patch is due to adding additional error handling, unrelated to the real change you're making. Maybe that deserves a separate patch? > --- > sound/soc/rockchip/rockchip_i2s.c | 134 ++++++++++++++++++++++++------ > 1 file changed, 108 insertions(+), 26 deletions(-) > > diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c > index 47a3971a9ce1..574d3d0900c4 100644 > --- a/sound/soc/rockchip/rockchip_i2s.c > +++ b/sound/soc/rockchip/rockchip_i2s.c > @@ -54,8 +54,40 @@ struct rk_i2s_dev { > const struct rk_i2s_pins *pins; > unsigned int bclk_ratio; > spinlock_t lock; /* tx/rx lock */ > + struct pinctrl *pinctrl; > + struct pinctrl_state *bclk_on; > + struct pinctrl_state *bclk_off; > }; > > +static int i2s_pinctrl_select_bclk_on(struct rk_i2s_dev *i2s) > +{ > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_on)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_on); > + > + if (ret) > + dev_err(i2s->dev, "bclk enable failed %d\n", ret); > + > + return ret; > +} > + > +static int i2s_pinctrl_select_bclk_off(struct rk_i2s_dev *i2s) > +{ > + > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_off)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_off); > + > + if (ret) > + dev_err(i2s->dev, "bclk disable failed %d\n", ret); > + > + return ret; > +} > + > static int i2s_runtime_suspend(struct device *dev) > { > struct rk_i2s_dev *i2s = dev_get_drvdata(dev); > @@ -92,39 +124,46 @@ static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai) > return snd_soc_dai_get_drvdata(dai); > } > > -static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > +static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > - > + int ret = 0; > + > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); I mentioned this off-list, but the 2nd-line indentation alignment *used* to be in a very particular style, and you've moved that around a lot. To match the previous style, it should be: ret = regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); (BTW, if you're using Gmail to view this, you're going to have no idea what I'm talking about, since it doesn't do whitespace or monospace font correctly...) The same applies throughout; most of the 2nd-line, 3rd-line, ... indentation is a little weird. > - > - regmap_update_bits(i2s->regmap, I2S_XFER, > + if (ret < 0) > + goto end; > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->tx_start = true; > } else { > i2s->tx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->rx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -138,42 +177,55 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > + int ret = 0; > > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); > + if (ret < 0) > + goto end; > > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->rx_start = true; > } else { > i2s->rx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->tx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > - I2S_XFER_RXS_START, > + I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -187,7 +239,12 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, > @@ -425,17 +482,25 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream, > case SNDRV_PCM_TRIGGER_RESUME: > case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: > if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 1); > + ret = rockchip_snd_rxctrl(i2s, 1); > else > - rockchip_snd_txctrl(i2s, 1); > + ret = rockchip_snd_txctrl(i2s, 1); > + if (ret < 0) > + return ret; > + i2s_pinctrl_select_bclk_on(i2s); > break; > case SNDRV_PCM_TRIGGER_SUSPEND: > case SNDRV_PCM_TRIGGER_STOP: > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: > - if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 0); > - else > - rockchip_snd_txctrl(i2s, 0); > + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { > + if (!i2s->tx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_rxctrl(i2s, 0); > + } else { > + if (!i2s->rx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_txctrl(i2s, 0); > + } > break; > default: > ret = -EINVAL; > @@ -736,6 +801,23 @@ static int rockchip_i2s_probe(struct platform_device *pdev) > } > > i2s->bclk_ratio = 64; > + i2s->pinctrl = devm_pinctrl_get(&pdev->dev); > + if (IS_ERR(i2s->pinctrl)) > + dev_err(&pdev->dev, "failed to find i2s pinctrl\n"); > + > + i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_on"); > + if (!IS_ERR_OR_NULL(i2s->bclk_on)) { > + dev_info(&pdev->dev, "switch bclk to GPIO func\n"); I don't think we need this printed at the KERN_INFO level. Either drop it, or maybe dev_dbg(). Brian > + i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_off"); > + if (IS_ERR_OR_NULL(i2s->bclk_off)) { > + dev_err(&pdev->dev, "failed to find i2s bclk_off\n"); > + goto err_clk; > + } > + } > + > + i2s_pinctrl_select_bclk_off(i2s); > > dev_set_drvdata(&pdev->dev, i2s); > > -- > 2.36.1.476.g0c4daa206d-goog > _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1229C43334 for ; Thu, 16 Jun 2022 20:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QgXR4T5YaMKkktzYpf3XsX95hFcPhQDeg9SmTLYaLuQ=; b=ponU5S+OEFYPof VIWzmDv0RhGD9xCNedRVeQsBiTkiSgo+JjsE/b30fU/YYRiWcm30XCH2PuDdYeP8QB75znYLsCyqO meL3mI6isFQjd7OjPyL/MoPdp1aPqWm+vNEbbdVO6z4K4q8lY9hcZpByA89dxCu3YlRSpYGdHrf4F jY14lXordUnILAkLnlHkMCM3hN5Bk3esJyE0ncsrGfYeE951MGx2+nwEoZpZzHPGSySq4yxAu6MME gW+904uEJFpY87aGn6z6gxDBeRerFBP3xCouxJeDZpzj//jyW9ciGn23c8dZHBXxJnARReIkVZ5ZP QloxS6rAwJKIcpeiVo5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1wT8-004Hv6-QR; Thu, 16 Jun 2022 20:51:59 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o1wPd-004Fxk-Ix for linux-arm-kernel@lists.infradead.org; Thu, 16 Jun 2022 20:48:23 +0000 Received: by mail-pj1-x102b.google.com with SMTP id k12-20020a17090a404c00b001eaabc1fe5dso2846399pjg.1 for ; Thu, 16 Jun 2022 13:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=i/kH0v1dne6Zn8uPbB1ueElswUjgT/yTFXTNnBQmQqVWocWZxvGDRFwBQPCgEjZcwt DHW+izRBKx0cz2xBlUq2RrN9DJ22qLSQ47bRF9P/mGJLryASSGePSxfmcFgmUCas2i23 asnkOlYviO3+ExgPo+5i6i0gV6JqUhM2S/znM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=hHG9SL/vl5XtApK+0hZ53UB7pHGktf9yfsxqIwFOSxkW3bTUcCSihrJNDwu6Bhx70p OtWBTVGr2XI3lZCbrqzGvTrT2ykinvL6EowvdpEaAQZrp+leLraO44YojM6XwURYgj2I iQbmD1TzYkgj9orE/YWPYLOFlWU8fBa2bX/oHm9SZDMBD0eVxzFYMfBQHDrGD6UAYYjL lvyJH54SBypdHZTPJIOJtNR6M/cr4xrfIhWZR2CNmCWtR8xnGr4Z6ARgqchYm/f9S+Hl sHE3rUWmz8O/zqnovPWOF5bsWhNKzqAGR+Ff4a9+uXJYqb+FvpUbBDJsIqe3xEQZIGUS GQKg== X-Gm-Message-State: AJIora/Vv+6aDaIsn2NXssjCRlFD4U2ivxWy/c3DUrO+AMKG/6A9JQw7 sh06rKmqey54jauJ3kPvI6rtFg== X-Google-Smtp-Source: AGRyM1sXlJmDftLj2gIeCg+QvZItPdfFXrzD22pR9q6/q1KwqJH22TcK4LdHMUYCPdy8v2eU0G7bwA== X-Received: by 2002:a17:90b:2310:b0:1e8:8379:6098 with SMTP id mt16-20020a17090b231000b001e883796098mr6832173pjb.112.1655412500987; Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Received: from google.com ([2620:15c:202:201:4709:a407:1ca6:24ea]) by smtp.gmail.com with ESMTPSA id fs20-20020a17090af29400b001ea75a02805sm4221264pjb.52.2022.06.16.13.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Date: Thu, 16 Jun 2022 13:48:18 -0700 From: Brian Norris To: Judy Hsiao Cc: Heiko Stuebner , Liam Girdwood , Rob Herring , Mark Brown , Jaroslav Kysela , Chen-Yu Tsai , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] ASoC: rockchip: i2s: switch BCLK to GPIO Message-ID: References: <20220616155836.3401420-1-judyhsiao@chromium.org> <20220616155836.3401420-2-judyhsiao@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220616155836.3401420-2-judyhsiao@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220616_134821_721568_BAB61CCD X-CRM114-Status: GOOD ( 37.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On Thu, Jun 16, 2022 at 03:58:34PM +0000, Judy Hsiao wrote: > We discoverd that the state of BCLK on, LRCLK off and SD_MODE on > may cause the speaker melting issue. Removing LRCLK while BCLK > is present can cause unexpected output behavior including a large > DC output voltage as described in the Max98357a datasheet. > > In order to: > 1. prevent BCLK from turning on by other component. > 2. keep BCLK and LRCLK being present at the same time > > This patch switches BCLK to GPIO func before LRCLK output, and > configures BCLK func back during LRCLK is output. > > Without this fix, BCLK is turned on 11 ms earlier than LRCK by the > da7219. > With this fix, BCLK is turned on only 0.4 ms earlier than LRCK by > the rockchip codec. > > Signed-off-by: Judy Hsiao It feels like a lot of the noise in this patch is due to adding additional error handling, unrelated to the real change you're making. Maybe that deserves a separate patch? > --- > sound/soc/rockchip/rockchip_i2s.c | 134 ++++++++++++++++++++++++------ > 1 file changed, 108 insertions(+), 26 deletions(-) > > diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c > index 47a3971a9ce1..574d3d0900c4 100644 > --- a/sound/soc/rockchip/rockchip_i2s.c > +++ b/sound/soc/rockchip/rockchip_i2s.c > @@ -54,8 +54,40 @@ struct rk_i2s_dev { > const struct rk_i2s_pins *pins; > unsigned int bclk_ratio; > spinlock_t lock; /* tx/rx lock */ > + struct pinctrl *pinctrl; > + struct pinctrl_state *bclk_on; > + struct pinctrl_state *bclk_off; > }; > > +static int i2s_pinctrl_select_bclk_on(struct rk_i2s_dev *i2s) > +{ > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_on)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_on); > + > + if (ret) > + dev_err(i2s->dev, "bclk enable failed %d\n", ret); > + > + return ret; > +} > + > +static int i2s_pinctrl_select_bclk_off(struct rk_i2s_dev *i2s) > +{ > + > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_off)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_off); > + > + if (ret) > + dev_err(i2s->dev, "bclk disable failed %d\n", ret); > + > + return ret; > +} > + > static int i2s_runtime_suspend(struct device *dev) > { > struct rk_i2s_dev *i2s = dev_get_drvdata(dev); > @@ -92,39 +124,46 @@ static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai) > return snd_soc_dai_get_drvdata(dai); > } > > -static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > +static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > - > + int ret = 0; > + > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); I mentioned this off-list, but the 2nd-line indentation alignment *used* to be in a very particular style, and you've moved that around a lot. To match the previous style, it should be: ret = regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); (BTW, if you're using Gmail to view this, you're going to have no idea what I'm talking about, since it doesn't do whitespace or monospace font correctly...) The same applies throughout; most of the 2nd-line, 3rd-line, ... indentation is a little weird. > - > - regmap_update_bits(i2s->regmap, I2S_XFER, > + if (ret < 0) > + goto end; > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->tx_start = true; > } else { > i2s->tx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->rx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -138,42 +177,55 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > + int ret = 0; > > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); > + if (ret < 0) > + goto end; > > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->rx_start = true; > } else { > i2s->rx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->tx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > - I2S_XFER_RXS_START, > + I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -187,7 +239,12 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, > @@ -425,17 +482,25 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream, > case SNDRV_PCM_TRIGGER_RESUME: > case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: > if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 1); > + ret = rockchip_snd_rxctrl(i2s, 1); > else > - rockchip_snd_txctrl(i2s, 1); > + ret = rockchip_snd_txctrl(i2s, 1); > + if (ret < 0) > + return ret; > + i2s_pinctrl_select_bclk_on(i2s); > break; > case SNDRV_PCM_TRIGGER_SUSPEND: > case SNDRV_PCM_TRIGGER_STOP: > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: > - if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 0); > - else > - rockchip_snd_txctrl(i2s, 0); > + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { > + if (!i2s->tx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_rxctrl(i2s, 0); > + } else { > + if (!i2s->rx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_txctrl(i2s, 0); > + } > break; > default: > ret = -EINVAL; > @@ -736,6 +801,23 @@ static int rockchip_i2s_probe(struct platform_device *pdev) > } > > i2s->bclk_ratio = 64; > + i2s->pinctrl = devm_pinctrl_get(&pdev->dev); > + if (IS_ERR(i2s->pinctrl)) > + dev_err(&pdev->dev, "failed to find i2s pinctrl\n"); > + > + i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_on"); > + if (!IS_ERR_OR_NULL(i2s->bclk_on)) { > + dev_info(&pdev->dev, "switch bclk to GPIO func\n"); I don't think we need this printed at the KERN_INFO level. Either drop it, or maybe dev_dbg(). Brian > + i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_off"); > + if (IS_ERR_OR_NULL(i2s->bclk_off)) { > + dev_err(&pdev->dev, "failed to find i2s bclk_off\n"); > + goto err_clk; > + } > + } > + > + i2s_pinctrl_select_bclk_off(i2s); > > dev_set_drvdata(&pdev->dev, i2s); > > -- > 2.36.1.476.g0c4daa206d-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8484C433EF for ; Thu, 16 Jun 2022 20:49:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378968AbiFPUtN (ORCPT ); Thu, 16 Jun 2022 16:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378874AbiFPUsj (ORCPT ); Thu, 16 Jun 2022 16:48:39 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A015EBC2 for ; Thu, 16 Jun 2022 13:48:21 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id g16-20020a17090a7d1000b001ea9f820449so2818803pjl.5 for ; Thu, 16 Jun 2022 13:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=i/kH0v1dne6Zn8uPbB1ueElswUjgT/yTFXTNnBQmQqVWocWZxvGDRFwBQPCgEjZcwt DHW+izRBKx0cz2xBlUq2RrN9DJ22qLSQ47bRF9P/mGJLryASSGePSxfmcFgmUCas2i23 asnkOlYviO3+ExgPo+5i6i0gV6JqUhM2S/znM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7AJn08pW02tF965v0Zsvg646CXfRm82BuAMcsSiDxYo=; b=UvBc/VpXCL65K1tQ2c6aBYPeCJqF08HHCtOtNkooX1wYFGvmRwEz8DGVre8uZyh9w9 8c3ZkMJ+Wr2LvwR5B95iGnO8eEkSvDNFsVLGpjPrw4dUoanS9YQGEYKGiNc1H27wtPJL P7n71p0B/KG2x2pTSZRdui9JGRzH9xAGdoBBsJIwn2ITx50gPaxChVa/DgpTBpFih01W ZNpSRdpKwHZMlvhzNi/XsQZMSPLEpHiTFDpoi7ncaDdSPXnDbAXFcpQFk5XxJljpoULv EOzqkCnWyq6M5d4hFgc7GSRIdH1/uT5lJn9eaR/vfHGE/qWlHx3LFr0qoNxFAPOhLMd4 fKFg== X-Gm-Message-State: AJIora/LEee1n8X/aRnyswmixnOYPI5haEjsfDNJwgvbEU1MG/8ZcSMX VBqXQCH/IWvqSlbOCgwpi2SLyA== X-Google-Smtp-Source: AGRyM1sXlJmDftLj2gIeCg+QvZItPdfFXrzD22pR9q6/q1KwqJH22TcK4LdHMUYCPdy8v2eU0G7bwA== X-Received: by 2002:a17:90b:2310:b0:1e8:8379:6098 with SMTP id mt16-20020a17090b231000b001e883796098mr6832173pjb.112.1655412500987; Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Received: from google.com ([2620:15c:202:201:4709:a407:1ca6:24ea]) by smtp.gmail.com with ESMTPSA id fs20-20020a17090af29400b001ea75a02805sm4221264pjb.52.2022.06.16.13.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jun 2022 13:48:20 -0700 (PDT) Date: Thu, 16 Jun 2022 13:48:18 -0700 From: Brian Norris To: Judy Hsiao Cc: Heiko Stuebner , Liam Girdwood , Rob Herring , Mark Brown , Jaroslav Kysela , Chen-Yu Tsai , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] ASoC: rockchip: i2s: switch BCLK to GPIO Message-ID: References: <20220616155836.3401420-1-judyhsiao@chromium.org> <20220616155836.3401420-2-judyhsiao@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220616155836.3401420-2-judyhsiao@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, Jun 16, 2022 at 03:58:34PM +0000, Judy Hsiao wrote: > We discoverd that the state of BCLK on, LRCLK off and SD_MODE on > may cause the speaker melting issue. Removing LRCLK while BCLK > is present can cause unexpected output behavior including a large > DC output voltage as described in the Max98357a datasheet. > > In order to: > 1. prevent BCLK from turning on by other component. > 2. keep BCLK and LRCLK being present at the same time > > This patch switches BCLK to GPIO func before LRCLK output, and > configures BCLK func back during LRCLK is output. > > Without this fix, BCLK is turned on 11 ms earlier than LRCK by the > da7219. > With this fix, BCLK is turned on only 0.4 ms earlier than LRCK by > the rockchip codec. > > Signed-off-by: Judy Hsiao It feels like a lot of the noise in this patch is due to adding additional error handling, unrelated to the real change you're making. Maybe that deserves a separate patch? > --- > sound/soc/rockchip/rockchip_i2s.c | 134 ++++++++++++++++++++++++------ > 1 file changed, 108 insertions(+), 26 deletions(-) > > diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c > index 47a3971a9ce1..574d3d0900c4 100644 > --- a/sound/soc/rockchip/rockchip_i2s.c > +++ b/sound/soc/rockchip/rockchip_i2s.c > @@ -54,8 +54,40 @@ struct rk_i2s_dev { > const struct rk_i2s_pins *pins; > unsigned int bclk_ratio; > spinlock_t lock; /* tx/rx lock */ > + struct pinctrl *pinctrl; > + struct pinctrl_state *bclk_on; > + struct pinctrl_state *bclk_off; > }; > > +static int i2s_pinctrl_select_bclk_on(struct rk_i2s_dev *i2s) > +{ > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_on)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_on); > + > + if (ret) > + dev_err(i2s->dev, "bclk enable failed %d\n", ret); > + > + return ret; > +} > + > +static int i2s_pinctrl_select_bclk_off(struct rk_i2s_dev *i2s) > +{ > + > + int ret = 0; > + > + if (!IS_ERR(i2s->pinctrl) && !IS_ERR_OR_NULL(i2s->bclk_off)) > + ret = pinctrl_select_state(i2s->pinctrl, > + i2s->bclk_off); > + > + if (ret) > + dev_err(i2s->dev, "bclk disable failed %d\n", ret); > + > + return ret; > +} > + > static int i2s_runtime_suspend(struct device *dev) > { > struct rk_i2s_dev *i2s = dev_get_drvdata(dev); > @@ -92,39 +124,46 @@ static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai) > return snd_soc_dai_get_drvdata(dai); > } > > -static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > +static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > - > + int ret = 0; > + > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); I mentioned this off-list, but the 2nd-line indentation alignment *used* to be in a very particular style, and you've moved that around a lot. To match the previous style, it should be: ret = regmap_update_bits(i2s->regmap, I2S_DMACR, I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE); (BTW, if you're using Gmail to view this, you're going to have no idea what I'm talking about, since it doesn't do whitespace or monospace font correctly...) The same applies throughout; most of the 2nd-line, 3rd-line, ... indentation is a little weird. > - > - regmap_update_bits(i2s->regmap, I2S_XFER, > + if (ret < 0) > + goto end; > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->tx_start = true; > } else { > i2s->tx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->rx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -138,42 +177,55 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > { > unsigned int val = 0; > int retry = 10; > + int ret = 0; > > spin_lock(&i2s->lock); > if (on) { > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE); > + if (ret < 0) > + goto end; > > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | I2S_XFER_RXS_START, > I2S_XFER_TXS_START | I2S_XFER_RXS_START); > - > + if (ret < 0) > + goto end; > i2s->rx_start = true; > } else { > i2s->rx_start = false; > > - regmap_update_bits(i2s->regmap, I2S_DMACR, > + ret = regmap_update_bits(i2s->regmap, I2S_DMACR, > I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_DISABLE); > + if (ret < 0) > + goto end; > > if (!i2s->tx_start) { > - regmap_update_bits(i2s->regmap, I2S_XFER, > + ret = regmap_update_bits(i2s->regmap, I2S_XFER, > I2S_XFER_TXS_START | > - I2S_XFER_RXS_START, > + I2S_XFER_RXS_START, > I2S_XFER_TXS_STOP | > I2S_XFER_RXS_STOP); > - > + if (ret < 0) > + goto end; > udelay(150); > - regmap_update_bits(i2s->regmap, I2S_CLR, > + ret = regmap_update_bits(i2s->regmap, I2S_CLR, > I2S_CLR_TXC | I2S_CLR_RXC, > I2S_CLR_TXC | I2S_CLR_RXC); > - > + if (ret < 0) > + goto end; > regmap_read(i2s->regmap, I2S_CLR, &val); > > /* Should wait for clear operation to finish */ > @@ -187,7 +239,12 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) > } > } > } > +end: > spin_unlock(&i2s->lock); > + if (ret < 0) > + dev_err(i2s->dev, "lrclk update failed\n"); > + > + return ret; > } > > static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai, > @@ -425,17 +482,25 @@ static int rockchip_i2s_trigger(struct snd_pcm_substream *substream, > case SNDRV_PCM_TRIGGER_RESUME: > case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: > if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 1); > + ret = rockchip_snd_rxctrl(i2s, 1); > else > - rockchip_snd_txctrl(i2s, 1); > + ret = rockchip_snd_txctrl(i2s, 1); > + if (ret < 0) > + return ret; > + i2s_pinctrl_select_bclk_on(i2s); > break; > case SNDRV_PCM_TRIGGER_SUSPEND: > case SNDRV_PCM_TRIGGER_STOP: > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: > - if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) > - rockchip_snd_rxctrl(i2s, 0); > - else > - rockchip_snd_txctrl(i2s, 0); > + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { > + if (!i2s->tx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_rxctrl(i2s, 0); > + } else { > + if (!i2s->rx_start) > + i2s_pinctrl_select_bclk_off(i2s); > + ret = rockchip_snd_txctrl(i2s, 0); > + } > break; > default: > ret = -EINVAL; > @@ -736,6 +801,23 @@ static int rockchip_i2s_probe(struct platform_device *pdev) > } > > i2s->bclk_ratio = 64; > + i2s->pinctrl = devm_pinctrl_get(&pdev->dev); > + if (IS_ERR(i2s->pinctrl)) > + dev_err(&pdev->dev, "failed to find i2s pinctrl\n"); > + > + i2s->bclk_on = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_on"); > + if (!IS_ERR_OR_NULL(i2s->bclk_on)) { > + dev_info(&pdev->dev, "switch bclk to GPIO func\n"); I don't think we need this printed at the KERN_INFO level. Either drop it, or maybe dev_dbg(). Brian > + i2s->bclk_off = pinctrl_lookup_state(i2s->pinctrl, > + "bclk_off"); > + if (IS_ERR_OR_NULL(i2s->bclk_off)) { > + dev_err(&pdev->dev, "failed to find i2s bclk_off\n"); > + goto err_clk; > + } > + } > + > + i2s_pinctrl_select_bclk_off(i2s); > > dev_set_drvdata(&pdev->dev, i2s); > > -- > 2.36.1.476.g0c4daa206d-goog >