From patchwork Fri May 27 10:45:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Zhong X-Patchwork-Id: 9138125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F34D960759 for ; Fri, 27 May 2016 10:47:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5EAC28135 for ; Fri, 27 May 2016 10:47:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAAF828159; Fri, 27 May 2016 10:47:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6641228137 for ; Fri, 27 May 2016 10:47:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b6FIR-0002dM-SZ; Fri, 27 May 2016 10:47:15 +0000 Received: from mail-pa0-f67.google.com ([209.85.220.67]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b6FHn-0001mH-OY for linux-rockchip@lists.infradead.org; Fri, 27 May 2016 10:46:38 +0000 Received: by mail-pa0-f67.google.com with SMTP id f8so12242618pag.0 for ; Fri, 27 May 2016 03:46:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wji1fkqVZIJ88T4RIP8Pa3Ti6vwTXj4amRT7yPAJMOY=; b=ltVNviAFspPAvQZNTXB4XrNo/nhQKWcg/5tXPGaKatPv8mLIFMMItihDdQqB+Rs8rC PWWFCQcAjy7MKkP5wYHtvZaZpksXolWUzVlj5g4toebdWlZXW3TPt52ZZ6w3jTYWRSDa skVEKBN0a88jrzJlEEMzsh0hV7LMLGXhBGPo45AvjZE4UIq5qMbpDiPvlL09cLy+ASSD e4i35m9quQo/mIcFWlsvVTDXBmGdoHBrQZ2F7ppD4isFMWXxgPYt8v63erWV7sDRFaQG iEg8vsCLcb2YFIBhrnRg/yl2kFPfAsGUzYlxLAg0sihy4GHi+02n10x2CSa1kk2ddTzE j8+Q== X-Gm-Message-State: ALyK8tIAdVzRsDxZGNwfP1K2s1TWd/ks/37DSyVLgSvnK5BkzQyyze6LU8Q+onxGCD/a/g== X-Received: by 10.66.43.232 with SMTP id z8mr21325541pal.17.1464345974966; Fri, 27 May 2016 03:46:14 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id u127sm12699222pfb.82.2016.05.27.03.46.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 May 2016 03:46:13 -0700 (PDT) From: Chris Zhong To: dianders@chromium.org, tfiga@chromium.org, heiko@sntech.de, yzq@rock-chips.com Subject: [RESEND PATCH 5/6] ASoC: cdn-dp: Add cdn DP codec driver Date: Fri, 27 May 2016 18:45:41 +0800 Message-Id: <1464345942-4795-6-git-send-email-zyw@rock-chips.com> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1464345942-4795-1-git-send-email-zyw@rock-chips.com> References: <1464345942-4795-1-git-send-email-zyw@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160527_034636_021276_FE09FC42 X-CRM114-Status: GOOD ( 18.41 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Oder Chiou , "Damien.Horsley" , Michael Trimarchi , alsa-devel@alsa-project.org, anish kumar , Vinod Koul , linux-kernel@vger.kernel.org, Takashi Iwai , Jyri Sarha , Liam Girdwood , linux-rockchip@lists.infradead.org, Jacob Siverskog , Mark Brown , Chris Zhong , Bard Liao , Charles Keepax , Jaroslav Kysela , Richard Fitzgerald , Adam Thomson , Caesar Wang MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP codec driver get some interfaces from cdn-dp driver, than using those to set DP audio formats, corresponding to alsa formats. Signed-off-by: Chris Zhong --- sound/soc/codecs/Kconfig | 3 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cdn-dp-audio.c | 246 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 sound/soc/codecs/cdn-dp-audio.c diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 7ef3a0c..7ddae65 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -365,6 +365,9 @@ config SND_SOC_ALC5623 config SND_SOC_ALC5632 tristate +config SND_SOC_CDN_DP_AUDIO + tristate + config SND_SOC_CQ0093VC tristate diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 185a712..7a703a7 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -32,6 +32,7 @@ snd-soc-ak4642-objs := ak4642.o snd-soc-ak4671-objs := ak4671.o snd-soc-ak5386-objs := ak5386.o snd-soc-arizona-objs := arizona.o +snd-soc-cdn-dp-audio-objs := cdn-dp-audio.o snd-soc-cq93vc-objs := cq93vc.o snd-soc-cs35l32-objs := cs35l32.o snd-soc-cs42l51-objs := cs42l51.o @@ -241,6 +242,7 @@ obj-$(CONFIG_SND_SOC_AK5386) += snd-soc-ak5386.o obj-$(CONFIG_SND_SOC_ALC5623) += snd-soc-alc5623.o obj-$(CONFIG_SND_SOC_ALC5632) += snd-soc-alc5632.o obj-$(CONFIG_SND_SOC_ARIZONA) += snd-soc-arizona.o +obj-$(CONFIG_SND_SOC_CDN_DP_AUDIO) += snd-soc-cdn-dp-audio.o obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o obj-$(CONFIG_SND_SOC_CS35L32) += snd-soc-cs35l32.o obj-$(CONFIG_SND_SOC_CS42L51) += snd-soc-cs42l51.o diff --git a/sound/soc/codecs/cdn-dp-audio.c b/sound/soc/codecs/cdn-dp-audio.c new file mode 100644 index 0000000..a68570f --- /dev/null +++ b/sound/soc/codecs/cdn-dp-audio.c @@ -0,0 +1,246 @@ +/* + * cdn dp audio support library + * + * Copyright (C) 2016 Chris Zhong + * Copyright (C) 2016 ROCKCHIP, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#define DRV_NAME "cdn-dp-audio" + +struct snd_cdn_dp_audio { + struct device *dev; + const struct cdn_dp_audio_ops *ops; + void *data; + bool is_playback_status; +}; + +static int snd_cdn_dp_audio_dai_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *codec_dai) +{ + struct snd_cdn_dp_audio *ad = snd_soc_dai_get_drvdata(codec_dai); + struct audio_info audio; + + ad->is_playback_status = true; + ad->ops->audio_startup(ad->data, &audio); + + return 0; +} + +static int snd_cdn_dp_audio_dai_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *codec_dai) +{ + struct snd_cdn_dp_audio *ad = snd_soc_dai_get_drvdata(codec_dai); + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct audio_info audio; + unsigned int fmt, rate, chan, width; + + fmt = rtd->dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK; + if (fmt == SND_SOC_DAIFMT_I2S) { + audio.type = AUDIO_TYPE_I2S; + } else { + dev_err(codec_dai->dev, "DAI format unsupported"); + return -EINVAL; + } + + width = params_width(params); + if ((width == 16) || (width == 24)) { + audio.word_length = width; + } else { + dev_err(codec_dai->dev, "width[%d] not support!\n", width); + return -EINVAL; + } + + chan = params_channels(params); + switch (chan) { + case 2: + case 4: + case 6: + case 8: + audio.channels = chan; + break; + default: + dev_err(codec_dai->dev, "channel[%d] not support!\n", chan); + return -EINVAL; + } + + rate = params_rate(params); + switch (rate) { + case 32000: + case 44100: + case 48000: + case 88200: + case 96000: + case 176400: + case 192000: + audio.freq = rate; + break; + default: + dev_err(codec_dai->dev, "rate[%d] not support!\n", rate); + return -EINVAL; + } + + ad->ops->audio_config(ad->data, &audio); + + return 0; +} + +static int snd_cdn_dp_audio_dai_trigger(struct snd_pcm_substream *substream, + int cmd, struct snd_soc_dai *codec_dai) +{ + struct snd_cdn_dp_audio *ad = snd_soc_dai_get_drvdata(codec_dai); + struct audio_info audio; + + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + ad->ops->audio_start(ad->data, &audio); + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + ad->ops->audio_stop(ad->data, &audio); + break; + default: + return -EINVAL; + } + + return 0; +} + +static void snd_cdn_dp_audio_dai_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *codec_dai) +{ + struct snd_cdn_dp_audio *ad = snd_soc_dai_get_drvdata(codec_dai); + struct audio_info audio; + + ad->is_playback_status = false; + ad->ops->audio_shutdown(ad->data, &audio); +} + +static const struct snd_soc_dapm_widget snd_cdn_dp_audio_widgets[] = { + SND_SOC_DAPM_OUTPUT("TX"), +}; + +static const struct snd_soc_dapm_route snd_cdn_dp_audio_routes[] = { + { "TX", NULL, "Playback" }, +}; + +static const struct snd_soc_dai_ops cdn_dp_audio_dai_ops = { + .startup = snd_cdn_dp_audio_dai_startup, + .hw_params = snd_cdn_dp_audio_dai_hw_params, + .trigger = snd_cdn_dp_audio_dai_trigger, + .shutdown = snd_cdn_dp_audio_dai_shutdown, +}; + +static struct snd_soc_dai_driver cdn_dp_audio_dai = { + .name = "cdn-dp-hifi", + .playback = { + .stream_name = "Playback", + .channels_min = 2, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_32000 | + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, + }, + .capture = { + .stream_name = "Capture", + .channels_min = 2, + .channels_max = 8, + .rates = SNDRV_PCM_RATE_32000 | + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE, + }, + + .ops = &cdn_dp_audio_dai_ops, +}; + +static const struct snd_soc_codec_driver cdn_dp_audio = { + .dapm_widgets = snd_cdn_dp_audio_widgets, + .num_dapm_widgets = ARRAY_SIZE(snd_cdn_dp_audio_widgets), + .dapm_routes = snd_cdn_dp_audio_routes, + .num_dapm_routes = ARRAY_SIZE(snd_cdn_dp_audio_routes), +}; + +static int cdn_dp_audio_probe(struct platform_device *pdev) +{ + struct cdn_dp_audio_pdata *pdata = pdev->dev.platform_data; + struct snd_cdn_dp_audio *ad; + int ret; + + ad = devm_kzalloc(&pdev->dev, sizeof(*ad), GFP_KERNEL); + if (!ad) + return -ENOMEM; + + ad->dev = pdata->dev; + ad->ops = pdata->ops; + ad->data = pdata->data; + + platform_set_drvdata(pdev, ad); + + ret = snd_soc_register_codec(&pdev->dev, &cdn_dp_audio, + &cdn_dp_audio_dai, 1); + if (ret) { + dev_err(&pdev->dev, "register codec failed (%d)\n", ret); + return ret; + } + + return 0; +} + +static int cdn_dp_audio_remove(struct platform_device *pdev) +{ + snd_soc_unregister_codec(&pdev->dev); + + return 0; +} + +static const struct of_device_id cdn_dp_audio_ids[] = { + { .compatible = "cdn-dp-audio", }, + { } +}; + +static struct platform_driver cdn_dp_audio_driver = { + .driver = { + .name = "cdn-dp-audio", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(cdn_dp_audio_ids), + }, + .probe = cdn_dp_audio_probe, + .remove = cdn_dp_audio_remove, +}; +module_platform_driver(cdn_dp_audio_driver); + +MODULE_AUTHOR("Chris Zhong "); +MODULE_DESCRIPTION("CDN DP Audio ASoC Interface"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform: cdn-dp-audio"); +MODULE_DEVICE_TABLE(of, cdn_dp_audio_ids);