From patchwork Fri Mar 11 22:59:42 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: 8569881 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 5BA3FC0553 for ; Fri, 11 Mar 2016 23:00:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9191120382 for ; Fri, 11 Mar 2016 23:00:08 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 5333A20377 for ; Fri, 11 Mar 2016 23:00:06 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9F69426602C; Sat, 12 Mar 2016 00:00:04 +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 78A6B261518; Fri, 11 Mar 2016 23:59:52 +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 D5796261564; Fri, 11 Mar 2016 23:59:50 +0100 (CET) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by alsa0.perex.cz (Postfix) with ESMTP id D242C2605F0 for ; Fri, 11 Mar 2016 23:59:45 +0100 (CET) Received: by mail-wm0-f46.google.com with SMTP id p65so35234826wmp.0 for ; Fri, 11 Mar 2016 14:59:45 -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-disposition:in-reply-to:user-agent; bh=Yhop9FGHPIL02f/vDJHE3sXoRY2tZ1935GH2unIi0YM=; b=A+ECB3qwCZcAbgnucZ4wvXEjSudkmDkiuYVGt4fOgwA+j/oQ3U8RgWlPassLqW10zj 4LKTJXrCQWPohs2ZZifg40SR2092w2vU8FXSRtup1bN3UVPXVk/o93eQQ9bfXbGc043e egK60alIAOWUEFnWyXv2TLXU0keNDqyLEe9Bfx9qCGS/i24QXoaSZfEMs9TKohjxpqZv 2jKsd37ZkqhgQb2OdDEByi6lOR43HiuvE7YVd1TJXSyZ5Zby55cFqkV7tK2h6XtwKvCA 1l2fjWU5Rt+OLf+3WVCGhIHM9L6VB0e6lfbcCrg8Vadp4z4WKq5TZrzZm02Pm6mGFBhp 15HA== 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-disposition:in-reply-to:user-agent; bh=Yhop9FGHPIL02f/vDJHE3sXoRY2tZ1935GH2unIi0YM=; b=k6ufAv0DzxfPXZC9wPEf8OnS+HBr0Hh1TjVlcbUjO9JXySUQV6kKOEollswxleHYBS pU+wyoehhPtAyf3CFthkpDTadUqdxYZf8vKeGgz/lXm1NRnHyu4/BSaZiDYaRmIDxbrh JNTQs4vvyWjmtMyTUqmKpykMDKkkuQ6Ebp9kVUWD90KRqYHZ7XbLTmNHSwl1c3wdmxxA gYnR9v6BaS4CVgVPmF+yZHmol5AX+l8SURKMBWtn6cr39Wqlnn7+HRY+qiqJw1YblpZk pRDPn4NzNuAXW0qP0JirTHWGvSdqjzmmobB0ocLykEOyIBTLy8BOt/nwD9Twp5FIzt9K xfBw== X-Gm-Message-State: AD7BkJLQ8HcnAgM9BMIboBgvjl2OwbWZuSo6XUAksco9aMqXBKB5UPMHohaCEF4E4ax3KUL4 X-Received: by 10.28.225.198 with SMTP id y189mr5676261wmg.94.1457737185456; Fri, 11 Mar 2016 14:59:45 -0800 (PST) Received: from panicking (93-34-51-230.ip48.fastwebnet.it. [93.34.51.230]) by smtp.gmail.com with ESMTPSA id k125sm4280748wmb.14.2016.03.11.14.59.44 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 11 Mar 2016 14:59:44 -0800 (PST) Date: Fri, 11 Mar 2016 23:59:42 +0100 From: Michael Trimarchi To: Mark Brown Message-ID: <20160311225937.GA27257@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> <20160110173812.GA16304@panicking> <20160205172451.GA30542@panicking> <20160222031944.GT18327@sirena.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160222031944.GT18327@sirena.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, adamo.a60@gmail.com, lgirdwood@gmail.com, Johan Hovold , Jacob Siverskog Subject: [alsa-devel] [PATCH V4] 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 ASoC: pcm179x: Add support for pcm1795 and pcm1796 Signed-off-by: Michael Trimarchi Tested-by: Angelo Adamo --- Changes v4 -> v3: - clean up compatible list - use enum type instead of pointer of int Changes v3 -> v2: - rebase after i2c support Changes v1 -> v2: - Use switch for support new variants - sort the compatible list sound/soc/codecs/pcm179x-i2c.c | 6 ---- sound/soc/codecs/pcm179x-spi.c | 6 ---- sound/soc/codecs/pcm179x.c | 65 ++++++++++++++++++++++++++++++++++++++++-- sound/soc/codecs/pcm179x.h | 9 ++++-- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/sound/soc/codecs/pcm179x-i2c.c b/sound/soc/codecs/pcm179x-i2c.c index 4118106..609f07f 100644 --- a/sound/soc/codecs/pcm179x-i2c.c +++ b/sound/soc/codecs/pcm179x-i2c.c @@ -44,12 +44,6 @@ static int pcm179x_i2c_remove(struct i2c_client *client) return pcm179x_common_exit(&client->dev); } -static const struct of_device_id pcm179x_of_match[] = { - { .compatible = "ti,pcm1792a", }, - { } -}; -MODULE_DEVICE_TABLE(of, pcm179x_of_match); - static const struct i2c_device_id pcm179x_i2c_ids[] = { { "pcm179x", 0 }, { } diff --git a/sound/soc/codecs/pcm179x-spi.c b/sound/soc/codecs/pcm179x-spi.c index da924d4..6ae0e4d 100644 --- a/sound/soc/codecs/pcm179x-spi.c +++ b/sound/soc/codecs/pcm179x-spi.c @@ -43,12 +43,6 @@ static int pcm179x_spi_remove(struct spi_device *spi) return pcm179x_common_exit(&spi->dev); } -static const struct of_device_id pcm179x_of_match[] = { - { .compatible = "ti,pcm1792a", }, - { } -}; -MODULE_DEVICE_TABLE(of, pcm179x_of_match); - static const struct spi_device_id pcm179x_spi_ids[] = { { "pcm179x", 0 }, { }, diff --git a/sound/soc/codecs/pcm179x.c b/sound/soc/codecs/pcm179x.c index 06a6657..5be782e 100644 --- a/sound/soc/codecs/pcm179x.c +++ b/sound/soc/codecs/pcm179x.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -68,12 +70,40 @@ static bool pcm179x_writeable_reg(struct device *dev, unsigned register reg) return accessible && reg != 0x16 && reg != 0x17; } +enum pcm179x_type { + PCM1792A, + PCM1795, + PCM1796, +}; + struct pcm179x_private { struct regmap *regmap; unsigned int format; unsigned int rate; + enum pcm179x_type 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 = PCM1792A_FORMATS; + + switch (priv->codec_model) { + case PCM1795: + formats = PCM1795_FORMATS; + break; + default: + break; + } + + 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) { @@ -112,8 +142,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: @@ -125,8 +157,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: @@ -152,6 +186,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, @@ -190,7 +225,7 @@ static struct snd_soc_dai_driver pcm179x_dai = { .rates = SNDRV_PCM_RATE_CONTINUOUS, .rate_min = 10000, .rate_max = 200000, - .formats = PCM1792A_FORMATS, }, + .formats = PCM179X_FORMATS, }, .ops = &pcm179x_dai_ops, }; @@ -214,15 +249,39 @@ static struct snd_soc_codec_driver soc_codec_dev_pcm179x = { .num_dapm_routes = ARRAY_SIZE(pcm179x_dapm_routes), }; +static const unsigned int codec_model = PCM1795; + +const struct of_device_id pcm179x_of_match[] = { + { .compatible = "ti,pcm1792a", }, + { .compatible = "ti,pcm1795", .data = (void *)PCM1795, }, + { .compatible = "ti,pcm1796", }, + { } +}; +MODULE_DEVICE_TABLE(of, pcm179x_of_match); +EXPORT_SYMBOL_GPL(pcm179x_of_match); + int pcm179x_common_init(struct device *dev, struct regmap *regmap) { struct pcm179x_private *pcm179x; + struct device_node *np = dev->of_node; + enum pcm179x_type codec_model = PCM1792A; pcm179x = devm_kzalloc(dev, sizeof(struct pcm179x_private), GFP_KERNEL); if (!pcm179x) return -ENOMEM; + if (np) { + const struct of_device_id *of_id; + + of_id = of_match_device(pcm179x_of_match, dev); + if (of_id) + codec_model = (enum pcm179x_type) of_id->data; + } + + if (codec_model) + pcm179x->codec_model = codec_model; + pcm179x->regmap = regmap; dev_set_drvdata(dev, pcm179x); diff --git a/sound/soc/codecs/pcm179x.h b/sound/soc/codecs/pcm179x.h index 11e3312..4c00047 100644 --- a/sound/soc/codecs/pcm179x.h +++ b/sound/soc/codecs/pcm179x.h @@ -17,10 +17,15 @@ #ifndef __PCM179X_H__ #define __PCM179X_H__ -#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) extern const struct regmap_config pcm179x_regmap_config; +extern const struct of_device_id pcm179x_of_match[]; int pcm179x_common_init(struct device *dev, struct regmap *regmap); int pcm179x_common_exit(struct device *dev);