blob: b2cff1a44aed6a0ff592553e44a4354f7e6f8263 [file] [log] [blame]
jassi brard0f5fa12009-09-19 09:46:06 +09001/*
Jassi Brard98ce6c2010-11-22 15:37:16 +09002 * smdk_wm8580.c
jassi brard0f5fa12009-09-19 09:46:06 +09003 *
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>
jassi brard0f5fa12009-09-19 09:46:06 +090019
Jassi Brarb0f39c22010-11-22 15:37:19 +090020#include <asm/mach-types.h>
21
jassi brard0f5fa12009-09-19 09:46:06 +090022#include "../codecs/wm8580.h"
Jassi Brar4b640cf2010-11-22 15:35:57 +090023#include "dma.h"
Jassi Brar0fff21a2010-11-22 15:37:07 +090024#include "i2s.h"
jassi brard0f5fa12009-09-19 09:46:06 +090025
Mark Brown9d37e892010-08-06 17:57:45 +010026/*
27 * Default CFG switch settings to use this driver:
28 *
29 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
30 */
31
Jassi Brard98ce6c2010-11-22 15:37:16 +090032/* SMDK has a 12MHZ crystal attached to WM8580 */
33#define SMDK_WM8580_FREQ 12000000
jassi brard0f5fa12009-09-19 09:46:06 +090034
Jassi Brard98ce6c2010-11-22 15:37:16 +090035static int smdk_hw_params(struct snd_pcm_substream *substream,
jassi brard0f5fa12009-09-19 09:46:06 +090036 struct snd_pcm_hw_params *params)
37{
38 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000039 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
40 struct snd_soc_dai *codec_dai = rtd->codec_dai;
jassi brard0f5fa12009-09-19 09:46:06 +090041 unsigned int pll_out;
42 int bfs, rfs, ret;
43
44 switch (params_format(params)) {
45 case SNDRV_PCM_FORMAT_U8:
46 case SNDRV_PCM_FORMAT_S8:
47 bfs = 16;
48 break;
49 case SNDRV_PCM_FORMAT_U16_LE:
50 case SNDRV_PCM_FORMAT_S16_LE:
51 bfs = 32;
52 break;
53 default:
54 return -EINVAL;
55 }
56
57 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
58 * This criterion can't be met if we request PLL output
59 * as {8000x256, 64000x256, 11025x256}Hz.
60 * As a wayout, we rather change rfs to a minimum value that
61 * results in (params_rate(params) * rfs), and itself, acceptable
62 * to both - the CODEC and the CPU.
63 */
64 switch (params_rate(params)) {
65 case 16000:
66 case 22050:
67 case 32000:
68 case 44100:
69 case 48000:
70 case 88200:
71 case 96000:
72 rfs = 256;
73 break;
74 case 64000:
75 rfs = 384;
76 break;
77 case 8000:
78 case 11025:
79 rfs = 512;
80 break;
81 default:
82 return -EINVAL;
83 }
84 pll_out = params_rate(params) * rfs;
85
86 /* Set the Codec DAI configuration */
87 ret = snd_soc_dai_set_fmt(codec_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 /* Set the AP DAI configuration */
94 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
95 | SND_SOC_DAIFMT_NB_NF
96 | SND_SOC_DAIFMT_CBM_CFM);
97 if (ret < 0)
98 return ret;
99
Mark Brown26d95b62009-10-28 15:47:48 +0000100 /* Set WM8580 to drive MCLK from its PLLA */
jassi brard0f5fa12009-09-19 09:46:06 +0900101 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
102 WM8580_CLKSRC_PLLA);
103 if (ret < 0)
104 return ret;
105
Mark Brownc5607d82010-08-13 19:05:04 +0100106 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
Jassi Brard98ce6c2010-11-22 15:37:16 +0900107 SMDK_WM8580_FREQ, pll_out);
jassi brard0f5fa12009-09-19 09:46:06 +0900108 if (ret < 0)
109 return ret;
110
Mark Brownc5607d82010-08-13 19:05:04 +0100111 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
112 pll_out, SND_SOC_CLOCK_IN);
jassi brard0f5fa12009-09-19 09:46:06 +0900113 if (ret < 0)
114 return ret;
115
jassi brard0f5fa12009-09-19 09:46:06 +0900116 return 0;
117}
118
119/*
Jassi Brard98ce6c2010-11-22 15:37:16 +0900120 * SMDK WM8580 DAI operations.
jassi brard0f5fa12009-09-19 09:46:06 +0900121 */
Jassi Brard98ce6c2010-11-22 15:37:16 +0900122static struct snd_soc_ops smdk_ops = {
123 .hw_params = smdk_hw_params,
jassi brard0f5fa12009-09-19 09:46:06 +0900124};
125
Jassi Brard98ce6c2010-11-22 15:37:16 +0900126/* SMDK Playback widgets */
jassi brard0f5fa12009-09-19 09:46:06 +0900127static const struct snd_soc_dapm_widget wm8580_dapm_widgets_pbk[] = {
Mark Brown698cb112010-08-06 17:23:02 +0100128 SND_SOC_DAPM_HP("Front", NULL),
129 SND_SOC_DAPM_HP("Center+Sub", NULL),
130 SND_SOC_DAPM_HP("Rear", NULL),
jassi brard0f5fa12009-09-19 09:46:06 +0900131};
132
Jassi Brard98ce6c2010-11-22 15:37:16 +0900133/* SMDK Capture widgets */
jassi brard0f5fa12009-09-19 09:46:06 +0900134static const struct snd_soc_dapm_widget wm8580_dapm_widgets_cpt[] = {
135 SND_SOC_DAPM_MIC("MicIn", NULL),
136 SND_SOC_DAPM_LINE("LineIn", NULL),
137};
138
139/* SMDK-PAIFTX connections */
140static const struct snd_soc_dapm_route audio_map_tx[] = {
141 /* MicIn feeds AINL */
142 {"AINL", NULL, "MicIn"},
143
144 /* LineIn feeds AINL/R */
145 {"AINL", NULL, "LineIn"},
146 {"AINR", NULL, "LineIn"},
147};
148
149/* SMDK-PAIFRX connections */
150static const struct snd_soc_dapm_route audio_map_rx[] = {
151 /* Front Left/Right are fed VOUT1L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100152 {"Front", NULL, "VOUT1L"},
153 {"Front", NULL, "VOUT1R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900154
155 /* Center/Sub are fed VOUT2L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100156 {"Center+Sub", NULL, "VOUT2L"},
157 {"Center+Sub", NULL, "VOUT2R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900158
159 /* Rear Left/Right are fed VOUT3L/R */
Mark Brown698cb112010-08-06 17:23:02 +0100160 {"Rear", NULL, "VOUT3L"},
161 {"Rear", NULL, "VOUT3R"},
jassi brard0f5fa12009-09-19 09:46:06 +0900162};
163
Jassi Brard98ce6c2010-11-22 15:37:16 +0900164static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
jassi brard0f5fa12009-09-19 09:46:06 +0900165{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000166 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200167 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000168
Jassi Brard98ce6c2010-11-22 15:37:16 +0900169 /* Add smdk specific Capture widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200170 snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_cpt,
jassi brard0f5fa12009-09-19 09:46:06 +0900171 ARRAY_SIZE(wm8580_dapm_widgets_cpt));
172
173 /* Set up PAIFTX audio path */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200174 snd_soc_dapm_add_routes(dapm, audio_map_tx, ARRAY_SIZE(audio_map_tx));
jassi brard0f5fa12009-09-19 09:46:06 +0900175
Mark Brown26d95b62009-10-28 15:47:48 +0000176 /* Enabling the microphone requires the fitting of a 0R
177 * resistor to connect the line from the microphone jack.
178 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200179 snd_soc_dapm_disable_pin(dapm, "MicIn");
jassi brard0f5fa12009-09-19 09:46:06 +0900180
181 /* signal a DAPM event */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200182 snd_soc_dapm_sync(dapm);
jassi brard0f5fa12009-09-19 09:46:06 +0900183
184 return 0;
185}
186
Jassi Brard98ce6c2010-11-22 15:37:16 +0900187static int smdk_wm8580_init_paifrx(struct snd_soc_pcm_runtime *rtd)
jassi brard0f5fa12009-09-19 09:46:06 +0900188{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000189 struct snd_soc_codec *codec = rtd->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200190 struct snd_soc_dapm_context *dapm = &codec->dapm;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000191
Jassi Brard98ce6c2010-11-22 15:37:16 +0900192 /* Add smdk specific Playback widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200193 snd_soc_dapm_new_controls(dapm, wm8580_dapm_widgets_pbk,
jassi brard0f5fa12009-09-19 09:46:06 +0900194 ARRAY_SIZE(wm8580_dapm_widgets_pbk));
195
196 /* Set up PAIFRX audio path */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200197 snd_soc_dapm_add_routes(dapm, audio_map_rx, ARRAY_SIZE(audio_map_rx));
jassi brard0f5fa12009-09-19 09:46:06 +0900198
jassi brard0f5fa12009-09-19 09:46:06 +0900199 /* signal a DAPM event */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200200 snd_soc_dapm_sync(dapm);
jassi brard0f5fa12009-09-19 09:46:06 +0900201
202 return 0;
203}
204
Jassi Brarb0f39c22010-11-22 15:37:19 +0900205enum {
206 PRI_PLAYBACK = 0,
207 PRI_CAPTURE,
208 SEC_PLAYBACK,
209};
210
Jassi Brard98ce6c2010-11-22 15:37:16 +0900211static struct snd_soc_dai_link smdk_dai[] = {
Jassi Brarb0f39c22010-11-22 15:37:19 +0900212 [PRI_PLAYBACK] = { /* Primary Playback i/f */
213 .name = "WM8580 PAIF RX",
214 .stream_name = "Playback",
Jassi Brar72685f22010-12-20 11:05:48 +0900215 .cpu_dai_name = "samsung-i2s.0",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900216 .codec_dai_name = "wm8580-hifi-playback",
217 .platform_name = "samsung-audio",
218 .codec_name = "wm8580-codec.0-001b",
219 .init = smdk_wm8580_init_paifrx,
220 .ops = &smdk_ops,
221 },
222 [PRI_CAPTURE] = { /* Primary Capture i/f */
223 .name = "WM8580 PAIF TX",
224 .stream_name = "Capture",
Jassi Brar72685f22010-12-20 11:05:48 +0900225 .cpu_dai_name = "samsung-i2s.0",
Jassi Brarb0f39c22010-11-22 15:37:19 +0900226 .codec_dai_name = "wm8580-hifi-capture",
227 .platform_name = "samsung-audio",
228 .codec_name = "wm8580-codec.0-001b",
229 .init = smdk_wm8580_init_paiftx,
230 .ops = &smdk_ops,
231 },
232 [SEC_PLAYBACK] = { /* Sec_Fifo Playback i/f */
233 .name = "Sec_FIFO TX",
234 .stream_name = "Playback",
235 .cpu_dai_name = "samsung-i2s.x",
236 .codec_dai_name = "wm8580-hifi-playback",
237 .platform_name = "samsung-audio",
238 .codec_name = "wm8580-codec.0-001b",
239 .init = smdk_wm8580_init_paifrx,
240 .ops = &smdk_ops,
241 },
jassi brard0f5fa12009-09-19 09:46:06 +0900242};
243
Jassi Brard98ce6c2010-11-22 15:37:16 +0900244static struct snd_soc_card smdk = {
245 .name = "SMDK-I2S",
246 .dai_link = smdk_dai,
Jassi Brarb0f39c22010-11-22 15:37:19 +0900247 .num_links = 2,
jassi brard0f5fa12009-09-19 09:46:06 +0900248};
249
Jassi Brard98ce6c2010-11-22 15:37:16 +0900250static struct platform_device *smdk_snd_device;
jassi brard0f5fa12009-09-19 09:46:06 +0900251
Jassi Brard98ce6c2010-11-22 15:37:16 +0900252static int __init smdk_audio_init(void)
jassi brard0f5fa12009-09-19 09:46:06 +0900253{
254 int ret;
Jassi Brarb0f39c22010-11-22 15:37:19 +0900255 char *str;
256
Jassi Brare3bd3e12010-12-20 11:05:53 +0900257 if (machine_is_smdkc100() || machine_is_smdk6442()
Jassi Brar40d24822010-12-20 11:05:55 +0900258 || machine_is_smdkv210() || machine_is_smdkc110()) {
Jassi Brarb0f39c22010-11-22 15:37:19 +0900259 smdk.num_links = 3;
Jassi Brarb0f39c22010-11-22 15:37:19 +0900260 /* Secondary is at offset SAMSUNG_I2S_SECOFF from Primary */
261 str = (char *)smdk_dai[SEC_PLAYBACK].cpu_dai_name;
262 str[strlen(str) - 1] = '0' + SAMSUNG_I2S_SECOFF;
Jassi Brar72685f22010-12-20 11:05:48 +0900263 } else if (machine_is_smdk6410()) {
264 str = (char *)smdk_dai[PRI_PLAYBACK].cpu_dai_name;
265 str[strlen(str) - 1] = '2';
266 str = (char *)smdk_dai[PRI_CAPTURE].cpu_dai_name;
267 str[strlen(str) - 1] = '2';
Jassi Brarb0f39c22010-11-22 15:37:19 +0900268 }
jassi brard0f5fa12009-09-19 09:46:06 +0900269
Jassi Brard98ce6c2010-11-22 15:37:16 +0900270 smdk_snd_device = platform_device_alloc("soc-audio", -1);
271 if (!smdk_snd_device)
jassi brard0f5fa12009-09-19 09:46:06 +0900272 return -ENOMEM;
273
Jassi Brard98ce6c2010-11-22 15:37:16 +0900274 platform_set_drvdata(smdk_snd_device, &smdk);
275 ret = platform_device_add(smdk_snd_device);
jassi brard0f5fa12009-09-19 09:46:06 +0900276
277 if (ret)
Jassi Brard98ce6c2010-11-22 15:37:16 +0900278 platform_device_put(smdk_snd_device);
jassi brard0f5fa12009-09-19 09:46:06 +0900279
280 return ret;
281}
Jassi Brard98ce6c2010-11-22 15:37:16 +0900282module_init(smdk_audio_init);
jassi brard0f5fa12009-09-19 09:46:06 +0900283
Mark Brown38533692010-11-24 17:18:45 +0000284static void __exit smdk_audio_exit(void)
285{
286 platform_device_unregister(smdk_snd_device);
287}
288module_exit(smdk_audio_exit);
289
jassi brard0f5fa12009-09-19 09:46:06 +0900290MODULE_AUTHOR("Jaswinder Singh, jassi.brar@samsung.com");
Jassi Brard98ce6c2010-11-22 15:37:16 +0900291MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
jassi brard0f5fa12009-09-19 09:46:06 +0900292MODULE_LICENSE("GPL");