Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 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> |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 16 | #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 Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 21 | #include "../codecs/wm8731.h" |
| 22 | #include "psc.h" |
| 23 | |
| 24 | /*------------------------- AC97 PART ---------------------------*/ |
| 25 | |
| 26 | static struct snd_soc_dai_link db1200_ac97_dai = { |
| 27 | .name = "AC97", |
| 28 | .stream_name = "AC97 HiFi", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 29 | .codec_dai_name = "ac97-hifi", |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 30 | .cpu_dai_name = "au1xpsc_ac97.1", |
| 31 | .platform_name = "au1xpsc-pcm.1", |
| 32 | .codec_name = "ac97-codec.1", |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | static struct snd_soc_card db1200_ac97_machine = { |
| 36 | .name = "DB1200_AC97", |
| 37 | .dai_link = &db1200_ac97_dai, |
| 38 | .num_links = 1, |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /*------------------------- I2S PART ---------------------------*/ |
| 42 | |
| 43 | static int db1200_i2s_startup(struct snd_pcm_substream *substream) |
| 44 | { |
| 45 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 46 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 47 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 48 | int ret; |
| 49 | |
| 50 | /* WM8731 has its own 12MHz crystal */ |
Mark Brown | 9745e82 | 2010-08-17 23:40:24 +0100 | [diff] [blame] | 51 | snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 52 | 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; |
| 66 | out: |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | static struct snd_soc_ops db1200_i2s_wm8731_ops = { |
| 71 | .startup = db1200_i2s_startup, |
| 72 | }; |
| 73 | |
| 74 | static struct snd_soc_dai_link db1200_i2s_dai = { |
| 75 | .name = "WM8731", |
| 76 | .stream_name = "WM8731 PCM", |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 77 | .codec_dai_name = "wm8731-hifi", |
| 78 | .cpu_dai_name = "au1xpsc_i2s.1", |
| 79 | .platform_name = "au1xpsc-pcm.1", |
Mark Brown | 99b59f3 | 2011-03-27 14:35:15 +0100 | [diff] [blame] | 80 | .codec_name = "wm8731.0-001b", |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 81 | .ops = &db1200_i2s_wm8731_ops, |
| 82 | }; |
| 83 | |
| 84 | static struct snd_soc_card db1200_i2s_machine = { |
| 85 | .name = "DB1200_I2S", |
| 86 | .dai_link = &db1200_i2s_dai, |
| 87 | .num_links = 1, |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /*------------------------- COMMON PART ---------------------------*/ |
| 91 | |
| 92 | static struct platform_device *db1200_asoc_dev; |
| 93 | |
| 94 | static int __init db1200_audio_load(void) |
| 95 | { |
| 96 | int ret; |
| 97 | |
| 98 | ret = -ENOMEM; |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 99 | db1200_asoc_dev = platform_device_alloc("soc-audio", 1); /* PSC1 */ |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 100 | 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 Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 105 | platform_set_drvdata(db1200_asoc_dev, &db1200_i2s_machine); |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 106 | else |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 107 | platform_set_drvdata(db1200_asoc_dev, &db1200_ac97_machine); |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 108 | |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 109 | ret = platform_device_add(db1200_asoc_dev); |
| 110 | |
| 111 | if (ret) { |
| 112 | platform_device_put(db1200_asoc_dev); |
| 113 | db1200_asoc_dev = NULL; |
| 114 | } |
| 115 | out: |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | static void __exit db1200_audio_unload(void) |
| 120 | { |
| 121 | platform_device_unregister(db1200_asoc_dev); |
| 122 | } |
| 123 | |
| 124 | module_init(db1200_audio_load); |
| 125 | module_exit(db1200_audio_unload); |
| 126 | |
| 127 | MODULE_LICENSE("GPL"); |
| 128 | MODULE_DESCRIPTION("DB1200 ASoC audio support"); |
| 129 | MODULE_AUTHOR("Manuel Lauss"); |