sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / soc / samsung / smdk_wm8580.c
blobde724ce7b955e2935f9df628bd3f8bc533b67fd3
1 /*
2 * smdk_wm8580.c
4 * Copyright (c) 2009 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassisinghbrar@gmail.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/module.h>
14 #include <sound/soc.h>
15 #include <sound/pcm_params.h>
17 #include "../codecs/wm8580.h"
18 #include "i2s.h"
21 * Default CFG switch settings to use this driver:
23 * SMDK6410: Set CFG1 1-3 Off, CFG2 1-4 On
26 /* SMDK has a 12MHZ crystal attached to WM8580 */
27 #define SMDK_WM8580_FREQ 12000000
29 static int smdk_hw_params(struct snd_pcm_substream *substream,
30 struct snd_pcm_hw_params *params)
32 struct snd_soc_pcm_runtime *rtd = substream->private_data;
33 struct snd_soc_dai *codec_dai = rtd->codec_dai;
34 unsigned int pll_out;
35 int bfs, rfs, ret;
37 switch (params_width(params)) {
38 case 8:
39 bfs = 16;
40 break;
41 case 16:
42 bfs = 32;
43 break;
44 default:
45 return -EINVAL;
48 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
49 * This criterion can't be met if we request PLL output
50 * as {8000x256, 64000x256, 11025x256}Hz.
51 * As a wayout, we rather change rfs to a minimum value that
52 * results in (params_rate(params) * rfs), and itself, acceptable
53 * to both - the CODEC and the CPU.
55 switch (params_rate(params)) {
56 case 16000:
57 case 22050:
58 case 32000:
59 case 44100:
60 case 48000:
61 case 88200:
62 case 96000:
63 rfs = 256;
64 break;
65 case 64000:
66 rfs = 384;
67 break;
68 case 8000:
69 case 11025:
70 rfs = 512;
71 break;
72 default:
73 return -EINVAL;
75 pll_out = params_rate(params) * rfs;
77 /* Set WM8580 to drive MCLK from its PLLA */
78 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
79 WM8580_CLKSRC_PLLA);
80 if (ret < 0)
81 return ret;
83 ret = snd_soc_dai_set_pll(codec_dai, WM8580_PLLA, 0,
84 SMDK_WM8580_FREQ, pll_out);
85 if (ret < 0)
86 return ret;
88 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_PLLA,
89 pll_out, SND_SOC_CLOCK_IN);
90 if (ret < 0)
91 return ret;
93 return 0;
97 * SMDK WM8580 DAI operations.
99 static struct snd_soc_ops smdk_ops = {
100 .hw_params = smdk_hw_params,
103 /* SMDK Playback widgets */
104 static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets[] = {
105 SND_SOC_DAPM_HP("Front", NULL),
106 SND_SOC_DAPM_HP("Center+Sub", NULL),
107 SND_SOC_DAPM_HP("Rear", NULL),
109 SND_SOC_DAPM_MIC("MicIn", NULL),
110 SND_SOC_DAPM_LINE("LineIn", NULL),
113 /* SMDK-PAIFTX connections */
114 static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
115 /* MicIn feeds AINL */
116 {"AINL", NULL, "MicIn"},
118 /* LineIn feeds AINL/R */
119 {"AINL", NULL, "LineIn"},
120 {"AINR", NULL, "LineIn"},
122 /* Front Left/Right are fed VOUT1L/R */
123 {"Front", NULL, "VOUT1L"},
124 {"Front", NULL, "VOUT1R"},
126 /* Center/Sub are fed VOUT2L/R */
127 {"Center+Sub", NULL, "VOUT2L"},
128 {"Center+Sub", NULL, "VOUT2R"},
130 /* Rear Left/Right are fed VOUT3L/R */
131 {"Rear", NULL, "VOUT3L"},
132 {"Rear", NULL, "VOUT3R"},
135 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
137 /* Enabling the microphone requires the fitting of a 0R
138 * resistor to connect the line from the microphone jack.
140 snd_soc_dapm_disable_pin(&rtd->card->dapm, "MicIn");
142 return 0;
145 enum {
146 PRI_PLAYBACK = 0,
147 PRI_CAPTURE,
150 #define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
151 SND_SOC_DAIFMT_CBM_CFM)
153 static struct snd_soc_dai_link smdk_dai[] = {
154 [PRI_PLAYBACK] = { /* Primary Playback i/f */
155 .name = "WM8580 PAIF RX",
156 .stream_name = "Playback",
157 .cpu_dai_name = "samsung-i2s.2",
158 .codec_dai_name = "wm8580-hifi-playback",
159 .platform_name = "samsung-i2s.0",
160 .codec_name = "wm8580.0-001b",
161 .dai_fmt = SMDK_DAI_FMT,
162 .ops = &smdk_ops,
164 [PRI_CAPTURE] = { /* Primary Capture i/f */
165 .name = "WM8580 PAIF TX",
166 .stream_name = "Capture",
167 .cpu_dai_name = "samsung-i2s.2",
168 .codec_dai_name = "wm8580-hifi-capture",
169 .platform_name = "samsung-i2s.0",
170 .codec_name = "wm8580.0-001b",
171 .dai_fmt = SMDK_DAI_FMT,
172 .init = smdk_wm8580_init_paiftx,
173 .ops = &smdk_ops,
177 static struct snd_soc_card smdk = {
178 .name = "SMDK-I2S",
179 .owner = THIS_MODULE,
180 .dai_link = smdk_dai,
181 .num_links = ARRAY_SIZE(smdk_dai),
183 .dapm_widgets = smdk_wm8580_dapm_widgets,
184 .num_dapm_widgets = ARRAY_SIZE(smdk_wm8580_dapm_widgets),
185 .dapm_routes = smdk_wm8580_audio_map,
186 .num_dapm_routes = ARRAY_SIZE(smdk_wm8580_audio_map),
189 static struct platform_device *smdk_snd_device;
191 static int __init smdk_audio_init(void)
193 int ret;
195 smdk_snd_device = platform_device_alloc("soc-audio", -1);
196 if (!smdk_snd_device)
197 return -ENOMEM;
199 platform_set_drvdata(smdk_snd_device, &smdk);
200 ret = platform_device_add(smdk_snd_device);
202 if (ret)
203 platform_device_put(smdk_snd_device);
205 return ret;
207 module_init(smdk_audio_init);
209 static void __exit smdk_audio_exit(void)
211 platform_device_unregister(smdk_snd_device);
213 module_exit(smdk_audio_exit);
215 MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
216 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
217 MODULE_LICENSE("GPL");