sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / soc / samsung / h1940_uda1380.c
blob5f5825faeb2a4331177595eaabcd0600b9d2476e
1 /*
2 * h1940-uda1380.c -- ALSA Soc Audio Layer
4 * Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
5 * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
7 * Based on version from Arnaud Patard <arnaud.patard@rtp-net.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/types.h>
17 #include <linux/gpio.h>
18 #include <linux/module.h>
20 #include <sound/soc.h>
21 #include <sound/jack.h>
23 #include "regs-iis.h"
24 #include <asm/mach-types.h>
26 #include <mach/gpio-samsung.h>
27 #include "s3c24xx-i2s.h"
29 static const unsigned int rates[] = {
30 11025,
31 22050,
32 44100,
35 static const struct snd_pcm_hw_constraint_list hw_rates = {
36 .count = ARRAY_SIZE(rates),
37 .list = rates,
40 static struct snd_soc_jack hp_jack;
42 static struct snd_soc_jack_pin hp_jack_pins[] = {
44 .pin = "Headphone Jack",
45 .mask = SND_JACK_HEADPHONE,
48 .pin = "Speaker",
49 .mask = SND_JACK_HEADPHONE,
50 .invert = 1,
54 static struct snd_soc_jack_gpio hp_jack_gpios[] = {
56 .gpio = S3C2410_GPG(4),
57 .name = "hp-gpio",
58 .report = SND_JACK_HEADPHONE,
59 .invert = 1,
60 .debounce_time = 200,
64 static int h1940_startup(struct snd_pcm_substream *substream)
66 struct snd_pcm_runtime *runtime = substream->runtime;
68 return snd_pcm_hw_constraint_list(runtime, 0,
69 SNDRV_PCM_HW_PARAM_RATE,
70 &hw_rates);
73 static int h1940_hw_params(struct snd_pcm_substream *substream,
74 struct snd_pcm_hw_params *params)
76 struct snd_soc_pcm_runtime *rtd = substream->private_data;
77 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
78 int div;
79 int ret;
80 unsigned int rate = params_rate(params);
82 switch (rate) {
83 case 11025:
84 case 22050:
85 case 44100:
86 div = s3c24xx_i2s_get_clockrate() / (384 * rate);
87 if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (192 * rate))
88 div++;
89 break;
90 default:
91 dev_err(rtd->dev, "%s: rate %d is not supported\n",
92 __func__, rate);
93 return -EINVAL;
96 /* select clock source */
97 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_PCLK, rate,
98 SND_SOC_CLOCK_OUT);
99 if (ret < 0)
100 return ret;
102 /* set MCLK division for sample rate */
103 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
104 S3C2410_IISMOD_384FS);
105 if (ret < 0)
106 return ret;
108 /* set BCLK division for sample rate */
109 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
110 S3C2410_IISMOD_32FS);
111 if (ret < 0)
112 return ret;
114 /* set prescaler division for sample rate */
115 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
116 S3C24XX_PRESCALE(div, div));
117 if (ret < 0)
118 return ret;
120 return 0;
123 static struct snd_soc_ops h1940_ops = {
124 .startup = h1940_startup,
125 .hw_params = h1940_hw_params,
128 static int h1940_spk_power(struct snd_soc_dapm_widget *w,
129 struct snd_kcontrol *kcontrol, int event)
131 if (SND_SOC_DAPM_EVENT_ON(event))
132 gpio_set_value(S3C_GPIO_END + 9, 1);
133 else
134 gpio_set_value(S3C_GPIO_END + 9, 0);
136 return 0;
139 /* h1940 machine dapm widgets */
140 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
141 SND_SOC_DAPM_HP("Headphone Jack", NULL),
142 SND_SOC_DAPM_MIC("Mic Jack", NULL),
143 SND_SOC_DAPM_SPK("Speaker", h1940_spk_power),
146 /* h1940 machine audio_map */
147 static const struct snd_soc_dapm_route audio_map[] = {
148 /* headphone connected to VOUTLHP, VOUTRHP */
149 {"Headphone Jack", NULL, "VOUTLHP"},
150 {"Headphone Jack", NULL, "VOUTRHP"},
152 /* ext speaker connected to VOUTL, VOUTR */
153 {"Speaker", NULL, "VOUTL"},
154 {"Speaker", NULL, "VOUTR"},
156 /* mic is connected to VINM */
157 {"VINM", NULL, "Mic Jack"},
160 static struct platform_device *s3c24xx_snd_device;
162 static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
164 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
165 &hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
167 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
168 hp_jack_gpios);
170 return 0;
173 static int h1940_uda1380_card_remove(struct snd_soc_card *card)
175 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
176 hp_jack_gpios);
178 return 0;
181 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
182 static struct snd_soc_dai_link h1940_uda1380_dai[] = {
184 .name = "uda1380",
185 .stream_name = "UDA1380 Duplex",
186 .cpu_dai_name = "s3c24xx-iis",
187 .codec_dai_name = "uda1380-hifi",
188 .init = h1940_uda1380_init,
189 .platform_name = "s3c24xx-iis",
190 .codec_name = "uda1380-codec.0-001a",
191 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
192 SND_SOC_DAIFMT_CBS_CFS,
193 .ops = &h1940_ops,
197 static struct snd_soc_card h1940_asoc = {
198 .name = "h1940",
199 .owner = THIS_MODULE,
200 .remove = h1940_uda1380_card_remove,
201 .dai_link = h1940_uda1380_dai,
202 .num_links = ARRAY_SIZE(h1940_uda1380_dai),
204 .dapm_widgets = uda1380_dapm_widgets,
205 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
206 .dapm_routes = audio_map,
207 .num_dapm_routes = ARRAY_SIZE(audio_map),
210 static int __init h1940_init(void)
212 int ret;
214 if (!machine_is_h1940())
215 return -ENODEV;
217 /* configure some gpios */
218 ret = gpio_request(S3C_GPIO_END + 9, "speaker-power");
219 if (ret)
220 goto err_out;
222 ret = gpio_direction_output(S3C_GPIO_END + 9, 0);
223 if (ret)
224 goto err_gpio;
226 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
227 if (!s3c24xx_snd_device) {
228 ret = -ENOMEM;
229 goto err_gpio;
232 platform_set_drvdata(s3c24xx_snd_device, &h1940_asoc);
233 ret = platform_device_add(s3c24xx_snd_device);
235 if (ret)
236 goto err_plat;
238 return 0;
240 err_plat:
241 platform_device_put(s3c24xx_snd_device);
242 err_gpio:
243 gpio_free(S3C_GPIO_END + 9);
245 err_out:
246 return ret;
249 static void __exit h1940_exit(void)
251 platform_device_unregister(s3c24xx_snd_device);
252 gpio_free(S3C_GPIO_END + 9);
255 module_init(h1940_init);
256 module_exit(h1940_exit);
258 /* Module information */
259 MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick");
260 MODULE_DESCRIPTION("ALSA SoC H1940");
261 MODULE_LICENSE("GPL");