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 SND_SOC_DAILINK_DEFS(uda1380,
76 DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")),
77 DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-001a",
79 DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis")));
81 static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
84 .stream_name = "UDA1380 Duplex",
85 .init = rx1950_uda1380_init,
86 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
87 SND_SOC_DAIFMT_CBS_CFS,
89 SND_SOC_DAILINK_REG(uda1380),
93 /* rx1950 machine dapm widgets */
94 static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = {
95 SND_SOC_DAPM_HP("Headphone Jack", NULL),
96 SND_SOC_DAPM_MIC("Mic Jack", NULL),
97 SND_SOC_DAPM_SPK("Speaker", rx1950_spk_power),
100 /* rx1950 machine audio_map */
101 static const struct snd_soc_dapm_route audio_map[] = {
102 /* headphone connected to VOUTLHP, VOUTRHP */
103 {"Headphone Jack", NULL, "VOUTLHP"},
104 {"Headphone Jack", NULL, "VOUTRHP"},
106 /* ext speaker connected to VOUTL, VOUTR */
107 {"Speaker", NULL, "VOUTL"},
108 {"Speaker", NULL, "VOUTR"},
110 /* mic is connected to VINM */
111 {"VINM", NULL, "Mic Jack"},
114 static struct snd_soc_card rx1950_asoc = {
116 .owner = THIS_MODULE,
117 .dai_link = rx1950_uda1380_dai,
118 .num_links = ARRAY_SIZE(rx1950_uda1380_dai),
120 .dapm_widgets = uda1380_dapm_widgets,
121 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
122 .dapm_routes = audio_map,
123 .num_dapm_routes = ARRAY_SIZE(audio_map),
126 static struct platform_device *s3c24xx_snd_device;
128 static int rx1950_startup(struct snd_pcm_substream *substream)
130 struct snd_pcm_runtime *runtime = substream->runtime;
132 return snd_pcm_hw_constraint_list(runtime, 0,
133 SNDRV_PCM_HW_PARAM_RATE,
137 static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
138 struct snd_kcontrol *kcontrol, int event)
140 if (SND_SOC_DAPM_EVENT_ON(event))
141 gpio_set_value(S3C2410_GPA(1), 1);
143 gpio_set_value(S3C2410_GPA(1), 0);
148 static int rx1950_hw_params(struct snd_pcm_substream *substream,
149 struct snd_pcm_hw_params *params)
151 struct snd_soc_pcm_runtime *rtd = substream->private_data;
152 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
155 unsigned int rate = params_rate(params);
156 int clk_source, fs_mode;
161 clk_source = S3C24XX_CLKSRC_PCLK;
162 fs_mode = S3C2410_IISMOD_256FS;
163 div = s3c24xx_i2s_get_clockrate() / (256 * rate);
164 if (s3c24xx_i2s_get_clockrate() % (256 * rate) > (128 * rate))
169 clk_source = S3C24XX_CLKSRC_MPLL;
170 fs_mode = S3C2410_IISMOD_384FS;
174 printk(KERN_ERR "%s: rate %d is not supported\n",
179 /* select clock source */
180 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
185 /* set MCLK division for sample rate */
186 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
191 /* set BCLK division for sample rate */
192 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
193 S3C2410_IISMOD_32FS);
197 /* set prescaler division for sample rate */
198 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
199 S3C24XX_PRESCALE(div, div));
206 static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
208 snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE,
209 &hp_jack, hp_jack_pins, ARRAY_SIZE(hp_jack_pins));
211 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
217 static int __init rx1950_init(void)
221 if (!machine_is_rx1950())
224 /* configure some gpios */
225 ret = gpio_request(S3C2410_GPA(1), "speaker-power");
229 ret = gpio_direction_output(S3C2410_GPA(1), 0);
233 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
234 if (!s3c24xx_snd_device) {
239 platform_set_drvdata(s3c24xx_snd_device, &rx1950_asoc);
240 ret = platform_device_add(s3c24xx_snd_device);
243 platform_device_put(s3c24xx_snd_device);
252 gpio_free(S3C2410_GPA(1));
258 static void __exit rx1950_exit(void)
260 platform_device_unregister(s3c24xx_snd_device);
261 gpio_free(S3C2410_GPA(1));
264 module_init(rx1950_init);
265 module_exit(rx1950_exit);
267 /* Module information */
268 MODULE_AUTHOR("Vasily Khoruzhick");
269 MODULE_DESCRIPTION("ALSA SoC RX1950");
270 MODULE_LICENSE("GPL");