diff options
author | Tomasz Figa <t.figa@samsung.com> | 2013-02-28 19:41:30 +0100 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-11-18 11:42:50 +0900 |
commit | 04a6ed8f389971bd8f93a6a2025426f4d81b58a1 (patch) | |
tree | 513bc21cd444f61c0a9743b0ec140ecd814f262a /sound | |
parent | 2f32bbd22632928b89200ca4ff2c03b3487e2020 (diff) | |
download | linux-3.10-04a6ed8f389971bd8f93a6a2025426f4d81b58a1.tar.gz linux-3.10-04a6ed8f389971bd8f93a6a2025426f4d81b58a1.tar.bz2 linux-3.10-04a6ed8f389971bd8f93a6a2025426f4d81b58a1.zip |
sound: soc: samsung: Add Trats platform audio driver
This patch adds ASoC platform glue driver for Trats board.
Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/samsung/Kconfig | 6 | ||||
-rw-r--r-- | sound/soc/samsung/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/samsung/trats_mc1n2.c | 334 |
3 files changed, 342 insertions, 0 deletions
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig index 475fb0d8b3c..0d321fcfbd0 100644 --- a/sound/soc/samsung/Kconfig +++ b/sound/soc/samsung/Kconfig @@ -199,6 +199,12 @@ config SND_SOC_TOBERMORY select SND_SAMSUNG_I2S select SND_SOC_WM8962 +config SND_SOC_TRATS + tristate "Audio support for Samsung Trats" + depends on SND_SOC_SAMSUNG && CPU_EXYNOS4210 + select SND_SAMSUNG_I2S + select SND_SOC_MC1N2 + config SND_SOC_BELLS tristate "Audio support for Wolfson Bells" depends on SND_SOC_SAMSUNG && MACH_WLF_CRAGG_6410 diff --git a/sound/soc/samsung/Makefile b/sound/soc/samsung/Makefile index 709f6059ad6..d2e9b373474 100644 --- a/sound/soc/samsung/Makefile +++ b/sound/soc/samsung/Makefile @@ -40,6 +40,7 @@ snd-soc-smdk-wm8580pcm-objs := smdk_wm8580pcm.o snd-soc-smdk-wm8994pcm-objs := smdk_wm8994pcm.o snd-soc-speyside-objs := speyside.o snd-soc-tobermory-objs := tobermory.o +snd-soc-trats-objs := trats_mc1n2.o snd-soc-lowland-objs := lowland.o snd-soc-littlemill-objs := littlemill.o snd-soc-bells-objs := bells.o @@ -64,6 +65,7 @@ obj-$(CONFIG_SND_SOC_SMDK_WM8580_PCM) += snd-soc-smdk-wm8580pcm.o obj-$(CONFIG_SND_SOC_SMDK_WM8994_PCM) += snd-soc-smdk-wm8994pcm.o obj-$(CONFIG_SND_SOC_SPEYSIDE) += snd-soc-speyside.o obj-$(CONFIG_SND_SOC_TOBERMORY) += snd-soc-tobermory.o +obj-$(CONFIG_SND_SOC_TRATS) += snd-soc-trats.o obj-$(CONFIG_SND_SOC_LOWLAND) += snd-soc-lowland.o obj-$(CONFIG_SND_SOC_LITTLEMILL) += snd-soc-littlemill.o obj-$(CONFIG_SND_SOC_BELLS) += snd-soc-bells.o diff --git a/sound/soc/samsung/trats_mc1n2.c b/sound/soc/samsung/trats_mc1n2.c new file mode 100644 index 00000000000..83701ddad74 --- /dev/null +++ b/sound/soc/samsung/trats_mc1n2.c @@ -0,0 +1,334 @@ +/* + * u1_mc1n2.c + * + * Copyright (c) 2009 Samsung Electronics Co. Ltd + * Author: aitdark.park <aitdark.park@samsung.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; either version 2 of the License, or (at your + * option) any later version. + */ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/module.h> +#include <linux/io.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/suspend.h> + +#include <sound/soc.h> +#include <sound/soc-dapm.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> + +#include "../codecs/mc1n2/mc1n2.h" + +static bool xclkout_enabled; +static struct clk *clkout; + +int mc1n2_set_mclk_source(bool on) +{ + if (xclkout_enabled == on) + return 0; + + if (on) + clk_prepare_enable(clkout); + else + clk_disable_unprepare(clkout); + + xclkout_enabled = on; + msleep(10); + + return 0; +} +EXPORT_SYMBOL(mc1n2_set_mclk_source); + +static int u1_hifi_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 *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *codec_dai = rtd->codec_dai; + int ret; + + /* Set the codec DAI configuration */ + ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S + | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM); + if (ret < 0) + return ret; + + /* Set the cpu DAI configuration */ + ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S + | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM); + if (ret < 0) + return ret; +/* check later + ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_I2SV2_CLKSRC_CDCLK, + 0, SND_SOC_CLOCK_IN); + if (ret < 0) + return ret; + + ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_MUX, + 0, SND_SOC_CLOCK_IN); + if (ret < 0) + return ret; +*/ + + ret = snd_soc_dai_set_clkdiv(codec_dai, MC1N2_BCLK_MULT, MC1N2_LRCK_X32); + + if (ret < 0) + return ret; + + return 0; +} + +/* U1 Audio extra controls */ +#define U1_AUDIO_OFF 0 +#define U1_HEADSET_OUT 1 +#define U1_MIC_IN 2 +#define U1_LINE_IN 3 + +static int u1_aud_mode; + +static const char *u1_aud_scenario[] = { + [U1_AUDIO_OFF] = "Off", + [U1_HEADSET_OUT] = "Playback Headphones", + [U1_MIC_IN] = "Capture Mic", + [U1_LINE_IN] = "Capture Line", +}; + +static void u1_aud_ext_control(struct snd_soc_codec *codec) +{ + struct snd_soc_dapm_context *dapm = &codec->dapm; + + switch (u1_aud_mode) { + case U1_HEADSET_OUT: + snd_soc_dapm_enable_pin(dapm, "Headset Out"); + snd_soc_dapm_disable_pin(dapm, "Mic In"); + snd_soc_dapm_disable_pin(dapm, "Line In"); + break; + case U1_MIC_IN: + snd_soc_dapm_disable_pin(dapm, "Headset Out"); + snd_soc_dapm_enable_pin(dapm, "Mic In"); + snd_soc_dapm_disable_pin(dapm, "Line In"); + break; + case U1_LINE_IN: + snd_soc_dapm_disable_pin(dapm, "Headset Out"); + snd_soc_dapm_disable_pin(dapm, "Mic In"); + snd_soc_dapm_enable_pin(dapm, "Line In"); + break; + case U1_AUDIO_OFF: + default: + snd_soc_dapm_disable_pin(dapm, "Headset Out"); + snd_soc_dapm_disable_pin(dapm, "Mic In"); + snd_soc_dapm_disable_pin(dapm, "Line In"); + break; + } + + snd_soc_dapm_sync(dapm); +} + +static int u1_mc1n2_getp(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + ucontrol->value.integer.value[0] = u1_aud_mode; + return 0; +} + +static int u1_mc1n2_setp(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); + + if (u1_aud_mode == ucontrol->value.integer.value[0]) + return 0; + + u1_aud_mode = ucontrol->value.integer.value[0]; + u1_aud_ext_control(codec); + + return 1; +} + +static const struct snd_soc_dapm_widget u1_dapm_widgets[] = { + SND_SOC_DAPM_HP("Headset Out", NULL), + SND_SOC_DAPM_MIC("Mic In", NULL), + SND_SOC_DAPM_LINE("Line In", NULL), +}; + +static const struct soc_enum u1_aud_enum[] = { + SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(u1_aud_scenario), + u1_aud_scenario), +}; + +static const struct snd_kcontrol_new u1_aud_controls[] = { + SOC_ENUM_EXT("U1 Audio Mode", u1_aud_enum[0], + u1_mc1n2_getp, u1_mc1n2_setp), +}; + +static const struct snd_soc_dapm_route u1_dapm_routes[] = { + /* Connections to Headset */ + {"Headset Out", NULL, "HPOUT1L"}, + {"Headset Out", NULL, "HPOUT1R"}, + /* Connections to Mics */ + {"IN1LN", NULL, "Mic In"}, + {"IN1RN", NULL, "Mic In"}, + /* Connections to Line In */ + {"IN2LN", NULL, "Line In"}, + {"IN2RN", NULL, "Line In"}, +}; + +static int u1_hifiaudio_init(struct snd_soc_pcm_runtime *rtd) +{ + return 0; +} + +/* + * U1 MC1N2 DAI operations. + */ +static struct snd_soc_ops u1_hifi_ops = { + .hw_params = u1_hifi_hw_params, +}; + +static struct snd_soc_dai_link u1_dai[] = { +#if defined(CONFIG_SND_SAMSUNG_LP) || defined(CONFIG_SND_SAMSUNG_ALP) + { /* Sec_Fifo DAI i/f */ + .name = "MC1N2 Sec_FIFO TX", + .stream_name = "Sec_Dai", + .cpu_dai_name = "samsung-i2s.4", + .codec_dai_name = "mc1n2-da0i", +#ifndef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER + .platform_name = "samsung-audio-idma", +#else + .platform_name = "samsung-audio", +#endif + .codec_name = "mc1n2.6-003a", + .init = u1_hifiaudio_init, + .ops = &u1_hifi_ops, + }, +#endif + { /* Primary DAI i/f */ + .name = "MC1N2 AIF1", + .stream_name = "hifiaudio", + .cpu_dai_name = "samsung-i2s.0", + .codec_dai_name = "mc1n2-da0i", + .platform_name = "samsung-audio", + .codec_name = "mc1n2.6-003a", + .init = u1_hifiaudio_init, + .ops = &u1_hifi_ops, + } +}; + +static int u1_card_suspend(struct snd_soc_card *card) +{ +#warning FIXME +#if 0 + exynos4_sys_powerdown_parent_control(xclkout_enabled ? 1 : 0); +#endif + return 0; +} + +static struct snd_soc_card u1_snd_card = { + .name = "U1-YMU823", + .dai_link = u1_dai, + .num_links = ARRAY_SIZE(u1_dai), + + .suspend_post = u1_card_suspend, +}; + +/* setup codec data from mc1n2 codec driver */ +extern void set_mc1n2_codec_data(struct mc1n2_setup *setup); + +static struct platform_device *u1_snd_device; + +static int u1_snd_probe(struct platform_device *pdev) +{ + int ret; + struct clk *out_mux; + struct clk *parent; + + if (pdev->dev.of_node) { + struct device_node *np = pdev->dev.of_node; + struct snd_soc_dai_link *link = u1_dai; + + link->cpu_dai_name = NULL; + link->cpu_of_node = of_parse_phandle(np, + "samsung,i2s-controller", 0); + if (!link->cpu_of_node) { + dev_err(&pdev->dev, "failed to parse samsung,i2s-controller phandle\n"); + return -EINVAL; + } + + link->platform_name = NULL; + link->platform_of_node = link->cpu_of_node; + + link->codec_name = NULL; + link->codec_of_node = of_parse_phandle(np, + "samsung,audio-codec", 0); + if (!link->codec_of_node) { + dev_err(&pdev->dev, "failed to parse samsung,audio-codec phandle\n"); + return -EINVAL; + } + } + + clkout = clk_get(&pdev->dev, "out"); + if (IS_ERR(clkout)) { + dev_err(&pdev->dev, "failed to get out clock\n"); + return PTR_ERR(clkout); + } + + out_mux = clk_get(&pdev->dev, "out-mux"); + if (IS_ERR(out_mux)) { + dev_err(&pdev->dev, "failed to get out mux clock\n"); + return PTR_ERR(out_mux); + } + + parent = clk_get(&pdev->dev, "parent"); + if (IS_ERR(parent)) { + dev_err(&pdev->dev, "failed to get parent clock\n"); + return PTR_ERR(parent); + } + + clk_set_parent(out_mux, parent); + mc1n2_set_mclk_source(true); + + u1_snd_device = platform_device_alloc("soc-audio", -1); + if (!u1_snd_device) + return -ENOMEM; + + platform_set_drvdata(u1_snd_device, &u1_snd_card); + + ret = platform_device_add(u1_snd_device); + if (ret) { + platform_device_put(u1_snd_device); + } + + return ret; +} + +static void u1_snd_remove(struct platform_device *pdev) +{ + platform_device_unregister(u1_snd_device); +} + +static struct of_device_id u1_snd_of_matches[] = { + { .compatible = "samsung,u1-platform-snd", }, + {} +}; + +static struct platform_driver u1_snd_driver = { + .driver = { + .name = "u1-platform-snd", + .of_match_table = u1_snd_of_matches, + }, + .probe = u1_snd_probe, + .remove = u1_snd_remove, +}; +module_platform_driver(u1_snd_driver); + +MODULE_AUTHOR("aitdark, aitdark.park@samsung.com"); +MODULE_DESCRIPTION("ALSA SoC U1 MC1N2"); +MODULE_LICENSE("GPL"); |