Merge tag 'pwm/for-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry...
[deliverable/linux.git] / sound / soc / intel / bytcr_dpcm_rt5640.c
CommitLineData
996cc849
SP
1/*
2 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
3 *
4 * Copyright (C) 2014 Intel Corp
5 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
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.
11 *
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.
16 *
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/device.h>
24#include <linux/slab.h>
25#include <linux/input.h>
26#include <sound/pcm.h>
27#include <sound/pcm_params.h>
28#include <sound/soc.h>
29#include "../codecs/rt5640.h"
30#include "sst-atom-controls.h"
31
32static const struct snd_soc_dapm_widget byt_dapm_widgets[] = {
33 SND_SOC_DAPM_HP("Headphone", NULL),
34 SND_SOC_DAPM_MIC("Headset Mic", NULL),
35 SND_SOC_DAPM_MIC("Int Mic", NULL),
36 SND_SOC_DAPM_SPK("Ext Spk", NULL),
37};
38
39static const struct snd_soc_dapm_route byt_audio_map[] = {
40 {"IN2P", NULL, "Headset Mic"},
41 {"IN2N", NULL, "Headset Mic"},
42 {"Headset Mic", NULL, "MICBIAS1"},
43 {"IN1P", NULL, "MICBIAS1"},
44 {"LDO2", NULL, "Int Mic"},
45 {"Headphone", NULL, "HPOL"},
46 {"Headphone", NULL, "HPOR"},
47 {"Ext Spk", NULL, "SPOLP"},
48 {"Ext Spk", NULL, "SPOLN"},
49 {"Ext Spk", NULL, "SPORP"},
50 {"Ext Spk", NULL, "SPORN"},
51
52 {"AIF1 Playback", NULL, "ssp2 Tx"},
53 {"ssp2 Tx", NULL, "codec_out0"},
54 {"ssp2 Tx", NULL, "codec_out1"},
55 {"codec_in0", NULL, "ssp2 Rx"},
56 {"codec_in1", NULL, "ssp2 Rx"},
57 {"ssp2 Rx", NULL, "AIF1 Capture"},
58};
59
60static const struct snd_kcontrol_new byt_mc_controls[] = {
61 SOC_DAPM_PIN_SWITCH("Headphone"),
62 SOC_DAPM_PIN_SWITCH("Headset Mic"),
63 SOC_DAPM_PIN_SWITCH("Int Mic"),
64 SOC_DAPM_PIN_SWITCH("Ext Spk"),
65};
66
67static int byt_aif1_hw_params(struct snd_pcm_substream *substream,
68 struct snd_pcm_hw_params *params)
69{
70 struct snd_soc_pcm_runtime *rtd = substream->private_data;
71 struct snd_soc_dai *codec_dai = rtd->codec_dai;
72 int ret;
73
74 snd_soc_dai_set_bclk_ratio(codec_dai, 50);
75
76 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
77 params_rate(params) * 512,
78 SND_SOC_CLOCK_IN);
79 if (ret < 0) {
80 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
81 return ret;
82 }
83
84 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1,
85 params_rate(params) * 50,
86 params_rate(params) * 512);
87 if (ret < 0) {
88 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
89 return ret;
90 }
91
92 return 0;
93}
94
95static const struct snd_soc_pcm_stream byt_dai_params = {
96 .formats = SNDRV_PCM_FMTBIT_S24_LE,
97 .rate_min = 48000,
98 .rate_max = 48000,
99 .channels_min = 2,
100 .channels_max = 2,
101};
102
103static int byt_codec_fixup(struct snd_soc_pcm_runtime *rtd,
104 struct snd_pcm_hw_params *params)
105{
106 struct snd_interval *rate = hw_param_interval(params,
107 SNDRV_PCM_HW_PARAM_RATE);
108 struct snd_interval *channels = hw_param_interval(params,
109 SNDRV_PCM_HW_PARAM_CHANNELS);
110
111 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
112 rate->min = rate->max = 48000;
113 channels->min = channels->max = 2;
114
115 /* set SSP2 to 24-bit */
116 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
117 SNDRV_PCM_HW_PARAM_FIRST_MASK],
118 SNDRV_PCM_FORMAT_S24_LE);
119 return 0;
120}
121
122static unsigned int rates_48000[] = {
123 48000,
124};
125
126static struct snd_pcm_hw_constraint_list constraints_48000 = {
127 .count = ARRAY_SIZE(rates_48000),
128 .list = rates_48000,
129};
130
131static int byt_aif1_startup(struct snd_pcm_substream *substream)
132{
133 return snd_pcm_hw_constraint_list(substream->runtime, 0,
134 SNDRV_PCM_HW_PARAM_RATE,
135 &constraints_48000);
136}
137
138static struct snd_soc_ops byt_aif1_ops = {
139 .startup = byt_aif1_startup,
140};
141
142static struct snd_soc_ops byt_be_ssp2_ops = {
143 .hw_params = byt_aif1_hw_params,
144};
145
146static struct snd_soc_dai_link byt_dailink[] = {
147 [MERR_DPCM_AUDIO] = {
148 .name = "Baytrail Audio Port",
149 .stream_name = "Baytrail Audio",
150 .cpu_dai_name = "media-cpu-dai",
151 .codec_dai_name = "snd-soc-dummy-dai",
152 .codec_name = "snd-soc-dummy",
153 .platform_name = "sst-mfld-platform",
154 .ignore_suspend = 1,
155 .dynamic = 1,
156 .dpcm_playback = 1,
157 .dpcm_capture = 1,
158 .ops = &byt_aif1_ops,
159 },
160 [MERR_DPCM_COMPR] = {
161 .name = "Baytrail Compressed Port",
162 .stream_name = "Baytrail Compress",
163 .cpu_dai_name = "compress-cpu-dai",
164 .codec_dai_name = "snd-soc-dummy-dai",
165 .codec_name = "snd-soc-dummy",
166 .platform_name = "sst-mfld-platform",
167 },
168 /* back ends */
169 {
170 .name = "SSP2-Codec",
171 .be_id = 1,
172 .cpu_dai_name = "ssp2-port",
173 .platform_name = "sst-mfld-platform",
174 .no_pcm = 1,
175 .codec_dai_name = "rt5640-aif1",
176 .codec_name = "i2c-10EC5640:00",
177 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
178 | SND_SOC_DAIFMT_CBS_CFS,
179 .be_hw_params_fixup = byt_codec_fixup,
180 .ignore_suspend = 1,
181 .dpcm_playback = 1,
182 .dpcm_capture = 1,
183 .ops = &byt_be_ssp2_ops,
184 },
185};
186
187/* SoC card */
188static struct snd_soc_card snd_soc_card_byt = {
189 .name = "baytrailcraudio",
190 .dai_link = byt_dailink,
191 .num_links = ARRAY_SIZE(byt_dailink),
192 .dapm_widgets = byt_dapm_widgets,
193 .num_dapm_widgets = ARRAY_SIZE(byt_dapm_widgets),
194 .dapm_routes = byt_audio_map,
195 .num_dapm_routes = ARRAY_SIZE(byt_audio_map),
196 .controls = byt_mc_controls,
197 .num_controls = ARRAY_SIZE(byt_mc_controls),
198};
199
200static int snd_byt_mc_probe(struct platform_device *pdev)
201{
202 int ret_val = 0;
203
204 /* register the soc card */
205 snd_soc_card_byt.dev = &pdev->dev;
206
207 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_byt);
208 if (ret_val) {
209 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n", ret_val);
210 return ret_val;
211 }
212 platform_set_drvdata(pdev, &snd_soc_card_byt);
213 return ret_val;
214}
215
216static struct platform_driver snd_byt_mc_driver = {
217 .driver = {
218 .owner = THIS_MODULE,
219 .name = "bytt100_rt5640",
220 .pm = &snd_soc_pm_ops,
221 },
222 .probe = snd_byt_mc_probe,
223};
224
225module_platform_driver(snd_byt_mc_driver);
226
227MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
228MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
229MODULE_LICENSE("GPL v2");
230MODULE_ALIAS("platform:bytrt5640-audio");
This page took 0.059477 seconds and 5 git commands to generate.