From patchwork Thu Nov 19 02:57:59 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregoire Gentil X-Patchwork-Id: 61227 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAJ2w1WX029307 for ; Thu, 19 Nov 2009 02:58:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758046AbZKSC56 (ORCPT ); Wed, 18 Nov 2009 21:57:58 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758045AbZKSC55 (ORCPT ); Wed, 18 Nov 2009 21:57:57 -0500 Received: from mail-gx0-f226.google.com ([209.85.217.226]:57673 "EHLO mail-gx0-f226.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758016AbZKSC54 (ORCPT ); Wed, 18 Nov 2009 21:57:56 -0500 Received: by mail-gx0-f226.google.com with SMTP id 26so1677303gxk.1 for ; Wed, 18 Nov 2009 18:58:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:subject:from:reply-to :to:cc:in-reply-to:references:content-type:organization:date :message-id:mime-version:x-mailer; bh=nD05MoejV6uaLGSghZtx3lp1o0Ww7TDpFw5yD/Jfotg=; b=JCcaou2iC0SDlg3wsONQ5skfvbn2AtfF2WUM+z86gkDu7iDLaOXjRm/q+Uh0JeFzKo m49QrrGAqrqn4wvugMW3/rdfXULEhN4pNc5wMVQc1R0jEOZeN8ahESM+xf1syyIdMd9O OeD7TqkzKUXOjEDJTQ4+ANjZ6FBe/Y2khxQUI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:subject:from:reply-to:to:cc:in-reply-to:references :content-type:organization:date:message-id:mime-version:x-mailer; b=JJzWnM2T8V/wGdc5qtspLOcGigMvLu+cR4OA9j7tEzeL2/pAKNX9uf82AfAYBF6Rha Jlci9NMsoBVbHM+OsXmGDWzmRwooVs2QPWf4FxvY5ttMMmU8Yb9KmivFzlMMjPb4uPUN mEhA6ASShqjZsHoVL2/STcRmlzW3RDXp3xf5M= Received: by 10.90.61.3 with SMTP id j3mr3510285aga.40.1258599482544; Wed, 18 Nov 2009 18:58:02 -0800 (PST) Received: from ?192.168.10.5? (c-98-210-206-210.hsd1.ca.comcast.net [98.210.206.210]) by mx.google.com with ESMTPS id 5sm67851yxg.46.2009.11.18.18.58.00 (version=SSLv3 cipher=RC4-MD5); Wed, 18 Nov 2009 18:58:01 -0800 (PST) Subject: [PATCH 6/8] AI TB: Audio driver of Always Innovating OMAP3-based Touch Book From: Gregoire Gentil Reply-To: gregoire@gentil.com To: linux-omap@vger.kernel.org, alsa-devel@alsa-project.org Cc: Tony Lindgren , Tim Yamin In-Reply-To: <1258345850.9089.21.camel@gregoire-laptop> References: <1258228079.16065.17.camel@runt> <1258345850.9089.21.camel@gregoire-laptop> Organization: Gregoire Gentil Date: Wed, 18 Nov 2009 18:57:59 -0800 Message-Id: <1258599479.8001.37.camel@gregoire-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From 6fdbeddabe5d368071fbc0c272302afe98580f55 Mon Sep 17 00:00:00 2001 From: Gregoire Gentil Date: Wed, 18 Nov 2009 18:33:55 -0800 Subject: [PATCH] Audio driver of Always Innovating OMAP3-based Touch Book Signed-off-by: Gregoire Gentil --- sound/soc/omap/Kconfig | 8 ++ sound/soc/omap/Makefile | 2 + sound/soc/omap/omap3touchbook.c | 211 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+), 0 deletions(-) create mode 100644 sound/soc/omap/omap3touchbook.c diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig index 653a362..c590252 100644 --- a/sound/soc/omap/Kconfig +++ b/sound/soc/omap/Kconfig @@ -83,6 +83,14 @@ config SND_OMAP_SOC_OMAP3_PANDORA help Say Y if you want to add support for SoC audio on the OMAP3 Pandora. +config SND_OMAP_SOC_OMAP3_TOUCHBOOK + tristate "SoC Audio support for OMAP3 Touch Book" + depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP3_TOUCHBOOK + select SND_OMAP_SOC_MCBSP + select SND_SOC_TWL4030 + help + Say Y if you want to add support for SoC audio on the OMAP3 Touch Book. + config SND_OMAP_SOC_OMAP3_BEAGLE tristate "SoC Audio support for OMAP3 Beagle" depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP3_BEAGLE diff --git a/sound/soc/omap/Makefile b/sound/soc/omap/Makefile index 02d6947..f360b82 100644 --- a/sound/soc/omap/Makefile +++ b/sound/soc/omap/Makefile @@ -15,6 +15,7 @@ snd-soc-omap3evm-objs := omap3evm.o snd-soc-sdp3430-objs := sdp3430.o snd-soc-omap3pandora-objs := omap3pandora.o snd-soc-omap3beagle-objs := omap3beagle.o +snd-soc-omap3touchbook-objs := omap3touchbook.o snd-soc-zoom2-objs := zoom2.o obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o @@ -26,4 +27,5 @@ obj-$(CONFIG_MACH_OMAP3EVM) += snd-soc-omap3evm.o obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o obj-$(CONFIG_SND_OMAP_SOC_OMAP3_BEAGLE) += snd-soc-omap3beagle.o +obj-$(CONFIG_SND_OMAP_SOC_OMAP3_TOUCHBOOK) += snd-soc-omap3touchbook.o obj-$(CONFIG_SND_OMAP_SOC_ZOOM2) += snd-soc-zoom2.o diff --git a/sound/soc/omap/omap3touchbook.c b/sound/soc/omap/omap3touchbook.c new file mode 100644 index 0000000..584f07d --- /dev/null +++ b/sound/soc/omap/omap3touchbook.c @@ -0,0 +1,211 @@ +/* + * omap3touchbook.c -- SoC audio for OMAP3 Touch Book + * + * Author: Gregoire Gentil + * + * Derived from sound/soc/omap/omap3beagle.c + * + * 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. + * + * 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 St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "omap-mcbsp.h" +#include "omap-pcm.h" +#include "../codecs/twl4030.h" + +#define TB_HEADPHONE_GPIO 56 +#define TB_HEADPHONE_IRQ OMAP_GPIO_IRQ(TB_HEADPHONE_GPIO) + +static int omap3touchbook_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->dai->codec_dai; + struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; + unsigned int fmt; + int ret; + + switch (params_channels(params)) { + case 2: /* Stereo I2S mode */ + fmt = SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBM_CFM; + break; + case 4: /* Four channel TDM mode */ + fmt = SND_SOC_DAIFMT_DSP_A | + SND_SOC_DAIFMT_IB_NF | + SND_SOC_DAIFMT_CBM_CFM; + break; + default: + return -EINVAL; + } + + /* Set codec DAI configuration */ + ret = snd_soc_dai_set_fmt(codec_dai, fmt); + if (ret < 0) { + printk(KERN_ERR "can't set codec DAI configuration\n"); + return ret; + } + + /* Set cpu DAI configuration */ + ret = snd_soc_dai_set_fmt(cpu_dai, fmt); + if (ret < 0) { + printk(KERN_ERR "can't set cpu DAI configuration\n"); + return ret; + } + + /* Set the codec system clock for DAC and ADC */ + ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000, + SND_SOC_CLOCK_IN); + if (ret < 0) { + printk(KERN_ERR "can't set codec system clock\n"); + return ret; + } + + return 0; +} + +static struct snd_soc_ops omap3touchbook_ops = { + .hw_params = omap3touchbook_hw_params, +}; + +/* Digital audio interface glue - connects codec <--> CPU */ +static struct snd_soc_dai_link omap3touchbook_dai = { + .name = "TWL4030", + .stream_name = "TWL4030", + .cpu_dai = &omap_mcbsp_dai[0], + .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], + .ops = &omap3touchbook_ops, +}; + +/* Audio machine driver */ +static struct snd_soc_card snd_soc_omap3touchbook = { + .name = "omap3touchbook", + .platform = &omap_soc_platform, + .dai_link = &omap3touchbook_dai, + .num_links = 1, +}; + +/* Audio subsystem */ +static struct snd_soc_device omap3touchbook_snd_devdata = { + .card = &snd_soc_omap3touchbook, + .codec_dev = &soc_codec_dev_twl4030, +}; + +static struct platform_device *omap3touchbook_snd_device; + +static void jack_work_func(struct work_struct *wq) +{ + struct snd_soc_device *socdev = platform_get_drvdata( + omap3touchbook_snd_device); + struct snd_soc_codec *codec = socdev->card->codec; + + snd_soc_dapm_sync(codec); +} +DECLARE_WORK(jack_work, jack_work_func); + +static irqreturn_t touchbook_headphone_event(int irq, void *snd) +{ + int status = gpio_get_value(TB_HEADPHONE_GPIO); + struct snd_soc_device *socdev = platform_get_drvdata( + omap3touchbook_snd_device); + struct snd_soc_codec *codec = socdev->card->codec; + + if (status) { + snd_soc_dapm_disable_pin(codec, "HFL"); + snd_soc_dapm_disable_pin(codec, "HFR"); + } else { + snd_soc_dapm_enable_pin(codec, "HFL"); + snd_soc_dapm_enable_pin(codec, "HFR"); + } + + schedule_work(&jack_work); + return IRQ_HANDLED; +} + +static int __init omap3touchbook_soc_init(void) +{ + int ret; + + if (!machine_is_touchbook()) { + pr_debug("Not OMAP3 Touch Book!\n"); + return -ENODEV; + } + pr_info("OMAP3 Touch Book SoC init\n"); + + omap3touchbook_snd_device = platform_device_alloc("soc-audio", -1); + if (!omap3touchbook_snd_device) { + printk(KERN_ERR "Platform device allocation failed\n"); + return -ENOMEM; + } + + platform_set_drvdata(omap3touchbook_snd_device, + &omap3touchbook_snd_devdata); + omap3touchbook_snd_devdata.dev = &omap3touchbook_snd_device->dev; + *(unsigned int *)omap3touchbook_dai.cpu_dai->private_data = 1; + + /* Touch Book -- headphone jack sensor */ + omap_set_gpio_debounce(TB_HEADPHONE_GPIO, 1); + omap_set_gpio_debounce_time(TB_HEADPHONE_GPIO, 0xff); + + ret = request_irq(TB_HEADPHONE_IRQ, touchbook_headphone_event, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + "touchbook_headphone", + omap3touchbook_snd_device); + if (ret < 0) + goto err1; + + ret = platform_device_add(omap3touchbook_snd_device); + if (ret) + goto err1; + + /* Detect headphone status */ + touchbook_headphone_event(0, omap3touchbook_snd_device); + + return 0; + +err1: + printk(KERN_ERR "Unable to add platform device\n"); + platform_device_put(omap3touchbook_snd_device); + + return ret; +} + +static void __exit omap3touchbook_soc_exit(void) +{ + platform_device_unregister(omap3touchbook_snd_device); +} + +module_init(omap3touchbook_soc_init); +module_exit(omap3touchbook_soc_exit); + +MODULE_AUTHOR("Gregoire Gentil "); +MODULE_DESCRIPTION("ALSA SoC OMAP3 Touch Book"); +MODULE_LICENSE("GPL"); -- 1.6.0.4