diff options
author | NeilBrown <neilb@suse.de> | 2011-11-18 16:28:12 +1100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2013-05-17 17:04:24 +1000 |
commit | abcc8a428730340928b58c0f7eabf6c36f96464a (patch) | |
tree | a55fd1b2e719ea4f5961bc9f47dee60190ea2fe3 /sound/soc/omap | |
parent | c240a539df4e2d50f86e2f31813ff6b7334cd493 (diff) | |
download | kernel_goldelico_gta04-abcc8a428730340928b58c0f7eabf6c36f96464a.zip kernel_goldelico_gta04-abcc8a428730340928b58c0f7eabf6c36f96464a.tar.gz kernel_goldelico_gta04-abcc8a428730340928b58c0f7eabf6c36f96464a.tar.bz2 |
Add GTA04 sound/codec files
Diffstat (limited to 'sound/soc/omap')
-rw-r--r-- | sound/soc/omap/Kconfig | 8 | ||||
-rw-r--r-- | sound/soc/omap/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/omap/gta04-audio.c | 255 | ||||
-rw-r--r-- | sound/soc/omap/gta04-fm.c | 157 | ||||
-rw-r--r-- | sound/soc/omap/gta04-headset.c | 154 | ||||
-rw-r--r-- | sound/soc/omap/gta04-voice.c | 181 | ||||
-rw-r--r-- | sound/soc/omap/gta04.c | 254 |
7 files changed, 1011 insertions, 0 deletions
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig index 60259f2..f2561d2 100644 --- a/sound/soc/omap/Kconfig +++ b/sound/soc/omap/Kconfig @@ -116,3 +116,11 @@ config SND_OMAP_SOC_OMAP3_PANDORA select SND_SOC_TWL4030 help Say Y if you want to add support for SoC audio on the OMAP3 Pandora. + +config SND_OMAP_SOC_GTA04 + tristate "SoC Audio support for GTA04" + depends on TWL4030_CORE && SND_OMAP_SOC && (MACH_GTA04 || MACH_OMAP3_BEAGLE) + select SND_OMAP_SOC_MCBSP + select SND_SOC_TWL4030 + help + Say Y if you want to add support for SoC audio on the GTA04. diff --git a/sound/soc/omap/Makefile b/sound/soc/omap/Makefile index 2b22594..5337069 100644 --- a/sound/soc/omap/Makefile +++ b/sound/soc/omap/Makefile @@ -20,6 +20,7 @@ snd-soc-am3517evm-objs := am3517evm.o snd-soc-omap-abe-twl6040-objs := omap-abe-twl6040.o snd-soc-omap-twl4030-objs := omap-twl4030.o snd-soc-omap3pandora-objs := omap3pandora.o +snd-soc-gta04-objs := gta04-audio.o gta04-voice.o gta04-headset.o gta04-fm.o snd-soc-omap-hdmi-card-objs := omap-hdmi-card.o obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o @@ -31,4 +32,5 @@ obj-$(CONFIG_SND_OMAP_SOC_AM3517EVM) += snd-soc-am3517evm.o obj-$(CONFIG_SND_OMAP_SOC_OMAP_ABE_TWL6040) += snd-soc-omap-abe-twl6040.o obj-$(CONFIG_SND_OMAP_SOC_OMAP_TWL4030) += snd-soc-omap-twl4030.o obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o +obj-$(CONFIG_SND_OMAP_SOC_GTA04) += snd-soc-gta04.o obj-$(CONFIG_SND_OMAP_SOC_OMAP_HDMI) += snd-soc-omap-hdmi-card.o diff --git a/sound/soc/omap/gta04-audio.c b/sound/soc/omap/gta04-audio.c new file mode 100644 index 0000000..3d55038 --- /dev/null +++ b/sound/soc/omap/gta04-audio.c @@ -0,0 +1,255 @@ +/* + * gta04.c -- SoC audio for GTA04 (based on OMAP3 Beagle) + * + * Author: Steve Sakoman <steve@sakoman.com> + * Author: Nikolaus Schaller <hns@goldelico.com> + * + * 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 <linux/clk.h> +#include <linux/platform_device.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/soc-dapm.h> + +#include <asm/mach-types.h> +#include <mach/hardware.h> +#include <mach/gpio.h> +#include <plat/mcbsp.h> + +#include "omap-mcbsp.h" +#include "omap-pcm.h" +#include "../codecs/twl4030.h" + +static int omap3gta04_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 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; +} + +/* this shows how we could control the AUX in/out switch or the Video in/out */ + +static int omap3pandora_hp_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *k, int event) +{ + /* + if (SND_SOC_DAPM_EVENT_ON(event)) { + gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 1); + gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 1); + } else { + gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 0); + mdelay(1); + gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 0); + } + */ + return 0; +} + +static const struct snd_soc_dapm_widget gta04_dapm_widgets[] = { + SND_SOC_DAPM_DAC("PCM DAC", "HiFi Playback", SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_PGA_E("Headphone Amplifier", SND_SOC_NOPM, + 0, 0, NULL, 0, omap3pandora_hp_event, + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + SND_SOC_DAPM_HP("Headphone Jack", NULL), + SND_SOC_DAPM_LINE("Line Out", NULL), + SND_SOC_DAPM_MIC("Internal Mic", NULL), + SND_SOC_DAPM_MIC("Headphone Mic", NULL), + SND_SOC_DAPM_LINE("Line In", NULL), +}; + +static const struct snd_soc_dapm_route audio_map[] = { + {"Headphone Amplifier", NULL, "PCM DAC"}, + {"Line Out", NULL, "PCM DAC"}, + {"Headphone Jack", NULL, "Headphone Amplifier"}, + + {"AUXL", NULL, "Line In"}, + {"AUXR", NULL, "Line In"}, + + /* Headset Mic: HSMIC with bias */ + {"HSMIC", NULL, "Headset Mic Bias"}, + {"Headset Mic Bias", NULL, "Headphone Mic"}, + + {"MAINMIC", NULL, "Mic Bias 1"}, + {"Mic Bias 1", NULL, "Internal Mic"}, + /* + {"SUBMIC", NULL, "Mic Bias 2"}, + {"Mic Bias 2", NULL, "Mic (external)"}, + */ +}; + +static int omap3gta04_init(struct snd_soc_codec *codec) +{ + int ret; + struct snd_soc_dapm_context *dapm = &codec->dapm; + + ret = snd_soc_dapm_new_controls(dapm, gta04_dapm_widgets, + ARRAY_SIZE(gta04_dapm_widgets)); + if (ret < 0) + return ret; + + snd_soc_dapm_add_routes(dapm, audio_map, + ARRAY_SIZE(audio_map)); + +// snd_soc_dapm_enable_pin(codec, "Ext Mic"); +// snd_soc_dapm_enable_pin(codec, "Ext Spk"); +// snd_soc_dapm_disable_pin(codec, "Headphone Mic"); +// snd_soc_dapm_disable_pin(codec, "Headphone Amplifier"); + + /* TWL4030 not connected pins */ + // snd_soc_dapm_nc_pin(codec, "OUTL"); + // snd_soc_dapm_nc_pin(codec, "OUTR"); + // snd_soc_dapm_nc_pin(codec, "EARPIECE"); + snd_soc_dapm_nc_pin(dapm, "PREDRIVEL"); + snd_soc_dapm_nc_pin(dapm, "PREDRIVER"); + // snd_soc_dapm_nc_pin(codec, "HSOL"); + // snd_soc_dapm_nc_pin(codec, "HSOR"); + snd_soc_dapm_nc_pin(dapm, "CARKITMIC"); + snd_soc_dapm_nc_pin(dapm, "CARKITL"); + snd_soc_dapm_nc_pin(dapm, "CARKITR"); + // snd_soc_dapm_nc_pin(codec, "HFL"); + // snd_soc_dapm_nc_pin(codec, "HFR"); + // snd_soc_dapm_nc_pin(codec, "VIBRA"); + // snd_soc_dapm_nc_pin(codec, "HSMIC"); + snd_soc_dapm_nc_pin(dapm, "DIGIMIC0"); + snd_soc_dapm_nc_pin(dapm, "DIGIMIC1"); + + return snd_soc_dapm_sync(dapm); +} + +static struct snd_soc_ops omap3gta04_ops = { + .hw_params = omap3gta04_hw_params, +}; + +/* Digital audio interface glue - connects codec <--> CPU */ +static struct snd_soc_dai_link omap3gta04_dai[] = { + { + .name = "TWL4030", + .stream_name = "TWL4030", + .cpu_dai_name = "omap-mcpdm-dai.0", + .codec_dai_name = "twl4030-hifi", + .ops = &omap3gta04_ops, + .init = &omap3gta04_init + } +}; + +/* Audio machine driver */ +static struct snd_soc_card snd_soc_omap3gta04 = { + .name = "gta04", +// .platform = &omap_soc_platform, + .dai_link = &omap3gta04_dai[0], + .num_links = ARRAY_SIZE(omap3gta04_dai), +}; + +/* Audio subsystem */ +/*static struct snd_soc_driver omap3gta04_snd_devdata = { + .card = &snd_soc_omap3gta04, + .codec_dev = &soc_codec_dev_twl4030, +};*/ + +static struct platform_device *omap3gta04_snd_device; + +static int __init omap3gta04_soc_init(void) +{ + int ret; + +/* if (!machine_is_gta04() && !machine_is_omap3_gta04()) { + pr_debug("Not GTA04!\n"); + return -ENODEV; + }*/ + pr_info("GTA04 OMAP3 SoC snd init\n"); + + // FIXME: set any GPIOs i.e. enable Audio in/out switch + // microphone power etc. + + omap3gta04_snd_device = platform_device_alloc("soc-audio", -1); + if (!omap3gta04_snd_device) { + printk(KERN_ERR "Platform device allocation failed\n"); + return -ENOMEM; + } + + platform_set_drvdata(omap3gta04_snd_device, &snd_soc_omap3gta04); +// omap3gta04_snd_devdata.dev = &omap3gta04_snd_device->dev; +// *(unsigned int *)omap3gta04_dai[0].cpu_dai->private_data = 1; /* McBSP2 = TPS65950 */ + ret = platform_device_add(omap3gta04_snd_device); + if (ret) + goto err1; + + return 0; + +err1: + printk(KERN_ERR "Unable to add platform device\n"); + platform_device_put(omap3gta04_snd_device); + + return ret; +} + +static void __exit omap3gta04_soc_exit(void) +{ + platform_device_unregister(omap3gta04_snd_device); + // switch off power +} + +module_init(omap3gta04_soc_init); +module_exit(omap3gta04_soc_exit); + +MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>"); +MODULE_DESCRIPTION("ALSA SoC OMAP3 GTA04"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/omap/gta04-fm.c b/sound/soc/omap/gta04-fm.c new file mode 100644 index 0000000..9a5d74e --- /dev/null +++ b/sound/soc/omap/gta04-fm.c @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2011 John Ogness + * Author: John Ogness <john.ogness@linutronix.de> + * + * based on sound/soc/omap/omap3beagle.c by + * Steve Sakoman <steve@sakoman.com> + * + * 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 version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, + * whether express or implied; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <linux/platform_device.h> + +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/soc-dapm.h> + +#include "omap-mcbsp.h" +#include "omap-pcm.h" +#include "../codecs/si47xx.h" + +static int gta04_fm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + /* setup codec dai and cpu dai hardware 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; + + fmt = SND_SOC_DAIFMT_I2S | // I2S + SND_SOC_DAIFMT_IB_IF | // positive sync pulse, driven on rising, sampled on falling clock + SND_SOC_DAIFMT_CBM_CFM; // clocks come from FM tuner + + /* 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; + } + + ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKX_EXT, 0, + SND_SOC_CLOCK_IN); + // FIXME: set clock divisor + if (ret < 0) { + printk(KERN_ERR "can't set cpu system clock\n"); + return ret; + } + + return 0; +} + +static int gta04_fm_init(struct snd_soc_codec *codec) +{ + /* add controls */ + /* add routes */ + /* setup pins */ + + snd_soc_dapm_sync(codec); + return 0; +} + +static int gta04_fm_startup(struct snd_pcm_substream *substream) +{ + /* enable clock used by codec */ + return 0; +} + +static void gta04_fm_shutdown(struct snd_pcm_substream *substream) +{ + /* disable clock used by codec */ +} + +static struct snd_soc_ops gta04_fm_ops = { + .startup = gta04_fm_startup, + .hw_params = gta04_fm_hw_params, + .shutdown = gta04_fm_shutdown, +}; + +/* digital fm interface glue - connects codec <--> cpu */ +static struct snd_soc_dai_link gta04_fm_dai = { + .name = "Si47xx", + .stream_name = "Si47xx", + .cpu_dai = &omap_mcbsp_dai[3], + .codec_dai = &si47xx_dai, + .init = gta04_fm_init, + .ops = >a04_fm_ops, +}; + +/* fm machine driver */ +static struct snd_soc_card gta04_fm_card = { + .name = "gta04-fm", + .platform = &omap_soc_platform, + .dai_link = >a04_fm_dai, + .num_links = 1, +}; + +/* fm subsystem */ +static struct si47xx_setup_data gta04_fm_soc_data = { + .i2c_bus = 2, + .i2c_address = 0x11, +}; +static struct snd_soc_device gta04_fm_devdata = { + .card = >a04_fm_card, + .codec_dev = &soc_codec_dev_si47xx, + .codec_data = >a04_fm_soc_data, +}; + +static struct platform_device *gta04_fm_snd_device; + +static int __init gta04_fm_soc_init(void) +{ + struct device *dev; + int ret; + + pr_info("gta04-fm SoC init\n"); + + gta04_fm_snd_device = platform_device_alloc("soc-audio", 3); + if (!gta04_fm_snd_device) { + printk(KERN_ERR "platform device allocation failed\n"); + return -ENOMEM; + } + + dev = >a04_fm_snd_device->dev; + + platform_set_drvdata(gta04_fm_snd_device, >a04_fm_card); +// gta04_fm_devdata.dev = >a04_fm_snd_device->dev; +// *(unsigned int *)gta04_fm_dai.cpu_dai->private_data = 0; // McBSP1 + + ret = platform_device_add(gta04_fm_snd_device); + if (ret) { + printk(KERN_ERR "unable to add platform device\n"); + platform_device_put(gta04_fm_snd_device); + } + + return ret; +} + +static void __exit gta04_fm_soc_exit(void) +{ + platform_device_unregister(gta04_fm_snd_device); +} + +module_init(gta04_fm_soc_init); +module_exit(gta04_fm_soc_exit); + +MODULE_AUTHOR("John Ogness <john.ogness@linutronix.de>"); +MODULE_DESCRIPTION("ALSA SoC GTA04 FM"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/omap/gta04-headset.c b/sound/soc/omap/gta04-headset.c new file mode 100644 index 0000000..e200ea7 --- /dev/null +++ b/sound/soc/omap/gta04-headset.c @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2011 John Ogness + * Author: John Ogness <john.ogness@linutronix.de> + * + * based on sound/soc/omap/omap3beagle.c by + * Steve Sakoman <steve@sakoman.com> + * + * 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 version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, + * whether express or implied; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <linux/platform_device.h> + +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/soc-dapm.h> + +#include "omap-mcbsp.h" +#include "omap-pcm.h" +#include "../codecs/w2cbw003-bt.h" + +static int gta04_headset_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + /* setup codec dai and cpu dai hardware 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->cpu_dai; + unsigned int fmt; + int ret; + + fmt = SND_SOC_DAIFMT_I2S | // I2S + SND_SOC_DAIFMT_IB_IF | // positive sync pulse, driven on rising, sampled on falling clock + SND_SOC_DAIFMT_CBM_CFM; // clocks come from bluetooth modem - but this can be configured in the Modem chip + + /* 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; + } + + ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKX_EXT, 0, + SND_SOC_CLOCK_IN); + // FIXME: set clock divisor + if (ret < 0) { + printk(KERN_ERR "can't set cpu system clock\n"); + return ret; + } + + return 0; +} + +static int gta04_headset_init(struct snd_soc_codec *codec) +{ + /* add controls */ + /* add routes */ + /* setup pins */ + struct snd_soc_dapm_context *dapm = &codec->dapm; + snd_soc_dapm_sync(dapm); + return 0; +} + +static int gta04_headset_startup(struct snd_pcm_substream *substream) +{ + /* enable clock used by codec */ + return 0; +} + +static void gta04_headset_shutdown(struct snd_pcm_substream *substream) +{ + /* disable clock used by codec */ +} + +static struct snd_soc_ops gta04_headset_ops = { + .startup = gta04_headset_startup, + .hw_params = gta04_headset_hw_params, + .shutdown = gta04_headset_shutdown, +}; + +/* digital headset interface glue - connects codec <--> cpu */ +static struct snd_soc_dai_link gta04_headset_dai = { + .name = "W2CBW003", + .stream_name = "W2CBW003", +// .cpu_dai = &omap_mcbsp_dai[2], + .cpu_dai_name = "omap-mcpdm-dai.2", +// .codec_dai = &w2cbw003_dai, + .codec_dai_name = "w2cbw003_codec_audio", + .init = gta04_headset_init, + .ops = >a04_headset_ops, +}; + +/* headset machine driver */ +static struct snd_soc_card gta04_headset_card = { + .name = "gta04-headset", +// .platform = &omap_soc_platform, + .dai_link = >a04_headset_dai, + .num_links = 1, +}; + +/* headset subsystem */ +/*static struct snd_soc_device gta04_headset_devdata = { + .card = >a04_headset_card, + .codec_dev = &soc_codec_dev_w2cbw003, +};*/ + +static struct platform_device *gta04_headset_snd_device; + +static int __init gta04_headset_soc_init(void) +{ + struct device *dev; + int ret; + + pr_info("gta04-headset SoC init\n"); + + gta04_headset_snd_device = platform_device_alloc("soc-audio", 2); + if (!gta04_headset_snd_device) { + printk(KERN_ERR "platform device allocation failed\n"); + return -ENOMEM; + } + + dev = >a04_headset_snd_device->dev; + + platform_set_drvdata(gta04_headset_snd_device, >a04_headset_card); +// gta04_headset_devdata.dev = >a04_headset_snd_device->dev; +// *(unsigned int *)gta04_headset_dai.cpu_dai->private_data = 2; // McBSP3 + + ret = platform_device_add(gta04_headset_snd_device); + if (ret) { + printk(KERN_ERR "unable to add platform device\n"); + platform_device_put(gta04_headset_snd_device); + } + + return ret; +} + +static void __exit gta04_headset_soc_exit(void) +{ + platform_device_unregister(gta04_headset_snd_device); +} + +module_init(gta04_headset_soc_init); +module_exit(gta04_headset_soc_exit); + +MODULE_AUTHOR("John Ogness <john.ogness@linutronix.de>"); +MODULE_DESCRIPTION("ALSA SoC GTA04 Headset"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/omap/gta04-voice.c b/sound/soc/omap/gta04-voice.c new file mode 100644 index 0000000..4c475edf --- /dev/null +++ b/sound/soc/omap/gta04-voice.c @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2011 John Ogness + * Author: John Ogness <john.ogness@linutronix.de> + * + * based on sound/soc/omap/omap3beagle.c by + * Steve Sakoman <steve@sakoman.com> + * + * 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 version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, + * whether express or implied; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +#include <linux/platform_device.h> + +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/soc-dapm.h> + +#include "omap-mcbsp.h" +#include "omap-pcm.h" +#include "../codecs/gtm601.h" + +static int gta04_voice_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params) +{ + /* setup codec dai and cpu dai hardware 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->cpu_dai; + unsigned int fmt; + int ret; + + fmt = SND_SOC_DAIFMT_I2S | // I2S + // SND_SOC_DAIFMT_GATED | // try to power down if not needed + SND_SOC_DAIFMT_IB_IF | // positive sync pulse, driven on rising, sampled on falling clock + SND_SOC_DAIFMT_CBM_CFM; // clocks come from GSM modem + +#if 0 // set clocks to be outputs + + fmt = SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_IB_IF | + SND_SOC_DAIFMT_CBS_CFS; + +#endif + /* 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; + } + +#if 0 // for testing we switch to output - don't use on a board with GTM601 installed!!! + ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLK, 26000000, + SND_SOC_CLOCK_OUT); + // set divider... +#else + ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_SYSCLK_CLKX_EXT, 0, + SND_SOC_CLOCK_IN); + if(cpu_dai == 0) { + /* + * could be necessary if we connect to McBSP1 - but we are on McBSP4 + * see http://mailman.alsa-project.org/pipermail/alsa-devel/2009-August/020771.html + */ + if(ret >= 0) + ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_CLKR_SRC_CLKX, 0, + SND_SOC_CLOCK_IN); + if(ret >= 0) + ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_MCBSP_FSR_SRC_FSX, 0, + SND_SOC_CLOCK_IN); + } +#endif + if (ret < 0) { + printk(KERN_ERR "can't set cpu system clock\n"); + return ret; + } + + return 0; +} + +static int gta04_voice_init(struct snd_soc_codec *codec) +{ + /* add controls */ + /* add routes */ + /* setup pins */ + struct snd_soc_dapm_context *dapm = &codec->dapm; + snd_soc_dapm_sync(dapm); + return 0; +} + +static int gta04_voice_startup(struct snd_pcm_substream *substream) +{ + /* enable clock used by codec */ + /* clock is provided by the GTM601 */ + return 0; +} + +static void gta04_voice_shutdown(struct snd_pcm_substream *substream) +{ + /* disable clock used by codec */ + /* clock is provided by the GTM601 */ +} + +static struct snd_soc_ops gta04_voice_ops = { + .startup = gta04_voice_startup, + .hw_params = gta04_voice_hw_params, + .shutdown = gta04_voice_shutdown, +}; + +/* digital voice interface glue - connects codec <--> cpu */ +static struct snd_soc_dai_link gta04_voice_dai = { + .name = "GTM601", + .stream_name = "GTM601", +// .cpu_dai = &omap_mcbsp_dai[1], + .cpu_dai_name = "omap-mcpdm-dai.1", +// .codec_dai = >m601_dai, + .codec_dai_name = "gtm601_codec_audio", + .init = gta04_voice_init, + .ops = >a04_voice_ops, +}; + +/* voice machine driver */ +static struct snd_soc_card gta04_voice_card = { + .name = "gta04-voice", +// .platform = &omap_soc_platform, + .dai_link = >a04_voice_dai, + .num_links = 1, +}; + +/* voice subsystem */ +/*static struct snd_soc_device gta04_voice_devdata = { + .card = >a04_voice_card, + .codec_dev = &soc_codec_dev_gtm601, +};*/ + +static struct platform_device *gta04_voice_snd_device; + +static int __init gta04_voice_soc_init(void) +{ + struct device *dev; + int ret; + + pr_info("gta04-voice SoC init\n"); + + gta04_voice_snd_device = platform_device_alloc("soc-audio", 1); + if (!gta04_voice_snd_device) { + printk(KERN_ERR "platform device allocation failed\n"); + return -ENOMEM; + } + + dev = >a04_voice_snd_device->dev; + + platform_set_drvdata(gta04_voice_snd_device, >a04_voice_card); +// gta04_voice_devdata.dev = >a04_voice_snd_device->dev; +// *(unsigned int *)gta04_voice_dai.cpu_dai->private_data = 3; // McBSP4 + + ret = platform_device_add(gta04_voice_snd_device); + if (ret) { + printk(KERN_ERR "unable to add platform device\n"); + platform_device_put(gta04_voice_snd_device); + } + + return ret; +} + +static void __exit gta04_voice_soc_exit(void) +{ + platform_device_unregister(gta04_voice_snd_device); +} + +module_init(gta04_voice_soc_init); +module_exit(gta04_voice_soc_exit); + +MODULE_AUTHOR("John Ogness <john.ogness@linutronix.de>"); +MODULE_DESCRIPTION("ALSA SoC GTA04 Voice"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/omap/gta04.c b/sound/soc/omap/gta04.c new file mode 100644 index 0000000..5191f26 --- /dev/null +++ b/sound/soc/omap/gta04.c @@ -0,0 +1,254 @@ +/* + * gta04.c -- SoC audio for GTA04 (based on OMAP3 Beagle) + * + * Author: Steve Sakoman <steve@sakoman.com> + * Author: Nikolaus Schaller <hns@goldelico.com> + * + * 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 <linux/clk.h> +#include <linux/platform_device.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/soc-dapm.h> + +#include <asm/mach-types.h> +#include <mach/hardware.h> +#include <mach/gpio.h> +#include <plat/mcbsp.h> + +#include "omap-mcbsp.h" +#include "omap-pcm.h" +#include "../codecs/twl4030.h" + +static int omap3beagle_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 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; +} + +/* this shows how we could control the AUX in/out switch or the Video in/out */ + +static int omap3pandora_hp_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *k, int event) +{ + /* + if (SND_SOC_DAPM_EVENT_ON(event)) { + gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 1); + gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 1); + } else { + gpio_set_value(OMAP3_PANDORA_AMP_POWER_GPIO, 0); + mdelay(1); + gpio_set_value(OMAP3_PANDORA_DAC_POWER_GPIO, 0); + } + */ + return 0; +} + +static const struct snd_soc_dapm_widget gta04_dapm_widgets[] = { + SND_SOC_DAPM_DAC("PCM DAC", "HiFi Playback", SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_PGA_E("Headphone Amplifier", SND_SOC_NOPM, + 0, 0, NULL, 0, omap3pandora_hp_event, + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + SND_SOC_DAPM_HP("Headphone Jack", NULL), + SND_SOC_DAPM_LINE("Line Out", NULL), + SND_SOC_DAPM_MIC("Internal Mic", NULL), + SND_SOC_DAPM_MIC("Headphone Mic", NULL), + SND_SOC_DAPM_LINE("Line In", NULL), +}; + +static const struct snd_soc_dapm_route audio_map[] = { + {"Headphone Amplifier", NULL, "PCM DAC"}, + {"Line Out", NULL, "PCM DAC"}, + {"Headphone Jack", NULL, "Headphone Amplifier"}, + + {"AUXL", NULL, "Line In"}, + {"AUXR", NULL, "Line In"}, + + /* Headset Mic: HSMIC with bias */ + {"HSMIC", NULL, "Headset Mic Bias"}, + {"Headset Mic Bias", NULL, "Headphone Mic"}, + + {"MAINMIC", NULL, "Mic Bias 1"}, + {"Mic Bias 1", NULL, "Internal Mic"}, + /* + {"SUBMIC", NULL, "Mic Bias 2"}, + {"Mic Bias 2", NULL, "Mic (external)"}, + */ +}; + +static int omap3gta04_init(struct snd_soc_codec *codec) +{ + int ret; + + ret = snd_soc_dapm_new_controls(codec, gta04_dapm_widgets, + ARRAY_SIZE(gta04_dapm_widgets)); + if (ret < 0) + return ret; + + snd_soc_dapm_add_routes(codec, audio_map, + ARRAY_SIZE(audio_map)); + +// snd_soc_dapm_enable_pin(codec, "Ext Mic"); +// snd_soc_dapm_enable_pin(codec, "Ext Spk"); +// snd_soc_dapm_disable_pin(codec, "Headphone Mic"); +// snd_soc_dapm_disable_pin(codec, "Headphone Amplifier"); + + /* TWL4030 not connected pins */ + // snd_soc_dapm_nc_pin(codec, "OUTL"); + // snd_soc_dapm_nc_pin(codec, "OUTR"); + // snd_soc_dapm_nc_pin(codec, "EARPIECE"); + snd_soc_dapm_nc_pin(codec, "PREDRIVEL"); + snd_soc_dapm_nc_pin(codec, "PREDRIVER"); + // snd_soc_dapm_nc_pin(codec, "HSOL"); + // snd_soc_dapm_nc_pin(codec, "HSOR"); + snd_soc_dapm_nc_pin(codec, "CARKITMIC"); + snd_soc_dapm_nc_pin(codec, "CARKITL"); + snd_soc_dapm_nc_pin(codec, "CARKITR"); + // snd_soc_dapm_nc_pin(codec, "HFL"); + // snd_soc_dapm_nc_pin(codec, "HFR"); + // snd_soc_dapm_nc_pin(codec, "VIBRA"); + // snd_soc_dapm_nc_pin(codec, "HSMIC"); + snd_soc_dapm_nc_pin(codec, "DIGIMIC0"); + snd_soc_dapm_nc_pin(codec, "DIGIMIC1"); + + return snd_soc_dapm_sync(codec); +} + +static struct snd_soc_ops omap3beagle_ops = { + .hw_params = omap3beagle_hw_params, +}; + +/* Digital audio interface glue - connects codec <--> CPU */ +static struct snd_soc_dai_link omap3beagle_dai[] = { + { + .name = "TWL4030", + .stream_name = "TWL4030", + .cpu_dai = &omap_mcbsp_dai[0], + .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI], + .ops = &omap3beagle_ops, + .init = &omap3gta04_init + } +}; + +/* Audio machine driver */ +static struct snd_soc_card snd_soc_omap3beagle = { + .name = "gta04", + .platform = &omap_soc_platform, + .dai_link = &omap3beagle_dai[0], + .num_links = ARRAY_SIZE(omap3beagle_dai), +}; + +/* Audio subsystem */ +static struct snd_soc_device omap3beagle_snd_devdata = { + .card = &snd_soc_omap3beagle, + .codec_dev = &soc_codec_dev_twl4030, +}; + +static struct platform_device *omap3beagle_snd_device; + +static int __init omap3beagle_soc_init(void) +{ + int ret; + + if (!machine_is_gta04() && !machine_is_omap3_beagle()) { + pr_debug("Not GTA04!\n"); + return -ENODEV; + } + pr_info("GTA04 OMAP3 SoC snd init\n"); + + // FIXME: set any GPIOs i.e. enable Audio in/out switch + // microphone power etc. + + omap3beagle_snd_device = platform_device_alloc("soc-audio", -1); + if (!omap3beagle_snd_device) { + printk(KERN_ERR "Platform device allocation failed\n"); + return -ENOMEM; + } + + platform_set_drvdata(omap3beagle_snd_device, &omap3beagle_snd_devdata); + omap3beagle_snd_devdata.dev = &omap3beagle_snd_device->dev; +// *(unsigned int *)omap3beagle_dai[0].cpu_dai->private_data = 1; /* McBSP2 = TPS65950 */ + ret = platform_device_add(omap3beagle_snd_device); + if (ret) + goto err1; + + return 0; + +err1: + printk(KERN_ERR "Unable to add platform device\n"); + platform_device_put(omap3beagle_snd_device); + + return ret; +} + +static void __exit omap3beagle_soc_exit(void) +{ + platform_device_unregister(omap3beagle_snd_device); + // switch off power +} + +module_init(omap3beagle_soc_init); +module_exit(omap3beagle_soc_exit); + +MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>"); +MODULE_DESCRIPTION("ALSA SoC OMAP3 GTA04"); +MODULE_LICENSE("GPL"); |