blob: a56117536c946b74c14423dbb0a59a7a65c3892e [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>
Padmavathi Venna28a48052013-01-18 17:17:06 +053013#include <linux/of.h>
Jassi Brar96657d32010-12-20 11:05:57 +090014
15 /*
16 * Default CFG switch settings to use this driver:
17 * SMDKV310: CFG5-1000, CFG7-111111
18 */
19
20 /*
21 * Configure audio route as :-
22 * $ amixer sset 'DAC1' on,on
23 * $ amixer sset 'Right Headphone Mux' 'DAC'
24 * $ amixer sset 'Left Headphone Mux' 'DAC'
25 * $ amixer sset 'DAC1R Mixer AIF1.1' on
26 * $ amixer sset 'DAC1L Mixer AIF1.1' on
27 * $ amixer sset 'IN2L' on
28 * $ amixer sset 'IN2L PGA IN2LN' on
29 * $ amixer sset 'MIXINL IN2L' on
30 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
31 * $ amixer sset 'IN2R' on
32 * $ amixer sset 'IN2R PGA IN2RN' on
33 * $ amixer sset 'MIXINR IN2R' on
34 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
35 */
36
37/* SMDK has a 16.934MHZ crystal attached to WM8994 */
38#define SMDK_WM8994_FREQ 16934000
39
40static int smdk_hw_params(struct snd_pcm_substream *substream,
41 struct snd_pcm_hw_params *params)
42{
43 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Jassi Brar96657d32010-12-20 11:05:57 +090044 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
Jassi Brar96657d32010-12-20 11:05:57 +090056 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
57 SMDK_WM8994_FREQ, pll_out);
58 if (ret < 0)
59 return ret;
60
61 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
62 pll_out, SND_SOC_CLOCK_IN);
63 if (ret < 0)
64 return ret;
65
66 return 0;
67}
68
69/*
70 * SMDK WM8994 DAI operations.
71 */
72static struct snd_soc_ops smdk_ops = {
73 .hw_params = smdk_hw_params,
74};
75
76static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
77{
78 struct snd_soc_codec *codec = rtd->codec;
79 struct snd_soc_dapm_context *dapm = &codec->dapm;
80
81 /* HeadPhone */
82 snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
83 snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
84
85 /* MicIn */
86 snd_soc_dapm_enable_pin(dapm, "IN1LN");
87 snd_soc_dapm_enable_pin(dapm, "IN1RN");
88
89 /* LineIn */
90 snd_soc_dapm_enable_pin(dapm, "IN2LN");
91 snd_soc_dapm_enable_pin(dapm, "IN2RN");
92
93 /* Other pins NC */
94 snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
95 snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
96 snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
97 snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
98 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
99 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
100 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
101 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
102 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
103 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
104 snd_soc_dapm_nc_pin(dapm, "IN1LP");
105 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
106 snd_soc_dapm_nc_pin(dapm, "IN1RP");
107 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
108
Jassi Brar96657d32010-12-20 11:05:57 +0900109 return 0;
110}
111
112static struct snd_soc_dai_link smdk_dai[] = {
113 { /* Primary DAI i/f */
114 .name = "WM8994 AIF1",
115 .stream_name = "Pri_Dai",
116 .cpu_dai_name = "samsung-i2s.0",
117 .codec_dai_name = "wm8994-aif1",
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530118 .platform_name = "samsung-i2s.0",
Jassi Brar96657d32010-12-20 11:05:57 +0900119 .codec_name = "wm8994-codec",
120 .init = smdk_wm8994_init_paiftx,
Mark Brownf6ecf502013-07-26 12:01:53 +0100121 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
122 SND_SOC_DAIFMT_CBM_CFM,
Jassi Brar96657d32010-12-20 11:05:57 +0900123 .ops = &smdk_ops,
124 }, { /* Sec_Fifo Playback i/f */
125 .name = "Sec_FIFO TX",
126 .stream_name = "Sec_Dai",
Padmavathi Venna7c62eeb2013-01-18 17:17:00 +0530127 .cpu_dai_name = "samsung-i2s-sec",
Jassi Brar96657d32010-12-20 11:05:57 +0900128 .codec_dai_name = "wm8994-aif1",
Padmavathi Venna7c62eeb2013-01-18 17:17:00 +0530129 .platform_name = "samsung-i2s-sec",
Jassi Brar96657d32010-12-20 11:05:57 +0900130 .codec_name = "wm8994-codec",
Mark Brownf6ecf502013-07-26 12:01:53 +0100131 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
132 SND_SOC_DAIFMT_CBM_CFM,
Jassi Brar96657d32010-12-20 11:05:57 +0900133 .ops = &smdk_ops,
134 },
135};
136
137static struct snd_soc_card smdk = {
138 .name = "SMDK-I2S",
Axel Lin095d79d2011-12-22 10:53:15 +0800139 .owner = THIS_MODULE,
Jassi Brar96657d32010-12-20 11:05:57 +0900140 .dai_link = smdk_dai,
141 .num_links = ARRAY_SIZE(smdk_dai),
142};
143
Jassi Brar96657d32010-12-20 11:05:57 +0900144
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500145static int smdk_audio_probe(struct platform_device *pdev)
Jassi Brar96657d32010-12-20 11:05:57 +0900146{
147 int ret;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530148 struct device_node *np = pdev->dev.of_node;
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530149 struct snd_soc_card *card = &smdk;
Jassi Brar96657d32010-12-20 11:05:57 +0900150
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530151 card->dev = &pdev->dev;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530152
153 if (np) {
154 smdk_dai[0].cpu_dai_name = NULL;
155 smdk_dai[0].cpu_of_node = of_parse_phandle(np,
156 "samsung,i2s-controller", 0);
157 if (!smdk_dai[0].cpu_of_node) {
158 dev_err(&pdev->dev,
159 "Property 'samsung,i2s-controller' missing or invalid\n");
160 ret = -EINVAL;
161 }
162
163 smdk_dai[0].platform_name = NULL;
164 smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
165 }
166
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530167 ret = snd_soc_register_card(card);
Jassi Brar96657d32010-12-20 11:05:57 +0900168
Jassi Brar96657d32010-12-20 11:05:57 +0900169 if (ret)
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530170 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
Jassi Brar96657d32010-12-20 11:05:57 +0900171
172 return ret;
173}
Jassi Brar96657d32010-12-20 11:05:57 +0900174
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500175static int smdk_audio_remove(struct platform_device *pdev)
Jassi Brar96657d32010-12-20 11:05:57 +0900176{
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530177 struct snd_soc_card *card = platform_get_drvdata(pdev);
178
179 snd_soc_unregister_card(card);
180
181 return 0;
Jassi Brar96657d32010-12-20 11:05:57 +0900182}
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530183
Padmavathi Venna28a48052013-01-18 17:17:06 +0530184#ifdef CONFIG_OF
185static const struct of_device_id samsung_wm8994_of_match[] = {
186 { .compatible = "samsung,smdk-wm8994", },
187 {},
188};
189MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
190#endif /* CONFIG_OF */
191
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530192static struct platform_driver smdk_audio_driver = {
193 .driver = {
Mark Brown0d47acc2013-07-17 17:20:19 +0100194 .name = "smdk-audio-wm8894",
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530195 .owner = THIS_MODULE,
Padmavathi Venna28a48052013-01-18 17:17:06 +0530196 .of_match_table = of_match_ptr(samsung_wm8994_of_match),
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530197 },
198 .probe = smdk_audio_probe,
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500199 .remove = smdk_audio_remove,
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530200};
201
202module_platform_driver(smdk_audio_driver);
Jassi Brar96657d32010-12-20 11:05:57 +0900203
204MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
205MODULE_LICENSE("GPL");
Mark Brown0d47acc2013-07-17 17:20:19 +0100206MODULE_ALIAS("platform:smdk-audio-wm8994");