blob: 5b544dcf18b4696bd2b0fd2f7a8b375ddc42244a [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>
Sachin Kamatde0022d2013-10-16 15:58:48 +053012#include <sound/soc.h>
Boojin Kim3d94a2a2011-11-22 11:03:22 +090013#include <linux/module.h>
Padmavathi Venna28a48052013-01-18 17:17:06 +053014#include <linux/of.h>
Mark Brownd30c1482013-07-26 12:42:19 +010015#include <linux/of_device.h>
Jassi Brar96657d32010-12-20 11:05:57 +090016
17 /*
18 * Default CFG switch settings to use this driver:
19 * SMDKV310: CFG5-1000, CFG7-111111
20 */
21
22 /*
23 * Configure audio route as :-
24 * $ amixer sset 'DAC1' on,on
25 * $ amixer sset 'Right Headphone Mux' 'DAC'
26 * $ amixer sset 'Left Headphone Mux' 'DAC'
27 * $ amixer sset 'DAC1R Mixer AIF1.1' on
28 * $ amixer sset 'DAC1L Mixer AIF1.1' on
29 * $ amixer sset 'IN2L' on
30 * $ amixer sset 'IN2L PGA IN2LN' on
31 * $ amixer sset 'MIXINL IN2L' on
32 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on
33 * $ amixer sset 'IN2R' on
34 * $ amixer sset 'IN2R PGA IN2RN' on
35 * $ amixer sset 'MIXINR IN2R' on
36 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on
37 */
38
39/* SMDK has a 16.934MHZ crystal attached to WM8994 */
40#define SMDK_WM8994_FREQ 16934000
41
Mark Brownd30c1482013-07-26 12:42:19 +010042struct smdk_wm8994_data {
43 int mclk1_rate;
44};
45
46/* Default SMDKs */
47static struct smdk_wm8994_data smdk_board_data = {
48 .mclk1_rate = SMDK_WM8994_FREQ,
49};
50
Jassi Brar96657d32010-12-20 11:05:57 +090051static int smdk_hw_params(struct snd_pcm_substream *substream,
52 struct snd_pcm_hw_params *params)
53{
54 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Jassi Brar96657d32010-12-20 11:05:57 +090055 struct snd_soc_dai *codec_dai = rtd->codec_dai;
56 unsigned int pll_out;
57 int ret;
58
59 /* AIF1CLK should be >=3MHz for optimal performance */
Tushar Behera88ce1462014-05-23 17:35:39 +053060 if (params_width(params) == 24)
Giridhar Maruthyb3d76152011-07-13 16:52:06 +053061 pll_out = params_rate(params) * 384;
62 else if (params_rate(params) == 8000 || params_rate(params) == 11025)
Jassi Brar96657d32010-12-20 11:05:57 +090063 pll_out = params_rate(params) * 512;
64 else
65 pll_out = params_rate(params) * 256;
66
Jassi Brar96657d32010-12-20 11:05:57 +090067 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
68 SMDK_WM8994_FREQ, pll_out);
69 if (ret < 0)
70 return ret;
71
72 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
73 pll_out, SND_SOC_CLOCK_IN);
74 if (ret < 0)
75 return ret;
76
77 return 0;
78}
79
80/*
81 * SMDK WM8994 DAI operations.
82 */
83static struct snd_soc_ops smdk_ops = {
84 .hw_params = smdk_hw_params,
85};
86
87static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
88{
89 struct snd_soc_codec *codec = rtd->codec;
90 struct snd_soc_dapm_context *dapm = &codec->dapm;
91
92 /* HeadPhone */
93 snd_soc_dapm_enable_pin(dapm, "HPOUT1R");
94 snd_soc_dapm_enable_pin(dapm, "HPOUT1L");
95
96 /* MicIn */
97 snd_soc_dapm_enable_pin(dapm, "IN1LN");
98 snd_soc_dapm_enable_pin(dapm, "IN1RN");
99
100 /* LineIn */
101 snd_soc_dapm_enable_pin(dapm, "IN2LN");
102 snd_soc_dapm_enable_pin(dapm, "IN2RN");
103
104 /* Other pins NC */
105 snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
106 snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
107 snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
108 snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
109 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
110 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
111 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
112 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
113 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
114 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
115 snd_soc_dapm_nc_pin(dapm, "IN1LP");
116 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
117 snd_soc_dapm_nc_pin(dapm, "IN1RP");
118 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
119
Jassi Brar96657d32010-12-20 11:05:57 +0900120 return 0;
121}
122
123static struct snd_soc_dai_link smdk_dai[] = {
124 { /* Primary DAI i/f */
125 .name = "WM8994 AIF1",
126 .stream_name = "Pri_Dai",
127 .cpu_dai_name = "samsung-i2s.0",
128 .codec_dai_name = "wm8994-aif1",
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530129 .platform_name = "samsung-i2s.0",
Jassi Brar96657d32010-12-20 11:05:57 +0900130 .codec_name = "wm8994-codec",
131 .init = smdk_wm8994_init_paiftx,
Mark Brownf6ecf502013-07-26 12:01:53 +0100132 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
133 SND_SOC_DAIFMT_CBM_CFM,
Jassi Brar96657d32010-12-20 11:05:57 +0900134 .ops = &smdk_ops,
135 }, { /* Sec_Fifo Playback i/f */
136 .name = "Sec_FIFO TX",
137 .stream_name = "Sec_Dai",
Padmavathi Venna7c62eeb2013-01-18 17:17:00 +0530138 .cpu_dai_name = "samsung-i2s-sec",
Jassi Brar96657d32010-12-20 11:05:57 +0900139 .codec_dai_name = "wm8994-aif1",
Padmavathi Venna7c62eeb2013-01-18 17:17:00 +0530140 .platform_name = "samsung-i2s-sec",
Jassi Brar96657d32010-12-20 11:05:57 +0900141 .codec_name = "wm8994-codec",
Mark Brownf6ecf502013-07-26 12:01:53 +0100142 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
143 SND_SOC_DAIFMT_CBM_CFM,
Jassi Brar96657d32010-12-20 11:05:57 +0900144 .ops = &smdk_ops,
145 },
146};
147
148static struct snd_soc_card smdk = {
149 .name = "SMDK-I2S",
Axel Lin095d79d2011-12-22 10:53:15 +0800150 .owner = THIS_MODULE,
Jassi Brar96657d32010-12-20 11:05:57 +0900151 .dai_link = smdk_dai,
152 .num_links = ARRAY_SIZE(smdk_dai),
153};
154
Mark Brownd30c1482013-07-26 12:42:19 +0100155static const struct of_device_id samsung_wm8994_of_match[] = {
156 { .compatible = "samsung,smdk-wm8994", .data = &smdk_board_data },
157 {},
158};
159MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
Jassi Brar96657d32010-12-20 11:05:57 +0900160
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500161static int smdk_audio_probe(struct platform_device *pdev)
Jassi Brar96657d32010-12-20 11:05:57 +0900162{
163 int ret;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530164 struct device_node *np = pdev->dev.of_node;
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530165 struct snd_soc_card *card = &smdk;
Mark Brownd30c1482013-07-26 12:42:19 +0100166 struct smdk_wm8994_data *board;
167 const struct of_device_id *id;
Jassi Brar96657d32010-12-20 11:05:57 +0900168
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530169 card->dev = &pdev->dev;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530170
Mark Brownd30c1482013-07-26 12:42:19 +0100171 board = devm_kzalloc(&pdev->dev, sizeof(*board), GFP_KERNEL);
172 if (!board)
173 return -ENOMEM;
174
Padmavathi Venna28a48052013-01-18 17:17:06 +0530175 if (np) {
176 smdk_dai[0].cpu_dai_name = NULL;
177 smdk_dai[0].cpu_of_node = of_parse_phandle(np,
178 "samsung,i2s-controller", 0);
179 if (!smdk_dai[0].cpu_of_node) {
180 dev_err(&pdev->dev,
181 "Property 'samsung,i2s-controller' missing or invalid\n");
182 ret = -EINVAL;
183 }
184
185 smdk_dai[0].platform_name = NULL;
186 smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
187 }
188
Sachin Kamatf83183c2014-01-22 17:30:43 +0530189 id = of_match_device(of_match_ptr(samsung_wm8994_of_match), &pdev->dev);
Mark Brownd30c1482013-07-26 12:42:19 +0100190 if (id)
191 *board = *((struct smdk_wm8994_data *)id->data);
192
193 platform_set_drvdata(pdev, board);
194
Mark Brown9a8e0322013-09-16 18:02:28 +0100195 ret = devm_snd_soc_register_card(&pdev->dev, card);
Jassi Brar96657d32010-12-20 11:05:57 +0900196
Jassi Brar96657d32010-12-20 11:05:57 +0900197 if (ret)
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530198 dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
Jassi Brar96657d32010-12-20 11:05:57 +0900199
200 return ret;
201}
Jassi Brar96657d32010-12-20 11:05:57 +0900202
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530203static struct platform_driver smdk_audio_driver = {
204 .driver = {
Paul Bolle0b166d82014-02-10 22:25:31 +0100205 .name = "smdk-audio-wm8994",
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530206 .owner = THIS_MODULE,
Padmavathi Venna28a48052013-01-18 17:17:06 +0530207 .of_match_table = of_match_ptr(samsung_wm8994_of_match),
Sachin Kamatde0022d2013-10-16 15:58:48 +0530208 .pm = &snd_soc_pm_ops,
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530209 },
210 .probe = smdk_audio_probe,
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530211};
212
213module_platform_driver(smdk_audio_driver);
Jassi Brar96657d32010-12-20 11:05:57 +0900214
215MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
216MODULE_LICENSE("GPL");
Mark Brown0d47acc2013-07-17 17:20:19 +0100217MODULE_ALIAS("platform:smdk-audio-wm8994");