/* * smdk_wm8994.c * * 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 #include #include #include #include #include "../codecs/wm8994.h" #include "pcm.h" /* * Default CFG switch settings to use this driver: * SMDKV310: CFG5-1000, CFG7-111111 */ /* * Configure audio route as :- * $ amixer sset 'DAC1' on,on * $ amixer sset 'Right Headphone Mux' 'DAC' * $ amixer sset 'Left Headphone Mux' 'DAC' * $ amixer sset 'DAC1R Mixer AIF1.1' on * $ amixer sset 'DAC1L Mixer AIF1.1' on * $ amixer sset 'IN2L' on * $ amixer sset 'IN2L PGA IN2LN' on * $ amixer sset 'MIXINL IN2L' on * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on * $ amixer sset 'IN2R' on * $ amixer sset 'IN2R PGA IN2RN' on * $ amixer sset 'MIXINR IN2R' on * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on */ /* SMDK has a 16.934MHZ crystal attached to WM8994 */ #define SMDK_WM8994_FREQ 16934000 #ifdef CONFIG_SND_SAMSUNG_PCM_USE_EPLL static int set_epll_rate(unsigned long rate) { struct clk *fout_epll; fout_epll = clk_get(NULL, "fout_epll"); if (IS_ERR(fout_epll)) { printk(KERN_ERR "%s: failed to get fout_epll\n", __func__); return PTR_ERR(fout_epll); } if (rate == clk_get_rate(fout_epll)) goto out; clk_set_rate(fout_epll, rate); out: clk_put(fout_epll); return 0; } #endif /* CONFIG_SND_SAMSUNG_PCM_USE_EPLL */ static int smdk_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; #ifdef CONFIG_SND_SAMSUNG_PCM_USE_EPLL unsigned long epll_out_rate; #endif /* CONFIG_SND_SAMSUNG_PCM_USE_EPLL */ int rfs, ret; #ifdef CONFIG_SND_SAMSUNG_PCM_USE_EPLL switch (params_rate(params)) { case 8000: case 12000: case 16000: case 24000: case 32000: case 48000: case 64000: case 96000: epll_out_rate = 49152000; break; case 11025: case 22050: case 44100: case 88200: epll_out_rate = 67737600; break; default: printk(KERN_ERR "%s:%d Sampling Rate %u not supported!\n", __func__, __LINE__, params_rate(params)); return -EINVAL; } #endif /* CONFIG_SND_SAMSUNG_PCM_USE_EPLL */ switch (params_rate(params)) { case 16000: case 22050: case 22025: case 32000: case 44100: case 48000: case 96000: case 24000: #ifdef CONFIG_SND_SAMSUNG_PCM_USE_EPLL rfs = 256; #else /* CONFIG_SND_SAMSUNG_PCM_USE_EPLL */ rfs = 384; #endif /* CONFIG_SND_SAMSUNG_PCM_USE_EPLL */ break; case 64000: rfs = 384; break; case 8000: case 11025: case 12000: rfs = 512; break; case 88200: rfs = 128; break; default: printk(KERN_ERR "%s:%d Sampling Rate %u not supported!\n", __func__, __LINE__, params_rate(params)); return -EINVAL; } /* Set the codec DAI configuration */ ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS); if (ret < 0) return ret; /* Set the cpu DAI configuration */ ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS); if (ret < 0) return ret; #ifdef CONFIG_SND_SAMSUNG_PCM_USE_EPLL /* * Samsung SoCs PCM has no MCLK(rclk) output support, so codec * should have to make its own MCLK with FLL(or PLL) from other * clock source. */ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1, params_rate(params)*rfs, SND_SOC_CLOCK_IN); if (ret < 0) return ret; ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1, SMDK_WM8994_FREQ, params_rate(params)*rfs); if (ret < 0) return ret; #endif /* CONFIG_SND_SAMSUNG_PCM_USE_EPLL */ ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, params_rate(params)*rfs, SND_SOC_CLOCK_IN); if (ret < 0) return ret; #ifdef CONFIG_SND_SAMSUNG_PCM_USE_EPLL /* Set EPLL clock rate */ ret = set_epll_rate(epll_out_rate); if (ret < 0) return ret; #endif /* CONFIG_SND_SAMSUNG_PCM_USE_EPLL */ /* Set SCLK_DIV for making bclk */ ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs); if (ret < 0) return ret; return 0; } /* * SMDK WM8994 DAI operations. */ static struct snd_soc_ops smdk_ops = { .hw_params = smdk_hw_params, }; static struct snd_soc_dai_link smdk_dai[] = { { /* Primary DAI i/f */ .name = "WM8994 AIF1", .stream_name = "PCM Tx/Rx", .cpu_dai_name = "samsung-pcm.0", .codec_dai_name = "wm8994-aif1", .platform_name = "samsung-audio", .codec_name = "wm8994-codec", .ops = &smdk_ops, }, }; static struct snd_soc_card smdk = { .name = "SMDK-PCM", .dai_link = smdk_dai, .num_links = ARRAY_SIZE(smdk_dai), }; static struct platform_device *smdk_snd_device; static int __init smdk_audio_init(void) { int ret; smdk_snd_device = platform_device_alloc("soc-audio", -1); if (!smdk_snd_device) return -ENOMEM; platform_set_drvdata(smdk_snd_device, &smdk); ret = platform_device_add(smdk_snd_device); if (ret) platform_device_put(smdk_snd_device); return ret; } module_init(smdk_audio_init); static void __exit smdk_audio_exit(void) { platform_device_unregister(smdk_snd_device); } module_exit(smdk_audio_exit); MODULE_DESCRIPTION("ALSA SoC SMDK WM8994"); MODULE_LICENSE("GPL");