Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: sound/soc/samsung/h1940_uda1380.c

Issue 6577007: CHROMIUM: ASoC: Import entire upstream ASoC tree (Closed)
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sound/soc/samsung/goni_wm8994.c ('k') | sound/soc/samsung/i2s.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * rx1950.c -- ALSA Soc Audio Layer 2 * h1940-uda1380.c -- ALSA Soc Audio Layer
3 * 3 *
4 * Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
4 * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com> 5 * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
5 * 6 *
6 * Based on smdk2440.c and magician.c 7 * Based on version from Arnaud Patard <arnaud.patard@rtp-net.org>
7 * 8 *
8 * Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com 9 * This program is free software; you can redistribute it and/or modify it
9 * Philipp Zabel <philipp.zabel@gmail.com> 10 * under the terms of the GNU General Public License as published by the
10 * Denis Grigoriev <dgreenday@gmail.com> 11 * Free Software Foundation; either version 2 of the License, or (at your
11 * Vasily Khoruzhick <anarsoul@gmail.com> 12 * option) any later version.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 * 13 *
18 */ 14 */
19 15
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/platform_device.h>
23 #include <linux/i2c.h>
24 #include <linux/gpio.h> 16 #include <linux/gpio.h>
25 #include <linux/clk.h>
26 17
27 #include <sound/soc.h> 18 #include <sound/soc.h>
28 #include <sound/soc-dapm.h>
29 #include <sound/uda1380.h>
30 #include <sound/jack.h> 19 #include <sound/jack.h>
31 20
32 #include <plat/regs-iis.h> 21 #include <plat/regs-iis.h>
33 22 #include <mach/h1940-latch.h>
34 #include <mach/regs-clock.h>
35
36 #include <asm/mach-types.h> 23 #include <asm/mach-types.h>
37 24
38 #include "s3c-dma.h"
39 #include "s3c24xx-i2s.h" 25 #include "s3c24xx-i2s.h"
40 #include "../codecs/uda1380.h"
41
42 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd);
43 static int rx1950_startup(struct snd_pcm_substream *substream);
44 static int rx1950_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params);
46 static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
47 struct snd_kcontrol *kcontrol, int event);
48 26
49 static unsigned int rates[] = { 27 static unsigned int rates[] = {
50 » 16000, 28 » 11025,
29 » 22050,
51 44100, 30 44100,
52 48000,
53 }; 31 };
54 32
55 static struct snd_pcm_hw_constraint_list hw_rates = { 33 static struct snd_pcm_hw_constraint_list hw_rates = {
56 .count = ARRAY_SIZE(rates), 34 .count = ARRAY_SIZE(rates),
57 .list = rates, 35 .list = rates,
58 .mask = 0, 36 .mask = 0,
59 }; 37 };
60 38
61 static struct snd_soc_jack hp_jack; 39 static struct snd_soc_jack hp_jack;
62 40
63 static struct snd_soc_jack_pin hp_jack_pins[] = { 41 static struct snd_soc_jack_pin hp_jack_pins[] = {
64 { 42 {
65 .pin = "Headphone Jack", 43 .pin = "Headphone Jack",
66 .mask = SND_JACK_HEADPHONE, 44 .mask = SND_JACK_HEADPHONE,
67 }, 45 },
68 { 46 {
69 .pin = "Speaker", 47 .pin = "Speaker",
70 .mask = SND_JACK_HEADPHONE, 48 .mask = SND_JACK_HEADPHONE,
71 .invert = 1, 49 .invert = 1,
72 }, 50 },
73 }; 51 };
74 52
75 static struct snd_soc_jack_gpio hp_jack_gpios[] = { 53 static struct snd_soc_jack_gpio hp_jack_gpios[] = {
76 » [0] = { 54 » {
77 » » .gpio» » » = S3C2410_GPG(12), 55 » » .gpio» » » = S3C2410_GPG(4),
78 .name = "hp-gpio", 56 .name = "hp-gpio",
79 .report = SND_JACK_HEADPHONE, 57 .report = SND_JACK_HEADPHONE,
80 .invert = 1, 58 .invert = 1,
81 .debounce_time = 200, 59 .debounce_time = 200,
82 }, 60 },
83 }; 61 };
84 62
85 static struct snd_soc_ops rx1950_ops = { 63 static int h1940_startup(struct snd_pcm_substream *substream)
86 » .startup» = rx1950_startup,
87 » .hw_params» = rx1950_hw_params,
88 };
89
90 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
91 static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
92 » {
93 » » .name» » = "uda1380",
94 » » .stream_name» = "UDA1380 Duplex",
95 » » .cpu_dai_name» = "s3c24xx-iis",
96 » » .codec_dai_name»= "uda1380-hifi",
97 » » .init» » = rx1950_uda1380_init,
98 » » .platform_name» = "s3c24xx-pcm-audio",
99 » » .codec_name» = "uda1380-codec.0-001a",
100 » » .ops» » = &rx1950_ops,
101 » },
102 };
103
104 static struct snd_soc_card rx1950_asoc = {
105 » .name = "rx1950",
106 » .dai_link = rx1950_uda1380_dai,
107 » .num_links = ARRAY_SIZE(rx1950_uda1380_dai),
108 };
109
110 /* rx1950 machine dapm widgets */
111 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
112 » SND_SOC_DAPM_HP("Headphone Jack", NULL),
113 » SND_SOC_DAPM_MIC("Mic Jack", NULL),
114 » SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power),
115 };
116
117 /* rx1950 machine audio_map */
118 static const struct snd_soc_dapm_route audio_map[] = {
119 » /* headphone connected to VOUTLHP, VOUTRHP */
120 » {"Headphone Jack", NULL, "VOUTLHP"},
121 » {"Headphone Jack", NULL, "VOUTRHP"},
122
123 » /* ext speaker connected to VOUTL, VOUTR */
124 » {"Speaker", NULL, "VOUTL"},
125 » {"Speaker", NULL, "VOUTR"},
126
127 » /* mic is connected to VINM */
128 » {"VINM", NULL, "Mic Jack"},
129 };
130
131 static struct platform_device *s3c24xx_snd_device;
132
133 static int rx1950_startup(struct snd_pcm_substream *substream)
134 { 64 {
135 struct snd_pcm_runtime *runtime = substream->runtime; 65 struct snd_pcm_runtime *runtime = substream->runtime;
136 66
137 runtime->hw.rate_min = hw_rates.list[0]; 67 runtime->hw.rate_min = hw_rates.list[0];
138 runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1]; 68 runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
139 runtime->hw.rates = SNDRV_PCM_RATE_KNOT; 69 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
140 70
141 return snd_pcm_hw_constraint_list(runtime, 0, 71 return snd_pcm_hw_constraint_list(runtime, 0,
142 SNDRV_PCM_HW_PARAM_RATE, 72 SNDRV_PCM_HW_PARAM_RATE,
143 &hw_rates); 73 &hw_rates);
144 } 74 }
145 75
146 static int rx1950_spk_power(struct snd_soc_dapm_widget *w, 76 static int h1940_hw_params(struct snd_pcm_substream *substream,
147 » » » » struct snd_kcontrol *kcontrol, int event)
148 {
149 » if (SND_SOC_DAPM_EVENT_ON(event))
150 » » gpio_set_value(S3C2410_GPA(1), 1);
151 » else
152 » » gpio_set_value(S3C2410_GPA(1), 0);
153
154 » return 0;
155 }
156
157 static int rx1950_hw_params(struct snd_pcm_substream *substream,
158 struct snd_pcm_hw_params *params) 77 struct snd_pcm_hw_params *params)
159 { 78 {
160 struct snd_soc_pcm_runtime *rtd = substream->private_data; 79 struct snd_soc_pcm_runtime *rtd = substream->private_data;
161 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 80 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
162 struct snd_soc_dai *codec_dai = rtd->codec_dai; 81 struct snd_soc_dai *codec_dai = rtd->codec_dai;
163 int div; 82 int div;
164 int ret; 83 int ret;
165 unsigned int rate = params_rate(params); 84 unsigned int rate = params_rate(params);
166 int clk_source, fs_mode;
167 85
168 switch (rate) { 86 switch (rate) {
169 » case 16000: 87 » case 11025:
170 » case 48000: 88 » case 22050:
171 » » clk_source = S3C24XX_CLKSRC_PCLK; 89 » case 44100:
172 » » fs_mode = S3C2410_IISMOD_256FS; 90 » » div = s3c24xx_i2s_get_clockrate() / (384 * rate);
173 » » div = s3c24xx_i2s_get_clockrate() / (256 * rate); 91 » » if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (192 * rate))
174 » » if (s3c24xx_i2s_get_clockrate() % (256 * rate) > (128 * rate))
175 div++; 92 div++;
176 break; 93 break;
177 case 44100:
178 case 88200:
179 clk_source = S3C24XX_CLKSRC_MPLL;
180 fs_mode = S3C2410_IISMOD_384FS;
181 div = 1;
182 break;
183 default: 94 default:
184 » » printk(KERN_ERR "%s: rate %d is not supported\n", 95 » » dev_err(&rtd->dev, "%s: rate %d is not supported\n",
185 __func__, rate); 96 __func__, rate);
186 return -EINVAL; 97 return -EINVAL;
187 } 98 }
188 99
189 /* set codec DAI configuration */ 100 /* set codec DAI configuration */
190 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | 101 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
191 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); 102 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
192 if (ret < 0) 103 if (ret < 0)
193 return ret; 104 return ret;
194 105
195 /* set cpu DAI configuration */ 106 /* set cpu DAI configuration */
196 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | 107 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
197 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); 108 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
198 if (ret < 0) 109 if (ret < 0)
199 return ret; 110 return ret;
200 111
201 /* select clock source */ 112 /* select clock source */
202 » ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate, 113 » ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_PCLK, rate,
203 SND_SOC_CLOCK_OUT); 114 SND_SOC_CLOCK_OUT);
204 if (ret < 0) 115 if (ret < 0)
205 return ret; 116 return ret;
206 117
207 /* set MCLK division for sample rate */ 118 /* set MCLK division for sample rate */
208 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK, 119 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
209 » » fs_mode); 120 » » S3C2410_IISMOD_384FS);
210 if (ret < 0) 121 if (ret < 0)
211 return ret; 122 return ret;
212 123
213 /* set BCLK division for sample rate */ 124 /* set BCLK division for sample rate */
214 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK, 125 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
215 S3C2410_IISMOD_32FS); 126 S3C2410_IISMOD_32FS);
216 if (ret < 0) 127 if (ret < 0)
217 return ret; 128 return ret;
218 129
219 /* set prescaler division for sample rate */ 130 /* set prescaler division for sample rate */
220 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER, 131 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
221 S3C24XX_PRESCALE(div, div)); 132 S3C24XX_PRESCALE(div, div));
222 if (ret < 0) 133 if (ret < 0)
223 return ret; 134 return ret;
224 135
225 return 0; 136 return 0;
226 } 137 }
227 138
228 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd) 139 static struct snd_soc_ops h1940_ops = {
140 » .startup» = h1940_startup,
141 » .hw_params» = h1940_hw_params,
142 };
143
144 static int h1940_spk_power(struct snd_soc_dapm_widget *w,
145 » » » » struct snd_kcontrol *kcontrol, int event)
146 {
147 » if (SND_SOC_DAPM_EVENT_ON(event))
148 » » gpio_set_value(H1940_LATCH_AUDIO_POWER, 1);
149 » else
150 » » gpio_set_value(H1940_LATCH_AUDIO_POWER, 0);
151
152 » return 0;
153 }
154
155 /* h1940 machine dapm widgets */
156 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
157 » SND_SOC_DAPM_HP("Headphone Jack", NULL),
158 » SND_SOC_DAPM_MIC("Mic Jack", NULL),
159 » SND_SOC_DAPM_SPK("Speaker", h1940_spk_power),
160 };
161
162 /* h1940 machine audio_map */
163 static const struct snd_soc_dapm_route audio_map[] = {
164 » /* headphone connected to VOUTLHP, VOUTRHP */
165 » {"Headphone Jack", NULL, "VOUTLHP"},
166 » {"Headphone Jack", NULL, "VOUTRHP"},
167
168 » /* ext speaker connected to VOUTL, VOUTR */
169 » {"Speaker", NULL, "VOUTL"},
170 » {"Speaker", NULL, "VOUTR"},
171
172 » /* mic is connected to VINM */
173 » {"VINM", NULL, "Mic Jack"},
174 };
175
176 static struct platform_device *s3c24xx_snd_device;
177
178 static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
229 { 179 {
230 struct snd_soc_codec *codec = rtd->codec; 180 struct snd_soc_codec *codec = rtd->codec;
181 struct snd_soc_dapm_context *dapm = &codec->dapm;
231 int err; 182 int err;
232 183
233 » /* Add rx1950 specific widgets */ 184 » /* Add h1940 specific widgets */
234 » err = snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets, 185 » err = snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
235 ARRAY_SIZE(uda1380_dapm_widgets)); 186 ARRAY_SIZE(uda1380_dapm_widgets));
236
237 if (err) 187 if (err)
238 return err; 188 return err;
239 189
240 » /* Set up rx1950 specific audio path audio_mapnects */ 190 » /* Set up h1940 specific audio path audio_mapnects */
241 » err = snd_soc_dapm_add_routes(codec, audio_map, 191 » err = snd_soc_dapm_add_routes(dapm, audio_map,
242 ARRAY_SIZE(audio_map)); 192 ARRAY_SIZE(audio_map));
243
244 if (err) 193 if (err)
245 return err; 194 return err;
246 195
247 » snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 196 » snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
248 » snd_soc_dapm_enable_pin(codec, "Speaker"); 197 » snd_soc_dapm_enable_pin(dapm, "Speaker");
198 » snd_soc_dapm_enable_pin(dapm, "Mic Jack");
249 199
250 » snd_soc_dapm_sync(codec); 200 » snd_soc_dapm_sync(dapm);
251 201
252 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE, 202 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
253 &hp_jack); 203 &hp_jack);
254 204
255 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins), 205 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
256 hp_jack_pins); 206 hp_jack_pins);
257 207
258 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios), 208 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
259 hp_jack_gpios); 209 hp_jack_gpios);
260 210
261 return 0; 211 return 0;
262 } 212 }
263 213
264 static int __init rx1950_init(void) 214 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
215 static struct snd_soc_dai_link h1940_uda1380_dai[] = {
216 » {
217 » » .name» » = "uda1380",
218 » » .stream_name» = "UDA1380 Duplex",
219 » » .cpu_dai_name» = "s3c24xx-iis",
220 » » .codec_dai_name»= "uda1380-hifi",
221 » » .init» » = h1940_uda1380_init,
222 » » .platform_name» = "samsung-audio",
223 » » .codec_name» = "uda1380-codec.0-001a",
224 » » .ops» » = &h1940_ops,
225 » },
226 };
227
228 static struct snd_soc_card h1940_asoc = {
229 » .name = "h1940",
230 » .dai_link = h1940_uda1380_dai,
231 » .num_links = ARRAY_SIZE(h1940_uda1380_dai),
232 };
233
234 static int __init h1940_init(void)
265 { 235 {
266 int ret; 236 int ret;
267 237
268 » if (!machine_is_rx1950()) 238 » if (!machine_is_h1940())
269 return -ENODEV; 239 return -ENODEV;
270 240
271 /* configure some gpios */ 241 /* configure some gpios */
272 » ret = gpio_request(S3C2410_GPA(1), "speaker-power"); 242 » ret = gpio_request(H1940_LATCH_AUDIO_POWER, "speaker-power");
243 » if (ret)
244 » » goto err_out;
245
246 » ret = gpio_direction_output(H1940_LATCH_AUDIO_POWER, 0);
273 if (ret) 247 if (ret)
274 goto err_gpio; 248 goto err_gpio;
275 249
276 ret = gpio_direction_output(S3C2410_GPA(1), 0);
277 if (ret)
278 goto err_gpio_conf;
279
280 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1); 250 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
281 if (!s3c24xx_snd_device) { 251 if (!s3c24xx_snd_device) {
282 ret = -ENOMEM; 252 ret = -ENOMEM;
283 » » goto err_plat_alloc; 253 » » goto err_gpio;
284 } 254 }
285 255
286 » platform_set_drvdata(s3c24xx_snd_device, &rx1950_asoc); 256 » platform_set_drvdata(s3c24xx_snd_device, &h1940_asoc);
287 ret = platform_device_add(s3c24xx_snd_device); 257 ret = platform_device_add(s3c24xx_snd_device);
288 258
289 » if (ret) { 259 » if (ret)
290 » » platform_device_put(s3c24xx_snd_device); 260 » » goto err_plat;
291 » » goto err_plat_add;
292 » }
293 261
294 return 0; 262 return 0;
295 263
296 err_plat_add: 264 err_plat:
297 err_plat_alloc: 265 » platform_device_put(s3c24xx_snd_device);
298 err_gpio_conf: 266 err_gpio:
299 » gpio_free(S3C2410_GPA(1)); 267 » gpio_free(H1940_LATCH_AUDIO_POWER);
300 268
301 err_gpio: 269 err_out:
302 return ret; 270 return ret;
303 } 271 }
304 272
305 static void __exit rx1950_exit(void) 273 static void __exit h1940_exit(void)
306 { 274 {
307 platform_device_unregister(s3c24xx_snd_device); 275 platform_device_unregister(s3c24xx_snd_device);
308 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios), 276 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
309 hp_jack_gpios); 277 hp_jack_gpios);
310 » gpio_free(S3C2410_GPA(1)); 278 » gpio_free(H1940_LATCH_AUDIO_POWER);
311 } 279 }
312 280
313 module_init(rx1950_init); 281 module_init(h1940_init);
314 module_exit(rx1950_exit); 282 module_exit(h1940_exit);
315 283
316 /* Module information */ 284 /* Module information */
317 MODULE_AUTHOR("Vasily Khoruzhick"); 285 MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick");
318 MODULE_DESCRIPTION("ALSA SoC RX1950"); 286 MODULE_DESCRIPTION("ALSA SoC H1940");
319 MODULE_LICENSE("GPL"); 287 MODULE_LICENSE("GPL");
OLDNEW
« no previous file with comments | « sound/soc/samsung/goni_wm8994.c ('k') | sound/soc/samsung/i2s.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698