2 * raumfeld_audio.c -- SoC audio for Raumfeld audio devices
4 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
8 * Wolfson Microelectronics PLC.
10 * Liam Girdwood <lrg@slimlogic.co.uk>
11 * Richard Purdie <richard@openedhand.com>
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.
19 #include <linux/module.h>
20 #include <linux/i2c.h>
21 #include <linux/delay.h>
22 #include <linux/gpio.h>
23 #include <sound/pcm.h>
24 #include <sound/soc.h>
26 #include <asm/mach-types.h>
30 #define GPIO_SPDIF_RESET (38)
31 #define GPIO_MCLK_RESET (111)
32 #define GPIO_CODEC_RESET (120)
34 static struct i2c_client
*max9486_client
;
35 static struct i2c_board_info max9486_hwmon_info
= {
36 I2C_BOARD_INFO("max9485", 0x63),
39 #define MAX9485_MCLK_FREQ_112896 0x22
40 #define MAX9485_MCLK_FREQ_122880 0x23
41 #define MAX9485_MCLK_FREQ_225792 0x32
42 #define MAX9485_MCLK_FREQ_245760 0x33
44 static void set_max9485_clk(char clk
)
46 i2c_master_send(max9486_client
, &clk
, 1);
49 static void raumfeld_enable_audio(bool en
)
52 gpio_set_value(GPIO_MCLK_RESET
, 1);
54 /* wait some time to let the clocks become stable */
57 gpio_set_value(GPIO_SPDIF_RESET
, 1);
58 gpio_set_value(GPIO_CODEC_RESET
, 1);
60 gpio_set_value(GPIO_MCLK_RESET
, 0);
61 gpio_set_value(GPIO_SPDIF_RESET
, 0);
62 gpio_set_value(GPIO_CODEC_RESET
, 0);
67 static int raumfeld_cs4270_startup(struct snd_pcm_substream
*substream
)
69 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
70 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
72 /* set freq to 0 to enable all possible codec sample rates */
73 return snd_soc_dai_set_sysclk(codec_dai
, 0, 0, 0);
76 static void raumfeld_cs4270_shutdown(struct snd_pcm_substream
*substream
)
78 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
79 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
81 /* set freq to 0 to enable all possible codec sample rates */
82 snd_soc_dai_set_sysclk(codec_dai
, 0, 0, 0);
85 static int raumfeld_cs4270_hw_params(struct snd_pcm_substream
*substream
,
86 struct snd_pcm_hw_params
*params
)
88 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
89 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
90 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
91 unsigned int fmt
, clk
= 0;
94 switch (params_rate(params
)) {
96 set_max9485_clk(MAX9485_MCLK_FREQ_112896
);
100 set_max9485_clk(MAX9485_MCLK_FREQ_122880
);
104 set_max9485_clk(MAX9485_MCLK_FREQ_225792
);
108 set_max9485_clk(MAX9485_MCLK_FREQ_245760
);
115 fmt
= SND_SOC_DAIFMT_I2S
|
116 SND_SOC_DAIFMT_NB_NF
|
117 SND_SOC_DAIFMT_CBS_CFS
;
119 /* setup the CODEC DAI */
120 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
124 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, clk
, 0);
128 /* setup the CPU DAI */
129 ret
= snd_soc_dai_set_pll(cpu_dai
, 0, 0, 0, clk
);
133 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
137 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, PXA_SSP_DIV_SCR
, 4);
141 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA_SSP_CLK_EXT
, clk
, 1);
148 static struct snd_soc_ops raumfeld_cs4270_ops
= {
149 .startup
= raumfeld_cs4270_startup
,
150 .shutdown
= raumfeld_cs4270_shutdown
,
151 .hw_params
= raumfeld_cs4270_hw_params
,
154 static int raumfeld_analog_suspend(struct snd_soc_card
*card
)
156 raumfeld_enable_audio(false);
160 static int raumfeld_analog_resume(struct snd_soc_card
*card
)
162 raumfeld_enable_audio(true);
168 static int raumfeld_ak4104_hw_params(struct snd_pcm_substream
*substream
,
169 struct snd_pcm_hw_params
*params
)
171 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
172 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
173 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
174 int fmt
, ret
= 0, clk
= 0;
176 switch (params_rate(params
)) {
178 set_max9485_clk(MAX9485_MCLK_FREQ_112896
);
182 set_max9485_clk(MAX9485_MCLK_FREQ_122880
);
186 set_max9485_clk(MAX9485_MCLK_FREQ_225792
);
190 set_max9485_clk(MAX9485_MCLK_FREQ_245760
);
197 fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
;
199 /* setup the CODEC DAI */
200 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
| SND_SOC_DAIFMT_CBS_CFS
);
204 /* setup the CPU DAI */
205 ret
= snd_soc_dai_set_pll(cpu_dai
, 0, 0, 0, clk
);
209 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
| SND_SOC_DAIFMT_CBS_CFS
);
213 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, PXA_SSP_DIV_SCR
, 4);
217 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA_SSP_CLK_EXT
, clk
, 1);
224 static struct snd_soc_ops raumfeld_ak4104_ops
= {
225 .hw_params
= raumfeld_ak4104_hw_params
,
228 #define DAI_LINK_CS4270 \
231 .stream_name = "CS4270", \
232 .cpu_dai_name = "pxa-ssp-dai.0", \
233 .platform_name = "pxa-pcm-audio", \
234 .codec_dai_name = "cs4270-hifi", \
235 .codec_name = "cs4270.0-0048", \
236 .ops = &raumfeld_cs4270_ops, \
239 #define DAI_LINK_AK4104 \
242 .stream_name = "Playback", \
243 .cpu_dai_name = "pxa-ssp-dai.1", \
244 .codec_dai_name = "ak4104-hifi", \
245 .platform_name = "pxa-pcm-audio", \
246 .ops = &raumfeld_ak4104_ops, \
247 .codec_name = "spi0.0", \
250 static struct snd_soc_dai_link snd_soc_raumfeld_connector_dai
[] =
256 static struct snd_soc_dai_link snd_soc_raumfeld_speaker_dai
[] =
261 static struct snd_soc_card snd_soc_raumfeld_connector
= {
262 .name
= "Raumfeld Connector",
263 .owner
= THIS_MODULE
,
264 .dai_link
= snd_soc_raumfeld_connector_dai
,
265 .num_links
= ARRAY_SIZE(snd_soc_raumfeld_connector_dai
),
266 .suspend_post
= raumfeld_analog_suspend
,
267 .resume_pre
= raumfeld_analog_resume
,
270 static struct snd_soc_card snd_soc_raumfeld_speaker
= {
271 .name
= "Raumfeld Speaker",
272 .owner
= THIS_MODULE
,
273 .dai_link
= snd_soc_raumfeld_speaker_dai
,
274 .num_links
= ARRAY_SIZE(snd_soc_raumfeld_speaker_dai
),
275 .suspend_post
= raumfeld_analog_suspend
,
276 .resume_pre
= raumfeld_analog_resume
,
279 static struct platform_device
*raumfeld_audio_device
;
281 static int __init
raumfeld_audio_init(void)
285 if (!machine_is_raumfeld_speaker() &&
286 !machine_is_raumfeld_connector())
289 max9486_client
= i2c_new_device(i2c_get_adapter(0),
290 &max9486_hwmon_info
);
295 set_max9485_clk(MAX9485_MCLK_FREQ_122880
);
297 /* Register analog device */
298 raumfeld_audio_device
= platform_device_alloc("soc-audio", 0);
299 if (!raumfeld_audio_device
)
302 if (machine_is_raumfeld_speaker())
303 platform_set_drvdata(raumfeld_audio_device
,
304 &snd_soc_raumfeld_speaker
);
306 if (machine_is_raumfeld_connector())
307 platform_set_drvdata(raumfeld_audio_device
,
308 &snd_soc_raumfeld_connector
);
310 ret
= platform_device_add(raumfeld_audio_device
);
312 platform_device_put(raumfeld_audio_device
);
316 raumfeld_enable_audio(true);
320 static void __exit
raumfeld_audio_exit(void)
322 raumfeld_enable_audio(false);
324 platform_device_unregister(raumfeld_audio_device
);
326 i2c_unregister_device(max9486_client
);
328 gpio_free(GPIO_MCLK_RESET
);
329 gpio_free(GPIO_CODEC_RESET
);
330 gpio_free(GPIO_SPDIF_RESET
);
333 module_init(raumfeld_audio_init
);
334 module_exit(raumfeld_audio_exit
);
336 /* Module information */
337 MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
338 MODULE_DESCRIPTION("Raumfeld audio SoC");
339 MODULE_LICENSE("GPL");