From patchwork Fri Jul 8 15:59:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Aisheng X-Patchwork-Id: 103872 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3DCDC1007D1 for ; Sat, 9 Jul 2011 01:40:43 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QfDAM-0000RU-Jy; Fri, 08 Jul 2011 15:40:32 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QfDAM-0001ln-35; Fri, 08 Jul 2011 15:40:30 +0000 Received: from tx2ehsobe001.messaging.microsoft.com ([65.55.88.11] helo=TX2EHSOBE002.bigfish.com) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QfD9V-0001TB-TQ for linux-arm-kernel@lists.infradead.org; Fri, 08 Jul 2011 15:39:40 +0000 Received: from mail159-tx2-R.bigfish.com (10.9.14.235) by TX2EHSOBE002.bigfish.com (10.9.40.22) with Microsoft SMTP Server id 14.1.225.22; Fri, 8 Jul 2011 15:39:36 +0000 Received: from mail159-tx2 (localhost.localdomain [127.0.0.1]) by mail159-tx2-R.bigfish.com (Postfix) with ESMTP id 95B62CC8564; Fri, 8 Jul 2011 15:39:35 +0000 (UTC) X-SpamScore: 6 X-BigFish: VS6(zzc8kzz1202h1082kzz8275bhz2dh2a8h668h839h66h) X-Spam-TCS-SCL: 5:0 X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail159-tx2 (localhost.localdomain [127.0.0.1]) by mail159-tx2 (MessageSwitch) id 1310139535618125_15119; Fri, 8 Jul 2011 15:38:55 +0000 (UTC) Received: from TX2EHSMHS009.bigfish.com (unknown [10.9.14.251]) by mail159-tx2.bigfish.com (Postfix) with ESMTP id B0EB447814A; Fri, 8 Jul 2011 15:37:28 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS009.bigfish.com (10.9.99.109) with Microsoft SMTP Server (TLS) id 14.1.225.22; Fri, 8 Jul 2011 15:37:25 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server id 14.1.289.8; Fri, 8 Jul 2011 10:37:23 -0500 Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id p68FbDOP001162; Fri, 8 Jul 2011 10:37:22 -0500 (CDT) From: Dong Aisheng To: Subject: [PATCH 03/10] ASoc: mxs: add mxs-sgtl5000 machine driver Date: Fri, 8 Jul 2011 23:59:43 +0800 Message-ID: <1310140790-2132-4-git-send-email-b29396@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1310140790-2132-1-git-send-email-b29396@freescale.com> References: <1310140790-2132-1-git-send-email-b29396@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110708_113938_201207_70A424CE X-CRM114-Status: GOOD ( 20.72 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [65.55.88.11 listed in list.dnswl.org] Cc: s.hauer@pengutronix.de, lrg@ti.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org The driver only supports playback firstly. For recording, as we have to use two saif instances to implement full duplex (playback & recording) due to hardware limitation, we need to figure out a good design to fit in ASoC. Signed-off-by: Dong Aisheng --- arch/arm/mach-mxs/include/mach/audio.h | 18 +++ sound/soc/mxs/mxs-sgtl5000.c | 181 ++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 0 deletions(-) diff --git a/arch/arm/mach-mxs/include/mach/audio.h b/arch/arm/mach-mxs/include/mach/audio.h new file mode 100644 index 0000000..2f543d2 --- /dev/null +++ b/arch/arm/mach-mxs/include/mach/audio.h @@ -0,0 +1,18 @@ +/* + * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __MACH_MXS_SAIF_H__ +#define __MACH_MXS_SAIF_H__ + +struct mxs_audio_platform_data { + int sysclk; + + int (*init) (void); /* board specific init */ + int (*finit) (void); /* board specific finit */ +}; +#endif /* __MACH_MXS_SAIF_H__ */ diff --git a/sound/soc/mxs/mxs-sgtl5000.c b/sound/soc/mxs/mxs-sgtl5000.c new file mode 100644 index 0000000..7ae7c86 --- /dev/null +++ b/sound/soc/mxs/mxs-sgtl5000.c @@ -0,0 +1,181 @@ +/* + * Copyright 2011 Freescale Semiconductor, 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, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../codecs/sgtl5000.h" +#include "mxs-saif.h" + +static struct mxs_sgtl5000_priv { + int sysclk; + struct platform_device *pdev; +} card_priv; + +static struct snd_soc_card mxs_sgtl5000; +static struct platform_device *mxs_sgtl5000_snd_device; + +static int mxs_sgtl5000_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 rate = params_rate(params); + u32 dai_format; + int ret; + + /* The SAIF clock should be either 512*fs or 384*fs */ + card_priv.sysclk = 512 * rate; + ret = snd_soc_dai_set_sysclk(cpu_dai, MXS_SAIF_SYS_CLK, + card_priv.sysclk, + SND_SOC_CLOCK_OUT); + if (ret < 0) + return ret; + + /* set SGTL5000_SYSCLK as 256*fs to support 96k sample rate */ + snd_soc_dai_set_sysclk(codec_dai, SGTL5000_SYSCLK, 256 * rate, 0); + + /* The MCLK output rate is 256*fs */ + snd_soc_dai_set_clkdiv(cpu_dai, MXS_SAIF_MCLK, 256); + + /* set codec to slave mode */ + dai_format = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS; + + /* set codec DAI configuration */ + ret = snd_soc_dai_set_fmt(codec_dai, dai_format); + if (ret < 0) + return ret; + + /* set cpu DAI configuration */ + ret = snd_soc_dai_set_fmt(cpu_dai, dai_format); + if (ret < 0) + return ret; + + return 0; +} + +static struct snd_soc_ops mxs_sgtl5000_hifi_ops = { + .hw_params = mxs_sgtl5000_hw_params, +}; + +static int mxs_sgtl5000_soc_init(struct snd_soc_pcm_runtime *rtd) +{ + /* TBD: add dapm widgets */ + + return 0; +} + +static struct snd_soc_dai_link mxs_sgtl5000_dai[] = { + { + .name = "HiFi", + .stream_name = "HiFi Playback", + .codec_dai_name = "sgtl5000", + .codec_name = "sgtl5000.0-000a", + .cpu_dai_name = "mxs-saif.0", + .platform_name = "mxs-pcm-audio.0", + .init = mxs_sgtl5000_soc_init, + .ops = &mxs_sgtl5000_hifi_ops, + }, +}; + +static struct snd_soc_card mxs_sgtl5000 = { + .name = "mxs_sgtl5000", + .dai_link = mxs_sgtl5000_dai, + .num_links = ARRAY_SIZE(mxs_sgtl5000_dai), +}; + +static int __devinit mxs_sgtl5000_probe(struct platform_device *pdev) +{ + struct mxs_audio_platform_data *plat = pdev->dev.platform_data; + int ret; + + card_priv.pdev = pdev; + + ret = -EINVAL; + if (plat && plat->init && plat->init()) + return ret; + + return 0; +} + +static int mxs_sgtl5000_remove(struct platform_device *pdev) +{ + struct mxs_audio_platform_data *plat = pdev->dev.platform_data; + + if (plat && plat->finit) + plat->finit(); + + return 0; +} + +static struct platform_driver mxs_sgtl5000_audio_driver = { + .probe = mxs_sgtl5000_probe, + .remove = mxs_sgtl5000_remove, + .driver = { + .name = "mxs-sgtl5000", + }, +}; + +static int __init mxs_sgtl5000_init(void) +{ + int ret; + + ret = platform_driver_register(&mxs_sgtl5000_audio_driver); + if (ret) + return ret; + + mxs_sgtl5000_snd_device = platform_device_alloc("soc-audio", -1); + if (!mxs_sgtl5000_snd_device) + return -ENOMEM; + + platform_set_drvdata(mxs_sgtl5000_snd_device, &mxs_sgtl5000); + + ret = platform_device_add(mxs_sgtl5000_snd_device); + if (ret) { + printk(KERN_ERR "ASoC: Platform device allocation failed\n"); + platform_device_put(mxs_sgtl5000_snd_device); + } + + return ret; +} + +static void __exit mxs_sgtl5000_exit(void) +{ + platform_driver_unregister(&mxs_sgtl5000_audio_driver); + platform_device_unregister(mxs_sgtl5000_snd_device); +} + +late_initcall(mxs_sgtl5000_init); +module_exit(mxs_sgtl5000_exit); + +MODULE_AUTHOR("Freescale Semiconductor, Inc."); +MODULE_DESCRIPTION("MXS ALSA SoC Machine driver"); +MODULE_LICENSE("GPL");