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/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/timer.h>
23 #include <linux/delay.h>
24 #include <linux/interrupt.h>
25 #include <linux/platform_device.h>
26 #include <linux/spinlock.h>
27 #include <linux/i2c.h>
28 #include <linux/gpio.h>
29 #include <linux/clk.h>
31 #include <sound/core.h>
32 #include <sound/pcm.h>
33 #include <sound/pcm_params.h>
34 #include <sound/soc.h>
35 #include <sound/soc-dapm.h>
36 #include <sound/uda1380.h>
37 #include <sound/jack.h>
39 #include <plat/regs-iis.h>
41 #include <mach/regs-clock.h>
43 #include <asm/mach-types.h>
46 #include "s3c24xx-i2s.h"
47 #include "../codecs/uda1380.h"
49 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime
*rtd
);
50 static int rx1950_startup(struct snd_pcm_substream
*substream
);
51 static int rx1950_hw_params(struct snd_pcm_substream
*substream
,
52 struct snd_pcm_hw_params
*params
);
53 static int rx1950_spk_power(struct snd_soc_dapm_widget
*w
,
54 struct snd_kcontrol
*kcontrol
, int event
);
56 static unsigned int rates
[] = {
63 static struct snd_pcm_hw_constraint_list hw_rates
= {
64 .count
= ARRAY_SIZE(rates
),
69 static struct snd_soc_jack hp_jack
;
71 static struct snd_soc_jack_pin hp_jack_pins
[] = {
73 .pin
= "Headphone Jack",
74 .mask
= SND_JACK_HEADPHONE
,
78 .mask
= SND_JACK_HEADPHONE
,
83 static struct snd_soc_jack_gpio hp_jack_gpios
[] = {
85 .gpio
= S3C2410_GPG(12),
87 .report
= SND_JACK_HEADPHONE
,
93 static struct snd_soc_ops rx1950_ops
= {
94 .startup
= rx1950_startup
,
95 .hw_params
= rx1950_hw_params
,
98 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
99 static struct snd_soc_dai_link rx1950_uda1380_dai
[] = {
102 .stream_name
= "UDA1380 Duplex",
103 .cpu_dai_name
= "s3c24xx-iis",
104 .codec_dai_name
= "uda1380-hifi",
105 .init
= rx1950_uda1380_init
,
106 .platform_name
= "s3c24xx-pcm-audio",
107 .codec_name
= "uda1380-codec.0-001a",
112 static struct snd_soc_card rx1950_asoc
= {
114 .dai_link
= rx1950_uda1380_dai
,
115 .num_links
= ARRAY_SIZE(rx1950_uda1380_dai
),
118 /* rx1950 machine dapm widgets */
119 static const struct snd_soc_dapm_widget uda1380_dapm_widgets
[] = {
120 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
121 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
122 SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power
),
125 /* rx1950 machine audio_map */
126 static const struct snd_soc_dapm_route audio_map
[] = {
127 /* headphone connected to VOUTLHP, VOUTRHP */
128 {"Headphone Jack", NULL
, "VOUTLHP"},
129 {"Headphone Jack", NULL
, "VOUTRHP"},
131 /* ext speaker connected to VOUTL, VOUTR */
132 {"Speaker", NULL
, "VOUTL"},
133 {"Speaker", NULL
, "VOUTR"},
135 /* mic is connected to VINM */
136 {"VINM", NULL
, "Mic Jack"},
139 static struct platform_device
*s3c24xx_snd_device
;
140 static struct clk
*xtal
;
142 static int rx1950_startup(struct snd_pcm_substream
*substream
)
144 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
146 runtime
->hw
.rate_min
= hw_rates
.list
[0];
147 runtime
->hw
.rate_max
= hw_rates
.list
[hw_rates
.count
- 1];
148 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
150 return snd_pcm_hw_constraint_list(runtime
, 0,
151 SNDRV_PCM_HW_PARAM_RATE
,
155 static int rx1950_spk_power(struct snd_soc_dapm_widget
*w
,
156 struct snd_kcontrol
*kcontrol
, int event
)
158 if (SND_SOC_DAPM_EVENT_ON(event
))
159 gpio_set_value(S3C2410_GPA(1), 1);
161 gpio_set_value(S3C2410_GPA(1), 0);
166 static int rx1950_hw_params(struct snd_pcm_substream
*substream
,
167 struct snd_pcm_hw_params
*params
)
169 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
170 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
171 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
174 unsigned int rate
= params_rate(params
);
175 int clk_source
, fs_mode
;
180 clk_source
= S3C24XX_CLKSRC_PCLK
;
181 fs_mode
= S3C2410_IISMOD_384FS
;
182 div
= s3c24xx_i2s_get_clockrate() / (384 * rate
);
183 if (s3c24xx_i2s_get_clockrate() % (384 * rate
) > (182 * rate
))
188 clk_source
= S3C24XX_CLKSRC_MPLL
;
189 fs_mode
= S3C2410_IISMOD_256FS
;
190 div
= clk_get_rate(xtal
) / (256 * rate
);
191 if (clk_get_rate(xtal
) % (256 * rate
) > (128 * rate
))
195 printk(KERN_ERR
"%s: rate %d is not supported\n",
200 /* set codec DAI configuration */
201 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
202 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
206 /* set cpu DAI configuration */
207 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
208 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
212 /* select clock source */
213 ret
= snd_soc_dai_set_sysclk(cpu_dai
, clk_source
, rate
,
218 /* set MCLK division for sample rate */
219 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_MCLK
,
220 S3C2410_IISMOD_384FS
);
224 /* set BCLK division for sample rate */
225 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_BCLK
,
226 S3C2410_IISMOD_32FS
);
230 /* set prescaler division for sample rate */
231 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_PRESCALER
,
232 S3C24XX_PRESCALE(div
, div
));
239 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime
*rtd
)
241 struct snd_soc_codec
*codec
= rtd
->codec
;
244 /* Add rx1950 specific widgets */
245 err
= snd_soc_dapm_new_controls(codec
, uda1380_dapm_widgets
,
246 ARRAY_SIZE(uda1380_dapm_widgets
));
251 /* Set up rx1950 specific audio path audio_mapnects */
252 err
= snd_soc_dapm_add_routes(codec
, audio_map
,
253 ARRAY_SIZE(audio_map
));
258 snd_soc_dapm_enable_pin(codec
, "Headphone Jack");
259 snd_soc_dapm_enable_pin(codec
, "Speaker");
261 snd_soc_dapm_sync(codec
);
263 snd_soc_jack_new(codec
, "Headphone Jack", SND_JACK_HEADPHONE
,
266 snd_soc_jack_add_pins(&hp_jack
, ARRAY_SIZE(hp_jack_pins
),
269 snd_soc_jack_add_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
275 static int __init
rx1950_init(void)
279 if (!machine_is_rx1950())
282 /* configure some gpios */
283 ret
= gpio_request(S3C2410_GPA(1), "speaker-power");
287 ret
= gpio_direction_output(S3C2410_GPA(1), 0);
291 s3c24xx_snd_device
= platform_device_alloc("soc-audio", -1);
292 if (!s3c24xx_snd_device
) {
297 platform_set_drvdata(s3c24xx_snd_device
, &rx1950_asoc
);
298 ret
= platform_device_add(s3c24xx_snd_device
);
301 platform_device_put(s3c24xx_snd_device
);
305 xtal
= clk_get(&s3c24xx_snd_device
->dev
, "xtal");
309 platform_device_unregister(s3c24xx_snd_device
);
319 gpio_free(S3C2410_GPA(1));
325 static void __exit
rx1950_exit(void)
327 platform_device_unregister(s3c24xx_snd_device
);
328 snd_soc_jack_free_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
331 gpio_free(S3C2410_GPA(1));
334 module_init(rx1950_init
);
335 module_exit(rx1950_exit
);
337 /* Module information */
338 MODULE_AUTHOR("Vasily Khoruzhick");
339 MODULE_DESCRIPTION("ALSA SoC RX1950");
340 MODULE_LICENSE("GPL");