From patchwork Thu Jun 4 12:22:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 6546381 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1C780C0020 for ; Thu, 4 Jun 2015 12:31:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23B8A20774 for ; Thu, 4 Jun 2015 12:31:55 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id C96332034E for ; Thu, 4 Jun 2015 12:31:53 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id F0EEF2666BC; Thu, 4 Jun 2015 14:31:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id B91A72665DE; Thu, 4 Jun 2015 14:26:01 +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 092382665D4; Thu, 4 Jun 2015 14:26:00 +0200 (CEST) Received: from arroyo.ext.ti.com (arroyo.ext.ti.com [192.94.94.40]) by alsa0.perex.cz (Postfix) with ESMTP id D93F42663DF for ; Thu, 4 Jun 2015 14:23:26 +0200 (CEST) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id t54CNPRn013751; Thu, 4 Jun 2015 07:23:25 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id t54CNPGU015786; Thu, 4 Jun 2015 07:23:25 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.224.2; Thu, 4 Jun 2015 07:23:24 -0500 Received: from dlep32.itg.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t54CMqXe028164; Thu, 4 Jun 2015 07:23:23 -0500 From: Peter Ujfalusi To: Mark Brown , Liam Girdwood , Date: Thu, 4 Jun 2015 15:22:37 +0300 Message-ID: <1433420571-5421-14-git-send-email-peter.ujfalusi@ti.com> X-Mailer: git-send-email 2.4.2 In-Reply-To: <1433420571-5421-1-git-send-email-peter.ujfalusi@ti.com> References: <1433420571-5421-1-git-send-email-peter.ujfalusi@ti.com> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 13/22] ASoC: tas2552: Add TDM 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 TDM support is achieved using DSP transfer mode and setting a programmable offset which specifies where data begins with respect to the frame sync. Signed-off-by: Peter Ujfalusi --- sound/soc/codecs/tas2552.c | 59 ++++++++++++++++++++++++++++++++++++++++++---- sound/soc/codecs/tas2552.h | 3 +++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c index 7615d1bc5f5d..432aa54fe707 100644 --- a/sound/soc/codecs/tas2552.c +++ b/sound/soc/codecs/tas2552.c @@ -78,6 +78,9 @@ struct tas2552_data { unsigned char regs[TAS2552_VBAT_DATA]; unsigned int pll_clkin; unsigned int pdm_clk; + + unsigned int dai_fmt; + unsigned int tdm_delay; }; /* Input mux controls */ @@ -191,10 +194,29 @@ static int tas2552_hw_params(struct snd_pcm_substream *substream, #define TAS2552_DAI_FMT_MASK (TAS2552_BCLKDIR | \ TAS2552_WCLKDIR | \ TAS2552_DATAFORMAT_MASK) +static int tas2552_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_soc_codec *codec = dai->codec; + struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec); + int delay = 0; + + /* TDM slot selection only valid in DSP_A/_B mode */ + if (tas2552->dai_fmt == SND_SOC_DAIFMT_DSP_A) + delay += (tas2552->tdm_delay + 1); + else if (tas2552->dai_fmt == SND_SOC_DAIFMT_DSP_B) + delay += tas2552->tdm_delay; + + /* Configure data delay */ + snd_soc_write(codec, TAS2552_SER_CTRL_2, delay); + + return 0; +} + static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) { struct snd_soc_codec *codec = dai->codec; - u8 delay = 0; + struct tas2552_data *tas2552 = dev_get_drvdata(codec->dev); u8 serial_format; switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { @@ -220,7 +242,6 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF): break; case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF): - delay = 1; case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF): serial_format |= TAS2552_DATAFORMAT_DSP; break; @@ -234,11 +255,10 @@ static int tas2552_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) dev_vdbg(codec->dev, "DAI Format is not found\n"); return -EINVAL; } + tas2552->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK; snd_soc_update_bits(codec, TAS2552_SER_CTRL_1, TAS2552_DAI_FMT_MASK, serial_format); - snd_soc_write(codec, TAS2552_SER_CTRL_2, delay); - return 0; } @@ -278,6 +298,35 @@ static int tas2552_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, return 0; } +static int tas2552_set_dai_tdm_slot(struct snd_soc_dai *dai, + unsigned int tx_mask, unsigned int rx_mask, + int slots, int slot_width) +{ + struct snd_soc_codec *codec = dai->codec; + struct tas2552_data *tas2552 = snd_soc_codec_get_drvdata(codec); + unsigned int lsb; + + if (unlikely(!tx_mask)) { + dev_err(codec->dev, "tx masks need to be non 0\n"); + return -EINVAL; + } + + /* TDM based on DSP mode requires slots to be adjacent */ + lsb = __ffs(tx_mask); + if ((lsb + 1) != __fls(tx_mask)) { + dev_err(codec->dev, "Invalid mask, slots must be adjacent\n"); + return -EINVAL; + } + + tas2552->tdm_delay = lsb * slot_width; + + /* DOUT in high-impedance on inactive bit clocks */ + snd_soc_update_bits(codec, TAS2552_DOUT, + TAS2552_SDOUT_TRISTATE, TAS2552_SDOUT_TRISTATE); + + return 0; +} + static int tas2552_mute(struct snd_soc_dai *dai, int mute) { u8 cfg1_reg = 0; @@ -330,8 +379,10 @@ static const struct dev_pm_ops tas2552_pm = { static struct snd_soc_dai_ops tas2552_speaker_dai_ops = { .hw_params = tas2552_hw_params, + .prepare = tas2552_prepare, .set_sysclk = tas2552_set_dai_sysclk, .set_fmt = tas2552_set_dai_fmt, + .set_tdm_slot = tas2552_set_dai_tdm_slot, .digital_mute = tas2552_mute, }; diff --git a/sound/soc/codecs/tas2552.h b/sound/soc/codecs/tas2552.h index 0a12b511e951..5bdc7eaaddea 100644 --- a/sound/soc/codecs/tas2552.h +++ b/sound/soc/codecs/tas2552.h @@ -62,6 +62,9 @@ #define TAS2552_LIM_EN (1 << 2) #define TAS2552_IVSENSE_EN (1 << 1) +/* DOUT Register Masks */ +#define TAS2552_SDOUT_TRISTATE (1 << 2) + /* Serial Interface Control Register Masks */ #define TAS2552_DATAFORMAT_I2S (0x0 << 2) #define TAS2552_DATAFORMAT_DSP (0x1 << 2)