1 /* 2 * sound/soc/samsung/smdk_wm8994pcm.c 3 * 4 * Copyright (c) 2011 Samsung Electronics Co., Ltd 5 * http://www.samsung.com 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the 9 * Free Software Foundation; either version 2 of the License, or (at your 10 * option) any later version. 11 */ 12 #include <linux/module.h> 13 #include <sound/soc.h> 14 #include <sound/pcm.h> 15 #include <sound/pcm_params.h> 16 17 #include "../codecs/wm8994.h" 18 #include "dma.h" 19 #include "pcm.h" 20 21 /* 22 * Board Settings: 23 * o '1' means 'ON' 24 * o '0' means 'OFF' 25 * o 'X' means 'Don't care' 26 * 27 * SMDKC210, SMDKV310: CFG3- 1001, CFG5-1000, CFG7-111111 28 */ 29 30 /* 31 * Configure audio route as :- 32 * $ amixer sset 'DAC1' on,on 33 * $ amixer sset 'Right Headphone Mux' 'DAC' 34 * $ amixer sset 'Left Headphone Mux' 'DAC' 35 * $ amixer sset 'DAC1R Mixer AIF1.1' on 36 * $ amixer sset 'DAC1L Mixer AIF1.1' on 37 * $ amixer sset 'IN2L' on 38 * $ amixer sset 'IN2L PGA IN2LN' on 39 * $ amixer sset 'MIXINL IN2L' on 40 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on 41 * $ amixer sset 'IN2R' on 42 * $ amixer sset 'IN2R PGA IN2RN' on 43 * $ amixer sset 'MIXINR IN2R' on 44 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on 45 */ 46 47 /* SMDK has a 16.9344MHZ crystal attached to WM8994 */ 48 #define SMDK_WM8994_FREQ 16934400 49 50 static int smdk_wm8994_pcm_hw_params(struct snd_pcm_substream *substream, 51 struct snd_pcm_hw_params *params) 52 { 53 struct snd_soc_pcm_runtime *rtd = substream->private_data; 54 struct snd_soc_dai *codec_dai = rtd->codec_dai; 55 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 56 unsigned long mclk_freq; 57 int rfs, ret; 58 59 switch(params_rate(params)) { 60 case 8000: 61 rfs = 512; 62 break; 63 default: 64 dev_err(cpu_dai->dev, "%s:%d Sampling Rate %u not supported!\n", 65 __func__, __LINE__, params_rate(params)); 66 return -EINVAL; 67 } 68 69 mclk_freq = params_rate(params) * rfs; 70 71 /* Set the codec DAI configuration */ 72 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B 73 | SND_SOC_DAIFMT_IB_NF 74 | SND_SOC_DAIFMT_CBS_CFS); 75 if (ret < 0) 76 return ret; 77 78 /* Set the cpu DAI configuration */ 79 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_B 80 | SND_SOC_DAIFMT_IB_NF 81 | SND_SOC_DAIFMT_CBS_CFS); 82 if (ret < 0) 83 return ret; 84 85 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1, 86 mclk_freq, SND_SOC_CLOCK_IN); 87 if (ret < 0) 88 return ret; 89 90 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1, 91 SMDK_WM8994_FREQ, mclk_freq); 92 if (ret < 0) 93 return ret; 94 95 /* Set PCM source clock on CPU */ 96 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C_PCM_CLKSRC_MUX, 97 mclk_freq, SND_SOC_CLOCK_IN); 98 if (ret < 0) 99 return ret; 100 101 /* Set SCLK_DIV for making bclk */ 102 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_PCM_SCLK_PER_FS, rfs); 103 if (ret < 0) 104 return ret; 105 106 return 0; 107 } 108 109 static struct snd_soc_ops smdk_wm8994_pcm_ops = { 110 .hw_params = smdk_wm8994_pcm_hw_params, 111 }; 112 113 static struct snd_soc_dai_link smdk_dai[] = { 114 { 115 .name = "WM8994 PAIF PCM", 116 .stream_name = "Primary PCM", 117 .cpu_dai_name = "samsung-pcm.0", 118 .codec_dai_name = "wm8994-aif1", 119 .platform_name = "samsung-pcm.0", 120 .codec_name = "wm8994-codec", 121 .ops = &smdk_wm8994_pcm_ops, 122 }, 123 }; 124 125 static struct snd_soc_card smdk_pcm = { 126 .name = "SMDK-PCM", 127 .owner = THIS_MODULE, 128 .dai_link = smdk_dai, 129 .num_links = 1, 130 }; 131 132 static int snd_smdk_probe(struct platform_device *pdev) 133 { 134 int ret = 0; 135 136 smdk_pcm.dev = &pdev->dev; 137 ret = snd_soc_register_card(&smdk_pcm); 138 if (ret) { 139 dev_err(&pdev->dev, "snd_soc_register_card failed %d\n", ret); 140 return ret; 141 } 142 143 return 0; 144 } 145 146 static int snd_smdk_remove(struct platform_device *pdev) 147 { 148 snd_soc_unregister_card(&smdk_pcm); 149 platform_set_drvdata(pdev, NULL); 150 return 0; 151 } 152 153 static struct platform_driver snd_smdk_driver = { 154 .driver = { 155 .owner = THIS_MODULE, 156 .name = "samsung-smdk-pcm", 157 }, 158 .probe = snd_smdk_probe, 159 .remove = snd_smdk_remove, 160 }; 161 162 module_platform_driver(snd_smdk_driver); 163 164 MODULE_AUTHOR("Sangbeom Kim, <sbkim73@samsung.com>"); 165 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994 for PCM"); 166 MODULE_LICENSE("GPL"); 167