ASoC: Support non-crystal master clocks for WM8731
[linux-2.6.git] / sound / soc / au1x / db1200.c
1 /*
2  * DB1200 ASoC audio fabric support code.
3  *
4  * (c) 2008-9 Manuel Lauss <manuel.lauss@gmail.com>
5  *
6  */
7
8 #include <linux/module.h>
9 #include <linux/moduleparam.h>
10 #include <linux/timer.h>
11 #include <linux/interrupt.h>
12 #include <linux/platform_device.h>
13 #include <sound/core.h>
14 #include <sound/pcm.h>
15 #include <sound/soc.h>
16 #include <sound/soc-dapm.h>
17 #include <asm/mach-au1x00/au1000.h>
18 #include <asm/mach-au1x00/au1xxx_psc.h>
19 #include <asm/mach-au1x00/au1xxx_dbdma.h>
20 #include <asm/mach-db1x00/bcsr.h>
21
22 #include "../codecs/wm8731.h"
23 #include "psc.h"
24
25 /*-------------------------  AC97 PART  ---------------------------*/
26
27 static struct snd_soc_dai_link db1200_ac97_dai = {
28         .name           = "AC97",
29         .stream_name    = "AC97 HiFi",
30         .cpu_dai_name   = "au1xpsc-ac97",
31         .codec_dai_name = "ac97-hifi",
32         .platform_name  =  "au1xpsc-pcm-audio",
33         .codec_name     = "ac97-codec",
34 };
35
36 static struct snd_soc_card db1200_ac97_machine = {
37         .name           = "DB1200_AC97",
38         .dai_link       = &db1200_ac97_dai,
39         .num_links      = 1,
40 };
41
42 /*-------------------------  I2S PART  ---------------------------*/
43
44 static int db1200_i2s_startup(struct snd_pcm_substream *substream)
45 {
46         struct snd_soc_pcm_runtime *rtd = substream->private_data;
47         struct snd_soc_dai *codec_dai = rtd->codec_dai;
48         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
49         int ret;
50
51         /* WM8731 has its own 12MHz crystal */
52         snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
53                                 12000000, SND_SOC_CLOCK_IN);
54
55         /* codec is bitclock and lrclk master */
56         ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
57                         SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
58         if (ret < 0)
59                 goto out;
60
61         ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_LEFT_J |
62                         SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
63         if (ret < 0)
64                 goto out;
65
66         ret = 0;
67 out:
68         return ret;
69 }
70
71 static struct snd_soc_ops db1200_i2s_wm8731_ops = {
72         .startup        = db1200_i2s_startup,
73 };
74
75 static struct snd_soc_dai_link db1200_i2s_dai = {
76         .name           = "WM8731",
77         .stream_name    = "WM8731 PCM",
78         .cpu_dai_name   = "au1xpsc",
79         .codec_dai_name = "wm8731-hifi"
80         .platform_name  = "au1xpsc-pcm-audio",
81         .codec_name     = "wm8731-codec.0-001a",
82         .ops            = &db1200_i2s_wm8731_ops,
83 };
84
85 static struct snd_soc_card db1200_i2s_machine = {
86         .name           = "DB1200_I2S",
87         .dai_link       = &db1200_i2s_dai,
88         .num_links      = 1,
89 };
90
91 /*-------------------------  COMMON PART  ---------------------------*/
92
93 static struct platform_device *db1200_asoc_dev;
94
95 static int __init db1200_audio_load(void)
96 {
97         int ret;
98
99         ret = -ENOMEM;
100         db1200_asoc_dev = platform_device_alloc("soc-audio", -1);
101         if (!db1200_asoc_dev)
102                 goto out;
103
104         /* DB1200 board setup set PSC1MUX to preferred audio device */
105         if (bcsr_read(BCSR_RESETS) & BCSR_RESETS_PSC1MUX)
106                 platform_set_drvdata(db1200_asoc_dev, &db1200_i2s_machine);
107         else
108                 platform_set_drvdata(db1200_asoc_dev, &db1200_ac97_machine);
109
110         ret = platform_device_add(db1200_asoc_dev);
111
112         if (ret) {
113                 platform_device_put(db1200_asoc_dev);
114                 db1200_asoc_dev = NULL;
115         }
116 out:
117         return ret;
118 }
119
120 static void __exit db1200_audio_unload(void)
121 {
122         platform_device_unregister(db1200_asoc_dev);
123 }
124
125 module_init(db1200_audio_load);
126 module_exit(db1200_audio_unload);
127
128 MODULE_LICENSE("GPL");
129 MODULE_DESCRIPTION("DB1200 ASoC audio support");
130 MODULE_AUTHOR("Manuel Lauss");