From patchwork Fri May 27 06:02:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Zhong X-Patchwork-Id: 9137677 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 0F3446075C for ; Fri, 27 May 2016 06:05:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0221027B90 for ; Fri, 27 May 2016 06:05:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA71128061; Fri, 27 May 2016 06:05:56 +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 6BE1D27B90 for ; Fri, 27 May 2016 06:05:56 +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 1b6Asf-00078A-PI; Fri, 27 May 2016 06:04:21 +0000 Received: from mail-pf0-f193.google.com ([209.85.192.193]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b6As0-0006YX-QT; Fri, 27 May 2016 06:03:43 +0000 Received: by mail-pf0-f193.google.com with SMTP id f144so4840790pfa.2; Thu, 26 May 2016 23:03:25 -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=MTKEahyTRkabkIgOFAdVfdLYTDCrO3w7CpOsY1QV8Io=; b=gONLH374l1UuZAYPMwMaZn3IYEkAI/GxmbhSQFS9KJJzm7KqBMb4yup5ioQ7juKcCE BBaRiALwd5ENQ9x/LUddQzUnFZ67VRUsfOwHfb5rR9PJnyWIAnz68GvzGRx75mpk8cg1 xjqwaCLji7rqr6+Qmj5l4Movytc+D7VtuQoVDMpXh9vbcK0Y3vKspMEuvbkapbODtSxa wW4d5KQ+YAEVo959U+pYJqwmaLHRpd0rDLHEWfadBzYGdojtCI/DFYptZLwuPRlbBPtC dfLi3SNb+9Nh/i4nJjn7T5DjkYzSyYNPu5pXPgx8LF56UsW+OD5moX3iFph9zp5P2vE5 dDOA== X-Gm-Message-State: ALyK8tK2ZYcm/1Kr/pSjmaInKTiKn2LZZM8LnrElsj/k0pp+Xjz66FrrNH3PM8/XsQ20Eg== X-Received: by 10.98.59.6 with SMTP id i6mr19667317pfa.45.1464329004967; Thu, 26 May 2016 23:03:24 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id yp9sm24787497pab.42.2016.05.26.23.03.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 May 2016 23:03:23 -0700 (PDT) From: Chris Zhong To: dianders@chromium.org, tfiga@chromium.org, heiko@sntech.de, yzq@rock-chips.com Subject: [PATCH 6/6] ASoC: rockchip: Add machine driver for cdn dp codec Date: Fri, 27 May 2016 14:02:19 +0800 Message-Id: <1464328939-8073-7-git-send-email-zyw@rock-chips.com> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1464328939-8073-1-git-send-email-zyw@rock-chips.com> References: <1464328939-8073-1-git-send-email-zyw@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160526_230341_066144_6EEA71F4 X-CRM114-Status: GOOD ( 21.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Pawel Moll , Ian Campbell , linux-kernel@vger.kernel.org, Takashi Iwai , Liam Girdwood , Rob Herring , Jaroslav Kysela , linux-rockchip@lists.infradead.org, Mark Brown , Kumar Gala , Chris Zhong , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The driver is used for cdn dp codec embedded in rk3399 Signed-off-by: Chris Zhong --- .../bindings/sound/rockchip-cdn-dp-audio.txt | 12 ++ sound/soc/rockchip/Kconfig | 9 ++ sound/soc/rockchip/Makefile | 2 + sound/soc/rockchip/rockchip-cdn-dp-audio.c | 167 +++++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/rockchip-cdn-dp-audio.txt create mode 100644 sound/soc/rockchip/rockchip-cdn-dp-audio.c diff --git a/Documentation/devicetree/bindings/sound/rockchip-cdn-dp-audio.txt b/Documentation/devicetree/bindings/sound/rockchip-cdn-dp-audio.txt new file mode 100644 index 0000000..b7b0898 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/rockchip-cdn-dp-audio.txt @@ -0,0 +1,12 @@ +Rockchip cdn dp audio bindings + +Required properties: +- compatible: platform specific, must be "rockchip,cdn-dp-audio" +- i2s-controller: the device of i2s controller + +Example: + + cdn_dp_audio: cdn-dp_audio { + compatible = "rockchip,cdn-dp-audio"; + i2s-controller = <&i2s2>; + }; diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig index f1e0c70..7e7d905 100644 --- a/sound/soc/rockchip/Kconfig +++ b/sound/soc/rockchip/Kconfig @@ -15,6 +15,15 @@ config SND_SOC_ROCKCHIP_I2S Rockchip I2S device. The device supports upto maximum of 8 channels each for play and record. +config SND_SOC_ROCKCHIP_CDN_DP_AUDIO + tristate "cdn DP audio support" + depends on ROCKCHIP_CDN_DP + select SND_SOC_ROCKCHIP_I2S + select SND_SOC_CDN_DP_AUDIO + help + Say Y or M here if you want to add support for SoC audio on Rockchip + boards using the cdn dp codec, such as RK3399. + config SND_SOC_ROCKCHIP_SPDIF tristate "Rockchip SPDIF Device Driver" depends on CLKDEV_LOOKUP && SND_SOC_ROCKCHIP diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile index c0bf560..9367f55 100644 --- a/sound/soc/rockchip/Makefile +++ b/sound/soc/rockchip/Makefile @@ -5,8 +5,10 @@ snd-soc-rockchip-spdif-objs := rockchip_spdif.o obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o obj-$(CONFIG_SND_SOC_ROCKCHIP_SPDIF) += snd-soc-rockchip-spdif.o +snd-soc-rockchip-cdn-dp-objs := rockchip-cdn-dp-audio.o snd-soc-rockchip-max98090-objs := rockchip_max98090.o snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o +obj-$(CONFIG_SND_SOC_ROCKCHIP_CDN_DP_AUDIO) += snd-soc-rockchip-cdn-dp.o obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o diff --git a/sound/soc/rockchip/rockchip-cdn-dp-audio.c b/sound/soc/rockchip/rockchip-cdn-dp-audio.c new file mode 100644 index 0000000..2bf6649 --- /dev/null +++ b/sound/soc/rockchip/rockchip-cdn-dp-audio.c @@ -0,0 +1,167 @@ +/* + * rockchip-cdn-dp-card.c + * + * ROCKCHIP ALSA SoC DAI driver for cdn dp audio on rockchip processors. + * + * 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 "rockchip_i2s.h" + +#define DRV_NAME "rockchip-cdn-dp-audio" + +static int cdn_dp_audio_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + unsigned int dai_fmt = rtd->dai_link->dai_fmt; + int mclk, ret; + + switch (params_rate(params)) { + case 8000: + case 16000: + case 24000: + case 32000: + case 48000: + case 64000: + case 96000: + mclk = 12288000; + break; + case 11025: + case 22050: + case 44100: + case 88200: + mclk = 11289600; + break; + default: + return -EINVAL; + } + + ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); + if (ret < 0) { + dev_err(cpu_dai->dev, "failed to set cpu_dai fmt.\n"); + return ret; + } + + ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT); + if (ret < 0) { + dev_err(cpu_dai->dev, "failed to set cpu_dai sysclk.\n"); + return ret; + } + + return 0; +} + +static struct snd_soc_ops cdn_dp_dai_ops = { + .hw_params = cdn_dp_audio_hw_params, +}; + +static struct snd_soc_dai_link cdn_dp_dai = { + .name = "cdn_dp", + .stream_name = "cdn_dp", + .codec_name = "cdn-dp-audio", + .codec_dai_name = "cdn-dp-hifi", + .ops = &cdn_dp_dai_ops, + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, +}; + +static struct snd_soc_card cdn_dp_audio_card = { + .name = "cdn_dp", + .owner = THIS_MODULE, + .dai_link = &cdn_dp_dai, + .num_links = 1, +}; + +static int cdn_dp_audio_probe(struct platform_device *pdev) +{ + struct snd_soc_card *card = &cdn_dp_audio_card; + struct device_node *np = pdev->dev.of_node; + int ret; + + card->dev = &pdev->dev; + platform_set_drvdata(pdev, card); + + cdn_dp_dai.cpu_of_node = of_parse_phandle(np, "i2s-controller", 0); + if (!cdn_dp_dai.cpu_of_node) { + dev_err(&pdev->dev, "Property 'i2s-controller' missing !\n"); + goto free_priv_data; + } + + cdn_dp_dai.platform_of_node = cdn_dp_dai.cpu_of_node; + + ret = snd_soc_register_card(card); + if (ret) { + dev_err(&pdev->dev, "register card failed (%d)\n", ret); + card->dev = NULL; + goto free_cpu_of_node; + } + + dev_info(&pdev->dev, "rockchip cdn dp audio init success.\n"); + + return 0; + +free_cpu_of_node: + cdn_dp_dai.cpu_of_node = NULL; + cdn_dp_dai.platform_of_node = NULL; +free_priv_data: + snd_soc_card_set_drvdata(card, NULL); + platform_set_drvdata(pdev, NULL); + card->dev = NULL; + + return ret; +} + +static int cdn_dp_audio_remove(struct platform_device *pdev) +{ + struct snd_soc_card *card = platform_get_drvdata(pdev); + + snd_soc_unregister_card(card); + snd_soc_card_set_drvdata(card, NULL); + platform_set_drvdata(pdev, NULL); + card->dev = NULL; + + return 0; +} + +static const struct of_device_id cdn_dp_audio_of_match[] = { + { .compatible = "rockchip,cdn-dp-audio", }, + {}, +}; + +static struct platform_driver cdn_dp_audio_driver = { + .driver = { + .name = DRV_NAME, + .owner = THIS_MODULE, + .pm = &snd_soc_pm_ops, + .of_match_table = cdn_dp_audio_of_match, + }, + .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:" DRV_NAME); +MODULE_DEVICE_TABLE(of, cdn_dp_audio_of_match);