MERGE-master-patchset-edits
[linux-2.6/openmoko-kernel.git] / sound / soc / s3c24xx / jive_wm8750.c
blob7dfe26ea8f40bd3f4085002a1e01aac0a23d4a36
1 /* sound/soc/s3c24xx/jive_wm8750.c
3 * Copyright 2007,2008 Simtec Electronics
5 * Based on sound/soc/pxa/spitz.c
6 * Copyright 2005 Wolfson Microelectronics PLC.
7 * Copyright 2005 Openedhand Ltd.
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.
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>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/soc.h>
24 #include <sound/soc-dapm.h>
26 #include <asm/mach-types.h>
28 #include "s3c24xx-pcm.h"
29 #include "s3c2412-i2s.h"
31 #include "../codecs/wm8750.h"
33 static const struct snd_soc_dapm_route audio_map[] = {
34 { "Headphone Jack", NULL, "LOUT1" },
35 { "Headphone Jack", NULL, "ROUT1" },
36 { "Internal Speaker", NULL, "LOUT2" },
37 { "Internal Speaker", NULL, "ROUT2" },
38 { "LINPUT1", NULL, "Line Input" },
39 { "RINPUT1", NULL, "Line Input" },
42 static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headphone Jack", NULL),
44 SND_SOC_DAPM_SPK("Internal Speaker", NULL),
45 SND_SOC_DAPM_LINE("Line In", NULL),
48 static int jive_startup(struct snd_pcm_substream *substream)
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 struct snd_soc_codec *codec = rtd->socdev->codec;
53 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
54 snd_soc_dapm_enable_pin(codec, "Internal Speaker");
55 snd_soc_dapm_enable_pin(codec, "Line In");
57 snd_soc_dapm_sync(codec);
59 return 0;
62 static int jive_hw_params(struct snd_pcm_substream *substream,
63 struct snd_pcm_hw_params *params)
65 struct snd_soc_pcm_runtime *rtd = substream->private_data;
66 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
67 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
68 struct s3c_i2sv2_rate_calc div;
69 unsigned int clk = 0;
70 int ret = 0;
72 switch (params_rate(params)) {
73 case 8000:
74 case 16000:
75 case 48000:
76 case 96000:
77 clk = 12288000;
78 break;
79 case 11025:
80 case 22050:
81 case 44100:
82 clk = 11289600;
83 break;
86 s3c_i2sv2_calc_rate(&div, NULL, params_rate(params),
87 s3c2412_get_iisclk());
89 /* set codec DAI configuration */
90 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
91 SND_SOC_DAIFMT_NB_NF |
92 SND_SOC_DAIFMT_CBS_CFS);
93 if (ret < 0)
94 return ret;
96 /* set cpu DAI configuration */
97 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
98 SND_SOC_DAIFMT_NB_NF |
99 SND_SOC_DAIFMT_CBS_CFS);
100 if (ret < 0)
101 return ret;
103 /* set the codec system clock for DAC and ADC */
104 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
105 SND_SOC_CLOCK_IN);
106 if (ret < 0)
107 return ret;
109 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
110 if (ret < 0)
111 return ret;
113 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
114 div.clk_div - 1);
115 if (ret < 0)
116 return ret;
118 return 0;
121 static struct snd_soc_ops jive_ops = {
122 .startup = jive_startup,
123 .hw_params = jive_hw_params,
126 static int jive_wm8750_init(struct snd_soc_codec *codec)
128 int err;
130 /* These endpoints are not being used. */
131 snd_soc_dapm_disable_pin(codec, "LINPUT2");
132 snd_soc_dapm_disable_pin(codec, "RINPUT2");
133 snd_soc_dapm_disable_pin(codec, "LINPUT3");
134 snd_soc_dapm_disable_pin(codec, "RINPUT3");
135 snd_soc_dapm_disable_pin(codec, "OUT3");
136 snd_soc_dapm_disable_pin(codec, "MONO");
138 /* Add jive specific widgets */
139 err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
140 ARRAY_SIZE(wm8750_dapm_widgets));
141 if (err) {
142 printk(KERN_ERR "%s: failed to add widgets (%d)\n",
143 __func__, err);
144 return err;
147 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
148 snd_soc_dapm_sync(codec);
150 return 0;
153 static struct snd_soc_dai_link jive_dai = {
154 .name = "wm8750",
155 .stream_name = "WM8750",
156 .cpu_dai = &s3c2412_i2s_dai,
157 .codec_dai = &wm8750_dai,
158 .init = jive_wm8750_init,
159 .ops = &jive_ops,
162 /* jive audio machine driver */
163 static struct snd_soc_machine snd_soc_machine_jive = {
164 .name = "Jive",
165 .dai_link = &jive_dai,
166 .num_links = 1,
169 /* jive audio private data */
170 static struct wm8750_setup_data jive_wm8750_setup = {
173 /* jive audio subsystem */
174 static struct snd_soc_device jive_snd_devdata = {
175 .machine = &snd_soc_machine_jive,
176 .platform = &s3c24xx_soc_platform,
177 .codec_dev = &soc_codec_dev_wm8750_spi,
178 .codec_data = &jive_wm8750_setup,
181 static struct platform_device *jive_snd_device;
183 static int __init jive_init(void)
185 int ret;
187 if (!machine_is_jive())
188 return 0;
190 printk("JIVE WM8750 Audio support\n");
192 jive_snd_device = platform_device_alloc("soc-audio", -1);
193 if (!jive_snd_device)
194 return -ENOMEM;
196 platform_set_drvdata(jive_snd_device, &jive_snd_devdata);
197 jive_snd_devdata.dev = &jive_snd_device->dev;
198 ret = platform_device_add(jive_snd_device);
200 if (ret)
201 platform_device_put(jive_snd_device);
203 return ret;
206 static void __exit jive_exit(void)
208 platform_device_unregister(jive_snd_device);
211 module_init(jive_init);
212 module_exit(jive_exit);
214 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
215 MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
216 MODULE_LICENSE("GPL");