blob: 07e8e51d10d60e925e05062cd331a58a36ba64c4 [file] [log] [blame]
jassi brard0f5fa12009-09-19 09:46:06 +09001/*
2 * smdk64xx_wm8580.c
3 *
4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassi.brar@samsung.com>
6 *
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.
11 */
12
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>
20
21#include "../codecs/wm8580.h"
Jassi Brard3ff5a32009-11-17 16:53:31 +090022#include "s3c-dma.h"
jassi brard0f5fa12009-09-19 09:46:06 +090023#include "s3c64xx-i2s.h"
24
jassi brard0f5fa12009-09-19 09:46:06 +090025/* SMDK64XX has a 12MHZ crystal attached to WM8580 */
26#define SMDK64XX_WM8580_FREQ 12000000
27
28static int smdk64xx_hw_params(struct snd_pcm_substream *substream,
29 struct snd_pcm_hw_params *params)
30{
31 struct snd_soc_pcm_runtime *rtd = substream->private_data;
32 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
33 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
34 unsigned int pll_out;
35 int bfs, rfs, ret;
36
37 switch (params_format(params)) {
38 case SNDRV_PCM_FORMAT_U8:
39 case SNDRV_PCM_FORMAT_S8:
40 bfs = 16;
41 break;
42 case SNDRV_PCM_FORMAT_U16_LE:
43 case SNDRV_PCM_FORMAT_S16_LE:
44 bfs = 32;
45 break;
46 default:
47 return -EINVAL;
48 }
49
50 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
51 * This criterion can't be met if we request PLL output
52 * as {8000x256, 64000x256, 11025x256}Hz.
53 * As a wayout, we rather change rfs to a minimum value that
54 * results in (params_rate(params) * rfs), and itself, acceptable
55 * to both - the CODEC and the CPU.
56 */
57 switch (params_rate(params)) {
58 case 16000:
59 case 22050:
60 case 32000:
61 case 44100:
62 case 48000:
63 case 88200:
64 case 96000:
65 rfs = 256;
66 break;
67 case 64000:
68 rfs = 384;
69 break;
70 case 8000:
71 case 11025:
72 rfs = 512;
73 break;
74 default:
75 return -EINVAL;
76 }
77 pll_out = params_rate(params) * rfs;
78
79 /* Set the Codec DAI configuration */
80 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
81 | SND_SOC_DAIFMT_NB_NF
82 | SND_SOC_DAIFMT_CBM_CFM);
83 if (ret < 0)
84 return ret;
85
86 /* Set the AP DAI configuration */
87 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
88 | SND_SOC_DAIFMT_NB_NF
89 | SND_SOC_DAIFMT_CBM_CFM);
90 if (ret < 0)
91 return ret;
92
93 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_CDCLK,
94 0, SND_SOC_CLOCK_IN);
95 if (ret < 0)
96 return ret;
97
98 /* We use PCLK for basic ops in SoC-Slave mode */
99 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C64XX_CLKSRC_PCLK,
100 0, SND_SOC_CLOCK_IN);
101 if (ret < 0)
102 return ret;
103
Mark Brown26d95b62009-10-28 15:47:48 +0000104 /* Set WM8580 to drive MCLK from its PLLA */
jassi brard0f5fa12009-09-19 09:46:06 +0900105 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
106 WM8580_CLKSRC_PLLA);
107 if (ret < 0)
108 return ret;
109
110 /* Explicitly set WM8580-DAC to source from MCLK */
111 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_DAC_CLKSEL,
112 WM8580_CLKSRC_MCLK);
113 if (ret < 0)
114 return ret;
115
Jassi Brarba2b87f2009-11-11 14:02:18 +0900116 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
jassi brard0f5fa12009-09-19 09:46:06 +0900117 SMDK64XX_WM8580_FREQ, pll_out);
118 if (ret < 0)
119 return ret;
120
121 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_BCLK, bfs);
122 if (ret < 0)
123 return ret;
124
125 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C_I2SV2_DIV_RCLK, rfs);
126 if (ret < 0)
127 return ret;
128
129 return 0;
130}
131
132/*
133 * SMDK64XX WM8580 DAI operations.
134 */
135static struct snd_soc_ops smdk64xx_ops = {
136 .hw_params = smdk64xx_hw_params,
137};
138
139/* SMDK64xx Playback widgets */
140static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
141 SND_SOC_DAPM_HP("Front-L/R", NULL),
142 SND_SOC_DAPM_HP("Center/Sub", NULL),
143 SND_SOC_DAPM_HP("Rear-L/R", NULL),
144};
145
146/* SMDK64xx Capture widgets */
147static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
148 SND_SOC_DAPM_MIC("MicIn", NULL),
149 SND_SOC_DAPM_LINE("LineIn", NULL),
150};
151
152/* SMDK-PAIFTX connections */
153static const struct snd_soc_dapm_route audio_map_tx[] = {
154 /* MicIn feeds AINL */
155 {"AINL", NULL, "MicIn"},
156
157 /* LineIn feeds AINL/R */
158 {"AINL", NULL, "LineIn"},
159 {"AINR", NULL, "LineIn"},
160};
161
162/* SMDK-PAIFRX connections */
163static const struct snd_soc_dapm_route audio_map_rx[] = {
164 /* Front Left/Right are fed VOUT1L/R */
165 {"Front-L/R", NULL, "VOUT1L"},
166 {"Front-L/R", NULL, "VOUT1R"},
167
168 /* Center/Sub are fed VOUT2L/R */
169 {"Center/Sub", NULL, "VOUT2L"},
170 {"Center/Sub", NULL, "VOUT2R"},
171
172 /* Rear Left/Right are fed VOUT3L/R */
173 {"Rear-L/R", NULL, "VOUT3L"},
174 {"Rear-L/R", NULL, "VOUT3R"},
175};
176
177static int smdk64xx_wm8580_init_paiftx(struct snd_soc_codec *codec)
178{
179 /* Add smdk64xx specific Capture widgets */
180 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_cpt,
181 ARRAY_SIZE(wm8580_dapm_widgets_cpt));
182
183 /* Set up PAIFTX audio path */
184 snd_soc_dapm_add_routes(codec, audio_map_tx, ARRAY_SIZE(audio_map_tx));
185
Mark Brown26d95b62009-10-28 15:47:48 +0000186 /* Enabling the microphone requires the fitting of a 0R
187 * resistor to connect the line from the microphone jack.
188 */
189 snd_soc_dapm_disable_pin(codec, "MicIn");
jassi brard0f5fa12009-09-19 09:46:06 +0900190
191 /* signal a DAPM event */
192 snd_soc_dapm_sync(codec);
193
194 return 0;
195}
196
197static int smdk64xx_wm8580_init_paifrx(struct snd_soc_codec *codec)
198{
199 /* Add smdk64xx specific Playback widgets */
200 snd_soc_dapm_new_controls(codec, wm8580_dapm_widgets_pbk,
201 ARRAY_SIZE(wm8580_dapm_widgets_pbk));
202
203 /* Set up PAIFRX audio path */
204 snd_soc_dapm_add_routes(codec, audio_map_rx, ARRAY_SIZE(audio_map_rx));
205
jassi brard0f5fa12009-09-19 09:46:06 +0900206 /* signal a DAPM event */
207 snd_soc_dapm_sync(codec);
208
209 return 0;
210}
211
212static struct snd_soc_dai_link smdk64xx_dai[] = {
213{ /* Primary Playback i/f */
214 .name = "WM8580 PAIF RX",
215 .stream_name = "Playback",
Jassi Brard0bbc242010-04-27 15:57:17 +0900216 .cpu_dai = &s3c64xx_i2s_v4_dai,
jassi brard0f5fa12009-09-19 09:46:06 +0900217 .codec_dai = &wm8580_dai[WM8580_DAI_PAIFRX],
218 .init = smdk64xx_wm8580_init_paifrx,
219 .ops = &smdk64xx_ops,
220},
221{ /* Primary Capture i/f */
222 .name = "WM8580 PAIF TX",
223 .stream_name = "Capture",
Jassi Brard0bbc242010-04-27 15:57:17 +0900224 .cpu_dai = &s3c64xx_i2s_v4_dai,
jassi brard0f5fa12009-09-19 09:46:06 +0900225 .codec_dai = &wm8580_dai[WM8580_DAI_PAIFTX],
226 .init = smdk64xx_wm8580_init_paiftx,
227 .ops = &smdk64xx_ops,
228},
229};
230
231static struct snd_soc_card smdk64xx = {
232 .name = "smdk64xx",
233 .platform = &s3c24xx_soc_platform,
234 .dai_link = smdk64xx_dai,
235 .num_links = ARRAY_SIZE(smdk64xx_dai),
236};
237
238static struct snd_soc_device smdk64xx_snd_devdata = {
239 .card = &smdk64xx,
240 .codec_dev = &soc_codec_dev_wm8580,
241};
242
243static struct platform_device *smdk64xx_snd_device;
244
245static int __init smdk64xx_audio_init(void)
246{
247 int ret;
248
249 smdk64xx_snd_device = platform_device_alloc("soc-audio", -1);
250 if (!smdk64xx_snd_device)
251 return -ENOMEM;
252
253 platform_set_drvdata(smdk64xx_snd_device, &smdk64xx_snd_devdata);
254 smdk64xx_snd_devdata.dev = &smdk64xx_snd_device->dev;
255 ret = platform_device_add(smdk64xx_snd_device);
256
257 if (ret)
258 platform_device_put(smdk64xx_snd_device);
259
260 return ret;
261}
262module_init(smdk64xx_audio_init);
263
264MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
265MODULE_DESCRIPTION("ALSA SoC SMDK64XX WM8580");
266MODULE_LICENSE("GPL");