Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 1 | /* |
Manuel Lauss | f869d42 | 2011-11-10 12:06:16 +0000 | [diff] [blame^] | 2 | * DB1200/DB1300/DB1550 ASoC audio fabric support code. |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 3 | * |
Manuel Lauss | adbc7a5 | 2011-07-25 13:45:03 +0200 | [diff] [blame] | 4 | * (c) 2008-2011 Manuel Lauss <manuel.lauss@googlemail.com> |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 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 | |
Manuel Lauss | adbc7a5 | 2011-07-25 13:45:03 +0200 | [diff] [blame] | 24 | static struct platform_device_id db1200_pids[] = { |
| 25 | { |
| 26 | .name = "db1200-ac97", |
| 27 | .driver_data = 0, |
| 28 | }, { |
| 29 | .name = "db1200-i2s", |
| 30 | .driver_data = 1, |
Manuel Lauss | 64cd04d | 2011-11-10 12:03:26 +0000 | [diff] [blame] | 31 | }, { |
| 32 | .name = "db1300-ac97", |
| 33 | .driver_data = 2, |
| 34 | }, { |
| 35 | .name = "db1300-i2s", |
| 36 | .driver_data = 3, |
Manuel Lauss | f869d42 | 2011-11-10 12:06:16 +0000 | [diff] [blame^] | 37 | }, { |
| 38 | .name = "db1550-ac97", |
| 39 | .driver_data = 4, |
| 40 | }, { |
| 41 | .name = "db1550-i2s", |
| 42 | .driver_data = 5, |
Manuel Lauss | adbc7a5 | 2011-07-25 13:45:03 +0200 | [diff] [blame] | 43 | }, |
| 44 | {}, |
| 45 | }; |
| 46 | |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 47 | /*------------------------- AC97 PART ---------------------------*/ |
| 48 | |
| 49 | static struct snd_soc_dai_link db1200_ac97_dai = { |
| 50 | .name = "AC97", |
| 51 | .stream_name = "AC97 HiFi", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 52 | .codec_dai_name = "ac97-hifi", |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 53 | .cpu_dai_name = "au1xpsc_ac97.1", |
| 54 | .platform_name = "au1xpsc-pcm.1", |
| 55 | .codec_name = "ac97-codec.1", |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | static struct snd_soc_card db1200_ac97_machine = { |
| 59 | .name = "DB1200_AC97", |
| 60 | .dai_link = &db1200_ac97_dai, |
| 61 | .num_links = 1, |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Manuel Lauss | 64cd04d | 2011-11-10 12:03:26 +0000 | [diff] [blame] | 64 | static struct snd_soc_dai_link db1300_ac97_dai = { |
| 65 | .name = "AC97", |
| 66 | .stream_name = "AC97 HiFi", |
| 67 | .codec_dai_name = "wm9712-hifi", |
| 68 | .cpu_dai_name = "au1xpsc_ac97.1", |
| 69 | .platform_name = "au1xpsc-pcm.1", |
| 70 | .codec_name = "wm9712-codec.1", |
| 71 | }; |
| 72 | |
| 73 | static struct snd_soc_card db1300_ac97_machine = { |
| 74 | .name = "DB1300_AC97", |
| 75 | .dai_link = &db1300_ac97_dai, |
| 76 | .num_links = 1, |
| 77 | }; |
| 78 | |
Manuel Lauss | f869d42 | 2011-11-10 12:06:16 +0000 | [diff] [blame^] | 79 | static struct snd_soc_card db1550_ac97_machine = { |
| 80 | .name = "DB1550_AC97", |
| 81 | .dai_link = &db1200_ac97_dai, |
| 82 | .num_links = 1, |
| 83 | }; |
| 84 | |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 85 | /*------------------------- I2S PART ---------------------------*/ |
| 86 | |
| 87 | static int db1200_i2s_startup(struct snd_pcm_substream *substream) |
| 88 | { |
| 89 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 90 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 91 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 92 | int ret; |
| 93 | |
| 94 | /* WM8731 has its own 12MHz crystal */ |
Mark Brown | 9745e82 | 2010-08-17 23:40:24 +0100 | [diff] [blame] | 95 | snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 96 | 12000000, SND_SOC_CLOCK_IN); |
| 97 | |
| 98 | /* codec is bitclock and lrclk master */ |
| 99 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J | |
| 100 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM); |
| 101 | if (ret < 0) |
| 102 | goto out; |
| 103 | |
| 104 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_LEFT_J | |
| 105 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM); |
| 106 | if (ret < 0) |
| 107 | goto out; |
| 108 | |
| 109 | ret = 0; |
| 110 | out: |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | static struct snd_soc_ops db1200_i2s_wm8731_ops = { |
| 115 | .startup = db1200_i2s_startup, |
| 116 | }; |
| 117 | |
| 118 | static struct snd_soc_dai_link db1200_i2s_dai = { |
| 119 | .name = "WM8731", |
| 120 | .stream_name = "WM8731 PCM", |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 121 | .codec_dai_name = "wm8731-hifi", |
| 122 | .cpu_dai_name = "au1xpsc_i2s.1", |
| 123 | .platform_name = "au1xpsc-pcm.1", |
Mark Brown | 99b59f3 | 2011-03-27 14:35:15 +0100 | [diff] [blame] | 124 | .codec_name = "wm8731.0-001b", |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 125 | .ops = &db1200_i2s_wm8731_ops, |
| 126 | }; |
| 127 | |
| 128 | static struct snd_soc_card db1200_i2s_machine = { |
| 129 | .name = "DB1200_I2S", |
| 130 | .dai_link = &db1200_i2s_dai, |
| 131 | .num_links = 1, |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 132 | }; |
| 133 | |
Manuel Lauss | 64cd04d | 2011-11-10 12:03:26 +0000 | [diff] [blame] | 134 | static struct snd_soc_dai_link db1300_i2s_dai = { |
| 135 | .name = "WM8731", |
| 136 | .stream_name = "WM8731 PCM", |
| 137 | .codec_dai_name = "wm8731-hifi", |
| 138 | .cpu_dai_name = "au1xpsc_i2s.2", |
| 139 | .platform_name = "au1xpsc-pcm.2", |
| 140 | .codec_name = "wm8731.0-001b", |
| 141 | .ops = &db1200_i2s_wm8731_ops, |
| 142 | }; |
| 143 | |
| 144 | static struct snd_soc_card db1300_i2s_machine = { |
| 145 | .name = "DB1300_I2S", |
| 146 | .dai_link = &db1300_i2s_dai, |
| 147 | .num_links = 1, |
| 148 | }; |
| 149 | |
Manuel Lauss | f869d42 | 2011-11-10 12:06:16 +0000 | [diff] [blame^] | 150 | static struct snd_soc_dai_link db1550_i2s_dai = { |
| 151 | .name = "WM8731", |
| 152 | .stream_name = "WM8731 PCM", |
| 153 | .codec_dai_name = "wm8731-hifi", |
| 154 | .cpu_dai_name = "au1xpsc_i2s.3", |
| 155 | .platform_name = "au1xpsc-pcm.3", |
| 156 | .codec_name = "wm8731.0-001b", |
| 157 | .ops = &db1200_i2s_wm8731_ops, |
| 158 | }; |
| 159 | |
| 160 | static struct snd_soc_card db1550_i2s_machine = { |
| 161 | .name = "DB1550_I2S", |
| 162 | .dai_link = &db1550_i2s_dai, |
| 163 | .num_links = 1, |
| 164 | }; |
| 165 | |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 166 | /*------------------------- COMMON PART ---------------------------*/ |
| 167 | |
Manuel Lauss | adbc7a5 | 2011-07-25 13:45:03 +0200 | [diff] [blame] | 168 | static struct snd_soc_card *db1200_cards[] __devinitdata = { |
| 169 | &db1200_ac97_machine, |
| 170 | &db1200_i2s_machine, |
Manuel Lauss | 64cd04d | 2011-11-10 12:03:26 +0000 | [diff] [blame] | 171 | &db1300_ac97_machine, |
| 172 | &db1300_i2s_machine, |
Manuel Lauss | f869d42 | 2011-11-10 12:06:16 +0000 | [diff] [blame^] | 173 | &db1550_ac97_machine, |
| 174 | &db1550_i2s_machine, |
Manuel Lauss | adbc7a5 | 2011-07-25 13:45:03 +0200 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | static int __devinit db1200_audio_probe(struct platform_device *pdev) |
| 178 | { |
| 179 | const struct platform_device_id *pid = platform_get_device_id(pdev); |
| 180 | struct snd_soc_card *card; |
| 181 | |
| 182 | card = db1200_cards[pid->driver_data]; |
| 183 | card->dev = &pdev->dev; |
| 184 | return snd_soc_register_card(card); |
| 185 | } |
| 186 | |
| 187 | static int __devexit db1200_audio_remove(struct platform_device *pdev) |
| 188 | { |
| 189 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 190 | snd_soc_unregister_card(card); |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static struct platform_driver db1200_audio_driver = { |
| 195 | .driver = { |
| 196 | .name = "db1200-ac97", |
| 197 | .owner = THIS_MODULE, |
| 198 | .pm = &snd_soc_pm_ops, |
| 199 | }, |
| 200 | .id_table = db1200_pids, |
| 201 | .probe = db1200_audio_probe, |
| 202 | .remove = __devexit_p(db1200_audio_remove), |
| 203 | }; |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 204 | |
| 205 | static int __init db1200_audio_load(void) |
| 206 | { |
Manuel Lauss | adbc7a5 | 2011-07-25 13:45:03 +0200 | [diff] [blame] | 207 | return platform_driver_register(&db1200_audio_driver); |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void __exit db1200_audio_unload(void) |
| 211 | { |
Manuel Lauss | adbc7a5 | 2011-07-25 13:45:03 +0200 | [diff] [blame] | 212 | platform_driver_unregister(&db1200_audio_driver); |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | module_init(db1200_audio_load); |
| 216 | module_exit(db1200_audio_unload); |
| 217 | |
| 218 | MODULE_LICENSE("GPL"); |
Manuel Lauss | f869d42 | 2011-11-10 12:06:16 +0000 | [diff] [blame^] | 219 | MODULE_DESCRIPTION("DB1200/DB1300/DB1550 ASoC audio support"); |
Manuel Lauss | 05ae323 | 2009-11-02 21:21:44 +0100 | [diff] [blame] | 220 | MODULE_AUTHOR("Manuel Lauss"); |