Add linux-next specific files for 20110421
[linux-2.6/next.git] / sound / soc / pxa / imote2.c
blob154fc6f234389e74d4354770b6057074377f6be2
2 #include <linux/module.h>
3 #include <sound/soc.h>
5 #include <asm/mach-types.h>
7 #include "../codecs/wm8940.h"
8 #include "pxa2xx-i2s.h"
10 static int imote2_asoc_hw_params(struct snd_pcm_substream *substream,
11 struct snd_pcm_hw_params *params)
13 struct snd_soc_pcm_runtime *rtd = substream->private_data;
14 struct snd_soc_dai *codec_dai = rtd->codec_dai;
15 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
16 unsigned int clk = 0;
17 int ret;
19 switch (params_rate(params)) {
20 case 8000:
21 case 16000:
22 case 48000:
23 case 96000:
24 clk = 12288000;
25 break;
26 case 11025:
27 case 22050:
28 case 44100:
29 clk = 11289600;
30 break;
33 /* set codec DAI configuration */
34 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
35 | SND_SOC_DAIFMT_NB_NF
36 | SND_SOC_DAIFMT_CBS_CFS);
37 if (ret < 0)
38 return ret;
40 /* CPU should be clock master */
41 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
42 | SND_SOC_DAIFMT_NB_NF
43 | SND_SOC_DAIFMT_CBS_CFS);
44 if (ret < 0)
45 return ret;
47 ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk,
48 SND_SOC_CLOCK_IN);
49 if (ret < 0)
50 return ret;
52 /* set the I2S system clock as input (unused) */
53 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk,
54 SND_SOC_CLOCK_OUT);
56 return ret;
59 static struct snd_soc_ops imote2_asoc_ops = {
60 .hw_params = imote2_asoc_hw_params,
63 static struct snd_soc_dai_link imote2_dai = {
64 .name = "WM8940",
65 .stream_name = "WM8940",
66 .cpu_dai_name = "pxa2xx-i2s",
67 .codec_dai_name = "wm8940-hifi",
68 .platform_name = "pxa-pcm-audio",
69 .codec_name = "wm8940-codec.0-0034",
70 .ops = &imote2_asoc_ops,
73 static struct snd_soc_card snd_soc_imote2 = {
74 .name = "Imote2",
75 .dai_link = &imote2_dai,
76 .num_links = 1,
79 static struct platform_device *imote2_snd_device;
81 static int __init imote2_asoc_init(void)
83 int ret;
85 if (!machine_is_intelmote2())
86 return -ENODEV;
87 imote2_snd_device = platform_device_alloc("soc-audio", -1);
88 if (!imote2_snd_device)
89 return -ENOMEM;
91 platform_set_drvdata(imote2_snd_device, &snd_soc_imote2);
92 ret = platform_device_add(imote2_snd_device);
93 if (ret)
94 platform_device_put(imote2_snd_device);
96 return ret;
98 module_init(imote2_asoc_init);
100 static void __exit imote2_asoc_exit(void)
102 platform_device_unregister(imote2_snd_device);
104 module_exit(imote2_asoc_exit);
106 MODULE_AUTHOR("Jonathan Cameron");
107 MODULE_DESCRIPTION("ALSA SoC Imote 2");
108 MODULE_LICENSE("GPL");