On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / sound / soc / s3c24xx / smdk64xx_wm8580.c
blob482aaf10eff65408a33a273bfc5887bb351ca05c
1 /*
2 * smdk64xx_wm8580.c
4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassi.brar@samsung.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/platform_device.h>
14 #include <linux/clk.h>
15 #include <sound/core.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 #include <sound/soc-dapm.h>
21 #include "../codecs/wm8580.h"
22 #include "s3c24xx-pcm.h"
23 #include "s3c64xx-i2s.h"
25 #define S3C64XX_I2S_V4 2
27 /* SMDK64XX has a 12MHZ crystal attached to WM8580 */
28 #define SMDK64XX_WM8580_FREQ 12000000
30 static int smdk64xx_hw_params(struct snd_pcm_substream *substream,
31 struct snd_pcm_hw_params *params)
33 struct snd_soc_pcm_runtime *rtd = substream->private_data;
34 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
35 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
36 unsigned int pll_out;
37 int bfs, rfs, ret;
39 switch (params_format(params)) {
40 case SNDRV_PCM_FORMAT_U8:
41 case SNDRV_PCM_FORMAT_S8:
42 bfs = 16;
43 break;
44 case SNDRV_PCM_FORMAT_U16_LE:
45 case SNDRV_PCM_FORMAT_S16_LE:
46 bfs = 32;
47 break;
48 default:
49 return -EINVAL;
52 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
53 * This criterion can't be met if we request PLL output
54 * as {8000x256, 64000x256, 11025x256}Hz.
55 * As a wayout, we rather change rfs to a minimum value that
56 * results in (params_rate(params) * rfs), and itself, acceptable
57 * to both - the CODEC and the CPU.
59 switch (params_rate(params)) {
60 case 16000:
61 case 22050:
62 case 32000:
63 case 44100:
64 case 48000:
65 case 88200:
66 case 96000:
67 rfs = 256;
68 break;
69 case 64000:
70 rfs = 384;
71 break;
72 case 8000:
73 case 11025:
74 rfs = 512;
75 break;
76 default:
77 return -EINVAL;
79 pll_out = params_rate(params) * rfs;
81 /* Set the Codec DAI configuration */
82 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
83 | SND_SOC_DAIFMT_NB_NF
84 | SND_SOC_DAIFMT_CBM_CFM);
85 if (ret < 0)
86 return ret;
88 /* Set the AP DAI configuration */
89 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
90 | SND_SOC_DAIFMT_NB_NF
91 | SND_SOC_DAIFMT_CBM_CFM);
92 if (ret < 0)
93 return ret;
95 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_CDCLK,
96 0, SND_SOC_CLOCK_IN);
97 if (ret < 0)
98 return ret;
100 /* We use PCLK for basic ops in SoC-Slave mode */
101 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
102 0, SND_SOC_CLOCK_IN);
103 if (ret < 0)
104 return ret;
106 /* Set WM8580 to drive MCLK from it's PLLA */
107 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
108 WM8580_CLKSRC_PLLA);
109 if (ret < 0)
110 return ret;
112 /* Explicitly set WM8580-DAC to source from MCLK */
113 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_DAC_CLKSEL,
114 WM8580_CLKSRC_MCLK);
115 if (ret < 0)
116 return ret;
118 /* Assuming the CODEC driver evaluates it's rfs too from this call */
119 ret = snd_soc_dai_set_pll(codec_dai, 0, WM8580_PLLA,
120 SMDK64XX_WM8580_FREQ, pll_out);
121 if (ret < 0)
122 return ret;
124 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_BCLK, bfs);
125 if (ret < 0)
126 return ret;
128 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, rfs);
129 if (ret < 0)
130 return ret;
132 return 0;
136 * SMDK64XX WM8580 DAI operations.
138 static struct snd_soc_ops smdk64xx_ops = {
139 .hw_params = smdk64xx_hw_params,
142 /* SMDK64xx Playback widgets */
143 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
144 SND_SOC_DAPM_HP("Front-L/R", NULL),
145 SND_SOC_DAPM_HP("Center/Sub", NULL),
146 SND_SOC_DAPM_HP("Rear-L/R", NULL),
149 /* SMDK64xx Capture widgets */
150 static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
151 SND_SOC_DAPM_MIC("MicIn", NULL),
152 SND_SOC_DAPM_LINE("LineIn", NULL),
155 /* SMDK-PAIFTX connections */
156 static const struct snd_soc_dapm_route audio_map_tx[] = {
157 /* MicIn feeds AINL */
158 {"AINL", NULL, "MicIn"},
160 /* LineIn feeds AINL/R */
161 {"AINL", NULL, "LineIn"},
162 {"AINR", NULL, "LineIn"},
165 /* SMDK-PAIFRX connections */
166 static const struct snd_soc_dapm_route audio_map_rx[] = {
167 /* Front Left/Right are fed VOUT1L/R */
168 {"Front-L/R", NULL, "VOUT1L"},
169 {"Front-L/R", NULL, "VOUT1R"},
171 /* Center/Sub are fed VOUT2L/R */
172 {"Center/Sub", NULL, "VOUT2L"},
173 {"Center/Sub", NULL, "VOUT2R"},
175 /* Rear Left/Right are fed VOUT3L/R */
176 {"Rear-L/R", NULL, "VOUT3L"},
177 {"Rear-L/R", NULL, "VOUT3R"},
180 static int smdk64xx_wm8580_init_paiftx(struct snd_soc_codec *codec)
182 /* Add smdk64xx specific Capture widgets */
183 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_cpt,
184 ARRAY_SIZE(wm8580_dapm_widgets_cpt));
186 /* Set up PAIFTX audio path */
187 snd_soc_dapm_add_routes(codec, audio_map_tx, ARRAY_SIZE(audio_map_tx));
189 /* All enabled by default */
190 snd_soc_dapm_enable_pin(codec, "MicIn");
191 snd_soc_dapm_enable_pin(codec, "LineIn");
193 /* signal a DAPM event */
194 snd_soc_dapm_sync(codec);
196 return 0;
199 static int smdk64xx_wm8580_init_paifrx(struct snd_soc_codec *codec)
201 /* Add smdk64xx specific Playback widgets */
202 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_pbk,
203 ARRAY_SIZE(wm8580_dapm_widgets_pbk));
205 /* Set up PAIFRX audio path */
206 snd_soc_dapm_add_routes(codec, audio_map_rx, ARRAY_SIZE(audio_map_rx));
208 /* All enabled by default */
209 snd_soc_dapm_enable_pin(codec, "Front-L/R");
210 snd_soc_dapm_enable_pin(codec, "Center/Sub");
211 snd_soc_dapm_enable_pin(codec, "Rear-L/R");
213 /* signal a DAPM event */
214 snd_soc_dapm_sync(codec);
216 return 0;
219 static struct snd_soc_dai_link smdk64xx_dai[] = {
220 { /* Primary Playback i/f */
221 .name = "WM8580 PAIF RX",
222 .stream_name = "Playback",
223 .cpu_dai = &s3c64xx_i2s_dai[S3C64XX_I2S_V4],
224 .codec_dai = &wm8580_dai[WM8580_DAI_PAIFRX],
225 .init = smdk64xx_wm8580_init_paifrx,
226 .ops = &smdk64xx_ops,
228 { /* Primary Capture i/f */
229 .name = "WM8580 PAIF TX",
230 .stream_name = "Capture",
231 .cpu_dai = &s3c64xx_i2s_dai[S3C64XX_I2S_V4],
232 .codec_dai = &wm8580_dai[WM8580_DAI_PAIFTX],
233 .init = smdk64xx_wm8580_init_paiftx,
234 .ops = &smdk64xx_ops,
238 static struct snd_soc_card smdk64xx = {
239 .name = "smdk64xx",
240 .platform = &s3c24xx_soc_platform,
241 .dai_link = smdk64xx_dai,
242 .num_links = ARRAY_SIZE(smdk64xx_dai),
245 static struct snd_soc_device smdk64xx_snd_devdata = {
246 .card = &smdk64xx,
247 .codec_dev = &soc_codec_dev_wm8580,
250 static struct platform_device *smdk64xx_snd_device;
252 static int __init smdk64xx_audio_init(void)
254 int ret;
256 smdk64xx_snd_device = platform_device_alloc("soc-audio", -1);
257 if (!smdk64xx_snd_device)
258 return -ENOMEM;
260 platform_set_drvdata(smdk64xx_snd_device, &smdk64xx_snd_devdata);
261 smdk64xx_snd_devdata.dev = &smdk64xx_snd_device->dev;
262 ret = platform_device_add(smdk64xx_snd_device);
264 if (ret)
265 platform_device_put(smdk64xx_snd_device);
267 return ret;
269 module_init(smdk64xx_audio_init);
271 MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
272 MODULE_DESCRIPTION("ALSA SoC SMDK64XX WM8580");
273 MODULE_LICENSE("GPL");