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/platform_device.h>
23 #include <linux/i2c.h>
24 #include <linux/gpio.h>
25 #include <linux/clk.h>
27 #include <sound/soc.h>
28 #include <sound/soc-dapm.h>
29 #include <sound/uda1380.h>
30 #include <sound/jack.h>
32 #include <plat/regs-iis.h>
34 #include <mach/regs-clock.h>
36 #include <asm/mach-types.h>
39 #include "s3c24xx-i2s.h"
40 #include "../codecs/uda1380.h"
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
);
49 static unsigned int rates
[] = {
56 static struct snd_pcm_hw_constraint_list hw_rates
= {
57 .count
= ARRAY_SIZE(rates
),
62 static struct snd_soc_jack hp_jack
;
64 static struct snd_soc_jack_pin hp_jack_pins
[] = {
66 .pin
= "Headphone Jack",
67 .mask
= SND_JACK_HEADPHONE
,
71 .mask
= SND_JACK_HEADPHONE
,
76 static struct snd_soc_jack_gpio hp_jack_gpios
[] = {
78 .gpio
= S3C2410_GPG(12),
80 .report
= SND_JACK_HEADPHONE
,
86 static struct snd_soc_ops rx1950_ops
= {
87 .startup
= rx1950_startup
,
88 .hw_params
= rx1950_hw_params
,
91 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
92 static struct snd_soc_dai_link rx1950_uda1380_dai
[] = {
95 .stream_name
= "UDA1380 Duplex",
96 .cpu_dai_name
= "s3c24xx-iis",
97 .codec_dai_name
= "uda1380-hifi",
98 .init
= rx1950_uda1380_init
,
99 .platform_name
= "s3c24xx-pcm-audio",
100 .codec_name
= "uda1380-codec.0-001a",
105 static struct snd_soc_card rx1950_asoc
= {
107 .dai_link
= rx1950_uda1380_dai
,
108 .num_links
= ARRAY_SIZE(rx1950_uda1380_dai
),
111 /* rx1950 machine dapm widgets */
112 static const struct snd_soc_dapm_widget uda1380_dapm_widgets
[] = {
113 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
114 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
115 SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power
),
118 /* rx1950 machine audio_map */
119 static const struct snd_soc_dapm_route audio_map
[] = {
120 /* headphone connected to VOUTLHP, VOUTRHP */
121 {"Headphone Jack", NULL
, "VOUTLHP"},
122 {"Headphone Jack", NULL
, "VOUTRHP"},
124 /* ext speaker connected to VOUTL, VOUTR */
125 {"Speaker", NULL
, "VOUTL"},
126 {"Speaker", NULL
, "VOUTR"},
128 /* mic is connected to VINM */
129 {"VINM", NULL
, "Mic Jack"},
132 static struct platform_device
*s3c24xx_snd_device
;
133 static struct clk
*xtal
;
135 static int rx1950_startup(struct snd_pcm_substream
*substream
)
137 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
139 runtime
->hw
.rate_min
= hw_rates
.list
[0];
140 runtime
->hw
.rate_max
= hw_rates
.list
[hw_rates
.count
- 1];
141 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
143 return snd_pcm_hw_constraint_list(runtime
, 0,
144 SNDRV_PCM_HW_PARAM_RATE
,
148 static int rx1950_spk_power(struct snd_soc_dapm_widget
*w
,
149 struct snd_kcontrol
*kcontrol
, int event
)
151 if (SND_SOC_DAPM_EVENT_ON(event
))
152 gpio_set_value(S3C2410_GPA(1), 1);
154 gpio_set_value(S3C2410_GPA(1), 0);
159 static int rx1950_hw_params(struct snd_pcm_substream
*substream
,
160 struct snd_pcm_hw_params
*params
)
162 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
163 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
164 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
167 unsigned int rate
= params_rate(params
);
168 int clk_source
, fs_mode
;
173 clk_source
= S3C24XX_CLKSRC_PCLK
;
174 fs_mode
= S3C2410_IISMOD_256FS
;
175 div
= s3c24xx_i2s_get_clockrate() / (256 * rate
);
176 if (s3c24xx_i2s_get_clockrate() % (256 * rate
) > (128 * rate
))
181 clk_source
= S3C24XX_CLKSRC_MPLL
;
182 fs_mode
= S3C2410_IISMOD_256FS
;
183 div
= clk_get_rate(xtal
) / (256 * rate
);
184 if (clk_get_rate(xtal
) % (256 * rate
) > (128 * rate
))
188 printk(KERN_ERR
"%s: rate %d is not supported\n",
193 /* set codec DAI configuration */
194 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
195 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
199 /* set cpu DAI configuration */
200 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
201 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
205 /* select clock source */
206 ret
= snd_soc_dai_set_sysclk(cpu_dai
, clk_source
, rate
,
211 /* set MCLK division for sample rate */
212 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_MCLK
,
213 S3C2410_IISMOD_384FS
);
217 /* set BCLK division for sample rate */
218 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_BCLK
,
219 S3C2410_IISMOD_32FS
);
223 /* set prescaler division for sample rate */
224 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_PRESCALER
,
225 S3C24XX_PRESCALE(div
, div
));
232 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime
*rtd
)
234 struct snd_soc_codec
*codec
= rtd
->codec
;
237 /* Add rx1950 specific widgets */
238 err
= snd_soc_dapm_new_controls(codec
, uda1380_dapm_widgets
,
239 ARRAY_SIZE(uda1380_dapm_widgets
));
244 /* Set up rx1950 specific audio path audio_mapnects */
245 err
= snd_soc_dapm_add_routes(codec
, audio_map
,
246 ARRAY_SIZE(audio_map
));
251 snd_soc_dapm_enable_pin(codec
, "Headphone Jack");
252 snd_soc_dapm_enable_pin(codec
, "Speaker");
254 snd_soc_dapm_sync(codec
);
256 snd_soc_jack_new(codec
, "Headphone Jack", SND_JACK_HEADPHONE
,
259 snd_soc_jack_add_pins(&hp_jack
, ARRAY_SIZE(hp_jack_pins
),
262 snd_soc_jack_add_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
268 static int __init
rx1950_init(void)
272 if (!machine_is_rx1950())
275 /* configure some gpios */
276 ret
= gpio_request(S3C2410_GPA(1), "speaker-power");
280 ret
= gpio_direction_output(S3C2410_GPA(1), 0);
284 s3c24xx_snd_device
= platform_device_alloc("soc-audio", -1);
285 if (!s3c24xx_snd_device
) {
290 platform_set_drvdata(s3c24xx_snd_device
, &rx1950_asoc
);
291 ret
= platform_device_add(s3c24xx_snd_device
);
294 platform_device_put(s3c24xx_snd_device
);
298 xtal
= clk_get(&s3c24xx_snd_device
->dev
, "xtal");
302 platform_device_unregister(s3c24xx_snd_device
);
312 gpio_free(S3C2410_GPA(1));
318 static void __exit
rx1950_exit(void)
320 platform_device_unregister(s3c24xx_snd_device
);
321 snd_soc_jack_free_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
324 gpio_free(S3C2410_GPA(1));
327 module_init(rx1950_init
);
328 module_exit(rx1950_exit
);
330 /* Module information */
331 MODULE_AUTHOR("Vasily Khoruzhick");
332 MODULE_DESCRIPTION("ALSA SoC RX1950");
333 MODULE_LICENSE("GPL");