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"
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
;
37 switch (params_width(params
)) {
45 /* The Fvco for WM8580 PLLs must fall within [90,100]MHz.
46 * This criterion can't be met if we request PLL output
47 * as {8000x256, 64000x256, 11025x256}Hz.
48 * As a wayout, we rather change rfs to a minimum value that
49 * results in (params_rate(params) * rfs), and itself, acceptable
50 * to both - the CODEC and the CPU.
52 switch (params_rate(params
)) {
72 pll_out
= params_rate(params
) * rfs
;
74 /* Set WM8580 to drive MCLK from its PLLA */
75 ret
= snd_soc_dai_set_clkdiv(codec_dai
, WM8580_MCLK
,
80 ret
= snd_soc_dai_set_pll(codec_dai
, WM8580_PLLA
, 0,
81 SMDK_WM8580_FREQ
, pll_out
);
85 ret
= snd_soc_dai_set_sysclk(codec_dai
, WM8580_CLKSRC_PLLA
,
86 pll_out
, SND_SOC_CLOCK_IN
);
94 * SMDK WM8580 DAI operations.
96 static struct snd_soc_ops smdk_ops
= {
97 .hw_params
= smdk_hw_params
,
100 /* SMDK Playback widgets */
101 static const struct snd_soc_dapm_widget smdk_wm8580_dapm_widgets
[] = {
102 SND_SOC_DAPM_HP("Front", NULL
),
103 SND_SOC_DAPM_HP("Center+Sub", NULL
),
104 SND_SOC_DAPM_HP("Rear", NULL
),
106 SND_SOC_DAPM_MIC("MicIn", NULL
),
107 SND_SOC_DAPM_LINE("LineIn", NULL
),
110 /* SMDK-PAIFTX connections */
111 static const struct snd_soc_dapm_route smdk_wm8580_audio_map
[] = {
112 /* MicIn feeds AINL */
113 {"AINL", NULL
, "MicIn"},
115 /* LineIn feeds AINL/R */
116 {"AINL", NULL
, "LineIn"},
117 {"AINR", NULL
, "LineIn"},
119 /* Front Left/Right are fed VOUT1L/R */
120 {"Front", NULL
, "VOUT1L"},
121 {"Front", NULL
, "VOUT1R"},
123 /* Center/Sub are fed VOUT2L/R */
124 {"Center+Sub", NULL
, "VOUT2L"},
125 {"Center+Sub", NULL
, "VOUT2R"},
127 /* Rear Left/Right are fed VOUT3L/R */
128 {"Rear", NULL
, "VOUT3L"},
129 {"Rear", NULL
, "VOUT3R"},
132 static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime
*rtd
)
134 /* Enabling the microphone requires the fitting of a 0R
135 * resistor to connect the line from the microphone jack.
137 snd_soc_dapm_disable_pin(&rtd
->card
->dapm
, "MicIn");
147 #define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
148 SND_SOC_DAIFMT_CBM_CFM)
150 static struct snd_soc_dai_link smdk_dai
[] = {
151 [PRI_PLAYBACK
] = { /* Primary Playback i/f */
152 .name
= "WM8580 PAIF RX",
153 .stream_name
= "Playback",
154 .cpu_dai_name
= "samsung-i2s.2",
155 .codec_dai_name
= "wm8580-hifi-playback",
156 .platform_name
= "samsung-i2s.0",
157 .codec_name
= "wm8580.0-001b",
158 .dai_fmt
= SMDK_DAI_FMT
,
161 [PRI_CAPTURE
] = { /* Primary Capture i/f */
162 .name
= "WM8580 PAIF TX",
163 .stream_name
= "Capture",
164 .cpu_dai_name
= "samsung-i2s.2",
165 .codec_dai_name
= "wm8580-hifi-capture",
166 .platform_name
= "samsung-i2s.0",
167 .codec_name
= "wm8580.0-001b",
168 .dai_fmt
= SMDK_DAI_FMT
,
169 .init
= smdk_wm8580_init_paiftx
,
174 static struct snd_soc_card smdk
= {
176 .owner
= THIS_MODULE
,
177 .dai_link
= smdk_dai
,
178 .num_links
= ARRAY_SIZE(smdk_dai
),
180 .dapm_widgets
= smdk_wm8580_dapm_widgets
,
181 .num_dapm_widgets
= ARRAY_SIZE(smdk_wm8580_dapm_widgets
),
182 .dapm_routes
= smdk_wm8580_audio_map
,
183 .num_dapm_routes
= ARRAY_SIZE(smdk_wm8580_audio_map
),
186 static struct platform_device
*smdk_snd_device
;
188 static int __init
smdk_audio_init(void)
192 smdk_snd_device
= platform_device_alloc("soc-audio", -1);
193 if (!smdk_snd_device
)
196 platform_set_drvdata(smdk_snd_device
, &smdk
);
197 ret
= platform_device_add(smdk_snd_device
);
200 platform_device_put(smdk_snd_device
);
204 module_init(smdk_audio_init
);
206 static void __exit
smdk_audio_exit(void)
208 platform_device_unregister(smdk_snd_device
);
210 module_exit(smdk_audio_exit
);
212 MODULE_AUTHOR("Jaswinder Singh, jassisinghbrar@gmail.com");
213 MODULE_DESCRIPTION("ALSA SoC SMDK WM8580");
214 MODULE_LICENSE("GPL");