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>
23 #include <sound/soc.h>
24 #include <sound/jack.h>
26 #include <plat/regs-iis.h>
27 #include <asm/mach-types.h>
29 #include "s3c24xx-i2s.h"
31 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime
*rtd
);
32 static int rx1950_startup(struct snd_pcm_substream
*substream
);
33 static int rx1950_hw_params(struct snd_pcm_substream
*substream
,
34 struct snd_pcm_hw_params
*params
);
35 static int rx1950_spk_power(struct snd_soc_dapm_widget
*w
,
36 struct snd_kcontrol
*kcontrol
, int event
);
38 static unsigned int rates
[] = {
44 static struct snd_pcm_hw_constraint_list hw_rates
= {
45 .count
= ARRAY_SIZE(rates
),
50 static struct snd_soc_jack hp_jack
;
52 static struct snd_soc_jack_pin hp_jack_pins
[] = {
54 .pin
= "Headphone Jack",
55 .mask
= SND_JACK_HEADPHONE
,
59 .mask
= SND_JACK_HEADPHONE
,
64 static struct snd_soc_jack_gpio hp_jack_gpios
[] = {
66 .gpio
= S3C2410_GPG(12),
68 .report
= SND_JACK_HEADPHONE
,
74 static struct snd_soc_ops rx1950_ops
= {
75 .startup
= rx1950_startup
,
76 .hw_params
= rx1950_hw_params
,
79 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
80 static struct snd_soc_dai_link rx1950_uda1380_dai
[] = {
83 .stream_name
= "UDA1380 Duplex",
84 .cpu_dai_name
= "s3c24xx-iis",
85 .codec_dai_name
= "uda1380-hifi",
86 .init
= rx1950_uda1380_init
,
87 .platform_name
= "samsung-audio",
88 .codec_name
= "uda1380-codec.0-001a",
93 static struct snd_soc_card rx1950_asoc
= {
95 .dai_link
= rx1950_uda1380_dai
,
96 .num_links
= ARRAY_SIZE(rx1950_uda1380_dai
),
99 /* rx1950 machine dapm widgets */
100 static const struct snd_soc_dapm_widget uda1380_dapm_widgets
[] = {
101 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
102 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
103 SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power
),
106 /* rx1950 machine audio_map */
107 static const struct snd_soc_dapm_route audio_map
[] = {
108 /* headphone connected to VOUTLHP, VOUTRHP */
109 {"Headphone Jack", NULL
, "VOUTLHP"},
110 {"Headphone Jack", NULL
, "VOUTRHP"},
112 /* ext speaker connected to VOUTL, VOUTR */
113 {"Speaker", NULL
, "VOUTL"},
114 {"Speaker", NULL
, "VOUTR"},
116 /* mic is connected to VINM */
117 {"VINM", NULL
, "Mic Jack"},
120 static struct platform_device
*s3c24xx_snd_device
;
122 static int rx1950_startup(struct snd_pcm_substream
*substream
)
124 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
126 runtime
->hw
.rate_min
= hw_rates
.list
[0];
127 runtime
->hw
.rate_max
= hw_rates
.list
[hw_rates
.count
- 1];
128 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
130 return snd_pcm_hw_constraint_list(runtime
, 0,
131 SNDRV_PCM_HW_PARAM_RATE
,
135 static int rx1950_spk_power(struct snd_soc_dapm_widget
*w
,
136 struct snd_kcontrol
*kcontrol
, int event
)
138 if (SND_SOC_DAPM_EVENT_ON(event
))
139 gpio_set_value(S3C2410_GPA(1), 1);
141 gpio_set_value(S3C2410_GPA(1), 0);
146 static int rx1950_hw_params(struct snd_pcm_substream
*substream
,
147 struct snd_pcm_hw_params
*params
)
149 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
150 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
151 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
154 unsigned int rate
= params_rate(params
);
155 int clk_source
, fs_mode
;
160 clk_source
= S3C24XX_CLKSRC_PCLK
;
161 fs_mode
= S3C2410_IISMOD_256FS
;
162 div
= s3c24xx_i2s_get_clockrate() / (256 * rate
);
163 if (s3c24xx_i2s_get_clockrate() % (256 * rate
) > (128 * rate
))
168 clk_source
= S3C24XX_CLKSRC_MPLL
;
169 fs_mode
= S3C2410_IISMOD_384FS
;
173 printk(KERN_ERR
"%s: rate %d is not supported\n",
178 /* set codec DAI configuration */
179 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
180 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
184 /* set cpu DAI configuration */
185 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
186 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
190 /* select clock source */
191 ret
= snd_soc_dai_set_sysclk(cpu_dai
, clk_source
, rate
,
196 /* set MCLK division for sample rate */
197 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_MCLK
,
202 /* set BCLK division for sample rate */
203 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_BCLK
,
204 S3C2410_IISMOD_32FS
);
208 /* set prescaler division for sample rate */
209 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_PRESCALER
,
210 S3C24XX_PRESCALE(div
, div
));
217 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime
*rtd
)
219 struct snd_soc_codec
*codec
= rtd
->codec
;
220 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
223 /* Add rx1950 specific widgets */
224 err
= snd_soc_dapm_new_controls(dapm
, uda1380_dapm_widgets
,
225 ARRAY_SIZE(uda1380_dapm_widgets
));
230 /* Set up rx1950 specific audio path audio_mapnects */
231 err
= snd_soc_dapm_add_routes(dapm
, audio_map
,
232 ARRAY_SIZE(audio_map
));
237 snd_soc_dapm_enable_pin(dapm
, "Headphone Jack");
238 snd_soc_dapm_enable_pin(dapm
, "Speaker");
239 snd_soc_dapm_enable_pin(dapm
, "Mic Jack");
241 snd_soc_dapm_sync(dapm
);
243 snd_soc_jack_new(codec
, "Headphone Jack", SND_JACK_HEADPHONE
,
246 snd_soc_jack_add_pins(&hp_jack
, ARRAY_SIZE(hp_jack_pins
),
249 snd_soc_jack_add_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
255 static int __init
rx1950_init(void)
259 if (!machine_is_rx1950())
262 /* configure some gpios */
263 ret
= gpio_request(S3C2410_GPA(1), "speaker-power");
267 ret
= gpio_direction_output(S3C2410_GPA(1), 0);
271 s3c24xx_snd_device
= platform_device_alloc("soc-audio", -1);
272 if (!s3c24xx_snd_device
) {
277 platform_set_drvdata(s3c24xx_snd_device
, &rx1950_asoc
);
278 ret
= platform_device_add(s3c24xx_snd_device
);
281 platform_device_put(s3c24xx_snd_device
);
290 gpio_free(S3C2410_GPA(1));
296 static void __exit
rx1950_exit(void)
298 platform_device_unregister(s3c24xx_snd_device
);
299 snd_soc_jack_free_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
301 gpio_free(S3C2410_GPA(1));
304 module_init(rx1950_init
);
305 module_exit(rx1950_exit
);
307 /* Module information */
308 MODULE_AUTHOR("Vasily Khoruzhick");
309 MODULE_DESCRIPTION("ALSA SoC RX1950");
310 MODULE_LICENSE("GPL");