blob: eef1f7b7b38e27c9ffcfb1b340df0f66d3173275 [file] [log] [blame]
Jonathan Camerona195b512009-05-04 14:54:11 +00001
2#include <linux/module.h>
3#include <sound/soc.h>
4
5#include <asm/mach-types.h>
6
7#include "../codecs/wm8940.h"
8#include "pxa2xx-i2s.h"
Jonathan Camerona195b512009-05-04 14:54:11 +00009
10static int imote2_asoc_hw_params(struct snd_pcm_substream *substream,
11 struct snd_pcm_hw_params *params)
12{
13 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000014 struct snd_soc_dai *codec_dai = rtd->codec_dai;
15 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Jonathan Camerona195b512009-05-04 14:54:11 +000016 unsigned int clk = 0;
17 int ret;
18
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;
31 }
32
Jonathan Camerona195b512009-05-04 14:54:11 +000033 ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk,
34 SND_SOC_CLOCK_IN);
35 if (ret < 0)
36 return ret;
37
38 /* set the I2S system clock as input (unused) */
39 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk,
40 SND_SOC_CLOCK_OUT);
41
42 return ret;
43}
44
45static struct snd_soc_ops imote2_asoc_ops = {
46 .hw_params = imote2_asoc_hw_params,
47};
48
49static struct snd_soc_dai_link imote2_dai = {
50 .name = "WM8940",
51 .stream_name = "WM8940",
Ian Larteya2a00862010-08-20 17:18:43 +010052 .cpu_dai_name = "pxa2xx-i2s",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000053 .codec_dai_name = "wm8940-hifi",
54 .platform_name = "pxa-pcm-audio",
55 .codec_name = "wm8940-codec.0-0034",
Axel Lin52ec35f2011-12-20 16:27:28 +080056 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
57 SND_SOC_DAIFMT_CBS_CFS,
Jonathan Camerona195b512009-05-04 14:54:11 +000058 .ops = &imote2_asoc_ops,
59};
60
Axel Linac1e8982011-12-15 10:55:24 +080061static struct snd_soc_card imote2 = {
Jonathan Camerona195b512009-05-04 14:54:11 +000062 .name = "Imote2",
Axel Lin561c6a12011-12-22 09:44:43 +080063 .owner = THIS_MODULE,
Jonathan Camerona195b512009-05-04 14:54:11 +000064 .dai_link = &imote2_dai,
65 .num_links = 1,
66};
67
Bill Pemberton570f6fe2012-12-07 09:26:17 -050068static int imote2_probe(struct platform_device *pdev)
Jonathan Camerona195b512009-05-04 14:54:11 +000069{
Axel Linac1e8982011-12-15 10:55:24 +080070 struct snd_soc_card *card = &imote2;
Jonathan Camerona195b512009-05-04 14:54:11 +000071 int ret;
72
Axel Linac1e8982011-12-15 10:55:24 +080073 card->dev = &pdev->dev;
Jonathan Camerona195b512009-05-04 14:54:11 +000074
Axel Linac1e8982011-12-15 10:55:24 +080075 ret = snd_soc_register_card(card);
Jonathan Camerona195b512009-05-04 14:54:11 +000076 if (ret)
Axel Linac1e8982011-12-15 10:55:24 +080077 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
78 ret);
Jonathan Camerona195b512009-05-04 14:54:11 +000079 return ret;
80}
Jonathan Camerona195b512009-05-04 14:54:11 +000081
Bill Pemberton570f6fe2012-12-07 09:26:17 -050082static int imote2_remove(struct platform_device *pdev)
Jonathan Camerona195b512009-05-04 14:54:11 +000083{
Axel Linac1e8982011-12-15 10:55:24 +080084 struct snd_soc_card *card = platform_get_drvdata(pdev);
85
86 snd_soc_unregister_card(card);
87 return 0;
Jonathan Camerona195b512009-05-04 14:54:11 +000088}
Axel Linac1e8982011-12-15 10:55:24 +080089
90static struct platform_driver imote2_driver = {
91 .driver = {
92 .name = "imote2-audio",
93 .owner = THIS_MODULE,
94 },
95 .probe = imote2_probe,
Bill Pemberton570f6fe2012-12-07 09:26:17 -050096 .remove = imote2_remove,
Axel Linac1e8982011-12-15 10:55:24 +080097};
98
99module_platform_driver(imote2_driver);
Jonathan Camerona195b512009-05-04 14:54:11 +0000100
101MODULE_AUTHOR("Jonathan Cameron");
102MODULE_DESCRIPTION("ALSA SoC Imote 2");
103MODULE_LICENSE("GPL");
Axel Linac1e8982011-12-15 10:55:24 +0800104MODULE_ALIAS("platform:imote2-audio");