staging: ozwpan: Add module parameter description
[linux/fpc-iii.git] / sound / soc / samsung / rx1950_uda1380.c
blob37688ebbb2b4b6be954150d1e17b721ed9ddf6f3
1 /*
2 * rx1950.c -- ALSA Soc Audio Layer
4 * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
6 * Based on smdk2440.c and magician.c
8 * Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com
9 * Philipp Zabel <philipp.zabel@gmail.com>
10 * Denis Grigoriev <dgreenday@gmail.com>
11 * Vasily Khoruzhick <anarsoul@gmail.com>
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.
20 #include <linux/types.h>
21 #include <linux/gpio.h>
22 #include <linux/module.h>
24 #include <sound/soc.h>
25 #include <sound/jack.h>
27 #include <mach/gpio-samsung.h>
28 #include "regs-iis.h"
29 #include <asm/mach-types.h>
31 #include "s3c24xx-i2s.h"
33 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd);
34 static int rx1950_uda1380_card_remove(struct snd_soc_card *card);
35 static int rx1950_startup(struct snd_pcm_substream *substream);
36 static int rx1950_hw_params(struct snd_pcm_substream *substream,
37 struct snd_pcm_hw_params *params);
38 static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
39 struct snd_kcontrol *kcontrol, int event);
41 static unsigned int rates[] = {
42 16000,
43 44100,
44 48000,
47 static struct snd_pcm_hw_constraint_list hw_rates = {
48 .count = ARRAY_SIZE(rates),
49 .list = rates,
50 .mask = 0,
53 static struct snd_soc_jack hp_jack;
55 static struct snd_soc_jack_pin hp_jack_pins[] = {
57 .pin = "Headphone Jack",
58 .mask = SND_JACK_HEADPHONE,
61 .pin = "Speaker",
62 .mask = SND_JACK_HEADPHONE,
63 .invert = 1,
67 static struct snd_soc_jack_gpio hp_jack_gpios[] = {
68 [0] = {
69 .gpio = S3C2410_GPG(12),
70 .name = "hp-gpio",
71 .report = SND_JACK_HEADPHONE,
72 .invert = 1,
73 .debounce_time = 200,
77 static struct snd_soc_ops rx1950_ops = {
78 .startup = rx1950_startup,
79 .hw_params = rx1950_hw_params,
82 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
83 static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
85 .name = "uda1380",
86 .stream_name = "UDA1380 Duplex",
87 .cpu_dai_name = "s3c24xx-iis",
88 .codec_dai_name = "uda1380-hifi",
89 .init = rx1950_uda1380_init,
90 .platform_name = "s3c24xx-iis",
91 .codec_name = "uda1380-codec.0-001a",
92 .ops = &rx1950_ops,
96 /* rx1950 machine dapm widgets */
97 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
98 SND_SOC_DAPM_HP("Headphone Jack", NULL),
99 SND_SOC_DAPM_MIC("Mic Jack", NULL),
100 SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power),
103 /* rx1950 machine audio_map */
104 static const struct snd_soc_dapm_route audio_map[] = {
105 /* headphone connected to VOUTLHP, VOUTRHP */
106 {"Headphone Jack", NULL, "VOUTLHP"},
107 {"Headphone Jack", NULL, "VOUTRHP"},
109 /* ext speaker connected to VOUTL, VOUTR */
110 {"Speaker", NULL, "VOUTL"},
111 {"Speaker", NULL, "VOUTR"},
113 /* mic is connected to VINM */
114 {"VINM", NULL, "Mic Jack"},
117 static struct snd_soc_card rx1950_asoc = {
118 .name = "rx1950",
119 .owner = THIS_MODULE,
120 .remove = rx1950_uda1380_card_remove,
121 .dai_link = rx1950_uda1380_dai,
122 .num_links = ARRAY_SIZE(rx1950_uda1380_dai),
124 .dapm_widgets = uda1380_dapm_widgets,
125 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
126 .dapm_routes = audio_map,
127 .num_dapm_routes = ARRAY_SIZE(audio_map),
130 static struct platform_device *s3c24xx_snd_device;
132 static int rx1950_startup(struct snd_pcm_substream *substream)
134 struct snd_pcm_runtime *runtime = substream->runtime;
136 return snd_pcm_hw_constraint_list(runtime, 0,
137 SNDRV_PCM_HW_PARAM_RATE,
138 &hw_rates);
141 static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
142 struct snd_kcontrol *kcontrol, int event)
144 if (SND_SOC_DAPM_EVENT_ON(event))
145 gpio_set_value(S3C2410_GPA(1), 1);
146 else
147 gpio_set_value(S3C2410_GPA(1), 0);
149 return 0;
152 static int rx1950_hw_params(struct snd_pcm_substream *substream,
153 struct snd_pcm_hw_params *params)
155 struct snd_soc_pcm_runtime *rtd = substream->private_data;
156 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
157 struct snd_soc_dai *codec_dai = rtd->codec_dai;
158 int div;
159 int ret;
160 unsigned int rate = params_rate(params);
161 int clk_source, fs_mode;
163 switch (rate) {
164 case 16000:
165 case 48000:
166 clk_source = S3C24XX_CLKSRC_PCLK;
167 fs_mode = S3C2410_IISMOD_256FS;
168 div = s3c24xx_i2s_get_clockrate() / (256 * rate);
169 if (s3c24xx_i2s_get_clockrate() % (256 * rate) > (128 * rate))
170 div++;
171 break;
172 case 44100:
173 case 88200:
174 clk_source = S3C24XX_CLKSRC_MPLL;
175 fs_mode = S3C2410_IISMOD_384FS;
176 div = 1;
177 break;
178 default:
179 printk(KERN_ERR "%s: rate %d is not supported\n",
180 __func__, rate);
181 return -EINVAL;
184 /* set codec DAI configuration */
185 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
186 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
187 if (ret < 0)
188 return ret;
190 /* set cpu DAI configuration */
191 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
192 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
193 if (ret < 0)
194 return ret;
196 /* select clock source */
197 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
198 SND_SOC_CLOCK_OUT);
199 if (ret < 0)
200 return ret;
202 /* set MCLK division for sample rate */
203 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
204 fs_mode);
205 if (ret < 0)
206 return ret;
208 /* set BCLK division for sample rate */
209 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
210 S3C2410_IISMOD_32FS);
211 if (ret < 0)
212 return ret;
214 /* set prescaler division for sample rate */
215 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
216 S3C24XX_PRESCALE(div, div));
217 if (ret < 0)
218 return ret;
220 return 0;
223 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
225 struct snd_soc_codec *codec = rtd->codec;
227 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
228 &hp_jack);
230 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
231 hp_jack_pins);
233 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
234 hp_jack_gpios);
236 return 0;
239 static int rx1950_uda1380_card_remove(struct snd_soc_card *card)
241 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
242 hp_jack_gpios);
244 return 0;
247 static int __init rx1950_init(void)
249 int ret;
251 if (!machine_is_rx1950())
252 return -ENODEV;
254 /* configure some gpios */
255 ret = gpio_request(S3C2410_GPA(1), "speaker-power");
256 if (ret)
257 goto err_gpio;
259 ret = gpio_direction_output(S3C2410_GPA(1), 0);
260 if (ret)
261 goto err_gpio_conf;
263 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
264 if (!s3c24xx_snd_device) {
265 ret = -ENOMEM;
266 goto err_plat_alloc;
269 platform_set_drvdata(s3c24xx_snd_device, &rx1950_asoc);
270 ret = platform_device_add(s3c24xx_snd_device);
272 if (ret) {
273 platform_device_put(s3c24xx_snd_device);
274 goto err_plat_add;
277 return 0;
279 err_plat_add:
280 err_plat_alloc:
281 err_gpio_conf:
282 gpio_free(S3C2410_GPA(1));
284 err_gpio:
285 return ret;
288 static void __exit rx1950_exit(void)
290 platform_device_unregister(s3c24xx_snd_device);
291 gpio_free(S3C2410_GPA(1));
294 module_init(rx1950_init);
295 module_exit(rx1950_exit);
297 /* Module information */
298 MODULE_AUTHOR("Vasily Khoruzhick");
299 MODULE_DESCRIPTION("ALSA SoC RX1950");
300 MODULE_LICENSE("GPL");