1 // SPDX-License-Identifier: GPL-2.0+
3 // rx1950.c - ALSA SoC Audio Layer
5 // Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
7 // Based on smdk2440.c and magician.c
9 // Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com
10 // Philipp Zabel <philipp.zabel@gmail.com>
11 // Denis Grigoriev <dgreenday@gmail.com>
12 // Vasily Khoruzhick <anarsoul@gmail.com>
14 #include <linux/types.h>
15 #include <linux/gpio.h>
16 #include <linux/module.h>
18 #include <sound/soc.h>
19 #include <sound/jack.h>
21 #include <mach/gpio-samsung.h>
23 #include <asm/mach-types.h>
25 #include "s3c24xx-i2s.h"
27 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd);
28 static int rx1950_startup(struct snd_pcm_substream *substream);
29 static int rx1950_hw_params(struct snd_pcm_substream *substream,
30 struct snd_pcm_hw_params *params);
31 static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
32 struct snd_kcontrol *kcontrol, int event);
34 static const unsigned int rates[] = {
40 static const struct snd_pcm_hw_constraint_list hw_rates = {
41 .count = ARRAY_SIZE(rates),
45 static struct snd_soc_jack hp_jack;
47 static struct snd_soc_jack_pin hp_jack_pins[] = {
49 .pin = "Headphone Jack",
50 .mask = SND_JACK_HEADPHONE,
54 .mask = SND_JACK_HEADPHONE,
59 static struct snd_soc_jack_gpio hp_jack_gpios[] = {
61 .gpio = S3C2410_GPG(12),
63 .report = SND_JACK_HEADPHONE,
69 static struct snd_soc_ops rx1950_ops = {
70 .startup = rx1950_startup,
71 .hw_params = rx1950_hw_params,
74 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
75 static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
78 .stream_name = "UDA1380 Duplex",
79 .cpu_dai_name = "s3c24xx-iis",
80 .codec_dai_name = "uda1380-hifi",
81 .init = rx1950_uda1380_init,
82 .platform_name = "s3c24xx-iis",
83 .codec_name = "uda1380-codec.0-001a",
84 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
85 SND_SOC_DAIFMT_CBS_CFS,
90 /* rx1950 machine dapm widgets */
91 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
92 SND_SOC_DAPM_HP("Headphone Jack", NULL),
93 SND_SOC_DAPM_MIC("Mic Jack", NULL),
94 SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power),
97 /* rx1950 machine audio_map */
98 static const struct snd_soc_dapm_route audio_map[] = {
99 /* headphone connected to VOUTLHP, VOUTRHP */
100 {"Headphone Jack", NULL, "VOUTLHP"},
101 {"Headphone Jack", NULL, "VOUTRHP"},
103 /* ext speaker connected to VOUTL, VOUTR */
104 {"Speaker", NULL, "VOUTL"},
105 {"Speaker", NULL, "VOUTR"},
107 /* mic is connected to VINM */
108 {"VINM", NULL, "Mic Jack"},
111 static struct snd_soc_card rx1950_asoc = {
113 .owner = THIS_MODULE,
114 .dai_link = rx1950_uda1380_dai,
115 .num_links = ARRAY_SIZE(rx1950_uda1380_dai),
117 .dapm_widgets = uda1380_dapm_widgets,
118 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
119 .dapm_routes = audio_map,
120 .num_dapm_routes = ARRAY_SIZE(audio_map),
123 static struct platform_device *s3c24xx_snd_device;
125 static int rx1950_startup(struct snd_pcm_substream *substream)
127 struct snd_pcm_runtime *runtime = substream->runtime;
129 return snd_pcm_hw_constraint_list(runtime, 0,
130 SNDRV_PCM_HW_PARAM_RATE,
134 static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
135 struct snd_kcontrol *kcontrol, int event)
137 if (SND_SOC_DAPM_EVENT_ON(event))
138 gpio_set_value(S3C2410_GPA(1), 1);
140 gpio_set_value(S3C2410_GPA(1), 0);
145 static int rx1950_hw_params(struct snd_pcm_substream *substream,
146 struct snd_pcm_hw_params *params)
148 struct snd_soc_pcm_runtime *rtd = substream->private_data;
149 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
152 unsigned int rate = params_rate(params);
153 int clk_source, fs_mode;
158 clk_source = S3C24XX_CLKSRC_PCLK;
159 fs_mode = S3C2410_IISMOD_256FS;
160 div = s3c24xx_i2s_get_clockrate() / (256 * rate);
161 if (s3c24xx_i2s_get_clockrate() % (256 * rate) > (128 * rate))
166 clk_source = S3C24XX_CLKSRC_MPLL;
167 fs_mode = S3C2410_IISMOD_384FS;
171 printk(KERN_ERR "%s: rate %d is not supported\n",
176 /* select clock source */
177 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
182 /* set MCLK division for sample rate */
183 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
188 /* set BCLK division for sample rate */
189 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
190 S3C2410_IISMOD_32FS);
194 /* set prescaler division for sample rate */
195 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
196 S3C24XX_PRESCALE(div, div));
203 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
205 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
206 &hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
208 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
214 static int __init rx1950_init(void)
218 if (!machine_is_rx1950())
221 /* configure some gpios */
222 ret = gpio_request(S3C2410_GPA(1), "speaker-power");
226 ret = gpio_direction_output(S3C2410_GPA(1), 0);
230 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
231 if (!s3c24xx_snd_device) {
236 platform_set_drvdata(s3c24xx_snd_device, &rx1950_asoc);
237 ret = platform_device_add(s3c24xx_snd_device);
240 platform_device_put(s3c24xx_snd_device);
249 gpio_free(S3C2410_GPA(1));
255 static void __exit rx1950_exit(void)
257 platform_device_unregister(s3c24xx_snd_device);
258 gpio_free(S3C2410_GPA(1));
261 module_init(rx1950_init);
262 module_exit(rx1950_exit);
264 /* Module information */
265 MODULE_AUTHOR("Vasily Khoruzhick");
266 MODULE_DESCRIPTION("ALSA SoC RX1950");
267 MODULE_LICENSE("GPL");