diff options
author | Ben Dooks <ben@simtec.co.uk> | 2009-03-03 19:49:27 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-03-06 08:37:07 -0500 |
commit | 3093e48c48b69ccc06a1f78ffe7ece7ee2ee09ef (patch) | |
tree | 653bcbbb6781b7727752cb374e8ea1298294acad /sound/soc/s3c24xx/jive_wm8750.c | |
parent | 979c036e090332cd3a090ce8b4eb50c3aa28dea0 (diff) |
ASoC: Add JIVE audio support
Add support for the Jive's WM8750 codec attached via the S3C2412 IIS.
Signed-off-by: Ben Dooks <ben@simtec.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/s3c24xx/jive_wm8750.c')
-rw-r--r-- | sound/soc/s3c24xx/jive_wm8750.c | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/sound/soc/s3c24xx/jive_wm8750.c b/sound/soc/s3c24xx/jive_wm8750.c new file mode 100644 index 000000000000..fe466c1f71ec --- /dev/null +++ b/sound/soc/s3c24xx/jive_wm8750.c | |||
@@ -0,0 +1,216 @@ | |||
1 | /* sound/soc/s3c24xx/jive_wm8750.c | ||
2 | * | ||
3 | * Copyright 2007,2008 Simtec Electronics | ||
4 | * | ||
5 | * Based on sound/soc/pxa/spitz.c | ||
6 | * Copyright 2005 Wolfson Microelectronics PLC. | ||
7 | * Copyright 2005 Openedhand Ltd. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | */ | ||
13 | |||
14 | #include <linux/module.h> | ||
15 | #include <linux/moduleparam.h> | ||
16 | #include <linux/timer.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/clk.h> | ||
20 | |||
21 | #include <sound/core.h> | ||
22 | #include <sound/pcm.h> | ||
23 | #include <sound/soc.h> | ||
24 | #include <sound/soc-dapm.h> | ||
25 | |||
26 | #include <asm/mach-types.h> | ||
27 | |||
28 | #include "s3c24xx-pcm.h" | ||
29 | #include "s3c2412-i2s.h" | ||
30 | |||
31 | #include "../codecs/wm8750.h" | ||
32 | |||
33 | static const struct snd_soc_dapm_route audio_map[] = { | ||
34 | { "Headphone Jack", NULL, "LOUT1" }, | ||
35 | { "Headphone Jack", NULL, "ROUT1" }, | ||
36 | { "Internal Speaker", NULL, "LOUT2" }, | ||
37 | { "Internal Speaker", NULL, "ROUT2" }, | ||
38 | { "LINPUT1", NULL, "Line Input" }, | ||
39 | { "RINPUT1", NULL, "Line Input" }, | ||
40 | }; | ||
41 | |||
42 | static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = { | ||
43 | SND_SOC_DAPM_HP("Headphone Jack", NULL), | ||
44 | SND_SOC_DAPM_SPK("Internal Speaker", NULL), | ||
45 | SND_SOC_DAPM_LINE("Line In", NULL), | ||
46 | }; | ||
47 | |||
48 | static int jive_startup(struct snd_pcm_substream *substream) | ||
49 | { | ||
50 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
51 | struct snd_soc_codec *codec = rtd->socdev->codec; | ||
52 | |||
53 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); | ||
54 | snd_soc_dapm_enable_pin(codec, "Internal Speaker"); | ||
55 | snd_soc_dapm_enable_pin(codec, "Line In"); | ||
56 | |||
57 | snd_soc_dapm_sync(codec); | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int jive_hw_params(struct snd_pcm_substream *substream, | ||
63 | struct snd_pcm_hw_params *params) | ||
64 | { | ||
65 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
66 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | ||
67 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | ||
68 | struct s3c2412_rate_calc div; | ||
69 | unsigned int clk = 0; | ||
70 | int ret = 0; | ||
71 | |||
72 | switch (params_rate(params)) { | ||
73 | case 8000: | ||
74 | case 16000: | ||
75 | case 48000: | ||
76 | case 96000: | ||
77 | clk = 12288000; | ||
78 | break; | ||
79 | case 11025: | ||
80 | case 22050: | ||
81 | case 44100: | ||
82 | clk = 11289600; | ||
83 | break; | ||
84 | } | ||
85 | |||
86 | s3c2412_iis_calc_rate(&div, NULL, params_rate(params), | ||
87 | s3c2412_get_iisclk()); | ||
88 | |||
89 | /* set codec DAI configuration */ | ||
90 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | | ||
91 | SND_SOC_DAIFMT_NB_NF | | ||
92 | SND_SOC_DAIFMT_CBS_CFS); | ||
93 | if (ret < 0) | ||
94 | return ret; | ||
95 | |||
96 | /* set cpu DAI configuration */ | ||
97 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | | ||
98 | SND_SOC_DAIFMT_NB_NF | | ||
99 | SND_SOC_DAIFMT_CBS_CFS); | ||
100 | if (ret < 0) | ||
101 | return ret; | ||
102 | |||
103 | /* set the codec system clock for DAC and ADC */ | ||
104 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, | ||
105 | SND_SOC_CLOCK_IN); | ||
106 | if (ret < 0) | ||
107 | return ret; | ||
108 | |||
109 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div); | ||
110 | if (ret < 0) | ||
111 | return ret; | ||
112 | |||
113 | ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER, | ||
114 | div.clk_div - 1); | ||
115 | if (ret < 0) | ||
116 | return ret; | ||
117 | |||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | static struct snd_soc_ops jive_ops = { | ||
122 | .startup = jive_startup, | ||
123 | .hw_params = jive_hw_params, | ||
124 | }; | ||
125 | |||
126 | static int jive_wm8750_init(struct snd_soc_codec *codec) | ||
127 | { | ||
128 | int err; | ||
129 | |||
130 | /* These endpoints are not being used. */ | ||
131 | snd_soc_dapm_disable_pin(codec, "LINPUT2"); | ||
132 | snd_soc_dapm_disable_pin(codec, "RINPUT2"); | ||
133 | snd_soc_dapm_disable_pin(codec, "LINPUT3"); | ||
134 | snd_soc_dapm_disable_pin(codec, "RINPUT3"); | ||
135 | snd_soc_dapm_disable_pin(codec, "OUT3"); | ||
136 | snd_soc_dapm_disable_pin(codec, "MONO"); | ||
137 | |||
138 | /* Add jive specific widgets */ | ||
139 | err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets, | ||
140 | ARRAY_SIZE(wm8750_dapm_widgets)); | ||
141 | if (err) { | ||
142 | printk(KERN_ERR "%s: failed to add widgets (%d)\n", | ||
143 | __func__, err); | ||
144 | return err; | ||
145 | } | ||
146 | |||
147 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); | ||
148 | snd_soc_dapm_sync(codec); | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static struct snd_soc_dai_link jive_dai = { | ||
154 | .name = "wm8750", | ||
155 | .stream_name = "WM8750", | ||
156 | .cpu_dai = &s3c2412_i2s_dai, | ||
157 | .codec_dai = &wm8750_dai, | ||
158 | .init = jive_wm8750_init, | ||
159 | .ops = &jive_ops, | ||
160 | }; | ||
161 | |||
162 | /* jive audio machine driver */ | ||
163 | static struct snd_soc_machine snd_soc_machine_jive = { | ||
164 | .name = "Jive", | ||
165 | .dai_link = &jive_dai, | ||
166 | .num_links = 1, | ||
167 | }; | ||
168 | |||
169 | /* jive audio private data */ | ||
170 | static struct wm8750_setup_data jive_wm8750_setup = { | ||
171 | }; | ||
172 | |||
173 | /* jive audio subsystem */ | ||
174 | static struct snd_soc_device jive_snd_devdata = { | ||
175 | .machine = &snd_soc_machine_jive, | ||
176 | .platform = &s3c24xx_soc_platform, | ||
177 | .codec_dev = &soc_codec_dev_wm8750_spi, | ||
178 | .codec_data = &jive_wm8750_setup, | ||
179 | }; | ||
180 | |||
181 | static struct platform_device *jive_snd_device; | ||
182 | |||
183 | static int __init jive_init(void) | ||
184 | { | ||
185 | int ret; | ||
186 | |||
187 | if (!machine_is_jive()) | ||
188 | return 0; | ||
189 | |||
190 | printk("JIVE WM8750 Audio support\n"); | ||
191 | |||
192 | jive_snd_device = platform_device_alloc("soc-audio", -1); | ||
193 | if (!jive_snd_device) | ||
194 | return -ENOMEM; | ||
195 | |||
196 | platform_set_drvdata(jive_snd_device, &jive_snd_devdata); | ||
197 | jive_snd_devdata.dev = &jive_snd_device->dev; | ||
198 | ret = platform_device_add(jive_snd_device); | ||
199 | |||
200 | if (ret) | ||
201 | platform_device_put(jive_snd_device); | ||
202 | |||
203 | return ret; | ||
204 | } | ||
205 | |||
206 | static void __exit jive_exit(void) | ||
207 | { | ||
208 | platform_device_unregister(jive_snd_device); | ||
209 | } | ||
210 | |||
211 | module_init(jive_init); | ||
212 | module_exit(jive_exit); | ||
213 | |||
214 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | ||
215 | MODULE_DESCRIPTION("ALSA SoC Jive Audio support"); | ||
216 | MODULE_LICENSE("GPL"); | ||