From patchwork Tue Oct 13 01:01:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shunqian Zheng X-Patchwork-Id: 7380281 Return-Path: X-Original-To: patchwork-linux-rockchip@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 2741EBEEA4 for ; Tue, 13 Oct 2015 01:02:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3104920982 for ; Tue, 13 Oct 2015 01:02:51 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 2A49320981 for ; Tue, 13 Oct 2015 01:02:50 +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 1ZlnzN-0000R5-CB; Tue, 13 Oct 2015 01:02:49 +0000 Received: from mail-qk0-f195.google.com ([209.85.220.195]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zlnym-000824-0A; Tue, 13 Oct 2015 01:02:16 +0000 Received: by qkey1 with SMTP id y1so128990qke.1; Mon, 12 Oct 2015 18:01:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H/wGvxh8mRke/nLYPrj2HpoucCvmpvDn03idWbnsmYE=; b=Ylcq4I2i2fLhNEdAxQ9ucyNgsVUwAbR5pPXsF1cpDOvc91WtpkEktUteuciDOPpYfv EHYICq11Cs0pmeoRnRbnH5BHLs+XdPoNVKiX29wrJofEI2KjFli7gH5G16PEBK5fzX7C 9kaSijVk+fmL9cD2Om2rmLrAbnbkTTzHuzZIQ/Nu0MkFTPXSUg+/fly1by3OvqLttfNM WVjEJg3DnRbZICO8/K0pffWISMZCgNFm0SpELltwdenZOzZkq/cbdB6NDPLlYZ5bg2Z9 H8fDGYuVnn4sA65OWxGmKAxfWiCkqfGXhiFhxh7LLVdzZ88P92nM//dDm3ThzeUstH65 VSPQ== X-Received: by 10.55.195.135 with SMTP id r7mr37451294qkl.4.1444698110689; Mon, 12 Oct 2015 18:01:50 -0700 (PDT) Received: from SHUNQIAN-W530.example.org ([173.239.41.6]) by smtp.gmail.com with ESMTPSA id v34sm168482qge.47.2015.10.12.18.01.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 18:01:50 -0700 (PDT) From: Shunqian Zheng To: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, ijc+devicetree@hellion.org.uk, galak@codeaurora.org, heiko@sntech.de, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, benzh@chromium.org Subject: [PATCH v1 3/4] ASoC: Add codec machine driver for RK3036 Date: Tue, 13 Oct 2015 09:01:08 +0800 Message-Id: <1444698070-4191-4-git-send-email-zhengsq@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444698070-4191-1-git-send-email-zhengsq@rock-chips.com> References: <1444698070-4191-1-git-send-email-zhengsq@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151012_180212_447224_82254E6D X-CRM114-Status: GOOD ( 18.83 ) X-Spam-Score: -2.6 (--) 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: linux-rockchip@lists.infradead.org, alsa-devel@alsa-project.org, ZhengShunQian , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: ZhengShunQian This patch add the machine driver for rk3036. RK3036 SoC is integrated with Inno codec, this patch should work for all RK3036 board. Signed-off-by: ZhengShunQian --- sound/soc/rockchip/Kconfig | 10 +++ sound/soc/rockchip/Makefile | 2 + sound/soc/rockchip/rockchip_rk3036.c | 147 +++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 sound/soc/rockchip/rockchip_rk3036.c diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig index 5709057..3d48bda 100644 --- a/sound/soc/rockchip/Kconfig +++ b/sound/soc/rockchip/Kconfig @@ -33,3 +33,13 @@ config SND_SOC_ROCKCHIP_RT5645 help Say Y or M here if you want to add support for SoC audio on Rockchip boards using the RT5645/RT5650 codec, such as Veyron. + +config SND_SOC_ROCKCHIP_RK3036 + tristate "ASoC support for RK3036 inner codec" + depends on SND_SOC_ROCKCHIP + select SND_SOC_ROCKCHIP_I2S + help + Say Y or M here if you want to add support for SoC audio on Rockchip + RK3036. + + diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile index e9ba558..9a770c8 100644 --- a/sound/soc/rockchip/Makefile +++ b/sound/soc/rockchip/Makefile @@ -4,7 +4,9 @@ snd-soc-rockchip-i2s-objs := rockchip_i2s.o obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-rockchip-i2s.o snd-soc-rockchip-max98090-objs := rockchip_max98090.o +snd-soc-rockchip-rk3036-objs := rockchip_rk3036.o snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o +obj-$(CONFIG_SND_SOC_ROCKCHIP_RK3036) += snd-soc-rockchip-rk3036.o obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o diff --git a/sound/soc/rockchip/rockchip_rk3036.c b/sound/soc/rockchip/rockchip_rk3036.c new file mode 100644 index 0000000..3747d90 --- /dev/null +++ b/sound/soc/rockchip/rockchip_rk3036.c @@ -0,0 +1,147 @@ +/* + * Machine driver for rk3036 audio codec. + * + * Copyright (c) 2015, ROCKCHIP CORPORATION. All rights reserved. + * + * Author: Zheng ShunQian + */ + +#include +#include +#include + +#include +#include +#include + +static int rk3036_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 *codec_dai = rtd->codec_dai; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + unsigned int dai_fmt = rtd->dai_link->dai_fmt; + int mclk, ret; + + dev_dbg(rtd->dev, "codec machine: %s\n", __func__); + /* set codec DAI configuration */ + ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); + if (ret < 0) + return ret; + + /* set cpu DAI configuration */ + ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt); + if (ret < 0) + return ret; + + switch (params_rate(params)) { + case 8000: + case 16000: + case 24000: + case 32000: + case 48000: + mclk = 12288000; + break; + case 44100: + mclk = 11289600; + break; + default: + return -EINVAL; + } + + /*Set the system clk for codec*/ + ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN); + if (ret < 0) + return ret; + + ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, SND_SOC_CLOCK_OUT); + if (ret < 0) + return ret; + + return 0; +} + +static struct snd_soc_ops rk3036_ops = { + .hw_params = rk3036_hw_params, +}; + +static int rk30_rk3036_codec_init(struct snd_soc_pcm_runtime *rtd) +{ + return 0; +} + +static struct snd_soc_dai_link rk3036_dai = { + .name = "INNO-RK3036", + .stream_name = "RK3036 CODEC PCM", + .codec_dai_name = "rk3036-codec-dai", + .init = rk30_rk3036_codec_init, + .ops = &rk3036_ops, + /* set codec as slave */ + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS, +}; + +static struct snd_soc_card rockchip_rk3036_snd_card = { + .name = "ROCKCHIP-I2S", + .dai_link = &rk3036_dai, + .num_links = 1, +}; + +static int rockchip_rk3036_audio_probe(struct platform_device *pdev) +{ + struct snd_soc_card *card = &rockchip_rk3036_snd_card; + struct device_node *np = pdev->dev.of_node; + + platform_set_drvdata(pdev, card); + card->dev = &pdev->dev; + + rk3036_dai.codec_of_node = of_parse_phandle(np, + "rockchip,audio-codec", 0); + if (!rk3036_dai.codec_of_node) { + dev_err(&pdev->dev, "Property 'rockchip,audio-codec' " + "missing or invalid\n"); + return -EINVAL; + } + + rk3036_dai.cpu_of_node = of_parse_phandle(np, + "rockchip,i2s-controller", 0); + if (!rk3036_dai.cpu_of_node) { + dev_err(&pdev->dev, "Property 'rockchip,i2s-controller' " + "missing or invalid\n"); + return -EINVAL; + } + + rk3036_dai.platform_of_node = rk3036_dai.cpu_of_node; + + return snd_soc_register_card(card); +} + +static int rockchip_rk3036_audio_remove(struct platform_device *pdev) +{ + struct snd_soc_card *card = platform_get_drvdata(pdev); + + snd_soc_unregister_card(card); + + return 0; +} + +static const struct of_device_id rockchip_rk3036_of_match[] = { + { .compatible = "rockchip,rk3036-audio", }, + {}, +}; +MODULE_DEVICE_TABLE(of, rockchip_rk3036_of_match); + +static struct platform_driver rockchip_rk3036_audio_driver = { + .driver = { + .name = "rk3036-audio", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(rockchip_rk3036_of_match), + }, + .probe = rockchip_rk3036_audio_probe, + .remove = rockchip_rk3036_audio_remove, +}; +module_platform_driver(rockchip_rk3036_audio_driver); + +MODULE_AUTHOR("Rockchip Inc."); +MODULE_DESCRIPTION("Rockchip RK3036 Inno codec machine ASoC driver"); +MODULE_LICENSE("GPL");