blob: dd0aa8cb1a9e6a1f40476c39addf1a676bfa1a97 [file] [log] [blame]
Jassi Brar96657d32010-12-20 11:05:57 +09001/*
2 * smdk_wm8994.c
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 */
9
10#include "../codecs/wm8994.h"
Giridhar Maruthyb3d76152011-07-13 16:52:06 +053011#include <sound/pcm_params.h>
Boojin Kim3d94a2a2011-11-22 11:03:22 +090012#include <linux/module.h>
Jassi Brar96657d32010-12-20 11:05:57 +090013
14 /*
15 * Default CFG switch settings to use this driver:
16 * SMDKV310: CFG5-1000, CFG7-111111
17 */
18
19 /*
20 * Configure audio route as :-
21 * $ amixer sset 'DAC1' on,on
22 * $ amixer sset 'Right Headphone Mux' 'DAC'
23 * $ amixer sset 'Left Headphone Mux' 'DAC'
24 * $ amixer sset 'DAC1R Mixer AIF1.1' on
25 * $ amixer sset 'DAC1L Mixer AIF1.1' on
26 * $ amixer sset 'IN2L' on
27 * $ amixer sset 'IN2L PGA IN2LN' on
28 * $ amixer sset 'MIXINL IN2L' on
29 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
30 * $ amixer sset 'IN2R' on
31 * $ amixer sset 'IN2R PGA IN2RN' on
32 * $ amixer sset 'MIXINR IN2R' on
33 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
34 */
35
36/* SMDK has a 16.934MHZ crystal attached to WM8994 */
37#define SMDK_WM8994_FREQ 16934000
38
39static int smdk_hw_params(struct snd_pcm_substream *substream,
40 struct snd_pcm_hw_params *params)
41{
42 struct snd_soc_pcm_runtime *rtd = substream->private_data;
43 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
44 struct snd_soc_dai *codec_dai = rtd->codec_dai;
45 unsigned int pll_out;
46 int ret;
47
48 /* AIF1CLK should be >=3MHz for optimal performance */
Giridhar Maruthyb3d76152011-07-13 16:52:06 +053049 if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE)
50 pll_out = params_rate(params) * 384;
51 else if (params_rate(params) == 8000 || params_rate(params) == 11025)
Jassi Brar96657d32010-12-20 11:05:57 +090052 pll_out = params_rate(params) * 512;
53 else
54 pll_out = params_rate(params) * 256;
55
56 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
57 | SND_SOC_DAIFMT_NB_NF
58 | SND_SOC_DAIFMT_CBM_CFM);
59 if (ret < 0)
60 return ret;
61
62 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
63 | SND_SOC_DAIFMT_NB_NF
64 | SND_SOC_DAIFMT_CBM_CFM);
65 if (ret < 0)
66 return ret;
67
68 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
69 SMDK_WM8994_FREQ, pll_out);
70 if (ret < 0)
71 return ret;
72
73 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
74 pll_out, SND_SOC_CLOCK_IN);
75 if (ret < 0)
76 return ret;
77
78 return 0;
79}
80
81/*
82 * SMDK WM8994 DAI operations.
83 */
84static struct snd_soc_ops smdk_ops = {
85 .hw_params = smdk_hw_params,
86};
87
88static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
89{
90 struct snd_soc_codec *codec = rtd->codec;
91 struct snd_soc_dapm_context *dapm = &codec->dapm;
92
93 /* HeadPhone */
94 snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
95 snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
96
97 /* MicIn */
98 snd_soc_dapm_enable_pin(dapm, "IN1LN");
99 snd_soc_dapm_enable_pin(dapm, "IN1RN");
100
101 /* LineIn */
102 snd_soc_dapm_enable_pin(dapm, "IN2LN");
103 snd_soc_dapm_enable_pin(dapm, "IN2RN");
104
105 /* Other pins NC */
106 snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
107 snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
108 snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
109 snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
110 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
111 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
112 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
113 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
114 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
115 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
116 snd_soc_dapm_nc_pin(dapm, "IN1LP");
117 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
118 snd_soc_dapm_nc_pin(dapm, "IN1RP");
119 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
120
Jassi Brar96657d32010-12-20 11:05:57 +0900121 return 0;
122}
123
124static struct snd_soc_dai_link smdk_dai[] = {
125 { /* Primary DAI i/f */
126 .name = "WM8994 AIF1",
127 .stream_name = "Pri_Dai",
128 .cpu_dai_name = "samsung-i2s.0",
129 .codec_dai_name = "wm8994-aif1",
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530130 .platform_name = "samsung-i2s.0",
Jassi Brar96657d32010-12-20 11:05:57 +0900131 .codec_name = "wm8994-codec",
132 .init = smdk_wm8994_init_paiftx,
133 .ops = &smdk_ops,
134 }, { /* Sec_Fifo Playback i/f */
135 .name = "Sec_FIFO TX",
136 .stream_name = "Sec_Dai",
137 .cpu_dai_name = "samsung-i2s.4",
138 .codec_dai_name = "wm8994-aif1",
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530139 .platform_name = "samsung-i2s.4",
Jassi Brar96657d32010-12-20 11:05:57 +0900140 .codec_name = "wm8994-codec",
141 .ops = &smdk_ops,
142 },
143};
144
145static struct snd_soc_card smdk = {
146 .name = "SMDK-I2S",
Axel Lin095d79d2011-12-22 10:53:15 +0800147 .owner = THIS_MODULE,
Jassi Brar96657d32010-12-20 11:05:57 +0900148 .dai_link = smdk_dai,
149 .num_links = ARRAY_SIZE(smdk_dai),
150};
151
Jassi Brar96657d32010-12-20 11:05:57 +0900152
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530153static int __devinit smdk_audio_probe(struct platform_device *pdev)
Jassi Brar96657d32010-12-20 11:05:57 +0900154{
155 int ret;
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530156 struct snd_soc_card *card = &smdk;
Jassi Brar96657d32010-12-20 11:05:57 +0900157
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530158 card->dev = &pdev->dev;
159 ret = snd_soc_register_card(card);
Jassi Brar96657d32010-12-20 11:05:57 +0900160
Jassi Brar96657d32010-12-20 11:05:57 +0900161 if (ret)
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530162 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
Jassi Brar96657d32010-12-20 11:05:57 +0900163
164 return ret;
165}
Jassi Brar96657d32010-12-20 11:05:57 +0900166
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530167static int __devexit smdk_audio_remove(struct platform_device *pdev)
Jassi Brar96657d32010-12-20 11:05:57 +0900168{
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530169 struct snd_soc_card *card = platform_get_drvdata(pdev);
170
171 snd_soc_unregister_card(card);
172
173 return 0;
Jassi Brar96657d32010-12-20 11:05:57 +0900174}
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530175
176static struct platform_driver smdk_audio_driver = {
177 .driver = {
178 .name = "smdk-audio",
179 .owner = THIS_MODULE,
180 },
181 .probe = smdk_audio_probe,
182 .remove = __devexit_p(smdk_audio_remove),
183};
184
185module_platform_driver(smdk_audio_driver);
Jassi Brar96657d32010-12-20 11:05:57 +0900186
187MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
188MODULE_LICENSE("GPL");
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530189MODULE_ALIAS("platform:smdk-audio");