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>
24 #include <asm/mach-types.h>
26 #include <mach/gpio-samsung.h>
27 #include "s3c24xx-i2s.h"
29 static unsigned int rates[] = {
35 static struct snd_pcm_hw_constraint_list hw_rates = {
36 .count = ARRAY_SIZE(rates),
41 static struct snd_soc_jack hp_jack;
43 static struct snd_soc_jack_pin hp_jack_pins[] = {
45 .pin = "Headphone Jack",
46 .mask = SND_JACK_HEADPHONE,
50 .mask = SND_JACK_HEADPHONE,
55 static struct snd_soc_jack_gpio hp_jack_gpios[] = {
57 .gpio = S3C2410_GPG(4),
59 .report = SND_JACK_HEADPHONE,
65 static int h1940_startup(struct snd_pcm_substream *substream)
67 struct snd_pcm_runtime *runtime = substream->runtime;
69 return snd_pcm_hw_constraint_list(runtime, 0,
70 SNDRV_PCM_HW_PARAM_RATE,
74 static int h1940_hw_params(struct snd_pcm_substream *substream,
75 struct snd_pcm_hw_params *params)
77 struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
81 unsigned int rate = params_rate(params);
87 div = s3c24xx_i2s_get_clockrate() / (384 * rate);
88 if (s3c24xx_i2s_get_clockrate() % (384 * rate) > (192 * rate))
92 dev_err(rtd->dev, "%s: rate %d is not supported\n",
97 /* select clock source */
98 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_PCLK, rate,
103 /* set MCLK division for sample rate */
104 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
105 S3C2410_IISMOD_384FS);
109 /* set BCLK division for sample rate */
110 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
111 S3C2410_IISMOD_32FS);
115 /* set prescaler division for sample rate */
116 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
117 S3C24XX_PRESCALE(div, div));
124 static struct snd_soc_ops h1940_ops = {
125 .startup = h1940_startup,
126 .hw_params = h1940_hw_params,
129 static int h1940_spk_power(struct snd_soc_dapm_widget *w,
130 struct snd_kcontrol *kcontrol, int event)
132 if (SND_SOC_DAPM_EVENT_ON(event))
133 gpio_set_value(S3C_GPIO_END + 9, 1);
135 gpio_set_value(S3C_GPIO_END + 9, 0);
140 /* h1940 machine dapm widgets */
141 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
142 SND_SOC_DAPM_HP("Headphone Jack", NULL),
143 SND_SOC_DAPM_MIC("Mic Jack", NULL),
144 SND_SOC_DAPM_SPK("Speaker", h1940_spk_power),
147 /* h1940 machine audio_map */
148 static const struct snd_soc_dapm_route audio_map[] = {
149 /* headphone connected to VOUTLHP, VOUTRHP */
150 {"Headphone Jack", NULL, "VOUTLHP"},
151 {"Headphone Jack", NULL, "VOUTRHP"},
153 /* ext speaker connected to VOUTL, VOUTR */
154 {"Speaker", NULL, "VOUTL"},
155 {"Speaker", NULL, "VOUTR"},
157 /* mic is connected to VINM */
158 {"VINM", NULL, "Mic Jack"},
161 static struct platform_device *s3c24xx_snd_device;
163 static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd)
165 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
166 &hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
168 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
174 static int h1940_uda1380_card_remove(struct snd_soc_card *card)
176 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
182 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
183 static struct snd_soc_dai_link h1940_uda1380_dai[] = {
186 .stream_name = "UDA1380 Duplex",
187 .cpu_dai_name = "s3c24xx-iis",
188 .codec_dai_name = "uda1380-hifi",
189 .init = h1940_uda1380_init,
190 .platform_name = "s3c24xx-iis",
191 .codec_name = "uda1380-codec.0-001a",
192 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
193 SND_SOC_DAIFMT_CBS_CFS,
198 static struct snd_soc_card h1940_asoc = {
200 .owner = THIS_MODULE,
201 .remove = h1940_uda1380_card_remove,
202 .dai_link = h1940_uda1380_dai,
203 .num_links = ARRAY_SIZE(h1940_uda1380_dai),
205 .dapm_widgets = uda1380_dapm_widgets,
206 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
207 .dapm_routes = audio_map,
208 .num_dapm_routes = ARRAY_SIZE(audio_map),
211 static int __init h1940_init(void)
215 if (!machine_is_h1940())
218 /* configure some gpios */
219 ret = gpio_request(S3C_GPIO_END + 9, "speaker-power");
223 ret = gpio_direction_output(S3C_GPIO_END + 9, 0);
227 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
228 if (!s3c24xx_snd_device) {
233 platform_set_drvdata(s3c24xx_snd_device, &h1940_asoc);
234 ret = platform_device_add(s3c24xx_snd_device);
242 platform_device_put(s3c24xx_snd_device);
244 gpio_free(S3C_GPIO_END + 9);
250 static void __exit h1940_exit(void)
252 platform_device_unregister(s3c24xx_snd_device);
253 gpio_free(S3C_GPIO_END + 9);
256 module_init(h1940_init);
257 module_exit(h1940_exit);
259 /* Module information */
260 MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick");
261 MODULE_DESCRIPTION("ALSA SoC H1940");
262 MODULE_LICENSE("GPL");