1 // SPDX-License-Identifier: GPL-2.0+
3 // h1940_uda1380.c - ALSA SoC Audio Layer
5 // Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
6 // Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
8 // Based on version from Arnaud Patard <arnaud.patard@rtp-net.org>
10 #include <linux/types.h>
11 #include <linux/gpio.h>
12 #include <linux/module.h>
14 #include <sound/soc.h>
15 #include <sound/jack.h>
18 #include <asm/mach-types.h>
20 #include <mach/gpio-samsung.h>
21 #include "s3c24xx-i2s.h"
23 static const unsigned int rates
[] = {
29 static const struct snd_pcm_hw_constraint_list hw_rates
= {
30 .count
= ARRAY_SIZE(rates
),
34 static struct snd_soc_jack hp_jack
;
36 static struct snd_soc_jack_pin hp_jack_pins
[] = {
38 .pin
= "Headphone Jack",
39 .mask
= SND_JACK_HEADPHONE
,
43 .mask
= SND_JACK_HEADPHONE
,
48 static struct snd_soc_jack_gpio hp_jack_gpios
[] = {
50 .gpio
= S3C2410_GPG(4),
52 .report
= SND_JACK_HEADPHONE
,
58 static int h1940_startup(struct snd_pcm_substream
*substream
)
60 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
62 return snd_pcm_hw_constraint_list(runtime
, 0,
63 SNDRV_PCM_HW_PARAM_RATE
,
67 static int h1940_hw_params(struct snd_pcm_substream
*substream
,
68 struct snd_pcm_hw_params
*params
)
70 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
71 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
74 unsigned int rate
= params_rate(params
);
80 div
= s3c24xx_i2s_get_clockrate() / (384 * rate
);
81 if (s3c24xx_i2s_get_clockrate() % (384 * rate
) > (192 * rate
))
85 dev_err(rtd
->dev
, "%s: rate %d is not supported\n",
90 /* select clock source */
91 ret
= snd_soc_dai_set_sysclk(cpu_dai
, S3C24XX_CLKSRC_PCLK
, rate
,
96 /* set MCLK division for sample rate */
97 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_MCLK
,
98 S3C2410_IISMOD_384FS
);
102 /* set BCLK division for sample rate */
103 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_BCLK
,
104 S3C2410_IISMOD_32FS
);
108 /* set prescaler division for sample rate */
109 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C24XX_DIV_PRESCALER
,
110 S3C24XX_PRESCALE(div
, div
));
117 static struct snd_soc_ops h1940_ops
= {
118 .startup
= h1940_startup
,
119 .hw_params
= h1940_hw_params
,
122 static int h1940_spk_power(struct snd_soc_dapm_widget
*w
,
123 struct snd_kcontrol
*kcontrol
, int event
)
125 if (SND_SOC_DAPM_EVENT_ON(event
))
126 gpio_set_value(S3C_GPIO_END
+ 9, 1);
128 gpio_set_value(S3C_GPIO_END
+ 9, 0);
133 /* h1940 machine dapm widgets */
134 static const struct snd_soc_dapm_widget uda1380_dapm_widgets
[] = {
135 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
136 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
137 SND_SOC_DAPM_SPK("Speaker", h1940_spk_power
),
140 /* h1940 machine audio_map */
141 static const struct snd_soc_dapm_route audio_map
[] = {
142 /* headphone connected to VOUTLHP, VOUTRHP */
143 {"Headphone Jack", NULL
, "VOUTLHP"},
144 {"Headphone Jack", NULL
, "VOUTRHP"},
146 /* ext speaker connected to VOUTL, VOUTR */
147 {"Speaker", NULL
, "VOUTL"},
148 {"Speaker", NULL
, "VOUTR"},
150 /* mic is connected to VINM */
151 {"VINM", NULL
, "Mic Jack"},
154 static struct platform_device
*s3c24xx_snd_device
;
156 static int h1940_uda1380_init(struct snd_soc_pcm_runtime
*rtd
)
158 snd_soc_card_jack_new(rtd
->card
, "Headphone Jack", SND_JACK_HEADPHONE
,
159 &hp_jack
, hp_jack_pins
, ARRAY_SIZE(hp_jack_pins
));
161 snd_soc_jack_add_gpios(&hp_jack
, ARRAY_SIZE(hp_jack_gpios
),
167 /* s3c24xx digital audio interface glue - connects codec <--> CPU */
168 SND_SOC_DAILINK_DEFS(uda1380
,
169 DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")),
170 DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-001a", "uda1380-hifi")),
171 DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis")));
173 static struct snd_soc_dai_link h1940_uda1380_dai
[] = {
176 .stream_name
= "UDA1380 Duplex",
177 .init
= h1940_uda1380_init
,
178 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
179 SND_SOC_DAIFMT_CBS_CFS
,
181 SND_SOC_DAILINK_REG(uda1380
),
185 static struct snd_soc_card h1940_asoc
= {
187 .owner
= THIS_MODULE
,
188 .dai_link
= h1940_uda1380_dai
,
189 .num_links
= ARRAY_SIZE(h1940_uda1380_dai
),
191 .dapm_widgets
= uda1380_dapm_widgets
,
192 .num_dapm_widgets
= ARRAY_SIZE(uda1380_dapm_widgets
),
193 .dapm_routes
= audio_map
,
194 .num_dapm_routes
= ARRAY_SIZE(audio_map
),
197 static int __init
h1940_init(void)
201 if (!machine_is_h1940())
204 /* configure some gpios */
205 ret
= gpio_request(S3C_GPIO_END
+ 9, "speaker-power");
209 ret
= gpio_direction_output(S3C_GPIO_END
+ 9, 0);
213 s3c24xx_snd_device
= platform_device_alloc("soc-audio", -1);
214 if (!s3c24xx_snd_device
) {
219 platform_set_drvdata(s3c24xx_snd_device
, &h1940_asoc
);
220 ret
= platform_device_add(s3c24xx_snd_device
);
228 platform_device_put(s3c24xx_snd_device
);
230 gpio_free(S3C_GPIO_END
+ 9);
236 static void __exit
h1940_exit(void)
238 platform_device_unregister(s3c24xx_snd_device
);
239 gpio_free(S3C_GPIO_END
+ 9);
242 module_init(h1940_init
);
243 module_exit(h1940_exit
);
245 /* Module information */
246 MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick");
247 MODULE_DESCRIPTION("ALSA SoC H1940");
248 MODULE_LICENSE("GPL");