From patchwork Sun Jan 10 17:38:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 7997541 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 196A19F3F6 for ; Sun, 10 Jan 2016 17:38:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2205220279 for ; Sun, 10 Jan 2016 17:38:45 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id B1B432025B for ; Sun, 10 Jan 2016 17:38:43 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 78884260614; Sun, 10 Jan 2016 18:38:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9EAE9260614; Sun, 10 Jan 2016 18:38:29 +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 AEE4126061E; Sun, 10 Jan 2016 18:38:27 +0100 (CET) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by alsa0.perex.cz (Postfix) with ESMTP id 304312605FF for ; Sun, 10 Jan 2016 18:38:22 +0100 (CET) Received: by mail-wm0-f53.google.com with SMTP id f206so187046769wmf.0 for ; Sun, 10 Jan 2016 09:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=HvCbRBRykey/j94/nWfDbvzQoXaJo5+e2VLZYm+FgCs=; b=EXDlHnKP5DiECdN06hLiUI6YHNZ3mUjyaEicnrCKJ/eyTcMpmiqfS4yZqdXVTywbnY UgZ1LvH4iJ6zR6R6NNRdqBTFbBuoXKIryjYY6LteLpJ+z60Ml7pT+DDg4VI5Vui6sxOd LmN+flQfYRanYcX8tLcGGVJWRBSfjWltuWOxzi2/HHGu2GYfmkOVPDKC0vg5p/bzrLPs 0rufCJRqlFXuZqZBx86wfkw0es9p4VGqDoK2ICl3+OTryWIFLFU/hXghwNy5G3ZV4J5+ MFk9vaDavPG2AeX5FcdnaR5wPXJlscE11vG6zS9JP4CPoMZpDNamrWllHXfPh8dFv2oZ dPmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=HvCbRBRykey/j94/nWfDbvzQoXaJo5+e2VLZYm+FgCs=; b=B0cnUiu2R0rhRy3PWxxPZaTvxWA9KOe1CNjX7oSw3Jc2gRSk8z3H/7Daa4DCJTEMRy 7VB33FPUvBbCiViB5LWDPNgvgLS+ofuz4XSF6NJrgbxp0kVlT8hjmncUsbh52+QELefz DXtHr+XWSZ4eqm2EMzgOUSynfvo5DiSxoMPVBIJOF9dn5+BVtuIDOt/3bSknmQmya7Ci Nh/1NoHtT2VY0K1i6TpiPmC9o/Ceixoue0+Dq4ytGD62Ly9klm+OSsKBqSGfExewI5pk jK6OSM0Yr7iuWTKkzf6M2mcGXMpiA7B5zIuiDN/6TyjLzwFNvBj25NaU54d0X0K0kRyp zRdA== X-Gm-Message-State: ALoCoQk/LgMy19BDiRa5Pxp/qAdZ4boIw+g+xad2fj1UKfVqeDkRov6fKpqtTAtA/IrZld/CVHiZJypu24yHiDESDro6Yo4PKQ== X-Received: by 10.28.87.135 with SMTP id l129mr9754354wmb.9.1452447501779; Sun, 10 Jan 2016 09:38:21 -0800 (PST) Received: from panicking (93-34-54-119.ip48.fastwebnet.it. [93.34.54.119]) by smtp.gmail.com with ESMTPSA id e2sm813133wma.1.2016.01.10.09.38.20 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 10 Jan 2016 09:38:21 -0800 (PST) Date: Sun, 10 Jan 2016 18:38:18 +0100 From: Michael Trimarchi To: Mark Brown Message-ID: <20160110173812.GA16304@panicking> References: <1452382685-18009-1-git-send-email-michael@amarulasolutions.com> <1452382685-18009-4-git-send-email-michael@amarulasolutions.com> <20160110120045.GW6588@sirena.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160110120045.GW6588@sirena.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, lgirdwood@gmail.com Subject: [alsa-devel] [PATCH V2] ASoC: pcm179x: Add support for pcm1795 and pcm1796 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 Signed-off-by: Michael Trimarchi --- Changes v1 -> v2: - Use switch for support new variants - sort the compatible list sound/soc/codecs/pcm179x.c | 56 ++++++++++++++++++++++++++++++++++++++++++---- sound/soc/codecs/pcm179x.h | 14 +++++++----- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/sound/soc/codecs/pcm179x.c b/sound/soc/codecs/pcm179x.c index a56c7b7..8784d52 100644 --- a/sound/soc/codecs/pcm179x.c +++ b/sound/soc/codecs/pcm179x.c @@ -74,8 +74,31 @@ struct pcm179x_private { struct regmap *regmap; unsigned int format; unsigned int rate; +#define PCM1795 1 + unsigned int codec_model; }; +static int pcm179x_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_soc_codec *codec = dai->codec; + struct pcm179x_private *priv = snd_soc_codec_get_drvdata(codec); + u64 formats; + + switch (priv->codec_model) { + case PCM1795: + formats = PCM1795_FORMATS; + break; + default: + formats = PCM1792A_FORMATS; + } + + snd_pcm_hw_constraint_mask64(substream->runtime, + SNDRV_PCM_HW_PARAM_FORMAT, formats); + + return 0; +} + static int pcm179x_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int format) { @@ -114,8 +137,10 @@ static int pcm179x_hw_params(struct snd_pcm_substream *substream, switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) { case SND_SOC_DAIFMT_RIGHT_J: switch (params_width(params)) { - case 24: case 32: + val = 1; + break; + case 24: val = 2; break; case 16: @@ -127,8 +152,10 @@ static int pcm179x_hw_params(struct snd_pcm_substream *substream, break; case SND_SOC_DAIFMT_I2S: switch (params_width(params)) { - case 24: case 32: + val = 4; + break; + case 24: val = 5; break; case 16: @@ -154,6 +181,7 @@ static int pcm179x_hw_params(struct snd_pcm_substream *substream, } static const struct snd_soc_dai_ops pcm179x_dai_ops = { + .startup = pcm179x_startup, .set_fmt = pcm179x_set_dai_fmt, .hw_params = pcm179x_hw_params, .digital_mute = pcm179x_digital_mute, @@ -189,13 +217,19 @@ static struct snd_soc_dai_driver pcm179x_dai = { .stream_name = "Playback", .channels_min = 2, .channels_max = 2, - .rates = PCM1792A_RATES, - .formats = PCM1792A_FORMATS, }, + .rates = PCM179X_RATES, + .formats = PCM179X_FORMATS, }, .ops = &pcm179x_dai_ops, }; +static const unsigned int codec_model = PCM1795; + static const struct of_device_id pcm179x_of_match[] = { { .compatible = "ti,pcm1792a", }, + { .compatible = "ti,pcm1795", + .data = &codec_model, + }, + { .compatible = "ti,pcm1796", }, { } }; MODULE_DEVICE_TABLE(of, pcm179x_of_match); @@ -222,8 +256,19 @@ static struct snd_soc_codec_driver soc_codec_dev_pcm179x = { static int pcm179x_spi_probe(struct spi_device *spi) { struct pcm179x_private *pcm179x; + struct device *dev = &spi->dev; + struct device_node *np = spi->dev.of_node; + const unsigned int *codec_model = NULL; int ret; + if (np) { + const struct of_device_id *of_id; + + of_id = of_match_device(pcm179x_of_match, dev); + if (of_id) + codec_model = of_id->data; + } + pcm179x = devm_kzalloc(&spi->dev, sizeof(struct pcm179x_private), GFP_KERNEL); if (!pcm179x) @@ -238,6 +283,9 @@ static int pcm179x_spi_probe(struct spi_device *spi) return ret; } + if (codec_model) + pcm179x->codec_model = *codec_model; + return snd_soc_register_codec(&spi->dev, &soc_codec_dev_pcm179x, &pcm179x_dai, 1); } diff --git a/sound/soc/codecs/pcm179x.h b/sound/soc/codecs/pcm179x.h index c6fdc06..d4b384d 100644 --- a/sound/soc/codecs/pcm179x.h +++ b/sound/soc/codecs/pcm179x.h @@ -17,11 +17,15 @@ #ifndef __PCM179X_H__ #define __PCM179X_H__ -#define PCM1792A_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_8000_48000 | \ - SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \ - SNDRV_PCM_RATE_192000) +#define PCM179X_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_8000_48000 | \ + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \ + SNDRV_PCM_RATE_192000) -#define PCM1792A_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE | \ - SNDRV_PCM_FMTBIT_S16_LE) +#define PCM179X_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE | \ + SNDRV_PCM_FMTBIT_S16_LE) + +#define PCM1792A_FORMATS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) + +#define PCM1795_FORMATS (SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S24_LE) #endif