blob: cb99f04abe88aaed8d42dc90e264c0137a5276a0 [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>
Manuel Lauss05ae3232009-11-02 21:21:44 +010016#include <asm/mach-au1x00/au1000.h>
17#include <asm/mach-au1x00/au1xxx_psc.h>
18#include <asm/mach-au1x00/au1xxx_dbdma.h>
19#include <asm/mach-db1x00/bcsr.h>
20
Manuel Lauss05ae3232009-11-02 21:21:44 +010021#include "../codecs/wm8731.h"
22#include "psc.h"
23
24/*------------------------- AC97 PART ---------------------------*/
25
26static struct snd_soc_dai_link db1200_ac97_dai = {
27 .name = "AC97",
28 .stream_name = "AC97 HiFi",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000029 .codec_dai_name = "ac97-hifi",
Manuel Laussffc4fdb2010-08-26 14:53:51 +020030 .cpu_dai_name = "au1xpsc_ac97.1",
31 .platform_name = "au1xpsc-pcm.1",
32 .codec_name = "ac97-codec.1",
Manuel Lauss05ae3232009-11-02 21:21:44 +010033};
34
35static struct snd_soc_card db1200_ac97_machine = {
36 .name = "DB1200_AC97",
37 .dai_link = &db1200_ac97_dai,
38 .num_links = 1,
Manuel Lauss05ae3232009-11-02 21:21:44 +010039};
40
41/*------------------------- I2S PART ---------------------------*/
42
43static int db1200_i2s_startup(struct snd_pcm_substream *substream)
44{
45 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000046 struct snd_soc_dai *codec_dai = rtd->codec_dai;
47 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Manuel Lauss05ae3232009-11-02 21:21:44 +010048 int ret;
49
50 /* WM8731 has its own 12MHz crystal */
Mark Brown9745e822010-08-17 23:40:24 +010051 snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
Manuel Lauss05ae3232009-11-02 21:21:44 +010052 12000000, SND_SOC_CLOCK_IN);
53
54 /* codec is bitclock and lrclk master */
55 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
56 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
57 if (ret < 0)
58 goto out;
59
60 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_LEFT_J |
61 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
62 if (ret < 0)
63 goto out;
64
65 ret = 0;
66out:
67 return ret;
68}
69
70static struct snd_soc_ops db1200_i2s_wm8731_ops = {
71 .startup = db1200_i2s_startup,
72};
73
74static struct snd_soc_dai_link db1200_i2s_dai = {
75 .name = "WM8731",
76 .stream_name = "WM8731 PCM",
Manuel Laussffc4fdb2010-08-26 14:53:51 +020077 .codec_dai_name = "wm8731-hifi",
78 .cpu_dai_name = "au1xpsc_i2s.1",
79 .platform_name = "au1xpsc-pcm.1",
80 .codec_name = "wm8731-codec.0-001b",
Manuel Lauss05ae3232009-11-02 21:21:44 +010081 .ops = &db1200_i2s_wm8731_ops,
82};
83
84static struct snd_soc_card db1200_i2s_machine = {
85 .name = "DB1200_I2S",
86 .dai_link = &db1200_i2s_dai,
87 .num_links = 1,
Manuel Lauss05ae3232009-11-02 21:21:44 +010088};
89
90/*------------------------- COMMON PART ---------------------------*/
91
92static struct platform_device *db1200_asoc_dev;
93
94static int __init db1200_audio_load(void)
95{
96 int ret;
97
98 ret = -ENOMEM;
Manuel Laussffc4fdb2010-08-26 14:53:51 +020099 db1200_asoc_dev = platform_device_alloc("soc-audio", 1); /* PSC1 */
Manuel Lauss05ae3232009-11-02 21:21:44 +0100100 if (!db1200_asoc_dev)
101 goto out;
102
103 /* DB1200 board setup set PSC1MUX to preferred audio device */
104 if (bcsr_read(BCSR_RESETS) & BCSR_RESETS_PSC1MUX)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000105 platform_set_drvdata(db1200_asoc_dev, &db1200_i2s_machine);
Manuel Lauss05ae3232009-11-02 21:21:44 +0100106 else
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000107 platform_set_drvdata(db1200_asoc_dev, &db1200_ac97_machine);
Manuel Lauss05ae3232009-11-02 21:21:44 +0100108
Manuel Lauss05ae3232009-11-02 21:21:44 +0100109 ret = platform_device_add(db1200_asoc_dev);
110
111 if (ret) {
112 platform_device_put(db1200_asoc_dev);
113 db1200_asoc_dev = NULL;
114 }
115out:
116 return ret;
117}
118
119static void __exit db1200_audio_unload(void)
120{
121 platform_device_unregister(db1200_asoc_dev);
122}
123
124module_init(db1200_audio_load);
125module_exit(db1200_audio_unload);
126
127MODULE_LICENSE("GPL");
128MODULE_DESCRIPTION("DB1200 ASoC audio support");
129MODULE_AUTHOR("Manuel Lauss");