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
);
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
;
72 switch (params_rate(params
)) {
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
);
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
);
103 /* set the codec system clock for DAC and ADC */
104 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8750_SYSCLK
, clk
,
109 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C2412_DIV_RCLK
, div
.fs_div
);
113 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, S3C2412_DIV_PRESCALER
,
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
)
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
));
142 printk(KERN_ERR
"%s: failed to add widgets (%d)\n",
147 snd_soc_dapm_add_routes(codec
, audio_map
, ARRAY_SIZE(audio_map
));
148 snd_soc_dapm_sync(codec
);
153 static struct snd_soc_dai_link jive_dai
= {
155 .stream_name
= "WM8750",
156 .cpu_dai
= &s3c2412_i2s_dai
,
157 .codec_dai
= &wm8750_dai
,
158 .init
= jive_wm8750_init
,
162 /* jive audio machine driver */
163 static struct snd_soc_machine snd_soc_machine_jive
= {
165 .dai_link
= &jive_dai
,
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)
187 if (!machine_is_jive())
190 printk("JIVE WM8750 Audio support\n");
192 jive_snd_device
= platform_device_alloc("soc-audio", -1);
193 if (!jive_snd_device
)
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
);
201 platform_device_put(jive_snd_device
);
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");