From patchwork Fri Jun 18 15:07:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Codrin Ciubotariu X-Patchwork-Id: 12331597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19EF6C48BE8 for ; Fri, 18 Jun 2021 15:09:43 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C34F661260 for ; Fri, 18 Jun 2021 15:09:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C34F661260 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xl8zCUb892d38R+QsZk83KdDJ0qplHIvpCOHrSz+OKk=; b=hqLy4y2ZKHRD3R W4wueTONwzWwOpxV7TkTBg7Nsm3wY5jVDcqDu2mM+3KmADuIZbnlH8AwRw3ReRn8ZQj8gYf5BrtyZ QP9CEjRgJbHQ4GLSYUNkgUVfptZ0X4OOmtmMlacqONJqkcUE92sAw7d2n2AlHnPK+a5HnLiP9T3Qh KKKFCccREjiCVjxT5rnVHNdK1BxdtjJNiXApTvjwQUENTDe5OepEeyxfRL1NLK+SxjZJTCwv02Xxk 0S60SUEk7Ob7n/EJQNpE3+pdq5vvZcJT5u6KBGLhsJEqNppenHmC1kCcNeS+k2G5s+ksgHdRozMjL i7XvNJ/irpSsX5aldjQg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1luG6Q-00Ecoe-6V; Fri, 18 Jun 2021 15:08:14 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1luG6C-00EcnV-N3 for linux-arm-kernel@lists.infradead.org; Fri, 18 Jun 2021 15:08:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1624028880; x=1655564880; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WpgZqaJX/+7BSkqSgUw8H/zUIGbOwzMBZkNkKWi6y/E=; b=ZAXMLbljW0iA3kv8EFI5ZsGYZcaW8kLi/jCAba9+VWimYi8Rb7E3002W oo1tYWWHbQifrJ3pSwbL7KVtBBYuXJS2mELFtXcxCkbZg292c6zqbsKle +Way8mOAD1qoL3QPpv8BRuD/jy1khkf/ncyGsTxfiZB0SFE1Sdtt3etJz nOvGtQJ10l0wzwKQ3emGSdjw6lR58Ff/VdbMJwFzfO7owZxH8qUTpqHrI hKnLB86itQtsi7HQ5IbKMvr1NyH3aLkx1RbGM7vFOmXCcWZzhSsJo9LtW W70quj0+r8+GREnBSbaxv1EWc/BI3aNG30KLunpQI405NIz5LIblrSy9s g==; IronPort-SDR: EtHACUtRraKX5sxLg2ztvjKgVg9okxvvn+O/IQyua40UpAUHhr6wD/VZowF5MRGsWLOLqJb8NC viCI6hrwBzifgGBOsVW3nJZTw5gLV0vDZqf42fRuWXq/emYnJjmzJPjk9mbEeC8ttOjDNTGrAP YZPuSHcbdLqn/cHQvRPX4oB9kYb4yQ5Y1Tt6U3vGYy418lvyuKD+HqoRUlme6OIG3wgiqPfFm7 NwT/tI8s+lem258t2CvySj0lrW7P3ZWg014mscOypO+NagjWxf1VKsJRw8M4V7Yycs8g/AL/v+ jhY= X-IronPort-AV: E=Sophos;i="5.83,284,1616482800"; d="scan'208";a="125835094" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 18 Jun 2021 08:08:00 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 18 Jun 2021 08:08:00 -0700 Received: from rob-ult-m19940.amer.actel.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Fri, 18 Jun 2021 08:07:57 -0700 From: Codrin Ciubotariu To: , , Subject: [PATCH 2/2] ASoC: atmel-i2s: Fix usage of capture and playback at the same time Date: Fri, 18 Jun 2021 18:07:41 +0300 Message-ID: <20210618150741.401739-2-codrin.ciubotariu@microchip.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210618150741.401739-1-codrin.ciubotariu@microchip.com> References: <20210618150741.401739-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210618_080800_802159_91F17FB1 X-CRM114-Status: GOOD ( 17.85 ) 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: , Cc: alexandre.belloni@bootlin.com, tiwai@suse.com, ludovic.desroches@microchip.com, broonie@kernel.org, Codrin Ciubotariu , perex@perex.cz Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For both capture and playback streams to work at the same time, only the needed values from a register need to be updated. Also, clocks should be enabled only when the first stream is started and stopped when there is no running stream. Fixes: b543e467d1a9 ("ASoC: atmel-i2s: add driver for the new Atmel I2S controller") Signed-off-by: Codrin Ciubotariu --- sound/soc/atmel/atmel-i2s.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/sound/soc/atmel/atmel-i2s.c b/sound/soc/atmel/atmel-i2s.c index a95002b0cc8e..6b3d9c05eaf2 100644 --- a/sound/soc/atmel/atmel-i2s.c +++ b/sound/soc/atmel/atmel-i2s.c @@ -200,6 +200,7 @@ struct atmel_i2s_dev { unsigned int fmt; const struct atmel_i2s_gck_param *gck_param; const struct atmel_i2s_caps *caps; + int clk_use_no; }; static irqreturn_t atmel_i2s_interrupt(int irq, void *dev_id) @@ -321,9 +322,16 @@ static int atmel_i2s_hw_params(struct snd_pcm_substream *substream, { struct atmel_i2s_dev *dev = snd_soc_dai_get_drvdata(dai); bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); - unsigned int mr = 0; + unsigned int mr = 0, mr_mask; int ret; + mr_mask = ATMEL_I2SC_MR_FORMAT_MASK | ATMEL_I2SC_MR_MODE_MASK | + ATMEL_I2SC_MR_DATALENGTH_MASK; + if (is_playback) + mr_mask |= ATMEL_I2SC_MR_TXMONO; + else + mr_mask |= ATMEL_I2SC_MR_RXMONO; + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_I2S: mr |= ATMEL_I2SC_MR_FORMAT_I2S; @@ -402,7 +410,7 @@ static int atmel_i2s_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - return regmap_write(dev->regmap, ATMEL_I2SC_MR, mr); + return regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr); } static int atmel_i2s_switch_mck_generator(struct atmel_i2s_dev *dev, @@ -495,18 +503,28 @@ static int atmel_i2s_trigger(struct snd_pcm_substream *substream, int cmd, is_master = (mr & ATMEL_I2SC_MR_MODE_MASK) == ATMEL_I2SC_MR_MODE_MASTER; /* If master starts, enable the audio clock. */ - if (is_master && mck_enabled) - err = atmel_i2s_switch_mck_generator(dev, true); - if (err) - return err; + if (is_master && mck_enabled) { + if (!dev->clk_use_no) { + err = atmel_i2s_switch_mck_generator(dev, true); + if (err) + return err; + } + dev->clk_use_no++; + } err = regmap_write(dev->regmap, ATMEL_I2SC_CR, cr); if (err) return err; /* If master stops, disable the audio clock. */ - if (is_master && !mck_enabled) - err = atmel_i2s_switch_mck_generator(dev, false); + if (is_master && !mck_enabled) { + if (dev->clk_use_no == 1) { + err = atmel_i2s_switch_mck_generator(dev, false); + if (err) + return err; + } + dev->clk_use_no--; + } return err; }