ASoC: Samsung: Generalize Kconfig symbols
[deliverable/linux.git] / sound / soc / s3c24xx / jive_wm8750.c
CommitLineData
3093e48c
BD
1/* sound/soc/s3c24xx/jive_wm8750.c
2 *
3 * Copyright 2007,2008 Simtec Electronics
4 *
5 * Based on sound/soc/pxa/spitz.c
6 * Copyright 2005 Wolfson Microelectronics PLC.
7 * Copyright 2005 Openedhand Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/timer.h>
17#include <linux/interrupt.h>
18#include <linux/platform_device.h>
19#include <linux/clk.h>
20
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
3093e48c
BD
24
25#include <asm/mach-types.h>
26
4b640cf3 27#include "dma.h"
3093e48c
BD
28#include "s3c2412-i2s.h"
29
30#include "../codecs/wm8750.h"
31
32static const struct snd_soc_dapm_route audio_map[] = {
33 { "Headphone Jack", NULL, "LOUT1" },
34 { "Headphone Jack", NULL, "ROUT1" },
35 { "Internal Speaker", NULL, "LOUT2" },
36 { "Internal Speaker", NULL, "ROUT2" },
37 { "LINPUT1", NULL, "Line Input" },
38 { "RINPUT1", NULL, "Line Input" },
39};
40
41static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
42 SND_SOC_DAPM_HP("Headphone Jack", NULL),
43 SND_SOC_DAPM_SPK("Internal Speaker", NULL),
44 SND_SOC_DAPM_LINE("Line In", NULL),
45};
46
3093e48c
BD
47static int jive_hw_params(struct snd_pcm_substream *substream,
48 struct snd_pcm_hw_params *params)
49{
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
f0fba2ad
LG
51 struct snd_soc_dai *codec_dai = rtd->codec_dai;
52 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
dc85447b 53 struct s3c_i2sv2_rate_calc div;
3093e48c
BD
54 unsigned int clk = 0;
55 int ret = 0;
56
57 switch (params_rate(params)) {
58 case 8000:
59 case 16000:
60 case 48000:
61 case 96000:
62 clk = 12288000;
63 break;
64 case 11025:
65 case 22050:
66 case 44100:
67 clk = 11289600;
68 break;
69 }
70
01c4cad4 71 s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
57282427 72 s3c_i2sv2_get_clock(cpu_dai));
3093e48c
BD
73
74 /* set codec DAI configuration */
75 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
76 SND_SOC_DAIFMT_NB_NF |
77 SND_SOC_DAIFMT_CBS_CFS);
78 if (ret < 0)
79 return ret;
80
81 /* set cpu DAI configuration */
82 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
83 SND_SOC_DAIFMT_NB_NF |
84 SND_SOC_DAIFMT_CBS_CFS);
85 if (ret < 0)
86 return ret;
87
88 /* set the codec system clock for DAC and ADC */
89 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
90 SND_SOC_CLOCK_IN);
91 if (ret < 0)
92 return ret;
93
94 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
95 if (ret < 0)
96 return ret;
97
98 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
99 div.clk_div - 1);
100 if (ret < 0)
101 return ret;
102
103 return 0;
104}
105
106static struct snd_soc_ops jive_ops = {
3093e48c
BD
107 .hw_params = jive_hw_params,
108};
109
f0fba2ad 110static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd)
3093e48c 111{
f0fba2ad 112 struct snd_soc_codec *codec = rtd->codec;
ce6120cc 113 struct snd_soc_dapm_context *dapm = &codec->dapm;
3093e48c
BD
114 int err;
115
116 /* These endpoints are not being used. */
ce6120cc
LG
117 snd_soc_dapm_nc_pin(dapm, "LINPUT2");
118 snd_soc_dapm_nc_pin(dapm, "RINPUT2");
119 snd_soc_dapm_nc_pin(dapm, "LINPUT3");
120 snd_soc_dapm_nc_pin(dapm, "RINPUT3");
121 snd_soc_dapm_nc_pin(dapm, "OUT3");
122 snd_soc_dapm_nc_pin(dapm, "MONO");
3093e48c
BD
123
124 /* Add jive specific widgets */
ce6120cc 125 err = snd_soc_dapm_new_controls(dapm, wm8750_dapm_widgets,
3093e48c
BD
126 ARRAY_SIZE(wm8750_dapm_widgets));
127 if (err) {
128 printk(KERN_ERR "%s: failed to add widgets (%d)\n",
129 __func__, err);
130 return err;
131 }
132
ce6120cc
LG
133 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
134 snd_soc_dapm_sync(dapm);
3093e48c
BD
135
136 return 0;
137}
138
139static struct snd_soc_dai_link jive_dai = {
140 .name = "wm8750",
141 .stream_name = "WM8750",
f0fba2ad
LG
142 .cpu_dai_name = "s3c2412-i2s",
143 .codec_dai_name = "wm8750-hifi",
58bb4072 144 .platform_name = "samsung-audio",
f0fba2ad 145 .codec_name = "wm8750-codec.0-0x1a",
3093e48c
BD
146 .init = jive_wm8750_init,
147 .ops = &jive_ops,
148};
149
150/* jive audio machine driver */
01c4cad4 151static struct snd_soc_card snd_soc_machine_jive = {
3093e48c
BD
152 .name = "Jive",
153 .dai_link = &jive_dai,
154 .num_links = 1,
155};
156
3093e48c
BD
157static struct platform_device *jive_snd_device;
158
159static int __init jive_init(void)
160{
161 int ret;
162
163 if (!machine_is_jive())
164 return 0;
165
166 printk("JIVE WM8750 Audio support\n");
167
168 jive_snd_device = platform_device_alloc("soc-audio", -1);
169 if (!jive_snd_device)
170 return -ENOMEM;
171
f0fba2ad 172 platform_set_drvdata(jive_snd_device, &snd_soc_machine_jive);
3093e48c
BD
173 ret = platform_device_add(jive_snd_device);
174
175 if (ret)
176 platform_device_put(jive_snd_device);
177
178 return ret;
179}
180
181static void __exit jive_exit(void)
182{
183 platform_device_unregister(jive_snd_device);
184}
185
186module_init(jive_init);
187module_exit(jive_exit);
188
189MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
190MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
191MODULE_LICENSE("GPL");
This page took 0.070148 seconds and 5 git commands to generate.