]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - sound/soc/samsung/rx1950_uda1380.c
sound: Add module.h to the previously silent sound users
[mirror_ubuntu-zesty-kernel.git] / sound / soc / samsung / rx1950_uda1380.c
CommitLineData
81d97802
VK
1/*
2 * rx1950.c -- ALSA Soc Audio Layer
3 *
4 * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com>
5 *
6 * Based on smdk2440.c and magician.c
7 *
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>
12 *
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.
17 *
18 */
19
b8487928 20#include <linux/types.h>
81d97802 21#include <linux/gpio.h>
da155d5b 22#include <linux/module.h>
81d97802 23
81d97802 24#include <sound/soc.h>
81d97802
VK
25#include <sound/jack.h>
26
27#include <plat/regs-iis.h>
dedc3cf5
VK
28#include <asm/mach-types.h>
29
81d97802 30#include "s3c24xx-i2s.h"
81d97802
VK
31
32static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd);
33static int rx1950_startup(struct snd_pcm_substream *substream);
34static int rx1950_hw_params(struct snd_pcm_substream *substream,
35 struct snd_pcm_hw_params *params);
36static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
37 struct snd_kcontrol *kcontrol, int event);
38
39static unsigned int rates[] = {
40 16000,
41 44100,
42 48000,
81d97802
VK
43};
44
45static struct snd_pcm_hw_constraint_list hw_rates = {
46 .count = ARRAY_SIZE(rates),
47 .list = rates,
48 .mask = 0,
49};
50
51static struct snd_soc_jack hp_jack;
52
53static struct snd_soc_jack_pin hp_jack_pins[] = {
54 {
55 .pin = "Headphone Jack",
56 .mask = SND_JACK_HEADPHONE,
57 },
58 {
59 .pin = "Speaker",
60 .mask = SND_JACK_HEADPHONE,
61 .invert = 1,
62 },
63};
64
65static struct snd_soc_jack_gpio hp_jack_gpios[] = {
66 [0] = {
67 .gpio = S3C2410_GPG(12),
68 .name = "hp-gpio",
69 .report = SND_JACK_HEADPHONE,
70 .invert = 1,
71 .debounce_time = 200,
72 },
73};
74
75static struct snd_soc_ops rx1950_ops = {
76 .startup = rx1950_startup,
77 .hw_params = rx1950_hw_params,
78};
79
80/* s3c24xx digital audio interface glue - connects codec <--> CPU */
81static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
82 {
83 .name = "uda1380",
84 .stream_name = "UDA1380 Duplex",
85 .cpu_dai_name = "s3c24xx-iis",
86 .codec_dai_name = "uda1380-hifi",
87 .init = rx1950_uda1380_init,
58bb4072 88 .platform_name = "samsung-audio",
81d97802
VK
89 .codec_name = "uda1380-codec.0-001a",
90 .ops = &rx1950_ops,
91 },
92};
93
81d97802
VK
94/* rx1950 machine dapm widgets */
95static 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),
99};
100
101/* rx1950 machine audio_map */
102static const struct snd_soc_dapm_route audio_map[] = {
103 /* headphone connected to VOUTLHP, VOUTRHP */
104 {"Headphone Jack", NULL, "VOUTLHP"},
105 {"Headphone Jack", NULL, "VOUTRHP"},
106
107 /* ext speaker connected to VOUTL, VOUTR */
108 {"Speaker", NULL, "VOUTL"},
109 {"Speaker", NULL, "VOUTR"},
110
111 /* mic is connected to VINM */
112 {"VINM", NULL, "Mic Jack"},
113};
114
8ae23229
MB
115static struct snd_soc_card rx1950_asoc = {
116 .name = "rx1950",
117 .dai_link = rx1950_uda1380_dai,
118 .num_links = ARRAY_SIZE(rx1950_uda1380_dai),
119
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),
124};
125
81d97802 126static struct platform_device *s3c24xx_snd_device;
81d97802
VK
127
128static int rx1950_startup(struct snd_pcm_substream *substream)
129{
130 struct snd_pcm_runtime *runtime = substream->runtime;
131
132 runtime->hw.rate_min = hw_rates.list[0];
133 runtime->hw.rate_max = hw_rates.list[hw_rates.count - 1];
134 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
135
136 return snd_pcm_hw_constraint_list(runtime, 0,
137 SNDRV_PCM_HW_PARAM_RATE,
138 &hw_rates);
139}
140
141static int rx1950_spk_power(struct snd_soc_dapm_widget *w,
142 struct snd_kcontrol *kcontrol, int event)
143{
144 if (SND_SOC_DAPM_EVENT_ON(event))
145 gpio_set_value(S3C2410_GPA(1), 1);
146 else
147 gpio_set_value(S3C2410_GPA(1), 0);
148
149 return 0;
150}
151
152static int rx1950_hw_params(struct snd_pcm_substream *substream,
153 struct snd_pcm_hw_params *params)
154{
155 struct snd_soc_pcm_runtime *rtd = substream->private_data;
156 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
157 struct snd_soc_dai *codec_dai = rtd->codec_dai;
158 int div;
159 int ret;
160 unsigned int rate = params_rate(params);
161 int clk_source, fs_mode;
162
163 switch (rate) {
164 case 16000:
165 case 48000:
166 clk_source = S3C24XX_CLKSRC_PCLK;
1fdc7dd5
VK
167 fs_mode = S3C2410_IISMOD_256FS;
168 div = s3c24xx_i2s_get_clockrate() / (256 * rate);
169 if (s3c24xx_i2s_get_clockrate() % (256 * rate) > (128 * rate))
81d97802
VK
170 div++;
171 break;
172 case 44100:
173 case 88200:
174 clk_source = S3C24XX_CLKSRC_MPLL;
ccb3b84f
VK
175 fs_mode = S3C2410_IISMOD_384FS;
176 div = 1;
81d97802
VK
177 break;
178 default:
179 printk(KERN_ERR "%s: rate %d is not supported\n",
180 __func__, rate);
181 return -EINVAL;
182 }
183
184 /* set codec DAI configuration */
185 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
186 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
187 if (ret < 0)
188 return ret;
189
190 /* set cpu DAI configuration */
191 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
192 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
193 if (ret < 0)
194 return ret;
195
196 /* select clock source */
197 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
198 SND_SOC_CLOCK_OUT);
199 if (ret < 0)
200 return ret;
201
202 /* set MCLK division for sample rate */
203 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
ccb3b84f 204 fs_mode);
81d97802
VK
205 if (ret < 0)
206 return ret;
207
208 /* set BCLK division for sample rate */
209 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_BCLK,
210 S3C2410_IISMOD_32FS);
211 if (ret < 0)
212 return ret;
213
214 /* set prescaler division for sample rate */
215 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
216 S3C24XX_PRESCALE(div, div));
217 if (ret < 0)
218 return ret;
219
220 return 0;
221}
222
223static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd)
224{
225 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 226 struct snd_soc_dapm_context *dapm = &codec->dapm;
81d97802
VK
227 int err;
228
ce6120cc
LG
229 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
230 snd_soc_dapm_enable_pin(dapm, "Speaker");
b60fc60c 231 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
81d97802 232
81d97802
VK
233 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
234 &hp_jack);
235
236 snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
237 hp_jack_pins);
238
239 snd_soc_jack_add_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
240 hp_jack_gpios);
241
242 return 0;
243}
244
245static int __init rx1950_init(void)
246{
247 int ret;
248
dedc3cf5
VK
249 if (!machine_is_rx1950())
250 return -ENODEV;
251
81d97802
VK
252 /* configure some gpios */
253 ret = gpio_request(S3C2410_GPA(1), "speaker-power");
254 if (ret)
255 goto err_gpio;
256
257 ret = gpio_direction_output(S3C2410_GPA(1), 0);
258 if (ret)
259 goto err_gpio_conf;
260
261 s3c24xx_snd_device = platform_device_alloc("soc-audio", -1);
262 if (!s3c24xx_snd_device) {
263 ret = -ENOMEM;
264 goto err_plat_alloc;
265 }
266
267 platform_set_drvdata(s3c24xx_snd_device, &rx1950_asoc);
268 ret = platform_device_add(s3c24xx_snd_device);
269
270 if (ret) {
271 platform_device_put(s3c24xx_snd_device);
272 goto err_plat_add;
273 }
274
81d97802
VK
275 return 0;
276
81d97802
VK
277err_plat_add:
278err_plat_alloc:
279err_gpio_conf:
280 gpio_free(S3C2410_GPA(1));
281
282err_gpio:
283 return ret;
284}
285
286static void __exit rx1950_exit(void)
287{
288 platform_device_unregister(s3c24xx_snd_device);
289 snd_soc_jack_free_gpios(&hp_jack, ARRAY_SIZE(hp_jack_gpios),
290 hp_jack_gpios);
81d97802
VK
291 gpio_free(S3C2410_GPA(1));
292}
293
294module_init(rx1950_init);
295module_exit(rx1950_exit);
296
297/* Module information */
298MODULE_AUTHOR("Vasily Khoruzhick");
299MODULE_DESCRIPTION("ALSA SoC RX1950");
300MODULE_LICENSE("GPL");