xref: /linux/sound/soc/samsung/smdk_wm8994.c (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 /*
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"
11 #include <sound/pcm_params.h>
12 #include <sound/soc.h>
13 #include <linux/module.h>
14 #include <linux/of.h>
15 #include <linux/of_device.h>
16 
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 
42 struct smdk_wm8994_data {
43 	int mclk1_rate;
44 };
45 
46 /* Default SMDKs */
47 static struct smdk_wm8994_data smdk_board_data = {
48 	.mclk1_rate = SMDK_WM8994_FREQ,
49 };
50 
51 static 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;
55 	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 */
60 	if (params_width(params) == 24)
61 		pll_out = params_rate(params) * 384;
62 	else if (params_rate(params) == 8000 || params_rate(params) == 11025)
63 		pll_out = params_rate(params) * 512;
64 	else
65 		pll_out = params_rate(params) * 256;
66 
67 	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  */
83 static struct snd_soc_ops smdk_ops = {
84 	.hw_params = smdk_hw_params,
85 };
86 
87 static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
88 {
89 	struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
90 
91 	/* Other pins NC */
92 	snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
93 	snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
94 	snd_soc_dapm_nc_pin(dapm, "SPKOUTLN");
95 	snd_soc_dapm_nc_pin(dapm, "SPKOUTLP");
96 	snd_soc_dapm_nc_pin(dapm, "SPKOUTRP");
97 	snd_soc_dapm_nc_pin(dapm, "SPKOUTRN");
98 	snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
99 	snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
100 	snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
101 	snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
102 	snd_soc_dapm_nc_pin(dapm, "IN1LP");
103 	snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
104 	snd_soc_dapm_nc_pin(dapm, "IN1RP");
105 	snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
106 
107 	return 0;
108 }
109 
110 static struct snd_soc_dai_link smdk_dai[] = {
111 	{ /* Primary DAI i/f */
112 		.name = "WM8994 AIF1",
113 		.stream_name = "Pri_Dai",
114 		.cpu_dai_name = "samsung-i2s.0",
115 		.codec_dai_name = "wm8994-aif1",
116 		.platform_name = "samsung-i2s.0",
117 		.codec_name = "wm8994-codec",
118 		.init = smdk_wm8994_init_paiftx,
119 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
120 			SND_SOC_DAIFMT_CBM_CFM,
121 		.ops = &smdk_ops,
122 	}, { /* Sec_Fifo Playback i/f */
123 		.name = "Sec_FIFO TX",
124 		.stream_name = "Sec_Dai",
125 		.cpu_dai_name = "samsung-i2s-sec",
126 		.codec_dai_name = "wm8994-aif1",
127 		.platform_name = "samsung-i2s-sec",
128 		.codec_name = "wm8994-codec",
129 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
130 			SND_SOC_DAIFMT_CBM_CFM,
131 		.ops = &smdk_ops,
132 	},
133 };
134 
135 static struct snd_soc_card smdk = {
136 	.name = "SMDK-I2S",
137 	.owner = THIS_MODULE,
138 	.dai_link = smdk_dai,
139 	.num_links = ARRAY_SIZE(smdk_dai),
140 };
141 
142 static const struct of_device_id samsung_wm8994_of_match[] = {
143 	{ .compatible = "samsung,smdk-wm8994", .data = &smdk_board_data },
144 	{},
145 };
146 MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
147 
148 static int smdk_audio_probe(struct platform_device *pdev)
149 {
150 	int ret;
151 	struct device_node *np = pdev->dev.of_node;
152 	struct snd_soc_card *card = &smdk;
153 	struct smdk_wm8994_data *board;
154 	const struct of_device_id *id;
155 
156 	card->dev = &pdev->dev;
157 
158 	board = devm_kzalloc(&pdev->dev, sizeof(*board), GFP_KERNEL);
159 	if (!board)
160 		return -ENOMEM;
161 
162 	if (np) {
163 		smdk_dai[0].cpu_dai_name = NULL;
164 		smdk_dai[0].cpu_of_node = of_parse_phandle(np,
165 				"samsung,i2s-controller", 0);
166 		if (!smdk_dai[0].cpu_of_node) {
167 			dev_err(&pdev->dev,
168 			   "Property 'samsung,i2s-controller' missing or invalid\n");
169 			ret = -EINVAL;
170 		}
171 
172 		smdk_dai[0].platform_name = NULL;
173 		smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node;
174 	}
175 
176 	id = of_match_device(of_match_ptr(samsung_wm8994_of_match), &pdev->dev);
177 	if (id)
178 		*board = *((struct smdk_wm8994_data *)id->data);
179 
180 	platform_set_drvdata(pdev, board);
181 
182 	ret = devm_snd_soc_register_card(&pdev->dev, card);
183 
184 	if (ret)
185 		dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
186 
187 	return ret;
188 }
189 
190 static struct platform_driver smdk_audio_driver = {
191 	.driver		= {
192 		.name	= "smdk-audio-wm8994",
193 		.of_match_table = of_match_ptr(samsung_wm8994_of_match),
194 		.pm	= &snd_soc_pm_ops,
195 	},
196 	.probe		= smdk_audio_probe,
197 };
198 
199 module_platform_driver(smdk_audio_driver);
200 
201 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
202 MODULE_LICENSE("GPL");
203 MODULE_ALIAS("platform:smdk-audio-wm8994");
204