From patchwork Thu Oct 17 09:01:15 2013
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Xiubo Li
X-Patchwork-Id: 3059651
Return-Path:
X-Original-To: patchwork-linux-arm@patchwork.kernel.org
Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org
Received: from mail.kernel.org (mail.kernel.org [198.145.19.201])
by patchwork1.web.kernel.org (Postfix) with ESMTP id 4FF369F243
for ;
Thu, 17 Oct 2013 09:15:04 +0000 (UTC)
Received: from mail.kernel.org (localhost [127.0.0.1])
by mail.kernel.org (Postfix) with ESMTP id DC7CA2011F
for ;
Thu, 17 Oct 2013 09:15:02 +0000 (UTC)
Received: from casper.infradead.org (casper.infradead.org [85.118.1.10])
(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
(No client certificate requested)
by mail.kernel.org (Postfix) with ESMTPS id D487A201B8
for ;
Thu, 17 Oct 2013 09:14:57 +0000 (UTC)
Received: from merlin.infradead.org ([2001:4978:20e::2])
by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux))
id 1VWjdz-0003UG-3X; Thu, 17 Oct 2013 09:13:24 +0000
Received: from localhost ([::1] helo=merlin.infradead.org)
by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux))
id 1VWjdV-0005e7-AE; Thu, 17 Oct 2013 09:12:53 +0000
Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12]
helo=tx2outboundpool.messaging.microsoft.com)
by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux))
id 1VWjcu-0005Xd-Kf for linux-arm-kernel@lists.infradead.org;
Thu, 17 Oct 2013 09:12:19 +0000
Received: from mail97-tx2-R.bigfish.com (10.9.14.251) by
TX2EHSOBE008.bigfish.com (10.9.40.28) with Microsoft SMTP Server id
14.1.225.22; Thu, 17 Oct 2013 09:11:54 +0000
Received: from mail97-tx2 (localhost [127.0.0.1]) by mail97-tx2-R.bigfish.com
(Postfix) with ESMTP id E70C3380064;
Thu, 17 Oct 2013 09:11:54 +0000 (UTC)
X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null);
IPV:NLI;
H:mail.freescale.net; RD:none; EFVD:NLI
X-SpamScore: 0
X-BigFish:
VS0(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzz1de098h1de097h8275bhz2dh2a8h839he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1dfeh1dffh1e23h1fe8h1ff5h1155h)
Received: from mail97-tx2 (localhost.localdomain [127.0.0.1]) by mail97-tx2
(MessageSwitch) id 1382001112385628_23626;
Thu, 17 Oct 2013 09:11:52 +0000 (UTC)
Received: from TX2EHSMHS022.bigfish.com (unknown [10.9.14.228]) by
mail97-tx2.bigfish.com (Postfix) with ESMTP id 57AD42E0031;
Thu, 17 Oct 2013 09:11:52 +0000 (UTC)
Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS022.bigfish.com
(10.9.99.122) with Microsoft SMTP Server (TLS) id 14.16.227.3;
Thu, 17 Oct 2013 09:11:52 +0000
Received: from az84smr01.freescale.net (10.64.34.197) by
039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP
Server (TLS) id 14.3.158.2; Thu, 17 Oct 2013 09:11:51 +0000
Received: from rock.am.freescale.net (rock.ap.freescale.net [10.193.20.106])
by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id
r9H9Aoil019785; Thu, 17 Oct 2013 02:11:43 -0700
From: Xiubo Li
To: , , ,
Subject: [PATCHv1 6/8] ASoC: fsl: add SGT15000 based audio machine driver.
Date: Thu, 17 Oct 2013 17:01:15 +0800
Message-ID: <1382000477-17304-7-git-send-email-Li.Xiubo@freescale.com>
X-Mailer: git-send-email 1.8.0
In-Reply-To: <1382000477-17304-1-git-send-email-Li.Xiubo@freescale.com>
References: <1382000477-17304-1-git-send-email-Li.Xiubo@freescale.com>
MIME-Version: 1.0
X-OriginatorOrg: freescale.com
X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn%
X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3
X-CRM114-CacheID: sfid-20131017_051217_067464_FF476AE7
X-CRM114-Status: GOOD ( 18.56 )
X-Spam-Score: -3.2 (---)
Cc: mark.rutland@arm.com, alsa-devel@alsa-project.org,
linux-doc@vger.kernel.org, tiwai@suse.de, b18965@freescale.com,
perex@perex.cz,
LW@KARO-electronics.de, linux@arm.linux.org.uk, b42378@freescale.com,
oskar@scara.com, grant.likely@linaro.org, devicetree@vger.kernel.org,
ian.campbell@citrix.com, pawel.moll@arm.com, swarren@wwwdotorg.org,
rob.herring@calxeda.com, linux-arm-kernel@lists.infradead.org,
fabio.estevam@freescale.com, linux-kernel@vger.kernel.org,
rob@landley.net, r64188@freescale.com, shawn.guo@linaro.org,
linuxppc-dev@lists.ozlabs.org
X-BeenThere: linux-arm-kernel@lists.infradead.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id:
List-Unsubscribe:
,
List-Archive:
List-Post:
List-Help:
List-Subscribe:
,
Sender: "linux-arm-kernel"
Errors-To:
linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org
X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC,
RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham
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
This is the SGTl5000 codec based audio driver supported with both
playback and capture dai link implemention.
This implementation is only compatible with device tree definition.
Signed-off-by: Alison Wang
---
sound/soc/fsl/Kconfig | 10 +++
sound/soc/fsl/Makefile | 2 +
sound/soc/fsl/fsl-sgtl5000.c | 208 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 220 insertions(+)
create mode 100644 sound/soc/fsl/fsl-sgtl5000.c
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index a49b386..3fbbbf2 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -220,4 +220,14 @@ config SND_SOC_FSL_PCM
tristate
select SND_SOC_GENERIC_DMAENGINE_PCM
+config SND_SOC_FSL_SGTL5000
+ tristate "SoC Audio support for FSL boards with sgtl5000"
+ depends on OF && I2C
+ select SND_SOC_FSL_SAI
+ select SND_SOC_FSL_PCM
+ select SND_SOC_SGTL5000
+ help
+ Say Y if you want to add support for SoC audio on an FSL board with
+ a sgtl5000 codec.
+
endif # SND_FSL_SOC
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index 865ac23..e8bf0bd 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -58,6 +58,8 @@ obj-$(CONFIG_SND_SOC_IMX_MC13783) += snd-soc-imx-mc13783.o
# FSL ARM SAI/SGT15000 Platform Support
snd-soc-fsl-sai-objs := fsl-sai.o
snd-soc-fsl-pcm-objs := fsl-pcm-dma.o
+snd-soc-fsl-sgtl5000-objs := fsl-sgtl5000.o
obj-$(CONFIG_SND_SOC_FSL_SAI) += snd-soc-fsl-sai.o
obj-$(CONFIG_SND_SOC_FSL_PCM) += snd-soc-fsl-pcm.o
+obj-$(CONFIG_SND_SOC_FSL_SGTL5000) += snd-soc-fsl-sgtl5000.o
diff --git a/sound/soc/fsl/fsl-sgtl5000.c b/sound/soc/fsl/fsl-sgtl5000.c
new file mode 100644
index 0000000..bab85ec
--- /dev/null
+++ b/sound/soc/fsl/fsl-sgtl5000.c
@@ -0,0 +1,208 @@
+/*
+ * Freeacale ALSA SoC Audio using SGT1500 as codec.
+ *
+ * Copyright 2012-2013 Freescale Semiconductor, Inc.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include "../codecs/sgtl5000.h"
+#include "fsl-sai.h"
+
+static unsigned int sysclk_rate;
+
+static int fsl_sgtl5000_dai_init(struct snd_soc_pcm_runtime *rtd)
+{
+ int ret;
+ struct device *dev = rtd->card->dev;
+
+ ret = snd_soc_dai_set_sysclk(rtd->codec_dai, SGTL5000_SYSCLK,
+ sysclk_rate, SND_SOC_CLOCK_IN);
+ if (ret) {
+ dev_err(dev, "could not set codec driver clock params :%d\n",
+ ret);
+ return ret;
+ }
+
+ ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, FSL_SAI_CLK_BUS,
+ sysclk_rate, SND_SOC_CLOCK_OUT);
+ if (ret) {
+ dev_err(dev, "could not set cpu dai driver clock params :%d\n",
+ ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int sgtl5000_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 channels = params_channels(params);
+
+ /* TODO: The SAI driver should figure this out for us */
+ switch (channels) {
+ case 2:
+ snd_soc_dai_set_tdm_slot(cpu_dai, 0xfffffffc, 0xfffffffc, 2, 0);
+ break;
+ case 1:
+ snd_soc_dai_set_tdm_slot(cpu_dai, 0xfffffffe, 0xfffffffe, 1, 0);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static struct snd_soc_ops fsl_sgtl5000_hifi_ops = {
+ .hw_params = sgtl5000_params,
+};
+
+static struct snd_soc_dai_link fsl_sgtl5000_dai = {
+ .name = "HiFi",
+ .stream_name = "HiFi",
+ .codec_dai_name = "sgtl5000",
+ .init = &fsl_sgtl5000_dai_init,
+ .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+ SND_SOC_DAIFMT_CBM_CFM,
+ .ops = &fsl_sgtl5000_hifi_ops,
+};
+
+static const struct snd_soc_dapm_widget fsl_sgtl5000_dapm_widgets[] = {
+ SND_SOC_DAPM_MIC("Mic Jack", NULL),
+ SND_SOC_DAPM_LINE("Line In Jack", NULL),
+ SND_SOC_DAPM_HP("Headphone Jack", NULL),
+ SND_SOC_DAPM_SPK("Line Out Jack", NULL),
+ SND_SOC_DAPM_SPK("Ext Spk", NULL),
+};
+
+static struct snd_soc_card fsl_sgt1500_card = {
+ .owner = THIS_MODULE,
+ .num_links = 1,
+ .dai_link = &fsl_sgtl5000_dai,
+ .dapm_widgets = fsl_sgtl5000_dapm_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(fsl_sgtl5000_dapm_widgets),
+};
+
+static int fsl_sgtl5000_parse_dt(struct platform_device *pdev)
+{
+ int ret;
+ struct device_node *sai_np, *codec_np;
+ struct clk *codec_clk;
+ struct i2c_client *codec_dev;
+ struct device_node *np = pdev->dev.of_node;
+
+ ret = snd_soc_of_parse_card_name(&fsl_sgt1500_card, "model");
+ if (ret)
+ return ret;
+
+ ret = snd_soc_of_parse_audio_routing(&fsl_sgt1500_card,
+ "audio-routing");
+ if (ret)
+ return ret;
+
+ sai_np = of_parse_phandle(np, "saif-controller", 0);
+ if (!sai_np) {
+ dev_err(&pdev->dev, "\"saif-controller\" phandle missing or "
+ "invalid\n");
+ return -EINVAL;
+ }
+ fsl_sgtl5000_dai.cpu_of_node = sai_np;
+ fsl_sgtl5000_dai.platform_of_node = sai_np;
+
+ codec_np = of_parse_phandle(np, "audio-codec", 0);
+ if (!codec_np) {
+ dev_err(&pdev->dev, "\"audio-codec\" phandle missing or "
+ "invalid\n");
+ ret = -EINVAL;
+ goto sai_np_fail;
+ }
+ fsl_sgtl5000_dai.codec_of_node = codec_np;
+
+ codec_dev = of_find_i2c_device_by_node(codec_np);
+ if (!codec_dev) {
+ dev_err(&pdev->dev, "failed to find codec platform device\n");
+ ret = PTR_ERR(codec_dev);
+ goto codec_np_fail;
+ }
+
+ codec_clk = devm_clk_get(&codec_dev->dev, NULL);
+ if (IS_ERR(codec_clk)) {
+ dev_err(&pdev->dev, "failed to get codec clock\n");
+ ret = PTR_ERR(codec_clk);
+ goto codec_np_fail;
+ }
+
+ sysclk_rate = clk_get_rate(codec_clk);
+
+codec_np_fail:
+ of_node_put(codec_np);
+sai_np_fail:
+ of_node_put(sai_np);
+
+ return ret;
+}
+
+static int fsl_sgtl5000_probe(struct platform_device *pdev)
+{
+ int ret;
+
+ fsl_sgt1500_card.dev = &pdev->dev;
+
+ ret = fsl_sgtl5000_parse_dt(pdev);
+ if (ret) {
+ dev_err(&pdev->dev,
+ "parse sgtl5000 device tree failed :%d\n",
+ ret);
+ return ret;
+ }
+
+ ret = snd_soc_register_card(&fsl_sgt1500_card);
+ if (ret) {
+ dev_err(&pdev->dev, "register soc sound card failed :%d\n",
+ ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int fsl_sgtl5000_remove(struct platform_device *pdev)
+{
+ snd_soc_unregister_card(&fsl_sgt1500_card);
+
+ return 0;
+}
+
+static const struct of_device_id fsl_sgtl5000_dt_ids[] = {
+ { .compatible = "fsl,vf610-sgtl5000", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, fsl_sgtl5000_dt_ids);
+
+static struct platform_driver fsl_sgtl5000_driver = {
+ .driver = {
+ .name = "fsl-sgtl5000",
+ .owner = THIS_MODULE,
+ .of_match_table = fsl_sgtl5000_dt_ids,
+ },
+ .probe = fsl_sgtl5000_probe,
+ .remove = fsl_sgtl5000_remove,
+};
+module_platform_driver(fsl_sgtl5000_driver);
+
+MODULE_AUTHOR("Xiubo Li ");
+MODULE_DESCRIPTION("Freescale SGTL5000 ASoC driver");
+MODULE_LICENSE("GPL");