blob: b62fcd33e586f812b9c556002bdec1b44ee774aa [file] [log] [blame]
Manuel Lauss05ae3232009-11-02 21:21:44 +01001/*
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
Manuel Lauss05ae3232009-11-02 21:21:44 +010022#include "../codecs/wm8731.h"
23#include "psc.h"
24
25/*------------------------- AC97 PART ---------------------------*/
26
27static struct snd_soc_dai_link db1200_ac97_dai = {
28 .name = "AC97",
29 .stream_name = "AC97 HiFi",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000030 .codec_dai_name = "ac97-hifi",
Manuel Laussffc4fdb2010-08-26 14:53:51 +020031 .cpu_dai_name = "au1xpsc_ac97.1",
32 .platform_name = "au1xpsc-pcm.1",
33 .codec_name = "ac97-codec.1",
Manuel Lauss05ae3232009-11-02 21:21:44 +010034};
35
36static struct snd_soc_card db1200_ac97_machine = {
37 .name = "DB1200_AC97",
38 .dai_link = &db1200_ac97_dai,
39 .num_links = 1,
Manuel Lauss05ae3232009-11-02 21:21:44 +010040};
41
42/*------------------------- I2S PART ---------------------------*/
43
44static int db1200_i2s_startup(struct snd_pcm_substream *substream)
45{
46 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000047 struct snd_soc_dai *codec_dai = rtd->codec_dai;
48 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Manuel Lauss05ae3232009-11-02 21:21:44 +010049 int ret;
50
51 /* WM8731 has its own 12MHz crystal */
Mark Brown9745e822010-08-17 23:40:24 +010052 snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
Manuel Lauss05ae3232009-11-02 21:21:44 +010053 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;
67out:
68 return ret;
69}
70
71static struct snd_soc_ops db1200_i2s_wm8731_ops = {
72 .startup = db1200_i2s_startup,
73};
74
75static struct snd_soc_dai_link db1200_i2s_dai = {
76 .name = "WM8731",
77 .stream_name = "WM8731 PCM",
Manuel Laussffc4fdb2010-08-26 14:53:51 +020078 .codec_dai_name = "wm8731-hifi",
79 .cpu_dai_name = "au1xpsc_i2s.1",
80 .platform_name = "au1xpsc-pcm.1",
81 .codec_name = "wm8731-codec.0-001b",
Manuel Lauss05ae3232009-11-02 21:21:44 +010082 .ops = &db1200_i2s_wm8731_ops,
83};
84
85static struct snd_soc_card db1200_i2s_machine = {
86 .name = "DB1200_I2S",
87 .dai_link = &db1200_i2s_dai,
88 .num_links = 1,
Manuel Lauss05ae3232009-11-02 21:21:44 +010089};
90
91/*------------------------- COMMON PART ---------------------------*/
92
93static struct platform_device *db1200_asoc_dev;
94
95static int __init db1200_audio_load(void)
96{
97 int ret;
98
99 ret = -ENOMEM;
Manuel Laussffc4fdb2010-08-26 14:53:51 +0200100 db1200_asoc_dev = platform_device_alloc("soc-audio", 1); /* PSC1 */
Manuel Lauss05ae3232009-11-02 21:21:44 +0100101 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)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000106 platform_set_drvdata(db1200_asoc_dev, &db1200_i2s_machine);
Manuel Lauss05ae3232009-11-02 21:21:44 +0100107 else
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000108 platform_set_drvdata(db1200_asoc_dev, &db1200_ac97_machine);
Manuel Lauss05ae3232009-11-02 21:21:44 +0100109
Manuel Lauss05ae3232009-11-02 21:21:44 +0100110 ret = platform_device_add(db1200_asoc_dev);
111
112 if (ret) {
113 platform_device_put(db1200_asoc_dev);
114 db1200_asoc_dev = NULL;
115 }
116out:
117 return ret;
118}
119
120static void __exit db1200_audio_unload(void)
121{
122 platform_device_unregister(db1200_asoc_dev);
123}
124
125module_init(db1200_audio_load);
126module_exit(db1200_audio_unload);
127
128MODULE_LICENSE("GPL");
129MODULE_DESCRIPTION("DB1200 ASoC audio support");
130MODULE_AUTHOR("Manuel Lauss");