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>
25 #include <sound/soc-dapm.h>
27 #include <asm/mach-types.h>
31 #define GPIO_SPDIF_RESET (38)
32 #define GPIO_MCLK_RESET (111)
33 #define GPIO_CODEC_RESET (120)
35 static struct i2c_client
*max9486_client
;
36 static struct i2c_board_info max9486_hwmon_info
= {
37 I2C_BOARD_INFO("max9485", 0x63),
40 #define MAX9485_MCLK_FREQ_112896 0x22
41 #define MAX9485_MCLK_FREQ_122880 0x23
42 #define MAX9485_MCLK_FREQ_225792 0x32
43 #define MAX9485_MCLK_FREQ_245760 0x33
45 static void set_max9485_clk(char clk
)
47 i2c_master_send(max9486_client
, &clk
, 1);
50 static void raumfeld_enable_audio(bool en
)
53 gpio_set_value(GPIO_MCLK_RESET
, 1);
55 /* wait some time to let the clocks become stable */
58 gpio_set_value(GPIO_SPDIF_RESET
, 1);
59 gpio_set_value(GPIO_CODEC_RESET
, 1);
61 gpio_set_value(GPIO_MCLK_RESET
, 0);
62 gpio_set_value(GPIO_SPDIF_RESET
, 0);
63 gpio_set_value(GPIO_CODEC_RESET
, 0);
68 static int raumfeld_cs4270_startup(struct snd_pcm_substream
*substream
)
70 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
71 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
73 /* set freq to 0 to enable all possible codec sample rates */
74 return snd_soc_dai_set_sysclk(codec_dai
, 0, 0, 0);
77 static void raumfeld_cs4270_shutdown(struct snd_pcm_substream
*substream
)
79 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
80 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
82 /* set freq to 0 to enable all possible codec sample rates */
83 snd_soc_dai_set_sysclk(codec_dai
, 0, 0, 0);
86 static int raumfeld_cs4270_hw_params(struct snd_pcm_substream
*substream
,
87 struct snd_pcm_hw_params
*params
)
89 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
90 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
91 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
92 unsigned int fmt
, clk
= 0;
95 switch (params_rate(params
)) {
97 set_max9485_clk(MAX9485_MCLK_FREQ_112896
);
101 set_max9485_clk(MAX9485_MCLK_FREQ_122880
);
105 set_max9485_clk(MAX9485_MCLK_FREQ_225792
);
109 set_max9485_clk(MAX9485_MCLK_FREQ_245760
);
116 fmt
= SND_SOC_DAIFMT_I2S
|
117 SND_SOC_DAIFMT_NB_NF
|
118 SND_SOC_DAIFMT_CBS_CFS
;
120 /* setup the CODEC DAI */
121 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
125 ret
= snd_soc_dai_set_sysclk(codec_dai
, 0, clk
, 0);
129 /* setup the CPU DAI */
130 ret
= snd_soc_dai_set_pll(cpu_dai
, 0, 0, 0, clk
);
134 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
138 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, PXA_SSP_DIV_SCR
, 4);
142 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA_SSP_CLK_EXT
, clk
, 1);
149 static struct snd_soc_ops raumfeld_cs4270_ops
= {
150 .startup
= raumfeld_cs4270_startup
,
151 .shutdown
= raumfeld_cs4270_shutdown
,
152 .hw_params
= raumfeld_cs4270_hw_params
,
155 static int raumfeld_line_suspend(struct platform_device
*pdev
, pm_message_t state
)
157 raumfeld_enable_audio(false);
161 static int raumfeld_line_resume(struct platform_device
*pdev
)
163 raumfeld_enable_audio(true);
169 static int raumfeld_ak4104_hw_params(struct snd_pcm_substream
*substream
,
170 struct snd_pcm_hw_params
*params
)
172 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
173 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
174 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
175 int fmt
, ret
= 0, clk
= 0;
177 switch (params_rate(params
)) {
179 set_max9485_clk(MAX9485_MCLK_FREQ_112896
);
183 set_max9485_clk(MAX9485_MCLK_FREQ_122880
);
187 set_max9485_clk(MAX9485_MCLK_FREQ_225792
);
191 set_max9485_clk(MAX9485_MCLK_FREQ_245760
);
198 fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
;
200 /* setup the CODEC DAI */
201 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
| SND_SOC_DAIFMT_CBS_CFS
);
205 /* setup the CPU DAI */
206 ret
= snd_soc_dai_set_pll(cpu_dai
, 0, 0, 0, clk
);
210 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
| SND_SOC_DAIFMT_CBS_CFS
);
214 ret
= snd_soc_dai_set_clkdiv(cpu_dai
, PXA_SSP_DIV_SCR
, 4);
218 ret
= snd_soc_dai_set_sysclk(cpu_dai
, PXA_SSP_CLK_EXT
, clk
, 1);
225 static struct snd_soc_ops raumfeld_ak4104_ops
= {
226 .hw_params
= raumfeld_ak4104_hw_params
,
229 static struct snd_soc_dai_link raumfeld_dai
[] = {
232 .stream_name
= "Playback",
233 .cpu_dai_name
= "pxa-ssp-dai.1",
234 .codec_dai_name
= "ak4104-hifi",
235 .platform_name
= "pxa-pcm-audio",
236 .ops
= &raumfeld_ak4104_ops
,
237 .codec_name
= "ak4104-codec.0",
241 .stream_name
= "CS4270",
242 .cpu_dai_name
= "pxa-ssp-dai.0",
243 .platform_name
= "pxa-pcm-audio",
244 .codec_dai_name
= "cs4270-hifi",
245 .codec_name
= "cs4270-codec.0-0048",
246 .ops
= &raumfeld_cs4270_ops
,
249 static struct snd_soc_card snd_soc_raumfeld
= {
251 .dai_link
= raumfeld_dai
,
252 .suspend_post
= raumfeld_line_suspend
,
253 .resume_pre
= raumfeld_line_resume
,
254 .num_links
= ARRAY_SIZE(raumfeld_dai
),
257 static struct platform_device
*raumfeld_audio_device
;
259 static int __init
raumfeld_audio_init(void)
263 if (!machine_is_raumfeld_speaker() &&
264 !machine_is_raumfeld_connector())
267 max9486_client
= i2c_new_device(i2c_get_adapter(0),
268 &max9486_hwmon_info
);
273 set_max9485_clk(MAX9485_MCLK_FREQ_122880
);
275 /* Register LINE and SPDIF */
276 raumfeld_audio_device
= platform_device_alloc("soc-audio", 0);
277 if (!raumfeld_audio_device
)
280 platform_set_drvdata(raumfeld_audio_device
,
282 ret
= platform_device_add(raumfeld_audio_device
);
284 /* no S/PDIF on Speakers */
285 if (machine_is_raumfeld_speaker())
288 raumfeld_enable_audio(true);
293 static void __exit
raumfeld_audio_exit(void)
295 raumfeld_enable_audio(false);
297 platform_device_unregister(raumfeld_audio_device
);
299 i2c_unregister_device(max9486_client
);
301 gpio_free(GPIO_MCLK_RESET
);
302 gpio_free(GPIO_CODEC_RESET
);
303 gpio_free(GPIO_SPDIF_RESET
);
306 module_init(raumfeld_audio_init
);
307 module_exit(raumfeld_audio_exit
);
309 /* Module information */
310 MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
311 MODULE_DESCRIPTION("Raumfeld audio SoC");
312 MODULE_LICENSE("GPL");