sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / soc / intel / boards / bytcr_rt5651.c
blob2d24dc04b5977a3bc8534e7e53780f6fb9f83547
1 /*
2 * bytcr_rt5651.c - ASoc Machine driver for Intel Byt CR platform
3 * (derived from bytcr_rt5640.c)
5 * Copyright (C) 2015 Intel Corp
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <linux/acpi.h>
24 #include <linux/device.h>
25 #include <linux/dmi.h>
26 #include <linux/slab.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/soc.h>
30 #include <sound/jack.h>
31 #include "../../codecs/rt5651.h"
32 #include "../atom/sst-atom-controls.h"
34 static const struct snd_soc_dapm_widget byt_rt5651_widgets[] = {
35 SND_SOC_DAPM_HP("Headphone", NULL),
36 SND_SOC_DAPM_MIC("Headset Mic", NULL),
37 SND_SOC_DAPM_MIC("Internal Mic", NULL),
38 SND_SOC_DAPM_SPK("Speaker", NULL),
41 static const struct snd_soc_dapm_route byt_rt5651_audio_map[] = {
42 {"AIF1 Playback", NULL, "ssp2 Tx"},
43 {"ssp2 Tx", NULL, "codec_out0"},
44 {"ssp2 Tx", NULL, "codec_out1"},
45 {"codec_in0", NULL, "ssp2 Rx"},
46 {"codec_in1", NULL, "ssp2 Rx"},
47 {"ssp2 Rx", NULL, "AIF1 Capture"},
49 {"Headset Mic", NULL, "micbias1"}, /* lowercase for rt5651 */
50 {"IN2P", NULL, "Headset Mic"},
51 {"Headphone", NULL, "HPOL"},
52 {"Headphone", NULL, "HPOR"},
53 {"Speaker", NULL, "LOUTL"},
54 {"Speaker", NULL, "LOUTR"},
57 static const struct snd_soc_dapm_route byt_rt5651_intmic_dmic1_map[] = {
58 {"DMIC1", NULL, "Internal Mic"},
61 static const struct snd_soc_dapm_route byt_rt5651_intmic_dmic2_map[] = {
62 {"DMIC2", NULL, "Internal Mic"},
65 static const struct snd_soc_dapm_route byt_rt5651_intmic_in1_map[] = {
66 {"Internal Mic", NULL, "micbias1"},
67 {"IN1P", NULL, "Internal Mic"},
70 enum {
71 BYT_RT5651_DMIC1_MAP,
72 BYT_RT5651_DMIC2_MAP,
73 BYT_RT5651_IN1_MAP,
76 #define BYT_RT5651_MAP(quirk) ((quirk) & 0xff)
77 #define BYT_RT5651_DMIC_EN BIT(16)
79 static unsigned long byt_rt5651_quirk = BYT_RT5651_DMIC1_MAP |
80 BYT_RT5651_DMIC_EN;
82 static const struct snd_kcontrol_new byt_rt5651_controls[] = {
83 SOC_DAPM_PIN_SWITCH("Headphone"),
84 SOC_DAPM_PIN_SWITCH("Headset Mic"),
85 SOC_DAPM_PIN_SWITCH("Internal Mic"),
86 SOC_DAPM_PIN_SWITCH("Speaker"),
89 static int byt_rt5651_aif1_hw_params(struct snd_pcm_substream *substream,
90 struct snd_pcm_hw_params *params)
92 struct snd_soc_pcm_runtime *rtd = substream->private_data;
93 struct snd_soc_dai *codec_dai = rtd->codec_dai;
94 int ret;
96 snd_soc_dai_set_bclk_ratio(codec_dai, 50);
98 ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_PLL1,
99 params_rate(params) * 512,
100 SND_SOC_CLOCK_IN);
101 if (ret < 0) {
102 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
103 return ret;
106 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5651_PLL1_S_BCLK1,
107 params_rate(params) * 50,
108 params_rate(params) * 512);
109 if (ret < 0) {
110 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
111 return ret;
114 return 0;
117 static const struct dmi_system_id byt_rt5651_quirk_table[] = {
121 static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime)
123 int ret;
124 struct snd_soc_card *card = runtime->card;
125 const struct snd_soc_dapm_route *custom_map;
126 int num_routes;
128 card->dapm.idle_bias_off = true;
130 dmi_check_system(byt_rt5651_quirk_table);
131 switch (BYT_RT5651_MAP(byt_rt5651_quirk)) {
132 case BYT_RT5651_IN1_MAP:
133 custom_map = byt_rt5651_intmic_in1_map;
134 num_routes = ARRAY_SIZE(byt_rt5651_intmic_in1_map);
135 break;
136 case BYT_RT5651_DMIC2_MAP:
137 custom_map = byt_rt5651_intmic_dmic2_map;
138 num_routes = ARRAY_SIZE(byt_rt5651_intmic_dmic2_map);
139 break;
140 default:
141 custom_map = byt_rt5651_intmic_dmic1_map;
142 num_routes = ARRAY_SIZE(byt_rt5651_intmic_dmic1_map);
145 ret = snd_soc_add_card_controls(card, byt_rt5651_controls,
146 ARRAY_SIZE(byt_rt5651_controls));
147 if (ret) {
148 dev_err(card->dev, "unable to add card controls\n");
149 return ret;
151 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
152 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
154 return ret;
157 static const struct snd_soc_pcm_stream byt_rt5651_dai_params = {
158 .formats = SNDRV_PCM_FMTBIT_S24_LE,
159 .rate_min = 48000,
160 .rate_max = 48000,
161 .channels_min = 2,
162 .channels_max = 2,
165 static int byt_rt5651_codec_fixup(struct snd_soc_pcm_runtime *rtd,
166 struct snd_pcm_hw_params *params)
168 struct snd_interval *rate = hw_param_interval(params,
169 SNDRV_PCM_HW_PARAM_RATE);
170 struct snd_interval *channels = hw_param_interval(params,
171 SNDRV_PCM_HW_PARAM_CHANNELS);
172 int ret;
174 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
175 rate->min = rate->max = 48000;
176 channels->min = channels->max = 2;
178 /* set SSP2 to 24-bit */
179 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
182 * Default mode for SSP configuration is TDM 4 slot, override config
183 * with explicit setting to I2S 2ch 24-bit. The word length is set with
184 * dai_set_tdm_slot() since there is no other API exposed
186 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
187 SND_SOC_DAIFMT_I2S |
188 SND_SOC_DAIFMT_NB_IF |
189 SND_SOC_DAIFMT_CBS_CFS
192 if (ret < 0) {
193 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
194 return ret;
197 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
198 if (ret < 0) {
199 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
200 return ret;
203 return 0;
206 static unsigned int rates_48000[] = {
207 48000,
210 static struct snd_pcm_hw_constraint_list constraints_48000 = {
211 .count = ARRAY_SIZE(rates_48000),
212 .list = rates_48000,
215 static int byt_rt5651_aif1_startup(struct snd_pcm_substream *substream)
217 return snd_pcm_hw_constraint_list(substream->runtime, 0,
218 SNDRV_PCM_HW_PARAM_RATE,
219 &constraints_48000);
222 static const struct snd_soc_ops byt_rt5651_aif1_ops = {
223 .startup = byt_rt5651_aif1_startup,
226 static const struct snd_soc_ops byt_rt5651_be_ssp2_ops = {
227 .hw_params = byt_rt5651_aif1_hw_params,
230 static struct snd_soc_dai_link byt_rt5651_dais[] = {
231 [MERR_DPCM_AUDIO] = {
232 .name = "Audio Port",
233 .stream_name = "Audio",
234 .cpu_dai_name = "media-cpu-dai",
235 .codec_dai_name = "snd-soc-dummy-dai",
236 .codec_name = "snd-soc-dummy",
237 .platform_name = "sst-mfld-platform",
238 .ignore_suspend = 1,
239 .nonatomic = true,
240 .dynamic = 1,
241 .dpcm_playback = 1,
242 .dpcm_capture = 1,
243 .ops = &byt_rt5651_aif1_ops,
245 [MERR_DPCM_DEEP_BUFFER] = {
246 .name = "Deep-Buffer Audio Port",
247 .stream_name = "Deep-Buffer Audio",
248 .cpu_dai_name = "deepbuffer-cpu-dai",
249 .codec_dai_name = "snd-soc-dummy-dai",
250 .codec_name = "snd-soc-dummy",
251 .platform_name = "sst-mfld-platform",
252 .ignore_suspend = 1,
253 .nonatomic = true,
254 .dynamic = 1,
255 .dpcm_playback = 1,
256 .ops = &byt_rt5651_aif1_ops,
258 [MERR_DPCM_COMPR] = {
259 .name = "Compressed Port",
260 .stream_name = "Compress",
261 .cpu_dai_name = "compress-cpu-dai",
262 .codec_dai_name = "snd-soc-dummy-dai",
263 .codec_name = "snd-soc-dummy",
264 .platform_name = "sst-mfld-platform",
266 /* CODEC<->CODEC link */
267 /* back ends */
269 .name = "SSP2-Codec",
270 .id = 1,
271 .cpu_dai_name = "ssp2-port",
272 .platform_name = "sst-mfld-platform",
273 .no_pcm = 1,
274 .codec_dai_name = "rt5651-aif1",
275 .codec_name = "i2c-10EC5651:00",
276 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
277 | SND_SOC_DAIFMT_CBS_CFS,
278 .be_hw_params_fixup = byt_rt5651_codec_fixup,
279 .ignore_suspend = 1,
280 .nonatomic = true,
281 .dpcm_playback = 1,
282 .dpcm_capture = 1,
283 .init = byt_rt5651_init,
284 .ops = &byt_rt5651_be_ssp2_ops,
288 /* SoC card */
289 static struct snd_soc_card byt_rt5651_card = {
290 .name = "bytcr-rt5651",
291 .owner = THIS_MODULE,
292 .dai_link = byt_rt5651_dais,
293 .num_links = ARRAY_SIZE(byt_rt5651_dais),
294 .dapm_widgets = byt_rt5651_widgets,
295 .num_dapm_widgets = ARRAY_SIZE(byt_rt5651_widgets),
296 .dapm_routes = byt_rt5651_audio_map,
297 .num_dapm_routes = ARRAY_SIZE(byt_rt5651_audio_map),
298 .fully_routed = true,
301 static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
303 int ret_val = 0;
305 /* register the soc card */
306 byt_rt5651_card.dev = &pdev->dev;
308 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5651_card);
310 if (ret_val) {
311 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
312 ret_val);
313 return ret_val;
315 platform_set_drvdata(pdev, &byt_rt5651_card);
316 return ret_val;
319 static struct platform_driver snd_byt_rt5651_mc_driver = {
320 .driver = {
321 .name = "bytcr_rt5651",
322 .pm = &snd_soc_pm_ops,
324 .probe = snd_byt_rt5651_mc_probe,
327 module_platform_driver(snd_byt_rt5651_mc_driver);
329 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver for RT5651");
330 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>");
331 MODULE_LICENSE("GPL v2");
332 MODULE_ALIAS("platform:bytcr_rt5651");