aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/intel
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/intel')
-rw-r--r--sound/soc/intel/Kconfig13
-rw-r--r--sound/soc/intel/Makefile5
-rw-r--r--sound/soc/intel/mfld_machine.c427
-rw-r--r--sound/soc/intel/sst_dsp.h134
-rw-r--r--sound/soc/intel/sst_platform.c735
-rw-r--r--sound/soc/intel/sst_platform.h157
6 files changed, 1471 insertions, 0 deletions
diff --git a/sound/soc/intel/Kconfig b/sound/soc/intel/Kconfig
new file mode 100644
index 000000000000..61c10bf503d2
--- /dev/null
+++ b/sound/soc/intel/Kconfig
@@ -0,0 +1,13 @@
1config SND_MFLD_MACHINE
2 tristate "SOC Machine Audio driver for Intel Medfield MID platform"
3 depends on INTEL_SCU_IPC
4 select SND_SOC_SN95031
5 select SND_SST_PLATFORM
6 help
7 This adds support for ASoC machine driver for Intel(R) MID Medfield platform
8 used as alsa device in audio substem in Intel(R) MID devices
9 Say Y if you have such a device
10 If unsure select "N".
11
12config SND_SST_PLATFORM
13 tristate
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile
new file mode 100644
index 000000000000..639883339465
--- /dev/null
+++ b/sound/soc/intel/Makefile
@@ -0,0 +1,5 @@
1snd-soc-sst-platform-objs := sst_platform.o
2snd-soc-mfld-machine-objs := mfld_machine.o
3
4obj-$(CONFIG_SND_SST_PLATFORM) += snd-soc-sst-platform.o
5obj-$(CONFIG_SND_MFLD_MACHINE) += snd-soc-mfld-machine.o
diff --git a/sound/soc/intel/mfld_machine.c b/sound/soc/intel/mfld_machine.c
new file mode 100644
index 000000000000..d3d4c32434f7
--- /dev/null
+++ b/sound/soc/intel/mfld_machine.c
@@ -0,0 +1,427 @@
1/*
2 * mfld_machine.c - ASoc Machine driver for Intel Medfield MID platform
3 *
4 * Copyright (C) 2010 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * Author: Harsha Priya <priya.harsha@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
27#include <linux/init.h>
28#include <linux/device.h>
29#include <linux/slab.h>
30#include <linux/io.h>
31#include <linux/module.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/soc.h>
35#include <sound/jack.h>
36#include "../codecs/sn95031.h"
37
38#define MID_MONO 1
39#define MID_STEREO 2
40#define MID_MAX_CAP 5
41#define MFLD_JACK_INSERT 0x04
42
43enum soc_mic_bias_zones {
44 MFLD_MV_START = 0,
45 /* mic bias volutage range for Headphones*/
46 MFLD_MV_HP = 400,
47 /* mic bias volutage range for American Headset*/
48 MFLD_MV_AM_HS = 650,
49 /* mic bias volutage range for Headset*/
50 MFLD_MV_HS = 2000,
51 MFLD_MV_UNDEFINED,
52};
53
54static unsigned int hs_switch;
55static unsigned int lo_dac;
56
57struct mfld_mc_private {
58 void __iomem *int_base;
59 u8 interrupt_status;
60};
61
62struct snd_soc_jack mfld_jack;
63
64/*Headset jack detection DAPM pins */
65static struct snd_soc_jack_pin mfld_jack_pins[] = {
66 {
67 .pin = "Headphones",
68 .mask = SND_JACK_HEADPHONE,
69 },
70 {
71 .pin = "AMIC1",
72 .mask = SND_JACK_MICROPHONE,
73 },
74};
75
76/* jack detection voltage zones */
77static struct snd_soc_jack_zone mfld_zones[] = {
78 {MFLD_MV_START, MFLD_MV_AM_HS, SND_JACK_HEADPHONE},
79 {MFLD_MV_AM_HS, MFLD_MV_HS, SND_JACK_HEADSET},
80};
81
82/* sound card controls */
83static const char *headset_switch_text[] = {"Earpiece", "Headset"};
84
85static const char *lo_text[] = {"Vibra", "Headset", "IHF", "None"};
86
87static const struct soc_enum headset_enum =
88 SOC_ENUM_SINGLE_EXT(2, headset_switch_text);
89
90static const struct soc_enum lo_enum =
91 SOC_ENUM_SINGLE_EXT(4, lo_text);
92
93static int headset_get_switch(struct snd_kcontrol *kcontrol,
94 struct snd_ctl_elem_value *ucontrol)
95{
96 ucontrol->value.integer.value[0] = hs_switch;
97 return 0;
98}
99
100static int headset_set_switch(struct snd_kcontrol *kcontrol,
101 struct snd_ctl_elem_value *ucontrol)
102{
103 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
104
105 if (ucontrol->value.integer.value[0] == hs_switch)
106 return 0;
107
108 if (ucontrol->value.integer.value[0]) {
109 pr_debug("hs_set HS path\n");
110 snd_soc_dapm_enable_pin(&codec->dapm, "Headphones");
111 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT");
112 } else {
113 pr_debug("hs_set EP path\n");
114 snd_soc_dapm_disable_pin(&codec->dapm, "Headphones");
115 snd_soc_dapm_enable_pin(&codec->dapm, "EPOUT");
116 }
117 snd_soc_dapm_sync(&codec->dapm);
118 hs_switch = ucontrol->value.integer.value[0];
119
120 return 0;
121}
122
123static void lo_enable_out_pins(struct snd_soc_codec *codec)
124{
125 snd_soc_dapm_enable_pin(&codec->dapm, "IHFOUTL");
126 snd_soc_dapm_enable_pin(&codec->dapm, "IHFOUTR");
127 snd_soc_dapm_enable_pin(&codec->dapm, "LINEOUTL");
128 snd_soc_dapm_enable_pin(&codec->dapm, "LINEOUTR");
129 snd_soc_dapm_enable_pin(&codec->dapm, "VIB1OUT");
130 snd_soc_dapm_enable_pin(&codec->dapm, "VIB2OUT");
131 if (hs_switch) {
132 snd_soc_dapm_enable_pin(&codec->dapm, "Headphones");
133 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT");
134 } else {
135 snd_soc_dapm_disable_pin(&codec->dapm, "Headphones");
136 snd_soc_dapm_enable_pin(&codec->dapm, "EPOUT");
137 }
138}
139
140static int lo_get_switch(struct snd_kcontrol *kcontrol,
141 struct snd_ctl_elem_value *ucontrol)
142{
143 ucontrol->value.integer.value[0] = lo_dac;
144 return 0;
145}
146
147static int lo_set_switch(struct snd_kcontrol *kcontrol,
148 struct snd_ctl_elem_value *ucontrol)
149{
150 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
151
152 if (ucontrol->value.integer.value[0] == lo_dac)
153 return 0;
154
155 /* we dont want to work with last state of lineout so just enable all
156 * pins and then disable pins not required
157 */
158 lo_enable_out_pins(codec);
159 switch (ucontrol->value.integer.value[0]) {
160 case 0:
161 pr_debug("set vibra path\n");
162 snd_soc_dapm_disable_pin(&codec->dapm, "VIB1OUT");
163 snd_soc_dapm_disable_pin(&codec->dapm, "VIB2OUT");
164 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0);
165 break;
166
167 case 1:
168 pr_debug("set hs path\n");
169 snd_soc_dapm_disable_pin(&codec->dapm, "Headphones");
170 snd_soc_dapm_disable_pin(&codec->dapm, "EPOUT");
171 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x22);
172 break;
173
174 case 2:
175 pr_debug("set spkr path\n");
176 snd_soc_dapm_disable_pin(&codec->dapm, "IHFOUTL");
177 snd_soc_dapm_disable_pin(&codec->dapm, "IHFOUTR");
178 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x44);
179 break;
180
181 case 3:
182 pr_debug("set null path\n");
183 snd_soc_dapm_disable_pin(&codec->dapm, "LINEOUTL");
184 snd_soc_dapm_disable_pin(&codec->dapm, "LINEOUTR");
185 snd_soc_update_bits(codec, SN95031_LOCTL, 0x66, 0x66);
186 break;
187 }
188 snd_soc_dapm_sync(&codec->dapm);
189 lo_dac = ucontrol->value.integer.value[0];
190 return 0;
191}
192
193static const struct snd_kcontrol_new mfld_snd_controls[] = {
194 SOC_ENUM_EXT("Playback Switch", headset_enum,
195 headset_get_switch, headset_set_switch),
196 SOC_ENUM_EXT("Lineout Mux", lo_enum,
197 lo_get_switch, lo_set_switch),
198};
199
200static const struct snd_soc_dapm_widget mfld_widgets[] = {
201 SND_SOC_DAPM_HP("Headphones", NULL),
202 SND_SOC_DAPM_MIC("Mic", NULL),
203};
204
205static const struct snd_soc_dapm_route mfld_map[] = {
206 {"Headphones", NULL, "HPOUTR"},
207 {"Headphones", NULL, "HPOUTL"},
208 {"Mic", NULL, "AMIC1"},
209};
210
211static void mfld_jack_check(unsigned int intr_status)
212{
213 struct mfld_jack_data jack_data;
214
215 jack_data.mfld_jack = &mfld_jack;
216 jack_data.intr_id = intr_status;
217
218 sn95031_jack_detection(&jack_data);
219 /* TODO: add american headset detection post gpiolib support */
220}
221
222static int mfld_init(struct snd_soc_pcm_runtime *runtime)
223{
224 struct snd_soc_codec *codec = runtime->codec;
225 struct snd_soc_dapm_context *dapm = &codec->dapm;
226 int ret_val;
227
228 /* Add jack sense widgets */
229 snd_soc_dapm_new_controls(dapm, mfld_widgets, ARRAY_SIZE(mfld_widgets));
230
231 /* Set up the map */
232 snd_soc_dapm_add_routes(dapm, mfld_map, ARRAY_SIZE(mfld_map));
233
234 /* always connected */
235 snd_soc_dapm_enable_pin(dapm, "Headphones");
236 snd_soc_dapm_enable_pin(dapm, "Mic");
237
238 ret_val = snd_soc_add_codec_controls(codec, mfld_snd_controls,
239 ARRAY_SIZE(mfld_snd_controls));
240 if (ret_val) {
241 pr_err("soc_add_controls failed %d", ret_val);
242 return ret_val;
243 }
244 /* default is earpiece pin, userspace sets it explcitly */
245 snd_soc_dapm_disable_pin(dapm, "Headphones");
246 /* default is lineout NC, userspace sets it explcitly */
247 snd_soc_dapm_disable_pin(dapm, "LINEOUTL");
248 snd_soc_dapm_disable_pin(dapm, "LINEOUTR");
249 lo_dac = 3;
250 hs_switch = 0;
251 /* we dont use linein in this so set to NC */
252 snd_soc_dapm_disable_pin(dapm, "LINEINL");
253 snd_soc_dapm_disable_pin(dapm, "LINEINR");
254
255 /* Headset and button jack detection */
256 ret_val = snd_soc_jack_new(codec, "Intel(R) MID Audio Jack",
257 SND_JACK_HEADSET | SND_JACK_BTN_0 |
258 SND_JACK_BTN_1, &mfld_jack);
259 if (ret_val) {
260 pr_err("jack creation failed\n");
261 return ret_val;
262 }
263
264 ret_val = snd_soc_jack_add_pins(&mfld_jack,
265 ARRAY_SIZE(mfld_jack_pins), mfld_jack_pins);
266 if (ret_val) {
267 pr_err("adding jack pins failed\n");
268 return ret_val;
269 }
270 ret_val = snd_soc_jack_add_zones(&mfld_jack,
271 ARRAY_SIZE(mfld_zones), mfld_zones);
272 if (ret_val) {
273 pr_err("adding jack zones failed\n");
274 return ret_val;
275 }
276
277 /* we want to check if anything is inserted at boot,
278 * so send a fake event to codec and it will read adc
279 * to find if anything is there or not */
280 mfld_jack_check(MFLD_JACK_INSERT);
281 return ret_val;
282}
283
284static struct snd_soc_dai_link mfld_msic_dailink[] = {
285 {
286 .name = "Medfield Headset",
287 .stream_name = "Headset",
288 .cpu_dai_name = "Headset-cpu-dai",
289 .codec_dai_name = "SN95031 Headset",
290 .codec_name = "sn95031",
291 .platform_name = "sst-platform",
292 .init = mfld_init,
293 },
294 {
295 .name = "Medfield Speaker",
296 .stream_name = "Speaker",
297 .cpu_dai_name = "Speaker-cpu-dai",
298 .codec_dai_name = "SN95031 Speaker",
299 .codec_name = "sn95031",
300 .platform_name = "sst-platform",
301 .init = NULL,
302 },
303 {
304 .name = "Medfield Vibra",
305 .stream_name = "Vibra1",
306 .cpu_dai_name = "Vibra1-cpu-dai",
307 .codec_dai_name = "SN95031 Vibra1",
308 .codec_name = "sn95031",
309 .platform_name = "sst-platform",
310 .init = NULL,
311 },
312 {
313 .name = "Medfield Haptics",
314 .stream_name = "Vibra2",
315 .cpu_dai_name = "Vibra2-cpu-dai",
316 .codec_dai_name = "SN95031 Vibra2",
317 .codec_name = "sn95031",
318 .platform_name = "sst-platform",
319 .init = NULL,
320 },
321 {
322 .name = "Medfield Compress",
323 .stream_name = "Speaker",
324 .cpu_dai_name = "Compress-cpu-dai",
325 .codec_dai_name = "SN95031 Speaker",
326 .codec_name = "sn95031",
327 .platform_name = "sst-platform",
328 .init = NULL,
329 },
330};
331
332/* SoC card */
333static struct snd_soc_card snd_soc_card_mfld = {
334 .name = "medfield_audio",
335 .owner = THIS_MODULE,
336 .dai_link = mfld_msic_dailink,
337 .num_links = ARRAY_SIZE(mfld_msic_dailink),
338};
339
340static irqreturn_t snd_mfld_jack_intr_handler(int irq, void *dev)
341{
342 struct mfld_mc_private *mc_private = (struct mfld_mc_private *) dev;
343
344 memcpy_fromio(&mc_private->interrupt_status,
345 ((void *)(mc_private->int_base)),
346 sizeof(u8));
347 return IRQ_WAKE_THREAD;
348}
349
350static irqreturn_t snd_mfld_jack_detection(int irq, void *data)
351{
352 struct mfld_mc_private *mc_drv_ctx = (struct mfld_mc_private *) data;
353
354 if (mfld_jack.codec == NULL)
355 return IRQ_HANDLED;
356 mfld_jack_check(mc_drv_ctx->interrupt_status);
357
358 return IRQ_HANDLED;
359}
360
361static int snd_mfld_mc_probe(struct platform_device *pdev)
362{
363 int ret_val = 0, irq;
364 struct mfld_mc_private *mc_drv_ctx;
365 struct resource *irq_mem;
366
367 pr_debug("snd_mfld_mc_probe called\n");
368
369 /* retrive the irq number */
370 irq = platform_get_irq(pdev, 0);
371
372 /* audio interrupt base of SRAM location where
373 * interrupts are stored by System FW */
374 mc_drv_ctx = devm_kzalloc(&pdev->dev, sizeof(*mc_drv_ctx), GFP_ATOMIC);
375 if (!mc_drv_ctx) {
376 pr_err("allocation failed\n");
377 return -ENOMEM;
378 }
379
380 irq_mem = platform_get_resource_byname(
381 pdev, IORESOURCE_MEM, "IRQ_BASE");
382 if (!irq_mem) {
383 pr_err("no mem resource given\n");
384 return -ENODEV;
385 }
386 mc_drv_ctx->int_base = devm_ioremap_nocache(&pdev->dev, irq_mem->start,
387 resource_size(irq_mem));
388 if (!mc_drv_ctx->int_base) {
389 pr_err("Mapping of cache failed\n");
390 return -ENOMEM;
391 }
392 /* register for interrupt */
393 ret_val = devm_request_threaded_irq(&pdev->dev, irq,
394 snd_mfld_jack_intr_handler,
395 snd_mfld_jack_detection,
396 IRQF_SHARED, pdev->dev.driver->name, mc_drv_ctx);
397 if (ret_val) {
398 pr_err("cannot register IRQ\n");
399 return ret_val;
400 }
401 /* register the soc card */
402 snd_soc_card_mfld.dev = &pdev->dev;
403 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_mfld);
404 if (ret_val) {
405 pr_debug("snd_soc_register_card failed %d\n", ret_val);
406 return ret_val;
407 }
408 platform_set_drvdata(pdev, mc_drv_ctx);
409 pr_debug("successfully exited probe\n");
410 return 0;
411}
412
413static struct platform_driver snd_mfld_mc_driver = {
414 .driver = {
415 .owner = THIS_MODULE,
416 .name = "msic_audio",
417 },
418 .probe = snd_mfld_mc_probe,
419};
420
421module_platform_driver(snd_mfld_mc_driver);
422
423MODULE_DESCRIPTION("ASoC Intel(R) MID Machine driver");
424MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
425MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
426MODULE_LICENSE("GPL v2");
427MODULE_ALIAS("platform:msic-audio");
diff --git a/sound/soc/intel/sst_dsp.h b/sound/soc/intel/sst_dsp.h
new file mode 100644
index 000000000000..0fce1de284ff
--- /dev/null
+++ b/sound/soc/intel/sst_dsp.h
@@ -0,0 +1,134 @@
1#ifndef __SST_DSP_H__
2#define __SST_DSP_H__
3/*
4 * sst_dsp.h - Intel SST Driver for audio engine
5 *
6 * Copyright (C) 2008-12 Intel Corporation
7 * Authors: Vinod Koul <vinod.koul@linux.intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26enum sst_codec_types {
27 /* AUDIO/MUSIC CODEC Type Definitions */
28 SST_CODEC_TYPE_UNKNOWN = 0,
29 SST_CODEC_TYPE_PCM, /* Pass through Audio codec */
30 SST_CODEC_TYPE_MP3,
31 SST_CODEC_TYPE_MP24,
32 SST_CODEC_TYPE_AAC,
33 SST_CODEC_TYPE_AACP,
34 SST_CODEC_TYPE_eAACP,
35};
36
37enum stream_type {
38 SST_STREAM_TYPE_NONE = 0,
39 SST_STREAM_TYPE_MUSIC = 1,
40};
41
42struct snd_pcm_params {
43 u16 codec; /* codec type */
44 u8 num_chan; /* 1=Mono, 2=Stereo */
45 u8 pcm_wd_sz; /* 16/24 - bit*/
46 u32 reserved; /* Bitrate in bits per second */
47 u32 sfreq; /* Sampling rate in Hz */
48 u8 use_offload_path;
49 u8 reserved2;
50 u16 reserved3;
51 u8 channel_map[8];
52} __packed;
53
54/* MP3 Music Parameters Message */
55struct snd_mp3_params {
56 u16 codec;
57 u8 num_chan; /* 1=Mono, 2=Stereo */
58 u8 pcm_wd_sz; /* 16/24 - bit*/
59 u8 crc_check; /* crc_check - disable (0) or enable (1) */
60 u8 reserved1; /* unused*/
61 u16 reserved2; /* Unused */
62} __packed;
63
64#define AAC_BIT_STREAM_ADTS 0
65#define AAC_BIT_STREAM_ADIF 1
66#define AAC_BIT_STREAM_RAW 2
67
68/* AAC Music Parameters Message */
69struct snd_aac_params {
70 u16 codec;
71 u8 num_chan; /* 1=Mono, 2=Stereo*/
72 u8 pcm_wd_sz; /* 16/24 - bit*/
73 u8 bdownsample; /*SBR downsampling 0 - disable 1 -enabled AAC+ only */
74 u8 bs_format; /* input bit stream format adts=0, adif=1, raw=2 */
75 u16 reser2;
76 u32 externalsr; /*sampling rate of basic AAC raw bit stream*/
77 u8 sbr_signalling;/*disable/enable/set automode the SBR tool.AAC+*/
78 u8 reser1;
79 u16 reser3;
80} __packed;
81
82/* WMA Music Parameters Message */
83struct snd_wma_params {
84 u16 codec;
85 u8 num_chan; /* 1=Mono, 2=Stereo */
86 u8 pcm_wd_sz; /* 16/24 - bit*/
87 u32 brate; /* Use the hard coded value. */
88 u32 sfreq; /* Sampling freq eg. 8000, 441000, 48000 */
89 u32 channel_mask; /* Channel Mask */
90 u16 format_tag; /* Format Tag */
91 u16 block_align; /* packet size */
92 u16 wma_encode_opt;/* Encoder option */
93 u8 op_align; /* op align 0- 16 bit, 1- MSB, 2 LSB */
94 u8 reserved; /* reserved */
95} __packed;
96
97/* Codec params struture */
98union snd_sst_codec_params {
99 struct snd_pcm_params pcm_params;
100 struct snd_mp3_params mp3_params;
101 struct snd_aac_params aac_params;
102 struct snd_wma_params wma_params;
103} __packed;
104
105/* Address and size info of a frame buffer */
106struct sst_address_info {
107 u32 addr; /* Address at IA */
108 u32 size; /* Size of the buffer */
109};
110
111struct snd_sst_alloc_params_ext {
112 struct sst_address_info ring_buf_info[8];
113 u8 sg_count;
114 u8 reserved;
115 u16 reserved2;
116 u32 frag_size; /*Number of samples after which period elapsed
117 message is sent valid only if path = 0*/
118} __packed;
119
120struct snd_sst_stream_params {
121 union snd_sst_codec_params uc;
122} __packed;
123
124struct snd_sst_params {
125 u32 stream_id;
126 u8 codec;
127 u8 ops;
128 u8 stream_type;
129 u8 device_type;
130 struct snd_sst_stream_params sparams;
131 struct snd_sst_alloc_params_ext aparams;
132};
133
134#endif /* __SST_DSP_H__ */
diff --git a/sound/soc/intel/sst_platform.c b/sound/soc/intel/sst_platform.c
new file mode 100644
index 000000000000..b6b5eb698d33
--- /dev/null
+++ b/sound/soc/intel/sst_platform.c
@@ -0,0 +1,735 @@
1/*
2 * sst_platform.c - Intel MID Platform driver
3 *
4 * Copyright (C) 2010-2013 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * Author: Harsha Priya <priya.harsha@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 *
24 *
25 */
26#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27
28#include <linux/slab.h>
29#include <linux/io.h>
30#include <linux/module.h>
31#include <sound/core.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/soc.h>
35#include <sound/compress_driver.h>
36#include "sst_platform.h"
37
38static struct sst_device *sst;
39static DEFINE_MUTEX(sst_lock);
40
41int sst_register_dsp(struct sst_device *dev)
42{
43 if (WARN_ON(!dev))
44 return -EINVAL;
45 if (!try_module_get(dev->dev->driver->owner))
46 return -ENODEV;
47 mutex_lock(&sst_lock);
48 if (sst) {
49 pr_err("we already have a device %s\n", sst->name);
50 module_put(dev->dev->driver->owner);
51 mutex_unlock(&sst_lock);
52 return -EEXIST;
53 }
54 pr_debug("registering device %s\n", dev->name);
55 sst = dev;
56 mutex_unlock(&sst_lock);
57 return 0;
58}
59EXPORT_SYMBOL_GPL(sst_register_dsp);
60
61int sst_unregister_dsp(struct sst_device *dev)
62{
63 if (WARN_ON(!dev))
64 return -EINVAL;
65 if (dev != sst)
66 return -EINVAL;
67
68 mutex_lock(&sst_lock);
69
70 if (!sst) {
71 mutex_unlock(&sst_lock);
72 return -EIO;
73 }
74
75 module_put(sst->dev->driver->owner);
76 pr_debug("unreg %s\n", sst->name);
77 sst = NULL;
78 mutex_unlock(&sst_lock);
79 return 0;
80}
81EXPORT_SYMBOL_GPL(sst_unregister_dsp);
82
83static struct snd_pcm_hardware sst_platform_pcm_hw = {
84 .info = (SNDRV_PCM_INFO_INTERLEAVED |
85 SNDRV_PCM_INFO_DOUBLE |
86 SNDRV_PCM_INFO_PAUSE |
87 SNDRV_PCM_INFO_RESUME |
88 SNDRV_PCM_INFO_MMAP|
89 SNDRV_PCM_INFO_MMAP_VALID |
90 SNDRV_PCM_INFO_BLOCK_TRANSFER |
91 SNDRV_PCM_INFO_SYNC_START),
92 .formats = (SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_U16 |
93 SNDRV_PCM_FMTBIT_S24 | SNDRV_PCM_FMTBIT_U24 |
94 SNDRV_PCM_FMTBIT_S32 | SNDRV_PCM_FMTBIT_U32),
95 .rates = (SNDRV_PCM_RATE_8000|
96 SNDRV_PCM_RATE_44100 |
97 SNDRV_PCM_RATE_48000),
98 .rate_min = SST_MIN_RATE,
99 .rate_max = SST_MAX_RATE,
100 .channels_min = SST_MIN_CHANNEL,
101 .channels_max = SST_MAX_CHANNEL,
102 .buffer_bytes_max = SST_MAX_BUFFER,
103 .period_bytes_min = SST_MIN_PERIOD_BYTES,
104 .period_bytes_max = SST_MAX_PERIOD_BYTES,
105 .periods_min = SST_MIN_PERIODS,
106 .periods_max = SST_MAX_PERIODS,
107 .fifo_size = SST_FIFO_SIZE,
108};
109
110/* MFLD - MSIC */
111static struct snd_soc_dai_driver sst_platform_dai[] = {
112{
113 .name = "Headset-cpu-dai",
114 .id = 0,
115 .playback = {
116 .channels_min = SST_STEREO,
117 .channels_max = SST_STEREO,
118 .rates = SNDRV_PCM_RATE_48000,
119 .formats = SNDRV_PCM_FMTBIT_S24_LE,
120 },
121 .capture = {
122 .channels_min = 1,
123 .channels_max = 5,
124 .rates = SNDRV_PCM_RATE_48000,
125 .formats = SNDRV_PCM_FMTBIT_S24_LE,
126 },
127},
128{
129 .name = "Speaker-cpu-dai",
130 .id = 1,
131 .playback = {
132 .channels_min = SST_MONO,
133 .channels_max = SST_STEREO,
134 .rates = SNDRV_PCM_RATE_48000,
135 .formats = SNDRV_PCM_FMTBIT_S24_LE,
136 },
137},
138{
139 .name = "Vibra1-cpu-dai",
140 .id = 2,
141 .playback = {
142 .channels_min = SST_MONO,
143 .channels_max = SST_MONO,
144 .rates = SNDRV_PCM_RATE_48000,
145 .formats = SNDRV_PCM_FMTBIT_S24_LE,
146 },
147},
148{
149 .name = "Vibra2-cpu-dai",
150 .id = 3,
151 .playback = {
152 .channels_min = SST_MONO,
153 .channels_max = SST_STEREO,
154 .rates = SNDRV_PCM_RATE_48000,
155 .formats = SNDRV_PCM_FMTBIT_S24_LE,
156 },
157},
158{
159 .name = "Compress-cpu-dai",
160 .compress_dai = 1,
161 .playback = {
162 .channels_min = SST_STEREO,
163 .channels_max = SST_STEREO,
164 .rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
165 .formats = SNDRV_PCM_FMTBIT_S16_LE,
166 },
167},
168};
169
170static const struct snd_soc_component_driver sst_component = {
171 .name = "sst",
172};
173
174/* helper functions */
175static inline void sst_set_stream_status(struct sst_runtime_stream *stream,
176 int state)
177{
178 unsigned long flags;
179 spin_lock_irqsave(&stream->status_lock, flags);
180 stream->stream_status = state;
181 spin_unlock_irqrestore(&stream->status_lock, flags);
182}
183
184static inline int sst_get_stream_status(struct sst_runtime_stream *stream)
185{
186 int state;
187 unsigned long flags;
188
189 spin_lock_irqsave(&stream->status_lock, flags);
190 state = stream->stream_status;
191 spin_unlock_irqrestore(&stream->status_lock, flags);
192 return state;
193}
194
195static void sst_fill_pcm_params(struct snd_pcm_substream *substream,
196 struct sst_pcm_params *param)
197{
198
199 param->codec = SST_CODEC_TYPE_PCM;
200 param->num_chan = (u8) substream->runtime->channels;
201 param->pcm_wd_sz = substream->runtime->sample_bits;
202 param->reserved = 0;
203 param->sfreq = substream->runtime->rate;
204 param->ring_buffer_size = snd_pcm_lib_buffer_bytes(substream);
205 param->period_count = substream->runtime->period_size;
206 param->ring_buffer_addr = virt_to_phys(substream->dma_buffer.area);
207 pr_debug("period_cnt = %d\n", param->period_count);
208 pr_debug("sfreq= %d, wd_sz = %d\n", param->sfreq, param->pcm_wd_sz);
209}
210
211static int sst_platform_alloc_stream(struct snd_pcm_substream *substream)
212{
213 struct sst_runtime_stream *stream =
214 substream->runtime->private_data;
215 struct sst_pcm_params param = {0};
216 struct sst_stream_params str_params = {0};
217 int ret_val;
218
219 /* set codec params and inform SST driver the same */
220 sst_fill_pcm_params(substream, &param);
221 substream->runtime->dma_area = substream->dma_buffer.area;
222 str_params.sparams = param;
223 str_params.codec = param.codec;
224 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
225 str_params.ops = STREAM_OPS_PLAYBACK;
226 str_params.device_type = substream->pcm->device + 1;
227 pr_debug("Playbck stream,Device %d\n",
228 substream->pcm->device);
229 } else {
230 str_params.ops = STREAM_OPS_CAPTURE;
231 str_params.device_type = SND_SST_DEVICE_CAPTURE;
232 pr_debug("Capture stream,Device %d\n",
233 substream->pcm->device);
234 }
235 ret_val = stream->ops->open(&str_params);
236 pr_debug("SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val);
237 if (ret_val < 0)
238 return ret_val;
239
240 stream->stream_info.str_id = ret_val;
241 pr_debug("str id : %d\n", stream->stream_info.str_id);
242 return ret_val;
243}
244
245static void sst_period_elapsed(void *mad_substream)
246{
247 struct snd_pcm_substream *substream = mad_substream;
248 struct sst_runtime_stream *stream;
249 int status;
250
251 if (!substream || !substream->runtime)
252 return;
253 stream = substream->runtime->private_data;
254 if (!stream)
255 return;
256 status = sst_get_stream_status(stream);
257 if (status != SST_PLATFORM_RUNNING)
258 return;
259 snd_pcm_period_elapsed(substream);
260}
261
262static int sst_platform_init_stream(struct snd_pcm_substream *substream)
263{
264 struct sst_runtime_stream *stream =
265 substream->runtime->private_data;
266 int ret_val;
267
268 pr_debug("setting buffer ptr param\n");
269 sst_set_stream_status(stream, SST_PLATFORM_INIT);
270 stream->stream_info.period_elapsed = sst_period_elapsed;
271 stream->stream_info.mad_substream = substream;
272 stream->stream_info.buffer_ptr = 0;
273 stream->stream_info.sfreq = substream->runtime->rate;
274 ret_val = stream->ops->device_control(
275 SST_SND_STREAM_INIT, &stream->stream_info);
276 if (ret_val)
277 pr_err("control_set ret error %d\n", ret_val);
278 return ret_val;
279
280}
281/* end -- helper functions */
282
283static int sst_platform_open(struct snd_pcm_substream *substream)
284{
285 struct snd_pcm_runtime *runtime = substream->runtime;
286 struct sst_runtime_stream *stream;
287 int ret_val;
288
289 pr_debug("sst_platform_open called\n");
290
291 snd_soc_set_runtime_hwparams(substream, &sst_platform_pcm_hw);
292 ret_val = snd_pcm_hw_constraint_integer(runtime,
293 SNDRV_PCM_HW_PARAM_PERIODS);
294 if (ret_val < 0)
295 return ret_val;
296
297 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
298 if (!stream)
299 return -ENOMEM;
300 spin_lock_init(&stream->status_lock);
301
302 /* get the sst ops */
303 mutex_lock(&sst_lock);
304 if (!sst) {
305 pr_err("no device available to run\n");
306 mutex_unlock(&sst_lock);
307 kfree(stream);
308 return -ENODEV;
309 }
310 if (!try_module_get(sst->dev->driver->owner)) {
311 mutex_unlock(&sst_lock);
312 kfree(stream);
313 return -ENODEV;
314 }
315 stream->ops = sst->ops;
316 mutex_unlock(&sst_lock);
317
318 stream->stream_info.str_id = 0;
319 sst_set_stream_status(stream, SST_PLATFORM_INIT);
320 stream->stream_info.mad_substream = substream;
321 /* allocate memory for SST API set */
322 runtime->private_data = stream;
323
324 return 0;
325}
326
327static int sst_platform_close(struct snd_pcm_substream *substream)
328{
329 struct sst_runtime_stream *stream;
330 int ret_val = 0, str_id;
331
332 pr_debug("sst_platform_close called\n");
333 stream = substream->runtime->private_data;
334 str_id = stream->stream_info.str_id;
335 if (str_id)
336 ret_val = stream->ops->close(str_id);
337 module_put(sst->dev->driver->owner);
338 kfree(stream);
339 return ret_val;
340}
341
342static int sst_platform_pcm_prepare(struct snd_pcm_substream *substream)
343{
344 struct sst_runtime_stream *stream;
345 int ret_val = 0, str_id;
346
347 pr_debug("sst_platform_pcm_prepare called\n");
348 stream = substream->runtime->private_data;
349 str_id = stream->stream_info.str_id;
350 if (stream->stream_info.str_id) {
351 ret_val = stream->ops->device_control(
352 SST_SND_DROP, &str_id);
353 return ret_val;
354 }
355
356 ret_val = sst_platform_alloc_stream(substream);
357 if (ret_val < 0)
358 return ret_val;
359 snprintf(substream->pcm->id, sizeof(substream->pcm->id),
360 "%d", stream->stream_info.str_id);
361
362 ret_val = sst_platform_init_stream(substream);
363 if (ret_val)
364 return ret_val;
365 substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
366 return ret_val;
367}
368
369static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream,
370 int cmd)
371{
372 int ret_val = 0, str_id;
373 struct sst_runtime_stream *stream;
374 int str_cmd, status;
375
376 pr_debug("sst_platform_pcm_trigger called\n");
377 stream = substream->runtime->private_data;
378 str_id = stream->stream_info.str_id;
379 switch (cmd) {
380 case SNDRV_PCM_TRIGGER_START:
381 pr_debug("sst: Trigger Start\n");
382 str_cmd = SST_SND_START;
383 status = SST_PLATFORM_RUNNING;
384 stream->stream_info.mad_substream = substream;
385 break;
386 case SNDRV_PCM_TRIGGER_STOP:
387 pr_debug("sst: in stop\n");
388 str_cmd = SST_SND_DROP;
389 status = SST_PLATFORM_DROPPED;
390 break;
391 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
392 pr_debug("sst: in pause\n");
393 str_cmd = SST_SND_PAUSE;
394 status = SST_PLATFORM_PAUSED;
395 break;
396 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
397 pr_debug("sst: in pause release\n");
398 str_cmd = SST_SND_RESUME;
399 status = SST_PLATFORM_RUNNING;
400 break;
401 default:
402 return -EINVAL;
403 }
404 ret_val = stream->ops->device_control(str_cmd, &str_id);
405 if (!ret_val)
406 sst_set_stream_status(stream, status);
407
408 return ret_val;
409}
410
411
412static snd_pcm_uframes_t sst_platform_pcm_pointer
413 (struct snd_pcm_substream *substream)
414{
415 struct sst_runtime_stream *stream;
416 int ret_val, status;
417 struct pcm_stream_info *str_info;
418
419 stream = substream->runtime->private_data;
420 status = sst_get_stream_status(stream);
421 if (status == SST_PLATFORM_INIT)
422 return 0;
423 str_info = &stream->stream_info;
424 ret_val = stream->ops->device_control(
425 SST_SND_BUFFER_POINTER, str_info);
426 if (ret_val) {
427 pr_err("sst: error code = %d\n", ret_val);
428 return ret_val;
429 }
430 return stream->stream_info.buffer_ptr;
431}
432
433static int sst_platform_pcm_hw_params(struct snd_pcm_substream *substream,
434 struct snd_pcm_hw_params *params)
435{
436 snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
437 memset(substream->runtime->dma_area, 0, params_buffer_bytes(params));
438
439 return 0;
440}
441
442static int sst_platform_pcm_hw_free(struct snd_pcm_substream *substream)
443{
444 return snd_pcm_lib_free_pages(substream);
445}
446
447static struct snd_pcm_ops sst_platform_ops = {
448 .open = sst_platform_open,
449 .close = sst_platform_close,
450 .ioctl = snd_pcm_lib_ioctl,
451 .prepare = sst_platform_pcm_prepare,
452 .trigger = sst_platform_pcm_trigger,
453 .pointer = sst_platform_pcm_pointer,
454 .hw_params = sst_platform_pcm_hw_params,
455 .hw_free = sst_platform_pcm_hw_free,
456};
457
458static void sst_pcm_free(struct snd_pcm *pcm)
459{
460 pr_debug("sst_pcm_free called\n");
461 snd_pcm_lib_preallocate_free_for_all(pcm);
462}
463
464static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
465{
466 struct snd_pcm *pcm = rtd->pcm;
467 int retval = 0;
468
469 pr_debug("sst_pcm_new called\n");
470 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream ||
471 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
472 retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
473 SNDRV_DMA_TYPE_CONTINUOUS,
474 snd_dma_continuous_data(GFP_KERNEL),
475 SST_MIN_BUFFER, SST_MAX_BUFFER);
476 if (retval) {
477 pr_err("dma buffer allocationf fail\n");
478 return retval;
479 }
480 }
481 return retval;
482}
483
484/* compress stream operations */
485static void sst_compr_fragment_elapsed(void *arg)
486{
487 struct snd_compr_stream *cstream = (struct snd_compr_stream *)arg;
488
489 pr_debug("fragment elapsed by driver\n");
490 if (cstream)
491 snd_compr_fragment_elapsed(cstream);
492}
493
494static int sst_platform_compr_open(struct snd_compr_stream *cstream)
495{
496
497 int ret_val = 0;
498 struct snd_compr_runtime *runtime = cstream->runtime;
499 struct sst_runtime_stream *stream;
500
501 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
502 if (!stream)
503 return -ENOMEM;
504
505 spin_lock_init(&stream->status_lock);
506
507 /* get the sst ops */
508 if (!sst || !try_module_get(sst->dev->driver->owner)) {
509 pr_err("no device available to run\n");
510 ret_val = -ENODEV;
511 goto out_ops;
512 }
513 stream->compr_ops = sst->compr_ops;
514
515 stream->id = 0;
516 sst_set_stream_status(stream, SST_PLATFORM_INIT);
517 runtime->private_data = stream;
518 return 0;
519out_ops:
520 kfree(stream);
521 return ret_val;
522}
523
524static int sst_platform_compr_free(struct snd_compr_stream *cstream)
525{
526 struct sst_runtime_stream *stream;
527 int ret_val = 0, str_id;
528
529 stream = cstream->runtime->private_data;
530 /*need to check*/
531 str_id = stream->id;
532 if (str_id)
533 ret_val = stream->compr_ops->close(str_id);
534 module_put(sst->dev->driver->owner);
535 kfree(stream);
536 pr_debug("%s: %d\n", __func__, ret_val);
537 return 0;
538}
539
540static int sst_platform_compr_set_params(struct snd_compr_stream *cstream,
541 struct snd_compr_params *params)
542{
543 struct sst_runtime_stream *stream;
544 int retval;
545 struct snd_sst_params str_params;
546 struct sst_compress_cb cb;
547
548 stream = cstream->runtime->private_data;
549 /* construct fw structure for this*/
550 memset(&str_params, 0, sizeof(str_params));
551
552 str_params.ops = STREAM_OPS_PLAYBACK;
553 str_params.stream_type = SST_STREAM_TYPE_MUSIC;
554 str_params.device_type = SND_SST_DEVICE_COMPRESS;
555
556 switch (params->codec.id) {
557 case SND_AUDIOCODEC_MP3: {
558 str_params.codec = SST_CODEC_TYPE_MP3;
559 str_params.sparams.uc.mp3_params.codec = SST_CODEC_TYPE_MP3;
560 str_params.sparams.uc.mp3_params.num_chan = params->codec.ch_in;
561 str_params.sparams.uc.mp3_params.pcm_wd_sz = 16;
562 break;
563 }
564
565 case SND_AUDIOCODEC_AAC: {
566 str_params.codec = SST_CODEC_TYPE_AAC;
567 str_params.sparams.uc.aac_params.codec = SST_CODEC_TYPE_AAC;
568 str_params.sparams.uc.aac_params.num_chan = params->codec.ch_in;
569 str_params.sparams.uc.aac_params.pcm_wd_sz = 16;
570 if (params->codec.format == SND_AUDIOSTREAMFORMAT_MP4ADTS)
571 str_params.sparams.uc.aac_params.bs_format =
572 AAC_BIT_STREAM_ADTS;
573 else if (params->codec.format == SND_AUDIOSTREAMFORMAT_RAW)
574 str_params.sparams.uc.aac_params.bs_format =
575 AAC_BIT_STREAM_RAW;
576 else {
577 pr_err("Undefined format%d\n", params->codec.format);
578 return -EINVAL;
579 }
580 str_params.sparams.uc.aac_params.externalsr =
581 params->codec.sample_rate;
582 break;
583 }
584
585 default:
586 pr_err("codec not supported, id =%d\n", params->codec.id);
587 return -EINVAL;
588 }
589
590 str_params.aparams.ring_buf_info[0].addr =
591 virt_to_phys(cstream->runtime->buffer);
592 str_params.aparams.ring_buf_info[0].size =
593 cstream->runtime->buffer_size;
594 str_params.aparams.sg_count = 1;
595 str_params.aparams.frag_size = cstream->runtime->fragment_size;
596
597 cb.param = cstream;
598 cb.compr_cb = sst_compr_fragment_elapsed;
599
600 retval = stream->compr_ops->open(&str_params, &cb);
601 if (retval < 0) {
602 pr_err("stream allocation failed %d\n", retval);
603 return retval;
604 }
605
606 stream->id = retval;
607 return 0;
608}
609
610static int sst_platform_compr_trigger(struct snd_compr_stream *cstream, int cmd)
611{
612 struct sst_runtime_stream *stream =
613 cstream->runtime->private_data;
614
615 return stream->compr_ops->control(cmd, stream->id);
616}
617
618static int sst_platform_compr_pointer(struct snd_compr_stream *cstream,
619 struct snd_compr_tstamp *tstamp)
620{
621 struct sst_runtime_stream *stream;
622
623 stream = cstream->runtime->private_data;
624 stream->compr_ops->tstamp(stream->id, tstamp);
625 tstamp->byte_offset = tstamp->copied_total %
626 (u32)cstream->runtime->buffer_size;
627 pr_debug("calc bytes offset/copied bytes as %d\n", tstamp->byte_offset);
628 return 0;
629}
630
631static int sst_platform_compr_ack(struct snd_compr_stream *cstream,
632 size_t bytes)
633{
634 struct sst_runtime_stream *stream;
635
636 stream = cstream->runtime->private_data;
637 stream->compr_ops->ack(stream->id, (unsigned long)bytes);
638 stream->bytes_written += bytes;
639
640 return 0;
641}
642
643static int sst_platform_compr_get_caps(struct snd_compr_stream *cstream,
644 struct snd_compr_caps *caps)
645{
646 struct sst_runtime_stream *stream =
647 cstream->runtime->private_data;
648
649 return stream->compr_ops->get_caps(caps);
650}
651
652static int sst_platform_compr_get_codec_caps(struct snd_compr_stream *cstream,
653 struct snd_compr_codec_caps *codec)
654{
655 struct sst_runtime_stream *stream =
656 cstream->runtime->private_data;
657
658 return stream->compr_ops->get_codec_caps(codec);
659}
660
661static int sst_platform_compr_set_metadata(struct snd_compr_stream *cstream,
662 struct snd_compr_metadata *metadata)
663{
664 struct sst_runtime_stream *stream =
665 cstream->runtime->private_data;
666
667 return stream->compr_ops->set_metadata(stream->id, metadata);
668}
669
670static struct snd_compr_ops sst_platform_compr_ops = {
671
672 .open = sst_platform_compr_open,
673 .free = sst_platform_compr_free,
674 .set_params = sst_platform_compr_set_params,
675 .set_metadata = sst_platform_compr_set_metadata,
676 .trigger = sst_platform_compr_trigger,
677 .pointer = sst_platform_compr_pointer,
678 .ack = sst_platform_compr_ack,
679 .get_caps = sst_platform_compr_get_caps,
680 .get_codec_caps = sst_platform_compr_get_codec_caps,
681};
682
683static struct snd_soc_platform_driver sst_soc_platform_drv = {
684 .ops = &sst_platform_ops,
685 .compr_ops = &sst_platform_compr_ops,
686 .pcm_new = sst_pcm_new,
687 .pcm_free = sst_pcm_free,
688};
689
690static int sst_platform_probe(struct platform_device *pdev)
691{
692 int ret;
693
694 pr_debug("sst_platform_probe called\n");
695 sst = NULL;
696 ret = snd_soc_register_platform(&pdev->dev, &sst_soc_platform_drv);
697 if (ret) {
698 pr_err("registering soc platform failed\n");
699 return ret;
700 }
701
702 ret = snd_soc_register_component(&pdev->dev, &sst_component,
703 sst_platform_dai, ARRAY_SIZE(sst_platform_dai));
704 if (ret) {
705 pr_err("registering cpu dais failed\n");
706 snd_soc_unregister_platform(&pdev->dev);
707 }
708 return ret;
709}
710
711static int sst_platform_remove(struct platform_device *pdev)
712{
713
714 snd_soc_unregister_component(&pdev->dev);
715 snd_soc_unregister_platform(&pdev->dev);
716 pr_debug("sst_platform_remove success\n");
717 return 0;
718}
719
720static struct platform_driver sst_platform_driver = {
721 .driver = {
722 .name = "sst-platform",
723 .owner = THIS_MODULE,
724 },
725 .probe = sst_platform_probe,
726 .remove = sst_platform_remove,
727};
728
729module_platform_driver(sst_platform_driver);
730
731MODULE_DESCRIPTION("ASoC Intel(R) MID Platform driver");
732MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
733MODULE_AUTHOR("Harsha Priya <priya.harsha@intel.com>");
734MODULE_LICENSE("GPL v2");
735MODULE_ALIAS("platform:sst-platform");
diff --git a/sound/soc/intel/sst_platform.h b/sound/soc/intel/sst_platform.h
new file mode 100644
index 000000000000..cacc9066ec52
--- /dev/null
+++ b/sound/soc/intel/sst_platform.h
@@ -0,0 +1,157 @@
1/*
2 * sst_platform.h - Intel MID Platform driver header file
3 *
4 * Copyright (C) 2010 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * Author: Harsha Priya <priya.harsha@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 *
24 *
25 */
26
27#ifndef __SST_PLATFORMDRV_H__
28#define __SST_PLATFORMDRV_H__
29
30#include "sst_dsp.h"
31
32#define SST_MONO 1
33#define SST_STEREO 2
34#define SST_MAX_CAP 5
35
36#define SST_MIN_RATE 8000
37#define SST_MAX_RATE 48000
38#define SST_MIN_CHANNEL 1
39#define SST_MAX_CHANNEL 5
40#define SST_MAX_BUFFER (800*1024)
41#define SST_MIN_BUFFER (800*1024)
42#define SST_MIN_PERIOD_BYTES 32
43#define SST_MAX_PERIOD_BYTES SST_MAX_BUFFER
44#define SST_MIN_PERIODS 2
45#define SST_MAX_PERIODS (1024*2)
46#define SST_FIFO_SIZE 0
47
48struct pcm_stream_info {
49 int str_id;
50 void *mad_substream;
51 void (*period_elapsed) (void *mad_substream);
52 unsigned long long buffer_ptr;
53 int sfreq;
54};
55
56enum sst_drv_status {
57 SST_PLATFORM_INIT = 1,
58 SST_PLATFORM_STARTED,
59 SST_PLATFORM_RUNNING,
60 SST_PLATFORM_PAUSED,
61 SST_PLATFORM_DROPPED,
62};
63
64enum sst_controls {
65 SST_SND_ALLOC = 0x00,
66 SST_SND_PAUSE = 0x01,
67 SST_SND_RESUME = 0x02,
68 SST_SND_DROP = 0x03,
69 SST_SND_FREE = 0x04,
70 SST_SND_BUFFER_POINTER = 0x05,
71 SST_SND_STREAM_INIT = 0x06,
72 SST_SND_START = 0x07,
73 SST_MAX_CONTROLS = 0x07,
74};
75
76enum sst_stream_ops {
77 STREAM_OPS_PLAYBACK = 0,
78 STREAM_OPS_CAPTURE,
79};
80
81enum sst_audio_device_type {
82 SND_SST_DEVICE_HEADSET = 1,
83 SND_SST_DEVICE_IHF,
84 SND_SST_DEVICE_VIBRA,
85 SND_SST_DEVICE_HAPTIC,
86 SND_SST_DEVICE_CAPTURE,
87 SND_SST_DEVICE_COMPRESS,
88};
89
90/* PCM Parameters */
91struct sst_pcm_params {
92 u16 codec; /* codec type */
93 u8 num_chan; /* 1=Mono, 2=Stereo */
94 u8 pcm_wd_sz; /* 16/24 - bit*/
95 u32 reserved; /* Bitrate in bits per second */
96 u32 sfreq; /* Sampling rate in Hz */
97 u32 ring_buffer_size;
98 u32 period_count; /* period elapsed in samples*/
99 u32 ring_buffer_addr;
100};
101
102struct sst_stream_params {
103 u32 result;
104 u32 stream_id;
105 u8 codec;
106 u8 ops;
107 u8 stream_type;
108 u8 device_type;
109 struct sst_pcm_params sparams;
110};
111
112struct sst_compress_cb {
113 void *param;
114 void (*compr_cb)(void *param);
115};
116
117struct compress_sst_ops {
118 const char *name;
119 int (*open) (struct snd_sst_params *str_params,
120 struct sst_compress_cb *cb);
121 int (*control) (unsigned int cmd, unsigned int str_id);
122 int (*tstamp) (unsigned int str_id, struct snd_compr_tstamp *tstamp);
123 int (*ack) (unsigned int str_id, unsigned long bytes);
124 int (*close) (unsigned int str_id);
125 int (*get_caps) (struct snd_compr_caps *caps);
126 int (*get_codec_caps) (struct snd_compr_codec_caps *codec);
127 int (*set_metadata) (unsigned int str_id,
128 struct snd_compr_metadata *mdata);
129
130};
131
132struct sst_ops {
133 int (*open) (struct sst_stream_params *str_param);
134 int (*device_control) (int cmd, void *arg);
135 int (*close) (unsigned int str_id);
136};
137
138struct sst_runtime_stream {
139 int stream_status;
140 unsigned int id;
141 size_t bytes_written;
142 struct pcm_stream_info stream_info;
143 struct sst_ops *ops;
144 struct compress_sst_ops *compr_ops;
145 spinlock_t status_lock;
146};
147
148struct sst_device {
149 char *name;
150 struct device *dev;
151 struct sst_ops *ops;
152 struct compress_sst_ops *compr_ops;
153};
154
155int sst_register_dsp(struct sst_device *sst);
156int sst_unregister_dsp(struct sst_device *sst);
157#endif