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>
22 #include <linux/module.h>
24 #include <sound/soc.h>
25 #include <sound/jack.h>
28 #include <asm/mach-types.h>
30 #include "s3c24xx-i2s.h"
32 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime
*rtd
);
33 static int rx1950_startup(struct snd_pcm_substream
*substream
);
34 static int rx1950_hw_params(struct snd_pcm_substream
*substream
,
35 struct snd_pcm_hw_params
*params
);
36 static int rx1950_spk_power(struct snd_soc_dapm_widget
*w
,
37 struct snd_kcontrol
*kcontrol
, int event
);
39 static unsigned int rates
[] = {
45 static struct snd_pcm_hw_constraint_list hw_rates
= {
46 .count
= ARRAY_SIZE(rates
),
51 static struct snd_soc_jack hp_jack
;
53 static struct snd_soc_jack_pin hp_jack_pins
[] = {
55 .pin
= "Headphone Jack",
56 .mask
= SND_JACK_HEADPHONE
,
60 .mask
= SND_JACK_HEADPHONE
,
65 static struct snd_soc_jack_gpio hp_jack_gpios
[] = {
67 .gpio
= S3C2410_GPG(12),
69 .report
= SND_JACK_HEADPHONE
,
75 static struct snd_soc_ops rx1950_ops
= {
76 .startup
= rx1950_startup
,
77 .hw_params
= rx1950_hw_params
,
80 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
81 static struct snd_soc_dai_link rx1950_uda1380_dai
[] = {
84 .stream_name
= "UDA1380 Duplex",
85 .cpu_dai_name
= "s3c24xx-iis",
86 .codec_dai_name
= "uda1380-hifi",
87 .init
= rx1950_uda1380_init
,
88 .platform_name
= "s3c24xx-iis",
89 .codec_name
= "uda1380-codec.0-001a",
94 /* rx1950 machine dapm widgets */
95 static const struct snd_soc_dapm_widget uda1380_dapm_widgets
[] = {
96 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
97 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
98 SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power
),
101 /* rx1950 machine audio_map */
102 static const struct snd_soc_dapm_route audio_map
[] = {
103 /* headphone connected to VOUTLHP, VOUTRHP */
104 {"Headphone Jack", NULL
, "VOUTLHP"},
105 {"Headphone Jack", NULL
, "VOUTRHP"},
107 /* ext speaker connected to VOUTL, VOUTR */
108 {"Speaker", NULL
, "VOUTL"},
109 {"Speaker", NULL
, "VOUTR"},
111 /* mic is connected to VINM */
112 {"VINM", NULL
, "Mic Jack"},
115 static struct snd_soc_card rx1950_asoc
= {
117 .owner
= THIS_MODULE
,
118 .dai_link
= rx1950_uda1380_dai
,
119 .num_links
= ARRAY_SIZE(rx1950_uda1380_dai
),
121 .dapm_widgets
= uda1380_dapm_widgets
,
122 .num_dapm_widgets
= ARRAY_SIZE(uda1380_dapm_widgets
),
123 .dapm_routes
= audio_map
,
124 .num_dapm_routes
= ARRAY_SIZE(audio_map
),
127 static struct platform_device
*s3c24xx_snd_device
;
129 static int rx1950_startup(struct snd_pcm_substream
*substream
)
131 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
133 runtime
->hw
.rate_min
= hw_rates
.list
[0];
134 runtime
->hw
.rate_max
= hw_rates
.list
[hw_rates
.count
- 1];
135 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
137 return snd_pcm_hw_constraint_list(runtime
, 0,
138 SNDRV_PCM_HW_PARAM_RATE
,
142 static int rx1950_spk_power(struct snd_soc_dapm_widget
*w
,
143 struct snd_kcontrol
*kcontrol
, int event
)
145 if (SND_SOC_DAPM_EVENT_ON(event
))
146 gpio_set_value(S3C2410_GPA(1), 1);
148 gpio_set_value(S3C2410_GPA(1), 0);
153 static int rx1950_hw_params(struct snd_pcm_substream
*substream
,
154 struct snd_pcm_hw_params
*params
)
156 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
157 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
158 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
161 unsigned int rate
= params_rate(params
);
162 int clk_source
, fs_mode
;
167 clk_source
= S3C24XX_CLKSRC_PCLK
;
168 fs_mode
= S3C2410_IISMOD_256FS
;
169 div
= s3c24xx_i2s_get_clockrate() / (256 * rate
);
170 if (s3c24xx_i2s_get_clockrate() % (256 * rate
) > (128 * rate
))
175 clk_source
= S3C24XX_CLKSRC_MPLL
;
176 fs_mode
= S3C2410_IISMOD_384FS
;
180 printk(KERN_ERR
"%s: rate %d is not supported\n",
185 /* set codec DAI configuration */
186 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_I2S
|
187 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
191 /* set cpu DAI configuration */
192 ret
= snd_soc_dai_set_fmt(cpu_dai
, SND_SOC_DAIFMT_I2S
|
193 SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS
);
197 /* select clock source */
198 ret
= snd_soc_dai_set_sysclk(cpu_dai
, clk_source
, rate
,
203 /* set MCLK division for sample rate */
204 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_MCLK
,
209 /* set BCLK division for sample rate */
210 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_BCLK
,
211 S3C2410_IISMOD_32FS
);
215 /* set prescaler division for sample rate */
216 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_PRESCALER
,
217 S3C24XX_PRESCALE(div
, div
));
224 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime
*rtd
)
226 struct snd_soc_codec
*codec
= rtd
->codec
;
227 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
230 snd_soc_dapm_enable_pin(dapm
, "Headphone Jack");
231 snd_soc_dapm_enable_pin(dapm
, "Speaker");
232 snd_soc_dapm_enable_pin(dapm
, "Mic Jack");
234 snd_soc_jack_new(codec
, "Headphone Jack", SND_JACK_HEADPHONE
,
237 snd_soc_jack_add_pins(&hp_jack
, ARRAY_SIZE(hp_jack_pins
),
240 snd_soc_jack_add_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
246 static int __init
rx1950_init(void)
250 if (!machine_is_rx1950())
253 /* configure some gpios */
254 ret
= gpio_request(S3C2410_GPA(1), "speaker-power");
258 ret
= gpio_direction_output(S3C2410_GPA(1), 0);
262 s3c24xx_snd_device
= platform_device_alloc("soc-audio", -1);
263 if (!s3c24xx_snd_device
) {
268 platform_set_drvdata(s3c24xx_snd_device
, &rx1950_asoc
);
269 ret
= platform_device_add(s3c24xx_snd_device
);
272 platform_device_put(s3c24xx_snd_device
);
281 gpio_free(S3C2410_GPA(1));
287 static void __exit
rx1950_exit(void)
289 platform_device_unregister(s3c24xx_snd_device
);
290 snd_soc_jack_free_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
292 gpio_free(S3C2410_GPA(1));
295 module_init(rx1950_init
);
296 module_exit(rx1950_exit
);
298 /* Module information */
299 MODULE_AUTHOR("Vasily Khoruzhick");
300 MODULE_DESCRIPTION("ALSA SoC RX1950");
301 MODULE_LICENSE("GPL");